/* NP Hover Swap Front — v0.1.4 */

/*
 * Image swap for WooCommerce catalogue images.
 * Markup: .np-hs > .np-hs__stage > .np-hs__inner > (.np-hs__back + .np-hs__front), plus .np-hs__flap.
 * Modifier on .np-hs: --none | --curl (page turn) | --flip.
 * The front face sits in normal flow, raised above the back with z-index (gives the box its height);
 * the back face is absolutely positioned behind it.
 * Triggers: pointer hover on devices that have one, or .np-hs--on (added by front.js on first tap on touch screens).
 * --c drives the page-turn: 0% = flat, 200% = fully peeled. Registered so it can animate.
 * Browsers without @property support get the end state instantly.
 * Hover is also taken from .wc-block-components-product-image (block grids), because WooCommerce
 * puts an overlay container over the image there that would otherwise catch the pointer.
 */
@property --c {
	syntax: '<percentage>';
	inherits: true;
	initial-value: 0%;
}

.np-hs,
.np-hs__stage,
.np-hs__inner,
.np-hs__face {
	display: block;
}

.np-hs {
	position: relative;
	width: 100%;
}

.np-hs__stage {
	position: relative;
	perspective: 900px;
}

.np-hs__inner {
	position: relative;
}

.np-hs__back {
	position: absolute;
	inset: 0;
}

.np-hs__back .np-hs__img {
	display: block;
	width: 100%;
	height: 100%;
	margin: 0;
	object-fit: cover;
}

.np-hs__front {
	position: relative;
	z-index: 1;
}

.np-hs__front img {
	display: block;
	width: 100%;
	height: auto;
	margin: 0;
}

.np-hs__flap {
	display: none;
}

/* Page turn: bottom-right corner peels away to the top-left */
.np-hs--curl .np-hs__inner {
	display: contents;
}

.np-hs--curl .np-hs__stage {
	overflow: hidden;
	--k: calc(200% - var(--c));
	--tx: min(100%, var(--k));
	--ty: max(0%, calc(100% - var(--c)));
	transition: --c 0.9s cubic-bezier(0.45, 0, 0.25, 1);
}

.np-hs--curl .np-hs__front {
	clip-path: polygon(0 0, var(--tx) 0, var(--tx) var(--ty), var(--ty) var(--tx), 0 var(--tx));
}

.np-hs--curl .np-hs__flap {
	display: block;
	position: absolute;
	inset: 0;
	z-index: 3;
	background: #f4f3ee;
	clip-path: polygon(
		calc(var(--k) - var(--ty)) calc(var(--k) - var(--tx)),
		calc(var(--k) - var(--ty)) calc(var(--k) - 100%),
		calc(var(--k) - 100%) calc(var(--k) - 100%),
		calc(var(--k) - 100%) calc(var(--k) - var(--ty)),
		calc(var(--k) - var(--tx)) calc(var(--k) - var(--ty))
	);
}

/* Flip: rotates around the vertical centre line, counter-clockwise */
.np-hs--flip .np-hs__inner {
	transform-style: preserve-3d;
	transition: transform 0.7s cubic-bezier(0.4, 0, 0.2, 1);
}

.np-hs--flip .np-hs__face {
	backface-visibility: hidden;
}

.np-hs--flip .np-hs__back {
	transform: rotateY(180deg);
}

/* Triggered state: tapped (touch) */
.np-hs--none.np-hs--on .np-hs__front {
	opacity: 0;
}

.np-hs--curl.np-hs--on .np-hs__stage {
	--c: 200%;
}

.np-hs--flip.np-hs--on .np-hs__inner {
	transform: rotateY(-180deg);
}

/* Triggered state: pointer hover */
@media (hover: hover) {
	.np-hs--none:hover .np-hs__front,
	.wc-block-components-product-image:hover .np-hs--none .np-hs__front {
		opacity: 0;
	}

	.np-hs--curl:hover .np-hs__stage,
	.wc-block-components-product-image:hover .np-hs--curl .np-hs__stage {
		--c: 200%;
	}

	.np-hs--flip:hover .np-hs__inner,
	.wc-block-components-product-image:hover .np-hs--flip .np-hs__inner {
		transform: rotateY(-180deg);
	}
}

@media (prefers-reduced-motion: reduce) {
	.np-hs--curl .np-hs__stage,
	.np-hs--flip .np-hs__inner {
		transition: none;
	}
}
