/*
 * Light from the surface, driven by the same --launch-depth as the countdown.
 *
 * --launch-depth is the shared "how deep" value (log of days remaining,
 * 0 = launch day, 1 = 730+ days out). The sea behind the page used to keep a
 * single dark tone regardless of it; this layer lets daylight reach the page
 * as the launch gets closer, and the light changes character on the way up.
 *
 *   - More than a year out: nothing changes (the original deep tone).
 *   - Inside the final year: the water turns from navy toward teal and the
 *     first thin shafts of light reach down from the surface.
 *   - ~100 days: a second set of shafts; they keep getting longer and stronger.
 *   - ~50 days: dawn gold starts to mix into the surface and the shafts.
 *   - ~2 weeks: a third set of shafts.
 *   - Launch day: full surface light.
 *
 * .8955 is --launch-depth at 365 days (log10(366) / log10(731)).
 * Preview any day with ?depth=days:N (e.g. days:400, days:100, days:7).
 */

:root {
  --launch-light-year: .8955;
  /* 0 beyond a year, 1 inside it. The ×1000 makes the clamp a hard step. */
  --launch-light-step: clamp(0, (var(--launch-light-year) - var(--launch-depth, 1)) * 1000, 1);
  /* How far up from the one-year depth toward the surface (0..1).
     ≈.02 today (335 days), .22 at 100, .42 at 30, .65 at 7, 1 on launch day. */
  --launch-light-rise: clamp(0, (var(--launch-light-year) - var(--launch-depth, 1)) / var(--launch-light-year), 1);
  /* Overall light: .42 on entering the last year, 1 on launch day. */
  --launch-light: calc(var(--launch-light-step) * (.42 + .58 * var(--launch-light-rise)));
  /* Dawn: 0 until ~50 days out, then up to 1 on launch day. */
  --launch-light-dawn: clamp(0, (var(--launch-light-rise) - .3) / .7, 1);
  /* Colour: how many hues the sea and the panels carry. A trace on entering
     the last year, full on launch day. */
  --launch-light-color: calc(var(--launch-light-step) * (.14 + .86 * var(--launch-light-rise)));

  /* Panel surface: deep navy → teal glass (the Speculation DIVE surface). */
  --launch-panel: color-mix(in oklab, rgb(13 23 29), rgb(20 66 82) calc(var(--launch-light-color) * 100%));

  /* Water tint: navy-blue → teal. A fifth of the way on entering the last
     year, so the change is visible from the first day. */
  --launch-light-water: color-mix(in oklab, rgb(84 156 206), rgb(70 204 196) calc((.2 + var(--launch-light-rise) * .8) * 100%));
  /* Shaft colour: pale cyan → warm dawn gold. */
  --launch-light-ray: color-mix(in oklab, rgb(176 228 246), rgb(255 214 150) calc(var(--launch-light-dawn) * 85%));
}

.launch-surface-light {
  position: fixed;
  /* Above the ocean canvases (z-index 1), which would otherwise cover it. */
  z-index: 2;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  opacity: var(--launch-light-step);
  transition: opacity 1.6s ease-out;
}

/* The water itself: a tint that is strongest under the surface. */
.launch-surface-light::before {
  position: absolute;
  inset: 0;
  content: "";
  background:
    radial-gradient(ellipse 72% 50% at 50% -6%, color-mix(in srgb, var(--launch-light-water) 34%, transparent), transparent 72%),
    linear-gradient(180deg,
      color-mix(in srgb, var(--launch-light-water) 24%, transparent) 0,
      color-mix(in srgb, var(--launch-light-water) 10%, transparent) 48%,
      transparent 100%);
  opacity: calc(.55 + var(--launch-light-rise) * .45);
}

/* Dawn at the surface: only once the launch is close. */
.launch-surface-light::after {
  position: absolute;
  inset: 0;
  content: "";
  background:
    radial-gradient(ellipse 64% 40% at 50% -4%, rgba(255, 204, 136, .62), transparent 72%),
    linear-gradient(180deg, rgba(255, 186, 116, .24), transparent 42%);
  mix-blend-mode: screen;
  opacity: var(--launch-light-dawn);
}

/*
 * More colours in the water as the surface nears: violet, sea green, amber
 * and rose pools around the edges, all in the light that reaches down.
 */
.launch-hue {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse 46% 52% at 8% 92%, rgba(150, 104, 246, .38), transparent 70%),
    radial-gradient(ellipse 42% 48% at 94% 62%, rgba(48, 228, 180, .32), transparent 70%),
    radial-gradient(ellipse 38% 30% at 82% 4%, rgba(255, 168, 88, .3), transparent 72%),
    radial-gradient(ellipse 50% 34% at 44% 104%, rgba(240, 104, 176, .24), transparent 70%),
    radial-gradient(ellipse 34% 40% at 22% 18%, rgba(76, 204, 244, .24), transparent 72%);
  mix-blend-mode: screen;
  opacity: var(--launch-light-color);
}

/*
 * Shafts. The sun is far away, so underwater shafts run almost parallel and
 * slant a little the same way, not fanning out from one point. Each set is
 * two stripe patterns at slightly different angles and odd periods; where
 * they overlap the shafts come out uneven in width and spacing.
 *
 * Two sets, each joining at its own point of the rise, so the count grows
 * with the days. Length follows the rise through the mask; strength follows
 * the rise through opacity.
 *
 * Performance: these are full-viewport layers that drift every frame under a
 * mask and a screen blend. A per-frame filter: blur() on top of that was the
 * heaviest part of the page, so the softness now lives in the gradient ramps
 * (wider fall-off) instead, and the finer third set (r2) is retired.
 */
.launch-ray {
  --ray-from: 0;
  --ray-angle: 101deg;
  --ray-color: color-mix(in srgb, var(--launch-light-ray) 34%, transparent);
  --ray-reach: calc(48% + var(--launch-light-rise) * 50%);
  --ray-strength: calc(.5 + var(--launch-light-rise) * .3);
  position: absolute;
  left: -20%;
  right: -20%;
  top: -8%;
  height: 116%;
  transform-origin: 50% 0;
  background:
    repeating-linear-gradient(var(--ray-angle),
      transparent 0,
      var(--ray-color) var(--ray-a-core, 16px),
      transparent var(--ray-a-width, 40px),
      transparent var(--ray-a-period, 157px)),
    repeating-linear-gradient(calc(var(--ray-angle) + 2.5deg),
      transparent 0,
      var(--ray-color) var(--ray-b-core, 28px),
      transparent var(--ray-b-width, 64px),
      transparent var(--ray-b-period, 263px));
  /* Fade downward, and soften toward the sides so the light has a centre. */
  -webkit-mask-image:
    linear-gradient(180deg, #000 0, rgba(0, 0, 0, .55) calc(var(--ray-reach) * .45), transparent var(--ray-reach)),
    radial-gradient(ellipse 70% 130% at 46% 0, #000 30%, rgba(0, 0, 0, .35) 70%, transparent 100%);
  -webkit-mask-composite: source-in;
  mask-image:
    linear-gradient(180deg, #000 0, rgba(0, 0, 0, .55) calc(var(--ray-reach) * .45), transparent var(--ray-reach)),
    radial-gradient(ellipse 70% 130% at 46% 0, #000 30%, rgba(0, 0, 0, .35) 70%, transparent 100%);
  mask-composite: intersect;
  mix-blend-mode: screen;
  opacity: calc(clamp(0, (var(--launch-light-rise) - var(--ray-from)) * 10 + .001, 1) * var(--ray-strength));
}

.launch-ray.r1 {
  --ray-from: -.1;
}

/* Retired for performance; the markup stays so cached pages keep working. */
.launch-ray.r2 {
  display: none;
}

/* ~2 weeks left: broad, soft beams. */
.launch-ray.r3 {
  --ray-from: .55;
  --ray-angle: 103deg;
  --ray-a-core: 52px;
  --ray-a-width: 120px;
  --ray-a-period: 311px;
  --ray-b-core: 40px;
  --ray-b-width: 94px;
  --ray-b-period: 229px;
}

/* The surface moves, so the shafts drift sideways rather than swing. */
html.crossroad-motion-full .launch-ray.r1 { animation: launch-ray-drift 23s ease-in-out infinite alternate; }
html.crossroad-motion-full .launch-ray.r3 { animation: launch-ray-drift 19s ease-in-out -4s infinite alternate; }

@keyframes launch-ray-drift {
  from { transform: translateX(-28px) skewX(-.6deg); }
  to { transform: translateX(28px) skewX(.6deg); }
}

.crossroad-top-underwater.is-ready {
  opacity: calc(.32 + var(--launch-light) * .2);
}

/*
 * Panels follow the water: every card shares one surface that moves from
 * deep navy to teal glass with the days. The colour range lives in the sea,
 * not in the panels. Selectors mirror crossroad-agreed-axis-cards.css
 * (loaded earlier) so these win by order.
 */

.prediction-card,
.latest-official,
.official-event {
  /* One surface for every panel; only the day changes it. */
  --launch-panel-face: var(--launch-panel);
}

html[data-crossroad-phase="prelaunch"] .prediction-card:not(.add-card),
html[data-crossroad-phase="prelaunch"] .prediction-card.lod-uniform:not(.add-card),
html[data-crossroad-phase="prelaunch"] .prediction-card.lod-uniform.is-light-near:not(.add-card),
html[data-crossroad-phase="prelaunch"] .prediction-card.is-featured:not(.add-card) {
  background: radial-gradient(
    ellipse 98% 128% at 46% 48%,
    color-mix(in srgb, var(--launch-panel-face) 95%, transparent) 0,
    color-mix(in srgb, var(--launch-panel-face) 84%, transparent) 56%,
    color-mix(in srgb, var(--launch-panel-face) 40%, transparent) 78%,
    transparent 100%
  ) !important;
}

html[data-crossroad-phase="prelaunch"] .prediction-card.lod-uniform.is-light-primary:not(.add-card),
html[data-crossroad-phase="prelaunch"] .prediction-card.lod-uniform:not(.add-card):hover,
html[data-crossroad-phase="prelaunch"] .prediction-card.lod-uniform:not(.add-card):focus-visible {
  --prediction-highlight-face: color-mix(in oklch, var(--launch-panel-face), white var(--prediction-highlight, 14%));
  background: radial-gradient(
    ellipse 98% 128% at 46% 48%,
    var(--prediction-highlight-face) 0,
    color-mix(in srgb, var(--prediction-highlight-face) 90%, transparent) 56%,
    color-mix(in srgb, var(--prediction-highlight-face) 45%, transparent) 78%,
    transparent 100%
  ) !important;
}

@media (hover: hover) {
  html[data-crossroad-phase="prelaunch"] .prediction-card.lod-uniform:not(.add-card):hover {
    --prediction-highlight: 21%;
  }

  html[data-crossroad-phase="prelaunch"] .rail .prediction-card.lod-uniform.is-past-position:not(.add-card):hover {
    opacity: max(var(--past-distance-opacity, .28), .58);
  }

  html[data-crossroad-phase="prelaunch"] .rail .prediction-card.lod-uniform.is-past-position.is-axis-overlap:not(.add-card):hover {
    opacity: .32;
  }
}

html[data-crossroad-phase="prelaunch"] .latest-official,
html[data-crossroad-phase="prelaunch"] .official-event {
  background:
    linear-gradient(90deg,
      color-mix(in srgb, var(--launch-panel-face) 88%, transparent),
      color-mix(in srgb, color-mix(in oklab, var(--launch-panel-face) 60%, black) 64%, transparent) 70%,
      transparent),
    radial-gradient(ellipse 66% 120% at 0 24%, rgba(130, 205, 252, calc(.075 + var(--launch-light-color) * .08)), transparent 64%);
}


@media (max-width: 760px) {
  .launch-surface-light::before {
    background:
      radial-gradient(ellipse 110% 44% at 50% -6%, color-mix(in srgb, var(--launch-light-water) 32%, transparent), transparent 74%),
      linear-gradient(180deg,
        color-mix(in srgb, var(--launch-light-water) 22%, transparent) 0,
        color-mix(in srgb, var(--launch-light-water) 9%, transparent) 48%,
        transparent 100%);
  }
}

@media (prefers-reduced-motion: reduce) {
  .launch-surface-light {
    transition: none;
  }

  .launch-ray {
    animation: none !important;
  }
}
