/*
 * 3D By Humpf Store: site-wide motion, small touches only [site-wide, subtle].
 * Page transitions, product card second photo, press and add-to-cart feedback, video controls.
 * The bigger home page motion lives in home.css (front page only).
 *
 * Off switches (Settings > Reading > Theme Motion adds the body class):
 *   humpf-no-transitions  page-to-page transitions
 *   humpf-no-card-hover   card second photo and lift
 *   humpf-no-feedback     button press and add-to-cart feedback
 *   humpf-no-reveal       fade-in on scroll (assets/js/motion.js only, no CSS here)
 * Reduced motion: no page transitions, no press scaling; the photo crossfade stays (opacity only).
 */

:root {
	--humpf-ease-out: cubic-bezier(0.16, 1, 0.3, 1);
}

/* ---------- Page transitions [site-wide, subtle] ----------
 * Same-site links cross-fade with a short rise; the header stays put. Browsers without
 * cross-document View Transitions navigate as before. */

@media (prefers-reduced-motion: no-preference) {
	@view-transition {
		navigation: auto;
	}
}

.wp-site-blocks > header.wp-block-template-part {
	view-transition-name: humpf-header;
}

::view-transition-old(root) {
	animation: 140ms ease-in both humpf-vt-out;
}

::view-transition-new(root) {
	animation: 280ms var(--humpf-ease-out) both humpf-vt-in;
}

::view-transition-group(humpf-header) {
	animation-duration: 0s;
}

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

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

html:has(body.humpf-no-transitions)::view-transition-group(*),
html:has(body.humpf-no-transitions)::view-transition-old(*),
html:has(body.humpf-no-transitions)::view-transition-new(*) {
	animation: none !important;
}

/* ---------- Product card: second photo on hover [site-wide, subtle] ----------
 * motion.js adds img.humpf-card__alt on the first hover (desktop pointers only). */

.humpf-card__media > a {
	position: relative;
	display: block;
}

.humpf-card__alt {
	position: absolute;
	inset: 0;
	width: 100%;
	height: 100% !important;
	object-fit: cover;
	opacity: 0;
	pointer-events: none;
	transition: opacity 0.4s var(--humpf-ease), transform 0.45s var(--humpf-ease);
}

@media (hover: hover) {
	body:not(.humpf-no-card-hover) .wc-block-product:hover .humpf-card__alt.is-ready {
		opacity: 1;
	}
}

body.humpf-no-card-hover .wp-block-woocommerce-product-template .wc-block-product > .wp-block-group:hover,
body.humpf-no-card-hover .wp-block-woocommerce-product-template .wc-block-product:hover .wc-block-components-product-image img {
	transform: none;
}

/* ---------- Press feedback [site-wide, subtle] ----------
 * Buttons sink a little while pressed. "scale" leaves other transforms alone. */

@media (prefers-reduced-motion: no-preference) {
	body:not(.humpf-no-feedback) :is(.wp-element-button, .wp-block-button__link, .wc-block-components-button, .wc-block-components-quantity-selector__button, .humpf-film-toggle):active {
		scale: 0.97;
	}
}

/* ---------- Video pause/play button (home films) ---------- */

.humpf-film-toggle {
	position: absolute;
	z-index: 3;
	right: var(--wp--preset--spacing--40);
	bottom: var(--wp--preset--spacing--40);
	display: grid;
	place-items: center;
	width: var(--humpf-tap);
	height: var(--humpf-tap);
	margin: 0 !important;
	padding: 0;
	border: 1px solid rgba(244, 241, 234, 0.4);
	border-radius: 50%;
	background: rgba(13, 13, 13, 0.6);
	color: var(--wp--preset--color--contrast);
	cursor: pointer;
	backdrop-filter: blur(6px);
	transition: background-color 0.15s ease, border-color 0.15s ease;
}

.humpf-film-toggle:hover {
	background: rgba(13, 13, 13, 0.85);
	border-color: var(--wp--preset--color--contrast);
}

/* Pause icon: two bars. Play icon: a triangle. */
.humpf-film-toggle::before {
	content: "";
	width: 12px;
	height: 14px;
	background: linear-gradient(90deg, currentColor 0 4px, transparent 4px 8px, currentColor 8px 12px);
}

.humpf-film-toggle[data-state="paused"]::before {
	width: 12px;
	margin-left: 3px;
	background: currentColor;
	clip-path: polygon(0 0, 100% 50%, 0 100%);
}

/* Home films: the video fades in over its poster once it plays. */
.humpf-film {
	position: absolute;
	inset: 0;
	width: 100%;
	height: 100%;
	object-fit: cover;
	border-radius: inherit;
	opacity: 0;
	transition: opacity 0.8s ease;
	pointer-events: none;
}

.is-started > .humpf-film {
	opacity: 1;
}

/* =========================================================================
 * Micro-interactions: additive polish. Original effects and timings stay above.
 * ====================================================================== */

/* Keep the existing hover lift/zoom, alternate-photo crossfade and their timings.
 * The independent scale property adds a press state without replacing transforms. */
@media (prefers-reduced-motion: no-preference) {
	body:not(.humpf-no-motion):not(.humpf-no-card-hover) .wp-block-woocommerce-product-template .wc-block-product > .wp-block-group {
		transition: border-color 0.2s ease, transform 0.25s var(--humpf-ease), box-shadow 0.25s var(--humpf-ease), scale 150ms var(--humpf-ease-out);
	}

	body:not(.humpf-no-motion):not(.humpf-no-card-hover) .wp-block-woocommerce-product-template .wc-block-product > .wp-block-group:active {
		scale: 0.99;
	}

	body:not(.humpf-no-motion):not(.humpf-no-feedback) :is(.wp-element-button, .wp-block-button__link, .wc-block-components-button, .wc-block-components-quantity-selector__button, .humpf-film-toggle) {
		transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease, scale 150ms var(--humpf-ease-out);
	}

	body:not(.humpf-no-motion):not(.humpf-no-feedback) .humpf-add-to-cart .single_add_to_cart_button,
	body:not(.humpf-no-motion):not(.humpf-no-feedback) .humpf-sticky-atc__button {
		will-change: transform, opacity;
	}

	/* Only the check fades; its existing reserved space and final shape stay put. */
	body:not(.humpf-no-motion):not(.humpf-no-feedback) .humpf-add-to-cart .wc-block-product-filter-chips__label::before {
		border-color: currentColor;
		opacity: 0;
		transition: opacity 180ms var(--humpf-ease-out);
	}

	body:not(.humpf-no-motion):not(.humpf-no-feedback) .humpf-add-to-cart .wc-block-product-filter-chips__item[aria-checked="true"] .wc-block-product-filter-chips__label::before {
		opacity: 1;
	}

	/* WordPress retains its native open/hidden state and layout timing. */
	body:not(.humpf-no-motion) .humpf-details .wp-block-accordion-item > .wp-block-accordion-heading .wp-block-accordion-heading__toggle-icon {
		transition: transform 180ms var(--humpf-ease-out);
	}

	body:not(.humpf-no-motion) .humpf-details .wp-block-accordion-item.is-open .wp-block-accordion-panel {
		animation: humpf-micro-fade-in 200ms var(--humpf-ease-out);
	}

	/* Easing only: Woo retains its durations, endpoints, aria and focus handling. */
	body:not(.humpf-no-motion) :is(.wc-block-mini-cart__drawer, .wc-block-mini-cart__drawer-overlay, .wc-block-components-drawer__screen-overlay, .wc-block-components-drawer__screen-overlay .wc-block-components-drawer) {
		transition-timing-function: var(--humpf-ease-out);
		animation-timing-function: var(--humpf-ease-out);
	}
}

/* Free pseudo-elements let the ring fade without moving a control's border. */
body:not(.humpf-no-motion):not(.humpf-no-feedback) :is(.humpf-add-to-cart .wc-block-product-filter-chips__item, .humpf-details .wp-block-accordion-heading__toggle, .humpf-sticky-atc__button) {
	position: relative;
}

body:not(.humpf-no-motion):not(.humpf-no-feedback) :is(.humpf-add-to-cart .wc-block-product-filter-chips__item, .humpf-details .wp-block-accordion-heading__toggle, .humpf-sticky-atc__button)::after {
	content: "";
	position: absolute;
	inset: 0;
	border-radius: inherit;
	outline: 2px solid var(--wp--custom--focus-ring);
	outline-offset: 2px;
	opacity: 0;
	pointer-events: none;
	transition: opacity 150ms var(--humpf-ease-out);
}

.humpf-details .wp-block-accordion-heading__toggle::after {
	outline-offset: -2px;
}

@media (forced-colors: none) and (prefers-reduced-motion: no-preference) {
	body:not(.humpf-no-motion):not(.humpf-no-feedback) :is(.humpf-add-to-cart .wc-block-product-filter-chips__item, .humpf-details .wp-block-accordion-heading__toggle, .humpf-sticky-atc__button):focus-visible {
		outline-color: transparent;
	}

	body:not(.humpf-no-motion):not(.humpf-no-feedback) :is(.humpf-add-to-cart .wc-block-product-filter-chips__item, .humpf-details .wp-block-accordion-heading__toggle, .humpf-sticky-atc__button):focus-visible::after {
		opacity: 1;
	}
}

@keyframes humpf-micro-fade-in {
	from { opacity: 0; }
	to { opacity: 1; }
}
