:root {
  color-scheme: dark;
  --panel: rgba(22, 22, 21, 0.92); --ink: #f0efec; --ink-2: #c3c2b7; --muted: #898781;
  --border: rgba(255, 255, 255, 0.12); --accent: #5598e7; --page: #0d0d0d;
  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
}
:root[data-base="light"] {
  color-scheme: light;
  --panel: rgba(252, 252, 251, 0.94); --ink: #0b0b0b; --ink-2: #52514e; --muted: #898781;
  --border: rgba(11, 11, 11, 0.12); --accent: #2a78d6; --page: #f9f9f7;
}
html, body { margin: 0; height: 100%; background: var(--page); font: 14px/1.45 var(--sans); color: var(--ink); }
#map { position: absolute; inset: 0; }
.panel {
  position: absolute; top: 12px; left: 12px; z-index: 2; width: 320px; max-width: calc(100vw - 24px);
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px;
  backdrop-filter: blur(6px); box-shadow: 0 8px 28px rgba(0,0,0,.25);
}
.panel h1 { font: 600 20px/1.2 var(--serif); margin: 0 0 2px; }
.panel .sub { color: var(--ink-2); font-size: 12.5px; margin: 0 0 12px; }
.panel a { color: var(--accent); text-decoration: none; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 10px; }
.row > label { font-size: 12px; color: var(--muted); min-width: 64px; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.seg button { font: inherit; font-size: 13px; padding: 5px 11px; border: 0; background: transparent; color: var(--ink-2); cursor: pointer; }
.seg button + button { border-left: 1px solid var(--border); }
.seg button.on { background: var(--ink); color: var(--page); }
input[type=range] { flex: 1; accent-color: var(--accent); }
.val { font-variant-numeric: tabular-nums; min-width: 34px; text-align: right; font-size: 13px; }
.legend { margin-top: 14px; }
.legend .bar { height: 12px; border-radius: 3px; position: relative; }
.legend .ticks { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); margin-top: 3px; font-variant-numeric: tabular-nums; }
.legend .avg { position: absolute; top: -4px; bottom: -4px; width: 2px; background: var(--ink); border-radius: 1px; }
.legend .cap { font-size: 12px; color: var(--ink-2); margin-bottom: 5px; display: flex; justify-content: space-between; }
.stats { margin-top: 12px; font-size: 12px; color: var(--ink-2); border-top: 1px solid var(--border); padding-top: 10px; }
.stats b { color: var(--ink); font-variant-numeric: tabular-nums; }
.sizes { display: flex; align-items: flex-end; gap: 12px; margin-top: 8px; font-size: 11px; color: var(--muted); }
.sizes span { display: inline-flex; flex-direction: column; align-items: center; gap: 3px; }
.sizes i { display: block; border-radius: 50%; border: 1px solid var(--ink-2); }
#search { width: 100%; box-sizing: border-box; font: inherit; font-size: 13px; padding: 6px 9px; border-radius: 8px; border: 1px solid var(--border); background: transparent; color: var(--ink); }
#hits { list-style: none; margin: 4px 0 0; padding: 0; max-height: 180px; overflow: auto; }
#hits li { padding: 4px 6px; border-radius: 6px; cursor: pointer; font-size: 12.5px; }
#hits li:hover { background: var(--border); }
#hits small { color: var(--muted); }
.toggle { position: absolute; top: 8px; right: 8px; background: none; border: 0; color: var(--muted); cursor: pointer; font-size: 16px; display: none; }
.maplibregl-popup-content { background: var(--panel); color: var(--ink); border-radius: 10px; padding: 10px 12px; font: 12.5px/1.45 var(--sans); box-shadow: 0 6px 20px rgba(0,0,0,.3); }
.maplibregl-popup-tip { display: none; }
.pop b { display: block; font-size: 13.5px; }
.pop .m { color: var(--muted); }
.pop .kv { display: flex; justify-content: space-between; gap: 18px; font-variant-numeric: tabular-nums; }
.pop i { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 6px; vertical-align: 0; }
@media (max-width: 640px) {
  .panel { width: auto; right: 12px; padding: 12px; }
  .panel.collapsed .body { display: none; }
  .toggle { display: block; }
}

/* ---- app additions ---- */
html, body { overscroll-behavior: none; }
.panel { top: max(12px, env(safe-area-inset-top)); max-height: calc(100dvh - 24px); overflow: auto; }
.val.wide { min-width: 70px; }
/* two range inputs stacked on one track = a low/high slider */
.range2 { position: relative; flex: 1; height: 22px; min-width: 120px; }
.range2::before { content: ""; position: absolute; left: 0; right: 0; top: 50%; height: 4px; margin-top: -2px; border-radius: 2px; background: var(--border); }
.range2 .fill { position: absolute; top: 50%; height: 4px; margin-top: -2px; border-radius: 2px; background: var(--accent); }
.range2 input { position: absolute; inset: 0; width: 100%; margin: 0; background: none; pointer-events: none; -webkit-appearance: none; appearance: none; }
.range2 input::-webkit-slider-thumb { pointer-events: auto; -webkit-appearance: none; width: 16px; height: 16px; border-radius: 50%; background: var(--ink); border: 2px solid var(--accent); cursor: pointer; }
.range2 input::-moz-range-thumb { pointer-events: auto; width: 14px; height: 14px; border-radius: 50%; background: var(--ink); border: 2px solid var(--accent); cursor: pointer; }
.range2 input::-moz-range-track { background: none; }
.legend .shade { position: absolute; top: 0; bottom: 0; background: var(--page); opacity: .72; }
.legend .shade#shadeL { left: 0; border-radius: 3px 0 0 3px; }
.legend .shade#shadeR { right: 0; border-radius: 0 3px 3px 0; }
details.more { margin-top: 12px; border-top: 1px solid var(--border); padding-top: 8px; }
details.more summary { cursor: pointer; font-size: 12.5px; color: var(--ink-2); }
.check { display: flex; gap: 6px; align-items: center; font-size: 13px; color: var(--ink-2); }
.reset { font: inherit; font-size: 12.5px; padding: 5px 10px; border-radius: 8px; border: 1px solid var(--border); background: transparent; color: var(--ink-2); cursor: pointer; }
.foot { margin: 10px 0 0; font-size: 11.5px; color: var(--muted); }
@media (max-width: 640px) {
  .panel { max-height: 55dvh; }
  .panel.collapsed { max-height: none; }
}
#subject { font: inherit; font-size: 13.5px; padding: 6px 28px 6px 10px; border-radius: 8px; border: 1px solid var(--border); background: transparent; color: var(--ink); flex: 1; min-width: 0; cursor: pointer; }
#subject option { background: var(--page); color: var(--ink); }
@media (max-width: 640px) {
  /* bottom sheet on phones so the map controls stay reachable */
  .panel { top: auto; bottom: max(12px, env(safe-area-inset-bottom)); left: 8px; right: 8px; max-width: none; }
  .panel h1 { font-size: 17px; padding-right: 28px; }
  .panel.collapsed .sub { margin-bottom: 0; }
  .maplibregl-ctrl-bottom-right { display: none; }
}
.checks { display: flex; flex-wrap: wrap; gap: 4px 14px; }

.sel { font: inherit; font-size: 13.5px; padding: 6px 28px 6px 10px; border-radius: 8px; border: 1px solid var(--border); background: transparent; color: var(--ink); flex: 1; min-width: 0; cursor: pointer; }
.sel option { background: var(--page); color: var(--ink); }
.row[hidden] { display: none; }
.pop a { color: var(--accent); }
.legend .avg[hidden] { display: none; }
.val.wide { min-width: 0; width: 72px; flex: none; white-space: nowrap; text-align: right; }
.pop .kind { font-size: 12px; color: var(--ink-2); font-weight: 600; margin-top: 2px; }
.maplibregl-popup-content .pop { min-width: min(380px, calc(100vw - 48px)); }
.pop .kv > span:first-child { white-space: nowrap; }
.maplibregl-popup-close-button { color: var(--muted); font-size: 18px; padding: 2px 8px; }
.maplibregl-popup-close-button:hover { background: none; color: var(--ink); }
.pop b { padding-right: 18px; }

/* popup links and the More info card */
.pop-links { display: flex; justify-content: space-between; gap: 12px; margin-top: 6px; }
.pop-links a { font-weight: 600; }
.detail { position: absolute; top: 12px; right: 56px; z-index: 3; width: 470px; max-width: calc(100vw - 80px); max-height: calc(100dvh - 24px); overflow: auto;
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 14px 18px 16px; backdrop-filter: blur(6px);
  box-shadow: 0 8px 28px rgba(0,0,0,.3); font-size: 13px; }
.detail[hidden] { display: none; }
.detail h3 { font: 600 19px/1.2 var(--serif); margin: 0 26px 2px 0; }
.detail h4 { font-size: 12.5px; margin: 14px 0 5px; color: var(--ink-2); text-transform: uppercase; letter-spacing: .04em; }
.detail .m { color: var(--muted); font-size: 12px; }
.detail .kind { font-size: 12px; color: var(--ink-2); font-weight: 600; margin-top: 2px; }
.detail a { color: var(--accent); font-weight: 600; }
.dclose { position: absolute; top: 8px; right: 10px; background: none; border: 0; color: var(--muted); font-size: 22px; cursor: pointer; }
.dclose:hover { color: var(--ink); }
.dt { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.dt th { font-size: 11px; color: var(--muted); font-weight: 600; text-align: right; padding: 2px 4px; }
.dt td { text-align: right; padding: 3px 4px; border-top: 1px solid var(--border); }
.dt th:first-child, .dt td:first-child { text-align: left; padding-left: 0; }
.dt tr.m td { color: var(--muted); font-size: 11.5px; }
.spark { width: 100%; height: auto; display: block; }
.spark .g { stroke: var(--border); }
.spark text { fill: var(--muted); font-size: 11px; }
.spark path { fill: none !important; }
.spark .c-ela, .dleg .c-ela { stroke: #5598e7; fill: #5598e7; background: #5598e7; }
.spark .c-math, .dleg .c-math { stroke: #f0a04b; fill: #f0a04b; background: #f0a04b; }
.dleg { display: flex; gap: 14px; font-size: 11.5px; color: var(--ink-2); }
.dleg i { display: inline-block; width: 14px; height: 3px; margin-right: 5px; vertical-align: middle; }
.dleg i.dash { border-top: 2px dashed var(--ink-2); height: 0; background: none; }
.dbars > div { display: grid; grid-template-columns: 1fr 120px 44px; gap: 8px; align-items: center; padding: 3px 0; }
.dbars .v { text-align: right; font-variant-numeric: tabular-nums; }
.dbar { position: relative; height: 9px; background: var(--border); border-radius: 3px; }
.dbar i { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 3px; }
.dbar i.c-comp { background: #21918c; } .dbar i.c-hs { background: #5598e7; }
.dbar b { position: absolute; top: -3px; bottom: -3px; width: 2px; background: var(--ink); }
@media (max-width: 640px) {
  .detail { top: 8px; left: 8px; right: 8px; width: auto; max-width: none; max-height: 70dvh; }
  .dbars > div { grid-template-columns: 1fr 90px 40px; }
}
@media (max-width: 640px) {
  .detail { font-size: 12.5px; padding: 12px 12px 14px; }
  .dt th, .dt td { padding: 2px 3px; font-size: 11.5px; }
  .dt th { font-size: 10.5px; }
}
.detail table.dt { table-layout: auto; }
.detail { overflow-x: hidden; }
