/** Application shell: top bar, icon rail, slide-over panel, timeline, overlays. */

/* ================================================================== *
 * Shell
 * ================================================================== */

.app {
  display: grid;
  grid-template-rows: var(--topbar-height) 1fr;
  height: 100vh;
  height: 100dvh;
}

.map-area {
  position: relative;
  overflow: hidden;
}

#map,
#map-3d {
  position: absolute;
  inset: 0;
}
#map-3d { display: none; }
.app[data-mode='3d'] #map-3d { display: block; }

/**
 * In 3D the Leaflet map is hidden but deliberately *not* `display: none`.
 *
 * Two products — the recoloured Global High Resolution composite and OPERA — are
 * mirrored into 3D by capturing the canvases Leaflet has already painted. Taking
 * the map out of layout collapses its size and its tiles' box metrics, so those
 * captures come back empty or stale and the 3D radar stops following the
 * scrubber. Keeping it laid out but invisible costs a little compositing and
 * makes the capture deterministic.
 */
.app[data-mode='3d'] #map {
  visibility: hidden;
  pointer-events: none;
}

/* ================================================================== *
 * Top bar
 * ================================================================== */

.topbar {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 0 var(--space-3);
  background: var(--surface-1);
  border-bottom: 1px solid var(--border-subtle);
  z-index: var(--z-topbar);
}

.brand {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-weight: var(--weight-bold);
  font-size: var(--text-md);
  letter-spacing: -0.02em;
  flex: none;
}
.brand__logo {
  height: 26px;
  width: auto;
  display: block;
}
/* The wordmark is light-on-dark artwork; on a light ground it needs a nudge. */
:root[data-theme='light'] .brand__logo {
  filter: brightness(0.15) saturate(0);
}
.brand__fallback { font-size: var(--text-md); }

/* Shown only on narrow screens, where the rail collapses into this button. */
.panel-toggle { display: none; }

.topbar__status {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-width: 0;
  overflow: hidden;
}

.topbar__spacer { flex: 1; }

.topbar__actions {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  flex: none;
}

/* Layer search */
.search {
  position: relative;
  width: 210px;
  flex: none;
}
.search__input { padding-left: 28px; }
.search__icon {
  position: absolute;
  left: 9px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-tertiary);
  pointer-events: none;
  font-size: var(--text-sm);
}
.search__results {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  width: 380px;
  max-height: 420px;
  overflow-y: auto;
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: var(--space-1);
  z-index: var(--z-modal);
}
.search__results[hidden] { display: none; }
.search__item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  width: 100%;
  padding: 7px 9px;
  border: 0;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--text-primary);
  font: inherit;
  font-size: var(--text-sm);
  text-align: left;
  cursor: pointer;
}
.search__item:hover,
.search__item[aria-selected='true'] { background: var(--surface-3); }
.search__item-group {
  margin-left: auto;
  font-size: var(--text-xs);
  color: var(--text-tertiary);
  flex: none;
}
.search__empty { padding: var(--space-3); color: var(--text-tertiary); font-size: var(--text-sm); }

/* ================================================================== *
 * Icon rail
 * ================================================================== */

.rail {
  position: absolute;
  top: var(--space-3);
  left: var(--space-3);
  bottom: calc(var(--timeline-height) + var(--space-3));
  width: var(--rail-width);
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  padding: var(--space-2) 0;
  background: color-mix(in srgb, var(--surface-1) 92%, transparent);
  backdrop-filter: blur(10px);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-md);
  z-index: var(--z-rail);
  overflow-y: auto;
  scrollbar-width: none;
}
.rail::-webkit-scrollbar { display: none; }

.rail__btn {
  position: relative;
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  margin: 0 auto;
  border: 0;
  border-radius: var(--radius-lg);
  background: transparent;
  color: var(--text-secondary);
  font-size: 17px;
  cursor: pointer;
  flex: none;
  transition: background var(--duration-fast) var(--ease), color var(--duration-fast) var(--ease);
}
/* Belt and braces with the U+FE0E in the icon itself: keep rail glyphs
   monochrome even where a browser would prefer a colour emoji font. */
.rail__btn { font-variant-emoji: text; }
.rail__btn:hover { background: var(--surface-3); color: var(--text-primary); }
.rail__btn[aria-selected='true'] {
  background: var(--accent-soft);
  color: var(--accent-text);
}
/* Active-group marker on the rail edge */
.rail__btn[aria-selected='true']::before {
  content: '';
  position: absolute;
  left: -8px;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 20px;
  border-radius: var(--radius-pill);
  background: var(--accent);
}
/* Dot showing the group has an active layer */
.rail__btn[data-active='true']::after {
  content: '';
  position: absolute;
  top: 6px;
  right: 6px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--ok);
  box-shadow: 0 0 0 2px var(--surface-1);
}

.rail__divider {
  height: 1px;
  margin: var(--space-1) var(--space-3);
  background: var(--border-subtle);
  flex: none;
}

/* Tooltip */
.rail__btn[data-tip]:hover::after {
  content: attr(data-tip);
  position: absolute;
  left: calc(100% + 10px);
  top: 50%;
  transform: translateY(-50%);
  padding: 5px 9px;
  border-radius: var(--radius-md);
  background: var(--surface-4);
  border: 1px solid var(--border-strong);
  color: var(--text-primary);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  white-space: nowrap;
  box-shadow: var(--shadow-md);
  pointer-events: none;
  z-index: 1;
}

/* ================================================================== *
 * Slide-over panel
 * ================================================================== */

.panel {
  position: absolute;
  top: var(--space-3);
  left: calc(var(--rail-width) + var(--space-3) * 2);
  bottom: calc(var(--timeline-height) + var(--space-3));
  width: var(--panel-width);
  display: flex;
  flex-direction: column;
  background: color-mix(in srgb, var(--surface-1) 96%, transparent);
  backdrop-filter: blur(14px);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  z-index: var(--z-panel);
  transition: opacity var(--duration-base) var(--ease), transform var(--duration-base) var(--ease);
}
/* The panel animates out rather than disappearing, so it opts out of the
   global `[hidden] { display: none !important }` rule in base.css. */
.panel[hidden] {
  display: flex !important;
  opacity: 0;
  transform: translateX(-12px);
  pointer-events: none;
}

.panel__head {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border-subtle);
  flex: none;
}
.panel__title {
  font-size: var(--text-md);
  font-weight: var(--weight-semibold);
}
.panel__subtitle {
  font-size: var(--text-xs);
  color: var(--text-tertiary);
}

.panel__body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

/* ================================================================== *
 * Layer cards
 * ================================================================== */

.card {
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  background: var(--surface-2);
  overflow: hidden;
  transition: border-color var(--duration-fast) var(--ease);
}
.card[data-active='true'] { border-color: color-mix(in srgb, var(--accent) 45%, var(--border-subtle)); }

.card__head {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-3);
}
.card__accent {
  width: 3px;
  height: 22px;
  border-radius: var(--radius-pill);
  background: var(--card-accent, var(--accent));
  flex: none;
}
.card__title {
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  flex: 1;
  min-width: 0;
}
.card__meta {
  font-size: var(--text-xs);
  color: var(--text-tertiary);
  font-weight: var(--weight-regular);
}

.card__body {
  padding: 0 var(--space-3) var(--space-3);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}
.card__body[hidden] { display: none; }

.opacity-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-xs);
  color: var(--text-secondary);
}
.opacity-row output {
  min-width: 34px;
  text-align: right;
  font-family: var(--font-mono);
  color: var(--text-tertiary);
}

/* Collapsible advanced block */
.disclosure {
  border-top: 1px solid var(--border-subtle);
  padding-top: var(--space-2);
}
.disclosure > summary {
  cursor: pointer;
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  color: var(--text-secondary);
  list-style: none;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 2px 0;
}
.disclosure > summary::-webkit-details-marker { display: none; }
.disclosure > summary::before {
  content: '▸';
  font-size: 9px;
  transition: transform var(--duration-fast) var(--ease);
}
.disclosure[open] > summary::before { transform: rotate(90deg); }
.disclosure > summary:hover { color: var(--text-primary); }
.disclosure__body { padding-top: var(--space-3); display: flex; flex-direction: column; gap: var(--space-3); }

/* ================================================================== *
 * Layer manager
 * ================================================================== */

.layer-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  position: relative;
}

.layer-row {
  display: flex;
  align-items: stretch;
  gap: var(--space-2);
  padding: var(--space-2);
  border: 1px solid var(--border-subtle);
  border-left: 3px solid var(--row-accent, var(--accent));
  border-radius: var(--radius-lg);
  background: var(--surface-2);
  touch-action: none; /* pointer dragging owns the gesture */
}

/* The row being dragged is lifted out of flow and follows the pointer. */
.layer-row--dragging {
  position: fixed;
  z-index: var(--z-modal);
  box-shadow: var(--shadow-lg);
  border-color: var(--accent);
  opacity: 0.96;
  pointer-events: none;
}

/* The gap the dragged row will drop into. */
.layer-row--placeholder {
  background: var(--accent-soft);
  border-style: dashed;
  border-color: var(--accent);
}
.layer-row--placeholder > * { display: none; }

.layer-row__handle {
  display: grid;
  place-items: center;
  width: 26px;
  border: 0;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--text-tertiary);
  font-size: 15px;
  cursor: grab;
  flex: none;
  letter-spacing: -2px;
}
.layer-row__handle:hover { background: var(--surface-3); color: var(--text-primary); }
.layer-row__handle:active { cursor: grabbing; }

.layer-row__body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.layer-row__title {
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
}
.layer-row__meta {
  font-size: var(--text-xs);
  color: var(--text-tertiary);
}
.layer-row__body .opacity-row { margin-top: 2px; }
.layer-row__body .opacity-row > span:first-child { display: none; }

.layer-row__actions {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: none;
}
.layer-row__actions .btn--icon { width: 26px; height: 22px; font-size: 11px; }

/* Branded panel header (Handry Outlook) */
.panel-brand {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  background: var(--surface-2);
}
.panel-brand__icon {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-md);
  flex: none;
}
.panel-brand__title {
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
}

/* Pressed state for toggle buttons in the top bar (3D). */
.btn--active {
  background: var(--accent-soft);
  color: var(--accent-text);
  border-color: color-mix(in srgb, var(--accent) 45%, transparent);
  font-weight: var(--weight-bold);
}

/* Section heading inside the panel */
.section-title {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-tertiary);
}
.section-title::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border-subtle);
}

/* Switch row */
.switch-row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  justify-content: space-between;
}
.switch-row__label { font-size: var(--text-sm); }
.switch-row__hint { font-size: var(--text-xs); color: var(--text-tertiary); }

/* ================================================================== *
 * Timeline
 * ================================================================== */

.timeline {
  position: absolute;
  left: var(--space-3);
  right: var(--space-3);
  bottom: var(--space-3);
  height: var(--timeline-height);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  background: color-mix(in srgb, var(--surface-1) 94%, transparent);
  backdrop-filter: blur(14px);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  z-index: var(--z-timeline);
}

.timeline__top {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.timeline__readout {
  display: flex;
  align-items: baseline;
  gap: var(--space-2);
  min-width: 190px;
}
.timeline__clock {
  font-family: var(--font-mono);
  font-size: var(--text-xl);
  font-weight: var(--weight-semibold);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}
.timeline__date { font-size: var(--text-xs); color: var(--text-tertiary); }

/* Shown when the timeline is pinned to a filter or outlook window. */
.chip--focus {
  border-color: color-mix(in srgb, var(--accent) 55%, var(--border-subtle));
  background: var(--accent-soft);
  color: var(--accent-text);
  cursor: pointer;
  font: inherit;
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  max-width: 230px;
}
.chip--focus:hover { background: color-mix(in srgb, var(--accent) 24%, transparent); }
.chip--focus .chip__label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip__close { opacity: 0.6; font-size: 9px; }
.chip--focus:hover .chip__close { opacity: 1; }

.timeline__transport {
  display: flex;
  align-items: center;
  gap: var(--space-1);
}

.timeline__scrub {
  position: relative;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

/* Tick marks under the scrubber */
.timeline__ticks {
  position: relative;
  height: 10px;
  pointer-events: none;
}
.timeline__tick {
  position: absolute;
  top: 0;
  width: 1px;
  height: 4px;
  background: var(--border-strong);
  transform: translateX(-0.5px);
}
.timeline__tick--major { height: 7px; background: var(--text-tertiary); }
.timeline__tick-label {
  position: absolute;
  top: 6px;
  transform: translateX(-50%);
  font-size: 9px;
  color: var(--text-tertiary);
  font-family: var(--font-mono);
  white-space: nowrap;
}

.timeline__meta {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  font-size: var(--text-xs);
  color: var(--text-tertiary);
  flex-wrap: wrap;
}

/* ================================================================== *
 * Floating cards (legend, outlook)
 * ================================================================== */

.floating {
  position: absolute;
  right: var(--space-3);
  width: 250px;
  max-height: calc(100% - var(--timeline-height) - var(--space-6));
  display: flex;
  flex-direction: column;
  background: color-mix(in srgb, var(--surface-1) 94%, transparent);
  backdrop-filter: blur(14px);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-md);
  z-index: var(--z-floating);
  overflow: hidden;
}
.floating--legend { top: var(--space-3); }

.floating__head {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  border-bottom: 1px solid var(--border-subtle);
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
  flex: none;
}
.floating__body {
  padding: var(--space-3);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  font-size: var(--text-xs);
}
.floating[data-collapsed='true'] .floating__body { display: none; }

/* Legend entries */
.legend-group { display: flex; flex-direction: column; gap: 6px; }
.legend-group__title {
  font-weight: var(--weight-semibold);
  color: var(--text-secondary);
  font-size: var(--text-xs);
}
.legend-scale {
  display: flex;
  height: 10px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--border-subtle);
}
.legend-scale__step { flex: 1; }
.legend-scale__labels {
  display: flex;
  justify-content: space-between;
  font-size: 9px;
  color: var(--text-tertiary);
  font-family: var(--font-mono);
}
.legend-item { display: flex; align-items: center; gap: var(--space-2); }
.legend-swatch {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  flex: none;
  border: 1px solid rgba(0, 0, 0, 0.25);
}

/* ================================================================== *
 * Calendar (outlooks)
 * ================================================================== */

.calendar { display: flex; flex-direction: column; gap: var(--space-2); }
.calendar__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
}
.calendar__grid,
.calendar__weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 3px;
}
.calendar__weekdays {
  font-size: 9px;
  color: var(--text-tertiary);
  text-align: center;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.calendar__day {
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: var(--surface-3);
  color: var(--text-secondary);
  font-size: var(--text-xs);
  cursor: pointer;
  position: relative;
}
.calendar__day:hover { border-color: var(--border-strong); color: var(--text-primary); }
.calendar__day[data-empty='true'] { background: transparent; cursor: default; color: var(--text-tertiary); opacity: 0.35; }
.calendar__day[aria-selected='true'] { border-color: var(--accent); color: var(--text-primary); }
.calendar__day[data-risk]::after {
  content: '';
  position: absolute;
  bottom: 3px;
  width: 60%;
  height: 2px;
  border-radius: var(--radius-pill);
  background: var(--day-risk, var(--accent));
}
.calendar__day[data-today='true'] { font-weight: var(--weight-bold); color: var(--text-primary); }

/* ================================================================== *
 * Progress
 * ================================================================== */

.progress {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3);
  border-radius: var(--radius-lg);
  background: var(--surface-3);
}
.progress[hidden] { display: none; }
.progress__dial {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: conic-gradient(var(--accent) var(--pct, 0%), var(--surface-4) 0);
  flex: none;
}
.progress__dial::after {
  content: attr(data-pct);
  display: grid;
  place-items: center;
  width: 31px;
  height: 31px;
  border-radius: 50%;
  background: var(--surface-2);
  font-size: 9px;
  font-family: var(--font-mono);
  color: var(--text-secondary);
}
.progress__text { font-size: var(--text-xs); color: var(--text-secondary); }

/* ================================================================== *
 * Modal
 * ================================================================== */

.scrim {
  position: fixed;
  inset: 0;
  background: rgba(3, 6, 12, 0.65);
  backdrop-filter: blur(3px);
  z-index: var(--z-modal);
  display: grid;
  place-items: center;
  padding: var(--space-4);
}
.scrim[hidden] { display: none; }

.modal {
  width: min(620px, 100%);
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  background: var(--surface-1);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}
.modal__head {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-4);
  border-bottom: 1px solid var(--border-subtle);
  flex: none;
}
.modal__title { font-size: var(--text-lg); flex: 1; }
.modal__body {
  padding: var(--space-4);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  font-size: var(--text-sm);
  line-height: 1.6;
  color: var(--text-secondary);
}
.modal__body h4 { color: var(--text-primary); font-size: var(--text-sm); margin-bottom: var(--space-1); }
.modal__body ul { margin: var(--space-1) 0 0; padding-left: var(--space-5); }
.modal__body li { margin-bottom: 3px; }
.modal__body kbd {
  padding: 1px 5px;
  border: 1px solid var(--border-strong);
  border-bottom-width: 2px;
  border-radius: var(--radius-sm);
  background: var(--surface-3);
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-primary);
}
.modal__foot {
  padding: var(--space-3) var(--space-4);
  border-top: 1px solid var(--border-subtle);
  display: flex;
  justify-content: flex-end;
  gap: var(--space-2);
  flex: none;
}

/* ================================================================== *
 * Toasts
 * ================================================================== */

.toasts {
  position: fixed;
  bottom: calc(var(--timeline-height) + var(--space-6));
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  z-index: var(--z-toast);
  pointer-events: none;
}
.toast {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: 9px 14px;
  border-radius: var(--radius-pill);
  background: var(--surface-4);
  border: 1px solid var(--border-strong);
  box-shadow: var(--shadow-lg);
  font-size: var(--text-sm);
  animation: toast-in var(--duration-base) var(--ease);
  pointer-events: auto;
}
.toast[data-tone='error'] { border-color: var(--danger); color: var(--danger); }
.toast[data-tone='success'] { border-color: var(--ok); }

.toast__action {
  margin-left: var(--space-1);
  padding: 4px 10px;
  border: 1px solid color-mix(in srgb, var(--accent) 55%, transparent);
  border-radius: var(--radius-pill);
  background: var(--accent-soft);
  color: var(--accent-text);
  font: inherit;
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  cursor: pointer;
  white-space: nowrap;
}
.toast__action:hover { background: color-mix(in srgb, var(--accent) 26%, transparent); }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

/* ================================================================== *
 * Palette editor
 * ================================================================== */

.palette-preview {
  display: flex;
  height: 14px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--border-subtle);
}
.palette-preview__step { flex: 1; }

.palette-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(78px, 1fr));
  gap: 5px;
}
.palette-swatch {
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: 9px;
  color: var(--text-tertiary);
  font-family: var(--font-mono);
}
.palette-swatch input[type='color'] {
  width: 100%;
  height: 20px;
  padding: 0;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  background: none;
  cursor: pointer;
}

/* ================================================================== *
 * Leaflet overrides
 * ================================================================== */

.leaflet-container {
  background: var(--surface-0);
  font-family: var(--font-sans);
}
/* Base map credits (Mapbox, OpenStreetMap, MapTiler, OpenTopoMap, Esri) stay —
   they are licence-required and they identify the map, not the weather data.
   Weather-provider names are removed further upstream, in data/sourceNames.js. */
.leaflet-control-attribution {
  background: color-mix(in srgb, var(--surface-1) 82%, transparent) !important;
  color: var(--text-tertiary) !important;
  font-size: 10px !important;
  border-radius: var(--radius-sm) 0 0 0;
  padding: 2px 6px !important;
}
.leaflet-control-attribution a { color: var(--text-secondary) !important; }

/* Weather tiles: seams between adjacent tiles are very visible on
   semi-transparent overlays, so nudge them to overlap by a hair. */
.wx-tile {
  image-rendering: -webkit-optimize-contrast;
  will-change: opacity;
}
.windy-radar-tile { image-rendering: pixelated; }
.opera-radar-canvas,
.strike-canvas {
  position: absolute;
  top: 0;
  left: 0;
  pointer-events: none;
}

.strike-count {
  display: grid;
  place-items: center;
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: var(--weight-bold);
  color: #fff;
  text-shadow: 0 0 3px #000, 0 0 6px #000;
  pointer-events: none;
}

/* Popups */
.wx-popup-shell .leaflet-popup-content-wrapper {
  padding: 0;
  border-radius: var(--radius-lg);
  background: var(--surface-1);
  color: var(--text-primary);
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border-strong);
  overflow: hidden;
}
.wx-popup-shell .leaflet-popup-content { margin: 0; width: auto !important; }
.wx-popup-shell .leaflet-popup-tip { background: var(--surface-1); border: 1px solid var(--border-strong); }
.wx-popup-shell .leaflet-popup-close-button { color: var(--text-tertiary); }

.wx-popup { min-width: 210px; font-size: var(--text-sm); }
.wx-popup__head {
  padding: var(--space-3);
  border-top: 3px solid var(--accent, #38bdf8);
  border-bottom: 1px solid var(--border-subtle);
  background: var(--surface-2);
}
.wx-popup__eyebrow {
  display: block;
  font-size: 9px;
  font-weight: var(--weight-bold);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent, #38bdf8);
}
.wx-popup__impact {
  padding: var(--space-2) var(--space-3);
  font-weight: var(--weight-semibold);
  color: var(--accent);
  border-bottom: 1px solid var(--border-subtle);
}
.wx-popup__rows {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px var(--space-3);
  margin: 0;
  padding: var(--space-3);
  font-size: var(--text-xs);
}
.wx-popup__rows--grid { grid-template-columns: 1fr 1fr; }
.wx-popup__rows--grid > div { display: flex; flex-direction: column; }
.wx-popup__rows dt { color: var(--text-tertiary); text-transform: capitalize; }
.wx-popup__rows dd { margin: 0; color: var(--text-primary); }
.wx-popup__body {
  padding: 0 var(--space-3) var(--space-3);
  max-height: 220px;
  overflow-y: auto;
  font-size: var(--text-xs);
  color: var(--text-secondary);
  white-space: pre-wrap;
}

/* ================================================================== *
 * Responsive
 * ================================================================== */

/* ================================================================== *
 * Responsive
 *
 * Two breakpoints. At tablet width the panel narrows and the legend goes.
 * Below 720px the layout changes shape rather than just shrinking: the icon
 * rail becomes a horizontal scroller docked above the timeline (thumb-reachable
 * rather than stretched down the far edge), and the panel becomes a bottom
 * sheet, which is where a one-handed grip expects controls to be.
 * ================================================================== */

@media (max-width: 1100px) {
  :root { --panel-width: 300px; }
  .search { width: 150px; }
  .floating--legend { width: 210px; }
}

@media (max-width: 900px) {
  :root { --timeline-height: 96px; }
  .search { display: none; }
  .floating--legend { display: none; }
  .timeline__readout { min-width: 0; }
  .timeline__clock { font-size: var(--text-lg); }
  .panel { width: calc(100vw - var(--rail-width) - var(--space-3) * 3); }
}

@media (max-width: 720px) {
  :root {
    --topbar-height: 52px;
    --timeline-height: auto;
    --rail-width: 100%;
  }

  /* Comfortable touch targets throughout. */
  .btn { min-height: 38px; padding: 8px 13px; }
  .btn--icon { width: 38px; height: 38px; }
  .switch { width: 40px; height: 23px; }
  .switch__track::after { width: 17px; height: 17px; }
  .switch input:checked + .switch__track::after { transform: translateX(17px); }
  .input, .select { padding: 10px 12px; font-size: var(--text-base); }
  .range { height: 30px; }
  .range::-webkit-slider-thumb { width: 20px; height: 20px; margin-top: -8px; }
  .range::-moz-range-thumb { width: 20px; height: 20px; }

  .topbar { padding: 0 var(--space-2); gap: var(--space-2); }
  .brand__logo { height: 22px; }
  .topbar__status { display: none; }
  .panel-toggle { display: inline-flex; }
  /* Full screen and locate are awkward on a phone; keep the essentials. */
  #btn-fullscreen { display: none; }

  /* --- docked chrome: timeline, then rail, then the panel sheet --- */
  /*
     All three used to be pinned to `bottom: 0` and separated only by z-index,
     which put the panel (the lowest) underneath the timeline and the icon rail.
     They are stacked against each other instead, using the measured heights
     published by ui/layout.js, so every control stays reachable with the sheet
     open. Nothing is hidden to make room.
  */
  .rail {
    top: auto;
    left: 0;
    right: 0;
    bottom: var(--timeline-dock, 96px);
    width: auto;
    flex-direction: row;
    gap: 2px;
    padding: var(--space-1) var(--space-2);
    border-radius: 0;
    border-left: 0;
    border-right: 0;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scroll-snap-type: x proximity;
  }
  .rail__btn { flex: none; width: 46px; height: 42px; scroll-snap-align: center; }
  .rail__btn[aria-selected='true']::before {
    left: 50%;
    top: auto;
    bottom: -4px;
    transform: translateX(-50%);
    width: 18px;
    height: 3px;
  }
  .rail__btn[data-tip]:hover::after { display: none; }
  .rail__divider { width: 1px; height: auto; margin: var(--space-2) var(--space-1); }

  /* --- panel: bottom sheet, sitting on top of the rail --- */
  .panel {
    top: auto;
    left: 0;
    right: 0;
    bottom: calc(var(--timeline-dock, 96px) + var(--rail-dock, 52px));
    width: auto;
    /* Whatever is left between the top bar and the docked chrome. */
    max-height: calc(100dvh - var(--topbar-height) - var(--timeline-dock, 96px) - var(--rail-dock, 52px) - var(--space-2));
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    border-left: 0;
    border-right: 0;
    border-bottom: 0;
  }
  .panel[hidden] { transform: translateY(16px); }
  /* Grab handle, so it reads as a sheet rather than a stuck overlay. */
  .panel__head::before {
    content: '';
    position: absolute;
    top: 6px;
    left: 50%;
    transform: translateX(-50%);
    width: 34px;
    height: 4px;
    border-radius: var(--radius-pill);
    background: var(--border-strong);
  }
  .panel__head { padding-top: var(--space-4); position: relative; }
  .panel__body { padding: var(--space-3); gap: var(--space-3); }

  /* --- timeline: two rows, transport under the readout --- */
  .timeline {
    left: 0;
    right: 0;
    bottom: 0;
    border-radius: 0;
    border-left: 0;
    border-right: 0;
    border-bottom: 0;
    padding: var(--space-2) var(--space-3) calc(var(--space-2) + env(safe-area-inset-bottom, 0px));
    gap: var(--space-1);
  }
  .timeline__top { flex-wrap: wrap; gap: var(--space-2); }
  .timeline__readout { order: 1; flex: 1; min-width: 0; }
  .timeline__transport { order: 2; }
  .timeline__scrub { order: 3; flex-basis: 100%; }
  /* The speed slider is a desktop refinement; the panel still exposes it. */
  .timeline__top > .row:last-child { display: none; }
  .timeline__clock { font-size: var(--text-lg); }
  .timeline__meta { font-size: 10px; }
  .timeline__tick-label { font-size: 8px; }

  /* The map must clear the docked rail and timeline. */
  .map-area { padding-bottom: 0; }

  /* Leaflet pins its attribution to the bottom of the map container, which on a
     phone sits underneath the docked rail and timeline. Move it to the top edge
     so it stays legible (and legally present) without colliding. */
  .leaflet-control-attribution {
    position: fixed;
    top: var(--topbar-height);
    right: 0;
    bottom: auto;
    max-width: 62vw;
    font-size: 9px !important;
    border-radius: 0 0 0 var(--radius-sm);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  /* Ticks need their own room once labels sit under them. */
  .timeline__ticks { height: 16px; }

  .toasts { bottom: auto; top: calc(var(--topbar-height) + var(--space-6)); }
  .modal { max-height: 88vh; }
  .scrim { padding: var(--space-2); align-items: flex-end; }
  .modal { border-radius: var(--radius-xl) var(--radius-xl) 0 0; }
  .palette-grid { grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); }
  .wx-popup { min-width: 180px; }
}

/* Very small phones: drop the date beside the clock. */
@media (max-width: 400px) {
  .timeline__date { display: none; }
  .brand__logo { height: 20px; }
  .rail__btn { width: 42px; }
}

/* Landscape phones are short, not narrow — reclaim vertical space. */
@media (max-height: 480px) and (orientation: landscape) {
  .timeline__meta { display: none; }
  /* The rail and the sheet keep stacking against the measured docks here too;
     overriding them with fixed values is what let the sheet slide back under
     the timeline in landscape. The sheet simply ends up shorter. */
}

/* ------------------------------------------------------------------ *
 * Drawn icons
 * ------------------------------------------------------------------ */

/* The icon set replaced the text glyphs the buttons used to hold; see
   ui/icons.js for why. Sizing lives here so a button can size its own icon. */
.icon {
  display: block;
  width: 20px;
  height: 20px;
  flex: none;
}
.rail__btn .icon { width: 21px; height: 21px; }
.btn--icon .icon { width: 18px; height: 18px; }

/* Waiting on the browser's location fix, which can take several seconds. */
.btn--busy { opacity: 0.6; pointer-events: none; }
.btn--busy .icon { animation: icon-pulse 1.1s ease-in-out infinite; }
@keyframes icon-pulse { 50% { opacity: 0.35; } }

/* The location dot and its accuracy halo. */
.locate-dot { filter: drop-shadow(0 1px 3px rgb(0 0 0 / 0.45)); }
.locate-halo { pointer-events: none; }

@media (prefers-reduced-motion: reduce) {
  .btn--busy .icon { animation: none; }
}

/* ------------------------------------------------------------------ *
 * Drawing toolbar
 * ------------------------------------------------------------------ */

/* leaflet-draw's toolbar is placed by Leaflet inside the map container, whose
   bottom edge runs underneath the docked timeline. Its default top-left corner
   is worse still — that is where the rail and the top bar are. Bottom-right,
   lifted clear of the timeline, is the only corner nothing else claims. */
.leaflet-bottom.leaflet-right {
  bottom: calc(var(--timeline-height) + var(--space-3));
}
.leaflet-draw-toolbar a {
  background-color: var(--surface-1) !important;
  border-bottom-color: var(--border) !important;
}
.leaflet-draw-toolbar a:hover { background-color: var(--surface-3) !important; }
.leaflet-draw-actions a {
  background: var(--surface-2) !important;
  color: var(--text-primary) !important;
  border-left-color: var(--border) !important;
}
.leaflet-draw-tooltip { display: none; }

@media (max-width: 780px) {
  /* The docked chrome is measured at runtime; see ui/layout.js. */
  .leaflet-bottom.leaflet-right {
    bottom: calc(var(--timeline-dock, 96px) + var(--rail-dock, 52px) + var(--space-2));
  }
}

/* ------------------------------------------------------------------ *
 * Station card
 * ------------------------------------------------------------------ */

/* The two series colours, from the validated categorical pair. Assigned by
   meaning rather than by order — the warm hue is the warm variable in every
   panel — and stepped for each surface rather than flipped between them. */
:root {
  --viz-cool: #2a78d6;
  --viz-warm: #eb6834;
}
:root:not([data-theme='light']) {
  --viz-cool: #3987e5;
  --viz-warm: #d95926;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) { --viz-cool: #3987e5; --viz-warm: #d95926; }
}
:root[data-theme='dark'] { --viz-cool: #3987e5; --viz-warm: #d95926; }

/* Bounded and scrollable: the full card runs to about 560px, which is most of a
   phone screen and can overflow a short window entirely — the header was the
   part that went. */
.wxcard {
  width: 336px;
  max-width: 78vw;
  max-height: min(66vh, 560px);
  overflow-y: auto;
  overscroll-behavior: contain;
  font-family: var(--font-sans);
}
/* The header stays put while the charts scroll under it. */
.wxcard__head {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--surface-1);
}
.wxcard__head { padding-bottom: var(--space-2); border-bottom: 1px solid var(--border); }
.wxcard__name { font-weight: 650; font-size: var(--text-md); color: var(--text-primary); }
.wxcard__sub {
  display: flex; gap: var(--space-2); align-items: baseline;
  font-size: 11px; color: var(--text-tertiary);
}
.wxcard__id {
  font-weight: 650; letter-spacing: 0.04em;
  color: var(--text-secondary);
}

.wxcard__readings {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 2px var(--space-3); padding: var(--space-2) 0;
}
.wxcard__reading { display: flex; justify-content: space-between; gap: var(--space-2); font-size: 11.5px; }
.wxcard__reading-label { color: var(--text-tertiary); }
/* Values wear text tokens, never a series colour. */
.wxcard__reading-value { color: var(--text-primary); font-weight: 600; font-variant-numeric: tabular-nums; }

.wxcard__panels { padding-top: var(--space-1); }
.wxcard__loading { padding: var(--space-3) 0; font-size: 11.5px; color: var(--text-tertiary); }
/* The chart picker. A native select: it is one control, it is reachable from the
   keyboard without any work, and on a phone it opens the platform's own list
   rather than a menu built out of divs. */
.wxcard__pick {
  width: 100%; margin-top: var(--space-2); padding: 5px var(--space-2);
  font: inherit; font-size: 11.5px; font-weight: 600;
  color: var(--text-primary); background: var(--surface-2);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
}
.wxcard__pick:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
/* The reported condition, as words, beside the station id. */
.wxcard__wx { color: var(--text-secondary); text-transform: capitalize; }

.wxchart { display: block; overflow: visible; touch-action: none; }
.wxchart__grid { stroke: var(--border); stroke-width: 1; }
/* The time axis is a touch stronger than the grid: it is a frame, not a guide. */
.wxchart__axis { stroke: var(--border-strong, var(--border)); stroke-width: 1; }
.wxchart__tick { fill: var(--text-tertiary); font-size: 9px; font-variant-numeric: tabular-nums; }
.wxchart__line { fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
/* A 1px surface gap between neighbouring bars, drawn as a stroke so the gap
   holds at any width. */
.wxchart__bar { stroke: var(--surface-1); stroke-width: 1; }
.wxchart__arrow { stroke: var(--text-secondary); stroke-width: 1.4; fill: none; stroke-linecap: round; }
.wxchart__note { font-size: 10px; color: var(--text-tertiary); margin-top: 2px; }
/* A 2px ring in the surface colour, so an end dot stays legible over a line. */
.wxchart__end { stroke: var(--surface-1); stroke-width: 2; }
.wxchart__hair { stroke: var(--text-tertiary); stroke-width: 1; }

.wxchart__legend { display: flex; gap: var(--space-3); font-size: 10px; color: var(--text-tertiary); }
.wxchart__legend-item { display: inline-flex; align-items: center; gap: 5px; }
/* A line key rather than a box: at this density a filled square is data-weight
   ink doing a label's job. */
.wxchart__legend-key { width: 12px; height: 2px; border-radius: 1px; flex: none; }

.wxchart__readout {
  display: flex; flex-wrap: wrap; gap: var(--space-1) var(--space-3);
  min-height: 20px; padding-top: var(--space-2);
  font-size: 11px; color: var(--text-tertiary);
}
.wxchart__readout-time { font-weight: 650; color: var(--text-secondary); font-variant-numeric: tabular-nums; }
.wxchart__readout-item { display: inline-flex; align-items: center; gap: 5px; }
.wxchart__readout-item strong { color: var(--text-primary); font-variant-numeric: tabular-nums; }

.wxcard__table-toggle { width: 100%; margin-top: var(--space-2); font-size: 11px; }
.wxcard__table {
  width: 100%; margin-top: var(--space-2);
  border-collapse: collapse; font-size: 10.5px;
  max-height: 190px; display: block; overflow: auto;
}
.wxcard__table th, .wxcard__table td {
  padding: 2px var(--space-1); text-align: right;
  border-bottom: 1px solid var(--border);
  font-variant-numeric: tabular-nums; white-space: nowrap;
}
.wxcard__table th { color: var(--text-tertiary); font-weight: 600; position: sticky; top: 0; background: var(--surface-2); }
.wxcard__table td { color: var(--text-secondary); }
.wxcard__table td:first-child, .wxcard__table th:first-child { text-align: left; }

/* The station card is wider than a normal popup and carries its own padding. */
.wxcard-shell .leaflet-popup-content { margin: var(--space-3); width: auto !important; }
.wxcard-shell .leaflet-popup-content-wrapper {
  background: var(--surface-1); color: var(--text-primary);
  border: 1px solid var(--border); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
}
.wxcard-shell .leaflet-popup-tip { background: var(--surface-1); border: 1px solid var(--border); }
/* The same card, in the GL view. Mapbox brings its own popup chrome, so the
   surface, border and radius have to be restated for it; everything inside is
   the shared .wxcard markup. */
.wxcard-shell.mapboxgl-popup { max-width: 360px !important; }
.wxcard-shell .mapboxgl-popup-content {
  padding: var(--space-3);
  background: var(--surface-1); color: var(--text-primary);
  border: 1px solid var(--border); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
}
.wxcard-shell .mapboxgl-popup-close-button {
  width: 26px; height: 26px; font-size: 16px; line-height: 1;
  color: var(--text-tertiary); background: none; border: 0;
}
.wxcard-shell .mapboxgl-popup-close-button:hover { color: var(--text-primary); background: none; }
.wxcard-shell .mapboxgl-popup-tip { border-top-color: var(--surface-1); border-bottom-color: var(--surface-1); }
.wxcard-shell.mapboxgl-popup-anchor-left .mapboxgl-popup-tip { border-right-color: var(--surface-1); }
.wxcard-shell.mapboxgl-popup-anchor-right .mapboxgl-popup-tip { border-left-color: var(--surface-1); }


/* Hold roughly the height the charts will take, so the popup does not jump by
   four hundred pixels when the history lands. */
.wxcard__charts--pending { min-height: 300px; }
