@import './tokens.css';

/* ── Trail map immersive — pinned full-bleed slow zoom ─────────────────
 * Opt-in cinematic reveal. Pair with js/cs-trail-map.js. The page must
 * include both this stylesheet and the script — main.js does NOT
 * auto-wire it.
 *
 * Mechanic: the section is full-bleed (100vw, breaks out of the text
 * band). The .cs-trail-map-pin stage is absolute by default, fixed
 * while .cs-trail-map.is-pinned, absolute-bottom while
 * .cs-trail-map.is-past — JS toggles those classes via
 * getBoundingClientRect. As scroll progresses through the pin range,
 * JS writes an eased 0–1 into --descent. CSS consumes it to drive a
 * gentle scale, a slight saturation/brightness lift, and a staggered
 * caption resolve. */

.cs-trail-map {
  position: relative;
  /* Break out of the text band to true viewport width. */
  left: 50%;
  margin-left: -50vw;
  width: 100vw;
  /* Scroll runway: ~2× viewport gives a calm pinned beat without
   * stranding the reader. */
  height: 220vh;
  margin-top: var(--space-12);
  margin-bottom: var(--space-12);
  background: var(--color-surface-page);
  --descent: 0;
}

.cs-trail-map-pin {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 100vh;
  overflow: hidden;
  background: var(--color-surface-inverse);
}

.cs-trail-map.is-pinned .cs-trail-map-pin {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  width: 100%;
}

.cs-trail-map.is-past .cs-trail-map-pin {
  position: absolute;
  top: auto;
  bottom: 0;
}

.cs-trail-map-stage {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

/* The track holds the image and gets the scroll-driven transform.
 * Scale from 1.00 → 1.12 across the pin — subtle, just enough to feel
 * like the camera is leaning in. */
.cs-trail-map-track {
  position: absolute;
  inset: 0;
  transform: scale(calc(1 + var(--descent) * 0.12));
  transform-origin: 50% 55%;
  filter:
    brightness(calc(0.92 + var(--descent) * 0.08))
    saturate(calc(0.95 + var(--descent) * 0.10));
  will-change: transform, filter;
}

.cs-trail-map-img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
}

/* Overlay — scrim + caption stack. Comes in during the first third of
 * the pinned scroll and stays on. */
.cs-trail-map-overlay {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 2;
  padding: var(--space-8) var(--space-12);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  color: var(--color-text-on-image);
  background: linear-gradient(
    to top,
    rgba(0, 0, 0, 0.55) 0%,
    rgba(0, 0, 0, 0.30) 45%,
    rgba(0, 0, 0, 0)    100%
  );
  pointer-events: none;
  opacity: clamp(0, calc((var(--descent) - 0.10) / 0.15), 1);
}

.cs-trail-map-overlay .cs-trail-map-eyebrow,
.cs-trail-map-overlay .cs-trail-map-label {
  color: var(--color-text-on-image);
}

.cs-trail-map-eyebrow {
  --in: clamp(0, calc((var(--descent) - 0.15) / 0.10), 1);
  font-size: var(--font-size-caption);
  line-height: var(--line-height-caption);
  letter-spacing: var(--letter-spacing-caption);
  font-weight: var(--font-light);
  margin: 0;
  opacity: calc(var(--in) * 0.75);
  transform: translateY(calc((1 - var(--in)) * 8px));
}

.cs-trail-map-label {
  --in: clamp(0, calc((var(--descent) - 0.20) / 0.12), 1);
  font-size: var(--font-size-display-m);
  line-height: var(--line-height-display-m);
  letter-spacing: var(--letter-spacing-display-m);
  font-weight: var(--font-book);
  margin: 0;
  max-width: 720px;
  opacity: var(--in);
  transform: translateY(calc((1 - var(--in)) * 14px));
  font-variant-numeric: tabular-nums;
}

@media (max-width: 1024px) {
  .cs-trail-map {
    height: 200vh;
  }

  .cs-trail-map-overlay {
    padding: var(--space-6) var(--space-8);
  }
}

@media (max-width: 640px) {
  .cs-trail-map {
    height: 180vh;
    margin-top: var(--space-8);
    margin-bottom: var(--space-8);
  }

  .cs-trail-map-overlay {
    padding: var(--space-5) var(--space-6);
  }

  .cs-trail-map-label {
    font-size: var(--font-size-h1);
    line-height: var(--line-height-h1);
    letter-spacing: var(--letter-spacing-h1);
    font-weight: var(--font-semi-bold);
  }
}

@media (prefers-reduced-motion: reduce) {
  .cs-trail-map {
    height: 100vh;
  }

  .cs-trail-map-track {
    transform: none;
    filter: none;
  }

  .cs-trail-map-overlay,
  .cs-trail-map-eyebrow,
  .cs-trail-map-label {
    opacity: 1;
    transform: none;
  }
}
