:root {
  --bg: #070b12;
  --panel: rgba(12, 18, 28, 0.92);
  --line: rgba(148, 163, 184, 0.22);
  --text: #e8eef8;
  --muted: #9aa8bd;
  --accent: #f59e0b;
  --accent-soft: rgba(245, 158, 11, 0.16);
  --danger: #f87171;
  --quake: #fb923c;
  --plane: #38bdf8;
  --boat: #2dd4bf;
  --weather: #a78bfa;
  --ok: #34d399;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
  --radius: 16px;
  font-family: Inter, ui-sans-serif, 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);
  -webkit-text-size-adjust: 100%;
}
body {
  display: grid;
  grid-template-rows: auto 1fr;
  min-height: 100dvh;
}

a,
a:visited,
a:hover,
a:active,
.shtf-popup a,
.leaflet-container a {
  text-decoration: none !important;
}
a:hover { opacity: 0.92; }

.topbar {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
  padding: .65rem 0.85rem;
  padding-left: max(0.85rem, env(safe-area-inset-left));
  padding-right: max(0.85rem, env(safe-area-inset-right));
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(15, 23, 42, 0.95), rgba(7, 11, 18, 0.88));
  backdrop-filter: blur(12px);
  z-index: 1000;
}
.brand {
  display: flex;
  align-items: center;
  gap: .65rem;
  min-width: 0;
}
.brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  background: var(--accent-soft);
  border: 1px solid rgba(245, 158, 11, 0.45);
  font-weight: 800;
  color: var(--accent);
}
.brand-mark-img {
  width: 40px;
  height: 40px;
  border-radius: 11px;
  object-fit: cover;
  border: 1px solid rgba(245, 158, 11, 0.4);
  box-shadow: 0 0 0 1px rgba(0,0,0,0.35), 0 6px 16px rgba(0,0,0,0.35);
  flex-shrink: 0;
}
.brand h1 {
  margin: 0;
  font-size: 1.05rem;
  letter-spacing: -0.02em;
}
.brand p {
  margin: 0;
  color: var(--muted);
  font-size: .75rem;
}
.top-actions {
  display: flex;
  gap: .5rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: rgba(255,255,255,0.04);
  color: var(--text);
  border-radius: 999px;
  padding: .45rem .85rem;
  font: inherit;
  font-size: .82rem;
  font-weight: 650;
  cursor: pointer;
}
.btn:hover { border-color: rgba(245, 158, 11, 0.55); }
a.btn { display: inline-flex; align-items: center; text-decoration: none !important; }
.btn-primary {
  background: linear-gradient(180deg, #f6b73d, #d97706);
  border-color: rgba(251, 191, 36, 0.5);
  color: #1c1405;
}
.btn-primary:hover { filter: brightness(1.05); }
.btn-icon {
  min-width: 2.4rem;
  justify-content: center;
  padding-left: .7rem;
  padding-right: .7rem;
}
.btn-label-short { display: none; }
#btn-layers { display: none; }
#btn-more { display: none; }
.top-more-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: max(0.75rem, env(safe-area-inset-right));
  z-index: 1200;
  min-width: 160px;
  padding: .4rem;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(12, 18, 28, 0.98);
  box-shadow: var(--shadow);
  display: grid;
  gap: .2rem;
}
.top-more-menu[hidden] { display: none !important; }
.top-more-menu a {
  display: block;
  padding: .55rem .7rem;
  border-radius: 8px;
  color: var(--text);
  font-size: .85rem;
  font-weight: 600;
}
.top-more-menu a:hover { background: rgba(255,255,255,0.06); }

.shell {
  display: grid;
  grid-template-columns: 320px 1fr;
  min-height: 0;
  min-height: 0;
  height: 100%;
}

.sidebar-backdrop {
  display: none;
}
.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .5rem;
  margin-bottom: .75rem;
}
.sidebar-head h2 {
  margin: 0;
}
#btn-layers-close { display: none; }

.sidebar {
  background: var(--panel);
  border-right: 1px solid var(--line);
  padding: 1rem;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}
.sidebar h2 {
  margin: 0 0 .75rem;
  font-size: .78rem;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--muted);
}
.sidebar-head h2 {
  margin: 0;
}
.layer-list {
  display: grid;
  gap: .55rem;
  margin-bottom: 1.25rem;
}
.layer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
  padding: .7rem .8rem;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(255,255,255,0.03);
}
.layer label {
  display: flex;
  align-items: center;
  gap: .55rem;
  cursor: pointer;
  font-weight: 600;
  font-size: .9rem;
}
.swatch {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  box-shadow: 0 0 0 3px rgba(255,255,255,0.06);
}
.swatch.quake { background: var(--quake); }
.swatch.plane { background: var(--plane); }
.swatch.boat { background: var(--boat); }
.swatch.weather { background: var(--weather); }
.swatch.ainuze { background: #b8f22e; box-shadow: 0 0 0 3px rgba(184, 242, 46, 0.18); }
.swatch.swatch-threat {
  width: 9px;
  height: 9px;
  border-radius: 2px;
  background: #e11d48;
  transform: rotate(45deg);
  box-shadow: 0 0 0 2px rgba(225, 29, 72, 0.25);
}
.layer .meta {
  color: var(--muted);
  font-size: .72rem;
  text-align: right;
}

.card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255,255,255,0.03);
  padding: .9rem;
  margin-bottom: 1rem;
}
.card h3 {
  margin: 0 0 .35rem;
  font-size: .95rem;
}
.card p {
  margin: 0 0 .75rem;
  color: var(--muted);
  font-size: .8rem;
  line-height: 1.45;
}
.row {
  display: flex;
  gap: .5rem;
  flex-wrap: wrap;
}
input[type="text"], input[type="number"], select {
  width: 100%;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: rgba(0,0,0,0.25);
  color: var(--text);
  padding: .55rem .65rem;
  font: inherit;
  margin-bottom: .5rem;
}

.map-wrap {
  position: relative;
  min-height: 0;
}
#map {
  position: absolute;
  inset: 0;
  background: #0b1220;
}
.map-note {
  position: absolute;
  left: 12px;
  bottom: 12px;
  z-index: 500;
  max-width: min(420px, calc(100% - 24px));
  padding: .55rem .75rem;
  border-radius: 12px;
  background: rgba(8, 12, 20, 0.88);
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: .72rem;
  line-height: 1.4;
  box-shadow: var(--shadow);
}
.status-pill {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 500;
  padding: .4rem .7rem;
  border-radius: 999px;
  background: rgba(8, 12, 20, 0.9);
  border: 1px solid var(--line);
  font-size: .75rem;
  font-weight: 650;
}
.status-pill.warn { border-color: rgba(245, 158, 11, 0.45); color: #fbbf24; }
.status-pill.ok { border-color: rgba(52, 211, 153, 0.4); color: #6ee7b7; }
.status-pill.bad { border-color: rgba(248, 113, 113, 0.45); color: #fca5a5; }

.leaflet-container { font: inherit; }
.leaflet-marker-icon.evt-marker-wrap,
.leaflet-marker-pane .evt-marker-wrap {
  overflow: visible !important;
}
.leaflet-marker-pane {
  overflow: visible;
}
.shtf-popup h4 { margin: 0 0 .25rem; font-size: .95rem; }
.shtf-popup p { margin: 0; color: #334155; font-size: .8rem; }
.shtf-popup a {
  color: #b45309;
  text-decoration: none !important;
  font-weight: 650;
}

/* Event markers — Tailwind-style ping (transform+opacity only = reliable) */
.evt-marker-wrap.leaflet-marker-icon,
.leaflet-div-icon.evt-marker-wrap,
.evt-marker-wrap {
  background: transparent !important;
  border: none !important;
  overflow: visible !important;
}
.leaflet-marker-icon {
  overflow: visible !important;
}
.evt-marker {
  position: relative;
  display: grid;
  place-items: center;
  pointer-events: auto;
  overflow: visible !important;
}
.eq-icon {
  position: relative;
  z-index: 2;
  border-radius: 999px;
  border: 2px solid rgba(255,255,255,0.95);
  box-shadow:
    0 0 0 2px rgba(0,0,0,0.4),
    0 0 14px var(--evt-color, #38bdf8);
}
.eq-icon.ainuze-dot {
  border-color: rgba(184, 242, 46, 0.95);
  box-shadow:
    0 0 0 2px rgba(0,0,0,0.35),
    0 0 16px #b8f22e;
}

/* Conflict / threats = hazard diamond (not RAF roundels) */
.eq-icon.eq-threat {
  border-radius: 2px !important;
  transform: rotate(45deg);
  border: 2px solid rgba(255, 255, 255, 0.95);
  display: grid;
  place-items: center;
}
.eq-threat-bang {
  transform: rotate(-45deg);
  color: #fff;
  font-weight: 900;
  font-size: 0.7em;
  line-height: 1;
  text-shadow: 0 1px 2px rgba(0,0,0,0.7);
  pointer-events: none;
}

/* The ping — filled circle that scales out (always visible) */
.evt-glow {
  position: absolute !important;
  z-index: 1;
  left: 50% !important;
  top: 50% !important;
  width: var(--evt-size, 12px) !important;
  height: var(--evt-size, 12px) !important;
  margin: 0 !important;
  border: none !important;
  border-radius: 999px !important;
  background: var(--evt-color, #38bdf8) !important;
  opacity: 0.75;
  pointer-events: none !important;
  transform: translate(-50%, -50%) scale(1);
  transform-origin: center center;
  animation: shtf-ping 2s cubic-bezier(0, 0, 0.2, 1) infinite !important;
}
.evt-glow-2 {
  animation-delay: 1s !important;
}
.evt-threat .evt-glow,
.evt-threat-hot .evt-glow {
  border-radius: 3px !important;
  animation-name: shtf-ping-diamond !important;
}
.evt-threat-hot .evt-glow {
  animation-duration: 1.5s !important;
}
.evt-threat-hot .evt-glow-2 {
  animation-delay: 0.75s !important;
}
.evt-ainuze .evt-glow {
  animation-duration: 2.2s !important;
}
.evt-weather .evt-glow {
  animation-duration: 2.8s !important;
}

@keyframes shtf-ping {
  0% {
    transform: translate(-50%, -50%) scale(1);
    opacity: 0.7;
  }
  75%, 100% {
    transform: translate(-50%, -50%) scale(2.8);
    opacity: 0;
  }
}
@keyframes shtf-ping-diamond {
  0% {
    transform: translate(-50%, -50%) rotate(45deg) scale(1);
    opacity: 0.7;
  }
  75%, 100% {
    transform: translate(-50%, -50%) rotate(45deg) scale(2.6);
    opacity: 0;
  }
}

.hotspot-pulse {
  animation: hotspot-ring-pulse 2.5s ease-in-out infinite;
}
@keyframes hotspot-ring-pulse {
  0%, 100% { stroke-opacity: 0.45; fill-opacity: 0.12; }
  50% { stroke-opacity: 0.95; fill-opacity: 0.3; }
}

/* Zoomed-out: keep ONE ping (still sexy), drop 2nd ring for FPS */
.shtf-pulse-lite .evt-glow-2 {
  display: none !important;
}
.shtf-pulse-lite .evt-glow {
  animation-duration: 2.8s !important;
}
.shtf-pulse-lite .evt-threat-hot .evt-glow {
  animation-duration: 2.2s !important;
}

/* Do NOT kill pulse for prefers-reduced-motion — map markers need the cue.
   Only skip the second ring. */
@media (prefers-reduced-motion: reduce) {
  .evt-glow-2 { display: none !important; }
  .evt-glow { animation-duration: 3.5s !important; }
}

.ac-marker { background: transparent !important; border: none !important; }
.ac-wrap {
  position: relative;
  width: 12px;
  height: 12px;
  pointer-events: auto;
}
/* Plane triangle — never apply this to helicopters */
.ac-wrap:not(.heli) .ac-icon-plane {
  width: 12px;
  height: 12px;
  background: #38bdf8;
  clip-path: polygon(50% 0, 100% 100%, 50% 70%, 0 100%);
  border-radius: 0;
  border: none;
  box-shadow: 0 0 0 1px rgba(0,0,0,0.45);
}
.ac-wrap.heli {
  width: 22px;
  height: 22px;
}
.ac-wrap.heli .ac-icon-heli {
  display: block;
  width: 22px;
  height: 22px;
  overflow: visible;
  filter: drop-shadow(0 0 1.5px rgba(0,0,0,0.95));
  clip-path: none !important;
  border: none !important;
  border-radius: 0 !important;
  background: transparent !important;
  box-shadow: none !important;
}
.ac-wrap.heli .ac-label {
  left: 24px;
  top: 2px;
}
.ac-label {
  position: absolute;
  left: 14px;
  top: -2px;
  white-space: nowrap;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.02em;
  line-height: 1.1;
  color: #e2e8f0;
  text-shadow:
    0 0 3px #000,
    0 1px 2px rgba(0,0,0,.9),
    1px 0 2px rgba(0,0,0,.7);
  max-width: 90px;
  overflow: hidden;
  text-overflow: ellipsis;
  pointer-events: none;
}
.shtf-popup.ac-popup .ac-cs { margin-bottom: .15rem; }
.shtf-popup.ac-popup .ac-meta-status { color: #64748b; font-size: .72rem; margin-top: .2rem; }

.boat-marker { background: transparent !important; border: none !important; }
.boat-wrap {
  position: relative;
  width: 10px;
  height: 10px;
  pointer-events: auto;
}
.boat-wrap .boat-icon {
  width: 10px;
  height: 10px;
  clip-path: polygon(50% 0, 100% 70%, 70% 100%, 30% 100%, 0 70%);
  box-shadow: 0 0 0 1px rgba(0,0,0,0.45);
  border: none;
  border-radius: 0;
}
.boat-wrap.stationary .boat-icon { opacity: 0.55; }
.boat-label {
  position: absolute;
  left: 12px;
  top: -2px;
  white-space: nowrap;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.02em;
  line-height: 1.1;
  color: #ccfbf1;
  text-shadow:
    0 0 3px #000,
    0 1px 2px rgba(0,0,0,.9);
  max-width: 100px;
  overflow: hidden;
  text-overflow: ellipsis;
  pointer-events: none;
}
.leaflet-interactive.shtf-trail {
  pointer-events: none;
}
.ac-wrap.stale,
.boat-wrap.stale {
  opacity: 0.55;
  filter: grayscale(0.25);
}
.ac-wrap.stale .ac-label::after,
.boat-wrap.stale .boat-label::after {
  content: ' · held';
  font-weight: 500;
  opacity: 0.75;
}
.watch-ring {
  stroke: #f59e0b;
  stroke-width: 2;
  fill: rgba(245, 158, 11, 0.12);
}

.event-list {
  display: grid;
  gap: .4rem;
  max-height: 220px;
  overflow: auto;
}
.event-item {
  appearance: none;
  width: 100%;
  text-align: left;
  border: 1px solid var(--line);
  background: rgba(0,0,0,.2);
  color: var(--text);
  border-radius: 10px;
  padding: .45rem .55rem;
  cursor: pointer;
  font: inherit;
  font-size: .75rem;
  line-height: 1.35;
}
.event-item strong {
  display: inline-block;
  margin-right: .35rem;
  color: var(--accent);
  text-transform: uppercase;
  font-size: .65rem;
  letter-spacing: .04em;
}
.event-item span {
  display: block;
  color: var(--muted);
  margin-top: .15rem;
}
.event-item:hover { border-color: rgba(245,158,11,.5); }
.muted { color: var(--muted); }

.auth {
  max-width: 420px;
  margin: 2.5rem auto;
  padding: 1rem;
  padding-bottom: max(1rem, env(safe-area-inset-bottom));
}
.auth h1 { margin-top: 0; font-size: 1.35rem; }
.auth a { text-decoration: none !important; }

/* ===== Mobile / tablet ===== */
@media (max-width: 900px) {
  .brand-tag { display: none; }
  .brand h1 { font-size: .98rem; }
  .brand-mark-img { width: 34px; height: 34px; }

  .btn-label-full { display: none; }
  .btn-label-short { display: inline; }
  .btn-desk { display: none !important; }
  #btn-layers,
  #btn-more { display: inline-flex; }
  #btn-layers-close { display: inline-flex; }

  .top-actions {
    flex-wrap: nowrap;
    gap: .35rem;
  }
  .btn {
    padding: .5rem .7rem;
    font-size: .78rem;
    min-height: 2.4rem;
  }

  .shell {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr;
    position: relative;
  }

  .sidebar-backdrop {
    display: block;
    position: absolute;
    inset: 0;
    z-index: 850;
    background: rgba(0, 0, 0, 0.55);
    border: 0;
    padding: 0;
    cursor: pointer;
  }
  .sidebar-backdrop[hidden] { display: none !important; }

  .sidebar {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 900;
    max-height: min(78dvh, 640px);
    border-right: 0;
    border-top: 1px solid var(--line);
    border-radius: 18px 18px 0 0;
    padding: .85rem 1rem max(1rem, env(safe-area-inset-bottom));
    box-shadow: 0 -18px 50px rgba(0,0,0,0.45);
    transform: translateY(110%);
    transition: transform .28s ease;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
  }
  body.sidebar-open .sidebar {
    transform: translateY(0);
  }

  .map-wrap {
    min-height: 0;
    height: 100%;
  }
  .map-note {
    left: 8px;
    right: 8px;
    bottom: max(8px, env(safe-area-inset-bottom));
    max-width: none;
    font-size: .68rem;
    padding: .45rem .6rem;
  }
  .status-pill {
    top: 8px;
    right: 8px;
    font-size: .7rem;
    max-width: calc(100% - 90px);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .layer {
    padding: .75rem .8rem;
    min-height: 2.75rem;
  }
  .layer label { font-size: .88rem; }
  .card .row .btn { flex: 1 1 auto; justify-content: center; }
}

@media (max-width: 420px) {
  #btn-refresh { display: none; }
  .brand h1 { font-size: .92rem; }
}

@media (min-width: 901px) {
  .sidebar-head { display: none; }
  .top-more-menu { display: none !important; }
}
