:root {
  /* Chrome palette: a neutral, warm-leaning ink/slate surface, deliberately
     kept OFF the magma_r data ramp so the panels never compete with the map.
     The single crimson --accent (the high end of magma_r) is reserved as a
     sparing focal accent on the headline RAW/CORRECTED control + play button. */
  --ink: #14181d;             /* near-black slate for primary type */
  --muted: #5c6470;           /* secondary type */
  --hair: #e7e9ee;            /* hairline rule on the neutral surface */
  --panel: rgba(252, 252, 251, 0.96);  /* warm off-white glass panel */
  --panel-border: #e1e4ea;
  --accent: #b3123f;          /* focal accent (high end of the magma_r ramp) */
  --accent-deep: #8e0e31;
  --accent-soft: #f3d9e0;
  --ok: #2c7fb8;              /* structural blue (matches CDC layer) */
  --shadow: 0 6px 24px rgba(20, 24, 30, 0.13), 0 1px 3px rgba(20, 24, 30, 0.08);
  --radius: 13px;
  --sans: "Inter", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, "SF Mono", "Cascadia Mono", Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font-family: var(--sans);
  color: var(--ink);
  background: #eceff2;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

#map {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

/* deck.gl canvas sits above maplibre; let map controls underneath breathe */
.maplibregl-ctrl-bottom-right { margin-bottom: 4px; }

/* --- Title card --------------------------------------------------------- */
#titlecard {
  position: absolute;
  top: 18px;
  left: 18px;
  max-width: 380px;
  padding: 16px 18px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  z-index: 5;
}
#titlecard h1 {
  margin: 0 0 6px;
  font-size: 18px;
  line-height: 1.25;
  font-weight: 700;
}
#subtitle {
  margin: 0;
  font-size: 12.5px;
  color: var(--muted);
  line-height: 1.4;
}
.view-presets {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 11px;
}
.presets-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
  margin-right: 2px;
}
.mini-btn {
  padding: 5px 11px;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--ink);
  background: #eef1f4;
  border: 1px solid var(--panel-border);
  border-radius: 7px;
  cursor: pointer;
  transition: all 0.15s ease;
}
.mini-btn:hover { background: var(--accent); color: #fff; border-color: var(--accent); }

/* --- Data-vintage stamp (Stage 6) --------------------------------------- */
#vintage-stamp {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-top: 13px;
  padding-top: 11px;
  border-top: 1px solid var(--hair);
}
.vintage-dot {
  flex: 0 0 auto;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--ok);
  box-shadow: 0 0 0 3px rgba(44, 127, 184, 0.16);
}
.vintage-text { display: flex; flex-direction: column; line-height: 1.25; }
.vintage-line {
  font-size: 11px;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 600;
}
.vintage-line b {
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0;
  text-transform: none;
  color: var(--ink);
}
.vintage-sub { font-size: 10.5px; color: var(--muted); margin-top: 1px; }

/* --- Surface toggle (the centerpiece interaction) ----------------------- */
#surface-toggle {
  position: absolute;
  top: 18px;
  right: 18px;
  z-index: 6;
  padding: 12px 12px 14px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  text-align: center;
}
.toggle-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 8px;
}
.seg {
  display: flex;
  gap: 6px;
  background: #eef1f4;
  padding: 5px;
  border-radius: 10px;
}
.seg-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-width: 120px;
  padding: 9px 14px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  cursor: pointer;
  transition: all 0.15s ease;
  color: var(--muted);
}
.seg-btn:hover { background: rgba(0, 0, 0, 0.04); }
.seg-btn.active {
  background: #fff;
  border-color: var(--accent);
  color: var(--ink);
  box-shadow: 0 1px 6px rgba(179, 18, 63, 0.18);
}
.seg-title { font-size: 15px; font-weight: 800; letter-spacing: 0.03em; }
.seg-btn.active .seg-title { color: var(--accent); }
.seg-sub { font-size: 10.5px; color: var(--muted); }

/* --- Time control ------------------------------------------------------- */
#time-control {
  position: absolute;
  bottom: 86px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 6;
  width: min(620px, calc(100% - 36px));
  padding: 12px 16px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.time-row {
  display: flex;
  align-items: center;
  gap: 12px;
}
.time-row.secondary {
  margin-top: 9px;
  justify-content: space-between;
  font-size: 12px;
  color: var(--muted);
}
.play-btn {
  flex: 0 0 auto;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #fff;
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease;
}
.play-btn:hover { background: #8e0e31; }
#slider {
  flex: 1 1 auto;
  accent-color: var(--accent);
  cursor: pointer;
}
#window-label {
  flex: 0 0 auto;
  min-width: 92px;
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  font-size: 15px;
}
.chk-group { display: flex; align-items: center; gap: 16px; }
.chk { display: flex; align-items: center; gap: 7px; cursor: pointer; }
.chk input { accent-color: var(--accent); cursor: pointer; }
#stat-readout { font-variant-numeric: tabular-nums; }

/* --- Legend ------------------------------------------------------------- */
#legend {
  position: absolute;
  bottom: 22px;
  left: 18px;
  z-index: 5;
  padding: 11px 14px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  width: 260px;
}
.legend-title { font-size: 11.5px; font-weight: 600; margin-bottom: 7px; line-height: 1.3; }
#legend-bar {
  height: 13px;
  border-radius: 3px;
  border: 1px solid rgba(0, 0, 0, 0.12);
}
.legend-ticks {
  display: flex;
  justify-content: space-between;
  font-size: 10.5px;
  color: var(--muted);
  margin-top: 3px;
  font-variant-numeric: tabular-nums;
}
.neon-legend {
  margin-top: 9px;
  padding-top: 8px;
  border-top: 1px solid var(--panel-border);
  font-size: 11px;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.neon-legend .dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-right: 5px;
  vertical-align: middle;
}
.neon-legend .dot.detected { background: #d62728; }
.neon-legend .dot.sampled { background: #fff; border: 1.5px solid #888; }
.line-swatch {
  display: inline-block;
  width: 18px;
  height: 0;
  border-top: 3px solid var(--accent);
  margin-right: 5px;
  vertical-align: middle;
}
.neon-legend .swatch {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 2px;
  margin-right: 5px;
  vertical-align: middle;
}
/* CDC + leading-edge swatches mirror config.STAGE5_CATEGORY_COLORS. */
.neon-legend .swatch.insufficient { background: rgba(207, 207, 207, 0.75); border: 1px solid #b8b8b8; }
.neon-legend .swatch.cdc-established { background: rgba(70, 130, 180, 0.55); border: 1px solid #4682b4; }
.neon-legend .swatch.le-norecords { background: rgba(215, 25, 28, 0.4); border: 1.5px solid #d7191c; }
.neon-legend .swatch.le-reported { background: rgba(253, 174, 97, 0.4); border: 1.5px solid #fdae61; }
.hidden { display: none !important; }

/* --- Caption ------------------------------------------------------------ */
#caption {
  position: absolute;
  bottom: 22px;
  right: 18px;
  z-index: 5;
  max-width: 384px;
  padding: 14px 16px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  font-size: 13px;
  line-height: 1.62;
  color: var(--muted);
}
#caption strong { color: var(--ink); }

/* --- Tooltip (custom designed panel, not the stock dark deck.gl box) ----- */
.deck-tooltip {
  font-family: var(--sans) !important;
  font-size: 12px !important;
  color: var(--ink) !important;
  background: rgba(252, 252, 251, 0.97) !important;
  border: 1px solid var(--panel-border) !important;
  border-radius: 9px !important;
  padding: 0 !important;
  box-shadow: var(--shadow) !important;
  max-width: 260px;
}
.lst-tip { padding: 9px 12px; }
.lst-tip .tip-title {
  font-weight: 700;
  font-size: 12.5px;
  letter-spacing: 0.01em;
  margin-bottom: 4px;
  color: var(--ink);
}
.lst-tip .tip-row { color: var(--muted); line-height: 1.45; }
.lst-tip .tip-val { font-family: var(--mono); font-weight: 600; color: var(--ink); }
.lst-tip .tip-accent { color: var(--accent); }
.lst-tip .tip-meta {
  margin-top: 5px;
  padding-top: 5px;
  border-top: 1px solid var(--hair);
  font-size: 10.5px;
  color: var(--muted);
}

/* --- Loading + empty states --------------------------------------------- */
#loading, #empty-state {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 13px 20px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  font-size: 13px;
  color: var(--muted);
}
#empty-state {
  flex-direction: column;
  gap: 3px;
  text-align: center;
}
#empty-state strong { color: var(--ink); font-size: 13.5px; }
.spinner {
  flex: 0 0 auto;
  width: 16px;
  height: 16px;
  border: 2.5px solid var(--accent-soft);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: lst-spin 0.7s linear infinite;
}
@keyframes lst-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .spinner { animation-duration: 2.4s; }
}

/* --- Responsive: reflow the panels on phone-width screens ---------------- */
@media (max-width: 760px) {
  #titlecard {
    position: absolute;
    top: 10px; left: 10px; right: 10px;
    max-width: none;
    padding: 12px 14px;
  }
  #titlecard h1 { font-size: 16px; }
  #vintage-stamp { margin-top: 10px; padding-top: 9px; }
  #surface-toggle {
    top: auto;
    bottom: 168px;
    left: 50%; right: auto;
    transform: translateX(-50%);
    padding: 9px 10px 11px;
  }
  .seg-btn { min-width: 92px; padding: 7px 10px; }
  #time-control { bottom: 12px; width: calc(100% - 20px); padding: 10px 12px; }
  .time-row.secondary { flex-direction: column; align-items: flex-start; gap: 7px; }
  .chk-group { flex-wrap: wrap; gap: 10px 14px; }
  /* On a phone the legend + caption would bury the map; collapse them to keep
     the interaction (toggle + slider) usable. They remain on tablet/desktop. */
  #legend, #caption { display: none; }
}
