/* ---------- Tokens ---------- */
:root {
  color-scheme: light;
  --bg: #fdfdfc;
  --panel: #f5f4f1;
  --card: #ffffff;
  --ink: #111110;
  --ink-2: #52514e;
  --muted: #898781;
  --line: #e1e0d9;
  --axis: #c3c2b7;
  --ring: rgba(11, 11, 11, 0.10);
  --accent: #2a78d6;
  --accent-ink: #1c5cab;

  /* chart roles */
  --gain: #2a78d6;
  --gain-hatch: #184f95;
  --loss: #e34948;
  --neutral-bar: #c3c2b7;
  --zero: #898781;

  /* MPVI module colors (from the paper's block diagram) */
  --m-plan: #2f9e7a;
  --m-orch: #3b6fb6;
  --m-nav: #c62f26;
  --m-manip: #9a4fc4;
  --m-check: #e0701a;

  --ok: #0a7d32;
  --fail: #c0302f;

  --radius: 14px;
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "SFMono-Regular", Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #111110;
    --panel: #181817;
    --card: #1f1f1e;
    --ink: #f0efec;
    --ink-2: #c3c2b7;
    --muted: #898781;
    --line: #2c2c2a;
    --axis: #383835;
    --ring: rgba(255, 255, 255, 0.10);
    --accent: #5598e7;
    --accent-ink: #86b6ef;
    --gain: #3987e5;
    --gain-hatch: #104281;
    --loss: #e66767;
    --neutral-bar: #52514e;
    --zero: #898781;
    --m-plan: #46c19a;
    --m-orch: #6b9be0;
    --m-nav: #ec5a51;
    --m-manip: #b97de0;
    --m-check: #f08a3a;
    --ok: #3fbf6a;
    --fail: #ef6b6a;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111110;
  --panel: #181817;
  --card: #1f1f1e;
  --ink: #f0efec;
  --ink-2: #c3c2b7;
  --muted: #898781;
  --line: #2c2c2a;
  --axis: #383835;
  --ring: rgba(255, 255, 255, 0.10);
  --accent: #5598e7;
  --accent-ink: #86b6ef;
  --gain: #3987e5;
  --gain-hatch: #104281;
  --loss: #e66767;
  --neutral-bar: #52514e;
  --zero: #898781;
  --m-plan: #46c19a;
  --m-orch: #6b9be0;
  --m-nav: #ec5a51;
  --m-manip: #b97de0;
  --m-check: #f08a3a;
  --ok: #3fbf6a;
  --fail: #ef6b6a;
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: 64px; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 17px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
img, video { max-width: 100%; display: block; }
a { color: var(--accent-ink); text-underline-offset: 2px; }
code { font-family: var(--mono); font-size: 0.86em; background: var(--panel); border: 1px solid var(--line); padding: 0.05em 0.35em; border-radius: 5px; word-break: break-word; }
h1, h2, h3, h4 { line-height: 1.2; margin: 0; letter-spacing: -0.01em; }
p { margin: 0 0 1em; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.wrap {
  max-width: 1120px; margin: 0 auto;
  padding-left: max(24px, env(safe-area-inset-left, 0px));
  padding-right: max(24px, env(safe-area-inset-right, 0px));
}
@media (max-width: 600px) {
  .wrap {
    padding-left: max(16px, env(safe-area-inset-left, 0px));
    padding-right: max(16px, env(safe-area-inset-right, 0px));
  }
  body { font-size: 16px; }
}

/* ---------- Top nav ---------- */
/* paints the phone safe-area band above the sticky bar */
body::before { content: ""; position: fixed; inset: 0 0 auto; height: env(safe-area-inset-top, 0px); z-index: 60; background: var(--bg); }
.topnav {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 50;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: saturate(160%) blur(10px);
  -webkit-backdrop-filter: saturate(160%) blur(10px);
  border-bottom: 1px solid var(--line);
}
.topnav-inner { max-width: 1120px; margin: 0 auto; padding-left: max(24px, env(safe-area-inset-left, 0px)); padding-right: max(24px, env(safe-area-inset-right, 0px)); height: 52px; display: flex; align-items: center; gap: 24px; }
.brand { font-weight: 800; color: var(--ink); text-decoration: none; letter-spacing: 0.02em; }
.navlinks { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; margin-left: auto; }
.navlinks::-webkit-scrollbar { display: none; }
.navlinks a { color: var(--ink-2); text-decoration: none; font-size: 14px; font-weight: 500; padding: 6px 10px; border-radius: 8px; white-space: nowrap; }
.navlinks a:hover { background: var(--panel); color: var(--ink); }
.navlinks a.active { color: var(--ink); background: var(--panel); }
@media (max-width: 600px) { .topnav-inner { padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); gap: 12px; } .navlinks a { padding: 6px 8px; font-size: 13px; } }

/* ---------- Hero ---------- */
.hero { padding: 64px 0 40px; text-align: center; }
.eyebrow { color: var(--accent-ink); font-weight: 600; font-size: 14px; letter-spacing: 0.08em; text-transform: uppercase; margin-bottom: 16px; }
.hero h1 { font-size: clamp(30px, 4.6vw, 52px); font-weight: 800; max-width: 920px; margin: 0 auto; letter-spacing: -0.025em; text-wrap: balance; }
.authors { margin: 20px 0 40px; color: var(--ink-2); font-size: 18px; }

.hero-video { margin: 0 auto; max-width: 960px; }
.hero-video figcaption { margin-top: 12px; }

/* ---------- Video / figure frames ---------- */
.video-frame {
  position: relative; border-radius: var(--radius); overflow: hidden;
  background: #000; aspect-ratio: 16 / 9;
  box-shadow: 0 0 0 1px var(--ring), 0 10px 30px -12px rgba(0,0,0,.25);
}
.video-frame.square { aspect-ratio: 1 / 1; }
.video-frame video { width: 100%; height: 100%; object-fit: contain; }
.badge {
  position: absolute; top: 12px; left: 12px; pointer-events: none;
  font-size: 12px; font-weight: 600; color: #fff;
  background: rgba(0,0,0,.55); padding: 3px 9px; border-radius: 999px;
}
.figure { margin: 0; }
.figure.wide { margin: 40px 0; }
.figure.narrow { max-width: 640px; margin: 40px auto 0; }
.figure-frame { background: #fff; border-radius: var(--radius); padding: 14px; box-shadow: 0 0 0 1px var(--ring); }
.figure-frame img { width: 100%; height: auto; }
figcaption { color: var(--ink-2); font-size: 14.5px; line-height: 1.55; margin-top: 12px; text-align: left; }
.hero figcaption { text-align: center; }

/* ---------- Stats ---------- */
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; margin: 40px auto 0; max-width: 640px; text-align: left; }
.stat { background: var(--card); border-radius: 12px; padding: 16px 18px; box-shadow: 0 0 0 1px var(--ring); margin: 0; }
.stat dt { font-size: 13px; color: var(--ink-2); font-weight: 500; }
.stat dd { margin: 4px 0 0; font-size: 34px; font-weight: 700; letter-spacing: -0.02em; line-height: 1.1; }
.stat dd span { font-size: 20px; color: var(--muted); font-weight: 600; }
.stat p { margin: 6px 0 0; font-size: 13px; color: var(--muted); line-height: 1.4; }
.footnote { font-size: 13px; color: var(--muted); margin: 10px 0 0; }
@media (max-width: 820px) { .stats { grid-template-columns: repeat(2, 1fr); } }

/* ---------- Sections ---------- */
.section { padding: 80px 0; }
.section.alt { background: var(--panel); }
.section-head { max-width: 780px; margin-bottom: 36px; }
.kicker { color: var(--accent-ink); font-weight: 600; font-size: 13px; letter-spacing: 0.08em; text-transform: uppercase; margin-bottom: 8px; }
.section-head h2 { font-size: clamp(26px, 3.2vw, 36px); font-weight: 750; letter-spacing: -0.02em; margin-bottom: 14px; text-wrap: balance; }
.lede { color: var(--ink-2); font-size: 17.5px; margin: 0; }
.subhead { font-size: 22px; font-weight: 700; margin: 56px 0 20px; }
.prose { max-width: 780px; }
.prose h2 { font-size: 26px; margin: 8px 0 16px; }
.prose p, .prose-p { color: var(--ink); max-width: 780px; }
.muted { color: var(--ink-2); }
@media (max-width: 600px) { .section { padding: 56px 0; } }

/* ---------- Observation / key idea ---------- */
.idea-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.idea { border-radius: var(--radius); padding: 22px 24px; background: var(--card); box-shadow: 0 0 0 1px var(--ring); border-top: 4px solid var(--c); }
.idea h3 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--c); margin-bottom: 8px; }
.idea p { margin: 0; font-size: 17px; }
.observation { --c: var(--m-orch); }
.keyidea { --c: var(--m-check); }
@media (max-width: 760px) { .idea-grid { grid-template-columns: 1fr; } }

/* ---------- Module inline labels & tags ---------- */
.mod { font-weight: 600; }
.mod.nav { color: var(--m-nav); }
.mod.manip { color: var(--m-manip); }
.mod.check { color: var(--m-check); }
.tag { display: inline-block; font-size: 11.5px; font-weight: 700; letter-spacing: 0.04em; padding: 1px 7px; border-radius: 5px; margin-right: 6px; vertical-align: 1px; border: 1px solid currentColor; }
.tag.fail { color: var(--fail); }
.tag.ok { color: var(--ok); }

/* ---------- Segmented control ---------- */
.segmented { display: inline-flex; background: var(--card); padding: 4px; border-radius: 12px; box-shadow: 0 0 0 1px var(--ring); margin-bottom: 20px; flex-wrap: wrap; }
.segmented button { font: inherit; font-size: 14px; font-weight: 600; border: 0; background: transparent; color: var(--ink-2); padding: 8px 14px; border-radius: 9px; cursor: pointer; }
.segmented button[aria-selected="true"] { background: var(--ink); color: var(--bg); }

/* ---------- Failure grid ---------- */
.failure-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; }
.failure { background: var(--card); border-radius: var(--radius); padding: 12px 12px 18px; box-shadow: 0 0 0 1px var(--ring); }
.failure .video-frame { aspect-ratio: 4 / 3; box-shadow: none; border-radius: 10px; }
.failure-grid[data-set-panel="hw"] .failure .video-frame { aspect-ratio: 16 / 9; }
.failure h3 { font-size: 17px; margin: 14px 6px 2px; }
.failure p { font-size: 14.5px; margin: 8px 6px 0; color: var(--ink-2); line-height: 1.5; }
.failure .task { margin-top: 2px; }
@media (max-width: 900px) { .failure-grid { grid-template-columns: 1fr; max-width: 560px; } }

.split { display: grid; grid-template-columns: 1fr 1fr; gap: 28px; margin-top: 40px; align-items: start; }
@media (max-width: 820px) { .split { grid-template-columns: 1fr; } }

/* ---------- Modules ---------- */
.modules { display: grid; grid-template-columns: repeat(5, 1fr); gap: 12px; }
.module { position: relative; background: var(--card); border-radius: 12px; padding: 18px 16px 16px; box-shadow: 0 0 0 1px var(--ring); border-top: 4px solid var(--mc); }
.module .num { display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 50%; background: var(--mc); color: #fff; font-size: 13px; font-weight: 700; margin-bottom: 10px; }
.module h3 { font-size: 16px; margin-bottom: 8px; }
.module h3 small { display: block; font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; margin-top: 2px; }
.module p { font-size: 14px; color: var(--ink-2); margin: 0; line-height: 1.5; }
@media (max-width: 1040px) { .modules { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 560px) { .modules { grid-template-columns: 1fr; } }

/* ---------- Subtask plan list (hardware section) ---------- */
.plan { list-style: none; margin: 0; padding: 0; counter-reset: seg -1; display: grid; gap: 8px; }
.seg {
  counter-increment: seg;
  display: grid; grid-template-columns: 40px 112px 1fr; align-items: center; gap: 12px;
  padding: 8px 12px; border-radius: 10px; background: var(--panel);
  border-left: 4px solid var(--sc, var(--muted));
}
.seg::before { content: "[" counter(seg) "]"; font-family: var(--mono); font-size: 13px; color: var(--muted); }
.seg.nav { --sc: var(--m-nav); }
.seg.manip { --sc: var(--m-manip); }
.seg .who { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--sc, var(--muted)); }
.seg .what { font-size: 14.5px; font-weight: 500; }
@media (max-width: 760px) {
  .seg { grid-template-columns: 40px 1fr; row-gap: 2px; }
  .seg .who, .seg .what { grid-column: 2; }
  .seg::before { grid-row: 1 / span 2; align-self: start; padding-top: 2px; }
}

/* ---------- Charts ---------- */
.chart-card { position: relative; background: var(--card); border-radius: var(--radius); padding: 22px 22px 14px; box-shadow: 0 0 0 1px var(--ring); }
.chart-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px 24px; flex-wrap: wrap; margin-bottom: 12px; }
.chart-head h3 { font-size: 17px; }
.chart-sub { font-size: 13.5px; color: var(--ink-2); margin: 4px 0 0; }
.chart-caption { font-size: 14.5px; color: var(--ink-2); line-height: 1.55; margin: 12px 0 4px; }
.hw-side .prose-p { font-size: 15.5px; margin: 0 0 14px; }
.hw-side .plan { margin-bottom: 14px; }
.legend { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 13px; color: var(--ink-2); }
.legend li { display: inline-flex; align-items: center; gap: 6px; }
.sw { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }
.sw.gain { background: var(--gain); }
.sw.hatched { background: repeating-linear-gradient(135deg, var(--gain) 0 2.2px, var(--card) 2.2px 3.6px); }
.sw.loss { background: var(--loss); }
.sw.zero { height: 3px; background: var(--zero); border-radius: 2px; }
.chart { width: 100%; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; font-family: var(--font); }
.chart .grid line { stroke: var(--line); stroke-width: 1; }
.chart .baseline { stroke: var(--axis); stroke-width: 1; }
.chart .tick text { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .axis-title { fill: var(--ink-2); font-size: 12px; font-weight: 500; }
.chart .hit { fill: transparent; cursor: pointer; }
.chart .col:hover .bar, .chart .col.hover .bar { filter: brightness(1.12); }
.chart .col:hover .colbg, .chart .col.hover .colbg { fill: var(--panel); }
.chart .colbg { fill: transparent; }
.chart .bar-label { fill: var(--ink); font-size: 12.5px; font-weight: 600; font-variant-numeric: tabular-nums; }
.chart .row-label { fill: var(--ink); font-size: 13.5px; font-weight: 500; }
.chart .row-label.strong { font-weight: 700; }
.chart .row-delta { fill: var(--ink-2); font-size: 12.5px; }

.tooltip {
  position: absolute; z-index: 10; pointer-events: none;
  background: var(--card); color: var(--ink); border-radius: 10px; padding: 10px 12px;
  box-shadow: 0 0 0 1px var(--ring), 0 12px 28px -8px rgba(0,0,0,.3);
  font-size: 13px; min-width: 190px; max-width: 260px;
}
.tooltip .tt-title { font-weight: 600; font-size: 13px; margin-bottom: 6px; word-break: break-word; }
.tooltip .tt-row { display: flex; justify-content: space-between; gap: 14px; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.tooltip .tt-row strong { color: var(--ink); }
.tooltip .tt-key { display: inline-block; width: 10px; height: 2px; margin-right: 6px; vertical-align: middle; border-radius: 1px; }

/* ---------- Tables ---------- */
.table-wrap { margin-top: 20px; background: var(--card); border-radius: var(--radius); box-shadow: 0 0 0 1px var(--ring); }
.table-wrap > summary { cursor: pointer; padding: 14px 20px; font-weight: 600; font-size: 15px; list-style: none; display: flex; align-items: center; gap: 10px; }
.table-wrap > summary::-webkit-details-marker { display: none; }
.table-wrap > summary::before { content: ""; width: 8px; height: 8px; border-right: 2px solid var(--ink-2); border-bottom: 2px solid var(--ink-2); transform: rotate(-45deg); transition: transform .2s; }
.table-wrap[open] > summary::before { transform: rotate(45deg); }
.table-tools { display: flex; flex-wrap: wrap; gap: 10px 16px; align-items: center; padding: 0 20px 12px; }
.search input { font: inherit; font-size: 14px; padding: 8px 12px; border-radius: 9px; border: 1px solid var(--line); background: var(--bg); color: var(--ink); width: 260px; max-width: 100%; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { font: inherit; font-size: 13px; font-weight: 600; padding: 6px 12px; border-radius: 999px; border: 1px solid var(--line); background: transparent; color: var(--ink-2); cursor: pointer; }
.chip[aria-pressed="true"] { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.table-scroll { overflow-x: auto; padding: 0 8px 12px; max-height: 560px; overflow-y: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 14px; font-variant-numeric: tabular-nums; }
table.data th, table.data td { padding: 8px 12px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.data th { position: sticky; top: 0; background: var(--card); font-size: 12.5px; color: var(--ink-2); font-weight: 600; z-index: 1; }
table.data th button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
table.data th button[aria-sort]::after { content: " \2193"; }
table.data th button[aria-sort="ascending"]::after { content: " \2191"; }
table.data .num { text-align: right; }
table.data td.task { font-family: var(--mono); font-size: 12.5px; }
table.data tr:hover td { background: var(--panel); }
table.data td.best { font-weight: 700; }
.dcell { display: inline-flex; align-items: center; gap: 8px; justify-content: flex-end; }
.dbar { display: inline-block; width: 60px; height: 8px; position: relative; }
.dbar::before { content: ""; position: absolute; left: 50%; top: -2px; bottom: -2px; width: 1px; background: var(--axis); }
.dbar i { position: absolute; top: 0; height: 8px; border-radius: 2px; }
.dsign { color: var(--muted); font-size: 11px; width: 10px; display: inline-block; text-align: center; }


/* ---------- Ablations ---------- */
.ablation-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin-top: 20px; }
.ablation { background: var(--card); border-radius: 12px; padding: 18px 20px; box-shadow: 0 0 0 1px var(--ring); border-left: 4px solid var(--mc); }
.ablation h3 { font-size: 16px; margin-bottom: 8px; display: flex; justify-content: space-between; gap: 10px; align-items: baseline; }
.ablation p { font-size: 14.5px; color: var(--ink-2); margin: 0; }
.delta { font-size: 14px; font-weight: 700; white-space: nowrap; font-variant-numeric: tabular-nums; }
.delta.down { color: var(--fail); }
.delta.up { color: var(--ok); }
@media (max-width: 900px) { .ablation-grid { grid-template-columns: 1fr; } }

/* ---------- Hardware ---------- */
.hw-layout { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); gap: 28px; align-items: center; }
.hw-video figcaption { font-style: italic; }
@media (max-width: 860px) { .hw-layout { grid-template-columns: 1fr; } }
.compare { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-top: 40px; }
.compare-col { background: var(--card); border-radius: var(--radius); padding: 22px; box-shadow: 0 0 0 1px var(--ring); display: grid; grid-template-columns: 120px 1fr; gap: 6px 20px; align-content: start; }
.compare-col img { grid-row: 1 / span 2; width: 120px; height: 140px; object-fit: contain; background: #fff; border-radius: 10px; padding: 6px; }
.compare-col h3 { font-size: 17px; align-self: end; }
.compare-col h3 small { display: block; font-size: 13px; color: var(--muted); font-weight: 500; margin-top: 3px; }
.compare-col dl { grid-column: 2; margin: 6px 0 0; font-size: 14px; display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; }
.compare-col dt { font-weight: 600; color: var(--ink-2); }
.compare-col dd { margin: 0; color: var(--ink); }
@media (max-width: 900px) { .compare { grid-template-columns: 1fr; } }
@media (max-width: 520px) {
  .compare-col { grid-template-columns: 1fr; }
  .compare-col img { grid-row: auto; width: 100%; height: 160px; }
  .compare-col dl { grid-column: 1; grid-template-columns: 1fr; gap: 0 0; }
  .compare-col dd { margin-bottom: 8px; }
}



/* ---------- Prompts ---------- */
.prompts { display: grid; gap: 16px; max-width: 900px; }
.prompt { background: var(--card); border-radius: 12px; box-shadow: 0 0 0 1px var(--ring); overflow: hidden; }
.prompt-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.prompt-head h4 { font-size: 15px; }
.copy { font: inherit; font-size: 13px; font-weight: 600; padding: 5px 12px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel); color: var(--ink); cursor: pointer; flex: none; }
.copy:hover { border-color: var(--axis); }
.prompt pre { margin: 0; padding: 16px; overflow-x: auto; max-height: 380px; font-size: 13px; line-height: 1.55; background: var(--panel); }
.prompt pre code { background: none; border: 0; padding: 0; font-size: inherit; word-break: normal; }
.prompt-out { margin: 0; padding: 12px 16px; font-family: var(--mono); font-size: 13px; border-top: 1px solid var(--line); }
.prompt-out span { font-family: var(--font); font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; margin-right: 10px; }

/* ---------- Footer ---------- */
.footer { border-top: 1px solid var(--line); padding: 32px 0 48px; color: var(--muted); font-size: 14px; }
.footer p { margin: 0; }

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  * { transition: none !important; }
}
