:root {
  --bg: #0b0f14;
  --panel: rgba(16, 22, 30, 0.92);
  --line: #233040;
  --text: #e6edf3;
  --muted: #8aa0b4;
  --accent: #e8902f;
}

* { box-sizing: border-box; }

/* On touch devices, double-tapping over the UI chrome (panel, legend, disclaimer,
   labels) was selecting text and popping the iOS copy callout, which fought with
   map navigation. Disable text selection + the callout/tap highlight everywhere,
   then re-enable selection only inside real text inputs. The map canvas keeps its
   own double-tap-to-zoom (it isn't selectable HTML). */
html, body {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;   /* also removes the 300ms tap delay */
}

input, textarea {
  -webkit-user-select: text;
  user-select: text;
  -webkit-touch-callout: default;
}

html, body, #map {
  margin: 0;
  height: 100%;
  width: 100%;
}

#map {
  position: absolute;
  inset: 0;
  z-index: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

/* Brand badge — upper-left over the map (top-right holds all the controls). */
.brand {
  position: absolute;
  top: 12px;
  left: 12px;
  z-index: 6;
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 5px 12px 5px 7px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  backdrop-filter: blur(6px);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.4);
  pointer-events: none;   /* branding only — never intercept map drags */
  user-select: none;
}
.brand-logo { height: 26px; width: auto; display: block; }
.brand-name { font-size: 15px; font-weight: 800; letter-spacing: 0.4px; color: var(--text); }
@media (max-width: 520px) {
  .brand { padding: 4px 10px 4px 6px; }
  .brand-logo { height: 22px; }
  .brand-name { font-size: 13px; }
}

.panel {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 6;
  width: 260px;
  max-width: calc(100vw - 24px);
  max-height: calc(100vh - 24px);
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 14px 14px 12px;
  backdrop-filter: blur(6px);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.4);
  transform-origin: top right;
  transition: opacity 0.16s ease, transform 0.16s ease, visibility 0.16s;
}
/* Collapsed: panel hidden, only the toggle icon shows (default on all devices). */
.panel.collapsed {
  opacity: 0;
  visibility: hidden;
  transform: translateX(10px) scale(0.98);
  pointer-events: none;
}

/* Floating round icon button that reveals the panel. */
.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 50%;
  cursor: pointer;
  backdrop-filter: blur(6px);
  -webkit-tap-highlight-color: transparent;
}
#panel-toggle {
  position: absolute;
  top: 64px;            /* below the radar play control */
  right: 12px;
  z-index: 5;
  width: 44px;
  height: 44px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.4);
}
#panel-toggle:hover { border-color: var(--accent); color: var(--accent); }

#storm-eta {
  position: absolute;
  top: 116px;          /* below the panel toggle */
  right: 12px;
  z-index: 5;
  width: 44px;
  height: 44px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.4);
}
#storm-eta:hover { border-color: var(--accent); color: var(--accent); }

.cell-eta { font-size: 12px; line-height: 1.4; }
.cell-eta .ce-head { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.4px; }
.cell-eta .ce-big { font-size: 16px; font-weight: 700; margin-top: 3px; }
.cell-eta .ce-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }

/* Nowcast banner: fixed in the lower third, centered, above the disclaimer. */
.cell-eta-banner {
  position: absolute;
  left: 50%;
  bottom: 15%;
  transform: translateX(-50%);
  z-index: 7;
  min-width: 210px;
  max-width: min(360px, calc(100vw - 24px));
  padding: 12px 34px 12px 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(6px);
}
#cell-eta-close { position: absolute; top: 8px; right: 8px; }

/* Radar loop control — top-right, directly ABOVE the filter (panel) button */
.radar-anim {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 5;
  display: flex;
  flex-direction: row-reverse;  /* play button on the right; time label to its left */
  align-items: center;
  gap: 8px;
}
#radar-play {
  width: 40px;
  height: 40px;
  font-size: 15px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.4);
}
#radar-play:hover { border-color: var(--accent); color: var(--accent); }
.radar-time {
  font-size: 12px;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 4px 8px;
  backdrop-filter: blur(6px);
  min-width: 0;
}
.radar-time:empty { display: none; }

.panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}
.panel-head h1 {
  font-size: 15px;
  margin: 0 0 2px;
  letter-spacing: 0.2px;
}
.panel-head .sub {
  font-size: 11px;
  color: var(--muted);
}
.icon-btn--sm {
  width: 28px;
  height: 28px;
  flex: 0 0 auto;
  color: var(--muted);
  background: transparent;
  border-color: transparent;
}
.icon-btn--sm:hover { color: var(--text); border-color: var(--line); }

.row { margin-top: 14px; }
.row label {
  display: block;
  font-size: 11px;
  color: var(--muted);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

label.check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  cursor: pointer;
  text-transform: none;
  letter-spacing: 0;
  color: var(--text);
  margin-bottom: 0;
}
label.check input { accent-color: var(--accent); width: 15px; height: 15px; }
.warn-status { margin-left: auto; font-size: 11px; color: var(--muted); }
.warn-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 12px;
  margin-top: 7px;
  font-size: 11px;
  color: var(--muted);
}
.warn-legend span { display: inline-flex; align-items: center; gap: 5px; }
.warn-legend i {
  width: 11px;
  height: 11px;
  border-radius: 2px;
  display: inline-block;
}

.hint { color: var(--muted); font-size: 10px; text-transform: none; letter-spacing: 0; }

/* Reorderable layer controls */
.layer-list { margin-top: 8px; display: flex; flex-direction: column; gap: 6px; }
.layer-row {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 7px 8px 8px;
}
.layer-row.dragging { opacity: 0.5; border-color: var(--accent); }
.layer-head { display: flex; align-items: center; gap: 7px; }
.layer-head .drag {
  cursor: grab;
  color: var(--muted);
  font-size: 13px;
  line-height: 1;
  user-select: none;
}
.layer-head .drag:active { cursor: grabbing; }
.layer-vis { accent-color: var(--accent); width: 14px; height: 14px; flex: 0 0 auto; }
.layer-name { font-size: 12.5px; color: var(--text); }
.layer-op { width: 100%; margin-top: 6px; accent-color: var(--accent); display: block; }

/* Horizontal color scale */
#legend-bar { margin-top: 8px; }
.legend-gradient {
  height: 13px;
  border-radius: 3px;
  border: 1px solid rgba(255, 255, 255, 0.15);
}
.legend-ticks { position: relative; height: 15px; margin-top: 3px; }
.legend-ticks .tick {
  position: absolute;
  transform: translateX(-50%);
  font-size: 10px;
  color: var(--muted);
  white-space: nowrap;
}

/* Warning details popup (dark themed) */
.maplibregl-popup-content {
  background: #10161e;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 10px 28px 11px 12px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.5);
  font-family: inherit;
  max-height: 48vh;
  overflow-y: auto;
}
.maplibregl-popup-close-button {
  color: var(--muted);
  font-size: 17px;
  width: 22px;
  padding-right: 4px;
}
.maplibregl-popup-close-button:hover { color: var(--text); background: transparent; }
.maplibregl-popup-anchor-top .maplibregl-popup-tip,
.maplibregl-popup-anchor-top-left .maplibregl-popup-tip,
.maplibregl-popup-anchor-top-right .maplibregl-popup-tip { border-bottom-color: #10161e; }
.maplibregl-popup-anchor-bottom .maplibregl-popup-tip,
.maplibregl-popup-anchor-bottom-left .maplibregl-popup-tip,
.maplibregl-popup-anchor-bottom-right .maplibregl-popup-tip { border-top-color: #10161e; }
.maplibregl-popup-anchor-left .maplibregl-popup-tip { border-right-color: #10161e; }
.maplibregl-popup-anchor-right .maplibregl-popup-tip { border-left-color: #10161e; }
.warn-popup .wp-count {
  font-size: 10px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
}
.warn-popup .wp-sep { border-top: 1px solid var(--line); margin: 10px 0; }
.warn-popup .wp-title { font-weight: 700; font-size: 13.5px; margin-bottom: 5px; }
.warn-popup .wp-until { font-size: 12px; }
.warn-popup .wp-until span {
  color: var(--muted);
  text-transform: uppercase;
  font-size: 10px;
  letter-spacing: 0.5px;
  margin-right: 4px;
}
.warn-popup .wp-area { font-size: 11px; color: var(--muted); margin-top: 6px; line-height: 1.4; }
.warn-popup .wp-src { font-size: 10px; color: var(--muted); margin-top: 6px; }
.warn-popup .wp-details-toggle {
  display: inline-block; margin-top: 8px; font-size: 12px; font-weight: 600;
  color: #6db3ff; text-decoration: none; cursor: pointer;
}
.warn-popup .wp-details-toggle:hover { text-decoration: underline; }
.warn-popup .wp-details {
  margin-top: 7px; padding-top: 7px; border-top: 1px solid var(--line);
  font-size: 11px; line-height: 1.45; color: #cdd6e2;
  max-height: 220px; overflow-y: auto;
}

.time { font-size: 13px; line-height: 1.5; }
.time .k {
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.time .utc { color: var(--muted); font-size: 12px; }

.stale {
  margin-top: 6px;
  color: #ffcf4d;
  font-size: 12px;
  font-weight: 600;
}
.hidden { display: none; }

.legend { margin-top: 16px; }
.legend .k {
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
}
.legend-stop {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  margin: 3px 0;
}
.legend-swatch {
  width: 18px;
  height: 12px;
  border-radius: 2px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  flex: 0 0 auto;
}

.status {
  margin-top: 12px;
  font-size: 11px;
  color: var(--muted);
  min-height: 14px;
}
.status.err { color: #ff6b6b; }

.disclaimer {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 5;
  padding: 7px 12px;
  font-size: 11px;
  color: var(--muted);
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.75) 40%);
  text-align: center;
}

.maplibregl-ctrl-attrib { font-size: 10px; }

/* --- "My location" geolocation marker (dot + optional name label) --- */
.user-loc {
  position: relative;
  width: 0;
  height: 0;
  pointer-events: none;
}
.user-loc-dot {
  position: absolute;
  left: 0; top: 0;
  width: 16px; height: 16px;
  margin: -8px 0 0 -8px;
  border-radius: 50%;
  background: #2f86ff;
  border: 2.5px solid #fff;
  box-shadow: 0 0 0 2px rgba(47, 134, 255, 0.45), 0 1px 4px rgba(0, 0, 0, 0.6);
}
.user-loc-dot::before {
  content: "";
  position: absolute;
  left: 50%; top: 50%;
  width: 16px; height: 16px;
  margin: -8px 0 0 -8px;
  border-radius: 50%;
  background: rgba(47, 134, 255, 0.5);
  animation: user-loc-pulse 2.6s ease-out infinite;
}
.user-loc-label {
  position: absolute;
  left: 13px; top: -9px;
  white-space: nowrap;
  font: 600 12px/1 ui-sans-serif, system-ui, sans-serif;
  color: #eaf2ff;
  background: rgba(14, 19, 26, 0.92);
  border: 1px solid #2f86ff;
  border-radius: 6px;
  padding: 3px 6px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.5);
}
.user-loc-label.hidden { display: none; }

/* Other users' shared locations (green, no pulse — distinct from your blue dot) */
.peer-loc { position: relative; width: 0; height: 0; pointer-events: none; }
.peer-loc-dot {
  position: absolute;
  left: 0; top: 0;
  width: 14px; height: 14px;
  margin: -7px 0 0 -7px;
  border-radius: 50%;
  background: #2ecc71;
  border: 2.5px solid #fff;
  box-shadow: 0 0 0 2px rgba(46, 204, 113, 0.4), 0 1px 4px rgba(0, 0, 0, 0.6);
}
.peer-loc-label {
  position: absolute;
  left: 12px; top: -9px;
  white-space: nowrap;
  font: 600 12px/1 ui-sans-serif, system-ui, sans-serif;
  color: #eafff2;
  background: rgba(14, 19, 26, 0.92);
  border: 1px solid #2ecc71;
  border-radius: 6px;
  padding: 3px 6px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.5);
}
.peer-loc-label.hidden { display: none; }
@keyframes user-loc-pulse {
  0%   { transform: scale(1); opacity: 0.6; }
  100% { transform: scale(3.4); opacity: 0; }
}
@media (prefers-reduced-motion: reduce) {
  .user-loc-dot::before { animation: none; display: none; }
}

/* --- "My location" panel controls --- */
.loc-row { display: flex; flex-direction: column; gap: 7px; }
.loc-track {
  display: flex;
  align-items: center;
  gap: 7px;
  cursor: pointer;
}
.loc-track input { cursor: pointer; }
.loc-track input:disabled { cursor: not-allowed; }
.loc-status { margin-left: auto; font-size: 11px; color: var(--muted); }
.loc-name {
  width: 100%;
  box-sizing: border-box;
  padding: 5px 8px;
  font-size: 12px;
  color: #e6edf5;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 6px;
}
.loc-name::placeholder { color: #7a8694; }
.loc-name:focus { outline: none; border-color: #2f86ff; }
.gps-btn {
  width: 100%;
  padding: 6px 8px;
  font-size: 12px;
  color: #e6edf5;
  background: rgba(47, 134, 255, 0.16);
  border: 1px solid rgba(47, 134, 255, 0.5);
  border-radius: 6px;
  cursor: pointer;
}
.gps-btn:hover { background: rgba(47, 134, 255, 0.26); }
.gps-btn.connected { background: rgba(46, 204, 113, 0.18); border-color: rgba(46, 204, 113, 0.6); }
