/* gpt-from-scratch: a phosphor terminal.
   Layout: one left-aligned column. The demo console first, then the five
   steps as a numbered sequence (text left, picture right), then training and
   the model table. A tmux-style bar at the bottom is the navigation. */

:root {
  --ground: #050a07;      /* the tube */
  --panel: #08120c;       /* raised areas */
  --rule: #163322;        /* hairlines */
  --rule-hi: #24543a;
  --ink: #b9ecc9;         /* body text */
  --bright: #e4ffe9;      /* emphasis */
  --dim: #5fa47b;         /* secondary text */
  --phos: #39ff7a;        /* TinyStories model, and the interface accent */
  --red: #ff3b5c;         /* Shakespeare model */
  --warn: #ffd166;        /* end-of-story marks */
  --cool: #6eaaff;        /* negative numbers in the embedding picture */
  --glow-phos: 0 0 6px rgba(57, 255, 122, .45), 0 0 18px rgba(57, 255, 122, .12);
  --glow-red: 0 0 6px rgba(255, 59, 92, .45), 0 0 18px rgba(255, 59, 92, .12);
  /* the demo and the explainer take the colour of the selected model */
  --accent: var(--phos); --accent-rgb: 57, 255, 122; --glow-accent: var(--glow-phos);

  --mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --crt: "VT323", "IBM Plex Mono", ui-monospace, monospace;
  --math: "STIX Two Text", "Cambria Math", "Times New Roman", serif;
  --fs-0: 0.8125rem;
  --fs-1: 0.9375rem;
  --fs-2: 1.0625rem;
  --fs-text: 0.875rem;  /* every explanatory paragraph below the intro */

  --measure: 68ch;
  --col: 1080px;
  --bar-h: 3.25rem;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }  /* hidden always wins over a component's own display */
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; scroll-behavior: smooth; scroll-padding-top: calc(var(--bar-h) + 1.5rem + env(safe-area-inset-top, 0px)); }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }

html, body { overflow-x: clip; }  /* the page only ever scrolls vertically */
body {
  margin: 0;
  background: var(--ground);
  color: var(--ink);
  font: 400 var(--fs-1)/1.6 var(--mono);
  -webkit-font-smoothing: antialiased;
}
body::after {   /* the tube: faint scanlines and a vignette */
  content: "";
  position: fixed; inset: 0; pointer-events: none; z-index: 50;
  background:
    repeating-linear-gradient(to bottom, rgba(0, 0, 0, 0) 0 2px, rgba(0, 0, 0, .16) 2px 3px),
    radial-gradient(ellipse at center, rgba(0, 0, 0, 0) 55%, rgba(0, 0, 0, .55) 100%);
}
/* the falling-characters background sits behind everything, faint */
.rain { position: fixed; inset: 0; width: 100%; height: 100%; z-index: 0; pointer-events: none; opacity: .5; }  /* glyphs draw at ~56%, so the usual look is unchanged and the cursor can light them up */
.screen, .tmux { position: relative; z-index: 1; }
::selection { background: var(--phos); color: var(--ground); }
a { color: var(--phos); }
b { font-weight: 600; color: var(--bright); }
.dim { color: var(--dim); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 2px solid var(--phos); outline-offset: 2px; }
.skip { position: absolute; left: 1rem; top: -3rem; z-index: 60; background: var(--phos); color: var(--ground); padding: .4rem .7rem; text-decoration: none; }
.skip:focus { top: 1rem; }

body[data-active="shakespeare"] #try, #how[data-active="shakespeare"] { --accent: var(--red); --accent-rgb: 255, 59, 92; --glow-accent: var(--glow-red); }

/* model identity: a colour swatch next to the name, everywhere */
.swatch { display: inline-block; width: .65em; height: .65em; margin-right: .5em; }
[data-model="shakespeare"] .swatch { background: var(--red); box-shadow: var(--glow-red); }
[data-model="tinystories"] .swatch { background: var(--phos); box-shadow: var(--glow-phos); }
.pane-name { font-weight: 600; color: var(--bright); }

/* ------------------------------------------------------------------ frame */
.screen {
  max-width: var(--col);
  margin: 0 auto;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  padding-block: 3rem calc(4rem + env(safe-area-inset-bottom, 0px));
  display: grid;
  gap: 6rem;
}
.block { display: grid; gap: 1.5rem; min-width: 0; }
.sec-head { display: grid; gap: .6rem; max-width: var(--measure); }
.sec-head h2 { margin: 0; font: 400 clamp(2.1rem, 5vw, 2.9rem)/1 var(--crt); color: var(--bright); text-wrap: balance; }
.intro { margin: 0; color: var(--ink); font-size: var(--fs-text); line-height: 1.7; }
.note, .chart-note { margin: 0; max-width: var(--measure); color: var(--dim); font-size: var(--fs-text); line-height: 1.65; }
.field-label { display: block; margin: 0; color: var(--dim); font-size: var(--fs-0); }
.flag { color: var(--dim); font-size: var(--fs-0); }

/* ------------------------------------------------------------------ intro */
.boot { display: grid; gap: 1.25rem; }
.boot-log { margin: 0; display: grid; color: var(--dim); font-size: var(--fs-0); }
.boot-log span { opacity: 0; animation: boot .01s steps(1) forwards; }
.boot-log span:nth-child(1) { animation-delay: .1s; }
.boot-log span:nth-child(2) { animation-delay: .4s; }
@keyframes boot { to { opacity: 1; } }
.title { margin: 0; font: 400 clamp(3.25rem, 11vw, 7.5rem)/.85 var(--crt); color: var(--phos); text-shadow: var(--glow-phos); overflow-wrap: anywhere; }
.title-cursor {  /* a terminal cursor after the name */
  display: inline-block; width: .45em; height: .8em; margin-left: .06em; vertical-align: -.06em;
  background: var(--phos); box-shadow: 0 0 6px rgba(57, 255, 122, .6); animation: blink 1s steps(1) infinite;
}
.lede { margin: 0; max-width: var(--measure); font-size: var(--fs-2); }
.lede a { color: var(--phos); text-decoration: underline; text-decoration-color: rgba(57, 255, 122, .4); text-underline-offset: 3px; }
.lede a:hover { text-decoration-color: var(--phos); color: var(--bright); }

/* ------------------------------------------------------------------ controls */
.chips { display: flex; flex-wrap: wrap; gap: .45rem; }
.chip {
  font: 500 var(--fs-0)/1 var(--mono); color: var(--ink);
  background: transparent; border: 1px solid var(--rule-hi);
  padding: .5rem .7rem; min-height: 2.1rem; cursor: pointer;
  transition: border-color .15s, color .15s, background-color .15s;
}
.chip:hover { border-color: var(--accent); color: var(--bright); }
.chip:active { transform: translateY(1px); }
.chip[aria-pressed="true"] { background: var(--rule); border-color: var(--accent); color: var(--bright); }

/* ------------------------------------------------------------------ the console */
.console {
  transition: border-color .35s;
  background: var(--panel);
  border: 1px solid var(--rule);
  border-top: 2px solid var(--accent);
  display: grid;
}
.console > .console-top, .console-inner > * { padding-inline: 1.1rem; }
/* after the first choice: a scanline sweeps down and the demo is drawn in behind it */
.console.unpicked .console-body { display: none; }
.console-body { position: relative; }
.console-inner { position: relative; }
.console.revealed .console-inner { animation: wipe .6s cubic-bezier(.4, 0, .2, 1) both; }
.console.revealed .console-body::after {
  content: ""; position: absolute; left: 0; right: 0; top: 0; height: 2px; pointer-events: none;
  background: var(--accent); box-shadow: 0 0 10px 2px rgba(var(--accent-rgb), .75), 0 0 30px 6px rgba(var(--accent-rgb), .25);
  animation: scan .6s cubic-bezier(.4, 0, .2, 1) both;
}
@keyframes wipe { from { clip-path: inset(0 0 100% 0); } to { clip-path: inset(0 0 0 0); } }
@keyframes scan { from { top: 0; opacity: 1; } 85% { opacity: 1; } to { top: 100%; opacity: 0; } }
.pick-label.swap { animation: swap .3s ease-out; }
@keyframes swap { 0% { opacity: 0; transform: translateY(-4px); } 100% { opacity: 1; } }
.steps.switching { animation: fadein .3s ease; }
@keyframes fadein { from { opacity: .25; } }
/* before a model is chosen, only the choice is shown */
.console.unpicked { border-top-color: var(--rule-hi); }
.console.unpicked .console-top { padding-block: 1.5rem; }
.pick-label { font-size: var(--fs-1); font-weight: 600; color: var(--bright); min-width: 18ch; }
.console-top { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .75rem 1.5rem; padding-block: 1rem .25rem; }
/* model switch: a coloured thumb slides behind the chosen button */
.seg { display: inline-grid; grid-template-columns: 1fr 1fr; gap: .4rem; position: relative; isolation: isolate; }  /* equal widths: nothing moves on switch */
.seg-thumb {
  position: absolute; z-index: -1; top: 0; left: 0; height: 0; width: 0;
  background: var(--m, var(--phos)); opacity: 0;
  box-shadow: 0 0 6px rgba(var(--m-rgb, 57, 255, 122), .45), 0 0 18px rgba(var(--m-rgb, 57, 255, 122), .15);
  transition: transform .32s cubic-bezier(.2, .9, .25, 1), width .32s cubic-bezier(.2, .9, .25, 1), height .32s cubic-bezier(.2, .9, .25, 1),
              background-color .32s ease, box-shadow .32s ease, opacity .2s ease;
}
.seg-thumb.on { opacity: 1; }
.seg-thumb.flash { animation: flash .45s ease-out; }
@keyframes flash { 0%, 55% { filter: brightness(1); } 70% { filter: brightness(1.9); } 100% { filter: brightness(1); } }
.seg button {
  font: 600 var(--fs-1)/1 var(--mono); color: var(--ink); background: transparent;
  border: 1px solid var(--rule-hi); padding: .7rem 1.1rem; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; text-align: center;
  transition: border-color .25s, color .25s, box-shadow .25s;
}
.seg button:hover { border-color: var(--m); color: var(--bright); box-shadow: 0 0 0 1px var(--m) inset; }
.seg button:active { transform: translateY(1px); }
.seg button[aria-checked="true"] { border-color: transparent; color: var(--ground); box-shadow: none; }
.seg button[aria-checked="true"] .swatch { background: var(--ground); box-shadow: none; }  /* the icon stays, so nothing shifts */
.seg-row { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem .9rem; margin-top: .3rem; }
.seg-row .flag { font-size: var(--fs-0); }
.mode { margin: 0; font-size: var(--fs-0); color: var(--warn); max-width: 52ch; }
.mode:empty { display: none; }
.mode { font-variant-numeric: tabular-nums; }
.mode .tag { color: var(--accent); font-weight: 600; }

/* one box: the text on the left, Generate inside it on the right */
.ask { padding-block: .5rem .75rem; }
.field {
  display: flex; align-items: center; gap: .5rem; padding: 4px 4px 4px .85rem;
  background: var(--ground); border: 1px solid var(--rule-hi);
  transition: border-color .2s, box-shadow .2s;
}
.field:focus-within { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.field .ps1 { color: var(--accent); font: 400 1.5rem/1 var(--crt); }
.field input {
  flex: 1; min-width: 0; padding: .6rem 0;
  background: transparent; color: var(--bright); caret-color: var(--accent);
  border: 0; font: 400 var(--fs-2)/1.3 var(--mono);
}
.field input:focus { outline: none; }
.ask-label { display: block; padding-top: 1rem; font-size: var(--fs-text); color: var(--ink); }
.go {
  font: 600 var(--fs-1)/1 var(--mono); color: var(--ground); background: var(--accent);
  border: 1px solid var(--accent); padding: .8rem 1.1rem; cursor: pointer; white-space: nowrap;
  box-shadow: var(--glow-accent); transition: filter .15s, transform .1s, background-color .35s, border-color .35s, box-shadow .35s;
}
.go:hover { filter: brightness(1.12); }
.go:active { transform: translateY(1px); }
.go:disabled { opacity: .5; cursor: progress; }
.examples { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem .8rem; padding-bottom: .5rem; }

.out {
  margin: 0; padding-block: 1rem;
  font: 400 var(--fs-1)/1.7 var(--mono);
  white-space: pre-wrap; overflow-wrap: anywhere;
  min-height: 15rem; color: var(--ink);
  border-top: 1px solid var(--rule);
}
/* the output area only exists once there is text: no empty box while waiting */
.console .out { min-height: 0; }
.console .out:empty, .console-foot:has(#count:empty) { display: none; }
.out .p { color: var(--bright); font-weight: 600; }
.out .eot { font-size: var(--fs-0); color: var(--ground); background: var(--warn); padding: 0 .35em; margin: 0 .2em; white-space: nowrap; }
.cursor { display: inline-block; width: .6em; height: 1.1em; vertical-align: text-bottom; margin-left: 1px; background: var(--accent); box-shadow: var(--glow-accent); animation: blink 1s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }
.console-foot { display: flex; flex-wrap: wrap; justify-content: space-between; gap: .5rem 1rem; align-items: center; padding-block: .6rem; border-top: 1px solid var(--rule); font-size: var(--fs-0); color: var(--dim); font-variant-numeric: tabular-nums; }
/* model loading: a short text progress bar, like a command-line download */
.loading { display: grid; gap: .15rem; padding-block: .9rem 1rem; border-top: 1px solid var(--rule); font: 400 var(--fs-0)/1.5 var(--mono); font-variant-numeric: tabular-nums; }
.load-name { color: var(--bright); }
.load-line { display: flex; flex-wrap: wrap; align-items: baseline; column-gap: .7rem; }
.load-bar { color: var(--accent); white-space: pre; }
.load-bar .off { color: var(--rule-hi); }
.load-pct { color: var(--accent); font-weight: 600; min-width: 4ch; }

/* ------------------------------------------------------------------ the five steps */
.steps { list-style: none; margin: 0; padding: 0; display: grid; gap: 3rem; counter-reset: step; }
.step {
  counter-increment: step;
  display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 7fr); gap: 1.25rem 2.5rem;
  padding-top: 1.5rem; border-top: 1px solid var(--rule);
}
.step-text { display: grid; align-content: start; gap: .5rem; }
.step-text::before { content: counter(step); font: 400 3rem/1 var(--crt); color: var(--accent); text-shadow: var(--glow-accent); }
.step-text h3 { margin: 0; font: 600 var(--fs-2)/1.35 var(--mono); color: var(--bright); }
.step-text p { margin: 0; color: var(--ink); font-size: var(--fs-text); line-height: 1.7; }
.step-vis { min-width: 0; align-self: center; }

.tokens { display: flex; flex-wrap: wrap; gap: 6px; }
.tcard { display: inline-grid; justify-items: center; gap: 2px; }
.tt { background: rgba(var(--accent-rgb), .14); border: 1px solid rgba(var(--accent-rgb), .35); color: var(--bright); padding: .35rem .5rem; white-space: pre; font-size: var(--fs-1); }
.tcard:nth-child(even) .tt { background: rgba(var(--accent-rgb), .26); }
.tid { font-size: 11px; color: var(--dim); font-variant-numeric: tabular-nums; }

.emb { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 5px .8rem; align-items: center; }
.emb-label { font-size: var(--fs-0); color: var(--bright); white-space: pre; text-align: right; max-width: 9ch; overflow: hidden; text-overflow: ellipsis; }
.emb-row { display: flex; gap: 2px; align-items: center; min-width: 0; }
.emb-row i { flex: 1; height: 1.1rem; min-width: 4px; border: 1px solid rgba(var(--accent-rgb), .08); }
.emb-row .more { color: var(--dim); font-size: var(--fs-0); padding-left: .3rem; }

.att { display: grid; grid-template-columns: auto repeat(var(--cols), minmax(0, 1fr)); gap: 3px; align-items: center; overflow-x: auto; }
.att-col { font-size: 11px; color: var(--bright); text-align: center; white-space: pre; overflow: hidden; text-overflow: ellipsis; padding-bottom: .2rem; }
.att-row { font-size: 11px; color: var(--dim); padding-right: .5rem; white-space: nowrap; }
.att i { display: block; height: 1.35rem; min-width: 10px; background: var(--accent); box-shadow: inset 0 0 0 1px rgba(5, 10, 7, .4); }

.bars { display: grid; gap: 4px; }
.bar { display: grid; grid-template-columns: 9ch minmax(0, 1fr) 6ch; gap: .7rem; align-items: center; font-size: var(--fs-0); font-variant-numeric: tabular-nums; }
.bar-tok { color: var(--bright); white-space: pre; overflow: hidden; text-overflow: ellipsis; text-align: right; }
.bar-track { height: 1rem; border-left: 1px solid var(--rule-hi); }
.bar-fill { display: block; height: 100%; background: var(--rule-hi); border-radius: 0 4px 4px 0; }
.bar-pct { color: var(--dim); text-align: right; }
.bar.picked .bar-fill { background: var(--accent); box-shadow: var(--glow-accent); }
.bar.picked .bar-tok, .bar.picked .bar-pct { color: var(--accent); }

.loop { display: grid; gap: .8rem; }
.loop-row { display: flex; flex-wrap: wrap; align-items: center; gap: .6rem; font-size: var(--fs-0); }
.lbox { border: 1px solid var(--rule-hi); padding: .45rem .65rem; color: var(--ink); white-space: pre-wrap; overflow-wrap: anywhere; }
.lbox b { color: var(--accent); font-weight: inherit; text-decoration: underline; text-decoration-thickness: 2px; text-underline-offset: 4px; }  /* the token it just added */
.lbox.model { color: var(--bright); background: var(--rule); }
.lbox.pick { color: var(--ground); background: var(--accent); border-color: var(--accent); font-weight: 600; min-width: 2.6em; text-align: center; white-space: pre; }
.arrow { color: var(--accent); font-size: 1.1rem; }

/* ------------------------------------------------------------------ the math, folded under steps 3 and 4 */
.math { grid-column: 1 / -1; }
.math > summary {
  list-style: none; cursor: pointer; width: fit-content;
  display: flex; align-items: baseline; flex-wrap: wrap; gap: .2rem .8rem;
  padding: .5rem 0; font: 500 var(--fs-0)/1.4 var(--mono);
}
.math > summary::-webkit-details-marker { display: none; }
.m-sign { color: var(--accent); }
.m-sign::before { content: "[+]"; }
.math[open] .m-sign::before { content: "[−]"; }
.m-title { color: var(--accent); }
.math > summary:hover .m-title { text-decoration: underline; text-underline-offset: 3px; }
.m-sub { color: var(--dim); }
.math[open] .m-open, .math:not([open]) .m-close { display: none; }
.math-body {
  display: grid; gap: 1rem; margin-top: .3rem; padding: 1.1rem 1.2rem 1.2rem;
  background: var(--panel); border: 1px solid var(--rule); border-left: 2px solid var(--accent);
  animation: unfold .25s ease-out;
}
@keyframes unfold { from { opacity: 0; transform: translateY(-4px); } }
.math-src { margin: 0; font-size: var(--fs-0); color: var(--dim); }
.math-src a { color: var(--accent); }
.eq {
  font: 400 clamp(1.2rem, 2.6vw, 1.55rem)/1.2 var(--math); color: var(--bright);
  display: flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: .15em .25em;
  padding: .9rem 1rem; background: var(--ground); border: 1px solid var(--rule); overflow-x: auto;
}
.eq var, .syms var, .math-note var { font-family: var(--math); font-style: italic; }
.eq sub, .eq sup { font-size: .6em; }
.fn { font-family: var(--math); font-style: normal; }
.frac { display: inline-grid; text-align: center; vertical-align: middle; margin: 0 .1em; }
.frac > span { padding: 0 .25em; }
.frac > span:first-child { border-bottom: 1px solid currentColor; padding-bottom: .1em; }
.frac > span:last-child { padding-top: .1em; }
.paren { font-size: 1.6em; font-weight: 300; line-height: 1; }
.big { font-size: 1.25em; }
.q { color: var(--warn); }
.k { color: var(--cool); }
.v { color: var(--accent); }
.d { color: var(--dim); }
.syms { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .5rem; }
.symc { display: grid; gap: .2rem; align-content: start; padding: .6rem .75rem; border: 1px solid var(--rule); background: var(--ground); }
.sym-k { font: 400 1.15rem/1.1 var(--math); color: var(--bright); min-height: 1.4rem; }
.sym-k sub, .sym-k sup { font-size: .6em; }
.symc b { font: 600 var(--fs-0)/1.3 var(--mono); color: var(--bright); }
.symc p { margin: 0; font-size: 12px; line-height: 1.5; color: var(--ink); }
.math-note { margin: 0; font-size: var(--fs-0); color: var(--dim); line-height: 1.65; max-width: var(--measure); }
.math-note a { color: var(--accent); }
.sm-tab { border-collapse: collapse; font-size: var(--fs-0); font-variant-numeric: tabular-nums; min-width: 30rem; }
.sm-tab th, .sm-tab td { padding: .45rem 1.1rem .45rem 0; text-align: right; border-bottom: 1px solid var(--rule); white-space: nowrap; }
.sm-tab th:first-child, .sm-tab td:first-child { text-align: left; }
.sm-tab thead th { font-weight: 400; color: var(--dim); }
.sm-tab td.tok { color: var(--bright); white-space: pre; }
.sm-tab td.res { color: var(--accent); font-weight: 600; }
.sm-tab .op { color: var(--dim); padding-right: .6rem; }
.sm-tab sup { font-size: .7em; }

/* ------------------------------------------------------------------ training */
.replay { display: grid; gap: .8rem; }
.replay-ctl { display: grid; grid-template-columns: 1fr auto; gap: .5rem 1.25rem; align-items: center; }
.readout { display: flex; align-items: baseline; gap: .4rem; font-variant-numeric: tabular-nums; }
.readout .big { font: 400 2.1rem/1 var(--crt); color: var(--phos); text-shadow: var(--glow-phos); min-width: 3.2ch; text-align: right; }
.readout .unit { color: var(--dim); font-size: var(--fs-0); margin-right: .8rem; }
.replay-out { background: var(--panel); border: 1px solid var(--rule); border-top: 2px solid var(--phos); padding-inline: 1.1rem; min-height: 11rem; }
/* the training slider: a big glowing handle so it clearly looks draggable */
.slide-hint { grid-column: 1 / -1; color: var(--phos); font: 600 var(--fs-1)/1.4 var(--mono); }
input[type="range"] {
  -webkit-appearance: none; appearance: none; width: 100%; height: 2.25rem; margin: 0;
  background: transparent; cursor: grab;
}
input[type="range"]:active { cursor: grabbing; }
input[type="range"]::-webkit-slider-runnable-track { height: 6px; background: var(--rule-hi); border-radius: 3px; }
input[type="range"]::-moz-range-track { height: 6px; background: var(--rule-hi); border-radius: 3px; }
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 22px; height: 22px; margin-top: -8px; border-radius: 50%;
  background: var(--phos); border: 3px solid var(--ground); box-shadow: 0 0 0 1px var(--phos), var(--glow-phos);
}
input[type="range"]::-moz-range-thumb {
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--phos); border: 3px solid var(--ground); box-shadow: 0 0 0 1px var(--phos), var(--glow-phos);
}
input[type="range"]:focus-visible { outline: none; }
input[type="range"]:focus-visible::-webkit-slider-thumb { box-shadow: 0 0 0 3px var(--phos), var(--glow-phos); }

.charts { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.chart { margin: 0; min-width: 0; background: var(--panel); border: 1px solid var(--rule); padding: .9rem; display: grid; gap: .6rem; }
.chart figcaption { font-size: var(--fs-0); color: var(--dim); }
.plot { position: relative; }
.plot svg { display: block; width: 100%; height: auto; overflow: visible; }
.plot .grid line { stroke: var(--rule); stroke-width: 1; }
.plot .axis text { fill: var(--dim); font: 400 11px var(--mono); }
.plot .series { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.plot .lbl { font: 500 11px var(--mono); }
.plot .ann line { stroke: var(--warn); stroke-dasharray: 2 3; }
.plot .ann text { fill: var(--warn); font: 400 11px var(--mono); }
.plot .hair { stroke: var(--rule-hi); stroke-width: 1; }
.plot .dot { stroke: var(--panel); stroke-width: 2; }
.plot .hit { fill: transparent; cursor: crosshair; }
.legend { display: flex; flex-wrap: wrap; gap: 1rem; font-size: var(--fs-0); color: var(--dim); }
.legend i { display: inline-block; width: 1.4em; height: 0; border-top: 2px solid; vertical-align: middle; margin-right: .4em; }
.legend i.dash { border-top-style: dashed; }
.tip { position: absolute; pointer-events: none; z-index: 5; background: var(--ground); border: 1px solid var(--rule-hi); padding: .45rem .6rem; font-size: var(--fs-0); line-height: 1.5; white-space: nowrap; font-variant-numeric: tabular-nums; }

/* ------------------------------------------------------------------ the two models, side by side */
.key { margin: 0; display: flex; gap: 1.5rem; font-size: var(--fs-0); color: var(--bright); }
.cmp { display: grid; gap: 3rem; }
.cmp-row { display: grid; grid-template-columns: minmax(0, 4fr) minmax(0, 8fr); gap: 1.25rem 2.5rem; padding-top: 1.5rem; border-top: 1px solid var(--rule); }
.cmp-text { display: grid; gap: .5rem; align-content: start; }
.cmp-text h3 { margin: 0; font: 600 var(--fs-2)/1.35 var(--mono); color: var(--bright); }
.cmp-text p { margin: 0; font-size: var(--fs-text); line-height: 1.7; }
.cmp-vis { min-width: 0; display: grid; gap: 1rem; align-content: start; }
[data-model="shakespeare"] { --m: var(--red); --m-rgb: 255, 59, 92; }
[data-model="tinystories"] { --m: var(--phos); --m-rgb: 57, 255, 122; }

.files { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; }
.file { margin: 0; border: 1px solid var(--rule); border-top: 2px solid var(--m); background: var(--panel); min-width: 0; }
.file figcaption { padding: .45rem .7rem; border-bottom: 1px solid var(--rule); font-size: var(--fs-0); color: var(--bright); }
.file pre {
  margin: 0; padding: .7rem; height: 8rem; overflow: hidden;
  font: 400 12px/1.55 var(--mono); color: var(--ink); white-space: pre-wrap;
  -webkit-mask-image: linear-gradient(to bottom, #000 55%, transparent); mask-image: linear-gradient(to bottom, #000 55%, transparent);
}
.scale { display: grid; gap: .5rem; }
.scale-row { display: grid; grid-template-columns: 7.5rem minmax(0, 1fr) auto; gap: .8rem; align-items: start; }
.scale-key { margin: 0 0 .2rem; font-size: var(--fs-0); color: var(--ink); }
.key-dot { display: inline-block; width: 6px; height: 6px; background: var(--ink); vertical-align: middle; margin: 0 .2rem; }
.scale-n { font-size: var(--fs-0); color: var(--dim); white-space: nowrap; }
.scale-label { font-size: var(--fs-0); color: var(--dim); }
.dots { display: flex; flex-wrap: wrap; gap: 1px; }
.dots i { width: 5px; height: 5px; background: var(--m); opacity: .85; }
.scale-row[data-model="shakespeare"] .dots i { box-shadow: 0 0 6px rgba(var(--m-rgb), .8); }

.split { display: grid; grid-template-columns: 3ch minmax(0, 1fr); gap: .8rem; align-items: start; }
.split + .split { margin-top: .6rem; }
.split-n { font: 400 1.8rem/1 var(--crt); color: var(--m); text-shadow: 0 0 6px rgba(var(--m-rgb), .45); text-align: right; }
.tbs { display: flex; flex-wrap: wrap; gap: 3px; }
.tb { padding: .25rem .3rem; font-size: var(--fs-0); white-space: pre; color: var(--bright); background: rgba(var(--m-rgb), .14); border: 1px solid rgba(var(--m-rgb), .35); }
.tb:nth-child(even) { background: rgba(var(--m-rgb), .26); }

.stacks { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; align-items: end; }
.layers { display: flex; flex-direction: column-reverse; gap: 4px; align-items: center; }
.layers span { display: block; height: 1.6rem; background: rgba(var(--m-rgb), .18); border: 1px solid rgba(var(--m-rgb), .6); color: var(--bright); font-size: 11px; line-height: 1.6rem; text-align: center; }
.stack p { margin: .7rem 0 0; text-align: center; font-size: var(--fs-0); color: var(--dim); }
.stack p b { color: var(--m); font: 400 1.5rem/1 var(--crt); }

.bars2 { display: grid; gap: .6rem; }
.b2 { display: grid; grid-template-columns: minmax(0, 1fr) 13rem; gap: .8rem; align-items: center; }
.b2-fill { display: block; height: 1.1rem; background: var(--m); border-radius: 0 4px 4px 0; box-shadow: 0 0 6px rgba(var(--m-rgb), .45); position: relative; overflow: hidden; }
.b2-fill.partial { background: rgba(var(--m-rgb), .18); box-shadow: none; border: 1px dashed rgba(var(--m-rgb), .6); }
.b2-fill .done { position: absolute; inset: 0 auto 0 0; background: var(--m); }
.b2-val { font-size: var(--fs-0); color: var(--ink); font-variant-numeric: tabular-nums; }
.shrink { display: grid; grid-template-columns: 7.5rem minmax(0, 1fr); gap: .8rem; align-items: center; }
.shrink + .shrink { margin-top: .9rem; }
.shrink-bars { display: grid; gap: .4rem; min-width: 0; }
.window { margin: 0; padding: .8rem; background: var(--panel); border: 1px solid var(--rule); font-size: 12px; line-height: 1.7; }
.w-both { background: rgba(255, 59, 92, .22); color: var(--bright); box-shadow: inset 0 -2px 0 rgba(57, 255, 122, .7); }
.w-bpe { box-shadow: inset 0 -2px 0 rgba(57, 255, 122, .7); color: var(--ink); }
.w-none { color: #2c5a3e; }

.scroll-x { overflow-x: auto; min-width: 0; }  /* wide tables scroll inside themselves, never the page */

.end p { margin: 0; max-width: var(--measure); font-size: var(--fs-text); }
.intro a, .refs a { color: var(--phos); text-decoration: underline; text-decoration-color: rgba(57, 255, 122, .4); text-underline-offset: 3px; }
.intro a:hover, .refs a:hover { text-decoration-color: var(--phos); color: var(--bright); }
.refs { display: grid; gap: .6rem; }  /* full width: each reference fits on one line on a laptop */
.credit { margin: 0; padding-top: 1.25rem; border-top: 1px solid var(--rule); color: var(--ink); font-size: var(--fs-text); }
.sig { font: 400 1.65em/1 var(--crt); color: var(--phos); text-shadow: var(--glow-phos); letter-spacing: .02em; vertical-align: -.08em; text-decoration: none; border-bottom: 1px dashed rgba(57, 255, 122, .5); }
.sig:hover { color: var(--bright); border-bottom-style: solid; border-bottom-color: var(--phos); }
.refs h2 { margin: 0; font: 600 var(--fs-0)/1.4 var(--mono); color: var(--dim); }
.refs ol { margin: 0; padding-left: 1.4rem; display: grid; gap: .4rem; font-size: var(--fs-0); line-height: 1.6; }
.refs li::marker { color: var(--dim); }

/* ------------------------------------------------------------------ tmux bar */
/* the tmux status bar, docked at the top (tmux's status-position top) */
body::before { content: ""; position: fixed; inset: 0 0 auto; height: env(safe-area-inset-top, 0px); z-index: 41; background: var(--phos); }
.tmux {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 40;
  display: flex; align-items: center; justify-content: space-between; gap: 1rem; min-height: var(--bar-h);
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  background: var(--phos); color: var(--ground);
  font: 500 var(--fs-1)/1 var(--mono);
}
.tmux-session { font: 400 1.6rem/1 var(--crt); color: var(--ground); text-decoration: none; white-space: nowrap; }
.tmux-session:hover { text-decoration: underline; text-underline-offset: 4px; }
.tmux-windows { list-style: none; margin: 0; padding: 0; display: flex; gap: .5rem; }
/* the two section links are real buttons: dark on the green bar, inverting on hover */
.tmux-windows a {
  display: block; white-space: nowrap; text-decoration: none; cursor: pointer;
  color: var(--phos); background: var(--ground); border: 1px solid var(--ground);
  padding: .55rem .9rem; font-weight: 600; transition: background-color .15s, color .15s;
}
.tmux-windows a:hover { background: transparent; color: var(--ground); }
.tmux-windows a:active { transform: translateY(1px); }
.tmux-windows a[aria-current="true"] { box-shadow: 0 0 0 2px var(--ground), 0 0 0 4px rgba(5, 10, 7, .25); }
.tmux-windows a:focus-visible { outline: 2px solid var(--ground); outline-offset: -2px; }

/* ------------------------------------------------------------------ narrow */
@media (max-width: 820px) {
  .step { grid-template-columns: 1fr; }
  .charts { grid-template-columns: 1fr; }
  .cmp-row { grid-template-columns: 1fr; }
  .syms { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 560px) {
  /* phones: the model buttons stack full width, and the highlight slides up and down */
  .seg-row { display: grid; width: 100%; }
  .seg { display: grid; grid-template-columns: 1fr; width: 100%; }
  .seg button { justify-content: center; padding: .9rem 1rem; }
  .screen { gap: 4.5rem; padding-top: 2rem; }
  .field .ps1 { display: none; }
  .field .go { padding: .75rem .9rem; }
  .replay-ctl { grid-template-columns: 1fr; }
  .tmux { font-size: var(--fs-0); gap: .5rem; }
  .tmux-session { font-size: 1.3rem; }
  .tmux-windows { gap: .35rem; }
  .tmux-windows a { padding: .5rem .55rem; }
  .bar { grid-template-columns: 7ch minmax(0, 1fr) 5.5ch; }
  .files { grid-template-columns: 1fr; }
  .syms { grid-template-columns: 1fr; }
  .b2 { grid-template-columns: minmax(0, 1fr) 9.5rem; }
  .scale-row { grid-template-columns: 1fr; gap: .3rem; }
  .shrink { grid-template-columns: 1fr; gap: .3rem; }
}
@media (prefers-reduced-motion: reduce) {
  .boot-log span { animation: none; opacity: 1; }
  .cursor, .title-cursor { animation: none; }
  .math-body { animation: none; }
  .seg-thumb { transition: none; }
  .console-inner, .console-body::after, .pick-label.swap, .steps.switching, .seg-thumb.flash { animation: none !important; }
  .console-body::after { display: none; }
}
