:root {
  color-scheme: light dark;

  --bg: #fbfbfa;
  --bg-panel: #ffffff;
  --bg-sunken: #f2f2f0;
  --bg-hover: #eeeeec;
  --border: #e0e0dc;
  --border-strong: #c8c8c2;
  --text: #1b1b19;
  --text-muted: #6a6a63;
  --text-faint: #96968d;
  --accent: #2f6f5e;
  --accent-soft: #e3efeb;
  --accent-2: #8a5a2b;
  --warn: #a8402f;
  --shadow: 0 1px 2px rgba(20, 20, 18, .05), 0 4px 14px rgba(20, 20, 18, .05);
  --mono: ui-monospace, "SFMono-Regular", "JetBrains Mono", Menlo, Consolas, monospace;
  --sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
  --radius: 10px;
  --max: 1280px;
}

[data-theme="dark"] {
  --bg: #14150f;
  --bg-panel: #1c1e17;
  --bg-sunken: #23261d;
  --bg-hover: #2c3025;
  --border: #32362a;
  --border-strong: #454a3a;
  --text: #ecedE4;
  --text-muted: #a2a696;
  --text-faint: #74786a;
  --accent: #7fc4a8;
  --accent-soft: #23342c;
  --accent-2: #d8a566;
  --warn: #e08b6f;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 20px rgba(0, 0, 0, .28);
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; scroll-padding-top: 74px; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.62;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { line-height: 1.25; font-weight: 620; letter-spacing: -.012em; margin: 0; }
h2 { font-size: 1.5rem; }
h3 { font-size: 1.05rem; }
h4 { font-size: .9rem; }
p { margin: 0 0 1em; }
a { color: var(--accent); text-decoration-thickness: 1px; text-underline-offset: 2px; }
code { font-family: var(--mono); font-size: .875em; background: var(--bg-sunken);
  padding: .1em .35em; border-radius: 4px; }

.wrap { max-width: var(--max); margin: 0 auto; padding: 0 26px; }

/* ---------- navigation ---------- */

.topbar {
  position: sticky; top: 0; z-index: 60;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--border);
}
.topbar .wrap { display: flex; align-items: center; gap: 20px; height: 56px; }
.brand { font-weight: 660; font-size: .9rem; letter-spacing: -.01em; white-space: nowrap; }
.brand span { color: var(--text-faint); font-weight: 450; }
.navlinks { display: flex; gap: 2px; margin-left: auto; overflow-x: auto; }
.navlinks a {
  color: var(--text-muted); text-decoration: none; font-size: .8rem; font-weight: 500;
  padding: 6px 10px; border-radius: 7px; white-space: nowrap;
}
.navlinks a:hover { background: var(--bg-hover); color: var(--text); }
.navlinks a.active { color: var(--accent); background: var(--accent-soft); }

.icon-btn {
  border: 1px solid var(--border); background: var(--bg-panel); color: var(--text-muted);
  width: 32px; height: 32px; border-radius: 8px; cursor: pointer; display: grid;
  place-items: center; font-size: .95rem; flex: none;
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text); }

/* ---------- hero ---------- */

.hero { padding: 54px 0 30px; border-bottom: 1px solid var(--border); }
.eyebrow {
  font-family: var(--mono); font-size: .7rem; letter-spacing: .1em;
  text-transform: uppercase; color: var(--accent); margin-bottom: 14px;
}
.hero h1 { font-size: clamp(1.9rem, 4vw, 2.7rem); max-width: 20ch; margin-bottom: 16px; }
.hero .lede { font-size: 1.06rem; color: var(--text-muted); max-width: 68ch; }

.statgrid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(148px, 1fr));
  gap: 1px; background: var(--border); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden; margin-top: 30px;
}
.stat { background: var(--bg-panel); padding: 15px 17px; }
.stat .k {
  font-size: .68rem; text-transform: uppercase; letter-spacing: .07em;
  color: var(--text-faint); font-weight: 600; margin-bottom: 5px;
}
.stat .v { font-size: 1.42rem; font-weight: 640; font-variant-numeric: tabular-nums;
  letter-spacing: -.02em; }
.stat .s { font-size: .74rem; color: var(--text-muted); margin-top: 1px; }

/* ---------- sections ---------- */

section { padding: 52px 0; border-bottom: 1px solid var(--border); }
section:last-of-type { border-bottom: 0; }
.sec-head { margin-bottom: 26px; max-width: 76ch; }
.sec-head .num {
  font-family: var(--mono); font-size: .72rem; color: var(--text-faint);
  letter-spacing: .08em; display: block; margin-bottom: 7px;
}
.sec-head p { color: var(--text-muted); margin: 10px 0 0; }

.panel {
  background: var(--bg-panel); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.panel-head {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 13px 17px; border-bottom: 1px solid var(--border);
}
.panel-head h3 { font-size: .92rem; }
.panel-head .hint { font-size: .76rem; color: var(--text-faint); margin-left: auto; }
.panel-body { padding: 17px; }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; align-items: start; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; align-items: start; }
@media (max-width: 940px) { .grid2, .grid3 { grid-template-columns: 1fr; } }

/* ---------- controls ---------- */

.controls { display: flex; flex-wrap: wrap; gap: 14px; align-items: flex-end; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field label {
  font-size: .68rem; text-transform: uppercase; letter-spacing: .07em;
  color: var(--text-faint); font-weight: 600;
}
select, input[type="search"] {
  font-family: inherit; font-size: .82rem; color: var(--text);
  background: var(--bg-panel); border: 1px solid var(--border-strong);
  border-radius: 7px; padding: 6px 9px; min-width: 130px;
}
select:focus, input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
input[type="range"] { width: 128px; accent-color: var(--accent); }

.segmented { display: inline-flex; background: var(--bg-sunken); border-radius: 8px;
  padding: 2px; gap: 2px; }
.segmented button {
  border: 0; background: transparent; color: var(--text-muted); cursor: pointer;
  font-family: inherit; font-size: .78rem; font-weight: 550; padding: 5px 11px;
  border-radius: 6px;
}
.segmented button.on { background: var(--bg-panel); color: var(--text); box-shadow: var(--shadow); }

.toggle { display: inline-flex; align-items: center; gap: 7px; font-size: .8rem;
  color: var(--text-muted); cursor: pointer; user-select: none; }
.toggle input { accent-color: var(--accent); }

/* ---------- spatial explorer ---------- */

.explorer { display: grid; grid-template-columns: minmax(0, 1fr) 268px; gap: 0; }
@media (max-width: 940px) { .explorer { grid-template-columns: 1fr; } }

.canvas-stack { position: relative; padding: 14px; min-height: 460px; }
.canvas-stack canvas { display: block; width: 100%; height: auto; border-radius: 8px;
  cursor: crosshair; }
.canvas-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.canvas-cell { position: relative; }
.canvas-cell .cap {
  font-size: .72rem; color: var(--text-faint); text-align: center; margin-top: 5px;
  font-weight: 550;
}

.sidepanel { border-left: 1px solid var(--border); padding: 14px; }
@media (max-width: 940px) { .sidepanel { border-left: 0; border-top: 1px solid var(--border); } }
.sidepanel h4 { font-size: .72rem; text-transform: uppercase; letter-spacing: .07em;
  color: var(--text-faint); margin-bottom: 9px; }

.patch-preview {
  width: 100%; aspect-ratio: 1; border-radius: 8px; background: var(--bg-sunken)
    center/cover no-repeat; border: 1px solid var(--border); image-rendering: auto;
  display: grid; place-items: center; color: var(--text-faint); font-size: .76rem;
}
.kv { display: grid; grid-template-columns: auto 1fr; gap: 3px 12px; font-size: .78rem;
  margin: 11px 0; }
.kv dt { color: var(--text-faint); }
.kv dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; font-weight: 550; }

.probbars { display: flex; flex-direction: column; gap: 4px; margin-top: 4px; }
.probrow { display: grid; grid-template-columns: 26px 1fr 38px; gap: 7px;
  align-items: center; font-size: .72rem; }
.probrow .bar { height: 8px; border-radius: 3px; background: var(--bg-sunken);
  overflow: hidden; }
.probrow .bar i { display: block; height: 100%; border-radius: 3px; }
.probrow .val { text-align: right; color: var(--text-muted);
  font-variant-numeric: tabular-nums; }

.legend { display: flex; flex-wrap: wrap; gap: 5px 12px; font-size: .76rem;
  color: var(--text-muted); }
.legend .item { display: inline-flex; align-items: center; gap: 5px; cursor: pointer; }
.legend .item.off { opacity: .3; }
.legend .sw { width: 11px; height: 11px; border-radius: 3px; flex: none;
  border: 1px solid rgba(128,128,128,.35); }
.rampbar { height: 10px; border-radius: 5px; margin: 4px 0; }
.ramplabels { display: flex; justify-content: space-between; font-size: .7rem;
  color: var(--text-faint); font-variant-numeric: tabular-nums; }

/* ---------- tables ---------- */

.tablewrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: .82rem; }
th, td { text-align: right; padding: 8px 11px; border-bottom: 1px solid var(--border);
  white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
thead th {
  font-size: .68rem; text-transform: uppercase; letter-spacing: .06em;
  color: var(--text-faint); font-weight: 620; cursor: pointer; user-select: none;
  position: sticky; top: 0; background: var(--bg-panel); z-index: 2;
}
thead th:hover { color: var(--text); }
thead th.sorted::after { content: " ▾"; color: var(--accent); }
thead th.sorted.asc::after { content: " ▴"; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: var(--bg-hover); }
tbody tr.sel { background: var(--accent-soft); }
tbody tr.sel td:first-child { box-shadow: inset 3px 0 0 var(--accent); }
td.num { font-variant-numeric: tabular-nums; }
td.best { font-weight: 680; color: var(--accent); }
.tag {
  font-size: .66rem; font-weight: 620; padding: 2px 7px; border-radius: 5px;
  background: var(--bg-sunken); color: var(--text-muted); letter-spacing: .02em;
}
.tag.ssl { background: var(--accent-soft); color: var(--accent); }
.tag.multimodal { background: color-mix(in srgb, var(--accent-2) 16%, transparent);
  color: var(--accent-2); }

/* ---------- charts ---------- */

.chart { width: 100%; display: block; overflow: visible; }
.chart text { font-family: var(--sans); fill: var(--text-muted); font-size: 10.5px; }
.chart .axis line, .chart .axis path { stroke: var(--border); }
.chart .grid line { stroke: var(--border); stroke-dasharray: 2 3; }
.chart .axlabel { fill: var(--text-faint); font-size: 10px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .06em; }

.tooltip {
  position: fixed; z-index: 200; pointer-events: none; opacity: 0;
  transition: opacity .1s; background: var(--bg-panel); color: var(--text);
  border: 1px solid var(--border-strong); border-radius: 8px; padding: 8px 11px;
  font-size: .76rem; box-shadow: var(--shadow); max-width: 260px; line-height: 1.45;
}
.tooltip .t { font-weight: 640; margin-bottom: 3px; }
.tooltip .r { display: flex; justify-content: space-between; gap: 14px;
  font-variant-numeric: tabular-nums; color: var(--text-muted); }
.tooltip .r b { color: var(--text); font-weight: 580; }

.note {
  font-size: .8rem; color: var(--text-muted); background: var(--bg-sunken);
  border-left: 2px solid var(--border-strong); padding: 10px 14px;
  border-radius: 0 7px 7px 0; margin: 14px 0 0;
}
.note strong { color: var(--text); font-weight: 620; }
/* An empty note would otherwise render as a bare grey slab. */
.note:empty { display: none; }
table:empty { display: none; }

.callout {
  border: 1px solid var(--border); border-left: 3px solid var(--accent);
  background: var(--accent-soft); border-radius: 0 var(--radius) var(--radius) 0;
  padding: 14px 18px; font-size: .87rem;
}
.callout p:last-child { margin-bottom: 0; }

.prose { max-width: 74ch; }
.prose h3 { margin: 26px 0 9px; }
.prose ul { padding-left: 1.15em; margin: 0 0 1em; }
.prose li { margin-bottom: .35em; }

pre {
  background: var(--bg-sunken); border: 1px solid var(--border); border-radius: 8px;
  padding: 13px 15px; overflow-x: auto; font-family: var(--mono); font-size: .78rem;
  line-height: 1.6; margin: 0 0 14px;
}
pre code { background: none; padding: 0; font-size: inherit; }

footer { padding: 34px 0 54px; color: var(--text-faint); font-size: .8rem; }
footer a { color: var(--text-muted); }

.loading { padding: 60px 20px; text-align: center; color: var(--text-faint); }
.hidden { display: none !important; }
.spacer { height: 18px; }
