:root {
  --bg: #111114;
  --panel: #1c1c1f;
  --row: #1a1a1d;
  --line: #2c2c31;
  --text: #ececf1;
  --dim: #9a9aa6;
  --accent: #8e3fd6;
  --accent-hi: #a868ec;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font-family: Roboto, system-ui, -apple-system, "Segoe UI", sans-serif; overflow: hidden; }
button { font: inherit; color: inherit; }

#map { position: fixed; inset: 0; background: #0d0d10; }
.leaflet-container { background: #0d0d10; font: inherit; }
.leaflet-control-attribution { background: rgba(0,0,0,.45) !important; color: #777 !important; font-size: 9px; }
.leaflet-control-attribution a { color: #999 !important; }
.leaflet-top.leaflet-right { top: var(--safe-t); }

/* ---------- bottom bar ---------- */
#bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 1000;
  background: rgba(17,17,20,.92); backdrop-filter: blur(8px);
  border-top: 1px solid var(--line);
  padding: 6px 12px calc(6px + var(--safe-b));
}
#timeline { display: flex; align-items: center; gap: 10px; }
#frame-time { min-width: 76px; font-variant-numeric: tabular-nums; font-size: 15px; font-weight: 500; }
#frame-time.latest { color: var(--accent-hi); }
#scrub { flex: 1; accent-color: var(--accent); height: 28px; }
#legend { display: flex; align-items: center; gap: 6px; font-size: 10px; color: var(--dim); margin: 2px 0 4px; }
#legend .ramp { flex: 1; height: 6px; border-radius: 3px; }
#tools { display: flex; align-items: center; gap: 4px; }
#status { margin-left: auto; font-size: 12px; color: var(--dim); text-align: right; }

.icon-btn { background: none; border: 0; padding: 8px; border-radius: 50%; cursor: pointer; display: grid; place-items: center; }
.icon-btn:active { background: rgba(255,255,255,.1); }
.icon-btn svg { width: 26px; height: 26px; fill: currentColor; }
#btn-play .i-pause { display: none; }
#btn-play.playing .i-play { display: none; }
#btn-play.playing .i-pause { display: block; }
#btn-locate.on { color: var(--accent-hi); }
#btn-refresh.spin svg { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- layers screen ---------- */
.screen { position: fixed; inset: 0; z-index: 2000; background: #000; overflow-y: auto; padding-bottom: calc(24px + var(--safe-b)); }
.screen header { position: sticky; top: 0; z-index: 1; display: flex; align-items: center; gap: 8px;
  background: var(--accent); padding: calc(8px + var(--safe-t)) 12px 8px; height: calc(64px + var(--safe-t)); }
.screen header h1 { flex: 1; margin: 0 44px 0 0; text-align: center; font-size: 20px; font-weight: 500; color: #e9dcf7; }
.list { margin: 16px 12px; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: var(--row); }
.row { display: flex; align-items: center; min-height: 58px; padding: 0 12px 0 16px; border-top: 1px solid var(--line); gap: 8px; }
.row:first-child { border-top: 0; }
.row .label { flex: 1; font-size: 17px; }
.row .label small { display: block; color: var(--dim); font-size: 12px; margin-top: 2px; }
.chev { background: none; border: 0; padding: 8px; color: var(--dim); cursor: pointer; transition: transform .15s; }
.chev svg { width: 22px; height: 22px; fill: currentColor; display: block; }
.chev.open { transform: rotate(90deg); }
.chev.hidden { visibility: hidden; }
.opts { display: none; padding: 4px 16px 14px; background: #141417; border-top: 1px solid var(--line); }
.opts.open { display: block; }
.opts label { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 0; font-size: 14px; color: var(--dim); }
.opts select, .opts input[type=range] { flex: 0 0 55%; }
.opts select { background: #222226; color: var(--text); border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; font: inherit; }
.opts input[type=range] { accent-color: var(--accent); }
.credits { color: #666; font-size: 11px; margin: 0 16px; line-height: 1.5; }

/* toggle switch */
.switch { position: relative; width: 52px; height: 32px; flex: none; }
.switch input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; z-index: 1; }
.switch span { position: absolute; inset: 0; border-radius: 16px; border: 2px solid #8a8a92; background: #2a2a2e; transition: .15s; }
.switch span::after { content: ""; position: absolute; left: 6px; top: 6px; width: 16px; height: 16px; border-radius: 50%; background: #8a8a92; transition: .15s; }
.switch input:checked + span { background: var(--accent); border-color: var(--accent); }
.switch input:checked + span::after { left: 22px; top: 2px; width: 24px; height: 24px; background: #fff; }

/* ---------- forecast sheet ---------- */
#sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 1500; max-height: 62vh; overflow-y: auto;
  background: var(--panel); border-radius: 16px 16px 0 0; border-top: 1px solid var(--line);
  padding: 8px 16px calc(16px + var(--safe-b)); box-shadow: 0 -8px 24px rgba(0,0,0,.5);
}
#sheet .grip { width: 40px; height: 4px; background: #444; border-radius: 2px; margin: 0 auto 4px; }
#btn-sheet-close { position: absolute; top: 4px; right: 6px; }
#sheet h2 { margin: 8px 40px 2px 0; font-size: 19px; font-weight: 500; }
#sheet .sub { color: var(--dim); font-size: 13px; margin-bottom: 10px; }
#sheet .now { display: flex; align-items: baseline; gap: 12px; margin: 6px 0 12px; }
#sheet .now .t { font-size: 44px; font-weight: 300; }
#sheet .now .d { color: var(--dim); }
.hourly { display: flex; gap: 14px; overflow-x: auto; padding-bottom: 8px; margin-bottom: 8px; }
.hourly div { flex: none; text-align: center; font-size: 12px; color: var(--dim); }
.hourly b { display: block; color: var(--text); font-size: 15px; font-weight: 500; margin-top: 2px; }
.days { border-top: 1px solid var(--line); }
.day { display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; padding: 9px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.day .n { font-weight: 500; }
.day .tt { text-align: right; font-variant-numeric: tabular-nums; }
.day .tt .lo { color: var(--dim); margin-left: 6px; }
.day .s { grid-column: 1 / -1; color: var(--dim); font-size: 13px; }
.alert { border-left: 4px solid #f33; background: #2a1a1d; border-radius: 6px; padding: 8px 10px; margin-bottom: 8px; }
.alert summary { cursor: pointer; font-weight: 500; }
.alert .meta { color: var(--dim); font-size: 12px; margin: 2px 0 0; }
.alert pre { white-space: pre-wrap; font: 12px/1.45 ui-monospace, monospace; color: #ccc; margin: 8px 0 0; }
.muted { color: var(--dim); font-size: 13px; }

/* ---------- map key ---------- */
#key { position: fixed; left: 8px; right: 8px; z-index: 1400; max-height: 45vh; overflow-y: auto;
  background: rgba(28,28,31,.96); border: 1px solid var(--line); border-radius: 12px; padding: 4px 14px 12px;
  box-shadow: 0 6px 20px rgba(0,0,0,.5); }
@media (min-width: 600px) { #key { right: auto; width: 340px; } }
#key header { position: sticky; top: 0; display: flex; align-items: center; background: inherit; }
#key header h2 { flex: 1; margin: 0; font-size: 16px; font-weight: 500; }
#key header .icon-btn svg { width: 22px; height: 22px; }
#key h3 { margin: 10px 0 4px; font-size: 12px; font-weight: 500; color: var(--dim); text-transform: uppercase; letter-spacing: .05em; }
.key-row { display: flex; align-items: center; gap: 10px; padding: 4px 0; font-size: 14px; }
.key-row .sw { flex: none; width: 22px; height: 14px; border-radius: 3px; box-shadow: inset 0 0 0 1px rgba(255,255,255,.15); }
.key-row .sw.line { background: transparent !important; box-shadow: none; border: 3px solid; }
.key-row .sw.dot { width: 14px; border-radius: 50%; margin: 0 4px; }
.key-row .n { margin-left: auto; color: var(--dim); font-size: 12px; font-variant-numeric: tabular-nums; }
#btn-key.on { color: var(--accent-hi); }

/* map markers */
.temp-label { color: #fff; font-size: 12px; font-weight: 700; text-align: center; line-height: 20px; border-radius: 10px;
  text-shadow: 0 0 3px #000; box-shadow: 0 0 0 1px rgba(0,0,0,.35); }
.here-dot { width: 18px; height: 18px; border-radius: 50%; background: #4aa3ff; border: 3px solid #fff; box-shadow: 0 0 0 6px rgba(74,163,255,.25); }
.pin-dot { width: 14px; height: 14px; border-radius: 50%; background: var(--accent-hi); border: 2px solid #fff; }
.leaflet-popup-content-wrapper, .leaflet-popup-tip { background: var(--panel); color: var(--text); }
.leaflet-popup-content { font-size: 13px; line-height: 1.45; margin: 10px 14px; }
.leaflet-popup-content a { color: var(--accent-hi); }
.leaflet-container a.leaflet-popup-close-button { color: var(--dim); }

#toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(130px + var(--safe-b)); z-index: 3000;
  background: #2a2a30; padding: 8px 14px; border-radius: 18px; font-size: 13px; opacity: 0; transition: opacity .2s; pointer-events: none; }
#toast.show { opacity: 1; }
