/* blocks/gallery-section
 *
 * Grid of square tiles plus the lightbox slider. The desktop column count comes
 * from the block's Section Settings as `--cols` (default 3) and steps down to 2
 * then 1 on smaller screens. Tiles are a wrapping flex row — no gap, the
 * spacing is margin on each item — matching the other section blocks.
 */

.section-gallery {
	--cols: 3;
	--tile-margin: 10px;
	--lightbox-backdrop: rgba(0, 0, 0, .9);
	padding: 80px 20px;
	text-align: center;
}

.section-gallery .section-head {
	margin-bottom: 40px;
}

.section-gallery .section-title {
	margin: 0;
}

/* --- Grid --------------------------------------------------------------- */
.section-gallery .gallery-grid {
	display: flex;
	flex-wrap: wrap;
	justify-content: center;
	margin-left: calc(var(--tile-margin) * -1);
	margin-right: calc(var(--tile-margin) * -1);
}

.section-gallery .gallery-item {
	width: calc(100% / var(--cols) - var(--tile-margin) * 2);
	margin: var(--tile-margin);
}

.section-gallery .gallery-link {
	position: relative;
	display: block;
	overflow: hidden;
	background-color: #f2f2f2;
	cursor: zoom-in;
}

.section-gallery .gallery-link img {
	width: 100%;
	height: 100%;
	aspect-ratio: 4 / 3;
	object-fit: cover;
	transition: transform .4s ease;
}

.section-gallery .gallery-link:hover img,
.section-gallery .gallery-link:focus-visible img {
	transform: scale(1.06);
}

/* Zoom badge — fades in over the tile on hover. */
.section-gallery .gallery-zoom {
	position: absolute;
	inset: 0;
	display: flex;
	align-items: center;
	justify-content: center;
	color: var(--white);
	background-color: rgba(60, 82, 33, .55);
	opacity: 0;
	transition: opacity .3s ease;
}

.section-gallery .gallery-link:hover .gallery-zoom,
.section-gallery .gallery-link:focus-visible .gallery-zoom {
	opacity: 1;
}

/* Video tiles keep the play badge visible instead of revealing it on hover —
 * a still frame with no badge reads as a photo. */
.section-gallery .gallery-item.is-video .gallery-zoom {
	inset: auto;
	top: 50%;
	left: 50%;
	width: 62px;
	height: 62px;
	transform: translate(-50%, -50%);
	border-radius: 50%;
	background-color: rgba(60, 82, 33, .78);
	opacity: 1;
	transition: background-color .3s ease, transform .3s ease;
}

.section-gallery .gallery-item.is-video .gallery-link:hover .gallery-zoom,
.section-gallery .gallery-item.is-video .gallery-link:focus-visible .gallery-zoom {
	background-color: var(--secondary-color);
	transform: translate(-50%, -50%) scale(1.08);
}

.section-gallery .gallery-item.is-video .gallery-link {
	cursor: pointer;
}

/* Stand-in tile when a video has no poster and no provider thumbnail
 * (Vimeo, mainly) — keeps the grid from collapsing. */
.section-gallery .gallery-placeholder {
	display: block;
	width: 100%;
	aspect-ratio: 4 / 3;
	background-color: var(--primary-color);
}

.section-gallery .gallery-caption {
	display: block;
	margin-top: 10px;
	font-size: 15px;
	line-height: 1.5;
}

/* --- Lightbox slider ----------------------------------------------------
 * Closed is the default state (display: none) and .is-open is what shows it,
 * rather than the other way round. The `hidden` attribute alone isn't enough:
 * in the block editor the canvas styles win over it and the shell would sit
 * over the page with no image in it.
 */
.section-gallery .gallery-lightbox {
	display: none;
	position: fixed;
	inset: 0;
	z-index: 9999;
	align-items: center;
	justify-content: center;
	padding: 40px 20px;
	background-color: var(--lightbox-backdrop);
}

.section-gallery .gallery-lightbox.is-open {
	display: flex;
}

.section-gallery .lightbox-inner {
	position: relative;
	display: flex;
	align-items: center;
	justify-content: center;
	width: 100%;
	max-width: 1100px;
}

.section-gallery .lightbox-figure {
	margin: 0;
	max-width: calc(100% - 140px);
}

.section-gallery .lightbox-image {
	max-width: 100%;
	max-height: 78vh;
	margin-inline: auto;
	opacity: 1;
	transition: opacity .25s ease;
}

/* Set by the script while the next file loads, so slides cross-fade. */
.section-gallery .lightbox-inner.is-loading .lightbox-image {
	opacity: 0;
}

/* --- Lightbox media: one player per slide type -------------------------
 * All three players live in the markup and only the matching one is shown.
 * The script sets .is-image / .is-video / .is-embed on the lightbox and clears
 * the other players' sources, so nothing keeps loading or playing off-screen.
 */
.section-gallery .lightbox-image,
.section-gallery .lightbox-video,
.section-gallery .lightbox-embed {
	display: none;
}

.section-gallery .gallery-lightbox.is-image .lightbox-image,
.section-gallery .gallery-lightbox.is-video .lightbox-video,
.section-gallery .gallery-lightbox.is-embed .lightbox-embed {
	display: block;
}

.section-gallery .lightbox-video {
	width: 100%;
	max-height: 78vh;
	background-color: #000;
}

/* 16:9 frame for the provider iframe — it has no intrinsic size. */
.section-gallery .lightbox-embed {
	position: relative;
	width: 100%;
	max-width: 1100px;
	aspect-ratio: 16 / 9;
	max-height: 78vh;
	background-color: #000;
}

.section-gallery .lightbox-embed iframe {
	position: absolute;
	inset: 0;
	width: 100%;
	height: 100%;
	border: 0;
}

/* Video slides need the full width of the inner box; an image is centred by
 * its own intrinsic size, but a player would otherwise sit at 4/3 of it. */
.section-gallery .gallery-lightbox.is-video .lightbox-figure,
.section-gallery .gallery-lightbox.is-embed .lightbox-figure {
	width: 100%;
}

.section-gallery .lightbox-caption {
	margin-top: 12px;
	color: var(--white);
	font-size: 15px;
	line-height: 1.5;
}

.section-gallery .lightbox-caption:empty {
	display: none;
}

.section-gallery .lightbox-counter {
	position: absolute;
	left: 50%;
	bottom: -34px;
	transform: translateX(-50%);
	margin: 0;
	color: var(--white);
	font-size: 15px;
	opacity: .75;
}

.section-gallery .lightbox-prev,
.section-gallery .lightbox-next,
.section-gallery .lightbox-close {
	display: flex;
	align-items: center;
	justify-content: center;
	border: 0;
	background-color: rgba(255, 255, 255, .12);
	color: var(--white);
	cursor: pointer;
	transition: background-color .2s ease;
}

.section-gallery .lightbox-prev:hover,
.section-gallery .lightbox-next:hover,
.section-gallery .lightbox-close:hover {
	background-color: rgba(255, 255, 255, .26);
}

.section-gallery .lightbox-prev,
.section-gallery .lightbox-next {
	position: absolute;
	top: 50%;
	transform: translateY(-50%);
	width: 52px;
	height: 52px;
	border-radius: 50%;
	font-size: 34px;
	line-height: 1;
	padding-bottom: 4px;
}

.section-gallery .lightbox-prev { left: 0; }
.section-gallery .lightbox-next { right: 0; }

/* One image = nothing to navigate to. */
.section-gallery .gallery-lightbox.is-single .lightbox-prev,
.section-gallery .gallery-lightbox.is-single .lightbox-next,
.section-gallery .gallery-lightbox.is-single .lightbox-counter {
	display: none;
}

.section-gallery .gallery-lightbox.is-single .lightbox-figure {
	max-width: 100%;
}

.section-gallery .lightbox-close {
	position: absolute;
	top: -34px;
	right: 0;
	width: 40px;
	height: 40px;
	border-radius: 50%;
	font-size: 26px;
	line-height: 1;
	padding-bottom: 4px;
}

/* Keeps the page from scrolling behind an open lightbox. */
body.gallery-lightbox-open {
	overflow: hidden;
}

/* --- Responsive -------------------------------------------------------- */
@media (max-width: 1024px) {
	.section-gallery {
		padding: 60px 20px;
	}

	.section-gallery .gallery-item {
		width: calc(100% / min(var(--cols), 2) - var(--tile-margin) * 2);
	}
}

@media (max-width: 767px) {
	.section-gallery {
		padding: 50px 20px;
		--tile-margin: 7px;
	}

	.section-gallery .section-head {
		margin-bottom: 28px;
	}

	.section-gallery .gallery-lightbox {
		padding: 60px 12px;
	}

	/* Arrows move below the image so they don't cover it on a narrow screen. */
	.section-gallery .lightbox-figure {
		max-width: 100%;
	}

	.section-gallery .lightbox-prev,
	.section-gallery .lightbox-next {
		top: auto;
		bottom: -64px;
		transform: none;
		width: 44px;
		height: 44px;
		font-size: 28px;
	}

	.section-gallery .lightbox-prev { left: calc(50% - 74px); }
	.section-gallery .lightbox-next { right: calc(50% - 74px); }

	.section-gallery .lightbox-counter {
		bottom: -52px;
	}

	.section-gallery .lightbox-image {
		max-height: 64vh;
	}
}

@media (max-width: 479px) {
	.section-gallery .gallery-item {
		width: calc(100% - var(--tile-margin) * 2);
	}
}
