/* spire-mentor docs. Dark-first (the screenshots are dark game art), with a
   light theme. One accent: ember gold. Headings in Kreon, a nod to the
   slab serif of the first game. */

:root {
  --bg: oklch(0.985 0.003 80);
  --surface: oklch(1 0 0);
  --surface-2: oklch(0.955 0.006 80);
  --text: oklch(0.24 0.015 60);
  --muted: oklch(0.46 0.02 60);
  --border: oklch(0.885 0.008 80);
  --border-soft: oklch(0.925 0.006 80);
  --accent: oklch(0.52 0.12 62);
  --accent-strong: oklch(0.42 0.11 55);
  --accent-soft: oklch(0.52 0.12 62 / 0.11);
  --game: oklch(0.52 0.12 40);
  --rust: oklch(0.55 0.14 55);
  --shadow: 0 1px 2px oklch(0.3 0.03 60 / 0.06), 0 10px 30px -12px oklch(0.3 0.03 60 / 0.18);
  --display: "Kreon", "Rockwell", "Roboto Slab", Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, "DejaVu Sans Mono", monospace;
  --radius: 12px;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --z-sticky: 10;
  --z-menu: 20;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: oklch(0.165 0.012 265);
    --surface: oklch(0.2 0.014 265);
    --surface-2: oklch(0.24 0.016 265);
    --text: oklch(0.93 0.008 80);
    --muted: oklch(0.73 0.018 80);
    --border: oklch(0.32 0.016 265);
    --border-soft: oklch(0.27 0.014 265);
    --accent: oklch(0.81 0.13 76);
    --accent-strong: oklch(0.88 0.11 82);
    --accent-soft: oklch(0.81 0.13 76 / 0.13);
    --game: oklch(0.74 0.12 45);
    --rust: oklch(0.76 0.13 60);
    --shadow: 0 1px 2px oklch(0 0 0 / 0.4), 0 14px 36px -14px oklch(0 0 0 / 0.7);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: oklch(0.165 0.012 265);
  --surface: oklch(0.2 0.014 265);
  --surface-2: oklch(0.24 0.016 265);
  --text: oklch(0.93 0.008 80);
  --muted: oklch(0.73 0.018 80);
  --border: oklch(0.32 0.016 265);
  --border-soft: oklch(0.27 0.014 265);
  --accent: oklch(0.81 0.13 76);
  --accent-strong: oklch(0.88 0.11 82);
  --accent-soft: oklch(0.81 0.13 76 / 0.13);
  --game: oklch(0.74 0.12 45);
  --rust: oklch(0.76 0.13 60);
  --shadow: 0 1px 2px oklch(0 0 0 / 0.4), 0 14px 36px -14px oklch(0 0 0 / 0.7);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: 5rem; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16.5px/1.65 var(--sans);
  -webkit-text-size-adjust: 100%;
}
a { color: var(--accent); text-decoration-thickness: 1px; text-underline-offset: 3px; transition: color 150ms var(--ease); }
a:hover { color: var(--accent-strong); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
code, kbd, pre { font-family: var(--mono); font-size: 0.88em; }
code { background: var(--surface-2); padding: 0.12em 0.38em; border-radius: 5px; }
pre {
  background: var(--surface-2); border: 1px solid var(--border-soft);
  padding: 0.9rem 1rem; border-radius: 10px; overflow-x: auto; line-height: 1.5; margin: 0.75rem 0 0;
}
pre code { background: none; padding: 0; font-size: 0.86rem; }
kbd {
  display: inline-block; padding: 0.05em 0.45em; border: 1px solid var(--border);
  border-bottom-width: 2px; border-radius: 6px; background: var(--surface); font-size: 0.82em;
}
small { color: var(--muted); }
strong { font-weight: 650; }

/* ---------- Top bar ---------- */
.top {
  position: sticky; top: 0; z-index: var(--z-sticky);
  display: flex; align-items: center; gap: 0.75rem;
  height: 3.75rem; padding: 0 clamp(16px, 3vw, 2rem);
  background: color-mix(in oklch, var(--bg) 86%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--border-soft);
}
.brand {
  display: inline-flex; align-items: center; gap: 0.55rem;
  font: 700 1.2rem/1 var(--display); color: var(--text); text-decoration: none; letter-spacing: 0.005em;
}
.brand svg { width: 1.35rem; height: 1.35rem; flex: none; }
.brand:hover { color: var(--text); }
.toplinks { margin-left: auto; display: flex; align-items: center; gap: 0.25rem; }
.toplinks a {
  display: inline-flex; align-items: center; gap: 0.4rem;
  padding: 0.42rem 0.8rem; border-radius: 999px;
  text-decoration: none; font-weight: 550; font-size: 0.94rem; color: var(--muted); white-space: nowrap;
  transition: color 150ms var(--ease), background-color 150ms var(--ease);
}
.toplinks a:hover { color: var(--text); background: var(--surface-2); }
.toplinks a[aria-current] { color: var(--accent-strong); background: var(--accent-soft); }
.toplinks .s { display: none; }
.toplinks .gh { margin-left: 0.4rem; }
.toplinks .gh::before {
  content: ""; width: 1px; height: 1.1rem; background: var(--border); margin: 0 0.6rem 0 -0.6rem;
}
.toplinks svg, .iconbtn svg { width: 1.05rem; height: 1.05rem; flex: none; }
.iconbtn, .menu {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
  font: 550 0.94rem/1 var(--sans); color: var(--muted); background: transparent;
  border: 1px solid var(--border); border-radius: 999px; cursor: pointer;
  transition: color 150ms var(--ease), background-color 150ms var(--ease), border-color 150ms var(--ease);
}
.iconbtn { width: 2.25rem; height: 2.25rem; padding: 0; }
.iconbtn:hover, .menu:hover { color: var(--text); background: var(--surface-2); }
.menu { display: none; height: 2.25rem; padding: 0 0.9rem; }
.menu .ico { display: none; width: 1.1rem; height: 1.1rem; }
.iconbtn .sun { display: none; }
:root[data-theme="dark"] .iconbtn .sun { display: block; }
:root[data-theme="dark"] .iconbtn .moon { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .iconbtn .sun { display: block; }
  :root:not([data-theme="light"]) .iconbtn .moon { display: none; }
}

/* ---------- Layout ---------- */
.layout {
  display: grid; grid-template-columns: 12.5rem minmax(0, 1fr);
  gap: clamp(1.5rem, 4vw, 4rem);
  max-width: 78rem; margin: 0 auto; padding: 0 clamp(16px, 3vw, 2rem);
}
.toc { position: sticky; top: 3.75rem; align-self: start; padding: 2.25rem 0; max-height: calc(100vh - 3.75rem); overflow-y: auto; }
.toc-title { font: 600 0.8rem/1 var(--sans); color: var(--muted); margin: 0 0 0.75rem 0.7rem; }
.toc ol { list-style: none; margin: 0; padding: 0; display: grid; gap: 1px; }
.toc a {
  display: block; padding: 0.38rem 0.7rem; border-radius: 8px;
  color: var(--muted); text-decoration: none; font-size: 0.92rem; line-height: 1.35;
  transition: color 150ms var(--ease), background-color 150ms var(--ease);
}
.toc a:hover { color: var(--text); background: var(--surface-2); }
.toc a[aria-current] { color: var(--accent-strong); background: var(--accent-soft); font-weight: 550; }

main { padding: 2.5rem 0 5rem; min-width: 0; }
section { padding: 3.5rem 0 0.5rem; }
section + section { border-top: 1px solid var(--border-soft); margin-top: 2rem; }
section.hero { padding-top: 1rem; }

h1, h2, h3 { font-family: var(--display); font-weight: 700; line-height: 1.12; text-wrap: balance; letter-spacing: -0.005em; }
h1 { font-size: clamp(2.3rem, 5.2vw, 3.6rem); margin: 0 0 1.1rem; max-width: 22ch; }
h2 { font-size: clamp(1.7rem, 3.2vw, 2.25rem); margin: 0 0 1.1rem; }
h3 { font-size: 1.28rem; margin: 2.25rem 0 0.6rem; }
p, li { text-wrap: pretty; }
p { max-width: 70ch; margin: 0 0 1rem; }
.lede { font-size: clamp(1.1rem, 1.6vw, 1.25rem); line-height: 1.6; color: var(--muted); max-width: 60ch; }
.note { font-size: 0.92rem; color: var(--muted); }
main ol { max-width: 70ch; padding-left: 1.3rem; }
main ol li { margin: 0.4rem 0; }
main ol li::marker { color: var(--accent); font-weight: 650; }

/* ---------- Figures ---------- */
figure { margin: 1.75rem 0; }
.shot img {
  display: block; width: 100%; height: auto; border-radius: var(--radius);
  border: 1px solid var(--border); box-shadow: var(--shadow); background: var(--surface-2);
}
.shot a img { transition: transform 300ms var(--ease), box-shadow 300ms var(--ease); }
.shot a:hover img { transform: translateY(-2px); }
figcaption { font-size: 0.9rem; color: var(--muted); margin-top: 0.7rem; max-width: 72ch; }

/* ---------- Key numbers: a ledger, not a card wall ---------- */
.stats {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 9.5rem), 1fr));
  gap: 1.25rem 2rem; margin: 2.5rem 0 0; padding: 1.5rem 0 0;
  border-top: 1px solid var(--border);
}
.stats div { display: flex; flex-direction: column-reverse; justify-content: flex-end; gap: 0.35rem; }
.stats dt { font-size: 0.88rem; line-height: 1.4; color: var(--muted); }
.stats dd { margin: 0; font: 700 2.1rem/1 var(--display); color: var(--text); font-variant-numeric: tabular-nums; }

/* ---------- Component lists (overview, mod modes) ---------- */
.cards {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 17rem), 1fr));
  gap: 0 2.5rem; margin: 1.25rem 0 1.5rem;
}
.cards article { padding: 1.1rem 0 1rem; border-top: 1px solid var(--border); }
.cards h3 { margin: 0 0 0.35rem; font-size: 1.12rem; color: var(--text); }
.cards p { margin: 0; font-size: 0.95rem; color: var(--muted); }

/* ---------- Getting-started tiers (a real sequence) ---------- */
.tiers { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 17rem), 1fr)); gap: 1rem; margin: 1.25rem 0; }
.tiers article {
  display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.15rem 1.2rem 1.2rem;
}
.tiers h3 { margin: 0 0 0.4rem; font-size: 1.12rem; }
.tiers p { margin: 0; font-size: 0.93rem; color: var(--muted); }
.tiers pre { font-size: 0.8rem; margin-top: auto; }
.tiers p + pre { margin-top: 0.9rem; }
.two { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 17rem), 1fr)); gap: 0 2.5rem; }

/* ---------- Tables ---------- */
.table-wrap {
  margin: 1.5rem 0; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); overflow-x: auto; overscroll-behavior-x: contain;
}
table { width: 100%; border-collapse: collapse; font-size: 0.94rem; line-height: 1.5; }
caption {
  caption-side: top; text-align: left; padding: 0.95rem 1.1rem 0.85rem;
  font: 700 1.05rem/1.3 var(--display); color: var(--text);
  border-bottom: 1px solid var(--border);
}
th, td { padding: 0.7rem 1.1rem; text-align: left; vertical-align: top; }
td { overflow-wrap: break-word; }
tbody tr + tr > * { border-top: 1px solid var(--border-soft); }
thead th {
  background: var(--surface-2); color: var(--muted);
  font-size: 0.82rem; font-weight: 600; letter-spacing: 0.01em; white-space: nowrap;
  border-bottom: 1px solid var(--border);
}
tbody th[scope="row"] { font-weight: 650; white-space: nowrap; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tbody tr { transition: background-color 120ms var(--ease); }
tbody tr:hover { background: color-mix(in oklch, var(--surface-2) 55%, transparent); }
/* Key/value tables (no header row): the key column reads as a label. */
table.kv td:first-child { width: 28%; min-width: 9rem; color: var(--muted); font-weight: 550; }
table.kv tbody tr:hover { background: none; }

/* Small numeric tables hug their content instead of spanning the column. */
.table-wrap.fit { width: fit-content; max-width: 100%; }
.table-wrap.fit table { width: auto; min-width: min(30rem, 100%); }

/* Win-rate heatmap */
table.heatmap { min-width: 44rem; }
table.heatmap th, table.heatmap td { padding: 0.6rem 0.55rem; }
table.heatmap thead th:first-child, table.heatmap tbody th { padding-left: 1.1rem; }
table.heatmap td.heat {
  background: color-mix(in oklch, var(--accent) calc(var(--p) * 0.6%), transparent);
  font-weight: 550;
}
/* Dark theme: the light accent at full strength puts light text on a light
   cell; a weaker mix keeps every cell at 4.5:1 or better. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) table.heatmap td.heat {
    background: color-mix(in oklch, var(--accent) calc(var(--p) * 0.45%), transparent);
  }
}
:root[data-theme="dark"] table.heatmap td.heat {
  background: color-mix(in oklch, var(--accent) calc(var(--p) * 0.45%), transparent);
}
table.heatmap tbody tr + tr > * { border-top-color: var(--surface); }
table.heatmap td.pooled { font-weight: 700; padding-right: 1.1rem; border-left: 1px solid var(--border); }
table.heatmap tbody tr:hover { background: none; }

/* ---------- Lists ---------- */
ul.facts { padding-left: 1.2rem; max-width: 72ch; }
ul.facts li { margin: 0.55rem 0; padding-left: 0.2rem; }
ul.facts li::marker { color: var(--accent); }

/* ---------- Flow diagrams ---------- */
.diagram { display: flex; flex-direction: column; align-items: center; gap: 0.7rem; margin: 2rem 0; }
.diagram .lane { display: flex; gap: 1rem; justify-content: center; width: 100%; position: relative; }
.diagram .lane + .lane::before {
  content: ""; position: absolute; top: -0.7rem; left: 50%; width: 1px; height: 0.7rem; background: var(--border);
}
.diagram .box {
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  padding: 0.65rem 1rem; text-align: center; font-size: 0.93rem; line-height: 1.45; max-width: 34rem;
  box-shadow: var(--shadow);
}
.diagram .box small { display: block; margin-top: 0.15rem; font-size: 0.82rem; }
.diagram .box.game { border-color: color-mix(in oklch, var(--game) 70%, var(--border)); }
.diagram .box.rust { border-color: color-mix(in oklch, var(--rust) 70%, var(--border)); }
.diagram .box.cmp { border-color: var(--accent); background: color-mix(in oklch, var(--accent-soft) 60%, var(--surface)); }
.diagram .split .box { flex: 1 1 0; max-width: 17rem; }

/* ---------- Gallery ---------- */
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 22rem), 1fr)); gap: 1.75rem 1.5rem; margin: 1.75rem 0; }
.gallery figure { margin: 0; }
.gallery a { display: block; }
.gallery .wide { grid-column: 1 / -1; }

.foot {
  display: flex; flex-wrap: wrap; justify-content: center; gap: 0.4rem 1.25rem;
  color: var(--muted); font-size: 0.86rem; padding: 2.25rem 16px 3rem; border-top: 1px solid var(--border-soft);
}
.foot a { color: var(--muted); }
.foot a:hover { color: var(--text); }

/* ---------- Narrow screens ---------- */
@media (max-width: 900px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .menu { display: inline-flex; }
  .toplinks { gap: 0.1rem; }
  .toplinks a { padding: 0.42rem 0.6rem; }
  .toplinks .l, .toplinks .gh { display: none; }
  .toplinks .s { display: inline; }
  .toc {
    position: fixed; top: 3.75rem; left: 0; right: 0; z-index: var(--z-menu); display: none;
    max-height: calc(100vh - 3.75rem); padding: 1rem 16px 1.25rem;
    background: var(--bg); border-bottom: 1px solid var(--border); box-shadow: var(--shadow);
  }
  .toc.open { display: block; }
  section { padding-top: 2.5rem; }
  .diagram .split { flex-direction: column; align-items: center; }
  .diagram .split .box { max-width: 100%; width: 100%; }
  table.kv td:first-child { width: auto; min-width: 7rem; }
}
@media (max-width: 900px) {
  /* A caption is as wide as its scrolling table: keep its text in view. */
  .table-wrap caption {
    max-width: calc(100vw - 2 * clamp(16px, 3vw, 2rem) - 2px);
    position: sticky; left: 0;
  }
}
@media (max-width: 600px) {
  /* Four page links, the theme switch and the contents button fit a phone
     with a gutter; the brand keeps its mark (and its aria-label). */
  .brand span { display: none; }
  .top { gap: 0.6rem; }
  .toplinks a { padding: 0.42rem 0.5rem; }
  .menu { width: 2.25rem; padding: 0; }
  .menu .lbl { display: none; }
  .menu .ico { display: block; }
}
@media (max-width: 480px) {
  th, td { padding: 0.6rem 0.8rem; }
  caption { padding: 0.85rem 0.8rem 0.75rem; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { transition: none !important; }
}

/* ---------- Illustrations (inline SVG, themed via tokens) ---------- */
.fig { margin: 2rem 0; }
.fig .canvas {
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface);
  padding: clamp(0.75rem, 2vw, 1.25rem); overflow-x: auto; overscroll-behavior-x: contain;
}
.fig svg { display: block; width: 100%; height: auto; min-width: 36rem; font-family: var(--sans); }
.fig svg.narrow-ok { min-width: 0; }
.fig figcaption { margin-top: 0.7rem; }
.fig .t { fill: var(--text); font-size: 14px; }
.fig .tb { fill: var(--text); font-size: 14px; font-weight: 650; }
.fig .h { fill: var(--text); font: 700 15px var(--display); }
.fig .m { fill: var(--muted); font-size: 12.5px; }
.fig .s { fill: var(--muted); font-size: 11.5px; }
.fig .num { font-variant-numeric: tabular-nums; }
.fig .box { fill: var(--surface-2); stroke: var(--border); stroke-width: 1; }
.fig .box2 { fill: var(--surface); stroke: var(--border); stroke-width: 1; }
.fig .hot { fill: var(--accent-soft); stroke: var(--accent); stroke-width: 1.5; }
.fig .line { stroke: var(--border); stroke-width: 1.5; fill: none; }
.fig .line-m { stroke: var(--muted); stroke-width: 1.25; fill: none; }
.fig .path { stroke: var(--accent); stroke-width: 2.25; fill: none; }
.fig .dash { stroke-dasharray: 4 4; }
.fig .grid { stroke: var(--border-soft); stroke-width: 1; }
.fig .acc { fill: var(--accent); }
.fig .acc-t { fill: var(--accent-strong); }
.fig .game { fill: var(--game); }
.fig .rust { fill: var(--rust); }
.fig .mutedfill { fill: color-mix(in oklch, var(--muted) 35%, transparent); }
.fig .faint { fill: color-mix(in oklch, var(--muted) 14%, transparent); }
.fig .arrowhead { fill: var(--muted); }
.fig .arrowhead-acc { fill: var(--accent); }
.fig .sq { stroke: var(--accent); stroke-width: 2; fill: none; stroke-linecap: round; }

/* Lineage: each character's path as a row of steps */
.lineage { display: grid; gap: 1.1rem; margin: 1.5rem 0; }
.lineage .row { display: grid; grid-template-columns: 8.5rem minmax(0, 1fr); gap: 0.4rem 1rem; align-items: start; }
.lineage .who { font: 700 1.05rem/2rem var(--display); }
.lineage ol { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 0.45rem 0.3rem; max-width: none; }
.lineage li { display: inline-flex; align-items: center; gap: 0.3rem; margin: 0; }
.lineage li + li::before { content: "→"; color: var(--muted); margin-right: 0.1rem; }
.lineage .step {
  display: inline-flex; align-items: baseline; gap: 0.4rem; padding: 0.25rem 0.65rem;
  border: 1px solid var(--border); border-radius: 999px; background: var(--surface); font-size: 0.88rem; line-height: 1.4;
}
.lineage .step b { font-weight: 650; color: var(--accent-strong); font-variant-numeric: tabular-nums; }
.lineage .step.now { border-color: var(--accent); background: var(--accent-soft); }
@media (max-width: 640px) {
  .lineage .row { grid-template-columns: minmax(0, 1fr); }
  .lineage .who { line-height: 1.3; }
}

/* Embedded video: 16:9, framed like the screenshots */
.video .frame {
  position: relative; aspect-ratio: 16 / 9; border-radius: var(--radius); overflow: hidden;
  border: 1px solid var(--border); box-shadow: var(--shadow); background: oklch(0.12 0.01 265);
}
.video iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
