/* SKY.TUTI.LT — spy visual pack (ported from God's Eye View concepts):
   NVG / FLIR / Noir / CRT map treatments, military HUD readout and circular
   scope mask. Pure CSS + vanilla JS — no new dependencies.

   Design rules (matching the site's existing conventions):
   • Filters apply to the MAP only (.leaflet-container) so panels and the
     top bar stay fully readable — the treatment is a view mode, not a
     screen-wide gimmick.
   • Accent colours follow the active style via CSS variables so the rest
     of the chrome subtly matches without breaking contrast (WCAG: all
     replacement accents keep ≥ 4.5:1 on the panel backgrounds).
   • Scope mask and HUD are non-interactive overlays (pointer-events:none)
     placed BELOW panels (z-index < 1000) so nothing is ever blocked.
   • CRT flicker/scanline animation is disabled for prefers-reduced-motion. */

/* ── Style presets — map filter + chrome accent ─────────────────────────── */

/* NVG — night-vision green (GEV "surveillance" style) */
body.spy-nvg { --acc: #57e389; --acc2: #b7f7a1; }
body.spy-nvg .leaflet-container {
  filter: sepia(1) hue-rotate(58deg) saturate(2.6) brightness(1.08) contrast(1.18);
}

/* FLIR — thermal white-hot (GEV "thermal" style) */
body.spy-flir { --acc: #e6ecf5; --acc2: #b9c4d6; }
body.spy-flir .leaflet-container {
  filter: grayscale(1) contrast(1.55) brightness(1.06);
}

/* Noir — desaturated, harder contrast (GEV "noir" style) */
body.spy-noir { --acc: #cbd5e1; --acc2: #9fb0c8; }
body.spy-noir .leaflet-container {
  filter: grayscale(1) contrast(1.28) brightness(.94);
}

/* CRT — retro phosphor amber (GEV "retro" style) */
body.spy-crt { --acc: #ffb454; --acc2: #ffd9a0; }
body.spy-crt .leaflet-container {
  filter: sepia(.35) hue-rotate(-18deg) saturate(1.5) contrast(1.1) brightness(.98);
}

/* Keep popups & tooltips legible under the map filter: raise their text
   contrast slightly (they sit INSIDE .leaflet-container, so they inherit
   the treatment — intended, it keeps the immersion honest). */
body.spy-nvg .leaflet-popup-content-wrapper,
body.spy-nvg .leaflet-tooltip,
body.spy-flir .leaflet-popup-content-wrapper,
body.spy-flir .leaflet-tooltip,
body.spy-noir .leaflet-popup-content-wrapper,
body.spy-noir .leaflet-tooltip,
body.spy-crt .leaflet-popup-content-wrapper,
body.spy-crt .leaflet-tooltip {
  background: #0d1118;
  color: #eef3fb;
}

/* ── Scanline / grain / vignette treatment layers ───────────────────────── */
/* One fixed overlay carries the per-style atmosphere; created and toggled
   by js/spy.js together with the body class. pointer-events: none. */
#spyAtmo {
  position: fixed; inset: 0; z-index: 940;   /* over map (400s), under panels (1000+) */
  pointer-events: none; opacity: 0;
  transition: opacity .25s ease;
}
#spyAtmo::before {   /* scanlines + grain */
  content: ""; position: absolute; inset: 0;
  background:
    repeating-linear-gradient(0deg,
      rgba(0, 0, 0, .16) 0px, rgba(0, 0, 0, .16) 1px,
      transparent 1px, transparent 3px);
  mix-blend-mode: multiply;
}
#spyAtmo::after {    /* vignette */
  content: ""; position: absolute; inset: 0;
  background: radial-gradient(ellipse at 50% 45%,
    transparent 52%, rgba(0, 0, 0, .38) 100%);
}
body.spy-nvg #spyAtmo, body.spy-crt #spyAtmo, body.spy-noir #spyAtmo { opacity: 1; }
body.spy-flir #spyAtmo { opacity: .45; }   /* thermal: vignette only, no scanlines */

/* CRT phosphor flicker (very subtle; skipped for reduced motion) */
@media (prefers-reduced-motion: no-preference) {
  body.spy-crt #spyAtmo { animation: spyCrtFlicker 4.2s steps(60) infinite; }
  @keyframes spyCrtFlicker {
    0%, 100% { opacity: 1; }
    48% { opacity: .96; }
    52% { opacity: 1; }
    73% { opacity: .94; }
    75% { opacity: 1; }
  }
}

/* ── Scope mask (GEV circular scope) ────────────────────────────────────── */
#spyMask {
  position: fixed; inset: 0; z-index: 950;   /* above atmosphere, below panels */
  pointer-events: none; display: none;
}
body.spy-mask-on #spyMask { display: block; }
/* Feathered circular opening centred slightly above true centre (map focus) */
#spyMask::before {
  content: ""; position: absolute; inset: 0;
  background: radial-gradient(circle at 50% 46%,
    transparent 0%, transparent 46%,
    rgba(0, 0, 0, .22) 55%,
    rgba(0, 0, 0, .62) 68%,
    rgba(0, 0, 0, .88) 82%, #000 100%);
}
/* Thin glass ring at the scope edge */
#spyMask::after {
  content: ""; position: absolute; left: 50%; top: 46%;
  width: min(92vh, 92vw); height: min(92vh, 92vw);
  transform: translate(-50%, -50%);
  border-radius: 50%;
  border: 1px solid rgba(190, 210, 240, .18);
  box-shadow: inset 0 0 40px rgba(0, 0, 0, .55);
}

/* ── HUD readout (GEV intelligence-HUD aesthetic) ───────────────────────── */
#spyHud {
  position: absolute; left: 12px; bottom: 8px; z-index: 930;  /* low-LEFT corner: #main ends exactly at the top edge of the fixed #statusbar, so bottom:8px parks the readout just above the "LIVE ADS-B · n/n feeds …" line */
  display: none;
  font-family: var(--mono); font-size: 11px; line-height: 1.65;
  color: var(--acc, #4da3ff);
  background: rgba(8, 11, 17, .82);
  border: 1px solid var(--line2, #2e3854);
  border-left: 3px solid var(--acc, #4da3ff);
  border-radius: 6px;
  padding: 8px 11px;
  max-width: min(330px, calc(100vw - 24px));
  user-select: none; pointer-events: none;
  letter-spacing: .4px;
}
body.spy-hud-on #spyHud { display: block; }
#spyHud .hud-th {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; margin-bottom: 3px;
}
#spyHud .hud-t {
  display: block; font-weight: 700; font-size: 10px; letter-spacing: 1.6px;
  color: var(--txt2, #8fa0bd);
}
/* ✕ close — the HUD root is pointer-events:none (click-through to the map),
   the button re-enables hit-testing for itself only. Closing remembers the
   choice in st_spy and un-ticks the Layers checkbox (same as the menu). */
#spyHud .hud-x {
  pointer-events: auto; flex: 0 0 auto;
  appearance: none; -webkit-appearance: none;
  width: 18px; height: 18px; padding: 0; margin: 0;
  display: inline-flex; align-items: center; justify-content: center;
  background: transparent; color: var(--txt3, #8494b3);
  border: 1px solid transparent; border-radius: 4px;
  font: 700 11px/1 var(--mono, monospace); cursor: pointer;
}
#spyHud .hud-x:hover, #spyHud .hud-x:focus-visible {
  color: var(--acc, #4da3ff);
  border-color: var(--line2, #2e3854);
  background: rgba(255, 255, 255, .06);
  outline: none;
}
#spyHud .hud-r { display: flex; gap: 7px; white-space: nowrap; }
#spyHud .hud-k { color: var(--txt3, #8494b3); min-width: 34px; text-align: right; }
#spyHud .hud-v { color: var(--acc, #4da3ff); overflow: hidden; text-overflow: ellipsis; }
#spyHud .hud-live { color: var(--acc2, #7fd4a8); }
#spyHud .hud-live.down { color: var(--warn, #fbbf24); }

/* Crosshair cursor while the HUD is on (the TGT row follows the cursor) */
body.spy-hud-on #map .leaflet-container { cursor: crosshair; }

/* Compact screens: drop the secondary rows, keep grid + target */
@media (max-width: 640px) {
  #spyHud { font-size: 10px; padding: 6px 9px; }
  #spyHud .hud-sec { display: none; }
}

/* Mobile layout (the site's stacked-header breakpoint, ≤860px): pin the
   HUD right of the Leaflet +/- zoom stack in the top-left corner — the
   stack spans x≈10–40px, so left:48px sits flush beside it and the readout
   stays clear of the status bar and the bottom-right view buttons. */
@media (max-width: 860px) {
  #spyHud { left: 48px; top: 10px; bottom: auto; max-width: calc(100vw - 60px); }
}

/* ── Style menu (spy view) controls ─────────────────────────────────────── */
.spy-style-row { display: flex; flex-wrap: wrap; gap: 6px; margin: 2px 0 6px; }
.spy-style-row label {
  display: inline-flex; align-items: center; gap: 5px;
  border: 1px solid var(--line2, #2e3854); border-radius: 999px;
  padding: 3px 10px 3px 8px; cursor: pointer; font-size: 12px; color: var(--txt2);
}
.spy-style-row label:has(input:checked) {
  border-color: var(--acc); color: var(--txt);
  box-shadow: 0 0 0 1px var(--acc) inset;
}
.spy-style-row input { accent-color: var(--acc); margin: 0; }
