:root {
  color-scheme: light;
  --ink: #123f50;
  --ink-soft: #506b76;
  --paper: rgba(255, 255, 255, 0.86);
  --paper-solid: #ffffff;
  --gold: #efbf04;
  --dem: #2b6cb0;
  --rep: #d73027;
  --neutral: #71808a;
  --border: rgba(18, 63, 80, 0.16);
  --shadow: 0 18px 55px rgba(11, 49, 64, 0.18);
}

* {
  box-sizing: border-box;
}

/* Suppress browser-generated gray tap flashes on touch devices.
   Keyboard focus remains handled by the existing :focus-visible rules. */
html {
  -webkit-tap-highlight-color: transparent;
}

button,
a,
[role="button"],
.map-state {
  -webkit-tap-highlight-color: transparent;
}

button,
a {
  touch-action: manipulation;
}

html,
body {
  width: 100%;
  height: 100%;
  min-height: 0;
  overflow: hidden;
}

body {
  margin: 0;
  padding: 24px 0 48px;
  color: var(--ink);
  background: transparent;
  font-family: Arial, Helvetica, sans-serif;
}

button,
a {
  font: inherit;
}

.breathing-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background:
    radial-gradient(circle at 20% 10%, rgba(255, 255, 255, 0.52), transparent 34%),
    radial-gradient(circle at 80% 70%, rgba(21, 83, 105, 0.16), transparent 42%);
  animation: breathe-move 9s ease-in-out infinite;
}

.map-header {
  width: min(1100px, 100%);
  margin: 0 auto 16px;
  text-align: center;
}

.preview-badge {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 6px 12px;
  border: 1px solid rgba(21, 83, 105, 0.22);
  border-radius: 999px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.74);
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.map-title {
  margin: 14px 0 8px;
  color: var(--ink);
  font-size: clamp(1.45rem, 3vw, 2.25rem);
  font-weight: 800;
  letter-spacing: 0.045em;
  line-height: 1.2;
}

.star {
  margin: 0 clamp(5px, 1.2vw, 12px);
  color: var(--gold);
  font-size: 0.8em;
}

.map-intro {
  max-width: 760px;
  margin: 0 auto;
  color: var(--ink-soft);
  font-size: clamp(0.9rem, 1.5vw, 1rem);
  line-height: 1.65;
}

.tabs {
  display: flex;
  justify-content: center;
  gap: 8px;
  width: min(1100px, 100%);
  margin: 18px auto 12px;
}

.tab-btn {
  min-width: 100px;
  padding: 10px 18px;
  cursor: pointer;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.56);
  border: 1px solid rgba(21, 83, 105, 0.13);
  border-radius: 999px;
  font-weight: 800;
  transition: transform 0.18s ease, background 0.18s ease, color 0.18s ease, box-shadow 0.18s ease;
}

.tab-btn:hover,
.tab-btn:focus-visible {
  transform: translateY(-1px);
  background: rgba(255, 255, 255, 0.9);
  outline: none;
  box-shadow: 0 8px 24px rgba(21, 83, 105, 0.12);
}

.tab-btn.active {
  color: #fff;
  background: var(--ink);
  border-color: var(--ink);
}

.map-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  margin: 0 auto;
}

.map-notice {
  width: min(760px, 100%);
  margin: 0 auto 8px;
  padding: 9px 14px;
  color: #5d4a00;
  background: rgba(255, 248, 215, 0.84);
  border: 1px solid rgba(166, 128, 0, 0.24);
  border-radius: 8px;
  font-size: 0.82rem;
  font-weight: 700;
  text-align: center;
}

#svg-holder {
  width: 100%;
  height: clamp(560px, 76vw, 900px);
  min-height: 0;
}

#svg-holder > svg {
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
}

/* Keep the current national map visible while a new race mode is prepared.
   Disabling pointer input prevents clicks from using stale state data during
   the very short Senate/House/Governor switch. */
#svg-holder.map-switching > svg {
  pointer-events: none;
}

.state-label {
  pointer-events: none;
  fill: #123f50;
  stroke: none;
  paint-order: normal;
  font-family: Arial, Helvetica, sans-serif;
  font-size: 25px;
  font-weight: 800;
  letter-spacing: 0.01em;
  text-anchor: middle;
  dominant-baseline: middle;
}

.map-state {
  cursor: pointer;
  outline: none;
}

.map-state path {
  transition: opacity 0.2s ease, filter 0.2s ease, stroke 0.2s ease;
}

.map-state:hover path,
.map-state:focus path {
  opacity: 0.82;
  filter: brightness(1.05);
}

.map-state.state-in-development path {
  opacity: 0.58;
  filter: saturate(0.35);
}

.map-state.state-in-development:hover path,
.map-state.state-in-development:focus path {
  opacity: 0.76;
}

.map-state.state-no-election {
  cursor: default;
}

.map-state.state-no-election path {
  opacity: 0.3;
  filter: grayscale(1) saturate(0);
}

.map-state.state-no-election:hover path,
.map-state.state-no-election:focus path {
  opacity: 0.3;
  filter: grayscale(1) saturate(0);
}

.state-selected {
  stroke: var(--gold) !important;
  stroke-width: 6px !important;
  vector-effect: non-scaling-stroke;
  filter: drop-shadow(0 0 5px rgba(239, 191, 4, 0.58));
}

.map-loading {
  display: grid;
  min-height: 180px;
  place-items: center;
  color: var(--ink-soft);
  font-weight: 700;
}

.map-error {
  display: grid;
  gap: 8px;
  max-width: 760px;
  margin: 40px auto;
  padding: 24px;
  color: #7a2028;
  background: #fff2f3;
  border: 1px solid #efc6ca;
  border-radius: 12px;
  line-height: 1.55;
}

.sheet {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 999;
  width: min(680px, calc(100% - 24px));
  max-height: min(78vh, 720px);
  margin: 0 auto;
  overflow: auto;
  color: var(--ink);
  background: rgba(247, 251, 252, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.82);
  border-radius: 22px 22px 0 0;
  box-shadow: 0 -16px 55px rgba(7, 38, 51, 0.24);
  backdrop-filter: blur(18px);
  opacity: 0;
  transform: translateY(105%);
  transition: transform 0.36s ease, opacity 0.26s ease;
}

.sheet.open {
  opacity: 1;
  transform: translateY(0);
}

.sheet-handle {
  width: 54px;
  height: 5px;
  margin: 8px auto 4px;
  background: rgba(21, 83, 105, 0.23);
  border-radius: 999px;
}

.sheet-close {
  position: absolute;
  top: 12px;
  right: 14px;
  display: grid;
  width: 34px;
  height: 34px;
  padding: 0;
  cursor: pointer;
  place-items: center;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid var(--border);
  border-radius: 50%;
  font-size: 1.5rem;
  line-height: 1;
}

.sheet-close:hover,
.sheet-close:focus-visible {
  background: #fff;
  outline: none;
}

.sheet-content {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  padding: 6px clamp(18px, 4vw, 32px) 30px;
}

.sheet-kicker {
  margin: 8px 0 5px;
  color: var(--neutral);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-align: center;
  text-transform: uppercase;
}

#sheet-state {
  margin: 0;
  padding: 0 36px;
  color: var(--ink);
  font-size: clamp(1.35rem, 4vw, 1.8rem);
  line-height: 1.25;
  text-align: center;
}

.sheet-status {
  max-width: 540px;
  margin: 8px auto 16px;
  color: var(--ink-soft);
  line-height: 1.55;
  text-align: center;
}

.national-race-bar {
  display: grid;
  grid-template-columns: 68px minmax(0, 1fr) 68px;
  gap: 16px;
  align-items: center;
  width: min(900px, calc(100% - 24px));
  margin: 10px auto 8px;
  padding: 12px 16px;
  background: rgba(255, 255, 255, 0.58);
  border: 1px solid rgba(18, 63, 80, 0.12);
  border-radius: 14px;
}

.national-race-logo {
  display: block;
  width: 68px;
  height: 68px;
}

.national-race-main {
  min-width: 0;
}

.national-race-values {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 12px;
  align-items: end;
  margin-bottom: 7px;
  color: var(--ink);
  font-size: 0.8rem;
  font-weight: 800;
  letter-spacing: 0.04em;
}

.national-race-values span:last-child {
  text-align: right;
}

.national-race-values strong {
  color: var(--neutral);
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-align: center;
  text-transform: uppercase;
}

.national-race-track {
  display: flex;
  width: 100%;
  height: 16px;
  overflow: hidden;
  background: #e2e8eb;
  border: 1px solid rgba(18, 63, 80, 0.13);
  border-radius: 999px;
}

.national-race-fill {
  flex: 0 0 0%;
  width: 0%;
  transition: flex-basis 0.8s ease, width 0.8s ease;
}

.national-race-dem {
  background: var(--dem);
}

.national-race-rep {
  order: 3;
  background: var(--rep);
}

.national-race-unreported {
  flex: 1 1 auto;
  min-width: 0;
  background: repeating-linear-gradient(
    135deg,
    rgba(255, 255, 255, 0.55) 0 7px,
    rgba(201, 211, 216, 0.55) 7px 14px
  );
}

.national-race-caption {
  margin: 7px 0 0;
  color: var(--neutral);
  font-size: 0.76rem;
  font-weight: 700;
  text-align: center;
}

.candidate-list {
  display: grid;
  grid-template-columns: 1fr;
  gap: 9px;
}

.candidate-list[hidden] {
  display: none;
}

.statewide-candidate-list {
  grid-template-columns: 1fr;
}

.candidate {
  display: grid;
  grid-template-columns: 52px minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  width: 100%;
  min-width: 0;
  padding: 10px 13px;
  background: rgba(255, 255, 255, 0.76);
  border: 1px solid rgba(21, 83, 105, 0.11);
  border-left-width: 4px;
  border-radius: 13px;
  box-shadow: 0 8px 24px rgba(15, 54, 69, 0.07);
}

.candidate.dem {
  border-left-color: var(--dem);
}

.candidate.rep {
  border-left-color: var(--rep);
}

.candidate.other {
  border-left-color: var(--neutral);
}

.candidate-photo,
.candidate-photo-placeholder {
  display: grid;
  width: 48px;
  height: 48px;
  place-items: center;
  border-radius: 50%;
  object-fit: cover;
}

.candidate-photo {
  background: #edf2f4;
  border: 2px solid #fff;
}

.candidate-photo-placeholder {
  color: #fff;
  background: linear-gradient(145deg, #70838c, #324f5b);
  border: 2px solid rgba(255, 255, 255, 0.9);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.08);
  font-size: 0.95rem;
  font-weight: 800;
}

.candidate.dem .candidate-photo-placeholder {
  background: linear-gradient(145deg, #4c83bd, #214f82);
}

.candidate.rep .candidate-photo-placeholder {
  background: linear-gradient(145deg, #e05b63, #9d2730);
}

.candidate-details {
  min-width: 0;
}

.candidate .name,
.candidate .party,
.candidate-stats {
  margin: 0;
}

.candidate .name {
  overflow-wrap: anywhere;
  color: var(--ink);
  font-size: 0.91rem;
  font-weight: 800;
  line-height: 1.25;
}

.candidate .party {
  margin-top: 2px;
  overflow-wrap: anywhere;
  color: var(--ink-soft);
  font-size: 0.74rem;
  font-weight: 700;
  line-height: 1.3;
}

.candidate-stats {
  margin-top: 5px;
  color: var(--neutral);
  font-size: 0.77rem;
  line-height: 1.3;
}

.vote-bar-wrapper {
  width: 100%;
  height: 7px;
  margin-top: 7px;
  overflow: hidden;
  background: rgba(0, 0, 0, 0.09);
  border-radius: 999px;
}

.vote-bar {
  width: 0;
  height: 100%;
  border-radius: inherit;
  transition: width 0.8s ease;
}

.candidate.dem .vote-bar {
  background: var(--dem);
}

.candidate.rep .vote-bar {
  background: var(--rep);
}

.candidate.other .vote-bar {
  background: var(--neutral);
}

.candidate-other-group {
  align-items: start;
}

.other-candidate-list {
  display: grid;
  gap: 0;
  margin-top: 7px;
  border-top: 1px solid rgba(21, 83, 105, 0.1);
}

.other-candidate-entry {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px 14px;
  align-items: baseline;
  padding: 7px 0;
  border-bottom: 1px solid rgba(21, 83, 105, 0.08);
}

.other-candidate-entry:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.other-candidate-name,
.other-candidate-party,
.other-candidate-stats {
  margin: 0;
}

.other-candidate-name {
  min-width: 0;
  overflow-wrap: anywhere;
  color: var(--ink);
  font-size: 0.82rem;
  font-weight: 800;
}

.other-candidate-party {
  color: var(--ink-soft);
  font-size: 0.7rem;
  font-weight: 700;
  text-align: right;
}

.other-candidate-stats {
  grid-column: 1 / -1;
  color: var(--neutral);
  font-size: 0.72rem;
}

.last-updated {
  margin: 4px 0 0;
  color: var(--neutral);
  font-size: 0.75rem;
  text-align: center;
}

.state-map-slot {
  width: 100%;
}

/* The bottom sheet is the only scrolling container. State maps should keep
   their native aspect ratio and expand naturally inside it. */
.state-map-holder {
  width: 100%;
  max-height: none;
  margin-top: 2px;
  overflow: visible;
  background: rgba(255, 255, 255, 0.58);
  border: 1px solid var(--border);
  border-radius: 14px;
}

.state-map-holder svg {
  display: block;
  width: 100%;
  height: auto;
  min-height: 0;
  overflow: visible;
}

/* Portrait SVGs, such as Maine, stay contained without creating a second
   scrollbar inside the bottom sheet. */
.state-map-holder.state-map-holder--portrait {
  display: grid;
  width: 100%;
  height: min(46vh, 430px);
  max-height: none;
  padding: 8px;
  overflow: hidden;
  place-items: center;
}

.state-map-holder.state-map-holder--portrait svg {
  width: 100%;
  height: 100%;
  min-height: 0;
}

.state-map-holder [data-district-id] {
  cursor: crosshair;
  transition: fill 0.35s ease, opacity 0.18s ease;
}

.state-map-holder [data-district-id].district-hover {
  opacity: 0.76;
}

.development-message {
  display: grid;
  gap: 8px;
  padding: 30px 22px;
  place-items: center;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.65);
  border: 1px dashed rgba(21, 83, 105, 0.28);
  border-radius: 14px;
  text-align: center;
}

.development-message h3,
.development-message p {
  margin: 0;
}

.development-message p {
  max-width: 500px;
  color: var(--ink-soft);
  line-height: 1.55;
}

.development-icon {
  color: var(--gold);
  font-size: 2rem;
}

.error-state {
  color: #7a2028;
  border-color: rgba(122, 32, 40, 0.3);
}

#district-tooltip {
  position: fixed;
  z-index: 9999;
  max-width: 230px;
  padding: 9px 11px;
  pointer-events: none;
  color: #fff;
  background: rgba(8, 38, 49, 0.94);
  border-radius: 7px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
  font-size: 0.76rem;
  line-height: 1.45;
  opacity: 0;
  transition: opacity 0.14s ease;
}

#district-tooltip strong {
  font-size: 0.82rem;
}

@keyframes breathe-move {
  0%, 100% { opacity: 0.42; transform: scale(1) translate(0, 0); }
  50% { opacity: 0.72; transform: scale(1.025) translate(-2px, 2px); }
}

@media (max-width: 760px) {
  body {
    padding: 18px 0 34px;
  }

  .star {
    display: none;
  }

  .tabs {
    gap: 5px;
  }

  .tab-btn {
    min-width: 0;
    flex: 1;
    padding: 9px 10px;
  }

  #svg-holder {
    height: clamp(350px, 78vw, 500px);
    min-height: 0;
  }

  .sheet {
    width: 100%;
    max-height: 82vh;
    border-radius: 18px 18px 0 0;
  }
}

@media (max-width: 430px) {
  .candidate {
    grid-template-columns: 44px minmax(0, 1fr);
    gap: 10px;
    padding: 9px 11px;
  }

  .candidate-photo,
  .candidate-photo-placeholder {
    width: 42px;
    height: 42px;
  }

  .other-candidate-entry {
    grid-template-columns: 1fr;
    gap: 2px;
  }

  .other-candidate-party {
    text-align: left;
  }

  #svg-holder {
    height: 320px;
    min-height: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

@media (max-width: 520px) {
  .national-race-bar {
    grid-template-columns: 46px minmax(0, 1fr) 46px;
    gap: 9px;
    width: 100%;
    padding: 9px 8px;
  }

  .national-race-logo {
    width: 46px;
    height: 46px;
  }

  .national-race-values {
    gap: 6px;
    font-size: 0.68rem;
  }

  .national-race-values strong {
    font-size: 0.62rem;
  }

  .national-race-caption {
    font-size: 0.68rem;
  }

  .state-label {
    font-size: 23px;
  }
}

@media (max-width: 600px) {
  .state-map-holder--portrait {
    height: min(42vh, 350px);
  }
}


/*
|--------------------------------------------------------------------------
| AFDES MODAL RELIABILITY V2
|--------------------------------------------------------------------------
|
| The closed sheet must never block map clicks.
| The header and close button remain fixed while the content scrolls.
|
*/

.sheet {
  max-height: min(
    calc(100dvh - 8px),
    760px
  );
  overflow: hidden;
  pointer-events: none;
  visibility: hidden;
  transition:
    transform 0.36s ease,
    opacity 0.26s ease,
    visibility 0s linear 0.36s;
}

.sheet.open {
  pointer-events: auto;
  visibility: visible;
  transition-delay: 0s;
}

.sheet-content {
  max-height: min(
    calc(100dvh - 26px),
    742px
  );
  padding-bottom: calc(
    30px + env(safe-area-inset-bottom)
  );
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
  scrollbar-width: thin;
  touch-action: pan-y;
  -webkit-overflow-scrolling: touch;
}

.sheet-content::-webkit-scrollbar {
  width: 8px;
}

.sheet-content::-webkit-scrollbar-thumb {
  background: rgba(18, 63, 80, 0.3);
  border-radius: 999px;
}

.candidate-other-group .candidate-details {
  width: 100%;
  min-width: 0;
}

@media (max-width: 760px) {
  .sheet {
    max-height: calc(100dvh - 8px);
  }

  .sheet-content {
    max-height: calc(100dvh - 26px);
  }
}


/*
|--------------------------------------------------------------------------
| AFDES ELECTION RESULT MAP COLORS
|--------------------------------------------------------------------------
|
| Reporting:
|   Light party color for the candidate currently leading.
|
| Called or certified:
|   Solid party color for the projected or certified winner.
|
| The House map is not assigned statewide result colors because
| congressional districts within one state may split by party.
|
*/

:root {
  --dem-leading: #b9d9f4;
  --rep-leading: #f3bbb8;
  --other-leading: #d8e0e5;
  --other-called: #687983;
}

.map-state path {
  transition:
    fill 0.45s ease,
    opacity 0.2s ease,
    filter 0.2s ease,
    stroke 0.2s ease;
}


/*
|--------------------------------------------------------------------------
| Reporting Leaders
|--------------------------------------------------------------------------
*/

.map-state.state-leading-dem path {
  fill: var(--dem-leading) !important;
  opacity: 1;
}

.map-state.state-leading-rep path {
  fill: var(--rep-leading) !important;
  opacity: 1;
}

.map-state.state-leading-other path {
  fill: var(--other-leading) !important;
  opacity: 1;
}


/*
|--------------------------------------------------------------------------
| Called and Certified Winners
|--------------------------------------------------------------------------
*/

.map-state.state-called-dem path {
  fill: var(--dem) !important;
  opacity: 1;
}

.map-state.state-called-rep path {
  fill: var(--rep) !important;
  opacity: 1;
}

.map-state.state-called-other path {
  fill: var(--other-called) !important;
  opacity: 1;
}


/*
|--------------------------------------------------------------------------
| Hover and Focus
|--------------------------------------------------------------------------
*/

.map-state.state-leading-dem:hover path,
.map-state.state-leading-dem:focus path,
.map-state.state-leading-rep:hover path,
.map-state.state-leading-rep:focus path,
.map-state.state-leading-other:hover path,
.map-state.state-leading-other:focus path,
.map-state.state-called-dem:hover path,
.map-state.state-called-dem:focus path,
.map-state.state-called-rep:hover path,
.map-state.state-called-rep:focus path,
.map-state.state-called-other:hover path,
.map-state.state-called-other:focus path {
  opacity: 0.88;
  filter: brightness(1.04);
}


/*
|--------------------------------------------------------------------------
| State Labels
|--------------------------------------------------------------------------
*/

.state-label.state-label-leading {
  fill: var(--ink);
}

.state-label.state-label-called {
  fill: #ffffff;
}


/*
|--------------------------------------------------------------------------
| Selected Result State
|--------------------------------------------------------------------------
|
| Keep the existing gold selection outline above the party color.
|
*/

.map-state path.state-selected {
  stroke: var(--gold) !important;
  stroke-width: 6px !important;
  vector-effect: non-scaling-stroke;
}

/* Keep state names readable during every election stage. */
.state-label,
.state-label.state-label-leading,
.state-label.state-label-called {
  fill: var(--ink) !important;
}

/* House district result colors. Compound SVG pieces share data-district-id,
   so islands and detached pieces behave as one congressional district. */
.state-map-holder [data-district-id].district-leading-dem { fill: var(--dem-leading) !important; }
.state-map-holder [data-district-id].district-leading-rep { fill: var(--rep-leading) !important; }
.state-map-holder [data-district-id].district-leading-other { fill: var(--other-leading) !important; }
.state-map-holder [data-district-id].district-called-dem { fill: var(--dem) !important; }
.state-map-holder [data-district-id].district-called-rep { fill: var(--rep) !important; }
.state-map-holder [data-district-id].district-called-other { fill: var(--other-called) !important; }
