:root {
  --bg: #0b1220;
  --bg-panel: #101a2e;
  --bg-panel-2: #14203a;
  --border: #22314f;
  --text: #e6edf7;
  --text-dim: #8fa3c2;
  --accent: #4fc3f7;
  --accent-2: #ffd166;
  --ocean: #0a1526;
  --no-data: #263349;
  --radius: 10px;
  font-size: 15px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body, #app { height: 100%; }

body {
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

#app { display: flex; flex-direction: column; }

/* ---------- Top bar ---------- */
#topbar {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  padding: 0.6rem 1rem;
  background: linear-gradient(180deg, #101c33, #0d1626);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.brand { display: flex; align-items: center; gap: 0.6rem; }
.brand-globe { font-size: 1.7rem; }
.brand h1 { font-size: 1.05rem; font-weight: 700; letter-spacing: 0.01em; }
.subtitle { font-size: 0.72rem; color: var(--text-dim); }

#indicator-tabs { display: flex; gap: 0.3rem; flex-wrap: wrap; }

#indicator-tabs button {
  background: transparent;
  color: var(--text-dim);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.32rem 0.75rem;
  font-size: 0.78rem;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}

#indicator-tabs button:hover { color: var(--text); border-color: var(--accent); }

#indicator-tabs button.active {
  background: var(--accent);
  color: #062033;
  border-color: var(--accent);
  font-weight: 600;
}

.topbar-right { margin-left: auto; }

#country-search {
  background: var(--bg-panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 0.45rem 0.7rem;
  width: 210px;
  font-size: 0.82rem;
  outline: none;
}
#country-search:focus { border-color: var(--accent); }
#country-search::placeholder { color: var(--text-dim); }

/* ---------- World stats strip ---------- */
#world-stats {
  display: flex;
  gap: 1px;
  background: var(--border);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
}

.world-stat {
  flex: 1;
  min-width: 130px;
  background: var(--bg-panel);
  padding: 0.45rem 0.9rem;
  text-align: center;
}
.world-stat .ws-label { font-size: 0.66rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-dim); }
.world-stat .ws-value { font-size: 1.02rem; font-weight: 700; color: var(--accent-2); font-variant-numeric: tabular-nums; }

/* ---------- Layout ---------- */
#layout { flex: 1; display: flex; min-height: 0; }

/* ---------- Rankings ---------- */
#rankings {
  width: 235px;
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 0.75rem;
  flex-shrink: 0;
}

#rankings h2 { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-dim); margin-bottom: 0.6rem; }

#rankings-list { list-style: none; counter-reset: rank; }

#rankings-list li {
  counter-increment: rank;
  display: flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.32rem 0.4rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.8rem;
  transition: background 0.12s ease;
}
#rankings-list li:hover { background: var(--bg-panel-2); }
#rankings-list li.selected { background: #1c2c4d; outline: 1px solid var(--accent); }

#rankings-list li::before {
  content: counter(rank);
  color: var(--text-dim);
  font-size: 0.68rem;
  width: 1.3em;
  text-align: right;
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
}

#rankings-list .rk-flag { flex-shrink: 0; }
#rankings-list .rk-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#rankings-list .rk-value { color: var(--accent-2); font-variant-numeric: tabular-nums; font-size: 0.75rem; flex-shrink: 0; }

/* ---------- Map ---------- */
#map-wrap { flex: 1; position: relative; background: radial-gradient(ellipse at center, #0d1930 0%, var(--ocean) 100%); min-width: 0; }

#map { width: 100%; height: 100%; display: block; cursor: grab; }
#map:active { cursor: grabbing; }

.country { stroke: #0b1220; stroke-width: 0.4px; transition: opacity 0.1s ease; }
.country:hover { stroke: #fff; stroke-width: 1px; }
.country.selected { stroke: var(--accent-2); stroke-width: 1.4px; }

#zoom-controls {
  position: absolute;
  top: 12px;
  right: 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
#zoom-controls button {
  width: 32px; height: 32px;
  background: var(--bg-panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 1rem;
  cursor: pointer;
}
#zoom-controls button:hover { border-color: var(--accent); color: var(--accent); }

/* ---------- Legend ---------- */
#legend {
  position: absolute;
  left: 14px;
  bottom: 14px;
  background: rgba(13, 22, 38, 0.88);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.55rem 0.8rem;
  backdrop-filter: blur(4px);
}
#legend .legend-title { font-size: 0.7rem; color: var(--text-dim); margin-bottom: 0.35rem; }
#legend svg { display: block; }
#legend text { fill: var(--text-dim); font-size: 9px; }
#legend .no-data-row { display: flex; align-items: center; gap: 0.4rem; margin-top: 0.35rem; font-size: 0.68rem; color: var(--text-dim); }
#legend .no-data-swatch { width: 12px; height: 12px; border-radius: 3px; background: var(--no-data); display: inline-block; }

/* ---------- Tooltip ---------- */
#tooltip {
  position: absolute;
  pointer-events: none;
  background: rgba(10, 17, 30, 0.95);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.55rem 0.75rem;
  font-size: 0.78rem;
  max-width: 260px;
  z-index: 20;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.5);
}
#tooltip.hidden { display: none; }
#tooltip .tt-name { font-weight: 700; font-size: 0.88rem; margin-bottom: 0.25rem; }
#tooltip .tt-row { display: flex; justify-content: space-between; gap: 1rem; color: var(--text-dim); }
#tooltip .tt-row b { color: var(--text); font-variant-numeric: tabular-nums; font-weight: 600; }

/* ---------- Detail panel ---------- */
#detail-panel {
  width: 320px;
  background: var(--bg-panel);
  border-left: 1px solid var(--border);
  overflow-y: auto;
  flex-shrink: 0;
}

#detail-content { padding: 1rem; }
#detail-content .placeholder { color: var(--text-dim); font-size: 0.85rem; padding-top: 2rem; text-align: center; }

.dp-header { display: flex; align-items: center; gap: 0.6rem; margin-bottom: 0.15rem; }
.dp-flag { font-size: 1.9rem; line-height: 1; }
.dp-header h2 { font-size: 1.1rem; }
.dp-meta { font-size: 0.72rem; color: var(--text-dim); margin-bottom: 0.8rem; }
.dp-close {
  margin-left: auto;
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 1.1rem;
  cursor: pointer;
  padding: 0.2rem;
}
.dp-close:hover { color: var(--text); }

.dp-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem; margin-bottom: 1rem; }
.dp-stat {
  background: var(--bg-panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5rem 0.6rem;
}
.dp-stat .label { font-size: 0.62rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-dim); }
.dp-stat .value { font-size: 0.98rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.dp-stat .value.pos { color: #6ee7a0; }
.dp-stat .value.neg { color: #f47c7c; }
.dp-stat .rank { font-size: 0.62rem; color: var(--accent); }

.dp-chart { margin-bottom: 0.9rem; }
.dp-chart h3 { font-size: 0.72rem; color: var(--text-dim); font-weight: 600; margin-bottom: 0.2rem; }
.dp-chart svg { display: block; width: 100%; }
.dp-chart .axis text { fill: var(--text-dim); font-size: 8.5px; }
.dp-chart .axis line, .dp-chart .axis path { stroke: var(--border); }
.dp-chart .series { fill: none; stroke: var(--accent); stroke-width: 1.6px; }
.dp-chart .area { fill: var(--accent); opacity: 0.12; }
.dp-chart .year-marker { stroke: var(--accent-2); stroke-width: 1px; stroke-dasharray: 3 2; }
.dp-chart .year-dot { fill: var(--accent-2); }
.dp-chart .zero-line { stroke: var(--text-dim); stroke-width: 0.7px; stroke-dasharray: 2 3; opacity: 0.6; }

/* ---------- Timeline ---------- */
#timeline {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  padding: 0.55rem 1.1rem;
  background: linear-gradient(0deg, #101c33, #0d1626);
  border-top: 1px solid var(--border);
}

#play-btn {
  width: 38px; height: 38px;
  border-radius: 50%;
  border: 1px solid var(--accent);
  background: transparent;
  color: var(--accent);
  font-size: 0.95rem;
  cursor: pointer;
  flex-shrink: 0;
  transition: all 0.15s ease;
}
#play-btn:hover, #play-btn.playing { background: var(--accent); color: #062033; }

#year-label {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--accent-2);
  width: 3.2ch;
  text-align: center;
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
}

#slider-wrap { flex: 1; position: relative; padding-top: 4px; }

#year-slider {
  width: 100%;
  -webkit-appearance: none;
  appearance: none;
  height: 6px;
  border-radius: 3px;
  background: var(--bg-panel-2);
  outline: none;
  cursor: pointer;
}
#year-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px; height: 18px;
  border-radius: 50%;
  background: var(--accent-2);
  border: 2px solid #062033;
  cursor: grab;
}
#year-slider::-moz-range-thumb {
  width: 16px; height: 16px;
  border-radius: 50%;
  background: var(--accent-2);
  border: 2px solid #062033;
  cursor: grab;
}

#slider-ticks { display: flex; justify-content: space-between; font-size: 0.62rem; color: var(--text-dim); margin-top: 3px; font-variant-numeric: tabular-nums; }

.footer-note { font-size: 0.68rem; color: var(--text-dim); flex-shrink: 0; }
.footer-note a { color: var(--text-dim); }
.footer-note a:hover { color: var(--accent); }

/* ---------- Loading ---------- */
#loading {
  position: fixed; inset: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 1rem;
  background: var(--bg);
  z-index: 100;
  font-size: 0.9rem;
  color: var(--text-dim);
}
.spinner {
  width: 42px; height: 42px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
  #rankings { display: none; }
}
@media (max-width: 820px) {
  body { overflow: auto; }
  #layout { flex-direction: column; }
  #map-wrap { height: 55vh; }
  #detail-panel { width: 100%; border-left: none; border-top: 1px solid var(--border); }
  .topbar-right { margin-left: 0; width: 100%; }
  #country-search { width: 100%; }
}
