/* ============ launch — the last sampler run ============
   The stage is transparent: the rocket is drawn by the page-wide particle field.

   Two seams, both handed over without a blank screen:
     --seam  the chapter rises over the last of Open's paper. The field's launch range
             (js/gl/director.js) is this section's own box, top top → bottom bottom, so the
             sampler starts while the paper still holds the top of the screen, and the stars
             (fixed behind the paper) are already out under its dissolving edge.
     --tail  Contact rises over the tail. It must stay small: the director hands the field to
             Contact as soon as Contact's top passes 90% of the screen, and that may only happen
             once the rocket has re-noised (L ≈ 0.96) — a bigger overlap would cut the lift-off
             short with a visible pop. 280vh puts the hand-over at L ≈ 0.98. */

.launch {
  --seam: 30vh;
  --tail: 14vh;
  --band: 120px; /* half the dissolve's height: the paper's edge sits at its middle */
  /* one dither for both halves of the dissolve: a fine turbulence thresholded against a
     vertical ramp — 0 at the top of the tile, 1 at the bottom (see ::before / ::after) */
  --dissolve: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='640' height='240'%3E%3Cdefs%3E%3ClinearGradient id='g' x2='0' y2='1'%3E%3Cstop offset='0' stop-color='%23fff' stop-opacity='0'/%3E%3Cstop offset='1' stop-color='%23fff'/%3E%3C/linearGradient%3E%3Cfilter id='d' x='0' y='0' width='1' height='1' color-interpolation-filters='sRGB'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.4' seed='3' stitchTiles='stitch' result='t'/%3E%3CfeColorMatrix in='t' result='n' values='0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 1 0 0 0 0'/%3E%3CfeComposite in='SourceGraphic' in2='n' operator='arithmetic' k2='1' k3='1.4' k4='-.7'/%3E%3CfeComponentTransfer%3E%3CfeFuncA type='linear' slope='10' intercept='-4.5'/%3E%3C/feComponentTransfer%3E%3C/filter%3E%3C/defs%3E%3Crect width='640' height='240' fill='url(%23g)' filter='url(%23d)'/%3E%3C/svg%3E");
  /* no z-index on purpose: a stacking context here would trap the dissolve under the paper act */
  position: relative;
  height: 280vh;
  margin-top: calc(-1 * var(--seam));
  margin-bottom: calc(-1 * var(--tail));
}

/* ---------- the dissolve: paper turns to night through grain, not along a ruled line ----------
   Centred on the paper's bottom edge (the act ends exactly --seam below this section's top).
   Above the edge, dark grains eat into the paper; below it, paper grains thin out into the dark,
   where the stars already show between them. Both halves read the same noise tile at the same
   size, so the grain runs straight across the edge. A static image, rasterised once. */
.launch::before,
.launch::after {
  content: "";
  position: absolute;
  z-index: 3; /* over the act (z 2); the field canvas is outside <main> and still draws on top */
  left: 0;
  right: 0;
  height: var(--band);
  pointer-events: none;
  -webkit-mask-repeat: repeat-x;
  mask-repeat: repeat-x;
  -webkit-mask-size: auto calc(2 * var(--band));
  mask-size: auto calc(2 * var(--band));
}
.launch::before {
  top: calc(var(--seam) - var(--band));
  background: var(--bg);
  -webkit-mask-image: var(--dissolve);
  mask-image: var(--dissolve);
  -webkit-mask-position: 0 0;
  mask-position: 0 0;
}
.launch::after {
  top: var(--seam);
  background: var(--ink); /* the dark theme's ink is the light act's paper, exactly */
  /* the complement of the same tile: paper wherever the dark grains are not */
  -webkit-mask-image: linear-gradient(#000 0 0), var(--dissolve);
  mask-image: linear-gradient(#000 0 0), var(--dissolve);
  -webkit-mask-size: 100% 100%, auto calc(2 * var(--band));
  mask-size: 100% 100%, auto calc(2 * var(--band));
  -webkit-mask-repeat: no-repeat, repeat-x;
  mask-repeat: no-repeat, repeat-x;
  -webkit-mask-position: 0 0, 0 100%;
  mask-position: 0 0, 0 100%;
  -webkit-mask-composite: xor;
  mask-composite: exclude;
}

.launch__stage {
  position: sticky;
  top: 0;
  height: 100vh;
  height: 100svh;
  overflow: hidden;
  display: grid;
  place-items: center;
  pointer-events: none;
}

/* the site's one voice (css/type.css): Mona Sans at the heading weight and width */
.launch__line {
  position: absolute;
  left: var(--gutter);
  right: var(--gutter);
  top: 50%;
  margin-top: -0.6em;
  font-size: clamp(3.2rem, 1.2rem + 8.5vw, 11rem);
  font-weight: var(--fw-head, 600);
  font-stretch: var(--wd-head, 104%);
  line-height: 1;
  letter-spacing: -0.05em;
  white-space: nowrap;
  opacity: 0;
  will-change: transform, opacity, filter;
}
.launch__line--a { text-align: left; }
.launch__line--b { text-align: right; }

.launch__hud {
  position: absolute;
  left: 50%;
  bottom: 1.6rem;
  transform: translateX(-50%);
  display: inline-flex;
  gap: 1rem;
  color: var(--ink-3);
  opacity: 0;
}
.launch__hud b { color: var(--ink); font-weight: 450; }

.launch__skip {
  position: absolute;
  right: var(--gutter);
  bottom: 1.4rem;
  min-height: 32px;
  display: inline-flex;
  align-items: center;
  color: var(--ink-3);
  pointer-events: auto;
}
.launch__skip:hover { color: var(--ink); }

/* engine shake: a few px, only while the rocket burns on the pad */
.launch.is-burning .launch__line--b { translate: calc(var(--shake, 0) * 3px) calc(var(--shake, 0) * 2px); }

/* the sky sits still behind the page: fixed, so the paper slides off it rather than dragging it
   along, and Contact rises over it as it fades. Hidden whenever the chapter is out of view. */
.launch__stars { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; }
html.in-launch .field { z-index: 2; }

/* reduced motion: a short, still statement; the dissolve stays, centred on the plain seam */
.launch.is-still { --seam: 0px; --tail: 0px; height: auto; }
.launch.is-still .launch__stage { position: relative; height: 70vh; }
.launch.is-still .launch__line { position: relative; top: auto; margin: 0; opacity: 1; }
.launch.is-still .launch__stage { display: flex; flex-direction: column; justify-content: center; gap: 1rem; }
.launch.is-still .launch__hud { display: none; }

@media (max-width: 760px) {
  .launch { --tail: 13vh; height: 240vh; }
  .launch__line { font-size: clamp(2.6rem, 14vw, 4.6rem); }
  /* phones stack: the rocket owns the middle of the screen, so both lines take the slot just
     above its nose — and "Here we go." rides the ascent out of frame (js) instead of being run
     into by it */
  .launch__line--a,
  .launch__line--b { top: 27%; margin-top: 0; text-align: left; }
  /* bottom-right belongs to the assistant's launcher on phones */
  .launch__skip { right: auto; left: var(--gutter); }
  .launch__hud { bottom: 3.8rem; left: var(--gutter); transform: none; }
}
