:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface-1: #fcfcfb;
  --surface-2: #f3f2ee;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #6d6b66;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.1);
  --accent: #2a78d6;
  --accent-ink: #1c5cab;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --muted-fill: #c3c2b7;
  --band: rgba(208, 59, 59, 0.08);
  --critical: #d03b3b;
  --warning: #fab219;
  --warning-ink: #8a5a00;
  --good: #006300;
  --selected: #e8f0fb;
  --badge-client-bg: #e3eefb;
  --badge-client-ink: #184f95;
  --badge-community-bg: #e2f4ec;
  --badge-community-ink: #0b5e41;
  --badge-assumed-bg: #fdf0d5;
  --badge-assumed-ink: #7a4f00;
  --badge-conflict-bg: #fbe4e4;
  --badge-conflict-ink: #9a2323;
  --radius: 10px;
  --font: system-ui, -apple-system, "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface-1: #1a1a19;
    --surface-2: #222220;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #9a9890;
    --grid: #2c2c2a;
    --axis: #45453f;
    --border: rgba(255, 255, 255, 0.1);
    --accent: #3987e5;
    --accent-ink: #86b6ef;
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --muted-fill: #45453f;
    --band: rgba(230, 103, 103, 0.12);
    --critical: #e66767;
    --warning: #fab219;
    --warning-ink: #fab219;
    --good: #0ca30c;
    --selected: #1c2a3d;
    --badge-client-bg: #17304f;
    --badge-client-ink: #b7d3f6;
    --badge-community-bg: #123528;
    --badge-community-ink: #9fe3c6;
    --badge-assumed-bg: #3a2c0b;
    --badge-assumed-ink: #f4cf80;
    --badge-conflict-bg: #3d1a1a;
    --badge-conflict-ink: #f2aaaa;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface-1: #1a1a19;
  --surface-2: #222220;
  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted: #9a9890;
  --grid: #2c2c2a;
  --axis: #45453f;
  --border: rgba(255, 255, 255, 0.1);
  --accent: #3987e5;
  --accent-ink: #86b6ef;
  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --muted-fill: #45453f;
  --band: rgba(230, 103, 103, 0.12);
  --critical: #e66767;
  --warning: #fab219;
  --warning-ink: #fab219;
  --good: #0ca30c;
  --selected: #1c2a3d;
  --badge-client-bg: #17304f;
  --badge-client-ink: #b7d3f6;
  --badge-community-bg: #123528;
  --badge-community-ink: #9fe3c6;
  --badge-assumed-bg: #3a2c0b;
  --badge-assumed-ink: #f4cf80;
  --badge-conflict-bg: #3d1a1a;
  --badge-conflict-ink: #f2aaaa;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--page);
  color: var(--text-primary);
  font: 15px/1.45 var(--font);
}
a { color: var(--accent-ink); }
h1, h2, h3 { line-height: 1.2; margin: 0; }
h1 { font-size: 1.45rem; }
h2 { font-size: 1.02rem; font-weight: 650; }
h3 { font-size: 0.95rem; margin: 1.2rem 0 0.4rem; }
p { margin: 0.4rem 0; }
button, input, select, textarea { font: inherit; color: inherit; }

.skip { position: absolute; left: -999px; }
.skip:focus { left: 16px; top: 8px; z-index: 10; background: var(--surface-1); padding: 6px 10px; border-radius: 6px; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Header */
.top { background: var(--surface-1); border-bottom: 1px solid var(--border); }
.top-inner, .link-bar { max-width: 1440px; margin: 0 auto; padding: 14px 16px; display: flex; gap: 16px; align-items: flex-end; justify-content: space-between; flex-wrap: wrap; }
.link-bar { padding-top: 0; align-items: center; justify-content: flex-start; }
.lede { color: var(--text-secondary); max-width: 62ch; }
.top-meta { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; font-size: 0.85rem; }
.data-version { color: var(--text-secondary); }
.link-help { color: var(--text-secondary); font-size: 0.85rem; flex: 1 1 280px; }

button {
  border: 1px solid transparent;
  background: var(--accent);
  color: #fff;
  border-radius: 8px;
  padding: 6px 12px;
  cursor: pointer;
}
button.secondary { background: transparent; color: var(--text-primary); border-color: var(--border); }
button:hover { filter: brightness(1.05); }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, [tabindex]:focus-visible, summary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Layout */
.layout {
  max-width: 1440px;
  margin: 0 auto;
  padding: 16px;
  display: grid;
  grid-template-columns: minmax(300px, 380px) minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}
.build { position: sticky; top: 12px; max-height: calc(100vh - 24px); overflow-y: auto; overflow-x: hidden; display: grid; gap: 12px; padding-right: 2px; }
.results { display: grid; gap: 14px; min-width: 0; }
@media (max-width: 960px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .build { position: static; max-height: none; overflow: visible; }
}

.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  min-width: 0;
}
.card-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 4px; }
.card-sub { color: var(--text-secondary); font-size: 0.86rem; }
.card > h2 { margin-bottom: 8px; }

/* Form */
.field { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.field.grow { flex: 1 1 auto; }
.label-row { display: flex; align-items: center; gap: 6px; font-size: 0.84rem; color: var(--text-secondary); min-height: 22px; }
.section-label { margin-top: 12px; font-weight: 600; color: var(--text-primary); }
.section-label .pill { margin-left: auto; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.row > .field { flex: 1 1 120px; }
.row.stats > .field { flex: 1 1 60px; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px 10px; margin-top: 6px; }
.grid-extra { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px 10px; margin-top: 6px; }
.hint { font-size: 0.75rem; color: var(--text-muted); }
input.num, select, input[type="text"], textarea {
  width: 100%;
  min-width: 0;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 6px 8px;
}
textarea { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 0.85rem; resize: vertical; }
input[type="range"] { width: 100%; margin: 10px 0 2px; accent-color: var(--accent); }
.check { display: flex; align-items: center; gap: 6px; font-size: 0.85rem; margin-top: 6px; cursor: pointer; }
.check input { accent-color: var(--accent); width: 16px; height: 16px; }
.checks { display: grid; gap: 2px; }

.segmented { display: flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.segmented label { flex: 1; position: relative; }
.segmented input { position: absolute; opacity: 0; inset: 0; cursor: pointer; }
.segmented span { display: block; text-align: center; padding: 6px 4px; font-size: 0.86rem; background: var(--surface-2); white-space: nowrap; }
.segmented input:checked + span { background: var(--accent); color: #fff; }
.segmented input:disabled + span { color: var(--text-muted); opacity: 0.6; }
.segmented input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: -2px; }

details > summary { cursor: pointer; display: flex; align-items: center; gap: 8px; list-style: none; }
details > summary::-webkit-details-marker { display: none; }
details > summary::before { content: "▸"; color: var(--text-muted); }
details[open] > summary::before { content: "▾"; }
table.constants { table-layout: auto; }
table.data.constants th { font-weight: 400; color: var(--text-secondary); white-space: normal; text-align: left; padding-left: 0; }
table.data.constants td { width: 1%; white-space: nowrap; padding: 4px; }
table.data.constants input { width: 68px; }
table.constants tr.changed th { color: var(--warning-ink); font-weight: 600; }
.f-source { font-size: 0.78rem; }

/* Pills, badges, info buttons */
.pill { font-size: 0.75rem; padding: 1px 8px; border-radius: 999px; background: var(--surface-2); color: var(--text-secondary); white-space: nowrap; font-weight: 500; }
.pill-warn { background: var(--badge-assumed-bg); color: var(--badge-assumed-ink); }
.pill-bad { background: var(--badge-conflict-bg); color: var(--badge-conflict-ink); }
.badge { font-size: 0.7rem; padding: 1px 7px; border-radius: 999px; font-weight: 600; white-space: nowrap; }
.badge-client { background: var(--badge-client-bg); color: var(--badge-client-ink); }
.badge-community { background: var(--badge-community-bg); color: var(--badge-community-ink); }
.badge-assumed { background: var(--badge-assumed-bg); color: var(--badge-assumed-ink); }
.badge-conflict { background: var(--badge-conflict-bg); color: var(--badge-conflict-ink); }
.tag { font-size: 0.7rem; margin-left: 6px; padding: 0 6px; border-radius: 999px; background: var(--surface-2); color: var(--text-secondary); font-weight: 500; }

button.info {
  width: 18px; height: 18px; padding: 0;
  border-radius: 50%;
  background: transparent;
  border: 1px solid var(--axis);
  color: var(--text-secondary);
  font: 600 11px/16px var(--font);
  font-style: italic;
  flex: none;
}
button.info:hover { border-color: var(--accent); color: var(--accent-ink); filter: none; }
.popover {
  position: absolute; z-index: 20;
  max-width: min(380px, calc(100vw - 16px));
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.18);
  padding: 10px 12px;
  font-size: 0.85rem;
}
.pop-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.formula { background: var(--surface-2); padding: 6px 8px; border-radius: 6px; white-space: pre-wrap; font: 0.78rem/1.4 ui-monospace, "SF Mono", Menlo, Consolas, monospace; margin: 6px 0; }
.pop-sources { margin: 4px 0 0; padding-left: 16px; }

/* Results */
.banner { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; background: var(--badge-assumed-bg); color: var(--badge-assumed-ink); border-radius: var(--radius); padding: 10px 12px; font-size: 0.88rem; }
.banner button { margin-left: auto; color: inherit; }
.warnings { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.warnings li { display: flex; gap: 8px; align-items: flex-start; background: var(--surface-1); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; font-size: 0.88rem; }
.warn-icon { flex: none; width: 18px; height: 18px; border-radius: 50%; display: grid; place-items: center; font: 700 12px/1 var(--font); color: #fff; }
.warn-error .warn-icon { background: var(--critical); }
.warn-warn .warn-icon { background: var(--warning); color: #0b0b0b; }
.warn-inline { color: var(--badge-conflict-ink); font-size: 0.85rem; }

.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 10px; }
.tile { background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 12px; min-width: 0; }
.tile-label { font-size: 0.82rem; }
.tile-value { font-size: 1.45rem; font-weight: 650; margin-top: 2px; }
.tile-sub { font-size: 0.78rem; color: var(--text-secondary); overflow-wrap: anywhere; }

.target-row > .field:first-child { flex: 3 1 260px; }
.explorer-row > .field { flex: 1 1 130px; }
.explorer-obs { margin-top: 10px; align-items: flex-start; }
.explorer-obs > .field { flex: 1 1 220px; max-width: 340px; }
.explorer-obs > div:last-child { flex: 2 1 260px; min-width: 0; }
.resid-summary { font-weight: 600; }
.mob-line { color: var(--text-secondary); font-size: 0.86rem; }

.table-wrap { overflow-x: auto; margin-top: 8px; }
table.data { border-collapse: collapse; width: 100%; font-size: 0.85rem; font-variant-numeric: tabular-nums; }
table.data th, table.data td { padding: 6px 8px; text-align: right; border-bottom: 1px solid var(--grid); white-space: nowrap; }
table.data th:first-child { text-align: left; }
table.data thead th { color: var(--text-secondary); font-weight: 500; font-size: 0.8rem; }
table.data thead th span { vertical-align: middle; }
table.data thead th button.info { margin-left: 4px; vertical-align: middle; }
table.data tbody th { font-weight: 550; }
table.data tr.selected { background: var(--selected); }
table.data tr.muted { color: var(--text-muted); }
table.data tr.muted td { text-align: left; white-space: normal; }
table.data tr.clickable { cursor: pointer; }
table.data tr.clickable:hover { background: var(--surface-2); }
table.data td.best { font-weight: 700; color: var(--good); }
table.data.compact th, table.data.compact td { padding: 3px 6px; }

.chart-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 440px), 1fr)); gap: 14px; }

/* Charts */
.chart { margin: 6px 0 0; }
.chart-title { font-weight: 600; margin-bottom: 4px; }
.chart-plot { position: relative; width: 100%; }
.chart-plot svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart-legend { list-style: none; display: flex; flex-wrap: wrap; gap: 4px 14px; padding: 0; margin: 2px 0 4px; font-size: 0.8rem; color: var(--text-secondary); }
.chart-legend li { display: flex; align-items: center; gap: 6px; }
.key { display: inline-block; flex: none; background: var(--key); }
.key-line { width: 14px; height: 2px; border-radius: 1px; }
.key-band { width: 14px; height: 10px; border-radius: 2px; opacity: 0.55; }
.key-dot { width: 8px; height: 8px; border-radius: 50%; }
.chart svg .grid { stroke: var(--grid); stroke-width: 1; }
.chart svg .axis { stroke: var(--axis); stroke-width: 1; }
.chart svg .tick, .chart svg .axis-label, .chart svg .end-label, .chart svg .row-label, .chart svg .bar-value, .chart svg .band-label, .chart svg .marker-label { fill: var(--text-secondary); font: 11.5px var(--font); font-variant-numeric: tabular-nums; }
.chart svg .axis-label { fill: var(--text-muted); }
.chart svg .row-label { fill: var(--text-primary); font-size: 12.5px; }
.chart svg .row-label.muted { fill: var(--text-muted); }
.chart svg .marker-label { fill: var(--text-primary); font-weight: 600; }
.chart svg .band-label { fill: var(--critical); }
.chart svg .line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart svg .area { opacity: 0.12; stroke: none; }
.chart svg .band { fill: var(--band); }
.chart svg .marker { fill: var(--text-primary); stroke: var(--surface-1); stroke-width: 2; }
.chart svg .obs { fill: var(--text-primary); stroke: var(--surface-1); stroke-width: 2; }
.chart svg .crosshair { stroke: var(--axis); stroke-width: 1; }
.chart svg .cross-dot { stroke: var(--surface-1); stroke-width: 2; }
.chart svg .hit { fill: transparent; outline: none; }
.chart svg .hit:focus-visible { stroke: var(--accent); stroke-width: 2; }
.chart svg .bar-highlight, .chart svg .bar { transition: opacity 0.1s; }
.chart-tip {
  position: absolute; pointer-events: none; z-index: 5;
  background: var(--surface-1); border: 1px solid var(--border); border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.14);
  padding: 6px 9px; font-size: 0.8rem; white-space: nowrap;
}
.tip-head { color: var(--text-secondary); margin-bottom: 2px; }
.tip-row { display: flex; align-items: center; gap: 6px; }
.tip-name { color: var(--text-secondary); }
.chart-table summary { font-size: 0.8rem; color: var(--text-secondary); margin-top: 6px; }
.chart-table table { border-collapse: collapse; font-size: 0.8rem; margin-top: 4px; font-variant-numeric: tabular-nums; }
.chart-table th, .chart-table td { padding: 2px 10px 2px 0; text-align: right; }
.chart-table th:first-child { text-align: left; }
.empty { color: var(--text-secondary); padding: 20px 0; }

/* Sources */
.sources { max-width: 1440px; margin: 0 auto; padding: 8px 16px 40px; }
.sources > * { max-width: 900px; }
.kinds, .source-list { list-style: none; padding: 0; display: grid; gap: 8px; }
.source-list li { background: var(--surface-1); border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; font-size: 0.88rem; }
.source-title { font-weight: 600; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.source-who { color: var(--text-secondary); font-size: 0.82rem; }
.small { font-size: 0.8rem; color: var(--text-muted); }
.noscript { padding: 16px; }
