:root {
  color-scheme: dark;
  --ink: #ecf3f5;
  --muted: #9db0b9;
  --panel: rgba(9, 23, 32, 0.92);
  --panel-strong: #0b1721;
  --line: rgba(204, 230, 235, 0.17);
  --accent: #2fd5c4;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html, body, .app-shell, #map {
  width: 100%;
  height: 100%;
  min-height: 100%;
  margin: 0;
}

body {
  background: #0b1721;
  color: var(--ink);
  overflow: hidden;
}

.app-shell { position: relative; }

#map {
  background: #132631;
  z-index: 0;
}

.topbar {
  position: absolute;
  z-index: 700;
  top: 16px;
  left: 16px;
  right: 16px;
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: 72px;
  padding: 12px 16px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
  box-shadow: 0 16px 50px rgba(0, 0, 0, 0.26);
  backdrop-filter: blur(14px);
}

.brand-mark {
  position: relative;
  flex: 0 0 42px;
  width: 42px;
  height: 42px;
}

.brand-mark span {
  position: absolute;
  inset: 50% auto auto 50%;
  border: 3px solid transparent;
  border-top-color: var(--accent);
  border-radius: 50%;
  transform: translate(-50%, -50%);
}

.brand-mark span:nth-child(1) { width: 40px; height: 40px; }
.brand-mark span:nth-child(2) { width: 27px; height: 27px; }
.brand-mark span:nth-child(3) {
  width: 11px;
  height: 11px;
  border: 0;
  background: #f4b942;
}

.title-group { min-width: 0; }

.title-group h1 {
  margin: 0;
  font-size: clamp(1.1rem, 2.3vw, 1.55rem);
  line-height: 1.2;
  letter-spacing: -0.025em;
}

.title-group p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.875rem;
}

.headline-stats {
  display: flex;
  gap: 26px;
  margin: 0 0 0 auto;
}

.headline-stats div { min-width: 118px; }
.headline-stats dt {
  margin-bottom: 3px;
  color: var(--muted);
  font-size: 0.75rem;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.headline-stats dd {
  margin: 0;
  font-size: 1.2rem;
  font-weight: 750;
  font-variant-numeric: tabular-nums;
}

.legend-panel {
  position: absolute;
  z-index: 700;
  left: 16px;
  bottom: 40px;
  width: 210px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.24);
  backdrop-filter: blur(14px);
}

.legend-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
  font-size: 0.9rem;
  font-weight: 700;
}

.legend-unit { color: var(--muted); font-size: 0.72rem; font-weight: 500; }
.legend-steps { display: grid; gap: 5px; }
.legend-row { display: flex; align-items: center; gap: 9px; font-size: 0.8rem; }
.legend-swatch { width: 28px; height: 12px; border-radius: 3px; border: 1px solid rgba(255,255,255,.18); }
.node-legend { display: grid; gap: 5px; margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--line); }
.node-legend-title { margin-bottom: 2px; font-size: 0.78rem; font-weight: 700; }
.node-dot { width: 11px; height: 11px; margin: 0 8px; border: 1px solid #10222c; border-radius: 50%; }
.node-dot-majority { background: #ffb400; }
.node-dot-other { background: #009ee0; }
.legend-panel p { margin: 11px 0 0; color: var(--muted); font-size: 0.75rem; }

.status-card, .demo-notice {
  position: absolute;
  z-index: 750;
  top: 104px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel-strong);
  box-shadow: 0 8px 28px rgba(0,0,0,.25);
  font-size: 0.85rem;
}

.status-card[hidden], .demo-notice[hidden] { display: none; }
.status-card.error { color: #ffd7d2; border-color: rgba(240, 79, 61, .55); }
.demo-notice { color: #161c20; background: #f4b942; border-color: #ffd97a; font-weight: 700; }

.spinner {
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255,255,255,.28);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.map-footer {
  position: absolute;
  z-index: 700;
  right: 9px;
  bottom: 7px;
  display: flex;
  gap: 14px;
  padding: 5px 8px;
  border-radius: 6px;
  color: #c7d4d9;
  background: rgba(5, 14, 20, .77);
  font-size: 0.7rem;
}

.leaflet-control-zoom {
  overflow: hidden;
  border: 1px solid var(--line) !important;
  border-radius: 10px !important;
  box-shadow: 0 8px 24px rgba(0,0,0,.25) !important;
}

.leaflet-control-zoom a {
  color: var(--ink) !important;
  background: var(--panel-strong) !important;
  border-color: var(--line) !important;
}

.leaflet-control-layers {
  color: var(--ink);
  background: var(--panel-strong);
  border: 1px solid var(--line) !important;
  border-radius: 10px !important;
  box-shadow: 0 8px 24px rgba(0,0,0,.25) !important;
}

.leaflet-control-layers-expanded { padding: 8px 10px; }
.leaflet-control-layers-selector { accent-color: #ffb400; }

.leaflet-popup-content-wrapper, .leaflet-popup-tip {
  color: var(--ink);
  background: #0d1d27;
}

.leaflet-popup-content-wrapper {
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 16px 44px rgba(0,0,0,.34);
}

.leaflet-popup-content { margin: 16px; min-width: 230px; font-size: 0.875rem; }
.leaflet-popup-close-button { color: #c8d5da !important; font-size: 22px !important; }
.popup-title { margin: 0 26px 4px 0; font-size: 1.05rem; }
.popup-summary { margin: 0 0 12px; color: var(--muted); }
.popup-list { display: grid; gap: 8px; margin: 0; padding: 0; list-style: none; }
.popup-community { display: flex; justify-content: space-between; gap: 16px; padding-top: 8px; border-top: 1px solid var(--line); }
.popup-community strong { font-weight: 650; }
.popup-community span { color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.popup-empty { margin: 0; color: var(--muted); }

@media (max-width: 720px) {
  .topbar { top: 8px; left: 8px; right: 8px; min-height: 64px; padding: 9px 11px; }
  .brand-mark { flex-basis: 36px; width: 36px; height: 36px; }
  .brand-mark span:nth-child(1) { width: 34px; height: 34px; }
  .brand-mark span:nth-child(2) { width: 23px; height: 23px; }
  .title-group p { display: none; }
  .headline-stats { gap: 14px; }
  .headline-stats div { min-width: 0; }
  .headline-stats dt { font-size: 0.65rem; }
  .headline-stats dd { font-size: 1rem; }
  .headline-stats div:nth-child(2) { display: none; }
  .status-card, .demo-notice { top: 82px; max-width: calc(100% - 20px); text-align: center; border-radius: 10px; }
  .legend-panel { left: 8px; bottom: 38px; width: 162px; padding: 10px; }
  .legend-heading { display: block; }
  .legend-unit { display: block; margin-top: 2px; }
  .legend-row { font-size: 0.74rem; }
  .legend-panel p { display: none; }
  .map-footer { right: 5px; bottom: 4px; }
  .map-footer span:first-child { display: none; }
}
