html, body { margin: 0; height: 100%; font: 14px/1.4 -apple-system, system-ui, sans-serif; }
#map { position: absolute; inset: 0; }

#controls {
  position: absolute;
  top: 12px;
  left: 12px;
  width: 300px;
  max-width: calc(100vw - 24px);
  background: rgba(255, 255, 255, 0.96);
  border-radius: 6px;
  padding: 12px 14px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  z-index: 1;
}
#controls .controls-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}
#controls h1 { font-size: 16px; margin: 0; }
#controls-toggle {
  width: 28px;
  height: 28px;
  flex: 0 0 auto;
  border: none;
  background: transparent;
  cursor: pointer;
  padding: 0;
  border-radius: 4px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
#controls-toggle:hover { background: rgba(0, 0, 0, 0.06); }
#controls-toggle .chevron {
  width: 10px;
  height: 10px;
  border-right: 2px solid #555;
  border-bottom: 2px solid #555;
  transform: translateY(-2px) rotate(-135deg);
  transition: transform 0.22s cubic-bezier(0.4, 0, 0.2, 1);
}
#controls-body {
  overflow: hidden;
  max-height: 1000px;
  opacity: 1;
  transition:
    max-height 0.28s cubic-bezier(0.4, 0, 0.2, 1),
    opacity 0.18s ease 0.06s;
}
#controls .controls-header { transition: margin-bottom 0.28s cubic-bezier(0.4, 0, 0.2, 1); }
#controls.collapsed .controls-header { margin-bottom: 0; }
#controls.collapsed #controls-body {
  max-height: 0;
  opacity: 0;
  transition:
    max-height 0.24s cubic-bezier(0.4, 0, 0.2, 1),
    opacity 0.12s ease;
}
#controls.collapsed #controls-toggle .chevron { transform: translateY(-4px) rotate(45deg); }
/* Suppress the transition during the initial auto-collapse on mobile so the
   panel doesn't briefly expand then close on page load. */
#controls.no-anim,
#controls.no-anim #controls-body,
#controls.no-anim .controls-header,
#controls.no-anim #controls-toggle .chevron { transition: none !important; }
@media (max-width: 640px) {
  #controls { width: calc(100vw - 24px); max-width: 320px; }
}
#controls fieldset { border: none; padding: 0; margin: 0 0 10px; }
#controls legend { font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; color: #555; padding: 0; margin-bottom: 4px; }
#controls label { display: block; padding: 2px 0; cursor: pointer; }

#legend { margin-bottom: 10px; }
.legend-bar {
  height: 10px;
  border-radius: 2px;
  background: linear-gradient(to right, #f7fbff, #6baed6, #08306b);
}
.legend-labels { display: flex; justify-content: space-between; font-size: 11px; color: #666; margin-top: 2px; }
.legend-caption { font-size: 11px; color: #333; margin-top: 2px; }

.note, .sources { font-size: 11px; color: #555; margin: 8px 0 0; }
.sources a { color: #3366cc; }

#labels-toggle {
  position: absolute;
  right: 12px;
  bottom: 36px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: none;
  background: #fff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.18), 0 1px 2px rgba(0, 0, 0, 0.08);
  cursor: pointer;
  z-index: 2;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #1a1a1a;
  transition: background 0.18s ease, color 0.18s ease, transform 0.08s ease;
}
#labels-toggle svg { width: 22px; height: 22px; fill: currentColor; }
#labels-toggle:hover { background: #f2f2f2; }
#labels-toggle:active { transform: scale(0.94); }
#labels-toggle[aria-pressed="true"] {
  background: #08519c;
  color: #fff;
  box-shadow: 0 2px 10px rgba(8, 81, 156, 0.35), 0 1px 2px rgba(0, 0, 0, 0.1);
}
#labels-toggle[aria-pressed="true"]:hover { background: #0a5fb3; }
@media (max-width: 640px) {
  #labels-toggle { right: 10px; bottom: 60px; }
}

.maplibregl-popup-content { font-size: 12px; }
.popup-zcta { font-weight: 600; font-size: 13px; margin-bottom: 1px; }
.popup-county { font-size: 11px; color: #666; margin-bottom: 4px; }
.popup-row { display: flex; justify-content: space-between; gap: 8px; }
.popup-row dt { color: #666; }
.popup-row dd { margin: 0; font-variant-numeric: tabular-nums; }
