/**
 * Cross-page View Transitions (owner B, THEME_SPEC 5.4).
 *
 * Loaded only when the page_transitions option is on and motion is not off
 * (an @view-transition rule cannot depend on a body class).
 * - Pages: the old one fades out rising 12px (260 ms), the new one fades in from
 *   12px below (380 ms, emphasized). Subtle level: a plain cross-fade.
 * - The header and the floating cart persist without animating. They are named
 *   only during a transition: a permanent view-transition-name would make the
 *   header a backdrop root and flatten the glass blur of its sticky bar.
 * - Product images morph from card to product page: inc/woocommerce.php gives them
 *   view-transition-name: revita-product-{ID} and view-transition-class: revita-product.
 *   On leaving a page, motion.js clears the name of every card image except the one
 *   linked to the destination, so only the clicked product morphs. Any product image
 *   left without a partner never ghosts over the new page: an old one is dropped, a new
 *   one enters with the page.
 * - Reduced motion: no transitions at all.
 */

@view-transition {
	navigation: auto;
}

::view-transition-old(root) {
	animation: revita-vt-out 260ms var(--wp--custom--motion--easing--standard, cubic-bezier(0.2, 0.7, 0.2, 1)) both;
}

::view-transition-new(root) {
	animation: revita-vt-in 380ms var(--wp--custom--motion--easing--emphasized, cubic-bezier(0.16, 1, 0.3, 1)) both;
}

html:has(> body.revita-motion-subtle)::view-transition-old(root) {
	animation-name: revita-vt-fade-out;
}

html:has(> body.revita-motion-subtle)::view-transition-new(root) {
	animation-name: revita-vt-fade-in;
	animation-duration: var(--wp--custom--motion--duration--base, 320ms);
}

/* Header and floating cart stay in place. */
html:active-view-transition .revita-header {
	view-transition-name: revita-header;
}

/* "body ..." because <body> carries the class revita-floating-cart too (names must be unique). */
html:active-view-transition body .revita-floating-cart {
	view-transition-name: revita-floating-cart;
}

::view-transition-group(revita-header),
::view-transition-group(revita-floating-cart),
::view-transition-new(revita-header),
::view-transition-new(revita-floating-cart) {
	animation: none;
}

::view-transition-old(revita-header),
::view-transition-old(revita-floating-cart) {
	display: none;
}

/* Product image morph (card → product page and back). */
::view-transition-group(*.revita-product) {
	animation-duration: 450ms;
	animation-timing-function: var(--wp--custom--motion--easing--emphasized, cubic-bezier(0.16, 1, 0.3, 1));
}

::view-transition-old(*.revita-product),
::view-transition-new(*.revita-product) {
	block-size: 100%;
	object-fit: contain;
}

/* Without a partner on the other page: no ghost of the old image; the new one enters like the page. */
::view-transition-old(*.revita-product):only-child {
	display: none;
}

::view-transition-new(*.revita-product):only-child {
	animation: revita-vt-in 380ms var(--wp--custom--motion--easing--emphasized, cubic-bezier(0.16, 1, 0.3, 1)) both;
}

@keyframes revita-vt-out {
	to {
		opacity: 0;
		transform: translateY(-12px);
	}
}

@keyframes revita-vt-in {
	from {
		opacity: 0;
		transform: translateY(12px);
	}
}

@keyframes revita-vt-fade-out {
	to {
		opacity: 0;
	}
}

@keyframes revita-vt-fade-in {
	from {
		opacity: 0;
	}
}

@media (prefers-reduced-motion: reduce) {
	@view-transition {
		navigation: none;
	}

	::view-transition-group(*),
	::view-transition-old(*),
	::view-transition-new(*) {
		animation: none !important;
	}
}
