:root {
  --bg: #ffffff;
  --panel: #f5f9fd;
  --line: #dbe7f3;
  --sky-50: #eef5fc;
  --sky-100: #dcebfa;
  --sky-500: #2f7fd1;
  --sky-700: #1d5a9e;
  --ink: #14243b;
  --muted: #5b6b80;
  --topbar-h: 56px;
  --panel-w: 330px;
  --radius: 10px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); }
body { display: flex; flex-direction: column; overflow: hidden; }
h1, h2, h3, p { margin: 0; }
button, select, input { font: inherit; color: inherit; }

.muted { color: var(--muted); }
.small { font-size: 12px; }

/* ---------------------------------------------------------------- Top bar */

.topbar {
  height: var(--topbar-h);
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 16px;
  background: linear-gradient(90deg, #ffffff 0%, var(--sky-100) 100%);
  border-bottom: 1px solid var(--line);
  z-index: 1000;
}
.brand { margin: 0; line-height: 0; min-width: 0; }
.brand img { height: 34px; width: auto; max-width: 100%; }

.topbar-actions { display: flex; align-items: center; gap: 8px; }
.topbar-actions button {
  height: 36px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.topbar-actions button:hover { border-color: var(--sky-500); color: var(--sky-700); }
/* Views menu (a <details> dropdown) */
.views { position: relative; }
.views summary {
  list-style: none;
  display: flex;
  align-items: center;
  height: 36px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
}
.views summary::-webkit-details-marker { display: none; }
.views summary::after { content: "▾"; margin-left: 6px; font-size: 11px; color: var(--muted); }
.views summary:hover { border-color: var(--sky-500); color: var(--sky-700); }
.views-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  z-index: 1200;
  min-width: 190px;
  display: grid;
  padding: 6px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgb(20 36 59 / 0.16);
}
.topbar-actions .views-menu button {
  height: 40px;
  border: none;
  border-radius: 8px;
  background: none;
  text-align: left;
  font-weight: 500;
}
.topbar-actions .views-menu button:hover { background: var(--sky-50); }

.updated { font-size: 12px; color: var(--muted); white-space: nowrap; }
.panel-toggle { display: none; }

/* ---------------------------------------------------------------- Layout */

.app { flex: 1; display: flex; min-height: 0; }
#map { flex: 1; background: #d9e9f6; }

.panel {
  width: var(--panel-w);
  flex: none;
  overflow-y: auto;
  background: var(--panel);
  border-right: 1px solid var(--line);
  padding: 8px 14px 20px;
  transition: width 0.25s ease, padding 0.25s ease;
}

/* Desktop: arrow tab on the sidebar's right edge that hides/shows it. */
.app { position: relative; }
.collapse-tab {
  position: absolute;
  top: 50%;
  left: var(--panel-w);
  z-index: 1000;
  width: 30px;
  height: 72px;
  display: grid;
  place-items: center;
  padding: 0;
  border: none;
  border-radius: 0 12px 12px 0;
  background: var(--sky-500);
  color: #fff;
  cursor: pointer;
  box-shadow: 3px 2px 10px rgb(20 36 59 / 0.3);
  transform: translateY(-50%);
  transition: left 0.25s ease, background 0.15s ease;
}
.collapse-tab:hover { background: var(--sky-700); }
.collapse-tab:focus-visible { outline: 3px solid var(--sky-100); outline-offset: 2px; }
.collapse-tab svg { transition: transform 0.25s ease; }
.panel-collapsed .collapse-tab svg { transform: rotate(180deg); }
@media (min-width: 761px) {
  .panel-collapsed .panel { width: 0; padding-left: 0; padding-right: 0; border-right: none; overflow: hidden; }
  .panel-collapsed .collapse-tab { left: 0; }
}
.panel section { padding: 12px 0; border-bottom: 1px solid var(--line); }
.panel h2 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--sky-700);
  margin-bottom: 10px;
}
.credits { padding-top: 12px; line-height: 1.4; }

/* Phone bottom-sheet header with a Close button (hidden on desktop). */
.sheet-header { display: none; }

/* ---------------------------------------------------------------- Storm cards */

.storm-list { display: grid; gap: 8px; }
.storm-card {
  display: flex;
  gap: 10px;
  padding: 10px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  cursor: pointer;
}
.storm-card:hover, .storm-card:focus-visible { border-color: var(--sky-500); outline: none; }
.storm-badge {
  flex: none;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--c);
  color: #fff;
  font-size: 12px;
  font-weight: 800;
  text-shadow: 0 0 3px rgb(0 0 0 / 0.5);
}
.storm-body { min-width: 0; display: grid; gap: 2px; font-size: 13px; }
.storm-body h3 { font-size: 15px; }
.storm-links { display: flex; flex-wrap: wrap; gap: 4px 12px; margin-top: 4px; }
.storm-links a { color: var(--sky-700); font-weight: 600; font-size: 12px; }

/* ---------------------------------------------------------------- Controls */

.toggles { display: grid; gap: 2px; }
.toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 36px;
  padding: 0 6px;
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
}
.toggle:hover { background: var(--sky-50); }
.toggle input { width: 18px; height: 18px; margin: 0; accent-color: var(--sky-500); }

.swatch { width: 14px; height: 14px; border-radius: 3px; flex: none; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  min-height: 34px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  font-size: 13px;
  cursor: pointer;
}
.chip:hover { border-color: var(--sky-500); }
.chip[aria-checked="true"] { background: var(--sky-500); border-color: var(--sky-500); color: #fff; font-weight: 600; }

.select-row, .slider-row { display: flex; align-items: center; gap: 10px; font-size: 13px; margin: 4px 0 8px; }
.select-row select {
  flex: 1;
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 0 8px;
}
.slider-row { margin-top: 10px; }
.slider-row input { flex: 1; accent-color: var(--sky-500); }
#model-status { margin-top: 6px; }

/* ---------------------------------------------------------------- Map symbols */

.storm-dot {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: var(--c);
  border: 2px solid #fff;
  box-shadow: 0 1px 4px rgb(0 0 0 / 0.35);
  color: #fff;
  font: 800 10px/1 system-ui, sans-serif;
  display: grid;
  place-items: center;
  text-shadow: 0 0 2px rgb(0 0 0 / 0.6);
}
.storm-dot.now { font-size: 12px; border-width: 3px; }

.outlook-x {
  color: var(--c);
  font: 900 22px/24px system-ui, sans-serif;
  text-align: center;
  text-shadow: 0 0 3px #fff, 0 0 3px #fff;
}

.model-label span {
  display: inline-block;
  transform: translate(6px, -50%);
  white-space: nowrap;
  font: 700 11px/1 system-ui, sans-serif;
  color: var(--c);
  text-shadow: 0 0 2px #fff, 0 0 3px #fff, 0 0 4px #fff;
}

.leaflet-tooltip.arrival-label {
  background: rgb(255 255 255 / 0.9);
  border: none;
  box-shadow: none;
  padding: 1px 4px;
  font-weight: 700;
  font-size: 11px;
}

.leaflet-container { font-family: inherit; }

.sat-player {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px 6px 6px;
  background: rgb(255 255 255 / 0.95);
  border: 1px solid var(--line);
  border-radius: 999px;
  box-shadow: 0 2px 10px rgb(20 36 59 / 0.15);
}
.sat-player[hidden] { display: none; }
.sat-play {
  width: 34px;
  height: 34px;
  flex: none;
  border: none;
  border-radius: 50%;
  background: var(--sky-500);
  color: #fff;
  font-size: 13px;
  cursor: pointer;
}
.sat-play:disabled { background: var(--line); cursor: default; }
.sat-frames { display: flex; align-items: center; gap: 3px; }
.sat-frame {
  width: 10px;
  height: 18px;
  padding: 0;
  border: none;
  border-radius: 3px;
  background: #e03131; /* still loading */
  cursor: pointer;
}
.sat-frame.ready { background: #2f9e44; }
.sat-frame.current { height: 26px; box-shadow: 0 0 0 2px #fff, 0 0 0 4px var(--ink); }
.sat-time { font-size: 12px; font-weight: 600; white-space: nowrap; font-variant-numeric: tabular-nums; }
/* Loading screen: covers the map until the first view is fully drawn. */
.loading {
  position: absolute;
  inset: 0;
  z-index: 1001;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 10px;
  background: linear-gradient(180deg, #ffffff 0%, var(--sky-100) 100%);
  color: var(--sky-700);
  font-weight: 600;
  transition: opacity 0.35s ease, visibility 0.35s;
}
.loading.done { opacity: 0; visibility: hidden; }
.loading-spinner { font-size: 44px; animation: spin 1.4s linear infinite; }
@keyframes spin { to { transform: rotate(-360deg); } }
@media (prefers-reduced-motion: reduce) { .loading-spinner { animation: none; } }

/* City labels: dark blue text with a white outline and a light drop shadow. */
.city-label {
  --label-ink: #102342;
  /* The marker itself is the dot; the name hangs off its right (or left) side. */
  box-sizing: border-box;
  border-radius: 50%;
  background: var(--label-ink);
  border: 2px solid #fff;
  filter: drop-shadow(0 1px 1.5px rgb(0 0 0 / 0.35));
  pointer-events: none;
}
.city-name {
  position: absolute;
  top: 50%;
  left: 13px;
  transform: translateY(-50%);
  white-space: nowrap;
  color: var(--label-ink);
  font: 700 13px/1 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  letter-spacing: 0.01em;
  /* 1px white outline in eight directions, plus a soft white glow. */
  text-shadow:
    -1px -1px 0 #fff, 0 -1px 0 #fff, 1px -1px 0 #fff,
    -1px 0 0 #fff, 1px 0 0 #fff,
    -1px 1px 0 #fff, 0 1px 0 #fff, 1px 1px 0 #fff,
    0 0 4px #fff;
}
.city-label.left .city-name { left: auto; right: 13px; }

/* Turns the gray basemap into white land and light-blue water. */
.basemap-tint { filter: sepia(0.25) hue-rotate(175deg) saturate(2.2) brightness(1.04); }
.leaflet-popup-content { font-size: 13px; line-height: 1.45; }

/* ---------------------------------------------------------------- Legend */

.legend {
  position: fixed;
  right: 12px;
  bottom: 28px;
  z-index: 900;
  max-width: 260px;
  max-height: 45vh;
  overflow-y: auto;
  background: rgb(255 255 255 / 0.95);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 4px 16px rgb(20 36 59 / 0.12);
  padding: 8px 10px;
  cursor: pointer;
}
.legend-block + .legend-block { margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--line); }
.legend h3 { font-size: 12px; margin-bottom: 4px; }
.legend.collapsed h3 { margin-bottom: 0; }
.legend-block:first-child h3::after { content: " ▾"; color: var(--muted); }
.legend.collapsed .legend-block:first-child h3::after { content: " ▸"; }
.legend-items { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 2px 10px; }
.legend-item { display: flex; align-items: center; gap: 6px; font-size: 11px; }
.legend-item img { width: 16px; height: 16px; flex: none; }
.legend.collapsed .legend-items { display: none; }
.legend-toggle { display: none; }

/* ---------------------------------------------------------------- Phones */

@media (max-width: 760px) {
  :root { --topbar-h: 52px; }
  .topbar { padding: 0 10px; }
  .brand img { height: 22px; }
  .updated { display: none; }
  .panel-toggle { display: inline-block; }
  .collapse-tab { display: none; }
  .topbar-actions button.panel-toggle { background: var(--sky-500); border-color: var(--sky-500); color: #fff; }

  /* The panel slides up as a sheet over the map. */
  .app { position: relative; }
  .panel {
    position: absolute;
    inset: auto 0 0 0;
    width: auto;
    height: 70%;
    z-index: 1100;
    border-right: none;
    border-top: 1px solid var(--line);
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -8px 24px rgb(20 36 59 / 0.18);
    padding-bottom: calc(20px + env(safe-area-inset-bottom));
    transform: translateY(105%);
    transition: transform 0.25s ease;
  }
  .panel-open .panel { transform: none; }
  .panel { padding-top: 0; }
  .sheet-header {
    position: sticky;
    top: 0;
    z-index: 1;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    height: 48px;
    margin: 0 -14px;
    padding: 0 10px;
    background: var(--panel);
    border-bottom: 1px solid var(--line);
  }
  .sheet-grip {
    position: absolute;
    left: 50%;
    top: 8px;
    width: 40px;
    height: 4px;
    margin-left: -20px;
    border-radius: 2px;
    background: var(--line);
  }
  #btn-close-panel {
    height: 34px;
    padding: 0 14px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: #fff;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
  }
  .legend { right: 12px; bottom: 36px; max-width: min(260px, calc(100vw - 24px)); max-height: 50vh; }
  .legend-items { grid-template-columns: 1fr; }
  .sat-band { display: none; }
  .sat-frame { width: 8px; }

  /* Collapsed on phones: only a floating "Legend" pill. */
  .legend.collapsed {
    padding: 0;
    background: none;
    border: none;
    box-shadow: none;
    overflow: visible;
  }
  .legend.collapsed .legend-block { display: none; }
  .legend.collapsed .legend-toggle {
    display: block;
    height: 40px;
    padding: 0 18px;
    border: none;
    border-radius: 999px;
    background: var(--sky-500);
    color: #fff;
    font-size: 14px;
    font-weight: 700;
    box-shadow: 0 4px 14px rgb(20 36 59 / 0.3);
    cursor: pointer;
  }
  .panel-open .legend { display: none; }
}
