:root {
  --bg: #f2f6fd;
  --bg-grid: #e4ecfa;
  --panel: #ffffff;
  --panel-2: #eef3fc;
  --border: #d3e0f7;
  --text: #0e1b34;
  --muted: #5b6c8c;
  --accent: #1d5fe0;
  --accent-soft: rgba(29, 95, 224, 0.09);
  --accent-2: #38bdf8;
  --amber: #d97a1f;
  --amber-soft: rgba(217, 122, 31, 0.12);
  --danger: #dc3651;
  --up: #1a9e6b;
  --down: #dc3651;
  --radius: 14px;
  --font-display: 'Space Grotesk', sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
  --font-body: 'Inter', sans-serif;
}

[data-theme="dark"] {
  --bg: #080c14;
  --bg-grid: #0d1320;
  --panel: #10182a;
  --panel-2: #131c31;
  --border: #212d47;
  --text: #e9edf7;
  --muted: #8390ab;
  --accent: #4fd8c4;
  --accent-soft: rgba(79, 216, 196, 0.14);
  --accent-2: #7c9eff;
  --amber: #f6a94a;
  --amber-soft: rgba(246, 169, 74, 0.14);
  --danger: #ef6a72;
  --up: #4fd8c4;
  --down: #ef6a72;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  transition: background 0.3s ease, color 0.3s ease;
}

body {
  background-image:
    linear-gradient(var(--bg-grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--bg-grid) 1px, transparent 1px);
  background-size: 42px 42px;
  min-height: 100vh;
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; }
}

.scanlines {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: repeating-linear-gradient(180deg, rgba(255,255,255,0.012) 0px, rgba(255,255,255,0.012) 1px, transparent 1px, transparent 3px);
  z-index: 999;
}

/* ---------- Topbar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 22px clamp(16px, 4vw, 48px);
  border-bottom: 1px solid var(--border);
}

.brand { display: flex; align-items: center; gap: 14px; }
.brand-mark { width: 34px; height: 34px; color: var(--accent); flex-shrink: 0; }

.eyebrow {
  margin: 0 0 2px;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.14em;
  color: var(--accent);
}

h1 {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(18px, 2.4vw, 24px);
  font-weight: 600;
  letter-spacing: -0.01em;
}

.topbar-actions { display: flex; align-items: center; gap: 12px; }

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.08em;
  color: var(--accent);
  border: 1px solid var(--border);
  padding: 7px 12px;
  border-radius: 999px;
  background: var(--panel);
}
.status-pill .dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 8px var(--accent);
  animation: pulse 1.8s ease-in-out infinite;
}
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.35; } }

.icon-btn {
  width: 38px; height: 38px;
  display: grid; place-items: center;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
}
.icon-btn svg { width: 18px; height: 18px; }
.icon-btn:hover { border-color: var(--accent); color: var(--accent); }

/* ---------- Grid layout ---------- */
.grid {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 18px;
  padding: 24px clamp(16px, 4vw, 48px) 8px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  grid-column: span 4;
}

.hero-panel { grid-column: span 8; }
.radar-panel { grid-column: span 4; display: flex; flex-direction: column; align-items: center; }
.wide-panel { grid-column: span 12; }

@media (max-width: 980px) {
  .panel, .hero-panel, .radar-panel, .wide-panel { grid-column: span 12; }
}

.panel-label {
  margin: 0 0 16px;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.1em;
  color: var(--muted);
}

/* ---------- Hero ticker ---------- */
.ticker-wrap { position: relative; margin-bottom: 22px; }
.ticker {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: clamp(30px, 6vw, 58px);
  letter-spacing: -0.01em;
  color: var(--text);
  position: relative;
  z-index: 1;
}
.ticker-glow {
  position: absolute;
  left: -20px; top: -30px;
  width: 260px; height: 130px;
  background: radial-gradient(circle, var(--accent-soft) 0%, transparent 70%);
  z-index: 0;
  pointer-events: none;
}

.hero-meta {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-bottom: 16px;
}
@media (max-width: 640px) { .hero-meta { grid-template-columns: repeat(2, 1fr); } }

.meta-item {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.meta-label { font-size: 11.5px; color: var(--muted); }
.meta-value { font-family: var(--font-mono); font-size: 17px; font-weight: 600; }
.meta-value.up { color: var(--accent); }
.meta-value.down { color: var(--danger); }

.hero-note { margin: 0; font-size: 12.5px; color: var(--muted); line-height: 1.6; }

/* ---------- Radar / Ping gauge ---------- */
.radar {
  position: relative;
  width: 220px;
  height: 220px;
  margin: 4px auto 14px;
}
.radar-rings, .radar-sweep, .radar-progress {
  position: absolute; inset: 0; width: 100%; height: 100%;
}
.ring { fill: none; stroke: var(--border); stroke-width: 1; }
.crosshair { stroke: var(--border); stroke-width: 1; }

.radar-sweep { animation: spin 3.4s linear infinite; transform-origin: 110px 110px; }
@keyframes spin { to { transform: rotate(360deg); } }

.progress-track { fill: none; stroke: var(--panel-2); stroke-width: 6; }
.progress-value {
  fill: none;
  stroke: var(--accent);
  stroke-width: 6;
  stroke-linecap: round;
  stroke-dasharray: 540;
  stroke-dashoffset: 540;
  transform: rotate(-90deg);
  transform-origin: 110px 110px;
  transition: stroke-dashoffset 0.6s ease, stroke 0.6s ease;
}

.radar-center {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
}
.ping-value { font-family: var(--font-mono); font-size: 40px; font-weight: 700; line-height: 1; }
.ping-unit { font-family: var(--font-mono); font-size: 12px; color: var(--muted); margin-top: 2px; }
.ping-label { font-size: 11px; color: var(--muted); margin-top: 8px; letter-spacing: 0.04em; }

.radar-history {
  display: flex;
  align-items: flex-end;
  gap: 3px;
  height: 32px;
  width: 100%;
}
.radar-history span {
  flex: 1;
  background: var(--accent);
  opacity: 0.55;
  border-radius: 2px 2px 0 0;
  min-height: 3px;
}

/* ---------- Charts ---------- */
.chart-holder {
  position: relative;
  width: 100%;
  height: 260px;
}
.wide-panel .chart-holder { height: 300px; }

.trend-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 18px;
}
.trend-badge {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 14px;
  flex: 1;
  min-width: 220px;
}
.trend-icon {
  width: 30px; height: 30px;
  border-radius: 8px;
  display: grid; place-items: center;
  flex-shrink: 0;
}
.trend-icon svg { width: 17px; height: 17px; }
.trend-icon.up { background: color-mix(in srgb, var(--up) 16%, transparent); color: var(--up); }
.trend-icon.down { background: color-mix(in srgb, var(--down) 16%, transparent); color: var(--down); }
.trend-text { display: flex; flex-direction: column; gap: 2px; }
.trend-title { font-size: 12px; color: var(--muted); }
.trend-figure { font-family: var(--font-mono); font-size: 16px; font-weight: 700; }
.trend-figure.up { color: var(--up); }
.trend-figure.down { color: var(--down); }

/* ---------- Country compare ---------- */
.select-row select {
  width: 100%;
  padding: 10px 12px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 14px;
  margin-bottom: 16px;
}
.compare-result { display: flex; justify-content: space-between; margin-bottom: 12px; }
.compare-figure { display: flex; flex-direction: column; gap: 4px; }
.compare-num { font-family: var(--font-mono); font-size: 20px; font-weight: 700; }
.compare-sub { font-size: 11.5px; color: var(--muted); }

.bar-track {
  width: 100%; height: 8px;
  background: var(--panel-2);
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid var(--border);
}
.bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent-2), var(--accent));
  border-radius: 999px;
  transition: width 0.6s ease;
}
.bar-fill.accent-amber { background: linear-gradient(90deg, var(--amber), #ffd08a); }

/* ---------- Milestone ---------- */
.milestone-row { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 8px; }
.milestone-row span:last-child { font-family: var(--font-mono); color: var(--amber); font-weight: 600; }
.milestone-eta { font-size: 11.5px; color: var(--muted); margin: 10px 0 14px; }

.log-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; max-height: 120px; overflow-y: auto; }
.log-list li {
  font-size: 12px;
  color: var(--muted);
  font-family: var(--font-mono);
  border-left: 2px solid var(--border);
  padding-left: 10px;
}
.log-list li.new { color: var(--accent); border-left-color: var(--accent); }

/* ---------- Export ---------- */
.export-desc { font-size: 13px; color: var(--muted); line-height: 1.6; margin: 0 0 16px; }
.export-btn {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  padding: 11px 16px;
  border-radius: 10px;
  border: 1px solid var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 13.5px;
  cursor: pointer;
}
.export-btn svg { width: 16px; height: 16px; }
.export-btn:hover { background: var(--accent); color: #04140f; }
.export-hint { font-size: 11.5px; color: var(--muted); margin-top: 10px; min-height: 14px; }

/* ---------- Footer / toast ---------- */
.footer {
  padding: 20px clamp(16px, 4vw, 48px) 40px;
  color: var(--muted);
  font-size: 11.5px;
  line-height: 1.6;
  max-width: 900px;
}

.toast {
  position: fixed;
  bottom: 22px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--panel);
  border: 1px solid var(--accent);
  color: var(--text);
  padding: 12px 18px;
  border-radius: 10px;
  font-size: 13px;
  font-family: var(--font-mono);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease, transform 0.3s ease;
  z-index: 1000;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

button, select { outline-offset: 2px; }
button:focus-visible, select:focus-visible, .icon-btn:focus-visible { outline: 2px solid var(--accent); }
