/* Gallery-scoped design tokens with fallbacks for pages missing theme variables. */
.xy-gallery {
	--xy-gallery-surface: var(--c-contrast-0, #fff);
	--xy-gallery-ink: var(--c-headings, #161616);
	--xy-gallery-muted: var(--c-contrast-600, #666);
	--xy-gallery-line: var(--c-separator, #e8e8e8);
	--xy-gallery-tile: var(--c-contrast-100, #e8e8e8);
	--xy-gallery-action: var(--c-main, #3c3fde);
	--xy-gallery-ui: var(--ui-font, "Outfit", system-ui, sans-serif);
	--xy-gallery-body: var(--body-font, "Inter", system-ui, sans-serif);
	--xy-gallery-media-radius: var(--media-radius, 10px);
	--xy-gallery-button-radius: var(--xy-radius-button, 6px);
}

.xy-gallery,
.xy-gallery * {
	box-sizing: border-box;
}

.site-s-dark .xy-gallery {
	--xy-gallery-surface: #101016;
	--xy-gallery-action: #a3a5ff;
}

/* The modal remains inside article content. Reset the theme's fixed button
 * height and uppercase treatment without changing controls outside galleries. */
.xy-gallery :is(button, select) {
	box-sizing: border-box;
	block-size: auto;
	box-shadow: none;
	letter-spacing: normal;
	text-transform: none;
}

.xy-gallery svg {
	flex-shrink: 0;
	inline-size: 20px;
	block-size: 20px;
	fill: none;
	stroke: currentcolor;
	stroke-width: 1.5;
	stroke-linecap: round;
	stroke-linejoin: round;
}

/* Album cover: the uploaded artwork keeps its full frame and embedded credits. */
.xy-gallery-cover {
	display: block;
	inline-size: 100%;
	padding: 0;
	border: 0;
	background: transparent;
	color: var(--xy-gallery-ink);
	text-align: start;
	cursor: pointer;
}

.xy-gallery-cover .popup-cover-image {
	display: block;
	inline-size: 100%;
	block-size: auto;
	border-radius: var(--xy-gallery-media-radius);
	background: var(--xy-gallery-tile);
}

/* Cancel the legacy popup plugin's hover zoom (0,3,1 on :hover) so the
 * cover never crops its embedded credits. */
.xy-gallery .xy-gallery-cover img.popup-cover-image,
.xy-gallery .xy-gallery-cover img.popup-cover-image:hover {
	transform: none;
	transition: none;
}

.xy-gallery-cover-meta {
	display: flex;
	align-items: center;
	justify-content: space-between;
	flex-wrap: wrap;
	gap: 4px 12px;
	padding-block-start: 12px;
}

.xy-gallery-cover-meta .xy-gallery-album-label {
	font: 600 16px / 1.5 var(--xy-gallery-body);
	letter-spacing: -0.02em;
}

.xy-gallery-cover-action {
	display: inline-flex;
	align-items: center;
	gap: 8px;
	min-block-size: 44px;
	color: var(--xy-gallery-action);
	font: 500 13px / 1.5 var(--xy-gallery-ui);
	white-space: nowrap;
}

.xy-gallery-cover:hover .xy-gallery-cover-action {
	text-decoration: underline;
	text-underline-offset: 4px;
}

/* The dialog stays the scroll root for pagination and lazy loading. */
.xy-gallery-dialog {
	box-sizing: border-box;
	position: fixed;
	inset: 0;
	inline-size: 100%;
	max-inline-size: none;
	block-size: 100dvh;
	max-block-size: none;
	margin: 0;
	padding: 0;
	border: 0;
	background: var(--xy-gallery-surface);
	color: var(--xy-gallery-ink);
	font-family: var(--xy-gallery-body);
	overflow: auto;
	overscroll-behavior: contain;
	scrollbar-gutter: stable;
}

.xy-gallery-dialog::backdrop {
	background: #101016;
}

.xy-gallery-bar {
	position: sticky;
	inset-block-start: 0;
	z-index: 2;
	display: grid;
	grid-template-columns: minmax(132px, 1fr) minmax(0, 2fr) minmax(132px, 1fr);
	align-items: center;
	gap: 16px;
	min-block-size: 80px;
	padding: 15px 32px 12px;
	border-block-end: 1px solid var(--xy-gallery-line);
	background: var(--xy-gallery-surface);
}

.xy-gallery-bar::before {
	content: "";
	position: absolute;
	inset: 0 0 auto;
	block-size: var(--xy-rule-weight, 3px);
	background: var(--xy-brand-gradient, linear-gradient(90deg, #e40666 0%, #3c3fde 100%));
}

.xy-gallery-bar-title {
	min-inline-size: 0;
	text-align: center;
}

.xy-gallery-dialog .xy-gallery-title {
	margin: 0;
	overflow: hidden;
	color: inherit;
	font: 600 18px / 1.35 var(--xy-gallery-ui);
	letter-spacing: -0.02em;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.xy-gallery-dialog .xy-gallery-kicker {
	margin: 3px 0 0;
	color: var(--xy-gallery-muted);
	font: 400 11px / 1.5 var(--xy-gallery-body);
}

.xy-gallery-back,
.xy-gallery-close {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: 8px;
	min-inline-size: 44px;
	min-block-size: 44px;
	padding: 10px;
	border: 0;
	border-radius: var(--xy-gallery-button-radius);
	background: transparent;
	color: inherit;
	font: 500 13px / 1.4 var(--xy-gallery-ui);
	cursor: pointer;
}

.xy-gallery-back {
	justify-self: start;
}

.xy-gallery-close {
	justify-self: end;
}

.xy-gallery-back:hover,
.xy-gallery-close:hover {
	background: var(--xy-gallery-tile);
	color: inherit;
}

.xy-gallery-overview {
	max-inline-size: 1440px;
	margin-inline: auto;
	padding: 32px clamp(16px, 4vw, 64px) 64px;
}

.xy-gallery-heading {
	display: flex;
	align-items: center;
	justify-content: space-between;
	flex-wrap: wrap;
	gap: 12px 24px;
	padding-block-end: 20px;
}

.xy-gallery-heading .xy-gallery-album-label {
	margin: 0;
	color: inherit;
	font: 600 28px / 1.25 var(--xy-gallery-ui);
	letter-spacing: -0.025em;
}

.xy-gallery-album-select {
	min-block-size: 44px;
	padding: 10px 14px;
	border: 1px solid var(--xy-gallery-line);
	border-radius: var(--xy-gallery-button-radius);
	background: var(--xy-gallery-surface);
	color: var(--xy-gallery-ink);
	font: 500 13px / 1.5 var(--xy-gallery-ui);
	cursor: pointer;
}

.xy-gallery-path {
	display: flex;
	flex-wrap: wrap;
	gap: 8px;
	padding-block-end: 16px;
}

.xy-gallery-path:empty {
	display: none;
}

.xy-gallery-path button,
.xy-gallery-more {
	min-block-size: 44px;
	padding: 8px 16px;
	border: 1px solid var(--xy-gallery-line);
	border-radius: var(--xy-gallery-button-radius);
	background: transparent;
	color: var(--xy-gallery-ink);
	font: 500 13px / 1.5 var(--xy-gallery-ui);
	cursor: pointer;
}

/* JavaScript owns tile size and transform; only non-layout properties animate. */
.xy-gallery-grid {
	position: relative;
	inline-size: 100%;
}

.xy-gallery-grid .xy-gallery-item {
	position: absolute;
	inset-block-start: 0;
	inset-inline-start: 0;
	display: block;
	margin: 0;
	padding: 0;
	overflow: hidden;
	border: 0;
	border-radius: var(--xy-gallery-media-radius);
	background: var(--xy-gallery-tile);
	color: var(--xy-gallery-ink);
	font: 600 15px / 1.4 var(--xy-gallery-ui);
	text-align: center;
	cursor: pointer;
	transition: none;
	-webkit-tap-highlight-color: transparent;
}

.xy-gallery-item img {
	display: block;
	inline-size: 100%;
	block-size: 100%;
	object-fit: cover;
}

.xy-gallery-grid .xy-gallery-item:hover {
	outline: 2px solid var(--xy-gallery-action);
	outline-offset: 2px;
}

.xy-gallery-video::after {
	content: "";
	position: absolute;
	inset-block-start: 50%;
	inset-inline-start: 50%;
	inline-size: 0;
	block-size: 0;
	margin: -14px 0 0 -9px;
	border-block: 14px solid transparent;
	border-inline-start: 22px solid #fff;
	filter: drop-shadow(0 1px 4px rgb(0 0 0 / 60%));
	pointer-events: none;
}

.xy-gallery-status {
	margin: 24px 0 0;
	color: var(--xy-gallery-muted);
	font: 400 14px / 1.5 var(--xy-gallery-body);
	text-align: center;
}

.xy-gallery-status:empty {
	display: none;
}

/* Automatic pagination observes and measures this marker below the grid. */
.xy-gallery-sentinel {
	block-size: 1px;
	margin-block-start: -1px;
	pointer-events: none;
	visibility: hidden;
}

.xy-gallery-more,
.xy-gallery-retry {
	display: block;
	margin: 32px auto 0;
}

.xy-gallery-retry {
	min-block-size: 44px;
	padding: 8px 20px;
	border: 0;
	border-radius: var(--xy-gallery-button-radius);
	background: var(--c-main, #3c3fde);
	color: #fff;
	font: 500 13px / 1.5 var(--xy-gallery-ui);
	cursor: pointer;
}

.xy-gallery-more:disabled {
	opacity: 0.5;
	cursor: progress;
}

.xy-gallery-path button:hover,
.xy-gallery-more:hover {
	border-color: var(--xy-gallery-action);
	color: var(--xy-gallery-action);
}

.xy-gallery-more[hidden],
.xy-gallery-retry[hidden] {
	display: none;
}

.xy-gallery :is(button, a, select):focus-visible {
	outline: 2px solid var(--xy-gallery-action);
	outline-offset: 3px;
}

/* Clickable containers otherwise get the mobile tap highlight across the whole
 * cover or full-screen dialog. Controls keep their :focus-visible outlines.
 * Photo tiles and the photo viewer set this in their own base rules. */
.xy-gallery-cover,
.xy-gallery-dialog {
	-webkit-tap-highlight-color: transparent;
}

/* Photo viewer, scoped to photos opened from these galleries. */
#ilb-container.xy-gallery-viewer {
	/* The vendor fades this dialog through inline opacity (0, then 1 after 50ms,
	 * then 0 before closing), exposing the page layers beneath it. Stay opaque so
	 * the viewer cuts directly to and from the open album while the photo itself
	 * still fades. Only !important can override the inline style. */
	opacity: 1 !important;
	inset: 0;
	width: 100%;
	height: 100dvh;
	max-width: none;
	max-height: none;
	background: #101016;
	color: #fff;
	font-family: var(--ui-font, "Outfit", system-ui, sans-serif);
	-webkit-tap-highlight-color: transparent;
}

/* showModal can focus the dialog itself; its default ring outlines the viewport.
 * The dialogs are containers, not controls, and focus moves to real controls. */
.xy-gallery-dialog:focus,
#ilb-container.xy-gallery-viewer:focus {
	outline: none;
}

#ilb-container.xy-gallery-viewer::before {
	content: "";
	position: absolute;
	inset: 0 0 auto;
	z-index: 10002;
	height: var(--xy-rule-weight, 3px);
	background: var(--xy-brand-gradient, linear-gradient(90deg, #e40666 0%, #3c3fde 100%));
}

.xy-gallery-viewer .ilb-image-container {
	inset: 72px 96px 56px;
}

.xy-gallery-viewer #ilb-image {
	box-shadow: none;
}

.xy-gallery-viewer-heading {
	position: absolute;
	inset: 3px 228px auto 24px;
	z-index: 10001;
	display: flex;
	flex-direction: column;
	justify-content: center;
	min-height: 66px;
	pointer-events: none;
}

.xy-gallery-viewer-heading > * {
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.xy-gallery-viewer-album {
	color: #a3a5ff;
	font-size: 11px;
	font-weight: 600;
	letter-spacing: 0.08em;
	text-transform: uppercase;
}

.xy-gallery-viewer-heading strong {
	font-size: 16px;
	font-weight: 600;
}

.xy-gallery-viewer .ilb-button {
	box-sizing: border-box;
	display: grid;
	place-items: center;
	width: 44px;
	height: 44px;
	padding: 0;
	border-radius: var(--xy-radius-button, 6px);
	background-color: rgb(255 255 255 / 8%);
	color: #fff;
}

.xy-gallery-viewer .ilb-button:hover {
	background-color: rgb(255 255 255 / 18%);
}

.xy-gallery-viewer .ilb-button:focus-visible {
	outline: 2px solid #a3a5ff;
	outline-offset: 2px;
}

.xy-gallery-viewer #ilb-close-button {
	top: 16px;
	right: 16px;
}

/* Owned download control; hidden if the shared viewer is reused by other galleries. */
.xy-gallery-download,
.xy-gallery-download-status {
	display: none;
}

.xy-gallery-viewer .xy-gallery-download {
	position: absolute;
	top: 16px;
	right: 68px;
	z-index: 10002;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: 8px;
	min-width: 44px;
	height: 44px;
	margin: 0;
	padding: 0 14px 0 12px;
	border: 0;
	border-radius: var(--xy-radius-button, 6px);
	background-color: rgb(255 255 255 / 8%);
	box-shadow: none;
	color: #fff;
	font: 500 13px / 1.4 var(--ui-font, "Outfit", system-ui, sans-serif);
	letter-spacing: normal;
	text-transform: none;
	white-space: nowrap;
	cursor: pointer;
}

.xy-gallery-viewer .xy-gallery-download[hidden] {
	display: none;
}

.xy-gallery-viewer .xy-gallery-download:hover {
	background-color: rgb(255 255 255 / 18%);
}

.xy-gallery-viewer .xy-gallery-download:focus-visible {
	outline: 2px solid #a3a5ff;
	outline-offset: 2px;
}

.xy-gallery-viewer .xy-gallery-download[aria-disabled="true"] {
	opacity: 0.7;
	cursor: progress;
}

.xy-gallery-viewer .xy-gallery-download svg {
	flex-shrink: 0;
	width: 20px;
	height: 20px;
	fill: none;
	stroke: currentcolor;
	stroke-width: 1.5;
	stroke-linecap: round;
	stroke-linejoin: round;
}

/* Announced only; the button text and label show the state visually. */
.xy-gallery-viewer .xy-gallery-download-status {
	position: absolute;
	display: block;
	overflow: hidden;
	width: 1px;
	height: 1px;
	clip-path: inset(50%);
	white-space: nowrap;
}

.xy-gallery-viewer #ilb-arrow-left {
	left: 24px;
}

.xy-gallery-viewer #ilb-arrow-right {
	right: 24px;
}

.xy-gallery-viewer #ilb-arrow-left::before,
.xy-gallery-viewer #ilb-arrow-right::before {
	top: 50%;
	left: 50%;
	width: 10px;
	height: 10px;
	margin: 0;
	border: 0;
	border-top: 2px solid #fff;
	border-right: 2px solid #fff;
}

.xy-gallery-viewer #ilb-arrow-left::before {
	transform: translate(-30%, -50%) rotate(-135deg);
}

.xy-gallery-viewer #ilb-arrow-right::before {
	transform: translate(-70%, -50%) rotate(45deg);
}

.xy-gallery-viewer #ilb-caption {
	box-sizing: border-box;
	right: 50%;
	bottom: 44px;
	left: auto;
	max-width: calc(100% - 64px);
	max-height: 64px;
	overflow-y: auto;
	padding: 4px 12px;
	transform: translateX(50%);
	border-radius: var(--xy-radius-button, 6px);
	background: rgb(16 16 22 / 85%);
	font-size: 13px;
	line-height: 1.4;
}

/* Descriptions get their own footer space so embedded photo credits remain visible. */
.xy-gallery-viewer:has(#ilb-caption) .ilb-image-container {
	inset-block-end: 112px;
}

/* Narrow override of the theme's filename pill. */
.xy-gallery-viewer #custom-ilb-caption.xy-lightbox-caption {
	bottom: max(16px, env(safe-area-inset-bottom));
	max-width: calc(100% - 64px);
	padding: 4px 12px;
	background: transparent;
	color: rgb(255 255 255 / 72%);
	font-size: 12px;
	font-variant-numeric: tabular-nums;
	letter-spacing: 0.03em;
}

.xy-gallery-viewer #ilb-activity-indicator {
	background-color: rgb(255 255 255 / 12%);
	box-shadow: none;
}

@media (width <= 700px) {
	.xy-gallery-bar {
		grid-template-columns: auto minmax(0, 1fr) auto;
		gap: 8px;
		min-block-size: 64px;
		padding: 10px 12px 8px;
	}

	.xy-gallery-dialog .xy-gallery-title {
		font-size: 16px;
	}

	/* Visually hidden; the button keeps its accessible name. */
	.xy-gallery-back-text {
		position: absolute;
		overflow: hidden;
		inline-size: 1px;
		block-size: 1px;
		clip-path: inset(50%);
		white-space: nowrap;
	}

	.xy-gallery-overview {
		padding-block: 24px 40px;
	}

	.xy-gallery-heading .xy-gallery-album-label {
		font-size: 24px;
	}

	.xy-gallery-viewer .ilb-image-container {
		inset: 72px 0 112px;
	}

	.xy-gallery-viewer:has(#ilb-caption) .ilb-image-container {
		inset-block-end: 164px;
	}

	.xy-gallery-viewer-heading {
		inset-inline: 16px 124px;
	}

	.xy-gallery-viewer #ilb-close-button {
		top: 14px;
		right: 12px;
	}

	.xy-gallery-viewer .xy-gallery-download {
		top: 14px;
		right: 64px;
		width: 44px;
		padding: 0;
	}

	/* Icon-only on mobile; aria-label keeps the accessible name. */
	.xy-gallery-viewer .xy-gallery-download-text {
		position: absolute;
		overflow: hidden;
		width: 1px;
		height: 1px;
		clip-path: inset(50%);
		white-space: nowrap;
	}

	.xy-gallery-viewer #ilb-arrow-left,
	.xy-gallery-viewer #ilb-arrow-right {
		top: auto;
		bottom: max(16px, env(safe-area-inset-bottom));
		transform: none;
	}

	.xy-gallery-viewer #ilb-arrow-left {
		left: calc(50% - 64px);
	}

	.xy-gallery-viewer #ilb-arrow-right {
		right: calc(50% - 64px);
	}

	.xy-gallery-viewer #custom-ilb-caption.xy-lightbox-caption {
		bottom: calc(max(16px, env(safe-area-inset-bottom)) + 52px);
		max-width: calc(100% - 32px);
	}

	.xy-gallery-viewer #ilb-caption {
		bottom: calc(max(16px, env(safe-area-inset-bottom)) + 80px);
		max-width: calc(100% - 32px);
	}
}

@media (height <= 500px) and (orientation: landscape) {
	.xy-gallery-bar {
		min-block-size: 56px;
		padding-block: 6px 4px;
	}

	.xy-gallery-overview {
		padding-block-start: 16px;
	}

	.xy-gallery-viewer .ilb-image-container {
		inset: 64px 80px 40px;
	}

	.xy-gallery-viewer:has(#ilb-caption) .ilb-image-container {
		inset-block-end: 104px;
	}

	.xy-gallery-viewer-heading {
		min-height: 58px;
	}

	.xy-gallery-viewer #ilb-close-button,
	.xy-gallery-viewer .xy-gallery-download {
		top: 10px;
	}

	.xy-gallery-viewer #ilb-arrow-left,
	.xy-gallery-viewer #ilb-arrow-right {
		top: 50%;
		bottom: auto;
		transform: translateY(-50%);
	}

	.xy-gallery-viewer #ilb-arrow-left {
		left: 16px;
	}

	.xy-gallery-viewer #ilb-arrow-right {
		right: 16px;
	}

	.xy-gallery-viewer #custom-ilb-caption.xy-lightbox-caption {
		bottom: 8px;
	}

	.xy-gallery-viewer #ilb-caption {
		bottom: 36px;
	}
}

@media (prefers-reduced-motion: no-preference) {
	.xy-gallery-back,
	.xy-gallery-close,
	.xy-gallery-path button,
	.xy-gallery-more {
		transition: background-color 0.15s, border-color 0.15s, color 0.15s;
	}
}

@media (prefers-reduced-motion: reduce) {
	.xy-gallery-viewer .ilb-button {
		transition: none;
	}
}
