/* ——— Carousel (T-621 / D-67, shared with the product page in T-628) ———
 *
 * Markup: .tg-carousel > .tg-carousel__viewport (horizontal scroll-snap) > .tg-carousel__track > items,
 * then .tg-carousel__nav with prev / pause / next. Pointer and touch use native scrolling;
 * assets/js/carousel.js only adds the buttons, keyboard, autoplay and the pause control.
 *
 * Loaded on the front page and on product pages (the Related products row). The Home-only card
 * styling stays in home-ui-v2.css.
 *
 * The track is flex, not `grid-auto-flow: column`, and that was measured, not preferred:
 *   - `width: max-content` + `grid-auto-columns: calc((100% - gap)/3)` resolves the percentage
 *     against the track's own max-content size, so the first column became content-width
 *     (1600px image → 1600px column) and not even one fit;
 *   - dropping `width: max-content` (`width: auto`) squeezes the track to the viewport, all six
 *     cards pile into one screen (scrollWidth - clientWidth = 0) and the carousel stops working.
 * With flex, `flex: 0 0 <percentage>` resolves against the track's containing block (the
 * viewport), so it can be exactly 1/2/3 columns and still overflow. Column widths:
 * 1 column = 100%, 2 = (100% - gap)/2, 3 = (100% - 2*gap)/3. */

.tg-carousel {
	--tg-carousel-gap: var(--wp--preset--spacing--50);
	--tg-carousel-slide: 100%;
}

/* The shell must be compressible to the container: with six cards in the track, its min-content
 * walks up through .wp-block-query → .tg-carousel → the parent group (measured: a 375px viewport
 * grew the section to 937px and the document overflowed to 961px). `min-width: 0` cuts that
 * chain; scrolling belongs to the viewport. */
.tg-carousel,
.tg-carousel__viewport,
.tg-carousel .wp-block-query {
	min-width: 0;
	max-width: 100%;
}

.tg-carousel__viewport {
	overflow-x: auto;
	overflow-y: hidden;
	scroll-snap-type: x mandatory;
	scrollbar-width: none;
	-ms-overflow-style: none;
	overscroll-behavior-inline: contain;
	/* Cards lift 4px with a shadow on hover; leave that space or overflow-y clips it. */
	padding-block: var(--wp--preset--spacing--20);
}

.tg-carousel__viewport:focus {
	outline: none;
}

.tg-carousel__viewport:focus-visible {
	outline: 2px solid var(--wp--preset--color--accent);
	outline-offset: 2px;
}

.tg-carousel__viewport::-webkit-scrollbar {
	display: none;
	width: 0;
	height: 0;
}

/* Flex, and never `width: fit-content` on the track: a percentage `flex-basis` would then
 * resolve against the track itself and each card becomes content-width (measured 936px per card
 * at a 375px viewport, i.e. whole-document overflow). The track keeps the viewport's definite
 * width and the viewport's scroll-snap does the scrolling. */
.tg-carousel__track,
ul.tg-carousel__track {
	display: flex;
	flex-wrap: nowrap;
	align-items: stretch;
	gap: var(--tg-carousel-gap);
	width: 100%;
	margin: 0;
	padding: 0;
	list-style: none;
}

.tg-carousel__track > li,
.tg-carousel__track > * {
	flex: 0 0 var(--tg-carousel-slide);
	scroll-snap-align: start;
	min-width: 0;
}

.tg-carousel__nav {
	display: flex;
	justify-content: flex-end;
	align-items: center;
	gap: var(--wp--preset--spacing--20);
	margin-top: var(--wp--preset--spacing--50);
}

.tg-carousel__nav[hidden] {
	display: none;
}

/* No-JS fallback: a track with one card (or none) needs no controls, otherwise a pause button
 * that does nothing is left behind. carousel.js hides it too; both paths, whichever runs first. */
.tg-carousel:has(.tg-carousel__track > :only-child) .tg-carousel__nav,
.tg-carousel:has(.tg-carousel__track:empty) .tg-carousel__nav {
	display: none;
}

.tg-carousel__nav button {
	box-sizing: border-box;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	min-width: 44px;
	min-height: 44px;
	padding: 0 var(--wp--preset--spacing--30);
	background: var(--wp--preset--color--surface);
	border: 1px solid var(--wp--preset--color--rule);
	border-radius: var(--wp--custom--radius--button);
	color: var(--wp--preset--color--ink);
	font: inherit;
	font-size: 0.9375rem;
	font-weight: 600;
	line-height: 1;
	cursor: pointer;
}

.tg-carousel__nav button:hover {
	border-color: var(--wp--preset--color--accent);
	color: var(--wp--preset--color--accent);
}

.tg-carousel__nav button:focus-visible {
	outline: 2px solid var(--wp--preset--color--accent);
	outline-offset: 2px;
}

.tg-carousel__nav button[aria-disabled="true"],
.tg-carousel__nav button[disabled] {
	opacity: 0.45;
	cursor: default;
}

.tg-carousel__pause {
	position: relative;
}

/* Under reduced motion carousel.js never autoplays, so the pause button would do nothing; hide it
 * rather than leave a visible control that is inert (aria-hidden alone is not enough). */
.tg-carousel__pause[aria-hidden="true"] {
	display: none;
}

.tg-carousel__pause::before,
.tg-carousel__pause::after {
	content: "";
	position: absolute;
	top: 50%;
	width: 3px;
	height: 14px;
	margin-top: -7px;
	background: currentColor;
	border-radius: 1px;
}

.tg-carousel__pause::before {
	left: calc(50% - 5px);
}

.tg-carousel__pause::after {
	left: calc(50% + 2px);
}

.tg-carousel__pause[aria-pressed="true"]::after {
	content: none;
}

.tg-carousel__pause[aria-pressed="true"]::before {
	/* A CSS triangle instead of a data URI: colour comes from currentColor, no hex in CSS. */
	top: 50%;
	left: 52%;
	width: 0;
	height: 0;
	margin: -7px 0 0 -4px;
	background: none;
	border-style: solid;
	border-width: 7px 0 7px 12px;
	border-color: transparent transparent transparent currentColor;
	border-radius: 0;
}

@media (min-width: 640px) {
	.tg-carousel {
		--tg-carousel-slide: calc((100% - var(--tg-carousel-gap)) / 2);
	}
}

/* Owner review 2026-10-15: on phones the carousels stop autoplaying and read as a swipe list —
 * 85% per snap with the next card peeking, so the gesture is discoverable and one card owns the
 * screen. The track bleeds to the document edge, otherwise the peek is clipped by the container
 * gutter. The pause control goes with the autoplay. Placed after the 640px step so 640–767px
 * stays one card per snap rather than two. */
@media (max-width: 767px) {
	.tg-carousel {
		--tg-carousel-gap: 16px;
		--tg-carousel-slide: 85%;
		--tg-carousel-bleed: clamp(24px, 5vw, 56px);
	}

	.tg-carousel__viewport {
		margin-inline: calc(-1 * var(--tg-carousel-bleed));
		padding-inline: var(--tg-carousel-bleed);
		scroll-padding-inline: var(--tg-carousel-bleed);
	}

	.tg-carousel__pause {
		display: none;
	}
}

@media (min-width: 1024px) {
	.tg-carousel {
		--tg-carousel-slide: calc((100% - 2 * var(--tg-carousel-gap)) / 3);
	}
}

@media (prefers-reduced-motion: reduce) {
	.tg-carousel__viewport {
		scroll-behavior: auto;
	}

	.tg-carousel__nav button {
		transition: none;
	}
}
