:root {
  --bg: #ffffff;
  --card: #ffffff;
  --ink: #111418;
  --muted: #5d6670;
  --rule: #d9dee3;
  --gridline: #eef1f4;
  --a: #f08a24;
  --b: #8e72c9;
  --hit: #1b9e77;
  --bad: #d62839;
  --bad-bg: #fdecee;
  --ok-bg: #e7f5ef;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1215;
    --card: #161a1e;
    --ink: #e6e9ec;
    --muted: #96a0aa;
    --rule: #2b3238;
    --gridline: #1d2227;
    --a: #f5a04d;
    --b: #a993e0;
    --hit: #34c495;
    --bad: #ff5c6c;
    --bad-bg: #3a1a1f;
    --ok-bg: #15302a;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  padding: 24px 16px 48px;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.45 var(--sans);
}

header.page, main { max-width: 1280px; margin: 0 auto; }

h1 { font-size: 26px; margin: 0 0 8px; letter-spacing: -0.01em; }
h2 { font-size: 20px; margin: 0 0 10px; letter-spacing: -0.01em; }
h3 { font-size: 16px; margin: 0 0 8px; }
.lede { max-width: 72ch; margin: 0 0 14px; color: var(--muted); font-size: 15px; }
.toc { display: flex; flex-wrap: wrap; gap: 4px 14px; padding: 10px 0; border-top: 1px solid var(--rule); font-size: 13px; }
.toc a { color: var(--ink); text-decoration: none; border-bottom: 1px solid var(--rule); }
.toc a:hover { border-color: var(--ink); }

.step { padding: 28px 0 8px; border-top: 1px solid var(--rule); }
#samples, #merge, #tree, #grid { border-top: 0; padding-top: 12px; }
.prose { max-width: 72ch; }
.prose p { margin: 0 0 10px; }
.plan { margin: 0 0 12px; padding-left: 22px; }
.plan li { margin-bottom: 4px; }

.demo {
  max-width: 820px;
  margin: 10px 0 16px;
  padding: 10px;
  border: 1px solid var(--rule);
  border-radius: 6px;
  background: var(--card);
}
.fig { display: block; width: 100%; height: auto; }
.fig.drag { touch-action: none; cursor: grab; }
.fig.dragging { cursor: grabbing; }
.controls-row, .presets { display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: center; margin-bottom: 8px; font-size: 13px; }
.slider { display: flex; gap: 8px; align-items: center; flex: 1; min-width: 180px; max-width: 420px; }
.slider input { flex: 1; }
button {
  padding: 4px 10px;
  border: 1px solid var(--rule);
  border-radius: 4px;
  background: var(--bg);
  color: var(--ink);
  font: 13px var(--sans);
  cursor: pointer;
}
button:hover { border-color: var(--muted); }
button.on { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.readout { margin-top: 8px; font: 12px/1.6 var(--mono); color: var(--muted); }
.readout b { color: var(--ink); }
.tag { display: inline-block; margin-bottom: 2px; padding: 0 6px; border-radius: 3px; background: var(--gridline); color: var(--ink); font-weight: 600; }

.snap { fill: var(--rule); }
.ext { stroke-width: 1; stroke-dasharray: 4 4; opacity: 0.7; }
.ext-a { stroke: var(--a); }
.ext-b { stroke: var(--b); }
.handle { fill: transparent; stroke-width: 1.5; }
.handle-a { stroke: var(--a); }
.handle-b { stroke: var(--b); }
.label { fill: var(--ink); font: italic 600 15px var(--sans); }
.label-a { fill: var(--a); font-style: normal; }
.label-b { fill: var(--b); font-style: normal; }
.sign { font: 700 15px var(--mono); }
.sign.pos { fill: var(--hit); }
.sign.neg { fill: var(--bad); }
.sign.zero { fill: var(--ink); }
.small { fill: var(--muted); font: 11px var(--mono); }

.sample { stroke: var(--gridline); }
.above-a { fill: var(--a); opacity: 0.6; }
.above-b { fill: var(--b); opacity: 0.6; }
.above-0 { fill: var(--hit); }
.flip { stroke: var(--hit); stroke-width: 2; }
.band { fill: var(--hit); fill-opacity: 0.08; stroke: var(--hit); stroke-opacity: 0.4; }
.band.skip { fill: var(--muted); fill-opacity: 0.08; stroke: var(--muted); stroke-dasharray: 4 3; }
.tick { stroke: var(--muted); }
.focus-a, .focus-b { fill: none; stroke-width: 6; stroke-linecap: round; stroke-linejoin: round; }
.focus-a { stroke: var(--a); }
.focus-b { stroke: var(--b); }
.focus-b.dim { stroke-width: 3; opacity: 0.6; }
.box { stroke-width: 1.5; }
.box-a { stroke: var(--a); fill: var(--a); fill-opacity: 0.1; }
.box-b { stroke: var(--b); fill: var(--b); fill-opacity: 0.1; }
.box.out { fill-opacity: 0; stroke-opacity: 0.35; stroke-dasharray: 3 3; stroke-width: 1; }
.cell { fill: var(--b); stroke: var(--card); stroke-width: 1; }
.cell-sel { fill: none; stroke: var(--ink); stroke-width: 2; }
.line-a.thin, .line-b.thin { stroke-width: 2; }
code { font-family: var(--mono); font-size: 0.92em; }

.bar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 24px;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
  border-top: 1px solid var(--rule);
  border-bottom: 1px solid var(--rule);
}
.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 16px;
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: 12px;
  color: var(--muted);
}
.legend li { display: flex; align-items: center; gap: 6px; }
.legend svg { overflow: visible; }

.controls { display: flex; gap: 12px; align-items: center; font-size: 13px; }
.controls input[type="search"] {
  width: 200px;
  padding: 5px 8px;
  border: 1px solid var(--rule);
  border-radius: 4px;
  background: var(--card);
  color: var(--ink);
  font: inherit;
}

.summary { margin: 12px 0 16px; font-family: var(--mono); font-size: 12px; color: var(--muted); }
.summary .bad { color: var(--bad); font-weight: 600; }

#cases .bar { margin-top: 8px; }
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 10px;
}

.card {
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--card);
  border: 1px solid var(--rule);
  border-radius: 6px;
  overflow: hidden;
}
.card.fail { border-color: var(--bad); }
.card[hidden] { display: none; }

.card h2 {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  justify-content: space-between;
  margin: 0;
  padding: 8px 10px 6px;
  font-size: 13px;
  font-weight: 600;
  line-height: 1.3;
}
.status {
  flex: none;
  padding: 1px 6px;
  border-radius: 3px;
  font: 600 10px/16px var(--mono);
  text-transform: uppercase;
  background: var(--ok-bg);
  color: var(--hit);
}
.fail .status { background: var(--bad-bg); color: var(--bad); }

.plot { display: block; width: 100%; height: auto; border-top: 1px solid var(--gridline); border-bottom: 1px solid var(--gridline); }
.plot .frame { fill: none; stroke: var(--gridline); }
.plot .axis { stroke: var(--rule); stroke-dasharray: 2 3; }

.line-a, .line-b { fill: none; stroke-width: 4; stroke-linecap: round; stroke-linejoin: round; opacity: 0.6; }
.line-a { stroke: var(--a); }
.line-b { stroke: var(--b); }
.dot-a { fill: var(--a); opacity: 0.8; }
.dot-b { fill: var(--b); opacity: 0.8; }
.vertex-a, .vertex-b { opacity: 0.6; }
.vertex-a { fill: var(--a); }
.vertex-b { fill: var(--b); }

.hit { stroke: var(--hit); stroke-width: 2; }
.hit.cross { fill: var(--hit); }
.hit.touch { fill: var(--card); }
.hit.end { fill: var(--hit); fill-opacity: 0.35; }
.stretch { fill: none; stroke: var(--hit); stroke-linejoin: round; stroke-width: 2; stroke-linecap: round; }
.stretch-end { fill: var(--hit); }
.count { fill: var(--hit); font: 600 10px var(--mono); }
.missed { fill: none; stroke: var(--bad); stroke-width: 1.5; stroke-dasharray: 3 2; }

.hits {
  margin: 0;
  padding: 6px 10px 8px;
  list-style: none;
  font: 11px/1.5 var(--mono);
  color: var(--muted);
  overflow-wrap: anywhere;
}
.hits .type { color: var(--ink); font-weight: 600; }
.hits .none { font-style: italic; }
.hits .problem { color: var(--bad); }

.inputs { padding: 0 10px 8px; font: 11px/1.4 var(--mono); color: var(--muted); }
.inputs summary { cursor: pointer; }
.inputs pre { margin: 4px 0 0; white-space: pre-wrap; overflow-wrap: anywhere; }

@media (max-width: 560px) {
  .controls { width: 100%; }
  .controls input[type="search"] { flex: 1; width: auto; }
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .card h2 { padding: 6px 8px 4px; font-size: 12px; }
  .status { padding: 0 4px; font-size: 9px; line-height: 14px; }
  .hits, .inputs { padding-left: 8px; padding-right: 8px; font-size: 10px; }
}
