/* wahoo — editorial, Distill-inspired layout (shared with math-of-ai) plus a light Mushroom Kingdom layer.
   System fonts only (no downloads, strict CSP). */

/* ------------------------------------------------------------------ tokens */

:root {
  --serif: Charter, "Bitstream Charter", "Sitka Text", Cambria, Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "Cascadia Mono", "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --qmark: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 14'%3E%3Cpath d='M2.6 4.4A2.4 2.4 0 1 1 6.54 6.24C5.4 7 5 7.5 5 8.6V9' fill='none' stroke='%23000' stroke-width='2.2' stroke-linecap='round'/%3E%3Ccircle cx='5' cy='12' r='1.3'/%3E%3C/svg%3E");

  --col: 680px;
  --outdent: 150px;

  --hue: 255;
  --chroma: 0.13;

  --bg: #ffffff;
  --bg-soft: #f6f5f1;
  --bg-figure: #fafaf7;
  --fg: #16181c;
  --text: rgba(16, 18, 22, 0.86);
  --muted: #636870;
  --faint: #9a9ea5;
  --rule: #e3e1da;
  --grid: #ecebe6;
  --accent: oklch(0.5 var(--chroma) var(--hue));
  --accent-strong: oklch(0.42 var(--chroma) var(--hue));
  --accent-soft: oklch(0.965 0.022 var(--hue));
  --accent-line: oklch(0.84 0.06 var(--hue));

  /* Categorical marks shared by every demo (class A / class B / highlights). */
  --k1: #2f6db5;
  --k2: #d2553b;
  --k3: #2e8b57;
  --k4: #9a5bbf;
  --k1-soft: rgba(47, 109, 181, 0.16);
  --k2-soft: rgba(210, 85, 59, 0.16);
  --good: #2e8b57;
  --bad: #c2412d;
  --warn: #a86400;

  /* The question block, and the colours of highlighted code. */
  --block: #f4b400;
  --block-edge: #8a4b08;
  --syn-k: #c0362c;
  --syn-s: #2e7d32;
  --syn-n: #a35a00;
  --syn-t: #1565c0;
  --syn-b: #8e24aa;
  --syn-c: #868b93;
  --syn-f: #c2185b;
  --syn-o: #5d6670;
  --syn-v: #00796b;
  --syn-i: #3949ab;
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #14161a;
  --bg-soft: #1b1e23;
  --bg-figure: #191c21;
  --fg: #eef0f3;
  --text: rgba(236, 239, 243, 0.87);
  --muted: #a3a8b0;
  --faint: #6f747c;
  --rule: #2c3037;
  --grid: #23272d;
  --accent: oklch(0.78 calc(var(--chroma) * 0.85) var(--hue));
  --accent-strong: oklch(0.86 calc(var(--chroma) * 0.7) var(--hue));
  --accent-soft: oklch(0.25 0.035 var(--hue));
  --accent-line: oklch(0.42 0.06 var(--hue));
  --k1: #6ea8ec;
  --k2: #f08a6c;
  --k3: #6cc48e;
  --k4: #c592e3;
  --k1-soft: rgba(110, 168, 236, 0.2);
  --k2-soft: rgba(240, 138, 108, 0.2);
  --good: #6cc48e;
  --bad: #f07a63;
  --warn: #e0a84a;
  --block: #d99a00;
  --block-edge: #6b3a06;
  --syn-k: #ff8a7a;
  --syn-s: #8fd694;
  --syn-n: #f0b45e;
  --syn-t: #7fb6f5;
  --syn-b: #d39ef0;
  --syn-c: #7a808a;
  --syn-f: #f48fb1;
  --syn-o: #aab1ba;
  --syn-v: #6fd6c4;
  --syn-i: #a5b1f5;
  color-scheme: dark;
}

/* One hue per chapter: it tints the chain, the headings' marks, the figures and the timeline. */
.ch-execution { --hue: 27; --chroma: 0.16; }
.ch-lexing { --hue: 75; --chroma: 0.13; }
.ch-parsing { --hue: 145; --chroma: 0.13; }
.ch-semantics { --hue: 250; --chroma: 0.14; }
.ch-codegen { --hue: 300; --chroma: 0.12; }
.ch-optimization { --hue: 50; --chroma: 0.14; }
.ch-runtime { --hue: 205; --chroma: 0.12; }

/* Accent colours are recomputed wherever a chapter sets its own --hue (custom properties resolve where defined). */
[class^="ch-"], [class*=" ch-"] {
  --accent: oklch(0.5 var(--chroma) var(--hue));
  --accent-strong: oklch(0.42 var(--chroma) var(--hue));
  --accent-soft: oklch(0.965 0.022 var(--hue));
  --accent-line: oklch(0.84 0.06 var(--hue));
}
:root[data-theme="dark"] [class^="ch-"], :root[data-theme="dark"] [class*=" ch-"] {
  --accent: oklch(0.78 calc(var(--chroma) * 0.85) var(--hue));
  --accent-strong: oklch(0.86 calc(var(--chroma) * 0.7) var(--hue));
  --accent-soft: oklch(0.25 0.035 var(--hue));
  --accent-line: oklch(0.42 0.06 var(--hue));
}

/* ------------------------------------------------------------------ base */

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; scroll-padding-top: 72px; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 400 1.1875rem/1.65 var(--serif);
  font-kerning: normal;
  text-rendering: optimizeLegibility;
}

::selection { background: var(--accent-soft); color: var(--fg); }

a { color: var(--accent-strong); text-decoration-thickness: 1px; text-underline-offset: 0.18em; }
a:hover { text-decoration-thickness: 2px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 3px; }

h1, h2, h3, h4 { font-family: var(--sans); color: var(--fg); line-height: 1.2; letter-spacing: -0.01em; }

p, ul, ol { margin: 0 0 1.05em; }
li { margin: 0.2em 0; }
strong { color: var(--fg); font-weight: 650; }
hr { border: 0; border-top: 1px solid var(--rule); margin: 3rem 0; }

code, kbd {
  font-family: var(--mono);
  font-size: 0.84em;
  background: var(--bg-soft);
  border: 1px solid var(--rule);
  border-radius: 4px;
  padding: 0.05em 0.3em;
}

.tex-error { color: var(--bad); }

.sr-only {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ------------------------------------------------------------------ header and footer */

.skip { position: absolute; left: -9999px; }
.skip:focus { left: 12px; top: 8px; z-index: 50; background: var(--bg); padding: 6px 10px; }

.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  height: 54px;
  padding: 0 20px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--rule);
  font-family: var(--sans);
  font-size: 0.9rem;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  color: var(--fg);
  font-weight: 700;
  text-decoration: none;
  letter-spacing: 0.01em;
}
.brand-mark {
  display: inline-grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 6px;
  background: var(--block);
  border: 2px solid var(--block-edge);
  font: 800 16px/1 var(--sans);
  --q-size: 13px;
  --q-shadow: 1px;
}

/* The "?" on the brand mark and the hero block is drawn, not typed: a system-ui glyph sits at a different height in
   every font, so it never looked centred. The text stays in the markup (transparent) and keeps the box's baseline. */
.brand-mark, .hero-block { position: relative; color: transparent; text-shadow: none; user-select: none; }
.brand-mark::before, .brand-mark::after, .hero-block::before, .hero-block::after {
  content: "";
  position: absolute;
  inset: 0;
  -webkit-mask: var(--qmark) center / auto var(--q-size) no-repeat;
  mask: var(--qmark) center / auto var(--q-size) no-repeat;
}
.brand-mark::before, .hero-block::before { background: var(--block-edge); translate: var(--q-shadow) var(--q-shadow); }
.brand-mark::after, .hero-block::after { background: #fff; }

.site-nav { display: flex; align-items: center; gap: 6px; }
.site-nav > a, .chapters-menu > summary {
  color: var(--muted);
  text-decoration: none;
  padding: 6px 10px;
  border-radius: 6px;
  cursor: pointer;
}
.site-nav > a:hover, .chapters-menu > summary:hover, .site-nav > a[aria-current] { color: var(--fg); background: var(--bg-soft); }

.chapters-menu { position: relative; }
.chapters-menu > summary { list-style: none; }
.chapters-menu > summary::-webkit-details-marker { display: none; }
.chapters-menu > summary::after { content: " ▾"; font-size: 0.8em; }
.chapters-menu ol {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  width: min(320px, 86vw);
  margin: 0;
  padding: 6px;
  list-style: none;
  background: var(--bg);
  border: 1px solid var(--rule);
  border-radius: 10px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.14);
}
.chapters-menu li { margin: 0; }
.chapters-menu li a {
  display: flex;
  gap: 10px;
  padding: 7px 10px;
  border-radius: 6px;
  color: var(--text);
  text-decoration: none;
}
.chapters-menu li a:hover, .chapters-menu li a[aria-current] { background: var(--accent-soft); color: var(--fg); }
.chapters-menu .num { font-family: var(--mono); color: var(--accent); font-size: 0.85em; padding-top: 1px; }

.langs { display: flex; gap: 2px; }
.langs a { color: var(--muted); text-decoration: none; font-size: 0.8rem; padding: 4px 6px; border-radius: 5px; }
.langs a[aria-current] { color: var(--fg); background: var(--bg-soft); }

.theme-toggle {
  display: inline-grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 1px solid var(--rule);
  border-radius: 8px;
  background: transparent;
  color: var(--fg);
  cursor: pointer;
}
.theme-icon {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid currentColor;
  background: linear-gradient(90deg, currentColor 50%, transparent 50%);
}

.site-footer {
  max-width: calc(var(--col) + 40px);
  margin: 5rem auto 0;
  padding: 24px 20px 48px;
  border-top: 1px solid var(--rule);
  color: var(--muted);
  font: 0.85rem/1.6 var(--sans);
}
.site-footer p { margin: 0 0 0.4em; }
.site-footer a { color: var(--muted); }

/* ------------------------------------------------------------------ layout */

main { display: block; }

.chapter-head, .prose, .page-head, .home, .timeline > * {
  max-width: calc(var(--col) + 40px);
  margin-left: auto;
  margin-right: auto;
  padding-left: 20px;
  padding-right: 20px;
}
.prose { counter-reset: figure; }
.prose::after { content: ""; display: block; clear: both; }

.prose h2 {
  position: relative;
  font-size: 1.65rem;
  margin: 3.2rem 0 1rem;
  padding-top: 1.4rem;
  border-top: 1px solid var(--rule);
}
.prose h3 { font-size: 1.2rem; margin: 2.2rem 0 0.7rem; }
.prose h4 { font-size: 1rem; margin: 1.6rem 0 0.5rem; }
.anchor {
  position: absolute;
  left: -1.1em;
  color: var(--faint);
  text-decoration: none;
  font-weight: 400;
  opacity: 0;
  transition: opacity 0.15s;
}
.prose h2:hover .anchor, .anchor:focus { opacity: 1; }

.prose > p:first-child::first-letter {
  float: left;
  font-size: 3.4em;
  line-height: 0.9;
  padding: 0.06em 0.08em 0 0;
  color: var(--accent);
  font-family: var(--serif);
}

blockquote {
  margin: 1.6em 0;
  padding: 0 0 0 1.2em;
  border-left: 3px solid var(--rule);
  color: var(--muted);
  font-style: italic;
}
blockquote cite { display: block; margin-top: 0.4em; font: normal 0.8rem var(--sans); }

/* Margin notes: in the right gutter on wide screens, inline callouts otherwise. */
.note {
  font: 0.86rem/1.55 var(--sans);
  color: var(--muted);
  margin: 1.2em 0;
  padding: 10px 14px;
  border-left: 2px solid var(--accent-line);
  background: var(--bg-soft);
  border-radius: 0 6px 6px 0;
}
.note strong { color: var(--text); }
@media (min-width: 1180px) {
  .note {
    float: right;
    clear: right;
    width: 220px;
    margin: 0.3em -260px 1em 0;
    padding: 0 0 0 12px;
    background: none;
    border-radius: 0;
  }
}

/* Wider-than-text elements. */
@media (min-width: 1040px) {
  .wide { margin-left: calc(-1 * var(--outdent)); margin-right: calc(-1 * var(--outdent)); }
}

/* ------------------------------------------------------------------ chapter head */

.chapter-head { padding-top: 2.2rem; }

.kicker {
  font: 700 0.78rem/1.4 var(--sans);
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--accent);
  margin: 2rem 0 0.6rem;
}
.chapter-head h1, .page-head h1 {
  font-size: clamp(2.2rem, 5.2vw, 3.3rem);
  font-weight: 750;
  letter-spacing: -0.025em;
  margin: 0 0 0.9rem;
}
.dek { font-size: 1.32rem; line-height: 1.5; color: var(--muted); margin-bottom: 1.8rem; }

.byline {
  display: grid;
  grid-template-columns: 1fr 2fr;
  gap: 14px 28px;
  margin: 0 0 1.6rem;
  padding: 14px 0;
  border-top: 1px solid var(--rule);
  border-bottom: 1px solid var(--rule);
  font: 0.86rem/1.5 var(--sans);
}
.byline .wide { grid-column: 1 / -1; margin: 0; }
.byline dt { color: var(--faint); text-transform: uppercase; letter-spacing: 0.07em; font-size: 0.72rem; margin-bottom: 3px; }
.byline dd { margin: 0; color: var(--text); }
.byline ul { margin: 0; padding: 0; list-style: none; display: flex; flex-wrap: wrap; gap: 6px; }
.byline li {
  margin: 0;
  padding: 2px 9px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.toc { font: 0.9rem/1.5 var(--sans); margin-bottom: 1rem; }
.toc-title { font-weight: 700; color: var(--fg); margin: 0 0 0.4rem; }
.toc ol { columns: 2; column-gap: 28px; margin: 0; padding-left: 1.3em; color: var(--faint); }
.toc li { break-inside: avoid; }
.toc a { color: var(--muted); text-decoration: none; }
.toc a:hover { color: var(--accent-strong); text-decoration: underline; }

/* Compact chain: where this chapter sits on the way from source text to a running program. */
.chain-compact {
  display: flex;
  margin: 0;
  padding: 0 0 4px;
  list-style: none;
  overflow-x: auto;
  scrollbar-width: none;
}
.chain-compact li { flex: 1 0 auto; min-width: 58px; margin: 0; position: relative; }
.chain-compact li::before {
  content: "";
  position: absolute;
  top: 6px;
  left: 0;
  right: 0;
  height: 2px;
  background: var(--rule);
}
.chain-compact li:first-child::before { left: 50%; }
.chain-compact li:last-child::before { right: 50%; }
.chain-compact a {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  text-decoration: none;
  color: var(--faint);
  font: 600 0.62rem/1.2 var(--sans);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  text-align: center;
  padding: 0 4px;
}
.chain-compact .dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--bg);
  border: 2px solid var(--accent-line);
}
.chain-compact a:hover { color: var(--accent-strong); }
.chain-compact a:hover .dot { background: var(--accent-soft); border-color: var(--accent); }
.chain-compact a[aria-current] { color: var(--accent-strong); }
.chain-compact a[aria-current] .dot { background: var(--accent); border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
@media (max-width: 600px) {
  .chain-compact .lbl { display: none; }
  .chain-compact li { min-width: 28px; }
}

/* ------------------------------------------------------------------ theorem, definition, proof */

.theorem, .definition, .idea {
  margin: 1.8em 0;
  padding: 14px 20px 6px;
  border-left: 3px solid var(--accent);
  background: var(--accent-soft);
  border-radius: 0 8px 8px 0;
}
.definition { border-left-color: var(--faint); background: var(--bg-soft); }
.idea { border-left-color: var(--k3); background: var(--bg-soft); }
.th-title {
  display: block;
  font: 700 0.76rem/1.4 var(--sans);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent-strong);
  margin-bottom: 0.45em;
}
.definition .th-title { color: var(--muted); }
.idea .th-title { color: var(--k3); }
.th-title .th-name { text-transform: none; letter-spacing: 0; font-weight: 600; color: var(--fg); }

details.proof {
  margin: 0.6em 0 1em;
  font-size: 0.97em;
}
details.proof > summary {
  cursor: pointer;
  font: 600 0.82rem/1.4 var(--sans);
  color: var(--accent-strong);
  list-style: none;
}
details.proof > summary::-webkit-details-marker { display: none; }
details.proof > summary::before { content: "▸ "; }
details.proof[open] > summary::before { content: "▾ "; }
details.proof > div { padding: 0.6em 0 0.2em; }
details.proof > div::after { content: "∎"; display: block; text-align: right; color: var(--muted); }

/* ------------------------------------------------------------------ figures and demos */

figure { margin: 2.4em 0; }
figure.demo {
  counter-increment: figure;
  padding: 18px 18px 14px;
  background: var(--bg-figure);
  border: 1px solid var(--rule);
  border-radius: 10px;
  clear: both;
}
figcaption {
  margin-top: 14px;
  font: 0.86rem/1.55 var(--sans);
  color: var(--muted);
}
figure.demo figcaption::before {
  content: "Fig. " counter(figure) " · ";
  font-weight: 700;
  color: var(--accent-strong);
}
@media (max-width: 720px) {
  figure.demo { margin-left: -20px; margin-right: -20px; border-radius: 0; border-left: 0; border-right: 0; padding: 16px 14px 12px; }
}

.demo-stage { font: 0.9rem/1.45 var(--sans); color: var(--text); }
.demo-canvas { display: block; width: 100%; touch-action: none; border-radius: 6px; }
.demo-svg { display: block; width: 100%; height: auto; overflow: visible; }
.demo-error { color: var(--bad); font: 0.9rem var(--sans); }
.js [data-demo]:not([data-ready]):not([data-error]) .demo-stage:empty { min-height: 120px; }
html:not(.js):lang(es) figure.demo::after { content: "Esta figura es interactiva y necesita JavaScript."; }
html:not(.js) figure.demo::after {
  content: "This figure is interactive and needs JavaScript.";
  display: block;
  font: 0.85rem var(--sans);
  color: var(--muted);
}

.demo-title { font: 700 0.95rem/1.3 var(--sans); color: var(--fg); margin: 0 0 10px; }
.demo-hint { font-size: 0.82rem; color: var(--muted); margin: 6px 0 0; }

.controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 18px;
  margin: 12px 0 4px;
}
.ctl { display: flex; align-items: center; gap: 8px; font: 0.84rem/1.3 var(--sans); }
.ctl label, .ctl-label { color: var(--muted); white-space: nowrap; }
.ctl-slider { flex: 1 1 210px; min-width: 190px; }
.ctl-slider.ctl-wide { flex-basis: 100%; }
.ctl-slider input { flex: 1; min-width: 70px; accent-color: var(--accent); }
.ctl output { font-family: var(--mono); font-size: 0.8rem; color: var(--fg); min-width: 4.4em; text-align: right; }
.ctl select {
  font: inherit;
  color: var(--fg);
  background: var(--bg);
  border: 1px solid var(--rule);
  border-radius: 6px;
  padding: 4px 6px;
}
.ctl-toggle input { accent-color: var(--accent); width: 16px; height: 16px; margin: 0; }

.btn {
  font: 600 0.82rem/1 var(--sans);
  color: var(--fg);
  background: var(--bg);
  border: 1px solid var(--rule);
  border-radius: 7px;
  padding: 8px 12px;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { border-color: var(--accent-line); background: var(--accent-soft); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--bg); }
.btn.primary:hover { background: var(--accent-strong); }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; }

.seg-group { display: inline-flex; border: 1px solid var(--rule); border-radius: 7px; overflow: hidden; }
.seg {
  font: 600 0.78rem/1 var(--sans);
  color: var(--muted);
  background: var(--bg);
  border: 0;
  border-right: 1px solid var(--rule);
  padding: 7px 10px;
  cursor: pointer;
}
.seg:last-child { border-right: 0; }
.seg[aria-pressed="true"] { background: var(--accent); color: var(--bg); }

.stats { display: flex; flex-wrap: wrap; gap: 8px 24px; margin: 10px 0 2px; }
.stat { display: flex; flex-direction: column; min-width: 80px; }
.stat-label { font: 600 0.74rem/1.3 var(--sans); color: var(--faint); }
.stat-val { font: 500 1.05rem/1.35 var(--mono); color: var(--fg); }
.stat.good .stat-val { color: var(--good); }
.stat.bad .stat-val { color: var(--bad); }
.stat.accent .stat-val { color: var(--accent-strong); }

.panel-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.panel-grid > * { min-width: 0; }
@media (max-width: 640px) { .panel-grid { grid-template-columns: 1fr; } }
.panel-label { font: 600 0.8rem/1.3 var(--sans); color: var(--muted); margin: 0 0 6px; }

/* SVG chart vocabulary used by the demos. */
.demo-svg text { font: 11px var(--sans); fill: var(--muted); }
.demo-svg .axis line, .demo-svg .axis path, .demo-svg line.axis { stroke: var(--faint); stroke-width: 1; }
.demo-svg .gridline { stroke: var(--grid); stroke-width: 1; }
.demo-svg .curve { fill: none; stroke: var(--accent); stroke-width: 2.2; }
.demo-svg .curve-2 { fill: none; stroke: var(--k2); stroke-width: 2; }
.demo-svg .curve-muted { fill: none; stroke: var(--faint); stroke-width: 1.5; stroke-dasharray: 4 4; }
.demo-svg .area { fill: var(--accent-soft); }
.demo-svg .bar { fill: var(--accent); }
.demo-svg .bar-soft { fill: var(--accent-line); }
.demo-svg .bar-2 { fill: var(--k2); }
.demo-svg .pt-a { fill: var(--k1); }
.demo-svg .pt-b { fill: var(--k2); }
.demo-svg .label-strong { fill: var(--fg); font-weight: 600; }
.demo-svg .mono { font-family: var(--mono); }

/* ------------------------------------------------------------------ prev / next */

.prev-next {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  max-width: calc(var(--col) + 40px);
  margin: 4rem auto 0;
  padding: 0 20px;
}
.pn-card {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 16px 18px;
  border: 1px solid var(--rule);
  border-radius: 10px;
  text-decoration: none;
  font-family: var(--sans);
  color: var(--text);
}
.pn-card:hover { border-color: var(--accent-line); background: var(--accent-soft); }
.pn-card.next { text-align: right; }
.pn-card.empty { border: 0; }
.pn-label { font-size: 0.72rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--faint); }
.pn-title { font-weight: 700; color: var(--accent-strong); }
.pn-dek { font-size: 0.86rem; color: var(--muted); }
@media (max-width: 560px) { .prev-next { grid-template-columns: 1fr; } .pn-card.next { text-align: left; } }

/* ------------------------------------------------------------------ references */

.references { font: 0.86rem/1.55 var(--sans); color: var(--muted); }
.references ol { padding-left: 1.4em; }
.references li { margin-bottom: 0.5em; }
.references h2 { font-size: 1.2rem; }

/* ------------------------------------------------------------------ home */

.home { padding-top: 3rem; }
.home figure.demo { margin-left: 0; margin-right: 0; }
.hero-title {
  font-size: clamp(2.5rem, 7vw, 4.4rem);
  font-weight: 780;
  letter-spacing: -0.035em;
  line-height: 1.02;
  margin: 0.3rem 0 1.2rem;
}
.home .lead { font-size: 1.38rem; line-height: 1.5; color: var(--muted); }
.home h2 { font-size: 1.65rem; margin: 3.6rem 0 1rem; padding-top: 1.4rem; border-top: 1px solid var(--rule); }
.home .kicker { --hue: 340; }

.chain { list-style: none; margin: 1.6rem 0; padding: 0; position: relative; }
.chain::before {
  content: "";
  position: absolute;
  left: 23px;
  top: 24px;
  bottom: 24px;
  width: 2px;
  background: linear-gradient(var(--rule), var(--rule));
}
.chain > li { margin: 0 0 12px; position: relative; }
.chain-card {
  display: flex;
  gap: 18px;
  padding: 14px 16px 14px 0;
  text-decoration: none;
  color: var(--text);
  border-radius: 10px;
}
.chain-card:hover { background: var(--accent-soft); }
.chain-num {
  position: relative;
  flex: 0 0 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--bg);
  border: 2px solid var(--accent);
  color: var(--accent-strong);
  font: 700 0.95rem var(--mono);
}
.chain-card:hover .chain-num { background: var(--accent); color: var(--bg); }
.chain-body { display: flex; flex-direction: column; gap: 3px; padding-top: 2px; }
.chain-tag { font: 700 0.72rem/1.3 var(--sans); letter-spacing: 0.09em; text-transform: uppercase; color: var(--accent); }
.chain-era { color: var(--faint); font-weight: 600; letter-spacing: 0.02em; margin-left: 6px; }
.chain-title { font: 700 1.2rem/1.3 var(--sans); color: var(--fg); }
.chain-dek { font-size: 1rem; line-height: 1.5; color: var(--muted); }
.chain-theorems { list-style: none; margin: 6px 0 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; font: 0.76rem/1.4 var(--sans); }
.chain-theorems li { margin: 0; padding: 2px 8px; border: 1px solid var(--accent-line); border-radius: 999px; color: var(--accent-strong); }

.cta-row { display: flex; flex-wrap: wrap; gap: 10px; margin: 1.6rem 0; font-family: var(--sans); }
.cta {
  display: inline-block;
  padding: 10px 16px;
  border-radius: 8px;
  border: 1px solid var(--rule);
  text-decoration: none;
  font-weight: 650;
  font-size: 0.95rem;
  color: var(--fg);
}
.cta.primary { background: var(--fg); color: var(--bg); border-color: var(--fg); }
.cta:hover { border-color: var(--faint); }

.home figure.demo { counter-increment: none; }
.home figure.demo figcaption::before { content: none; }

/* ------------------------------------------------------------------ timeline */

.timeline .page-head { padding-top: 3rem; }
.timeline-filter {
  position: sticky;
  top: 54px;
  z-index: 10;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding-top: 10px !important;
  padding-bottom: 10px !important;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--rule);
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font: 600 0.72rem/1 var(--sans);
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
  background: var(--bg);
  border: 1px solid var(--rule);
  border-radius: 999px;
  padding: 6px 10px;
  cursor: pointer;
}
.chip .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }
.chip[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent-strong); border-color: var(--accent-line); }
.chip[data-filter="all"][aria-pressed="true"] { background: var(--fg); color: var(--bg); border-color: var(--fg); }

.era { margin: 2.6rem 0 0; }
.era-head { margin-bottom: 1rem; }
.era-years { font: 700 0.75rem var(--mono); color: var(--faint); margin: 0; }
.era-head h2 { font-size: 1.5rem; margin: 0.2rem 0 0.5rem; }
.era-head p { color: var(--muted); font-size: 1.02rem; }

.events { list-style: none; margin: 0; padding: 4px 0; position: relative; }
.events::before { content: ""; position: absolute; left: 76px; top: 0; bottom: 0; width: 2px; background: var(--rule); }
.event { display: grid; grid-template-columns: 64px 1fr; gap: 26px; margin: 0; padding: 12px 10px 12px 0; position: relative; }
.event::before {
  content: "";
  position: absolute;
  left: 71px;
  top: 19px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--bg);
  border: 3px solid var(--accent);
}
.event.ch-none::before { border-color: var(--faint); }
.event.ev-milestone::before { background: var(--accent); }
.ev-year { font: 700 0.95rem/1.5 var(--mono); color: var(--accent-strong); text-align: right; padding-top: 6px; }
.event.ch-none .ev-year { color: var(--muted); }
.ev-body h3 { font-size: 1.08rem; margin: 0.25rem 0 0.15rem; }
.ev-who { font: 0.8rem var(--sans); color: var(--faint); margin: 0 0 0.35rem; }
.ev-body p { font-size: 1rem; margin-bottom: 0.4rem; }
.ev-link { font: 600 0.8rem var(--sans); text-decoration: none; }
.event[hidden] { display: none; }
.era.empty { display: none; }
@media (max-width: 560px) {
  .event { grid-template-columns: 46px 1fr; gap: 20px; }
  .events::before { left: 56px; }
  .event::before { left: 51px; }
  .ev-year { font-size: 0.82rem; }
}
/* Code listings in the prose. */
pre.code-block {
  font: 0.84rem/1.55 var(--mono);
  color: var(--fg);
  background: var(--bg-soft);
  border: 1px solid var(--rule);
  border-radius: 8px;
  padding: 12px 14px;
  overflow-x: auto;
  margin: 0 0 1.2em;
}
pre.code-block code { background: none; border: 0; padding: 0; font-size: 1em; }

/* ------------------------------------------------------------------ highlighted code (build time and editor) */

pre.code-block { tab-size: 2; }
.lang-wat { font-size: 0.8rem; }
.k { color: var(--syn-k); font-weight: 650; }
.s { color: var(--syn-s); }
.n { color: var(--syn-n); }
.t { color: var(--syn-t); }
.b { color: var(--syn-b); font-weight: 650; }
.c { color: var(--syn-c); font-style: italic; }
.f { color: var(--syn-f); font-weight: 650; }
.o { color: var(--syn-o); }
.v { color: var(--syn-v); }
.i { color: var(--syn-i); }

/* Two columns of code side by side (source and what the compiler makes of it). */
.code-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin: 0 0 1.2em; }
.code-pair > * { min-width: 0; }
.code-pair pre.code-block { margin: 0; height: 100%; }
@media (max-width: 760px) { .code-pair { grid-template-columns: 1fr; } }
@media (min-width: 1040px) { .code-pair.wide { margin-left: calc(-1 * var(--outdent) / 2); margin-right: calc(-1 * var(--outdent) / 2); } }

/* ------------------------------------------------------------------ editor */

.editor {
  display: grid;
  grid-template-columns: auto 1fr;
  border: 1px solid var(--rule);
  border-radius: 8px;
  background: var(--bg);
  overflow: hidden;
  font: 0.86rem/1.55 var(--mono);
  height: 360px;
}
.editor-small { height: 190px; }
.editor:focus-within { border-color: var(--accent-line); box-shadow: 0 0 0 3px var(--accent-soft); }
.ed-gutter {
  overflow: hidden;
  padding: 10px 8px 10px 10px;
  background: var(--bg-soft);
  border-right: 1px solid var(--rule);
  color: var(--faint);
  text-align: right;
  user-select: none;
}
.ed-gutter .ln { display: block; min-width: 2ch; }
.ed-gutter .ln.err { color: var(--bad); font-weight: 700; }
.ed-gutter .ln.err::before { content: "● "; font-size: 0.7em; vertical-align: 1px; }
.ed-gutter .ln.warn { color: var(--warn); font-weight: 700; }
.ed-body { position: relative; min-width: 0; }
.ed-hl, .ed-input {
  position: absolute;
  inset: 0;
  margin: 0;
  padding: 10px 12px;
  font: inherit;
  white-space: pre;
  tab-size: 2;
  overflow: auto;
  border: 0;
}
.ed-hl { color: var(--fg); pointer-events: none; overflow: hidden; }
.ed-hl code { font: inherit; background: none; border: 0; padding: 0; }
.ed-input {
  resize: none;
  color: transparent;
  background: transparent;
  caret-color: var(--fg);
  outline: none;
}
.ed-input::selection { background: color-mix(in srgb, var(--accent) 28%, transparent); color: transparent; }

/* ------------------------------------------------------------------ diagnostics */

.diags { list-style: none; margin: 10px 0 0; padding: 0; font: 0.84rem/1.45 var(--sans); }
.diag {
  display: grid;
  grid-template-columns: auto auto 1fr;
  gap: 2px 10px;
  margin: 0 0 8px;
  padding: 8px 12px;
  border-left: 3px solid var(--bad);
  background: var(--bg-soft);
  border-radius: 0 6px 6px 0;
  cursor: pointer;
}
.diag-warning { border-left-color: var(--warn); }
.diag-code { font: 700 0.76rem var(--mono); color: var(--bad); padding-top: 2px; }
.diag-warning .diag-code { color: var(--warn); }
.diag-where { font: 0.76rem var(--mono); color: var(--faint); padding-top: 2px; }
.diag-title { color: var(--fg); font-weight: 600; }
.diag-label, .diag-hint { grid-column: 3; color: var(--muted); }
.diag-label { font-style: italic; }
.diag-hint::before { content: "→ "; color: var(--accent); }
.compile-ok { font: 600 0.84rem var(--sans); color: var(--good); margin: 10px 0 0; }

/* ------------------------------------------------------------------ tokens */

.tok-stream { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px 4px; }
.tok {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  margin: 0;
  padding: 3px 7px 2px;
  border-radius: 6px;
  border: 1px solid var(--rule);
  background: var(--bg);
}
.tok-text { font: 0.84rem/1.3 var(--mono); color: var(--fg); white-space: pre; }
.tok-class { font: 600 0.58rem/1.2 var(--sans); letter-spacing: 0.06em; text-transform: uppercase; color: var(--faint); }
.tok-keyword { border-color: color-mix(in srgb, var(--syn-k) 45%, transparent); }
.tok-keyword .tok-text { color: var(--syn-k); font-weight: 650; }
.tok-number { border-color: color-mix(in srgb, var(--syn-n) 45%, transparent); }
.tok-number .tok-text { color: var(--syn-n); }
.tok-symbol .tok-text { color: var(--syn-o); }
li.tok-text { border-color: color-mix(in srgb, var(--syn-s) 45%, transparent); }
li.tok-text .tok-text { color: var(--syn-s); }
.tok-eof { border-style: dashed; }
.tok-break { flex-basis: 100%; height: 0; margin: 0; }

/* ------------------------------------------------------------------ syntax trees */

.ast-scroll { overflow: auto; max-height: 520px; padding: 4px; }
.ast-svg { display: block; font: 12px var(--mono); }
.ast-edges line { stroke: var(--faint); stroke-width: 1.2; }
.ast-node rect { fill: var(--bg); stroke: var(--rule); stroke-width: 1.2; }
.ast-node text { fill: var(--fg); }
.ast-root rect, .ast-item rect { fill: var(--fg); stroke: var(--fg); }
.ast-root text, .ast-item text { fill: var(--bg); font-weight: 700; }
.ast-stmt rect { fill: var(--accent-soft); stroke: var(--accent-line); }
.ast-stmt text { fill: var(--accent-strong); font-weight: 650; }
.ast-block rect { fill: none; stroke-dasharray: 3 3; }
.ast-block text { fill: var(--muted); }
.ast-op rect { fill: color-mix(in srgb, var(--syn-o) 12%, var(--bg)); }
.ast-lit text { fill: var(--syn-n); }
.ast-name text { fill: var(--syn-t); }
.ast-call text { fill: var(--syn-f); font-weight: 650; }
.ast-node:hover rect { stroke: var(--accent); stroke-width: 2; }

/* ------------------------------------------------------------------ bytes */

.hex-legend { width: 100%; border-collapse: collapse; font: 0.8rem/1.4 var(--sans); margin: 8px 0 12px; }
.hex-legend th { text-align: left; color: var(--faint); font-weight: 600; border-bottom: 1px solid var(--rule); padding: 4px 6px; }
.hex-legend td { padding: 3px 6px; border-bottom: 1px solid var(--grid); }
.hex-legend td.num { font-family: var(--mono); white-space: nowrap; }
.hx-swatch { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; background: var(--hx); }
.hex-dump { font: 0.78rem/1.6 var(--mono); overflow-x: auto; }
.hex-row { display: flex; white-space: nowrap; }
.hex-off { color: var(--faint); width: 5ch; flex: none; }
.hx { display: inline-block; width: 2.6ch; text-align: center; background: color-mix(in srgb, var(--hx) 22%, transparent); color: var(--fg); }
.hx-start { box-shadow: inset 2px 0 0 var(--hx); font-weight: 700; }
.hex-ascii { color: var(--faint); margin-left: 1.5ch; }
.hx-header { --hx: #8a8f98; }
.hx-type { --hx: #e0794f; }
.hx-import { --hx: #d4a72c; }
.hx-function { --hx: #8fb339; }
.hx-memory { --hx: #3fa796; }
.hx-export { --hx: #4b8fd8; }
.hx-code { --hx: #8b6bd6; }
.hx-data { --hx: #d45b9a; }
.hx-custom { --hx: #9aa0a8; }

/* ------------------------------------------------------------------ running */

.run-output {
  margin: 0;
  min-height: 3em;
  max-height: 320px;
  overflow: auto;
  padding: 10px 12px;
  background: #15171b;
  color: #e9edf2;
  border-radius: 8px;
  font: 0.86rem/1.5 var(--mono);
  white-space: pre-wrap;
}
.run-trap, .run-done { font: 600 0.84rem/1.4 var(--sans); margin: 8px 0 0; }
.run-trap { color: var(--bad); }
.run-done { color: var(--good); }

/* ------------------------------------------------------------------ playground */

.page-playground .page-head, .page-playground .prose { max-width: 1240px; }
.page-playground .prose > p:first-child::first-letter { float: none; font-size: inherit; padding: 0; color: inherit; }
.pg { font: 0.9rem/1.45 var(--sans); }
.pg-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; margin-bottom: 10px; }
.pg-bar .spacer { flex: 1; }
.pg-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; align-items: start; }
@media (max-width: 900px) { .pg-grid { grid-template-columns: 1fr; } }
.pg .editor { height: 460px; }
.pg-summary { font: 600 0.84rem var(--sans); margin: 10px 0 0; }
.pg-summary.ok { color: var(--good); }
.pg-summary.bad { color: var(--bad); }
.tabs { display: flex; flex-wrap: wrap; gap: 2px; border-bottom: 1px solid var(--rule); margin-bottom: 10px; }
.tab {
  font: 600 0.8rem/1 var(--sans);
  color: var(--muted);
  background: none;
  border: 0;
  border-bottom: 2px solid transparent;
  padding: 9px 12px;
  cursor: pointer;
}
.tab[aria-selected="true"] { color: var(--accent-strong); border-bottom-color: var(--accent); }
.tab-panel { min-height: 200px; }
.tab-panel pre.code-block { max-height: 520px; overflow: auto; }
.pg-note { font-size: 0.8rem; color: var(--muted); }

/* ------------------------------------------------------------------ chapter demos */

/* Execution: one row of boxes per stage, from source to the CPU. */
.pipe-flow { display: flex; flex-wrap: wrap; align-items: stretch; margin: 14px 0 6px; }
.pipe-step {
  position: relative;
  flex: 1 1 120px;
  min-width: 110px;
  margin: 0 18px 10px 0;
  padding: 9px 10px;
  border-radius: 8px;
  border: 1px solid var(--rule);
  background: var(--bg);
  font: 0.8rem/1.35 var(--sans);
}
.pipe-step::after {
  content: "→";
  position: absolute;
  right: -15px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--faint);
  font-weight: 700;
}
.pipe-step:last-child::after { content: none; }
.pipe-step strong { display: block; color: var(--fg); font-size: 0.84rem; }
.pipe-step .when { display: block; font: 600 0.62rem/1.4 var(--sans); letter-spacing: 0.07em; text-transform: uppercase; margin-top: 4px; }
.pipe-step.at-build { border-color: var(--accent-line); background: var(--accent-soft); }
.pipe-step.at-build .when { color: var(--accent-strong); }
.pipe-step.at-run { border-style: dashed; }
.pipe-step.at-run .when { color: var(--k1); }
.pipe-step.hw { background: var(--fg); border-color: var(--fg); color: var(--bg); }
.pipe-step.hw strong { color: var(--bg); }
.pipe-step.hw .when { color: var(--bg); opacity: 0.7; }
.lang-picker { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 6px; }
.lang-picker .chip[aria-pressed="true"] { background: var(--accent); color: var(--bg); border-color: var(--accent); }
.pipe-note { font: 0.86rem/1.5 var(--sans); color: var(--muted); margin: 6px 0 0; }

.compare-wrap { overflow-x: auto; margin: 1.6em 0; }
table.compare { width: 100%; border-collapse: collapse; font: 0.8rem/1.4 var(--sans); }
table.compare th, table.compare td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--rule); vertical-align: top; }
table.compare th { color: var(--faint); font-weight: 600; font-size: 0.72rem; letter-spacing: 0.05em; text-transform: uppercase; }
table.compare td:first-child { font-weight: 700; color: var(--fg); white-space: nowrap; }
.pill { display: inline-block; padding: 1px 7px; border-radius: 999px; font-size: 0.72rem; font-weight: 600; white-space: nowrap; }
.pill-aot { background: color-mix(in srgb, var(--k2) 18%, transparent); color: var(--k2); }
.pill-vm { background: color-mix(in srgb, var(--k1) 18%, transparent); color: var(--k1); }
.pill-jit { background: color-mix(in srgb, var(--k4) 18%, transparent); color: var(--k4); }
.pill-interp { background: color-mix(in srgb, var(--k3) 18%, transparent); color: var(--k3); }
.pill-trans { background: var(--bg-soft); color: var(--muted); border: 1px solid var(--rule); }

/* Code generation: the operand stack while a stack machine runs. */
.sm { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); gap: 16px; }
@media (max-width: 640px) { .sm { grid-template-columns: 1fr; } }
.sm-code { list-style: none; margin: 0; padding: 6px 0; font: 0.82rem/1.6 var(--mono); background: var(--bg); border: 1px solid var(--rule); border-radius: 8px; max-height: 320px; overflow: auto; }
.sm-code li { margin: 0; padding: 0 12px; white-space: pre; }
.sm-code li.pc { background: var(--accent-soft); box-shadow: inset 3px 0 0 var(--accent); }
.sm-code li.done { color: var(--faint); }
.sm-stack { display: flex; flex-direction: column-reverse; gap: 4px; min-height: 180px; padding: 8px; border: 1px dashed var(--rule); border-radius: 8px; }
.sm-cell { padding: 5px 10px; border-radius: 6px; background: var(--accent-soft); border: 1px solid var(--accent-line); font: 600 0.9rem var(--mono); color: var(--accent-strong); text-align: center; }
.sm-cell.new { background: var(--accent); color: var(--bg); }
.sm-empty { color: var(--faint); font-size: 0.8rem; text-align: center; margin: auto; }
.sm-vars { display: flex; flex-wrap: wrap; gap: 10px; margin: 8px 0; }
.sm-vars label { font: 0.84rem var(--mono); display: flex; align-items: center; gap: 6px; }
.sm-vars input { width: 5em; font: inherit; padding: 3px 6px; border: 1px solid var(--rule); border-radius: 5px; background: var(--bg); color: var(--fg); }
.expr-input {
  width: 100%;
  font: 0.95rem var(--mono);
  padding: 8px 10px;
  border: 1px solid var(--rule);
  border-radius: 7px;
  background: var(--bg);
  color: var(--fg);
}
.expr-input:focus { outline: none; border-color: var(--accent-line); box-shadow: 0 0 0 3px var(--accent-soft); }
.expr-input.bad { border-color: var(--bad); }

/* Inference rules in the prose: premises over a line, conclusion under it. */
.rules { margin: 1.4em 0; text-align: center; }
.rule {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  margin: 0.4em 1.2em 0.8em;
  font: 0.86rem/1.5 var(--mono);
  color: var(--fg);
  vertical-align: top;
}
.rule .premises { padding: 0 0.8em 0.25em; }
.rule .conclusion { padding: 0.25em 0.8em 0; border-top: 1.5px solid var(--fg); }
.rule-name { font: 600 0.72rem var(--sans); color: var(--accent-strong); }

/* ------------------------------------------------------------------ the Mushroom Kingdom layer */
/* Kept light: a question-block mark, a row of bricks under the header, a coin trail on the home page and
   chapter numbers that look like little blocks. No game art: everything here is drawn with CSS. */

:root { --brick: #b5532a; --brick-mortar: #e9c9a6; }
:root[data-theme="dark"] { --brick: #8a3d1f; --brick-mortar: #3a2a20; }

.site-header::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: -5px;
  height: 4px;
  background: linear-gradient(90deg, var(--brick-mortar) 1px, transparent 1px) 0 0 / 16px 4px, var(--brick);
  opacity: 0.85;
}

.chain-num { border-radius: 10px; transition: transform 0.15s; }
.chain-card:hover .chain-num { transform: translateY(-3px); }
@media (prefers-reduced-motion: reduce) { .chain-card:hover .chain-num { transform: none; } }

.hero-block {
  display: inline-grid;
  place-items: center;
  width: 1.05em;
  height: 1.05em;
  margin-right: 0.18em;
  vertical-align: -0.12em;
  border-radius: 0.16em;
  background: var(--block);
  border: 0.06em solid var(--block-edge);
  font-size: 0.9em;
  --q-size: 0.74em;
  --q-shadow: 0.04em;
  animation: bump 2.8s ease-in-out infinite;
}
@keyframes bump { 0%, 82%, 100% { transform: translateY(0); } 88% { transform: translateY(-0.18em); } }
@media (prefers-reduced-motion: reduce) { .hero-block { animation: none; } }

.coin-trail { display: flex; gap: 10px; margin: 0.4rem 0 1.4rem; }
.coin-trail span {
  width: 12px;
  height: 18px;
  border-radius: 50%;
  background: radial-gradient(circle at 40% 35%, #ffe680, #f4b400 60%, #b07800);
  box-shadow: inset 0 0 0 1px rgba(120, 70, 0, 0.5);
}

.site-footer { position: relative; }
.site-footer::before {
  content: "";
  position: absolute;
  left: 20px;
  right: 20px;
  top: -1px;
  height: 6px;
  background: linear-gradient(90deg, var(--brick-mortar) 1px, transparent 1px) 0 0 / 24px 6px, var(--brick);
  opacity: 0.6;
  border-radius: 2px;
}

/* Small screens: the chapters menu carries the extra pages so the header fits. */
.chapters-menu li.menu-extra, .chapters-menu li.menu-sep { display: none; }
.chapters-menu li.menu-sep { height: 1px; background: var(--rule); margin: 6px 4px; }
@media (max-width: 760px) {
  .site-nav > a.nav-reference, .site-nav > a.nav-timeline { display: none; }
  .chapters-menu li.menu-extra, .chapters-menu li.menu-sep { display: block; }
  .site-header { padding: 0 12px; gap: 8px; }
}
@media (max-width: 440px) {
  .site-nav > a.nav-playground { display: none; }
}

/* ------------------------------------------------------------------ title screen (home) */
/* The home page is a single screen: the copy on the left and, behind it, a canvas where a line of Wahoo goes
   through the real compiler as a tiny level (js/demos/splash.js). On narrow screens the canvas goes under the copy. */

.splash {
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: max(calc(100svh - 59px), 600px);
  overflow: hidden;
  font-family: var(--sans);
  background: linear-gradient(var(--bg-soft), var(--bg));
}
.splash-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: manipulation; }
.splash-copy {
  position: relative;
  z-index: 1;
  width: min(46vw, 600px);
  margin-left: max(28px, calc((100vw - 1320px) / 2));
  padding-top: clamp(24px, 7vh, 80px);
}
.splash-title {
  margin: 0 0 0.9rem;
  font: 800 clamp(2.8rem, 6.2vw, 5rem)/0.98 var(--sans);
  letter-spacing: -0.04em;
  color: var(--fg);
  text-shadow: 0 2px 0 color-mix(in srgb, var(--bg) 60%, transparent);
}
.splash-sub { display: block; margin-top: 0.12em; font-size: 0.56em; font-weight: 750; letter-spacing: -0.025em; }
.splash-lead { margin: 0 0 0.4rem; font: 1.12rem/1.55 var(--serif); color: var(--text); max-width: 34rem; }
.splash .cta-row { margin: 1.2rem 0 1rem; }
.splash .cta { background: color-mix(in srgb, var(--bg) 82%, transparent); backdrop-filter: blur(6px); }
.splash .cta.primary { background: var(--fg); }
.splash-try { display: grid; gap: 6px; max-width: 30rem; font-size: 0.86rem; color: var(--muted); }
.splash-try-row { display: flex; gap: 8px; }
.splash-try input {
  flex: 1;
  min-width: 0;
  padding: 9px 12px;
  border: 1px solid var(--rule);
  border-radius: 8px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  color: var(--fg);
  font: 0.92rem var(--mono);
}
.splash-try input:focus { outline: 2px solid var(--block); outline-offset: 1px; }
.splash-try .cta { padding: 8px 14px; cursor: pointer; font-family: var(--sans); }

.splash-hud {
  position: absolute;
  z-index: 1;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 14px;
  padding: 10px max(20px, calc((100vw - 1320px) / 2));
  color: #fff;
  font-size: 0.8rem;
}
.splash-phases { display: flex; flex-wrap: wrap; gap: 6px; margin: 0; padding: 0; list-style: none; }
.splash-phases li {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px 4px 5px;
  border-radius: 999px;
  background: rgba(16, 18, 24, 0.62);
  color: rgba(255, 255, 255, 0.72);
  font-weight: 650;
  transition: background 0.2s, color 0.2s;
}
.splash-phases .n {
  display: inline-grid;
  place-items: center;
  width: 18px;
  height: 18px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.16);
  font: 700 0.7rem/1 var(--mono);
}
.splash-phases li.done { color: #fff; }
.splash-phases li.done .n { background: #2e8b57; }
.splash-phases li[aria-current] { background: #f4b400; color: #2b1800; }
.splash-phases li[aria-current] .n { background: #8a4b08; color: #fff; }
.splash-phases li.bad { background: #c2412d; color: #fff; }
.splash-caption { flex: 1 1 260px; margin: 0; padding: 4px 10px; border-radius: 6px; background: rgba(16, 18, 24, 0.62); }
.splash-caption.bad { background: rgba(194, 65, 45, 0.85); }
.splash-ctrls { display: flex; gap: 6px; }
.splash-btn {
  padding: 4px 10px;
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 6px;
  background: rgba(16, 18, 24, 0.62);
  color: #fff;
  font: 650 0.78rem var(--sans);
  cursor: pointer;
}
.splash-btn:hover { background: rgba(16, 18, 24, 0.85); }

.nav-start .ext { margin-left: 3px; font-size: 0.85em; }
.chapters-menu li.menu-intro a { font-weight: 650; }

@media (max-width: 899px) {
  .splash { min-height: 0; }
  .splash-copy { width: auto; margin: 0; padding: 28px 20px 8px; }
  .splash-copy { order: 1; }
  .splash-canvas { order: 2; position: relative; height: clamp(440px, 72svh, 560px); }
  .splash-hud { order: 3; position: relative; padding: 10px 16px 14px; background: #1b1e23; }
}
@media (max-width: 760px) {
  .site-nav > a.nav-start { display: none; }
}
