/* v5 stadium light (ported from the v4 prototype): a field of far stadium lights out of focus, two
   floodlight towers just outside the top corners whose beams meet on the number, the glare of each
   source, the hit flash and an anamorphic lens streak. Base styles are the final frame (beams at rest
   on the number); page.mjs plays the entrance with transform and opacity only. All decorative. */

/* The camera: everything on the screen, so page.mjs can settle it from a slow push-in. */
.camera {
  position: absolute;
  inset: 0;
}

/* ------------------------------------------------------------------ far bokeh */

/* Soft discs, a flat fill with a slightly brighter rim like a lens wide open: small far stand
   lights (a, c) and a few big near ones out of focus (b). They twinkle after the entrance. Each
   disc is its own background tile, the size of the disc, placed by its centre in % of the screen
   (cq units of .bokeh): the rest of each full-screen set paints nothing, so the compositor skips
   those tiles instead of blending three empty screens on every frame of the twinkle. */
.bokeh {
  position: absolute;
  inset: 0;
  container-type: size;
  pointer-events: none;
}
.bokeh__set {
  position: absolute;
  inset: 0 0 auto;
}
.bokeh__set--a,
.bokeh__set--b,
.bokeh__set--c {
  background-repeat: no-repeat;
}
/* each set's box ends under its lowest disc, so its layer is no taller than its lights */
.bokeh__set--a {
  height: calc(62cqh + 3.6vmin);
  background-image:
    radial-gradient(circle 2.4vmin, var(--bk-a) 0 66%, var(--bk-a-rim) 84%, var(--bk-0) 100%),
    radial-gradient(circle 3.2vmin, var(--bk-a) 0 66%, var(--bk-a-rim) 84%, var(--bk-0) 100%),
    radial-gradient(circle 1.8vmin, var(--bk-a) 0 66%, var(--bk-a-rim) 84%, var(--bk-0) 100%),
    radial-gradient(circle 2.8vmin, var(--bk-a) 0 66%, var(--bk-a-rim) 84%, var(--bk-0) 100%),
    radial-gradient(circle 3.6vmin, var(--bk-a) 0 66%, var(--bk-a-rim) 84%, var(--bk-0) 100%),
    radial-gradient(circle 2vmin, var(--bk-a) 0 66%, var(--bk-a-rim) 84%, var(--bk-0) 100%),
    radial-gradient(circle 2.2vmin, var(--bk-a) 0 66%, var(--bk-a-rim) 84%, var(--bk-0) 100%),
    radial-gradient(circle 2.6vmin, var(--bk-a) 0 66%, var(--bk-a-rim) 84%, var(--bk-0) 100%),
    radial-gradient(circle 3vmin, var(--bk-a) 0 66%, var(--bk-a-rim) 84%, var(--bk-0) 100%),
    radial-gradient(circle 2.2vmin, var(--bk-a) 0 66%, var(--bk-a-rim) 84%, var(--bk-0) 100%);
  background-size:
    4.8vmin 4.8vmin,
    6.4vmin 6.4vmin,
    3.6vmin 3.6vmin,
    5.6vmin 5.6vmin,
    7.2vmin 7.2vmin,
    4vmin 4vmin,
    4.4vmin 4.4vmin,
    5.2vmin 5.2vmin,
    6vmin 6vmin,
    4.4vmin 4.4vmin;
  background-position:
    calc(8cqw - 2.4vmin) calc(30cqh - 2.4vmin),
    calc(21cqw - 3.2vmin) calc(14cqh - 3.2vmin),
    calc(34cqw - 1.8vmin) calc(24cqh - 1.8vmin),
    calc(68cqw - 2.8vmin) calc(18cqh - 2.8vmin),
    calc(83cqw - 3.6vmin) calc(28cqh - 3.6vmin),
    calc(93cqw - 2vmin) calc(12cqh - 2vmin),
    calc(58cqw - 2.2vmin) calc(8cqh - 2.2vmin),
    calc(3cqw - 2.6vmin) calc(62cqh - 2.6vmin),
    calc(97cqw - 3vmin) calc(58cqh - 3vmin),
    calc(38cqw - 2.2vmin) calc(6cqh - 2.2vmin);
}
.bokeh__set--b {
  height: calc(62cqh + 9.5vmin);
  background-image:
    radial-gradient(circle 8vmin, var(--bk-w) 0 66%, var(--bk-w-rim) 84%, var(--bk-0) 100%),
    radial-gradient(circle 9.5vmin, var(--bk-w) 0 66%, var(--bk-w-rim) 84%, var(--bk-0) 100%),
    radial-gradient(circle 7vmin, var(--bk-w) 0 66%, var(--bk-w-rim) 84%, var(--bk-0) 100%),
    radial-gradient(circle 6vmin, var(--bk-w) 0 66%, var(--bk-w-rim) 84%, var(--bk-0) 100%),
    radial-gradient(circle 7.5vmin, var(--bk-w) 0 66%, var(--bk-w-rim) 84%, var(--bk-0) 100%);
  background-size:
    16vmin 16vmin,
    19vmin 19vmin,
    14vmin 14vmin,
    12vmin 12vmin,
    15vmin 15vmin;
  background-position:
    calc(6cqw - 8vmin) calc(20cqh - 8vmin),
    calc(92cqw - 9.5vmin) calc(30cqh - 9.5vmin),
    calc(70cqw - 7vmin) calc(4cqh - 7vmin),
    calc(26cqw - 6vmin) calc(52cqh - 6vmin),
    calc(80cqw - 7.5vmin) calc(62cqh - 7.5vmin);
}
.bokeh__set--c {
  height: calc(44cqh + 1.3vmin);
  background-image:
    radial-gradient(circle 1vmin, var(--bk-a) 0 66%, var(--bk-a-rim) 84%, var(--bk-0) 100%),
    radial-gradient(circle 1.2vmin, var(--bk-a) 0 66%, var(--bk-a-rim) 84%, var(--bk-0) 100%),
    radial-gradient(circle 0.9vmin, var(--bk-a) 0 66%, var(--bk-a-rim) 84%, var(--bk-0) 100%),
    radial-gradient(circle 1.1vmin, var(--bk-a) 0 66%, var(--bk-a-rim) 84%, var(--bk-0) 100%),
    radial-gradient(circle 1.3vmin, var(--bk-a) 0 66%, var(--bk-a-rim) 84%, var(--bk-0) 100%),
    radial-gradient(circle 0.9vmin, var(--bk-a) 0 66%, var(--bk-a-rim) 84%, var(--bk-0) 100%),
    radial-gradient(circle 1vmin, var(--bk-a) 0 66%, var(--bk-a-rim) 84%, var(--bk-0) 100%),
    radial-gradient(circle 1.2vmin, var(--bk-a) 0 66%, var(--bk-a-rim) 84%, var(--bk-0) 100%),
    radial-gradient(circle 0.8vmin, var(--bk-a) 0 66%, var(--bk-a-rim) 84%, var(--bk-0) 100%),
    radial-gradient(circle 1vmin, var(--bk-a) 0 66%, var(--bk-a-rim) 84%, var(--bk-0) 100%),
    radial-gradient(circle 0.9vmin, var(--bk-a) 0 66%, var(--bk-a-rim) 84%, var(--bk-0) 100%),
    radial-gradient(circle 1.1vmin, var(--bk-a) 0 66%, var(--bk-a-rim) 84%, var(--bk-0) 100%);
  background-size:
    2vmin 2vmin,
    2.4vmin 2.4vmin,
    1.8vmin 1.8vmin,
    2.2vmin 2.2vmin,
    2.6vmin 2.6vmin,
    1.8vmin 1.8vmin,
    2vmin 2vmin,
    2.4vmin 2.4vmin,
    1.6vmin 1.6vmin,
    2vmin 2vmin,
    1.8vmin 1.8vmin,
    2.2vmin 2.2vmin;
  background-position:
    calc(27cqw - 1vmin) calc(30cqh - 1vmin),
    calc(40cqw - 1.2vmin) calc(26cqh - 1.2vmin),
    calc(52cqw - 0.9vmin) calc(22cqh - 0.9vmin),
    calc(62cqw - 1.1vmin) calc(28cqh - 1.1vmin),
    calc(73cqw - 1.3vmin) calc(33cqh - 1.3vmin),
    calc(18cqw - 0.9vmin) calc(36cqh - 0.9vmin),
    calc(86cqw - 1vmin) calc(20cqh - 1vmin),
    calc(48cqw - 1.2vmin) calc(34cqh - 1.2vmin),
    calc(11cqw - 0.8vmin) calc(8cqh - 0.8vmin),
    calc(64cqw - 1vmin) calc(6cqh - 1vmin),
    calc(31cqw - 0.9vmin) calc(16cqh - 0.9vmin),
    calc(78cqw - 1.1vmin) calc(44cqh - 1.1vmin);
}

/* ------------------------------------------------------------------ floodlights */

.lights {
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
}
/* A beam is a soft cone with its apex at the lamp (--ax, --ay). It hangs straight down from the
   apex and turns by --aim onto the number: page.mjs measures the angle, the CSS below is a fair
   guess without it. Three nested boxes share the apex: the aim, the sweep (GSAP on the entrance,
   the idle drift after it), the cone. The cone has a flat core and soft shoulders, so it reads
   as a volume of lit haze. The box ends where the cone does: the mask fades it out by 0.9 of
   --bl, and at that length the widest cone (13 deg) is 0.42 of --bl across, so the drifting
   layers carry no empty corners. The mask stops are the old 4/50/90% of a full --bl. */
.beam {
  position: absolute;
  left: var(--ax);
  top: var(--ay);
  width: calc(var(--bl) * 0.44);
  height: calc(var(--bl) * 0.9);
  translate: -50% 0;
  transform-origin: 50% 0;
  rotate: var(--aim, var(--aim-fixed));
  --bl: 130vmax;
  --ty: 40svh;
}
@supports (rotate: atan2(1px, 1px)) {
  .beam {
    rotate: var(--aim, atan2(calc(var(--ax) - 50vw), calc(var(--ty) - var(--ay))));
  }
}
.beam__sweep,
.beam__cone {
  position: absolute;
  inset: 0;
  transform-origin: 50% 0;
}
.beam__sweep {
  opacity: var(--beam-rest);
}
.beam__cone {
  background: conic-gradient(
    at 50% 0%,
    var(--beam-0) calc(180deg - var(--spread)),
    var(--beam-soft) calc(180deg - var(--spread) * 0.78),
    var(--beam) calc(180deg - var(--spread) * 0.32) calc(180deg + var(--spread) * 0.32),
    var(--beam-soft) calc(180deg + var(--spread) * 0.78),
    var(--beam-0) calc(180deg + var(--spread))
  );
  mask-image: linear-gradient(
    180deg,
    var(--black) 4.44%,
    var(--beam-mask-mid) 55.56%,
    transparent 100%
  );
}
.beam--l {
  --ax: 0.5vw;
  --ay: -1.5svh;
  --spread: 11deg;
  --aim-fixed: -58deg;
  --drift: 2.2deg;
  --drift-t: var(--t-drift);
}
.beam--l2 {
  --ax: 7vw;
  --ay: -4svh;
  --spread: 5deg;
  --aim-fixed: -50deg;
  --drift: -4deg;
  --drift-t: calc(var(--t-drift) * 0.77);
}
.beam--r {
  --ax: 99.5vw;
  --ay: -1.5svh;
  --spread: 11deg;
  --aim-fixed: 58deg;
  --drift: -2.4deg;
  --drift-t: calc(var(--t-drift) * 1.17);
}
@media (max-aspect-ratio: 1 / 1) {
  .beam {
    --ty: 36svh;
  }
  .beam--l,
  .beam--l2 {
    --aim-fixed: -32deg;
  }
  .beam--r {
    --aim-fixed: 32deg;
  }
  .beam--l,
  .beam--r {
    --spread: 13deg;
  }
  .beam--l2 {
    --spread: 6deg;
  }
}

/* Glare of each source, centred just outside the corner: a hot core, a warm halo and a flat
   anamorphic flare along the top edge. */
.lamp {
  position: absolute;
  top: -1.5svh;
  width: max(56vmin, 20rem);
  aspect-ratio: 1;
  translate: -50% -50%;
  background:
    radial-gradient(ellipse 50% 2.2% at 50% 50%, var(--lamp) 0%, var(--lamp-0) 100%),
    radial-gradient(closest-side, var(--lamp) 0 7%, var(--lamp-halo) 22%, var(--lamp-0) 100%);
}
.lamp--l {
  left: 0.5vw;
}
.lamp--r {
  left: 99.5vw;
}

/* ------------------------------------------------------------------ the hit */

/* Anamorphic lens streak through the number, and a flash over the whole frame. Both rest hidden. */
.lens {
  position: absolute;
  left: var(--cx);
  top: var(--cy);
  z-index: 6;
  width: 170vw;
  height: clamp(0.75rem, 2.2vmin, 1.5rem);
  translate: -50% -50%;
  background: linear-gradient(
    90deg,
    var(--lens-0),
    var(--lens-soft) 28%,
    var(--lens) 50%,
    var(--lens-soft) 72%,
    var(--lens-0)
  );
  mask-image: linear-gradient(180deg, transparent, var(--black) 46% 54%, transparent);
  opacity: 0;
  pointer-events: none;
}
.whiteout {
  position: absolute;
  inset: 0;
  z-index: 6;
  background: radial-gradient(
    ellipse 60% 55% at var(--cx) var(--cy),
    var(--whiteout),
    var(--whiteout-edge)
  );
  opacity: 0;
  pointer-events: none;
}

.is-pending .bokeh,
.is-pending .lights {
  opacity: 0;
}
/* While the entrance runs, the big light layers move on their own compositor layers (GSAP writes
   inline transforms, which the browser does not promote by itself). */
[data-intro="running"] :is(.camera, .bokeh, .lamp, .beam__sweep, .lens, .whiteout, .flash, .wave) {
  will-change: transform, opacity;
}

/* ------------------------------------------------------------------ idle */

/* After the entrance the beams drift a little off the number and back, out of step, and the far
   lights twinkle. Both start when the intro flag goes (no animation under the entrance, which
   moves the same boxes with GSAP) and use the individual rotate/translate properties plus
   opacity, so they compose with any inline transform and stay on the compositor. The drift turns
   the sweep, not the cone: the cone's mask then sits inside a moving layer and is drawn into it
   once, instead of a masked layer of over a screen being composited again on every frame. Delays
   are positive and there is no fill mode, so each loop starts from the rest frame without a jump.
   The hit effects are hidden outright after the entrance, so they hold no layer in the idle
   screen. */
@media (prefers-reduced-motion: no-preference) {
  html:not([data-intro]) .beam__sweep {
    animation: drift var(--drift-t) ease-in-out infinite;
  }
  html:not([data-intro]) .bokeh__set {
    animation: twinkle var(--t-twinkle) ease-in-out infinite;
  }
  html:not([data-intro]) .bokeh__set--b {
    animation-duration: calc(var(--t-twinkle) * 1.35);
    animation-delay: 1.7s;
  }
  html:not([data-intro]) .bokeh__set--c {
    animation-duration: calc(var(--t-twinkle) * 0.7);
    animation-delay: 0.9s;
  }
}
@keyframes drift {
  0%,
  100% {
    rotate: 0deg;
  }
  50% {
    rotate: var(--drift);
  }
}
@keyframes twinkle {
  0%,
  100% {
    opacity: 1;
    translate: 0;
  }
  50% {
    opacity: 0.5;
    translate: 0.4vmin;
  }
}
html:not([data-intro]) :is(.lens, .whiteout) {
  visibility: hidden;
}
