:root {
  --c-bg: #040826;
  --c-adsb: #5ce36a;
  --c-mlat: #48d6f2;
  --c-tisb: #e59a5b;
  --c-other: #d4a45c;
  --c-emerg: #ff4b4b;
  --c-sel: #ffffff;
  --c-ring: rgba(92, 227, 106, 0.32);
  --c-ink: #cfe9d3;
  --c-dim: #7d9a95;
  --c-panel: rgba(4, 10, 38, 0.9);
  --c-edge: rgba(92, 227, 106, 0.28);
  --f-data: 'B612 Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --f-ui: 'B612', system-ui, -apple-system, 'Segoe UI', sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--c-bg);
  color: var(--c-ink);
  font: 13px/1.4 var(--f-ui);
  overflow: hidden;
}

#map { position: fixed; inset: 0; background: var(--c-bg); }
.leaflet-container { background: var(--c-bg); font-family: var(--f-ui); }

/* Dark Matter richting marineblauw scope trekken */
.tint .leaflet-tile-pane {
  filter: sepia(1) hue-rotate(188deg) saturate(3.2) brightness(0.62) contrast(1.15);
}

.leaflet-control-attribution {
  background: rgba(4, 8, 38, 0.7) !important;
  color: var(--c-dim) !important;
  font-size: 10px;
}
.leaflet-control-attribution a { color: var(--c-dim) !important; }
.leaflet-bar a {
  background: var(--c-panel);
  color: var(--c-ink);
  border-bottom-color: var(--c-edge);
}
.leaflet-bar a:hover { background: #0a1650; color: #fff; }

/* ---------- doelen ---------- */
.leaflet-marker-icon.ac { background: none; border: 0; }
.ac-in { position: relative; width: 10px; height: 10px; color: var(--c-adsb); transform: scale(var(--s, 1)); transform-origin: 5px 5px; }
/* weergavegrootte (legenda → Weergave, of ?size=tv): knoppen en panelen schalen mee */
.bar, .controls, #panel, #legend, #pb, .leaflet-control-zoom, .gps-btn { zoom: var(--s, 1); }
.ac-in.src-mlat  { color: var(--c-mlat); }
.ac-in.src-tisb  { color: var(--c-tisb); }
.ac-in.src-other { color: var(--c-other); }
.ac-in.emerg     { color: var(--c-emerg); }
.ac-in.sel       { color: var(--c-sel); }
.ac-in.stale     { opacity: 0.45; }

.tgt {
  position: absolute;
  inset: 1px;
  border: 1.5px solid currentColor;
  background: currentColor; /* gevuld vierkantje */
  cursor: pointer;
}
.sel .tgt { color: var(--c-sel) !important; outline: 1.5px solid var(--c-sel); outline-offset: 2px; } /* selectie: wit met ring */
.emerg .tgt { animation: blink 1s steps(2, start) infinite; }
@keyframes blink { to { visibility: hidden; } }

.lbl {
  position: absolute;
  white-space: nowrap;
  font: 11px/1.22 var(--f-data);
  color: currentColor;
  /* donkere ondergrond + rand om de letters: leesbaar boven plaatsnamen, vliegvelden en lijnen */
  background: var(--c-lbl-bg, rgba(2, 5, 24, 0.72));
  padding: 1px 3px;
  border-radius: 2px;
  text-shadow: -1px -1px 0 #000, 1px -1px 0 #000, -1px 1px 0 #000, 1px 1px 0 #000;
  cursor: pointer;
}
/* label altijd aan de kant tegenover de vector */
.q-ne .lbl { left: 13px; bottom: 9px; }
.q-nw .lbl { right: 13px; bottom: 9px; }
.q-se .lbl { left: 13px; top: 9px; }
.q-sw .lbl { right: 13px; top: 9px; }
.lbl-off .lbl { display: none; }
.lbl-hide .lbl { visibility: hidden; } /* ontward: plek bezet, label tijdelijk weg */

/* ---------- ontvanger & ringen ---------- */
.apt-lbl { color: var(--c-dim); font: calc(10px * var(--s, 1))/1 var(--f-data); white-space: nowrap; text-align: center; opacity: 0.85; letter-spacing: 0.05em; }
.rx { color: var(--c-adsb); font: 16px/1 var(--f-data); text-align: center; opacity: 0.8; }
.ring-lbl { color: var(--c-adsb); opacity: 0.5; font: calc(10px * var(--s, 1))/1 var(--f-data); text-align: center; }

/* ---------- statusbalk ---------- */
.bar {
  position: fixed;
  top: calc(10px + env(safe-area-inset-top, 0px));
  left: 10px;
  z-index: 1000;
  display: flex;
  align-items: baseline;
  gap: 14px;
  padding: 6px 12px;
  background: var(--c-panel);
  border: 1px solid var(--c-edge);
  font-family: var(--f-data);
  font-size: 12px;
}
.bar-title { font-family: var(--f-ui); font-size: 14px; color: #fff; }
.feed::before {
  content: '';
  display: inline-block;
  width: 7px; height: 7px;
  margin-right: 6px;
  background: var(--c-dim);
  vertical-align: 1px;
}
.feed-ok::before  { background: var(--c-adsb); }
.feed-err { color: var(--c-emerg); }
.feed-err::before { background: var(--c-emerg); }
#clock { color: #fff; }

/* ---------- knoppen ---------- */
.controls {
  position: fixed;
  right: 10px;
  bottom: calc(22px + env(safe-area-inset-bottom, 0px));
  z-index: 1000;
  display: flex;
  gap: 4px;
}
.controls button {
  font: 12px/1 var(--f-data);
  color: var(--c-dim);
  background: var(--c-panel);
  border: 1px solid var(--c-edge);
  padding: 7px 10px;
  cursor: pointer;
}
.controls button[aria-pressed='true'],
.controls button[data-act='labels'] { color: var(--c-adsb); }
.controls button:hover { color: #fff; }
.controls button:focus-visible,
.panel-close:focus-visible { outline: 2px solid var(--c-mlat); outline-offset: 2px; }

/* ---------- detailpaneel ---------- */
#panel {
  position: fixed;
  top: calc(10px + env(safe-area-inset-top, 0px));
  right: 10px;
  z-index: 1001;
  width: 270px;
  max-height: calc(100% - 90px);
  overflow-y: auto;
  padding: 12px 14px;
  background: var(--c-panel);
  border: 1px solid var(--c-edge);
  border-left: 3px solid var(--c-sel);
}
.panel-close {
  position: absolute;
  top: 6px; right: 8px;
  background: none;
  border: 0;
  color: var(--c-dim);
  font-size: 20px;
  cursor: pointer;
}
.p-cs { font: 700 20px/1.1 var(--f-ui); color: #fff; margin: 0 0 2px; }
.p-sub { color: var(--c-dim); margin: 0 0 10px; }
#panel dl {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 3px 12px;
  margin: 0 0 10px;
  font: 12px/1.35 var(--f-data);
}
#panel dt { color: var(--c-dim); }
#panel dd { margin: 0; color: var(--c-ink); text-align: right; }
#panel a { color: var(--c-mlat); }

/* ---------- legenda ---------- */
.legend-btn {
  margin-left: 2px;
  width: 22px; height: 22px;
  align-self: center;
  font: 700 13px/1 var(--f-ui);
  color: var(--c-ink);
  background: none;
  border: 1px solid var(--c-edge);
  border-radius: 50%;
  cursor: pointer;
}
.legend-btn:hover, .legend-btn[aria-expanded='true'] { color: #fff; border-color: var(--c-ink); }
#legend {
  position: fixed;
  top: calc(52px + env(safe-area-inset-top, 0px));
  left: 10px;
  z-index: 1001;
  width: 300px;
  max-height: calc(100% - 200px); /* vrij van +/- en locatieknop */
  overflow-y: auto;
  padding: 12px 14px;
  background: var(--c-panel);
  border: 1px solid var(--c-edge);
  color: var(--c-ink);
  font: 12px/1.35 var(--f-data);
}
#legend h2 { font: 700 16px/1.1 var(--f-ui); color: #fff; margin: 0 0 8px; }
#legend h3 { font: 700 11px/1.2 var(--f-ui); color: var(--c-dim); text-transform: uppercase; letter-spacing: 0.06em; margin: 12px 0 5px; }
#legend ul { list-style: none; margin: 0; padding: 0; }
#legend li { display: flex; align-items: center; gap: 9px; margin: 3px 0; }
.lg-sq { flex: none; width: 9px; height: 9px; margin: 0 5px; background: currentColor; border: 1.5px solid currentColor; }
.lg-sq[data-blink] { animation: blink 1s steps(2, start) infinite; }
.lg-sel { color: var(--c-sel); outline: 1.5px solid var(--c-sel); outline-offset: 2px; }
.lg-stale { color: var(--c-adsb); opacity: 0.45; }
.lg-txt { flex: none; width: 44px; font-weight: 700; }
.lg-line { flex: none; width: 22px; border-top: 2px solid var(--c-adsb); }
.lg-dot { border-top-style: dotted; }
.lg-keys { display: grid; grid-template-columns: auto 1fr; gap: 3px 10px; margin: 0; }
.lg-keys dd { margin: 0; }
#legend kbd { display: inline-block; min-width: 18px; padding: 1px 4px; text-align: center; border: 1px solid var(--c-edge); border-radius: 3px; color: #fff; font: 11px/1.3 var(--f-data); }
.lg-note { margin: 12px 0 0; color: var(--c-dim); }
.lg-size { display: flex; flex-wrap: wrap; gap: 4px; }
.lg-size button, #pb button, #pb select {
  font: 12px/1 var(--f-data);
  color: var(--c-dim);
  background: var(--c-panel);
  border: 1px solid var(--c-edge);
  padding: 6px 8px;
  cursor: pointer;
}
.lg-size button[aria-pressed='true'] { color: var(--c-adsb); border-color: var(--c-adsb); }
.lg-size button:hover, #pb button:hover { color: #fff; }

/* ---------- playback ---------- */
.pb-btn { font-size: 11px; }
.pb-btn[aria-pressed='true'] { color: #ffb84d; border-color: #ffb84d; }
#pb {
  position: fixed;
  left: 50%;
  bottom: calc(64px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  z-index: 1000;
  display: flex;
  align-items: center;
  gap: 6px;
  width: min(640px, calc(100% - 20px));
  padding: 6px 8px;
  background: var(--c-panel);
  border: 1px solid #ffb84d;
  font: 12px/1 var(--f-data);
  color: #ffb84d;
}
#pb[hidden] { display: none; }
#pb input[type='range'] { flex: 1; min-width: 60px; accent-color: #ffb84d; }
#pb .pb-time { white-space: nowrap; min-width: 128px; text-align: right; }
#pb [data-pb='play'] { min-width: 34px; color: #ffb84d; }
#pb [data-pb='live'] { color: var(--c-adsb); }
@media (max-width: 640px) {
  #pb { flex-wrap: wrap; bottom: calc(60px + env(safe-area-inset-bottom, 0px)); }
  #pb input[type='range'] { flex-basis: 100%; order: -1; }
  #pb .pb-time { flex: 1; min-width: 0; text-align: left; }
}

/* ---------- eigen locatie ---------- */
.gps-btn {
  width: 34px; height: 34px;
  display: grid; place-items: center;
  color: var(--c-dim);
  background: var(--c-panel);
  border: 1px solid var(--c-edge);
  cursor: pointer;
}
.gps-btn:hover { color: #fff; }
.gps-btn[data-state='on'] { color: #4da3ff; }
.gps-btn[data-state='wait'] { color: #4da3ff; animation: blink 1s steps(2, start) infinite; }
.gps-btn[data-state='err'] { color: var(--c-emerg); }
.me span {
  display: block; width: 12px; height: 12px; margin: 2px;
  border-radius: 50%;
  background: #4da3ff;
  border: 2px solid #fff;
  box-shadow: 0 0 0 4px rgba(77, 163, 255, 0.3);
}

@media (max-width: 640px) {
  #legend {
    top: auto;
    left: 10px;
    right: 10px;
    bottom: calc(64px + env(safe-area-inset-bottom, 0px));
    width: auto;
    max-height: 55%;
  }
  .bar { gap: 10px; right: 10px; }
  .bar-title { display: none; }
  .controls { left: 10px; right: 10px; justify-content: space-between; }
  .controls button { flex: 1; padding: 9px 4px; font-size: 11px; }
  #panel {
    top: auto;
    left: 10px;
    right: 10px;
    bottom: calc(64px + env(safe-area-inset-bottom, 0px));
    width: auto;
    max-height: 45%;
  }
  .leaflet-bottom.leaflet-left { bottom: 50px; }
}

@media (prefers-reduced-motion: reduce) {
  .emerg .tgt { animation: none; }
}
