:root {
  --bg: #fbfbfd;
  --surface: #ffffff;
  --fg: #1d1f24;
  --muted: #5f6672;
  --line: #e3e5ea;
  --accent: #3657c8;
  --accent-fg: #ffffff;
  --code: #f2f3f6;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111317;
    --surface: #181b21;
    --fg: #e7e9ee;
    --muted: #9aa1ad;
    --line: #2b3038;
    --accent: #7d97f2;
    --accent-fg: #0d1020;
    --code: #1f232b;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #111317; --surface: #181b21; --fg: #e7e9ee; --muted: #9aa1ad; --line: #2b3038;
  --accent: #7d97f2; --accent-fg: #0d1020; --code: #1f232b; color-scheme: dark;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--fg); font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--accent); }
.wrap { max-width: 1240px; margin: 0 auto; padding: 0 16px; }
header { border-bottom: 1px solid var(--line); background: var(--surface); }
h1 { margin: 18px 0 2px; font-size: 1.6rem; letter-spacing: -0.01em; }
h2 { font-size: 1.1rem; margin: 1.4em 0 0.4em; }
.lede { margin: 0 0 12px; color: var(--muted); }
nav { display: flex; gap: 2px; overflow-x: auto; }
nav button { background: none; border: 0; border-bottom: 2px solid transparent; color: var(--muted); padding: 10px 14px; font: inherit; cursor: pointer; white-space: nowrap; }
nav button[aria-selected="true"] { color: var(--fg); border-bottom-color: var(--accent); font-weight: 600; }
main { padding-top: 14px; padding-bottom: 24px; }
.status { color: var(--muted); margin: 0 0 8px; min-height: 1.5em; }
.status.error { color: #c0392b; }
.hint { color: var(--muted); margin: 0 0 12px; max-width: 980px; }
.controls { display: flex; flex-wrap: wrap; gap: 10px 16px; align-items: flex-end; margin-bottom: 12px; }
.controls label, fieldset { display: flex; flex-direction: column; gap: 4px; font-size: 0.85rem; color: var(--muted); }
.controls .grow { flex: 1 1 240px; }
fieldset { border: 0; padding: 0; margin: 0; flex-direction: row; flex-wrap: wrap; gap: 8px; align-items: center; }
fieldset legend { font-size: 0.85rem; color: var(--muted); padding: 0; margin-bottom: 4px; width: 100%; }
.controls fieldset label { flex-direction: row; align-items: center; gap: 3px; color: var(--fg); font-size: 0.9rem; }
select, input[type="number"] { font: inherit; color: var(--fg); background: var(--surface); border: 1px solid var(--line); border-radius: 6px; padding: 5px 8px; min-width: 0; }
input[type="number"] { width: 6.5em; }
input[type="range"] { width: 100%; accent-color: var(--accent); }
button { font: inherit; color: var(--fg); background: var(--surface); border: 1px solid var(--line); border-radius: 6px; padding: 6px 12px; cursor: pointer; }
button.primary { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); font-weight: 600; }
button:disabled { opacity: 0.55; cursor: progress; }
.pager { display: inline-flex; align-items: center; gap: 6px; }
.pager span { min-width: 5.5em; text-align: center; font-size: 0.9rem; color: var(--muted); }
.split { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 16px; align-items: start; }
.plots > div { width: 100%; }
.plot-lg { width: 100%; height: 640px; }
.plot-md { width: 100%; height: 480px; }
aside { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 12px; }
aside button { width: 100%; margin-top: 10px; }
table.info { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
table.info td, table.info th { padding: 4px 6px; border-bottom: 1px solid var(--line); text-align: left; }
table.info td:last-child, table.info th:not(:first-child) { text-align: right; font-variant-numeric: tabular-nums; }
.note p { margin: 0 0 8px; }
.note b { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); font-size: 0.9rem; }
.prose { max-width: 860px; }
pre { background: var(--code); border: 1px solid var(--line); border-radius: 8px; padding: 12px; overflow-x: auto; font-size: 0.85rem; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
footer { padding-top: 8px; padding-bottom: 24px; border-top: 1px solid var(--line); }
@media (max-width: 860px) {
  .split { grid-template-columns: minmax(0, 1fr); }
  .plot-lg { height: 480px; }
}

/* data generation tab */
.sticky { position: sticky; top: 0; z-index: 5; background: var(--bg); padding: 8px 0; margin-bottom: 4px; }
nav.stages { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0 14px; }
nav.stages a { text-decoration: none; font-size: 0.85rem; padding: 4px 10px; border: 1px solid var(--line); border-radius: 999px; color: var(--fg); background: var(--surface); }
nav.stages a:hover { border-color: var(--accent); }
article.stage { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; margin: 0 0 16px; scroll-margin-top: 70px; }
article.stage > header { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 12px; margin-bottom: 6px; }
article.stage h3 { margin: 0; font-size: 1.05rem; }
article.stage .num { font-size: 1.2rem; color: var(--accent); }
article.stage header code { font-size: 0.78rem; color: var(--muted); background: var(--code); padding: 2px 6px; border-radius: 4px; }
article.stage .ref { font-size: 0.78rem; color: var(--muted); margin-left: auto; }
article.stage aside { background: var(--bg); }
.pair { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.triple { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.seg { display: inline-flex; gap: 4px; }
.seg button { padding: 3px 10px; font-size: 0.85rem; }
.seg button.on { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
.chain { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin: 6px 0 10px; }
.chain .step { display: flex; flex-direction: column; border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; background: var(--bg); font-size: 0.82rem; }
.chain .step span { color: var(--muted); font-variant-numeric: tabular-nums; }
.chain .arrow { color: var(--muted); }
table.info.wide { margin-top: 10px; }
table.info tr.hl td { font-weight: 600; }
b.pass { color: #2e9d55; } b.fail { color: #d0453a; }
pre.record { font-size: 0.75rem; max-height: 220px; overflow: auto; margin: 10px 0 0; }
aside label input[type="range"] { margin-top: 4px; }
@media (max-width: 860px) { .pair, .triple { grid-template-columns: minmax(0, 1fr); } article.stage .ref { margin-left: 0; } }
select { max-width: 100%; }
.controls label.grow select { width: 100%; }
table.info.wide { display: block; overflow-x: auto; }
table.info.wide td:not(:first-child), table.info.wide th:not(:first-child) { text-align: right; }
