/* Visual system follows NC Early Vote (ncearly.peark.es): one page column, sections split by rules,
   charts in titled panels with the legend above, one color per election cycle. */
:root {
  color-scheme: light;
  --page: #fcfcfb; --surface: #ffffff; --ink: #0b0b0b; --ink-2: #52514e; --muted: #6b6a66;
  --ring: #e4e3df; --grid: #ececE8; --axis: #d6d5d0; --wash: #f2f1ee; --accent: #2a78d6;
  /* one color per cycle; 2024 is also dashed because it is a presidential year */
  --c2026: #2a78d6; --c2022: #eb6834; --c2018: #1baf7a; --c2024: #6250d6;
  /* categorical: blue, orange, aqua, yellow, magenta (validated adjacent) */
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100; --s5: #e87ba4;
  /* party: D blue, R red, U aqua (validated all-pairs; CVD warn -> direct labels + tables) */
  --pD: #2a78d6; --pR: #e34948; --pU: #1baf7a; --pL: #eda100;
  /* ordinal blue ramp 250 -> 650 */
  --o1: #86b6ef; --o2: #5598e7; --o3: #2a78d6; --o4: #1c5cab; --o5: #184f95; --o6: #104281;
  --up: #0a7a0a; --down: #b32f2f;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #1a1a19; --surface: #222221; --ink: #f0efec; --ink-2: #c3c2b7; --muted: #a09f98;
    --ring: #383835; --grid: #2e2e2c; --axis: #4a4a46; --wash: #2b2b29; --accent: #3987e5;
    --c2026: #3987e5; --c2022: #d95926; --c2018: #199e70; --c2024: #9085e9;
    --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500; --s5: #d55181;
    --pD: #3987e5; --pR: #e66767; --pU: #199e70; --pL: #c98500;
    --o1: #184f95; --o2: #1c5cab; --o3: #256abf; --o4: #3987e5; --o5: #6da7ec; --o6: #9ec5f4;
    --up: #5fd05f; --down: #ee7b7b;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #1a1a19; --surface: #222221; --ink: #f0efec; --ink-2: #c3c2b7; --muted: #a09f98;
  --ring: #383835; --grid: #2e2e2c; --axis: #4a4a46; --wash: #2b2b29; --accent: #3987e5;
  --c2026: #3987e5; --c2022: #d95926; --c2018: #199e70; --c2024: #9085e9;
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500; --s5: #d55181;
  --pD: #3987e5; --pR: #e66767; --pU: #199e70; --pL: #c98500;
  --o1: #184f95; --o2: #1c5cab; --o3: #256abf; --o4: #3987e5; --o5: #6da7ec; --o6: #9ec5f4;
  --up: #5fd05f; --down: #ee7b7b;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { scroll-behavior: smooth; scroll-padding-top: 150px; }
body { margin: 0; background: var(--page); color: var(--ink); font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; -webkit-text-size-adjust: 100%; }
a { color: var(--accent); }
code { font-size: .9em; background: var(--wash); padding: 0 4px; border-radius: 3px; }
.wrap { max-width: 1080px; margin: 0 auto; padding: 0 16px; }
.skip { position: absolute; left: -999px; }
.skip:focus { left: 8px; top: 8px; background: var(--surface); padding: 6px 10px; z-index: 50; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* header */
.top { position: sticky; top: 0; z-index: 20; background: var(--page); border-bottom: 1px solid var(--ring); }
.top-row { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; padding-top: 12px; }
h1 { margin: 0; font-size: 1.5rem; letter-spacing: -.01em; }
.sub { margin: 2px 0 0; color: var(--ink-2); font-size: .9rem; }
.nav { display: flex; gap: 4px 14px; overflow-x: auto; padding-top: 6px; padding-bottom: 6px; white-space: nowrap; scrollbar-width: none; }
.nav a { color: var(--ink-2); text-decoration: none; font-size: .9rem; padding: 2px 0; border-bottom: 2px solid transparent; }
.nav a:hover { color: var(--ink); border-bottom-color: var(--accent); }
.filters { display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: center; padding-bottom: 10px; }
.filters label { display: flex; align-items: center; gap: 8px; font-size: .78rem; color: var(--muted); max-width: 100%; }
.src { color: var(--muted); font-size: .85rem; max-width: 90ch; margin: 16px 0 0; }

/* controls: captioned dropdowns and joined toggle buttons */
.btn, select, input[type=search], .seg button {
  font: inherit; font-size: .9rem; color: var(--ink); background: var(--surface);
  border: 1px solid var(--ring); border-radius: 6px; padding: 6px 10px; max-width: 100%;
}
.btn { cursor: pointer; } .btn:hover, .seg button:hover { background: var(--wash); }
#f-geo { min-width: 220px; }
.controls { display: flex; flex-wrap: wrap; gap: 10px 14px; align-items: end; margin: 8px 0 12px; }
.controls label { display: flex; flex-direction: column; gap: 3px; font-size: .78rem; color: var(--muted); max-width: 100%; }
.controls label select, .controls label input, .filters label select { min-width: 0; color: var(--ink); }
.controls .grow { flex: 1 1 200px; }
.seg { display: inline-flex; flex-wrap: wrap; }
.seg button { border-radius: 0; margin-left: -1px; cursor: pointer; }
.seg button:first-child { border-radius: 6px 0 0 6px; margin-left: 0; }
.seg button:last-child { border-radius: 0 6px 6px 0; }
.seg button[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #fff; position: relative; z-index: 1; }
.seg button:disabled { opacity: .45; cursor: not-allowed; }

/* sections */
section { padding: 28px 0 8px; border-bottom: 1px solid var(--ring); }
section:last-of-type { border-bottom: 0; }
h2 { margin: 0 0 6px; font-size: 1.3rem; }
h3 { margin: 22px 0 6px; font-size: 1.05rem; }
h4 { margin: 0 0 4px; font-size: .9rem; font-weight: 600; }
.lede { color: var(--ink-2); margin: 0 0 14px; max-width: 78ch; }
.sentence { margin: 8px 0; max-width: 80ch; }
.note { color: var(--muted); font-size: .85rem; max-width: 90ch; margin: 8px 0 0; }
details { margin: 10px 0; }
details summary { cursor: pointer; color: var(--ink-2); font-size: .9rem; }
details .tablewrap { margin: 8px 0 14px; }

/* number cards */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 12px; margin: 10px 0 12px; }
.tiles.five { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.tile { background: var(--surface); border: 1px solid var(--ring); border-radius: 8px; padding: 12px 14px; min-width: 0; }
.tile .k { font-size: .8rem; color: var(--muted); }
.tile .v { font-size: 1.9rem; font-weight: 650; letter-spacing: -.02em; line-height: 1.2; }
.tile .d { font-size: .9rem; color: var(--ink-2); margin-top: 2px; }
.tile .also { font-size: .8rem; color: var(--muted); margin-top: 6px; }
.tile .sw { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 6px; vertical-align: 1px; }
.tile.main { border-left: 4px solid var(--c2026); }
.tile.bench { border-left: 4px solid var(--c2022); }
.up { color: var(--up); } .down { color: var(--down); }

/* chart panels */
.legend { display: flex; flex-wrap: wrap; gap: 4px 16px; font-size: .85rem; color: var(--ink-2); margin: 4px 0 8px; }
.legend .it { display: inline-flex; align-items: center; gap: 6px; }
.legend svg { width: 26px; height: 8px; overflow: visible; }
.panels { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(320px, 100%), 1fr)); gap: 14px; }
.panels.one { grid-template-columns: minmax(0, 1fr); }
.panels.multiples { grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; }
.panel { background: var(--surface); border: 1px solid var(--ring); border-radius: 8px; padding: 8px 10px 4px; min-width: 0; }
.panel + .panel { margin-top: 0; }
.panel h4 { margin: 2px 4px 0; }
.multiples .panel h4 { display: flex; justify-content: space-between; gap: 8px; }
.multiples .panel h4 span { color: var(--ink-2); font-weight: 500; }
.panel.click { cursor: pointer; }
.panel.click:hover { border-color: var(--axis); }
.two { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(340px, 100%), 1fr)); gap: 14px; }
.two > div { min-width: 0; }
svg { display: block; overflow: visible; }
svg.chart-svg { width: 100%; height: auto; touch-action: pan-y; }
svg text { fill: var(--muted); font-size: 11px; font-family: inherit; font-variant-numeric: tabular-nums; }
svg .lbl { fill: var(--ink-2); font-size: 11px; font-weight: 600; }
svg .lbl-strong { fill: var(--ink); font-size: 11px; font-weight: 650; }
.gridline { stroke: var(--grid); stroke-width: 1; }
.axisline { stroke: var(--ring); stroke-width: 1; }
.cross { stroke: var(--ink-2); stroke-width: 1; stroke-dasharray: 3 3; }

/* 100% stacked bars (who is voting) */
.stack { margin: 8px 0 10px; }
.stack .row { display: grid; grid-template-columns: 56px 1fr; gap: 8px; align-items: center; margin: 4px 0; }
.stack .yr { font-weight: 600; font-size: .9rem; }
.stack .bar { display: flex; gap: 2px; height: 30px; }
.stack .seg2 { height: 100%; min-width: 1px; border-radius: 2px; display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: .75rem; font-weight: 600; overflow: hidden; }
.stack .seg2:hover { filter: brightness(1.12); outline: 2px solid var(--ink); outline-offset: -2px; }

/* tables */
.tablewrap { overflow-x: auto; border: 1px solid var(--ring); border-radius: 8px; background: var(--surface); margin-top: 8px; }
.tablewrap.tall { max-height: 560px; overflow-y: auto; }
table { border-collapse: collapse; width: 100%; font-size: .88rem; font-variant-numeric: tabular-nums; }
th, td { padding: 6px 10px; text-align: right; white-space: nowrap; border-bottom: 1px solid var(--ring); }
th:first-child, td:first-child { text-align: left; position: sticky; left: 0; background: var(--surface); }
thead th { position: sticky; top: 0; background: var(--surface); z-index: 2; font-weight: 600; color: var(--ink-2); font-size: .8rem; cursor: pointer; user-select: none; }
thead th:first-child { z-index: 3; }
thead tr.grp th { text-align: center; border-bottom: 0; padding-bottom: 0; cursor: default; }
thead tr.grp + tr th { top: 24px; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: var(--wash); }
tr.tot td { font-weight: 650; }
td.na { color: var(--muted); }
tr.clickable { cursor: pointer; }

/* map */
.map-panel { padding: 10px; }
.map-panel svg { width: 100%; height: auto; max-height: 560px; }
#m-chart path.cty { stroke: var(--surface); stroke-width: 1; cursor: pointer; }
#m-chart path.cty:hover, #m-chart path.cty.sel { stroke: var(--ink); stroke-width: 1.5; }
.steps { margin: 10px 0 2px; font-size: .8rem; color: var(--ink-2); }
.steps svg { width: 100%; max-width: 420px; height: auto; }

.tip { position: fixed; z-index: 60; pointer-events: none; background: var(--surface); color: var(--ink);
  border: 1px solid var(--ring); border-radius: 6px; padding: 6px 9px; font-size: .82rem; box-shadow: 0 4px 14px rgba(0,0,0,.18); max-width: 280px; }
.tip b { font-weight: 650; }
.tip .row { display: flex; justify-content: space-between; gap: 14px; font-variant-numeric: tabular-nums; }
.tip .sw { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 6px; }

.prose { max-width: 80ch; }
.prose h3 { margin-top: 18px; }
.prose p, .prose li { color: var(--ink-2); }
.foot { color: var(--muted); font-size: .8rem; padding-top: 24px; padding-bottom: 40px; }
@media (max-width: 560px) {
  html { scroll-padding-top: 190px; }
  h1 { font-size: 1.25rem; } .panels { grid-template-columns: minmax(0, 1fr); }
  .tile .v { font-size: 1.6rem; } section { padding-top: 22px; }
  .controls label { flex: 1 1 44%; } .controls label select { width: 100%; }
  /* one compact filter row so the sticky header stays short on phones */
  .filters { flex-wrap: nowrap; gap: 8px; }
  .filters label { min-width: 0; } .filters label.geo { flex: 1 1 auto; }
  .filters .cap { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  #f-geo { min-width: 0; width: 100%; }
}
@media (forced-colors: active) { .seg button[aria-pressed="true"] { outline: 2px solid; } }
