:root {
  color-scheme: light;
  --page: #fcfbf8;
  --surface: #f3f1eb;
  --ink: #0f0e0b;
  --ink-2: #4d4a43;
  --muted: #78746a;
  --line: #e3dfd5;
  --axis: #c5bfb1;
  --tree: #a7a194;
  --tree-soft: #d8d3c7;
  --accent: #8a6d3b;
  --accent-soft: rgba(188, 169, 138, 0.26);
  --c1: #1d1c19;
  --c2: #b39a6c;
  --c3: #cfcabf;
  --second: #8a6d3b;
  --good: #4d4a43;
  --good-mark: #4d4a43;
  --bad: #8a6d3b;
  --bad-mark: #b39a6c;
  --ring: rgba(15, 14, 11, 0.1);
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #12110d;
    --surface: #1b1a15;
    --ink: #efe5d0;
    --ink-2: #c9c0ad;
    --muted: #8f887a;
    --line: #2c2a23;
    --axis: #48443a;
    --tree: #6f6a5e;
    --tree-soft: #36332b;
    --accent: #bca98a;
    --accent-soft: rgba(188, 169, 138, 0.18);
    --c1: #efe5d0;
    --c2: #bca98a;
    --c3: #6f6a5e;
    --second: #bca98a;
    --good: #c9c0ad;
    --good-mark: #c9c0ad;
    --bad: #d9c49d;
    --bad-mark: #bca98a;
    --ring: rgba(239, 229, 208, 0.1);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #12110d;
  --surface: #1b1a15;
  --ink: #efe5d0;
  --ink-2: #c9c0ad;
  --muted: #8f887a;
  --line: #2c2a23;
  --axis: #48443a;
  --tree: #6f6a5e;
  --tree-soft: #36332b;
  --accent: #bca98a;
  --accent-soft: rgba(188, 169, 138, 0.18);
  --c1: #efe5d0;
  --c2: #bca98a;
  --c3: #6f6a5e;
  --second: #bca98a;
  --good: #c9c0ad;
  --good-mark: #c9c0ad;
  --bad: #d9c49d;
  --bad-mark: #bca98a;
  --ring: rgba(239, 229, 208, 0.1);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: 64px; }
body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font: 16px/1.6 var(--sans);
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration-color: var(--axis); text-underline-offset: 3px; }
a:hover { text-decoration-color: currentColor; }
dfn { font-style: normal; font-weight: 600; }
sup { line-height: 0; }

.top {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 10px max(16px, calc((100vw - 1040px) / 2));
  background: color-mix(in srgb, var(--page) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
  font-size: 14px;
}
.mark { display: inline-flex; align-items: center; gap: 8px; font-weight: 650; text-decoration: none; letter-spacing: -0.01em; }
.mark svg { width: 18px; height: 18px; }
.top nav { display: flex; gap: 18px; overflow-x: auto; scrollbar-width: none; flex: 1; }
.top nav a, .lab { text-decoration: none; color: var(--ink-2); white-space: nowrap; }
.top nav a:hover, .lab:hover { color: var(--ink); }
.lab { border: 1px solid var(--line); border-radius: 6px; padding: 3px 10px; }

main { max-width: 720px; margin: 0 auto; padding: 0 16px 48px; }
section { padding-top: 56px; }
section + section { border-top: 1px solid var(--line); margin-top: 56px; }
h1 { font-size: clamp(32px, 5vw, 46px); line-height: 1.08; letter-spacing: -0.025em; margin: 8px 0 18px; font-weight: 700; }
h2 { font-size: 26px; letter-spacing: -0.015em; line-height: 1.2; margin: 0 0 14px; }
h3 { font-size: 17px; margin: 28px 0 8px; }
p { margin: 0 0 14px; }
.lede { font-size: 18px; color: var(--ink-2); }
.note { font-size: 13.5px; color: var(--muted); line-height: 1.5; }
.hero { padding-top: 48px; }

.tiles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; margin: 28px 0 14px; }
.tile { background: var(--page); padding: 16px 16px 14px; }
.tile .k { font-size: 12.5px; color: var(--muted); }
.tile .v { font-size: 30px; font-weight: 650; letter-spacing: -0.02em; line-height: 1.15; margin: 6px 0 4px; font-variant-numeric: tabular-nums; }
.tile .v small { font-size: 15px; font-weight: 500; color: var(--ink-2); margin-left: 2px; }
.tile .s { font-size: 12.5px; color: var(--ink-2); display: flex; align-items: center; gap: 6px; }

figure { margin: 24px 0; }
figcaption { font-size: 14px; margin-bottom: 10px; display: flex; flex-direction: column; gap: 2px; }
figcaption span { color: var(--muted); font-size: 13px; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart text, .tree text { font-family: var(--sans); fill: var(--ink-2); }
.chart .axis line, .chart .axis path { stroke: var(--axis); }
.chart .grid { stroke: var(--line); }
.chart .tick { font-size: 11px; fill: var(--muted); }
.chart .label { font-size: 12.5px; fill: var(--ink); }
.chart .value, .chart .label { paint-order: stroke; stroke: var(--page); stroke-width: 4px; stroke-linejoin: round; }
.chart .value { font-size: 12px; fill: var(--ink-2); font-variant-numeric: tabular-nums; }
.chart .hit { fill: transparent; cursor: default; }
.chart .hl { fill: var(--accent); }
.chart .base { fill: var(--tree); }
.chart .budget { stroke: var(--ink); stroke-dasharray: 4 3; }

details { border: 1px solid var(--line); border-radius: 8px; padding: 10px 14px; margin: 16px 0; }
details > summary { cursor: pointer; font-size: 14px; color: var(--ink-2); }
details[open] > summary { margin-bottom: 10px; }
details p { font-size: 14px; color: var(--ink-2); }

table { border-collapse: collapse; width: 100%; font-size: 13.5px; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 7px 10px 7px 0; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-weight: 550; color: var(--muted); font-size: 12.5px; }
td.n, th.n { text-align: right; }
tr.sel td { background: var(--accent-soft); }
tr.sel td:first-child { box-shadow: inset 3px 0 0 var(--accent); padding-left: 8px; }
.table-wrap { overflow-x: auto; margin: 16px 0; }
th button { all: unset; cursor: pointer; }
th button:hover { color: var(--ink); }
th button[aria-sort]::after { content: " ↓"; }

.construction { display: grid; grid-template-columns: 240px 1fr; gap: 24px; align-items: start; margin: 20px 0; }
.steps { margin: 0; padding: 0; list-style: none; counter-reset: s; font-size: 14px; }
.steps li { counter-increment: s; padding: 10px 12px 10px 40px; border-radius: 8px; position: relative; cursor: default; color: var(--ink-2); }
.steps li strong { color: var(--ink); display: block; }
.steps li::before { content: counter(s); position: absolute; left: 12px; top: 10px; width: 20px; height: 20px; border-radius: 50%; border: 1px solid var(--axis); font-size: 12px; display: grid; place-items: center; color: var(--ink-2); }
.steps li.on { background: var(--accent-soft); }
.steps li.on::before { border-color: var(--accent); color: var(--accent); }
.tree-figure { margin: 0; }
.tree svg { width: 100%; height: auto; display: block; }
.tree .edge { stroke: var(--tree); stroke-width: 0.8; fill: none; }
.tree .edge.soft { stroke: var(--tree-soft); }
.tree .path { stroke: var(--ink); stroke-width: 1.6; fill: none; }
.tree .layer-fill { fill: transparent; }
.tree .top-fill { fill: var(--surface); }
.tree .chain { stroke: var(--tree); stroke-width: 1.1; }
.tree .chain.used { stroke: var(--ink); }
.tree .t-label { font-size: 11.5px; fill: var(--muted); }
.tree .t-strong { font-size: 12px; fill: var(--ink); font-weight: 600; }
.tree .brace { stroke: var(--axis); fill: none; }
.tree [data-part] { cursor: default; }
.tree [data-part]:focus { outline: none; }
.tree .zone { fill: transparent; }
.tree .zone.on, .tree [data-part]:focus .zone { fill: var(--accent-soft); }
.tree .on .path, .tree .on .chain.used { stroke: var(--accent); }
.tree-caption { font-size: 13.5px; color: var(--ink-2); min-height: 3em; margin: 10px 0 0; }
.tree.small { margin-top: 18px; }

.slider { display: flex; align-items: center; gap: 12px; font-size: 13px; color: var(--ink-2); margin-bottom: 8px; flex-wrap: wrap; }
.slider input { flex: 1; min-width: 160px; accent-color: var(--accent); }
.slider output { font-variant-numeric: tabular-nums; color: var(--ink); min-width: 9em; }

.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
.card { border: 1px solid var(--line); border-radius: 10px; padding: 16px 18px; }
.card h3 { margin-top: 0; }
.card p { font-size: 14.5px; }

.limits { list-style: none; padding: 0; margin: 0 0 18px; display: grid; gap: 8px; }
.limits li { position: relative; padding-left: 34px; }
.limits .num { position: absolute; left: 0; top: 2px; }
.num { flex: none; width: 22px; height: 22px; border-radius: 50%; background: var(--ink); color: var(--page); font-size: 12px; display: inline-grid; place-items: center; font-weight: 600; transform: translateY(-1px); }
ul.plain { padding-left: 18px; }
ul.plain li { margin-bottom: 6px; }

.playground { border: 1px solid var(--line); border-radius: 12px; padding: 16px; margin: 20px -8px; background: var(--page); }
.presets { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 16px; }
.presets button, .seg button, .row button, .stepper button {
  font: inherit; font-size: 13px; color: var(--ink); background: var(--page);
  border: 1px solid var(--line); border-radius: 6px; padding: 4px 10px; cursor: pointer; line-height: 1.5;
}
.presets button:hover, .seg button:hover, .row button:hover, .stepper button:hover { border-color: var(--axis); }
.presets button[aria-pressed="true"], .seg button[aria-pressed="true"] { background: var(--ink); color: var(--page); border-color: var(--ink); }
.presets button small { color: var(--muted); margin-left: 4px; }
.presets button[aria-pressed="true"] small { color: inherit; opacity: 0.75; }
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.pg-body { display: grid; grid-template-columns: 250px 1fr; gap: 24px; }
.controls { display: grid; gap: 14px; align-content: start; }
.ctl > span { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 4px; }
.ctl > span b { color: var(--ink); font-weight: 600; }
.seg { display: inline-flex; flex-wrap: wrap; gap: 0; }
.seg button { border-radius: 0; margin-left: -1px; }
.seg button:first-child { border-radius: 6px 0 0 6px; margin-left: 0; }
.seg button:last-child { border-radius: 0 6px 6px 0; }
.stepper { display: inline-flex; align-items: center; gap: 0; }
.stepper button { width: 30px; padding: 4px 0; text-align: center; }
.stepper button:first-child { border-radius: 6px 0 0 6px; }
.stepper button:last-child { border-radius: 0 6px 6px 0; }
.stepper output { min-width: 40px; text-align: center; font-variant-numeric: tabular-nums; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); padding: 4px 6px; font-size: 13px; line-height: 1.5; }
.stepper button:disabled { opacity: 0.35; cursor: default; }
.layers { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.pg-out table td:first-child { color: var(--ink-2); }
.status { display: inline-flex; align-items: center; gap: 5px; font-size: 12.5px; white-space: nowrap; }
.status svg { width: 13px; height: 13px; flex: none; }
.status.ok { color: var(--good); }
.status.miss { color: var(--bad); }
.status.na { color: var(--muted); }
.src { font-size: 11.5px; color: var(--muted); display: block; }
.big { font-size: 15px; font-weight: 600; color: var(--ink); }

.digits { display: flex; gap: 2px; align-items: flex-end; height: 64px; margin: 12px 0 8px; }
.digits span { flex: 1; background: var(--tree); border-radius: 2px 2px 0 0; min-height: 2px; transition: height 0.2s, background 0.2s; }
.digits span.up { background: var(--bad-mark); }
.row { display: flex; gap: 8px; flex-wrap: wrap; }
.row .ghost { color: var(--ink-2); }
.grind { display: grid; grid-template-columns: repeat(32, 1fr); gap: 2px; margin: 12px 0 8px; }
.grind span { aspect-ratio: 1; background: var(--tree-soft); border-radius: 1.5px; }
.grind span.hit { background: var(--accent); }

.tip {
  position: fixed; z-index: 20; pointer-events: none; max-width: 280px;
  background: var(--ink); color: var(--page); font-size: 12.5px; line-height: 1.45;
  padding: 7px 10px; border-radius: 6px; box-shadow: 0 4px 16px rgba(0, 0, 0, 0.18);
}
.tip b { font-weight: 600; }

footer { border-top: 1px solid var(--line); padding: 24px 16px 40px; text-align: center; font-size: 13px; color: var(--muted); }

@media (max-width: 760px) {
  .tiles { grid-template-columns: 1fr 1fr; }
  .tile .v { font-size: 24px; }
  .construction, .pg-body, .pair { grid-template-columns: 1fr; }
  .playground { margin: 20px 0; padding: 12px; }
  .top { gap: 14px; }
  .lab { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .digits span { transition: none; }
}

.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 12.5px; color: var(--ink-2); margin-top: 8px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; vertical-align: -1px; }
.legend b { font-weight: 600; color: var(--ink); font-variant-numeric: tabular-nums; margin-left: 2px; }
.tree svg.route .path { stroke: var(--accent); }
