:root {
  --bg: #f6f7f5;
  --panel: #ffffff;
  --text: #1f2328;
  --muted: #646a70;
  --line: #d9dcd8;
  --link: #1f5fd1;
  --mark: #e8b20c;
  --mark-soft: #fbefc4;
  --warn-bg: #fff4e5;
  --warn-text: #8a4b00;
  --land: #ecedea;
  --land-other: #e2e3df;
  --water: #d7e3ea;
  --place: #3d4247;
  --place-halo: rgba(255, 255, 255, 0.85);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111317; --panel: #181b20; --text: #e6e6e6; --muted: #9aa3ad; --line: #2e333a; --link: #7aa2ff; --mark: #f2c230; --mark-soft: #3b3215;
    --warn-bg: #3a2a12; --warn-text: #ffcf8a; --land: #22262b; --land-other: #1b1e22; --water: #12191f;
    --place: #d6d9dc; --place-halo: rgba(0, 0, 0, 0.7);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #111317; --panel: #181b20; --text: #e6e6e6; --muted: #9aa3ad; --line: #2e333a; --link: #7aa2ff; --mark: #f2c230; --mark-soft: #3b3215;
  --warn-bg: #3a2a12; --warn-text: #ffcf8a; --land: #22262b; --land-other: #1b1e22; --water: #12191f;
  --place: #d6d9dc; --place-halo: rgba(0, 0, 0, 0.7);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: "Heebo", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  font-size: 14px;
}
.site-nav { flex: none; }
.site-nav-in { max-width: none; }  /* the map is full width, so the header is too */
.app { flex: 1; min-height: 0; display: flex; }
#panel {
  width: 360px;
  flex: none;
  height: 100%;
  overflow-y: auto;
  background: var(--panel);
  border-left: 1px solid var(--line);
  padding: 18px 18px 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}
#panel > section, #panel > details { flex: none; }
#sheet-handle { display: none; }
#map { flex: 1; height: 100%; }
h1 { font-family: "Frank Ruhl Libre", serif; font-weight: 500; font-size: 26px; line-height: 1.15; margin: 0; }
h2 { font-size: 15px; margin: 0 0 8px; color: var(--text); font-weight: 700; }
.sub { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
.note { color: var(--muted); font-size: 12.5px; line-height: 1.5; margin: 6px 0 0; }
a { color: var(--link); }

#sim-banner {
  margin-top: 10px;
  padding: 8px 10px;
  border-radius: 6px;
  background: var(--warn-bg);
  color: var(--warn-text);
  font-size: 13px;
}

/* The three questions a reader comes with (which election, what, where) come first. */
.controls { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.controls .wide { grid-column: 1 / -1; }
label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; font-weight: 500; color: var(--text); }
select, input:not([type="checkbox"]):not([type="range"]) {
  font: inherit;
  font-size: 15px;
  font-weight: 400;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--control-line, #b4b9b3);
  border-radius: var(--radius-control, 8px);
  height: var(--control-h, 38px);
  padding: 0 10px;
}
select:focus-visible, input:focus-visible, button:focus-visible, summary:focus-visible { outline: 3px solid var(--mark); outline-offset: 1px; }
.controls .search input { border-color: var(--text); border-width: 1.5px; }
.legend-box { border-top: 1px solid var(--line); padding-top: 16px; }
#info { background: var(--bg); border-radius: var(--radius-card, 10px); padding: 14px 16px; }
#info .hint { margin: 0; }
.opts { border-top: 1px solid var(--line); padding-top: 12px; }
.opts summary { cursor: pointer; font-weight: 700; font-size: 15px; padding-block: 4px; }
.opts .toggles { margin-top: 12px; gap: 12px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
  border-radius: 999px;
  min-height: 30px;
  padding: 0 12px;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}
.chip[aria-pressed="true"] { border-color: var(--control-line, #b4b9b3); }
.chip[aria-pressed="false"] { opacity: 0.5; text-decoration: line-through; }

#legend .bar { height: 12px; border-radius: 2px; }
#legend .ticks { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); margin-top: 3px; direction: ltr; }
#legend .swatches { display: grid; grid-template-columns: 1fr 1fr; gap: 3px 10px; }
#legend .sw { display: flex; align-items: center; gap: 6px; font-size: 13px; }
#legend .sw i { width: 12px; height: 12px; border-radius: 2px; flex: none; }

#info h3 { margin: 0; font-size: 18px; }
#info .meta { color: var(--muted); font-size: 12px; margin: 2px 0 8px; }
#info table { width: 100%; border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; }
#info th, #info td { padding: 3px 4px; border-bottom: 1px solid var(--line); text-align: right; }
#info th { color: var(--muted); font-weight: 500; }
#info td.num { text-align: left; direction: ltr; }
#info i.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-left: 4px; }
.pos { color: #15803d; }
.neg { color: #b91c1c; }

.leaflet-tooltip { font-family: "Heebo", sans-serif; direction: rtl; padding: 8px 12px; border-radius: 8px; border: 1px solid var(--line); box-shadow: 0 6px 24px rgba(0, 0, 0, .14); font-size: 13px; line-height: 1.5; }

/* Phone: the map takes the screen, the search floats over it, and the panel is a bottom sheet
   with three heights (peek: legend; half: + selected area and controls; full). */
@media (max-width: 760px) {
  .app { position: relative; }
  #map { height: 100%; }
  #panel { position: absolute; inset-inline: 0; bottom: 0; width: 100%; height: 30%; min-height: 150px; z-index: 1000;
    border-left: none; border-radius: 14px 14px 0 0; box-shadow: 0 -6px 24px rgba(0, 0, 0, .18); padding: 0 16px 24px; gap: 16px;
    transition: height .25s ease; }
  #panel[data-sheet="half"] { height: 58%; }
  #panel[data-sheet="full"] { height: calc(100% - 8px); }
  #panel[data-sheet="peek"] { overflow: hidden; }
  #sheet-handle { display: flex; justify-content: center; align-items: center; position: sticky; top: 0; z-index: 2; flex: none;
    height: 28px; margin: 0 -16px -8px; width: calc(100% + 32px); background: var(--panel); border: 0; cursor: pointer; touch-action: none; }
  #sheet-handle span { width: 40px; height: 5px; border-radius: 3px; background: #b9bdb8; }
  #panel > header { order: 1; }
  #panel header > :not(#sim-banner) { display: none; }
  #sim-banner { margin-top: 0; }
  #panel > * { order: 5; }
  #panel > #sheet-handle { order: 0; }
  #panel > #live { order: 1; }
  #panel > .legend-box { order: 2; border-top: 0; padding-top: 0; }
  #panel > #info { order: 3; }
  #panel > .controls { order: 4; }
  .controls .search { position: fixed; top: calc(var(--nav-h, 50px) + 10px); inset-inline: 12px; z-index: 1001; }
  .controls .search input { height: 44px; box-shadow: 0 2px 10px rgba(0, 0, 0, .18); font-size: 16px; }
  .controls .search { font-size: 0; gap: 0; }
  @media (prefers-reduced-motion: reduce) { #panel { transition: none; } }
  .leaflet-top { top: 60px; }
}
label.check { flex-direction: row; align-items: center; gap: 8px; font-size: 13px; color: var(--text); cursor: pointer; }
label.check input { margin: 0; }
.toggles { display: flex; flex-direction: column; gap: 6px; }
.site-pop { direction: rtl; font-family: "Heebo", sans-serif; }
.site-pop table { border-collapse: collapse; font-size: 10.5px; margin-top: 6px; font-variant-numeric: tabular-nums; }
.site-pop th, .site-pop td { padding: 2px 4px; white-space: nowrap; border-bottom: 1px solid #e5e7eb; text-align: right; }
.site-pop th { font-weight: 500; color: #6b7280; white-space: nowrap; }
.site-pop td.num { text-align: left; direction: ltr; }
.site-pop i.dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; margin-left: 3px; }

#live { border: 1px solid var(--line); border-radius: 8px; padding: 10px; }
#live table { width: 100%; border-collapse: collapse; font-size: 12px; font-variant-numeric: tabular-nums; }
#live th, #live td { padding: 2px 4px; border-bottom: 1px solid var(--line); text-align: right; }
#live th { color: var(--muted); font-weight: 500; }
#live td.num, #live th.num { text-align: left; direction: ltr; }
#live i.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-left: 4px; }
#live .sw { display: flex; align-items: center; gap: 6px; font-size: 12px; }
#live .sw i { width: 12px; height: 12px; border-radius: 2px; }
.site-pop .note { white-space: normal; font-size: 11px; color: #6b7280; }
#live td, #live th { white-space: nowrap; }

.place span { position: absolute; transform: translate(-50%, -50%); white-space: nowrap; font: 500 11px "Heebo", sans-serif;
  color: var(--place); text-shadow: 0 0 3px var(--place-halo), 0 0 3px var(--place-halo); pointer-events: none; }
.leaflet-container { font-family: "Heebo", system-ui, sans-serif; }
footer.note a { color: var(--link); }
h1 .home-link { color: inherit; text-decoration: none; }
.tt-note { color: #666; font-size: 11px; }
.prof summary { cursor: pointer; font-weight: 500; margin-top: 8px; }
.profile { display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; margin: 6px 0; font-size: 12px; }
.profile dt { color: var(--muted, #666); }
.profile dd { margin: 0; }
.venues { font-size: 12px; display: flex; flex-direction: column; gap: 2px; }
.venues b { font-weight: 500; }
.leaflet-tooltip { white-space: normal; width: max-content; max-width: 280px; direction: rtl; text-align: right; }
/* The gray basemap is very light; a little contrast keeps streets visible under the colors. */
.leaflet-tiles-pane img { filter: contrast(1.4); }
.tt-head { font-size: 13px; }
.tt-metric { margin: 5px 0; padding: 4px 8px; border-inline-start: 3px solid var(--text, #1f2328); background: rgba(0, 0, 0, .04); border-radius: 4px; }
.tt-label { font-size: 11px; color: #555; }
.tt-value { font-size: 16px; font-weight: 700; line-height: 1.3; }
.tt-value .dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-inline-end: 5px; vertical-align: middle; }
.tt-sub { display: block; font-size: 11px; font-weight: 400; color: #555; }
