/* ============================================================
   The Chapin Map — Session 1 styles
   Editorial palette: navy, off-white, warm neutrals
   Typography: Libre Baskerville (display) + Inter (UI)
   ============================================================ */

* {
  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: #0a0a0a;
  color: #f5f5f5;
  overflow: hidden;
}

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

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

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

.overlay .subtitle {
  margin-top: 8px;
  font-size: 13.5px;
  color: #555;
  font-weight: 400;
  line-height: 1.4;
  letter-spacing: 0.005em;
}

.overlay .phase-tag {
  margin-top: 14px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #1a4d8f;
}

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

.controls button {
  font-family: 'Inter', sans-serif;
  font-size: 12.5px;
  font-weight: 500;
  padding: 10px 16px;
  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 14px rgba(0, 0, 0, 0.14);
  transition: background 0.15s, transform 0.12s, box-shadow 0.15s;
  letter-spacing: 0.01em;
  min-width: 140px;
  text-align: left;
}

.controls button:hover {
  background: #ffffff;
  transform: translateY(-1px);
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.18);
}

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

/* ---------- Metric selector dropdown (top-right cluster) ---------- */
.metric-selector-wrap {
  display: flex;
  flex-direction: column;
  gap: 4px;
  background: rgba(255, 255, 255, 0.96);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  border-radius: 4px;
  box-shadow: 0 2px 14px rgba(0, 0, 0, 0.14);
  padding: 8px 12px 10px;
  min-width: 220px;
}

.metric-selector-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.10em;
  color: #1a4d8f;
  font-family: 'Inter', sans-serif;
}

.metric-selector {
  font-family: 'Libre Baskerville', Georgia, serif;
  font-size: 13px;
  font-weight: 700;
  padding: 4px 0 0 0;
  background: transparent;
  border: none;
  color: #0a0a0a;
  cursor: pointer;
  letter-spacing: -0.005em;
  width: 100%;
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  background-image: url("data:image/svg+xml;charset=US-ASCII,%3Csvg%20xmlns%3D%22http%3A//www.w3.org/2000/svg%22%20width%3D%2210%22%20height%3D%226%22%20viewBox%3D%220%200%2010%206%22%3E%3Cpath%20fill%3D%22%231a4d8f%22%20d%3D%22M0%200l5%206%205-6z%22/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right center;
  padding-right: 18px;
}

.metric-selector:focus {
  outline: 2px solid #1a4d8f;
  outline-offset: 2px;
}

/* ---------- 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: 8px 14px;
  border-radius: 4px;
  letter-spacing: 0.02em;
}

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

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

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

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

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

.transcript {
  max-width: 480px;
  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.20);
  font-size: 13.5px;
  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: #1a4d8f;
  color: #ffffff;
  border: none;
  border-radius: 100px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  box-shadow: 0 6px 28px rgba(26, 77, 143, 0.50), 0 2px 10px rgba(0, 0, 0, 0.20);
  transition: background 0.2s, transform 0.15s, box-shadow 0.2s;
  letter-spacing: 0.01em;
}

.voice-btn:hover {
  background: #234e91;
  transform: translateY(-1px);
  box-shadow: 0 8px 32px rgba(26, 77, 143, 0.58), 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: #c1392b;
  box-shadow: 0 6px 28px rgba(193, 57, 43, 0.50), 0 2px 10px rgba(0, 0, 0, 0.20);
}

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

/* Pulsing ring during call (red) */
.voice-btn.active::before {
  content: '';
  position: absolute;
  inset: -4px;
  border-radius: 100px;
  border: 2px solid rgba(193, 57, 43, 0.55);
  animation: voice-pulse 1.6s ease-out infinite;
  pointer-events: none;
}

/* Extra pulse when assistant is speaking */
.voice-btn.speaking::after {
  content: '';
  position: absolute;
  inset: -10px;
  border-radius: 100px;
  border: 2px solid rgba(255, 255, 255, 0.45);
  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;   }
}

/* ---------- Census legend (bottom-LEFT) ---------- */
.legend {
  position: absolute;
  bottom: 56px;       /* sits above attribution */
  left: 24px;
  right: auto;
  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: 4px;
  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, transform 0.25s;
}

.legend.hidden {
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
}

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

.legend-bar {
  height: 10px;
  border-radius: 2px;
  margin-bottom: 4px;
  overflow: hidden;
}

.legend-gradient {
  height: 100%;
  background: linear-gradient(
    to right,
    #4a4a4a 0%,
    #888888 12%,
    #f3e8d6 25%,
    #9bb8d3 45%,
    #3d6fa3 65%,
    #1a4d8f 85%,
    #0a2845 100%
  );
}

.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: 8px;
  font-size: 10.5px;
  color: #555;
  line-height: 1.3;
}

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

.legend-extra .swatch.new-tract {
  background: rgba(180, 180, 180, 0.7);
  border: 1px solid rgba(0, 0, 0, 0.15);
}

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

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

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

.legend-line.dashed {
  border-top: 2px dashed #c9a55a;
}

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

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

/* ---------- Cinematic mode (Chapin floating in space) ---------- */
body.cinematic {
  background: #000000;
}

body.cinematic .overlay,
body.cinematic .legend,
body.cinematic .attribution,
body.cinematic .controls,
body.cinematic .voice-cluster,
body.cinematic .time-slider {
  opacity: 0.18;
  transition: opacity 0.4s ease;
}

body.cinematic .overlay:hover,
body.cinematic .legend:hover,
body.cinematic .controls:hover,
body.cinematic .voice-cluster:hover,
body.cinematic .time-slider:hover {
  opacity: 1;
}

/* Cinematic button is always visible at full opacity */
body.cinematic #toggleCinematic {
  opacity: 1 !important;
}

/* ---------- Time slider (year scrubber) ---------- */
.time-slider {
  position: absolute;
  bottom: 130px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10;
  background: rgba(255, 255, 255, 0.97);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  border-radius: 6px;
  box-shadow: 0 6px 28px rgba(0, 0, 0, 0.20);
  padding: 14px 22px 10px;
  min-width: 360px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  transition: opacity 0.25s, transform 0.25s;
  font-family: 'Inter', sans-serif;
}

.time-slider.hidden {
  opacity: 0;
  transform: translateX(-50%) translateY(8px);
  pointer-events: none;
}

.time-slider-label {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 8px;
  margin-bottom: 4px;
}

.time-slider-prefix {
  font-size: 9.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: #888;
}

.time-slider-year {
  font-family: 'Libre Baskerville', Georgia, serif;
  font-size: 26px;
  font-weight: 700;
  color: #1a4d8f;
  letter-spacing: -0.01em;
  font-variant-numeric: tabular-nums;
}

.time-slider input[type="range"] {
  width: 100%;
  -webkit-appearance: none;
  appearance: none;
  background: transparent;
  cursor: pointer;
  margin: 0;
}

.time-slider input[type="range"]::-webkit-slider-runnable-track {
  height: 4px;
  background: linear-gradient(to right, #c9a55a 0%, #1a4d8f 100%);
  border-radius: 2px;
}

.time-slider input[type="range"]::-moz-range-track {
  height: 4px;
  background: linear-gradient(to right, #c9a55a 0%, #1a4d8f 100%);
  border-radius: 2px;
  border: none;
}

.time-slider input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  background: #1a4d8f;
  border-radius: 50%;
  border: 3px solid #ffffff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
  cursor: pointer;
  margin-top: -7px;
}

.time-slider input[type="range"]::-moz-range-thumb {
  width: 18px;
  height: 18px;
  background: #1a4d8f;
  border-radius: 50%;
  border: 3px solid #ffffff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
  cursor: pointer;
}

.time-slider-bounds {
  display: flex;
  justify-content: space-between;
  font-size: 10px;
  font-weight: 500;
  color: #888;
  letter-spacing: 0.05em;
  margin-top: 2px;
}

/* ---------- Place popup ---------- */
.place-popup h3 {
  font-family: 'Libre Baskerville', Georgia, serif;
  font-size: 14.5px;
  font-weight: 700;
  margin-bottom: 6px;
  color: #0a0a0a;
  letter-spacing: -0.005em;
}

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

/* ---------- Tract popup (Census click) ---------- */
.tract-popup h3 {
  font-family: 'Libre Baskerville', Georgia, serif;
  font-size: 14.5px;
  font-weight: 700;
  margin-bottom: 4px;
  color: #0a0a0a;
  letter-spacing: -0.005em;
}

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

.tract-county .ga-tag {
  display: inline-block;
  background: #c9a55a;
  color: #ffffff;
  padding: 1px 6px;
  border-radius: 3px;
  font-size: 9.5px;
  letter-spacing: 0.08em;
  margin-left: 4px;
}

.tract-stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  column-gap: 12px;
  row-gap: 4px;
  margin-bottom: 4px;
}

.tract-stat-grid .tract-stat {
  margin-bottom: 0;
}

.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;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  font-size: 10px;
}

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

.tract-growth {
  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;
}

.tract-growth.positive {
  background: rgba(26, 77, 143, 0.10);
  color: #1a4d8f;
}

.tract-growth.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;
}

/* ---------- Mobile tweaks ----------
   Goal: minimal screen real-estate consumed by chrome,
   maximum map visible. Everything that's not essential
   goes away or collapses on small screens.
   ---------------------------------- */
@media (max-width: 600px) {
  /* Smaller header — just the title + tiny phase tag, no subtitle */
  .overlay {
    top: 8px;
    left: 8px;
    right: auto;
    max-width: 70%;
    padding: 8px 12px 7px;
    border-radius: 3px;
  }
  .overlay h1 {
    font-size: 16px;
    line-height: 1.05;
    letter-spacing: -0.01em;
  }
  .overlay .subtitle { display: none; }
  .overlay .phase-tag {
    font-size: 8.5px;
    margin-top: 4px;
    letter-spacing: 0.06em;
  }

  /* Controls: top-right cluster, very compact */
  .controls {
    top: 8px;
    right: 8px;
    bottom: auto;
    left: auto;
    width: auto;
    max-width: 26%;
    flex-direction: column;
    align-items: stretch;
    gap: 4px;
    z-index: 11;
  }
  .metric-selector-wrap {
    min-width: 0;
    width: 100%;
    padding: 5px 10px 6px;
  }
  .metric-selector-label {
    font-size: 8.5px;
    letter-spacing: 0.06em;
  }
  .metric-selector {
    font-size: 11px;
    padding-right: 14px;
  }
  .controls button {
    font-size: 10px;
    padding: 5px 8px;
    min-width: 0;
    letter-spacing: 0;
    text-align: center;
  }

  /* Legend: compact bottom-left, hide Places section + source on mobile */
  .legend {
    top: auto;
    bottom: 90px;
    left: 8px;
    right: auto;
    width: 60%;
    max-width: 220px;
    padding: 8px 10px 8px;
    font-size: 9.5px;
  }
  .legend-title {
    font-size: 10.5px;
    margin-bottom: 5px;
    line-height: 1.15;
  }
  .legend-bar { height: 7px; }
  .legend-labels {
    font-size: 8.5px;
    margin-bottom: 4px;
  }
  .legend-extra {
    font-size: 9px;
    margin-bottom: 3px;
    gap: 6px;
  }
  /* Hide non-essential legend extras on mobile (info still in popups) */
  .legend-section-divider,
  .legend-section-title,
  .legend-source {
    display: none;
  }
  /* Keep only the first .legend-extra (the "new tract" indicator) — hide Places legend */
  .legend-extra ~ .legend-section-divider ~ .legend-extra { display: none; }

  /* Time slider: full-width near bottom on mobile */
  .time-slider {
    bottom: 100px;
    left: 8px;
    right: 8px;
    transform: none;
    min-width: 0;
    width: auto;
    padding: 8px 14px 6px;
  }
  .time-slider.hidden {
    transform: translateY(8px);
  }
  .time-slider-year { font-size: 18px; }
  .time-slider-prefix { font-size: 8.5px; }
  .time-slider-bounds { font-size: 9px; }

  /* Voice cluster floats just above attribution, narrower */
  .voice-cluster {
    bottom: 36px;
  }
  .transcript {
    max-width: calc(100vw - 24px);
    font-size: 12px;
    padding: 10px 14px;
  }
  .voice-btn {
    font-size: 13px;
    padding: 11px 18px 11px 16px;
  }

  /* Attribution: hide on mobile — too much pixel cost for tiny font */
  .attribution {
    display: none;
  }
}
