:root {
  --bg: #0b0f14;
  --panel: rgba(14, 19, 26, 0.94);
  --sheet: #0e131a; /* opaque: text under an overlay must not show through */
  --line: #233042;
  --text: #e6edf3;
  --muted: #8b9bb0;
  --fix: #3ee6c4;
  --heard: #ffb547;
  --plane: #c9d6e6;
  --high: #5b6b80;
  --danger: #ff6b6b;
  --gps: #5aa9ff;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; overflow: hidden; }
button { font: inherit; color: inherit; cursor: pointer; }

#map { position: fixed; inset: 0; background: #0d1218; }
.leaflet-container { background: #0d1218; }
.leaflet-control-attribution { background: rgba(11, 15, 20, 0.7) !important; color: var(--muted) !important; font-size: 10px; }
.leaflet-control-attribution a { color: var(--muted) !important; }
.leaflet-top { top: calc(var(--safe-t) + 52px); }

.top { position: fixed; top: 0; left: 0; right: 0; z-index: 1000; display: flex; justify-content: space-between; align-items: center; padding: calc(var(--safe-t) + 10px) 16px 10px; pointer-events: none; }
.top > * { pointer-events: auto; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 650; letter-spacing: 0.02em; background: var(--panel); border: 1px solid var(--line); padding: 6px 12px; border-radius: 999px; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--high); transition: background 0.3s; }
/* hidden must win over component display rules (e.g. .sheet.guide is flex) */
[hidden] { display: none !important; }
body.listening .dot { background: var(--fix); box-shadow: 0 0 0 0 var(--fix); animation: ping 1.6s infinite; }
@keyframes ping { 0% { box-shadow: 0 0 0 0 rgba(62, 230, 196, 0.6); } 100% { box-shadow: 0 0 0 10px rgba(62, 230, 196, 0); } }
.chip { background: var(--panel); border: 1px solid var(--line); padding: 6px 12px; border-radius: 999px; font-size: 13px; }

.panel { position: fixed; left: 0; right: 0; bottom: 0; z-index: 1000; background: var(--panel); border-top: 1px solid var(--line); border-radius: 16px 16px 0 0; padding: 14px 16px calc(var(--safe-b) + 12px); backdrop-filter: blur(8px); max-width: 720px; margin: 0 auto; }
.fix { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.label { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; }
.big { font-size: 20px; font-weight: 650; font-variant-numeric: tabular-nums; }
.big.good { color: var(--fix); }
.sub { color: var(--muted); font-size: 13px; }
.primary { background: var(--fix); color: #04241e; border: 0; border-radius: 10px; padding: 10px 16px; font-weight: 650; }
.primary.round { width: 56px; height: 56px; border-radius: 50%; display: grid; place-items: center; flex: none; padding: 0; }
body.listening .primary.round { background: var(--danger); color: #2a0606; }
.ghost { background: transparent; border: 1px solid var(--line); border-radius: 10px; padding: 9px 14px; color: var(--text); }
.ghost.small { padding: 5px 10px; font-size: 13px; }

.catchup { margin: 12px 0 0; font-size: 13px; color: var(--text); }
.catchup[hidden] { display: none; }
.catchup .bar { height: 4px; margin-top: 6px; border-radius: 2px; background: var(--line); overflow: hidden; }
.catchup .bar > div { height: 100%; width: 0; background: var(--fix); transition: width 0.2s; }

#spec { display: block; width: 100%; height: 96px; margin: 12px 0 10px; border-radius: 8px; background: #05080c; image-rendering: pixelated; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.stats > div { display: flex; flex-direction: column; min-width: 0; }
.stats span:last-child { font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.events { list-style: none; margin: 10px 0 0; padding: 0; max-height: 66px; overflow-y: auto; font-size: 13px; color: var(--muted); }
.events li { display: flex; justify-content: space-between; gap: 8px; padding: 2px 0; }
.events b { color: var(--heard); font-weight: 600; }
.foot { display: flex; justify-content: space-between; align-items: center; margin-top: 10px; font-size: 13px; color: var(--muted); }
.toggles { display: flex; flex-wrap: wrap; gap: 4px 14px; }
.toggle { display: flex; gap: 6px; align-items: center; }
.toggle[hidden] { display: none; }
.sub.gps { color: var(--gps); }

body.choosing .panel { display: none; }
.chips { display: flex; gap: 8px; }

.sheet { position: fixed; z-index: 1100; left: 16px; right: 16px; top: calc(var(--safe-t) + 60px); max-width: 520px; margin: 0 auto; background: var(--sheet); box-shadow: 0 12px 40px rgba(0, 0, 0, 0.55); border: 1px solid var(--line); border-radius: 14px; padding: 16px; }
.sheet h2 { margin: 0 0 6px; font-size: 17px; }
.sheet p { margin: 0 0 12px; color: var(--muted); font-size: 14px; }
.sheet .row { display: flex; justify-content: space-between; font-size: 14px; }
.sheet input[type=range] { width: 100%; accent-color: var(--fix); margin: 8px 0 14px; }
.actions { display: flex; justify-content: flex-end; gap: 8px; }

.toast { position: fixed; z-index: 1200; left: 50%; transform: translateX(-50%); top: calc(var(--safe-t) + 64px); background: #1b2633; border: 1px solid var(--line); padding: 8px 14px; border-radius: 10px; font-size: 14px; max-width: calc(100% - 32px); }
/* While picking an area the setup sheet sits at the top; keep hints clear of it. */
body.choosing .toast { top: auto; bottom: calc(var(--safe-b, 0px) + 24px); }

.plane { width: 28px; height: 28px; }
.plane svg { width: 28px; height: 28px; filter: drop-shadow(0 1px 2px #000); }
.plane-label { position: absolute; left: 26px; top: 4px; white-space: nowrap; font-size: 11px; color: var(--plane); text-shadow: 0 1px 2px #000, 0 0 4px #000; font-variant-numeric: tabular-nums; }
.plane.heard .plane-label { color: var(--heard); font-weight: 600; }
.plane-type { display: block; font-size: 10px; opacity: 0.8; font-weight: 400; }
.leaflet-tooltip.gps-label { background: rgba(11, 15, 20, 0.85); border: 1px solid var(--gps); color: var(--gps); box-shadow: none; font-size: 12px; font-weight: 600; padding: 1px 6px; }
.leaflet-tooltip.gps-label::before { display: none; }
.leaflet-tooltip.truth-label { background: rgba(11, 15, 20, 0.8); border: 1px solid #ff8bd1; box-shadow: none; }
.leaflet-tooltip.truth-label::before { display: none; }
.truth-label { color: #ff8bd1; font-size: 11px; white-space: nowrap; text-shadow: 0 1px 2px #000; }

@media (max-width: 420px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
  .big { font-size: 18px; }
}

/* ---------- guide slideshow ---------- */
.sheet.guide { padding: 16px 0 12px; display: flex; flex-direction: column; max-height: calc(100% - var(--safe-t) - 80px); }
.guide-close { position: absolute; top: 6px; right: 8px; z-index: 2; background: none; border: 0; color: var(--muted); font-size: 26px; line-height: 1; padding: 6px 10px; }
.guide .slides { overflow: hidden; flex: 1 1 auto; min-height: 0; touch-action: pan-y; }
.guide .track { display: flex; height: 100%; transition: transform 0.35s ease; }
.guide .slide { flex: 0 0 100%; padding: 4px 18px 8px; overflow-y: auto; }
.guide h2 { margin: 6px 0 6px; font-size: 18px; }
.guide .kicker { margin: 0; color: var(--fix); font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em; }
.guide p { margin: 0 0 10px; color: var(--text); font-size: 14px; }
.guide p.muted { color: var(--muted); font-size: 13px; }
.guide .tips { margin: 0 0 10px; padding-left: 18px; font-size: 14px; }
.guide .tips li { margin: 6px 0; }
.guide .toggle { margin: 8px 0 2px; font-size: 14px; }
.sheet.share .toggle { margin: 12px 0 2px; font-size: 15px; }
.sheet.share p.muted { font-size: 13px; margin: 2px 0 6px 24px; }
.sheet.share .actions { margin-top: 14px; }
.guide-nav { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 16px 0; }
.guide-nav .ghost[disabled] { visibility: hidden; }
.dots { display: flex; gap: 6px; }
.dots button { width: 7px; height: 7px; padding: 0; border-radius: 50%; border: 0; background: var(--line); }
.dots button[aria-selected="true"] { background: var(--fix); width: 18px; border-radius: 4px; }
.linkish { background: none; border: 0; padding: 0; color: var(--fix); text-decoration: underline; font-size: 14px; }

.art { width: 100%; max-height: 150px; display: block; margin: 0 auto 6px; }
.art .ground, .art .axis { stroke: var(--line); stroke-width: 1.5; }
.art .mark { stroke: var(--muted); stroke-dasharray: 3 4; }
.art .label { fill: var(--muted); font-size: 11px; }
.art .label.muted { opacity: 0.7; }
.art .plane-art { stroke: var(--text); stroke-width: 2.4; fill: none; stroke-linecap: round; stroke-linejoin: round; }
.art .phone-art { fill: none; stroke: var(--fix); stroke-width: 2; }
.art .path { stroke: var(--muted); stroke-width: 1.5; stroke-dasharray: 6 5; fill: none; }
.art .ring, .art .pulse { fill: none; stroke: var(--fix); stroke-width: 1.5; }
.art .glide { fill: none; stroke: var(--fix); stroke-width: 3; stroke-linecap: round; stroke-dasharray: 340; stroke-dashoffset: 340; }
.art .band { fill: var(--fix); opacity: 0.16; }
.art .fix-dot { fill: var(--fix); }
.grid-art .cell { fill: var(--line); }
.grid-art .cell.match { fill: var(--fix); }

@media (prefers-reduced-motion: no-preference) {
  .art .fly { animation: fly 7s linear infinite; }
  .art .ring { animation: ring 1.8s ease-out infinite; }
  .art .ring.r2 { animation-delay: 0.6s; }
  .art .ring.r3 { animation-delay: 1.2s; }
  .art .pulse { animation: ring 2s ease-out infinite; }
  .art .pulse.p2 { animation-delay: 1s; }
  .slide.active .glide { animation: draw 2.4s ease-in-out forwards; }
  .grid-art .cell { animation: flicker 2.6s ease-in-out infinite; }
  .grid-art .cell.match { animation: glow 1.4s ease-in-out infinite; }
  .art .band { animation: breathe 3s ease-in-out infinite; }
  .art .band.b2 { animation-delay: 1.5s; }
  .art .fix-dot { animation: glow 1.4s ease-in-out infinite; }
}
@media (prefers-reduced-motion: reduce) {
  .art .fly { transform: translateX(160px); }
  .art .glide { stroke-dashoffset: 0; }
  .guide .track { transition: none; }
}
@keyframes fly { from { transform: translateX(-30px); } to { transform: translateX(350px); } }
@keyframes ring { from { r: 6px; opacity: 0.9; } to { r: 46px; opacity: 0; } }
@keyframes draw { to { stroke-dashoffset: 0; } }
@keyframes flicker { 0%, 100% { opacity: 0.35; } 50% { opacity: 0.8; } }
@keyframes glow { 0%, 100% { opacity: 1; } 50% { opacity: 0.45; } }
@keyframes breathe { 0%, 100% { opacity: 0.1; } 50% { opacity: 0.28; } }

.sheet.privacy { max-height: calc(100% - var(--safe-t) - 80px); overflow-y: auto; }
.sheet.privacy h1 { font-size: 18px; margin: 0 0 6px; }
.sheet.privacy h2 { font-size: 15px; margin: 16px 0 6px; color: var(--fix); }
.sheet.privacy p, .sheet.privacy li { font-size: 14px; color: var(--text); }
.sheet.privacy ul { padding-left: 18px; }
.sheet.privacy .todo { background: #5c4400; color: #fff3cd; padding: 0 4px; border-radius: 3px; }
