/* A Look Behind the AI Curtain -- chapter styles.
   Midnight-and-crimson palette, Syne display + Source Serif 4 body + JetBrains Mono.
   Deliberately distinct from docs/graphics (warm paper / amber / Fraunces). */

:root {
  --bg:      #f2f3f8;  --bg2: #e8eaf2;  --surface: #fbfbfe;
  --ink:     #171a2b;  --muted: #555b74; --faint: #7a809a;
  --line:    rgba(23,26,43,0.14);  --line2: rgba(23,26,43,0.08);
  --accent:  #c1203f;  --accent-ink: #a3142f;  --accent-soft: rgba(193,32,63,0.10);
  --glow:    rgba(193,32,63,0.16);
  --gold:    #b7891f;  --curtain-a: #b8233f;  --curtain-b: #8f1430;
  --c-red: #d04a4a;  --c-green: #2f9a63;  --c-blue: #3b63d6;
  --c-a: #c1203f;  --c-b: #b7891f;  --c-c: #1f9a8a;
  --code-bg: #141833;  --code-ink: #e9ebf5;  --code-c: #7f87a6;  --code-kw: #ff5c7a; --code-str:#8fe0c8; --code-num:#ffcf7a;
  --eq-bg:   #eceef6;
  --screen:  #0e1226;
  --shadow:  0 1px 2px rgba(23,26,43,.06), 0 8px 30px rgba(23,26,43,.08);
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #0f1222; --bg2: #141833; --surface: #171b33;
  --ink: #e9ebf5; --muted: #aab0c8; --faint: #7f87a6;
  --line: rgba(233,235,245,0.13); --line2: rgba(233,235,245,0.06);
  --accent: #ff5c7a; --accent-ink: #ff8aa0; --accent-soft: rgba(255,92,122,0.14);
  --glow: rgba(255,92,122,0.22);
  --gold: #e5b94e;  --curtain-a: #ff5c7a;  --curtain-b: #b8233f;
  --c-red: #ff7a7a; --c-green: #5ee0a0; --c-blue: #7aa2ff;
  --c-a: #ff5c7a; --c-b: #e5b94e; --c-c: #5ee0c8;
  --code-bg: #0a0d1c; --code-ink: #e9ebf5; --code-c: #6f7795; --code-kw: #ff5c7a; --code-str:#8fe0c8; --code-num:#ffcf7a;
  --eq-bg: #141833;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 12px 40px rgba(0,0,0,.45);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: "Source Serif 4", Georgia, serif; font-optical-sizing: auto;
  font-size: 17.5px; line-height: 1.68;
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
}
::selection { background: var(--accent-soft); }
.wrap { max-width: 730px; margin: 0 auto; padding: 0 24px; }
.wide { max-width: 1080px; margin: 0 auto; padding: 0 24px; }
p { margin: 0 0 1.1em; }
a { color: var(--accent-ink); text-underline-offset: 3px; }
strong { font-weight: 700; color: var(--ink); }
h1,h2,h3,h4 { font-family: "Syne", system-ui, sans-serif; text-wrap: balance; line-height: 1.08; margin: 0; }

/* -- top bar + chapter drawer ------------------------------------------- */
.topbar { position: sticky; top: 0; z-index: 50; display: flex; align-items: center; justify-content: space-between;
  gap: 16px; padding: 10px 20px; background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: blur(10px); border-bottom: 1px solid var(--line2); }
.topbar .left { display: flex; align-items: center; gap: 14px; min-width: 0; }
.brand { font-family: "JetBrains Mono", monospace; font-size: 12px; letter-spacing: .14em; text-transform: uppercase; color: var(--muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-decoration: none; }
.brand b { color: var(--ink); font-weight: 600; }
.toggle, .menu-btn { font: inherit; font-size: 13px; display: inline-flex; align-items: center; gap: 7px; padding: 6px 13px;
  cursor: pointer; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: 6px; }
.menu-btn { padding: 7px 10px; }
.menu-btn svg { display: block; }
.toggle:hover, .menu-btn:hover { border-color: var(--accent); }
.toggle:focus-visible, .menu-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.drawer-scrim { position: fixed; inset: 0; background: rgba(10,8,5,.45); z-index: 90; opacity: 0; pointer-events: none; transition: opacity .2s; }
.drawer { position: fixed; top: 0; left: 0; bottom: 0; width: min(380px, 88vw); z-index: 100; background: var(--surface);
  border-right: 1px solid var(--line); box-shadow: var(--shadow); transform: translateX(-102%); transition: transform .24s ease;
  display: flex; flex-direction: column; }
body.nav-open .drawer { transform: none; }
body.nav-open .drawer-scrim { opacity: 1; pointer-events: auto; }
.drawer-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 18px 12px; border-bottom: 1px solid var(--line2); }
.drawer-head a { font-family: "Syne", sans-serif; font-size: 1.1rem; font-weight: 600; color: var(--ink); text-decoration: none; }
.drawer-close { font: inherit; font-size: 20px; line-height: 1; background: none; border: 0; color: var(--muted); cursor: pointer; padding: 4px 8px; }
.drawer nav { overflow-y: auto; padding: 8px 0 30px; }
.drawer .part { font-family: "JetBrains Mono", monospace; font-size: 10.5px; letter-spacing: .16em; text-transform: uppercase; color: var(--accent-ink);
  padding: 16px 20px 6px; }
.drawer a.ch, .drawer span.ch { display: grid; grid-template-columns: 28px 1fr; gap: 6px; padding: 6px 20px; font-size: 15px; line-height: 1.35;
  color: var(--ink); text-decoration: none; border-left: 3px solid transparent; }
.drawer a.ch:hover { background: var(--accent-soft); }
.drawer a.ch.current { border-left-color: var(--accent); background: var(--accent-soft); font-weight: 600; }
.drawer span.ch { color: var(--faint); cursor: default; }
.drawer .ch .num { font-family: "JetBrains Mono", monospace; font-size: 12px; color: var(--faint); padding-top: 2px; }
.drawer .soon { font-family: "JetBrains Mono", monospace; font-size: 10px; letter-spacing: .08em; text-transform: uppercase; color: var(--faint);
  border: 1px solid var(--line); border-radius: 6px; padding: 0 6px; margin-left: 6px; white-space: nowrap; }

/* -- hero ---------------------------------------------------------------- */
.hero { padding: 64px 0 30px; position: relative; overflow: hidden; }
/* the curtain: a band of folds along the top edge, and a crimson glow under it */
.hero::before { content:""; position:absolute; left:0; right:0; top:0; height:12px; pointer-events:none;
  background: repeating-linear-gradient(90deg, var(--curtain-a) 0 22px, var(--curtain-b) 22px 44px); }
.hero::after { content:""; position:absolute; inset:0 0 auto 0; height: 420px; pointer-events:none; z-index:-1;
  background: radial-gradient(70% 80% at 18% 0%, var(--glow), transparent 65%); }
.eyebrow { font-family: "JetBrains Mono", monospace; font-size: 12px; letter-spacing: .2em; text-transform: uppercase; color: var(--gold); margin: 0 0 18px; display:flex; align-items:center; gap:10px; }
.eyebrow::before { content:""; width:26px; height:3px; background: var(--accent); flex:none; }
h1 { font-size: clamp(2.3rem, 5.6vw, 4.1rem); font-weight: 800; letter-spacing: -0.035em; margin-bottom: 20px; }
h1 em { font-style: normal; color: var(--accent); font-weight: 800; }
.byline { font-size: 1.05rem; color: var(--muted); margin: -8px 0 0; }
.byline b { color: var(--ink); font-weight: 600; }
.standfirst { font-size: clamp(1.1rem, 2.3vw, 1.36rem); color: var(--muted); max-width: 46ch; }
.standfirst b { color: var(--ink); font-weight: 600; }

figure { margin: 0; }
.stage { margin: 34px 0 8px; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; background: var(--screen); box-shadow: var(--shadow); position: relative; }
.stage canvas { display: block; width: 100%; height: auto; }
.stage-hud { position: absolute; left: 14px; top: 12px; font-family: "JetBrains Mono", monospace; font-size: 12px; color: #e9ebf5;
  text-shadow: 0 1px 4px rgba(0,0,0,.8); display: flex; gap: 18px; align-items: baseline; pointer-events: none; }
.stage-hud b { color: #ff8aa0; font-weight: 500; font-variant-numeric: tabular-nums; }
.stage-controls { position: absolute; right: 12px; bottom: 12px; display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.stage-bar { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; padding: 10px 12px; background: #141833; border-top: 1px solid rgba(255,255,255,.07); }
.stage-btn { font: inherit; font-size: 12.5px; padding: 6px 12px; cursor: pointer; color: #160a10; background: #ff5c7a; border: 0; border-radius: 6px; font-weight: 600; }
.stage-btn.ghost { background: rgba(255,255,255,.14); color: #e9ebf5; backdrop-filter: blur(4px); }
.stage-btn[aria-pressed="true"] { background: #ff5c7a; color: #160a10; }
.stage-btn:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }
figcaption { font-size: 14px; color: var(--faint); margin-top: 12px; font-style: italic; }
figcaption b { font-style: normal; font-weight: 600; color: var(--muted); }

/* -- sections ------------------------------------------------------------ */
section { padding: 22px 0; }
.section-head { margin: 36px 0 6px; }
.kicker { font-family: "JetBrains Mono", monospace; font-size: 11.5px; letter-spacing: .18em; text-transform: uppercase; color: var(--gold); margin: 0 0 12px; display: flex; align-items: center; gap: 10px; }
.kicker::before { content:""; width: 18px; height: 3px; background: var(--accent); flex: none; }
h2 { font-size: clamp(1.65rem, 3.4vw, 2.3rem); font-weight: 700; letter-spacing: -0.03em; }
h3 { font-size: 1.3rem; font-weight: 700; margin: 34px 0 6px; letter-spacing: -0.02em; }
h4 { font-size: 1.02rem; margin: 26px 0 4px; font-weight: 700; letter-spacing: -0.01em; }
.lede { font-size: 1.2rem; color: var(--muted); margin-top: 12px; }
hr.rule { border: 0; border-top: 3px solid var(--accent); margin: 54px auto; max-width: 56px; }
.part-tab { font-family: "JetBrains Mono", monospace; font-size: 11.5px; letter-spacing: .16em; text-transform: uppercase;
  color: #fff; background: var(--accent); border-radius: 3px; padding: 4px 11px; display: inline-block; margin-bottom: 18px; }
.prose ol, .prose ul { margin: 0 0 1.1em; padding-left: 1.35em; }
.prose li { margin: 0 0 .5em; }

code { font-family: "JetBrains Mono", monospace; font-size: 0.85em; background: var(--accent-soft); color: var(--accent-ink); padding: 1px 6px; border-radius: 5px; }
.mono { font-family: "JetBrains Mono", monospace; font-size: .82em; }

/* "the idea in plain words" panel -- this book's stand-in for equations */
.math { background: var(--eq-bg); border: 1px solid var(--line); border-left: 3px solid var(--accent); border-radius: 10px; padding: 18px 20px; margin: 22px 0; }
.math .tag { font-family: "JetBrains Mono", monospace; font-size: 11px; letter-spacing: .14em; text-transform: uppercase; color: var(--accent-ink); display: block; margin-bottom: 10px; }
.math p:last-child { margin-bottom: 0; }
.eqline { font-family: "JetBrains Mono", monospace; font-size: 1.02rem; text-align: center; margin: 12px 0; line-height: 1.6; overflow-x: auto; color: var(--ink); }
.eqline .op { color: var(--accent-ink); padding: 0 .15em; }
.where { list-style: none; margin: 12px 0 0; padding: 0; display: flex; flex-direction: column; gap: 6px; font-size: 0.95rem; color: var(--muted); }
.where li { display: grid; grid-template-columns: minmax(64px, auto) 1fr; gap: 12px; align-items: baseline; }
.where .sym { font-family: "JetBrains Mono", monospace; color: var(--ink); font-size: .92rem; text-align: right; }

/* code panels: write <div class="code" data-file="gfx.js"><pre><code>...</code></pre></div>;
   book.js highlights the contents. */
.code { background: var(--code-bg); border-radius: 6px; border-left: 4px solid var(--accent); margin: 22px 0; overflow: hidden; box-shadow: var(--shadow); }
.code .filelabel { font-family: "JetBrains Mono", monospace; font-size: 11px; letter-spacing: .06em; color: var(--code-c);
  padding: 9px 16px; border-bottom: 1px solid rgba(255,255,255,.07); display: flex; justify-content: space-between; }
.code .filelabel .lang { color: var(--code-kw); }
.code pre { margin: 0; padding: 16px; overflow-x: auto; max-height: 620px; }
.code code, .playground code { background: none; color: var(--code-ink); padding: 0; font-size: 13px; line-height: 1.6; }
/* JetBrains Mono ships ligatures (=> becomes an arrow); keep code looking like what you typed */
code, pre, textarea, .transcript, .tokens, .out { font-variant-ligatures: none; font-feature-settings: "liga" 0, "calt" 0; }
.tok-c { color: var(--code-c); font-style: italic; }
.tok-k { color: var(--code-kw); }
.tok-s { color: var(--code-str); }
.tok-n { color: var(--code-num); }
.tok-t { color: #8fb3d9; }

.aside { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 18px 22px; margin: 24px 0; box-shadow: var(--shadow); }
.aside .tag { font-family: "JetBrains Mono", monospace; font-size: 11px; letter-spacing: .14em; text-transform: uppercase; color: var(--accent-ink); display: block; margin-bottom: 8px; }
.aside p:last-child { margin-bottom: 0; }
.note { border-left: 2px solid var(--accent); padding: 2px 0 2px 16px; color: var(--muted); margin: 20px 0; font-size: .98em; }

/* numbered steps */
.step { display: grid; grid-template-columns: 58px 1fr; gap: 20px; margin: 30px 0; align-items: start; }
.step-num { font-family: "Syne", serif; font-size: 2.2rem; font-weight: 500; color: var(--accent); line-height: 1; font-variant-numeric: tabular-nums; border-top: 2px solid var(--accent); padding-top: 8px; }
.step h3 { margin: 2px 0 6px; }
.step p:last-child { margin-bottom: 0; }

/* card strip */
.pipe { display: grid; grid-template-columns: repeat(3,1fr); gap: 12px; margin: 24px 0; }
.pipe.four { grid-template-columns: repeat(4,1fr); }
.pipe .card { background: var(--surface); border: 1px solid var(--line); border-top: 3px solid var(--accent); border-radius: 4px; padding: 15px; }
.pipe .card .n { font-family: "JetBrains Mono", monospace; font-size: 10.5px; color: var(--gold); letter-spacing: .1em; }
.pipe .card h4 { font-weight: 600; font-size: 1.02rem; margin: 5px 0; }
.pipe .card p { margin: 0; font-size: .86em; color: var(--muted); }

/* data table */
.table-wrap { overflow-x: auto; margin: 22px 0; }
table.data { border-collapse: collapse; width: 100%; font-size: .92em; }
table.data th { font-family: "JetBrains Mono", monospace; font-size: 11px; letter-spacing: .1em; text-transform: uppercase; color: var(--accent-ink);
  text-align: left; font-weight: 500; padding: 8px 10px; border-bottom: 1px solid var(--line); }
table.data td { padding: 8px 10px; border-bottom: 1px solid var(--line2); vertical-align: top; }
table.data td.num { font-family: "JetBrains Mono", monospace; font-size: .9em; text-align: right; white-space: nowrap; }

/* svg diagrams */
.diagram { margin: 24px 0; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 12px; box-shadow: var(--shadow); }
.diagram svg { width: 100%; height: auto; display: block; }
.diagram text { font-family: "JetBrains Mono", monospace; fill: var(--muted); font-size: 12px; }
.diagram .ink { fill: var(--ink); }
.diagram .acc { fill: var(--accent-ink); }
.diagram .s-ink { stroke: var(--ink); fill: none; }
.diagram .s-acc { stroke: var(--accent); fill: none; }
.diagram .s-line { stroke: var(--line); fill: none; }
.diagram .f-surf { fill: var(--bg2); }
.diagram .f-acc { fill: var(--accent-soft); }
.diagram .box { fill: var(--bg2); stroke: var(--line); }
.diagram .abox { fill: var(--accent-soft); stroke: var(--accent); }
.diagram .wire { stroke: var(--muted); fill: none; stroke-width: 1.5; }
.diagram .awire { stroke: var(--accent); fill: none; stroke-width: 1.5; }

/* -- interactive demos --------------------------------------------------- */
.demo { background: var(--surface); border: 1px solid var(--line); border-left: 4px solid var(--accent); border-radius: 4px; padding: 16px 18px; margin: 24px 0; box-shadow: var(--shadow); }
.demo .dhead { font-family:"JetBrains Mono",monospace; font-size:11px; letter-spacing:.14em; text-transform:uppercase; color:var(--gold); margin-bottom:12px; display:flex; align-items:center; gap:10px; }
.demo .dhead::before { content:""; width:8px; height:8px; background:var(--accent); transform: rotate(45deg); flex:none; }
.panels { display:flex; gap:12px; flex-wrap:wrap; }
.panel { flex:1 1 0; min-width:180px; display:flex; flex-direction:column; gap:6px; }
.panel .plabel { font-family:"JetBrains Mono",monospace; font-size:11px; color:var(--faint); letter-spacing:.02em; }
.panel .plabel b { color:var(--accent-ink); font-weight:500; }
/* tile galleries (sprite samples, clip frames, chat drawings): tiles keep their own pixel size and wrap */
.samples { display:flex; flex-wrap:wrap; gap:6px; margin-top:8px; min-width:0; }
.demo canvas { width:100%; height:auto; display:block; border-radius:4px; border:1px solid var(--line); background:var(--screen); touch-action: none; }
.controls { display:flex; align-items:center; gap:10px 16px; flex-wrap:wrap; margin-top:14px; font-size:13px; color:var(--muted); }
.controls label { display:flex; align-items:center; gap:9px; }
.controls .cval { font-family:"JetBrains Mono",monospace; color:var(--ink); min-width:44px; font-size:12.5px; }
.controls .readout { font-family:"JetBrains Mono",monospace; font-size:12.5px; color:var(--ink); }
.controls .readout b { color: var(--accent-ink); font-weight: 500; }
.seg { display:inline-flex; border:1px solid var(--line); border-radius:6px; overflow:hidden; flex-wrap: wrap; }
.seg button, .btn { font: inherit; font-size: 12.5px; padding: 5px 12px; cursor: pointer; background: var(--bg); color: var(--ink); border: 0; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button[aria-pressed="true"] { background: var(--accent); color: #160a10; font-weight: 600; }
.btn { border: 1px solid var(--line); border-radius: 6px; background: var(--bg); }
.btn:hover, .seg button:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); color: #160a10; border-color: var(--accent); font-weight: 600; }
.btn:focus-visible, .seg button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
input[type=range] { -webkit-appearance:none; appearance:none; height:4px; border-radius:2px; background:var(--line); outline:none; width:150px; }
input[type=range]::-webkit-slider-thumb { -webkit-appearance:none; width:16px; height:16px; border-radius:50%; background:var(--accent); cursor:pointer; border:2px solid var(--surface); }
input[type=range]::-moz-range-thumb { width:16px; height:16px; border-radius:50%; background:var(--accent); cursor:pointer; border:2px solid var(--surface); }
input[type=range]:focus-visible { outline:2px solid var(--accent); outline-offset:3px; }
.demo figcaption { margin-top:12px; }
/* A WebGPU demo's recording, shown where the browser has no WebGPU (book.js gpuFallback). */
.nogpu-still img { width:100%; height:auto; display:block; border-radius:7px; border:1px solid var(--line); background:var(--screen); }
.nogpu-note { margin:8px 0 0; font-size:13px; color:var(--muted); }
.nogpu-note b { color:var(--accent-ink); font-weight:600; }
.nogpu-figure .controls { opacity:.45; pointer-events:none; }

/* -- live-code playground ------------------------------------------------ */
.playground { background: var(--code-bg); border-radius: 6px; margin: 24px 0; overflow: hidden; box-shadow: var(--shadow); }
/* playgrounds break out of the 730px prose column so the editor has room */
.wrap .playground { width: min(1040px, calc(100vw - 32px)); margin-left: calc(50% - min(520px, 50vw - 16px)); }
.playground .pg-head { font-family: "JetBrains Mono", monospace; font-size: 11px; letter-spacing: .06em; color: var(--code-c);
  padding: 9px 12px 9px 16px; border-bottom: 1px solid rgba(255,255,255,.07); display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.playground .pg-head .lang { color: var(--code-kw); }
.playground .pg-btns { display: flex; gap: 6px; align-items: center; }
.playground .pg-status { font-size: 11px; color: #8fb98f; margin-right: 6px; white-space: nowrap; }
.playground .pg-status.err { color: #f08a7a; }
.playground .pg-btns button { font: inherit; font-size: 11.5px; padding: 4px 11px; cursor: pointer; border-radius: 6px; border: 1px solid rgba(255,255,255,.16); background: transparent; color: var(--code-ink); }
.playground .pg-btns button.run { background: #ff5c7a; color: #160a10; border-color: #ff5c7a; font-weight: 600; }
.playground .pg-btns button.src { color: #ff5c7a; }
.playground .pg-body { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); }
.playground .pg-editor { position: relative; min-height: 220px; border-right: 1px solid rgba(255,255,255,.07); }
.playground .pg-editor pre, .playground .pg-editor textarea {
  margin: 0; padding: 14px 16px; font-family: "JetBrains Mono", monospace; font-size: 13px; line-height: 1.6; tab-size: 2;
  white-space: pre; overflow: auto; position: absolute; inset: 0; border: 0; letter-spacing: 0; }
.playground .pg-editor pre { pointer-events: none; color: var(--code-ink); }
.playground .pg-editor textarea { background: transparent; color: transparent; caret-color: #ff8aa0; resize: none; outline: none; }
.playground .pg-editor textarea::selection { background: rgba(255,92,122,.3); color: transparent; }
.playground .pg-out { display: flex; flex-direction: column; background: #0a0d1c; }
.playground .pg-out canvas { width: 100%; height: auto; display: block; background: #fff; image-rendering: auto; }
.playground .pg-out canvas.pixelated { image-rendering: pixelated; }
.playground .pg-out img { width: 100%; height: auto; display: block; }
.playground .pg-log { font-family: "JetBrains Mono", monospace; font-size: 11.5px; color: var(--code-c); padding: 8px 12px; min-height: 30px; white-space: pre-wrap; }
.playground .pg-log.err { color: #f08a7a; }
@media (max-width: 760px) {
  .playground .pg-body { grid-template-columns: 1fr; }
  .playground .pg-editor { min-height: 300px; border-right: 0; border-bottom: 1px solid rgba(255,255,255,.07); }
}

/* prev / next */
.chapter-nav { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 50px 0 0; }
.chapter-nav > a, .chapter-nav > span { display: block; padding: 14px 18px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); text-decoration: none; color: var(--ink); }
.chapter-nav > a:hover { border-color: var(--accent); }
.chapter-nav .dir { font-family: "JetBrains Mono", monospace; font-size: 11px; letter-spacing: .14em; text-transform: uppercase; color: var(--accent-ink); display: block; margin-bottom: 4px; }
.chapter-nav .t { font-family: "Syne", serif; font-size: 1.05rem; font-weight: 600; }
.chapter-nav .next { text-align: right; grid-column: 2; }
.chapter-nav > span { color: var(--faint); }

/* cover page table of contents */
.toc-part { margin: 34px 0 10px; }
.toc-part h3 { margin: 4px 0 4px; }
.toc-part p { color: var(--muted); font-size: .96em; margin: 0 0 10px; }
.toc-list { list-style: none; padding: 0; margin: 0; border-top: 1px solid var(--line2); }
.toc-list li { display: grid; grid-template-columns: 38px 1fr auto; gap: 10px; padding: 10px 2px; border-bottom: 1px solid var(--line2); align-items: baseline; }
.toc-list .num { font-family: "JetBrains Mono", monospace; font-size: 12.5px; color: var(--faint); }
.toc-list a { color: var(--ink); font-weight: 600; text-decoration: none; }
.toc-list a:hover { color: var(--accent-ink); }
.toc-list .t { font-weight: 600; color: var(--faint); }
.toc-list .sub { display: block; font-size: .88em; color: var(--muted); font-weight: 400; }
.toc-list .status { font-family: "JetBrains Mono", monospace; font-size: 10.5px; letter-spacing: .08em; text-transform: uppercase; color: var(--faint); }
.toc-list .status.ready { color: var(--accent-ink); }

footer { border-top: 1px solid var(--line); margin-top: 64px; padding: 38px 0 68px; color: var(--faint); font-size: 14px; }
footer p { margin: 0 0 6px; }
footer a { color: var(--accent-ink); }
.contact { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.contact a {
  display: inline-flex; align-items: center; gap: 7px; padding: 6px 12px; border: 1px solid var(--line);
  border-radius: 6px; color: var(--muted); text-decoration: none; font-size: 14px; transition: color 0.15s, border-color 0.15s;
}
.contact a:hover { color: var(--accent-ink); border-color: var(--accent); }
.contact svg { width: 15px; height: 15px; fill: currentColor; flex: none; }
/* the front page's build date, changelog link and contact links, under the byline */
.hero-meta { margin: 14px 0 28px; padding-bottom: 24px; border-bottom: 1px solid var(--line); }
.gpu-notice { margin: 0 0 28px; }
.gpu-notice p { margin: 0 0 10px; font-size: 15px; }
.gpu-dismiss { font: inherit; font-size: 13px; padding: 5px 14px; border-radius: 6px; border: 1px solid var(--line); background: transparent; color: var(--ink); cursor: pointer; }
.gpu-dismiss:hover { border-color: var(--accent); color: var(--accent-ink); }
.hero-meta .hero-links { font-size: 14px; color: var(--faint); margin: 0; }
.hero-meta .hero-links a { color: var(--accent-ink); }
.hero-meta .contact { margin-top: 10px; }

@media (max-width: 720px) {
  body { font-size: 17px; }
  .pipe, .pipe.four { grid-template-columns: 1fr; }
  .step { grid-template-columns: 42px 1fr; gap: 14px; }
  .step-num { font-size: 1.8rem; }
  .stage-hud { font-size: 11px; gap: 11px; }
  .chapter-nav { grid-template-columns: 1fr; }
  .chapter-nav .next { grid-column: 1; }
  .topbar { padding: 9px 14px; }
}

/* -- search --------------------------------------------------------------- */
.topbar .right { display: flex; align-items: center; gap: 8px; }
@media (max-width: 560px) {
  .playground .pg-head, .playground .pg-btns { flex-wrap: wrap; }
  .topbar .toggle-label { display: none; }
}
dialog.searchdlg { width: min(720px, calc(100vw - 24px)); max-height: min(80vh, 760px); margin: 8vh auto auto; padding: 0;
  border: 0; border-radius: 12px; background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
dialog.searchdlg[open] { display: flex; flex-direction: column; }
dialog.searchdlg::backdrop { background: rgba(12,9,6,.62); }
.searchdlg .search-head { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--line);
  color: var(--muted); }
.searchdlg .search-head input { flex: 1; min-width: 0; font: inherit; font-size: 17px; border: 0; outline: 0; background: transparent;
  color: var(--ink); }
.searchdlg .search-head input::-webkit-search-cancel-button { -webkit-appearance: none; appearance: none; }
.searchdlg .search-close { font-family: "JetBrains Mono", monospace; font-size: 11px; border: 1px solid var(--line); border-radius: 6px;
  background: none; color: var(--muted); padding: 2px 7px; cursor: pointer; }
.searchdlg .search-status { padding: 8px 16px 2px; font-family: "JetBrains Mono", monospace; font-size: 12px; color: var(--faint); }
.searchdlg .search-results { list-style: none; margin: 0; padding: 4px 8px 12px; overflow: auto; }
.searchdlg .search-results a { display: block; padding: 9px 10px; border-radius: 8px; text-decoration: none; color: inherit; }
.searchdlg .search-results a:hover, .searchdlg .search-results a[aria-selected="true"] { background: var(--accent-soft); }
.searchdlg .sres-where { display: block; font-family: "JetBrains Mono", monospace; font-size: 11px; letter-spacing: .04em;
  color: var(--accent-ink); }
.searchdlg .sres-title { display: block; font-weight: 600; margin: 2px 0; }
.searchdlg .sres-snip { display: block; font-size: 14px; color: var(--muted); }
.searchdlg .sres-snip mark { background: var(--accent-soft); color: var(--ink); border-radius: 2px; padding: 0 1px; }

/* -- link anchors on sections, figures and playgrounds ------------------- */
main section[id], main h3[id], figure.demo[id], .playground[id] { scroll-margin-top: 72px; }
.anchor { margin-left: 0.35em; color: var(--faint); text-decoration: none; font-weight: 400; opacity: 0; transition: opacity 0.15s, color 0.15s; }
h2:hover > .anchor, h3:hover > .anchor, .anchor:focus-visible { opacity: 1; }
.anchor:hover { color: var(--accent-ink); }
.demo .dhead .anchor, .pg-head .anchor { margin-left: 0; opacity: 0.55; }
.pg-head .anchor { margin-left: 0.6em; }
.demo .dhead:hover .anchor, .pg-head:hover .anchor { opacity: 1; }
.anchor.copied::after { content: " link copied"; font-family: "JetBrains Mono", monospace; font-size: 11px; letter-spacing: 0.08em; text-transform: none; color: var(--accent-ink); }
@media (hover: none) {
  .anchor { opacity: 0.45; }
}

/* -- "source" links on figures, and the source viewer -------------------- */
.demo .dhead .srcbtn { margin-left: auto; font: inherit; font-size: 10.5px; letter-spacing: .12em; text-transform: uppercase; cursor: pointer;
  background: none; border: 1px solid var(--line); border-radius: 6px; padding: 3px 10px; color: var(--accent-ink); }
.demo .dhead .srcbtn:hover { border-color: var(--accent); }
.demo .dhead .srcbtn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
dialog.srcdlg { width: min(1040px, calc(100vw - 32px)); max-height: 88vh; padding: 0; border: 0; border-radius: 12px; overflow: auto;
  background: var(--code-bg); color: var(--code-ink); box-shadow: 0 20px 60px rgba(0,0,0,.45); }
dialog.srcdlg::backdrop { background: rgba(12,9,6,.62); }
.srcdlg .srchead { position: sticky; top: 0; z-index: 1; display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 16px;
  background: var(--code-bg); border-bottom: 1px solid rgba(255,255,255,.08); font-family: "JetBrains Mono", monospace; font-size: 12px; letter-spacing: .08em; text-transform: uppercase; color: var(--code-kw); }
.srcdlg button { font: inherit; font-family: "JetBrains Mono", monospace; font-size: 11px; text-transform: none; letter-spacing: 0; cursor: pointer;
  background: transparent; color: var(--code-ink); border: 1px solid rgba(255,255,255,.16); border-radius: 6px; padding: 3px 10px; }
.srcdlg .srcpart { border-bottom: 1px solid rgba(255,255,255,.06); }
.srcdlg .srclabel { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 10px 16px 0;
  font-family: "JetBrains Mono", monospace; font-size: 11px; letter-spacing: .04em; color: var(--code-c); }
.srcdlg .srclabel .lang { color: var(--code-kw); margin-right: 8px; }
.srcdlg pre { margin: 0; padding: 10px 16px 16px; overflow-x: auto; font-family: "JetBrains Mono", monospace; font-size: 12.5px; line-height: 1.55; tab-size: 2; }
.srcdlg code { background: none; color: var(--code-ink); padding: 0; font-size: 12.5px; line-height: 1.55; }
.srcdlg .srcnotes { padding: 12px 16px 16px; font-size: 13px; color: var(--code-c); line-height: 1.6; }
.srcdlg .srcnotes a { color: var(--code-kw); }
.srcdlg .srcnotes code { font-size: 12px; color: var(--code-ink); }
.srcdlg .srclabel button { margin-left: 6px; }

/* ===================================================================== */
/* -- additions for "How Language Models Learn" ------------------------- */
/* ===================================================================== */
:root { --splat-a: #d98a2b; --splat-b: #c25a6b; --splat-c: #2f8f86; }
:root[data-theme="dark"] { --splat-a: #ff5c7a; --splat-b: #e27e90; --splat-c: #5ee0c8; }

/* figures built from text rather than canvases */
.demo textarea, .demo input[type=text] { font: inherit; font-family: "JetBrains Mono", monospace; font-size: 13px; width: 100%; padding: 8px 10px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--bg); color: var(--ink); resize: vertical; }
.demo textarea:focus, .demo input[type=text]:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.demo .plabel { font-family: "JetBrains Mono", monospace; font-size: 11px; color: var(--faint); letter-spacing: .02em; }
.demo .plabel b { color: var(--accent-ink); font-weight: 500; }
.demo .controls button.primary { background: var(--accent); color: #160a10; border-color: var(--accent); font-weight: 600; }
.demo .controls select { font: inherit; font-size: 12.5px; padding: 4px 10px; border-radius: 6px; color: var(--ink); background: var(--bg); border: 1px solid var(--line); }
.tokens { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 10px; font-family: "JetBrains Mono", monospace; font-size: 13px; line-height: 1.4; min-height: 28px; }
.tokens .tk { padding: 2px 6px; border-radius: 5px; white-space: pre; border: 1px solid var(--line); background: var(--bg); position: relative; }
.tokens .tk .id { display: block; font-size: 9.5px; color: var(--faint); line-height: 1; margin-top: 2px; }
.bars { display: flex; flex-direction: column; gap: 5px; margin-top: 10px; font-family: "JetBrains Mono", monospace; font-size: 12.5px; }
.bars .row { display: grid; grid-template-columns: 110px 1fr 54px; gap: 10px; align-items: center; }
.bars .lab { white-space: pre; overflow: hidden; text-overflow: ellipsis; color: var(--ink); }
.bars .bar { height: 12px; border-radius: 3px; background: var(--line2); overflow: hidden; }
.bars .bar i { display: block; height: 100%; background: var(--accent); }
.bars .bar i.rose { background: var(--splat-b); }
.bars .bar i.teal { background: var(--splat-c); }
.bars .pct { color: var(--muted); text-align: right; }
.out { font-family: "JetBrains Mono", monospace; font-size: 13px; line-height: 1.55; white-space: pre-wrap; word-break: break-word; margin-top: 10px; padding: 10px 12px; border-radius: 8px; background: var(--bg); border: 1px solid var(--line); min-height: 2.4em; }
.out .p { color: var(--faint); }
.out .g { color: var(--ink); }
.out .ok { color: var(--c-green); }
.out .bad { color: var(--c-red); }
.surp { font-family: "JetBrains Mono", monospace; font-size: 13.5px; line-height: 1.9; white-space: pre-wrap; word-break: break-word; margin-top: 10px; }
.surp span { padding: 1px 2px; border-radius: 3px; }
.chip { display: inline-block; font-family: "JetBrains Mono", monospace; font-size: 11.5px; padding: 2px 8px; border-radius: 6px; border: 1px solid var(--line); color: var(--muted); margin: 2px 4px 2px 0; cursor: pointer; background: var(--bg); }
.chip:hover { border-color: var(--accent); color: var(--ink); }
.legend { display: flex; gap: 16px; flex-wrap: wrap; font-family: "JetBrains Mono", monospace; font-size: 11.5px; color: var(--muted); margin-top: 8px; }
.legend i { display: inline-block; width: 14px; height: 3px; vertical-align: middle; margin-right: 6px; border-radius: 2px; }
.grid-cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-top: 12px; }

/* prose furniture the chapters use */
.frac { display: inline-flex; flex-direction: column; vertical-align: middle; text-align: center; margin: 0 .18em; }
.frac .num { border-bottom: 1.5px solid currentColor; padding: 0 .35em; }
.frac .den { padding: 0 .35em; }
ol.mech { counter-reset: mech; list-style: none; padding-left: 0; margin: 20px 0; display: flex; flex-direction: column; gap: 16px; }
ol.mech > li { display: grid; grid-template-columns: 30px 1fr; gap: 15px; align-items: start; }
ol.mech > li::before { counter-increment: mech; content: counter(mech); font-family: "JetBrains Mono", monospace; font-size: 13px; color: var(--accent-ink); border: 1px solid var(--line); border-radius: 7px; width: 28px; height: 28px; display: grid; place-items: center; margin-top: 2px; }
ol.mech .h { font-weight: 600; color: var(--ink); }
.kv { list-style: none; margin: 14px 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.kv li { display: grid; grid-template-columns: 170px 1fr; gap: 14px; font-size: .95em; }
.kv .k { font-family: "JetBrains Mono", monospace; font-size: 12.5px; color: var(--accent-ink); }
.kv .v { color: var(--muted); }
table.t { border-collapse: collapse; width: 100%; font-size: .92em; margin: 16px 0; }
table.t th, table.t td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.t th { font-family: "JetBrains Mono", monospace; font-size: 11.5px; letter-spacing: .08em; text-transform: uppercase; color: var(--accent-ink); font-weight: 500; }
table.t td.num { font-family: "JetBrains Mono", monospace; font-size: 12.5px; white-space: nowrap; }
table.t td b { font-weight: 600; }
.refs ol { padding-left: 1.4em; margin: 12px 0 0; display: flex; flex-direction: column; gap: 10px; font-size: .92rem; color: var(--muted); }
.refs ol li::marker { color: var(--accent-ink); font-family: "JetBrains Mono", monospace; font-size: .85em; }
.refs .refnote { display: block; color: var(--faint); font-size: .92em; }
.transcript { font-family: "JetBrains Mono", monospace; font-size: 12.5px; line-height: 1.6; margin: 22px 0; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: var(--surface); box-shadow: var(--shadow); }
.transcript .turn { padding: 10px 16px; border-bottom: 1px solid var(--line2); white-space: pre-wrap; word-break: break-word; }
.transcript .turn:last-child { border-bottom: 0; }
.transcript .who { display: block; font-size: 10.5px; letter-spacing: .14em; text-transform: uppercase; color: var(--accent-ink); margin-bottom: 4px; }
.transcript .turn.tool { background: var(--eq-bg); }
.transcript .turn.think { color: var(--muted); font-style: italic; }
.swatch { display: inline-block; width: 12px; height: 12px; border-radius: 3px; vertical-align: middle; margin-right: 5px; }
@media (max-width: 720px) {
  .kv li { grid-template-columns: 1fr; gap: 2px; }
  .bars .row { grid-template-columns: 80px 1fr 48px; }
}

/* cover subtitle */
.subtitle { font-family: "Syne", sans-serif; font-size: clamp(1.15rem, 2.4vw, 1.55rem); font-weight: 500; color: var(--muted); margin: -6px 0 2px; letter-spacing: -0.01em; }

/* the front page's illustration plate, between the byline and the links */
.cover-plate { margin: 22px 0 6px; }
.cover-plate img { display: block; width: 100%; height: auto; border-radius: 4px;
  box-shadow: 0 0 0 1px var(--line), 0 14px 40px rgba(0,0,0,.35); }
.cover-plate figcaption { margin-top: 10px; font-size: 13.5px; font-style: italic; color: var(--faint); }
/* the front page's training replay sits in the text column but, like the playgrounds, spans the wider page */
.wrap #hero { width: min(1040px, calc(100vw - 32px)); margin-left: calc(50% - min(520px, 50vw - 16px)); }
/* the "why might WebGPU not be working?" list inside the WebGPU notice */
.gpu-notice details { margin: 0 0 12px; font-size: 15px; }
.gpu-notice summary { cursor: pointer; color: var(--accent-ink); }
.gpu-notice details ul { margin: 8px 0 0; padding-left: 20px; }
.gpu-notice details li { margin: 0 0 6px; }
.gpu-notice code { font-size: 0.88em; }
