:root {
  color-scheme: dark;
  --canvas: #0b1118;
  --surface: #111a23;
  --surface-raised: #17232f;
  --surface-soft: #0e1720;
  --text: #f4f7fa;
  --text-muted: #bac4ce;
  --border: #344454;
  --border-control: #5f789a;
  --link: #8cc8ff;
  --accent: #6fd8c6;
  --on-accent: #071512;
  --focus: #ffd166;
  --warning: #f4c56b;
  --danger: #ffaaa5;
  --party-democratic: #83c5ff;
  --party-republican: #ffaaa7;
  --party-libertarian: #f4df74;
  --party-constitution: #bce88c;
  --party-forward: #d4b6ff;
  --party-independent-american: #7fe0d4;
  --shadow: none;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --content: 74rem;
}

@media (prefers-color-scheme: light) {
  :root {
    color-scheme: light;
    --canvas: #f4f1ea;
    --surface: #fff;
    --surface-raised: #eae6dd;
    --surface-soft: #f8f6f1;
    --text: #17202a;
    --text-muted: #53606d;
    --border: #cbd2d9;
    --border-control: #7b8794;
    --link: #005ea8;
    --accent: #006b5e;
    --on-accent: #fff;
    --focus: #9c5b00;
    --warning: #7a4a00;
    --danger: #9d2118;
    --party-democratic: #075a9c;
    --party-republican: #a2262d;
    --party-libertarian: #695700;
    --party-constitution: #3d6b1f;
    --party-forward: #6738a3;
    --party-independent-american: #00685e;
    --shadow: 0 10px 24px rgb(41 49 56 / 10%);
  }
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--canvas);
  color: var(--text);
  font: 1rem/1.58 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
a { color: var(--link); text-underline-offset: 3px; }
a:hover { text-decoration-thickness: 2px; }
button, input, select { font: inherit; }
button, select { cursor: pointer; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }
[hidden] { display: none !important; }

.skip-link {
  position: fixed;
  z-index: 100;
  top: 10px;
  left: 10px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  background: var(--text);
  color: var(--canvas);
  transform: translateY(-150%);
}
.skip-link:focus { transform: translateY(0); }

.site-header, main, .site-footer {
  width: min(var(--content), calc(100% - 40px));
  margin-inline: auto;
}

.masthead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 64px;
  border-bottom: 1px solid var(--border);
}
.masthead .brand { color: var(--text); font-weight: 800; text-decoration: none; }
.masthead div { display: flex; gap: 22px; }
.masthead div a { color: var(--text-muted); font-size: .9rem; }

.hero { max-width: 58rem; padding: 54px 0 32px; }
.eyebrow, .kicker, .race-kicker {
  margin: 0 0 7px;
  color: var(--accent);
  font-size: .78rem;
  font-weight: 850;
  letter-spacing: .1em;
  text-transform: uppercase;
}
h1, h2, h3 { letter-spacing: -.025em; }
h1 { max-width: 52rem; margin: 0 0 14px; font-size: clamp(2.5rem, 5vw, 3.6rem); line-height: 1.03; }
h2 { margin: 0; font-size: clamp(1.6rem, 3vw, 2.1rem); line-height: 1.15; }
h3 { line-height: 1.2; }
.lede { max-width: 52rem; margin: 0; color: var(--text-muted); font-size: 1.12rem; }
.hero-actions, .action-row { display: flex; flex-wrap: wrap; gap: 10px; }
.hero-actions { margin-top: 24px; }
.privacy-note, .field-help { margin: 10px 0 0; color: var(--text-muted); font-size: .88rem; }
.research-notice {
  max-width: 52rem;
  margin: 20px 0 0;
  padding: 14px 16px;
  border-left: 3px solid var(--accent);
  background: var(--surface-soft);
  color: var(--text-muted);
  font-size: .92rem;
}
.research-notice strong { color: var(--text); }

.button {
  display: inline-flex;
  min-height: 46px;
  align-items: center;
  justify-content: center;
  padding: 10px 16px;
  border: 1px solid var(--border-control);
  border-radius: var(--radius-md);
  background: var(--surface);
  color: var(--text);
  font-weight: 750;
  text-decoration: none;
}
.button-primary { border-color: var(--accent); background: var(--accent); color: var(--on-accent); }
.button-secondary:hover, .button-quiet:hover { background: var(--surface-raised); }
.button-quiet { min-height: 42px; color: var(--text-muted); }

.trust-strip {
  margin: 0;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
}
.trust-strip > summary { padding: 13px 16px; cursor: pointer; color: var(--text-muted); font-weight: 750; }
.trust-strip[open] > summary { border-bottom: 1px solid var(--border); color: var(--text); }
.trust-grid { display: grid; grid-template-columns: 1.3fr 1.2fr 1fr; gap: 1px; margin: 0; background: var(--border); }
.trust-grid div { padding: 14px 16px; background: var(--surface); }
.trust-strip dt { color: var(--text-muted); font-size: .76rem; font-weight: 800; letter-spacing: .05em; text-transform: uppercase; }
.trust-strip dd { margin: 3px 0 0; font-size: .92rem; }

main { padding: 44px 0 24px; }
.panel {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow);
}
.finder, .search-panel, .empty-state { padding: 24px; }
.section-heading, .result-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
}
.section-heading > a { max-width: 23rem; text-align: right; }
.section-copy { max-width: 55rem; margin: 10px 0 20px; color: var(--text-muted); }

.district-form {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  align-items: end;
}
.district-form .button { grid-column: 1 / -1; justify-self: start; }
label span {
  display: block;
  margin-bottom: 5px;
  color: var(--text-muted);
  font-size: .8rem;
  font-weight: 750;
}
input, select {
  width: 100%;
  min-height: 48px;
  padding: 10px 12px;
  border: 1px solid var(--border-control);
  border-radius: var(--radius-md);
  background: var(--surface-soft);
  color: var(--text);
}
.finder-warning {
  margin: 20px 0 0;
  padding: 13px 15px;
  border-left: 4px solid var(--warning);
  border-radius: var(--radius-sm);
  background: var(--surface-raised);
  color: var(--text-muted);
}
.finder-warning strong { color: var(--text); }

.browse-section { padding: 54px 0 20px; }
.inventory { margin: 0; color: var(--text-muted); text-align: right; }
.category-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 12px;
  margin-top: 20px;
}
.category-card {
  min-height: 78px;
  padding: 13px 15px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  color: var(--text);
  text-align: left;
  box-shadow: none;
}
.category-card:hover, .category-card[aria-pressed="true"] { border-color: var(--border-control); background: var(--surface-raised); }
.category-card span { display: block; }
.category-name { font-size: 1.12rem; font-weight: 800; }
.category-count { margin-top: 4px; color: var(--text-muted); font-size: .8rem; font-weight: 700; }

.search-panel {
  display: grid;
  grid-template-columns: minmax(220px, .8fr) minmax(320px, 1.2fr);
  gap: 24px 34px;
  align-items: end;
  margin-top: 34px;
  padding: 24px 0;
  border-block: 1px solid var(--border);
}
.search-panel .field-help { grid-column: 2; }
.search-row { display: grid; grid-template-columns: 1fr auto; gap: 10px; }

.results-section { padding-top: 56px; scroll-margin-top: 20px; }
.result-status { margin: 12px 0 18px; color: var(--text-muted); }
#races { display: grid; min-width: 0; gap: 12px; }
.race-group {
  min-width: 0;
  overflow: visible;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
}
.race-group[open] { border-color: var(--border-control); }
.race-group > summary {
  display: flex;
  min-height: 88px;
  align-items: center;
  justify-content: space-between;
  gap: 22px;
  padding: 16px 20px;
  cursor: pointer;
  list-style: none;
}
.race-group > summary::-webkit-details-marker { display: none; }
.race-group > summary::after { content: "+"; color: var(--link); font-size: 1.7rem; line-height: 1; }
.race-group[open] > summary::after { content: "−"; }
.race-summary-copy { display: grid; flex: 1; min-width: 0; }
.race-summary-copy strong { font-size: 1.12rem; }
.race-kicker { margin-bottom: 2px; font-size: .7rem; }
.race-names { overflow: hidden; color: var(--text-muted); font-size: .88rem; text-overflow: ellipsis; white-space: nowrap; }
.race-summary-copy > .badge { width: max-content; margin-top: 7px; }
.race-count { margin-left: auto; color: var(--text-muted); font-size: .82rem; white-space: nowrap; }
.race-content { min-width: 0; padding: 0 20px 20px; border-top: 1px solid var(--border); }
.race-note { margin: 0 -20px 18px; padding: 12px 20px; background: var(--surface-raised); color: var(--text-muted); font-size: .9rem; }
.candidate-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 12px; }
.candidate-summary {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 14px;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface-soft);
}
.candidate-identity { display: flex; align-items: flex-start; gap: 12px; min-width: 0; }
.candidate-identity h3 { margin: 3px 0 5px; font-size: 1.08rem; }
.candidate-meta { margin: 0; color: var(--text-muted); font-size: .86rem; }
.party-label { font-weight: 800; }
.party-label.party-democratic { color: var(--party-democratic); }
.party-label.party-republican { color: var(--party-republican); }
.party-label.party-libertarian { color: var(--party-libertarian); }
.party-label.party-constitution { color: var(--party-constitution); }
.party-label.party-forward { color: var(--party-forward); }
.party-label.party-independent-american { color: var(--party-independent-american); }
.party-label.party-unaffiliated, .party-label.party-unlisted { color: var(--text-muted); }
.label-row { display: flex; flex-wrap: wrap; gap: 6px; }
.badge {
  display: inline-flex;
  min-height: 26px;
  align-items: center;
  padding: 3px 8px;
  border: 1px solid var(--border-control);
  border-radius: 999px;
  color: var(--warning);
  font-size: .76rem;
  font-weight: 750;
}
.badge.neutral { color: var(--text-muted); }
.badge.sourced { border-color: var(--accent); color: var(--accent); }
.badge.reviewed { border-color: var(--link); color: var(--link); }
.badge.draft { color: var(--text-muted); }
.badge.conflict { border-color: var(--danger); color: var(--danger); }
.action-row { margin-top: auto; }
.text-action {
  display: inline-flex;
  min-height: 44px;
  align-items: center;
  padding: 8px 2px;
  font-size: .9rem;
  font-weight: 700;
}
.text-action + .text-action { margin-left: 12px; }
.empty-state { text-align: left; }
.empty-state h2, .empty-state h3 { margin-top: 0; }
.form-error { margin: 14px 0 0; color: var(--danger); font-weight: 750; }

.comparison-scroll { width: 100%; max-width: 100%; overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--surface-soft); }
.comparison-table { width: 100%; min-width: 42rem; border-collapse: collapse; table-layout: fixed; }
.comparison-table caption { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.comparison-table th, .comparison-table td { min-width: 10rem; padding: 12px 14px; border-bottom: 1px solid var(--border); border-left: 1px solid var(--border); text-align: left; vertical-align: top; }
.comparison-table tr:last-child > * { border-bottom: 0; }
.comparison-table th:first-child { width: 9rem; min-width: 9rem; border-left: 0; color: var(--text-muted); font-size: .8rem; }
.comparison-table thead th { background: var(--surface-raised); color: var(--text); font-size: 1rem; }
.comparison-table thead th:not(:first-child) a { display: block; font-size: 1.05rem; }
.comparison-table thead th span { display: block; margin-top: 3px; color: var(--text-muted); font-size: .76rem; font-weight: 650; }
.comparison-table .text-action { min-height: 36px; }

.site-footer { padding: 56px 0 42px; color: var(--text-muted); font-size: .9rem; }
.site-footer p { max-width: 62rem; }

/* Legal pages */
.legal-layout { max-width: 58rem; }
.legal-layout article { min-width: 0; }
.legal-callout {
  margin: 0 0 28px;
  padding: 16px 18px;
  border: 1px solid var(--border);
  border-left: 4px solid var(--warning);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text-muted);
}
.legal-callout strong { color: var(--text); }
.legal-meta { color: var(--text-muted); font-size: .9rem; }
.legal-layout h2 { font-size: clamp(1.35rem, 2.5vw, 1.65rem); }
.legal-layout li { margin: 7px 0; }

/* Detail and methodology pages */
.profile-header { padding: 42px 0 26px; }
.profile-header h1 { margin-top: 12px; }
.profile-identity-block { max-width: 58rem; padding-top: 34px; }
.profile-caveat { max-width: 54rem; margin: 18px 0 0; padding: 12px 14px; border-left: 4px solid var(--warning); background: var(--surface); color: var(--text-muted); }
.conflict-notice { max-width: 54rem; margin-top: 18px; padding: 14px 16px; border: 1px solid var(--danger); border-left-width: 5px; border-radius: var(--radius-sm); background: var(--surface); }
.conflict-notice strong { color: var(--danger); }
.conflict-notice p { margin: 4px 0 0; color: var(--text-muted); }
.loading-status { min-height: 180px; padding: 32px 0; color: var(--text-muted); }
.profile-labels { display: flex; flex-wrap: wrap; gap: 8px; }
.profile-layout { display: grid; grid-template-columns: minmax(0, 2fr) minmax(280px, 1fr); gap: 22px; }
.profile-section { margin-bottom: 18px; padding: 20px 0; border: 0; border-top: 1px solid var(--border); border-radius: 0; background: transparent; }
.profile-section h2 { margin-top: 0; }
.profile-section p { max-width: 72ch; white-space: pre-line; }
.profile-section dl { display: grid; grid-template-columns: minmax(130px, 1fr) 2fr; gap: 8px 14px; }
.profile-section dt { color: var(--text-muted); font-weight: 700; }
.profile-section dd { margin: 0; }
.profile-section li { margin: 7px 0; }
.source-kicker { margin: 0 0 3px !important; color: var(--accent); font-size: .76rem; font-weight: 800; letter-spacing: .07em; text-transform: uppercase; }
.trust-summary { border-top: 4px solid var(--accent); }
.trust-summary.has-conflict { border-top-color: var(--danger); }
.source-list { padding-left: 20px; }
.source-list > li { margin-bottom: 16px; }
.link-note { display: block; margin-top: 2px; color: var(--text-muted); font-size: .8rem; }
.source-list details { margin-top: 7px; color: var(--text-muted); font-size: .85rem; }
.source-list summary { cursor: pointer; color: var(--link); }
.source-list blockquote { margin: 8px 0; padding-left: 12px; border-left: 3px solid var(--border); }

@media (max-width: 1020px) {
  .category-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .district-form { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .profile-layout { grid-template-columns: 1fr; }
}

@media (max-width: 760px) {
  .site-header, main, .site-footer { width: min(100% - 32px, var(--content)); }
  .masthead { align-items: flex-start; flex-direction: column; gap: 10px; padding: 15px 0; }
  .masthead div { width: 100%; justify-content: space-between; gap: 10px; }
  .hero { padding: 36px 0 24px; }
  h1 { font-size: clamp(2.25rem, 11vw, 2.75rem); }
  .hero-actions .button { width: 100%; }
  .trust-grid { grid-template-columns: 1fr; }
  main { padding-top: 30px; }
  .section-heading, .result-heading { align-items: flex-start; flex-direction: column; gap: 10px; }
  .section-heading > a, .inventory { text-align: left; }
  .finder, .search-panel, .empty-state { padding: 18px; }
  .search-panel { padding-inline: 0; }
  .district-form, .search-panel { grid-template-columns: 1fr; }
  .district-form .button { width: 100%; }
  .category-grid { grid-template-columns: 1fr 1fr; }
  .category-card { min-height: 74px; }
  .search-panel .field-help { grid-column: 1; }
  .race-group > summary { min-height: 76px; padding: 14px 16px; }
  .race-count { display: none; }
  .race-content { padding: 0 14px 14px; }
  .race-note { margin: 0 -14px 14px; padding: 12px 14px; }
  .candidate-grid { grid-template-columns: 1fr; }
  .profile-section dl { grid-template-columns: 1fr; }
  .profile-section dd { margin-bottom: 8px; }
}

@media (max-width: 430px) {
  .category-grid { grid-template-columns: 1fr; }
  .search-row { grid-template-columns: 1fr; }
  .search-row .button { width: 100%; }
  .race-names { white-space: normal; }
}

@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }

@media (forced-colors: active) {
  .button, .panel, .race-group, .candidate-summary, .category-card, .comparison-scroll, .badge, .conflict-notice, .legal-callout { forced-color-adjust: auto; }
  .button-primary { border: 2px solid ButtonText; }
  .party-label { color: CanvasText; }
}

@media print {
  :root { color-scheme: light; --canvas: #fff; --surface: #fff; --surface-soft: #fff; --text: #000; --text-muted: #333; --border: #777; --link: #000; }
  .masthead div, .hero-actions, .finder, .search-panel, .category-grid, .button { display: none !important; }
  .race-group > summary { break-after: avoid; }
  .race-group:not([open]) > *:not(summary) { display: block; }
  .comparison-scroll { overflow: visible; }
  .comparison-table { min-width: 0; font-size: .8rem; }
  .comparison-table th, .comparison-table td { min-width: 0; padding: 7px; overflow-wrap: anywhere; }
  .party-label { color: #000; }
}
