/*
 * WCCP Pro — built-in lightbox (front end).
 *
 * Self-contained: themes style button, figure, img and figcaption freely, so
 * every element of the viewer resets what it relies on. Scoped variables keep
 * the few values in one place (this file is front-end only: the admin design
 * tokens are not loaded on the visitor's page).
 *
 * Layout: the top bar (counter + tools) and the bottom thumbnail strip are
 * fixed bands; the picture gets the room between them, minus the caption's
 * measured height (--wccp-lb-cap, set by lightbox.js). Long captions scroll
 * inside their own area and never reach the buttons.
 */
.wccp-lb {
	--wccp-lb-bg: rgba(12, 14, 18, .94);
	--wccp-lb-fg: #f4f5f7;
	--wccp-lb-muted: #c4c8cf;
	--wccp-lb-btn: rgba(255, 255, 255, .12);
	--wccp-lb-btn-hover: rgba(255, 255, 255, .24);
	--wccp-lb-btn-active: rgba(255, 255, 255, .32);
	--wccp-lb-band: rgba(0, 0, 0, .35);
	--wccp-lb-ring: #ffffff;
	--wccp-lb-gutter: 72px;
	--wccp-lb-top: 72px;
	--wccp-lb-foot: 24px;
	--wccp-lb-strip: 0px;
	--wccp-lb-thumb: 60px;
	--wccp-lb-cap: 0px;
	--wccp-lb-dur: .2s;

	position: fixed;
	inset: 0;
	z-index: 2147483000;
	display: flex;
	align-items: center;
	justify-content: center;
	opacity: 0;
	transition: opacity var(--wccp-lb-dur) ease;
	font: 400 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
	color: var(--wccp-lb-fg);
	-webkit-tap-highlight-color: transparent;
}

.wccp-lb.has-strip {
	--wccp-lb-strip: calc(var(--wccp-lb-thumb) + 28px);
}

.wccp-lb[hidden],
.wccp-lb [hidden] {
	display: none !important;
}

.wccp-lb.is-visible {
	opacity: 1;
}

.wccp-lb:fullscreen {
	width: 100%;
	height: 100%;
}

.wccp-lb:-webkit-full-screen {
	width: 100%;
	height: 100%;
}

html.wccp-lb-open,
html.wccp-lb-open body {
	overflow: hidden !important;
}

.wccp-lb-backdrop {
	position: absolute;
	inset: 0;
	background: var(--wccp-lb-bg);
}

.wccp-lb .wccp-lb-stage {
	position: relative;
	box-sizing: border-box;
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	width: 100%;
	height: 100%;
	margin: 0;
	padding: var(--wccp-lb-top) var(--wccp-lb-gutter) calc(var(--wccp-lb-foot) + var(--wccp-lb-strip));
	border: 0;
	background: none;
	touch-action: pan-y;
}

.wccp-lb .wccp-lb-frame {
	position: relative;
	display: inline-block;
	flex: none;
	max-width: 100%;
	line-height: 0;
	margin: 0;
	padding: 0;
}

.wccp-lb .wccp-lb-img {
	display: block;
	width: auto;
	height: auto;
	max-width: calc(100vw - 2 * var(--wccp-lb-gutter));
	max-height: calc(100vh - var(--wccp-lb-top) - var(--wccp-lb-foot) - var(--wccp-lb-strip) - var(--wccp-lb-cap));
	max-height: max(120px, calc(100dvh - var(--wccp-lb-top) - var(--wccp-lb-foot) - var(--wccp-lb-strip) - var(--wccp-lb-cap)));
	margin: 0;
	padding: 0;
	border: 0;
	border-radius: 4px;
	box-shadow: 0 12px 48px rgba(0, 0, 0, .45);
	object-fit: contain;
	pointer-events: none;
	-webkit-user-select: none;
	user-select: none;
	-webkit-user-drag: none;
	-webkit-touch-callout: none;
	transition: opacity var(--wccp-lb-dur) ease;
}

.wccp-lb.is-loading .wccp-lb-img,
.wccp-lb.has-error .wccp-lb-img {
	opacity: 0;
}

/* Title + caption: under the picture, scrolling on its own when long. */
.wccp-lb .wccp-lb-caption {
	box-sizing: border-box;
	flex: none;
	width: auto;
	max-width: min(70ch, 100%);
	max-height: 24vh;
	max-height: 24dvh;
	margin: 12px 0 0;
	padding: 0 4px;
	overflow-x: hidden;
	overflow-y: auto;
	overscroll-behavior: contain;
	scrollbar-width: thin;
	scrollbar-color: var(--wccp-lb-btn-hover) transparent;
	color: var(--wccp-lb-fg);
	font-size: 14px;
	line-height: 1.5;
	text-align: center;
	overflow-wrap: anywhere;
	background: none;
	border: 0;
	border-radius: 4px;
}

.wccp-lb .wccp-lb-caption:focus {
	outline: none;
}

.wccp-lb .wccp-lb-caption:focus-visible {
	outline: 3px solid var(--wccp-lb-ring);
	outline-offset: 2px;
}

.wccp-lb .wccp-lb-title {
	margin: 0;
	font-size: 15px;
	font-weight: 600;
	line-height: 1.4;
}

.wccp-lb .wccp-lb-text {
	margin: 0;
	color: var(--wccp-lb-muted);
	white-space: pre-line;
}

.wccp-lb .wccp-lb-title + .wccp-lb-text {
	margin-top: 4px;
}

/* Top bar: counter at the start, tools at the end. Its empty middle lets the
   click through to the backdrop (which closes the viewer). */
.wccp-lb .wccp-lb-bar {
	position: absolute;
	top: 0;
	inset-inline: 0;
	box-sizing: border-box;
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 12px;
	height: var(--wccp-lb-top);
	padding: 12px;
	pointer-events: none;
	/* Above the stage, which comes later in the markup and spans the viewer. */
	z-index: 1;
}

.wccp-lb .wccp-lb-counter {
	padding-inline-start: 12px;
	color: var(--wccp-lb-muted);
	font-size: 13px;
	font-variant-numeric: tabular-nums;
	white-space: nowrap;
}

.wccp-lb .wccp-lb-tools {
	display: flex;
	align-items: center;
	gap: 8px;
	pointer-events: auto;
}

/* Announced to screen readers; shown only when the image fails to load. */
.wccp-lb .wccp-lb-status {
	position: absolute;
	width: 1px;
	height: 1px;
	margin: -1px;
	padding: 0;
	overflow: hidden;
	clip: rect(0 0 0 0);
	white-space: nowrap;
}

.wccp-lb.has-error .wccp-lb-status {
	position: absolute;
	top: 50%;
	left: 50%;
	width: auto;
	height: auto;
	margin: 0;
	padding: 12px 18px;
	overflow: visible;
	clip: auto;
	white-space: normal;
	transform: translate(-50%, -50%);
	border-radius: 8px;
	background: var(--wccp-lb-btn);
	color: var(--wccp-lb-fg);
}

/* Spinner while the picture loads. */
.wccp-lb.is-loading::after {
	content: "";
	position: absolute;
	top: 50%;
	left: 50%;
	width: 36px;
	height: 36px;
	margin: -18px 0 0 -18px;
	border: 3px solid var(--wccp-lb-btn-hover);
	border-top-color: var(--wccp-lb-fg);
	border-radius: 50%;
	animation: wccp-lb-spin .8s linear infinite;
}

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

/* "Expand on click" images are buttons: show where keyboard focus is. */
[data-wccp-lightbox-src]:not(a) img {
	cursor: zoom-in;
}

[data-wccp-lightbox-key]:focus {
	outline: none;
}

[data-wccp-lightbox-key]:focus-visible {
	outline: 3px solid currentColor;
	outline-offset: 3px;
}

/* Buttons: every property themes like to set is reset first. */
.wccp-lb .wccp-lb-btn {
	all: unset;
	position: absolute;
	box-sizing: border-box;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 48px;
	height: 48px;
	border-radius: 50%;
	background: var(--wccp-lb-btn);
	color: var(--wccp-lb-fg);
	cursor: pointer;
	transition: background-color var(--wccp-lb-dur) ease, transform var(--wccp-lb-dur) ease;
}

.wccp-lb .wccp-lb-tools .wccp-lb-btn {
	position: relative;
	flex: none;
}

.wccp-lb .wccp-lb-btn svg {
	display: block;
	width: 24px;
	height: 24px;
	pointer-events: none;
}

.wccp-lb .wccp-lb-btn:hover {
	background: var(--wccp-lb-btn-hover);
}

.wccp-lb .wccp-lb-btn:active {
	background: var(--wccp-lb-btn-active);
	transform: scale(.94);
}

/* Play / full screen / thumbnails while switched on. */
.wccp-lb .wccp-lb-btn[aria-pressed="true"] {
	background: var(--wccp-lb-btn-active);
	box-shadow: inset 0 0 0 2px var(--wccp-lb-fg);
}

.wccp-lb .wccp-lb-btn:focus {
	outline: none;
}

.wccp-lb .wccp-lb-btn:focus-visible {
	outline: 3px solid var(--wccp-lb-ring);
	outline-offset: 2px;
}

.wccp-lb .wccp-lb-prev,
.wccp-lb .wccp-lb-next {
	top: calc((100% - var(--wccp-lb-strip)) / 2);
	margin-top: -24px;
}

.wccp-lb .wccp-lb-prev {
	inset-inline-start: 12px;
}

.wccp-lb .wccp-lb-next {
	inset-inline-end: 12px;
}

[dir="rtl"] .wccp-lb .wccp-lb-prev svg,
[dir="rtl"] .wccp-lb .wccp-lb-next svg {
	transform: scaleX(-1);
}

/* Thumbnail strip. The track is centred while it fits and scrolls once it
   does not; the active thumbnail is kept in view by lightbox.js. */
.wccp-lb .wccp-lb-thumbs {
	position: absolute;
	bottom: 0;
	inset-inline: 0;
	box-sizing: border-box;
	height: var(--wccp-lb-strip);
	margin: 0;
	padding: 10px 16px;
	overflow-x: auto;
	overflow-y: hidden;
	overscroll-behavior: contain;
	scrollbar-width: thin;
	scrollbar-color: var(--wccp-lb-btn-hover) transparent;
	background: var(--wccp-lb-band);
}

.wccp-lb .wccp-lb-track {
	display: flex;
	gap: 8px;
	width: max-content;
	margin: 0 auto;
	padding: 4px;
}

.wccp-lb .wccp-lb-thumb {
	all: unset;
	position: relative;
	flex: none;
	box-sizing: border-box;
	width: var(--wccp-lb-thumb);
	height: var(--wccp-lb-thumb);
	padding: 2px;
	overflow: hidden;
	border-radius: 6px;
	background: transparent;
	opacity: .55;
	cursor: pointer;
	line-height: 0;
	transition: opacity var(--wccp-lb-dur) ease, background-color var(--wccp-lb-dur) ease;
}

.wccp-lb .wccp-lb-thumb:hover {
	opacity: .85;
}

.wccp-lb .wccp-lb-thumb:active {
	opacity: 1;
	background: var(--wccp-lb-btn-active);
}

.wccp-lb .wccp-lb-thumb[aria-current="true"] {
	opacity: 1;
	background: var(--wccp-lb-fg);
}

.wccp-lb .wccp-lb-thumb:focus {
	outline: none;
}

.wccp-lb .wccp-lb-thumb:focus-visible {
	opacity: 1;
	outline: 3px solid var(--wccp-lb-ring);
	outline-offset: 2px;
}

.wccp-lb .wccp-lb-thumb-img {
	display: block;
	width: 100%;
	height: 100%;
	max-width: none;
	margin: 0;
	padding: 0;
	border: 0;
	border-radius: 4px;
	object-fit: cover;
	background: var(--wccp-lb-btn);
	pointer-events: none;
	-webkit-user-select: none;
	user-select: none;
	-webkit-user-drag: none;
	-webkit-touch-callout: none;
}

/* Stand-in for a set member with no picture on the page. */
.wccp-lb .wccp-lb-thumb-num {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 100%;
	height: 100%;
	border-radius: 4px;
	background: var(--wccp-lb-btn);
	color: var(--wccp-lb-fg);
	font-size: 13px;
	line-height: 1;
	font-variant-numeric: tabular-nums;
}

@media (max-width: 720px) {
	.wccp-lb {
		--wccp-lb-gutter: 8px;
		--wccp-lb-top: 60px;
		--wccp-lb-foot: 80px;
		--wccp-lb-thumb: 48px;
	}

	.wccp-lb .wccp-lb-bar {
		padding: 8px;
	}

	.wccp-lb .wccp-lb-tools {
		gap: 4px;
	}

	.wccp-lb .wccp-lb-tools .wccp-lb-btn {
		width: 44px;
		height: 44px;
	}

	.wccp-lb .wccp-lb-prev,
	.wccp-lb .wccp-lb-next {
		top: auto;
		bottom: calc(16px + var(--wccp-lb-strip));
		margin-top: 0;
	}

	.wccp-lb .wccp-lb-thumbs {
		padding: 10px 8px;
	}
}

@media (max-width: 520px) {
	.wccp-lb .wccp-lb-counter {
		padding-inline-start: 4px;
	}

	.wccp-lb .wccp-lb-caption {
		max-height: 20vh;
		max-height: 20dvh;
	}
}

@media (prefers-reduced-motion: reduce) {
	.wccp-lb,
	.wccp-lb .wccp-lb-img,
	.wccp-lb .wccp-lb-btn,
	.wccp-lb .wccp-lb-thumb {
		transition: none;
	}

	.wccp-lb .wccp-lb-btn:active {
		transform: none;
	}

	.wccp-lb.is-loading::after {
		animation: none;
	}
}
