:root {
  --bg: #f8f7f4;
  --panel: #ffffff;
  --fg: #1d1c1a;
  --muted: #6a665e;
  --line: #e4e0d8;
  --grid: #eeebe5;
  --axis: #a09a8f;
  --accent: #2f5bd3;
  --on-accent: #ffffff;
  --exact: #2f5bd3;
  --num: #e07a00;
  --shock: #d0303a;
  --rare: #1f9254;
  --contact: #7a4ee0;
  --left: #0f8b8d;
  --right: #c2255c;
  --water: rgba(47, 91, 211, 0.14);
  --good: #1f9254;
  --sans: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --serif: "Source Serif 4", Georgia, serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #131416;
    --panel: #1b1d20;
    --fg: #ecebe8;
    --muted: #a09d97;
    --line: #2d3035;
    --grid: #24272b;
    --axis: #6d6a65;
    --accent: #7c9cff;
    --on-accent: #0f1530;
    --exact: #8aa8ff;
    --num: #ffb347;
    --shock: #ff6b6b;
    --rare: #4fd18b;
    --contact: #b197fc;
    --left: #3cc9c4;
    --right: #f783ac;
    --water: rgba(124, 156, 255, 0.16);
    --good: #4fd18b;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #131416;
  --panel: #1b1d20;
  --fg: #ecebe8;
  --muted: #a09d97;
  --line: #2d3035;
  --grid: #24272b;
  --axis: #6d6a65;
  --accent: #7c9cff;
  --on-accent: #0f1530;
  --exact: #8aa8ff;
  --num: #ffb347;
  --shock: #ff6b6b;
  --rare: #4fd18b;
  --contact: #b197fc;
  --left: #3cc9c4;
  --right: #f783ac;
  --water: rgba(124, 156, 255, 0.16);
  --good: #4fd18b;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--fg); font-family: var(--sans); font-size: 15px; line-height: 1.5; }
a { color: var(--accent); }
code { font-size: 0.9em; }
.wrap { max-width: 1240px; margin: 0 auto; padding: 0 16px 64px; }
.foot { margin-top: 64px; padding-top: 20px; border-top: 1px solid var(--line); color: var(--muted); font-size: 13px; }
.foot a { color: inherit; }

/* ───────── example pages (shared layout) ───────── */
.crumb { font-size: 14px; color: var(--muted); margin: 18px 0; }
.crumb a { color: inherit; }
.hero { padding: 22px 0 8px; }
.hero h1 { font-family: var(--serif); font-weight: 600; font-size: clamp(30px, 5vw, 44px); line-height: 1.1; margin: 0 0 12px; letter-spacing: -0.01em; }
.hero p { max-width: 68ch; color: var(--muted); font-size: 17px; margin: 0; }
.kicker { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--accent); font-weight: 600; margin-bottom: 8px; }

.lab { display: grid; grid-template-columns: 280px minmax(0, 1fr); gap: 20px; margin: 28px 0 12px; align-items: start; }
.lab > * { min-width: 0; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; }
.controls { padding: 16px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 18px; position: sticky; top: 12px; }
.controls > * { min-width: 0; }
.controls h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 0 0 8px; font-weight: 600; }
.controls p.note { margin: 8px 0 0; font-size: 13px; color: var(--muted); }
select, button { font: inherit; color: var(--fg); }
.controls select { width: 100%; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); }
.presets { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 1px solid var(--line); background: var(--bg); border-radius: 999px; padding: 5px 11px; font-size: 13px; cursor: pointer; }
.chip:hover { border-color: var(--accent); }
.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn { border: 1px solid var(--line); background: var(--bg); border-radius: 8px; padding: 7px 12px; font-size: 14px; cursor: pointer; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btns { display: flex; flex-wrap: wrap; gap: 6px; }
.slider { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 2px 8px; margin-bottom: 8px; font-size: 14px; }
.slider label { display: flex; align-items: center; gap: 6px; }
.slider output { font-variant-numeric: tabular-nums; font-size: 13px; color: var(--muted); }
.slider input { grid-column: 1 / -1; width: 100%; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex: none; }
input[type=range] { accent-color: var(--accent); }
.check { display: flex; gap: 8px; align-items: center; font-size: 14px; margin-bottom: 6px; cursor: pointer; }

.plots { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; min-width: 0; }
.plot { padding: 12px 12px 8px; min-width: 0; }
.plot.wide { grid-column: 1 / -1; }
.plot header { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 4px; flex-wrap: wrap; }
.plot h2 { font-size: 15px; margin: 0; font-weight: 600; }
.plot .hint { font-size: 12.5px; color: var(--muted); }
.plot canvas { display: block; width: 100%; height: 300px; touch-action: none; }
.plot canvas.tall { height: 440px; }
.plot canvas.short { height: 220px; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 12.5px; color: var(--muted); padding: 6px 4px 2px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.sw { width: 18px; height: 0; border-top: 2px solid currentColor; display: inline-block; }
.sw.dash { border-top-style: dashed; }
.sw.thick { border-top-width: 3.5px; }

.readout { grid-column: 1 / -1; padding: 14px 16px; display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px 24px; }
.readout .w { font-size: 14px; }
.readout .w b { display: block; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-bottom: 2px; font-weight: 600; }
.readout .big { display: block; font-size: 26px; font-weight: 600; font-variant-numeric: tabular-nums; line-height: 1.2; }
.num { font-variant-numeric: tabular-nums; }

article { max-width: 720px; margin: 48px auto 0; font-family: var(--serif); font-size: 18px; line-height: 1.65; }
article h2 { font-family: var(--sans); font-size: 22px; margin: 44px 0 10px; letter-spacing: -0.01em; }
article .katex-display { overflow-x: auto; overflow-y: hidden; padding: 4px 0; }
article .try { font-family: var(--sans); font-size: 15px; background: var(--panel); border: 1px solid var(--line); border-left: 3px solid var(--accent); border-radius: 8px; padding: 12px 16px; }
article .try button { font-size: 14px; border: 0; background: none; color: var(--accent); cursor: pointer; padding: 0; text-decoration: underline; text-underline-offset: 2px; }
article ul, article ol { padding-left: 22px; }
article table { border-collapse: collapse; font-family: var(--sans); font-size: 14px; margin: 12px 0; width: 100%; }
article th, article td { border-bottom: 1px solid var(--line); padding: 6px 8px; text-align: right; }
article th:first-child, article td:first-child { text-align: left; }
.pager { display: flex; justify-content: space-between; gap: 12px; max-width: 720px; margin: 48px auto 0; font-size: 14px; }
.pager a { text-decoration: none; }

@media (max-width: 900px) {
  .lab { grid-template-columns: minmax(0, 1fr); }
  .controls { position: static; }
  .plots { grid-template-columns: minmax(0, 1fr); }
  .plot canvas.tall { height: 360px; }
}
