/*
 * Carousel, CSS version: a scroll snap carousel with no script.
 * The arrows come from ::scroll-button() and the dots from ::scroll-marker (Chrome 135 and
 * later). The browser disables each arrow at its end and marks the dot for the slide in view.
 * Slides and colors are the ones on purecss.com/scroll-carousel/.
 * Icons: Font Awesome Free 7.3.1 arrow-left and arrow-right, CC BY 4.0,
 * https://fontawesome.com/license/free
 */

/* The arrows are placed against the wrap, so it is the positioned box */
.demo-scroll-carousel .carousel-wrap {
	position: relative;
	width: 100%;
	max-width: 520px;
	margin: 0 auto;
}

.demo-scroll-carousel .carousel {
	display: flex;
	overflow-x: auto;
	scroll-snap-type: x mandatory;
	scroll-behavior: smooth;
	/* hands the scroller to the compositor, so the arrows' smooth scroll keeps moving while the
	   page's main thread is busy (without it Chrome 157 scrolled this one on the main thread) */
	will-change: scroll-position;
	border-radius: 10px;
	scrollbar-width: none;
	/* the dots are drawn in a row after the carousel. With tabs, they are one Tab stop and the
	   arrow keys move between them (plain "after" makes each dot its own Tab stop). The first
	   line is a fallback, kept in case a browser reads "after" but not "after tabs" */
	scroll-marker-group: after;
	scroll-marker-group: after tabs;
}

.demo-scroll-carousel .carousel::-webkit-scrollbar {
	display: none;
}

.demo-scroll-carousel .carousel-slide {
	flex: 0 0 100%;
	height: 160px;
	scroll-snap-align: start;
	/* a fast swipe stops at the next slide instead of flying past it */
	scroll-snap-stop: always;
	display: flex;
	align-items: center;
	justify-content: center;
	font-size: 1.2rem;
	font-weight: 700;
	color: #0c0c0d;
	-webkit-user-select: none;
	user-select: none;
}

.demo-scroll-carousel .carousel-slide:nth-child(1) { background: #c084fc; }
.demo-scroll-carousel .carousel-slide:nth-child(2) { background: #38bdf8; }
.demo-scroll-carousel .carousel-slide:nth-child(3) { background: #ffd444; }
.demo-scroll-carousel .carousel-slide:nth-child(4) { background: #57d9a3; }
.demo-scroll-carousel .carousel-slide:nth-child(5) { background: #b8ff57; }

/* Arrows. Each click scrolls one slide; the text after the slash is the button's name */
.demo-scroll-carousel .carousel::scroll-button(*) {
	/* a page's *::before, *::after reset does not reach these pseudo-elements */
	box-sizing: border-box;
	position: absolute;
	/* half the slide height, so the arrow sits on the slide's middle */
	top: 80px;
	width: 40px;
	height: 40px;
	margin-top: -20px;
	padding: 0;
	border: 0;
	border-radius: 50%;
	background-color: rgba(24, 22, 29, .6);
	background-position: center;
	background-size: 16px 16px;
	background-repeat: no-repeat;
	cursor: pointer;
}

.demo-scroll-carousel .carousel::scroll-button(left) {
	content: "" / "Previous slide";
	left: 8px;
	background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 512 512'%3E%3Cpath fill='%23fff' d='M9.4 233.4c-12.5 12.5-12.5 32.8 0 45.3l160 160c12.5 12.5 32.8 12.5 45.3 0s12.5-32.8 0-45.3L109.3 288 480 288c17.7 0 32-14.3 32-32s-14.3-32-32-32l-370.7 0 105.4-105.4c12.5-12.5 12.5-32.8 0-45.3s-32.8-12.5-45.3 0l-160 160z'/%3E%3C/svg%3E");
}

.demo-scroll-carousel .carousel::scroll-button(right) {
	content: "" / "Next slide";
	right: 8px;
	background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 512 512'%3E%3Cpath fill='%23fff' d='M502.6 278.6c12.5-12.5 12.5-32.8 0-45.3l-160-160c-12.5-12.5-32.8-12.5-45.3 0s-12.5 32.8 0 45.3L402.7 224 32 224c-17.7 0-32 14.3-32 32s14.3 32 32 32l370.7 0-105.4 105.4c-12.5 12.5-12.5 32.8 0 45.3s32.8 12.5 45.3 0l160-160z'/%3E%3C/svg%3E");
}

/* the browser disables an arrow when there is no slide left in its direction */
.demo-scroll-carousel .carousel::scroll-button(*):disabled {
	opacity: .35;
	cursor: default;
}

.demo-scroll-carousel .carousel::scroll-button(*):focus-visible {
	outline: 2px solid #18161d;
	outline-offset: 2px;
}

/* Dots: one marker per slide, in a 20px box with a 10px dot inside */
.demo-scroll-carousel .carousel::scroll-marker-group {
	display: flex;
	justify-content: center;
	gap: 10px;
	height: 20px;
	margin: 5px 0;
}

.demo-scroll-carousel .carousel-slide::scroll-marker {
	content: "";
	box-sizing: border-box;
	width: 20px;
	height: 20px;
	border: 5px solid transparent;
	border-radius: 50%;
	background: rgba(24, 22, 29, .25) padding-box;
	cursor: pointer;
}

/* the text after the slash names each dot for screen readers */
.demo-scroll-carousel .carousel-slide:nth-child(1)::scroll-marker { content: "" / "Slide 1"; }
.demo-scroll-carousel .carousel-slide:nth-child(2)::scroll-marker { content: "" / "Slide 2"; }
.demo-scroll-carousel .carousel-slide:nth-child(3)::scroll-marker { content: "" / "Slide 3"; }
.demo-scroll-carousel .carousel-slide:nth-child(4)::scroll-marker { content: "" / "Slide 4"; }
.demo-scroll-carousel .carousel-slide:nth-child(5)::scroll-marker { content: "" / "Slide 5"; }

/* the dot for the slide in view */
.demo-scroll-carousel .carousel-slide::scroll-marker:target-current {
	background-color: rgba(24, 22, 29, .75);
}

.demo-scroll-carousel .carousel-slide::scroll-marker:focus-visible {
	outline: 2px solid #18161d;
	outline-offset: 1px;
}

@media (prefers-reduced-motion: reduce) {
	.demo-scroll-carousel .carousel {
		scroll-behavior: auto;
		transition: none;
		animation: none;
	}
}
