:root {
  --bg: #0d1117;
  --card: #161b22;
  --card-2: #1c232d;
  --line: #2a323d;
  --text: #e6edf3;
  --muted: #8b949e;
  --accent: #58a6ff;
  --good: #3fb950;
  --warn: #d29922;
  --bad: #f85149;
  --route: #c9a2ff;
  --trail: #58a6ff;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding: max(10px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
  max-width: 1500px;
  margin: 0 auto;
}
button { font: inherit; cursor: pointer; }

/* ---------- header */
.top { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 6px 0 10px; }
.callsign { font-size: 13px; letter-spacing: .08em; color: var(--muted); font-weight: 600; }
.route { font-size: 21px; font-weight: 700; line-height: 1.2; }
.route small { font-size: 13px; color: var(--muted); font-weight: 500; }
.aircraft { font-size: 13px; color: var(--muted); }
.top-side { display: flex; align-items: center; gap: 10px; flex-shrink: 0; padding-top: 4px; }
.phase {
  padding: 4px 10px; border-radius: 999px; font-size: 13px; font-weight: 700;
  background: var(--card-2); border: 1px solid var(--line); color: var(--muted);
}
.phase[data-phase="Taxi"], .phase[data-phase="Landed"] { color: var(--warn); border-color: #5c4813; }
.phase[data-phase="Takeoff"], .phase[data-phase="Climb"] { color: var(--good); border-color: #23532c; }
.phase[data-phase="Cruise"] { color: var(--accent); border-color: #1f4570; }
.phase[data-phase="Descent"], .phase[data-phase="Approach"] { color: var(--route); border-color: #4a3870; }
.conn { width: 11px; height: 11px; border-radius: 50%; background: var(--bad); box-shadow: 0 0 0 3px #f8514922; }
.conn.ok { background: var(--good); box-shadow: 0 0 0 3px #3fb95022; }
.conn.partial { background: var(--warn); box-shadow: 0 0 0 3px #d2992222; }

/* ---------- banner + status */
.banner {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 6px 16px;
  background: linear-gradient(90deg, #1f4570, #2b2150); border: 1px solid #2f5f99;
  border-radius: 12px; padding: 12px 14px; margin-bottom: 10px; font-weight: 600;
}
.banner[hidden] { display: none; }
.banner-count { font-variant-numeric: tabular-nums; color: #bcd7ff; }
.status-line { margin: 0 0 10px; color: var(--muted); font-size: 14px; min-height: 1.4em; }

/* ---------- alerts */
.alerts {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px 16px;
  background: var(--card); border: 1px solid #2f5f99; border-radius: 12px; padding: 12px 14px; margin-bottom: 12px;
}
.alerts[hidden] { display: none; }
.alerts-text { flex: 1 1 240px; }
.alerts-text b { color: var(--accent); }
.alerts-actions { display: flex; gap: 8px; align-items: center; }
.alerts-btn {
  border: 0; border-radius: 10px; padding: 9px 14px; background: var(--accent); color: #04121f; font-weight: 700;
}
.alerts-btn[hidden] { display: none; }
.alerts-x, .link-btn { border: 0; background: none; color: var(--muted); padding: 6px; text-decoration: underline; }
.link-btn[hidden] { display: none; }
.foot { margin: 16px 0 4px; color: var(--muted); font-size: 13px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* ---------- layout */
.layout { display: grid; gap: 12px; }
.col-a, .col-b { display: grid; gap: 12px; align-content: start; min-width: 0; }
@media (min-width: 900px) {
  .layout { grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); }
  .col-b { position: sticky; top: 12px; }
  .map-card { height: calc(100vh - 150px); min-height: 420px; }
}

/* ---------- video */
.video-card {
  position: relative; aspect-ratio: 16 / 9; background: #000; border-radius: 12px; overflow: hidden;
  border: 1px solid var(--line);
}
.video-card video { width: 100%; height: 100%; display: block; object-fit: contain; background: #000; }
.video-label {
  position: absolute; top: 8px; left: 8px; padding: 3px 8px; border-radius: 6px;
  background: #000a; font-size: 12px; font-weight: 600; pointer-events: none;
}
.video-label::before { content: ""; display: inline-block; width: 7px; height: 7px; border-radius: 50%; margin-right: 6px; background: var(--muted); vertical-align: 1px; }
.video-card.live .video-label::before { background: var(--bad); }
.unmute {
  position: absolute; bottom: 10px; right: 10px; border: 0; border-radius: 8px;
  padding: 6px 10px; background: #000b; color: var(--text); font-size: 13px;
}
.unmute[hidden], .fullscreen[hidden] { display: none; }
.fullscreen {
  position: absolute; bottom: 10px; left: 10px; border: 0; border-radius: 8px;
  padding: 6px 10px; background: #000b; color: var(--text); font-size: 13px;
}
.video-offline {
  position: absolute; inset: 0; display: grid; place-items: center; text-align: center; padding: 16px;
  background: radial-gradient(circle at 50% 40%, #1c232d, #0d1117); color: var(--muted); font-weight: 600;
}
.video-card.live .video-offline { display: none; }

/* ---------- stats */
.stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
@media (min-width: 560px) { .stats { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; min-width: 0; }
.stat .k { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .05em; }
.stat .v { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat .u { font-size: 12px; color: var(--muted); }
.stat-wide { grid-column: 1 / -1; }
.stats.stale .v { opacity: .45; }
.bar { height: 8px; background: var(--card-2); border-radius: 99px; margin: 8px 0 4px; overflow: hidden; }
.bar-fill { height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), var(--route)); border-radius: 99px; transition: width 1s linear; }
.bar-ends { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); }
#s-prog { color: var(--text); }

/* ---------- map */
.map-card { position: relative; height: 58vh; min-height: 320px; border-radius: 12px; overflow: hidden; border: 1px solid var(--line); }
#map { position: absolute; inset: 0; background: #1a1d21; }
.map-btns { position: absolute; z-index: 500; top: 10px; right: 10px; display: flex; gap: 6px; }
.follow, .fit {
  border: 1px solid var(--line); border-radius: 999px;
  padding: 7px 12px; background: #161b22e6; color: var(--text); font-size: 13px; font-weight: 600;
}
.follow.on { border-color: var(--accent); color: var(--accent); }
.plane-icon { width: 34px; height: 34px; transition: none; filter: drop-shadow(0 1px 3px #000c); }
.plane-icon svg { width: 100%; height: 100%; display: block; }
.fix-label {
  background: transparent; border: 0; box-shadow: none; color: #d8c4ff; font-size: 11px; font-weight: 700;
  text-shadow: 0 0 3px #000, 0 0 3px #000; padding: 0;
}
.fix-label::before { display: none; }
.apt-label { color: #fff; font-size: 12px; }
.leaflet-container { font: inherit; }
.leaflet-control-attribution { background: #0d1117b3 !important; color: var(--muted) !important; }
.leaflet-control-attribution a { color: var(--accent) !important; }
.leaflet-bar a { background: var(--card); color: var(--text); border-color: var(--line); }

/* ---------- login */
.login { position: fixed; inset: 0; z-index: 2000; display: grid; place-items: center; padding: 16px; background: var(--bg); }
.login[hidden] { display: none; }
.login-card { width: 100%; max-width: 340px; text-align: center; }
.login-plane { font-size: 44px; color: var(--accent); transform: rotate(-30deg); }
.login-card h1 { margin: 8px 0 4px; font-size: 24px; }
.login-card p { color: var(--muted); margin: 0 0 16px; }
.login-card input {
  width: 100%; padding: 12px 14px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--card); color: var(--text); font-size: 17px; margin-bottom: 10px;
}
.login-card button {
  width: 100%; padding: 12px; border: 0; border-radius: 10px; background: var(--accent); color: #04121f;
  font-size: 17px; font-weight: 700;
}
.login-error { color: var(--bad) !important; margin-top: 10px !important; min-height: 1.4em; }
