:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --text: #1c2024;
  --muted: #5f6b76;
  --border: #e1e5ea;
  --up: #1b7a43;
  --down: #c62828;
  --nodata: #e3e6ea;
  --land-border: #ffffff;
  --legend: linear-gradient(90deg, #c62828, #f3b8b5 49%, #b7e4c7 51%, #1b7a43);
  --selected: #fff4d6;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1216;
    --surface: #171b21;
    --text: #e7eaee;
    --muted: #9aa5b1;
    --border: #2a3039;
    --up: #3fbf7a;
    --down: #ef6461;
    --nodata: #262c34;
    --land-border: #0f1216;
    --legend: linear-gradient(90deg, #e05250, #6b3534 49%, #2e5b42 51%, #3fbf7a);
    --selected: #2d2a1e;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

.top {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 4px 24px;
  padding: 16px 20px 8px;
}

h1 { margin: 0; font-size: 1.35rem; }
.updated { margin: 2px 0 0; font-weight: 600; color: var(--muted); }
.note { margin: 0; font-size: 0.78rem; color: var(--muted); }

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 16px;
  padding: 8px 20px 20px;
}

.map-wrap, .panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
}

.map-wrap { position: relative; min-width: 0; }
.map { width: 100%; height: min(78vh, 720px); min-height: 360px; }

.legend {
  position: absolute;
  left: 14px;
  bottom: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.75rem;
  color: var(--muted);
}
.legend-bar { width: 140px; height: 8px; border-radius: 4px; background: var(--legend); }
.legend-nodata { display: inline-flex; align-items: center; gap: 4px; margin-left: 8px; }
.legend-nodata i { width: 12px; height: 8px; border-radius: 2px; background: var(--nodata); border: 1px solid var(--border); }

.panel { padding: 14px 0 6px; align-self: start; }
.panel h2 { margin: 0 16px 8px; font-size: 0.95rem; }

.list { list-style: none; margin: 0; padding: 0; }
.list li {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0 12px;
  padding: 9px 16px;
  border-top: 1px solid var(--border);
  cursor: pointer;
  opacity: 0;
  transform: translateX(12px);
  transition: opacity 0.4s ease, transform 0.4s ease, background-color 0.2s;
}
.list li.shown { opacity: 1; transform: none; }
.list li:hover, .list li:focus-visible { background: var(--bg); outline: none; }
.list li.active { background: var(--selected); }

.idx-name { font-weight: 600; display: flex; align-items: center; gap: 6px; }
.flag { width: 18px; height: 13.5px; border-radius: 2px; box-shadow: 0 0 0 1px var(--border); flex: none; }
.idx-country { grid-column: 1; font-size: 0.8rem; color: var(--muted); }
.idx-pct { grid-row: 1 / span 2; grid-column: 2; align-self: center; font-weight: 700; font-variant-numeric: tabular-nums; text-align: right; }
.idx-pct small { display: block; font-weight: 400; font-size: 0.75rem; color: var(--muted); }
.up { color: var(--up); }
.down { color: var(--down); }
.stale { font-size: 0.7rem; color: var(--muted); border: 1px solid var(--border); border-radius: 4px; padding: 0 4px; margin-left: 4px; }

.error { padding: 16px; color: var(--down); }

@media (max-width: 860px) {
  .top { padding: 12px 16px 6px; }
  .layout { grid-template-columns: 1fr; padding: 6px 16px 16px; gap: 12px; }
  .map { height: auto; aspect-ratio: 1 / 1; min-height: 300px; max-height: 70vh; }
  .legend { bottom: 8px; left: 10px; }
  .legend-bar { width: 90px; }
}

@media (prefers-reduced-motion: reduce) {
  .list li { transition: none; }
}
