/* Competition slider — a coverflow stack of image-led competition cards. The
   mechanics, and why this is not wage/carousel, are in render.php. */

.wp-block-wage-tccc-competition-slider {
	/* Percentages of a SLIDE's own width, so they hold at every viewport. */
	--competition-slider-behind-shift: -16%;
	--competition-slider-behind-scale: 0.8;
	/* The margin over 100% IS the gap between the active and ahead cards. */
	--competition-slider-ahead-shift: 105%;
	/* Off-stage parking — fully clear before the opacity fade finishes. */
	--competition-slider-out-left: -45%;
	--competition-slider-out-right: 216%;
	--competition-slider-dim: 0.5;
	/* The active card's width. Capped: past this the photo stops gaining. */
	--competition-slider-width: 48rem;
	--competition-slider-btn-size: 4rem;
	/* One paging speed: the desktop slide and the phone crossfade. */
	--competition-slider-speed: 0.5s;
	/* One size for the title AND the nav row that centres on it. */
	--competition-slide-title-size: var(--wp--preset--font-size--h-4);

	min-width: 0;
	/* Concede vertical scrolling, keep horizontal: otherwise a touch drag is
	   claimed by the browser and pointerup never lands. */
	touch-action: pan-y;
}

/* ── The stack ──────────────────────────────────────────────────────────── */

.competition-slider__stage {
	position: relative;
	max-width: var(--competition-slider-width);
	margin: 0;
	padding: 0;
	list-style: none;
}

/* Parked off-stage right by DEFAULT; the offset rules promote the few on screen. */
.competition-slider__slide {
	position: absolute;
	inset-block-start: 0;
	inset-inline-start: 0;
	width: 100%;
	z-index: 1;
	transform: translateX(var(--competition-slider-out-right));
	opacity: 0;
	/* Two or more steps away: contents unrendered, so their lazy photos are
	   not fetched until a slide is one step from showing. The discrete
	   transition holds a leaving card rendered until its fade-out is done. */
	content-visibility: hidden;
	transition: transform var(--competition-slider-speed) ease-in-out, opacity 0.35s 0.15s, content-visibility var(--competition-slider-speed) allow-discrete;
}

.competition-slider__slide:is([data-offset="0"], [data-offset="-1"], [data-offset="1"]) {
	content-visibility: visible;
}

/* The one slide in normal flow, so it gives the stage its height. No jump on
   change: every slide measures the same (fixed aspect, 2-line foot). */
.competition-slider__slide[data-offset="0"] {
	position: relative;
	z-index: 5;
	transform: none;
	opacity: 1;
}

.competition-slider__slide[data-offset="-1"] {
	z-index: 4;
	transform: translateX(var(--competition-slider-behind-shift)) scale(var(--competition-slider-behind-scale));
	opacity: var(--competition-slider-dim);
}

/* The active card's foot is transparent, so a title underlapping it would
   read through. The title only: the price in the same row flags the photo. */
.competition-slider__slide:is([data-offset="-1"], [data-offset="-2"], [data-offset="-3"]) .competition-slide__title {
	opacity: 0;
}

/* Faded, not cut: gone within the first half of the slide, before it can
   read through the incoming card's foot. */
.competition-slide__title {
	transition: opacity calc(var(--competition-slider-speed) / 2) ease-out;
}

/* Ahead keeps full scale — it is the same card arriving, not one receding. */
.competition-slider__slide[data-offset="1"] {
	z-index: 4;
	transform: translateX(var(--competition-slider-ahead-shift));
	opacity: var(--competition-slider-dim);
}

.competition-slider__slide:is([data-offset="-2"], [data-offset="-3"]) {
	z-index: 2;
	transform: translateX(var(--competition-slider-out-left)) scale(var(--competition-slider-behind-scale));
	opacity: 0;
}

.competition-slider__slide:is([data-offset="2"], [data-offset="3"]) {
	z-index: 2;
	transform: translateX(var(--competition-slider-out-right));
	opacity: 0;
}

/* ── Nav ────────────────────────────────────────────────────────────────── */

/* On the active card's photo: a box the photo's size, at the stage's top,
   pins one arrow to each side, vertically centred. */
.competition-slider__stack {
	position: relative;
}

.competition-slider__nav {
	position: absolute;
	/* Above the active slide (5) — its stretched link covers the foot too. */
	z-index: 6;
	inset-block-start: 0;
	inset-inline-start: 0;
	box-sizing: border-box;
	inline-size: min(100%, var(--competition-slider-width));
	aspect-ratio: var(--wp--custom--product--image--aspect-ratio);
	display: flex;
	justify-content: space-between;
	align-items: center;
	padding-inline: var(--wp--preset--spacing--xxs);
	/* The row itself must not eat clicks meant for the card under it. */
	pointer-events: none;
}

.competition-slider__btn {
	display: flex;
	align-items: center;
	justify-content: center;
	width: var(--competition-slider-btn-size);
	height: var(--competition-slider-btn-size);
	padding: 0;
	border: 0;
	/* A bare chevron on the photo: white, with a shadow so it holds on a light shot. */
	background: none;
	color: var(--wp--preset--color--white);
	filter: drop-shadow(0 1px 3px rgb(0 0 0 / 0.5));
	cursor: pointer;
	pointer-events: auto;
	transition: transform var(--wp--custom--transition--base);
}

.competition-slider__btn:hover {
	transform: scale(1.15);
}

.competition-slider__btn svg {
	inline-size: 100%;
	block-size: 100%;
}

/* ── Dots ───────────────────────────────────────────────────────────────── */

/* Built by view.js. The active dot is a pill whose fill is the time left
   before autoplay advances; its animationend IS the tick. They sit right of
   the active card's title: a box the height of a 2-line title, stage-wide,
   at the stack's bottom edge, holds them level with its FIRST line, so they
   stay put whether the title runs to one line or two. */
.wp-block-wage-tccc-competition-slider {
	--competition-slider-interval: 6s;
	--competition-slider-dot: 0.5rem;
	/* Each side of each dot, so the gap between two is one dot wide. */
	--competition-slider-dot-pad: calc(var(--competition-slider-dot) / 2);
	/* n hit areas, plus the pill's extra 3 dots. 0 until view.js sets the count. */
	--competition-slider-dots-width: calc(var(--competition-slider-dot-count, 0) * (var(--competition-slider-dot) + 2 * var(--competition-slider-dot-pad)) + min(var(--competition-slider-dot-count, 0), 1) * 3 * var(--competition-slider-dot));
}

.competition-slider__dots {
	position: absolute;
	/* Above the active slide (5) — its stretched link covers the foot too. */
	z-index: 6;
	inset-block-end: 0;
	inset-inline-start: 0;
	box-sizing: border-box;
	inline-size: min(100%, var(--competition-slider-width));
	block-size: calc(2 * var(--competition-slide-title-size) * var(--wp--custom--line-height--snug));
	display: flex;
	justify-content: flex-end;
	align-items: flex-start;
	/* Centres a dot's hit area on one title line. */
	padding-block-start: calc((var(--competition-slide-title-size) * var(--wp--custom--line-height--snug) - var(--competition-slider-dot) - 2 * var(--wp--preset--spacing--xxs)) / 2);
	/* The row must not eat clicks meant for the card under it. */
	pointer-events: none;
}

/* The button is the hit area; the bar inside it is what you see. */
.competition-slider__dot {
	display: flex;
	align-items: center;
	padding: var(--wp--preset--spacing--xxs) var(--competition-slider-dot-pad);
	border: 0;
	background: none;
	color: inherit;
	cursor: pointer;
	pointer-events: auto;
}

.competition-slider__dot-bar {
	position: relative;
	display: block;
	inline-size: var(--competition-slider-dot);
	block-size: var(--competition-slider-dot);
	border-radius: var(--wp--preset--border-radius--circle);
	overflow: hidden;
	background: color-mix(in oklch, currentColor 35%, transparent);
	transition: inline-size var(--wp--custom--transition--base);
}

.competition-slider__dot[aria-current] .competition-slider__dot-bar {
	inline-size: calc(4 * var(--competition-slider-dot));
}

.competition-slider__dot[aria-current] .competition-slider__dot-bar::after {
	content: "";
	position: absolute;
	inset: 0;
	background: currentColor;
	transform-origin: left;
	animation: competition-slider-progress var(--competition-slider-interval) linear forwards;
}

@keyframes competition-slider-progress {
	from { transform: scaleX(0); }
	to { transform: scaleX(1); }
}

/* Paused while someone is reading or using it. Hover only where hover is
   real: a tap leaves :hover stuck on touch screens. */
.wp-block-wage-tccc-competition-slider:focus-within .competition-slider__dot-bar::after {
	animation-play-state: paused;
}

@media (hover: hover) {
	.wp-block-wage-tccc-competition-slider:hover .competition-slider__dot-bar::after {
		animation-play-state: paused;
	}
}

/* ── The card ───────────────────────────────────────────────────────────── */

.competition-slide {
	position: relative;
	display: flex;
	flex-direction: column;
}

.competition-slide__link {
	position: absolute;
	inset: 0;
	z-index: 1;
}

.competition-slide__media {
	position: relative;
	aspect-ratio: var(--wp--custom--product--image--aspect-ratio);
	border-radius: var(--wp--preset--border-radius--l);
	overflow: clip;
	background: var(--wp--preset--color--tint);
}

.competition-slide__media img {
	display: block;
	width: 100%;
	height: 100%;
	object-fit: cover;
}

/* Anchored to the CARD, not the media box — the media's clip would crop the
   overhang that makes the ribbon read as a tag laid over the photo. */
.competition-slide__price {
	position: absolute;
	z-index: 1;
	inset-block-start: var(--wp--preset--spacing--m);
	inset-inline-end: 0;
	/* Extra inline-start padding pays for the slice the clip-path takes off. */
	padding: var(--wp--preset--spacing--xxs) var(--wp--preset--spacing--m) var(--wp--preset--spacing--xxs) var(--wp--preset--spacing--l);
	clip-path: polygon(var(--wp--preset--spacing--m) 0, 100% 0, 100% 100%, 0 100%);
	background: var(--wp--preset--color--secondary);
	color: var(--wp--preset--color--secondary-foreground);
	font-family: var(--wp--custom--heading--font-family);
	font-size: var(--wp--preset--font-size--h-4);
	font-weight: var(--wp--custom--heading--font-weight);
	line-height: var(--wp--custom--line-height--tight);
	white-space: nowrap;
}

/* price_html wraps every state in its own spans — keep each legible on the ribbon. */
.competition-slide__price :is(.woocommerce-Price-amount, .price, bdi, del, ins) {
	color: inherit;
	background: none;
	text-decoration: inherit;
}

/* The was-price: `inherit` above would wipe del's strike, so restate it. */
.competition-slide__price del {
	text-decoration: line-through;
}

/* Reserves the dots' width (measured by view.js) so a 2-line title can't run under them. */
.competition-slide__foot {
	margin-top: var(--wp--preset--spacing--s);
	padding-inline-end: calc(var(--competition-slider-dots-width, 0px) + var(--wp--preset--spacing--m));
}

/* Two lines, and two lines' height even at one: every slide must measure the
   same or the stage resizes as you page. Body vocabulary, not display — the
   prize name reads as a label beside the price, not a headline. */
.competition-slide__title {
	display: -webkit-box;
	-webkit-box-orient: vertical;
	-webkit-line-clamp: 2;
	overflow: hidden;
	margin: 0;
	min-height: calc(2em * var(--wp--custom--line-height--snug));
	font-family: var(--wp--preset--font-family--body);
	font-size: var(--competition-slide-title-size);
	font-weight: var(--wp--custom--font-weight--regular);
	line-height: var(--wp--custom--line-height--snug);
}

.competition-slide__title a {
	color: inherit;
	text-decoration: none;
}

.competition-slide__title a:hover {
	text-decoration: underline;
}

/* Phone only: desktop's whole card is the link, and the hero has its own button. */
.competition-slide__cta {
	display: none;
}

/* Closed to entry: the image carries the state, the price already says why. */
.competition-slide.is-closed .competition-slide__media {
	filter: grayscale(1);
}

.competition-slide.is-closed .competition-slide__price {
	background: var(--wp--preset--color--tint);
	color: var(--wp--preset--color--contrast);
}

/* ── Draw date ──────────────────────────────────────────────────────────── */

/* The pill is zap-competitions' zapc/draw-date block; its look is theme.json
   styles.blocks["zapc/draw-date"]. Only its place on the slide lives here. */
.competition-slide .wp-block-zapc-draw-date {
	font-size: var(--wp--preset--font-size--l);
	position: absolute;
	z-index: 1;
	inset-block-end: var(--wp--preset--spacing--s);
	inset-inline-start: var(--wp--preset--spacing--s);
}

/* Narrow desktop: the hero's slider column overlaps the text column's last
   track, so the behind card tucks flush under the active one instead of
   peeking left into the trust pill. */
@media (min-width: 64.0625rem) and (max-width: 80rem) {
	.wp-block-wage-tccc-competition-slider {
		--competition-slider-behind-shift: -10%;
	}
}

/* ── Stacked ────────────────────────────────────────────────────────────── */

@media (max-width: 64rem) {
	.wp-block-wage-tccc-competition-slider {
		/* min(100%, …) means the cap only bites on a tablet; a phone lane
		   narrower than it still gets a full-width card. */
		--competition-slider-width: 32rem;
		--competition-slide-title-size: var(--wp--preset--font-size--xl);
	}

	.competition-slide .wp-block-zapc-draw-date {
		font-size: var(--wp--preset--font-size--s);
	}

	.competition-slide__price {
		font-size: var(--wp--preset--font-size--l);
	}
}

@media (prefers-reduced-motion: reduce) {
	.competition-slider__slide,
	.competition-slider__btn,
	.competition-slider__dot-bar,
	.competition-slide__title {
		transition: none;
	}

	/* No animation, no autoplay: the active pill just shows full. */
	.competition-slider__dot[aria-current] .competition-slider__dot-bar::after {
		animation: none;
	}
}

/* ── Phone: flush ───────────────────────────────────────────────────────── */

/* The photo runs edge to edge, square, and fades into the section at its
   foot. Assumes a host with no inline padding at this width (the hero's
   slider column: @mobile padding 0), so the text takes the gutter itself. */
@media (max-width: 48rem) {
	.wp-block-wage-tccc-competition-slider {
		--competition-slider-width: 100%;
		/* The phone card has no ribbon-and-label pairing to defer to: the
		   prize name IS the headline here, so h-4 in the heading face. */
		--competition-slide-title-size: var(--wp--preset--font-size--h-4);
	}

	/* Square and full width. Stretched by hand: the card's column is
	   start-aligned so Enter Now keeps its natural width. */
	.competition-slide__media {
		align-self: stretch;
		border-radius: 0;
		background: none;
	}

	/* Opaque, in the section's own colour: during the crossfade the slide
	   underneath must not show through the fade or the title area. So the
	   photo's foot fades INTO that colour (a gradient laid over it), not
	   out to transparent (a mask). One column on the gutter: photo, title
	   row, Enter Now. */
	.competition-slide {
		align-items: flex-start;
		background: var(--wp--preset--color--base);
	}

	/* Desktop hides titles on the cards tucked behind; here nothing is
	   tucked behind, and the outgoing title must stay under the incoming
	   one like the photo does, whichever way you page. */
	.competition-slider__slide:is([data-offset]) .competition-slide__title {
		opacity: 1;
	}

	.competition-slide::before {
		content: "";
		position: absolute;
		/* Above the media box, which is positioned and later in the markup. */
		z-index: 1;
		inset-block-start: 0;
		inset-inline: 0;
		aspect-ratio: var(--wp--custom--product--image--aspect-ratio);
		background: linear-gradient(to bottom, transparent 60%, var(--wp--preset--color--base));
		pointer-events: none;
	}

	/* A crossfade, not the coverflow: at full bleed a card sliding the
	   width of the screen reads as the page moving. Every slide stays put;
	   only the active one is visible, and it fades in over the last. */
	.competition-slider__slide:not([data-offset="0"]) {
		transform: none;
		opacity: 0;
	}

	/* The incoming slide (z 5) fades in OVER the outgoing one, which holds
	   at full opacity until it is covered, then drops: no mid-fade dip to
	   the section background. */
	@media (prefers-reduced-motion: no-preference) {
		.competition-slider__slide {
			transition: opacity 0s var(--competition-slider-speed);
		}

		.competition-slider__slide[data-offset="0"] {
			transition: opacity var(--competition-slider-speed) ease-in-out;
		}
	}

	/* Title row: the title, then the price flag flush to the right edge.
	   No gap above: the fade already separates it from the photo. Still two
	   lines tall (every slide must measure the same), but the row sits at
	   the BOTTOM of that box, so a one-line title's spare line lands in the
	   photo's fade, not above Enter Now. */
	.competition-slide__foot {
		box-sizing: border-box;
		display: grid;
		grid-template-columns: 1fr auto;
		align-content: end;
		align-items: center;
		column-gap: var(--wp--preset--spacing--m);
		inline-size: 100%;
		min-block-size: calc(2 * var(--competition-slide-title-size) * var(--wp--custom--line-height--snug));
		margin-top: 0;
		padding-inline: var(--wp--preset--spacing--gutter);
	}

	.competition-slide__title {
		min-height: 0;
		font-family: var(--wp--custom--heading--font-family);
		font-weight: var(--wp--custom--heading--font-weight);
	}

	/* Off the photo and into the row: same flag shape, the draw-date pill's
	   colours (theme.json zapc/draw-date), out through the gutter to the edge. */
	.competition-slide__price {
		position: static;
		margin-inline-end: calc(-1 * var(--wp--preset--spacing--gutter));
		background: var(--wp--preset--color--tint);
		color: var(--wp--preset--color--contrast);
	}

	/* No draw date on a phone: the title row goes straight to Enter Now. */
	.competition-slide .wp-block-zapc-draw-date {
		display: none;
	}

	/* Above the stretched card link (z 1), so it is its own target. */
	.competition-slide__cta {
		position: relative;
		z-index: 2;
		display: inline-flex;
		margin-top: var(--wp--preset--spacing--s);
		margin-inline-start: var(--wp--preset--spacing--gutter);
	}

	/* Arrows nearer the screen edge. The chevron is the middle third of its
	   icon, so the icon slides outward inside the button (same hit area) and
	   the button clips the empty part that would pass the edge. */
	.competition-slider__btn {
		overflow: clip;
	}

	.competition-slider__btn[data-competition-slider-prev] svg {
		translate: -25% 0;
	}

	.competition-slider__btn[data-competition-slider-next] svg {
		translate: 25% 0;
	}

	/* On the Enter Now row, right-aligned. Anchor positioning pins them to
	   the ACTIVE card's button, whatever its height; anchor-scope keeps two
	   sliders on one page from sharing an anchor. Without anchor support
	   they sit at the stack's bottom-right instead. */
	.wp-block-wage-tccc-competition-slider {
		anchor-scope: --competition-slider-cta;
	}

	.competition-slider__slide[data-offset="0"] .competition-slide__cta {
		anchor-name: --competition-slider-cta;
	}

	.competition-slider__dots {
		inset-block-end: 0;
		inset-inline: auto calc(var(--wp--preset--spacing--gutter) - var(--competition-slider-dot-pad));
		inline-size: auto;
		block-size: auto;
		padding-block-start: 0;
	}

	@supports (anchor-name: --a) {
		.competition-slider__dots {
			position-anchor: --competition-slider-cta;
			inset-block: anchor(center) auto;
			translate: 0 -50%;
		}
	}
}

