:root {
  --bg: #10151c;
  --panel: #172029;
  --panel-2: #1e2a35;
  --line: #2b3947;
  --ink: #e6edf3;
  --ink-dim: #8fa3b5;
  --accent: #4bb3fd;
  --warn: #f0a04b;
  --good: #58c98a;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, monospace;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg); color: var(--ink); font-family: var(--font);
  font-size: 14px; display: flex; flex-direction: column;
}

header {
  display: flex; align-items: baseline; gap: 16px; padding: 12px 18px;
  border-bottom: 1px solid var(--line); background: var(--panel);
}
header h1 { margin: 0; font-size: 19px; letter-spacing: .3px; }
header .tag { margin: 0; color: var(--ink-dim); font-size: 12.5px; }
.hdr-actions { margin-left: auto; display: flex; gap: 8px; align-items: center; }
.btn-link {
  color: var(--accent); text-decoration: none; font-size: 12.5px; font-weight: 600;
  border: 1px solid var(--accent); border-radius: 6px; padding: 6px 12px;
}
.btn-link:hover { background: rgba(75,179,253,.12); }

button {
  background: var(--accent); color: #06222f; border: 0; border-radius: 6px;
  padding: 7px 13px; font-weight: 600; font-size: 12.5px; cursor: pointer;
  font-family: var(--font);
}
button:hover { filter: brightness(1.1); }
button.ghost { background: transparent; color: var(--ink-dim); border: 1px solid var(--line); }
button.ghost:hover { color: var(--ink); border-color: var(--accent); }
button.small { padding: 5px 9px; font-size: 11.5px; width: 100%; margin-top: 8px; }

#app { flex: 1; display: grid; grid-template-columns: 320px 1fr 340px; min-height: 0; }

aside {
  background: var(--panel); overflow-y: auto; padding: 14px;
}
#controls { border-right: 1px solid var(--line); }
#results  { border-left: 1px solid var(--line); }

section { margin-bottom: 22px; }
h2 { font-size: 12px; text-transform: uppercase; letter-spacing: .9px;
     color: var(--ink-dim); margin: 0 0 8px; }
.hint { color: var(--ink-dim); font-size: 11.5px; margin: 4px 0 8px; line-height: 1.45; }

label { display: block; margin-bottom: 10px; font-size: 12.5px; color: var(--ink-dim); }
.row { display: flex; gap: 6px; margin-top: 4px; }
input, select {
  width: 100%; background: var(--panel-2); color: var(--ink);
  border: 1px solid var(--line); border-radius: 5px; padding: 5px 7px;
  font-size: 12.5px; font-family: var(--font);
}

.wt-head { display: flex; align-items: center; justify-content: space-between; gap: 8px;
           margin-bottom: 12px; padding-bottom: 7px; border-bottom: 1px solid var(--line); }
.wt-head h2 { margin: 0; color: var(--ink); font-size: 13px; }
.wt-count { font-size: 11px; color: var(--accent); font-family: var(--mono);
            display: flex; align-items: center; gap: 10px; }
.wt-count .none { color: var(--ink-dim); }
button.linkish {
  background: none; border: 0; padding: 0; color: var(--ink-dim);
  font-size: 11px; text-decoration: underline; cursor: pointer; font-weight: 500;
}
button.linkish:hover { color: var(--accent); }

.presets { display: flex; flex-wrap: wrap; gap: 6px; }
.presets button {
  background: var(--panel-2); color: var(--ink); border: 1px solid var(--line);
  font-weight: 500; padding: 6px 10px;
}
.presets button.on { background: var(--accent); color: #06222f; border-color: var(--accent); }
/* Betsy's picks -- the person this was built for. A quiet warm tint so it reads
   as "hers" without shouting. */
.presets button.betsy { border-color: #d98aa8; color: #f0b6c9; }
.presets button.betsy:hover { background: rgba(217,138,168,.12); }
.presets button.betsy.on { background: #d98aa8; color: #2a0e18; border-color: #d98aa8; }

/* weight sliders, grouped into collapsible domains */
.domain { margin-bottom: 14px; }
.dom-head {
  display: flex; align-items: center; gap: 6px; width: 100%;
  background: none; border: 0; border-bottom: 1px solid var(--line);
  padding: 3px 0; margin: 0 0 6px; cursor: pointer;
  font-family: var(--font); font-size: 11px; text-transform: uppercase;
  letter-spacing: .7px; color: var(--accent); font-weight: 600; text-align: left;
}
.dom-head:hover { color: var(--ink); border-color: var(--accent); }
.dom-head .chev {
  display: inline-block; width: 9px; flex: none;
  transition: transform .12s ease; color: var(--ink-dim);
}
.dom-head .chev::before { content: "▾"; }
.domain.collapsed .dom-head .chev { transform: rotate(-90deg); }
.dom-head .dom-name { flex: 1; }
/* Active-weight count stays visible when the section is shut, so folding a
   domain away never hides the fact that it is driving the score. */
.dom-head .dom-badge .on {
  color: var(--good); font-family: var(--mono); font-size: 10px;
  text-transform: none; letter-spacing: 0; font-weight: 700;
}
/* The unfiltered case is stated explicitly rather than left blank, so a shut
   Universe reads as "nothing is narrowed" instead of ambiguous silence. */
.dom-head .dom-badge .all {
  color: var(--ink-dim); font-family: var(--mono); font-size: 10px;
  text-transform: none; letter-spacing: 0; font-weight: 400;
}
.dom-head .dom-total {
  color: var(--ink-dim); font-family: var(--mono); font-size: 10px;
  font-weight: 400; letter-spacing: 0;
}
.domain.collapsed .dom-body { display: none; }
/* Row rhythm: gaps WITHIN a row stay small and even (label 3px slider 5px dir),
   the gap BETWEEN rows is distinctly larger (16px) so the eye groups each
   label+slider+caption as one unit instead of reading an even cramped stack. */
.wrow { margin-bottom: 11px; }
.wrow .top { display: flex; justify-content: space-between; align-items: baseline; gap: 6px; margin-bottom: 1px; }
.wrow .lbl-wrap { display: inline-flex; align-items: center; gap: 5px; }
.wrow .lbl { font-size: 12.5px; color: var(--ink); cursor: help; }
.wrow .info {
  font-size: 11px; color: var(--ink-dim); cursor: help; flex: none;
  line-height: 1; opacity: .65;
}
.wrow .info:hover { color: var(--accent); opacity: 1; }
.wrow .val { font-family: var(--mono); font-size: 11px; color: var(--ink-dim); }
.wrow .val.on { color: var(--accent); font-weight: 700; }
.wrow input[type=range] { width: 100%; height: 16px; margin: 0 0 2px; accent-color: var(--accent); display: block; }
/* Caption is a flex row so the grain badge sits inline when it fits and wraps
   just under the text when it doesn't. Kept tight -- the row rhythm carries the
   separation, so the caption hugs its slider. */
.wrow .dir {
  display: flex; flex-wrap: wrap; align-items: center; gap: 2px 8px;
  font-size: 10.5px; line-height: 1.2; color: var(--ink-dim);
}
.wrow .dir .gbadge { margin-left: 0; }

#map { height: 100%; width: 100%; background: #0b1016; }
main { position: relative; min-height: 0; }
#legend {
  position: absolute; bottom: 14px; left: 14px; z-index: 500;
  background: rgba(23,32,41,.94); border: 1px solid var(--line);
  border-radius: 6px; padding: 8px 10px; font-size: 11px; color: var(--ink-dim);
}
#layer-control {
  position: absolute; top: 14px; right: 14px; z-index: 500;
  background: rgba(23,32,41,.94); border: 1px solid var(--line);
  border-radius: 6px; padding: 8px 10px; font-size: 12px; color: var(--ink);
}
.layer-toggle { display: flex; align-items: center; gap: 7px; cursor: pointer; margin: 0; }
.layer-toggle input { width: auto; accent-color: #d98aa8; margin: 0; }
.swatch-pin {
  width: 11px; height: 11px; border-radius: 50%; flex: none;
  background: #d98aa8; border: 2px solid #f0b6c9;
}
.layer-toggle + .layer-toggle { margin-top: 6px; }
.swatch-sstax {
  width: 15px; height: 10px; border-radius: 2px; flex: none;
  background: rgba(224,68,63,.55); border: 1px solid #e0443f;
}
.leaflet-tooltip .sstax { color: #f08a86; font-size: 10.5px; margin-top: 2px; }
.swatch-census {
  width: 11px; height: 11px; border-radius: 50%; flex: none;
  background: #f0a04b; border: 2px solid #f5c07a;
}
.swatch-rucc {
  width: 14px; height: 11px; border-radius: 2px; flex: none;
  background: linear-gradient(90deg, rgb(118,42,131), rgb(175,141,195),
                             rgb(90,174,97), rgb(27,120,55));
}
.leaflet-tooltip .approx { color: var(--warn); font-size: 10.5px; margin-top: 2px; }

#legend .bar { display: flex; height: 9px; width: 190px; margin: 5px 0 3px; border-radius: 2px; overflow: hidden; }
#legend .bar i { flex: 1; }
#legend .ends { display: flex; justify-content: space-between; }
#legend .key { display: flex; align-items: center; gap: 6px; margin-top: 7px;
               padding-top: 6px; border-top: 1px solid var(--line); }
#legend .swatch-outline {
  width: 15px; height: 10px; flex: none; border-radius: 2px;
  background: #35506a; border: 1.6px solid #fff;
}

.hidden { display: none; }
.view-toggle { display: flex; gap: 0; margin-bottom: 12px; border: 1px solid var(--line);
               border-radius: 7px; overflow: hidden; }
.vt { flex: 1; background: var(--panel); color: var(--ink-dim); border: 0;
      padding: 7px 0; font-size: 12.5px; font-weight: 600; cursor: pointer;
      font-family: var(--font); }
.vt.on { background: var(--accent); color: #06222f; }
.vt:not(.on):hover { background: var(--panel-2); color: var(--ink); }

/* states view */
.state-row { padding: 10px 4px; border-bottom: 1px solid rgba(43,57,71,.5); cursor: pointer; }
.state-row:hover { background: var(--panel-2); }
.sr-top { display: flex; align-items: baseline; gap: 8px; }
.sr-rank { font-family: var(--mono); font-size: 11px; color: var(--ink-dim); width: 18px; }
.sr-name { flex: 1; font-weight: 600; font-size: 13.5px; }
.sr-best { font-family: var(--mono); font-size: 15px; font-weight: 700; color: var(--accent); }
.spread { position: relative; height: 6px; background: var(--panel-2);
          border-radius: 3px; margin: 6px 0 5px; }
.spread-range { position: absolute; top: 0; height: 100%; border-radius: 3px;
                background: linear-gradient(90deg, #35506a, var(--accent)); }
.spread-median { position: absolute; top: -2px; width: 2px; height: 10px;
                 background: var(--ink); border-radius: 1px; }
.sr-foot { display: flex; align-items: center; gap: 8px; font-size: 11px; color: var(--ink-dim); }
.sr-foot > span:first-child { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sr-n { font-family: var(--mono); flex: none; }
.tax-tag { font-size: 10px; font-weight: 700; padding: 1px 6px; border-radius: 3px;
           border: 1px solid currentColor; color: var(--ink-dim); flex: none; }
.tax-tag.good { color: var(--good); }
.tax-tag.bad { color: var(--warn); }

.results-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.results-head h2 { margin: 0; }
.showing { margin: 0; display: flex; align-items: center; gap: 5px; font-size: 11.5px; }
.showing select { width: auto; }

table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
th { text-align: left; color: var(--ink-dim); font-weight: 600; font-size: 11px;
     text-transform: uppercase; letter-spacing: .5px;
     border-bottom: 1px solid var(--line); padding: 6px 4px; position: sticky; top: 0;
     background: var(--panel); }
td { padding: 5px 4px; border-bottom: 1px solid rgba(43,57,71,.5); }
tbody tr { cursor: pointer; }
tbody tr:hover { background: var(--panel-2); }
tbody tr.sel { background: rgba(75,179,253,.15); }
td.num { font-family: var(--mono); text-align: right; }
td.empty { padding: 22px 6px; border: 0; }
td.empty p { margin: 0 0 9px; }
td.empty p:first-child { color: var(--ink); font-size: 13px; }
.cov { font-family: var(--mono); font-size: 11px; }
.cov.low { color: var(--warn); }

/* slide-over panels */
.panel {
  position: fixed; top: 0; right: 0; width: 520px; max-width: 94vw; height: 100%;
  background: var(--panel); border-left: 1px solid var(--line); z-index: 1000;
  overflow-y: auto; padding: 18px 20px; box-shadow: -14px 0 40px rgba(0,0,0,.45);
}
.panel.hidden { display: none; }
.panel h2 { font-size: 17px; text-transform: none; letter-spacing: 0; color: var(--ink); }
.panel .close { position: absolute; top: 14px; right: 16px; }
.panel .sub { color: var(--ink-dim); font-size: 12.5px; margin: 0 0 14px; }
.panel .verdict {
  font-size: 14px; color: var(--ink); background: var(--panel-2);
  border-left: 3px solid var(--accent); border-radius: 4px;
  padding: 10px 12px; margin: 2px 0 10px; line-height: 1.45;
}
.panel .verdict strong { color: var(--ink); }
.panel .verdict span { color: var(--ink-dim); }
.panel .math { font-size: 11.5px; color: var(--ink-dim); margin: -4px 0 10px; line-height: 1.5; }
.panel .math .mono { font-family: var(--mono); color: var(--ink); font-size: 11px; }
.howto { margin: 0 0 12px; font-size: 12.5px; color: var(--ink-dim); }
.howto summary { cursor: pointer; color: var(--accent); font-weight: 600; font-size: 12.5px; }
.howto ol { margin: 8px 0 4px 18px; padding: 0; line-height: 1.5; }
.howto li { margin-bottom: 4px; }
.panel .verdict.muted {
  border-left-color: var(--line); color: var(--ink-dim); font-size: 12.5px;
}

.mrow { border-bottom: 1px solid var(--line); padding: 9px 0; }
.mrow .mtop { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; }
.mrow .mname { font-weight: 600; }
.mrow .mval { font-family: var(--mono); font-size: 12px; }
.mrow .meter { height: 5px; background: var(--panel-2); border-radius: 3px; margin: 5px 0 4px; }
.mrow .meter i { display: block; height: 100%; border-radius: 3px; background: var(--accent); }
.mrow .cite { font-size: 11px; color: var(--ink-dim); line-height: 1.5; }

/* Grain badges: how literally to take the number. Deliberately NOT applied to
   plain county-measured metrics -- badging everything hides the exceptions. */
.gbadge {
  display: inline-block; margin-left: 6px; padding: 1px 6px;
  font-size: 9.5px; font-weight: 700; letter-spacing: .4px;
  text-transform: uppercase; border-radius: 3px; vertical-align: middle;
  border: 1px solid currentColor; white-space: nowrap;
}
.gbadge.g-est { color: #7fb3d5; }   /* survey estimate  */
.gbadge.g-pt  { color: #9d8ec7; }   /* point sample     */
.gbadge.g-imp { color: var(--warn); }  /* borrowed value */
.gbadge.g-law { color: var(--good); }  /* exact by law   */

.mrow .moe { font-family: var(--mono); font-size: 11px; color: var(--ink-dim); }
.mrow .moe.wide { color: var(--warn); font-weight: 700; }
.mrow .caveat { font-size: 11px; color: var(--warn); line-height: 1.5; margin-top: 3px; }
.mrow .wt { font-size: 10.5px; color: var(--ink-dim); font-family: var(--mono); }

/* Sources panel: an accordion grouped by agency, so it scans as a list of
   one-liners instead of a wall of text. Detail opens on click. */
.src-agency {
  display: flex; align-items: baseline; justify-content: space-between; gap: 8px;
  margin: 18px 0 4px; padding-bottom: 4px; border-bottom: 1px solid var(--line);
}
.src-agency .sa-name {
  font-size: 11px; text-transform: uppercase; letter-spacing: .7px;
  color: var(--accent); font-weight: 700;
}
.src-agency .sa-count { font-size: 10.5px; color: var(--ink-dim); font-family: var(--mono); }

.src-item { border-bottom: 1px solid rgba(43,57,71,.5); }
.src-head {
  display: flex; align-items: center; gap: 8px; width: 100%; text-align: left;
  background: none; border: 0; padding: 9px 2px; cursor: pointer;
  font-family: var(--font); color: var(--ink);
}
.src-head:hover { color: var(--accent); }
.src-head .chev {
  flex: none; width: 9px; color: var(--ink-dim); transition: transform .12s;
}
.src-head .chev::before { content: "▸"; }
.src-item.open .src-head .chev { transform: rotate(90deg); }
.src-head .src-name { flex: 1; font-size: 13px; font-weight: 500; }
.src-head .src-meta {
  flex: none; font-family: var(--mono); font-size: 10px; color: var(--ink-dim);
  background: var(--panel-2); border-radius: 10px; padding: 1px 7px;
}

.src-detail { display: none; padding: 0 2px 12px 17px; }
.src-item.open .src-detail { display: block; }
.src-actions { display: flex; gap: 14px; margin: 6px 0 2px; }
.src-note { color: var(--ink-dim); font-size: 11.5px; line-height: 1.5; margin-top: 7px; }
.src-license { color: var(--ink-dim); font-size: 10.5px; margin-top: 4px; opacity: .8; }

/* Citation block: monospace and selectable so it can be read carefully and
   copied by hand if needed. */
.src-detail .citation {
  font-family: var(--mono); font-size: 11px; line-height: 1.6;
  color: var(--ink); background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 5px; padding: 8px 9px; margin: 4px 0 0;
  user-select: all; word-break: break-word;
}
