/* ==========================================================================
   The Decision Machine — an explorable about Contrastive Language Models
   Visual grammar (never broken):
     blue   = the STATE side (the situation, the ticket, the state head)
     amber  = the ACTION side (the options, the menu, the action head)
     grey   = FROZEN / shared (the backbone nobody trains)
     green / red = right / wrong, always with a label
   ========================================================================== */

:root {
  --bg: #0a0c11;
  --bg-2: #0f1219;
  --panel: #12161f;
  --panel-2: #181d28;
  --line: #232a38;
  --line-2: #2f384a;
  --ink: #ece7dc;
  --ink-2: #b9b4a9;
  --ink-3: #7d8191;

  --state: #5ab0ff;
  --state-2: #2d6fb3;
  --state-wash: rgba(90, 176, 255, 0.13);
  --action: #ffb547;
  --action-2: #b9781d;
  --action-wash: rgba(255, 181, 71, 0.13);
  --frozen: #8a92a3;
  --frozen-wash: rgba(138, 146, 163, 0.12);
  --good: #3fd08a;
  --bad: #ff6b5b;
  --violet: #b495ff;

  --f-display: "Instrument Serif", "Iowan Old Style", Georgia, serif;
  --f-body: "Inter Tight", "Inter", -apple-system, "Segoe UI", sans-serif;
  --f-mono: "JetBrains Mono", ui-monospace, Menlo, monospace;

  --col: 680px;
  --wide: 1120px;
  --r: 14px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { background: var(--bg); scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--f-body);
  font-size: 18px;
  line-height: 1.68;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
::selection { background: var(--state-wash); color: var(--ink); }

/* ---------- prose ---------- */
.prose { max-width: var(--col); margin: 0 auto; padding: 0 20px; }
.prose p { margin: 0 0 1.15em; color: var(--ink-2); }
.prose p strong, .prose li strong { color: var(--ink); font-weight: 600; }
.prose em { color: var(--ink); }
.prose a { color: var(--state); text-underline-offset: 3px; }
.prose ul, .prose ol { color: var(--ink-2); padding-left: 1.2em; }
.prose li { margin: 0.35em 0; }
.prose code, .mono { font-family: var(--f-mono); font-size: 0.86em; }
.prose code { background: var(--panel-2); padding: 0.1em 0.38em; border-radius: 5px; color: var(--ink); }
.s { color: var(--state); font-weight: 600; }
.a { color: var(--action); font-weight: 600; }
.f { color: var(--frozen); font-weight: 600; }

.eq {
  font-family: var(--f-mono);
  font-size: 0.92rem;
  color: var(--ink);
  background: var(--panel);
  border: 1px solid var(--line);
  border-left: 3px solid var(--violet);
  border-radius: 10px;
  padding: 0.9rem 1.1rem;
  margin: 1.4em 0;
  line-height: 1.9;
  white-space: normal;
}
.eq .s, .eq .a { font-weight: 500; }

/* ---------- chapter scaffolding ---------- */
.chapter { padding: 7rem 0 2rem; position: relative; }
.chapter-head { max-width: var(--col); margin: 0 auto 2.2rem; padding: 0 20px; }
.chapter-no {
  font-family: var(--f-mono);
  font-size: 0.74rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-3);
  display: flex; align-items: center; gap: 0.8rem;
}
.chapter-no::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.chapter h2 {
  font-family: var(--f-display);
  font-weight: 400;
  font-size: clamp(2.3rem, 5vw, 3.4rem);
  line-height: 1.04;
  letter-spacing: -0.01em;
  margin: 0.8rem 0 0.6rem;
  color: var(--ink);
}
.chapter h2 i { color: var(--action); }
.chapter .lede { font-size: 1.16rem; color: var(--ink-2); margin: 0; }
.prose h3 {
  font-family: var(--f-body); font-weight: 650; font-size: 1.08rem;
  margin: 2.2em 0 0.6em; color: var(--ink); letter-spacing: 0.005em;
}

/* ---------- figure / stage ---------- */
.stage {
  max-width: var(--wide);
  margin: 2.4rem auto;
  padding: 0 20px;
}
.stage-inner {
  background: linear-gradient(180deg, var(--panel) 0%, var(--bg-2) 100%);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 22px;
  position: relative;
  overflow: hidden;
}
.stage-title {
  display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; flex-wrap: wrap;
  font-family: var(--f-mono); font-size: 0.74rem; letter-spacing: 0.12em; text-transform: uppercase;
  color: var(--ink-3); margin-bottom: 14px;
}
.stage-title b { color: var(--ink); font-weight: 600; }
.stage-caption {
  max-width: var(--col); margin: 0.9rem auto 0; padding: 0 2px;
  font-size: 0.86rem; line-height: 1.55; color: var(--ink-3);
}
.stage-caption b { color: var(--ink-2); font-weight: 600; }

/* provenance badges: every number says where it comes from */
.badge {
  display: inline-flex; align-items: center; gap: 0.35em;
  font-family: var(--f-mono); font-size: 0.66rem; letter-spacing: 0.08em; text-transform: uppercase;
  padding: 0.18em 0.6em; border-radius: 99px; border: 1px solid var(--line-2); color: var(--ink-3);
  white-space: nowrap; vertical-align: middle;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.toy { color: var(--violet); border-color: rgba(180,149,255,.35); }
.badge.cited { color: var(--good); border-color: rgba(63,208,138,.35); }
.badge.self { color: var(--action); border-color: rgba(255,181,71,.35); }
.badge.schematic { color: var(--frozen); }
.badge.guess { color: var(--bad); border-color: rgba(255,107,91,.35); }

/* ---------- controls ---------- */
.controls { display: flex; flex-wrap: wrap; gap: 10px 14px; align-items: center; margin: 14px 0 0; }
.btn {
  font: 500 0.84rem/1 var(--f-body);
  color: var(--ink);
  background: var(--panel-2);
  border: 1px solid var(--line-2);
  border-radius: 9px;
  padding: 0.62rem 0.95rem;
  cursor: pointer;
  transition: border-color .15s, background .15s, transform .08s;
  display: inline-flex; align-items: center; gap: 0.5em;
}
.btn:hover { border-color: var(--ink-3); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible, .chip:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid var(--state); outline-offset: 2px; }
.btn[aria-pressed="true"] { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.btn.primary { background: var(--state); color: #06121f; border-color: var(--state); font-weight: 650; }
.btn.amber { background: var(--action); color: #1f1405; border-color: var(--action); font-weight: 650; }
.btn.ghost { background: transparent; }
.btn:disabled { opacity: .4; cursor: not-allowed; }

.seg { display: inline-flex; border: 1px solid var(--line-2); border-radius: 10px; padding: 3px; background: var(--bg-2); gap: 2px; flex-wrap: wrap; }
.seg button {
  font: 500 0.8rem/1 var(--f-body); color: var(--ink-3); background: transparent; border: 0;
  padding: 0.55rem 0.8rem; border-radius: 7px; cursor: pointer;
}
.seg button[aria-pressed="true"] { background: var(--panel-2); color: var(--ink); box-shadow: inset 0 0 0 1px var(--line-2); }

.slider { display: inline-flex; align-items: center; gap: 0.7rem; font-family: var(--f-mono); font-size: 0.78rem; color: var(--ink-3); }
.slider output { color: var(--ink); min-width: 3.5em; font-variant-numeric: tabular-nums; }
input[type=range] { -webkit-appearance: none; appearance: none; width: 150px; height: 22px; background: transparent; cursor: pointer; }
input[type=range]::-webkit-slider-runnable-track { height: 4px; background: var(--line-2); border-radius: 4px; }
input[type=range]::-moz-range-track { height: 4px; background: var(--line-2); border-radius: 4px; }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 16px; height: 16px; border-radius: 50%; background: var(--ink); margin-top: -6px; border: 3px solid var(--bg); box-shadow: 0 0 0 1px var(--ink-3); }
input[type=range]::-moz-range-thumb { width: 12px; height: 12px; border-radius: 50%; background: var(--ink); border: 3px solid var(--bg); }

.chip {
  font: 500 0.82rem/1.2 var(--f-body);
  border-radius: 99px; padding: 0.45rem 0.8rem; cursor: pointer;
  border: 1px solid var(--line-2); background: var(--panel-2); color: var(--ink-2);
  transition: all .15s;
}
.chip.state[aria-pressed="true"] { background: var(--state-wash); border-color: var(--state); color: var(--ink); }
.chip.action[aria-pressed="true"] { background: var(--action-wash); border-color: var(--action); color: var(--ink); }

/* readouts */
.readout { font-family: var(--f-mono); font-variant-numeric: tabular-nums; }
.kpi { display: flex; flex-direction: column; gap: 2px; }
.kpi .k { font-family: var(--f-mono); font-size: 0.68rem; letter-spacing: .1em; text-transform: uppercase; color: var(--ink-3); }
.kpi .v { font-family: var(--f-mono); font-size: 1.5rem; color: var(--ink); font-variant-numeric: tabular-nums; }

/* probability bars, reused everywhere */
.pbars { display: grid; gap: 7px; }
.pbar { display: grid; grid-template-columns: minmax(90px, 160px) 1fr 3.6em; align-items: center; gap: 10px; font-size: 0.84rem; }
.pbar .lbl { color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pbar .track { height: 10px; background: var(--bg-2); border-radius: 6px; overflow: hidden; border: 1px solid var(--line); }
.pbar .fill { height: 100%; width: 0; background: var(--action); border-radius: 6px; transition: width .35s cubic-bezier(.2,.7,.2,1); }
.pbar .num { font-family: var(--f-mono); font-size: 0.8rem; text-align: right; color: var(--ink); font-variant-numeric: tabular-nums; }
.pbar.win .lbl { color: var(--ink); font-weight: 600; }

/* callout */
.callout {
  border: 1px solid var(--line); border-left: 3px solid var(--action);
  background: var(--panel); border-radius: 10px; padding: 1rem 1.2rem; margin: 1.6em 0;
}
.callout p:last-child { margin-bottom: 0; }
.callout .t { font-family: var(--f-mono); font-size: 0.7rem; letter-spacing: .14em; text-transform: uppercase; color: var(--action); margin-bottom: .4rem; }

/* canvases */
canvas { display: block; max-width: 100%; }
.cv-wrap { position: relative; }

/* generic two-column layout inside stages */
.duo { display: grid; grid-template-columns: 1.15fr 1fr; gap: 26px; align-items: start; }
@media (max-width: 860px) { .duo { grid-template-columns: 1fr; } }

/* ---------- hero ---------- */
.hero { min-height: 100vh; position: relative; display: grid; place-items: center; overflow: hidden; }
.hero canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.hero-copy { position: relative; z-index: 2; text-align: center; padding: 0 20px; max-width: 900px; pointer-events: none; }
.hero-kicker { font-family: var(--f-mono); font-size: .76rem; letter-spacing: .24em; text-transform: uppercase; color: var(--ink-3); }
.hero h1 {
  font-family: var(--f-display); font-weight: 400; font-size: clamp(3rem, 9vw, 7rem);
  line-height: .95; margin: 1.2rem 0 1.2rem; letter-spacing: -0.02em;
}
.hero h1 .s, .hero h1 .a { font-weight: 400; font-style: italic; }
.hero .dek { font-size: 1.22rem; color: var(--ink-2); max-width: 640px; margin: 0 auto; }
.hero-legend { margin-top: 2rem; display: flex; justify-content: center; gap: 1.6rem; flex-wrap: wrap; font-family: var(--f-mono); font-size: .76rem; color: var(--ink-3); }
.hero-legend span { display: inline-flex; align-items: center; gap: .5em; }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.dot.s { background: var(--state); box-shadow: 0 0 12px var(--state); }
.dot.a { background: var(--action); box-shadow: 0 0 12px var(--action); }
.dot.f { background: var(--frozen); }
.scroll-cue { position: absolute; bottom: 28px; left: 50%; transform: translateX(-50%); z-index: 2; font-family: var(--f-mono); font-size: .7rem; letter-spacing: .2em; color: var(--ink-3); text-transform: uppercase; }

/* table of contents rail */
.toc { max-width: var(--col); margin: 0 auto; padding: 0 20px; display: grid; gap: 4px; counter-reset: c; }
.toc a { display: grid; grid-template-columns: 2.4em 1fr; color: var(--ink-2); text-decoration: none; padding: .35rem 0; border-bottom: 1px dashed var(--line); font-size: .95rem; }
.toc a:hover { color: var(--ink); }
.toc a span { font-family: var(--f-mono); font-size: .76rem; color: var(--ink-3); padding-top: .2em; }

/* scorecard */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 14px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 16px 18px; }
.card h4 { margin: 0 0 .5rem; font-size: .95rem; font-weight: 600; }
.card .big { font-family: var(--f-mono); font-size: 1.35rem; color: var(--ink); }
.card p { font-size: .86rem; color: var(--ink-3); margin: .5rem 0 0; line-height: 1.5; }

footer.colophon { max-width: var(--col); margin: 6rem auto 4rem; padding: 2rem 20px 0; border-top: 1px solid var(--line); font-size: .84rem; color: var(--ink-3); }
footer.colophon a { color: var(--ink-2); }

@media (max-width: 640px) {
  body { font-size: 17px; }
  .stage { padding: 0 10px; }
  .stage-inner { padding: 14px; }
  .chapter { padding-top: 5rem; }
  .pbar { grid-template-columns: 96px 1fr 3.2em; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition-duration: .01ms !important; animation-duration: .01ms !important; }
}
