:root {
  --bg: #0b0e14;
  --bg-2: #11151e;
  --card: rgba(22, 27, 38, 0.78);
  --line: rgba(255, 255, 255, 0.07);
  --text: #e6e9ef;
  --muted: #8a93a6;
  --accent: #e9c46a;
  --ok: #4ade80;
  --warn: #f4a261;
  --bad: #ef476f;
  --radius: 14px;
  --font: "Inter", "SF Pro Text", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  --mono: "JetBrains Mono", "SF Mono", ui-monospace, Menlo, Consolas, monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background:
    radial-gradient(1200px 600px at 20% -10%, rgba(42, 157, 143, 0.12), transparent 60%),
    radial-gradient(900px 500px at 110% 10%, rgba(214, 40, 104, 0.10), transparent 60%),
    var(--bg);
  color: var(--text);
  font: 14px/1.45 var(--font);
  font-feature-settings: "tnum" 1, "cv11" 1;
  -webkit-font-smoothing: antialiased;
  display: flex; flex-direction: column;
}
h1, h2 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: 18px; }
h2 { font-size: 12px; text-transform: uppercase; letter-spacing: 0.09em; color: var(--muted); margin-bottom: 10px; }
.muted { color: var(--muted); font-weight: 400; }
.small { font-size: 12px; }

/* top bar */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  padding: 14px 22px; border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(17, 21, 30, 0.9), rgba(11, 14, 20, 0.6));
  backdrop-filter: blur(8px);
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 30px; height: 30px; border-radius: 9px;
  background: conic-gradient(from 210deg, #1f4f8f, #2a9d8f, #e9c46a, #e76f51, #d62868, #1f4f8f);
  box-shadow: 0 0 24px rgba(233, 196, 106, 0.25);
}
.subtitle { margin: 2px 0 0; color: var(--muted); font-size: 12.5px; }
.layer-switcher { display: flex; gap: 6px; flex-wrap: wrap; padding: 4px; border-radius: 999px; background: var(--bg-2); border: 1px solid var(--line); }
.layer-btn {
  font: inherit; font-size: 12.5px; color: var(--muted); background: transparent; border: 0;
  padding: 6px 14px; border-radius: 999px; cursor: pointer; transition: all .2s;
}
.layer-btn:hover:not([disabled]) { color: var(--text); }
.layer-btn.active { background: var(--text); color: var(--bg); font-weight: 600; }
.layer-btn.soon { cursor: not-allowed; opacity: .55; }
.soon-tag { font-size: 9.5px; text-transform: uppercase; letter-spacing: .08em; border: 1px solid var(--line); padding: 1px 5px; border-radius: 6px; margin-left: 3px; }

/* layout */
.layout { flex: 1; display: grid; grid-template-columns: minmax(0, 1fr) 340px; min-height: 0; }
@media (max-width: 900px) { .layout { grid-template-columns: 1fr; } .map-wrap { height: 62vh; } }
.map-wrap { position: relative; min-height: 520px; overflow: hidden; }
#map { position: absolute; inset: 0; width: 100%; height: 100%; cursor: grab; }
#map:active { cursor: grabbing; }
.sphere { fill: #0e131c; stroke: rgba(255, 255, 255, 0.08); }
.graticule { fill: none; stroke: rgba(255, 255, 255, 0.04); stroke-width: .5; vector-effect: non-scaling-stroke; }
.country { stroke: #0b0e14; stroke-width: .5; vector-effect: non-scaling-stroke; transition: filter .15s, stroke .15s; }
.country.has-data { cursor: pointer; }
.country.stale { opacity: .55; }
.country:hover { stroke: #fff; stroke-width: 1.2; filter: brightness(1.15); }
.country.selected { stroke: var(--accent); stroke-width: 1.8; filter: brightness(1.2); }
.map-hint { position: absolute; right: 16px; bottom: 12px; color: var(--muted); font-size: 11.5px; opacity: .7; pointer-events: none; }

/* legend */
.legend {
  position: absolute; left: 18px; bottom: 18px; padding: 12px 14px 10px; width: 300px;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); backdrop-filter: blur(10px);
}
.legend-title { font-size: 12px; font-weight: 600; margin-bottom: 8px; }
.legend-bar { display: flex; height: 10px; border-radius: 5px; overflow: hidden; }
.legend-bar span { flex: 1; }
.legend-ticks { position: relative; height: 16px; font-size: 10.5px; color: var(--muted); font-family: var(--mono); }
.legend-ticks span { position: absolute; top: 3px; transform: translateX(-50%); }
.legend-nodata { display: flex; align-items: center; gap: 6px; font-size: 11px; color: var(--muted); margin-top: 4px; }
.swatch { width: 14px; height: 10px; border-radius: 3px; display: inline-block; border: 1px solid var(--line); }

/* tooltip */
.tooltip {
  position: absolute; left: 0; top: 0; min-width: 240px; pointer-events: none; z-index: 5;
  padding: 12px 14px; border-radius: var(--radius);
  background: rgba(15, 19, 28, 0.94); border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5); backdrop-filter: blur(10px);
}
.tooltip[hidden] { display: none; }
.tt-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.tt-name { font-weight: 600; font-size: 14px; }
.tt-value { font-size: 28px; font-weight: 700; letter-spacing: -0.02em; color: var(--c); margin: 2px 0 0; }
.tt-meta { color: var(--muted); font-size: 12px; margin-bottom: 8px; }
.tt-nodata { color: var(--muted); font-size: 12.5px; margin-top: 4px; }
.tt-spark-label { font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin-bottom: 2px; }
.spark { display: block; }
.spark-axis { display: flex; justify-content: space-between; font-size: 10px; color: var(--muted); font-family: var(--mono); margin-top: 2px; gap: 8px; }
.spark-empty { font-size: 11px; color: var(--muted); }
.tag { font-size: 10px; text-transform: uppercase; letter-spacing: .06em; padding: 2px 6px; border-radius: 6px; }
.tag.warn { color: var(--warn); border: 1px solid rgba(244, 162, 97, .4); }

/* panel */
.panel { border-left: 1px solid var(--line); padding: 16px; display: flex; flex-direction: column; gap: 14px; overflow-y: auto; min-height: 0; max-height: calc(100vh - 66px); }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stat-v { font-size: 20px; font-weight: 700; letter-spacing: -0.02em; }
.stat-l { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .07em; }
.agg-row { display: flex; justify-content: space-between; align-items: baseline; font-size: 13.5px; }
.agg-row strong { font-size: 18px; }
.agg .spark { margin-top: 6px; width: 100%; }
.ranking { list-style: none; margin: 0; padding: 0; max-height: 360px; overflow-y: auto; }
.ranking li { display: grid; grid-template-columns: 112px 1fr 44px; align-items: center; gap: 8px; padding: 3px 4px; border-radius: 6px; font-size: 12.5px; cursor: default; }
.ranking li:hover { background: rgba(255, 255, 255, 0.05); }
.rk-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rk-bar { height: 6px; background: rgba(255, 255, 255, 0.05); border-radius: 3px; overflow: hidden; }
.rk-bar span { display: block; height: 100%; border-radius: 3px; }
.rk-val { text-align: right; font-family: var(--mono); font-size: 12px; }
.sources ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.sources li { display: flex; gap: 10px; align-items: flex-start; }
.dot { width: 8px; height: 8px; border-radius: 50%; margin-top: 6px; flex: none; }
.dot.ok { background: var(--ok); box-shadow: 0 0 8px var(--ok); }
.dot.stale { background: var(--warn); }
.dot.failed { background: var(--bad); }
::-webkit-scrollbar { width: 8px; } ::-webkit-scrollbar-thumb { background: rgba(255,255,255,.08); border-radius: 4px; }

/* ---------- Milestone 2 ---------- */
.controls { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.mode-toggle { display: flex; padding: 4px; border-radius: 999px; background: var(--bg-2); border: 1px solid var(--line); }
.mode-btn { font: inherit; font-size: 12.5px; color: var(--muted); background: transparent; border: 0; padding: 6px 14px; border-radius: 999px; cursor: pointer; transition: all .2s; }
.mode-btn:hover { color: var(--text); }
.mode-btn.active { background: linear-gradient(90deg, #2a9d8f, #e9c46a); color: #0b0e14; font-weight: 600; }
.country.inverted { stroke: #ff1f5a; stroke-width: 1.6; filter: drop-shadow(0 0 3px rgba(255, 31, 90, .8)); }
.country.noted { fill: #2f3647 !important; stroke-dasharray: 2 2; stroke: #8a93a6; }
.arrow { font-size: .8em; margin-right: 1px; }
.arrow.up { color: #f4a261; } .arrow.down { color: #8ecae6; } .arrow.flat { color: var(--muted); }
.tt-tags { display: flex; gap: 4px; }
.tag { border: 1px solid var(--line); color: var(--muted); }
.tag.bad { color: #ff4d6d; border-color: rgba(255, 77, 109, .5); }
.tt-dir { font-size: 13px; margin: 2px 0 4px; }
.tt-extra { font-size: 11.5px; color: #c3c9d6; margin-bottom: 3px; max-width: 280px; }
.tooltip { max-width: 320px; }
.spark-zero { stroke: #ff4d6d; stroke-dasharray: 3 3; stroke-width: 1; opacity: .7; }
.spark-from { fill: #0b0e14; stroke: #e6e9ef; stroke-width: 1.5; }
.spark-from-key { display: inline-block; width: 7px; height: 7px; border: 1.5px solid #e6e9ef; border-radius: 50%; vertical-align: -1px; }
.legend { width: 330px; }
.legend-unit { font-size: 11px; color: var(--muted); margin: -4px 0 8px; }
.legend-dir { display: flex; justify-content: space-between; font-size: 10.5px; color: var(--muted); margin-top: 2px; }
.legend-dir .neg { color: #ff4d6d; }
.legend-foot { display: flex; justify-content: space-between; gap: 8px; font-size: 10.5px; color: var(--muted); margin-top: 6px; align-items: center; }
.legend-foot > span { display: flex; align-items: center; gap: 5px; }
.stats { grid-template-columns: repeat(3, 1fr); }
.stat.wide { grid-column: span 3; display: flex; justify-content: space-between; align-items: baseline; border-top: 1px solid var(--line); padding-top: 6px; }
.stat-s { font-size: 13px; } .stat-s strong { margin-left: 6px; }
.stat-v .arrow { font-size: .6em; } .stat-v.neg { color: #ff4d6d; }
.stat-v { font-size: 18px; }
.layer-info p { margin: 0 0 6px; color: #c3c9d6; } .layer-info .note { color: var(--warn); }
.rk-bar { position: relative; }
.rk-bar span { position: absolute; top: 0; }
.rk-bar.div::after { content: ""; position: absolute; left: 50%; top: -2px; bottom: -2px; width: 1px; background: rgba(255,255,255,.25); }
.ranking li.stale { opacity: .55; }
.ranking { max-height: 300px; }
.ranking li { grid-template-columns: 120px 1fr 52px; }
.dot.unreachable { background: #6b7385; }
.footnote { font-size: 11px; color: var(--muted); margin-top: 4px; }
