/**
 * Banner Shuffle — front end. Neutral styles that inherit the theme's colours.
 * Custom properties a theme can set (on .banner-shuffle or any ancestor):
 *   --banner-shuffle-gap, --banner-shuffle-control-size, --banner-shuffle-transition,
 *   --banner-shuffle-radius, --banner-shuffle-shadow, --banner-shuffle-glow-blur,
 *   --banner-shuffle-glow-opacity, --banner-shuffle-shine-color, --banner-shuffle-shine-period
 */

.banner-shuffle {
	clear: both;
	margin-block: 2em;
	text-align: center;
}

/* Banners are stacked in one grid cell: the zone keeps its height while they change. */
.banner-shuffle__track {
	display: grid;
	align-items: center;
}

.banner-shuffle__slide {
	position: relative;
	isolation: isolate; /* Keeps the glow (z-index: -1) inside the slide. */
	grid-area: 1 / 1;
	min-width: 0;
	opacity: 0;
	visibility: hidden;
	transition: opacity var(--banner-shuffle-transition, 0.4s) ease, visibility 0s linear var(--banner-shuffle-transition, 0.4s);
}

.banner-shuffle__slide.is-active {
	opacity: 1;
	visibility: visible;
	transition: opacity var(--banner-shuffle-transition, 0.4s) ease;
}

/* Edge to edge: the banner takes the full width of its container. */
.banner-shuffle__frame {
	position: relative;
	overflow: hidden;
}

.banner-shuffle__link {
	display: block;
	line-height: 0;
}

.banner-shuffle__link:focus {
	outline: none;
}

/* The frame clips its content: the focus ring is drawn on the frame. */
.banner-shuffle__frame:has(.banner-shuffle__link:focus-visible) {
	outline: 2px solid currentColor;
	outline-offset: 3px;
}

.banner-shuffle__image {
	display: block;
	width: 100%;
	max-width: none;
	height: auto;
}

/* ---------- Highlight effects (Banners > Settings > Style) ---------- */

.banner-shuffle--fx .banner-shuffle__frame {
	border-radius: var(--banner-shuffle-radius, 12px);
	box-shadow: var(--banner-shuffle-shadow, 0 1px 2px rgb(0 0 0 / 0.12), 0 14px 32px -14px rgb(0 0 0 / 0.5));
	transition: transform 0.3s ease, box-shadow 0.3s ease;
}

/* Thin inner light edge. */
.banner-shuffle--fx .banner-shuffle__frame::before {
	content: "";
	position: absolute;
	z-index: 2;
	inset: 0;
	border-radius: inherit;
	box-shadow: inset 0 0 0 1px rgb(255 255 255 / 0.14);
	pointer-events: none;
}

/* Light sweep across the banner, then a pause. */
.banner-shuffle--fx .banner-shuffle__frame::after {
	content: "";
	position: absolute;
	z-index: 1;
	inset: 0;
	background: linear-gradient(110deg, transparent 30%, var(--banner-shuffle-shine-color, rgb(255 255 255 / 0.5)) 50%, transparent 70%);
	transform: translateX(-100%);
	animation: banner-shuffle-shine var(--banner-shuffle-shine-period, 6s) ease-in-out 1s infinite;
	pointer-events: none;
}

/* Glow: the banner itself, blurred behind the frame (same file as the image). */
.banner-shuffle--fx .banner-shuffle__slide::before {
	content: "";
	position: absolute;
	z-index: -1;
	inset: 16% 3% -16%;
	border-radius: var(--banner-shuffle-radius, 12px);
	background: var(--banner-shuffle-glow, none) center / cover no-repeat;
	filter: blur(var(--banner-shuffle-glow-blur, 24px)) saturate(1.6);
	opacity: var(--banner-shuffle-glow-opacity, 0.75);
	animation: banner-shuffle-glow 4s ease-in-out infinite alternate;
	pointer-events: none;
	will-change: transform, opacity;
}

.banner-shuffle--fx .banner-shuffle__slide:hover .banner-shuffle__frame,
.banner-shuffle--fx .banner-shuffle__slide:focus-within .banner-shuffle__frame {
	transform: translateY(-2px);
	box-shadow: 0 2px 4px rgb(0 0 0 / 0.14), 0 22px 40px -16px rgb(0 0 0 / 0.55);
}

@keyframes banner-shuffle-shine {
	0% {
		transform: translateX(-100%);
	}
	30%,
	100% {
		transform: translateX(100%);
	}
}

/* Only transform and opacity are animated: composited, no repaint of the blur. */
@keyframes banner-shuffle-glow {
	from {
		opacity: calc(var(--banner-shuffle-glow-opacity, 0.75) * 0.6);
		transform: scale(0.97);
	}
	to {
		opacity: var(--banner-shuffle-glow-opacity, 0.75);
		transform: scale(1.02);
	}
}

/* Hidden until the script has picked the banner; shown anyway after 3 s if the script never runs. */
.banner-shuffle-js .banner-shuffle--pending {
	opacity: 0;
	animation: banner-shuffle-reveal 0s linear 3s forwards;
}

@keyframes banner-shuffle-reveal {
	to {
		opacity: 1;
	}
}

.banner-shuffle__controls {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	justify-content: center;
	gap: var(--banner-shuffle-gap, 0.5em);
	margin-top: var(--banner-shuffle-gap, 0.5em);
}

.banner-shuffle__controls[hidden] {
	display: none;
}

.banner-shuffle__button,
.banner-shuffle__dot {
	margin: 0;
	border: 1px solid currentColor;
	border-radius: 50%;
	background: transparent;
	color: inherit;
	cursor: pointer;
	opacity: 0.7;
}

.banner-shuffle__button {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: var(--banner-shuffle-control-size, 2rem);
	height: var(--banner-shuffle-control-size, 2rem);
	padding: 0;
}

.banner-shuffle__dots {
	display: inline-flex;
	gap: 0.25em;
}

/* 24×24 px hit area (WCAG 2.5.8) around a small visible dot. */
.banner-shuffle__dot {
	width: 24px;
	height: 24px;
	padding: 0;
	border: 0;
	background: radial-gradient(circle, currentColor 0 4px, transparent 5px);
	opacity: 0.35;
}

.banner-shuffle__dot[aria-current="true"] {
	opacity: 0.9;
}

.banner-shuffle__button:hover,
.banner-shuffle__button:focus-visible,
.banner-shuffle__dot:hover,
.banner-shuffle__dot:focus-visible {
	opacity: 1;
}

.banner-shuffle__button:focus-visible,
.banner-shuffle__dot:focus-visible {
	outline: 2px solid currentColor;
	outline-offset: 2px;
}

.banner-shuffle__icon-play,
.banner-shuffle.is-paused .banner-shuffle__icon-pause {
	display: none;
}

.banner-shuffle.is-paused .banner-shuffle__icon-play {
	display: block;
}

@media (prefers-reduced-motion: reduce) {
	.banner-shuffle__slide,
	.banner-shuffle__slide.is-active,
	.banner-shuffle--fx .banner-shuffle__frame {
		transition: none;
	}

	/* Static glow and shadow, no light sweep. */
	.banner-shuffle--fx .banner-shuffle__frame::after,
	.banner-shuffle--fx .banner-shuffle__slide::before {
		animation: none;
	}

	.banner-shuffle--fx .banner-shuffle__frame::after {
		display: none;
	}

	.banner-shuffle--fx .banner-shuffle__slide:hover .banner-shuffle__frame,
	.banner-shuffle--fx .banner-shuffle__slide:focus-within .banner-shuffle__frame {
		transform: none;
	}
}
