* { box-sizing: border-box; }
html, body, #app {
  height: 100%;
  margin: 0;
  font-family: var(--font-sans);
  background: var(--surface-canvas);
  color: var(--text-primary);
}

#app { display: flex; flex-direction: column; }

.hidden { display: none !important; }

.micro-upper {
  font: var(--text-micro-upper);
  color: var(--text-tertiary);
  letter-spacing: var(--tracking-upper);
  text-transform: uppercase;
  white-space: nowrap;
}

/* ---------------- Toolbar ---------------- */

#toolbar {
  height: var(--toolbar-h);
  flex-shrink: 0;
  background: var(--surface-app);
  border-bottom: 1px solid var(--border-strong);
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 0 20px;
  overflow-x: auto;
  position: relative;
  z-index: 30;
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  font: var(--text-title);
  font-weight: 800;
  color: var(--smoke-500);
  white-space: nowrap;
  flex-shrink: 0;
}
.brand img { height: 28px; border-radius: 6px; }

.divider {
  width: 1px;
  height: 26px;
  background: var(--border-hairline);
  flex-shrink: 0;
}

.toolbar-group {
  display: flex;
  align-items: center;
  gap: 22px;
  flex-shrink: 0;
}

.toolbar-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 10px;
  padding-left: 20px;
  flex-shrink: 0;
}

/* Segmented control */
.segmented {
  display: inline-flex;
  gap: 4px;
  background: var(--surface-panel);
  padding: 4px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-hairline);
  flex-shrink: 0;
}
.seg {
  padding: 6px 14px;
  border-radius: 4px;
  border: none;
  cursor: pointer;
  font: var(--text-small-medium);
  background: transparent;
  color: var(--text-secondary);
  transition: background var(--duration-fast) var(--ease-standard),
    color var(--duration-fast) var(--ease-standard);
}
.seg:hover { color: var(--text-primary); }
.seg.active { background: var(--surface-accent); color: var(--text-on-accent); }

/* Layers button (mobile-only trigger -- see #layersBtn media query below).
   Hidden by ID rather than the .layers-btn class so it reliably beats the
   later, equal-specificity .icon-btn{display:flex} base rule. */
.layers-btn { position: relative; flex-shrink: 0; }
#layersBtn { display: none; }
.layers-badge {
  position: absolute;
  top: 1px;
  right: 0;
  min-width: 13px;
  height: 13px;
  padding: 0 3px;
  box-sizing: border-box;
  border-radius: 7px;
  background: var(--surface-accent);
  color: var(--text-on-accent);
  font: var(--text-data-sm);
  line-height: 13px;
  text-align: center;
}

/* Settings/Layers bottom-sheet-on-mobile menus. On desktop these render as a
   floating dropdown anchored under the toolbar; the mobile media query below
   turns them into a docked bottom sheet instead. */
.settings { position: relative; flex-shrink: 0; }
.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 1300;
}
.sheet-panel {
  position: fixed;
  top: calc(var(--toolbar-h) + 6px);
  right: 16px;
  width: 244px;
  background: var(--surface-app);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-float);
  padding: 16px;
  z-index: 1301;
  display: flex;
  flex-direction: column;
  gap: 18px;
}
.sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.sheet-title {
  font: var(--text-micro-upper);
  color: var(--text-secondary);
  letter-spacing: var(--tracking-upper);
}
.sheet-close {
  width: 26px;
  height: 26px;
  background: transparent;
  border-color: transparent;
  color: var(--text-tertiary);
}
.sheet-body { display: flex; flex-direction: column; gap: 18px; }
.settings-group { display: flex; flex-direction: column; gap: 8px; }
.settings-row { display: flex; align-items: center; gap: 8px; }
.settings-row .sw-select { max-width: none; flex: 1; }

.theme-control {
  display: flex;
  gap: 4px;
  background: var(--surface-panel);
  padding: 4px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-hairline);
}
.theme-opt {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 8px 4px;
  border-radius: 4px;
  border: none;
  cursor: pointer;
  font: var(--text-small-medium);
  background: transparent;
  color: var(--text-secondary);
  transition: background var(--duration-fast) var(--ease-standard),
    color var(--duration-fast) var(--ease-standard);
}
.theme-opt:hover { color: var(--text-primary); }
.theme-opt.active { background: var(--surface-accent); color: var(--text-on-accent); }

/* Toggle */
.toggle {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  font: var(--text-body);
  color: var(--text-primary);
  white-space: nowrap;
}
.toggle input { position: absolute; opacity: 0; width: 0; height: 0; }
.toggle-box {
  width: 16px;
  height: 16px;
  border-radius: 4px;
  display: inline-flex;
  flex-shrink: 0;
  background: transparent;
  border: 1px solid var(--border-strong);
  transition: background var(--duration-fast) var(--ease-standard),
    border-color var(--duration-fast) var(--ease-standard);
}
.toggle input:checked + .toggle-box {
  background: var(--surface-accent);
  border-color: var(--surface-accent);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 10 10'%3E%3Cpath d='M1 5l3 3 5-6' stroke='%231a1206' stroke-width='1.6' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: center;
}
.toggle input:focus-visible + .toggle-box {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

/* Opacity slider group */
.opacity-group {
  display: flex;
  align-items: center;
  gap: 12px;
  white-space: nowrap;
  transition: opacity var(--duration-base) var(--ease-standard);
}
.opacity-group.disabled { opacity: 0.4; pointer-events: none; }
.opacity-val {
  font: var(--text-data-sm);
  color: var(--text-secondary);
  width: 40px;
  text-align: right;
}

/* Range slider */
.sw-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100px;
  height: 4px;
  border-radius: 2px;
  background: var(--ink-4);
  outline: none;
  cursor: pointer;
}
.sw-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--fog-1);
  border: 2px solid var(--smoke-500);
  cursor: pointer;
}
.sw-slider::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--fog-1);
  border: 2px solid var(--smoke-500);
  cursor: pointer;
}

/* Live status (satellite) */
.live-status {
  display: flex;
  align-items: center;
  gap: 10px;
  font: var(--text-data-sm);
  color: var(--text-secondary);
  white-space: nowrap;
}
.live-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--aqi-good);
  box-shadow: 0 0 8px var(--aqi-good);
}

/* Buttons */
.btn-ghost,
.btn-secondary {
  display: inline-flex;
  align-items: center;
  border-radius: var(--radius-sm);
  padding: 6px 12px;
  font: var(--text-small-medium);
  cursor: pointer;
  transition: background var(--duration-fast) var(--ease-standard),
    border-color var(--duration-fast) var(--ease-standard),
    color var(--duration-fast) var(--ease-standard);
  white-space: nowrap;
}
.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid transparent;
}
.btn-ghost:hover { color: var(--text-primary); }
.btn-secondary {
  background: var(--surface-panel-raised);
  color: var(--text-primary);
  border: 1px solid var(--border-hairline);
}
.btn-secondary:hover { border-color: var(--border-strong); }

/* Timezone select */
.sw-select {
  background: var(--surface-panel-raised);
  color: var(--text-primary);
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  font: var(--text-small-medium);
  cursor: pointer;
  max-width: 240px;
}

.tz-hint {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--surface-panel-raised);
  color: var(--smoke-500);
  font-size: 12px;
  cursor: help;
}

/* ---------------- Map ---------------- */

#map { flex: 1; position: relative; min-height: 0; }
.leaflet-container { background: var(--ink-0); }
.leaflet-control-attribution { display: none; }

/* Fire perimeter name labels -- plain text, no tooltip chrome. Visibility at
   low zoom is handled in app.js (open/closeTooltip per layer, not CSS) since
   that's the tooltip's own supported on/off mechanism rather than fighting
   Leaflet's default display for the underlying element. */
.fire-label.fire-label {
  background: transparent;
  border: none;
  box-shadow: none;
  padding: 0;
  font-size: 11px;
  font-weight: 700;
  color: #ff4d2e;
  -webkit-text-stroke: 3px #fff;
  paint-order: stroke fill;
  pointer-events: none;
}
.fire-label::before { display: none; }

/* Restyled Leaflet zoom control as icon buttons */
.leaflet-control-zoom { border: none !important; box-shadow: none !important; }
.leaflet-control-zoom a {
  width: 32px;
  height: 32px;
  line-height: 30px;
  background: var(--surface-panel-raised);
  color: var(--text-secondary);
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-sm) !important;
  margin-bottom: 6px;
  font-size: 18px;
  transition: color var(--duration-fast) var(--ease-standard);
}
.leaflet-control-zoom a:hover {
  background: var(--surface-panel-raised);
  color: var(--text-primary);
}

.map-attribution {
  position: absolute;
  bottom: 4px;
  right: 8px;
  z-index: 10;
  font: var(--text-data-sm);
  color: rgba(255, 255, 255, 0.4);
}

/* ---------------- Timeline transport ---------------- */

.timeline {
  position: absolute;
  bottom: 22px;
  left: 50%;
  transform: translateX(-50%);
  width: min(720px, calc(100% - 48px));
  background: var(--surface-panel);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-float);
  padding: 14px 18px 16px;
  z-index: 1200;
  transition: opacity var(--duration-base) var(--ease-standard);
}
.timeline.disabled { opacity: 0.5; pointer-events: none; }

.tl-head {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 13px;
}
.tl-transport { display: flex; align-items: center; gap: 8px; }

.icon-btn {
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-panel-raised);
  color: var(--text-secondary);
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--duration-fast) var(--ease-standard),
    color var(--duration-fast) var(--ease-standard);
}
.icon-btn:hover { color: var(--text-primary); }
.icon-btn-lg { width: 40px; height: 40px; }
.icon-btn.active {
  background: var(--surface-accent);
  color: var(--text-on-accent);
  border-color: var(--surface-accent);
}
.icon-btn.active:hover { color: var(--text-on-accent); }

.tl-time { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.tl-clock { font: var(--text-data-lg); color: var(--text-primary); white-space: nowrap; }

.tl-meta {
  margin-left: auto;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
  text-align: right;
  min-width: 0;
}
.tl-source {
  font: var(--text-data-sm);
  color: var(--text-tertiary);
  white-space: nowrap;
}
.tl-source.older-forecast { color: var(--smoke-400); cursor: help; }
.tl-counter {
  font: var(--text-data-sm);
  color: var(--text-tertiary);
  white-space: nowrap;
}

.tl-track {
  position: relative;
  height: 34px;
  cursor: pointer;
  touch-action: none;
}
.tl-track-base {
  position: absolute;
  top: 7px;
  left: 0;
  right: 0;
  height: 4px;
  border-radius: 2px;
  background: var(--ink-4);
}
.tl-fill {
  position: absolute;
  top: 7px;
  left: 0;
  height: 4px;
  border-radius: 2px;
  background: var(--surface-accent);
}
.tl-tick {
  position: absolute;
  top: 4px;
  width: 1px;
  height: 10px;
  transform: translateX(-0.5px);
}
.tl-tick.past { background: var(--smoke-600); }
.tl-tick.future { background: var(--ink-5); }
.tl-playhead {
  position: absolute;
  top: 9px;
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: var(--fog-1);
  border: 3px solid var(--smoke-500);
  transform: translate(-50%, -50%);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.5);
}
.tl-label {
  position: absolute;
  top: 19px;
  font: var(--text-data-sm);
  color: var(--text-tertiary);
  white-space: nowrap;
}
.tl-label.now { color: var(--smoke-400); }

@keyframes sw-spin { to { transform: rotate(360deg); } }

/* ---------------- Map loading overlay ---------------- */
/* Shown while satellite frames are being preloaded (see loadSatelliteMeta /
   preloadSatelliteFrames in app.js) -- covers the whole map, including the
   zoom control, since scrubbing or zooming mid-fetch is what caused the
   sluggishness this is meant to fix. */

.map-loading {
  position: absolute;
  inset: 0;
  z-index: 1300;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(10, 12, 15, 0.35);
}
.map-loading-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  background: var(--surface-panel);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-float);
  padding: 22px 28px;
}
.map-spinner {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 3px solid var(--ink-4);
  border-top-color: var(--smoke-500);
  animation: sw-spin 0.8s linear infinite;
}
.map-loading-title { font: var(--text-subtitle); color: var(--text-primary); }
.map-loading-sub { font: var(--text-data-sm); color: var(--text-tertiary); }

.timeline.loading { opacity: 0.5; pointer-events: none; }

/* Mobile-only timeline bits: hidden/inert on desktop, activated below the
   breakpoint. Kept in normal CSS (not the media query) so their base state
   is a harmless no-op if that ever changes. */
.tl-chevron { display: none; color: var(--text-tertiary); flex-shrink: 0; }
.tl-expand-wrap { display: none; }

/* ---------------- Mobile layout ---------------- */
/* Below this width the toolbar collapses to brand + view switch + two icon
   buttons (Layers, Settings), the per-layer controls move into a bottom
   sheet (see #layersSheetBody reparenting in app.js), Settings becomes a
   sheet too, and the floating timeline docks edge-to-edge to the bottom of
   the screen with an expandable section for tick labels and step controls. */
@media (max-width: 680px) {
  .brand-text { display: none; }
  .brand img { height: 24px; }

  .divider { display: none; }

  #toolbar {
    height: auto;
    gap: 8px;
    padding: max(8px, env(safe-area-inset-top)) 10px 8px;
    overflow: visible;
  }

  .segmented { flex: 1; min-width: 0; }
  .seg { flex: 1; text-align: center; padding: 7px 6px; }

  #layersBtn { display: flex; }

  .toolbar-right { padding-left: 0; margin-left: 0; }

  /* ---- bottom sheets (Layers, Settings) ---- */
  .sheet-panel.hidden {
    display: flex !important;
    transform: translateY(110%);
    pointer-events: none;
  }
  .sheet-panel {
    top: auto;
    left: 0;
    right: 0;
    bottom: 0;
    width: auto;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    max-height: 75vh;
    overflow-y: auto;
    padding: 14px 16px calc(16px + env(safe-area-inset-bottom));
    transform: translateY(0);
    transition: transform var(--duration-base) var(--ease-standard);
    box-shadow: 0 -12px 40px -8px rgba(0, 0, 0, 0.6);
  }
  .sheet-backdrop.hidden {
    display: block !important;
    opacity: 0;
    pointer-events: none;
  }
  .sheet-backdrop {
    background: rgba(0, 0, 0, 0.45);
    opacity: 1;
    transition: opacity var(--duration-base) var(--ease-standard);
  }

  /* Layer rows read as a vertical list of settings rows rather than a
     horizontal toolbar strip once they're inside the sheet. */
  .sheet-panel .toolbar-group {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    width: 100%;
    padding: 13px 0;
    border-top: 1px solid var(--border-hairline);
  }
  /* forecastControls/satelliteControls share one slot (only one is ever
     visible at a time), so both -- not just whichever is first in the DOM --
     need the borderless "first row" treatment. */
  #layersSheetBody #forecastControls,
  #layersSheetBody #satelliteControls {
    border-top: none;
    padding-top: 0;
  }
  /* The desktop markup is <input><toggle-box>label (switch-first, so it
     reads well as a compact inline toolbar item); row-reverse gives the
     conventional label-left/switch-right order for a full-width sheet row
     without touching the shared HTML. */
  .sheet-panel .toggle { flex-direction: row-reverse; justify-content: space-between; width: 100%; }
  .sheet-panel .opacity-group,
  .sheet-panel .live-status { width: 100%; }
  .sheet-panel .sw-slider { flex: 1; width: auto; }

  /* Toggle switches read better as a pill switch than a checkbox once
     they're full-width sheet rows. */
  .sheet-panel .toggle-box {
    width: 38px;
    height: 22px;
    border-radius: var(--radius-pill);
    position: relative;
    flex-shrink: 0;
    background: var(--ink-4);
    border: none;
  }
  .sheet-panel .toggle-box::after {
    content: "";
    position: absolute;
    top: 2px;
    left: 2px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--fog-1);
    transition: transform var(--duration-fast) var(--ease-standard);
  }
  .sheet-panel .toggle input:checked + .toggle-box {
    background-image: none;
  }
  .sheet-panel .toggle input:checked + .toggle-box::after {
    transform: translateX(16px);
  }

  /* ---- docked, expandable timeline ---- */
  .timeline {
    left: 0;
    right: 0;
    bottom: 0;
    width: auto;
    transform: none;
    border-radius: 0;
    border-left: none;
    border-right: none;
    border-bottom: none;
    padding: 10px 14px calc(10px + env(safe-area-inset-bottom));
    box-shadow: 0 -10px 30px -10px rgba(0, 0, 0, 0.55);
  }
  .tl-head { cursor: pointer; }
  .tl-head:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 2px; }
  #tlBack, #tlFwd, .tl-head #tlSource { display: none; }
  .tl-chevron {
    display: block;
    transition: transform var(--duration-base) var(--ease-standard);
  }
  .timeline.expanded .tl-chevron { transform: rotate(180deg); }

  .timeline:not(.expanded) .tl-labels { opacity: 0; pointer-events: none; }
  .tl-labels { transition: opacity var(--duration-base) var(--ease-standard); }

  .tl-expand-wrap {
    display: block;
    overflow: hidden;
    max-height: 0;
    transition: max-height var(--duration-base) var(--ease-standard);
  }
  .timeline.expanded .tl-expand-wrap { max-height: 64px; }
  .tl-expand-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    padding: 10px 0 2px;
  }
  .tl-expand-row .tl-source { flex: 1; text-align: center; }
}
