/**
 * Casa Rispo — gallery and lightbox styles.
 *
 * Loaded only where a gallery is rendered (gallery template, experience
 * galleries, single posts with a gallery block).
 */

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

.cr-lightbox {
	position: fixed;
	inset: 0;
	z-index: var(--z-modal);
	display: flex;
	flex-direction: column;
	background-color: rgba(9, 26, 18, 0.95);
	color: #fff;
	opacity: 0;
	visibility: hidden;
	transition:
		opacity var(--dur) var(--ease),
		visibility var(--dur) var(--ease);
}

.cr-lightbox.is-open {
	opacity: 1;
	visibility: visible;
}

.cr-lightbox__bar {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: var(--space-sm);
	padding: 0.75rem clamp(0.75rem, 3vw, 1.75rem);
	flex: none;
}

.cr-lightbox__counter {
	font-size: var(--text-xs);
	letter-spacing: 0.14em;
	color: rgba(255, 255, 255, 0.62);
	font-variant-numeric: tabular-nums;
}

.cr-lightbox__tools {
	display: flex;
	gap: 0.35rem;
}

.cr-lightbox__btn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 46px;
	height: 46px;
	border: 1px solid rgba(255, 255, 255, 0.22);
	border-radius: 50%;
	color: #fff;
	background-color: transparent;
	transition:
		background-color var(--dur) var(--ease),
		border-color var(--dur) var(--ease),
		color var(--dur) var(--ease);
}

.cr-lightbox__btn:hover:not([disabled]),
.cr-lightbox__btn:focus-visible {
	background-color: #fff;
	border-color: #fff;
	color: var(--color-primary);
}

.cr-lightbox__btn[disabled] {
	opacity: 0.28;
	cursor: default;
}

.cr-lightbox__stage {
	position: relative;
	flex: 1;
	display: grid;
	place-items: center;
	padding: 0 clamp(0.5rem, 3vw, 4.5rem) var(--space-sm);
	min-height: 0;
	touch-action: pan-y;
}

.cr-lightbox__figure {
	margin: 0;
	max-width: 100%;
	max-height: 100%;
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: var(--space-sm);
}

.cr-lightbox__image {
	max-width: min(100%, 1400px);
	max-height: 72svh;
	width: auto;
	height: auto;
	object-fit: contain;
	border-radius: var(--radius-sm);
	background-color: rgba(255, 255, 255, 0.04);
	transition: transform var(--dur) var(--ease), opacity var(--dur-fast) var(--ease);
	cursor: zoom-in;
}

.cr-lightbox__image.is-zoomed {
	transform: scale(1.6);
	cursor: zoom-out;
}

.cr-lightbox__image.is-loading {
	opacity: 0.25;
}

.cr-lightbox__caption {
	max-width: 62ch;
	text-align: center;
	font-size: var(--text-sm);
	line-height: 1.6;
	color: rgba(255, 255, 255, 0.78);
}

.cr-lightbox__caption strong {
	display: block;
	font-family: var(--font-display);
	font-size: var(--text-lg);
	font-weight: 400;
	color: #fff;
	margin-bottom: 0.25rem;
}

/* Arrows sit on the sides from tablet up, and under the image on phones. */
.cr-lightbox__arrow {
	position: absolute;
	top: 50%;
	transform: translateY(-50%);
	z-index: 2;
}

.cr-lightbox__arrow--prev {
	left: clamp(0.25rem, 1.5vw, 1.25rem);
}

.cr-lightbox__arrow--next {
	right: clamp(0.25rem, 1.5vw, 1.25rem);
}

@media (max-width: 575px) {
	.cr-lightbox__arrow {
		position: static;
		transform: none;
	}

	.cr-lightbox__mobile-nav {
		display: flex;
		justify-content: center;
		gap: var(--space-sm);
		padding-bottom: calc(var(--space-sm) + env(safe-area-inset-bottom, 0px));
	}
}

@media (min-width: 576px) {
	.cr-lightbox__mobile-nav {
		display: none;
	}
}

/* Thumbnail strip. */
.cr-lightbox__thumbs {
	display: flex;
	gap: 0.4rem;
	overflow-x: auto;
	padding: 0.75rem clamp(0.75rem, 3vw, 1.75rem) calc(0.75rem + env(safe-area-inset-bottom, 0px));
	flex: none;
	scrollbar-width: thin;
	scrollbar-color: rgba(255, 255, 255, 0.25) transparent;
}

@media (max-width: 575px) {
	.cr-lightbox__thumbs {
		display: none;
	}
}

.cr-lightbox__thumb {
	flex: none;
	width: 74px;
	height: 54px;
	padding: 0;
	border: 1px solid transparent;
	border-radius: var(--radius-xs);
	overflow: hidden;
	opacity: 0.45;
	transition: opacity var(--dur) var(--ease), border-color var(--dur) var(--ease);
}

.cr-lightbox__thumb img {
	width: 100%;
	height: 100%;
	object-fit: cover;
}

.cr-lightbox__thumb:hover,
.cr-lightbox__thumb:focus-visible {
	opacity: 0.85;
}

.cr-lightbox__thumb[aria-current="true"] {
	opacity: 1;
	border-color: var(--color-accent);
}

/* ==========================================================================
   Gallery grid interactions
   ========================================================================== */

.cr-gallery-item {
	position: relative;
	display: block;
	width: 100%;
	padding: 0;
	border: 0;
	overflow: hidden;
	border-radius: var(--radius-sm);
	background-color: var(--color-background-alt);
	aspect-ratio: 4 / 3;
	cursor: zoom-in;
}

.cr-gallery-item--portrait {
	aspect-ratio: 3 / 4;
}

.cr-gallery-item--square {
	aspect-ratio: 1 / 1;
}

.cr-gallery-item img {
	width: 100%;
	height: 100%;
	object-fit: cover;
	transition: transform 900ms var(--ease-out);
}

/* Gallery page: 4 columns, uniform 5:4 tiles. */
.cr-gallery-grid--4 {
	grid-template-columns: repeat(2, minmax(0, 1fr));
	gap: var(--space-sm);
}

@media (min-width: 768px) {
	.cr-gallery-grid--4 {
		grid-template-columns: repeat(3, minmax(0, 1fr));
	}
}

@media (min-width: 1100px) {
	.cr-gallery-grid--4 {
		grid-template-columns: repeat(4, minmax(0, 1fr));
	}
}

.cr-gallery-grid--4 .cr-gallery-item,
.cr-gallery-grid--4 .cr-gallery-item--portrait,
.cr-gallery-grid--4 .cr-gallery-item--square {
	aspect-ratio: 5 / 4;
}

.cr-gallery-item:hover img,
.cr-gallery-item:focus-visible img {
	transform: scale(1.055);
}

.cr-gallery-item__overlay {
	position: absolute;
	inset: 0;
	display: flex;
	flex-direction: column;
	justify-content: flex-end;
	gap: 0.3rem;
	padding: var(--space-sm);
	background: linear-gradient(180deg, transparent 40%, rgba(14, 42, 29, 0.78) 100%);
	color: #fff;
	text-align: left;
	opacity: 0;
	transition: opacity var(--dur) var(--ease);
}

.cr-gallery-item:hover .cr-gallery-item__overlay,
.cr-gallery-item:focus-visible .cr-gallery-item__overlay {
	opacity: 1;
}

.cr-gallery-item__title {
	font-family: var(--font-display);
	font-size: var(--text-lg);
	font-weight: 400;
	line-height: 1.2;
}

.cr-gallery-item__category {
	font-size: 0.7rem;
	letter-spacing: 0.14em;
	text-transform: uppercase;
	color: var(--color-accent-light);
}

.cr-gallery-item__zoom {
	position: absolute;
	top: var(--space-sm);
	right: var(--space-sm);
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 38px;
	height: 38px;
	border-radius: 50%;
	background-color: rgba(255, 255, 255, 0.92);
	color: var(--color-primary);
	opacity: 0;
	transform: scale(0.85);
	transition: opacity var(--dur) var(--ease), transform var(--dur) var(--ease);
}

.cr-gallery-item:hover .cr-gallery-item__zoom,
.cr-gallery-item:focus-visible .cr-gallery-item__zoom {
	opacity: 1;
	transform: scale(1);
}

/* Empty state after filtering. */
.cr-gallery-empty {
	padding: var(--space-xl) 0;
	text-align: center;
	color: var(--color-text-muted);
}

.cr-gallery-empty[hidden] {
	display: none;
}

/* ==========================================================================
   WordPress core gallery block
   ========================================================================== */

.wp-block-gallery.has-nested-images figure.wp-block-image {
	border-radius: var(--radius-sm);
	overflow: hidden;
}

.wp-block-gallery.has-nested-images figure.wp-block-image img {
	transition: transform 900ms var(--ease-out);
}

.wp-block-gallery.has-nested-images figure.wp-block-image:hover img {
	transform: scale(1.04);
}
