/* =========================================================================
   Lance Gallery
   ========================================================================= */

.lance-gallery {
	--lance-gap: 8px;
	display: flex;
	flex-wrap: wrap;
	gap: var(--lance-gap);
	margin: 0 0 1.5rem;
	padding: 0;
	list-style: none;
}

/* Each figure. Width/height are set inline by JS once the justified layout
   runs; the rules here are the no-JS / pre-JS fallback (a simple 3-up grid). */
.lance-gallery__item {
	position: relative;
	margin: 0;
	padding: 0;
	overflow: hidden;
	background: #f2f0ec;
	width: calc(33.333% - var(--lance-gap));
	aspect-ratio: var(--lance-aspect, 3 / 2);
}

@media (max-width: 900px) {
	.lance-gallery__item { width: calc(50% - var(--lance-gap)); }
}
@media (max-width: 540px) {
	.lance-gallery__item { width: 100%; }
}

.lance-gallery__link {
	display: block;
	width: 100%;
	height: 100%;
	cursor: zoom-in;
	outline-offset: -2px;
}

.lance-gallery__img {
	display: block;
	width: 100%;
	height: 100%;
	object-fit: cover;
	transition: transform .5s cubic-bezier(.2, .6, .2, 1), filter .5s ease;
	will-change: transform;
}

.lance-gallery__item:hover .lance-gallery__img,
.lance-gallery__link:focus-visible .lance-gallery__img {
	transform: scale(1.035);
	filter: brightness(.92);
}

/* -------------------------------------------------------------------------
   Caption. Hidden from view by default (the lightbox reads it), but kept in
   the DOM for screen readers and for the JS. `captions="below"` reveals it.
   ------------------------------------------------------------------------- */
.lance-gallery:not(.lance-gallery--captions) .lance-gallery__caption {
	position: absolute;
	width: 1px;
	height: 1px;
	margin: -1px;
	padding: 0;
	border: 0;
	overflow: hidden;
	clip: rect(0 0 0 0);
	clip-path: inset(50%);
}

/* Title on hover (only when captions are not shown below) */
.lance-gallery:not(.lance-gallery--captions) .lance-gallery__item::after {
	content: attr(data-title);
	position: absolute;
	left: 0;
	right: 0;
	bottom: 0;
	padding: 2.2rem .9rem .8rem;
	font: 500 .82rem/1.3 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
	color: #fff;
	letter-spacing: .01em;
	background: linear-gradient(to top, rgba(0, 0, 0, .55), rgba(0, 0, 0, 0));
	opacity: 0;
	transition: opacity .35s ease;
	pointer-events: none;
}
.lance-gallery:not(.lance-gallery--captions) .lance-gallery__item:hover::after,
.lance-gallery:not(.lance-gallery--captions) .lance-gallery__item:focus-within::after {
	opacity: 1;
}

/* captions="below" */
.lance-gallery--captions .lance-gallery__caption {
	display: block;
	padding: .5rem .1rem 0;
	font: 400 .8rem/1.4 Georgia, "Times New Roman", serif;
	color: #555;
}
.lance-gallery--captions .lance-gallery__title { font-style: italic; }
.lance-gallery--captions .lance-gallery__meta {
	display: block;
	font-size: .72rem;
	color: #999;
	margin-top: .1rem;
}
.lance-gallery--captions .lance-gallery__desc { margin-top: .25rem; }

.lance-gallery__empty {
	padding: 1rem 1.25rem;
	background: #fff6e5;
	border: 1px solid #f0d9a8;
	border-radius: 4px;
	font-size: .9rem;
}

/* =========================================================================
   Lightbox
   ========================================================================= */
body.lance-lb-open {
	overflow: hidden;
	padding-right: var(--lance-sbw, 0px);
}

.lance-lb {
	position: fixed;
	inset: 0;
	z-index: 99999;
	opacity: 0;
	visibility: hidden;
	transition: opacity .28s ease, visibility 0s linear .28s;
}
.lance-lb[aria-hidden="false"] {
	opacity: 1;
	visibility: visible;
	transition: opacity .28s ease;
}

.lance-lb__backdrop {
	position: absolute;
	inset: 0;
	background: #0b0b0b;
	opacity: .985;
	-webkit-backdrop-filter: blur(3px);
	backdrop-filter: blur(3px);
}

.lance-lb__stage {
	position: absolute;
	inset: 0;
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 2rem 4.5rem 3.75rem;
}

.lance-lb__figure {
	margin: 0;
	display: flex;
	flex-direction: column;
	align-items: center;
	max-width: 100%;
	max-height: 100%;
}

.lance-lb__img {
	max-width: min(92vw, 1600px);
	max-height: 66vh;
	flex: 0 1 auto;
	min-height: 0;
	object-fit: contain;
	background: #1b1b1b;
	opacity: .25;
	transform: scale(.99);
	transition: opacity .25s ease, transform .25s ease;
}
.lance-lb__img.is-loaded {
	opacity: 1;
	transform: none;
}

.lance-lb__cap {
	flex: 0 0 auto;
	margin-top: .85rem;
	max-width: 64ch;
	max-height: 24vh;
	overflow-y: auto;
	overscroll-behavior: contain;
	text-align: center;
	color: #d8d5cf;
	font: 400 .85rem/1.5 Georgia, "Times New Roman", serif;
}
.lance-lb__cap .lance-gallery__title {
	display: block;
	font-style: italic;
	color: #fff;
	font-size: .95rem;
	margin-bottom: .15rem;
}
.lance-lb__cap .lance-gallery__meta {
	display: block;
	font-size: .72rem;
	letter-spacing: .04em;
	text-transform: uppercase;
	color: #8f8b83;
	margin-bottom: .35rem;
}
.lance-lb__cap p { margin: .6rem 0 0; }
.lance-lb__cap p:first-child { margin-top: 0; }

.lance-lb__btn {
	position: absolute;
	display: flex;
	align-items: center;
	justify-content: center;
	width: 46px;
	height: 46px;
	padding: 0;
	border: 0;
	border-radius: 50%;
	background: rgba(255, 255, 255, .08);
	color: #fff;
	cursor: pointer;
	transition: background .2s ease, opacity .2s ease;
}
.lance-lb__btn:hover { background: rgba(255, 255, 255, .2); }
.lance-lb__btn:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }
.lance-lb__btn svg { width: 24px; height: 24px; }

.lance-lb__prev  { left: 1rem;  top: 50%; transform: translateY(-50%); }
.lance-lb__next  { right: 1rem; top: 50%; transform: translateY(-50%); }
.lance-lb__close { top: 1rem; right: 1rem; }

.lance-lb__counter {
	position: absolute;
	left: 50%;
	bottom: 1.1rem;
	transform: translateX(-50%);
	color: #9a958c;
	font: 400 .75rem/1 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
	letter-spacing: .08em;
}

@media (max-width: 640px) {
	.lance-lb__stage { padding: 3rem 1rem 4rem; }
	.lance-lb__img { max-height: 72vh; }
	.lance-lb__prev  { left: .35rem; }
	.lance-lb__next  { right: .35rem; }
	.lance-lb__btn { width: 42px; height: 42px; background: rgba(255, 255, 255, .12); }
}

@media (prefers-reduced-motion: reduce) {
	.lance-gallery__img,
	.lance-lb,
	.lance-lb__img,
	.lance-gallery__item::after { transition: none !important; }
}
