:root {
  --bg: #071018;
  --bg-elev: #0d1822;
  --card: #121c28;
  --card-2: #172333;
  --line: rgba(62, 224, 197, 0.16);
  --line-strong: rgba(232, 240, 246, 0.12);
  --text: #e8f0f6;
  --muted: #8aa0b3;
  --teal: #3ee0c5;
  --teal-dim: rgba(62, 224, 197, 0.14);
  --caution: #f5b942;
  --caution-dim: rgba(245, 185, 66, 0.14);
  --danger: #ff4d4d;
  --danger-dim: rgba(255, 77, 77, 0.16);
  --safe: #3ee0c5;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
  --radius: 18px;
  --font: "Outfit", "Segoe UI", system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bot: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font);
  min-height: 100dvh;
  overflow-x: hidden;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--teal); }

.app {
  max-width: 560px;
  margin: 0 auto;
  padding: calc(12px + var(--safe-top)) 16px calc(28px + var(--safe-bot));
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark {
  width: 36px; height: 36px; border-radius: 11px;
  background: url("../icons/icon-192.png") center/cover;
  box-shadow: 0 0 0 1px var(--line), 0 0 24px rgba(62, 224, 197, 0.18);
}
.brand h1 {
  margin: 0; font-size: 1.05rem; font-weight: 650; letter-spacing: 0.01em;
}
.brand p { margin: 0; color: var(--muted); font-size: 0.72rem; letter-spacing: 0.08em; text-transform: uppercase; }
.icon-btn {
  width: 44px; height: 44px; border: 1px solid var(--line-strong);
  background: var(--card); border-radius: 14px;
  display: grid; place-items: center;
  color: var(--text);
}
.icon-btn svg { width: 20px; height: 20px; }

.status {
  position: relative;
  border-radius: 24px;
  padding: 22px 20px 20px;
  overflow: hidden;
  background: #0b1c1c;
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  margin-bottom: 14px;
}
.status::before {
  content: "";
  position: absolute; inset: -40% -20% auto;
  height: 140%;
  background: radial-gradient(circle, var(--glow, rgba(62,224,197,0.22)), transparent 60%);
  pointer-events: none;
}
.status[data-level="caution"] { background: #1a160c; border-color: rgba(245,185,66,0.28); --glow: rgba(245,185,66,0.22); }
.status[data-level="danger"] { background: #1c0d10; border-color: rgba(255,77,77,0.35); --glow: rgba(255,77,77,0.25); }
.status[data-level="danger"].pulse { animation: dangerPulse 1.8s ease-in-out infinite; }
@keyframes dangerPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255,77,77,0.0), var(--shadow); }
  50% { box-shadow: 0 0 0 6px rgba(255,77,77,0.12), var(--shadow); }
}
.status-kicker {
  position: relative;
  font-size: 0.72rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0 0 4px;
}
.status-title {
  position: relative;
  margin: 0;
  font-size: clamp(2.4rem, 12vw, 3.3rem);
  line-height: 0.95;
  font-weight: 700;
  letter-spacing: -0.04em;
}
.status[data-level="safe"] .status-title { color: var(--safe); }
.status[data-level="caution"] .status-title { color: var(--caution); }
.status[data-level="danger"] .status-title { color: var(--danger); }
.status-copy { position: relative; margin: 10px 0 0; color: var(--text); font-size: 1rem; }
.status-meta { position: relative; margin: 8px 0 0; color: var(--muted); font-size: 0.85rem; }

.conditions {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 14px;
}
.stat {
  background: var(--card);
  border: 1px solid var(--line-strong);
  border-radius: 14px;
  padding: 10px 8px;
  text-align: center;
  min-width: 0;
}
.stat b { display: block; font-size: 0.92rem; font-weight: 650; }
.stat span { display: block; margin-top: 2px; color: var(--muted); font-size: 0.68rem; letter-spacing: 0.04em; text-transform: uppercase; }

.map-wrap {
  position: relative;
  height: 42vh;
  min-height: 260px;
  max-height: 420px;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--line-strong);
  margin-bottom: 8px;
  background: #0a1218;
}
#map { height: 100%; width: 100%; background: #0a1218; }
.map-tools {
  position: absolute;
  left: 10px; bottom: 12px;
  z-index: 500;
  display: flex; gap: 6px; flex-wrap: wrap;
  max-width: 58%;
}
.chip {
  border: 0;
  background: rgba(7, 16, 24, 0.82);
  color: var(--text);
  backdrop-filter: blur(8px);
  border-radius: 999px;
  padding: 8px 12px;
  font-size: 0.8rem;
  border: 1px solid var(--line-strong);
}
.chip[aria-pressed="true"] { background: var(--teal); color: #071018; border-color: transparent; font-weight: 650; }
.map-credit {
  margin: 0 2px 4px;
  font-size: 0.68rem;
  color: var(--muted);
  line-height: 1.4;
}
.radar-time {
  position: absolute;
  right: 10px; bottom: 12px;
  z-index: 500;
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--text);
  background: rgba(7, 16, 24, 0.82);
  border-radius: 999px;
  padding: 6px 10px;
  border: 1px solid var(--line-strong);
}
.leaflet-control-attribution {
  background: rgba(7,16,24,0.75) !important;
  color: #8aa0b3 !important;
  font-size: 9px !important;
  max-width: 70%;
}
.leaflet-control-attribution a { color: #3ee0c5 !important; }
.leaflet-bar a { background: #121c28 !important; color: #e8f0f6 !important; border-bottom-color: #243044 !important; }
.user-marker { background: none; border: 0; }
.user-dot {
  display: block; width: 22px; height: 22px; border-radius: 50%;
  background: #3ee0c5;
  box-shadow: 0 0 0 6px rgba(62,224,197,0.25), 0 0 0 11px rgba(62,224,197,0.12);
}

.radius-card, .panel, .threat, .later, .banner, .footer {
  background: var(--card);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
}
.radius-card { padding: 14px 16px 16px; margin: 10px 0 14px; }
.radius-row, .sheet-row, .setting-row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
}
.radius-card label, .setting-row span, .field-label { color: var(--muted); font-size: 0.82rem; }
.radius-value, .value-pill {
  font-family: var(--mono);
  font-size: 0.85rem;
  color: var(--teal);
}
input[type="range"] {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 28px; background: transparent; margin: 8px 0 0;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 6px; border-radius: 999px;
  background: linear-gradient(90deg, var(--teal), #1a6d62);
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--text); border: 3px solid var(--teal);
  margin-top: -8px; box-shadow: 0 0 0 4px rgba(62,224,197,0.12);
}
input[type="range"]::-moz-range-track {
  height: 6px; border-radius: 999px; background: #1a6d62;
}
input[type="range"]::-moz-range-thumb {
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--text); border: 3px solid var(--teal);
}

.section-title {
  display: flex; align-items: baseline; justify-content: space-between;
  margin: 4px 2px 10px;
  font-size: 0.78rem; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted);
}

.threats { display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; }
.threat {
  padding: 14px 14px 14px 16px;
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 10px 12px;
  align-items: start;
}
.threat[data-level="danger"] { border-color: rgba(255,77,77,0.35); background: linear-gradient(180deg, rgba(255,77,77,0.08), var(--card)); }
.threat[data-level="caution"] { border-color: rgba(245,185,66,0.28); }
.badge {
  width: 38px; height: 38px; border-radius: 12px;
  display: grid; place-items: center;
  background: var(--teal-dim); color: var(--teal);
}
.threat[data-level="danger"] .badge { background: var(--danger-dim); color: var(--danger); }
.threat[data-level="caution"] .badge { background: var(--caution-dim); color: var(--caution); }
.badge svg { width: 20px; height: 20px; }
.threat h3 { margin: 0; font-size: 1rem; font-weight: 650; }
.threat p { margin: 3px 0 0; color: var(--muted); font-size: 0.86rem; }
.threat .eta {
  text-align: right;
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--text);
}
.pill {
  display: inline-block;
  margin-top: 6px;
  font-size: 0.68rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 3px 7px;
  border-radius: 999px;
  background: var(--teal-dim);
  color: var(--teal);
}
.threat[data-level="danger"] .pill { background: var(--danger-dim); color: #ffb3b3; }
.empty {
  padding: 20px; text-align: center; color: var(--muted); font-size: 0.92rem;
}

.hourly {
  display: flex; gap: 8px; overflow-x: auto;
  padding: 2px 2px 12px; margin-bottom: 8px;
  scroll-snap-type: x mandatory; -webkit-overflow-scrolling: touch;
}
.hour {
  flex: 0 0 74px; scroll-snap-align: start;
  background: var(--card); border: 1px solid var(--line-strong);
  border-radius: 14px; padding: 10px 6px; text-align: center;
}
.hour[data-level="caution"] { border-color: rgba(245,185,66,0.4); }
.hour[data-level="danger"] { border-color: rgba(255,77,77,0.5); background: #1c1013; }
.hour .t { font-family: var(--mono); font-size: 0.72rem; color: var(--muted); }
.hour .c { margin-top: 6px; font-size: 0.78rem; font-weight: 600; line-height: 1.2; }
.hour .v { margin-top: 6px; font-size: 0.7rem; color: var(--muted); }

.later { padding: 12px 14px; margin-bottom: 14px; color: var(--muted); font-size: 0.88rem; }
.later strong { color: var(--caution); font-weight: 650; }

.banner {
  padding: 10px 14px; margin-bottom: 12px;
  font-size: 0.85rem; color: var(--text);
  display: none;
}
.banner.show { display: block; }
.banner.warn { border-color: rgba(245,185,66,0.35); color: #f3d28a; }
.banner.err { border-color: rgba(255,77,77,0.4); color: #ffb3b3; }
.banner.offline { border-color: rgba(138,160,179,0.3); }

.actions { display: flex; gap: 8px; margin: 8px 0 16px; }
.btn {
  flex: 1; min-height: 48px; border-radius: 14px; border: 1px solid var(--line-strong);
  background: var(--card-2); font-weight: 600;
}
.btn.primary { background: var(--teal); color: #071018; border: 0; }
.btn:disabled { opacity: 0.55; }

.footer { padding: 14px; font-size: 0.75rem; color: var(--muted); line-height: 1.5; }
.footer h4 { margin: 0 0 6px; color: var(--text); font-size: 0.8rem; letter-spacing: 0.08em; text-transform: uppercase; font-weight: 650; }

/* Settings sheet */
.sheet-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.55);
  z-index: 2000; opacity: 0; pointer-events: none; transition: opacity 0.2s;
}
.sheet-backdrop.open { opacity: 1; pointer-events: auto; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 2001;
  max-width: 560px; margin: 0 auto;
  background: #101924; border: 1px solid var(--line-strong);
  border-radius: 22px 22px 0 0;
  padding: 10px 16px calc(20px + var(--safe-bot));
  transform: translateY(110%); transition: transform 0.28s ease;
  max-height: 88dvh; overflow: auto;
}
.sheet.open { transform: translateY(0); }
.grab { width: 42px; height: 4px; border-radius: 999px; background: #2a3a4a; margin: 4px auto 12px; }
.sheet h2 { margin: 0 0 12px; font-size: 1.15rem; }
.setting-row, .sheet-block { padding: 10px 0; border-bottom: 1px solid var(--line-strong); }
.sheet-block:last-child, .setting-row:last-child { border-bottom: 0; }
.setting-row label { display: flex; align-items: center; justify-content: space-between; width: 100%; gap: 12px; }
select, .text-input {
  background: var(--bg); border: 1px solid var(--line-strong);
  border-radius: 10px; padding: 8px 10px; min-height: 42px;
}
.toggle { position: relative; width: 48px; height: 28px; flex: 0 0 48px; }
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle span {
  position: absolute; inset: 0; border-radius: 999px; background: #243044;
  transition: 0.2s;
}
.toggle span::after {
  content: ""; position: absolute; top: 3px; left: 3px;
  width: 22px; height: 22px; border-radius: 50%; background: #e8f0f6;
  transition: 0.2s;
}
.toggle input:checked + span { background: var(--teal); }
.toggle input:checked + span::after { transform: translateX(20px); background: #071018; }
.hint { color: var(--muted); font-size: 0.78rem; margin-top: 6px; line-height: 1.4; }

.scanning .brand-mark { animation: spin 1.4s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (min-width: 720px) {
  .app { padding-top: 24px; }
  .map-wrap { height: 380px; }
}
