:root {
  --bg: #05080f;
  --bg-2: #0a1020;
  --panel: rgba(10, 18, 34, 0.72);
  --panel-brd: rgba(80, 140, 220, 0.18);
  --text: #cfe2ff;
  --text-dim: #6f86ad;
  --accent: #32d9ff;
  --good: #30f29a;
  --bad: #ff2d55;
  /* attack severity bands (feed rails, icons, badges) */
  --sev-crit: #ff2d55;
  --sev-high: #ff7a45;
  --sev-med:  #ffd246;
  --sev-low:  #32d9ff;
  --font: "SF Mono", "JetBrains Mono", "Roboto Mono", ui-monospace, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

/* Thin, on-brand scrollbars everywhere. Standard props cover Firefox &
   modern browsers; the -webkit- pseudo-elements cover Chrome/Edge/Safari.
   scrollbar-width/color are inherited, so html propagates to all panels. */
html { scrollbar-width: thin; scrollbar-color: rgba(50, 217, 255, 0.35) transparent; }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: rgba(50, 217, 255, 0.32);
  border-radius: 8px;
  border: 2px solid transparent;   /* inset padding → a slim pill */
  background-clip: padding-box;
}
::-webkit-scrollbar-thumb:hover { background: rgba(50, 217, 255, 0.6); background-clip: padding-box; }
::-webkit-scrollbar-corner { background: transparent; }

#app { display: flex; flex-direction: column; height: 100vh; }

/* ---------- Top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 28px;
  padding: 12px 22px;
  border-bottom: 1px solid var(--panel-brd);
  background: linear-gradient(180deg, rgba(10,18,34,0.95), rgba(5,8,15,0.85));
  z-index: 10;
}

.brand { display: flex; align-items: center; gap: 16px; }
.brand-logo { height: 54px; width: auto; display: block; filter: drop-shadow(0 0 10px rgba(50,217,255,0.15)); }
.brand-divider { width: 1px; height: 34px; background: var(--panel-brd); }
.brand-mark {
  width: 14px; height: 14px; border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, #7af0ff, var(--accent));
  box-shadow: 0 0 16px var(--accent), 0 0 4px #fff inset;
}
.brand-text h1 {
  margin: 0; font-size: 17px; letter-spacing: 3px; font-weight: 700;
  background: linear-gradient(90deg, #fff, var(--accent));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.brand-text p { margin: 2px 0 0; font-size: 11px; color: var(--text-dim); letter-spacing: 1px; }
.brand-text .src { color: var(--accent); }

/* centre CTA — "Under attack?" + Contact button, sits between the brand and
   the counters. margin-left:auto on both this and .counters splits the free
   space evenly, so this block stays centred between the two side groups. */
.under-attack {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  margin-left: auto;
}
.ua-label {
  font-size: 10px; font-weight: 700; letter-spacing: 2px; text-transform: uppercase;
  color: var(--bad); text-shadow: 0 0 12px rgba(255, 45, 85, 0.45);
}
.ua-btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 6px 15px; border-radius: 999px;
  font-family: var(--font); font-size: 11px; font-weight: 700;
  letter-spacing: 1.5px; text-transform: uppercase; text-decoration: none;
  white-space: nowrap; color: #fff;
  background: linear-gradient(180deg, rgba(255, 45, 85, 0.22), rgba(255, 45, 85, 0.08));
  border: 1px solid rgba(255, 45, 85, 0.55);
  box-shadow: 0 0 14px rgba(255, 45, 85, 0.22);
  transition: background .15s ease, border-color .15s ease, box-shadow .15s ease, transform .15s ease;
}
.ua-btn:hover {
  background: linear-gradient(180deg, rgba(255, 45, 85, 0.36), rgba(255, 45, 85, 0.16));
  border-color: var(--bad);
  box-shadow: 0 0 22px rgba(255, 45, 85, 0.45);
  transform: translateY(-1px);
}
.ua-link {
  font-size: 9px; letter-spacing: 1px; color: var(--text-dim);
  text-decoration: none; transition: color .15s ease;
}
.ua-link:hover { color: var(--accent); }

.counters { display: flex; gap: 30px; margin-left: auto; }
.counter { display: flex; flex-direction: column; align-items: flex-end; }
.counter[hidden] { display: none; } /* override .counter's display:flex when withheld */
#c-online { color: #30f29a; text-shadow: 0 0 18px rgba(48,242,154,0.45); } /* "watching now" reads as a live figure */
.counter-value {
  font-size: 26px; font-weight: 700; line-height: 1; color: #fff;
  font-variant-numeric: tabular-nums; text-shadow: 0 0 18px rgba(50,217,255,0.4);
  transition: color .15s ease;
}
.counter-value.flash { color: var(--accent); }
.counter-label { font-size: 10px; color: var(--text-dim); letter-spacing: 1.5px; text-transform: uppercase; margin-top: 4px; }

.status { display: flex; align-items: center; gap: 8px; font-size: 11px; color: var(--text-dim); letter-spacing: 1px; }
.status .dot { width: 9px; height: 9px; border-radius: 50%; background: #444; }
.status.online .dot { background: var(--good); box-shadow: 0 0 10px var(--good); }
.status.offline .dot { background: var(--bad); box-shadow: 0 0 10px var(--bad); }

/* ---------- Stage / map ---------- */
.stage { position: relative; flex: 1; overflow: hidden; }
#map { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

/* ---------- Map zoom controls ---------- */
.map-controls {
  position: absolute;
  top: 18px; left: 18px;
  display: flex; flex-direction: column; gap: 6px;
  z-index: 20;
}
.map-controls button {
  width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; line-height: 1;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--panel-brd);
  border-radius: 9px;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  cursor: pointer;
  transition: background .12s ease, color .12s ease, border-color .12s ease;
  font-family: var(--font);
}
.map-controls button:hover {
  color: #fff;
  border-color: var(--accent);
  background: rgba(50, 217, 255, 0.12);
  box-shadow: 0 0 14px rgba(50, 217, 255, 0.25);
}
.map-controls button:active { transform: translateY(1px); }
/* sound toggle: highlighted when on */
#sound-toggle.on { color: var(--accent); border-color: var(--accent); box-shadow: 0 0 12px rgba(50, 217, 255, 0.25); }
#sound-toggle svg { display: block; }

/* "click to enable sound" prompt — shown when sound was on before but the
   browser still blocks audio until the first user interaction. */
.sound-prompt {
  position: absolute; top: 16px; left: 50%; transform: translateX(-50%);
  display: flex; align-items: center; gap: 9px;
  padding: 9px 16px; font-size: 12px; letter-spacing: .4px;
  color: var(--text); font-family: var(--font);
  background: var(--panel); border: 1px solid var(--accent); border-radius: 999px;
  box-shadow: 0 0 22px rgba(50, 217, 255, 0.28);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  cursor: pointer; z-index: 40;
  animation: prompt-in .3s ease;
}
.sound-prompt svg { width: 16px; height: 16px; color: var(--accent); flex: 0 0 auto; }
.sound-prompt:hover { border-color: #fff; color: #fff; }
@keyframes prompt-in { from { opacity: 0; transform: translate(-50%, -8px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* ---------- Sound-pack picker (custom dropdown with icons) ---------- */
/* The trigger button reuses the .map-controls button look (36×36, glass);
   it shows the current pack's icon plus a small caret, and opens a flyout
   menu to the right of the controls. Menu items are <div>s (not <button>s)
   so they don't inherit the square control styling. */
.sound-picker { position: relative; }
.sp-btn { position: relative; padding: 0; }
.sp-btn svg { width: 19px; height: 19px; display: block; }
.sp-btn::after {
  content: ''; position: absolute; right: 3px; bottom: 3px;
  border-left: 3px solid transparent; border-right: 3px solid transparent;
  border-top: 4px solid currentColor; opacity: .55;
}
.sound-picker.open .sp-btn {
  color: #fff; border-color: var(--accent); background: rgba(50, 217, 255, 0.12);
}
.sp-menu {
  position: absolute; top: 0; left: calc(100% + 8px);
  display: none; flex-direction: column;
  min-width: 188px; padding: 6px;
  max-height: min(74vh, 480px); overflow-y: auto;
  background: var(--panel); border: 1px solid var(--panel-brd); border-radius: 11px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  z-index: 50;
}
.sound-picker.open .sp-menu { display: flex; animation: sp-in .14s ease; }
@keyframes sp-in { from { opacity: 0; transform: translateX(-6px); } to { opacity: 1; transform: translateX(0); } }
.sp-list { display: flex; flex-direction: column; gap: 2px; }

/* volume row (static header above the pack list) */
.sp-vol {
  display: flex; align-items: center; gap: 8px;
  padding: 4px 8px 9px; margin-bottom: 5px;
  border-bottom: 1px solid var(--panel-brd);
}
.sp-vol-ico { width: 16px; height: 16px; flex: 0 0 auto; color: var(--accent); display: flex; }
.sp-vol-ico svg { width: 16px; height: 16px; display: block; }
.sp-vol-val { width: 30px; text-align: right; flex: 0 0 auto; font: 600 11px var(--font); color: var(--text-dim); font-variant-numeric: tabular-nums; }
.sp-range {
  flex: 1; -webkit-appearance: none; appearance: none;
  height: 4px; border-radius: 3px; cursor: pointer;
  background: rgba(80, 140, 220, 0.28);
}
.sp-range::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 13px; height: 13px; border-radius: 50%; border: none;
  background: var(--accent); box-shadow: 0 0 8px rgba(50, 217, 255, 0.6); cursor: pointer;
}
.sp-range::-moz-range-thumb {
  width: 13px; height: 13px; border-radius: 50%; border: none;
  background: var(--accent); box-shadow: 0 0 8px rgba(50, 217, 255, 0.6); cursor: pointer;
}
.sp-range::-moz-range-track { height: 4px; border-radius: 3px; background: rgba(80, 140, 220, 0.28); }
.sp-item {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 9px; border-radius: 8px; cursor: pointer;
  color: var(--text); font: 600 12.5px var(--font); letter-spacing: .3px;
  border: 1px solid transparent; user-select: none;
  transition: background .1s ease, color .1s ease;
}
.sp-item:hover { background: rgba(50, 217, 255, 0.10); color: #fff; }
.sp-item.sel { color: #fff; background: rgba(50, 217, 255, 0.08); border-color: var(--accent); }
.sp-item .sp-ico { width: 18px; height: 18px; flex: 0 0 auto; color: var(--accent); display: flex; align-items: center; justify-content: center; }
.sp-item .sp-ico svg { width: 18px; height: 18px; display: block; }
.sp-item .sp-name { flex: 1; white-space: nowrap; }
.sp-item .sp-check { width: 15px; height: 15px; flex: 0 0 auto; color: var(--accent); opacity: 0; }
.sp-item.sel .sp-check { opacity: 1; }
.sp-item .sp-check svg { width: 15px; height: 15px; display: block; }

/* ---------- Panels ---------- */
.panel {
  position: absolute;
  background: var(--panel);
  border: 1px solid var(--panel-brd);
  border-radius: 12px;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  box-shadow: 0 10px 40px rgba(0,0,0,0.45);
  /* Float above the map, zoom controls and legend so an open panel is
     always fully visible and never covered by another overlay. */
  z-index: 30;
}

.panel-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 14px 8px; }
.panel-head h2, .stat-block h3 { margin: 0; font-size: 12px; letter-spacing: 2px; color: var(--text); text-transform: uppercase; }

.pulse-pill { display: inline-flex; align-items: center; gap: 6px; font-size: 10px; letter-spacing: 1.5px; color: var(--bad); }
.pulse-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--bad); box-shadow: 0 0 8px var(--bad); animation: blink 1.2s infinite; }
@keyframes blink { 0%,100% { opacity: 1; } 50% { opacity: .25; } }

/* feed (collapsible side panel) */
.feed {
  top: 18px; right: 18px; width: 360px; max-height: calc(100% - 36px);
  display: flex; flex-direction: column;
  overflow: hidden;   /* clip the IP-detail overlay to the rounded panel */
  transition: transform .28s ease, opacity .28s ease;
}
.stage.feed-collapsed .feed {
  transform: translateX(calc(100% + 28px));
  opacity: 0; pointer-events: none;
}
.feed .panel-head .pulse-pill { margin-left: auto; }
#feed-toggle {
  margin-left: 8px; width: 24px; height: 24px;
  display: flex; align-items: center; justify-content: center;
  background: transparent; color: var(--text-dim);
  border: 1px solid var(--panel-brd); border-radius: 6px;
  cursor: pointer; font-size: 12px; font-family: var(--font);
  transition: color .12s ease, border-color .12s ease;
}
#feed-toggle:hover { color: #fff; border-color: var(--accent); }
#feed-toggle svg { display: block; width: 15px; height: 15px; }

/* reopen tab — only visible when the feed is collapsed */
#feed-open {
  position: absolute; top: 18px; right: 18px; z-index: 12;
  display: none; align-items: center; gap: 7px;
  padding: 9px 13px; font-size: 11px; letter-spacing: 2px; font-weight: 700;
  color: var(--text); background: var(--panel);
  border: 1px solid var(--panel-brd); border-radius: 10px;
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  cursor: pointer; font-family: var(--font);
  transition: color .12s ease, border-color .12s ease;
}
#feed-open:hover { color: #fff; border-color: var(--accent); }
.stage.feed-collapsed #feed-open { display: flex; }
/* overflow-x:hidden stops the row entry animation (translateX) from briefly
   pushing content past the right edge and flashing a horizontal scrollbar. */
.feed-list { list-style: none; margin: 0; padding: 4px 8px 10px; overflow-y: auto; overflow-x: hidden; flex: 1; }

/* ---------- Feed header widgets (clock · threat meter · sparkline · chips) ---------- */
.feed-clock {
  display: flex; align-items: center; gap: 10px; margin: 10px 14px 0; padding: 8px 11px;
  border-radius: 9px; border: 1px solid rgba(50,217,255,0.14);
  background: linear-gradient(90deg, rgba(50,217,255,0.06), rgba(50,217,255,0.02));
}
.feed-clock .fc-ico { width: 14px; height: 14px; color: var(--accent); flex: 0 0 auto; filter: drop-shadow(0 0 6px rgba(50,217,255,.5)); }
.fc-time { font-size: 18px; font-weight: 700; color: #fff; letter-spacing: 1.5px; font-variant-numeric: tabular-nums; text-shadow: 0 0 14px rgba(50,217,255,0.35); }
.fc-time .cln { animation: fc-colon 1.05s steps(1, end) infinite; }
@keyframes fc-colon { 50% { opacity: .2; } }
@media (prefers-reduced-motion: reduce) { .fc-time .cln { animation: none; } }
.fc-date { margin-left: auto; text-align: right; line-height: 1.2; }
.fc-dow { display: block; font-size: 10px; font-weight: 700; color: var(--accent); letter-spacing: 2px; }
.fc-ymd { display: block; font-size: 9px; color: var(--text-dim); letter-spacing: 1.2px; font-variant-numeric: tabular-nums; }

.feed-metrics { display: flex; align-items: flex-end; gap: 14px; margin: 12px 14px 0; }
.fm-meter { flex: 1; min-width: 0; }
.fm-meter-top { display: flex; justify-content: space-between; font-size: 8.5px; letter-spacing: 1.5px; color: var(--text-dim); margin-bottom: 5px; text-transform: uppercase; }
.fm-meter-top b { color: #fff; font-weight: 700; transition: color .3s ease; }
.fm-track { height: 6px; border-radius: 6px; background: rgba(255,255,255,0.06); overflow: hidden; }
.fm-fill {
  height: 100%; width: 0; border-radius: 6px; transition: width .6s ease;
  background: linear-gradient(90deg, var(--sev-low), var(--sev-med), var(--sev-high), var(--sev-crit));
  box-shadow: 0 0 10px currentColor;
}
.fm-spark-wrap { flex: 0 0 auto; }
.fm-spark { display: flex; align-items: flex-end; gap: 2px; height: 28px; width: 92px; }
.fm-spark i { flex: 1; min-height: 2px; border-radius: 1px; background: rgba(50,217,255,0.25); transition: height .3s ease, background .3s ease; }

.feed-chips { display: flex; gap: 6px; flex-wrap: wrap; padding: 12px 14px 4px; }
.fchip {
  display: inline-flex; align-items: center; gap: 6px; padding: 4px 9px;
  font-size: 9.5px; letter-spacing: .5px; color: var(--text-dim);
  background: rgba(255,255,255,0.03); border: 1px solid var(--panel-brd);
  border-radius: 999px; cursor: pointer; user-select: none; font-family: var(--font);
  transition: color .15s ease, border-color .15s ease, background .15s ease;
}
.fchip:hover { color: var(--text); border-color: rgba(80,140,220,0.4); }
.fchip.on { color: #fff; background: rgba(50,217,255,0.1); border-color: var(--accent); }
.fchip .sw { width: 7px; height: 7px; border-radius: 50%; }
.fchip .ct { font-variant-numeric: tabular-nums; color: var(--text-dim); opacity: .7; font-weight: 700; }
.fchip.on .ct { color: var(--text); opacity: 1; }

/* paused-on-hover banner: appears when the feed is paused with queued events */
.feed-resume {
  display: none; align-items: center; justify-content: center; gap: 8px;
  margin: 6px 8px 0; padding: 8px; border-radius: 8px; cursor: pointer;
  font-size: 11px; letter-spacing: 1px; font-weight: 700; color: #05080f;
  background: linear-gradient(90deg, var(--accent), #7af0ff); font-family: var(--font);
}
.feed-resume.show { display: flex; }
.feed-resume:hover { filter: brightness(1.08); }
.feed.paused .pulse-pill { color: var(--sev-med); }
.feed.paused .pulse-dot { background: var(--sev-med); box-shadow: 0 0 8px var(--sev-med); animation: none; }

.feed-row.fr-hide { display: none; }

/* Severity-driven feed cards: a glowing left rail, an attack-type icon chip,
   a severity badge and a time block — driven by --sev (set per row in JS). */
.feed-row {
  position: relative;
  display: grid;
  grid-template-columns: 6px 1fr;
  margin: 7px 0;
  border-radius: 11px;
  overflow: hidden;
  background: rgba(255,255,255,0.025);
  border: 1px solid rgba(80,140,220,0.10);
  cursor: pointer;   /* clickable → IP intelligence drill-down */
  transition: border-color .15s ease, background .15s ease, transform .15s ease;
  animation: rowin .4s cubic-bezier(.2,.8,.2,1);
}
.feed-row:hover { background: rgba(50,217,255,0.05); border-color: rgba(50,217,255,0.35); transform: translateX(-2px); }
@keyframes rowin { from { opacity: 0; transform: translateX(20px) scale(.98); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .feed-row { animation: none; } }

/* left rail — severity colour with a soft glow; critical pulses */
.fr-rail { background: var(--sev, var(--accent)); box-shadow: inset 0 0 8px rgba(0,0,0,.4), 0 0 12px -2px var(--sev, var(--accent)); }
.feed-row.sev-crit .fr-rail { animation: railpulse 1.6s ease-in-out infinite; }
@keyframes railpulse { 0%,100% { box-shadow: 0 0 8px -2px var(--sev); } 50% { box-shadow: 0 0 16px 0 var(--sev); } }
@media (prefers-reduced-motion: reduce) { .feed-row.sev-crit .fr-rail { animation: none; } }

/* one-shot ring flash when a new row arrives */
.feed-row.fr-new::after {
  content: ""; position: absolute; inset: 0; border-radius: 11px; pointer-events: none;
  box-shadow: 0 0 0 1px var(--sev), 0 0 22px -2px var(--sev); animation: frnewring 1.4s ease-out forwards;
}
@keyframes frnewring { from { opacity: 1; } to { opacity: 0; } }

.fr-body { padding: 9px 11px; min-width: 0; }
.fr-row1 { display: flex; align-items: center; gap: 8px; }
.fr-ico {
  width: 26px; height: 26px; flex: 0 0 auto;
  display: flex; align-items: center; justify-content: center;
  border-radius: 7px; color: var(--sev, var(--accent));
  background: color-mix(in srgb, var(--sev, var(--accent)) 14%, transparent);
  border: 1px solid color-mix(in srgb, var(--sev, var(--accent)) 35%, transparent);
}
.fr-ico svg { width: 15px; height: 15px; }
.fr-title { font-size: 12.5px; font-weight: 700; color: var(--sev, var(--accent)); letter-spacing: .2px; line-height: 1.2; word-break: break-word; }

.fr-time { margin-left: auto; text-align: right; flex: 0 0 auto; line-height: 1.2; padding-left: 8px; border-left: 1px solid rgba(80,140,220,0.14); }
.fr-time .clk { display: block; font-size: 13px; font-weight: 700; color: #fff; letter-spacing: .5px; font-variant-numeric: tabular-nums; }
.fr-time .dt  { display: block; font-size: 9px; color: var(--text-dim); letter-spacing: .3px; font-variant-numeric: tabular-nums; margin-top: 1px; }
.fr-time .rel { color: var(--sev, var(--accent)); }

.fr-route { display: flex; align-items: center; gap: 6px; margin-top: 7px; font-size: 12px; flex-wrap: wrap; }
.fr-route .cc { color: #fff; }
.fr-route .arrow { color: var(--sev, var(--accent)); }
.fr-route .router { color: var(--text); font-weight: 600; }
.fr-route .sev-badge {
  margin-left: auto; font-size: 8.5px; font-weight: 700; letter-spacing: 1px; flex: 0 0 auto;
  padding: 2px 7px; border-radius: 5px; color: var(--sev, var(--accent));
  background: color-mix(in srgb, var(--sev, var(--accent)) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--sev, var(--accent)) 30%, transparent);
}

.fr-meta { margin-top: 5px; font-size: 10px; color: var(--text-dim); word-break: break-word; }
.fr-meta .ip-lk { color: var(--text); border-bottom: 1px dotted transparent; transition: color .12s ease, border-color .12s ease; }
.feed-row:hover .fr-meta .ip-lk { color: var(--accent); border-bottom-color: rgba(50,217,255,0.5); }
/* SVG flag images — render the same on every OS (incl. Windows). */
.flag {
  width: 21px; height: 15px; flex: 0 0 auto;
  border-radius: 2px; object-fit: cover; vertical-align: -3px;
  box-shadow: 0 0 0 1px rgba(255,255,255,0.1); background: rgba(255,255,255,0.04);
}

/* insights (bottom-left stats) — capped to the stage height with an
   internal scroll so a long stats list can never overflow past the header
   and break the layout. */
.insights {
  left: 18px; bottom: 18px; width: 340px;
  height: auto;                /* auto-fits content (grows/shrinks) */
  max-height: calc(100% - 36px);
  display: flex; flex-direction: column;
  overflow: hidden;            /* the inner body scrolls only if capped */
  min-width: 240px;
  transition: transform .28s ease, opacity .28s ease;
}
.insights-body {
  flex: 1 1 auto; min-height: 0;
  overflow-y: auto; overflow-x: hidden; overscroll-behavior: contain;
  padding: 4px 14px 12px;      /* was supplied by the panel's own padding */
  container-type: inline-size; /* enables @container width queries for .stat-grid */
}

/* collapse to the left, mirroring the feed (which collapses to the right) */
.stage.insights-collapsed .insights {
  transform: translateX(calc(-100% - 28px));
  opacity: 0; pointer-events: none;
}
.insights .panel-head { padding-bottom: 4px; }
#insights-toggle {
  margin-left: 8px; width: 24px; height: 24px;
  display: flex; align-items: center; justify-content: center;
  background: transparent; color: var(--text-dim);
  border: 1px solid var(--panel-brd); border-radius: 6px;
  cursor: pointer; font-size: 12px; font-family: var(--font);
  transition: color .12s ease, border-color .12s ease;
}
#insights-toggle:hover { color: #fff; border-color: var(--accent); }
#insights-toggle svg { display: block; width: 15px; height: 15px; }

/* reopen control — an icon button in the top-left control column (just below
   the sound toggle). Inherits the square .map-controls button styling; here
   we only size the icon and toggle visibility (shown when collapsed). */
#insights-open { display: none; position: relative; }
#insights-open svg { display: block; width: 17px; height: 17px; }
/* red blinking activity dot, pinned to the top-right corner of the button */
#insights-open .pulse-dot { position: absolute; top: 4px; right: 4px; }
.stage.insights-collapsed #insights-open { display: flex; }

/* a profile can withhold every Insights section; with nothing left to show,
   hide the panel and its reopen button entirely. */
.stage.insights-empty .insights,
.stage.insights-empty #insights-open { display: none !important; }

/* width handle on the right edge (height is automatic). Width is remembered
   across reloads; double-click resets it. */
.resize-grip {
  position: absolute; top: 8px; bottom: 8px; right: 0;
  width: 10px; cursor: ew-resize; z-index: 3; touch-action: none;
  display: flex; align-items: center; justify-content: center;
}
.resize-grip::before {
  content: ""; width: 3px; height: 30px; border-radius: 3px;
  background: var(--text-dim); opacity: .35;
  transition: opacity .12s ease, background .12s ease;
}
.resize-grip:hover::before { opacity: 1; background: var(--accent); }
body.resizing-insights { cursor: ew-resize; user-select: none; }
/* The rank lists (Countries / Victims / Companies) flow into as many columns
   as the panel width allows: side by side when there's room, stacked when the
   panel is narrow. auto-fit collapses empty tracks, so however many sections a
   profile shows, they spread to fill the width with no dead space. */
.stat-grid {
  margin-top: 14px;
  display: grid;
  grid-template-columns: 1fr;   /* narrow panel: a single column (stacked) */
  gap: 14px 18px;
  align-items: start;
}
/* Without this a grid track grows to its widest content (a long company name),
   pushing the panel past its width and adding a horizontal scrollbar. min-width:0
   keeps each track at 1fr and lets long names truncate instead. */
.stat-block { min-width: 0; }
/* Wide enough panel → two columns. Top Blacklists (the first block) spans both
   columns when an ODD number of sections is shown (.stat-grid-odd, set by the
   server), so it sits alone on top and the rest pair up below: 3 shown → 1 on
   top + 2 below; 4 shown → a tidy 2×2; 1 → full width. */
@container (min-width: 440px) {
  .stat-grid { grid-template-columns: 1fr 1fr; }
  .stat-grid.stat-grid-odd > .stat-block:first-child { grid-column: 1 / -1; }
}
.bars { margin-top: 10px; display: flex; flex-direction: column; gap: 10px; }
/* full name + count on top, the bar spans the full width below — so long
   blacklist names are shown in full (wrapping if needed), never truncated. */
.bar-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  grid-template-areas: "name cat val" "bar bar bar";
  column-gap: 8px; row-gap: 4px;
  align-items: center; font-size: 11px;
}
.bar-row .name { grid-area: name; color: var(--text); line-height: 1.3; overflow-wrap: anywhere; min-width: 0; }
.bar-row .cat-tag {
  grid-area: cat; font-size: 8.5px; font-weight: 700; letter-spacing: .5px;
  text-transform: uppercase; padding: 1px 6px; border-radius: 999px;
  border: 1px solid currentColor; opacity: .85; white-space: nowrap;
}
.bar-row .val { grid-area: val; text-align: right; color: var(--text-dim); font-variant-numeric: tabular-nums; }
.bar-track { grid-area: bar; height: 12px; background: rgba(255,255,255,0.05); border-radius: 6px; overflow: hidden; }
.bar-fill {
  display: block; height: 100%; width: 0; border-radius: 6px;
  transition: width .5s ease;
  position: relative; overflow: hidden;
  box-shadow: 0 0 6px currentColor;
}
/* one-shot highlight that flies left → right ONLY when the count changes
   (like an arc launching on the map). Invisible while idle. */
.bar-fill::after {
  content: ""; position: absolute; inset: 0;
  background-image: linear-gradient(90deg, transparent 0%, rgba(255,255,255,0.9) 50%, transparent 100%);
  background-repeat: no-repeat;
  background-size: 35% 100%;
  background-position: -50% 0;
  opacity: 0;
}
.bar-fill.sweep::after { animation: bar-sweep 0.7s ease-out 1; }
@keyframes bar-sweep {
  0%   { background-position: -50% 0; opacity: 1; }
  100% { background-position: 150% 0; opacity: 0; }
}
@media (prefers-reduced-motion: reduce) {
  .bar-fill.sweep::after { animation: none; }
}

.rank { list-style: none; margin: 8px 0 0; padding: 0; }
.rank li { display: flex; justify-content: space-between; gap: 6px; font-size: 11px; padding: 3px 0; color: var(--text); }
.rank li .n { color: var(--text-dim); font-variant-numeric: tabular-nums; flex: 0 0 auto; }
/* min-width:0 lets the flex item shrink so a long name (e.g. "UCLOUD
   INFORMATION TECHNOLOGY (HK) LIMITED") truncates with "…" instead of forcing
   the column — and the panel — wider, which previously caused a bottom scroll. */
.rank li .name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* inline SVG shield in the Top Routers list */
.ico-shield {
  width: 13px; height: 13px; flex: 0 0 auto;
  margin-right: 6px; vertical-align: -2px;
  color: var(--accent);
  filter: drop-shadow(0 0 4px rgba(50, 217, 255, 0.45));
}

/* legend */
.legend {
  position: absolute; bottom: 18px; left: 50%; transform: translateX(-50%);
  display: flex; flex-wrap: wrap; gap: 6px 16px; justify-content: center;
  padding: 8px 16px; max-width: 60%;

  /* background: var(--panel); 
  border: 1px solid var(--panel-brd);

  border-radius: 999px;  */
  
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
}
.legend-item { display: flex; align-items: center; gap: 6px; font-size: 10px; letter-spacing: .5px; color: var(--text-dim); }
.legend-swatch { width: 9px; height: 9px; border-radius: 50%; box-shadow: 0 0 8px currentColor; }
/* The legend is always shown on desktop; its open-on-tap handle is mobile-only. */
#legend-handle { display: none; }

/* ---------- IP intelligence drill-down ---------- */
.ip-detail {
  position: absolute; inset: 0; z-index: 6;
  display: flex; flex-direction: column;
  background: linear-gradient(180deg, rgba(10,18,34,0.98), rgba(5,8,15,0.98));
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-radius: 12px;
  transform: translateX(100%); opacity: 0; pointer-events: none;
  transition: transform .3s cubic-bezier(.4,0,.2,1), opacity .3s ease;
}
.feed.detail-open .ip-detail { transform: none; opacity: 1; pointer-events: auto; }

.ipd-head { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--panel-brd); }
.ipd-title { font-size: 12px; letter-spacing: 2px; color: var(--text); font-weight: 700; text-transform: uppercase; }
.ipd-title small { display: block; font-size: 9px; letter-spacing: 1px; color: var(--text-dim); font-weight: 400; text-transform: none; margin-top: 2px; }
.ipd-back, .ipd-copy {
  width: 26px; height: 26px; display: flex; align-items: center; justify-content: center;
  background: transparent; color: var(--text-dim);
  border: 1px solid var(--panel-brd); border-radius: 7px;
  cursor: pointer; font-family: var(--font); font-size: 15px; line-height: 1;
  transition: color .12s ease, border-color .12s ease;
}
.ipd-back:hover, .ipd-copy:hover { color: #fff; border-color: var(--accent); }
.ipd-copy { margin-left: auto; font-size: 13px; }
.ipd-copy.ok { color: var(--good); border-color: var(--good); }

.ipd-ctx {
  display: flex; align-items: center; gap: 7px; flex-wrap: wrap;
  padding: 10px 14px; font-size: 12px;
  border-bottom: 1px solid var(--panel-brd);
  background: color-mix(in srgb, var(--type-color, var(--accent)) 7%, transparent);
}
.ipd-cico {
  width: 24px; height: 24px; flex: 0 0 auto;
  display: flex; align-items: center; justify-content: center;
  border-radius: 7px; color: var(--type-color, var(--accent));
  background: color-mix(in srgb, var(--type-color, var(--accent)) 14%, transparent);
  border: 1px solid color-mix(in srgb, var(--type-color, var(--accent)) 35%, transparent);
}
.ipd-cico svg { width: 14px; height: 14px; }
.ipd-ctx .cat { color: var(--type-color, var(--accent)); font-weight: 700; }
.ipd-sev {
  font-size: 8.5px; font-weight: 700; letter-spacing: 1px; padding: 2px 7px; border-radius: 5px;
  color: var(--type-color, var(--accent));
  background: color-mix(in srgb, var(--type-color, var(--accent)) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--type-color, var(--accent)) 30%, transparent);
}
.ipd-ctx .rt { color: var(--text-dim); flex-basis: 100%; display: flex; align-items: center; gap: 5px; }
.ipd-ctx .rt .flag { width: 18px; height: 13px; }

.ipd-body { flex: 1; overflow-y: auto; overflow-x: hidden; padding: 14px; }
.ipd-ip {
  font-size: 18px; font-weight: 700; color: var(--accent); letter-spacing: .5px;
  font-variant-numeric: tabular-nums; word-break: break-all;
  text-shadow: 0 0 16px rgba(50,217,255,0.3);
}
.ipd-hero { display: flex; align-items: center; gap: 12px; margin: 12px 0; }
.ipd-hero .flag { width: 34px; height: 24px; }
.ipd-hero .loc { font-size: 15px; font-weight: 700; color: #fff; }
.ipd-hero .sub { font-size: 11px; color: var(--text-dim); margin-top: 2px; }

.ipd-tags { display: flex; gap: 6px; flex-wrap: wrap; margin: 10px 0; }
.ipd-tag { font-size: 9px; font-weight: 700; letter-spacing: 1px; padding: 3px 8px; border-radius: 6px; }
.ipd-tag.type { color: var(--accent); background: rgba(50,217,255,0.1); border: 1px solid rgba(50,217,255,0.3); }
.ipd-tag.host { color: #ffd60a; background: rgba(255,214,10,0.1); border: 1px solid rgba(255,214,10,0.3); }
.ipd-tag.eu { color: var(--good); background: rgba(48,242,154,0.1); border: 1px solid rgba(48,242,154,0.3); }

.ipd-sec { font-size: 9px; letter-spacing: 2px; color: var(--text-dim); text-transform: uppercase; margin: 16px 0 2px; padding-bottom: 6px; border-bottom: 1px solid var(--panel-brd); }
.ipd-row { display: flex; justify-content: space-between; gap: 12px; padding: 7px 0; border-bottom: 1px solid rgba(255,255,255,0.04); }
.ipd-row .k { color: var(--text-dim); font-size: 10px; letter-spacing: .5px; flex: 0 0 auto; }
.ipd-row .v { color: var(--text); font-size: 12px; text-align: right; word-break: break-word; font-variant-numeric: tabular-nums; }

.ipd-map {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  margin-top: 14px; padding: 10px; text-decoration: none;
  font-size: 11px; letter-spacing: 1px; font-weight: 700; color: var(--accent);
  background: rgba(50,217,255,0.07); border: 1px solid rgba(50,217,255,0.25); border-radius: 9px;
  transition: background .15s ease, color .15s ease;
}
.ipd-map:hover { background: rgba(50,217,255,0.16); color: #fff; }
.ipd-map svg { width: 14px; height: 14px; }
.ipd-foot { margin-top: 12px; text-align: center; font-size: 9px; color: var(--text-dim); letter-spacing: .3px; }

.ipd-sk {
  height: 13px; border-radius: 5px; margin: 10px 0;
  background: linear-gradient(90deg, rgba(255,255,255,0.04), rgba(255,255,255,0.1), rgba(255,255,255,0.04));
  background-size: 200% 100%; animation: ipd-shimmer 1.25s linear infinite;
}
@keyframes ipd-shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) { .ipd-sk { animation: none; } }
.ipd-msg { padding: 28px 14px; text-align: center; font-size: 12px; color: var(--text-dim); line-height: 1.6; }
.ipd-msg b { color: var(--text); }
.ipd-msg svg { width: 26px; height: 26px; color: var(--text-dim); display: block; margin: 0 auto 10px; }
.ipd-retry {
  margin-top: 14px; padding: 7px 14px; font-family: var(--font); font-size: 11px; letter-spacing: 1px;
  color: var(--accent); background: rgba(50,217,255,0.08); border: 1px solid rgba(50,217,255,0.3);
  border-radius: 8px; cursor: pointer;
}
.ipd-retry:hover { background: rgba(50,217,255,0.18); color: #fff; }

@media (max-width: 900px) {
  .counters { gap: 16px; }
  .counter-value { font-size: 20px; }
  .ua-btn { padding: 5px 12px; letter-spacing: 1px; }
  .ua-label, .ua-link { letter-spacing: 1px; }
  .feed { width: 260px; }
  .insights { width: 260px; }
  .legend { max-width: 90%; }
}

/* ================= Phones ================= */
@media (max-width: 640px) {
  /* ---- Header: compact; counters wrap to a second row ---- */
  .topbar { gap: 8px 12px; padding: 8px 12px; flex-wrap: wrap; }
  .brand { gap: 9px; }
  .brand-logo { height: 30px; }
  .brand-divider { display: none; }
  .brand-text h1 { font-size: 13px; letter-spacing: 1.4px; }
  .brand-text p { display: none; }            /* drop the subtitle to save a row */
  .under-attack { margin-left: auto; gap: 0; }
  .ua-label { display: none; }                /* keep the CTA button, drop its label */
  .ua-btn { padding: 5px 11px; font-size: 10px; letter-spacing: 1px; }
  .status { font-size: 10px; gap: 6px; }
  .counters { order: 5; width: 100%; margin: 0; gap: 24px; justify-content: flex-start; }
  .counter { align-items: flex-start; }
  .counter-value { font-size: 18px; }
  .counter-label { font-size: 9px; }

  /* ---- Side panels: full-stage drawers (start collapsed; opened on demand) ---- */
  .feed, .insights {
    left: 8px; right: 8px; top: 8px; bottom: 8px;
    width: auto; max-width: none; max-height: none; min-width: 0;
  }
  .insights { height: auto; }                 /* override desktop bottom-anchored auto height */
  .resize-grip { display: none; }             /* no drag-resize on touch */

  /* ---- Legend: bottom sheet opened via #legend-handle ---- */
  .legend {
    position: absolute; left: 0; right: 0; bottom: 0;
    width: 100%; max-width: none;
    justify-content: flex-start; gap: 12px 18px;
    max-height: 48%; overflow-y: auto;
    padding: 18px 16px calc(64px + env(safe-area-inset-bottom, 0px)); /* room for the floating handle */
    background: linear-gradient(180deg, rgba(10,18,34,0.96), rgba(5,8,15,0.98));
    border-top: 1px solid var(--panel-brd);
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -12px 40px rgba(0,0,0,0.5);
    transform: translateY(100%);
    transition: transform .28s cubic-bezier(.4,0,.2,1);
    z-index: 25;
  }
  .legend-item { font-size: 12px; }           /* a touch larger for touch reading */
  .stage.legend-open .legend { transform: translateY(0); }

  #legend-handle {
    display: flex; align-items: center; gap: 8px;
    position: absolute; left: 50%; bottom: calc(12px + env(safe-area-inset-bottom, 0px));
    transform: translateX(-50%); z-index: 26;
    padding: 9px 18px;
    font-family: var(--font); font-size: 11px; font-weight: 700;
    letter-spacing: 2px; text-transform: uppercase; color: var(--text);
    background: var(--panel); border: 1px solid var(--panel-brd); border-radius: 999px;
    box-shadow: 0 6px 20px rgba(0,0,0,0.4);
    backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
    cursor: pointer;
  }
  #legend-handle::after {                      /* caret: points up when closed, flips when open */
    content: ''; border-left: 4px solid transparent; border-right: 4px solid transparent;
    border-bottom: 5px solid currentColor; opacity: .7; transition: transform .2s ease;
  }
  .stage.legend-open #legend-handle::after { transform: rotate(180deg); }
  .stage.legend-empty #legend-handle { display: none; } /* nothing to show */
}
