/*
 * core/group "Carousel": O17 card carousel, A12 arrows. Events cards EV 2945:2907,
 * Learn webinars LE 2960:4595, Success story gallery SS 2958:4345.
 *
 * The track is the Group itself (cards as direct children) or, when the Group
 * holds a Query Loop, the Query's Post Template. It's a horizontal scroll-snap
 * row: 3 cards per view on desktop, 2 from 782 px, 1 below 782 px. Add the class
 * meckup-carousel-single for one item per view (the gallery).
 *
 * assets/js/carousel.js adds the prev/next buttons after the track and hides
 * them when everything fits. Until it runs, space for the arrow row is
 * reserved when the item count predicts an overflow, so nothing shifts.
 *
 * Arrows (A12, provisional): 43 px circles with a 1 px border and the
 * chevron icon at 40 %, 24 px apart, 36 px below the cards, left aligned.
 */

.wp-block-group.is-style-carousel {
	--meckup-carousel-per-view: 3;
	--meckup-carousel-gap: var(--wp--preset--spacing--40);
	--meckup-carousel-nav-space: calc(var(--wp--custom--icon--carousel) + 3 * var(--wp--preset--spacing--30));
}

.wp-block-group.is-style-carousel.meckup-carousel-single {
	--meckup-carousel-per-view: 1;
}

@media (max-width: 1079px) {
	.wp-block-group.is-style-carousel {
		--meckup-carousel-per-view: 2;
	}
}

@media (max-width: 781px) {
	.wp-block-group.is-style-carousel {
		--meckup-carousel-per-view: 1;
	}
}

/* The track. */
.wp-block-group.is-style-carousel:not(:has(> .wp-block-query)),
.wp-block-group.is-style-carousel > .wp-block-query > .wp-block-post-template {
	display: flex;
	flex-wrap: nowrap;
	align-items: stretch;
	gap: var(--meckup-carousel-gap);
	padding: 0;
	overflow-x: auto;
	overscroll-behavior-x: contain;
	scroll-snap-type: x mandatory;
	scrollbar-width: none;
}

.wp-block-group.is-style-carousel > .wp-block-query > .wp-block-post-template {
	margin: 0;
	list-style: none;
}

.wp-block-group.is-style-carousel:not(:has(> .wp-block-query))::-webkit-scrollbar,
.wp-block-group.is-style-carousel > .wp-block-query > .wp-block-post-template::-webkit-scrollbar {
	display: none;
}

@media (prefers-reduced-motion: no-preference) {
	.wp-block-group.is-style-carousel:not(:has(> .wp-block-query)),
	.wp-block-group.is-style-carousel > .wp-block-query > .wp-block-post-template {
		scroll-behavior: smooth;
	}
}

/* The items: a fixed share of the track, snapped to its start edge. */
.wp-block-group.is-style-carousel:not(:has(> .wp-block-query)) > *,
.wp-block-group.is-style-carousel > .wp-block-query > .wp-block-post-template > * {
	flex: 0 0 calc((100% - (var(--meckup-carousel-per-view) - 1) * var(--meckup-carousel-gap)) / var(--meckup-carousel-per-view));
	min-width: 0;
	margin: 0;
	scroll-snap-align: start;
}

/* A card inside a Post Template item fills the item's height. */
.wp-block-group.is-style-carousel > .wp-block-query > .wp-block-post-template > * > .wp-block-group:only-child {
	box-sizing: border-box;
	height: 100%;
}

/*
 * Reserve the arrow row before the script runs, when the item count says the
 * track will overflow at this width. The script removes it (.is-carousel-ready).
 * Padding, not margin, so it can't collapse into the next section's gap.
 */
.wp-block-group.is-style-carousel:not(.is-carousel-ready):not(:has(> .wp-block-query)):has(> :nth-child(4)),
.wp-block-group.is-style-carousel:not(.is-carousel-ready) > .wp-block-query > .wp-block-post-template:has(> :nth-child(4)) {
	padding-block-end: var(--meckup-carousel-nav-space);
}

@media (max-width: 1079px) {
	.wp-block-group.is-style-carousel:not(.is-carousel-ready):not(:has(> .wp-block-query)):has(> :nth-child(3)),
	.wp-block-group.is-style-carousel:not(.is-carousel-ready) > .wp-block-query > .wp-block-post-template:has(> :nth-child(3)) {
		padding-block-end: var(--meckup-carousel-nav-space);
	}
}

@media (max-width: 781px) {
	.wp-block-group.is-style-carousel:not(.is-carousel-ready):not(:has(> .wp-block-query)):has(> :nth-child(2)),
	.wp-block-group.is-style-carousel:not(.is-carousel-ready) > .wp-block-query > .wp-block-post-template:has(> :nth-child(2)) {
		padding-block-end: var(--meckup-carousel-nav-space);
	}
}

.wp-block-group.is-style-carousel.meckup-carousel-single:not(.is-carousel-ready):not(:has(> .wp-block-query)):has(> :nth-child(2)) {
	padding-block-end: var(--meckup-carousel-nav-space);
}

/*
 * A12 arrows, added by carousel.js right after the track (after the Group, or
 * after the Post Template). Doubled class to beat the layout's block gap.
 */
.meckup-carousel-nav.meckup-carousel-nav {
	display: flex;
	gap: calc(2 * var(--wp--preset--spacing--30)); /* 24 px */
	margin-block: calc(3 * var(--wp--preset--spacing--30)) 0; /* 36 px below the cards */
}

.meckup-carousel-nav.meckup-carousel-nav[hidden] {
	display: none;
}

.meckup-carousel-nav button {
	display: grid;
	place-items: center;
	box-sizing: border-box;
	width: var(--wp--custom--icon--carousel);
	height: var(--wp--custom--icon--carousel);
	margin: 0;
	padding: 0;
	border: 1px solid currentColor;
	border-radius: 50%;
	background: none;
	color: var(--wp--preset--color--contrast);
	cursor: pointer;
}

.meckup-carousel-nav button::before {
	content: "";
	width: 40%;
	height: 40%;
	background-color: currentColor;
	-webkit-mask: var(--meckup-icon-chevron) center / contain no-repeat;
	mask: var(--meckup-icon-chevron) center / contain no-repeat;
}

.meckup-carousel-nav .meckup-carousel-prev::before {
	transform: scaleX(-1);
}

/* Hover isn't designed: orange, like nav items. Disabled is #666 (A12). */
.meckup-carousel-nav button:is(:hover, :focus-visible):not(:disabled) {
	color: var(--wp--preset--color--primary);
}

.meckup-carousel-nav button:disabled {
	color: var(--wp--preset--color--muted);
	cursor: default;
}

@media (prefers-reduced-motion: no-preference) {
	.meckup-carousel-nav button {
		transition: color 0.15s ease;
	}
}
