/**
 * Header motion (owner B, THEME_SPEC 5.3); the static header is parts/header.css (owner C).
 * - body.revita-sticky-header: the template-part wrapper sticks (the header group cannot:
 *   its parent is exactly as tall as it is).
 * - motion.js toggles .is-scrolled past 24px and measures the top bar into
 *   --revita-header-collapse (what tucks under the screen edge, keeping
 *   --revita-header-keep visible) and --revita-header-h (visible sticky height).
 * - Scrolled: the whole honeycomb top bar tucks away through the sticky offset (no height
 *   animation, so nothing reflows), leaving the 60px navigation bar; on the desktop layout
 *   (1100px wide and taller than 500px) the small logo appears at its start (shown by
 *   parts/header.css, animated here). The purple bar turns to glass with a soft shadow, painted on
 *   ::before so the fixed mobile menu inside never gets a filtered ancestor.
 *   No JS: the whole header sticks. Motion off: no transitions.
 * - Add to cart: motion.js adds .is-bumped to the header's mini-cart for 900 ms (the header
 *   is always in view): a honey ring at every level, plus a bounce, a badge pop and a ripple
 *   with motion on.
 */

:root {
	--revita-adminbar: var(--wp-admin--admin-bar--height, 0px);
}

/* The admin bar scrolls away below 600px. */
@media (max-width: 600px) {
	:root {
		--revita-adminbar: 0px;
	}
}

/* How much of the top bar stays in view when scrolled (a variation may keep some). */
.revita-header {
	--revita-header-keep: 0px;
}

body.revita-sticky-header .wp-site-blocks > .wp-block-template-part:has(> .revita-header) {
	position: sticky;
	inset-block-start: calc(var(--revita-adminbar) - var(--revita-header-collapse, 0px));
	z-index: var(--wp--custom--z--header, 50);
}

/* In-page anchors stop below the visible part of the sticky header. */
html:root:has(> body.revita-sticky-header) {
	scroll-padding-block-start: calc(var(--revita-header-h, var(--wp--custom--header--height-compact, 60px)) + var(--revita-adminbar) + 1rem);
}

/* Scrolled, on the desktop layout: parts/header.css shows the small logo (hidden there while
 * the big one shows) in the free start column of the navigation bar; it scales in below. */

/* Glass bar: deep purple at 86% (white text 7:1, honey 4.6:1 even over white content). */
.revita-header .revita-header__nav {
	isolation: isolate;
}

.revita-header .revita-header__nav::before {
	content: "";
	position: absolute;
	inset: 0;
	z-index: -1;
	background-color: var(--wp--preset--color--primary-deep);
	background-color: color-mix(in srgb, var(--wp--preset--color--primary-deep) 86%, transparent);
	-webkit-backdrop-filter: blur(14px) saturate(140%);
	backdrop-filter: blur(14px) saturate(140%);
	box-shadow: var(--wp--preset--shadow--soft);
	opacity: 0;
	pointer-events: none;
}

body.revita-sticky-header .revita-header.is-scrolled .revita-header__nav {
	background: transparent;
}

body.revita-sticky-header .revita-header.is-scrolled .revita-header__nav::before {
	opacity: 1;
}

/* No backdrop-filter: a solid bar instead of a see-through one. */
@supports not ((-webkit-backdrop-filter: blur(1px)) or (backdrop-filter: blur(1px))) {
	.revita-header .revita-header__nav::before {
		background-color: var(--wp--preset--color--primary-deep);
	}
}

/* "Added!" ring on the header cart at every motion level (it does not move). */
.revita-header .wc-block-mini-cart.is-bumped .wc-block-mini-cart__button {
	box-shadow: 0 0 0 3px var(--wp--preset--color--accent);
}

/* The keyboard focus ring (header.css) stays on top of the bump. */
.revita-header .wc-block-mini-cart.is-bumped .wc-block-mini-cart__button:focus-visible {
	outline: 2px solid var(--wp--preset--color--base);
	outline-offset: 3px;
}

@media (prefers-reduced-motion: no-preference) {
	body.revita-sticky-header:not(.revita-motion-off) .revita-header .revita-header__nav::before {
		transition: opacity var(--wp--custom--motion--duration--fast, 160ms) linear;
	}

	body:not(.revita-motion-off) .revita-header .wc-block-mini-cart.is-bumped .wc-block-mini-cart__button {
		animation:
			revita-cart-bounce 700ms var(--wp--custom--motion--easing--standard, cubic-bezier(0.2, 0.7, 0.2, 1)),
			revita-cart-ripple 900ms var(--wp--custom--motion--easing--standard, cubic-bezier(0.2, 0.7, 0.2, 1));
	}

	body:not(.revita-motion-off) .revita-header .wc-block-mini-cart.is-bumped .wc-block-mini-cart__badge {
		animation: revita-cart-badge-pop 700ms var(--wp--custom--motion--easing--standard, cubic-bezier(0.2, 0.7, 0.2, 1));
	}
}

/* Desktop layout only: in the compact layout the small logo is always there, so it must not
 * pop each time the header turns .is-scrolled. */
@media (prefers-reduced-motion: no-preference) and (min-width: 1100px) and (min-height: 501px) {
	body.revita-sticky-header:not(.revita-motion-off) .revita-header.is-scrolled .revita-header__nav .revita-header__mobile-logo {
		animation: revita-header-logo-in var(--wp--custom--motion--duration--base, 320ms) var(--wp--custom--motion--easing--emphasized, cubic-bezier(0.16, 1, 0.3, 1)) both;
	}
}

@keyframes revita-header-logo-in {
	from {
		opacity: 0;
		scale: 0.6;
	}
}

/* Hop, squash, settle (small: the bar is only 60px tall); translate and scale leave
 * WooCommerce's own transforms intact. */
@keyframes revita-cart-bounce {
	0%,
	100% {
		translate: 0 0;
		scale: 1;
	}

	22% {
		translate: 0 -6px;
		scale: 0.94 1.06;
	}

	42% {
		translate: 0 0;
		scale: 1.1 0.9;
	}

	62% {
		translate: 0 -2px;
		scale: 0.98 1.03;
	}

	82% {
		translate: 0 0;
		scale: 1.02 0.98;
	}
}

/* A honey ring spreads out and fades. */
@keyframes revita-cart-ripple {
	from {
		box-shadow: 0 0 0 0 var(--wp--preset--color--accent);
	}

	to {
		box-shadow: 0 0 0 14px color-mix(in srgb, var(--wp--preset--color--accent) 0%, transparent);
	}
}

@keyframes revita-cart-badge-pop {
	0%,
	100% {
		scale: 1;
	}

	30% {
		scale: 1.5;
	}

	55% {
		scale: 0.88;
	}

	78% {
		scale: 1.12;
	}
}
