/* Same light palette as the other tools. Tokens are pastel chips cycling
   through five colours, the model's picks are blue, and the figures sit on a
   dark card like the slide they go with. */
:root {
  color-scheme: light;
  --ink: #15202a;
  --muted: #61707d;
  --line: #d8e0e6;
  --line-strong: #a8b5bf;
  --paper: #f4f7f9;
  --surface: #ffffff;
  --sidebar: #edf2f5;
  --accent-dark: #c94f10;
  --model: #2d79ff;
  --shadow: 0 12px 34px rgba(20, 32, 42, 0.1);
  --mono: ui-monospace, "Cascadia Mono", "SF Mono", Menlo, Consolas, monospace;

  --card: #121a22;
  --card-ink: #d9e2ea;
  --card-muted: #8fa3b5;
  --card-line: rgba(255, 255, 255, 0.1);

  --chip-0: #ffd9c2;
  --chip-1: #cfe0ff;
  --chip-2: #d5f0dc;
  --chip-3: #eedcff;
  --chip-4: #fff0b8;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body {
  background: var(--paper);
  color: var(--ink);
  font-size: 17px;
}

[hidden] { display: none !important; }
button, input { font: inherit; }
h2, h3, p { margin: 0; }

.eyebrow { color: var(--muted); font-size: 0.75rem; font-weight: 800; letter-spacing: 0.12em; text-transform: uppercase; }

.button {
  min-height: 40px;
  padding: 8px 14px;
  border: 1px solid transparent;
  border-radius: 3px;
  font-size: 0.9rem;
  font-weight: 750;
  cursor: pointer;
}
.button.primary { color: #1b120c; background: var(--accent); }
.button.secondary { color: var(--ink); background: var(--surface); border-color: var(--line-strong); }
.button:hover { filter: brightness(1.06); }
.button.secondary:hover { filter: none; background: var(--sidebar); }
.button:disabled { opacity: 0.4; cursor: default; filter: none; }
.button.secondary:disabled:hover { background: var(--surface); }

/* ---- Layout: step bar, the input strip, then text beside a figure ---- */
.tokens {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.strip {
  flex: none;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 18px;
  padding: 12px clamp(16px, 3vw, 36px);
  border-bottom: 1px solid var(--line);
  background: var(--sidebar);
}
.strip-chips { flex: 1; min-width: 0; display: flex; flex-wrap: wrap; align-items: stretch; gap: 3px; }
.strip-text { font-size: 1.2rem; font-weight: 600; }
.strip-count { color: var(--muted); font-weight: 700; font-variant-numeric: tabular-nums; }

.blank { display: inline-block; width: 3em; border-bottom: 3px solid currentColor; vertical-align: baseline; }

.stage {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(280px, 5fr) minmax(0, 6fr);
  gap: clamp(16px, 3vw, 36px);
  padding: 20px clamp(16px, 3vw, 36px);
}

.text-col { min-height: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 16px; }
.step-text { display: flex; flex-direction: column; gap: 16px; }
.step-text h2 { font-size: clamp(24px, 2.6vw, 34px); line-height: 1.15; letter-spacing: -0.02em; }
.body { max-width: 62ch; font-size: clamp(17px, 1.35vw, 20px); line-height: 1.55; }

.footnote { margin-top: auto; padding-top: 8px; font-size: 0.8rem; line-height: 1.5; color: var(--muted); }

.figure {
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: clamp(18px, 2.4vw, 32px);
  border-radius: 8px;
  background: var(--card);
  color: var(--card-ink);
  box-shadow: var(--shadow);
}
.fig-label { color: var(--card-muted); font-size: 0.75rem; font-weight: 800; letter-spacing: 0.12em; text-transform: uppercase; }
.fig-caption { color: var(--card-muted); font-size: 0.9rem; line-height: 1.5; font-style: italic; }
.fig-formula { font-size: 1.05rem; line-height: 1.5; }
.fig-sentence { font-family: var(--mono); font-size: clamp(22px, 2.2vw, 30px); line-height: 1.5; }
.fig-sentence.small { font-size: clamp(17px, 1.5vw, 21px); }
.fig-sentence .added { color: #8fb6ff; font-weight: 700; }

/* ---- Tokens ---- */
.chips { display: inline-flex; flex-wrap: wrap; gap: 3px; vertical-align: middle; }
.chip {
  --chip: var(--chip-0);
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  min-width: 1.4em;
  padding: 3px 6px;
  border-radius: 4px;
  background: var(--chip);
  color: var(--ink);
  font-family: var(--mono);
  font-size: 0.95rem;
  line-height: 1.3;
  white-space: pre;
}
.chip[data-i="1"] { --chip: var(--chip-1); }
.chip[data-i="2"] { --chip: var(--chip-2); }
.chip[data-i="3"] { --chip: var(--chip-3); }
.chip[data-i="4"] { --chip: var(--chip-4); }
.chip-id { font-family: Inter, ui-sans-serif, system-ui, sans-serif; font-size: 0.68rem; font-weight: 700; color: #4d5b67; font-variant-numeric: tabular-nums; }
.ws { color: rgba(21, 32, 42, 0.38); }
.special { font-family: Inter, ui-sans-serif, system-ui, sans-serif; font-size: 0.8em; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase; }
.chip.is-new { --chip: var(--model); color: #fff; }
.chip.is-new .chip-id, .chip.is-new .ws { color: rgba(255, 255, 255, 0.78); }
.chip.is-latest { animation: pop-in 350ms ease-out; }
.chip.next { background: transparent; border: 2px dashed var(--line-strong); color: var(--muted); min-width: 3em; font-weight: 700; }
.chips.big .chip { font-size: clamp(18px, 1.7vw, 24px); padding: 6px 9px; }
@keyframes pop-in { from { opacity: 0; transform: translateY(-6px); } }
@media (prefers-reduced-motion: reduce) { .chip.is-latest { animation: none; } }

/* A token named in running text, on the light side or the dark card. */
q.tq { quotes: none; font-family: var(--mono); font-size: 0.92em; font-weight: 650; padding: 0 3px; border-radius: 3px; background: var(--sidebar); }
.figure q.tq { background: rgba(255, 255, 255, 0.1); }
.figure .ws, .figure q.tq .ws { color: rgba(217, 226, 234, 0.45); }
.figure .chip .ws { color: rgba(21, 32, 42, 0.38); }

/* ---- Step 2: stats and notes ---- */
.stats { display: flex; flex-wrap: wrap; gap: 12px 36px; margin: 0; }
.stats dt { color: var(--card-muted); font-size: 0.75rem; font-weight: 800; letter-spacing: 0.12em; text-transform: uppercase; }
.stats dd { margin: 0; font-size: 2rem; font-weight: 750; font-variant-numeric: tabular-nums; }
.stats div:last-child dd { color: var(--accent); }
.notes { display: grid; gap: 10px; margin: 0; padding-left: 1.2em; line-height: 1.5; }

/* ---- Step 3: merges ---- */
.merges { display: grid; gap: 6px; margin: 0; padding: 0; list-style: none; }
.merges li {
  display: grid;
  grid-template-columns: minmax(9em, 13em) 1fr;
  align-items: center;
  gap: 12px;
  animation: fade-in 300ms ease-out both;
  animation-delay: calc(var(--d) * 120ms);
}
.merge-rule { color: var(--card-muted); font-size: 0.85rem; font-weight: 650; }
.merge-rule .ws { color: var(--card-muted); }
.chip.is-merged { box-shadow: 0 0 0 2px var(--accent); }
@keyframes fade-in { from { opacity: 0; transform: translateX(-6px); } }
@media (prefers-reduced-motion: reduce) { .merges li { animation: none; } }

/* ---- Step 4: IDs ---- */
.ids { margin: 0; padding: 12px 14px; border-radius: 4px; background: rgba(255, 255, 255, 0.06); font-family: var(--mono); font-size: 0.95rem; white-space: pre-wrap; overflow-wrap: anywhere; color: #ffb27d; }
.vocab { columns: 2 14em; column-gap: 28px; margin: 0; padding: 0; list-style: none; }
.vocab li { display: flex; align-items: center; gap: 12px; padding: 3px 6px; break-inside: avoid; border-radius: 4px; }
.vocab li.is-used { background: rgba(255, 122, 47, 0.14); }
.vocab li.gap { color: var(--card-muted); padding-left: 1.5em; }
.vocab-id { min-width: 4.5em; text-align: right; font-variant-numeric: tabular-nums; color: var(--card-muted); font-weight: 700; }
.vocab li.is-used .vocab-id { color: #ffb27d; }

/* ---- Step 5: the map ---- */
.map { width: 100%; height: auto; max-height: 440px; }
.map circle { fill: #6d8196; }
.map text { fill: var(--card-muted); font-size: 11px; font-family: var(--mono); }
.map .is-used circle { fill: var(--accent); }
.map .is-used text { fill: #fff; font-weight: 700; }
.map .map-group { fill: rgba(217, 226, 234, 0.35); font-family: Inter, ui-sans-serif, system-ui, sans-serif; font-size: 10px; font-weight: 800; letter-spacing: 0.12em; text-transform: uppercase; }
.key { display: inline-block; width: 10px; height: 10px; border-radius: 50%; background: var(--accent); vertical-align: middle; }

/* ---- Step 6: the pass ---- */
.pipe { display: grid; grid-template-columns: repeat(var(--cols), minmax(0, 1fr)); gap: 6px 4px; align-items: end; }
.pipe-tok { font-family: var(--mono); font-size: 0.72rem; text-align: center; overflow: hidden; white-space: nowrap; }
.pipe-id { font-size: 0.66rem; font-weight: 700; text-align: center; color: #ffb27d; font-variant-numeric: tabular-nums; overflow: hidden; }
.pipe-note { grid-column: 1 / -1; padding: 4px 0; color: var(--card-muted); font-size: 0.85rem; }
.pipe-note.is-end { text-align: right; color: var(--card-ink); font-weight: 650; }
.vec { display: flex; flex-direction: column; gap: 2px; padding: 3px; border-radius: 3px; background: rgba(255, 255, 255, 0.05); }
.vec i { display: block; height: 7px; border-radius: 1px; }
.is-faded { opacity: 0.35; }
.is-last .vec { box-shadow: 0 0 0 2px var(--accent); }

.scores { display: grid; gap: 4px; margin: 0; padding: 0; list-style: none; font-family: var(--mono); }
.scores li { display: flex; justify-content: space-between; gap: 16px; padding: 4px 10px; border-radius: 3px; background: rgba(255, 255, 255, 0.05); }
.scores li:first-child { color: #fff; font-weight: 700; }
.scores li.gap { background: none; color: var(--card-muted); font-family: Inter, ui-sans-serif, system-ui, sans-serif; font-size: 0.85rem; }
.score { font-variant-numeric: tabular-nums; }

/* ---- Probability bars (steps 8 to 10) ---- */
.bars { display: grid; grid-template-columns: max-content minmax(60px, 1fr) 5.5em; align-items: center; gap: 8px 14px; }
.bars.has-tally { grid-template-columns: max-content minmax(60px, 1fr) 5.5em 2.5em; }
.bar-label { font-family: var(--mono); font-size: 1rem; }
.bar-label.is-rest { font-family: Inter, ui-sans-serif, system-ui, sans-serif; font-size: 0.85rem; color: var(--card-muted); }
.bar-track { display: block; height: 16px; border-radius: 3px; background: rgba(255, 255, 255, 0.07); overflow: hidden; }
.bar-fill { display: block; height: 100%; border-radius: 3px; background: #6d8196; transition: width 250ms ease; }
.bar-track.is-top .bar-fill, .bar-track.is-pick .bar-fill { background: var(--accent); }
.bar-track.is-rest .bar-fill { background: #4a5a6a; }
.bar-pct { text-align: right; font-variant-numeric: tabular-nums; color: var(--card-muted); }
.bar-label.is-top, .bar-label.is-pick { color: #fff; font-weight: 700; }
.bar-pct.is-top, .bar-pct.is-pick { color: var(--accent); font-weight: 700; }
.bar-tally { text-align: right; font-variant-numeric: tabular-nums; font-weight: 700; color: #8fb6ff; }

.temp { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; }
.temp label { font-weight: 750; }
.temp input { flex: 1; min-width: 140px; max-width: 320px; accent-color: var(--accent); }
.temp output { min-width: 2.2em; font-size: 1.3rem; font-weight: 750; font-variant-numeric: tabular-nums; color: var(--accent); }
.temp-note { color: var(--card-muted); font-style: italic; }
.roll { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 12px; }
.roll-result { font-weight: 650; }

/* ---- Step 7: softmax table ---- */
.softmax { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.softmax th { padding: 0 8px 8px; color: var(--card-muted); font-size: 0.72rem; font-weight: 800; letter-spacing: 0.1em; text-transform: uppercase; text-align: left; }
.softmax th i, .softmax th sup { text-transform: none; letter-spacing: 0; }
.softmax td { padding: 7px 8px; border-top: 1px solid var(--card-line); }
.softmax td:first-child { font-family: var(--mono); }
.softmax .n { text-align: right; white-space: nowrap; }
.softmax .share { font-weight: 700; }
.softmax .barcell { width: 30%; }
.softmax tr.is-top td { color: #fff; font-weight: 700; }
.softmax tr.is-top .share { color: var(--accent); }
.softmax tr.is-top .bar-fill { background: var(--accent); }
.softmax tr.is-rest td:first-child { font-family: inherit; font-size: 0.85rem; color: var(--card-muted); }
.softmax tfoot td { border-top: 2px solid rgba(255, 255, 255, 0.3); font-weight: 750; font-family: inherit; }
.softmax tfoot .bar-fill { background: #4a5a6a; }

/* ---- Step 10: the passes ---- */
.rounds { display: grid; gap: 16px; margin: 0; padding: 0; list-style: none; }
.rounds li { display: grid; gap: 8px; padding: 12px 14px; border-radius: 6px; background: rgba(255, 255, 255, 0.05); transition: opacity 300ms ease; }
.rounds li.is-waiting { opacity: 0.12; }
.round-head { color: var(--card-muted); }
.round-head b { color: var(--card-ink); }
#replay { align-self: flex-start; }

/* ---- Step 11: quirks ---- */
.quirks { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 14px; }
.quirk { display: flex; flex-direction: column; gap: 10px; padding: 16px; border-radius: 6px; background: rgba(255, 255, 255, 0.05); line-height: 1.5; }
.quirk h3 { font-size: 1.05rem; color: #fff; }
.quirk p { font-size: 0.92rem; color: var(--card-ink); }
.quirk-vs { color: var(--card-muted); }

/* ---- Narrow screens: everything in one scrolling column ---- */
@media (max-width: 760px) {
  .tokens { overflow-y: auto; }
  .stage { flex: none; grid-template-columns: 1fr; }
  .text-col, .figure { overflow: visible; }
  .pipe-tok { display: none; }
  .merges li { grid-template-columns: 1fr; gap: 4px; }
}
