/*
 * gpuslider: the layout, in three tiers.
 *
 * 1. Without the script the track is a native scroller with scroll-snap.
 * 2. With the script (.gs-on) the slides are moved by `translate`; their
 *    `transform`, `scale` and `rotate` are the page's.
 * 3. With the canvas layer (.gs-gl) the canvas draws the media.
 *
 * The page decides the layout; the script only measures it:
 *
 *     --gs-per-view  slides per view, fractions allowed
 *     --gs-gap       gap between slides
 *
 * Both can change in media queries.
 */

.gs {
	--gs-per-view: 1;
	--gs-gap: 0px;

	position: relative;
	/* As a flex or grid item it would otherwise be as wide as its images. */
	min-width: 0;
	overflow: hidden;
}

.gs-track {
	position: relative;
	display: flex;
	gap: var(--gs-gap);
	overflow-x: auto;
	overscroll-behavior-x: contain;
	scroll-snap-type: x mandatory;
	scrollbar-width: none;
}

.gs-slide {
	position: relative;
	flex: 0 0
		calc(
			( 100% - ( var(--gs-per-view) - 1 ) * var(--gs-gap) ) /
				var(--gs-per-view)
		);
	min-width: 0;
	scroll-snap-align: start;
}

/* Downwards. The slider needs a height: the page gives it one. */
.gs-y > .gs-track {
	flex-direction: column;
	height: 100%;
	overflow: hidden auto;
	overscroll-behavior: auto contain;
	scroll-snap-type: y mandatory;
}

.gs-y .gs-slide {
	min-height: 0;
}

/* Each slide as wide as its content. */
.gs-auto .gs-slide {
	flex-basis: auto;
}

/* --gs-focus is the point of the image that stays in view when it is
   cut: "30% 20%" is a third from the left, a fifth from the top. Set it on
   a slide or on the slider. */
.gs-media {
	display: block;
	width: 100%;
	height: 100%;
	object-fit: cover;
	object-position: var(--gs-focus, 50% 50%);
}

.gs-auto .gs-media {
	width: auto;
	max-width: none;
}

/* Auto height: every slide as high as its content, the slider as high as
   the slides in view. */
.gs-tall > .gs-track {
	align-items: start;
}

.gs-tall .gs-media {
	height: auto;
}

/* Content on top of the media. */
.gs-content {
	position: absolute;
	inset: 0;
	z-index: 1;
}

/* Tier 2: the script moves the slides. */

.gs-on {
	touch-action: pan-y;
	cursor: grab;
}

.gs-on > .gs-track {
	overflow: visible;
	scroll-snap-type: none;
	will-change: transform;
}

.gs-on.gs-y {
	touch-action: pan-x;
}

.gs-on.gs-dragging {
	cursor: grabbing;
	user-select: none;
	-webkit-user-select: none;
}

.gs-on:focus-visible {
	outline: 2px solid Highlight;
	outline-offset: 2px;
}

/* Stack: all slides in one place, the two around the position shown. */

.gs-stack > .gs-track {
	display: grid;
	gap: 0;
	will-change: auto;
}

/* The width is said: a slide with an aspect-ratio and a max-height would
   otherwise be as narrow as its height allows. */
.gs-stack .gs-slide {
	grid-area: 1 / 1;
	box-sizing: border-box;
	width: 100%;
	min-height: 0;
}

/* Until the plugin says which slides are shown, the first is: in a
   stack that the page has said in its HTML that is before the script is
   there, and without it. */
.gs-stack:not(.gs-on) > .gs-track {
	overflow: hidden;
}

.gs-stack .gs-slide:not(:first-child) {
	visibility: hidden;
	/* And its images that wait for their place go on waiting. */
	content-visibility: hidden;
}

.gs-stack .gs-media {
	opacity: var(--gs-cover, 1);
}

.gs-stack .gs-content {
	opacity: var(--gs-near, 1);
}

/* Panes: several in view that stay, each turns into the next of its
   place. Shown are the slides that the plugin says. */

.gs-panes > .gs-track {
	will-change: auto;
}

.gs-panes .gs-slide {
	visibility: hidden;
}

.gs-panes .gs-media {
	opacity: var(--gs-cover, 1);
}

.gs-panes .gs-content {
	opacity: var(--gs-near, 1);
}

/* Tier 3: the canvas draws the media. */

.gs-canvas {
	position: absolute;
	inset: 0;
	width: 100%;
	height: 100%;
	pointer-events: none;
}

/* Transparent, not hidden: the image keeps its place, its text for
   screen readers and its menu, and a video keeps playing. */
.gs .gs-media.gs-drawn {
	opacity: 0;
}

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