:root {
  --bg: #0b1220;
  --surface: rgba(15, 23, 42, 0.92);
  --surface-solid: #111a2e;
  --border: rgba(148, 163, 184, 0.2);
  --text: #e6ebf3;
  --muted: #94a3b8;
  --accent: #fbbf24;
  --ok: #34d399;
  --warn: #fbbf24;
  --bad: #f87171;
  --radius: 12px;
  --topbar-h: 56px;
  --panel-w: 340px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
button, input { font: inherit; color: inherit; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
[hidden] { display: none !important; }

#map { position: fixed; inset: 0; outline: none; }
.leaflet-container { background: var(--bg); font: inherit; }
.leaflet-container.basemap-light { background: #e3e9f0; }
.leaflet-control-attribution { background: rgba(11, 18, 32, 0.7) !important; color: var(--muted) !important; font-size: 10px; }
.leaflet-control-attribution a { color: #cbd5e1 !important; }
.leaflet-bar a { background: var(--surface-solid); color: var(--text); border-color: var(--border); }
.leaflet-bar a:hover { background: #1b2742; color: #fff; }

/* ---------- top bar ---------- */
.topbar {
  position: fixed; z-index: 1000; top: 10px; left: 10px; right: 10px;
  height: var(--topbar-h);
  display: flex; align-items: center; gap: 10px;
  padding: 0 10px 0 14px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); backdrop-filter: blur(10px);
}
.brand { display: flex; align-items: center; gap: 8px; color: var(--accent); white-space: nowrap; }
.brand-text { font-weight: 700; letter-spacing: 0.01em; color: var(--text); }
.brand-text span { color: var(--accent); margin-left: 4px; font-weight: 500; }

/* link back to the main website; hidden on narrow screens (the same link is in the layers menu) */
.site-link {
  white-space: nowrap; font-size: 12.5px; color: var(--muted); text-decoration: none; padding: 5px 10px;
  border: 1px solid var(--border); border-radius: 99px;
}
.site-link:hover { color: var(--text); background: rgba(148, 163, 184, 0.14); }
.site-link:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.pop .links { display: grid; gap: 6px; margin: 0; }
.pop .links a { color: var(--accent); }
.search { position: relative; flex: 1 1 280px; max-width: 420px; }
.search input {
  width: 100%; height: 38px; padding: 0 34px 0 12px;
  background: rgba(2, 6, 23, 0.55); border: 1px solid var(--border); border-radius: 9px; outline: none;
}
.search input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(251, 191, 36, 0.18); }
.search input::placeholder { color: #64748b; }
.search .hint {
  position: absolute; right: 9px; top: 9px; padding: 0 6px; height: 20px; line-height: 18px;
  font: 11px ui-monospace, monospace; color: var(--muted); border: 1px solid var(--border); border-radius: 5px; pointer-events: none;
}
.search input:focus + .hint, .search input:not(:placeholder-shown) + .hint { display: none; }

#search-results {
  position: absolute; top: 44px; left: 0; right: 0; margin: 0; padding: 4px; list-style: none;
  background: var(--surface-solid); border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow);
  max-height: 60vh; overflow: auto;
}
#search-results li { display: flex; align-items: baseline; gap: 8px; padding: 8px 10px; border-radius: 7px; cursor: pointer; }
#search-results li[aria-selected="true"], #search-results li:hover { background: rgba(251, 191, 36, 0.12); }
#search-results .sr-cs { font-weight: 700; min-width: 74px; }
#search-results .sr-meta { color: var(--muted); font-size: 12px; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#search-results .sr-tag { font-size: 10px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
#search-results .group, #search-results .note { cursor: default; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; padding: 8px 10px 4px; }
#search-results .note { text-transform: none; letter-spacing: 0; font-size: 12.5px; padding: 8px 10px; }
#search-results .group:hover, #search-results .note:hover { background: none; }
#search-results .note.plain { color: var(--text); padding: 4px 10px; font-size: 12.5px; }
#search-results .note code { font: 11.5px ui-monospace, SFMono-Regular, Menlo, monospace; padding: 1px 5px; border-radius: 4px; background: rgba(148, 163, 184, 0.16); }
#search-results .sr-tag.flight, #search-results .sr-tag.registration { color: var(--accent); }

.status { display: flex; align-items: center; gap: 8px; margin-left: auto; color: var(--muted); font-size: 12.5px; white-space: nowrap; min-width: 0; }
.status #status-text { overflow: hidden; text-overflow: ellipsis; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: #64748b; flex: none; }
.dot.live { background: var(--ok); box-shadow: 0 0 0 0 rgba(52, 211, 153, 0.6); animation: pulse 2s infinite; }
.dot.demo { background: #60a5fa; }
.dot.warn { background: var(--warn); }
.dot.bad { background: var(--bad); }
@keyframes pulse { 70% { box-shadow: 0 0 0 7px rgba(52, 211, 153, 0); } 100% { box-shadow: 0 0 0 0 rgba(52, 211, 153, 0); } }

.tools { display: flex; gap: 4px; }
.icon-btn {
  width: 38px; height: 38px; display: grid; place-items: center; cursor: pointer;
  background: transparent; border: 1px solid transparent; border-radius: 9px; color: var(--muted);
}
.icon-btn:hover, .icon-btn[aria-expanded="true"] { background: rgba(148, 163, 184, 0.14); color: var(--text); }
.icon-btn:focus-visible, .btn:focus-visible, .close:focus-visible, .link-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- banner ---------- */
.banner {
  position: fixed; z-index: 1001; top: calc(var(--topbar-h) + 20px); left: 50%; transform: translateX(-50%);
  max-width: min(640px, calc(100vw - 24px)); display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; justify-content: center;
  padding: 10px 14px; border-radius: 10px; background: #3b1d1d; border: 1px solid rgba(248, 113, 113, 0.5); color: #fecaca; box-shadow: var(--shadow);
}
.banner.info { background: #172554; border-color: rgba(96, 165, 250, 0.5); color: #dbeafe; }
.banner-actions { display: inline-flex; gap: 8px; }
.banner button { background: rgba(255, 255, 255, 0.12); border: 1px solid rgba(255, 255, 255, 0.25); border-radius: 7px; padding: 4px 10px; cursor: pointer; color: inherit; }
.banner button:hover { background: rgba(255, 255, 255, 0.22); }

/* ---------- popovers ---------- */
.pop {
  position: fixed; z-index: 1000; top: calc(var(--topbar-h) + 20px); right: 10px; width: 300px; max-height: calc(100vh - 100px); overflow: auto;
  padding: 14px 16px; background: var(--surface-solid); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
}
.pop h2 { margin: 0 0 8px; font-size: 12px; text-transform: uppercase; letter-spacing: 0.09em; color: var(--muted); }
.pop h2:not(:first-child) { margin-top: 16px; }
.pop fieldset { border: 0; margin: 0 0 12px; padding: 0; }
.pop legend { display: flex; justify-content: space-between; width: 100%; padding: 0; margin-bottom: 6px; font-weight: 600; }
.pop output { color: var(--muted); font-weight: 400; font-variant-numeric: tabular-nums; }
.check { display: flex; align-items: center; gap: 9px; padding: 5px 0; cursor: pointer; }
.check input { accent-color: var(--accent); width: 16px; height: 16px; margin: 0; }
.range-pair { display: grid; gap: 4px; }
.range-pair input { width: 100%; accent-color: var(--accent); }
.seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; padding: 3px; margin-bottom: 8px; background: rgba(2, 6, 23, 0.55); border-radius: 9px; }
.seg label { cursor: pointer; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span { display: block; text-align: center; padding: 6px 0; border-radius: 7px; color: var(--muted); }
.seg input:checked + span { background: rgba(251, 191, 36, 0.16); color: var(--accent); font-weight: 600; }
.seg input:focus-visible + span { outline: 2px solid var(--accent); }
.link-btn { background: none; border: 0; color: var(--accent); cursor: pointer; padding: 6px 0 0; text-decoration: underline; }
.fine { color: var(--muted); font-size: 12px; margin: 8px 0 0; }

/* ---------- aircraft panel ---------- */
.panel {
  position: fixed; z-index: 999; top: calc(var(--topbar-h) + 20px); right: 10px; bottom: 28px; width: var(--panel-w);
  display: flex; flex-direction: column; padding: 16px; overflow: auto;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); backdrop-filter: blur(10px);
}
/* the panel scrolls; its sections must keep their natural height instead of being squeezed by flexbox */
.panel > * { flex-shrink: 0; }
.panel .close {
  position: absolute; top: 8px; right: 10px; width: 32px; height: 32px; border-radius: 8px; border: 0; background: transparent; color: var(--muted); font-size: 24px; line-height: 1; cursor: pointer;
}
.panel .close:hover { background: rgba(148, 163, 184, 0.16); color: var(--text); }
.p-head { padding-right: 34px; margin-bottom: 12px; }
.p-callsign { font-size: 26px; font-weight: 800; letter-spacing: 0.02em; line-height: 1.1; }
.p-airline { color: var(--muted); margin-top: 2px; min-height: 1.4em; }
.p-route { margin-top: 6px; font-weight: 700; font-size: 16px; color: var(--accent); }
.p-badges { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.badge { font-size: 11px; font-weight: 700; letter-spacing: 0.04em; padding: 2px 8px; border-radius: 99px; background: rgba(148, 163, 184, 0.18); color: var(--text); }
.badge.bad { background: rgba(248, 113, 113, 0.22); color: #fecaca; border: 1px solid rgba(248, 113, 113, 0.6); animation: blink 1.4s infinite; }
.badge.warn { background: rgba(251, 191, 36, 0.18); color: #fde68a; }
@keyframes blink { 50% { opacity: 0.55; } }
.p-grid { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 1px; margin: 0 0 12px; background: var(--border); border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.p-grid > div { background: rgba(15, 23, 42, 0.96); padding: 8px 10px; min-width: 0; }
.p-grid .wide { grid-column: span 3; display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.p-grid dt { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.07em; }
.p-grid dd { margin: 2px 0 0; overflow-wrap: anywhere; }
.p-grid .wide dd { margin: 0; text-align: right; }
.p-grid b { font-size: 15px; font-variant-numeric: tabular-nums; }
.p-grid small { color: var(--muted); font-size: 12px; margin-left: 4px; font-variant-numeric: tabular-nums; }
.p-sec { display: flex; align-items: center; gap: 8px; margin: 2px 0 8px; font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.09em; color: var(--muted); }
.p-sim { font-size: 10px; letter-spacing: 0.06em; padding: 1px 7px; border-radius: 99px; background: rgba(96, 165, 250, 0.2); color: #bfdbfe; border: 1px solid rgba(96, 165, 250, 0.5); }
.p-note { margin: -4px 0 12px; font-size: 12px; color: var(--muted); }
.p-trace { margin: 0 0 12px; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.p-note code { font: 11.5px ui-monospace, SFMono-Regular, Menlo, monospace; padding: 1px 5px; border-radius: 4px; background: rgba(148, 163, 184, 0.16); color: var(--text); }
.spark { margin: 0 0 12px; }
#p-spark { width: 100%; height: 64px; display: block; background: rgba(2, 6, 23, 0.45); border-radius: 8px; }
.spark figcaption { color: var(--muted); font-size: 11.5px; margin-top: 4px; }
.p-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: auto; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; padding: 8px 12px; border-radius: 9px; cursor: pointer; text-decoration: none; font-weight: 600;
  background: var(--accent); color: #1a1203; border: 1px solid transparent;
}
.btn:hover { filter: brightness(1.08); }
.btn[aria-pressed="true"] { background: #fff; }
.btn.ghost { background: transparent; color: var(--text); border-color: var(--border); font-weight: 500; }
.btn.ghost:hover { background: rgba(148, 163, 184, 0.14); }

/* ---------- legend / map overlays ---------- */
.legend { position: fixed; z-index: 800; left: 12px; bottom: 28px; width: 190px; padding: 8px 10px 6px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; font-size: 11px; color: var(--muted); }
.legend-title { margin-bottom: 4px; text-transform: uppercase; letter-spacing: 0.08em; }
.legend-bar { height: 8px; border-radius: 4px; }
.legend-ticks { display: flex; justify-content: space-between; margin-top: 3px; font-variant-numeric: tabular-nums; }
.leaflet-pane.leaflet-aircraft-pane { z-index: 450; pointer-events: none; }
.leaflet-pane.leaflet-basemap-pane { z-index: 190; }
/* the vector land layer is decorative: its canvas must never intercept (or swallow) pointer events */
.leaflet-basemap-pane canvas { pointer-events: none; }
.ac-canvas { position: absolute; left: 0; top: 0; pointer-events: none; }
.ac-tip {
  position: absolute; z-index: 700; pointer-events: none; transform: translate(12px, -50%); white-space: nowrap;
  padding: 3px 8px; border-radius: 6px; font-size: 12px; font-weight: 600; background: rgba(2, 6, 23, 0.92); border: 1px solid var(--border); color: var(--text);
}
.ac-tip small { color: var(--muted); font-weight: 400; margin-left: 6px; }
.apt { display: flex; align-items: center; gap: 4px; transform: translate(-5px, -5px); pointer-events: auto; }
.apt i { width: 9px; height: 9px; border-radius: 2px; background: #7dd3fc; border: 1.5px solid #0b1220; flex: none; }
.apt span { font: 700 10.5px/1 system-ui, sans-serif; color: #bae6fd; text-shadow: 0 0 3px #0b1220, 0 0 3px #0b1220, 0 0 3px #0b1220; letter-spacing: 0.04em; }
.basemap-light .apt span { color: #0c4a6e; text-shadow: 0 0 3px #fff, 0 0 3px #fff; }
.leaflet-popup-content-wrapper, .leaflet-popup-tip { background: var(--surface-solid); color: var(--text); }
.leaflet-popup-content { margin: 10px 14px; }
.leaflet-popup-content b { color: var(--accent); }

body.panel-open .leaflet-right { margin-right: calc(var(--panel-w) + 12px); }

/* ---------- small screens ---------- */
@media (max-width: 1100px) {
  .site-link { display: none; }
}
@media (max-width: 860px) {
  .brand-text { display: none; }
  .status #status-text { max-width: 36vw; }
}
@media (max-width: 720px) {
  .topbar { top: 6px; left: 6px; right: 6px; gap: 6px; padding: 0 6px 0 10px; }
  .search { flex-basis: 120px; }
  .search .hint { display: none; }
  .status { display: none; }
  .tools { margin-left: auto; }
  .pop { left: 6px; right: 6px; width: auto; top: calc(var(--topbar-h) + 12px); }
  .panel {
    top: auto; left: 6px; right: 6px; bottom: 6px; width: auto; max-height: 52vh; padding: 14px;
    border-radius: 14px 14px 12px 12px;
  }
  body.panel-open .leaflet-right { margin-right: 0; }
  .legend { display: none; }
  .leaflet-control-zoom { display: none; }
  .banner { top: calc(var(--topbar-h) + 14px); }
  .p-callsign { font-size: 22px; }
}
@media (max-width: 720px) {
  body.panel-open .leaflet-bottom { margin-bottom: 52vh; }
}
@media (prefers-reduced-motion: reduce) {
  .dot.live, .badge.bad { animation: none; }
}
