:root {
  --bg: #f7f7f5;
  --surface: #ffffff;
  --text: #1c1c1e;
  --muted: #6b6b70;
  --border: #dcdcd8;
  --state: #e3e6ea;
  --state-hover: #cdd5de;
  --state-active: #b9cbe0;
  --state-dim: #eef0f2;
  --state-stroke: #ffffff;
  --city: #d0492f;
  --city-active: #1f5fa8;
  --accent: #1f5fa8;
  --drop: #c2410c;
  --rise: #1f5fa8;
  /* Chart: categorical series (validated order) + recessive chrome */
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --series-4: #eda100;
  --series-5: #e87ba4;
  --series-6: #008300;
  --grid: #ebebe7;
  --axis: #c3c2b7;
  --forecast-bg: rgba(11, 11, 11, 0.035);
  --risk-bg: rgba(194, 65, 12, 0.12);
  --risk-ink: #b23a0a;
  --event-bg: rgba(11, 11, 11, 0.07);
  /* Sequential (one hue, low -> high) for the state fluctuation colors; validated as an ordinal ramp. */
  --seq-1: #86b6ef;
  --seq-2: #5598e7;
  --seq-3: #2a78d6;
  --seq-4: #1c5cab;
  --seq-5: #104281;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141416;
    --surface: #1d1d20;
    --text: #ececef;
    --muted: #9a9aa2;
    --border: #2e2e33;
    --state: #2c3038;
    --state-hover: #3a4150;
    --state-active: #34506f;
    --state-dim: #222529;
    --state-stroke: #141416;
    --city: #f07a5f;
    --city-active: #7fb2ea;
    --accent: #7fb2ea;
    --drop: #f59e6b;
    --rise: #7fb2ea;
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --series-4: #c98500;
    --series-5: #d55181;
    --series-6: #008300;
    --grid: #2c2c2a;
    --axis: #383835;
    --forecast-bg: rgba(255, 255, 255, 0.04);
    --risk-bg: rgba(245, 158, 107, 0.16);
    --risk-ink: #f59e6b;
    --event-bg: rgba(255, 255, 255, 0.10);
    --seq-1: #184f95;
    --seq-2: #256abf;
    --seq-3: #3987e5;
    --seq-4: #6da7ec;
    --seq-5: #9ec5f4;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #141416;
  --surface: #1d1d20;
  --text: #ececef;
  --muted: #9a9aa2;
  --border: #2e2e33;
  --state: #2c3038;
  --state-hover: #3a4150;
  --state-active: #34506f;
  --state-dim: #222529;
  --state-stroke: #141416;
  --city: #f07a5f;
  --city-active: #7fb2ea;
  --accent: #7fb2ea;
  --drop: #f59e6b;
  --rise: #7fb2ea;
  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --series-4: #c98500;
  --series-5: #d55181;
  --series-6: #008300;
  --grid: #2c2c2a;
  --axis: #383835;
  --forecast-bg: rgba(255, 255, 255, 0.04);
  --risk-bg: rgba(245, 158, 107, 0.16);
  --risk-ink: #f59e6b;
  --event-bg: rgba(255, 255, 255, 0.10);
  --seq-1: #184f95;
  --seq-2: #256abf;
  --seq-3: #3987e5;
  --seq-4: #6da7ec;
  --seq-5: #9ec5f4;
  color-scheme: dark;
}

* { box-sizing: border-box; }

/* Components set their own display (flex/grid), which would otherwise override the hidden attribute. */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

.site-header {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 8px 24px;
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
}

.site-header h1 {
  margin: 0;
  font-size: 20px;
}

/* .page is a size container so .layout can size the map from its width (cqw units). */
.page {
  container-type: inline-size;
  max-width: 1400px;
  margin: 0 auto;
  padding: 24px;
}

.layout {
  --panel-w: 320px;
  --gap: 24px;
  /* Vertical space taken by the header, page padding and footer, so the page fits without scrolling. */
  --chrome-h: 152px;
  /* Map height when zoomed in (a square next to the panel) and on the full-width US view;
     both capped so the map fits on short screens. */
  --map-h: min(calc((100cqw - var(--panel-w) - var(--gap)) * 610 / 975), calc(100vh - var(--chrome-h)));
  --map-h-full: min(calc(100cqw * 610 / 975), calc(100vh - var(--chrome-h)));
  --ease: cubic-bezier(0.65, 0, 0.35, 1); /* matches d3.easeCubicInOut */
  display: flex;
  align-items: flex-start;
  gap: var(--gap);
}

.map-wrap {
  position: relative;
  flex: none;
  width: 100%;
  height: var(--map-h-full);
  transition: width 750ms var(--ease), height 750ms var(--ease);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}

/* Zoomed into a state: the map narrows to a square and the panel takes the freed space. */
.layout.detail .map-wrap { width: var(--map-h); height: var(--map-h); }

#map {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

#map .bg { fill: transparent; }

#map .state {
  fill: var(--state);
  stroke: var(--state-stroke);
  stroke-width: 1;
  vector-effect: non-scaling-stroke;
  cursor: pointer;
  transition: fill 150ms;
}

/* States take focus when clicked; hide the browser's focus ring and use a stroke for keyboard focus instead. */
#map .state:focus { outline: none; }
#map .state:hover,
#map .state:focus-visible { fill: var(--state-hover); }
#map .state:focus-visible { stroke: var(--accent); stroke-width: 2; }

#map.zoomed .state { fill: var(--state-dim); }
#map.zoomed .state:hover { fill: var(--state-hover); }
#map .state.active,
#map.zoomed .state.active { fill: var(--state-active); cursor: default; }

#map .borders {
  fill: none;
  stroke: var(--state-stroke);
  stroke-width: 1;
  vector-effect: non-scaling-stroke;
  pointer-events: none;
}

#map .city circle {
  fill: var(--city);
  stroke: var(--surface);
  vector-effect: non-scaling-stroke;
  stroke-width: 1.5;
}

#map .city { cursor: pointer; outline: none; }
#map .city:hover circle,
#map .city:focus-visible circle { stroke: var(--text); }
#map .city.active circle { fill: var(--city-active); }

#map .city text {
  fill: var(--text);
  paint-order: stroke;
  stroke: var(--surface); /* width set in map.js so it stays constant while zooming */
  stroke-linejoin: round;
  font-weight: 500;
  user-select: none;
}

.tooltip {
  position: absolute;
  pointer-events: none;
  background: var(--text);
  color: var(--bg);
  font-size: 13px;
  padding: 4px 8px;
  border-radius: 6px;
  white-space: nowrap;
  transform: translate(-50%, calc(-100% - 10px));
}

.status {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  margin: 0;
  color: var(--muted);
}

.panel {
  flex: 1;
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  align-self: start;
}

.panel h2 {
  margin: 0 0 4px;
  font-size: 20px;
}

.panel .sub {
  margin: 0 0 16px;
  color: var(--muted);
}

.panel dl {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 8px 16px;
  margin: 0;
}

.panel dt { color: var(--muted); }
.panel dd { margin: 0; font-variant-numeric: tabular-nums; }

.panel ul {
  margin: 0;
  padding-left: 18px;
}

.panel .note {
  margin-top: 16px;
  font-size: 13px;
  color: var(--muted);
}

.panel .note.error { color: var(--drop); }
.panel .muted { color: var(--muted); }
.panel .drop { color: var(--drop); font-weight: 600; }
.panel .rise { color: var(--rise); font-weight: 600; }

/* ---- Pressure chart ---- */

.chart-card {
  margin: 4px 0 20px;
}

.range-picker {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 2px;
  padding: 2px;
  margin-bottom: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
}

.range-picker button {
  font: inherit;
  font-size: 13px;
  color: var(--muted);
  background: none;
  border: 0;
  border-radius: 6px;
  padding: 4px 10px;
  cursor: pointer;
}

.range-picker button:hover { color: var(--text); }

.range-picker button[aria-pressed="true"] {
  color: var(--text);
  background: var(--surface);
  font-weight: 600;
  box-shadow: 0 0 0 1px var(--border);
}

.chart-frame {
  position: relative;
  min-height: 270px; /* toolbar + plot, so loading doesn't shift the layout */
}

.chart { transition: opacity 150ms; }
.chart.refreshing { opacity: 0.4; }

.chart-status {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  margin: 0;
  font-size: 13px;
  color: var(--muted);
  pointer-events: none;
}

.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 16px;
  margin: 4px 0 0;
  padding: 0;
  list-style: none;
  font-size: 13px;
  color: var(--muted);
}

.chart-legend li {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.line-key {
  display: inline-block;
  width: 12px;
  height: 2px;
  border-radius: 1px;
  flex: none;
}

.chart-plot { position: relative; }
.chart-svg { display: block; overflow: visible; }

.chart-svg .grid line { stroke: var(--grid); stroke-width: 1; }
.chart-svg .baseline { stroke: var(--axis); stroke-width: 1; }
.chart-svg .axis-label,
.chart-svg .chart-note {
  fill: var(--muted);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}
.chart-svg .forecast-bg { fill: var(--forecast-bg); }
.chart-svg .now-line { stroke: var(--axis); stroke-width: 1; stroke-dasharray: 3 3; }

.chart-svg .series-line {
  fill: none;
  stroke-width: 2;
  stroke-linejoin: round;
  stroke-linecap: round;
}
.chart-svg .series-line.forecast { stroke-dasharray: 4 4; }

.chart-svg .end-labels text {
  fill: var(--muted);
  font-size: 12px;
}

.chart-svg .hover-target { fill: transparent; outline: none; cursor: grab; }
.chart-svg .hover-target:active { cursor: grabbing; }

.chart-toolbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  min-height: 26px; /* room for the reset button, so showing it doesn't shift the chart */
  margin-bottom: 4px;
}

.chart-reset {
  flex: none;
  font: inherit;
  font-size: 12px;
  color: var(--accent);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 2px 8px;
  cursor: pointer;
}
.chart-svg .crosshair line { stroke: var(--muted); stroke-width: 1; }
.chart-svg .crosshair circle { stroke: var(--surface); stroke-width: 2; }

.chart-tooltip {
  position: absolute;
  z-index: 1;
  min-width: 150px;
  padding: 8px 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
  font-size: 12px;
  pointer-events: none;
}

.chart-tooltip .tip-time {
  margin-bottom: 4px;
  color: var(--muted);
}

.chart-tooltip .tip-row {
  display: flex;
  align-items: center;
  gap: 8px;
  line-height: 1.7;
}

.chart-tooltip strong {
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

.chart-tooltip .tip-name { color: var(--muted); }

.chart-table {
  width: 100%;
  margin-top: 12px;
  border-collapse: collapse;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.chart-table th,
.chart-table td {
  padding: 6px 8px;
  text-align: right;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.chart-table thead th {
  color: var(--muted);
  font-weight: 500;
}

.chart-table th:first-child {
  text-align: left;
  font-weight: 500;
}

.chart-table tbody th .line-key { margin-right: 8px; vertical-align: middle; }

@media (max-width: 800px) and (orientation: portrait), (max-width: 800px) and (min-height: 501px) {
  .site-header { padding: 12px 16px; }
  .page { padding: 16px; }
  .layout {
    --gap: 16px;
    --map-h: calc(100cqw * 610 / 975);
    flex-direction: column;
    align-items: stretch;
  }
  .map-wrap,
  .layout.detail .map-wrap { width: 100%; height: var(--map-h); }
}

/* ---- Compare ---- */

.compare-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
  font-size: 13px;
}

.compare-bar label { color: var(--muted); }

.compare-bar input {
  flex: 1 1 200px;
  min-width: 0;
  max-width: 320px;
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 10px;
}

.compare-bar input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.compare-bar button {
  font: inherit;
  color: var(--accent);
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 10px;
  cursor: pointer;
}

.panel h2 .vs {
  font-weight: 400;
  color: var(--muted);
}

.compare-stats {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}

.compare-stats th,
.compare-stats td {
  padding: 6px 8px;
  text-align: right;
  border-bottom: 1px solid var(--border);
}

.compare-stats thead th {
  font-weight: 600;
  white-space: nowrap;
}

.compare-stats thead .line-key { margin-right: 8px; vertical-align: middle; }

.compare-stats tbody th {
  text-align: left;
  font-weight: 400;
  color: var(--muted);
}

/* ---- Migraine-risk highlighting ---- */

.chart-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 16px;
  margin-bottom: 12px;
}

.chart-controls .range-picker { margin-bottom: 0; }

.risk-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}

.risk-toggle {
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 10px;
  cursor: pointer;
}

.risk-toggle::before {
  content: "";
  display: inline-block;
  width: 10px;
  height: 10px;
  margin-right: 6px;
  border-radius: 2px;
  border: 1px solid var(--risk-ink);
  vertical-align: -1px;
}

.risk-toggle[aria-pressed="true"] {
  font-weight: 600;
  border-color: var(--risk-ink);
}

.risk-toggle[aria-pressed="true"]::before { background: var(--risk-ink); }

.risk-sensitivity {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
}

.risk-sensitivity select {
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 3px 6px;
}

.risk-sensitivity select:disabled { opacity: 0.5; }

.chart-keys {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 16px;
}

.risk-key {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 4px;
  font-size: 13px;
  color: var(--muted);
}

.risk-swatch {
  width: 12px;
  height: 12px;
  border-radius: 2px;
  background: var(--risk-bg);
  box-shadow: inset 0 0 0 1px var(--risk-ink);
}

.chart-svg .risk-band { fill: var(--risk-bg); }

.chart-svg .risk-label {
  fill: var(--risk-ink);
  font-size: 11px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.chart-tooltip .tip-risk {
  margin-left: auto;
  padding-left: 8px;
  color: var(--risk-ink);
  font-weight: 600;
  white-space: nowrap;
}

.risk-sources {
  margin-top: 12px;
  font-size: 12px;
  line-height: 1.5;
  color: var(--muted);
}

.risk-sources p { margin: 0 0 4px; }
.risk-sources ul { margin: 0; padding-left: 18px; }
.risk-sources a { color: var(--accent); }

/* ---- Header tabs ---- */

.tabs {
  display: flex;
  gap: 4px;
}

.tabs a {
  color: var(--muted);
  text-decoration: none;
  padding: 4px 10px;
  border-radius: 6px;
}

.tabs a:hover { color: var(--text); background: var(--surface); }

.tabs a[aria-current="page"] {
  color: var(--text);
  font-weight: 600;
  background: var(--surface);
  box-shadow: 0 0 0 1px var(--border);
}

/* ---- Migraine log screen ---- */

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

.card h2 { margin: 0 0 12px; font-size: 20px; }
.card h3 { margin: 20px 0 8px; font-size: 15px; }

.muted { color: var(--muted); font-weight: 400; }

.mg-layout {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  gap: 24px;
  align-items: start;
}

.mg-city input {
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 8px;
}

.mg-list {
  margin: 0;
  padding: 0;
  list-style: none;
  max-height: 420px;
  overflow-y: auto;
}

.mg-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}

.mg-list li.mg-empty { color: var(--muted); border: 0; }

.mg-list button {
  font: inherit;
  color: var(--muted);
  background: none;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 0 8px;
  cursor: pointer;
}

.mg-list button:hover { color: var(--text); border-color: var(--border); }

.mg-city {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
  font-size: 13px;
}

.mg-city label { color: var(--muted); }
.mg-city input { flex: 1 1 220px; max-width: 320px; min-width: 0; }

.mg-stats h3 { margin-top: 8px; }

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

.mg-stat {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
}

.mg-stat-value { font-size: 28px; font-weight: 600; line-height: 1.1; }
.mg-stat-label { font-size: 13px; color: var(--muted); }

.mg-stats .note,
.mg-log .note { font-size: 13px; color: var(--muted); }
.mg-log .note.error { color: var(--drop); }
.mg-yes { color: var(--risk-ink); font-weight: 600; }

.chart-svg .event-band { fill: var(--event-bg); }
.chart-svg .event-line { stroke: var(--text); stroke-width: 1.5; }
.chart-svg .event-dot { fill: var(--text); stroke: var(--surface); stroke-width: 2; }

.event-swatch {
  width: 12px;
  height: 12px;
  border-radius: 2px;
  background: var(--event-bg);
  box-shadow: inset 0 0 0 1px var(--text);
}

@media (max-width: 800px) and (orientation: portrait), (max-width: 800px) and (min-height: 501px) {
  .mg-layout { grid-template-columns: minmax(0, 1fr); gap: 16px; }
  .card { padding: 16px; }
}

/* ---- City rankings screen ---- */

.rk { max-width: 900px; }
.rk-intro { margin-top: 0; font-size: 14px; color: var(--muted); }

.rk-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px 16px;
  margin: 16px 0 8px;
}

.rk-controls .range-picker { margin-bottom: 0; }
.rk-summary { font-size: 13px; color: var(--muted); }

.rk-table th,
.rk-table td { text-align: left; }
.rk-table tbody th { font-weight: 500; }
.rk-table .rk-rank { width: 3em; text-align: right; color: var(--muted); }
.rk-table .rk-state { color: var(--muted); }
.rk-table .rk-count { width: 40%; }
.rk-table thead .rk-count { text-align: left; }

.rk-cell {
  display: flex;
  align-items: center;
  gap: 8px;
}

.rk-bar {
  flex: none;
  height: 8px;
  max-width: calc(100% - 3.5em);
  min-width: 2px;
  border-radius: 0 4px 4px 0;
  background: var(--risk-ink);
  opacity: 0.55;
}

.rk-value { font-variant-numeric: tabular-nums; }
.rk-missing { color: var(--muted); }
.rk-missing .rk-bar { display: none; }
.rk-message { text-align: center !important; color: var(--muted); padding: 24px !important; }

@media (max-width: 800px) and (orientation: portrait), (max-width: 800px) and (min-height: 501px) {
  .rk-table .rk-count { width: auto; }
}

/* ---- Migraine calendar ---- */

.mg-cal {
  margin: 8px 0 4px;
  user-select: none;
}

.mg-cal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
  font-weight: 600;
}

#mg-cal-prev,
#mg-cal-next {
  font: inherit;
  font-size: 18px;
  line-height: 1;
  color: var(--text);
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  width: 32px;
  height: 32px;
  cursor: pointer;
}

#mg-cal-prev:disabled,
#mg-cal-next:disabled { opacity: 0.35; cursor: default; }

.mg-cal-weekdays,
.mg-cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}

.mg-cal-weekdays {
  margin-bottom: 4px;
  font-size: 12px;
  color: var(--muted);
  text-align: center;
}

.mg-cal-grid button {
  aspect-ratio: 1;
  font: inherit;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  background: var(--bg);
  border: 1px solid transparent;
  border-radius: 8px;
  cursor: pointer;
}

.mg-cal-grid button:hover:not(:disabled) { border-color: var(--border); }
.mg-cal-grid button.today { border-color: var(--muted); }
.mg-cal-grid button:disabled { color: var(--muted); opacity: 0.4; cursor: default; }

/* Marked migraine days use the same ink as the chart's migraine markers. */
.mg-cal-grid button[aria-pressed="true"] {
  color: var(--surface);
  background: var(--text);
  font-weight: 600;
}

.mg-cal-grid button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.mg-cal-head { position: relative; }

.mg-cal-title {
  font: inherit;
  font-weight: 600;
  color: var(--text);
  background: none;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 4px 10px;
  cursor: pointer;
}

.mg-cal-title::after {
  content: "▾";
  margin-left: 6px;
  font-size: 12px;
  color: var(--muted);
}

.mg-cal-title:hover,
.mg-cal-title[aria-expanded="true"] { border-color: var(--border); }

.mg-cal-picker {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px 12px;
  margin-bottom: 8px;
  padding: 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
}

.mg-cal-picker label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
}

.mg-cal-picker select {
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 3px 6px;
}

.panel .sub + .panel-hint { margin-top: -8px; }

.panel-hint {
  margin: 0 0 16px;
  font-size: 14px;
  color: var(--accent);
}

.table-scroll { overflow-x: auto; }

/* ---- Compared-city pills ---- */

.compare-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  flex-basis: 100%;
  margin: 0;
  padding: 0;
  list-style: none;
}

.compare-pills li {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 4px 2px 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 13px;
  white-space: nowrap;
}

.compare-pills button {
  font: inherit;
  font-size: 15px;
  line-height: 1;
  color: var(--muted);
  background: none;
  border: 0;
  border-radius: 50%;
  width: 22px;
  height: 22px;
  cursor: pointer;
}

.compare-pills button:hover { color: var(--text); background: var(--surface); }

.compare-limit {
  flex-basis: 100%;
  margin: 0;
  font-size: 12px;
  color: var(--muted);
}

.compare-bar input:disabled { opacity: 0.5; }

.compare-stats th,
.compare-stats td { white-space: nowrap; }

/* ---- Footer: freshness of the pre-downloaded history ---- */

.site-footer {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 24px 16px;
  text-align: right;
  font-size: 12px;
  color: var(--muted);
}

@media (max-width: 800px) and (orientation: portrait), (max-width: 800px) and (min-height: 501px) {
  .site-footer { padding: 0 16px 12px; }
}

.map-hint {
  position: absolute;
  top: 12px;
  left: 12px;
  margin: 0;
  padding: 4px 10px;
  font-size: 13px;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  pointer-events: none;
}

.map-back {
  position: absolute;
  top: 12px;
  left: 12px;
  z-index: 1;
  font: inherit;
  font-size: 13px;
  color: var(--accent);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 12px;
  cursor: pointer;
}

.map-back:hover { background: var(--bg); }
.map-back:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* Rankings: table card on the left, sources card on the right. */
.rk-layout {
  display: grid;
  grid-template-columns: minmax(0, 900px) minmax(240px, 320px);
  gap: 24px;
  align-items: start;
}

.rk-sources { position: sticky; top: 16px; } /* stays in view beside the long table */
.rk-sources h3 { margin: 0 0 8px; font-size: 15px; }
.rk-sources .risk-sources { margin-top: 0; }

@media (max-width: 900px) {
  .rk-layout { grid-template-columns: minmax(0, 1fr); gap: 16px; }
  .rk-sources { position: static; }
}

/* ---- Map: state fluctuation colors + legend ---- */

/* Inline fills win over :hover fill, so hover lifts the state instead. */
#map.choropleth .state:hover,
#map.choropleth .state:focus-visible { filter: brightness(1.15) saturate(1.1); }

.map-legend {
  position: absolute;
  right: 12px;
  bottom: 12px;
  z-index: 1;
  width: 210px;
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 12px;
}

.map-legend-title {
  margin: 0 0 6px;
  font-weight: 600;
  color: var(--text);
}

.map-legend-period {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 8px;
  color: var(--muted);
}

.map-legend-period select {
  flex: 1;
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 2px 4px;
}

.legend-scale {
  margin: 0;
  padding: 0;
  list-style: none;
}

.legend-scale li {
  display: flex;
  align-items: center;
  gap: 8px;
  line-height: 1.8;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

.legend-swatch {
  flex: none;
  width: 16px;
  height: 12px;
  border-radius: 2px;
}

.legend-count {
  margin-left: auto;
  color: var(--muted);
}

.map-legend-note {
  margin: 6px 0 0;
  color: var(--muted);
  line-height: 1.4;
}

@media (max-width: 800px) and (orientation: portrait), (max-width: 800px) and (min-height: 501px) {
  .map-legend { right: 8px; bottom: 8px; width: 180px; padding: 8px; font-size: 11px; }
  .map-legend-note { display: none; }
}

/* Phones in portrait: a single compact strip below the map drawing (the box grows to make room). */
@media (max-width: 600px) and (orientation: portrait) {
  .layout:not(.detail) .map-wrap { height: calc(var(--map-h) + var(--legend-strip-h)); }
  .layout:not(.detail) #map { height: calc(100% - var(--legend-strip-h)); }
  .layout { --legend-strip-h: 56px; }
  .map-legend {
    left: 6px;
    right: 6px;
    bottom: 6px;
    width: auto;
    padding: 6px 8px;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px 8px;
    font-size: 10px;
  }
  .map-legend-title { margin: 0; flex: 1 1 auto; }
  .map-legend-period { margin: 0; }
  .map-legend-period select { padding: 0 2px; }
  .legend-scale { display: flex; flex-basis: 100%; justify-content: space-between; gap: 4px; }
  .legend-scale li { gap: 3px; line-height: 1.4; }
  .legend-swatch { width: 10px; height: 10px; }
  .legend-count { display: none; }
}

/* ---- Rotate-to-landscape prompt (phones held upright; see rotate.js) ---- */

.rotate-prompt {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(0, 0, 0, 0.55);
}

.rotate-card {
  max-width: 320px;
  padding: 24px;
  text-align: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25);
}

.rotate-icon {
  width: 72px;
  height: 72px;
  color: var(--accent);
}

.rotate-card h2 {
  margin: 12px 0 8px;
  font-size: 20px;
}

.rotate-card p {
  margin: 0 0 20px;
  color: var(--muted);
}

.rotate-card button {
  font: inherit;
  font-weight: 600;
  color: var(--accent);
  background: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 16px;
  cursor: pointer;
}

/* ---- Zoomed in: keep the map in view while the (long) panel scrolls ---- */
.layout.detail .map-wrap {
  position: sticky;
  top: 12px;
}

@media (max-width: 800px) and (orientation: portrait), (max-width: 800px) and (min-height: 501px) {
  .layout.detail .map-wrap { position: relative; top: auto; } /* stacked layout: map scrolls with the page */
}

/* ---- Short landscape screens (phones on their side) ---- */
@media (orientation: landscape) and (max-height: 500px) {
  .site-header { padding: 6px 16px; gap: 4px 16px; }
  .site-header h1 { font-size: 16px; }
  .tabs a { padding: 2px 8px; font-size: 14px; }
  .page { padding: 10px 16px; }
  .site-footer { padding: 0 16px 6px; font-size: 11px; }
  .layout {
    --gap: 12px;
    --chrome-h: 92px; /* compact header + padding + footer */
  }
  .layout.detail .map-wrap { top: 8px; }
  .panel { padding: 14px; }
  .panel h2 { font-size: 18px; }

  .map-hint,
  .map-back { top: 8px; left: 8px; font-size: 12px; padding: 3px 10px; }

  /* Narrow legend in the corner beside the map (the US fits the height, leaving room at the sides). */
  .map-legend { right: 8px; bottom: 8px; width: 150px; padding: 6px 8px; font-size: 10.5px; }
  .map-legend-title { margin-bottom: 4px; }
  .map-legend-period { margin-bottom: 4px; }
  .legend-scale li { line-height: 1.6; }
  .legend-count,
  .map-legend-note { display: none; }

  .card { padding: 14px; }
  .mg-layout,
  .rk-layout { gap: 12px; }
  .mg-layout { grid-template-columns: 280px minmax(0, 1fr); }
}

/* The "Most drops month" line is a sentence: let it wrap as text, not as separate flex items. */
.risk-key.risk-peak { display: block; }
