/*
 * WP8 Lightbox 1.3.0
 * Design über CSS-Variablen (werden von der Einstellungsseite gesetzt):
 * --wp8lb-backdrop, --wp8lb-blur, --wp8lb-color, --wp8lb-icon, --wp8lb-btn-bg, --wp8lb-btn-size,
 * --wp8lb-img-max-w, --wp8lb-img-max-h, --wp8lb-radius, --wp8lb-caption-size, --wp8lb-focus
 */

html.wp8lb-locked {
	overflow: hidden;
	scrollbar-gutter: stable;
}

.wp8lb-trigger {
	cursor: zoom-in;
}

:where(dialog).wp8lb {
	box-sizing: border-box;
	position: fixed;
	inset: 0;
	width: 100%;
	height: 100%;
	max-width: none;
	max-height: none;
	margin: 0;
	padding: 0;
	border: 0;
	overflow: hidden;
	overscroll-behavior: contain;
	background: transparent;
	color: var(--wp8lb-color, #fff);
}

:where(dialog).wp8lb::backdrop {
	background: transparent;
}

:where(dialog).wp8lb [hidden] {
	display: none !important;
}

:where(dialog.wp8lb) .wp8lb__bg {
	position: absolute;
	inset: 0;
	background: var(--wp8lb-backdrop, rgb(0 0 0 / .9));
	-webkit-backdrop-filter: var(--wp8lb-blur, none);
	backdrop-filter: var(--wp8lb-blur, none);
}

/* Nur für Screenreader */
:where(dialog.wp8lb) .wp8lb__sr {
	position: absolute;
	width: 1px;
	height: 1px;
	margin: -1px;
	padding: 0;
	overflow: hidden;
	clip: rect(0 0 0 0);
	white-space: nowrap;
	border: 0;
}

/* Slides: vorheriges, aktuelles und nächstes liegen nebeneinander */
:where(dialog.wp8lb) .wp8lb__track,
:where(dialog.wp8lb) .wp8lb__slide {
	position: absolute;
	inset: 0;
}

:where(dialog.wp8lb) .wp8lb__figure {
	--wp8lb-cap: 0px; /* Höhe der Bildunterschrift, setzt lightbox.js */
	position: absolute;
	inset: calc(var(--wp8lb-btn-size, 48px) + 1rem) calc(var(--wp8lb-btn-size, 48px) + 1.5rem) 1.5rem;
	container-type: size;
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	gap: .75rem;
	margin: 0;
}

:where(dialog.wp8lb) .wp8lb__img {
	display: block;
	flex: none;
	width: auto;
	height: auto;
	max-width: min(100cqw, var(--wp8lb-img-max-w, 100vw));
	max-height: min(100cqh - var(--wp8lb-cap), var(--wp8lb-img-max-h, 100vh));
	object-fit: contain;
	border-radius: var(--wp8lb-radius, 0);
	transition: opacity 200ms ease;
}

:where(dialog.wp8lb) .wp8lb__slide.is-loading .wp8lb__img {
	opacity: 0;
}

:where(dialog.wp8lb) .wp8lb__slide.is-error .wp8lb__img {
	display: none;
}

:where(dialog.wp8lb) .wp8lb__caption {
	flex: none;
	max-width: 70ch;
	max-height: 25vh;
	overflow: auto;
	margin: 0;
	font-size: var(--wp8lb-caption-size, 1rem);
	line-height: 1.5;
	text-align: center;
}

/* Ladeanzeige: erst nach kurzer Verzögerung, damit sie bei schnellen Bildern nicht flackert */
:where(dialog.wp8lb) .wp8lb__slide.is-loading .wp8lb__figure::after {
	content: "";
	position: absolute;
	top: 50%;
	left: 50%;
	width: 2.5rem;
	height: 2.5rem;
	margin: -1.25rem 0 0 -1.25rem;
	border: 3px solid rgb(255 255 255 / .3);
	border-top-color: var(--wp8lb-color, #fff);
	border-radius: 50%;
	opacity: 0;
	animation: wp8lb-fade-in 0s 300ms forwards, wp8lb-spin .8s linear infinite;
}

@keyframes wp8lb-spin {
	to { transform: rotate(360deg); }
}

@keyframes wp8lb-fade-in {
	to { opacity: 1; }
}

/* Zähler */
:where(dialog.wp8lb) .wp8lb__counter {
	position: absolute;
	z-index: 1;
	top: calc(.75rem + var(--wp8lb-btn-size, 48px) / 2);
	inset-inline-start: 1.25rem;
	margin: 0;
	font-size: .9375rem;
	line-height: 1;
	transform: translateY(-50%);
}

/* Buttons */
:where(dialog.wp8lb) .wp8lb__btn {
	position: absolute;
	z-index: 1;
	display: grid;
	place-items: center;
	box-sizing: border-box;
	width: var(--wp8lb-btn-size, 48px);
	height: var(--wp8lb-btn-size, 48px);
	margin: 0;
	padding: 0;
	border: 2px solid transparent; /* sichtbar im Kontrastmodus */
	border-radius: 4px;
	background: var(--wp8lb-btn-bg, rgb(0 0 0 / .45));
	color: var(--wp8lb-icon, #fff);
	cursor: pointer;
}

:where(dialog.wp8lb) .wp8lb__btn svg {
	width: 50%;
	height: 50%;
	fill: none;
	stroke: currentColor;
	stroke-width: 1.5;
	stroke-linecap: round;
	stroke-linejoin: round;
}

:where(dialog.wp8lb) .wp8lb__btn:hover {
	background: color-mix(in srgb, var(--wp8lb-btn-bg, rgb(0 0 0 / .45)), #fff 20%);
}

/* Weißer Ring mit dunklem Rand – auf hellen und dunklen Bildern sichtbar */
:where(dialog.wp8lb) .wp8lb__btn:focus-visible {
	outline: 3px solid var(--wp8lb-focus, #fff);
	outline-offset: 2px;
	box-shadow: 0 0 0 2px #000;
}

:where(dialog.wp8lb) .wp8lb__btn:disabled {
	opacity: .35;
	cursor: default;
}

:where(dialog.wp8lb) .wp8lb__close {
	top: .75rem;
	inset-inline-end: .75rem;
}

:where(dialog.wp8lb) .wp8lb__prev,
:where(dialog.wp8lb) .wp8lb__next {
	top: 50%;
	transform: translateY(-50%);
}

:where(dialog.wp8lb) .wp8lb__prev {
	inset-inline-start: .75rem;
}

:where(dialog.wp8lb) .wp8lb__next {
	inset-inline-end: .75rem;
}

[dir="rtl"] :where(dialog.wp8lb) .wp8lb__prev svg,
[dir="rtl"] :where(dialog.wp8lb) .wp8lb__next svg {
	transform: scaleX(-1);
}

/* Smartphones: Pfeile unten, Bild nutzt die volle Breite */
@media (max-width: 600px) {
	:where(dialog.wp8lb) .wp8lb__figure {
		inset: calc(var(--wp8lb-btn-size, 48px) + 1rem) .5rem calc(var(--wp8lb-btn-size, 48px) + 1.5rem);
	}

	:where(dialog.wp8lb) .wp8lb__prev,
	:where(dialog.wp8lb) .wp8lb__next {
		top: auto;
		bottom: .75rem;
		transform: none;
	}
}

@media (prefers-reduced-motion: reduce) {
	:where(dialog).wp8lb,
	:where(dialog).wp8lb * {
		transition: none !important;
	}

	:where(dialog.wp8lb) .wp8lb__slide.is-loading .wp8lb__figure::after {
		animation: wp8lb-fade-in 0s 300ms forwards;
	}
}

@media (forced-colors: active) {
	:where(dialog.wp8lb) .wp8lb__bg {
		background: Canvas;
	}

	:where(dialog).wp8lb {
		color: CanvasText;
	}

	:where(dialog.wp8lb) .wp8lb__btn {
		border-color: ButtonText;
	}
}
