:root {
  --bg: #f5f5f4;
  --surface: #ffffff;
  --surface-subtle: #f1f1f0;
  --text: #18181b;
  --muted: #6f7177;
  --border: #d7d7dc;
  --accent: #2f3437;
  --accent-soft: #f0f1f2;
  --accent-border: #9ca3af;
  --party-color: #52525b;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
  word-break: keep-all;
  overflow-x: hidden;
}

a {
  color: inherit;
}

.site-header,
main {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
}

.site-header {
  display: grid;
  grid-template-columns: minmax(320px, 440px) 1fr;
  gap: 22px;
  align-items: end;
  padding: 22px 0 16px;
}

.date,
.muted {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

h1,
h2,
h3,
p {
  margin-top: 0;
  overflow-wrap: break-word;
  text-wrap: pretty;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(28px, 4vw, 40px);
  line-height: 1.15;
}

h2 {
  margin-bottom: 8px;
  font-size: 21px;
}

h3 {
  margin-bottom: 8px;
}

.search {
  display: grid;
  gap: 8px;
}

.search label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.search-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

input,
button,
.button {
  min-height: 42px;
  border-radius: 8px;
  font: inherit;
}

input {
  min-width: 0;
  width: 100%;
  border: 1px solid var(--border);
  padding: 0 13px;
  background: white;
}

button,
.button {
  border: 1px solid var(--border);
  background: var(--surface);
  padding: 0 14px;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  line-height: 1.2;
  text-align: center;
  min-width: 0;
  white-space: normal;
}

button:disabled {
  cursor: wait;
  opacity: 0.65;
}

.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: white;
}

.small-button {
  min-height: 32px;
  padding: 0 10px;
  font-size: 13px;
}

main {
  display: grid;
  gap: 18px;
  padding-bottom: 40px;
}

.seo-shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 24px 0 40px;
}

.seo-kicker {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

.seo-lead {
  max-width: 860px;
  color: #34383c;
  font-size: 17px;
  line-height: 1.65;
}

.seo-summary {
  margin-top: 16px;
}

.seo-metrics {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin: 0;
}

.seo-metrics div,
.seo-list li {
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fbfbfa;
  padding: 12px;
}

.seo-metrics dt,
.seo-list span {
  color: var(--muted);
  font-size: 13px;
}

.seo-metrics dd {
  margin: 6px 0 0;
  font-size: 20px;
  font-weight: 800;
}

.seo-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.seo-list.compact {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.seo-list li {
  display: grid;
  gap: 4px;
}

.seo-official {
  margin: 16px 0 0;
  color: var(--muted);
}

.seo-official a {
  color: var(--accent);
  font-weight: 800;
}

section,
.official-grid {
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  padding: 18px;
}

.official-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 16px;
  align-items: center;
}

.button-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(150px, 1fr));
  gap: 8px;
  min-width: min(520px, 100%);
}

.official-grid > *,
.section-title > *,
.results-layout > *,
.race-heading > *,
.candidate-topline > * {
  min-width: 0;
}

.section-title {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
}

.status-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  justify-content: flex-end;
  color: var(--muted);
  font-size: 13px;
  min-width: 0;
}

.status-pill {
  display: inline-flex;
  min-height: 30px;
  align-items: center;
  border-radius: 999px;
  padding: 0 10px;
  font-weight: 800;
  max-width: 100%;
  line-height: 1.25;
  text-align: center;
}

.status-pill.ok {
  border: 1px solid #16a34a;
  background: #dcfce7;
  color: #14532d;
  box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.16);
}

.status-pill.warning {
  background: #f3f1ea;
  color: #5f574b;
}

.status-pill.danger {
  background: #f3eeee;
  color: #5f4848;
}

.time-chip {
  display: inline-flex;
  min-height: 30px;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: #fbfbfa;
  padding: 0 10px;
  line-height: 1.25;
}

.time-chip.checked {
  color: var(--accent);
  font-weight: 800;
}

.broadcast-tabs {
  display: grid;
  gap: 12px;
  min-width: 0;
}

.broadcast-disclosure {
  width: 100%;
  display: flex;
  min-height: 54px;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-color: var(--border);
  background: #fbfbfa;
  color: var(--text);
  text-align: left;
}

.broadcast-disclosure span:first-child {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.broadcast-disclosure strong,
.broadcast-disclosure small {
  display: block;
}

.broadcast-disclosure small {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  line-height: 1.35;
}

.broadcast-toggle-indicator {
  flex: 0 0 auto;
  width: 10px;
  height: 10px;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(45deg);
  transition: transform 160ms ease;
}

.broadcast-tabs.open .broadcast-toggle-indicator {
  transform: rotate(225deg);
}

.broadcast-panel {
  display: grid;
  gap: 12px;
  width: min(100%, 680px);
  margin-inline: auto;
  min-width: 0;
  justify-self: center;
  justify-items: center;
}

.broadcast-tablist {
  display: flex;
  gap: 8px;
  justify-content: center;
  width: 100%;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  padding-bottom: 3px;
  scrollbar-gutter: stable;
  min-width: 0;
}

.broadcast-tab {
  flex: 0 0 auto;
  min-height: 38px;
  border-color: var(--border);
  background: #fbfbfa;
  color: var(--text);
  font-size: 13px;
}

.broadcast-tab.selected {
  border-color: var(--accent);
  background: var(--accent);
  color: white;
}

.broadcast-card {
  width: 100%;
  min-width: 0;
  min-height: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fbfbfa;
  overflow: hidden;
  display: grid;
  grid-template-rows: auto 1fr;
}

.broadcast-frame {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #18181b;
}

.broadcast-frame iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
}

.broadcast-meta {
  display: grid;
  gap: 7px;
  padding: 12px;
}

.broadcast-meta h3 {
  margin-bottom: 0;
}

.text-link {
  color: #3f3f46;
  font-size: 13px;
  font-weight: 800;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
  overflow-wrap: break-word;
}

.national-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin: 10px 0 14px;
}

.metric {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fbfbfa;
  padding: 12px;
  min-width: 0;
}

.metric span,
.race-summary span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.metric strong,
.race-summary strong {
  display: block;
  margin-top: 4px;
  font-size: 20px;
  overflow-wrap: break-word;
}

.notice {
  grid-column: 1 / -1;
  margin: 0;
  border: 1px solid #ded8c5;
  border-radius: 8px;
  background: #f8f6ef;
  color: #5b5549;
  padding: 10px 12px;
  font-size: 14px;
}

.selection-bar {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
  margin: 2px 0 14px;
  min-width: 0;
}

.election-tabs {
  flex: 1 1 auto;
  display: flex;
  gap: 8px;
  margin: 0;
  padding-bottom: 3px;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scrollbar-gutter: stable;
  min-width: 0;
}

.election-tab {
  flex: 0 0 auto;
  display: inline-flex;
  gap: 8px;
  min-height: 38px;
  border-color: var(--border);
  background: #fbfbfa;
  color: var(--text);
  font-size: 13px;
}

.election-tab strong {
  display: inline-flex;
  min-width: 24px;
  height: 24px;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  background: var(--surface-subtle);
  padding: 0 7px;
  font-size: 12px;
}

.election-tab.selected {
  border-color: var(--accent);
  background: var(--accent);
  color: white;
}

.election-tab.selected strong {
  background: rgba(255, 255, 255, 0.18);
}

.detail-control {
  flex: 0 1 280px;
  display: grid;
  gap: 5px;
  min-width: min(280px, 100%);
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.detail-control select {
  width: 100%;
  min-height: 38px;
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: white;
  color: var(--text);
  padding: 0 10px;
  font: inherit;
  font-size: 13px;
}

.results-layout {
  display: grid;
  grid-template-columns: 300px 1fr;
  gap: 14px;
}

.region-list {
  display: grid;
  align-content: start;
  gap: 8px;
  max-height: min(640px, 70vh);
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fbfbfa;
  padding: 8px;
}

.region-item {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: white;
  min-height: 74px;
  padding: 12px 14px;
  text-align: center;
  display: grid;
  grid-template-rows: auto auto;
  align-content: center;
  align-items: center;
  justify-content: stretch;
  justify-items: center;
  gap: 6px;
  line-height: 1.25;
}

.region-item.selected {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.region-name {
  display: block;
  width: 100%;
  font-weight: 800;
  line-height: 1.3;
  overflow-wrap: break-word;
}

.region-meta {
  display: block;
  width: 100%;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
  overflow-wrap: break-word;
}

.race-panel {
  min-height: 260px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
  min-width: 0;
  background: #fbfbfa;
}

.race-heading {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
}

.race-heading h3 {
  margin-bottom: 0;
  font-size: 24px;
  overflow-wrap: break-word;
}

.panel-heading {
  margin-bottom: 14px;
}

.eyebrow {
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.count-rate {
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  padding: 7px 10px;
  font-weight: 900;
  white-space: nowrap;
}

.race-summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin: 14px 0;
}

.race-group {
  display: grid;
  gap: 12px;
}

.race-card {
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: white;
  padding: 14px;
}

.race-card-heading {
  margin-bottom: 12px;
}

.race-card-heading h3 {
  font-size: 19px;
  line-height: 1.25;
}

.race-summary div {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  background: #fbfbfa;
  min-width: 0;
}

.candidate-list {
  display: grid;
  gap: 10px;
}

.candidate-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  background: white;
  min-width: 0;
}

.candidate-topline {
  display: grid;
  grid-template-columns: 56px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
}

.candidate-portrait {
  position: relative;
  display: inline-flex;
  width: 52px;
  height: 62px;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 900;
}

.candidate-portrait img {
  position: absolute;
  inset: 0;
  z-index: 1;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.portrait-fallback {
  font-size: 20px;
}

.rank-badge {
  position: absolute;
  z-index: 2;
  top: 4px;
  left: 4px;
  display: inline-flex;
  width: 22px;
  height: 22px;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(255, 255, 255, 0.72);
  border-radius: 999px;
  background: rgba(24, 24, 27, 0.78);
  color: white;
  font-size: 12px;
  font-weight: 900;
}

.candidate-name {
  min-width: 0;
}

.candidate-name strong,
.candidate-name span {
  display: block;
  overflow-wrap: break-word;
}

.candidate-name span {
  margin-top: 2px;
  color: var(--muted);
  font-size: 13px;
}

.candidate-rate {
  font-weight: 900;
  white-space: nowrap;
}

.candidate-votes {
  margin-top: 6px;
  color: var(--muted);
  font-size: 13px;
  text-align: right;
}

.bar {
  height: 8px;
  margin-top: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--surface-subtle);
}

.bar span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--party-color);
}

@media (max-width: 860px) {
  .site-header {
    grid-template-columns: 1fr;
    gap: 14px;
    align-items: stretch;
  }

  .search {
    order: -1;
  }

  .official-grid,
  .results-layout {
    grid-template-columns: 1fr;
  }

  .button-row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    min-width: 0;
  }

  .selection-bar {
    align-items: stretch;
    flex-direction: column;
  }

  .detail-control {
    flex-basis: auto;
    width: 100%;
  }

  .national-grid,
  .seo-metrics,
  .race-summary {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .seo-list,
  .seo-list.compact {
    grid-template-columns: 1fr;
  }

  .region-list {
    max-height: min(380px, 45vh);
  }
}

@media (max-width: 430px) {
  .site-header,
  main,
  .seo-shell {
    width: min(100% - 20px, 1180px);
  }

  .site-header {
    padding-top: 12px;
  }

  .search-row {
    grid-template-columns: 1fr 72px;
  }

  h1 {
    font-size: 28px;
  }

  section,
  .official-grid {
    padding: 13px;
  }

  .button-row,
  .national-grid,
  .seo-metrics,
  .race-summary {
    grid-template-columns: 1fr;
  }

  .section-title,
  .status-row,
  .race-heading {
    align-items: stretch;
    flex-direction: column;
  }

  .status-row {
    justify-content: flex-start;
  }

  .status-pill,
  .time-chip,
  .small-button {
    width: 100%;
    justify-content: center;
  }

  .candidate-topline {
    grid-template-columns: 56px minmax(0, 1fr);
  }

  .candidate-rate {
    grid-column: 2;
  }

  .candidate-votes {
    text-align: left;
  }
}
