/* Layout: a night thermal pass over central Chile; the map is the whole screen, the timeline is a strip-chart recorder along the bottom edge. */
:root {
  color-scheme: dark;
  /* Night pass: blue-biased neutrals, so the amber of fire is the only warm thing on screen */
  --ocean: #070c16;
  --land: #131c2b;
  --land-edge: #26344b;
  --grid: #1a2538;
  --ink: #e8edf5;
  --ink-2: #a7b3c6;
  --ink-3: #8797b3; /* ≥ 4.5:1 on every panel and hover background (WCAG 1.4.3) */
  --band: rgba(9, 14, 25, 0.86);
  /* Fire intensity (FRP), one hue, dark to light = weak to strong (validated, dataviz ordinal check) */
  --frp-1: #9a3d12; /* < 10 MW */
  --frp-2: #c95b17; /* 10–30 */
  --frp-3: #ec8128; /* 30–100 */
  --frp-4: #f9a957; /* 100–300 */
  --frp-5: #ffd9a8; /* ≥ 300 */
  --bar-idle: #33251f;
  --focus: #ffd9a8;
  --font-ui: "Barlow", "Helvetica Neue", Arial, sans-serif;
  --font-display: "Barlow Condensed", "Arial Narrow", "Helvetica Neue", sans-serif;
  --font-data: "Martian Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;
  --gutter-l: max(20px, env(safe-area-inset-left, 0px));
  --gutter-r: max(20px, env(safe-area-inset-right, 0px));
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--ocean);
  color: var(--ink);
  font: 15px/1.4 var(--font-ui);
  overflow: hidden;
}
#map { position: fixed; inset: 0; }
/* Stacking: map (auto) < header (1, lets clicks through) < floating UI (2+). The header comes before the map in the DOM
   (reading order), so everything drawn above the map says so explicitly. Never put the map below 0: the body would catch its clicks. */
/* `particles` layers (layers/particles.js): own canvas above the map, never catches the mouse */
.particles-canvas { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 2; transition: opacity .3s; }
.maplibregl-ctrl-attrib { background: rgba(7, 12, 22, .7) !important; color: var(--ink-3); font: 11px var(--font-ui); }
.maplibregl-ctrl-attrib a { color: var(--ink-2); }

/* ---------- Header: what, where, when ---------- */
.head {
  position: fixed; top: env(safe-area-inset-top, 0px); left: 0; right: 0;
  display: flex; justify-content: space-between; align-items: flex-start; gap: 24px;
  padding: 18px var(--gutter-r) 40px var(--gutter-l);
  background: linear-gradient(to bottom, rgba(7, 12, 22, .94) 0%, rgba(7, 12, 22, .86) 65%, rgba(7, 12, 22, 0));
  /* Header text can sit on the light Topo base map: a dark halo keeps it readable (WCAG 1.4.3) */
  text-shadow: 0 0 3px #070c16, 0 0 8px #070c16;
  pointer-events: none;
  z-index: 1;
}
.title { min-width: 0; }
.wordmark {
  margin: 0; font: 700 26px/1 var(--font-display); letter-spacing: .14em; text-transform: uppercase;
  display: flex; align-items: center; gap: 12px;
}
.wordmark .emblem { flex: none; width: 40px; height: 40px; filter: drop-shadow(0 0 4px #070c16); } /* white on transparent: a dark halo keeps it on the light base map */
.caption { margin: 28px 0 0; color: var(--ink-2); font-size: 15px; line-height: 1.45; }
.caption strong { color: var(--ink); font-weight: 600; }

.readouts { display: flex; gap: 28px; text-align: right; }
.readout dt { color: var(--ink-3); font: 500 12px/1.3 var(--font-ui); letter-spacing: .06em; text-transform: uppercase; }
.readout dt span { text-transform: none; letter-spacing: 0; }
.readout dd { margin: 4px 0 0; font: 500 34px/1 var(--font-data); font-variant-numeric: tabular-nums; }
.readout dd small { font: 500 15px var(--font-ui); color: var(--ink-2); margin-left: 4px; }
.readout .sub { margin-top: 5px; color: var(--ink-3); font: 12px var(--font-ui); }

/* ---------- Story callouts ---------- */
.callout {
  font: 14px/1.35 var(--font-ui); color: var(--ink);
  background: var(--band); border: 1px solid #3a2a1c;
  padding: 10px 12px; border-radius: 6px; max-width: 250px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .45);
}
.callout b { display: block; font: 600 12px var(--font-ui); letter-spacing: .06em; text-transform: uppercase; color: var(--frp-4); margin-bottom: 2px; }
.callout .big { font: 500 22px/1.1 var(--font-data); color: var(--frp-5); }

/* ---------- City labels ---------- */
.city { font: 500 12px var(--font-ui); color: var(--ink-2); text-shadow: 0 0 2px #070c16, 0 0 3px #070c16, 0 0 6px #070c16; letter-spacing: .04em; pointer-events: none; white-space: nowrap; }
.city::before { content: ""; display: inline-block; width: 4px; height: 4px; border-radius: 50%; background: var(--ink-3); margin-right: 6px; vertical-align: middle; }
.grid-label { font: 11px var(--font-data); color: #3b4b66; pointer-events: none; }

/* ---------- Timeline: the strip-chart recorder ---------- */
.timeline {
  position: fixed; z-index: 2; left: 0; right: 0; bottom: 0;
  padding: 14px var(--gutter-r) calc(14px + env(safe-area-inset-bottom, 0px)) var(--gutter-l);
  background: var(--band); border-top: 1px solid var(--grid);
  display: grid; grid-template-columns: auto 1fr; gap: 10px 24px; align-items: end;
}
.clock { min-width: 220px; }
.clock .date { font: 700 46px/0.95 var(--font-display); letter-spacing: .02em; text-transform: uppercase; }
.clock .time { font: 500 15px var(--font-data); color: var(--ink-2); margin-top: 6px; font-variant-numeric: tabular-nums; }
.controls { display: flex; align-items: center; gap: 8px; margin-top: 12px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 34px; min-width: 34px; padding: 0 10px; border-radius: 6px;
  font: 600 13px var(--font-ui); color: var(--ink); background: #172236; border: 1px solid var(--land-edge); cursor: pointer;
}
.btn:hover { background: #1d2b44; }
.btn.play { background: var(--frp-3); border-color: var(--frp-3); color: #1a0c03; min-width: 44px; }
.btn.play:hover { background: var(--frp-4); }
.btn[aria-pressed="true"] { border-color: var(--frp-4); color: var(--frp-5); }
.speed { display: inline-flex; gap: 2px; }
.speed .btn { min-width: 38px; padding: 0 6px; font: 500 12px var(--font-data); }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

.strip { position: relative; min-width: 0; }
.strip svg { display: block; width: 100%; height: 96px; overflow: visible; cursor: pointer; touch-action: none; }
.strip .days { display: grid; grid-template-columns: repeat(14, 1fr); margin-top: 4px; font: 11px var(--font-data); color: var(--ink-3); }
.strip .days span { text-align: center; }
.strip-caption { margin: 4px 0 0; font: 11px var(--font-ui); color: var(--ink-3); }
.keys { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 6px 16px; color: var(--ink-3); font-size: 12px; }
.keys kbd { font: 500 11px var(--font-data); color: var(--ink-2); border: 1px solid var(--land-edge); border-bottom-width: 2px; border-radius: 4px; padding: 1px 5px; margin-right: 4px; background: #111a29; }
.tip {
  position: absolute; pointer-events: none; transform: translate(-50%, -100%);
  background: #0f1828; border: 1px solid var(--land-edge); border-radius: 4px; padding: 4px 8px;
  font: 12px var(--font-ui); color: var(--ink); white-space: nowrap;
}

/* ---------- Episode row ---------- */
.episode-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 32px; }
.episode-row .episode-pick { margin-top: 0; }

/* ---------- Episode selector ---------- */
.episode-pick { display: inline-flex; align-items: center; gap: 8px; margin-top: 10px; font: 600 11px var(--font-ui);
  letter-spacing: .06em; text-transform: uppercase; color: var(--ink-3); pointer-events: auto; }
.episode-select { min-height: 28px; pointer-events: auto; font: 500 13px var(--font-ui); letter-spacing: 0; text-transform: none; color: var(--ink);
  background: #172236; border: 1px solid var(--land-edge); border-radius: 6px; padding: 4px 8px; }

/* ---------- Scope: whole area or visible area ---------- */
.scope { margin: 22px 0 0; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; font-size: 13px; color: var(--ink-3); }
.scope button { pointer-events: auto; } /* only the button catches clicks: the line itself lets the map through */
.scope.visible-area #scope-text { color: var(--frp-4); }
.scope button {
  font: 600 12px var(--font-ui); color: var(--ink); background: #172236; border: 1px solid var(--land-edge);
  border-radius: 6px; padding: 3px 8px; cursor: pointer;
}
.scope button:hover { background: #1d2b44; }

/* ---------- Base map picker ---------- */
.basemap-switch { display: flex; gap: 4px; margin-bottom: 10px; }
.basemap-switch button {
  flex: 1; padding: 5px 0; border-radius: 6px; border: 1px solid var(--grid); background: transparent;
  color: var(--ink-2); font: 600 12px var(--font-ui); cursor: pointer;
}
.basemap-switch button:hover { background: #1d2b44; }
.basemap-switch button[aria-pressed="true"] { background: #1d2b44; color: var(--ink); border-color: var(--ink-2); }
.basemap-switch button:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }

.alert-icon { width: 13px; height: 13px; flex: none; }
.popup-msg { margin: 4px 0; font-size: 12px; max-width: 240px; }
#alerts-list .none { color: var(--ink-3); padding: 8px; font-size: 13px; }
.alert-mark { position: relative; width: 0; height: 0; display: none; }
body.alert-labels .alert-mark { display: block; }
.alert-mark .halo { position: absolute; left: calc(-1 * var(--r, 24px)); top: calc(-1 * var(--r, 24px)); width: calc(2 * var(--r, 24px)); height: calc(2 * var(--r, 24px)); border-radius: 50%; padding: 0;
  background: none; border: 2px solid var(--c); box-shadow: 0 0 14px var(--c); cursor: pointer; opacity: .9; }
.alert-mark.risk-high .halo { border-width: 1.5px; }
.alert-mark .label { position: absolute; left: 30px; top: -10px; white-space: nowrap; font: 600 12px var(--font-ui);
  color: var(--ink); background: var(--band); border: 1px solid var(--c); border-radius: 4px; padding: 2px 6px; pointer-events: none; }

/* ---------- Status badge ---------- */
.status {
  position: fixed; z-index: 2; left: 50%; transform: translateX(-50%); top: calc(14px + env(safe-area-inset-top, 0px));
  margin: 0; padding: 4px 10px; border-radius: 999px;
  background: var(--band); border: 1px solid var(--grid); color: var(--ink-3); font: 12px var(--font-ui);
}
.status.warn { color: var(--frp-4); border-color: #4a3420; }

/* ---------- Map unavailable ---------- */
.map-error {
  position: fixed; z-index: 2; left: 50%; top: 45%; transform: translate(-50%, -50%); margin: 0;
  max-width: 420px; text-align: center; color: var(--ink-2); font-size: 15px;
  background: var(--band); border: 1px solid #4a3420; border-radius: 8px; padding: 16px 18px;
}
.map-error b { display: block; color: var(--frp-4); margin-bottom: 4px; }

@media (max-width: 760px) {
  .head { flex-direction: column; gap: 12px; padding-top: 14px; padding-bottom: 28px; }
  .wordmark { font-size: 22px; }
  .caption { font-size: 13px; }
  .readouts { text-align: left; gap: 28px; }
  .readout dd { font-size: 26px; }
  .readout .sub { font-size: 11px; }
  .speed, .keys { display: none; }
  .timeline { grid-template-columns: 1fr; gap: 8px; padding-top: 10px; }
  .clock { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-width: 0; }
  .clock .date { font-size: 26px; white-space: nowrap; }
  .clock .time { font-size: 12px; margin-top: 2px; }
  .controls { margin-top: 0; gap: 6px; }
  .strip svg { height: 72px; }
  .strip .days { font-size: 10px; }
  .strip-caption { font-size: 10px; }
  .status { display: none; }
}

.maplibregl-popup-content { background: #0f1828; color: var(--ink); border: 1px solid var(--land-edge); font: 13px var(--font-ui); }
.maplibregl-popup-tip { border-top-color: #0f1828 !important; border-bottom-color: #0f1828 !important; }
.maplibregl-popup-close-button { color: var(--ink-2); }

/* ---------- Story marks on the strip ---------- */
.strip-mark { position: absolute; top: -16px; font: 600 11px var(--font-ui); letter-spacing: .06em; text-transform: uppercase; white-space: nowrap; }
.strip-mark.left { transform: translateX(calc(-100% - 6px)); }
.strip-mark.right { transform: translateX(6px); }
.strip-mark.tail { top: 36px; transform: translateX(-50%); color: var(--ink-3); font-weight: 500; letter-spacing: .04em; text-transform: none; }
/* Mobile: room above the bars for the Peak label (it ran over the clock); the "Last detection" label and the caption
   give way (its dashed line and "No detections · burned area only" still say it) */
@media (max-width: 760px) {
  .strip { margin-top: 16px; }
  .strip-mark { font-size: 10px; }
  .strip-mark.left, .strip-caption { display: none; }
}
.strip .days small { font-size: inherit; }
@media (max-width: 760px) { .strip .days small { display: none; } }

/* ---------- Mobile pass: compact header, visible map, panel as a bottom sheet ---------- */
@media (max-width: 760px) {
  .head { padding: 10px var(--gutter-r) 18px var(--gutter-l); gap: 22px; }
  .wordmark { font-size: 20px; }
  .wordmark .emblem { width: 32px; height: 32px; }
  .caption { font-size: 12px; margin-top: 16px; }
  .caption strong { display: none; }
  .caption br { display: none; }
  .episode-row { margin-top: 20px; gap: 8px; }
  .episode-pick { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; } /* label kept for screen readers */
  .episode-select { font-size: 12px; max-width: 220px; padding: 3px 6px; }
  .scope { margin-top: 14px; font-size: 11px; }
  .readouts { gap: 18px; }
  .readout dt { font-size: 10px; }
  .readout dd { font-size: 22px; margin-top: 2px; }
  .readout .sub { display: none; }

}

/* ---------- Alert type filters ---------- */
.alert-filters button { display: inline-flex; align-items: center; gap: 4px; font: 600 11px var(--font-ui); color: var(--ink-2);
  background: #172236; border: 1px solid var(--land-edge); border-radius: 999px; padding: 3px 9px; cursor: pointer; }
.alert-filters button svg { width: 12px; height: 12px; color: var(--c, var(--ink-2)); }
.alert-filters button[aria-pressed="true"] { color: var(--ink); border-color: var(--c, var(--frp-4)); }

/* ---------- Demo disclaimer (W5-F2) ---------- */
.demo-banner {
  position: fixed; left: 50%; transform: translateX(-50%); top: calc(48px + env(safe-area-inset-top, 0px)); z-index: 8;
  display: flex; align-items: center; gap: 12px; max-width: min(620px, calc(100vw - 32px));
  padding: 8px 10px 8px 14px; border-radius: 8px; background: var(--band); border: 1px solid #4a3420;
  color: var(--ink-2); font: 13px var(--font-ui); box-shadow: 0 8px 24px rgba(0, 0, 0, .45);
}
.demo-banner b { color: var(--frp-4); }
.demo-banner button { flex: none; font: 600 12px var(--font-ui); color: #1a0c03; background: var(--frp-3); border: 0; border-radius: 6px; padding: 5px 10px; cursor: pointer; }
@media (max-width: 760px) { .demo-banner { top: auto; bottom: calc(var(--tl-h, 160px) + 64px); font-size: 12px; } }

/* ---------- Alert window: one row per fire, sticky filters, counts ---------- */
.alert-filters { position: sticky; top: 0; z-index: 1; }
.alert-filters .n { font: 500 11px var(--font-data); color: var(--ink); margin-left: 3px; }
#alerts-list { flex: 1 1 auto; min-height: 0; }
#alerts-list .type { display: inline-flex; color: var(--c); }
.alert-mark.hot .halo { border-width: 3px; box-shadow: 0 0 22px var(--c); opacity: 1; }

/* ---------- Timeline fold: clock and controls only ---------- */
.tl-fold svg { transition: transform .15s ease; }
body.tl-folded .tl-fold svg { transform: rotate(180deg); }
body.tl-folded .strip, body.tl-folded .keys { display: none; }
body.tl-folded .timeline { grid-template-columns: 1fr; padding-top: 8px; padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px)); }
body.tl-folded .clock { display: flex; align-items: center; gap: 18px; }
body.tl-folded .clock > div:first-child { display: flex; align-items: baseline; gap: 10px; }
body.tl-folded .clock .date { font-size: 26px; }
body.tl-folded .clock .time { margin-top: 0; }
body.tl-folded .controls { margin-top: 0; }
@media (max-width: 760px) {
  body.tl-folded .clock .date { font-size: 20px; }
}

/* ---------- Map popups: readable, never taller than the screen ---------- */
.maplibregl-popup-content { max-height: min(50vh, 380px); overflow: auto; padding: 10px 26px 10px 12px; box-shadow: 0 8px 24px rgba(0, 0, 0, .45); }
.maplibregl-popup-content > strong { display: block; margin-bottom: 6px; font: 600 12px var(--font-ui); letter-spacing: .06em; text-transform: uppercase; }
.popup-id { color: var(--ink-3); font-family: var(--font-data); letter-spacing: 0; }
table.popup { border-collapse: collapse; font-size: 12px; width: 100%; }
table.popup th { text-align: left; font-weight: 400; color: var(--ink-3); padding: 2px 12px 2px 0; white-space: nowrap; vertical-align: top; }
table.popup td { color: var(--ink); padding: 2px 0; overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }
@media (max-width: 760px) { .maplibregl-popup-content { max-height: 40vh; } }

/* ---------- Alert rows: where, how many people, how bad ---------- */
#alerts-list { gap: 2px; }
#alerts-list .fire-head { gap: 3px; padding: 7px 8px 7px 10px; }
#alerts-list .r1 { display: flex; align-items: baseline; gap: 6px; min-width: 0; }
#alerts-list .place { font: 600 14px var(--font-ui); color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#alerts-list .fid { font: 11px var(--font-data); color: var(--ink-3); }
#alerts-list .badge { margin-left: auto; flex: none; font: 600 10px var(--font-ui); font-style: normal; letter-spacing: .06em; text-transform: uppercase;
  color: var(--risk); border: 1px solid color-mix(in srgb, var(--risk) 45%, transparent); border-radius: 999px; padding: 1px 7px; }
#alerts-list .r2 { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--ink-2); }
#alerts-list .what { flex: 1; min-width: 0; }
#alerts-list .ppl { font: 500 15px var(--font-data); color: var(--ink); font-variant-numeric: tabular-nums; }
#alerts-list .types { display: inline-flex; gap: 4px; flex: none; }
#alerts-list .r3 { font-size: 11px; color: var(--ink-3); }

/* ---------- Timeline fold: a small tab on the top edge ---------- */
.tl-fold { position: absolute; left: 50%; top: -24px; transform: translateX(-50%); width: 44px; height: 24px; padding: 0;
  display: inline-flex; align-items: center; justify-content: center; cursor: pointer;
  color: var(--ink-2); background: var(--band); border: 1px solid var(--grid); border-bottom: 0; border-radius: 8px 8px 0 0; }
.tl-fold:hover { color: var(--ink); }

/* ---------- Alerts: one panel, list or one fire's detail ---------- */
.alert-filters { background: none; border: 0; border-radius: 0; padding: 8px 10px 4px; }
#alerts-list { background: none; border: 0; border-radius: 0; max-height: none; flex: 1 1 auto; min-height: 0; padding: 4px 6px 8px; gap: 1px; }
.alerts.detail .alert-filters, .alerts.detail #alerts-list { display: none; }
.alerts:not(.detail) .alerts-detail { display: none; }
#alerts-list .fire-row { position: relative; display: grid; gap: 3px; width: 100%; padding: 8px 26px 8px 8px; border: 0; border-radius: 6px;
  background: none; color: var(--ink); text-align: left; font: 13px var(--font-ui); cursor: pointer; }
#alerts-list .fire-row:hover, #alerts-list .fire-row:focus-visible { background: #172236; }
#alerts-list .fire-row .go { position: absolute; right: 8px; top: 50%; transform: translateY(-50%); color: var(--ink-3); }
#alerts-list .fire-row:hover .go { color: var(--ink); }
.badge { flex: none; font: 600 10px var(--font-ui); font-style: normal; letter-spacing: .06em; text-transform: uppercase;
  color: var(--risk); border: 1px solid color-mix(in srgb, var(--risk) 45%, transparent); border-radius: 999px; padding: 1px 7px; }
#alerts-list .badge { margin-left: auto; }

.alerts-detail { overflow: auto; min-height: 0; padding: 8px 12px 14px; display: grid; gap: 14px; align-content: start; }
.alerts-detail .back { justify-self: start; display: inline-flex; align-items: center; gap: 4px; padding: 4px 8px 4px 4px; margin-left: -4px;
  border: 0; border-radius: 6px; background: none; color: var(--ink-2); font: 600 12px var(--font-ui); cursor: pointer; }
.alerts-detail .back:hover { color: var(--ink); background: #172236; }
.alerts-detail .d-head { display: flex; align-items: center; gap: 8px; }
.alerts-detail h2 { margin: 0; font: 600 18px/1.2 var(--font-ui); color: var(--ink); flex: 1; min-width: 0; }
.alerts-detail .fid { font: 12px var(--font-data); color: var(--ink-3); }
.alerts-detail h3 { margin: 0 0 6px; font: 600 11px var(--font-ui); letter-spacing: .06em; text-transform: uppercase; color: var(--ink-3); }
.alerts-detail .rings { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 0; }
.alerts-detail .rings dt { font-size: 11px; color: var(--ink-3); }
.alerts-detail .rings dd { margin: 2px 0 0; font: 500 17px var(--font-data); color: var(--ink); font-variant-numeric: tabular-nums; }
.alerts-detail .rings div:nth-child(2) dd { color: var(--frp-5); }
.d-alerts { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.d-alerts li { display: flex; gap: 8px; align-items: flex-start; }
.d-alerts li > svg { width: 14px; height: 14px; margin-top: 2px; color: var(--c); flex: none; }
.d-alerts b { font: 600 13px var(--font-ui); color: var(--ink); margin-right: 4px; }
.d-alerts p { margin: 3px 0 2px; font-size: 13px; color: var(--ink-2); }
.d-alerts small { font-size: 11px; color: var(--ink-3); }
.alerts-detail .facts { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; margin: 0; font-size: 12px; }
.alerts-detail .facts div { display: contents; }
.alerts-detail .facts dt { color: var(--ink-3); }
.alerts-detail .facts dd { margin: 0; color: var(--ink); font-variant-numeric: tabular-nums; }
.alerts-detail .none { margin: 0; font-size: 13px; color: var(--ink-3); }

/* ---------- Map panel: one panel, two tabs (Layers, Alerts) ----------
   Desktop: a column on the right, under the header figures, above the timeline (heights measured in app.js).
   Mobile: the same panel as a bottom sheet above the timeline. Spacing on a 4 px scale:
   4–8 inside a layer, 14 + a rule between groups, so each theme reads as its own block. */
.panel {
  position: fixed; z-index: 3; right: var(--gutter-r); width: 320px;
  top: calc(var(--figures-h, 110px) + 24px); bottom: calc(var(--tl-h, 170px) + 16px);
  display: flex; flex-direction: column;
  background: #0b111d; /* opaque: text never sits on the map */ border: 1px solid var(--grid); border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .35); overflow: hidden;
}
.panel.folded { bottom: auto; }
.panel-bar { flex: none; display: flex; align-items: center; gap: 4px; padding: 6px; border-bottom: 1px solid var(--grid); }
.panel.folded .panel-bar { border-bottom: 0; }
.tabs { flex: 1; display: flex; gap: 4px; min-width: 0; }
.tabs [role="tab"] {
  flex: 1; min-height: 34px; padding: 0 10px; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: 600 12px var(--font-ui); letter-spacing: .06em; text-transform: uppercase; white-space: nowrap;
  color: var(--ink-2); background: none; border: 1px solid transparent; border-radius: 6px; cursor: pointer;
}
.tabs [role="tab"]:hover { color: var(--ink); background: #172236; }
/* Selected = filled + an amber underline, not color alone */
.tabs [role="tab"][aria-selected="true"] { color: var(--ink); background: #1d2b44; border-color: var(--land-edge); box-shadow: inset 0 -2px 0 var(--frp-3); }
.panel.folded .tabs [role="tab"][aria-selected="true"] { box-shadow: none; background: #172236; }
.tabs .count {
  font: 500 11px var(--font-data); letter-spacing: 0; text-transform: none; color: var(--ink);
  padding: 1px 7px; border-radius: 999px; background: #172236; border: 1px solid var(--land-edge);
}
.tabs .has-critical .count { background: #3a0d10; border-color: #a50f15; color: #ffb4a8; }
.panel-fold {
  flex: none; width: 34px; height: 34px; display: inline-flex; align-items: center; justify-content: center;
  color: var(--ink-2); background: none; border: 0; border-radius: 6px; cursor: pointer;
}
.panel-fold:hover { color: var(--ink); background: #172236; }
.panel-fold svg { transition: transform .15s ease; }
.panel.folded .panel-fold svg { transform: rotate(180deg); }
.panel-body { flex: 1 1 auto; min-height: 0; overflow: auto; overscroll-behavior: contain; }
.panel-body[hidden] { display: none; }

/* Layers tab: one block per theme */
#tp-layers { padding: 0 18px 20px; }
.group { margin: 0; padding: 18px 0 0; border: 0; min-width: 0; }
.group + .group, #layer-list > .group, #layer-list + .group { margin-top: 18px; border-top: 1px solid var(--grid); }
.group > legend { float: left; width: 100%; padding: 0; margin: 0 0 12px; font: 600 11px var(--font-ui); letter-spacing: .08em; text-transform: uppercase; color: var(--ink-2); }
.group > legend + * { clear: both; }
.basemap-switch { display: flex; gap: 4px; margin: 0; }
.layer-row + .layer-row { margin-top: 10px; }
label.layer { display: grid; grid-template-columns: 16px 1fr; gap: 10px; align-items: start; min-height: 24px; padding: 2px 0; cursor: pointer; font: 13px/1.35 var(--font-ui); color: var(--ink); }
label.layer input { width: 16px; height: 16px; margin: 1px 0 0; accent-color: var(--frp-3); cursor: pointer; }
label.layer small { display: block; margin-top: 2px; font-size: 11px; color: var(--ink-3); }
label.layer.loading span::after { content: " · loading…"; font-size: 11px; color: var(--frp-4); }
/* Legend of a ticked layer, tucked under its name */
.layer-legend { margin: 6px 0 4px 7px; padding: 2px 0 2px 18px; border-left: 1px solid var(--grid); }
.legend-items { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; font: 12px/1.3 var(--font-ui); color: var(--ink-2); }
.legend-items li { display: flex; align-items: center; gap: 8px; }
.legend-items i { flex: none; }
.legend-items .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--c); }
.legend-items .ring { width: 11px; height: 11px; border-radius: 50%; border: 2px solid var(--c); }
.legend-items .area { width: 12px; height: 9px; border-radius: 2px; background: var(--c); opacity: .8; }
.legend-items .line { width: 14px; height: 0; border-top: 2px solid var(--c); }
.legend-items .arrow { width: 12px; height: 12px; display: inline-flex; color: var(--c); }
.legend-items .arrow svg { width: 12px; height: 12px; }
.legend-note { margin: 4px 0 0; font-size: 11px; font-style: italic; color: var(--ink-3); }

/* Alerts tab: summary + controls, then the list (or one fire's detail) */
.alerts-head { display: grid; gap: 12px; padding: 16px 18px; border-bottom: 1px solid var(--grid); }
.alerts-summary { margin: 0; font-size: 13px; color: var(--ink-2); }
.alerts-summary:empty { display: none; }
.alert-filters { display: flex; flex-wrap: wrap; gap: 6px; width: auto; padding: 0; background: none; border: 0; border-radius: 0; position: static; }
.alerts.detail .alerts-head { display: none; }
#alerts-list { list-style: none; margin: 0; padding: 8px 10px 14px; display: grid; gap: 4px; }
#alerts-list .none { padding: 8px; font-size: 13px; color: var(--ink-3); }
.alerts-detail { padding: 14px 18px 20px; overflow: visible; }

/* Date of the satellite image: bottom left, above the timeline */
.sat-badge {
  position: fixed; z-index: 2; left: var(--gutter-l); bottom: calc(var(--tl-h, 170px) + 16px); margin: 0;
  padding: 4px 10px; border-radius: 999px; background: var(--band); border: 1px solid var(--grid);
  color: var(--ink-2); font: 12px var(--font-ui);
}

@media (max-width: 760px) {
  .panel {
    left: 0; right: 0; width: auto; top: auto; bottom: var(--tl-h, 160px); max-height: 55vh;
    border-width: 1px 0 0; border-radius: 12px 12px 0 0; box-shadow: 0 -6px 24px rgba(0, 0, 0, .5);
  }
  .panel-bar { padding: 6px 8px; }
  .panel.folded { bottom: var(--tl-h, 160px); }
  /* The panel bar sits on the timeline's top edge: its fold tab would cover it */
  .tl-fold { display: none; }
  .sat-badge { top: calc(var(--head-h, 170px) + 8px); bottom: auto; }
}

/* ---------- Accessibility (WCAG 2.2 AA) ---------- */
.sr-only {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; border: 0;
}
/* 2.4.1: first Tab stop, visible only when focused */
.skip-link {
  position: fixed; left: var(--gutter-l); top: 8px; z-index: 20; transform: translateY(-200%);
  padding: 8px 12px; border-radius: 6px; background: var(--frp-5); color: #1a0c03; font: 600 14px var(--font-ui); text-decoration: none;
}
.skip-link:focus { transform: none; }
.episode-go {
  min-height: 28px; pointer-events: auto; font: 600 12px var(--font-ui); color: var(--ink); background: #172236;
  border: 1px solid var(--land-edge); border-radius: 6px; padding: 3px 10px; cursor: pointer;
}
.episode-go:hover { background: #1d2b44; }
/* 2.5.8: every pointer target at least 24 × 24 px */
.scope button, .alert-filters button, .alerts-detail .back, .basemap-switch button, .demo-banner button, .maplibregl-popup-close-button {
  min-height: 24px; min-width: 24px;
}
.keys-toggle { display: inline-flex; align-items: center; gap: 6px; margin-left: auto; cursor: pointer; color: var(--ink-2); }
.keys-toggle input { accent-color: var(--frp-3); width: 16px; height: 16px; margin: 0; }
/* The chart is a slider: the focus ring goes around the whole strip */
.strip svg:focus-visible { outline: 2px solid var(--focus); outline-offset: 4px; border-radius: 2px; }
.halo:focus-visible { outline-offset: 3px; }
/* 2.3.3 / comfort: no slides or fades for visitors who ask for less motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; scroll-behavior: auto !important; }
}
/* Windows high contrast: keep focus and panel edges visible */
@media (forced-colors: active) {
  :focus-visible { outline: 2px solid CanvasText; }
  .btn[aria-pressed="true"], .basemap-switch button[aria-pressed="true"], .alert-filters button[aria-pressed="true"] { outline: 2px solid Highlight; }
}
