/*
 * Motion system (brand guide §7, R-REMEDIATION-BRIEF §R3.7): gentle fade +
 * upward reveal, staggered, a stroke-draw loading sprig, and a hard
 * `prefers-reduced-motion` floor. Nothing here ever targets the LCP
 * element — hero heading/image are never given the `vv-reveal` class
 * (see patterns/hero.php).
 *
 * Two mechanisms drive `.vv-reveal`, never both at once on the same
 * browser: native `animation-timeline: view()` where supported (R3.5's
 * explicit requirement — compositor-only, zero JS, self-pauses off-screen),
 * with the pre-existing IntersectionObserver (assets/js/motion.js) as the
 * fallback everywhere else. `motion.js` feature-detects the same
 * `@supports` condition below and skips attaching its observer entirely
 * when native support exists, so the two never fight over the same
 * element — the identical "native-first, JS only when unsupported"
 * architecture R3.4 already established for the header's scroll-shrink.
 */

.vv-reveal {
	opacity: 0;
	transform: translateY(var(--wp--custom--motion--reveal-translate));
	transition:
		opacity var(--wp--custom--motion--large-duration) var(--wp--custom--motion--entrance-ease),
		transform var(--wp--custom--motion--large-duration) var(--wp--custom--motion--entrance-ease);
}

.vv-reveal.is-visible {
	opacity: 1;
	transform: translateY(0);
}

/* R7: the how-it-works numerals are the one `.vv-reveal` element that
   wants a scale pop instead of the shared translateY rise — they're a
   focal, oversized element, not a card sliding up. Settles at scale(1),
   never overshoots past it (no bounce/spring easing — R7's own "earthy,
   not gimmicky" constraint). Higher specificity than `.vv-reveal` alone
   overrides the shared transform cleanly. */
.vv-steps__num.vv-reveal {
	transform: scale(0.85);
}

.vv-steps__num.vv-reveal.is-visible {
	transform: scale(1);
}

/* Stagger: 40-60ms per item, capped at 6 — the 7th+ item shares the
   6th item's delay so a long grid doesn't cascade slowly. */
.vv-reveal-group > .vv-reveal:nth-child(1) { transition-delay: calc(var(--wp--custom--motion--stagger-step) * 0); }
.vv-reveal-group > .vv-reveal:nth-child(2) { transition-delay: calc(var(--wp--custom--motion--stagger-step) * 1); }
.vv-reveal-group > .vv-reveal:nth-child(3) { transition-delay: calc(var(--wp--custom--motion--stagger-step) * 2); }
.vv-reveal-group > .vv-reveal:nth-child(4) { transition-delay: calc(var(--wp--custom--motion--stagger-step) * 3); }
.vv-reveal-group > .vv-reveal:nth-child(5) { transition-delay: calc(var(--wp--custom--motion--stagger-step) * 4); }
.vv-reveal-group > .vv-reveal:nth-child(n+6) { transition-delay: calc(var(--wp--custom--motion--stagger-step) * 5); }

/*
 * Native scroll-driven reveal (R3.5, R3.7): `animation-timeline: view()`
 * ties the element's own progress through the viewport directly to the
 * animation, so it needs no observer, no scroll listener, and pauses for
 * free the instant the element leaves view. `animation-range: entry 0%
 * cover 35%` — the required explicit range clause — starts the animation
 * the moment the element's leading edge enters the scrollport and finishes
 * once it's 35% into "covering" it, matching the brief's timing exactly.
 * Gated behind the same two-part `@supports` test as the header (R3.4):
 * `animation-timeline` alone is not enough signal, since some browsers
 * shipped it without range support — the `animation-range` clause is
 * required to exclude that partial-support tier.
 */
@supports ((animation-timeline: view()) and (animation-range: 0% 100%)) {
	.vv-reveal {
		opacity: 0;
		transform: translateY(var(--wp--custom--motion--reveal-translate));
		transition: none;
		animation: vv-view-reveal var(--wp--custom--motion--large-duration) var(--wp--custom--motion--entrance-ease) both;
		animation-timeline: view();
		animation-range: entry 0% cover 35%;
	}

	/* The JS-driven `.is-visible` toggle never fires on a browser that
	   reaches this block (motion.js feature-detects the same condition
	   and skips its observer) — this rule is a defensive no-op in case
	   any element ever gets the class from elsewhere regardless. */
	.vv-reveal.is-visible {
		opacity: 1;
		transform: translateY(0);
	}

	@keyframes vv-view-reveal {
		from { opacity: 0; transform: translateY(var(--wp--custom--motion--reveal-translate)); }
		to   { opacity: 1; transform: translateY(0); }
	}

	/* R7: native-path equivalent of the numeral scale-pop above — same
	   element, same "settle at 1, never overshoot" rule, just swapping
	   which keyframe drives it since this path animates via `animation`
	   shorthand rather than a transition. `animation-name` alone overrides
	   just that part of the shorthand `.vv-reveal` already set. */
	.vv-steps__num.vv-reveal {
		transform: scale(0.85);
		animation-name: vv-num-pop;
	}

	@keyframes vv-num-pop {
		from { opacity: 0; transform: scale(0.85); }
		to   { opacity: 1; transform: scale(1); }
	}

	/* Stagger under the native path: `animation-delay`, not
	   `transition-delay` — same 40-60ms-per-item, 6-item cap. */
	.vv-reveal-group > .vv-reveal:nth-child(1) { animation-delay: calc(var(--wp--custom--motion--stagger-step) * 0); }
	.vv-reveal-group > .vv-reveal:nth-child(2) { animation-delay: calc(var(--wp--custom--motion--stagger-step) * 1); }
	.vv-reveal-group > .vv-reveal:nth-child(3) { animation-delay: calc(var(--wp--custom--motion--stagger-step) * 2); }
	.vv-reveal-group > .vv-reveal:nth-child(4) { animation-delay: calc(var(--wp--custom--motion--stagger-step) * 3); }
	.vv-reveal-group > .vv-reveal:nth-child(5) { animation-delay: calc(var(--wp--custom--motion--stagger-step) * 4); }
	.vv-reveal-group > .vv-reveal:nth-child(n+6) { animation-delay: calc(var(--wp--custom--motion--stagger-step) * 5); }
}

/*
 * Hero entrance (R3.5): load-triggered, never scroll-triggered — the hero
 * is above the fold on arrival, so there is no "entry" to key off. Heading,
 * subheading/eyebrow, buttons and image stagger in at 70ms intervals
 * (inside the brief's 60-90ms band) via plain `animation-delay` on page
 * load. The LCP element (`.vv-hero-image`, or the heading on a slow
 * connection where the image hasn't painted) is deliberately excluded —
 * see patterns/hero.php.
 */
.vv-hero-enter {
	opacity: 0;
	transform: translateY(var(--wp--custom--motion--reveal-translate));
	animation: vv-hero-enter var(--wp--custom--motion--large-duration) var(--wp--custom--motion--entrance-ease) both;
}

.vv-hero-enter[data-vv-hero-order="1"] { animation-delay: 70ms; }
.vv-hero-enter[data-vv-hero-order="2"] { animation-delay: 140ms; }
.vv-hero-enter[data-vv-hero-order="3"] { animation-delay: 210ms; }
.vv-hero-enter[data-vv-hero-order="4"] { animation-delay: 280ms; }

@keyframes vv-hero-enter {
	from { opacity: 0; transform: translateY(var(--wp--custom--motion--reveal-translate)); }
	to   { opacity: 1; transform: translateY(0); }
}

/*
 * The hero photo gets a slower, larger-scale settle (brief: "subtle scale
 * on load") — `transform` only, deliberately never `opacity`. The image is
 * almost always the actual LCP candidate in this layout (it's the largest
 * painted rect above the fold); animating its opacity would delay the
 * moment the browser can measure it as "painted" and directly hurt LCP,
 * the exact failure CLAUDE.md's "never animate the LCP element" rule
 * exists to prevent. Staying opaque from frame one while still scaling
 * satisfies the brief's "staggered entrance... then image" without that
 * cost — the image is visually part of the stagger, its paint isn't
 * delayed by it.
 */
.vv-hero-image-enter {
	transform: scale(1.04);
	animation: vv-hero-image-enter 600ms cubic-bezier(0.16, 1, 0.3, 1) both;
	animation-delay: 90ms;
}

@keyframes vv-hero-image-enter {
	from { transform: scale(1.04); }
	to   { transform: scale(1); }
}

@media (prefers-reduced-motion: reduce) {
	.vv-hero-enter,
	.vv-hero-image-enter {
		animation: none !important;
		opacity: 1;
		transform: none;
	}
}

/*
 * View Transitions (R3.7) — the cross-document transition itself is
 * declared once, site-wide, via the `<meta name="view-transition"
 * content="same-origin">` tag (functions.php); a browser without support
 * just navigates normally, which is the whole of "progressively
 * enhanced" here. This only tunes the transition's timing to the site's
 * own motion contract (520ms large-tier, matching a page-level
 * navigation) and — because the View Transition API does not honour
 * `prefers-reduced-motion` on its own — turns it off outright when that
 * preference is set, same as every other animation in this file.
 */
@supports (view-transition-name: none) {
	::view-transition-group(*) {
		animation-duration: var(--wp--custom--motion--large-duration);
	}

	::view-transition-old(*),
	::view-transition-new(*) {
		animation-timing-function: var(--wp--custom--motion--entrance-ease);
	}
}

@media (prefers-reduced-motion: reduce) {
	::view-transition-group(*),
	::view-transition-old(*),
	::view-transition-new(*) {
		animation: none !important;
	}
}

/* Loading sprig: uniform stroke-draw regardless of path length, thanks
   to pathLength="1" on each <path> in growing-sprig-loading.svg. */
.vv-illustration-loading .vv-draw {
	stroke-dasharray: 1;
	stroke-dashoffset: 1;
	animation: vv-stroke-draw var(--wp--custom--motion--loading-duration) var(--wp--custom--motion--loading-ease) infinite alternate;
}

.vv-illustration-loading .vv-draw:nth-child(2) { animation-delay: 120ms; }
.vv-illustration-loading .vv-draw:nth-child(3) { animation-delay: 240ms; }

@keyframes vv-stroke-draw {
	from { stroke-dashoffset: 1; }
	to { stroke-dashoffset: 0; }
}

/*
 * R7 — low-stock "sonar ping" (base.css scopes `position: relative` to
 * `.vv-badge--low-stock` only, not the shared `.vv-badge` rule). A ring
 * scales outward while fading — transform + opacity only, compositor-only,
 * cheap regardless of how many low-stock badges are on screen at once.
 * Deliberately `animation-iteration-count: 3`, not `infinite` — a grid of
 * 6-8 low-stock products all pulsing forever is visual noise, not
 * excitement, and undercuts the "earthy, not gimmicky" brief. Reuses
 * `.vv-reveal`'s own scroll-into-view trigger (`.is-visible`) rather than
 * firing off-screen the moment the page loads.
 */
.vv-badge--low-stock.vv-reveal.is-visible::before,
.vv-badge--low-stock.vv-reveal.is-visible::after {
	content: "";
	position: absolute;
	inset: 0;
	border-radius: inherit;
	border: 1.5px solid var(--wp--preset--color--harvest-600);
	animation: vv-badge-ping var(--wp--custom--motion--badge-ping-duration) ease-out 3;
	pointer-events: none;
}

.vv-badge--low-stock.vv-reveal.is-visible::after {
	animation-delay: calc(var(--wp--custom--motion--badge-ping-duration) / 2);
}

@keyframes vv-badge-ping {
	from { transform: scale(1); opacity: 0.6; }
	to   { transform: scale(1.6); opacity: 0; }
}

/*
 * R7 — cart-count bump. Fired once per increase by adding/removing this
 * class in cart-count.js (a reflow forces the animation to restart on
 * rapid successive adds rather than silently no-op). Transform only.
 */
.vv-cart-bump {
	animation: vv-cart-bump var(--wp--custom--motion--cart-bump-duration) var(--wp--custom--motion--entrance-ease) both;
}

@keyframes vv-cart-bump {
	0%, 100% { transform: scale(1); }
	50% { transform: scale(1.25); }
}

/*
 * R7 — how-it-works connecting line "draws in" once step 1 is visible.
 * `.vv-steps::before` is a flat CSS background bar (base.css), not SVG
 * geometry, so the stroke-dasharray technique above doesn't apply — this
 * is the transform-only equivalent, gated behind real `:has()` support
 * with a graceful fallback (line simply always shown, never a functional
 * break for a browser without `:has()`).
 */
@supports selector(:has(a)) {
	.vv-steps {
		--vv-steps-line-scale: 0;
	}

	.vv-steps:has(.vv-steps__item:first-child.is-visible) {
		--vv-steps-line-scale: 1;
	}

	.vv-steps::before {
		transform: scaleX(var(--vv-steps-line-scale));
		transform-origin: left center;
		transition: transform var(--wp--custom--motion--large-duration) var(--wp--custom--motion--entrance-ease);
	}
}

/* Reduced motion: every animation above collapses to an instant,
   opacity-only change. Content still appears, nothing moves or draws. */
@media (prefers-reduced-motion: reduce) {
	/* Explicitly kills the native `animation-timeline: view()` path above,
	   not just the JS/transition path — R3.7: "disabling scroll-driven
	   animation entirely rather than merely shortening it." `!important`
	   is needed here because the `@supports` block's own rule is otherwise
	   equal specificity and this must win regardless of source order. */
	.vv-reveal {
		transition: opacity 1ms linear !important;
		animation: none !important;
		animation-timeline: none !important;
		transform: none;
		opacity: 1;
	}

	.vv-illustration-loading .vv-draw {
		animation: none;
		stroke-dasharray: none;
		stroke-dashoffset: 0;
	}

	.vv-product-card__image img {
		transition: none;
	}

	.vv-product-card:hover .vv-product-card__image img,
	.vv-product-card:focus-within .vv-product-card__image img {
		transform: none;
	}

	/* R7: WooCommerce/WC-Blocks Add to Cart button hover-lift — declared in
	   woocommerce.css, killed here to keep every reduced-motion override in
	   one place, matching this file's own existing convention above. */
	.woocommerce a.button:hover,
	.woocommerce button.button:hover,
	.woocommerce input.button:hover,
	.wc-block-components-button:hover {
		transform: none;
	}

	.vv-badge--low-stock.vv-reveal.is-visible::before,
	.vv-badge--low-stock.vv-reveal.is-visible::after {
		animation: none;
		display: none;
	}

	.vv-cart-bump {
		animation: none;
	}

	.vv-steps::before {
		transition: none;
	}
}
