/* Layout: a bound manuscript (samut thai). Dark = black-lacquer folio with gold ink; light = white khoi paper with black ink. */
:root {
  --bg: #13100c;
  --surface: #1c1813;
  --surface-2: #241f18;
  --line: #3b3226;
  --fg: #efe5cf;
  --muted: #b2a68c;
  --gold: #d6a84a;
  --gold-ink: #e6c27a;
  --vermilion: #d0553a;
  --human: #e0b04c;
  --vanara: #73c9a5;
  --yak: #b48ae6;
  --ok: #7cc48b;
  --warn: #e0a84c;
  --todo: #7d7468;
  --shadow: 0 1px 0 rgba(0,0,0,.4), 0 12px 32px rgba(0,0,0,.35);
  --font-display: "Taviraj", "Noto Serif Thai", "Times New Roman", serif;
  --font-body: "Sarabun", "Noto Sans Thai", "Segoe UI", sans-serif;
  --font-label: "Chakra Petch", "Sarabun", "Segoe UI", sans-serif;
  --measure: 68ch;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #e3e0d4; --surface: #ece9de; --surface-2: #f3f1e8; --line: #c7c1ae;
    --fg: #1d1a15; --muted: #5d5646; --gold: #8a6416; --gold-ink: #7a5610; --vermilion: #a83a22;
    --human: #8a6416; --vanara: #2f7d5c; --yak: #6a45a8; --ok: #2f7d45; --warn: #9a6512; --todo: #8a8270;
    --shadow: 0 1px 0 rgba(0,0,0,.06), 0 10px 24px rgba(60,50,30,.12);
    color-scheme: light;
  }
}
:root[data-theme="light"] {
  --bg: #e3e0d4; --surface: #ece9de; --surface-2: #f3f1e8; --line: #c7c1ae;
  --fg: #1d1a15; --muted: #5d5646; --gold: #8a6416; --gold-ink: #7a5610; --vermilion: #a83a22;
  --human: #8a6416; --vanara: #2f7d5c; --yak: #6a45a8; --ok: #2f7d45; --warn: #9a6512; --todo: #8a8270;
  --shadow: 0 1px 0 rgba(0,0,0,.06), 0 10px 24px rgba(60,50,30,.12);
  color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--fg);
  font-family: var(--font-body); font-size: 16px; line-height: 1.7;
}
img { max-width: 100%; height: auto; display: block; }
a { color: var(--gold-ink); text-underline-offset: 3px; }
a:focus-visible, button:focus-visible, summary:focus-visible { outline: 2px solid var(--gold); outline-offset: 3px; }
h1, h2, h3 { font-family: var(--font-display); font-weight: 600; line-height: 1.25; text-wrap: balance; margin: 0; }
h1 { font-size: clamp(2rem, 4.5vw, 3.1rem); }
h2 { font-size: clamp(1.45rem, 3vw, 2rem); }
h3 { font-size: 1.2rem; }
p { margin: 0; max-width: var(--measure); }
.label {
  font-family: var(--font-label); font-size: .78rem; letter-spacing: .12em; text-transform: uppercase;
  color: var(--muted); font-weight: 500;
}
.num { font-variant-numeric: tabular-nums; }

/* masthead */
.masthead {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 20;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(8px); border-bottom: 1px solid var(--line);
}
.masthead-inner {
  max-width: 1200px; margin: 0 auto; padding-inline: 16px; padding-block: 10px;
  display: flex; align-items: center; gap: 18px; flex-wrap: wrap;
}
.brand { display: flex; align-items: baseline; gap: 10px; text-decoration: none; color: var(--fg); }
.brand b { font-family: var(--font-display); font-size: 1.25rem; font-weight: 600; color: var(--gold-ink); }
.brand span { font-family: var(--font-label); font-size: .72rem; letter-spacing: .14em; color: var(--muted); }
.chapters { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: thin; flex: 1 1 auto; min-width: 0; }
.chapters a {
  font-family: var(--font-label); font-size: .86rem; white-space: nowrap; text-decoration: none;
  color: var(--muted); padding: 6px 10px; border-radius: 4px;
}
.chapters a:hover { color: var(--fg); background: var(--surface); }
.chapters a[aria-current="page"] { color: var(--bg); background: var(--gold); }

main { max-width: 1200px; margin: 0 auto; padding-inline: 16px; padding-block: 36px 80px; display: grid; gap: 56px; }

/* chapter opener */
.opener { display: grid; gap: 14px; padding-bottom: 28px; border-bottom: 1px solid var(--line); }
.opener .label { color: var(--gold); }
.opener p { color: var(--muted); font-size: 1.08rem; }

section { display: grid; gap: 20px; min-width: 0; }
.section-head { display: grid; gap: 6px; }
.section-head p { color: var(--muted); }

/* gold-leaf rule, like the ruled margins of a samut thai */
.rule { height: 1px; background: linear-gradient(90deg, var(--gold), transparent 70%); opacity: .55; }

.grid { display: grid; gap: 18px; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr)); }
.grid.three { grid-template-columns: repeat(auto-fit, minmax(min(100%, 300px), 1fr)); }
.grid.four { grid-template-columns: repeat(auto-fit, minmax(min(100%, 220px), 1fr)); }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 6px; padding: 18px; display: grid; gap: 10px; min-width: 0; }
.panel h3 { color: var(--gold-ink); }
.panel ul { margin: 0; padding-left: 1.1em; }
.panel li + li { margin-top: 4px; }

figure { margin: 0; display: grid; gap: 8px; min-width: 0; }
figcaption { font-size: .85rem; color: var(--muted); }
.zoom { display: block; border-radius: 4px; overflow: hidden; background: var(--surface-2); border: 1px solid var(--line); cursor: zoom-in; }
.zoom img { width: 100%; }
.missing {
  display: grid; place-items: center; min-height: 160px; padding: 18px; text-align: center;
  border: 1px dashed var(--line); border-radius: 4px; color: var(--todo); font-family: var(--font-label); font-size: .85rem;
}

/* tribe accents */
[data-tribe="human"] { --tribe: var(--human); }
[data-tribe="vanara"] { --tribe: var(--vanara); }
[data-tribe="yak"] { --tribe: var(--yak); }

/* roster: rows = tribes, columns = roles */
.roster { overflow-x: auto; }
.roster table { border-collapse: separate; border-spacing: 10px; width: 100%; min-width: 720px; }
.roster th { font-family: var(--font-label); font-weight: 600; font-size: .8rem; letter-spacing: .12em; color: var(--muted); text-align: center; }
.roster th[scope="row"] { writing-mode: vertical-rl; transform: rotate(180deg); color: var(--tribe); width: 28px; }
.roster td { vertical-align: top; width: 25%; }
.roster a.card { display: grid; gap: 6px; text-decoration: none; color: var(--fg); }
.roster a.card img { aspect-ratio: 2 / 3; object-fit: cover; border-radius: 4px; border: 1px solid var(--line); background: var(--surface-2); }
.roster a.card:hover img { border-color: var(--tribe); }
.roster .cname { font-family: var(--font-display); font-weight: 600; font-size: 1rem; line-height: 1.3; }
.roster .cen { font-family: var(--font-label); font-size: .75rem; color: var(--muted); }

.tribe-card { border-top: 3px solid var(--tribe); }
.tribe-card h3 { color: var(--tribe); }

/* chips */
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  font-family: var(--font-label); font-size: .76rem; letter-spacing: .04em; padding: 3px 9px; border-radius: 999px;
  border: 1px solid var(--line); color: var(--muted); white-space: nowrap;
}
.chip.tribe { border-color: var(--tribe); color: var(--tribe); }
.chip.ok { border-color: var(--ok); color: var(--ok); }
.chip.warn { border-color: var(--warn); color: var(--warn); }
.chip.todo { border-style: dashed; color: var(--todo); }

/* class page */
.class-head { display: grid; gap: 10px; }
.class-head .en { font-family: var(--font-label); color: var(--muted); letter-spacing: .06em; }
.heroes { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
@media (max-width: 560px) { .heroes { grid-template-columns: 1fr; } }
.swatches { display: flex; flex-wrap: wrap; gap: 10px; }
.swatch { display: flex; align-items: center; gap: 8px; font-size: .88rem; }
.swatch i { width: 22px; height: 22px; border-radius: 50%; border: 1px solid var(--line); display: inline-block; }
dl.pieces { display: grid; grid-template-columns: max-content 1fr; gap: 8px 16px; margin: 0; }
dl.pieces dt { font-family: var(--font-label); font-size: .82rem; color: var(--gold); padding-top: 2px; }
dl.pieces dd { margin: 0; min-width: 0; }
@media (max-width: 480px) { dl.pieces { grid-template-columns: 1fr; } dl.pieces dd { margin-bottom: 6px; } }

.pipeline { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 8px; }
.step { border: 1px solid var(--line); border-radius: 4px; padding: 10px; display: grid; gap: 4px; background: var(--surface); }
.step b { font-family: var(--font-label); font-size: .8rem; font-weight: 600; }
.step.ok { border-color: var(--ok); }
.step.warn { border-color: var(--warn); }
.step.todo { border-style: dashed; opacity: .8; }

.pager { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; border-top: 1px solid var(--line); padding-top: 18px; }
.pager a { font-family: var(--font-label); text-decoration: none; }

/* maps */
.map-entry { display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); gap: 20px; align-items: start; padding-block: 8px 24px; border-bottom: 1px solid var(--line); }
@media (max-width: 860px) { .map-entry { grid-template-columns: 1fr; } }
.map-entry .meta { display: grid; gap: 10px; min-width: 0; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; font-size: .92rem; }
.kv dt { color: var(--muted); font-family: var(--font-label); font-size: .8rem; padding-top: 3px; }
.kv dd { margin: 0; min-width: 0; }
.flow { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: 6px; padding: 12px; }
.flow svg { display: block; min-width: 720px; width: 100%; height: auto; }
.flow .n rect { fill: var(--surface-2); stroke: var(--line); stroke-width: 1.5; }
.flow .n.main rect { stroke: var(--gold); }
.flow .n.lock rect { stroke: var(--vermilion); stroke-dasharray: 5 4; }
.flow text { fill: var(--fg); font-family: var(--font-label); font-size: 15px; font-weight: 600; }
.flow text.small { fill: var(--muted); font-size: 12px; font-weight: 500; }
.flow .e { stroke: var(--gold); stroke-width: 2; fill: none; }
.flow .e.opt { stroke: var(--muted); stroke-dasharray: 5 5; stroke-width: 1.5; }

table.data { border-collapse: collapse; width: 100%; font-size: .92rem; }
.table-wrap { overflow-x: auto; }
table.data th, table.data td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.data th { font-family: var(--font-label); font-size: .78rem; letter-spacing: .08em; color: var(--muted); font-weight: 600; }
.src { font-family: var(--font-label); font-size: .72rem; color: var(--todo); }

.callout { border-left: 3px solid var(--vermilion); background: var(--surface); padding: 12px 16px; border-radius: 0 6px 6px 0; display: grid; gap: 6px; }
.callout b { color: var(--vermilion); font-family: var(--font-label); font-size: .82rem; letter-spacing: .06em; }

.status-table td:first-child a { text-decoration: none; }
.chapter-card { text-decoration: none; color: inherit; align-content: start; }
.chapter-card img { aspect-ratio: 3 / 2; object-fit: cover; border-radius: 4px; border: 1px solid var(--line); }
.chapter-card:hover { border-color: var(--gold); }
.chapter-card h3 { color: var(--fg); }

footer.colophon { max-width: 1200px; margin: 0 auto; padding-inline: 16px; padding-block: 24px 48px; color: var(--muted); font-size: .85rem; border-top: 1px solid var(--line); }

/* lightbox */
dialog.lightbox { border: 0; padding: 0; background: transparent; max-width: 96vw; max-height: 94vh; }
dialog.lightbox::backdrop { background: rgba(8,6,4,.86); }
dialog.lightbox img { max-width: 96vw; max-height: 90vh; width: auto; border-radius: 4px; }
dialog.lightbox p { color: #e9dfc8; font-size: .85rem; padding-top: 6px; text-align: center; max-width: none; }

@media (prefers-reduced-motion: no-preference) {
  .roster a.card img, .zoom { transition: border-color .15s ease; }
}

.map-entry, section { scroll-margin-top: 72px; }
