* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, sans-serif;
  background: #1a1a2e;
  color: #eee;
  height: 100vh;
  display: flex;
  flex-direction: column;
}

#controls {
  padding: 10px 20px;
  background: #16213e;
  display: flex;
  align-items: center;
  gap: 20px;
  flex-wrap: wrap;
  border-bottom: 2px solid #0f3460;
}

/* ── Fuzzy state search ── */

.state-search {
  position: relative;
  min-width: 160px;
}

.state-search-display {
  padding: 6px 12px;
  border: 1px solid #0f3460;
  border-radius: 4px;
  background: #0f1929;
  color: #eee;
  font-size: 14px;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.state-search-display.placeholder { color: #667; }
.state-search-display:hover { border-color: #4a7c9e; }

.state-search-input {
  width: 100%;
  padding: 6px 12px;
  border: 1px solid #4a9eff;
  border-radius: 4px;
  background: #0f1929;
  color: #eee;
  font-size: 14px;
  outline: none;
}

.state-search-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  max-height: 240px;
  overflow-y: auto;
  background: #0f1929;
  border: 1px solid #0f3460;
  border-top: none;
  border-radius: 0 0 4px 4px;
  z-index: 100;
}

.state-search-item {
  padding: 6px 12px;
  font-size: 13px;
  cursor: pointer;
  color: #ccc;
}

.state-search-item:hover {
  background: #1a3a5c;
  color: #fff;
}

/* Panel label variant — overlaid on the map */
.panel-label {
  position: absolute;
  top: 8px;
  left: 8px;
  z-index: 2;
}

.panel-label .state-search-display {
  background: rgba(15, 25, 41, 0.92);
  font-weight: 600;
}

.panel-label .state-search-dropdown {
  background: rgba(15, 25, 41, 0.97);
  min-width: 200px;
}

/* ── Time controls ── */

#time-controls {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
  min-width: 250px;
}

#time-controls label {
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
}

#year-slider {
  flex: 1;
  min-width: 200px;
  height: 4px;
  border-radius: 2px;
  background: linear-gradient(to right, #444, #666);
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}

#year-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px; height: 14px;
  border-radius: 50%;
  background: #4a9eff;
  cursor: pointer;
  box-shadow: 0 0 4px rgba(74, 158, 255, 0.5);
}

#year-slider::-moz-range-thumb {
  width: 14px; height: 14px;
  border-radius: 50%;
  background: #4a9eff;
  cursor: pointer;
  border: none;
}

#play-btn {
  width: 30px; height: 30px;
  border: 1px solid #0f3460;
  border-radius: 4px;
  background: #0f1929;
  color: #4a9eff;
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

#play-btn:hover { background: #1a3a5c; }

#year-display {
  font-family: 'Courier New', monospace;
  font-size: 1.4em;
  font-weight: 600;
  min-width: 4ch;
  color: #4a9eff;
}

#speed-label {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 13px;
  color: #aaa;
  white-space: nowrap;
}

#play-speed {
  background: #0f1929;
  color: #eee;
  border: 1px solid #0f3460;
  border-radius: 3px;
  padding: 2px 4px;
  font-size: 13px;
}

/* ── Legend ── */

#legend {
  display: flex;
  flex-direction: column;
  gap: 4px;
  width: 200px;
}

#legend-bar {
  width: 100%;
  height: 20px;
  border-radius: 3px;
  background: linear-gradient(to right,
    #ffffcc 0%, #fed976 15%, #fd8d3c 30%, #fc4e2a 45%,
    #e31a1c 60%, #bd0026 80%, #4a0014 100%);
  border: 1px solid #333;
}

#legend-labels {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: #aaa;
}

/* ── Sync toggle ── */

#sync-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  cursor: pointer;
  user-select: none;
}

#sync-toggle input[type="checkbox"] {
  width: 16px; height: 16px;
  cursor: pointer;
  accent-color: #4a9eff;
}

/* ── Map grid ── */

#map-grid {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
  gap: 4px;
  padding: 4px;
  background: #0a0a1a;
  overflow: auto;
}

.map-panel {
  position: relative;
  min-height: 300px;
  background: #0a0a1a;
  border-radius: 4px;
  overflow: hidden;
}

.map-panel .remove-btn,
.map-panel .reset-btn {
  position: absolute;
  z-index: 2;
  width: 28px; height: 28px;
  border: 1px solid #0f3460;
  border-radius: 3px;
  background: rgba(15, 25, 41, 0.92);
  color: #eee;
  font-size: 16px;
  font-weight: bold;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.map-panel .remove-btn { top: 8px; right: 8px; }
.map-panel .reset-btn { top: 8px; right: 42px; }

.map-panel .remove-btn:hover,
.map-panel .reset-btn:hover { background: rgba(31, 65, 120, 0.95); }

.map-panel .zoom-slider {
  position: absolute;
  right: 10px;
  top: 50%;
  z-index: 2;
  width: 100px;
  height: 4px;
  transform: rotate(-90deg) translateX(-50%);
  transform-origin: top right;
  -webkit-appearance: none;
  appearance: none;
  background: rgba(68, 68, 68, 0.7);
  border-radius: 2px;
  outline: none;
}

.map-panel .zoom-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 12px; height: 12px;
  border-radius: 50%;
  background: #4a9eff;
  cursor: pointer;
}

.map-panel .zoom-slider::-moz-range-thumb {
  width: 12px; height: 12px;
  border-radius: 50%;
  background: #4a9eff;
  cursor: pointer;
  border: none;
}

.map-container {
  width: 100%;
  height: 100%;
}

.maplibregl-canvas { position: absolute; }

/* ── Tooltip ── */

.tract-tooltip {
  position: fixed;
  pointer-events: none;
  background: rgba(15, 25, 41, 0.95);
  border: 1px solid #0f3460;
  border-radius: 6px;
  padding: 8px 12px;
  font-size: 13px;
  z-index: 10;
  max-width: 250px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.6);
}

/* ── Scale control ── */

.maplibregl-ctrl-scale {
  background: rgba(15, 25, 41, 0.8) !important;
  color: #aaa !important;
  border-color: #555 !important;
  font-size: 11px !important;
  padding: 0 4px !important;
}

/* ── Scrollbar ── */

#map-grid::-webkit-scrollbar { width: 8px; }
#map-grid::-webkit-scrollbar-track { background: #0a0a1a; }
#map-grid::-webkit-scrollbar-thumb { background: #333; border-radius: 4px; }
#map-grid::-webkit-scrollbar-thumb:hover { background: #444; }
