:root {
  --bg: #0b1220;
  --panel: #121b2e;
  --panel-2: #1a2540;
  --line: #26324d;
  --text: #e8eefc;
  --muted: #8c9ab8;
  --accent: #ff8a3d;
  --accent-2: #ffb36b;
  --danger: #ff4d5e;
  --ok: #3ddc97;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --topbar-h: 56px;
  --tabbar-h: 60px;
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); overflow: hidden; }
body { font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; overscroll-behavior: none; }
button { font: inherit; color: inherit; }
.hidden { display: none !important; }

/* Top bar */
.topbar {
  position: fixed; inset: 0 0 auto 0; z-index: 1000;
  height: calc(var(--topbar-h) + var(--safe-top)); padding: var(--safe-top) 12px 0 14px;
  display: flex; align-items: center; justify-content: space-between;
  background: linear-gradient(to bottom, rgba(11,18,32,.96), rgba(11,18,32,.85));
  backdrop-filter: blur(8px); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand h1 { margin: 0; font-size: 17px; letter-spacing: .2px; }
.status { margin: 0; font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 70vw; }
.status .dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--ok); margin-right: 5px; vertical-align: 1px; }
.status .dot.bad { background: var(--danger); }
.icon-btn { background: none; border: 0; padding: 8px; color: var(--muted); border-radius: 10px; }
.icon-btn:active { background: var(--panel-2); }

/* Views */
main { z-index: 1; position: fixed; inset: calc(var(--topbar-h) + var(--safe-top)) 0 calc(var(--tabbar-h) + var(--safe-bottom)) 0; }
.view { position: absolute; inset: 0; display: none; }
.view.active { display: block; }
#map { position: absolute; inset: 0; background: #0e1626; }
#map.map-light { background: #f2efe9; }
/* Recolor standard OpenStreetMap tiles into a dark theme */
.tiles-dark { filter: invert(1) hue-rotate(180deg) brightness(.9) contrast(.85) saturate(.5); }

/* Tab bar */
.tabbar {
  position: fixed; inset: auto 0 0 0; z-index: 1000;
  height: calc(var(--tabbar-h) + var(--safe-bottom)); padding-bottom: var(--safe-bottom);
  display: grid; grid-template-columns: repeat(3, 1fr);
  background: var(--panel); border-top: 1px solid var(--line);
}
.tab { background: none; border: 0; color: var(--muted); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: 11px; }
.tab.active { color: var(--accent); }

/* Map markers */
.plane-marker { position: relative; width: 34px; height: 34px; }
.plane-marker svg { width: 34px; height: 34px; filter: drop-shadow(0 1px 2px rgba(0,0,0,.8)); transition: transform .4s linear; }
.plane-marker .lbl {
  position: absolute; left: 30px; top: 6px; white-space: nowrap;
  font: 600 11px/1 system-ui, sans-serif; color: #fff; background: rgba(11,18,32,.75);
  padding: 3px 5px; border-radius: 5px; pointer-events: none;
}
.plane-marker.selected svg { filter: drop-shadow(0 0 6px var(--accent)) drop-shadow(0 1px 2px #000); }
.plane-marker.selected .lbl { background: var(--accent); color: #111; }
.plane-marker.emergency .lbl { background: var(--danger); }
.me-marker { width: 18px; height: 18px; border-radius: 50%; background: #4da3ff; border: 3px solid #fff; box-shadow: 0 0 0 6px rgba(77,163,255,.25); }
.airport-marker { font: 700 11px/1 system-ui, sans-serif; color: #111; background: var(--accent-2); padding: 3px 5px; border-radius: 4px; white-space: nowrap; transform: translate(-50%, -50%); display: inline-block; }
.leaflet-container { font: inherit; }
.leaflet-control-attribution { background: rgba(11,18,32,.7) !important; color: var(--muted) !important; font-size: 10px; }
.leaflet-control-attribution a { color: var(--muted) !important; }
.leaflet-bar a { background: var(--panel) !important; color: var(--text) !important; border-color: var(--line) !important; }

.map-tools { position: absolute; right: 12px; bottom: 16px; z-index: 500; display: flex; flex-direction: column; gap: 10px; }
.fab { width: 46px; height: 46px; border-radius: 50%; border: 1px solid var(--line); background: var(--panel); color: var(--text); display: grid; place-items: center; box-shadow: 0 4px 14px rgba(0,0,0,.4); }

/* Sky view */
#view-sky { background: radial-gradient(ellipse at 50% 120%, #1d2b4d 0%, #0b1220 60%, #05080f 100%); overflow: hidden; touch-action: none; }
#camera { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
#sky { position: absolute; inset: 0; width: 100%; height: 100%; }
.reticle { position: absolute; left: 50%; top: 50%; width: 64px; height: 64px; margin: -32px 0 0 -32px; border: 2px solid rgba(255,255,255,.55); border-radius: 50%; pointer-events: none; }
.reticle::after { content: ""; position: absolute; left: 50%; top: 50%; width: 4px; height: 4px; margin: -2px; background: #fff; border-radius: 50%; }
.sky-hint { position: absolute; left: 12px; right: 12px; top: 96px; padding: 10px 12px; border-radius: 12px; background: rgba(11,18,32,.85); border: 1px solid var(--line); font-size: 13px; text-align: center; }
.sky-tools { position: absolute; left: 0; right: 0; bottom: 12px; display: flex; justify-content: center; gap: 8px; pointer-events: none; }
.pill { pointer-events: auto; border: 1px solid var(--line); background: rgba(18,27,46,.88); color: var(--text); padding: 8px 12px; border-radius: 999px; font-size: 13px; }
.target-card {
  position: absolute; left: 12px; right: 12px; bottom: 58px; padding: 12px 14px; border-radius: 14px;
  background: rgba(18,27,46,.92); border: 1px solid var(--accent); display: flex; align-items: center; gap: 12px;
  backdrop-filter: blur(6px);
}
.target-card .t-main { flex: 1; min-width: 0; }
.target-card .t-cs { font-weight: 700; font-size: 17px; }
.target-card .t-sub { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.target-card button { border: 0; background: var(--accent); color: #111; font-weight: 700; padding: 9px 12px; border-radius: 10px; }

/* List */
#view-list { overflow-y: auto; -webkit-overflow-scrolling: touch; }
.plane-list { list-style: none; margin: 0; padding: 8px 10px 20px; }
.plane-list li { display: flex; align-items: center; gap: 12px; padding: 12px; margin-bottom: 8px; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; }
.plane-list li:active { background: var(--panel-2); }
.plane-list .alt-chip { width: 10px; align-self: stretch; border-radius: 6px; }
.plane-list .main { flex: 1; min-width: 0; }
.plane-list .cs { font-weight: 700; }
.plane-list .sub { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.plane-list .dist { text-align: right; font-variant-numeric: tabular-nums; }
.plane-list .dist small { display: block; color: var(--muted); }
.plane-list .bearing { width: 26px; height: 26px; color: var(--accent); }
.badge { display: inline-block; font-size: 10px; font-weight: 700; padding: 2px 6px; border-radius: 6px; background: var(--accent); color: #111; margin-left: 6px; vertical-align: 2px; }
.badge.red { background: var(--danger); color: #fff; }
.empty { text-align: center; color: var(--muted); padding: 40px 20px; }

/* Bottom sheet */
.sheet {
  position: fixed; left: 0; right: 0; bottom: calc(var(--tabbar-h) + var(--safe-bottom)); z-index: 900;
  max-height: 72vh; overflow-y: auto; background: var(--panel); border-top: 1px solid var(--line);
  border-radius: 18px 18px 0 0; box-shadow: 0 -10px 30px rgba(0,0,0,.5);
  transform: translateY(calc(100% + var(--tabbar-h) + 40px)); visibility: hidden; transition: transform .25s ease, visibility 0s .25s; padding: 6px 16px 18px;
}
.sheet.open { transform: translateY(0); visibility: visible; transition: transform .25s ease; }
.sheet-grip { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 4px auto 10px; }
.sh-head { display: flex; align-items: flex-start; gap: 10px; }
.sh-head .t { flex: 1; min-width: 0; }
.sh-head h2 { margin: 0; font-size: 22px; }
.sh-head .sub { color: var(--muted); font-size: 13px; }
.sh-close { background: var(--panel-2); border: 0; width: 32px; height: 32px; border-radius: 50%; color: var(--muted); font-size: 18px; }
.route { display: flex; align-items: center; gap: 10px; margin: 14px 0 6px; }
.route .ap { text-align: center; min-width: 60px; }
.route .ap b { display: block; font-size: 22px; letter-spacing: 1px; }
.route .ap small { color: var(--muted); font-size: 11px; display: block; max-width: 110px; }
.route .bar { flex: 1; height: 4px; background: var(--line); border-radius: 2px; position: relative; }
.route .bar i { position: absolute; inset: 0 auto 0 0; background: var(--accent); border-radius: 2px; }
.route .bar svg { position: absolute; top: -9px; width: 22px; height: 22px; margin-left: -11px; color: var(--accent); transform: rotate(90deg); }
.photo { width: 100%; border-radius: 12px; margin: 10px 0 4px; aspect-ratio: 16/9; object-fit: cover; background: var(--panel-2); }
.photo-credit { font-size: 10px; color: var(--muted); margin: 0 0 6px; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 12px 0; }
.stat { background: var(--panel-2); border-radius: 10px; padding: 8px 10px; }
.stat small { display: block; color: var(--muted); font-size: 11px; }
.stat b { font-variant-numeric: tabular-nums; font-size: 15px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.actions button { flex: 1 1 auto; border: 1px solid var(--line); background: var(--panel-2); padding: 10px 12px; border-radius: 10px; font-weight: 600; }
.actions button.hot { background: var(--accent); border-color: var(--accent); color: #111; }
.splain { margin-top: 12px; padding: 12px 14px; border-radius: 12px; background: #20180f; border: 1px solid #5a3a1c; font-size: 14px; }
.splain p { margin: 0 0 8px; }
.splain .who { color: var(--accent-2); font-weight: 700; font-size: 12px; text-transform: uppercase; letter-spacing: .6px; }

/* Modals */
.modal { position: fixed; inset: 0; z-index: 2000; background: rgba(5,8,15,.75); display: grid; place-items: center; padding: 20px; }
.modal-card { width: min(420px, 100%); max-height: 90vh; overflow-y: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 20px; }
.modal-card h2 { margin: 0 0 12px; }
.modal-card label { display: block; margin: 14px 0 4px; font-size: 14px; color: var(--muted); }
.modal-card label.row { display: flex; align-items: center; gap: 10px; color: var(--text); }
.modal-card output { float: right; color: var(--text); }
.modal-card input[type=range], .modal-card select { width: 100%; margin-top: 6px; }
.modal-card select { background: var(--panel-2); color: var(--text); border: 1px solid var(--line); border-radius: 10px; padding: 9px; }
.modal-card input[type=range] { accent-color: var(--accent); }
.primary { width: 100%; margin-top: 18px; border: 0; background: var(--accent); color: #111; font-weight: 700; padding: 13px; border-radius: 12px; font-size: 16px; }
.link { background: none; border: 0; color: var(--muted); margin-top: 10px; text-decoration: underline; width: 100%; padding: 8px; }
.fine { color: var(--muted); font-size: 12px; margin: 10px 0 0; }
.splash-card { text-align: center; }
.logo-panel { background: #fff; border-radius: 14px; padding: 16px 18px; margin-bottom: 14px; }
.logo-panel img { display: block; width: 100%; max-width: 220px; height: auto; margin: 0 auto; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.tagline { color: var(--muted); margin: 0 0 6px; }

.toast { position: fixed; left: 50%; top: calc(var(--topbar-h) + var(--safe-top) + 10px); transform: translateX(-50%); z-index: 2100; background: var(--panel-2); border: 1px solid var(--line); padding: 9px 14px; border-radius: 10px; font-size: 13px; max-width: 90vw; }
