/* Transformer Lab — a small book with live numbers */

:root {
  --paper: #fffdf8;
  --bg: #f6f1e7;
  --ink: #2a2622;
  --ink-soft: #4d463f;
  --muted: #7a7166;
  --line: #e6dfd2;
  --line-strong: #d3c9b8;
  --accent: #0f766e;
  --accent-rgb: 15, 118, 110;
  --accent-soft: #e3f2ef;
  --warm: #c2552e;
  --warm-soft: #fbe9e0;
  --pos-rgb: 194, 85, 46;
  --neg-rgb: 59, 111, 214;
  --amber-soft: #fdf3d7;
  --amber: #9a6b12;
  --hl: #fff6cf;
  --flash: rgba(255, 196, 0, 0.45);
  --serif: "Source Serif 4", "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --display: "Fraunces", "Iowan Old Style", Georgia, serif;
  --sans: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(40, 30, 10, .06), 0 8px 24px -12px rgba(40, 30, 10, .18);
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #1e1b17;
    --bg: #15130f;
    --ink: #ece6da;
    --ink-soft: #cfc7b8;
    --muted: #9a9082;
    --line: #322d26;
    --line-strong: #47403a;
    --accent: #3fb8a8;
    --accent-rgb: 63, 184, 168;
    --accent-soft: #163330;
    --warm: #ef8a63;
    --warm-soft: #3a2118;
    --pos-rgb: 239, 138, 99;
    --neg-rgb: 121, 160, 255;
    --amber-soft: #33290f;
    --amber: #e5b04a;
    --hl: #3a3218;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px -12px rgba(0,0,0,.6);
  }
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 17px/1.65 var(--serif);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration-thickness: 1px; text-underline-offset: 3px; }
strong { font-weight: 600; }
code, .num, .mono { font-family: var(--mono); font-size: .88em; }
h1, h2, h3, .display { font-family: var(--display); font-weight: 600; letter-spacing: -.01em; line-height: 1.15; }
h2 { font-size: 1.75rem; margin: 0 0 .5rem; }
h3 { font-size: 1.15rem; margin: 1.4rem 0 .4rem; }
p { margin: 0 0 1rem; }
button, select, input[type=number], input[type=text], textarea {
  font: 15px/1.4 var(--sans); color: inherit; background: var(--paper);
  border: 1px solid var(--line-strong); border-radius: 8px; padding: .45rem .7rem;
}
button { cursor: pointer; transition: background .15s, transform .05s; }
button:hover { background: var(--bg); }
button:active { transform: translateY(1px); }
button.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
button.primary:hover { filter: brightness(1.08); background: var(--accent); }
button.ghost { background: transparent; border-color: transparent; color: var(--muted); padding: .2rem .5rem; }
button.danger { color: var(--warm); }
button:disabled { opacity: .5; cursor: default; }
textarea { width: 100%; min-height: 3.4rem; resize: vertical; font-family: var(--serif); font-size: 1.15rem; }
label { display: flex; flex-direction: column; gap: .25rem; font: 13px/1.3 var(--sans); color: var(--muted); }
label > input, label > select { color: var(--ink); }
label.inline { flex-direction: row; align-items: center; gap: .5rem; font-size: 14px; color: var(--ink-soft); }

/* ---------- top bar ---------- */
#nav {
  position: sticky; top: 0; z-index: 10; background: color-mix(in srgb, var(--paper) 88%, transparent);
  backdrop-filter: blur(10px); border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 1.2rem; padding: .55rem 1.5rem; font-family: var(--sans);
}
#nav .brand { font-family: var(--display); font-weight: 700; font-size: 1.05rem; color: var(--ink); text-decoration: none; }
#nav nav { display: flex; gap: .15rem; flex-wrap: wrap; }
#nav nav a { font-size: 13.5px; color: var(--muted); text-decoration: none; padding: .3rem .65rem; border-radius: 999px; }
#nav nav a:hover { color: var(--ink); background: var(--bg); }
#nav nav a.active { color: var(--accent); background: var(--accent-soft); font-weight: 600; }
#nav nav a .n { display: inline-block; width: 1.25rem; height: 1.25rem; border-radius: 50%; border: 1px solid currentColor; font-size: 11px; line-height: 1.2rem; text-align: center; margin-right: .35rem; }
.nav-sentence { margin-left: auto; color: var(--muted); font-style: italic; font-family: var(--serif); font-size: .95rem; }

/* ---------- page ---------- */
main.page { max-width: 1080px; margin: 0 auto; padding: 2.5rem 1.5rem 5rem; }
.chapter-head { margin-bottom: 2rem; max-width: 46rem; }
.eyebrow { font: 600 12px/1 var(--sans); letter-spacing: .14em; text-transform: uppercase; color: var(--accent); margin-bottom: .8rem; }
.chapter-head h1 { font-size: clamp(2rem, 4.5vw, 3rem); margin: 0 0 .6rem; }
.dek { font-size: 1.2rem; color: var(--ink-soft); margin: 0; line-height: 1.5; }

.lesson { margin: 0 0 3rem; }
.lesson > h2 { margin-top: 0; }
.prose { max-width: 42rem; }
.prose p:last-child { margin-bottom: 0; }
.prose ul, .prose ol { padding-left: 1.3rem; margin: 0 0 1rem; }
.prose li { margin-bottom: .3rem; }
.tag { display: inline-block; font: 600 11px/1 var(--sans); letter-spacing: .08em; text-transform: uppercase; padding: .3rem .5rem; border-radius: 6px; background: var(--bg); color: var(--muted); vertical-align: middle; }
.tag.stored { background: var(--warm-soft); color: var(--warm); }
.tag.derived { background: var(--accent-soft); color: var(--accent); }

.card {
  background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1.25rem 1.4rem; box-shadow: var(--shadow); margin: 1.25rem 0;
}
.card.flush { padding: 1rem 1.1rem; }
.figure { margin: 1.25rem 0; }
.figure.recalc, .card.recalc { animation: flash 1.2s ease-out; }
@keyframes flash {
  0% { box-shadow: 0 0 0 4px var(--flash); background: var(--hl); }
  100% { box-shadow: var(--shadow); background: var(--paper); }
}
.figure-row { display: flex; flex-wrap: wrap; gap: 1.1rem; align-items: flex-start; }
.figure-row > .op { align-self: center; font-family: var(--display); font-size: 1.7rem; color: var(--muted); padding: 0 .1rem; }
.fig-caption { font: 13.5px/1.5 var(--sans); color: var(--muted); max-width: 42rem; margin: .5rem 0 0; }

/* ---------- callouts ---------- */
.callout {
  border-radius: var(--radius); padding: 1rem 1.2rem 1rem 1.1rem; margin: 1.25rem 0; max-width: 46rem;
  border: 1px solid transparent; font-size: 1rem; position: relative;
}
.callout .label { font: 700 12px/1 var(--sans); letter-spacing: .12em; text-transform: uppercase; margin-bottom: .45rem; display: flex; align-items: center; gap: .45rem; }
.callout p:last-child, .callout ul:last-child { margin-bottom: 0; }
.callout.idea { background: var(--amber-soft); border-color: color-mix(in srgb, var(--amber) 25%, transparent); }
.callout.idea .label { color: var(--amber); }
.callout.try { background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 25%, transparent); }
.callout.try .label { color: var(--accent); }
.callout.key { background: var(--paper); border-color: var(--line-strong); border-left: 4px solid var(--ink); }
.callout.key .label { color: var(--ink-soft); }
.callout ul { padding-left: 1.2rem; margin: 0; }
.callout li { margin: .25rem 0; }

details.under-hood { margin: 1rem 0; max-width: 46rem; font-size: .95rem; }
details.under-hood summary { cursor: pointer; font: 600 13.5px/1.4 var(--sans); color: var(--muted); }
details.under-hood[open] summary { margin-bottom: .5rem; }
details.under-hood .formula { display: inline-block; background: var(--bg); padding: .35rem .6rem; border-radius: 6px; font-family: var(--mono); font-size: .9rem; margin: .2rem 0 .6rem; }

/* worked example */
.worked { font-family: var(--mono); font-size: .86rem; line-height: 1.9; background: var(--bg); border-radius: 10px; padding: .8rem 1rem; overflow-x: auto; max-width: 100%; }
.worked .lhs { color: var(--accent); font-weight: 600; }
.worked .term { white-space: nowrap; }
.worked b { font-weight: 600; color: var(--ink); }
.worked .a { color: rgb(var(--neg-rgb)); }
.worked .b { color: rgb(var(--pos-rgb)); }
.worked .eq { color: var(--muted); padding: 0 .3rem; }
.worked .result { font-weight: 700; }

/* ---------- matrices ---------- */
.matrix-wrap { margin: 0; min-width: 0; }
.matrix-wrap figcaption { display: flex; gap: .55rem; align-items: baseline; margin-bottom: .4rem; font-family: var(--sans); }
.mtitle { font-weight: 600; font-size: 14px; }
.shape { color: var(--muted); font-size: 12px; font-family: var(--mono); }
.badge { font: 600 10.5px/1 var(--sans); letter-spacing: .06em; text-transform: uppercase; color: var(--warm); background: var(--warm-soft); border-radius: 4px; padding: .25rem .4rem; }
.scroll { overflow-x: auto; max-width: 100%; }
table.matrix { border-collapse: separate; border-spacing: 2px; font-family: var(--mono); font-size: 12.5px; }
table.matrix th { color: var(--muted); font: 500 12px/1.2 var(--sans); padding: .2rem .4rem; text-align: right; white-space: nowrap; }
table.matrix thead th { text-align: center; padding-bottom: .35rem; }
table.matrix td {
  padding: .3rem .45rem; text-align: right; min-width: 3.4rem; border-radius: 5px;
  background: var(--heat, var(--bg)); font-variant-numeric: tabular-nums; color: var(--ink);
}
table.matrix.small td { min-width: 2.7rem; padding: .18rem .3rem; font-size: 11.5px; }
table.matrix tr.hl th { color: var(--accent); font-weight: 700; }
table.matrix tr.hl td { box-shadow: inset 0 0 0 1.5px var(--accent); }
table.matrix tr.dim td { opacity: .45; }
table.matrix.editable td { padding: 0; }
table.matrix.editable input {
  width: 4rem; border: 0; background: transparent; padding: .3rem .4rem; text-align: right;
  font-family: var(--mono); font-size: 12.5px; color: inherit; border-radius: 5px;
}
table.matrix.editable input:focus { outline: 2px solid var(--accent); background: var(--paper); }
p.note { color: var(--muted); font: 13px/1.5 var(--sans); margin: .4rem 0 0; max-width: 34ch; }

/* ---------- tokens / chips ---------- */
.chips { display: flex; flex-wrap: wrap; gap: .5rem; }
.chip {
  display: inline-flex; align-items: baseline; gap: .4rem; background: var(--paper); border: 1px solid var(--line-strong);
  border-radius: 10px; padding: .35rem .75rem; font-family: var(--serif); font-size: 1.05rem;
}
.chip small { font: 11px/1 var(--sans); color: var(--muted); }
.chip b { font-family: var(--mono); font-weight: 600; color: var(--accent); }
.chip.arrow { border-style: dashed; }

/* ---------- overview ---------- */
.hero { display: grid; grid-template-columns: 1.3fr 1fr; gap: 1.5rem; align-items: start; }
.toc { list-style: none; margin: 0; padding: 0; counter-reset: ch; }
.toc li { display: grid; grid-template-columns: 2.2rem 1fr auto; gap: .8rem; align-items: baseline; padding: .55rem .4rem; border-bottom: 1px solid var(--line); }
.toc li:last-child { border-bottom: 0; }
.toc li.recalc { animation: flash 1.2s ease-out; border-radius: 8px; }
.toc .idx { font: 600 12px/1 var(--mono); color: var(--muted); }
.toc a { font-family: var(--serif); font-size: 1.02rem; text-decoration: none; color: var(--ink); }
.toc a:hover { color: var(--accent); }
.toc .what { display: block; font: 13px/1.4 var(--sans); color: var(--muted); }
.toc .shape { align-self: center; }
.toc li.chapter { background: var(--bg); border-radius: 8px; margin-top: .4rem; border: 0; }
.toc li.chapter .idx { color: var(--accent); }
.toc li.chapter a { font-weight: 600; }
.controls { display: flex; flex-wrap: wrap; gap: 1rem 1.25rem; align-items: flex-end; }
.controls label { min-width: 7.5rem; }
.stack { display: flex; flex-direction: column; gap: .7rem; width: 100%; }
.kpis { display: flex; gap: 1.5rem 2.2rem; flex-wrap: wrap; }
.kpis div { display: flex; flex-direction: column; }
.kpis b { font-family: var(--display); font-size: 1.7rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.kpis span { color: var(--muted); font: 13px/1.3 var(--sans); }

.snapshots { list-style: none; padding: 0; margin: .8rem 0 0; display: flex; flex-direction: column; gap: .45rem; font-family: var(--sans); font-size: 14px; }
.snapshots li { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; padding: .5rem .7rem; background: var(--bg); border-radius: 10px; }
.snapshots li .meta { color: var(--muted); font-size: 12.5px; }
.snapshots li .spacer { flex: 1; }

/* ---------- prediction ---------- */
table.pred { border-collapse: collapse; font-family: var(--sans); font-size: 14.5px; width: 100%; max-width: 40rem; }
table.pred th { text-align: left; font-weight: 600; color: var(--muted); font-size: 12.5px; padding: .3rem .6rem; border-bottom: 1px solid var(--line-strong); }
table.pred td { padding: .4rem .6rem; border-bottom: 1px solid var(--line); }
table.pred td.word { font-family: var(--serif); font-size: 1.05rem; }
table.pred .ok { color: var(--accent); font-weight: 700; }
table.pred .miss { color: var(--warm); font-weight: 700; }
.bar { display: inline-block; height: 8px; border-radius: 4px; background: var(--accent); vertical-align: middle; margin-right: .4rem; }
.sparkline { width: 100%; max-width: 440px; height: 90px; display: block; margin-top: .5rem; }

/* ---------- chapter footer nav ---------- */
.chapter-nav { display: flex; gap: 1rem; margin-top: 3rem; font-family: var(--sans); }
.chapter-nav a { flex: 1; text-decoration: none; color: var(--ink); background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.2rem; box-shadow: var(--shadow); }
.chapter-nav a:hover { border-color: var(--accent); }
.chapter-nav a.next { text-align: right; }
.chapter-nav small { display: block; color: var(--muted); font-size: 12px; letter-spacing: .08em; text-transform: uppercase; margin-bottom: .3rem; }
.chapter-nav b { font-family: var(--display); font-size: 1.1rem; }

/* ---------- "what just changed" ---------- */
#recalc-log {
  position: fixed; right: 1.25rem; bottom: 1.25rem; width: min(360px, calc(100vw - 2.5rem));
  background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: 0 12px 40px -10px rgba(0,0,0,.35); font: 13.5px/1.45 var(--sans); z-index: 20; overflow: hidden;
}
#recalc-log header { display: flex; justify-content: space-between; align-items: center; padding: .6rem .9rem; border-bottom: 1px solid var(--line); }
#recalc-log header strong { font-size: 13px; }
#recalc-log .entries { list-style: none; margin: 0; padding: 0; max-height: 40vh; overflow: auto; }
#recalc-log .entry { padding: .65rem .9rem; border-bottom: 1px dashed var(--line); }
#recalc-log .entry:first-child { background: color-mix(in srgb, var(--hl) 40%, var(--paper)); }
#recalc-log .cause { font-weight: 600; margin-bottom: .35rem; }
#recalc-log .steps { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: .3rem; }
#recalc-log .steps li { font-size: 12px; padding: .15rem .5rem; border-radius: 999px; background: var(--accent-soft); color: var(--accent); animation: pop .25s ease-out; }
#recalc-log .steps li.stored { background: var(--warm-soft); color: var(--warm); }
@keyframes pop { from { opacity: 0; transform: scale(.85); } to { opacity: 1; } }
#recalc-log .entries:empty::after { content: 'Edit any highlighted number and this shows what recalculates.'; display: block; padding: .8rem .9rem; color: var(--muted); }
#recalc-log.collapsed .entries { display: none; }

@media (max-width: 760px) {
  body { font-size: 16px; }
  main.page { padding: 1.5rem 1rem 4rem; }
  .hero { grid-template-columns: 1fr; }
  .nav-sentence { display: none; }
  #recalc-log { position: static; width: auto; margin: 1rem; }
  .chapter-nav { flex-direction: column; }
}

/* ---------- playground ---------- */
.compare { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 1.25rem; }
.card.model { margin: 0; }
.card.model.yours { border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); }
.model-head { display: flex; flex-direction: column; gap: .2rem; margin-bottom: 1rem; }
.model .sub { font: 600 11.5px/1 var(--sans); letter-spacing: .1em; text-transform: uppercase; color: var(--muted); margin: 1rem 0 .5rem; }
.keyboard { display: flex; gap: .5rem; background: var(--bg); border-radius: 12px; padding: .5rem; min-height: 3.2rem; align-items: center; }
.keyboard .key { flex: 1; background: var(--paper); border: 1px solid var(--line-strong); border-radius: 8px; padding: .5rem .4rem; font-family: var(--serif); font-size: 1.05rem; display: flex; flex-direction: column; align-items: center; gap: .1rem; }
.keyboard .key.best { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.keyboard .key small { font: 11px/1 var(--sans); color: var(--muted); }
.chip.prompt { background: var(--bg); border-color: transparent; color: var(--ink-soft); }
.chip.gen { cursor: pointer; border-color: color-mix(in srgb, var(--accent) calc(var(--conf) * 100%), var(--line-strong)); background: color-mix(in srgb, var(--accent-soft) calc(var(--conf) * 100%), var(--paper)); }
.chip.gen.sel { outline: 2px solid var(--accent); }
.trace { margin-top: .9rem; background: var(--bg); border-radius: 10px; padding: .7rem .9rem; font-family: var(--sans); font-size: 13px; }
.bars { display: flex; flex-direction: column; gap: .25rem; }
.barrow { display: grid; grid-template-columns: 5rem 1fr 3rem; align-items: center; gap: .5rem; }
.barrow .w { font-family: var(--serif); font-size: 14px; text-align: right; }
.barrow .p { color: var(--muted); font-size: 12px; }
table.scale td:not(.word) { font-family: var(--mono); font-size: 13px; }
input[type=range] { width: 12rem; accent-color: var(--accent); }
.figure-row > .card.figure { margin: 0; flex: 1 1 auto; }

/* ---------- step-through players ---------- */
.card.player { padding: 1rem 1.1rem .7rem; }
.player-stage { min-height: 3rem; }
.player-caption { margin-top: .9rem; font-family: var(--sans); font-size: 14px; color: var(--ink-soft); line-height: 1.5; min-height: 1.5rem; }
.player-caption.fresh { animation: fadeup .4s ease-out both; }
@keyframes fadeup { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .player-caption.fresh { animation: none; } }
.player-caption .caption-text { max-width: 60rem; }
.player-caption .worked { margin-top: .5rem; }
.player.idle .player-caption .caption-text { color: var(--muted); }
.done-mark { color: var(--accent); font-weight: 600; }
.player-bar {
  display: flex; align-items: center; gap: .35rem; margin-top: .8rem; padding-top: .6rem;
  border-top: 1px solid var(--line); font-family: var(--sans); flex-wrap: wrap;
}
.pbtn { width: 2rem; height: 2rem; padding: 0; display: inline-flex; align-items: center; justify-content: center; border-radius: 8px; color: var(--ink-soft); }
.pbtn:disabled { opacity: .3; }
.player-bar .pbtn:nth-child(3) { background: var(--accent); color: #fff; border-color: var(--accent); width: 2.4rem; }
.player.playing .player-bar .pbtn:nth-child(3) { background: var(--warm); border-color: var(--warm); }
.player-bar .counter { font-family: var(--mono); font-size: 12px; color: var(--muted); min-width: 4.2rem; text-align: center; }
.player-bar .scrub { flex: 1; min-width: 6rem; margin: 0 .3rem; }
.player-bar .speed { font-size: 12px; padding: .25rem .4rem; }
.player.idle .player-stage { opacity: .9; }

table.matrix td.blank { color: var(--line-strong); background: transparent; box-shadow: inset 0 0 0 1px var(--line); text-align: center; }
table.matrix th.hl, table.matrix tr.hlrow th { color: var(--accent); font-weight: 700; transition: color .3s; }
/* row/column/cell highlights are drawn by the sliding .hl-box overlay (player.js) */
.hl-layer { position: absolute; inset: 0; pointer-events: none; z-index: 2; }
.hl-box { position: absolute; border-radius: 7px; box-sizing: border-box; border: 2px solid color-mix(in srgb, var(--accent) 60%, transparent); background: color-mix(in srgb, var(--accent) 7%, transparent);
  transition: left .45s cubic-bezier(.4,0,.2,1), top .45s cubic-bezier(.4,0,.2,1), width .45s cubic-bezier(.4,0,.2,1), height .45s cubic-bezier(.4,0,.2,1), opacity .25s; }
.hl-box.target { border-color: var(--accent); background: transparent; box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent); }
.hl-box.off { opacity: 0; }
.hl-box.scan { border: 0; border-bottom: 3px solid var(--accent); border-radius: 4px 4px 0 0; background: color-mix(in srgb, var(--accent) 12%, transparent); }
.hl-box.chip { border-color: var(--accent); background: transparent; border-radius: 12px; }
@media (prefers-reduced-motion: reduce) { .hl-box { transition: none; } }
table.matrix td.pulse { animation: cellpop .55s cubic-bezier(.2,.9,.3,1.2); }
@keyframes cellpop { 0% { transform: scale(.6); background: var(--hl); } 100% { transform: scale(1); } }
.chip.pulse { animation: cellpop .55s cubic-bezier(.2,.9,.3,1.2); border-color: var(--accent); }
.chip.todo { opacity: .35; border-style: dashed; }

.sentence-scan { font-family: var(--serif); font-size: 1.35rem; line-height: 1.6; padding: .4rem .2rem; }
.sentence-scan .todo { color: var(--muted); opacity: .55; }
.sentence-scan .seen { color: var(--ink); border-bottom: 2px solid var(--line-strong); }
.sentence-scan .cur { color: var(--accent); }
.sentence-scan .gap { color: var(--muted); }

.chapter-controls { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; margin: -0.5rem 0 2rem; font-family: var(--sans); }
.chapter-controls button { display: inline-flex; align-items: center; gap: .4rem; }
.chapter-controls .ghost { color: var(--muted); }

#recalc-log .hint { color: var(--muted); font-size: 12.5px; margin: .2rem 0 .4rem; }
.chip-link { font-size: 12px; padding: .15rem .55rem; border-radius: 999px; background: var(--amber-soft); color: var(--amber); text-decoration: none; border: 1px solid color-mix(in srgb, var(--amber) 30%, transparent); }
.chip-link:hover { background: var(--amber); color: #fff; }
table.pred tr.hlrow td { background: var(--accent-soft); }
.toc li.played .idx { color: var(--accent); }
.ghost-cell { position: absolute; z-index: 5; pointer-events: none; display: flex; align-items: center; justify-content: flex-end; padding: 0 .45rem; border-radius: 5px; font-family: var(--mono); box-shadow: 0 2px 8px rgba(0,0,0,.18); color: var(--ink); }
@media (prefers-reduced-motion: reduce) { table.matrix td.pulse, .chip.pulse { animation: none; } }

/* ---------- attention arcs ---------- */
svg.arcs { width: 100%; height: auto; display: block; color: var(--accent); overflow: visible; }
svg.arcs .base { stroke: var(--line-strong); stroke-width: 1; }
svg.arcs .arc { fill: none; stroke: var(--muted); transition: opacity .2s; }
svg.arcs .arc.focus { stroke: var(--accent); stroke-dasharray: 1; stroke-dashoffset: 1; animation: drawarc .7s ease-out forwards; }
@keyframes drawarc { to { stroke-dashoffset: 0; } }
@media (prefers-reduced-motion: reduce) { svg.arcs .arc.focus { animation: none; stroke-dashoffset: 0; } }
svg.arcs .word text { fill: var(--ink); font-family: var(--serif); cursor: default; }
svg.arcs .word .idx { fill: var(--muted); font-family: var(--mono); }
svg.arcs .word.focus text { fill: var(--accent); font-weight: 600; }
svg.arcs[data-hover] .arc { opacity: .06 !important; }
svg.arcs[data-hover="0"] .arc.from-0, svg.arcs[data-hover="1"] .arc.from-1, svg.arcs[data-hover="2"] .arc.from-2, svg.arcs[data-hover="3"] .arc.from-3, svg.arcs[data-hover="4"] .arc.from-4, svg.arcs[data-hover="5"] .arc.from-5, svg.arcs[data-hover="6"] .arc.from-6, svg.arcs[data-hover="7"] .arc.from-7, svg.arcs[data-hover="8"] .arc.from-8, svg.arcs[data-hover="9"] .arc.from-9, svg.arcs[data-hover="10"] .arc.from-10, svg.arcs[data-hover="11"] .arc.from-11, svg.arcs[data-hover="12"] .arc.from-12, svg.arcs[data-hover="13"] .arc.from-13, svg.arcs[data-hover="14"] .arc.from-14, svg.arcs[data-hover="15"] .arc.from-15 { opacity: 1 !important; stroke: var(--accent); }
.arcs-wrap { width: 100%; margin-top: .6rem; }
.arcs-wrap .fig-caption { margin-top: .2rem; }

/* ---------- hover linking ---------- */
table.matrix td.hov { box-shadow: inset 0 0 0 2px var(--warm); }
table.matrix td.hov-cell { box-shadow: inset 0 0 0 2px var(--warm); cursor: help; }
.hover-tip { position: absolute; z-index: 4; max-width: min(90%, 640px); pointer-events: none; }
.hover-tip .worked { box-shadow: 0 8px 24px rgba(0,0,0,.18); border: 1px solid var(--line-strong); background: var(--paper); }
.group-bar { margin-top: 0; padding-top: 0; border-top: 0; }
.group-label { font: 600 13px/1 var(--sans); color: var(--ink-soft); margin-right: .4rem; }

/* ---------- softmax bars ---------- */
.softmax-bars { display: flex; gap: .8rem; align-items: flex-start; flex-wrap: wrap; margin-top: .6rem; font-family: var(--sans); font-size: 12px; }
.softmax-bars > .op { align-self: center; font-size: 1.2rem; }
.sbars { display: flex; flex-direction: column; gap: .25rem; min-width: 12rem; }
.sbars-title { font: 600 11px/1 var(--sans); letter-spacing: .08em; text-transform: uppercase; color: var(--muted); margin-bottom: .2rem; }
.sbar { display: grid; grid-template-columns: 4.5rem 1fr 3.2rem; align-items: center; gap: .4rem; }
.sbar .lbl { text-align: right; color: var(--ink-soft); font-family: var(--serif); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sbar .track { height: 9px; background: var(--bg); border-radius: 4px; overflow: hidden; }
.sbar .fill { display: block; height: 100%; border-radius: 4px; background: var(--accent); transform-origin: left; animation: growbar both ease-out; }
.sbar.raw .fill { background: rgb(var(--pos-rgb)); }
.sbar.raw.neg .fill { background: rgb(var(--neg-rgb)); }
.sbar.exp .fill { background: var(--warm); }
.sbar.hidden .lbl, .sbar.hidden .val { opacity: .4; }
.sbar .val { font-family: var(--mono); color: var(--muted); font-size: 11.5px; }
@keyframes growbar { from { transform: scaleX(0); } to { transform: scaleX(1); } }
@media (prefers-reduced-motion: reduce) { .sbar .fill { animation: none; } }

/* ---------- layer norm strip ---------- */
svg.norm-strip { width: 100%; max-width: 520px; height: auto; display: block; margin-top: .6rem; font-family: var(--sans); }
svg.norm-strip .axis { stroke: var(--line-strong); }
svg.norm-strip .zero { stroke: var(--muted); stroke-dasharray: 2 2; }
svg.norm-strip .mean { stroke: var(--warm); stroke-width: 2; }
svg.norm-strip .lbl { fill: var(--ink-soft); font-size: 12px; font-family: var(--mono); }
svg.norm-strip .note { fill: var(--muted); font-size: 10px; }
svg.norm-strip .dot { fill: rgb(var(--pos-rgb)); stroke: var(--paper); stroke-width: 1.5; transform: translateX(var(--x1)); animation: slidex both ease-in-out; }
svg.norm-strip .dot.neg { fill: rgb(var(--neg-rgb)); }
@keyframes slidex { from { transform: translateX(var(--x0)); } to { transform: translateX(var(--x1)); } }
@media (prefers-reduced-motion: reduce) { svg.norm-strip .dot { animation: none; } }

/* ---------- causal mask curtain ---------- */
table.matrix td.masked { position: relative; color: var(--muted); overflow: hidden; }
table.matrix td.masked::after {
  content: ''; position: absolute; inset: 0; pointer-events: none; border-radius: 5px;
  background: repeating-linear-gradient(135deg, color-mix(in srgb, var(--ink) 10%, transparent) 0 3px, transparent 3px 8px);
}
table.matrix tr.hlrow td.masked::after { animation: curtain .5s cubic-bezier(.4,0,.2,1) both; animation-delay: calc(320ms + var(--c) * 55ms); }
@keyframes curtain { from { transform: translateX(105%); } to { transform: translateX(0); } }
@media (prefers-reduced-motion: reduce) { table.matrix tr.hlrow td.masked::after { animation: none; } }

/* ---------- tokenizer animations ---------- */
.sentence-scan { position: relative; }
.sentence-scan .cur .ch { display: inline-block; animation: readch .35s ease-out both; }
@keyframes readch { 0% { color: var(--muted); transform: translateY(0); } 40% { color: var(--accent); transform: translateY(-4px); } 100% { color: var(--accent); transform: translateY(0); } }
.sentence-scan .cur .ch.lowercased { animation-name: readch-lc; }
@keyframes readch-lc { 0% { color: var(--muted); transform: translateY(0) rotateX(0); } 50% { color: var(--warm); transform: translateY(-4px) rotateX(90deg); } 100% { color: var(--accent); transform: translateY(0) rotateX(0); } }
.ghost-fly { position: absolute; z-index: 5; pointer-events: none; display: inline-flex; align-items: center; justify-content: center; white-space: nowrap; box-shadow: 0 6px 18px rgba(0,0,0,.18); }
.ghost-fly.chip-ghost { font-family: var(--serif); font-size: 1.05rem; background: var(--paper); border: 1px solid var(--accent); border-radius: 10px; padding: .35rem .75rem; color: var(--ink); }
.ghost-fly.word-ghost { background: var(--accent-soft); border-radius: 6px; padding: 0 .4rem; color: var(--accent); font-family: var(--serif); }
.ghost-fly.ticket-ghost { background: var(--accent); color: #fff; border-radius: 6px; padding: 0 .45rem; font-family: var(--mono); font-weight: 600; }
@media (prefers-reduced-motion: reduce) { .sentence-scan .cur .ch { animation: none; color: var(--accent); } }
.cellref { color: inherit; text-decoration: underline dotted var(--accent); text-underline-offset: 3px; }
.cellref:hover { color: var(--accent); }
table.matrix td.flash { animation: cellflash 1s ease-out; }
@keyframes cellflash { 0% { box-shadow: 0 0 0 4px var(--warm); background: var(--warm-soft); } 100% { box-shadow: 0 0 0 0 transparent; } }
