:root {
  --bg: #0b0b0b;
  --fg: #f5f5f5;
  --muted: #a5a5a5;
  --accent: #e1e6ea;
  --card: #141414;
  --border: #2a2a2a
}

/* Shift Vectors - region color variables and legend tweaks */
:root {
  --region-blue: #3b82f6;
  --region-green: #10b981;
  --region-amber: #f59e0b;
  --region-purple: #8b5cf6;
}

.shift-vectors .legend-block { display: block; }
.shift-vectors .legend-section { margin-bottom: 6px; }
.shift-vectors .badges.small .badge { font-size: 0.86em; padding: 6px 8px; }
.shift-vectors .legend-note { font-size: 0.9em; color: rgba(255,255,255,0.72); margin-top:6px; }

* {
  box-sizing: border-box
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.5 system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, "Helvetica Neue", Arial
}

a {
  color: var(--accent);
  text-decoration: none
}

a:hover {
  text-decoration: underline
}

.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 16px
}

.header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px
}

.header h1 {
  font-size: 1.25rem;
  margin: 0
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px
}

.grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px
}

@media (min-width: 900px) {
  .grid {
    grid-template-columns: 2fr 1fr
  }
}

.small-links {
  display: flex;
  flex-wrap: wrap;
  gap: 8px
}

.dataset-switch {
  margin-bottom: 16px;
}

.dataset-switch select {
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #1b1b1b;
  color: var(--fg);
}

.dataset-sections {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.dataset-section {
  display: none;
}

.dataset-section.is-active {
  display: block;
}

/* Make small-links buttons a consistent size and center their content */
.small-links .btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 56px;
  padding: 8px 10px;
  background: #1e1e1e;
  border: 1px solid var(--border);
  border-radius: 10px;
  text-align: center
}

/* NATIONAL quick link should be wider than state links */
#top-links .btn {
  min-width: 120px;
  padding: 10px 16px
}

.btn {
  display: inline-block;
  padding: 10px 14px;
  background: #1e1e1e;
  border: 1px solid var(--border);
  border-radius: 10px
}

.btn,
.btn:visited,
.btn:active {
  color: #fff
}

.btn:hover {
  color: #fff;
  filter: brightness(1.15)
}

.btn:focus {
  outline: 2px solid var(--accent);
  outline-offset: 2px
}

footer {
  margin-top: 24px;
  color: var(--muted);
  font-size: .9rem
}

img.plot {
  width: 100%;
  max-width: 900px;
  display: block;
  margin: 0 auto;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #000
}

.table-wrap {
  overflow: auto;
  border-radius: 10px;
  border: 1px solid var(--border);
  position: relative;
  max-height: 80vh
}

/* For pv-tools pages (like laplace), allow table to expand fully and let the page scroll instead */
.pv-tools .table-wrap {
  max-height: none;
  overflow: visible;
}
/* Mobile: avoid tables expanding the page horizontally. Make table scroll inside the card. */
@media (max-width: 640px) {
  /* Ensure the outer container can scroll horizontally without breaking the viewport */
  .pv-tools .table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* Make the table layout more compact on small screens */
  .pv-tools .table-wrap table {
    min-width: 600px; /* allow internal scrolling while keeping readable columns */
    font-size: 14px;
  }

  /* Reduce control spacing and font sizes in pv-tools for mobile */
  .pv-tools .controls .field {
    padding: 6px 0;
  }
  .pv-tools .controls label { font-size: 0.92rem; }

  /* Make table cells wrap where sensible and keep nowrap cells from forcing width */
  .pv-tools .table-wrap table td,
  .pv-tools .table-wrap table th {
    white-space: nowrap;
    padding: 6px 8px;
  }

  /* Allow the rank and abbr columns to stay visible but keep them compact */
  .pv-tools .table-wrap table td.rank { width: 36px; text-align: center; }

  /* Actions row: wrap buttons to avoid overflow */
  .pv-tools .actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
  }

  /* Ensure status text can break to next line */
  .pv-tools .actions .summary { flex: 1 1 100%; min-width: 0; }
}

table {
  width: 100%;
  border-collapse: collapse;
  background: #111;
  border-left: 1px solid var(--border);
  border-right: 1px solid var(--border)
}

th,
td {
  padding: 10px 12px;
  border-bottom: 1px solid #1f1f1f;
  white-space: nowrap;
  text-align: center;
  border-right: 1px solid var(--border)
}

th {
  position: sticky;
  top: 0;
  background: #161616;
  z-index: 10
}

tbody tr:hover {
  background: #151515
}

/* Remove the right border from the last column for a cleaner edge */
thead th:last-child,
tbody td:last-child {
  border-right: none
}

/* Sticky first column (year) */
table th:first-child,
table td:first-child {
  position: sticky;
  left: 0;
  z-index: 5;
  background: #161616
}

table td:first-child {
  background: #111
}

table tbody tr:hover td:first-child {
  background: #151515
}

/* Higher z-index for first header cell to appear above sticky column */
table th:first-child {
  z-index: 11
}

/* Sticky second column (abbr) for presidential_margins table - seamless with first column */
.presidential-margins-table th:nth-child(2),
.presidential-margins-table td:nth-child(2) {
  position: sticky;
  left: 76px;
  z-index: 5;
  background: #161616;
  border-left: none;
  margin-left: -1px
}

.presidential-margins-table td:nth-child(2) {
  background: #111;
  border-left: none;
  margin-left: -1px
}

.presidential-margins-table tbody tr:hover td:nth-child(2) {
  background: #151515
}

.presidential-margins-table th:nth-child(2) {
  z-index: 11
}

/* Remove borders between the two sticky columns to create seamless appearance */
.presidential-margins-table th:first-child,
.presidential-margins-table td:first-child {
  border-right: none !important
}

.presidential-margins-table tbody tr:hover td:first-child {
  border-right: none !important
}

/* Make the columns appear as one unit by overlapping slightly */
.presidential-margins-table th:nth-child(2),
.presidential-margins-table td:nth-child(2) {
  box-shadow: -1px 0 0 #161616
}

.presidential-margins-table td:nth-child(2) {
  box-shadow: -1px 0 0 #111
}

.presidential-margins-table tbody tr:hover td:nth-child(2) {
  box-shadow: -1px 0 0 #151515
}

.back {
  margin-bottom: 12px;
  display: inline-block
}

hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 16px 0
}

.legend {
  color: var(--muted);
  font-size: .95rem
}

.center {
  text-align: center
}

/* EV text: make large, readable on dark backgrounds with stroke and shadow */
#evText {
  position: relative;
  color: var(--fg);
  font-weight: 800;
  padding: 2px 8px;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.45);
  font-variant-numeric: tabular-nums
}

#evText {
  -webkit-text-stroke: 1px rgba(0, 0, 0, 0.8);
}

/* Floating EV labels are hidden by default; scripts explicitly show them when needed */
.ev-global-label {
  display: none;
}

/* State label styling: keep map label stroke and sizing across site builds */
.state-label {
  fill: #fff;
  /* white fill for readability */
  stroke: #000;
  /* black outline */
  stroke-width: 2px;
  paint-order: stroke fill;
  /* draw stroke behind fill */
  stroke-linejoin: round;
  font-family: 'Helvetica Neue', Arial, sans-serif;
  pointer-events: none;
}

.state-label tspan:first-child {
  font-weight: 800;
  font-size: 14px;
}

.state-label tspan:last-child {
  font-weight: 600;
  font-size: 12px;
}

/* When there's only one tspan (abbr only), apply the larger bold style */
.state-label tspan:only-child {
  font-weight: 800;
  font-size: 14px;
}

/* Persistent site header that stays at the top while scrolling */
.site-header {
  position: sticky;
  top: 0;
  z-index: 1100;
  background: linear-gradient(180deg, rgba(11, 11, 11, 0.98), rgba(11, 11, 11, 0.95));
  backdrop-filter: blur(4px);
  margin-bottom: 12px;
  border-radius: 10px
}

.card.site-header {
  padding: 8px
}

/* Site branding: prepend a consistent site name in the header for clear branding */
.card.site-header .legend::before {
  content: "Margin Matters";
  display: inline-block;
  font-weight: 700;
  margin-right: 12px;
  color: var(--accent);
}

/* Header toggle button (hamburger menu) - hidden on desktop */
.header-toggle {
  display: none;
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 8px;
  flex-direction: column;
  gap: 4px;
  z-index: 1101;
}

.header-toggle span {
  display: block;
  width: 24px;
  height: 3px;
  background: var(--accent);
  border-radius: 2px;
  transition: all 0.3s ease;
}

.header-toggle.active span:nth-child(1) {
  transform: rotate(45deg) translate(6px, 6px);
}

.header-toggle.active span:nth-child(2) {
  opacity: 0;
}

.header-toggle.active span:nth-child(3) {
  transform: rotate(-45deg) translate(6px, -6px);
}

/* Mobile header collapsible menu */
@media (max-width: 768px) {
  .header-toggle {
    display: flex;
  }

  .site-header .small-links {
    position: fixed;
    top: 60px;
    left: 0;
    right: 0;
    background: var(--card);
    border: 1px solid var(--border);
    border-top: none;
    border-radius: 0 0 12px 12px;
    flex-direction: column;
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease, padding 0.3s ease;
    padding: 0 16px;
    z-index: 1100;
  }

  .site-header .small-links.expanded {
    max-height: 500px;
    padding: 16px;
  }

  .site-header .small-links .btn {
    width: 100%;
    text-align: left;
    justify-content: flex-start;
  }

  .card.site-header {
    flex-wrap: wrap;
  }

  .card.site-header .legend {
    order: -1;
    flex: 1;
    text-align: center;
  }
}

/* PV slider value and totals: keep spacing stable and make numbers pop */
#pvVal {
  display: inline-block;
  min-width: 140px;
  text-align: left;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.2px;
  color: #fff;
  background: rgba(0, 0, 0, 0.35);
  padding: 3px 8px;
  border-radius: 8px
}

.pv-totals {
  display: flex;
  gap: 10px;
  align-items: stretch;
  justify-content: center;
  margin-top: 10px;
  flex-wrap: wrap
}

.pv-badge {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: center;
  padding: 8px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #111;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.05) inset
}

.pv-badge .label {
  font-size: .9rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .6px
}

.pv-badge .num {
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  min-width: 8ch;
  text-align: right;
  color: #fff
}

.pv-badge.pv-d {
  background: linear-gradient(180deg, rgba(49, 88, 206, 0.15), rgba(21, 32, 61, 0.15));
  border-color: #2a3d78
}

.pv-badge.pv-r {
  background: linear-gradient(180deg, rgba(193, 55, 55, 0.15), rgba(66, 18, 18, 0.15));
  border-color: #6d2424
}

.pv-badge.pv-o {
  background: linear-gradient(180deg, rgba(201, 164, 0, 0.18), rgba(72, 59, 0, 0.15));
  border-color: #6b5b00
}

.pv-badge.pv-total {
  background: linear-gradient(180deg, rgba(120, 120, 120, 0.12), rgba(40, 40, 40, 0.12));
  border-color: #3a3a3a
}

/* Align raw values and inline delta consistently inside table cells */
.cell-inner {
  display: inline-grid;
  grid-auto-flow: column;
  align-items: center;
  gap: 8px
}

.cell-inner .raw {
  font-variant-numeric: tabular-nums;
  text-align: right;
  display: block
}

.cell-inner .delta {
  color: var(--muted);
  white-space: nowrap;
  font-size: 0.95rem
}

/* Column explanations (definition list) styling */
.info-dl {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 6px 16px;
  align-items: start;
  margin: 0
}

.info-dl dt {
  font-weight: 700;
  color: var(--fg);
  margin: 0;
  padding: 6px 0
}

.info-dl dd {
  margin: 0;
  padding: 6px 0;
  color: var(--muted);
  font-size: 0.95rem
}

@media (max-width:800px) {
  .info-dl {
    grid-template-columns: 1fr
  }
}

/* Map hover tooltip */
#mapTip {
  position: absolute;
  pointer-events: none;
  z-index: 1200;
  transform: translate(-50%, -120%);
  background: rgba(20, 20, 20, 0.95);
  color: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 10px;
  white-space: nowrap;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35)
}

/* Map layout: full-width map, any overlays drawn inside SVG */
#map-wrap {
  position: relative;
  display: block;
  /* no side column so map can use full width */
}

#smallStateBoxes {
  /* allow small state boxes to render on probabilities & paths pages */
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.small-state-box {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 8px;
  border: 1px solid rgba(0, 0, 0, 0.35);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25) inset;
  background: #222;
}

.prob-table {
  margin-top: 12px;
  font-size: 0.95rem;
  background: #111;
  border-radius: 10px;
  overflow: hidden
}

.prob-table th,
.prob-table td {
  padding: 8px 12px;
  text-align: center;
  font-variant-numeric: tabular-nums
}

.prob-table th {
  text-transform: uppercase;
  font-size: 0.8rem;
  letter-spacing: 0.6px;
  color: var(--muted);
  background: #161616
}

.prob-table td:first-child,
.prob-table th:first-child {
  text-align: left;
  font-variant-numeric: normal
}

.prob-table td:last-child,
.prob-table th:last-child {
  text-align: center
}

.prob-table tbody tr:hover {
  background: #161616
}

.small-state-box .label {
  font-weight: 800;
  letter-spacing: 0.3px;
  -webkit-text-stroke: 1.5px rgba(0, 0, 0, 0.8);
  /* Add stroke for better readability */
}

.small-state-box .ev {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  -webkit-text-stroke: 0.5px rgba(0, 0, 0, 0.8);
  /* Add stroke for better readability */
}

@media (max-width: 900px) {
  #map-wrap {
    display: block
  }
}

/* Flip scenario UI */
.flip-controls {
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
  margin-top: 10px
}

.flip-summary {
  display: flex;
  gap: 10px;
  align-items: stretch;
  justify-content: center;
  margin-top: 10px;
  flex-wrap: wrap
}

.flip-badge {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: center;
  padding: 6px 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #111
}

.flip-badge .label {
  font-size: .85rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .6px
}

.flip-badge .num {
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  min-width: 6ch;
  text-align: right;
  color: #fff
}

.flip-table {
  width: 100%;
  border-collapse: collapse;
  background: #111;
  margin-top: 8px
}

.flip-table th,
.flip-table td {
  padding: 8px 10px;
  border-bottom: 1px solid #1f1f1f;
  text-align: center;
  white-space: nowrap
}

.flip-table th {
  background: #161616;
  position: sticky;
  top: 0
}

/* Ensure flip buttons text is white for readability (consistent with Explorer) */
.flip-controls .btn {
  color: #fff
}

/* Delta toggle UI - sticky footer */
.delta-toggle-footer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 2100;
  background: linear-gradient(180deg, rgba(11, 11, 11, 0.98), rgba(11, 11, 11, 0.95));
  backdrop-filter: blur(4px);
  border-top: 1px solid var(--border);
  padding: 8px 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  pointer-events: auto
}

.delta-toggle-footer .toggle-group {
  display: flex;
  align-items: center;
  gap: 8px
}

.delta-toggle-footer label {
  font-size: 0.9rem;
  color: var(--fg);
  cursor: pointer
}

.delta-toggle-footer input[type="checkbox"] {
  width: 18px;
  height: 18px;
  cursor: pointer
}

/* Hide deltas when toggle is off */
.hide-deltas .delta {
  display: none !important
}

/* Add padding to body when delta toggle is visible to prevent content being hidden behind it */
body.has-delta-toggle {
  padding-bottom: 60px
}

/* Add padding to body when proportional EV toggle is visible */
body.has-prop-ev-toggle {
  padding-bottom: 60px
}

/* Increase padding on mobile to ensure sticky footer doesn't cover actual footer */
@media (max-width: 768px) {

  body.has-delta-toggle,
  body.has-prop-ev-toggle {
    padding-bottom: 100px;
  }
}

/* PV tools specific styling to match future.html dark look
  Ensure high contrast white text on dark backgrounds so controls
  remain readable when pages are rebuilt from templates. */
.pv-tools {
  color: #fff
}

.pv-tools .btn {
  background: var(--card);
  color: #fff;
  border: 1px solid var(--border)
}

.pv-tools .btn:hover {
  color: #fff
}

.pv-tools input[type="text"],
.pv-tools select,
.pv-tools input[type="number"],
.pv-tools textarea {
  background: #111;
  border: 1px solid var(--border);
  color: #fff;
  padding: 8px;
  border-radius: 8px
}

.pv-tools input::placeholder,
.pv-tools textarea::placeholder {
  color: rgba(255, 255, 255, 0.6)
}

.pv-tools input[type="range"] {
  accent-color: var(--accent)
}

/* Consistent slider visuals for PV tools and controls (match shift-vectors year slider) */
.pv-tools .field label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.pv-tools input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 28px;
  background: transparent;
  margin-top: 6px;
}

.pv-tools input[type="range"]::-webkit-slider-runnable-track {
  height: 10px;
  background: linear-gradient(90deg, rgba(102,179,255,0.12), rgba(255,255,255,0.04));
  border-radius: 8px;
  border: 1px solid var(--border);
}

.pv-tools input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid #444;
  margin-top: -4px; /* center thumb over track */
  box-shadow: 0 2px 6px rgba(0,0,0,0.3);
}

.pv-tools input[type="range"]::-moz-range-track {
  height: 10px;
  background: linear-gradient(90deg, rgba(102,179,255,0.12), rgba(255,255,255,0.04));
  border-radius: 8px;
  border: 1px solid var(--border);
}

.pv-tools input[type="range"]::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid #444;
  box-shadow: 0 2px 6px rgba(0,0,0,0.3);
}

.pv-tools input[type="range"]:focus {
  outline: none;
}

.pv-tools input[type="range"]:focus::-webkit-slider-thumb {
  box-shadow: 0 0 0 8px rgba(102,179,255,0.08);
}

.pv-tools .muted {
  font-variant-numeric: tabular-nums;
  min-width: 5ch;
  text-align: right;
}

/* Ensure all table text in pv-tools (e.g., laplace) is centered */
.pv-tools .table-wrap table,
.pv-tools .table-wrap table th,
.pv-tools .table-wrap table td {
  text-align: center !important;
}

/* Make sure even the first sticky column is centered inside pv-tools tables */
.pv-tools .table-wrap table th:first-child,
.pv-tools .table-wrap table td:first-child {
  text-align: center !important;
}

/* Dual-range year slider used on state pages and trend viewer */
.dual-range-slider {
  position: relative;
  height: 28px;
  display: block;
}

.dual-range-slider .slider-track {
  position: absolute;
  inset: 0 0 0 0;
  top: 50%;
  transform: translateY(-50%);
  height: 6px;
  background: #0f0f0f;
  border: 1px solid var(--border);
  border-radius: 6px;
  pointer-events: none; /* important: track should not catch clicks */
}

.dual-range-slider .slider-range {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  height: 6px;
  background: linear-gradient(90deg, rgba(74, 222, 128, 0.9), rgba(244, 114, 182, 0.9));
  border-radius: 6px;
  left: 0;
  width: 0;
  pointer-events: none; /* important: decorative only */
  z-index: 1;
}

.dual-range-slider .slider-input {
  position: absolute;
  inset: 0;
  width: 100%;
  background: transparent;
  -webkit-appearance: none;
  appearance: none;
  margin: 0;
}

/* Put max on top by default so right-side clicks hit the max thumb */
.slider-input--min { z-index: 2; }
.slider-input--max { z-index: 3; }

.dual-range-slider .slider-input::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px; height: 14px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid #222;
}

.dual-range-slider .slider-input::-moz-range-thumb {
  width: 14px; height: 14px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid #222;
}

/* Hide native thumbs but keep inputs for value/storage; we'll use custom thumbs */
.dual-range-slider .slider-input::-webkit-slider-thumb { opacity: 0; width: 0; height: 0; }
.dual-range-slider .slider-input::-moz-range-thumb { opacity: 0; width: 0; height: 0; }
.dual-range-slider .slider-input { pointer-events: none; }

/* Custom thumb visuals */
.slider-thumb {
  position: absolute;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid #444;
  box-shadow: 0 2px 6px rgba(0,0,0,0.4);
  z-index: 10;
  cursor: grab;
}
.slider-thumb:active { cursor: grabbing; }
.slider-thumb.thumb-start { background: linear-gradient(180deg,#fff,#e6f7ff); }
.slider-thumb.thumb-end { background: linear-gradient(180deg,#fff,#ffe6f0); }

/* While a slider thumb is being dragged we add a body class (`slider-dragging`).
   Force a grabbing cursor for the whole document during that interaction to
   avoid flicker when the pointer briefly leaves the thumb element. */
body.slider-dragging,
body.slider-dragging * {
  cursor: grabbing !important;
}

.pv-tools label {
  color: var(--muted)
}

.pv-tools .legend {
  color: var(--muted)
}

.pv-tools datalist {
  color: #fff
}

/* Ensure the "Compare to" select in the Relative margin change card is readable on dark pages */
#relBaseline,
#relDeltas select,
#relDeltas .btn {
  color: #fff;
  background: var(--card);
  border: 1px solid var(--border);
}

#relBaseline {
  padding: 6px 8px;
  border-radius: 8px
}

/* Possibilities page layout */
.possibilities-controls .control-row {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}

.possibilities-controls .control-row:last-of-type {
  margin-bottom: 0
}

.possibilities-controls label {
  min-width: 160px;
  font-weight: 600;
  color: var(--fg)
}

#thresholdSlider {
  width: 220px;
  accent-color: var(--accent)
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px
}

.summary-card {
  background: #111;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px
}

.summary-card .label {
  text-transform: uppercase;
  font-size: 0.8rem;
  color: var(--muted);
  letter-spacing: 0.6px
}

.summary-card .value {
  font-weight: 900;
  font-size: 1.2rem;
  font-variant-numeric: tabular-nums;
  color: #fff
}

.summary-card .note {
  color: var(--muted);
  font-size: 0.9rem;
  font-variant-numeric: tabular-nums
}

.summary-card .names {
  color: var(--muted);
  font-size: 0.9rem
}

.paths-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
  margin-top: 12px
}

.paths-card {
  background: #111;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 4px
}

.paths-card .label {
  text-transform: uppercase;
  font-size: 0.85rem;
  color: var(--muted);
  letter-spacing: 0.6px
}

.paths-card .value {
  font-weight: 900;
  font-size: 1.4rem;
  font-variant-numeric: tabular-nums;
  color: #fff
}

.paths-card .pct {
  color: var(--muted);
  font-size: 0.95rem;
  font-variant-numeric: tabular-nums
}

.tossup-list {
  margin-top: 10px;
  color: var(--muted);
  font-size: 0.95rem
}

.tossup-list strong {
  color: var(--fg)
}

.state {
  cursor: pointer;
  transition: fill 0.25s ease, filter 0.2s ease
}

.state:hover {
  filter: brightness(1.08)
}

.state.locked {
  cursor: not-allowed !important;
  filter: brightness(0.85) saturate(0.85);
}

.manual-note {
  color: var(--accent);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.5px
}

/* Election-night call log floating panel */
#enLogPanel {
  position: fixed;
  top: 110px;
  right: clamp(12px, 3vw, 32px);
  width: min(320px, 28vw);
  max-height: 72vh;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: linear-gradient(180deg, rgba(24, 24, 24, 0.88), rgba(12, 12, 12, 0.82));
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px;
  box-shadow: 0 16px 36px rgba(0, 0, 0, 0.45);
  z-index: 1400;
  backdrop-filter: blur(8px);
}

.en-log-header {
  font-weight: 700;
  font-size: 0.95rem;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  color: var(--accent);
}

.en-log-body {
  flex: 1 1 auto;
  overflow-y: auto;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 10px;
  padding: 10px;
  background: rgba(10, 10, 10, 0.65);
  font-size: 0.85rem;
  line-height: 1.38;
  color: var(--fg);
  min-height: 120px;
}

.en-log-entry {
  font-variant-numeric: tabular-nums;
  color: var(--fg);
}

.en-log-entry+.en-log-entry {
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px solid rgba(255, 255, 255, 0.05)
}

.en-log-outcome {
  margin-top: 12px;
  padding: 12px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: linear-gradient(145deg, rgba(255, 255, 255, 0.10), rgba(255, 255, 255, 0.02));
  font-weight: 800;
  font-size: 1rem;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  color: #f0f0f0;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}

.en-log-outcome.win-dem {
  border-color: rgba(111, 168, 255, 0.6);
  background: linear-gradient(145deg, rgba(111, 168, 255, 0.15), rgba(30, 60, 120, 0.25));
  color: #9ec8ff
}

.en-log-outcome.win-rep {
  border-color: rgba(255, 153, 153, 0.6);
  background: linear-gradient(145deg, rgba(255, 153, 153, 0.15), rgba(120, 30, 30, 0.25));
  color: #ffb9b9
}

.en-log-outcome.tie {
  border-color: rgba(255, 215, 0, 0.5);
  background: linear-gradient(145deg, rgba(255, 215, 0, 0.18), rgba(80, 80, 10, 0.25));
  color: #ffe27a
}

.en-log-notice {
  color: #f0d28c;
  font-style: italic;
}

.en-log-victory {
  display: none;
  margin-top: 10px;
  padding: 12px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: linear-gradient(145deg, rgba(255, 255, 255, 0.10), rgba(255, 255, 255, 0.02));
  font-weight: 800;
  font-size: 0.95rem;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  color: #f0f0f0;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}

.en-log-victory.win-dem {
  border-color: rgba(111, 168, 255, 0.6);
  background: linear-gradient(145deg, rgba(111, 168, 255, 0.15), rgba(30, 60, 120, 0.25));
  color: #9ec8ff
}

.en-log-victory.win-rep {
  border-color: rgba(255, 153, 153, 0.6);
  background: linear-gradient(145deg, rgba(255, 153, 153, 0.15), rgba(120, 30, 30, 0.25));
  color: #ffb9b9
}

.en-log-victory.tie {
  border-color: rgba(255, 215, 0, 0.5);
  background: linear-gradient(145deg, rgba(255, 215, 0, 0.18), rgba(80, 80, 10, 0.25));
  color: #ffe27a
}

.en-log-uncalled {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  display: flex;
  flex-direction: column;
  gap: 8px
}

.en-log-uncalled:empty {
  display: none;
  margin-top: 0;
  padding-top: 0;
  border-top: none
}

.en-log-section-title {
  text-transform: uppercase;
  font-size: 0.78rem;
  letter-spacing: 0.08em;
  color: rgba(255, 255, 255, 0.65)
}

.en-log-uncalled-cards {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 300px;
  overflow-y: auto;
  overflow-x: hidden
}

.en-log-uncalled-card {
  padding: 8px 10px;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(0, 0, 0, 0.35);
  color: rgba(255, 255, 255, 0.88);
  font-size: 0.9rem;
  line-height: 1.35
}

.en-log-uncalled-card:hover {
  border-color: rgba(255, 255, 255, 0.18);
  background: rgba(255, 255, 255, 0.08)
}

#enConfidence {
  accent-color: var(--accent)
}

#enConfidenceVal {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  color: #fff
}

@media (max-width: 1200px) {
  #enLogPanel {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    top: auto;
    width: 100%;
    max-width: 100%;
    margin: 0;
    border-radius: 16px 16px 0 0;
    border-bottom: none;
    max-height: 70vh;
    transition: transform 0.3s ease;
    z-index: 2200;
  }

  #enLogPanel.collapsed {
    transform: translateY(calc(100% - 50px));
  }

  #enLogPanel.collapsed .en-log-body,
  #enLogPanel.collapsed .en-log-uncalled {
    display: none;
  }

  .en-log-header {
    cursor: pointer;
    user-select: none;
    position: relative;
    padding-right: 30px;
  }

  .en-log-header::after {
    content: '';
    position: absolute;
    right: 0;
    top: 50%;
    transform: translateY(-50%) rotate(180deg);
    width: 0;
    height: 0;
    border-left: 6px solid transparent;
    border-right: 6px solid transparent;
    border-bottom: 8px solid var(--accent);
    transition: transform 0.3s ease;
  }

  #enLogPanel.collapsed .en-log-header::after {
    transform: translateY(-50%) rotate(0deg);
  }

  .en-log-body {
    max-height: calc(70vh - 100px)
  }
}

@media (max-width: 720px) {
  #enLogPanel {
    padding: 12px;
    box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.5);
  }
}

/* Category abbreviation list styling */
.category-abbrs {
  margin-top: 6px;
  font-size: 0.75rem;
  line-height: 1.3;
  color: var(--muted);
  word-wrap: break-word
}

.category-abbrs strong {
  color: var(--fg);
  font-weight: 600
}

/* Enumerated path lists */
.possibilities-enumeration h3 {
  font-size: 0.9rem;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--muted)
}

.enum-list {
  list-style: decimal-leading-zero inside
}

.enum-list li {
  margin: 0 0 4px 0;
  padding: 4px 6px;
  background: #111;
  border: 1px solid #1f1f1f;
  border-radius: 6px;
  font-variant-numeric: tabular-nums
}

.enum-list li:nth-child(odd) {
  background: #101010
}

.enum-list li:hover {
  background: #181818
}

.enum-list code {
  background: #181818;
  padding: 2px 4px;
  border-radius: 4px;
  color: #fff
}

/* Mini cards for per-path formatting */
.path-mini-card {
  display: grid;
  grid-template-columns: auto auto auto;
  gap: 4px 12px;
  align-items: center;
  font-size: 0.7rem;
  font-weight: 600
}

.path-mini-card .pv {
  font-weight: 800;
  color: #fff
}

/* New: card styling for enumerated paths */
.path-card {
  background: #0f0f0f;
  border: 1px solid #222;
  padding: 8px;
  border-radius: 8px;
  display: block
}

.path-card .row {
  display: flex;
  gap: 8px;
  align-items: center
}

.path-card .dlist {
  color: #7fb3ff;
  font-weight: 700
}

.path-card .rlist {
  color: #ff9b9b;
  font-weight: 700
}

.path-card .evs {
  margin-left: auto;
  color: #fff;
  font-weight: 800
}

.enum-list li {
  padding: 6px
}

/* Modal styles */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.85);
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  pointer-events: none
}

.modal-content {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  max-width: 900px;
  max-height: 90vh;
  width: 100%;
  display: flex;
  flex-direction: column
}

.modal-content {
  pointer-events: auto
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border)
}

.modal-header h3 {
  color: var(--fg);
  font-size: 1.2rem
}

.modal-close {
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 2rem;
  line-height: 1;
  cursor: pointer;
  padding: 0 8px;
  transition: color 0.2s
}

.modal-close:hover {
  color: var(--fg)
}

.modal-body {
  padding: 20px;
  overflow: auto;
  flex: 1
}

/* EV Breakdown table specific styles */
.ev-breakdown-table {
  width: 100%;
  border-collapse: collapse;
  background: #111
}

.ev-breakdown-table th,
.ev-breakdown-table td {
  padding: 10px 12px;
  border-bottom: 1px solid #1f1f1f;
  text-align: center;
  white-space: nowrap
}

.ev-breakdown-table th {
  background: #161616;
  position: sticky;
  top: 0;
  z-index: 10;
  cursor: pointer;
  user-select: none
}

.ev-breakdown-table th.sortable:hover {
  background: #1a1a1a
}

.ev-breakdown-table th.sorted-asc::after {
  content: " ▲";
  font-size: 0.7rem;
  opacity: 0.6
}

.ev-breakdown-table th.sorted-desc::after {
  content: " ▼";
  font-size: 0.7rem;
  opacity: 0.6
}

.ev-breakdown-table tbody tr:hover {
  background: #151515;
  cursor: pointer
}

.ev-breakdown-table td:first-child {
  text-align: left;
  font-weight: 500
}

.ev-breakdown-table .blank-entry {
  color: var(--muted);
  font-style: italic
}

.ev-breakdown-table .total-row {
  border-top: 2px solid var(--border);
  background: #161616
}

.ev-breakdown-table .total-row td {
  padding-top: 14px;
  font-weight: 700
}

/* ===== shift-vectors page specific styles (migrated from shift-vectors.html) ===== */
:root {
  --bg: #0b0b0b;
  --fg: #f5f5f5;
  --muted: #a5a5a5;
  --accent: #66b3ff;
  --card: #141414;
  --border: #2a2a2a;
  --plot-grid: rgba(255, 255, 255, 0.08);
  --plot-zero: rgba(255, 255, 255, 0.25);
  --plot-circle: rgba(102, 179, 255, 0.2);
  --plot-circle-stroke: rgba(102, 179, 255, 0.5);
  --quad-blue: #60a5fa;
  --quad-red: #f87171;
  --quad-green: #34d399;
  --quad-amber: #fbbf24;
  --quad-purple: #c084fc;
  --quad-muted: #9ca3af;
}

body.shift-vectors-page {
  background: var(--bg);
  color: var(--fg);
}

.shift-vectors .container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 16px;
}

.shift-vectors .card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 12px;
}

.shift-vectors .legend { color: var(--muted); }
.shift-vectors .page-title { display:flex; flex-direction:column; gap:6px }
.shift-vectors .page-title h1 { font-size:1.65rem; margin:0 }
.shift-vectors .controls { display:grid; gap:16px }
@media (min-width:720px) { .shift-vectors .controls { grid-template-columns: repeat(2, minmax(0,1fr)); align-items:end } }
@media (min-width:1024px) { .shift-vectors .controls { grid-template-columns: repeat(3, minmax(0,1fr)) } }

/* Mobile-first: stack chart above controls and table for small screens */
@media (max-width: 720px) {
  .shift-vectors .chart-card { order: 0; }
  .shift-vectors .controls { order: 1; }
  .shift-vectors .data-panel { order: 2; }
  .shift-vectors .card { padding: 12px }
  /* larger touch targets */
  .shift-vectors .toggle-row label, .shift-vectors .badge, .shift-vectors .btn { padding: 10px 12px }
  .shift-vectors .chart-card { min-height: 360px }
}

/* Data panel styles */
.shift-vectors .data-panel .btn { min-width: 120px }
.shift-vectors #dataPanel { transition: max-height 0.28s ease, opacity 0.2s ease }
.shift-vectors .shift-data-table th, .shift-vectors .shift-data-table td { font-size: 0.92rem; padding: 8px 10px }
.shift-vectors .shift-data-table thead th.sortable { cursor: pointer }
.shift-vectors .shift-data-table thead th.sorted-asc::after, .shift-vectors .shift-data-table thead th.sorted-desc::after { margin-left: 6px; opacity: 0.85 }

/* Make table rows easier to tap on mobile */
.shift-vectors .shift-data-table tbody tr { touch-action: manipulation }
.shift-vectors .shift-data-table tbody tr td { padding: 12px 10px }

/* small screens: let table take full width and allow scrolling horizontally */
@media (max-width: 520px) {
  .shift-vectors .table-wrap { overflow-x: auto }
  .shift-vectors .shift-data-table th, .shift-vectors .shift-data-table td { white-space: nowrap }
}
.shift-vectors .field { display:flex; flex-direction:column; gap:8px }
.shift-vectors .field label { font-size:0.9rem; color:var(--muted) }
.shift-vectors .slider-row { display:flex; align-items:center; gap:12px }
.shift-vectors .toggle-row { display:flex; gap:16px; flex-wrap:wrap; align-items:center }
.shift-vectors .toggle-row label { display:inline-flex; gap:8px; align-items:center; font-size:0.92rem; color:var(--muted); cursor:pointer }
.shift-vectors .metrics { display:flex; gap:18px; flex-wrap:wrap; font-size:0.9rem; color:var(--muted) }
.shift-vectors .chart-card { position:relative; overflow:hidden }
.shift-vectors #vectorChart { width:100%; height:100%; min-height:420px; display:block }
.shift-vectors .empty-state { display:none; text-align:center; font-size:1rem; padding:24px 0; color:var(--muted) }
.shift-vectors .tooltip { position:fixed; pointer-events:none; background:rgba(17,17,17,0.95); border:1px solid var(--border); padding:8px 10px; border-radius:8px; color:var(--fg); font-size:0.92rem; line-height:1.4; opacity:0; transform:translateY(-6px); transition:opacity 0.1s ease, transform 0.1s ease; box-shadow:0 8px 16px rgba(0,0,0,0.45); z-index:20; max-width:42ch; max-width:420px; white-space:normal; word-wrap:break-word; overflow-wrap:break-word; }
.shift-vectors .tooltip.visible { opacity:1; transform:translateY(0) }
.shift-vectors .tooltip-note { margin-top:6px; font-size:0.82rem; color:var(--muted) }
.shift-vectors .tooltip .arrow { font-weight:700; margin-right:6px }
.shift-vectors .tooltip .pct { color: rgba(255,255,255,0.78); font-weight:600 }
.shift-vectors .chart-note { margin-top:10px; font-size:0.9rem; color:var(--muted) }
.shift-vectors .loading { font-size:0.95rem; color:var(--muted) }
.shift-vectors .axis text { fill:var(--muted); font-size:0.75rem }
.shift-vectors .axis path, .shift-vectors .axis line { stroke:var(--plot-grid) }
.shift-vectors .axis-label { fill:var(--muted); font-size:0.82rem; text-transform:uppercase; letter-spacing:0.08em }
.shift-vectors .zero-line { stroke:var(--plot-zero); stroke-width:1.4; stroke-dasharray:4 4 }
.shift-vectors .unit-circle { fill:var(--plot-circle); stroke:var(--plot-circle-stroke); stroke-width:1.2 }
.shift-vectors .point { stroke:rgba(11,11,11,0.85); stroke-width:1; cursor:pointer }
.shift-vectors .point:hover, .shift-vectors .point.active { stroke-width:2; stroke:#fff }
.shift-vectors .badge { display:inline-flex; align-items:center; gap:6px; font-size:0.85rem; background:rgba(255,255,255,0.05); border:1px solid var(--border); border-radius:999px; padding:4px 10px }
.shift-vectors .badge .swatch { width:10px; height:10px; border-radius:3px }
.shift-vectors .badges { display:flex; flex-wrap:wrap; gap:8px; margin-top:12px; color:var(--muted) }
.shift-vectors .status-row { display:flex; gap:12px; flex-wrap:wrap; align-items:center; font-size:0.9rem; color:var(--muted) }
.shift-vectors input[type="range"] { accent-color: var(--accent) }

/* Make the Year slider span the full width of the controls area and expand */
.shift-vectors .controls .field:first-child {
  /* span all columns so the slider can be very wide */
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 12px;
}
.shift-vectors .controls .field:first-child .slider-row {
  flex: 1 1 0;
  min-width: 0;
  display: flex;
}
.shift-vectors #yearSlider {
  width: 100%;
  flex: 1 1 0;
  min-width: 0;
}

/* stronger explicit rules for the year-field wrapper to avoid selector timing issues */
.shift-vectors .year-field { grid-column: 1 / -1; display:flex; align-items:center; gap:12px }
.shift-vectors .year-field .slider-row { flex:1 1 0; min-width:0; display:flex; align-items:center }
.shift-vectors .year-field .badge { margin-left: 12px }

/* Make the year slider visually larger: taller track and larger thumb */
.shift-vectors #yearSlider {
  -webkit-appearance: none;
  appearance: none;
  height: 28px; /* overall control height */
  background: transparent; /* track drawn via pseudo-elements */
}

.shift-vectors #yearSlider::-webkit-slider-runnable-track {
  height: 10px;
  background: linear-gradient(90deg, rgba(102,179,255,0.2), rgba(255,255,255,0.06));
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,0.06);
}
.shift-vectors #yearSlider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid #444;
  margin-top: -5px; /* center thumb over track */
  box-shadow: 0 2px 6px rgba(0,0,0,0.3);
}

.shift-vectors #yearSlider::-moz-range-track {
  height: 10px;
  background: linear-gradient(90deg, rgba(102,179,255,0.2), rgba(255,255,255,0.06));
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,0.06);
}
.shift-vectors #yearSlider::-moz-range-thumb {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid #444;
  box-shadow: 0 2px 6px rgba(0,0,0,0.3);
}

/* Focus styles for accessibility */
.shift-vectors #yearSlider:focus {
  outline: none;
}
.shift-vectors #yearSlider:focus::-webkit-slider-thumb {
  box-shadow: 0 0 0 6px rgba(102,179,255,0.12);
}

/* small label styling for the SVG label groups */
.shift-vectors .labels .lbl { font-size:11px; fill:#fff; pointer-events:none }
.shift-vectors .labels .box { fill: rgba(0,0,0,0.6); stroke: rgba(255,255,255,0.06); rx:6; ry:6 }
.shift-vectors .labels .leader { stroke: rgba(255,255,255,0.6); stroke-width:1; opacity:0.85 }

/* allow label group to receive pointer events so hover handlers can trigger tooltips;
   keep individual decorative children non-interactive so they don't block other elements */
.shift-vectors .labels .label { pointer-events: auto; }
.shift-vectors .labels .box { pointer-events: auto; }
.shift-vectors .labels .lbl,
.shift-vectors .labels .leader { pointer-events: none; }

/* end shift-vectors specific styles */

/* Histogram bar styles (used by docs/histograms.js) */
.bar {
  stroke: rgba(255,255,255,0.06);
  stroke-width: 1px;
  transition: opacity 0.12s ease, transform 0.12s ease;
}
.bar-positive {
  fill: #4169E1; /* blue */
}
.bar-negative {
  fill: #B22222; /* red */
}
.bar-neutral {
  fill: #888888; /* gray */
}
.bar:hover,
.bar:focus {
  opacity: 0.85;
  transform: translateY(-2px);
  filter: drop-shadow(0 4px 8px rgba(0,0,0,0.45));
}

/* Make sure the tooltip contents remain readable over dark background */
.tooltip {
  background: rgba(17,17,17,0.95);
  color: var(--fg);
  border: 1px solid var(--border);
}