:root {
  --bg: #eef3f8;
  --ocean: #dbe8f3;
  --border: #ffffff;
  --panel: #ffffff;
  --text: #1f2933;
  --muted: #66727f;
  --accent: #2563eb;
  --danger: #c0392b;
  --shadow: 0 4px 18px rgba(15, 23, 42, .15);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

[hidden] { display: none !important; }

#map { display: block; width: 100vw; height: 100vh; }
#map .sphere { fill: var(--ocean); }
#map .country { stroke: var(--border); stroke-width: .5; vector-effect: non-scaling-stroke; }
#map .country:hover { filter: brightness(.92); }
body.editing #map .country { cursor: pointer; }
#map .country.selected { stroke: var(--text); stroke-width: 1.5; }
#map .label {
  pointer-events: none;
  text-anchor: middle;
  dominant-baseline: central;
  font-weight: 600;
  paint-order: stroke;
  stroke-linejoin: round;
}

.btn {
  font: inherit;
  padding: 6px 12px;
  border: 1px solid #cbd2d9;
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  cursor: pointer;
}
.btn:hover { background: #f3f4f6; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); }
.btn.link { border: none; background: none; color: var(--muted); padding: 4px 0; text-decoration: underline; }

#edit-btn { position: fixed; top: 16px; right: 16px; box-shadow: var(--shadow); z-index: 10; min-width: 70px; }

#panel {
  position: fixed;
  top: 60px;
  right: 16px;
  width: 260px;
  max-width: calc(100vw - 32px);
  padding: 16px;
  background: var(--panel);
  border-radius: 10px;
  box-shadow: var(--shadow);
  z-index: 10;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
#panel h2 { margin: 0; font-size: 16px; }
#panel .hint { margin: 0; color: var(--muted); font-size: 13px; }
#panel label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
#panel input[type=text] { font: inherit; padding: 6px 8px; border: 1px solid #cbd2d9; border-radius: 6px; color: var(--text); }
.colors { display: flex; gap: 12px; }
.colors input[type=color] { width: 56px; height: 32px; padding: 0 2px; border: 1px solid #cbd2d9; border-radius: 6px; background: #fff; cursor: pointer; }
.row { display: flex; gap: 8px; }
.row .btn { flex: 1; white-space: nowrap; padding: 6px 8px; }
.gradient-bar { height: 10px; border-radius: 5px; }

#popup {
  position: fixed;
  z-index: 20;
  width: 220px;
  padding: 12px;
  background: var(--panel);
  border-radius: 8px;
  box-shadow: var(--shadow);
}
#popup-name { font-weight: 600; margin-bottom: 8px; }
#popup-form { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
#popup-input { flex: 1; min-width: 0; font: inherit; padding: 6px 8px; border: 1px solid #cbd2d9; border-radius: 6px; }
#popup-input.invalid { border-color: var(--danger); outline-color: var(--danger); }
#popup-unit { color: var(--muted); }
#popup .row { width: 100%; }

#zoom-controls {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 10;
  display: flex;
  flex-direction: column;
  border-radius: 6px;
  box-shadow: var(--shadow);
}
#zoom-controls .btn {
  width: 36px;
  height: 36px;
  padding: 0;
  font-size: 18px;
  line-height: 1;
  border-radius: 0;
}
#zoom-controls .btn + .btn { border-top: none; }
#zoom-controls .btn:first-child { border-radius: 6px 6px 0 0; }
#zoom-controls .btn:last-child { border-radius: 0 0 6px 6px; font-size: 16px; }
#map { cursor: grab; }
#map:active { cursor: grabbing; }

#tooltip {
  position: fixed;
  z-index: 30;
  pointer-events: none;
  padding: 4px 8px;
  background: rgba(17, 24, 39, .9);
  color: #fff;
  border-radius: 4px;
  font-size: 12px;
  white-space: nowrap;
}

#legend {
  position: fixed;
  left: 16px;
  bottom: 16px;
  width: 220px;
  padding: 10px 12px;
  background: rgba(255, 255, 255, .92);
  border-radius: 8px;
  box-shadow: var(--shadow);
  font-size: 12px;
}
.legend-scale { display: flex; justify-content: space-between; margin-top: 4px; }
.legend-nodata { display: flex; align-items: center; gap: 6px; margin-top: 6px; color: var(--muted); }
.legend-nodata i { width: 16px; height: 10px; border-radius: 2px; display: inline-block; }

#toast {
  position: fixed;
  left: 50%;
  top: 16px;
  transform: translateX(-50%);
  padding: 8px 14px;
  background: rgba(17, 24, 39, .9);
  color: #fff;
  border-radius: 6px;
  z-index: 40;
}
