/* =================================================================
   Gallery Block
   ================================================================= */

/* Base */
.gallery {
	position: relative;
	margin-block-start: 0 !important;
}

/* Padding */
.gallery--py-sm {
	padding-block: 2rem;
}
.gallery--py-md {
	padding-block: 3rem;
}
.gallery--py-lg {
	padding-block: 4rem;
}

/* Background */
.gallery--bg-default {
	background-color: var(--wp--preset--color--bg);
}
.gallery--bg-light {
	background-color: var(--wp--preset--color--bg-secondary);
}
.gallery--bg-dark {
	background-color: var(--wp--preset--color--bg-dark, #1a1a2e);
	color: var(--wp--preset--color--white);
}
.gallery--bg-dark .header-section__title {
	color: var(--wp--preset--color--white);
}
.gallery--bg-dark .header-section__tagline {
	color: var(--wp--preset--color--white);
	opacity: 0.8;
}
.gallery--bg-dark .header-section__description,
.gallery--bg-dark .header-section__description p {
	color: var(--wp--preset--color--white);
	opacity: 0.85;
}

/* =================================================================
   Grid
   ================================================================= */

/* Mobile default: horizontal carousel (scroll-snap), one image per view
   with the next/previous image peeking at the edges. Reset back to a
   grid at 48rem — see Responsive section below. */
.gallery__grid {
	/* border-box + sin "padding-inline": el padding en % se sumaba al
	   100% de ancho (content-box por defecto en este theme) y el grid
	   medía 116% → scroll horizontal en toda la página en móvil. El
	   "peek" de la foto siguiente sale del ítem al 82% + snap centrado;
	   los ítems primero y último llevan margen para poder centrarse. */
	box-sizing: border-box;
	display: flex;
	flex-wrap: nowrap;
	align-items: flex-start;
	margin-top: 2rem;
	overflow-x: auto;
	overscroll-behavior-x: contain;
	scroll-snap-type: x mandatory;
	scroll-padding-inline: 9%;
	-webkit-overflow-scrolling: touch;
	scrollbar-width: none;
}

.gallery__grid::-webkit-scrollbar {
	display: none;
}

.gallery__item {
	flex: 0 0 82%;
	scroll-snap-align: center;
}

.gallery__item:first-child {
	margin-inline-start: 9%;
}
.gallery__item:last-child {
	margin-inline-end: 9%;
}

/* --- Gap modifiers (exposed as --gal-gap so the carousel item width
   can subtract it in its calc()) --- */
.gallery__grid {
	gap: var(--gal-gap, 0.5rem);
}
.gallery--gap-none .gallery__grid {
	--gal-gap: 0;
}
.gallery--gap-sm .gallery__grid {
	--gal-gap: 0.5rem;
}
.gallery--gap-md .gallery__grid {
	--gal-gap: 1rem;
}
.gallery--gap-lg .gallery__grid {
	--gal-gap: 1.5rem;
}

/* --- Column variables --- */
.gallery--cols-2 .gallery__grid {
	--gal-cols: 2;
}
.gallery--cols-3 .gallery__grid {
	--gal-cols: 3;
}
.gallery--cols-4 .gallery__grid {
	--gal-cols: 4;
}

/* Items visible per view when the grid becomes a carousel (>= 48rem).
   Mobile keeps its own fixed 82% item width regardless of this. */
.gallery--carousel .gallery__grid {
	--gal-visible: min(var(--gal-cols, 3), 2);
}

/* =================================================================
   Items
   ================================================================= */

.gallery__item {
	margin: 0;
	overflow: hidden;
	position: relative;
}

.gallery--rounded .gallery__item {
	border-radius: var(--wp--custom--radius--8, 0.5rem);
}

/* Image */
.gallery__img {
	display: block;
	width: 100%;
	height: auto;
	object-fit: cover;
}

/* Fixed aspect ratio mode */
.gallery--fixed-ratio .gallery__img {
	aspect-ratio: var(--gallery-ratio, 4/3);
	height: 100%;
}

/* Link (lightbox trigger) */
.gallery__link {
	display: block;
	cursor: zoom-in;
	line-height: 0;
}

.gallery--has-lightbox .gallery__item:hover .gallery__img {
	opacity: 0.88;
	transition: opacity 0.25s ease;
}

.gallery__img {
	transition: opacity 0.25s ease;
}

/* Caption */
.gallery__caption {
	font-size: 0.8125rem;
	line-height: 1.4;
	padding: 0.5rem 0.25rem;
	color: var(--wp--preset--color--text-muted);
	text-align: center;
}

.gallery--bg-dark .gallery__caption {
	color: var(--wp--preset--color--white);
	opacity: 0.7;
}

/* =================================================================
   Carousel navigation (desktop only)
   Arrows are rendered by render.php only when the block is a carousel
   (more images than columns). Hidden until >= 64rem — on touch widths
   the swipe/scroll is enough, same as the mobile view.
   ================================================================= */
.gallery__viewport {
	position: relative;
}

.gallery__nav {
	display: none;
	position: absolute;
	top: 50%;
	z-index: 3;
	width: 2.75rem;
	height: 2.75rem;
	margin-top: -1.375rem;
	align-items: center;
	justify-content: center;
	padding: 0;
	border: none;
	border-radius: 999px;
	background: var(--wp--preset--color--white, #fff);
	color: var(--wp--preset--color--text, #331f19);
	box-shadow: var(--wp--custom--shadows--200, 0 2px 8px rgb(0 0 0 / 0.15));
	cursor: pointer;
	transition: opacity 0.2s ease, background-color 0.2s ease;
}

.gallery__nav--prev {
	left: 0.5rem;
}
.gallery__nav--next {
	right: 0.5rem;
}

.gallery__nav:hover {
	background: var(--wp--preset--color--bg-secondary, #eff0f0);
}

.gallery__nav:focus-visible {
	outline: 2px solid var(--wp--preset--color--primary);
	outline-offset: 2px;
}

.gallery__nav[disabled] {
	opacity: 0.35;
	cursor: default;
}

@media (min-width: 64rem) {
	.gallery--carousel .gallery__nav {
		display: flex;
	}
}

@media (prefers-reduced-motion: reduce) {
	.gallery__nav {
		transition: none;
	}
}

/* --- Footer (button below grid) --- */
.gallery__footer {
	margin-top: 1.5rem;
	text-align: center;
}

.gallery__btn {
	color: inherit;
	text-decoration: underline;
	text-underline-offset: 0.2em;
	font-size: 0.9375rem;
	font-weight: 500;
}

.gallery__btn:hover {
	opacity: 0.75;
}

.gallery--bg-dark .gallery__btn {
	color: var(--wp--preset--color--white);
}

/* Placeholder (editor) */
.gallery__placeholder {
	min-height: 12rem;
	border: 2px dashed var(--wp--preset--color--border);
	background: var(--wp--preset--color--bg-secondary);
	display: flex;
	align-items: center;
	justify-content: center;
	border-radius: var(--wp--custom--radius--8);
	color: var(--wp--preset--color--text-muted);
	font-size: 0.875rem;
	grid-column: 1 / -1;
}

/* =================================================================
   Lightbox
   ================================================================= */

.gallery-lightbox {
	position: fixed;
	inset: 0;
	z-index: 999999;
	display: flex;
	align-items: center;
	justify-content: center;
	background: rgba(0, 0, 0, 0.92);
	opacity: 0;
	visibility: hidden;
	transition:
		opacity 0.3s ease,
		visibility 0.3s ease;
}

.gallery-lightbox[aria-hidden="false"] {
	opacity: 1;
	visibility: visible;
}

.gallery-lightbox__inner {
	position: relative;
	display: flex;
	align-items: center;
	justify-content: center;
	width: 100%;
	height: 100%;
	padding: 3rem 1rem;
}

.gallery-lightbox__img {
	max-width: 90vw;
	max-height: 85vh;
	width: auto;
	height: auto;
	object-fit: contain;
	border-radius: 0.25rem;
	user-select: none;
	-webkit-user-drag: none;
}

.gallery-lightbox__caption {
	position: absolute;
	bottom: 1rem;
	left: 50%;
	transform: translateX(-50%);
	color: var(--wp--preset--color--white);
	font-size: 0.875rem;
	line-height: 1.4;
	text-align: center;
	max-width: 80vw;
	opacity: 0.85;
	padding: 0.25rem 0.75rem;
}

/* Counter */
.gallery-lightbox__counter {
	position: absolute;
	top: 1rem;
	left: 50%;
	transform: translateX(-50%);
	color: var(--wp--preset--color--white);
	font-size: 0.8125rem;
	opacity: 0.6;
	pointer-events: none;
}

/* Close button */
.gallery-lightbox__close {
	position: absolute;
	top: 1rem;
	right: 1rem;
	width: 2.75rem;
	height: 2.75rem;
	display: flex;
	align-items: center;
	justify-content: center;
	background: transparent;
	border: none;
	color: var(--wp--preset--color--white);
	font-size: 1.5rem;
	cursor: pointer;
	opacity: 0.7;
	transition: opacity 0.2s ease;
	z-index: 10;
	border-radius: 50%;
}

.gallery-lightbox__close:hover,
.gallery-lightbox__close:focus-visible {
	opacity: 1;
	background: rgba(255, 255, 255, 0.1);
}

/* Prev / Next buttons */
.gallery-lightbox__prev,
.gallery-lightbox__next {
	position: absolute;
	top: 50%;
	transform: translateY(-50%);
	width: 3rem;
	height: 3rem;
	display: flex;
	align-items: center;
	justify-content: center;
	background: transparent;
	border: none;
	color: var(--wp--preset--color--white);
	font-size: 1.5rem;
	cursor: pointer;
	opacity: 0.6;
	transition: opacity 0.2s ease;
	z-index: 10;
	border-radius: 50%;
}

.gallery-lightbox__prev {
	left: 0.75rem;
}

.gallery-lightbox__next {
	right: 0.75rem;
}

.gallery-lightbox__prev:hover,
.gallery-lightbox__prev:focus-visible,
.gallery-lightbox__next:hover,
.gallery-lightbox__next:focus-visible {
	opacity: 1;
	background: rgba(255, 255, 255, 0.1);
}

/* Hide navigation when only 1 image */
.gallery-lightbox--single .gallery-lightbox__prev,
.gallery-lightbox--single .gallery-lightbox__next,
.gallery-lightbox--single .gallery-lightbox__counter {
	display: none;
}

/* =================================================================
   Responsive
   ================================================================= */

/* Tablet (48rem / 768px) */
@media (min-width: 48rem) {
	.gallery--py-sm {
		padding-block: 3rem;
	}
	.gallery--py-md {
		padding-block: 4.5rem;
	}
	.gallery--py-lg {
		padding-block: 6rem;
	}

	/* Back to a grid (the mobile carousel is count-independent) */
	.gallery__grid {
		display: grid;
		grid-template-columns: repeat(min(var(--gal-cols, 3), 2), 1fr);
		overflow-x: visible;
		scroll-snap-type: none;
		padding-inline: 0;
	}

	.gallery__item {
		flex: initial;
		scroll-snap-align: none;
	}
	.gallery__item:first-child,
	.gallery__item:last-child {
		margin-inline: 0;
	}

	.gallery--gap-sm .gallery__grid {
		--gal-gap: 0.75rem;
	}
	.gallery--gap-md .gallery__grid {
		--gal-gap: 1.25rem;
	}
	.gallery--gap-lg .gallery__grid {
		--gal-gap: 2rem;
	}

	/* More images than columns → horizontal carousel instead of stacking
	   extra rows (same behaviour as the mobile view, showing --gal-visible
	   items per page with the next one peeking). */
	.gallery--carousel .gallery__grid {
		display: flex;
		flex-wrap: nowrap;
		overflow-x: auto;
		overscroll-behavior-x: contain;
		scroll-snap-type: x proximity;
		scroll-padding-inline: 0;
		padding-inline: 0;
		scrollbar-width: none;
	}
	.gallery--carousel .gallery__grid::-webkit-scrollbar {
		display: none;
	}
	.gallery--carousel .gallery__item {
		flex: 0 0 calc(
			(100% - (var(--gal-visible, 2) - 1) * var(--gal-gap, 1rem))
			/ var(--gal-visible, 2) - 0.75rem
		);
		scroll-snap-align: start;
	}

	.gallery-lightbox__inner {
		padding: 3rem 4rem;
	}

	.gallery-lightbox__prev {
		left: 1.25rem;
	}
	.gallery-lightbox__next {
		right: 1.25rem;
	}
}

/* Desktop (64rem / 1024px) */
@media (min-width: 64rem) {
	.gallery__grid {
		grid-template-columns: repeat(var(--gal-cols, 3), 1fr);
	}

	.gallery--gap-lg .gallery__grid {
		--gal-gap: 2.5rem;
	}

	/* Carousel: show the full configured column count per view. */
	.gallery--carousel .gallery__grid {
		--gal-visible: var(--gal-cols, 3);
	}
}
