/* ---------- Tokens ---------- */
:root {
  --bg: #fbfaf7;
  --ink: #1d2024;
  --muted: #5f636a;
  --faint: #8a8d92;
  --line: #e4e1da;
  --panel: #ffffff;
  --tint: #f3f1ec;
  --accent: #2c5d63;
  --video-bg: #15191c;
  --serif: "Source Serif 4", "Source Serif Pro", Georgia, "Times New Roman", serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --measure: 1080px;
  --wide: 1080px;
  color-scheme: light;
}
body.dark {
  --bg: #16181b;
  --ink: #e7e5e0;
  --muted: #a6a9ae;
  --faint: #7d8187;
  --line: #2f3237;
  --panel: #1d2024;
  --tint: #22252a;
  --accent: #8fc0c4;
  --video-bg: #0f1113;
  color-scheme: dark;
}

/* Agent colors match the rendered video */
.agent-1 { --agent: #a1ddff; }
.agent-2 { --agent: #f8a975; }
.agent-3 { --agent: #ffcb73; }

/* ---------- Base ---------- */
* { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: 24px; -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--serif);
  font-size: 18px;
  line-height: 1.65;
  font-optical-sizing: auto;
}
h1, h2, h3 { font-weight: 600; margin: 0; line-height: 1.25; }
p { margin: 0 0 1em; }
a { color: var(--accent); text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 3px; text-decoration-color: color-mix(in srgb, var(--accent) 40%, transparent); }
a:hover { text-decoration-color: currentColor; }
button { font: inherit; color: inherit; cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
img { max-width: 100%; }

.measure { width: min(var(--measure), 100% - 32px); margin-inline: auto; }
.wide { width: min(var(--wide), 100% - 32px); margin-inline: auto; }

.skip { position: absolute; left: 8px; top: -60px; background: var(--ink); color: var(--bg); padding: 8px 12px; z-index: 10; }
.skip:focus { top: 8px; }

.note, figcaption, caption {
  font-family: var(--sans);
  font-size: 13.5px;
  line-height: 1.6;
  color: var(--muted);
}
.note { margin-top: 12px; }

/* ---------- Header ---------- */
.site-header { border-bottom: 1px solid var(--line); }
.header-inner { display: flex; align-items: center; gap: 28px; height: 60px; }
.wordmark {
  font-family: var(--sans); font-weight: 600; font-size: 14px; letter-spacing: .08em;
  color: var(--ink); text-decoration: none;
}
.site-header nav { margin-left: auto; display: flex; gap: 22px; font-family: var(--sans); font-size: 14px; }
.site-header nav a { color: var(--muted); text-decoration: none; }
.site-header nav a:hover { color: var(--ink); }
.theme-toggle {
  border: 1px solid var(--line); background: transparent; border-radius: 50%;
  width: 32px; height: 32px; display: grid; place-items: center; padding: 0; color: var(--muted);
}
.theme-toggle:hover { color: var(--ink); }

/* ---------- Title ---------- */
.title-block { padding: 88px 0 40px; }
.title-block h1 { font-size: clamp(32px, 4.6vw, 46px); letter-spacing: -.01em; line-height: 1.15; }
.subtitle { font-size: clamp(20px, 2.4vw, 24px); font-style: italic; color: var(--muted); margin: 10px 0 32px; }
.authors { font-size: 19px; margin: 0; }
.affiliation { font-size: 16px; color: var(--muted); margin: 2px 0 26px; }
.links { font-family: var(--sans); font-size: 15px; display: flex; flex-wrap: wrap; gap: 8px 24px; margin: 0; }
.links a { font-weight: 500; }

/* ---------- Abstract ---------- */
.abstract { padding: 32px 0 8px; border-top: 1px solid var(--line); }
.label {
  font-family: var(--sans); font-size: 12px; font-weight: 600; letter-spacing: .08em;
  text-transform: uppercase; color: var(--muted); margin-bottom: 12px;
}

/* ---------- Sections ---------- */
.section { padding: 72px 0 8px; }
.section h2 { font-size: 28px; margin-bottom: 18px; }
.section h3 { font-size: 20px; }
.section > .measure + .wide, .section > .wide + .measure { margin-top: 28px; }
em { font-style: italic; }

/* ---------- Figures ---------- */
figure { margin: 36px auto 0; }
figure > a { display: block; }
figure img {
  display: block; width: 100%; height: auto;
  background: #fff; border: 1px solid var(--line); border-radius: 4px; padding: 14px;
}
figcaption { margin-top: 12px; max-width: var(--measure); }
.fig-label { font-weight: 600; color: var(--ink); margin-right: 4px; }

/* ---------- Episode ---------- */
.clip-buttons, .segmented {
  display: inline-flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden;
  font-family: var(--sans); background: var(--panel);
}
.clip-buttons { margin-bottom: 14px; }
.clip-buttons button, .segmented button {
  border: 0; background: transparent; padding: 8px 14px; font-size: 14px; color: var(--muted);
  border-right: 1px solid var(--line); min-height: 38px;
}
.clip-buttons button:last-child, .segmented button:last-child { border-right: 0; }
.clip-buttons button[aria-pressed="true"], .segmented button[aria-pressed="true"] { background: var(--tint); color: var(--ink); font-weight: 500; }
.clip-buttons small { font-size: 12px; color: var(--faint); margin-left: 6px; font-variant-numeric: tabular-nums; }

.video-shell { background: var(--video-bg); border-radius: 6px; overflow: hidden; }
.video-panel-labels {
  display: grid; grid-template-columns: repeat(3, 23.1%) 1fr;
  font-family: var(--sans); color: #d8dcdc; font-size: 12px; letter-spacing: .02em;
}
.video-panel-labels span { text-align: center; padding: 8px 4px 7px; border-top: 3px solid var(--agent, #5a6166); }
#rollout { display: block; width: 100%; height: auto; aspect-ratio: 976 / 224; background: var(--video-bg); }

.chapter-strip { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 10px; }
.chapter-strip button {
  display: grid; grid-template-columns: 22px 1fr auto; align-items: baseline; gap: 10px;
  text-align: left; background: transparent; border: 1px solid var(--line); border-radius: 6px;
  padding: 11px 16px; font-family: var(--sans);
}
.chapter-strip button[aria-current="step"] { background: var(--panel); border-color: var(--faint); }
.chapter-num { font-size: 13px; color: var(--faint); font-variant-numeric: tabular-nums; }
.chapter-strip strong { font-size: 14px; font-weight: 500; }
.chapter-strip small { font-size: 12px; color: var(--faint); font-variant-numeric: tabular-nums; }

.episode-grid { display: grid; grid-template-columns: 1.4fr 1fr; gap: 20px; margin-top: 28px; align-items: start; }
.panel { min-width: 0; background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 22px 24px; }
.panel h3 { font-size: 18px; }
.panel-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.turn-pill { font-family: var(--sans); font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }

.graph-scroll { overflow-x: auto; margin: 14px -12px 10px; }
.mission-dag { display: block; width: 100%; min-width: 540px; color: var(--faint); font-family: var(--sans); }
.dag-node rect { fill: var(--panel); stroke: var(--line); stroke-width: 1.2; transition: stroke .2s; }
.dag-node circle { fill: var(--agent); }
.dag-node .node-number { fill: #1d2024; font-size: 14px; font-weight: 600; }
.dag-node .node-label { fill: var(--ink); font-size: 15px; font-weight: 500; }
.dag-node .node-sub { fill: var(--muted); font-size: 12px; }
.dag-node.in-turn rect { stroke: var(--agent); stroke-width: 3; }
.dag-node.earlier-turn rect { stroke: var(--agent); stroke-width: 1.5; stroke-dasharray: 4 3; }
.dag-annotation { fill: var(--muted); font-size: 12px; }

.agent-legend { display: flex; flex-wrap: wrap; gap: 6px 18px; font-family: var(--sans); font-size: 13px; color: var(--muted); }
.agent-legend span { display: inline-flex; align-items: center; gap: 7px; }
.agent-legend i { width: 10px; height: 10px; border-radius: 50%; background: var(--agent); }

.turn-card h3 { margin-bottom: 10px; }
.turn-card > p:not(.note) { font-size: 16px; color: var(--muted); }
.turn-task { display: flex; gap: 10px; align-items: baseline; margin: 10px 0; font-size: 16px; line-height: 1.5; }
.task-badge {
  flex: 0 0 22px; height: 22px; line-height: 22px; text-align: center; border-radius: 4px;
  background: var(--agent); color: #1d2024; font-family: var(--sans); font-size: 12px; font-weight: 600;
  transform: translateY(-1px);
}
.firing-figure { margin: 20px 0 0; }
.firing-figure img { max-height: 120px; object-fit: contain; padding: 10px; }
.firing-figure img.is-turn-1 { padding: 10px 32%; }
.turn-card .note { font-size: 13px; }

.regime { margin-top: 28px; padding-top: 22px; border-top: 1px solid var(--line); }
.regime-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px 20px; }
.regime-head h3 { font-size: 18px; }
.instructions { margin-top: 14px; }
.instructions summary, .disclosure summary {
  cursor: pointer; font-family: var(--sans); font-size: 14px; color: var(--accent);
}
#original-instruction { display: grid; gap: 4px; }
#original-instruction article { padding-top: 16px; max-width: var(--measure); }
#original-instruction h3 {
  display: inline-block; font-family: var(--sans); font-size: 14px; font-weight: 600;
  border-bottom: 3px solid var(--agent); margin-bottom: 8px; padding-bottom: 1px;
}
#original-instruction p { font-size: 16px; color: var(--muted); }

/* ---------- Task ---------- */
.triad { margin: 8px 0 0; display: grid; gap: 14px; }
.triad div { padding-left: 16px; border-left: 2px solid var(--line); }
.triad dt { font-weight: 600; }
.triad dd { margin: 0; color: var(--muted); }

/* ---------- Benchmark ---------- */
.stats {
  display: grid; grid-template-columns: repeat(4, 1fr); margin: 4px 0 28px;
  border-top: 1px solid var(--line); border-bottom: 1px solid var(--line);
}
.stats div { padding: 16px 0 14px; }
.stats div + div { padding-left: 20px; border-left: 1px solid var(--line); }
.stats dt { font-family: var(--sans); font-size: 12.5px; color: var(--muted); }
.stats dd { margin: 2px 0 0; font-size: 26px; font-variant-numeric: lining-nums tabular-nums; }

/* ---------- Tables ---------- */
table { border-collapse: collapse; width: 100%; font-family: var(--sans); font-size: 14px; font-variant-numeric: tabular-nums; }
caption { text-align: left; padding: 0 0 10px; }
th, td { padding: 8px 12px; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; }
th:first-child { text-align: left; }
thead th { font-weight: 600; color: var(--muted); font-size: 13px; border-bottom-color: var(--faint); }
tbody th { font-weight: 400; }
.splits { max-width: 420px; margin-top: 6px; }
.table-scroll { overflow-x: auto; }
.results td:nth-child(2) { text-align: left; color: var(--muted); }
.results tr.group th { text-align: left; font-size: 12px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); padding-top: 18px; border-bottom-color: var(--line); }
.results tr.ours { background: var(--tint); }
.results b { font-weight: 700; }
.results small { font-size: 11px; color: var(--faint); }
.results.full { font-size: 13px; }
.results.full thead th { text-align: center; }
.results.full th, .results.full td { padding: 7px 9px; }
.compact { min-width: 640px; }
.compact tbody th, .compact thead th:first-child { width: 28%; }
.compact td:nth-child(2), .compact thead th:nth-child(2) { text-align: left; }

.disclosure { margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--line); }
.disclosure > .table-scroll, .disclosure > .metrics { margin-top: 14px; }
.metrics { display: grid; grid-template-columns: max-content 1fr; gap: 8px 20px; margin: 0; font-size: 16px; max-width: 860px; }
.metrics div { display: contents; }
.metrics dt { font-family: var(--sans); font-size: 14px; font-weight: 600; padding-top: 2px; }
.metrics dd { margin: 0; color: var(--muted); }

.case-study { margin-top: 56px; }
.case-study h3 { margin-bottom: 12px; }

/* ---------- Citation ---------- */
.bibtex { position: relative; margin-top: 4px; }
.bibtex pre {
  margin: 0; padding: 18px 20px; overflow-x: auto;
  background: var(--panel); border: 1px solid var(--line); border-radius: 6px;
  font-family: var(--mono); font-size: 13px; line-height: 1.7;
}
#copy {
  position: absolute; top: 10px; right: 10px;
  font-family: var(--sans); font-size: 12px; color: var(--muted);
  background: var(--bg); border: 1px solid var(--line); border-radius: 4px; padding: 4px 10px;
}
#copy:hover { color: var(--ink); }
#copy-status:empty { display: none; }
#citation > p:last-child { margin-top: 20px; font-size: 16px; color: var(--muted); }

/* ---------- Footer ---------- */
.site-footer { margin-top: 80px; padding: 22px 0 28px; border-top: 1px solid var(--line); font-family: var(--sans); font-size: 13px; color: var(--faint); }

/* ---------- Responsive ---------- */
@media (max-width: 960px) {
  .episode-grid { grid-template-columns: 1fr; }
  .site-header nav a[href="#citation"], .site-header nav a[href="#episode"] { display: none; }
}
@media (max-width: 640px) {
  body { font-size: 17px; }
  .header-inner { gap: 14px; }
  .site-header nav { gap: 14px; font-size: 13px; }
  .site-header nav a[href="#task"] { display: none; }
  .title-block { padding: 52px 0 30px; }
  .section { padding-top: 56px; }
  .section h2 { font-size: 24px; }
  .clip-buttons { display: flex; }
  .clip-buttons button { flex: 1; padding: 8px 6px; font-size: 13px; }
  .clip-buttons small { display: block; margin: 0; }
  .video-panel-labels { font-size: 10px; }
  .chapter-strip { grid-template-columns: 1fr; }
  .panel { padding: 18px 16px; }
  .graph-scroll { margin-inline: -8px; }
  .segmented { display: flex; width: 100%; }
  .segmented button { flex: 1; padding: 8px 6px; font-size: 13px; }
  .stats { grid-template-columns: 1fr 1fr; }
  .stats div:nth-child(3) { padding-left: 0; border-left: 0; border-top: 1px solid var(--line); }
  .stats div:nth-child(4) { border-top: 1px solid var(--line); }
  .metrics { grid-template-columns: 1fr; gap: 2px; }
  .metrics dd { margin-bottom: 10px; }
  figure img { padding: 6px; }
}
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  * { transition: none !important; }
}
