/* ============================================================
   map.css — Sticky scrollytelling map scene.
   ============================================================ */

.scene--map-pinned {
  display: block;
  padding: 0;
  position: relative;
}

.map-sticky {
  position: sticky;
  top: 0;
  height: 100vh;
  width: 100%;
  overflow: hidden;
  background: var(--bg);
}

.map-container {
  position: absolute;
  inset: 0;
}

.map-panels {
  position: relative;
  z-index: 2;
  pointer-events: none;
  /* Pull panels up so they scroll over the sticky map below. */
  margin-top: -100vh;
}
.map-panel {
  height: 130vh;
  position: relative;
  padding: 0;
}
/* Each panel is 130vh tall so its callout "hangs" in place for ~0.3
   extra scroll-screens between entrance and exit. The inner frame is
   sticky and 100vh — the rule-of-thirds anchors position against it. */
/* The last panel gets extra height so the "Go deeper" CTA has room
   to breathe before the scene unpins and the next section takes over. */
.map-panel:last-child { height: 150vh; }
.map-panel-frame {
  position: sticky;
  top: 0;
  height: 100vh;
  width: 100%;
}

/* ── Rule-of-thirds anchored callouts ──
   Cards are absolutely positioned to one of four thirds-corner anchors
   or to dead center within the sticky frame. Only one panel may use
   `is-pos-c`. */
.map-panel .map-annotation { position: absolute; }
.map-panel.is-pos-tl .map-annotation { top: 14vh;    left: 14vw; }
.map-panel.is-pos-tr .map-annotation { top: 14vh;    right: 14vw; }
.map-panel.is-pos-bl .map-annotation { bottom: 14vh; left: 14vw; }
.map-panel.is-pos-br .map-annotation { bottom: 14vh; right: 14vw; }
.map-panel.is-pos-c  .map-annotation {
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
}

.map-annotation {
  pointer-events: auto;
  width: 380px;
  max-width: 380px;
  padding: var(--space-6);
  background: var(--map-panel-grad);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}
.map-annotation > * { margin: 0; }
.map-annotation h3 {
  font-size: var(--text-xl);
  line-height: 1.2;
  letter-spacing: -0.01em;
}
.map-annotation p {
  color: var(--text-soft);
  font-size: var(--text-sm);
  line-height: 1.65;
}
.map-annotation p strong { color: var(--text); }

/* Gold hairline above the eyebrow on corner-anchored cards to
   reinforce the rule-of-thirds composition. */
.map-panel[class*='is-pos-'] .map-annotation .eyebrow {
  position: relative;
  padding-top: var(--space-3);
}
.map-panel[class*='is-pos-'] .map-annotation .eyebrow::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 24px;
  height: 2px;
  background: var(--gold);
  border-radius: 1px;
}

/* ── Lead stat: the single anchoring number that opens every card ── */
.annotation-lead {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.annotation-lead-value {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 32px;
  line-height: 1;
  color: var(--text);
  font-feature-settings: 'tnum' 1, 'lnum' 1;
  letter-spacing: -0.01em;
}
.annotation-lead-label {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 500;
}

/* ── Personalization: locate button, stats list, CTA card ── */
.map-annotation.is-locked   { border-style: dashed; border-color: var(--gold-soft); }
.map-annotation.is-locked h3,
.map-annotation.is-locked p { opacity: 0.92; }

.annotation-cta {
  width: 100%;
  font-family: var(--font-body);
  font-weight: 700;
  letter-spacing: -0.005em;
}
.annotation-cta[disabled] { opacity: 0.7; cursor: progress; }
.annotation-cta-note {
  margin: 0;
  font-size: var(--text-xs);
  color: var(--muted);
  line-height: 1.4;
}
.annotation-cta-note.is-error { color: var(--los-c); }

/* ── State picker (fallback to "Find my state" geolocation) ──
   Hidden by default; revealed by the "Or pick your state"
   toggle, or auto-shown when geolocation is denied/unavailable.
   Uses a native <select> so iOS/Android show their platform
   picker (wheel / dropdown) — no custom dropdown to maintain,
   and keyboard / screen-reader accessibility comes for free. */
.annotation-picker-toggle {
  background: none;
  border: 0;
  padding: 0;
  margin: 0;
  font-family: var(--font-body);
  font-size: var(--text-xs);
  color: var(--muted);
  cursor: pointer;
  text-align: left;
  text-decoration: underline;
  text-decoration-color: var(--line-strong);
  text-underline-offset: 3px;
  transition: color var(--dur-fast) var(--ease-out);
}
.annotation-picker-toggle:hover,
.annotation-picker-toggle:focus-visible {
  color: var(--primary-bright);
  text-decoration-color: var(--primary-bright);
}
.annotation-picker-toggle[hidden] { display: none; }

.annotation-picker {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 2px;
}
.annotation-picker[hidden] { display: none; }
.annotation-picker-label {
  font-family: var(--font-body);
  font-size: var(--text-xs);
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 600;
}
.annotation-picker-select {
  appearance: none;
  -webkit-appearance: none;
  width: 100%;
  padding: var(--space-3) var(--space-4);
  background-color: var(--map-glass-soft);
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='%23e3a72f' stroke-width='2'><polyline points='3,6 8,11 13,6'/></svg>");
  background-repeat: no-repeat;
  background-position: right var(--space-3) center;
  background-size: 14px 14px;
  padding-right: calc(var(--space-3) * 2 + 14px);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-md);
  color: var(--text);
  font-family: var(--font-body);
  font-size: var(--text-sm);
  font-weight: 600;
  cursor: pointer;
  transition: border-color var(--dur-fast) var(--ease-out),
              box-shadow var(--dur-fast) var(--ease-out);
}
.annotation-picker-select:hover { border-color: var(--gold); }
.annotation-picker-select:focus-visible {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(58, 119, 232, 0.25);
}
/* Native option list — colors only apply on platforms that respect them
   (Firefox, Chrome on Win/Linux); iOS uses the platform sheet anyway. */
.annotation-picker-select option {
  background: var(--surface-2);
  color: var(--text);
}

/* Inline "Not [State]?" button inside the personalized stats dek. */
.map-annotation .link-button {
  background: none;
  border: 0;
  padding: 0;
  margin: 0;
  font: inherit;
  color: var(--primary-bright);
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.map-annotation .link-button:hover,
.map-annotation .link-button:focus-visible {
  color: var(--gold-bright);
}

.annotation-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--space-3);
  margin: 0;
  padding: 0;
}
.annotation-stat { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.annotation-stat dt {
  font-size: var(--text-xs);
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.annotation-stat dd {
  margin: 0;
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: var(--text-xl);
  color: var(--text);
  line-height: 1.1;
  display: flex;
  align-items: baseline;
  gap: 4px;
}
.annotation-stat dd .unit {
  font-size: var(--text-md);
  font-weight: 500;
  color: var(--muted);
}

.map-cta-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-4) var(--space-5);
  background: linear-gradient(135deg, rgba(227, 167, 47, 0.22), rgba(245, 196, 94, 0.08));
  border: 1px solid var(--gold);
  border-radius: var(--radius-md);
  color: var(--text);
  text-decoration: none;
  transition: transform var(--dur-fast) var(--ease-out),
              box-shadow var(--dur-fast) var(--ease-out),
              border-color var(--dur-fast) var(--ease-out);
}
.map-cta-card:hover,
.map-cta-card:focus-visible {
  transform: translateY(-1px);
  border-color: var(--gold-bright);
  box-shadow: 0 12px 32px rgba(227, 167, 47, 0.18);
}
.map-cta-card-body { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.map-cta-card-eyebrow {
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--gold-bright);
  font-weight: 700;
}
.map-cta-card-label {
  font-family: var(--font-body);
  font-weight: 700;
  font-size: var(--text-lg);
  color: var(--text);
  letter-spacing: -0.005em;
}
.map-cta-card-arrow {
  font-family: var(--font-mono);
  font-size: var(--text-xl);
  color: var(--gold-bright);
  flex-shrink: 0;
}
.map-cta-card.is-locked {
  pointer-events: none;
  border-style: dashed;
  border-color: var(--line-strong);
  background: var(--map-glass);
}
.map-cta-card.is-locked .map-cta-card-arrow { color: var(--muted); }
.map-cta-card.is-locked .map-cta-card-eyebrow { color: var(--muted); }

.map-legend {
  position: absolute;
  /* Lift clear of the Mapbox attribution row pinned to the bottom-left. */
  bottom: calc(var(--space-4) + 30px);
  left: var(--space-4);
  z-index: 3;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  background: var(--map-glass);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  backdrop-filter: blur(8px);
  font-size: var(--text-xs);
  color: var(--muted);
}
.map-legend .scale {
  width: 220px;
  height: 8px;
  border-radius: var(--radius-pill);
  background: linear-gradient(90deg, var(--los-a), var(--los-c), var(--los-d));
}
.map-legend .labels { display: flex; justify-content: space-between; font-family: var(--font-mono); }

/* Hover tooltip — floats with the cursor over the choropleth. */
.map-tooltip {
  position: absolute;
  z-index: 4;
  pointer-events: none;
  min-width: 168px;
  padding: var(--space-3) var(--space-4);
  background: var(--map-glass-strong);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-md);
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  color: var(--text);
  font-family: var(--font-body);
  font-size: var(--text-sm);
  transition: transform var(--dur-fast) var(--ease-out);
}
.map-tooltip-name {
  font-weight: 700;
  font-size: var(--text-md);
  letter-spacing: -0.01em;
  margin-bottom: var(--space-2);
}
.map-tooltip-row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin-bottom: 2px;
}
.map-tooltip-val {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: var(--text-lg);
  color: var(--text);
}
.map-tooltip-label {
  font-size: var(--text-xs);
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.map-tooltip-sub {
  display: flex;
  align-items: baseline;
  gap: var(--space-2);
  margin-top: var(--space-2);
  padding-top: var(--space-2);
  border-top: 1px solid var(--line);
}
.map-tooltip-count {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: var(--text-md);
  color: var(--text);
}
.map-tooltip-sublabel {
  font-size: var(--text-xs);
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

/* Mapbox controls — tune for dark navy surface. */
.mapboxgl-ctrl-bottom-right { display: none; }
.mapboxgl-ctrl-bottom-left  { opacity: 0.45; }
.mapboxgl-ctrl-bottom-left:hover { opacity: 1; }
.mapboxgl-ctrl-group {
  background: var(--map-glass-strong) !important;
  border: 1px solid var(--line-strong) !important;
  backdrop-filter: blur(8px);
}
.mapboxgl-ctrl-group button {
  background-color: transparent !important;
}
.mapboxgl-ctrl-group button + button {
  border-top: 1px solid var(--line) !important;
}
.mapboxgl-ctrl-group button .mapboxgl-ctrl-icon { filter: var(--map-ctrl-icon-filter); }

/* ============================================================
   In-annotation rank list (used by the rankings map scene).
   Compact rank / state / delay / LOS row.
   ============================================================ */
.rank-list-mini {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.rank-card-mini {
  display: grid;
  grid-template-columns: 24px 1fr auto auto;
  align-items: center;
  gap: var(--space-3);
  padding: 4px var(--space-2);
  background: transparent;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
}
.rank-card-mini:last-child { border-bottom: 0; }
.rank-card-mini .rank {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--muted);
  font-weight: 700;
}
.rank-card-mini .name {
  font-weight: 600;
  font-size: var(--text-sm);
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.rank-card-mini .delay {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: var(--text-sm);
  color: var(--text);
}
.rank-card-mini .delay .unit {
  font-size: var(--text-xs);
  font-weight: 500;
  color: var(--muted);
  margin-left: 2px;
}

/* ============================================================
   Plotly chart embedded inside an annotation card.
   ============================================================ */
.annotation-chart {
  background: var(--map-glass-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-3) var(--space-2);
}
.annotation-chart .chart {
  width: 100%;
  height: 140px;
}

/* ============================================================
   Mobile reflow for the pinned scrollytelling map scene.
   On narrow viewports the rule-of-thirds anchors (14vw inset) push
   380px-wide cards off-screen. Pin annotations to the bottom of the
   sticky frame as a single full-width sheet — the same affordance
   the NYT Graphics team uses for mobile scrollytelling maps.
   ============================================================ */
@media (max-width: 720px) {
  .map-panel,
  .map-panel:last-child {
    /* Shorter dwell on mobile — each callout still hangs for ~0.2 extra
       scroll-screens but the user reaches the next scene faster. */
    height: 115vh;
  }

  .map-panel.is-pos-tl .map-annotation,
  .map-panel.is-pos-tr .map-annotation,
  .map-panel.is-pos-bl .map-annotation,
  .map-panel.is-pos-br .map-annotation,
  .map-panel.is-pos-c  .map-annotation {
    top: auto;
    left: var(--space-3);
    right: var(--space-3);
    bottom: max(var(--space-4), env(safe-area-inset-bottom, 0px));
    transform: none;
    width: auto;
    max-width: none;
  }

  .map-annotation {
    padding: var(--space-4);
    gap: var(--space-3);
    max-height: 62vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  .map-annotation h3 { font-size: var(--text-lg); }
  .map-annotation p  { font-size: var(--text-sm); line-height: 1.55; }

  /* Lead stat shrinks slightly so the card doesn't dominate the viewport. */
  .annotation-lead-value { font-size: 26px; }

  /* Stats grid: 3 columns gets cramped under 320px — wrap to 2 columns. */
  .annotation-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-2); }
  .annotation-stat dd { font-size: var(--text-lg); }

  /* Embedded chart card needs less internal padding. */
  .annotation-chart { padding: var(--space-2) var(--space-2) 0; }
  .annotation-chart .chart { height: 120px; }

  /* Legend repositions to top so it doesn't collide with the bottom card. */
  .map-legend {
    bottom: auto;
    top: calc(var(--space-4) + 80px); /* clear the fixed two-row header */
    left: var(--space-3);
    right: var(--space-3);
    padding: var(--space-2) var(--space-3);
  }
  .map-legend .scale { width: 100%; }
}
