/* CMH Globe: every style js/globe.js needs. All classes are prefixed cmhg-.
   The container keeps its own size and position; the module only adds
   .cmhg-root (plus state classes) and fills it.

   Hooks the page can set on the container:
     --cmhg-canvas-z / --cmhg-labels-z  z-index of the WebGL canvas and of the label layer
                                         (lets a title sit between them, if no ancestor inside
                                         the container creates a stacking context)
     --cmhg-ink, --cmhg-muted, --cmhg-accent, --cmhg-halo, --cmhg-rule  colours */

.cmhg-root {
  --cmhg-ink: #0E0E0E;
  --cmhg-muted: #8C8C8C;
  --cmhg-accent: #FF5C00;
  --cmhg-halo: #FFFFFF;
  --cmhg-rule: #ECE7DE;
  --cmhg-sans: 'Geist', ui-sans-serif, system-ui, -apple-system, 'Helvetica Neue', Arial, sans-serif;
  --cmhg-mono: 'Geist Mono', ui-monospace, 'SFMono-Regular', Menlo, Consolas, monospace;
}

/* ---------- stage (globe.gl lives in here) ---------- */

.cmhg-stage {
  position: absolute;
  inset: 0;
  overflow: hidden;
}

.cmhg-stage canvas {
  display: block;
  position: relative;
  z-index: var(--cmhg-canvas-z, auto);
  outline: none;
  opacity: 0;
  transition: opacity 1.2s cubic-bezier(.2, .6, .2, 1);
  -webkit-tap-highlight-color: transparent;
}

.cmhg-ready .cmhg-stage canvas { opacity: 1; }

.cmhg-labels { z-index: var(--cmhg-labels-z, auto); }

/* globe.gl's hover tooltip and nav hint are never used here */
.cmhg-stage .float-tooltip-kap,
.cmhg-stage .scene-nav-info { display: none !important; }

/* Touch screens: the globe ignores pointers so it never captures the page scroll. */
.cmhg-coarse .cmhg-stage,
.cmhg-coarse .cmhg-stage canvas {
  pointer-events: none !important;
  touch-action: auto !important;
}

/* ---------- city labels ---------- */

/* Root is a zero size anchor on the city; globe.gl moves it every frame. */
.cmhg-label {
  position: absolute;
  left: 0;
  top: 0;
  width: 0;
  height: 0;
  pointer-events: none;
  opacity: 0;
  transition: opacity .3s ease;
  will-change: transform, opacity;
}

.cmhg-ready .cmhg-label:not(.is-hidden) { opacity: 1; }

.cmhg-label__dot {
  position: absolute;
  left: -3px;
  top: -3px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--cmhg-accent);
  box-shadow: 0 0 0 2px var(--cmhg-halo);
}

/* Offset from the anchor is set in JS (transform), per city and per frame need. */
.cmhg-label__text {
  position: absolute;
  left: 0;
  top: 0;
  display: block;
  white-space: nowrap;
  text-align: left;
  transition: transform .45s cubic-bezier(.2, .7, .2, 1);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.cmhg-label.is-left .cmhg-label__text { text-align: right; }

/* Soft white plate hugging the text, so the grey type reads over land dots
   and arcs. The text box has a transform, so z-index -1 stays inside the label. */
.cmhg-label__text::before {
  content: '';
  position: absolute;
  z-index: -1;
  inset: -1px -4px -2px;
  border-radius: 12px;
  background: var(--cmhg-halo);
  opacity: .72;
  filter: blur(5px);
}

.cmhg-label__city,
.cmhg-label__meta {
  display: block;
  /* plus a white halo: solid for the first 2px around each glyph, then a soft glow */
  text-shadow:
    0 0 1px var(--cmhg-halo),
    0 0 2px var(--cmhg-halo),
    0 0 2px var(--cmhg-halo),
    0 0 3px var(--cmhg-halo),
    0 0 4px var(--cmhg-halo),
    0 0 6px var(--cmhg-halo),
    0 0 9px var(--cmhg-halo);
}

.cmhg-label__city {
  font-family: var(--cmhg-sans);
  font-weight: 500;
  font-size: 15px;
  line-height: 18px;
  letter-spacing: -0.005em;
  color: var(--cmhg-ink);
}

.cmhg-label__meta {
  margin-top: 3px;
  font-family: var(--cmhg-mono);
  font-weight: 400;
  font-size: 10.5px;
  line-height: 13px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--cmhg-muted);
  font-variant-numeric: tabular-nums;
}

.cmhg-narrow .cmhg-label__city { font-size: 13px; line-height: 16px; }
.cmhg-narrow .cmhg-label__meta { margin-top: 2px; font-size: 9.5px; line-height: 12px; }

/* On a small globe the plate would erase too much land: tight 2px halo only. */
.cmhg-narrow .cmhg-label__text::before { display: none; }
.cmhg-narrow .cmhg-label__city,
.cmhg-narrow .cmhg-label__meta {
  text-shadow:
    0 0 1px var(--cmhg-halo),
    0 0 1px var(--cmhg-halo),
    0 0 2px var(--cmhg-halo),
    0 0 2px var(--cmhg-halo),
    0 0 3px var(--cmhg-halo);
}

/* Entrance: labels rise in one after another once the globe has faded in.
   Uses the separate `translate` property so it never fights the JS transform. */
.cmhg-ready .cmhg-label__text,
.cmhg-ready .cmhg-label__dot {
  animation: cmhg-rise .8s cubic-bezier(.2, .7, .2, 1) both;
  animation-delay: calc(.55s + var(--cmhg-i, 0) * 90ms);
}

.cmhg-ready .cmhg-label__dot { animation-name: cmhg-pop; }

@keyframes cmhg-rise {
  from { opacity: 0; translate: 0 6px; }
  to { opacity: 1; translate: 0 0; }
}

@keyframes cmhg-pop {
  from { opacity: 0; scale: .2; }
  to { opacity: 1; scale: 1; }
}

/* ---------- screen reader list (always present while the globe shows) ---------- */

.cmhg-sr,
.cmhg-vh {
  position: absolute !important;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
  list-style: none;
}

/* ---------- fallback: no WebGL, or the build failed ---------- */

.cmhg-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

/* Centred in the container by default; a page with a title over the globe can
   move the list below it with --cmhg-fallback-top (e.g. 260px or 55%). */
.cmhg-fallback .cmhg-list {
  position: absolute;
  top: var(--cmhg-fallback-top, 0);
  right: 0;
  bottom: var(--cmhg-fallback-bottom, 0);
  left: 0;
  z-index: var(--cmhg-labels-z, auto);
  width: min(560px, calc(100% - 32px));
  height: -webkit-fit-content;
  height: fit-content;
  max-height: calc(100% - 32px);
  margin: auto;
  overflow: auto;
}

.cmhg-list__item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 15px 2px;
  border-top: 1px solid var(--cmhg-rule);
}

.cmhg-list__item:last-child { border-bottom: 1px solid var(--cmhg-rule); }

.cmhg-list__dot {
  flex: none;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--cmhg-accent);
}

.cmhg-list__city {
  flex: 1 1 auto;
  min-width: 0;
  font-family: var(--cmhg-sans);
  font-weight: 500;
  font-size: 18px;
  line-height: 1.2;
  letter-spacing: -0.01em;
  color: var(--cmhg-ink);
}

.cmhg-list__meta {
  flex: none;
  font-family: var(--cmhg-mono);
  font-weight: 400;
  font-size: 11px;
  line-height: 1.3;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--cmhg-muted);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.cmhg-list__time { color: var(--cmhg-ink); }

@media (max-width: 420px) {
  .cmhg-list__item { gap: 10px; padding: 13px 0; }
  .cmhg-list__city { font-size: 16px; }
  .cmhg-list__meta { font-size: 10px; letter-spacing: 0.1em; }
}

/* ---------- reduced motion ---------- */

/* Static mode (?static=1 or { static: true }): no entrance and no transitions,
   so screenshots are identical run to run. */
.cmhg-static .cmhg-stage canvas,
.cmhg-static .cmhg-label,
.cmhg-static .cmhg-label__text { transition: none !important; }
.cmhg-static.cmhg-ready .cmhg-label__text,
.cmhg-static.cmhg-ready .cmhg-label__dot { animation: none !important; }

/* Fades stay (they are not motion); the sliding label offsets and the rise-in go. */
@media (prefers-reduced-motion: reduce) {
  .cmhg-label__text { transition: none !important; }
  .cmhg-ready .cmhg-label__text,
  .cmhg-ready .cmhg-label__dot { animation: none !important; }
}
