/* ============================================================
   GLOBE — Countries section augmentation
   Owns: globe stage, HUD, legend, custom tooltip, chip extras,
         globe-tweaks divider in the existing tweaks panel.
   Reuses every token already defined in css/hearth.css.
   ============================================================ */

/* ─── Section bloom layered over .h-countries when the globe is on ─── */
.h-countries.has-globe {
  background:
    radial-gradient(ellipse 60% 90% at 50% 40%, rgba(232, 101, 26, 0.07) 0%, transparent 60%),
    var(--h-bg-2);
  padding-top: 90px;
  padding-bottom: 120px;
  overflow: hidden;
}
.h-countries.has-globe .h-section-intro {
  color: var(--cream-2);
  max-width: 56ch;
  margin: 14px auto 0;
  font-size: 0.98rem;
  text-align: center;
  line-height: 1.65;
}

/* ─── Wrapper: holds stage + HUD together so HUD can overlay on desktop
       and flow below the stage on mobile ─── */
.h-globe-wrap {
  position: relative;
  max-width: 1180px;
  margin: 36px auto 28px;
}

/* ─── Stage ─── */
.h-globe-stage {
  position: relative;
  aspect-ratio: 16 / 11;
  border-radius: var(--r-xl);
  overflow: hidden;
  background:
    radial-gradient(ellipse 55% 55% at 50% 55%, #1a0d04 0%, #0a0502 60%, var(--h-bg) 100%);
  isolation: isolate;
}
.h-globe-stage::before {
  content: "";
  position: absolute; inset: 0;
  background:
    linear-gradient(rgba(232, 101, 26, 0.04) 1px, transparent 1px) 0 0 / 120px 120px,
    linear-gradient(90deg, rgba(232, 101, 26, 0.04) 1px, transparent 1px) 0 0 / 120px 120px;
  -webkit-mask-image: radial-gradient(ellipse 70% 70% at 50% 50%, #000 30%, transparent 80%);
          mask-image: radial-gradient(ellipse 70% 70% at 50% 50%, #000 30%, transparent 80%);
  pointer-events: none;
}

/* Corner crosshairs (instrumented vibe) */
.h-stage-corner {
  position: absolute;
  width: 18px; height: 18px;
  border: 1px solid rgba(232, 101, 26, 0.4);
  pointer-events: none;
  z-index: 4;
}
.h-stage-corner.tl { top: 18px; left: 18px;   border-right: none; border-bottom: none; }
.h-stage-corner.tr { top: 18px; right: 18px;  border-left:  none; border-bottom: none; }
.h-stage-corner.bl { bottom: 18px; left: 18px;  border-right: none; border-top: none; }
.h-stage-corner.br { bottom: 18px; right: 18px; border-left:  none; border-top: none; }

/* Stage labels */
.h-stage-label {
  position: absolute;
  font-family: var(--font-mono);
  font-size: 0.62rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--muted);
  pointer-events: none;
  z-index: 5;
}
.h-stage-label.tl { top: 28px; left: 48px; }
.h-stage-label.tr { top: 28px; right: 48px; color: var(--ember); }
.h-stage-label.tr .h-stage-dot {
  display: inline-block;
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--ember);
  margin-right: 8px;
  box-shadow: 0 0 8px var(--ember-glow);
  animation: hGlobeBlink 1.6s ease-in-out infinite;
}
@keyframes hGlobeBlink {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.25; }
}

/* Globe mount */
#hGlobe { position: absolute; inset: 0; }
/* Hide the default Globe.gl tooltip — we render our own */
.h-globe-stage .scene-tooltip { display: none !important; }

/* ─── City labels (htmlElementsData DOM overlay) ─── */
/* .outer is 0-sized; CSS2DRenderer centers it on the 3D point.
   .h-city-label is absolutely positioned inside it, growing left
   (San Diego / Santa Clara, right-edge cities) or right (Barnaul). */
.h-city-label {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  white-space: nowrap;
  color: rgba(255, 241, 194, 0.92);   /* visitedStroke amber — set dynamically too */
  font-family: var(--font-mono);
  font-size: 0.60rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  pointer-events: none;
  text-shadow: 0 1px 5px rgba(0, 0, 0, 0.85), 0 0 10px rgba(0, 0, 0, 0.6);
  user-select: none;
}

/* ─── Custom tooltip ─── */
.h-globe-tooltip {
  position: absolute;
  pointer-events: none;
  background: rgba(13, 8, 4, 0.92);
  border: 1px solid rgba(232, 101, 26, 0.35);
  border-radius: 10px;
  padding: 10px 14px;
  color: var(--cream);
  font-size: 0.84rem;
  line-height: 1.4;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(255, 255, 255, 0.03) inset;
  opacity: 0;
  transform: translate(-50%, -120%);
  transition: opacity 0.16s ease;
  z-index: 6;
  white-space: nowrap;
  font-family: var(--font-body);
}
.h-globe-tooltip.is-visible { opacity: 1; }
.h-globe-tooltip-flag {
  display: inline-block;
  width: 18px;
  margin-right: 8px;
  transform: translateY(2px);
  border-radius: 2px;
  overflow: hidden;
}
.h-globe-tooltip-name {
  font-family: var(--font-display);
  font-size: 1.05rem;
  color: var(--cream);
}
.h-globe-tooltip-meta {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: var(--gold);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  margin-top: 2px;
}
.h-globe-tooltip-meta .sep { opacity: 0.4; margin: 0 6px; }

/* ─── Flight HUD ───
   Desktop: absolutely positioned over the stage (wrapper is the ref).
   Mobile: static block flowing below the stage. ─── */
.h-flight-hud {
  position: absolute;
  top: 56px; left: 48px;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: var(--cream-2);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  z-index: 5;
  pointer-events: none;
  background: rgba(13, 8, 4, 0.55);
  border: 1px solid rgba(255, 180, 100, 0.16);
  border-radius: 10px;
  padding: 14px 16px 12px;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  min-width: 188px;
}
.h-flight-hud-title {
  color: var(--ember);
  font-size: 0.6rem;
  letter-spacing: 0.32em;
  margin-bottom: 10px;
}
.h-flight-leg {
  display: flex; align-items: center; gap: 8px;
  margin-bottom: 4px;
  opacity: 0.5;
  transition: opacity 0.4s ease, color 0.4s ease;
}
.h-flight-leg.is-active { opacity: 1; color: var(--gold); }
.h-flight-leg.is-done   { opacity: 0.85; color: var(--cream); }
.h-flight-leg-dot {
  display: inline-block;
  width: 7px; height: 7px;
  border-radius: 50%;
  background: currentColor;
  box-shadow: 0 0 8px currentColor;
}
.h-flight-leg-name {
  letter-spacing: 0.16em;
  font-size: 0.7rem;
}
.h-flight-leg-coord {
  font-size: 0.58rem;
  color: var(--muted);
  letter-spacing: 0.1em;
  margin-left: 16px;
}
.h-flight-arrow {
  margin-left: 14px;
  color: rgba(255, 180, 100, 0.25);
  font-size: 0.7rem;
  line-height: 1;
}

/* ─── Legend ─── */
.h-globe-legend {
  position: absolute;
  right: 30px; bottom: 30px;
  background: rgba(13, 8, 4, 0.55);
  border: 1px solid rgba(255, 180, 100, 0.14);
  border-radius: 10px;
  padding: 12px 14px;
  font-family: var(--font-mono);
  font-size: 0.62rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--cream-2);
  z-index: 5;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
.h-globe-legend-row { display: flex; align-items: center; gap: 10px; padding: 4px 0; }
.h-globe-legend-swatch {
  width: 14px; height: 6px; border-radius: 2px;
}
.h-globe-legend-swatch.is-visited {
  background: var(--gold);
  box-shadow: 0 0 10px var(--gold-glow);
}
.h-globe-legend-swatch.is-atlas {
  background: rgba(255, 200, 130, 0.14);
}
.h-globe-legend-swatch.is-arc {
  background: linear-gradient(90deg, transparent, var(--gold-2), transparent);
  height: 2px;
}

/* ─── Chip strip augmentation ───
   Keeps the existing .h-chip pattern; adds .h-chip-yr (year stamp)
   and .is-hover state that mirrors :hover so chip↔globe sync works. */
.h-countries.has-globe .h-chips {
  max-width: 1180px;
  margin: 8px auto 0;
  padding: 0 16px;
}
.h-chip[data-iso] {
  padding: 9px 16px 9px 12px;
  cursor: pointer;
  transition: border-color 0.2s ease, background 0.2s ease,
              box-shadow 0.2s ease, transform 0.2s ease, color 0.2s ease;
}
.h-chip[data-iso] .h-chip-yr {
  font-family: var(--font-mono);
  font-size: 0.66rem;
  color: var(--muted);
  letter-spacing: 0.1em;
  margin-left: 4px;
}
.h-chip.is-hover {
  border-color: var(--ember);
  color: var(--cream);
  background: var(--ember-dim);
  box-shadow: 0 0 16px var(--ember-dim);
  transform: translateY(-2px);
}
.h-chip.is-active {
  border-color: var(--gold);
  color: var(--cream);
  background: rgba(240, 180, 41, 0.12);
  box-shadow: 0 0 0 2px var(--gold), 0 0 20px var(--gold-glow);
  transform: translateY(-2px);
}

/* ─── WebGL fallback card ─── */
.h-globe-fallback {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 14px;
  padding: 24px;
  text-align: center;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--cream-2);
  letter-spacing: 0.18em;
  text-transform: uppercase;
}
.h-globe-fallback svg { opacity: 0.7; }
.h-globe-fallback-note {
  color: var(--muted);
  font-family: var(--font-body);
  font-size: 0.72rem;
  letter-spacing: 0.04em;
  max-width: 38ch;
  line-height: 1.6;
  text-transform: none;
}
.h-globe-fallback-btn {
  margin-top: 6px;
  padding: 10px 22px;
  background: var(--ember);
  color: var(--cream);
  border: none;
  border-radius: 100px;
  font-family: var(--font-body);
  font-size: 0.78rem;
  letter-spacing: 0.08em;
  cursor: pointer;
  box-shadow: 0 4px 24px var(--ember-glow);
  transition: background 0.22s ease, transform 0.2s ease;
}
.h-globe-fallback-btn:hover { background: var(--ember-2); transform: translateY(-1px); }

/* ─── Tweaks panel: divider before the globe rows + max-height guard ─── */
.h-tweaks-panel { max-height: calc(100dvh - 110px); overflow-y: auto; }
.h-tweak-divider {
  margin: 18px 0 12px;
  padding-top: 14px;
  border-top: 1px solid var(--h-line);
  font-family: var(--font-mono);
  font-size: 0.66rem;
  letter-spacing: 0.28em;
  text-transform: uppercase;
  color: var(--ember);
}

/* ─── Responsive ─── */
@media (max-width: 820px) {
  .h-countries.has-globe { padding-top: 60px; padding-bottom: 90px; }
  .h-globe-wrap { margin: 24px auto; }
  .h-globe-stage { aspect-ratio: 4 / 5; border-radius: var(--r-lg); }
  .h-stage-label, .h-stage-corner { display: none; }

  /* HUD flows below the stage instead of overlapping it */
  .h-flight-hud {
    position: static;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0 16px;
    margin: 10px 4px 0;
    padding: 10px 14px;
    min-width: 0;
    font-size: 0.6rem;
    border-radius: var(--r-lg);
  }
  .h-flight-hud-title { margin-bottom: 0; margin-right: auto; }
  .h-flight-arrow { display: none; }
  .h-flight-leg { margin-bottom: 0; }
  .h-flight-leg-coord { display: none; }

  .h-globe-legend {
    right: 14px; bottom: 14px;
    padding: 8px 10px;
    font-size: 0.55rem;
  }
}
@media (max-width: 480px) {
  .h-globe-legend-row:not(:first-child) { display: none; }
}


/* ═══════════════════════════════════════════════════════════════════
   CITY LABEL SUB-ELEMENTS
   All city labels (Barnaul, San Diego, Santa Clara) now share a
   text + coord two-line structure inside .h-city-label.
   ═══════════════════════════════════════════════════════════════════ */
.h-city-label-text {
  display: block;
}
.h-city-label-coord {
  display: block;
  font-size: 0.52rem;
  color: var(--gold);
  letter-spacing: 0.10em;
  margin-top: 2px;
  opacity: 0.85;
}

/* ─── Hidden until cue ─── */
.h-city-label.is-hidden { display: none; }


/* ═══════════════════════════════════════════════════════════════════
   SAN DIEGO — dimmed by default; .is-restored flips back to settled.
   Default state is ~74% scale so Santa Clara's spotlight reads larger.
   ═══════════════════════════════════════════════════════════════════ */
.h-city-label[data-key="san_diego"] .h-city-label-text {
  transform: scale(0.74);
  transform-origin: right center;
  color: rgba(244, 237, 224, 0.42);
  transition: transform 0.9s cubic-bezier(.2,.7,.2,1), color 0.9s ease;
}
.h-city-label[data-key="san_diego"] .h-city-label-coord {
  transform: scale(0.74);
  transform-origin: right center;
  opacity: 0.35;
  color: rgba(240, 180, 41, 0.55);
  transition: transform 0.9s cubic-bezier(.2,.7,.2,1),
              opacity 0.9s ease,
              color 0.9s ease;
}
.h-city-label[data-key="san_diego"].is-restored .h-city-label-text {
  transform: scale(1);
  color: var(--cream);
}
.h-city-label[data-key="san_diego"].is-restored .h-city-label-coord {
  transform: scale(1);
  opacity: 0.85;
  color: var(--gold);
}


/* ═══════════════════════════════════════════════════════════════════
   SANTA CLARA — spotlight + settled transitions.
   Transitions on the base selector so removing .is-spotlight
   animates back smoothly over 900ms.
   ═══════════════════════════════════════════════════════════════════ */
.h-city-label[data-key="santa_clara"] .h-city-label-text,
.h-city-label[data-key="santa_clara"] .h-city-label-coord {
  transition: transform 0.9s cubic-bezier(.2,.7,.2,1),
              color 0.9s ease,
              filter 0.9s ease,
              opacity 0.9s ease;
}

/* Santa Clara spotlight — active during the 1 s hold after reveal */
.h-city-label[data-key="santa_clara"].is-spotlight .h-city-label-text {
  transform: scale(1.62);
  filter: drop-shadow(0 0 14px var(--ember-glow))
          drop-shadow(0 0 28px var(--gold-glow));
}
.h-city-label[data-key="santa_clara"].is-spotlight .h-city-label-coord {
  transform: scale(1.15);
  color: var(--ember-2);
  opacity: 1;
}


/* ═══════════════════════════════════════════════════════════════════
   CONSTELLATION FX
   Default: all SC label content is hidden (display:none).
   .is-revealing on the label makes everything visible and starts
   the CSS animations. Removing .is-revealing re-hides everything,
   which also resets animations — the reflow trick in JS ensures they
   restart cleanly on replay.
   ═══════════════════════════════════════════════════════════════════ */

/* Hide all SC label content until .is-revealing is added */
.h-city-label[data-key="santa_clara"] .h-city-label-text,
.h-city-label[data-key="santa_clara"] .h-city-label-coord,
.h-city-label[data-key="santa_clara"] .h-city-fx-star,
.h-city-label[data-key="santa_clara"] .h-city-fx-thread,
.h-city-label[data-key="santa_clara"] .h-city-fx-flash { display: none; }

/* Show everything once the reveal starts */
.h-city-label[data-key="santa_clara"].is-revealing .h-city-label-text,
.h-city-label[data-key="santa_clara"].is-revealing .h-city-label-coord,
.h-city-label[data-key="santa_clara"].is-revealing .h-city-fx > * { display: block; }

/* FX container — zero-size, positioned at the label anchor point */
.h-city-fx {
  position: absolute;
  left: 0; top: 0;
  width: 0; height: 0;
  pointer-events: none;
}
/* For right-anchored labels (Santa Clara) the FX origin must sit on the
   city dot, which is 4 px to the right of the label's right edge. */
.h-city-label[data-key="santa_clara"] .h-city-fx {
  left: auto;
  right: -4px;  /* city dot is 4 px right of the label's right edge */
  top: 50%;
  transform: translateY(-50%);
}

/* ─── Stars ─── */
.h-city-fx-star {
  position: absolute;
  width: 6px; height: 6px;
  margin: -3px 0 0 -3px;
  border-radius: 50%;
  background: radial-gradient(circle, #fff 0%, var(--gold-2) 50%, transparent 100%);
  box-shadow: 0 0 14px var(--gold-2), 0 0 28px var(--gold-glow);
  opacity: 0;
}
.h-city-fx-star.s1 {
  left: -50px; top: -34px;
  animation: cons-star-s1 1700ms cubic-bezier(.4,0,.2,1) forwards;
}
.h-city-fx-star.s2 {
  left: 48px; top: -42px;
  animation: cons-star-s2 1700ms cubic-bezier(.4,0,.2,1) forwards;
}
.h-city-fx-star.s3 {
  left: -8px; top: 42px;
  animation: cons-star-s3 1700ms cubic-bezier(.4,0,.2,1) forwards;
}

/* Stars travel toward the pin then fade — translate vectors are the
   negatives of each star's offset so they converge on the anchor */
@keyframes cons-star-s1 {
  0%   { opacity: 0; transform: scale(.3); }
  20%  { opacity: 1; transform: scale(1); }
  75%  { opacity: 1; transform: translate(50px, 34px) scale(.9); }
  100% { opacity: 0; transform: translate(50px, 34px) scale(.3); }
}
@keyframes cons-star-s2 {
  0%   { opacity: 0; transform: scale(.3); }
  20%  { opacity: 1; transform: scale(1); }
  75%  { opacity: 1; transform: translate(-48px, 42px) scale(.9); }
  100% { opacity: 0; transform: translate(-48px, 42px) scale(.3); }
}
@keyframes cons-star-s3 {
  0%   { opacity: 0; transform: scale(.3); }
  20%  { opacity: 1; transform: scale(1); }
  75%  { opacity: 1; transform: translate(8px, -42px) scale(.9); }
  100% { opacity: 0; transform: translate(8px, -42px) scale(.3); }
}

/* ─── Threads ─── */
.h-city-fx-thread {
  position: absolute;
  left: 0; top: 0;
  height: 1px;
  background: linear-gradient(90deg,
    transparent,
    var(--gold) 30%,
    var(--gold-2) 50%,
    var(--gold) 70%,
    transparent);
  transform-origin: left center;
  opacity: 0;
}
.h-city-fx-thread.t1 {
  width: 60px;
  animation: cons-thread-t1 1100ms ease-out 500ms forwards;
}
.h-city-fx-thread.t2 {
  width: 64px;
  animation: cons-thread-t2 1100ms ease-out 600ms forwards;
}
.h-city-fx-thread.t3 {
  width: 43px;
  animation: cons-thread-t3 1100ms ease-out 700ms forwards;
}

@keyframes cons-thread-t1 {
  0%   { opacity: 0; transform: rotate(214deg) scaleX(0); }
  35%  { opacity: 1; transform: rotate(214deg) scaleX(1); }
  80%  { opacity: 0.9; transform: rotate(214deg) scaleX(1); }
  100% { opacity: 0; transform: rotate(214deg) scaleX(1); }
}
@keyframes cons-thread-t2 {
  0%   { opacity: 0; transform: rotate(-41deg) scaleX(0); }
  35%  { opacity: 1; transform: rotate(-41deg) scaleX(1); }
  80%  { opacity: 0.9; transform: rotate(-41deg) scaleX(1); }
  100% { opacity: 0; transform: rotate(-41deg) scaleX(1); }
}
@keyframes cons-thread-t3 {
  0%   { opacity: 0; transform: rotate(101deg) scaleX(0); }
  35%  { opacity: 1; transform: rotate(101deg) scaleX(1); }
  80%  { opacity: 0.9; transform: rotate(101deg) scaleX(1); }
  100% { opacity: 0; transform: rotate(101deg) scaleX(1); }
}

/* ─── Flash burst ─── */
.h-city-fx-flash {
  position: absolute;
  left: -3px; top: -3px;
  width: 6px; height: 6px;
  border-radius: 50%;
  background: radial-gradient(circle,
    #fff 0%,
    var(--gold-2) 30%,
    var(--ember-2) 60%,
    transparent 100%);
  box-shadow: 0 0 36px var(--gold-2), 0 0 70px var(--ember-glow);
  opacity: 0;
  animation: cons-flash 900ms cubic-bezier(.2,.7,.2,1) 1600ms forwards;
}

@keyframes cons-flash {
  0%   { opacity: 0; transform: scale(.3); }
  35%  { opacity: 1; transform: scale(10); }
  100% { opacity: 0; transform: scale(2); }
}

/* ─── Label type-in — starts at 1800ms ─── */
.h-city-label[data-key="santa_clara"].is-revealing .h-city-label-text {
  opacity: 0;
  animation: cons-label 1200ms cubic-bezier(.2,.7,.2,1) 1800ms forwards;
}

@keyframes cons-label {
  0% {
    opacity: 0;
    clip-path: inset(0 100% 0 0);
    letter-spacing: 0.35em;
    color: var(--gold-2);
    text-shadow: 0 0 22px var(--gold), 0 0 44px var(--ember-glow);
  }
  60% { opacity: 1; }
  100% {
    opacity: 1;
    clip-path: inset(0 0% 0 0);
    letter-spacing: 0.005em;
    color: var(--cream);
    text-shadow: 0 0 12px rgba(0,0,0,.7), 0 1px 2px rgba(0,0,0,.6);
  }
}

/* ─── Coord fade-in — starts at 2500ms ─── */
.h-city-label[data-key="santa_clara"].is-revealing .h-city-label-coord {
  opacity: 0;
  animation: gl-fade-in 700ms ease 2500ms forwards;
}

@keyframes gl-fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}


/* ═══════════════════════════════════════════════════════════════════
   FLIGHT HUD — Santa Clara leg (fades in at t≈600ms during reveal)
   ═══════════════════════════════════════════════════════════════════ */
.h-flight-leg.is-home,
.h-flight-arrow.is-home {
  opacity: 0;
  color: var(--ember-2);
  transition: opacity 0.6s ease;
}
.h-flight-leg.is-home.shown,
.h-flight-arrow.is-home.shown { opacity: 0.95; }


/* ═══════════════════════════════════════════════════════════════════
   REDUCED MOTION overrides
   ═══════════════════════════════════════════════════════════════════ */
@media (prefers-reduced-motion: reduce) {
  .h-stage-label.tr .h-stage-dot { animation: none; }
  .h-flight-leg, .h-globe-tooltip { transition: none; }

  /* Collapse all Santa Clara constellation animations to 220ms */
  .h-city-label[data-key="santa_clara"].is-revealing * {
    animation-duration: 220ms !important;
    animation-delay: 0ms !important;
  }
  /* Remove transitions on city label state changes */
  .h-city-label[data-key="san