/**
 * Slider: a block style on core/query, not a custom block.
 *
 * The track is plain CSS scroll-snap, so it is already usable by touch, trackpad and
 * keyboard before any JavaScript runs. slider.js only adds the arrows, the dots and the
 * ARIA wiring. If the script fails to load, the section degrades to a horizontal
 * scroller rather than breaking.
 */

.wp-block-query.is-style-slider {
	position: relative;
}

.wp-block-query.is-style-slider .wp-block-post-template {
	display: flex;
	flex-wrap: nowrap;
	gap: var(--wp--preset--spacing--40);
	margin: 0;
	padding: 0;
	list-style: none;
	overflow-x: auto;
	overscroll-behavior-x: contain;
	scroll-snap-type: x mandatory;
	scroll-behavior: smooth;
	scrollbar-width: none;
	-ms-overflow-style: none;
	/* Room for the card's top spine and focus rings. */
	padding-block: 3px;
}

.wp-block-query.is-style-slider .wp-block-post-template::-webkit-scrollbar {
	display: none;
}

.wp-block-query.is-style-slider .wp-block-post-template > li {
	flex: 0 0 var(--mf-slide, 82%);
	scroll-snap-align: start;
	margin: 0;
}

@media (min-width: 600px) {
	.wp-block-query.is-style-slider .wp-block-post-template > li {
		--mf-slide: calc((100% - var(--wp--preset--spacing--40)) / 2);
	}
}

@media (min-width: 900px) {
	.wp-block-query.is-style-slider .wp-block-post-template > li {
		--mf-slide: calc((100% - 2 * var(--wp--preset--spacing--40)) / 3);
	}
}

@media (min-width: 1200px) {
	.wp-block-query.is-style-slider .wp-block-post-template > li {
		--mf-slide: calc((100% - 3 * var(--wp--preset--spacing--40)) / 4);
	}
}

/* ----------------------------------------------------------------- controls */

.mf-slider__controls {
	display: flex;
	align-items: center;
	gap: 0.5rem;
	margin-block-start: var(--wp--preset--spacing--40);
}

.mf-slider__btn {
	flex: 0 0 auto;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	inline-size: 2.75rem;
	block-size: 2.75rem;
	padding: 0;
	background-color: var(--wp--preset--color--base);
	color: var(--wp--preset--color--contrast);
	border: 1px solid var(--wp--preset--color--contrast);
	border-radius: 0;
	cursor: pointer;
	transition: background-color 120ms ease, color 120ms ease;
}

.mf-slider__btn:hover:not([disabled]) {
	background-color: var(--wp--preset--color--primary);
	border-color: var(--wp--preset--color--primary);
	color: var(--wp--preset--color--base);
}

.mf-slider__btn:focus-visible {
	outline: 2px solid var(--wp--preset--color--primary);
	outline-offset: 2px;
}

.mf-slider__btn[disabled] {
	opacity: 0.3;
	cursor: default;
}

.mf-slider__btn svg {
	inline-size: 1.1rem;
	block-size: 1.1rem;
	fill: none;
	stroke: currentColor;
	stroke-width: 2;
}

/* Progress: one tick per page of slides, filling from the left. */
.mf-slider__dots {
	display: flex;
	flex: 0 1 auto;
	min-width: 0;
	gap: 0.35rem;
	margin-inline-start: auto;
}

.mf-slider__dot {
	/* Shrinks when there are many pages (one slide per page on phones). */
	flex: 0 1 1.75rem;
	min-inline-size: 0.5rem;
	inline-size: 1.75rem;
	block-size: 3px;
	padding: 0;
	border: 0;
	background-color: var(--wp--preset--color--line);
	cursor: pointer;
	transition: background-color 120ms ease;
}

.mf-slider__dot[aria-current="true"] {
	background-color: var(--wp--preset--color--primary);
}

.mf-slider__dot:focus-visible {
	outline: 2px solid var(--wp--preset--color--primary);
	outline-offset: 3px;
}

/* Keyboard users land on the track itself and arrow through it. */
.wp-block-query.is-style-slider .wp-block-post-template:focus-visible {
	outline: 2px solid var(--wp--preset--color--primary);
	outline-offset: 4px;
}

@media (prefers-reduced-motion: reduce) {
	.wp-block-query.is-style-slider .wp-block-post-template {
		scroll-behavior: auto;
	}

	.mf-slider__btn,
	.mf-slider__dot {
		transition: none;
	}
}
