:root {
  --bg: #fafaf9;
  --card: #ffffff;
  --ink: #18181b;
  --muted: #6b7280;
  --line: #e7e5e4;
  --soft: #f4f4f5;
  --think: #4f46e5;
  --think-soft: #eef2ff;
  --direct: #d97706;
  --direct-soft: #fef3c7;
  --bad: #dc2626;
  --bad-soft: #fee2e2;
  --good: #16a34a;
  --good-soft: #dcfce7;
  --term: #111827;
  --term-ink: #e5e7eb;
  --radius: 14px;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --sans: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f0f12;
    --card: #17171c;
    --ink: #f4f4f5;
    --muted: #a1a1aa;
    --line: #2a2a31;
    --soft: #1f1f26;
    --think: #818cf8;
    --think-soft: #1e1b4b;
    --direct: #f59e0b;
    --direct-soft: #3a2a0a;
    --bad: #f87171;
    --bad-soft: #3b1515;
    --good: #4ade80;
    --good-soft: #0f2e1b;
    --term: #0b0b0f;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.6 var(--sans);
  -webkit-font-smoothing: antialiased;
}

main { max-width: 980px; margin: 0 auto; padding: 0 20px 80px; }

a { color: var(--think); text-decoration: none; }
a:hover { text-decoration: underline; }

code, .mono { font-family: var(--mono); font-size: 0.88em; }

/* ---------- header ---------- */
header { text-align: center; padding: 72px 0 28px; }
header h1 { font-size: clamp(1.7rem, 4.2vw, 2.6rem); line-height: 1.15; margin: 0 auto 22px; max-width: 820px; letter-spacing: -0.02em; text-wrap: balance; }
header .subtitle { font-size: clamp(1.1rem, 2.6vw, 1.45rem); color: var(--muted); margin: 0 0 22px; font-weight: 500; }
.authors { font-size: 1.05rem; margin: 0; }
.affil { color: var(--muted); margin: 2px 0 22px; }
.links { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.links a {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 9px 18px; border-radius: 999px;
  background: var(--ink); color: var(--bg); font-weight: 600; font-size: 0.95rem;
}
.links a:hover { text-decoration: none; opacity: 0.85; }
.links svg { width: 16px; height: 16px; fill: currentColor; }

/* ---------- text blocks ---------- */
.tldr {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 22px 26px; margin: 18px 0 8px; font-size: 1.08rem;
}
.tldr b { color: var(--think); }

section { margin-top: 72px; }
section h2 { font-size: 1.6rem; letter-spacing: -0.01em; margin: 0 0 6px; }
.kicker { color: var(--think); font-weight: 600; font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.08em; margin: 0 0 4px; }
section > p { max-width: 760px; }
.caption { color: var(--muted); font-size: 0.85rem; margin-top: 10px; }

.findings { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; margin-top: 18px; }
.finding {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px 20px; color: var(--ink);
}
.finding:hover { text-decoration: none; border-color: var(--think); }
.finding .num { white-space: nowrap; font-size: 1.55rem; font-weight: 700; color: var(--think); line-height: 1.1; }
.finding p { margin: 6px 0 0; font-size: 0.95rem; }

/* ---------- demo cards ---------- */
.demo {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px; margin-top: 20px; box-shadow: 0 1px 2px rgba(0,0,0,0.04), 0 8px 24px rgba(0,0,0,0.04);
}
.demo-bar { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.seg { display: inline-flex; background: var(--soft); border-radius: 999px; padding: 3px; }
.seg button {
  border: 0; background: transparent; color: var(--muted); font: 600 0.85rem var(--sans);
  padding: 6px 14px; border-radius: 999px; cursor: pointer;
}
.seg button.on { background: var(--card); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,0.12); }
.replay {
  border: 1px solid var(--line); background: var(--card); color: var(--ink); border-radius: 999px;
  font: 600 0.85rem var(--sans); padding: 6px 14px; cursor: pointer;
}
.replay:hover { border-color: var(--think); }
.label { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); font-weight: 600; margin-bottom: 6px; }

/* ---------- episode player ---------- */
.episode-grid { display: grid; grid-template-columns: 1fr 1.5fr; gap: 16px; }
.fs { display: flex; flex-direction: column; gap: 10px; }
.dir { border: 1px dashed var(--line); border-radius: 12px; padding: 10px; min-height: 110px; }
.dir-name { font-family: var(--mono); font-size: 0.8rem; color: var(--muted); margin-bottom: 8px; }
.slots { display: flex; flex-wrap: wrap; gap: 8px; }
.file {
  position: relative; display: inline-flex; align-items: center; gap: 6px;
  font-family: var(--mono); font-size: 0.82rem; padding: 6px 10px; border-radius: 9px;
  border: 1px solid var(--line); background: var(--soft); transition: background 0.4s, border-color 0.4s;
}
.file svg { width: 14px; height: 14px; }
.file.locked svg { color: var(--bad); }
.file.unlocked svg { color: var(--good); }
.file.arrive { animation: arrive 0.6s ease; }
.file.flash { animation: flash 1.2s ease; }
.file .q {
  position: absolute; top: -9px; right: -9px; width: 18px; height: 18px; border-radius: 50%;
  background: var(--direct); color: #fff; font: 700 0.7rem/18px var(--sans); text-align: center;
  animation: pop 0.3s ease;
}
@keyframes arrive { from { opacity: 0; transform: translateY(-8px) scale(0.9); } to { opacity: 1; transform: none; } }
@keyframes flash { 0%, 100% { box-shadow: 0 0 0 0 transparent; } 30% { box-shadow: 0 0 0 5px var(--direct-soft); border-color: var(--direct); } }
@keyframes pop { from { transform: scale(0); } to { transform: scale(1); } }
.fs-note { font-size: 0.8rem; color: var(--muted); margin: 0; }
.fs-note b { color: var(--direct); }

.term { background: var(--term); border-radius: 12px; overflow: hidden; display: flex; flex-direction: column; }
.term-head { font: 600 0.75rem var(--sans); color: #9ca3af; padding: 8px 12px; border-bottom: 1px solid #1f2937; display: flex; gap: 6px; align-items: center; }
.term-head i { width: 9px; height: 9px; border-radius: 50%; background: #374151; display: inline-block; }
.term-body { font-family: var(--mono); font-size: 0.8rem; color: var(--term-ink); padding: 12px; height: 330px; overflow-y: auto; scroll-behavior: smooth; }
.term-body .ln { white-space: pre-wrap; margin: 0 0 4px; animation: fadein 0.35s ease; }
.term-body .obs { color: #9ca3af; }
.term-body .sys { color: #fbbf24; }
.term-body .cmd { color: #f9fafb; font-weight: 700; }
.term-body .cmd::before { content: "CMD: "; color: #6b7280; font-weight: 400; }
.term-body .think {
  color: #c7d2fe; font-style: italic; border-left: 2px solid #6366f1; padding: 4px 0 4px 10px; margin: 6px 0;
}
.term-body .think::before { content: "<think> … "; color: #818cf8; font-style: normal; }
.term-body .err { color: #fca5a5; font-weight: 700; }
.term-body .okk { color: #86efac; font-weight: 700; }
@keyframes fadein { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.verdict { margin-top: 14px; min-height: 44px; display: flex; align-items: center; gap: 10px; font-weight: 600; }
.pill { display: inline-flex; align-items: center; gap: 6px; border-radius: 999px; padding: 5px 12px; font-size: 0.85rem; font-weight: 600; animation: pop 0.3s ease; }
.pill.bad { background: var(--bad-soft); color: var(--bad); }
.pill.good { background: var(--good-soft); color: var(--good); }
.pill.neutral { background: var(--soft); color: var(--muted); }

/* ---------- conditions ---------- */
.cond-grid { display: grid; grid-template-columns: 1.45fr 1fr; gap: 20px; align-items: start; }
.prompt { display: flex; flex-direction: column; gap: 8px; }
.turnrow { display: flex; gap: 6px; align-items: center; min-width: 0; }
.turnrow .t { font: 600 0.72rem var(--sans); color: var(--muted); width: 50px; flex: none; white-space: nowrap; }
.blk {
  font: 0.75rem var(--mono); padding: 5px 9px; border-radius: 7px; border: 1px solid var(--line);
  background: var(--soft); max-width: 260px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; flex: none;
  transition: max-width 0.5s ease, opacity 0.5s ease, padding 0.5s ease, border-width 0.5s ease;
}
.blk.ob { max-width: 160px; flex: 0 1 auto; }
.blk.th { background: var(--think-soft); border-color: transparent; color: var(--think); font-style: italic; }
.blk.rp { background: var(--soft); }
.blk.cm { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.blk.gone { max-width: 0; opacity: 0; padding-left: 0; padding-right: 0; border-width: 0; margin-left: -6px; }
.blk.live { animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.45; } }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 0.78rem; color: var(--muted); margin-top: 10px; }
.legend span::before { content: ""; display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; background: var(--c); border: 1px solid var(--line); }
.cond-name { font: 700 1rem var(--mono); margin-bottom: 10px; }
.cond-name small { font: 500 0.85rem var(--sans); color: var(--muted); margin-left: 8px; }

.bars { display: flex; flex-direction: column; gap: 9px; }
.bar { display: grid; grid-template-columns: 92px 1fr 52px; align-items: center; gap: 8px; font-size: 0.82rem; transition: opacity 0.3s; }
.bar .nm { font-family: var(--mono); font-size: 0.78rem; }
.bar .track { background: var(--soft); border-radius: 6px; height: 22px; overflow: hidden; }
.bar .fill { height: 100%; width: 0; border-radius: 6px; background: var(--think); transition: width 1.3s cubic-bezier(.2,.8,.2,1); }
.bar .fill.d { background: var(--direct); }
.bar .fill.b { background: var(--bad); }
.bar .fill.g { background: var(--good); }
.bar .val { font-variant-numeric: tabular-nums; font-weight: 600; text-align: right; }
.bar.dim { opacity: 0.4; }
.deltas { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 16px; }
.delta { flex: 1 1 200px; border-radius: 12px; padding: 12px 14px; background: var(--soft); opacity: 0; transform: translateY(6px); transition: opacity 0.5s, transform 0.5s; }
.delta.show { opacity: 1; transform: none; }
.delta b { font-size: 1.5rem; display: block; line-height: 1.2; }
.delta.gen b { color: var(--think); }
.delta span { font-size: 0.82rem; line-height: 1.4; color: var(--muted); display: block; }

/* ---------- fixed history ---------- */
.fixed-grid { display: grid; grid-template-columns: 1fr 1.1fr; gap: 18px; align-items: start; }
.mini-term { background: var(--term); border-radius: 12px; padding: 12px; font: 0.76rem var(--mono); color: var(--term-ink); }
.mini-term .ln { white-space: pre-wrap; margin: 0 0 3px; }
.mini-term .obs { color: #9ca3af; }
.mini-term .sys { color: #fbbf24; }
.mini-term .cmd { color: #fff; font-weight: 700; }
.mini-term .cmd::before { content: "CMD: "; color: #6b7280; font-weight: 400; }
.slot {
  margin-top: 10px; border: 2px dashed var(--think); border-radius: 12px; padding: 10px 12px;
  min-height: 96px; background: var(--think-soft); transition: border-color 0.3s;
}
.slot .arm { font: 700 0.78rem var(--sans); color: var(--think); text-transform: uppercase; letter-spacing: 0.06em; }
.slot .content { font: 0.78rem var(--mono); white-space: pre-wrap; margin-top: 4px; color: var(--ink); min-height: 40px; }
.slot .content.empty { color: var(--muted); font-style: italic; }
.outcome { display: flex; align-items: center; gap: 10px; margin-top: 10px; min-height: 34px; }
.outcome .c { font: 700 0.85rem var(--mono); background: var(--ink); color: var(--bg); border-radius: 8px; padding: 5px 10px; animation: pop 0.3s ease; }

/* ---------- swap ---------- */
.swap-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.swap-col { display: flex; flex-direction: column; gap: 10px; }
.swap-col h4 { margin: 0; font-size: 0.95rem; }
.hl { background: var(--direct-soft); color: var(--ink); border-radius: 4px; padding: 0 3px; font-weight: 700; }
.rcard {
  border-radius: 12px; padding: 10px 12px; font: 0.78rem var(--mono); min-height: 92px;
  background: var(--think-soft); border: 1px solid transparent; color: var(--ink);
  transition: transform 1.1s cubic-bezier(.6,0,.2,1), opacity 0.4s;
}
.rcard .who { font: 700 0.72rem var(--sans); text-transform: uppercase; letter-spacing: 0.06em; color: var(--think); margin-bottom: 4px; }
.rcard.swapped { border-color: var(--direct); }
.counts { margin-top: 18px; display: grid; grid-template-columns: auto 1fr 1fr; gap: 6px; align-items: stretch; font-size: 0.85rem; }
.counts div { padding: 8px 10px; border-radius: 9px; }
.counts .h { font-weight: 600; color: var(--muted); font-size: 0.78rem; }
.counts .n { background: var(--soft); font-variant-numeric: tabular-nums; font-weight: 700; font-size: 1.05rem; text-align: center; transition: background 0.4s; }
.counts .n.bad { background: var(--bad-soft); color: var(--bad); }
.counts .n small { display: block; font-weight: 500; font-size: 0.72rem; color: var(--muted); }

/* ---------- probes ---------- */
.probe-grid { display: grid; grid-template-columns: 0.9fr 1.4fr; gap: 22px; align-items: start; }
.gauge { position: relative; height: 104px; margin: 34px 22px 6px 6px; }
.gauge .scale { position: absolute; top: 22px; left: 0; right: 0; height: 10px; border-radius: 6px; background: linear-gradient(90deg, var(--good-soft), var(--bad-soft)); border: 1px solid var(--line); }
.gauge .end { position: absolute; top: 64px; font-size: 0.75rem; line-height: 1.3; color: var(--muted); white-space: nowrap; }
.gauge .tick { position: absolute; top: 18px; width: 1px; height: 18px; background: var(--muted); }
.gauge .full { position: absolute; top: 12px; height: 30px; border-left: 2px dashed var(--muted); transition: left 0.8s ease; }
.gauge .full span { position: absolute; top: 32px; left: 0; transform: translateX(-50%); font-size: 0.7rem; color: var(--muted); white-space: nowrap; }
.layerpick { display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: 0.85rem; }
.layerpick input { width: 180px; accent-color: var(--think); }
.layerpick input:focus-visible { outline: 2px solid var(--think); outline-offset: 3px; }
.dirrow { cursor: pointer; }
.dirrow .desc { font-size: 0.78rem; color: var(--muted); margin: -2px 0 6px; }
.gauge .needle { position: absolute; top: 10px; width: 4px; height: 38px; margin-left: -2px; background: var(--think); border-radius: 2px; left: 0; transition: left 1.1s cubic-bezier(.2,.8,.2,1); }
.gauge .needle::after { content: attr(data-v); position: absolute; top: -22px; left: 50%; transform: translateX(-50%); font: 700 0.8rem var(--sans); color: var(--think); white-space: nowrap; }
.gauge .needle[data-side="l"]::after { left: 0; transform: none; }
.gauge .needle[data-side="r"]::after { left: auto; right: 0; transform: none; }
.probe-dir { font-weight: 700; min-height: 1.6em; }
.dirs { display: flex; flex-direction: column; gap: 12px; }
.dirrow { padding: 10px 12px; border-radius: 12px; border: 1px solid var(--line); transition: border-color 0.3s, background 0.3s; }
.dirrow.on { border-color: var(--think); background: var(--think-soft); }
.dirrow .nm { font-weight: 600; font-size: 0.9rem; margin-bottom: 6px; }
.dirrow .bar { grid-template-columns: 130px 1fr 44px; }
.dirrow .bar .nm { font-family: var(--sans); font-weight: 400; color: var(--muted); margin: 0; font-size: 0.76rem; }

.episode-grid > *, .cond-grid > *, .fixed-grid > *, .probe-grid > *, .swap-col { min-width: 0; }

/* ---------- misc ---------- */
.takeaways { padding-left: 20px; }
.takeaways li { margin-bottom: 8px; }
pre.bib {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; overflow-x: auto; font: 0.8rem/1.5 var(--mono);
}
footer { text-align: center; color: var(--muted); font-size: 0.8rem; margin-top: 60px; }

@media (max-width: 760px) {
  .episode-grid, .cond-grid, .fixed-grid, .probe-grid { grid-template-columns: 1fr; }
  .term-body { height: 280px; }
  .bar { grid-template-columns: 78px 1fr 46px; }
  .turnrow { flex-wrap: wrap; }
  .turnrow .t { width: 100%; }
  .swap-grid { grid-template-columns: 1fr; }
  .counts { font-size: 0.78rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
