:root {
  --bg: #0f1720;
  --panel: #16202b;
  --panel-2: #1d2a38;
  --line: #2a3a4c;
  --text: #e6edf3;
  --muted: #8aa0b4;
  --accent: #ffc93c;
  --accent-ink: #1a1300;
  --danger: #ff4d4f;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-family: var(--font); font-size: 14px; }
#map { position: fixed; inset: 0; background: #0b1218; }
button { font: inherit; color: inherit; cursor: pointer; }

/* top bar */
#topbar {
  position: fixed; top: 0; left: 0; right: 0; height: 52px; z-index: 1000;
  display: flex; align-items: center; gap: 16px; padding: 0 16px;
  background: linear-gradient(to bottom, rgba(10,16,22,.95), rgba(10,16,22,.75));
  border-bottom: 1px solid rgba(255,255,255,.06); backdrop-filter: blur(6px);
}
.brand { font-weight: 700; font-size: 18px; color: var(--accent); white-space: nowrap; letter-spacing: .3px; }
.search { position: relative; flex: 1; max-width: 420px; margin-left: auto; }
.search input {
  width: 100%; height: 34px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--panel); color: var(--text); padding: 0 12px; font: inherit; outline: none;
}
.search input:focus { border-color: var(--accent); }
#results {
  position: absolute; top: 38px; left: 0; right: 0; margin: 0; padding: 4px; list-style: none;
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px; max-height: 320px; overflow: auto;
}
#results li { padding: 8px 10px; border-radius: 6px; cursor: pointer; display: flex; justify-content: space-between; gap: 8px; }
#results li:hover, #results li.active { background: var(--panel-2); }
#results li small { color: var(--muted); }
.stats { color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.stats #count { color: var(--text); font-weight: 600; }

/* plane markers */
.plane-icon { background: none; border: none; }
.plane-icon svg { display: block; transition: transform .2s linear; filter: drop-shadow(0 0 1.5px rgba(0,0,0,.8)); }
.plane-icon.selected svg { filter: drop-shadow(0 0 4px #fff) drop-shadow(0 0 1px #000); }
.plane-label {
  position: absolute; left: 22px; top: 2px; white-space: nowrap; pointer-events: none;
  font-size: 11px; font-weight: 600; color: #fff; background: rgba(10,16,22,.75); padding: 1px 4px; border-radius: 3px;
}
.plane-label small { color: #b9c7d4; font-weight: 400; margin-left: 4px; }
body.no-labels .plane-label, body.far .plane-label { display: none; }
body.no-labels .plane-icon.selected .plane-label, body.far .plane-icon.selected .plane-label { display: block; }

/* side panel */
#panel {
  position: fixed; top: 64px; left: 12px; bottom: 12px; width: 340px; z-index: 1000;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px; overflow: auto;
  box-shadow: 0 10px 30px rgba(0,0,0,.5);
}
.p-head { display: flex; align-items: flex-start; gap: 8px; padding: 12px 12px 10px; background: var(--panel-2); }
.p-head > div:first-child { flex: 1; min-width: 0; }
.p-callsign { font-size: 22px; font-weight: 700; color: var(--accent); }
.p-airline { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.p-badges { display: flex; gap: 4px; margin-top: 4px; }
.badge { font-size: 11px; font-weight: 700; padding: 2px 6px; border-radius: 4px; background: #e6edf3; color: #111; }
.badge.alt { background: #3b6fd8; color: #fff; }
.badge:empty { display: none; }
.icon-btn { background: none; border: none; font-size: 18px; color: var(--muted); padding: 2px 6px; border-radius: 6px; }
.icon-btn:hover { background: rgba(255,255,255,.08); color: var(--text); }
.p-photo { aspect-ratio: 16/9; background: #0b1218 center/cover no-repeat; display: flex; align-items: center; justify-content: center; color: var(--muted); position: relative; }
.p-photo.has-img span { display: none; }
.p-photo a { position: absolute; inset: 0; }
.emerg { background: var(--danger); color: #fff; font-weight: 700; padding: 8px 12px; text-align: center; letter-spacing: .5px; }
.route { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; padding: 14px 12px 6px; text-align: center; }
.route .code { font-size: 30px; font-weight: 700; letter-spacing: .5px; }
.route .city { color: var(--muted); font-size: 12px; text-transform: uppercase; }
.plane-dot { width: 40px; height: 40px; border-radius: 50%; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; font-size: 20px; transform: rotate(0deg); }
.progress { padding: 6px 12px 12px; }
.progress .bar { height: 4px; background: var(--line); border-radius: 2px; overflow: hidden; }
.progress #p-bar { height: 100%; width: 0; background: var(--accent); transition: width .5s; }
.prog-labels { display: flex; justify-content: space-between; color: var(--muted); font-size: 12px; margin-top: 6px; }
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1px; background: var(--line); border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.grid > div { background: var(--panel); padding: 8px 12px; }
.grid label { display: block; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .4px; }
.grid b { font-weight: 600; font-variant-numeric: tabular-nums; }
.p-actions { display: flex; gap: 8px; padding: 12px; }
.p-actions button { flex: 1; height: 36px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel-2); }
.p-actions button:hover { border-color: var(--accent); }
.p-actions button.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }

/* map controls */
#controls { position: fixed; right: 12px; top: 64px; z-index: 1000; display: flex; flex-direction: column; gap: 8px; }
.ctl { width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--line); background: rgba(22,32,43,.92); font-size: 16px; box-shadow: 0 2px 8px rgba(0,0,0,.4); }
.ctl:hover, .ctl.on { border-color: var(--accent); color: var(--accent); }
.leaflet-control-zoom { display: none; }
.popover { position: fixed; right: 60px; top: 64px; z-index: 1001; width: 280px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 12px; box-shadow: 0 10px 30px rgba(0,0,0,.5); }
.popover h4 { margin: 0 0 10px; font-size: 13px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); }
.popover label { display: block; margin-bottom: 10px; font-size: 13px; }
.popover label span { float: right; color: var(--accent); font-variant-numeric: tabular-nums; }
.popover input[type=range] { width: 100%; accent-color: var(--accent); }
.popover input[type=text] { width: 100%; margin-top: 4px; height: 30px; border-radius: 6px; border: 1px solid var(--line); background: var(--panel-2); color: var(--text); padding: 0 8px; }
.popover .chk { display: flex; gap: 8px; align-items: center; }
#layer-list button { display: block; width: 100%; text-align: left; padding: 8px 10px; margin-bottom: 4px; border-radius: 6px; border: 1px solid var(--line); background: var(--panel-2); }
#layer-list button.on { border-color: var(--accent); color: var(--accent); }

/* legend */
#legend { position: fixed; bottom: 22px; right: 12px; z-index: 1000; background: rgba(22,32,43,.9); border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; font-size: 11px; color: var(--muted); }
#legend .ramp { height: 6px; width: 220px; border-radius: 3px; margin-bottom: 3px; }
#legend .ticks { display: flex; justify-content: space-between; }

#toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); z-index: 1002; background: var(--panel-2); border: 1px solid var(--line); padding: 8px 14px; border-radius: 8px; color: var(--text); }

a.ctl { display: grid; place-items: center; text-decoration: none; color: var(--text); }
a.ctl[hidden] { display: none; }

/* sign-in overlay */
#signin { position: fixed; inset: 0; z-index: 2000; display: grid; place-items: center; padding: 16px; background: rgba(8,12,17,.82); backdrop-filter: blur(4px); }
#signin[hidden] { display: none; }
.signin-card { width: 100%; max-width: 340px; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 24px; text-align: center; box-shadow: 0 10px 40px rgba(0,0,0,.6); }
.signin-card .brand { font-size: 24px; margin-bottom: 8px; }
.signin-card p { color: var(--muted); margin: 0 0 20px; line-height: 1.4; }
.signin-btn { display: block; height: 44px; line-height: 44px; border-radius: 10px; background: var(--accent); color: var(--accent-ink); font-weight: 700; text-decoration: none; }
#signin-error { color: var(--danger); margin-top: 12px; font-size: 13px; min-height: 1em; }

/* phones: respect the notch / home indicator when installed to the home screen */
#topbar { padding-top: env(safe-area-inset-top); height: calc(52px + env(safe-area-inset-top)); }
#controls, .popover { top: calc(64px + env(safe-area-inset-top)); }
@media (min-width: 641px) { #panel { top: calc(64px + env(safe-area-inset-top)); } }
@media (max-width: 640px) { #panel { padding-bottom: env(safe-area-inset-bottom); } }

.leaflet-container { font-family: var(--font); }
.leaflet-control-attribution { background: rgba(10,16,22,.7) !important; color: #7d8d9c !important; }
.leaflet-control-attribution a { color: #9fb3c6 !important; }

@media (max-width: 640px) {
  #topbar { gap: 8px; padding: 0 10px; }
  .brand { font-size: 15px; }
  .stats { display: none; }
  #panel { top: auto; left: 0; right: 0; bottom: 0; width: auto; max-height: 55vh; border-radius: 12px 12px 0 0; }
  #legend { display: none; }
}
