/**
 * SBX Marquee.
 *
 * The track lays out as a wrapping flex row by default, so without JS (or under
 * reduced motion) the content is simply visible and centred. Once the script
 * has cloned items to fill the viewport it sets data-animated="true", which
 * switches the track to a single nowrap line and runs the scroll animation.
 *
 * The script supplies --sbx-marquee-shift (the exact one-group translate, as a
 * fraction of the rendered track width) and --sbx-marquee-duration, so the loop
 * is seamless and the velocity is constant regardless of content width.
 */

.sbx-marquee {
	--sbx-marquee-gap: 2rem;
	--sbx-marquee-fade: 2rem;
	position: relative;
	overflow: hidden; /* fallback for iOS Safari < 16 */
	overflow: clip;
}

.sbx-marquee[data-axis="x"] {
	--sbx-marquee-fade-angle: 90deg;
}

.sbx-marquee[data-axis="y"] {
	--sbx-marquee-fade-angle: 180deg;
}

/* Static / no-JS / reduced-motion layout. */
.sbx-marquee__track {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	justify-content: center;
	gap: var( --sbx-marquee-gap );
}

.sbx-marquee[data-axis="y"] .sbx-marquee__track {
	flex-direction: column;
}

/* Item sizing — the var only applies when the control sets it. */
.sbx-marquee[data-axis="x"] .sbx-marquee__track > * {
	flex-shrink: 0;
	width: var( --sbx-marquee-item-size );
}

.sbx-marquee[data-axis="y"] .sbx-marquee__track > * {
	flex-shrink: 0;
	height: var( --sbx-marquee-item-size );
}

/* Primed state (set at init when JS is running, before the deferred build):
   take the final single-line layout straight away so the height never changes
   when the build later runs. No-JS/reduced-motion visitors keep the wrapped
   fallback above. */
.sbx-marquee[data-sbx-primed="true"] .sbx-marquee__track {
	flex-wrap: nowrap;
	justify-content: flex-start;
}

/* Animated state (set by the script once items fill the viewport). */
.sbx-marquee[data-animated="true"] .sbx-marquee__track {
	flex-wrap: nowrap;
	justify-content: flex-start;
	width: max-content;
	animation: sbx-marquee-x var( --sbx-marquee-duration, 40s ) linear infinite;
	will-change: transform;
}

.sbx-marquee[data-axis="y"][data-animated="true"] .sbx-marquee__track {
	width: auto;
	height: max-content;
	animation-name: sbx-marquee-y;
}

/* Right / down reverse the travel. */
.sbx-marquee[data-direction="right"] .sbx-marquee__track,
.sbx-marquee[data-direction="down"] .sbx-marquee__track {
	animation-direction: reverse;
}

/* Pause states. */
.sbx-marquee[data-pause-hover="true"]:hover .sbx-marquee__track {
	animation-play-state: paused;
}

.sbx-marquee[data-pause-offscreen="true"][data-inview="false"] .sbx-marquee__track {
	animation-play-state: paused;
}

/* Edge fade. */
.sbx-marquee[data-fade="true"] {
	-webkit-mask: linear-gradient(
		var( --sbx-marquee-fade-angle, 90deg ),
		transparent,
		#000 var( --sbx-marquee-fade ),
		#000 calc( 100% - var( --sbx-marquee-fade ) ),
		transparent
	);
	mask: linear-gradient(
		var( --sbx-marquee-fade-angle, 90deg ),
		transparent,
		#000 var( --sbx-marquee-fade ),
		#000 calc( 100% - var( --sbx-marquee-fade ) ),
		transparent
	);
}

@keyframes sbx-marquee-x {
	to {
		transform: translateX( var( --sbx-marquee-shift, 0px ) );
	}
}

@keyframes sbx-marquee-y {
	to {
		transform: translateY( var( --sbx-marquee-shift, 0px ) );
	}
}

/* Belt-and-braces: never animate under reduced motion, even if mis-flagged. */
@media ( prefers-reduced-motion: reduce ) {
	.sbx-marquee .sbx-marquee__track {
		animation: none !important;
	}
}
