/* Redesign (2026-10-27, from eg/dashboard concept.png): purple accent, header nav and search, Explore sidebar,
   location card, bottom card row, full-page ballot. Loaded after style.css, so its tokens and layout win. */
:root {
  --bg: #f3f2f9;
  --surface: #ffffff;
  --surface-2: #f7f6fc;
  --ink: #1b1a33;
  --muted: #5b5a76;
  --line: #dddaec;
  --accent: #6a3fd1;
  --accent-soft: #ece6ff;
  --accent-ink: #ffffff;
  --map-bg: #e8edf5;
  --land: #f7f7f3;
  --land-line: #cfd4de;
  --map-label: #5f6678;
  --county-line: #c9c6d3;
  --focus: #b64b00;
  --endorse: #6a3d9a;
  --pick: #1b1a33;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0a0f1e;
    --surface: #111a2e;
    --surface-2: #16203a;
    --ink: #eef0fa;
    --muted: #a6aeca;
    --line: #27314f;
    --accent: #ab87ff;
    --accent-soft: #2a2352;
    --accent-ink: #140b30;
    --map-bg: #0c1426;
    --land: #141d33;
    --land-line: #26304a;
    --map-label: #8f98b5;
    --county-line: #4a4366;
    --focus: #ffb76b;
    --endorse: #c7a6f2;
    --pick: #eef0fa;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0a0f1e;
  --surface: #111a2e;
  --surface-2: #16203a;
  --ink: #eef0fa;
  --muted: #a6aeca;
  --line: #27314f;
  --accent: #ab87ff;
  --accent-soft: #2a2352;
  --accent-ink: #140b30;
  --map-bg: #0c1426;
  --land: #141d33;
  --land-line: #26304a;
  --map-label: #8f98b5;
  --county-line: #4a4366;
  --focus: #ffb76b;
  --endorse: #c7a6f2;
  --pick: #eef0fa;
}

body { background: var(--bg); color: var(--ink); }
.visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
[data-icon] { display: inline-flex; align-items: center; gap: 8px; }
[data-icon] > svg.icon { width: 18px; height: 18px; flex: none; }

/* Header: brand, section nav, address search, account */
.topbar {
  max-width: 1600px; margin: 0 auto; padding-block: 12px;
  display: grid; grid-template-columns: auto auto minmax(220px, 1fr) auto; gap: 12px 16px; align-items: center;
}
.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--ink); text-decoration: none; }
.brand-mark { width: 40px; height: 40px; fill: none; stroke: var(--accent); stroke-width: 1.4; stroke-linejoin: round; }
.brand-name { display: grid; line-height: 1.05; font-size: 1.05rem; }
.brand-name strong { font-size: 1.45rem; letter-spacing: -.01em; }
.topnav { display: flex; flex-wrap: wrap; gap: 4px; padding: 4px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; justify-self: start; }
.topnav a, .topnav button { white-space: nowrap; padding: 8px 10px; border: 0; border-radius: 9px; background: transparent; color: var(--ink); font: inherit; font-size: .9rem; font-weight: 600; text-decoration: none; cursor: pointer; }
.topnav a:hover, .topnav button:hover { background: var(--surface-2); }
.topnav [aria-current="page"] { background: var(--accent); color: var(--accent-ink); }
.topsearch-wrap { position: relative; min-width: 0; }
.topsearch { display: flex; align-items: stretch; gap: 0; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 2px; }
.topsearch:focus-within { border-color: var(--accent); }
.topsearch-box { flex: 1; display: flex; align-items: center; gap: 8px; padding-left: 10px; min-width: 0; font-weight: 400; }
#address-form.topsearch { flex-wrap: nowrap; }
#address-form.topsearch .topsearch-box { flex: 1; min-width: 0; }
.topsearch-pin { color: var(--muted); }
.topsearch-box input { flex: 1; min-width: 0; border: 0; background: transparent; padding: 9px 4px; font-size: .92rem; }
.topsearch-box input:focus { outline: none; }
.topsearch-go { border: 0; background: transparent; color: var(--muted); padding: 0 10px; }
.topsearch-feedback { position: absolute; z-index: 20; top: calc(100% + 6px); left: 0; right: 0; display: grid; gap: 8px; }
@media (max-width: 700px) { .topsearch-feedback { position: static; } }
.topsearch-feedback:has(> :not(:empty)) { padding: 10px; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 8px 24px var(--shadow); }
.topsearch-wrap .address-suggestions { top: calc(100% + 4px); }
.account-open { display: inline-flex; align-items: center; gap: 8px; background: transparent; border: 0; color: var(--ink); font-weight: 600; }
.topbar .header-account-actions { display: flex; align-items: center; justify-self: end; gap: 4px; white-space: nowrap; }
.topbar .account-open { grid-column: auto; grid-row: auto; align-self: center; white-space: nowrap; }
.account-open svg.icon { width: 30px; height: 30px; }
.account-signout { align-self: center; white-space: nowrap; }
.account-signout[hidden] { display: none; }

/* Three columns and the card row */
#dashboard, .voter-cards, #summary-strip { max-width: 1600px; margin-inline: auto; }
.controls-section, .map-section, #panel { background: var(--surface); border-color: var(--line); }
.controls-section, #panel { max-height: none; overflow: visible; }
.explore { display: grid; align-content: start; gap: 14px; }
.explore-title { margin: 0; font-size: 1.2rem; }
.explore .controls { gap: 12px; }
.switch { display: flex; align-items: center; gap: 10px; font-weight: 500; cursor: pointer; }
.switch input { appearance: none; width: 36px; height: 20px; padding: 0; border-radius: 999px; background: var(--line); border: 0; position: relative; cursor: pointer; flex: none; }
.switch input::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: var(--surface); transition: transform .15s; }
.switch input:checked { background: var(--accent); }
.switch input:checked::after { transform: translateX(16px); }
.explore #legend { position: static; width: auto; box-shadow: none; background: var(--surface-2); }
.explore-nav { display: grid; gap: 2px; }
.explore-nav button { justify-content: flex-start; padding: 8px 10px; border: 0; border-radius: 8px; background: transparent; color: var(--ink); font-weight: 500; text-align: left; }
.explore-nav button:hover, .explore-nav button[aria-current="true"] { background: var(--accent-soft); color: var(--ink); }
.explore-nav svg.icon { color: var(--accent); }
.explore-status p { margin: 4px 0; font-size: .78rem; }
.explore-status #headline { font-size: .85rem; font-weight: 600; }

/* Map: ocean, neighbouring land, labels, callout */
.map-section { background: var(--map-bg); overflow: hidden; }
.land { fill: var(--land); stroke: var(--land-line); stroke-width: .8; vector-effect: non-scaling-stroke; }
.land-texas { fill: none; stroke: none; }
.map-label { fill: var(--map-label); font-size: 13px; letter-spacing: .14em; text-transform: uppercase; pointer-events: none; }
.map-label.water { font-style: italic; letter-spacing: .06em; text-transform: none; }
.city-dot { fill: var(--surface); stroke: var(--ink); stroke-width: 1.4; vector-effect: non-scaling-stroke; pointer-events: none; }
.city-label { fill: var(--ink); font-size: 12px; font-weight: 650; paint-order: stroke; stroke: var(--surface); stroke-width: 3px; stroke-linejoin: round; pointer-events: none; }
.cities-hidden .city { display: none; }
#map-callout {
  position: absolute; z-index: 3; display: flex; align-items: center; gap: 10px; padding: 8px 10px 8px 12px;
  background: var(--surface); color: var(--ink); border: 1px solid var(--line); border-radius: 10px;
  box-shadow: 0 6px 18px var(--shadow); font-size: .82rem; line-height: 1.35; pointer-events: auto;
}
#map-callout strong { display: block; font-size: .9rem; }
#map-callout button { border: 0; background: transparent; color: var(--muted); padding: 2px; }
.county.selected { stroke: var(--accent); stroke-width: 2.5; }

/* Right column: location card and tabs */
.location-card { display: grid; grid-template-columns: 96px minmax(0, 1fr); gap: 8px 14px; padding: 14px; margin-bottom: 14px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px; }
.location-card h2 { grid-column: 1 / -1; display: flex; justify-content: space-between; align-items: center; margin: 0; font-size: 1.15rem; }
.location-card h2 button { font-size: .8rem; padding: 4px 12px; }
.location-thumb { width: 96px; height: 72px; border-radius: 8px; background: var(--map-bg); display: block; }
.location-thumb path { fill: var(--land); stroke: var(--accent); stroke-width: 1.5; vector-effect: non-scaling-stroke; }
.location-thumb circle { fill: var(--accent); stroke: var(--surface); stroke-width: 2; }
.location-text { min-width: 0; display: grid; gap: 4px; align-content: start; }
.location-text strong { font-size: .98rem; overflow-wrap: anywhere; }
.location-districts { font-size: .8rem; color: var(--muted); }
.panel-tabs { display: flex; gap: 4px; padding: 4px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface-2); }
.panel-tabs button { flex: 1; padding: 8px 6px; border: 0; border-radius: 7px; background: transparent; color: var(--ink); font-size: .85rem; font-weight: 600; }
.panel-tabs button[aria-selected="true"] { background: var(--accent); color: var(--accent-ink); }
.overview-hero { display: grid; grid-template-columns: minmax(0, 11rem) minmax(0, 1fr); gap: 12px; align-items: center; padding: 14px; margin-block: 12px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px; }
.overview-hero .hero-label { margin: 0; font-weight: 650; }
.overview-hero .hero-value { display: block; font-size: 2.3rem; line-height: 1.1; font-weight: 750; }
.overview-hero .hero-sub { margin: 2px 0 0; font-size: .82rem; color: var(--muted); }
.overview-more { margin-top: 12px; }
.overview-more > summary { cursor: pointer; font-weight: 650; padding: 6px 0; }
@container (max-width: 380px) { .overview-hero { grid-template-columns: 1fr; } }

/* Bottom row of cards when an address is known */
.voter-cards { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; width: 100%; margin-block: 12px; }
.voter-cards > section { min-width: 0; height: auto; max-height: none; overflow: visible; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 16px; }
#summary-strip > section { background: var(--surface); }

/* Pages: Candidates, Quizzes, Resources */
.page-view { display: block; max-width: 1600px; margin: 0 auto; padding-block: 12px 32px; }
.page-view:focus { outline: none; }
.page-view h1 { margin: 6px 0 4px; font-size: 1.7rem; }

/* The ballot uses the regular page flow so the document owns scrolling. */
.ballot-page { max-width: 1600px; margin: 0 auto; padding: 16px max(16px, env(safe-area-inset-left, 0px)) calc(32px + env(safe-area-inset-bottom, 0px)); display: grid; gap: 16px; }
.ballot-page-head { display: flex; justify-content: space-between; align-items: center; gap: 16px; padding: 16px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; }
.ballot-page-head h1 { margin: 0; font-size: 1.5rem; }
.ballot-page-head p { margin: 3px 0 0; }
.ballot-page-back { display: inline-flex; align-items: center; gap: 7px; flex: none; }
.ballot-page-back svg.icon { width: 16px; height: 16px; }
.ballot-page-content { display: grid; gap: 12px; min-width: 0; }
.ballot-page-content > * { max-width: none; margin: 0; }
.ballot-page-content .race { scroll-margin-top: 16px; }
.ballot-page-content .race.flash { animation: race-flash 1.6s ease-out; }
@keyframes race-flash { from { background: var(--accent-soft); } to { background: transparent; } }

/* Wide screens: the dashboard fills the window (style.css sets the body grid); the card row is part of it */
/* Explore is the whole left side; the cards sit under the map and the county panel. */
main#dashboard { grid-template-areas: "explore map" "panel panel" "cards cards"; }
.explore { grid-area: explore; }
main#dashboard > .map-section { grid-area: map; }
main#dashboard > #panel { grid-area: panel; }
main#dashboard > .voter-cards, main#dashboard > #summary-strip { grid-area: cards; margin: 0; width: auto; max-width: none; }
.voter-cards { grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: start; }
.voter-cards:not([hidden]) ~ #summary-strip { display: none; }
/* Phones: the map and the statewide panel lead, the Explore controls come after, and the card row stays last.
   display: grid overrides the generic main { display: block; } in style.css so the areas below apply. */
@media (max-width: 799px) {
  main#dashboard { display: grid; grid-template-columns: minmax(0, 1fr); grid-template-areas: "map" "panel" "explore" "cards"; }
}
@media (min-width: 1100px) {
  main#dashboard {
    grid-template-columns: 300px minmax(0, 1fr) clamp(380px, 30vw, 460px);
    grid-template-rows: minmax(560px, auto) auto;
    grid-template-areas: "explore map panel" "explore cards cards";
  }
  main#dashboard > .map-section { height: auto; min-height: 560px; }
  /* The map sets the height of the top row; the county panel scrolls inside it (Nate, 2026-10-27: opening
     "More turnout detail" must not stretch the map). height: 0 + min-height: 100% keeps the panel out of the
     row's sizing. */
  main#dashboard { grid-template-rows: auto auto; }
  main#dashboard > .map-section { aspect-ratio: 760 / 700; min-height: 0; max-height: 82vh; align-self: start; }
  main#dashboard > #panel { height: 0; min-height: 100%; overflow-y: auto; overscroll-behavior: contain; }
}
@media (min-width: 1100px) and (min-height: 720px) {
  body { height: auto; min-height: 100dvh; grid-template-rows: auto auto auto; }
  body.page-open { display: block; height: auto; min-height: 100dvh; }
  main#dashboard { height: auto; margin-bottom: 12px; }
  .topbar { width: 100%; padding-block: 12px 0; }
  .voter-cards { height: auto; }
  .controls-section, #panel { height: 100%; max-height: none; overflow: visible; }
  #summary-strip { height: auto; align-items: start; }
  #summary-strip > section { height: auto; max-height: none; overflow: visible; }
}
@media (max-width: 1399px) {
  .topbar { grid-template-columns: auto minmax(0, 1fr) auto; }
  .topnav { grid-column: 1 / -1; grid-row: 2; }
}
@media (max-width: 899px) {
  .voter-cards { grid-template-columns: 1fr; }
}
@media (max-width: 700px) {
  .topbar { grid-template-columns: minmax(0, 1fr) auto; }
  .topsearch-wrap { grid-column: 1 / -1; grid-row: 2; }
  .topnav { grid-row: 3; overflow-x: auto; flex-wrap: nowrap; justify-self: stretch; }
  /* Phones: the five sections share the row as icon-over-label tabs, so none hides off the edge. */
  .topnav a, .topnav button { flex: 1 1 0; min-width: 0; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 2px; font-size: .74rem; }
  .account-open span { display: none; }
  .brand-name strong { font-size: 1.2rem; }
  .ballot-page-head { align-items: flex-start; }
  .ballot-page-head h1 { font-size: 1.25rem; }
}

/* Phones: the county panel sits in the page after the map instead of a bottom sheet that scrolls by itself. */
@media (max-width: 799px) {
  body.county-open #panel { position: static; max-height: none; overflow: visible; box-shadow: none; border-radius: 12px; padding-bottom: 16px; }
  body.county-open .panel-top { position: static; }
}

/* Your location on the ballot page, with its own address search */
.ballot-location { display: grid; gap: 8px; padding: 16px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; }
.ballot-location h2 { margin: 0; font-size: 1.1rem; }
.ballot-location p { margin: 0; }
.ballot-location-label { font-weight: 650; }
.ballot-location-districts { font-size: .85rem; color: var(--muted); }
.address-box { display: flex; flex-wrap: nowrap; align-items: stretch; gap: 8px; max-width: 640px; position: relative; }
.address-box-field { flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px; padding: 0 10px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; font-weight: 400; }
.address-box-field:focus-within { border-color: var(--accent); }
.address-box-field svg.icon { color: var(--muted); width: 18px; height: 18px; flex: none; }
.address-box-field input { flex: 1; min-width: 0; border: 0; background: transparent; padding: 10px 2px; }
.address-box-field input:focus { outline: none; }
.address-box button[type=submit] { padding: 0 18px; }
.address-box-status:empty, .address-box-choices:empty { display: none; }
.address-box-choices { display: grid; gap: 8px; }

/* Where to vote: the map stays on the left and the right-hand box widens to hold the list and detail card. */
body.where-open .voter-cards { display: none; }
body.where-open #panel .where-to-vote .where-head h2,
body.where-open #panel .where-to-vote .where-sub,
body.where-open #close { display: none; }
@media (min-width: 1400px) {
  body.where-open main#dashboard { grid-template-columns: 280px minmax(0, 1fr) clamp(620px, 46vw, 820px); }
  body.where-open main#dashboard > .map-section { aspect-ratio: auto; height: max(640px, calc(100dvh - 130px)); max-height: none; }
}
@media (min-width: 1100px) and (max-width: 1399px) {
  body.where-open main#dashboard { grid-template-columns: 300px minmax(0, 1fr); grid-template-rows: auto auto; grid-template-areas: "explore map" "explore panel"; }
  body.where-open main#dashboard > #panel { height: auto; min-height: 0; overflow: visible; }
}

/* Your ballot replaces the map and county panel; the Explore sidebar stays. Location | contests | my ballot sheet. */
.ballot-view[hidden] { display: none; }
body.ballot-open .explore, body.ballot-open main#dashboard > .map-section, body.ballot-open #panel, body.ballot-open .voter-cards, body.ballot-open #summary-strip { display: none; }
body.ballot-open main#dashboard { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto; grid-template-areas: "ballot"; }
body.ballot-open main#dashboard > #ballot-view { grid-area: ballot; min-width: 0; }
.ballot-page { max-width: none; margin: 0; padding: 0; }
.ballot-grid { display: grid; gap: 16px; grid-template-columns: minmax(0, 1fr); align-items: start; }
.ballot-col { display: grid; gap: 12px; min-width: 0; align-content: start; }
@media (min-width: 1100px) {
  body.ballot-open main#dashboard { grid-template-columns: minmax(0, 1fr); grid-template-areas: "ballot"; }
  .ballot-grid { grid-template-columns: minmax(0, 1fr) 360px; grid-template-areas: "middle right" "left right"; }
  .ballot-col-left { grid-area: left; } .ballot-col-middle { grid-area: middle; } .ballot-col-right { grid-area: right; position: sticky; top: 12px; }
}
@media (min-width: 1280px) {
  .ballot-grid { grid-template-columns: minmax(300px, 24%) minmax(0, 1fr) 380px; grid-template-areas: "left middle right"; }
}
/* The small map under Your location */
.ballot-col-left .map-section { aspect-ratio: 760 / 700; height: auto; min-height: 0; max-height: none; border: 1px solid var(--line); border-radius: 12px; position: relative; }
.ballot-col-left .map-section #legend { position: absolute; bottom: 8px; left: 8px; width: min(220px, calc(100% - 16px)); font-size: .66rem; }
.ballot-col-left #map-callout { display: none; }
.panel-tabs button[aria-current="page"] { background: var(--accent); color: var(--accent-ink); }
.mode-tabs { margin: 0 0 12px; }
.ballot-col-right .mode-tabs { margin: 0 0 4px; }
.ballot-col-right .mode-tabs button { white-space: nowrap; font-size: .8rem; padding: 8px 4px; }
.header-account-actions { flex-wrap: wrap; }
.account-entry { white-space: nowrap; padding: 6px 9px; }
@media (max-width: 700px) { .topbar .header-account-actions { max-width: 200px; justify-content: flex-end; gap: 3px; } }
/* The narrowest phones (320–360px): smaller tab labels, and the name stays on two whole-word lines. */
@media (max-width: 360px) {
  .topnav a, .topnav button { font-size: .66rem; }
  .brand-name { white-space: nowrap; }
  .brand { gap: 6px; }
  .brand-mark { flex: none; width: 28px; height: 28px; }
  .brand-name strong { font-size: 1rem; }
  .brand-name { font-size: .9rem; }
}
