/**
 * Nebula scroll animations — pre-hide layer for Animate.css reveals.
 *
 * Only hides elements once JS has confirmed it can animate (the `nebula-anim-ready`
 * flag is added to <html> by animations.js before paint). So:
 *   - no-JS visitors                → .nebula-anim stays visible
 *   - reduced-motion / no IntersectionObserver → stays visible (flag never set)
 *   - otherwise                     → hidden until it scrolls in, then Animate.css
 *                                      takes over via its own keyframes.
 */
html.nebula-anim-ready .nebula-anim:not(.animate__animated) {
	opacity: 0;
}

/*
 * GSAP engine (gsap-animations.js). Same pre-hide contract: hide until the
 * runtime takes over with inline styles (gsap.from sets inline opacity, which
 * beats this rule). The shared `nebula-anim-ready` flag (set in <head> by
 * animations.js, which always loads) keeps no-JS / reduced-motion visitors safe.
 */
html.nebula-anim-ready .nebula-gsap {
	opacity: 0;
}

/*
 * Custom (library-free) engine — `.nebula-rvl`. A CSS transition reveal fired by
 * IntersectionObserver (animations.js adds `.is-in`). Direction comes from
 * `data-rvl-effect`; distance / duration / delay ride on CSS custom properties set
 * inline by Animations::inject_custom(). Same pre-hide contract as above (only
 * applies once `nebula-anim-ready` is set, so no-JS / reduced-motion stay visible).
 */
html.nebula-anim-ready .nebula-rvl {
	opacity: 0;
	transform: translate3d(0, var(--rvl-dist, 30px), 0);
	transition:
		opacity var(--rvl-dur, 1s) cubic-bezier(0.22, 1, 0.36, 1) var(--rvl-delay, 0s),
		transform calc(var(--rvl-dur, 1s) * 1.15) cubic-bezier(0.22, 1, 0.36, 1) var(--rvl-delay, 0s);
	will-change: opacity, transform;
}

html.nebula-anim-ready .nebula-rvl[data-rvl-effect="down"] {
	transform: translate3d(0, calc(var(--rvl-dist, 30px) * -1), 0);
}

html.nebula-anim-ready .nebula-rvl[data-rvl-effect="left"] {
	transform: translate3d(var(--rvl-dist, 30px), 0, 0);
}

html.nebula-anim-ready .nebula-rvl[data-rvl-effect="right"] {
	transform: translate3d(calc(var(--rvl-dist, 30px) * -1), 0, 0);
}

html.nebula-anim-ready .nebula-rvl[data-rvl-effect="fade"] {
	transform: none;
}

html.nebula-anim-ready .nebula-rvl[data-rvl-effect="zoom"] {
	transform: scale(0.92);
}

/* Revealed state — must follow the direction rules so it wins the specificity tie. */
html.nebula-anim-ready .nebula-rvl.is-in {
	opacity: 1;
	transform: none;
}

/*
 * Mask / line-wipe reveal (the R2 hero "NEXT STARTS HERE" effect). The block clips
 * (overflow:hidden) and an inner wrapper — added at runtime by animations.js — slides
 * up from below, so the text wipes in from behind a mask. Distance is fixed (130% of
 * its own height); duration / delay still ride on the CSS vars.
 */
html.nebula-anim-ready .nebula-rvl[data-rvl-effect="mask"] {
	overflow: hidden;
	transform: none;
}

html.nebula-anim-ready .nebula-rvl[data-rvl-effect="mask"] > .nebula-rvl__inner {
	display: block;
	transform: translate3d(0, 130%, 0);
	transition: transform var(--rvl-dur, 1.2s) cubic-bezier(0.22, 1, 0.36, 1) var(--rvl-delay, 0s);
	will-change: transform;
}

html.nebula-anim-ready .nebula-rvl[data-rvl-effect="mask"].is-in > .nebula-rvl__inner {
	transform: none;
}

/*
 * Per-line wipe (`mask-lines`) — the R2 hero / closing CTA headline effect. animations.js
 * splits the block at its <br>s into `.nebula-rvl__line`s, each clipping its own
 * `.nebula-rvl__inner`; every inner slides up from below its mask, the Nth line
 * --rvl-stagger later than the one before (on top of --rvl-delay). The clip is padded
 * so descenders and italic overhangs aren't cut. Once split (`is-split`) the block
 * itself is visible — only the lines are hidden — so it beats the generic pre-hide.
 */
html.nebula-anim-ready .nebula-rvl[data-rvl-effect="mask-lines"].is-split {
	opacity: 1;
	transform: none;
	transition: none;
}

.nebula-rvl[data-rvl-effect="mask-lines"] > .nebula-rvl__line {
	display: block;
	clip-path: inset(-0.35em -0.2em 0 -0.2em);
}

.nebula-rvl[data-rvl-effect="mask-lines"] > .nebula-rvl__line > .nebula-rvl__inner {
	display: block;
}

html.nebula-anim-ready .nebula-rvl[data-rvl-effect="mask-lines"] > .nebula-rvl__line > .nebula-rvl__inner {
	transform: translate3d(0, 135%, 0);
	transition: transform var(--rvl-dur, 1.2s) cubic-bezier(0.22, 1, 0.36, 1)
		calc(var(--rvl-delay, 0s) + var(--rvl-i, 0) * var(--rvl-stagger, 0.12s));
	will-change: transform;
}

html.nebula-anim-ready .nebula-rvl[data-rvl-effect="mask-lines"].is-in > .nebula-rvl__line > .nebula-rvl__inner {
	transform: none;
}

/*
 * Media Settle (`media-settle`, `media-fade-settle`) — for a Cover (or any block with a
 * background video / image). The block itself stays visible and still; only its
 * background media eases down from --rvl-media-scale (default 108%; the block's "Zoom
 * from" setting) and, for fade-settle, fades up from black, as it comes into view. Uses the independent `scale` property so it never fights the
 * media's own transforms / object-position. Duration rides on --rvl-dur.
 */
html.nebula-anim-ready .nebula-rvl.nebula-rvl[data-rvl-effect^="media-"] {
	opacity: 1;
	transform: none;
	transition: none;
}

html.nebula-anim-ready .nebula-rvl[data-rvl-effect^="media-"] :is(.wp-block-cover__video-background, .wp-block-cover__image-background) {
	scale: var(--rvl-media-scale, 1.08);
	transition:
		scale var(--rvl-dur, 2.2s) cubic-bezier(0.16, 1, 0.3, 1) var(--rvl-delay, 0s),
		opacity calc(var(--rvl-dur, 2.2s) * 0.64) ease var(--rvl-delay, 0s);
}

html.nebula-anim-ready .nebula-rvl[data-rvl-effect="media-fade-settle"] :is(.wp-block-cover__video-background, .wp-block-cover__image-background) {
	opacity: 0;
}

html.nebula-anim-ready .nebula-rvl[data-rvl-effect^="media-"].is-in :is(.wp-block-cover__video-background, .wp-block-cover__image-background) {
	scale: 1;
	opacity: 1;
}

/*
 * Frame Rise + Photo Settle (`frame-settle`) — for an Image / Featured Image block (the
 * R3 prototype's article-hero frame, `.sh .frame`). The block fades and rises like `up`
 * (Distance / Duration) and clips its photo, which settles from --rvl-media-scale (the
 * block's "Zoom from") to 1 over a longer, softer ease.
 */
html.nebula-anim-ready .nebula-rvl[data-rvl-effect="frame-settle"] {
	overflow: hidden;
}

html.nebula-anim-ready .nebula-rvl[data-rvl-effect="frame-settle"] img {
	scale: var(--rvl-media-scale, 1.08);
	transition: scale calc(var(--rvl-dur, 1s) * 1.85) cubic-bezier(0.16, 1, 0.3, 1) var(--rvl-delay, 0s);
}

html.nebula-anim-ready .nebula-rvl[data-rvl-effect="frame-settle"].is-in img {
	scale: 1;
}

/*
 * Line Draw (`draw`) — for a Separator or any thin rule: it draws in from the left
 * (scaleX 0 → 1) instead of rising, like the R3 prototype's rules above the stats rows
 * (`.sst::before`, 1.2s ease-out). Distance doesn't apply.
 */
html.nebula-anim-ready .nebula-rvl[data-rvl-effect="draw"] {
	transform: scaleX(0);
	transform-origin: 0 50%;
	transition:
		opacity calc(var(--rvl-dur, 1s) * 0.4) linear var(--rvl-delay, 0s),
		transform var(--rvl-dur, 1s) cubic-bezier(0.16, 1, 0.3, 1) var(--rvl-delay, 0s);
}

html.nebula-anim-ready .nebula-rvl[data-rvl-effect="draw"].is-in {
	transform: none;
}

/*
 * Stagger children (`.nebula-rvl-group`) — the group holds the effect + timing and
 * stays put; animations.js turns each child (or each Query Loop post) into a
 * `.nebula-rvl` with the same effect and an increasing --rvl-delay. The children are
 * pre-hidden by the head guard (Animations::print_prehide_guard) so nothing flashes
 * before the script runs. Children inherit --rvl-dist / --rvl-dur from the group.
 */
