:root {
  --c-text: #e0e0e0;
  --c-muted: #888;
  --c-accent: #4ecdc4;
  --c-border: #333;
  --c-bg: rgba(15, 15, 15, 0.92);
  --c-bg-overlay: rgba(15, 15, 15, 0.95);
  --c-bg-body: #0a0a0a;
  --c-dim: #666;
  --c-faint: #1a1a1a;
  --c-hint: #555;
  --c-accent-60: rgba(78, 205, 196, 0.6);
  --c-shadow: rgba(0, 0, 0, 0.8);
  --font-body: 'DM Mono', monospace;
  --font-heading: 'Syne', sans-serif;

  --fs-xs: 0.625rem;
  --fs-s: 0.6875rem;
  --fs-m: 0.8125rem;
  --fs-l: 1rem;
  --fs-xl: 1.5rem;

  --sp-xs: 0.25rem;
  --sp-s: 0.5rem;
  --sp-m: 0.75rem;
  --sp-l: 1rem;
  --sp-xl: 1.25rem;

  --w-s: 12.5rem;
  --w-m: 17.5rem;
  --w-l: 21.25rem;
  --sidebar-offset: 22.5rem;

  --r-s: 0.1875rem;
  --r: 0.5rem;
  --blur: blur(0.5rem);
  --blur-l: blur(0.75rem);
  --ls: 0.0625rem;
  --ls-s: 0.03125rem;
  --border: 0.0625rem solid var(--c-border);
  --border-subtle: 0.0625rem solid var(--c-faint);
  --z: 1000;
}

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

body {
  font-family: var(--font-body);
  background: var(--c-bg-body);
  color: var(--c-text);
}

#map {
  width: 100vw;
  height: 100vh;
  user-select: none;
}

#controls {
  position: absolute;
  top: var(--sp-l);
  left: var(--sp-l);
  z-index: var(--z);
  padding: var(--sp-l);
  min-width: var(--w-s);
  background: var(--c-bg);
  border: var(--border);
  border-radius: var(--r);
  backdrop-filter: var(--blur);
}

#controls h2 {
  font-size: var(--fs-l);
  letter-spacing: var(--ls);
  margin-bottom: var(--sp-m);
}

.layer-toggle {
  display: flex;
  align-items: center;
  gap: var(--sp-s);
  padding: var(--sp-xs) 0;
  cursor: pointer;
  font-size: var(--fs-m);
}

.layer-toggle input[type="checkbox"] {
  accent-color: var(--c-accent);
  width: var(--sp-l);
  height: var(--sp-l);
}

.layer-name { opacity: 0.8; }

.ward-label { pointer-events: none; }
.ward-label span {
  font-size: var(--fs-xs);
  color: var(--c-accent-60);
  text-shadow: 0 0 var(--sp-xs) var(--c-shadow);
  white-space: nowrap;
}


.cluster-icon {
  filter: drop-shadow(0 0 var(--r-s) var(--c-shadow));
}

#legend {
  position: absolute;
  bottom: var(--sp-l);
  left: 50%;
  transform: translateX(-50%);
  z-index: var(--z);
  padding: var(--sp-m) var(--sp-xl);
  display: flex;
  align-items: center;
  gap: var(--sp-l);
  background: var(--c-bg);
  border: var(--border);
  border-radius: var(--r);
  backdrop-filter: var(--blur);
}

#legend h3 {
  font-size: var(--fs-s);
  letter-spacing: var(--ls-s);
  white-space: nowrap;
}

.legend-gradient {
  display: flex;
  flex-direction: column;
  gap: var(--sp-xs);
}

.gradient-bar {
  width: var(--w-s);
  height: var(--sp-m);
  border-radius: var(--r-s);
  background: linear-gradient(to right,
    rgb(30,60,120) 0%, rgb(40,120,140) 20%, rgb(60,170,90) 40%,
    rgb(200,180,50) 60%, rgb(230,120,40) 80%, rgb(200,50,50) 100%);
}

.gradient-bar.area-bar {
  background: linear-gradient(to right,
    rgb(80,80,80) 0%, rgb(40,120,180) 5%, rgb(40,180,140) 20%,
    rgb(80,200,80) 40%, rgb(220,200,40) 60%, rgb(230,120,30) 80%,
    rgb(200,40,40) 100%);
}

.gradient-labels {
  display: flex;
  justify-content: space-between;
  font-size: var(--fs-xs);
  color: var(--c-muted);
}

.legend-count {
  font-size: var(--fs-s);
  color: var(--c-dim);
  margin-top: var(--sp-xs);
}

/* Leaflet popup overrides */
.leaflet-popup-content-wrapper {
  background: var(--c-bg-overlay);
  border-radius: var(--r);
  border: var(--border);
}

.leaflet-popup-tip { background: var(--c-bg-overlay); }

.leaflet-popup-content {
  font-size: var(--fs-m);
  line-height: 1.6;
}

.popup-title {
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: var(--fs-l);
  margin-bottom: var(--sp-s);
  color: var(--c-accent);
}

.popup-row {
  display: flex;
  justify-content: space-between;
  gap: var(--sp-m);
}

.popup-label { color: var(--c-muted); }
.popup-value { font-weight: 500; }

/* Sidebar */
#sidebar {
  position: absolute;
  top: 0;
  right: calc(-1 * var(--sidebar-offset));
  width: var(--w-l);
  height: 100vh;
  border-left: var(--border);
  z-index: var(--z);
  padding: var(--sp-xl);
  overflow-y: auto;
  transition: right 0.25s ease;
  backdrop-filter: var(--blur-l);
}

#sidebar.open { right: 0; }

.sidebar-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--sp-xl);
  padding-bottom: var(--sp-m);
  border-bottom: var(--border);
}

.sidebar-header h2 {
  font-size: var(--fs-l);
  color: var(--c-accent);
  margin: 0;
}

#sidebar-close {
  background: none;
  border: none;
  color: var(--c-muted);
  font-size: var(--fs-xl);
  cursor: pointer;
  padding: 0 var(--sp-xs);
  line-height: 1;
}

#sidebar-close:hover { color: var(--c-text); }

.sidebar-stats {
  display: flex;
  flex-direction: column;
  gap: var(--sp-s);
  margin-bottom: var(--sp-l);
}

.stat-row {
  display: flex;
  justify-content: space-between;
  padding: var(--sp-s) 0;
  border-bottom: var(--border-subtle);
  font-size: var(--fs-m);
}

.stat-label { color: var(--c-muted); }
.stat-value { font-weight: 500; }

.sidebar-hint {
  font-size: var(--fs-s);
  color: var(--c-hint);
  margin-top: var(--sp-s);
}

#debug-panel {
  position: absolute;
  bottom: var(--sp-l);
  left: var(--sp-l);
  z-index: var(--z);
  padding: var(--sp-m) var(--sp-l);
  font-size: var(--fs-xs);
  color: var(--c-muted);
  background: var(--c-bg);
  border: var(--border);
  border-radius: var(--r);
  backdrop-filter: var(--blur);
  line-height: 1.6;
}
