/*
 * css/base.css — Ayutthaya: The River Throne · type, controls and lacquer surfaces (builder E-ui).
 * Palette tokens live in css/art.css (DESIGN §12); this file adds the type system, buttons, chips,
 * badges, panels, modals, toasts and the debug error box. Layouts are in css/screens.css.
 * Thai: line-height 1.75, never italic, never letter-spaced, no word-break:break-all (clusters stay whole).
 */
:root {
  --f-en-head: "Cormorant Garamond", Georgia, "Times New Roman", "Noto Serif Thai", "Leelawadee UI", Tahoma, serif;
  --f-en-body: "Crimson Pro", Georgia, "Times New Roman", "Sarabun", "Leelawadee UI", Tahoma, serif;
  --f-th-head: "Noto Serif Thai", "Leelawadee UI", Tahoma, Georgia, serif;
  --f-th-body: "Sarabun", "Leelawadee UI", Tahoma, "Noto Sans Thai", Georgia, sans-serif;
  --f-head: var(--f-en-head); --f-body: var(--f-en-body); --lh: 1.5; --lh-head: 1.18; --track: .14em;
  --gold-line: rgba(138, 106, 30, .6);
  --up: var(--gold-2); --down: #E57A63; --even: var(--ivory-dim);
  --band-devoted: var(--gold-3); --band-friendly: var(--gold-2); --band-neutral: var(--ivory-dim); --band-cold: #D9906F; --band-hostile: #E5694F;
  --panel: linear-gradient(180deg, #1B1410 0%, #140F0B 60%, #120D0A 100%);
  --shadow: 0 18px 40px rgba(0, 0, 0, .55), 0 2px 0 rgba(0, 0, 0, .6);
  --ease: cubic-bezier(.2, .7, .2, 1);
  --lacquer-field: none;
}
html[lang="th"] { --f-head: var(--f-th-head); --f-body: var(--f-th-body); --lh: 1.75; --lh-head: 1.45; --track: 0; }
html[lang="en"] [lang="th"] { font-family: var(--f-th-body); line-height: 1.7; font-style: normal; letter-spacing: 0; }
html[lang="th"] [lang="en"] { font-family: var(--f-en-body); line-height: 1.5; }
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; background: var(--lacquer-0); color-scheme: dark; }
body {
  margin: 0; min-height: 100vh; color: var(--ivory); font-family: var(--f-body); font-size: 17px; line-height: var(--lh);
  background-color: var(--lacquer-0);
  background-image: radial-gradient(120% 70% at 50% -10%, rgba(107, 26, 20, .38), transparent 62%), radial-gradient(90% 60% at 50% 120%, rgba(59, 13, 11, .5), transparent 70%), var(--lacquer-field);
  background-attachment: fixed; overflow-wrap: break-word; word-break: normal; line-break: auto;
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
}
h1, h2, h3, h4 { font-family: var(--f-head); font-weight: 600; line-height: var(--lh-head); color: var(--gold-2); margin: 0; }
p { margin: 0 0 .7em; }
p:last-child { margin-bottom: 0; }
q { quotes: "“" "”"; }
button { font: inherit; color: inherit; }
kbd { font-family: inherit; }
.sr { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--ivory-dim); }
.small { font-size: .86rem; }
.kicker {
  display: inline-flex; align-items: center; gap: 6px; font-family: var(--f-body); font-size: .74rem; font-weight: 600;
  letter-spacing: var(--track); text-transform: uppercase; color: var(--gold-1); line-height: 1.4;
}
html[lang="th"] .kicker { font-size: .84rem; text-transform: none; font-weight: 500; }
.kicker-s { font-size: .78rem; color: var(--ivory-dim); margin-right: 6px; }
.mini-ic { width: 16px; height: 16px; color: var(--gold-1); flex: none; }
:focus { outline: none; }
:focus-visible { outline: 2px solid var(--gold-3); outline-offset: 2px; }
::selection { background: rgba(201, 161, 59, .35); color: var(--gold-3); }
* { scrollbar-width: thin; scrollbar-color: var(--gold-0) transparent; }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: rgba(138, 106, 30, .55); border-radius: 8px; }
::-webkit-scrollbar-track { background: transparent; }

/* ---- lacquer surfaces: double gold rule + kranok corners ------------------------------------- */
.lacquer {
  position: relative; background: var(--panel);
  box-shadow: inset 0 0 0 1px var(--gold-0), inset 0 0 0 4px #120D0A, inset 0 0 0 5px rgba(201, 161, 59, .55), var(--shadow);
}
.panel-soft { position: relative; background: linear-gradient(180deg, rgba(27, 20, 16, .92), rgba(18, 13, 10, .92)); box-shadow: inset 0 0 0 1px rgba(138, 106, 30, .5); }
span.corners { position: absolute; inset: 0; pointer-events: none; z-index: 1; }
.corners .ayu-corner { position: absolute; width: 22px; height: 22px; }
.corners .tl { left: 2px; top: 2px; } .corners .tr { right: 2px; top: 2px; } .corners .bl { left: 2px; bottom: 2px; } .corners .br { right: 2px; bottom: 2px; }
/* ---- buttons ---------------------------------------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 8px 18px;
  border: 1px solid var(--gold-0); border-radius: 2px; cursor: pointer; color: var(--gold-2);
  background: linear-gradient(180deg, #241A13, #17110C); font-family: var(--f-head); font-size: 1.02rem; font-weight: 600; letter-spacing: .02em;
  transition: border-color .2s, color .2s, box-shadow .2s, background .2s; text-align: center;
}
html[lang="th"] .btn { font-size: .98rem; font-weight: 500; letter-spacing: 0; }
.btn .ayu-icon { width: 18px; height: 18px; }
.btn:hover { border-color: var(--gold-1); color: var(--gold-3); box-shadow: 0 0 0 1px rgba(201, 161, 59, .25), 0 0 22px rgba(201, 161, 59, .12); }
.btn-primary { background: linear-gradient(180deg, #7C2219, var(--red-1) 55%, #561410); border-color: var(--gold-1); color: var(--gold-3); }
.btn-primary:hover { background: linear-gradient(180deg, #8C281D, #74201A 55%, #5E1712); }
.btn-quiet { background: transparent; border-color: rgba(138, 106, 30, .55); color: var(--gold-1); }
.btn-danger { background: transparent; border-color: var(--vermilion); color: #F1B2A3; }
.btn-danger:hover { border-color: #F0866F; color: #FFD3C8; box-shadow: 0 0 18px rgba(210, 85, 63, .2); }
.btn-n { color: var(--ivory-dim); font-weight: 400; }
.icon-btn {
  display: inline-grid; place-items: center; width: 44px; height: 44px; padding: 0; border: 1px solid transparent; border-radius: 2px;
  background: transparent; color: var(--gold-1); cursor: pointer;
}
.icon-btn:hover { color: var(--gold-3); border-color: rgba(138, 106, 30, .6); }
.icon-btn .ayu-icon { width: 22px; height: 22px; }
.icon-btn.sm { width: 36px; height: 36px; }
.link-btn { background: none; border: 0; padding: 4px 2px; min-height: 32px; color: var(--gold-2); cursor: pointer; text-decoration: underline; text-decoration-color: rgba(230, 199, 106, .4); text-underline-offset: 3px; }
.link-btn:hover { color: var(--gold-3); }
/* the "go on" button: red lacquer, gold rule, kranok flourishes either side */
.btn-go {
  position: relative; min-height: 50px; padding: 8px 14px; gap: 6px; font-size: 1.1rem;
  background: linear-gradient(180deg, #82251B, var(--red-1) 50%, #4E120E); border: 1px solid var(--gold-1); color: var(--gold-3);
  box-shadow: inset 0 0 0 3px #4E120E, inset 0 0 0 4px rgba(230, 199, 106, .45), 0 8px 22px rgba(0, 0, 0, .45);
}
.btn-go:hover { background: linear-gradient(180deg, #932B1F, #7A1F18 50%, #5A1610); color: #FFF3CF; }
.btn-go .ayu-btn-orn { width: 24px; height: 24px; flex: none; }
.btn-go-t { padding: 0 4px; }
.kbd {
  display: inline-grid; place-items: center; min-width: 22px; height: 22px; padding: 0 5px; margin-left: 4px; font-size: .72rem; line-height: 1;
  border: 1px solid rgba(201, 161, 59, .45); border-radius: 3px; color: var(--gold-1); font-family: var(--f-en-body); opacity: .8;
}
.go-row { display: flex; flex-wrap: wrap; justify-content: flex-end; align-items: center; gap: 12px; margin-top: 20px; }
.row-end { display: flex; justify-content: flex-end; gap: 10px; flex-wrap: wrap; margin-top: 18px; }

/* ---- chips: arrow + icon + number, never colour alone (DESIGN §11) ----------------------------- */
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 4px; padding: 1px 9px 1px 7px; border: 1px solid; border-radius: 999px;
  font-family: var(--f-body); font-size: .84rem; line-height: 1.6; white-space: nowrap; max-width: 100%;
}
.chip .arr { font-size: .56rem; line-height: 1; }
.chip-ic { width: 15px; height: 15px; flex: none; }
.chip-t { overflow: hidden; text-overflow: ellipsis; }
.chip.up { color: var(--up); border-color: rgba(230, 199, 106, .45); background: rgba(230, 199, 106, .07); }
.chip.down { color: var(--down); border-color: rgba(210, 85, 63, .6); background: rgba(210, 85, 63, .09); }
.chip.even { color: var(--even); border-color: rgba(191, 180, 154, .35); background: rgba(191, 180, 154, .05); }
.chip-opinion { border-style: dashed; }
.chip-secret { color: #A6D0B0 !important; border-color: rgba(94, 140, 106, .75) !important; background: rgba(94, 140, 106, .14) !important; }
.chip-trait { color: var(--gold-3); }
.chip-icon-only { padding: 1px 6px; }
/* an income that stops: the treasury mark struck through, on a dotted (ending) border */
.chip-endIncome { border-style: dotted; }
.chip-ic-ended { position: relative; display: inline-flex; flex: none; }
.chip-ic-ended::after { content: ""; position: absolute; left: -1px; right: -1px; top: 50%; height: 1.6px; background: currentColor; transform: rotate(-38deg); border-radius: 1px; }
.delta { display: inline-flex; align-items: center; gap: 3px; font-weight: 600; white-space: nowrap; }
.delta .arr { font-size: .58em; }
.delta.up { color: var(--up); } .delta.down { color: var(--down); }
.up > b, b.up { color: var(--up); } .down > b, b.down { color: var(--down); }
/* ---- regard badges and bands ---------------------------------------------------------------- */
.badge {
  display: inline-flex; align-items: center; gap: 3px; padding: 0 8px 0 5px; min-height: 24px; border-radius: 999px; border: 1px solid currentColor;
  font-size: .8rem; font-weight: 600; line-height: 1.5; white-space: nowrap; background: rgba(11, 9, 7, .6); vertical-align: middle;
}
.badge-ic { width: 15px; height: 15px; }
.band-devoted { --band: var(--band-devoted); } .band-friendly { --band: var(--band-friendly); } .band-neutral { --band: var(--band-neutral); }
.band-cold { --band: var(--band-cold); } .band-hostile { --band: var(--band-hostile); }
.badge.band-devoted, .badge.band-friendly, .badge.band-neutral, .badge.band-cold, .badge.band-hostile { color: var(--band); }
.trait-chip {
  display: inline-flex; align-items: center; gap: 5px; padding: 2px 10px; margin: 0 6px 6px 0; border: 1px solid rgba(201, 161, 59, .5);
  border-radius: 2px; color: var(--gold-2); font-size: .86rem; background: rgba(201, 161, 59, .06);
}
/* faces: the art supplies its own arched frame; a face that opens a sheet is a real button */
.face { display: block; line-height: 0; }
.face-btn { display: block; width: 100%; padding: 0; border: 0; background: none; cursor: pointer; border-radius: 6px; transition: transform .25s var(--ease), filter .25s; }
.face-btn:hover { transform: translateY(-2px); filter: brightness(1.08) drop-shadow(0 0 10px rgba(201, 161, 59, .25)); }
.face .ayu-portrait { width: 100%; height: auto; }

/* ---- modals ------------------------------------------------------------------------------------ */
#modal-layer { position: relative; z-index: 50; }
/* behind an open panel nothing answers the pointer (fallback for browsers without the inert attribute) */
.is-inert { pointer-events: none; user-select: none; }
.modal-wrap { position: fixed; inset: 0; display: grid; place-items: center; padding: 28px 20px; z-index: 50; }
.modal-backdrop { position: absolute; inset: 0; background: radial-gradient(80% 80% at 50% 40%, rgba(11, 9, 7, .72), rgba(11, 9, 7, .9)); backdrop-filter: blur(2px); }
.modal {
  position: relative; display: flex; flex-direction: column; width: min(720px, 100%); max-height: min(88vh, 900px); outline: none;
  transition: transform .32s var(--ease), opacity .32s;
}
.w420 .modal { width: min(420px, 100%); } .w560 .modal { width: min(560px, 100%); } .w760 .modal { width: min(760px, 100%); }
.w800 .modal { width: min(820px, 100%); } .w900 .modal { width: min(920px, 100%); }
.modal-wrap.enter .modal { transform: translateY(14px) scale(.985); opacity: 0; }
.modal-head { display: flex; align-items: center; gap: 12px; padding: 18px 22px 10px 28px; border-bottom: 1px solid rgba(138, 106, 30, .35); position: relative; z-index: 2; }
.modal-title { flex: 1; font-size: 1.5rem; color: var(--gold-2); }
html[lang="th"] .modal-title { font-size: 1.3rem; }
.modal-body { overflow-y: auto; padding: 18px 28px 26px; position: relative; z-index: 2; overscroll-behavior: contain; }
.confirm-text { color: var(--ivory); font-size: 1.05rem; }
.tabs { position: relative; display: flex; flex-wrap: wrap; gap: 4px; margin: -4px 0 18px; border-bottom: 1px solid rgba(138, 106, 30, .35); }
.tab {
  min-height: 44px; padding: 8px 14px; border: 0; border-bottom: 2px solid transparent; background: none; color: var(--ivory-dim); cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px; font-family: var(--f-head); font-size: 1rem; font-weight: 600;
}
.tab:hover { color: var(--gold-2); }
.tab.on { color: var(--gold-3); border-bottom-color: var(--gold-1); }
.empty-note { display: flex; align-items: center; gap: 8px; color: var(--ivory-dim); font-style: italic; }
html[lang="th"] .empty-note { font-style: normal; }

/* ---- toasts and the debug box ------------------------------------------------------------------ */
/* save failure: persistent until dismissed, never blocks play; sits under the top bar, above panels */
.save-banner { position: fixed; z-index: 70; top: 66px; left: 50%; transform: translateX(-50%); width: min(560px, calc(100vw - 24px));
  display: flex; align-items: flex-start; gap: 12px; padding: 12px 10px 12px 16px; color: var(--ivory); font-size: .9rem; line-height: 1.45; }
.save-banner .sb-ic { width: 22px; height: 22px; flex: none; color: var(--down); margin-top: 1px; }
.save-banner .sb-t { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.save-banner .sb-t b { color: var(--gold-2); font-family: var(--f-head); font-weight: 600; font-size: 1rem; }
.save-banner .sb-x { flex: none; }
.save-note.save-bad { color: #E2A08F; margin-top: 8px; }
@media (max-width: 719px) { .save-banner { top: 98px; font-size: .84rem; padding: 10px 6px 10px 12px; } }   /* below the two-row phone top bar */
#toasts { position: fixed; right: 18px; bottom: 18px; z-index: 60; display: flex; flex-direction: column; gap: 8px; max-width: min(380px, calc(100vw - 32px)); pointer-events: none; }
.toast { display: flex; align-items: center; gap: 10px; padding: 12px 16px; color: var(--ivory); font-size: .92rem; animation: toast-in .45s var(--ease) both; pointer-events: auto; }
.toast-ic { width: 22px; height: 22px; color: var(--gold-2); flex: none; }
.toast-jade .toast-ic { color: #8FC29C; } .toast-warn .toast-ic { color: var(--down); }
.toast.out { opacity: 0; transform: translateY(8px); transition: opacity .45s, transform .45s; }
@keyframes toast-in { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
#ayu-errors {
  position: fixed; top: 0; left: 0; right: 0; z-index: 9999; max-height: 40vh; overflow: auto; padding: 10px 16px;
  background: #B3261E; color: #fff; font: 13px/1.45 Consolas, Menlo, monospace; box-shadow: 0 4px 20px rgba(0, 0, 0, .6);
}
#ayu-errors ol { margin: 4px 0 0; padding-left: 22px; }
/* ---- motion: everything stops under reduced motion / instant ----------------------------------- */
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .001ms !important; animation-delay: 0s !important; transition-duration: .001ms !important; } }
html.reduce-motion *, html.reduce-motion *::before, html.reduce-motion *::after { animation-duration: .001ms !important; animation-delay: 0s !important; transition-duration: .001ms !important; }
