/* GoBolt launch kit v2. atmosphere.
   The drifting colour fields from the onboarding welcome, as a background layer.

   v2 (BRIEF-V2 decision 7): each blob follows a closed path of six waypoints with linear
   timing. v1 ping-ponged between two points with ease-in-out, so every blob came to a dead
   stop twice a cycle and the field looked stuck. Now nothing is ever stationary: prove it
   with `node atmo-check.mjs` (frames one second apart, every transform must change).

   <div class="atmo" data-mood="dawn" aria-hidden="true"><i></i><i></i><i></i><i></i><b></b></div>

   Put it first inside a position:relative; isolation:isolate parent (.scene has both).
   Moods: dawn (default, the welcome), day (lighter, greener), dusk (deeper, warmer).
   Only transforms animate. The softness is in each blob's gradient, not a filter: blur() on five moving layers
   ran at about 8 fps without GPU compositing (software GL); the soft stops look the same and cost nothing.
   Use behind heroes, scene changes and end cards. Not behind body text. */

.atmo {
  --a1: var(--k-violet); --a2: var(--k-coral); --a3: var(--k-honey); --a4: var(--k-sage);
  --atmo-strength: 1;
  --atmo-rise: 0%;          /* lift or sink the whole field */
  --atmo-cap: 88%;          /* where the field has faded out entirely */
  --atmo-hold: 30%;         /* up to here it is still at full weight */
  --atmo-foot: 0%;          /* 0 = hard bottom edge. data-edge="soft" fades it into paper */
  --atmo-lift: 1;           /* full-bleed scenes carry less of it */
  --atmo-narrow: 1;         /* phones carry a little less again */
  position: absolute; inset: 0; z-index: -1;
  overflow: hidden; pointer-events: none;
  opacity: calc(var(--atmo-strength) * var(--atmo-lift) * var(--atmo-narrow));
  transition: opacity var(--k-slow) var(--k-ease);
  /* fade the top edge so the colour always rises from the bottom */
  -webkit-mask-image: linear-gradient(to top, transparent 0, #000 var(--atmo-foot), #000 var(--atmo-hold), transparent var(--atmo-cap));
          mask-image: linear-gradient(to top, transparent 0, #000 var(--atmo-foot), #000 var(--atmo-hold), transparent var(--atmo-cap));
}

/* A field that fills a whole viewport stops being light at the bottom edge and becomes four
   bands of colour behind the words. On a full-bleed scene, cap it near the bottom 45% and take
   a third of its weight off, so paper stays dominant: the restraint of the onboarding welcome
   (packages/meridian/src/onboarding-welcome/welcome.module.css), whose field is bounded by a
   card rather than by a screen. Full-bleed means the kit's own .scene--full and .scene--center,
   a full-screen sky layer at rest ([data-sky="full"]), or an explicit data-field="low". */
:where(.scene--full, .scene--center) > .atmo,
:where([data-sky="full"]) .atmo,
.atmo[data-field="low"] { --atmo-cap: 46%; --atmo-hold: 18%; --atmo-lift: 0.65; }
.atmo[data-mood="day"]  { --a1: var(--k-sage); --a2: var(--k-honey); --a3: var(--k-pearl); --a4: var(--k-sage); --atmo-strength: 0.9; }
.atmo[data-mood="dusk"] { --a1: var(--k-violet); --a2: var(--k-coral); --a3: var(--k-coral); --a4: var(--k-violet); --atmo-strength: 0.95; --atmo-rise: -6%; }

.atmo > i, .atmo > b {
  position: absolute; display: block;
  width: 80%; height: 80%;
  will-change: transform;
  animation: 22s var(--k-ease-drift) infinite;   /* --k-ease-drift is linear in v2 */
  margin-bottom: var(--atmo-rise);
}
/* The colour is painted on ::before, a box 1.216x the blob's and centred on it, with a closest-side gradient that
   reaches transparent exactly at that box's ellipse. The blob itself paints nothing, so no clip edge ever cuts the
   gradient (round 7: a farthest-corner gradient under border-radius:50% was cut at 71% of its radius, about 14% alpha,
   and drew hard arcs across the field). The stops are the old farthest-corner ones, divided by 0.86, so the light
   is the same size and weight; only its tail now fades into paper. The blob's box, position and drift are unchanged. */
.atmo > i::before, .atmo > b::before { content: ""; position: absolute; border-radius: 50%; }
.atmo > i::before { inset: -10.8%; background: radial-gradient(ellipse closest-side, var(--c) 0%, color-mix(in srgb, var(--c) 86%, transparent) 23.3%, color-mix(in srgb, var(--c) 64%, transparent) 44.2%, color-mix(in srgb, var(--c) 40%, transparent) 62.8%, color-mix(in srgb, var(--c) 20%, transparent) 76.7%, color-mix(in srgb, var(--c) 7%, transparent) 88.4%, transparent 100%); }
.atmo > i:nth-child(1) { --c: var(--a1); left: -31%; bottom: -35%; animation-name: atmo-1; animation-duration: 22s; animation-delay: -5s; }
.atmo > i:nth-child(2) { --c: var(--a2); left: -5%;  bottom: -42%; animation-name: atmo-2; animation-duration: 27s; animation-delay: -10s; }
.atmo > i:nth-child(3) { --c: var(--a3); left: 29%;  bottom: -45%; animation-name: atmo-3; animation-duration: 24s; animation-delay: -3s; }
.atmo > i:nth-child(4) { --c: var(--a4); left: 62%;  bottom: -32%; animation-name: atmo-4; animation-duration: 30s; animation-delay: -14s; }
.atmo > b {
  left: 13%; bottom: -22%; width: 76%; height: 62%;
  mix-blend-mode: screen;
  animation-name: atmo-5; animation-duration: 32s; animation-delay: -8s;
}
/* 1.103x the box (the old gradient went transparent at 78% of farthest-corner), stops divided by 0.78 */
.atmo > b::before { inset: -5.15%; background: radial-gradient(ellipse closest-side, color-mix(in srgb, var(--k-pearl) 62%, transparent) 0%, color-mix(in srgb, var(--k-pearl) 34%, transparent) 46.2%, color-mix(in srgb, var(--k-pearl) 12%, transparent) 74.4%, transparent 100%); }

/* Six waypoints each, the last equal to the first, linear between them. Consecutive waypoints
   always differ in position, so the velocity never reaches zero; the corners are softened by the
   soft gradient. Percentages are uneven so the five never line up. Ranges are the v1 ones. */
@keyframes atmo-1 {
  0%   { transform: translate3d(-3%, 4%, 0)   rotate(-9deg) scale(0.98, 1.02); }
  18%  { transform: translate3d(5%, -2%, 0)   rotate(-2deg) scale(1.04, 1.05); }
  36%  { transform: translate3d(12%, -9%, 0)  rotate(10deg) scale(1.12, 1.08); }
  55%  { transform: translate3d(9%, -11%, 0)  rotate(4deg)  scale(1.08, 1.10); }
  72%  { transform: translate3d(1%, -5%, 0)   rotate(-4deg) scale(1.02, 1.06); }
  88%  { transform: translate3d(-5%, 1%, 0)   rotate(-8deg) scale(0.97, 1.00); }
  100% { transform: translate3d(-3%, 4%, 0)   rotate(-9deg) scale(0.98, 1.02); }
}
@keyframes atmo-2 {
  0%   { transform: translate3d(-7%, 4%, 0)   rotate(6deg)   scale(1.08, 0.94); }
  15%  { transform: translate3d(2%, -1%, 0)   rotate(0deg)   scale(1.04, 1.02); }
  34%  { transform: translate3d(9%, -8%, 0)   rotate(-10deg) scale(0.98, 1.16); }
  52%  { transform: translate3d(5%, -12%, 0)  rotate(-6deg)  scale(1.02, 1.10); }
  70%  { transform: translate3d(-3%, -7%, 0)  rotate(2deg)   scale(1.06, 1.00); }
  86%  { transform: translate3d(-9%, -1%, 0)  rotate(7deg)   scale(1.10, 0.96); }
  100% { transform: translate3d(-7%, 4%, 0)   rotate(6deg)   scale(1.08, 0.94); }
}
@keyframes atmo-3 {
  0%   { transform: translate3d(8%, 6%, 0)    rotate(-7deg) scale(1.06, 1.00); }
  17%  { transform: translate3d(-1%, 2%, 0)   rotate(-2deg) scale(1.10, 1.05); }
  38%  { transform: translate3d(-13%, -7%, 0) rotate(8deg)  scale(1.13, 1.12); }
  56%  { transform: translate3d(-9%, -11%, 0) rotate(3deg)  scale(1.08, 1.10); }
  73%  { transform: translate3d(0%, -6%, 0)   rotate(-3deg) scale(1.04, 1.06); }
  89%  { transform: translate3d(7%, 0%, 0)    rotate(-6deg) scale(1.02, 1.02); }
  100% { transform: translate3d(8%, 6%, 0)    rotate(-7deg) scale(1.06, 1.00); }
}
@keyframes atmo-4 {
  0%   { transform: translate3d(6%, 0%, 0)    rotate(8deg)  scale(1.00, 1.06); }
  16%  { transform: translate3d(-2%, -4%, 0)  rotate(2deg)  scale(1.04, 1.10); }
  35%  { transform: translate3d(-11%, -11%, 0) rotate(-9deg) scale(1.08, 1.15); }
  54%  { transform: translate3d(-6%, -13%, 0) rotate(-4deg) scale(1.06, 1.12); }
  71%  { transform: translate3d(2%, -8%, 0)   rotate(3deg)  scale(1.02, 1.08); }
  87%  { transform: translate3d(7%, -3%, 0)   rotate(7deg)  scale(0.98, 1.04); }
  100% { transform: translate3d(6%, 0%, 0)    rotate(8deg)  scale(1.00, 1.06); }
}
@keyframes atmo-5 {
  0%   { transform: translate3d(-14%, 5%, 0)  rotate(-13deg) scale(0.90, 1.00); }
  19%  { transform: translate3d(-2%, 0%, 0)   rotate(-4deg)  scale(1.02, 1.04); }
  37%  { transform: translate3d(17%, -13%, 0) rotate(10deg)  scale(1.14, 1.10); }
  53%  { transform: translate3d(11%, -16%, 0) rotate(5deg)   scale(1.10, 1.08); }
  71%  { transform: translate3d(-2%, -9%, 0)  rotate(-3deg)  scale(1.00, 1.04); }
  87%  { transform: translate3d(-12%, -2%, 0) rotate(-10deg) scale(0.94, 1.00); }
  100% { transform: translate3d(-14%, 5%, 0)  rotate(-13deg) scale(0.90, 1.00); }
}

/* phones: taller fields so the colour still reaches mid-screen, and one less layer */
@media (max-width: 640px) {
  .atmo > i { width: 120%; height: 58%; }
  .atmo > i:nth-child(1) { left: -60%; bottom: -22%; }
  .atmo > i:nth-child(2) { left: -25%; bottom: -28%; }
  .atmo > i:nth-child(3) { left: 15%;  bottom: -30%; }
  .atmo > i:nth-child(4) { left: 45%;  bottom: -20%; }
  .atmo > b { display: none; }
  .atmo { --atmo-narrow: 0.85; }
}

/* a page hero that flows into paper below it: soften the bottom edge too.
   Both stops are read off --atmo-cap, so the shape holds when the field is capped. */
.atmo[data-edge="soft"] { --atmo-foot: calc(var(--atmo-cap) * 0.25); --atmo-hold: calc(var(--atmo-cap) * 0.39); }

/* A card hero (the Harvey hero: two lines, then a .stage-card full width). A field anchored to the
   scene's bottom lives behind the card, and the drift cannot be seen (v2 finding: two gutters of
   near-paper). Here the field is a band that starts a little above the card (--atmo-card-top, a share
   of the scene's height), with the blobs lifted so their colour gathers at the card's upper edge and in
   the gutters beside it. It fades out upward before the button and downward behind the card. Automatic
   on .hero--card; anywhere else, data-field="card". atmo-check.mjs proves the drift with pixel diffs. */
.scene.hero--card > .atmo, .atmo[data-field="card"] {
  inset: var(--atmo-card-top, 28%) 0 0 0;
  --atmo-lift: 1; --atmo-cap: 100%; --atmo-hold: 76%; --atmo-foot: 34%;
}
.scene.hero--card > .atmo > i:nth-child(1), .atmo[data-field="card"] > i:nth-child(1) { bottom: 4%; }
.scene.hero--card > .atmo > i:nth-child(2), .atmo[data-field="card"] > i:nth-child(2) { bottom: 0%; }
.scene.hero--card > .atmo > i:nth-child(3), .atmo[data-field="card"] > i:nth-child(3) { bottom: -4%; }
.scene.hero--card > .atmo > i:nth-child(4), .atmo[data-field="card"] > i:nth-child(4) { bottom: 6%; }
.scene.hero--card > .atmo > b, .atmo[data-field="card"] > b { bottom: 18%; }
@media (max-width: 640px) {
  .scene.hero--card > .atmo, .atmo[data-field="card"] { --atmo-hold: 80%; --atmo-foot: 40%; }
  .scene.hero--card > .atmo > i, .atmo[data-field="card"] > i { height: 70%; }
}

/* a renderer can freeze the field at a known phase: <div class="atmo" data-paused>. components.js sets
   data-offscreen on a field out of view, so its drift costs nothing while nobody can see it */
.atmo[data-paused] > *, .atmo[data-offscreen] > *, .still .atmo > * { animation-play-state: paused; }

@media (prefers-reduced-motion: reduce) {
  .atmo > * { animation-play-state: paused !important; }   /* rests mid-drift, the same frame as ?still */
}
