/**
 * Revita motion: reveal engine, honeycomb drift, hover micro-interactions (owner B, THEME_SPEC 5).
 *
 * .revita-reveal + one .revita-reveal--{effect}; .revita-stagger reveals its direct children
 * in turn (motion.js sets --revita-i); .is-style-timeline children reveal on their own.
 * Nothing is hidden by CSS alone: motion.js gives .revita-pending only to targets that start
 * below the first screen, and they enter when they scroll in (.is-revealed). Everything in
 * or above the first screen is painted at once and stays still. Hidden states apply only on
 * screens, at motion full/subtle and without a reduced-motion preference; keyboard focus
 * inside a waiting target shows it at once. Offsets use translate/scale/rotate, so an
 * entrance never overrides a block's own transform and ends exactly on it. Loaded in the
 * editor canvas too (tokens and keyframes only; nothing hides there).
 */

/* 1. Tokens, inherited by stagger children. */
.revita-reveal,
.revita-stagger,
.is-style-timeline > * {
	--revita-d: var(--wp--custom--motion--distance--md, 28px);
	--revita-tx: 0px;
	--revita-ty: var(--revita-d);
	--revita-s: 1;
	--revita-r: 0deg;
	--revita-kf: revita-reveal;
	--revita-dur: var(--wp--custom--motion--duration--slow, 640ms);
	--revita-ease: var(--wp--custom--motion--easing--emphasized, cubic-bezier(0.16, 1, 0.3, 1));
	--revita-delay: 0ms;
	--revita-i: 0;
}

/* Timeline cards glide towards the line: from the end side on phones, from both sides at 782px+. */
.is-style-timeline > * {
	--revita-tx: calc(var(--revita-d) * var(--revita-dir, 1));
	--revita-ty: 0px;
}

:root {
	--revita-origin-start: 0 50%;
}

:root[dir="rtl"] {
	--revita-dir: -1;
	--revita-origin-start: 100% 50%;
}

@media (min-width: 782px) {
	.is-style-timeline > :where(:nth-child(odd)) {
		--revita-tx: calc(var(--revita-d) * var(--revita-dir, 1) * -1);
	}
}

/* 2. Effects (named after the direction of travel). */
.revita-reveal--fade { --revita-ty: 0px; }
.revita-reveal--fade-up { --revita-ty: var(--revita-d); }
.revita-reveal--fade-down { --revita-ty: calc(var(--revita-d) * -1); }
.revita-reveal--fade-left { --revita-tx: var(--revita-d); --revita-ty: 0px; }
.revita-reveal--fade-right { --revita-tx: calc(var(--revita-d) * -1); --revita-ty: 0px; }
.revita-reveal--zoom-in { --revita-ty: 0px; --revita-s: 0.9; }
.revita-reveal--zoom-out { --revita-ty: 0px; --revita-s: 1.08; }
.revita-reveal--blur-in { --revita-ty: 0px; --revita-s: 1.03; --revita-kf: revita-reveal-blur; }
/* Clip-path wipe from the bottom with a short rise: made for headings. */
.revita-reveal--mask-up { --revita-ty: calc(var(--revita-d) * 0.5); --revita-kf: revita-reveal-mask; }
/* Hexagons pop in with a small turn. */
.revita-reveal--hex-pop { --revita-ty: 0px; --revita-s: 0.6; --revita-r: -8deg; }

/* 3. Duration (default slow, 640 ms) and delay. */
.revita-duration-fast { --revita-dur: var(--wp--custom--motion--duration--fast, 160ms); }
.revita-duration-slow { --revita-dur: var(--wp--custom--motion--duration--slow, 640ms); }
.revita-duration-slower { --revita-dur: var(--wp--custom--motion--duration--slower, 900ms); }
.revita-delay-100 { --revita-delay: 100ms; }
.revita-delay-200 { --revita-delay: 200ms; }
.revita-delay-300 { --revita-delay: 300ms; }
.revita-delay-400 { --revita-delay: 400ms; }
.revita-delay-500 { --revita-delay: 500ms; }
.revita-delay-600 { --revita-delay: 600ms; }
.revita-delay-700 { --revita-delay: 700ms; }
.revita-delay-800 { --revita-delay: 800ms; }

/* 4. Subtle: small distances; zoom, blur and turns become a short rise. */
body.revita-motion-subtle :is(.revita-reveal, .revita-stagger, .is-style-timeline > *) {
	--revita-d: var(--wp--custom--motion--distance--sm, 12px);
}

body.revita-motion-subtle :is(.revita-reveal--zoom-in, .revita-reveal--zoom-out, .revita-reveal--blur-in, .revita-reveal--hex-pop) {
	--revita-ty: var(--revita-d);
	--revita-s: 1;
	--revita-r: 0deg;
	--revita-kf: revita-reveal;
}

/* 5. Waiting below the first screen (.revita-pending, set by motion.js), then one entrance
 * (fill backwards only, so it ends on the element's own styles). Screens only: print always
 * shows everything. */
@media screen and (prefers-reduced-motion: no-preference) {
	body:is(.revita-motion-full, .revita-motion-subtle) :is(.revita-reveal:not(.revita-stagger), .revita-stagger > *, .is-style-timeline > *).revita-pending:not(.is-revealed) {
		opacity: 0;
		translate: var(--revita-tx) var(--revita-ty);
		scale: var(--revita-s);
		rotate: var(--revita-r);
	}

	body.revita-motion-full :is(.revita-reveal.revita-reveal--blur-in:not(.revita-stagger), .revita-stagger.revita-reveal--blur-in > *).revita-pending:not(.is-revealed) {
		filter: blur(12px);
	}

	/* Keyboard focus inside shows it at once (motion.js then drops the waiting state). */
	body:is(.revita-motion-full, .revita-motion-subtle) :is(.revita-reveal:not(.revita-stagger), .revita-stagger > *, .is-style-timeline > *).revita-pending:not(.is-revealed):focus-within {
		opacity: 1;
		translate: none;
		scale: none;
		rotate: none;
		filter: none;
	}

	/* Mask-up waits by opacity only: IntersectionObserver counts a clipped box as
	 * invisible, so its clip-path lives in the keyframes (fill backwards covers delays). */

	body:is(.revita-motion-full, .revita-motion-subtle) :is(.revita-reveal:not(.revita-stagger), .revita-stagger > *, .is-style-timeline > *).revita-pending.is-revealed {
		animation: var(--revita-kf) var(--revita-dur) var(--revita-ease) calc(var(--revita-delay) + var(--revita-i) * var(--wp--custom--motion--stagger, 80ms)) backwards;
	}

	/* Subtle: durations capped at "base". */
	body.revita-motion-subtle :is(.revita-reveal:not(.revita-stagger), .revita-stagger > *, .is-style-timeline > *).revita-pending.is-revealed {
		animation-duration: min(var(--revita-dur), var(--wp--custom--motion--duration--base, 320ms));
	}
}

/* Pause/play buttons (carousel, marquee; rendered by inc/motion.php): motion.js adds
 * .is-paused, which swaps the pause bars for the play triangle. */
.revita-toggle:not(.is-paused) .revita-toggle__play,
.revita-toggle.is-paused .revita-toggle__pause {
	display: none;
}

@keyframes revita-reveal {
	from {
		opacity: 0;
		translate: var(--revita-tx) var(--revita-ty);
		scale: var(--revita-s);
		rotate: var(--revita-r);
	}
}

@keyframes revita-reveal-blur {
	from {
		opacity: 0;
		translate: var(--revita-tx) var(--revita-ty);
		scale: var(--revita-s);
		filter: blur(12px);
	}
}

@keyframes revita-reveal-mask {
	from {
		translate: var(--revita-tx) var(--revita-ty);
		clip-path: polygon(-20% 100%, 120% 100%, 120% 140%, -20% 140%);
	}

	to {
		clip-path: polygon(-20% -20%, 120% -20%, 120% 140%, -20% 140%);
	}
}

/* 6. Honeycomb drift (full motion + option): one tile per loop, so it never jumps.
 * Tiles: honeycomb*.svg 84x48 (core-group.css); honeycomb-dense.svg 48x28 (header.css),
 * whose second layer, the gradient, stays put. */
@media (prefers-reduced-motion: no-preference) {
	body.revita-motion-full.revita-honeycomb-anim .wp-block-group.is-style-honeycomb::before {
		animation: revita-honeycomb-drift 80s linear infinite;
	}

	body.revita-motion-full.revita-honeycomb-anim .revita-header .revita-header__top {
		animation: revita-honeycomb-drift-top 80s linear infinite;
	}
}

@keyframes revita-honeycomb-drift {
	to {
		background-position: 84px 48px;
	}
}

@keyframes revita-honeycomb-drift-top {
	to {
		background-position: 48px 28px, 0 0;
	}
}

/* 7. Hover micro-interactions (not with motion off or reduced motion). Product cards,
 * post cards and the arrow button carry their own (woocommerce-product-template.css,
 * post-card.css, core-button.css). */
@media (prefers-reduced-motion: no-preference) {
	/* Cards lift 4px; core-group.css adds the lifted shadow and the transition. */
	body:is(.revita-motion-full, .revita-motion-subtle) .wp-block-group.is-style-card:has(:focus-visible) {
		translate: 0 -4px;
	}

	/* Images in clipped frames zoom with the viscous honey easing (full motion: subtle has no zoom). */
	body.revita-motion-full :is(.is-style-card .wp-block-image.is-style-rounded-card img, .wp-block-cover.is-style-rounded > .wp-block-cover__image-background) {
		transition: transform var(--wp--custom--motion--duration--slow, 640ms) var(--wp--custom--motion--easing--honey, cubic-bezier(0.65, 0, 0.35, 1));
	}
}

@media (prefers-reduced-motion: no-preference) and (hover: hover) {
	body:is(.revita-motion-full, .revita-motion-subtle) .wp-block-group.is-style-card:hover {
		translate: 0 -4px;
	}

	body.revita-motion-full :is(.is-style-card:hover .wp-block-image.is-style-rounded-card img, .wp-block-cover.is-style-rounded:hover > .wp-block-cover__image-background) {
		transform: scale(1.04);
	}
}

/* Desktop menu bar (1100px wide and taller than 500px, as in parts/header.css): an underline
 * grows from the start edge on hover and keyboard focus (below that the links are in the
 * overlay, which has big links of its own). */
@media (prefers-reduced-motion: no-preference) and (min-width: 1100px) and (min-height: 501px) {
	body:is(.revita-motion-full, .revita-motion-subtle) .revita-header__nav .wp-block-navigation__container > li > .wp-block-navigation-item__content .wp-block-navigation-item__label {
		position: relative;
	}

	body:is(.revita-motion-full, .revita-motion-subtle) .revita-header__nav .wp-block-navigation__container > li > .wp-block-navigation-item__content .wp-block-navigation-item__label::after {
		content: "";
		position: absolute;
		inset-inline: 0;
		inset-block-end: -0.35em;
		block-size: 2px;
		border-radius: var(--wp--custom--radius--pill, 999px);
		background-color: currentColor;
		transform: scaleX(0);
		transform-origin: var(--revita-origin-start);
		transition: transform var(--wp--custom--motion--duration--base, 320ms) var(--wp--custom--motion--easing--honey, cubic-bezier(0.65, 0, 0.35, 1));
		pointer-events: none;
	}

	body:is(.revita-motion-full, .revita-motion-subtle) .revita-header__nav .wp-block-navigation__container > li > .wp-block-navigation-item__content:is(:hover, :focus-visible) .wp-block-navigation-item__label::after {
		transform: scaleX(1);
	}
}

/* 8. Print: motion controls, marquee copies and the progress bar are screen-only. */
@media print {
	.revita-carousel__controls,
	.revita-marquee__toggle,
	.revita-marquee__track > [data-revita-clone],
	.revita-progress {
		display: none !important;
	}
}

/* 9. Deferred images on phones, in portrait and in landscape (below 782px wide, or at most 500px
 * tall as in header.css and carousel.css; inc/motion.php, R2X-perf-woo-02): lazy cover photos,
 * the later slides of a photo carousel, the product gallery's later photos and a product's
 * description photos wait for the load event (or until they come near the screen), so they never
 * share a slow connection with the first screen's largest image. Moved far out of the page rather
 * than hidden: the box keeps its size (no layout shift), the browser's lazy loading ignores them,
 * and the src stays in the HTML. An inline script removes the marker; a noscript style cancels this.
 * Landscape phones since the speed fix (R5X-verify-03): at 844x390 the home page's promo photo
 * (687 KB) and category photos loaded next to the 167 KB hero photo. With this rule and the
 * release script's wait for the hero on short screens, the home page's LCP there went from
 * 4.51 to 3.48 s (mobile lab, DPR 2, Slow 4G, 4x CPU, median of 6 pairs; for the hero file at
 * that size see revita_motion_slide_sizes() in inc/motion.php). Portrait phones run the same code
 * as before. Desktop windows at most 500px tall get the rule too (unchanged at 10 Mbps, 0.10 s
 * faster under Slow 4G); screens taller than 500px from 782px wide (tablets, desktops) still load
 * these photos lazily as before. */
@media screen and (max-width: 781px), screen and (max-height: 500px) {
	img[data-revita-defer] {
		translate: 0 -200000px !important;
	}
}

/* 10. A product page's lower sections on phones, in portrait and in landscape (below 782px wide,
 * or at most 500px tall with a touch screen; inc/motion.php, R2X-perf-woo-02): the details,
 * related products and articles are laid out and painted only when they come near the screen,
 * so late fonts and the main photo re-lay out only the first screen. Each keeps its last
 * rendered height ("auto"); 900px stands in until then. html.revita-cv is set only on a plain
 * navigation without a #fragment, so a reload, a back/forward load or a link to #reviews lands
 * exactly. Reveals still start when they scroll in (motion.js reads their real boxes once the
 * section renders). The section clips its painting like overflow: clip, so overflow-clip-margin
 * lets the cards' shadows (up to 60px for the "lifted" preset) paint past its edges; browsers
 * without overflow-clip-margin skip the whole rule. Not on the home page: there the freed main
 * thread requested the footer's scripts and icons earlier, and they slowed the hero photo (mobile
 * lab, fix round 4; the speed fix measured it again at 390px: no gain over 30 rounds). Landscape
 * phones since the speed fix: at 844x390 the variable product's LCP went from 2.53 to 2.43 s
 * (mobile lab, DPR 2, Slow 4G, 4x CPU, median of 10 pairs, faster in 10 of 10; CLS unchanged).
 * Not on desktop windows at most 500px tall (pointer: coarse): there the stand-ins made the
 * scrollbar thumb shrink, then grow and jump while scrolling down (V3-02). */
@supports (overflow-clip-margin: 1px) {
	@media screen and (max-width: 781px), screen and (max-height: 500px) and (pointer: coarse) {
		.revita-cv main > :is(.revita-product-details, .revita-related, .revita-product-articles) {
			content-visibility: auto;
			contain-intrinsic-size: auto 900px;
			overflow-clip-margin: 64px;
		}
	}
}
