:root {
  color-scheme: light;
  --bg: #f6f4ee;
  --surface: #fcfcfb;
  --surface-2: #efece4;
  --border: #dcd8cc;
  --text: #1b1b19;
  --text-2: #52514e;
  --text-3: #7a786f;
  --accent: #1b6b3a;
  --accent-ink: #f4efe1;
  --focus: #2a78d6;
  --shadow: 0 1px 2px rgba(0, 0, 0, .06), 0 4px 16px rgba(0, 0, 0, .08);
  --seq-1: #86b6ef; --seq-2: #5598e7; --seq-3: #2a78d6; --seq-4: #1c5cab; --seq-5: #104281;
  --target: #1b1b19;
  --baseline: #9b998f;
  --bar: #2f7d4b;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #141413; --surface: #1a1a19; --surface-2: #242422; --border: #383835;
    --text: #f0efec; --text-2: #c3c2b7; --text-3: #95938a;
    --accent: #4fa36a; --accent-ink: #0f1a12; --focus: #3987e5;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 4px 16px rgba(0, 0, 0, .4);
    --seq-1: #9ec5f4; --seq-2: #6da7ec; --seq-3: #3987e5; --seq-4: #256abf; --seq-5: #184f95;
    --target: #f0efec; --baseline: #7a786f; --bar: #4fa36a;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #141413; --surface: #1a1a19; --surface-2: #242422; --border: #383835;
  --text: #f0efec; --text-2: #c3c2b7; --text-3: #95938a;
  --accent: #4fa36a; --accent-ink: #0f1a12; --focus: #3987e5;
  --seq-1: #9ec5f4; --seq-2: #6da7ec; --seq-3: #3987e5; --seq-4: #256abf; --seq-5: #184f95;
  --target: #f0efec; --baseline: #7a786f; --bar: #4fa36a;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.45; display: flex; flex-direction: column; }
a { color: var(--accent); }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

.topbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 10px 18px; background: var(--surface); border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.brand h1 { margin: 0; font-size: 18px; letter-spacing: -.01em; }
.subtitle { margin: 2px 0 0; color: var(--text-2); font-size: 13px; }
.toplinks { display: flex; gap: 16px; align-items: center; font-size: 13px; }
.linkbtn, .inline-link { background: none; border: 0; padding: 0; color: var(--accent); font: inherit; cursor: pointer; text-decoration: underline; }

.layout { flex: 1; display: grid; grid-template-columns: 400px minmax(0, 1fr); min-height: 0; }
.panel { overflow-y: auto; padding: 16px 18px 24px; background: var(--surface); border-right: 1px solid var(--border); }
.panel section { margin-bottom: 20px; }
.panel h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--text-2); margin: 0 0 8px; }
.intro p { margin: 0 0 6px; }
.caveat { color: var(--text-2); font-size: 13px; }
.hint { color: var(--text-3); font-size: 12px; margin: 4px 0 0; }

.control { margin-bottom: 14px; }
.control label, .control .label { display: flex; align-items: center; justify-content: space-between; font-weight: 600; margin-bottom: 4px; gap: 6px; }
.control .label { justify-content: flex-start; }
.control output { font-variant-numeric: tabular-nums; color: var(--accent); font-weight: 700; }
input[type="range"] { width: 100%; accent-color: var(--accent); margin: 2px 0; }
.ticks { display: flex; justify-content: space-between; font-size: 11px; color: var(--text-3); padding: 0 2px; font-variant-numeric: tabular-nums; }
.info { width: 18px; height: 18px; border-radius: 50%; border: 1px solid var(--border); background: var(--surface-2); color: var(--text-2); font-size: 11px; line-height: 1; cursor: help; padding: 0; }

.segmented { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: var(--surface-2); }
.segmented button { border: 0; background: transparent; color: var(--text-2); padding: 6px 14px; font: inherit; cursor: pointer; }
.segmented button + button { border-left: 1px solid var(--border); }
.segmented button[aria-checked="true"] { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.segmented.small button { padding: 3px 9px; font-size: 12px; }

.metrics { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.stat { background: var(--surface-2); border-radius: 10px; padding: 10px 12px; display: flex; flex-direction: column; min-width: 0; }
.stat-label { font-size: 12px; color: var(--text-2); }
.stat-value { font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.stat-sub { font-size: 11.5px; color: var(--text-3); font-variant-numeric: tabular-nums; }

.zonebar { display: flex; height: 14px; border-radius: 4px; overflow: hidden; gap: 2px; background: var(--surface); }
.zonebar span { display: block; height: 100%; transition: width .25s ease; }
.zonelegend { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 4px; font-size: 12.5px; }
.zonelegend li { display: grid; grid-template-columns: 12px 1fr auto; gap: 8px; align-items: center; }
.zonelegend i { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }
.zonelegend .v { font-variant-numeric: tabular-nums; color: var(--text-2); }

.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .axis line, .chart .grid line { stroke: var(--border); }
.chart .axis text, .chart .axlabel { fill: var(--text-3); font-size: 10.5px; }
.chart .dot { cursor: pointer; }
.chart .dim { opacity: .18; }
.chart .curve { fill: none; stroke: var(--text-2); stroke-width: 2; }
.chart .current { fill: none; stroke: var(--text); stroke-width: 2; pointer-events: none; }
.chart .baseline-mark { stroke: var(--baseline); stroke-dasharray: 3 3; }
.chart-legend { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 11.5px; color: var(--text-2); margin-top: 4px; align-items: center; }
.chart-legend i { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 4px; vertical-align: -1px; }

.features { display: grid; gap: 5px; }
.frow { display: grid; grid-template-columns: minmax(0, 1fr) 120px 38px; gap: 8px; align-items: center; font-size: 12.5px; }
.frow .name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.frow .name small { color: var(--text-3); }
.frow .track { position: relative; height: 10px; background: var(--surface-2); border-radius: 3px; }
.frow .fill { position: absolute; left: 0; top: 0; bottom: 0; background: var(--bar); border-radius: 0 3px 3px 0; transition: width .25s ease; }
.frow .tick { position: absolute; top: -3px; bottom: -3px; width: 2px; background: var(--target); }
.frow .tick.base { background: var(--baseline); }
.frow .v { text-align: right; font-variant-numeric: tabular-nums; color: var(--text-2); }
.fgroup { font-size: 11px; color: var(--text-3); text-transform: uppercase; letter-spacing: .05em; margin-top: 6px; }

.credits { font-size: 11px; color: var(--text-3); border-top: 1px solid var(--border); padding-top: 10px; }

.mapwrap { position: relative; min-height: 0; }
#map { position: absolute; inset: 0; }
.mapctl { position: absolute; top: 12px; right: 12px; background: var(--surface); border-radius: 10px; box-shadow: var(--shadow); padding: 10px 12px; display: grid; gap: 8px; max-width: min(320px, calc(100% - 24px)); font-size: 12.5px; }
.ctlrow { display: grid; grid-template-columns: 92px minmax(0, 1fr); align-items: center; gap: 8px; }
.ctllabel { color: var(--text-2); }
.mapctl select { width: 100%; font: inherit; padding: 4px; border-radius: 6px; border: 1px solid var(--border); background: var(--surface); color: var(--text); }
.maplegend { position: absolute; left: 12px; bottom: 28px; background: var(--surface); border-radius: 10px; box-shadow: var(--shadow); padding: 10px 12px; font-size: 12px; max-width: 280px; }
.maplegend h3 { margin: 0 0 6px; font-size: 12px; }
.maplegend .row { display: flex; align-items: center; gap: 6px; margin: 2px 0; }
.maplegend i { width: 12px; height: 12px; border-radius: 3px; display: inline-block; flex: none; }
.maplegend .ramp { height: 10px; border-radius: 3px; margin: 4px 0 2px; }
.maplegend .rampl { display: flex; justify-content: space-between; color: var(--text-3); font-variant-numeric: tabular-nums; }
.maplegend + .maplegend { bottom: auto; }
.loading { position: absolute; inset: 0; display: grid; place-items: center; background: color-mix(in srgb, var(--bg) 70%, transparent); font-weight: 600; }
.loading[hidden] { display: none; }

.tooltip { position: fixed; z-index: 20; pointer-events: none; background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: 8px; box-shadow: var(--shadow); padding: 8px 10px; font-size: 12px; max-width: 280px; }
.tooltip b { font-weight: 600; }
.tooltip .k { color: var(--text-3); }

.maplibregl-popup-content { background: var(--surface); color: var(--text); font: 12.5px/1.45 system-ui, sans-serif; border-radius: 8px; box-shadow: var(--shadow); }
.maplibregl-popup-tip { border-top-color: var(--surface) !important; border-bottom-color: var(--surface) !important; }
.maplibregl-popup-close-button { color: var(--text-2); font-size: 16px; }
.popup table { border-collapse: collapse; }
.popup td { padding: 1px 6px 1px 0; }
.popup td:first-child { color: var(--text-3); }

dialog { max-width: 640px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); color: var(--text); padding: 20px 24px; box-shadow: var(--shadow); }
dialog::backdrop { background: rgba(0, 0, 0, .35); }
dialog h2 { margin-top: 0; }
dialog .close { float: right; border: 0; background: none; font-size: 22px; cursor: pointer; color: var(--text-2); }

@media (max-width: 860px) {
  html, body { height: auto; }
  body { display: block; }
  .layout { display: flex; flex-direction: column; }
  .mapwrap { display: flex; flex-direction: column; order: -1; }
  #map { position: relative; height: 58vh; min-height: 340px; }
  .mapctl { position: static; max-width: none; border-radius: 0; box-shadow: none; border-bottom: 1px solid var(--border); padding: 10px 16px; }
  .ctlrow { grid-template-columns: 84px minmax(0, 1fr); }
  .maplegend { top: 8px; left: 8px; bottom: auto; max-width: 70%; padding: 6px 8px; font-size: 11px; }
  .panel { overflow: visible; border-right: 0; padding: 14px 16px; }
  .topbar { padding: 10px 16px; }
  .toplinks { gap: 12px; }
}
