/* Ambient doodle motion for the posters (11/18-11/19). Small idle touches that make the doodles feel alive
   ("lightbulbs glow, fire flickers") without ever competing with the text. Separate from the step-by-step
   "Play" animations (bb-poster-anim.css/js).

   CLASS CONTRACT (tag 2-5 elements per poster, in the poster SOURCES, never in built output):
     .amb-glow     soft glow pulse. PREFERRED: an overlay layer <svg class="amb-layer amb-glow" viewBox="same as the
                   drawing"> placed right before the drawing's svg, holding HALO COPIES of the shapes (class "amb-halo"
                   + the wave's stroke color class, e.g. s3 / m2). The layer is invisible at rest and fades to .34 and
                   back on the compositor (no repaint). Helper: poster_ambient.halo(). Lightbulbs, stars, bolts, "aha"
                   marks, cheese, the IPv6 force-field rim. On a visible element without a layer, .amb-glow is a slow
                   breathing shimmer (opacity 1 -> .6 -> 1; waves 4-5 use it on LEDs and stars).
     .amb-flicker  fire/flame flicker: scale + opacity jitter around the flame base (transform-origin bottom).
     .amb-pulse    gentle attention pulse (scale 1 -> 1.06) for warning marks.
     .amb-twitch   EXAM TRAPS use the mouse-trap doodle (shared drawing: codex-queue/tools/poster_ambient.py, same
                   geometry as bb-poster-w4.js). Put .amb-twitch on a <g> around the spring bar: a tiny nervous twitch
                   every ~6-8 s, fired by the JS (pivot at the hinge, bottom right of the bar). The cheese gets an amb-glow halo layer.
     .amb-wave     radio / Wi-Fi / sound arcs rippling outward. Tag each arc (inner -> outer) and add amb-d1..amb-d4
                   for the stagger, or wrap the arcs in .amb-wave-set (children stagger by nth-child).
     .amb-float    zzz / steam / sweat / bubbles drifting up and fading, then back. Stagger with amb-d1..d4.
     .amb-blink    eye blink on faces: a <g> around the two eye dots. Rare (every 6-9 s per face, random, fired by
                   the JS one face at a time, so faces never blink together).
     .amb-bob      tiny idle bob for characters (1.5px).
     .amb-glint    light pulse along a beam / wire (opacity dip that travels with the stagger).
     .amb-d1..d4   stagger helpers (delay + slightly different period).

   COST: SVG children are never composited, so every visual change repaints that bit of the svg, wobble filter
   included. So: glows live in an overlay svg root (amb-layer); the continuous loops use steps() timing (about 3-7
   visual changes a second instead of 60; a slow glow or flicker reads the same); blink and twitch are JS-fired
   one-shots, so between shots nothing animates at all.
   RULES: transform and opacity only (never filters, fills on big areas or layout). Slow and subtle (2-9 s loops,
   small amplitude). Keyframe 0% = the drawing at rest, so screenshots, print and reduced motion look identical.
   Continuous motion (glow, flicker, wave, float, bob, glint) only on small doodles or elements outside the big
   wobble-filtered groups (each change re-filters whatever group the moving element sits in). One-shots (blink,
   twitch) may sit inside a filtered group.
   Loops are PAUSED until js/bb-poster-ambient.js marks a poster as on screen (.amb-in), and paused again when it
   scrolls away. prefers-reduced-motion and print: no motion at all. */

/* transformed parts scale/rotate around their own box */
.amb-flicker,.amb-pulse,.amb-twitch,.amb-float,.amb-blink,.amb-bob{transform-box:fill-box}

/* glow halo layer (preferred for glows): a separate overlay <svg class="amb-layer amb-glow"> with the same viewBox,
   placed right BEFORE the main svg, holding wide soft-stroke copies of the shapes (class "amb-halo" + a stroke color).
   An opacity loop on an svg ROOT runs on the compositor: no repaint, no re-filtering of the wobbly doodle. */
/* left/top stay auto: the layer keeps its in-flow spot, which is exactly where the next svg starts */
.amb-layer{position:absolute;pointer-events:none;opacity:0}
.amb-layer+svg{position:relative}
/* hosts that are not positioned yet (so width:100% resolves against the host, like the drawing) */
.w1-side:has(>.amb-layer),figure:has(>.amb-layer),
.w3d:not(.v3--pinout):not(.v3--keycards) .v3-dd-title:has(>.amb-layer),.w3d .v3-timeline .v3-dd-tlC:has(>.amb-layer){position:relative}
.bb-poster svg .amb-halo.amb-halo,svg .amb-halo.amb-halo{fill:none;stroke-width:9px;stroke-linejoin:round;stroke-linecap:round}
@keyframes amb-halo{0%,100%{opacity:0}50%{opacity:.34}}
/* a halo copy INSIDE an svg (older form) also works, but repaints: invisible at rest, stepped loop */
.amb-halo.amb-glow{opacity:0}
/* .amb-glow on a visible element: a slow "breathing" shimmer (full at rest, dips to .6) */
.amb-glow{animation:amb-glow 4.6s steps(14,jump-none) infinite}
@keyframes amb-glow{0%,100%{opacity:1}50%{opacity:.6}}
.amb-layer.amb-glow{animation:amb-halo 4.6s steps(16,jump-none) infinite}
.amb-halo.amb-glow{animation:amb-halo 4.6s steps(14,jump-none) infinite}

.amb-flicker{transform-origin:50% 100%;animation:amb-flicker 2.3s steps(2,jump-none) infinite}
@keyframes amb-flicker{0%,100%{transform:none;opacity:1}18%{transform:scale(.95,1.07);opacity:.92}36%{transform:scale(1.04,.95)}
  55%{transform:scale(.97,1.05) skewX(1.5deg);opacity:.95}76%{transform:scale(1.02,.97) skewX(-1deg)}}

.amb-pulse{transform-origin:50% 60%;animation:amb-pulse 3.2s steps(10,jump-none) infinite}
@keyframes amb-pulse{0%,100%{transform:none}50%{transform:scale(1.06)}}

/* blink + twitch are one-shots: js/bb-poster-ambient.js adds .amb-go to one element at a time (every ~6-9 s per
   element, random, only on posters in view) and removes it when the shot ends. Between shots nothing is animating. */
.amb-twitch{transform-origin:70% 100%}
.amb-twitch.amb-go{animation:amb-twitch .5s linear 1}
@keyframes amb-twitch{0%,100%{transform:none}22%{transform:rotate(-5deg)}48%{transform:rotate(3deg)}74%{transform:rotate(-2deg)}}

.amb-wave,.amb-wave-set>*{animation:amb-wave 2.8s steps(4,jump-none) infinite}
.amb-wave-set>:nth-child(2){animation-delay:.3s}.amb-wave-set>:nth-child(3){animation-delay:.6s}.amb-wave-set>:nth-child(4){animation-delay:.9s}
@keyframes amb-wave{0%,45%,100%{opacity:1}18%{opacity:.25}}

.amb-float{transform-origin:50% 100%;animation:amb-float 3.8s steps(8,jump-none) infinite}
@keyframes amb-float{0%,100%{transform:none;opacity:1}55%{transform:translateY(-5px);opacity:.15}56%{transform:translateY(3px);opacity:0}80%{transform:translateY(1px);opacity:.8}}

.amb-blink{transform-origin:50% 50%}
.amb-blink.amb-go{animation:amb-blink .22s linear 1}
@keyframes amb-blink{0%,100%{transform:none}45%{transform:scaleY(.12)}}

.amb-bob{animation:amb-bob 3.4s steps(6,jump-none) infinite}
@keyframes amb-bob{0%,100%{transform:none}50%{transform:translateY(-1.5px)}}

.amb-glint{animation:amb-glint 3.6s steps(6,jump-none) infinite}
@keyframes amb-glint{0%,40%,100%{opacity:1}20%{opacity:.45}}

/* stagger: delay + its own period so tagged parts drift apart and never sync */
.amb-d1{animation-delay:-.4s}
.amb-d2{animation-delay:-1.7s;animation-duration:8.1s}
.amb-d3{animation-delay:-3.1s;animation-duration:6.4s}
.amb-d4{animation-delay:-4.6s;animation-duration:8.9s}
.amb-wave.amb-d1,.amb-wave.amb-d2,.amb-wave.amb-d3,.amb-wave.amb-d4{animation-duration:2.8s}
.amb-wave.amb-d1{animation-delay:0s}.amb-wave.amb-d2{animation-delay:.3s}.amb-wave.amb-d3{animation-delay:.6s}.amb-wave.amb-d4{animation-delay:.9s}
.amb-float.amb-d1,.amb-float.amb-d2,.amb-float.amb-d3,.amb-float.amb-d4{animation-duration:3.8s}
.amb-float.amb-d1{animation-delay:0s}.amb-float.amb-d2{animation-delay:.7s}.amb-float.amb-d3{animation-delay:1.4s}.amb-float.amb-d4{animation-delay:2.1s}
.amb-glint.amb-d1,.amb-glint.amb-d2{animation-duration:3.6s}.amb-glint.amb-d1{animation-delay:0s}.amb-glint.amb-d2{animation-delay:1.8s}
.amb-glow.amb-d3{animation-delay:-2.3s;animation-duration:5.4s}
/* poster-level stagger on the review pages: neighbouring posters' glows start at different points */
.review-poster:nth-child(even) .amb-glow:not(.amb-d3){animation-delay:-1.9s}

/* paused until js/bb-poster-ambient.js marks the poster as on screen (.amb-in); declared after the animation shorthands */
.amb-glow,.amb-flicker,.amb-pulse,.amb-wave,.amb-wave-set>*,.amb-float,.amb-bob,.amb-glint,
.amb-layer.amb-glow,.amb-halo.amb-glow{animation-play-state:paused}
.amb-in .amb-layer.amb-glow,.amb-in .amb-halo.amb-glow,.amb-in .amb-glow,.amb-in .amb-flicker,.amb-in .amb-pulse,.amb-in .amb-wave,.amb-in .amb-wave-set>*,
.amb-in .amb-float,.amb-in .amb-bob,.amb-in .amb-glint{animation-play-state:running}

@media (prefers-reduced-motion:reduce){
  .amb-glow,.amb-flicker,.amb-pulse,.amb-twitch,.amb-wave,.amb-wave-set>*,.amb-float,.amb-blink,.amb-bob,.amb-glint{animation:none!important}
}
@media print{
  .amb-glow,.amb-flicker,.amb-pulse,.amb-twitch,.amb-wave,.amb-wave-set>*,.amb-float,.amb-blink,.amb-bob,.amb-glint{animation:none!important}
}
