/* ============================================================
   Charleston Map — TownRing
   Harbor palette: deep teal, palmetto gold, warm white
   ============================================================ */

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

html, body {
  height: 100%;
  width: 100%;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  background: #0a0e14;
  color: #f5f0e8;
  overflow: hidden;
}

/* ---- Map fills viewport ---- */
#map {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
}

/* ---- Header card (top-left) ---- */
.overlay {
  position: absolute;
  top: 24px; left: 24px;
  z-index: 10;
  padding: 20px 26px 18px;
  background: rgba(255, 255, 255, 0.96);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  border-radius: 6px;
  box-shadow: 0 4px 28px rgba(0, 0, 0, 0.22);
  max-width: 360px;
}

.back-link {
  display: block;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #0e4d6c;
  text-decoration: none;
  margin-bottom: 10px;
  opacity: 0.7;
  transition: opacity 0.15s;
}
.back-link:hover { opacity: 1; }

.overlay h1 {
  font-family: 'Libre Baskerville', Georgia, serif;
  font-size: 28px;
  font-weight: 700;
  color: #0a0a0a;
  letter-spacing: -0.02em;
  line-height: 1.05;
}

.overlay .subtitle {
  margin-top: 7px;
  font-size: 13px;
  color: #555;
  font-weight: 400;
  line-height: 1.4;
}

.overlay .phase-tag {
  margin-top: 12px;
  font-size: 10.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #0e4d6c;
}

/* ---- Control buttons (top-right) ---- */
.controls {
  position: absolute;
  top: 24px; right: 24px;
  z-index: 10;
  display: flex;
  flex-direction: column;
  gap: 7px;
  align-items: flex-end;
}

.controls button {
  font-family: 'Inter', sans-serif;
  font-size: 12px;
  font-weight: 500;
  padding: 9px 15px;
  background: rgba(255, 255, 255, 0.96);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  border: none;
  border-radius: 4px;
  color: #0a0a0a;
  cursor: pointer;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.16);
  transition: background 0.15s, transform 0.12s;
  letter-spacing: 0.01em;
  min-width: 130px;
  text-align: left;
}

.controls button:hover {
  background: #ffffff;
  transform: translateY(-1px);
}

.controls button:active { transform: translateY(0); }

/* ---- Metric selector ---- */
.metric-selector {
  position: absolute;
  top: 24px; right: 24px;
  margin-top: 320px; /* pushed below buttons — adjusted by JS if needed */
  z-index: 10;
  background: rgba(255, 255, 255, 0.96);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  border-radius: 4px;
  padding: 10px 14px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.16);
  min-width: 200px;
}

/* Actually position it below the controls dynamically — simpler to just stack it */
.metric-selector {
  position: absolute;
  top: auto;
  bottom: 180px;
  right: 24px;
  margin-top: 0;
}

.metric-label {
  display: block;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #777;
  margin-bottom: 5px;
}

#metricSelect {
  width: 100%;
  font-family: 'Inter', sans-serif;
  font-size: 12.5px;
  font-weight: 500;
  color: #0a0a0a;
  background: transparent;
  border: none;
  cursor: pointer;
  outline: none;
  padding: 0;
}

/* ---- Year slider ---- */
.year-slider-wrap {
  position: absolute;
  bottom: 230px;
  right: 24px;
  z-index: 10;
  background: rgba(255, 255, 255, 0.96);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  border-radius: 4px;
  padding: 10px 14px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.16);
  min-width: 200px;
}

.year-label {
  display: block;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #777;
  margin-bottom: 6px;
}

#yearSlider {
  width: 100%;
  accent-color: #0e4d6c;
}

.year-range {
  display: flex;
  justify-content: space-between;
  font-size: 10px;
  color: #aaa;
  margin-top: 4px;
}

/* ---- Attribution footer (bottom-left) ---- */
.attribution {
  position: absolute;
  bottom: 16px; left: 24px;
  z-index: 10;
  font-size: 11px;
  font-weight: 500;
  color: #f5f5f5;
  background: rgba(0, 0, 0, 0.55);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  padding: 7px 13px;
  border-radius: 4px;
  letter-spacing: 0.02em;
}

/* ---- Marker popups ---- */
.mapboxgl-popup-content {
  font-family: 'Inter', sans-serif;
  padding: 14px 18px;
  border-radius: 5px;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.18);
}

.marker-popup h3 {
  font-family: 'Libre Baskerville', Georgia, serif;
  font-size: 15px;
  font-weight: 700;
  margin-bottom: 4px;
  color: #0a0a0a;
}

.marker-popup p {
  font-size: 12px;
  color: #555;
  line-height: 1.45;
}

/* ---- Voice cluster (bottom-center) ---- */
.voice-cluster {
  position: absolute;
  bottom: 52px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  pointer-events: none;
  width: max-content;
  max-width: calc(100% - 48px);
}

.voice-cluster > * { pointer-events: auto; }

.transcript {
  max-width: 500px;
  padding: 12px 18px;
  background: rgba(255, 255, 255, 0.97);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  border-radius: 6px;
  box-shadow: 0 4px 22px rgba(0, 0, 0, 0.22);
  font-size: 13px;
  color: #0a0a0a;
  line-height: 1.5;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.25s, transform 0.25s;
  display: flex;
  gap: 10px;
  align-items: flex-start;
}

.transcript.visible { opacity: 1; transform: translateY(0); }

.transcript .role { font-size: 16px; flex-shrink: 0; line-height: 1.3; }

.voice-status {
  font-size: 10.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: #f5f5f5;
  background: rgba(0, 0, 0, 0.62);
  padding: 5px 12px;
  border-radius: 100px;
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 0.2s, transform 0.2s;
}

.voice-status.visible { opacity: 1; transform: translateY(0); }

.voice-btn {
  position: relative;
  font-family: 'Inter', sans-serif;
  font-size: 14px;
  font-weight: 600;
  padding: 14px 24px 14px 20px;
  background: #0e4d6c;
  color: #ffffff;
  border: none;
  border-radius: 100px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  box-shadow: 0 6px 28px rgba(14, 77, 108, 0.52), 0 2px 10px rgba(0, 0, 0, 0.22);
  transition: background 0.2s, transform 0.15s, box-shadow 0.2s;
}

.voice-btn:hover {
  background: #155e82;
  transform: translateY(-1px);
  box-shadow: 0 8px 32px rgba(14, 77, 108, 0.60), 0 2px 14px rgba(0, 0, 0, 0.25);
}

.voice-btn:active { transform: translateY(0); }
.voice-btn .mic-icon { width: 18px; height: 18px; }

.voice-btn.active {
  background: #9e2a2b;
  box-shadow: 0 6px 28px rgba(158, 42, 43, 0.50), 0 2px 10px rgba(0, 0, 0, 0.20);
}

.voice-btn.active:hover { background: #b5343a; }

.voice-btn.active::before {
  content: '';
  position: absolute;
  inset: -4px;
  border-radius: 100px;
  border: 2px solid rgba(158, 42, 43, 0.55);
  animation: voice-pulse 1.6s ease-out infinite;
  pointer-events: none;
}

.voice-btn.speaking::after {
  content: '';
  position: absolute;
  inset: -10px;
  border-radius: 100px;
  border: 2px solid rgba(255, 255, 255, 0.40);
  animation: voice-pulse 1.2s ease-out infinite;
  pointer-events: none;
}

@keyframes voice-pulse {
  0%   { transform: scale(1);    opacity: 0.85; }
  100% { transform: scale(1.45); opacity: 0;   }
}

/* ---- Legend (bottom-right) ---- */
.legend {
  position: absolute;
  bottom: 100px; right: 24px;
  z-index: 10;
  width: 240px;
  padding: 14px 16px 12px;
  background: rgba(255, 255, 255, 0.96);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  border-radius: 5px;
  box-shadow: 0 4px 22px rgba(0, 0, 0, 0.18);
  font-family: 'Inter', sans-serif;
  font-size: 11px;
  color: #333;
  transition: opacity 0.25s;
}

.legend.hidden { opacity: 0; pointer-events: none; }

.legend-title {
  font-family: 'Libre Baskerville', Georgia, serif;
  font-size: 12px;
  font-weight: 700;
  color: #0a0a0a;
  margin-bottom: 8px;
  letter-spacing: 0.005em;
  line-height: 1.3;
}

.legend-bar { height: 10px; border-radius: 2px; margin-bottom: 4px; overflow: hidden; }
.legend-gradient { height: 100%; transition: background 0.3s; }

.legend-labels {
  display: flex;
  justify-content: space-between;
  font-size: 10px;
  font-weight: 500;
  color: #555;
  letter-spacing: 0.02em;
  margin-bottom: 10px;
}

.legend-extra {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
  font-size: 10.5px;
  color: #555;
  line-height: 1.3;
}

.swatch {
  display: inline-block;
  width: 14px; height: 14px;
  border-radius: 2px;
  flex-shrink: 0;
}

.null-swatch { background: rgba(180, 180, 180, 0.7); border: 1px solid rgba(0,0,0,0.12); }

.legend-section-divider { height: 1px; background: rgba(0,0,0,0.08); margin: 8px -16px 8px; }

.legend-section-title {
  font-family: 'Libre Baskerville', Georgia, serif;
  font-size: 11px;
  font-weight: 700;
  color: #0a0a0a;
  margin-bottom: 5px;
  letter-spacing: 0.02em;
}

.legend-line {
  display: inline-block;
  width: 18px;
  height: 0;
  flex-shrink: 0;
  border-top: 2px solid #0e4d6c;
  margin-top: 8px;
}

.legend-dot {
  display: inline-block;
  width: 10px; height: 10px;
  border-radius: 50%;
  background: #c9a84c;
  border: 2px solid #ffffff;
  box-shadow: 0 0 0 1px rgba(0,0,0,0.22);
  flex-shrink: 0;
}

.legend-source {
  font-size: 9.5px;
  color: #888;
  font-style: italic;
  line-height: 1.3;
  margin-top: 8px;
  border-top: 1px solid rgba(0,0,0,0.08);
  padding-top: 6px;
}

/* ---- Tract popup ---- */
.tract-popup h3 {
  font-family: 'Libre Baskerville', Georgia, serif;
  font-size: 14px;
  font-weight: 700;
  margin-bottom: 4px;
  color: #0a0a0a;
}

.tract-county {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #0e4d6c;
  margin-bottom: 8px;
}

.tract-stat {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 12px;
  color: #444;
  margin-bottom: 2px;
}

.tract-stat .label {
  font-weight: 500;
  color: #777;
  text-transform: uppercase;
  font-size: 10px;
  letter-spacing: 0.05em;
}

.tract-stat .value {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  color: #0a0a0a;
}

.tract-highlight {
  margin-top: 8px;
  padding: 5px 9px;
  border-radius: 3px;
  font-size: 12px;
  font-weight: 600;
  text-align: center;
  letter-spacing: 0.02em;
  font-variant-numeric: tabular-nums;
  background: rgba(14, 77, 108, 0.10);
  color: #0e4d6c;
}

.tract-highlight.negative {
  background: rgba(74, 74, 74, 0.10);
  color: #4a4a4a;
}

.tract-note {
  margin-top: 8px;
  font-size: 11px;
  color: #888;
  font-style: italic;
  line-height: 1.35;
}

/* ---- Place popup ---- */
.place-popup h3 {
  font-family: 'Libre Baskerville', Georgia, serif;
  font-size: 14px;
  font-weight: 700;
  margin-bottom: 5px;
  color: #0a0a0a;
}

.place-popup p { font-size: 12px; color: #555; line-height: 1.45; }

/* ---- Mobile ---- */
@media (max-width: 640px) {
  .overlay { top: 16px; left: 16px; right: 16px; max-width: none; }
  .overlay h1 { font-size: 22px; }
  .controls { top: auto; bottom: 150px; right: 14px; flex-direction: row; flex-wrap: wrap; justify-content: flex-end; }
  .controls button { min-width: 0; font-size: 11px; padding: 8px 11px; }
  .metric-selector { bottom: 220px; right: 14px; left: 14px; min-width: 0; }
  .legend { bottom: 80px; right: 12px; left: auto; width: 180px; max-height: 42vh; overflow-y: auto; }
  .voice-cluster { bottom: 70px; }
  .transcript { max-width: calc(100vw - 48px); font-size: 12.5px; }
  .attribution { bottom: 10px; left: 12px; right: 12px; font-size: 10px; text-align: center; }
}
