/* =====================================================================
   EFCHESP — Homepage gallery: a sheared coverflow, then the lightbox
   The cards are parallelograms held in perspective. JavaScript sets two
   custom properties per card — --o (signed offset from the active card)
   and --d (its absolute value) — and CSS does the rest.
   ===================================================================== */

.gallery {
	--ease-out-expo: cubic-bezier(0.16, 1, 0.3, 1);
	--card-w: clamp(280px, 46vw, 640px);
	--card-h: clamp(300px, 31vw, 440px);
	position: relative;
	background:
		radial-gradient(130% 80% at 50% 0%, rgba(34, 45, 85, 0.75) 0%, rgba(14, 27, 51, 0) 60%),
		var(--color-blue-dark);
	color: var(--color-text-on-dark);
	overflow: hidden;
}
.section.gallery,
.gallery + .section { padding-top: var(--space-7); }

@media (min-width: 768px) {
	.section.gallery,
	.gallery + .section { padding-top: var(--space-9); }
}

/* ---------------------------------------------------------------------
   Head: title + filters
   --------------------------------------------------------------------- */

.gallery__head {
	display: flex;
	flex-wrap: wrap;
	align-items: flex-end;
	justify-content: space-between;
	gap: var(--space-5) var(--space-7);
}
.gallery__intro { max-width: 40rem; }
.gallery__intro .section-title { margin-bottom: var(--space-3); }
.gallery__lead { color: var(--color-muted-on-dark); margin: 0; }

.gallery__filters { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.gallery__filter {
	display: inline-flex;
	align-items: center;
	gap: var(--space-2);
	min-height: 44px;
	padding: var(--space-2) var(--space-4);
	border: 1px solid rgba(255, 255, 255, 0.22);
	border-radius: var(--radius-sm);
	background: transparent;
	color: var(--color-white);
	font-size: var(--fs-small);
	font-weight: 600;
	cursor: pointer;
	transition: background var(--transition-base), color var(--transition-base), border-color var(--transition-base);
}
.gallery__filter:hover { border-color: rgba(255, 255, 255, 0.6); }
.gallery__filter.is-active { background: var(--color-white); border-color: var(--color-white); color: var(--color-blue-dark); }
.gallery__filter-count { font-size: 0.6875rem; font-variant-numeric: tabular-nums; opacity: 0.6; }

/* ---------------------------------------------------------------------
   The coverflow
   --------------------------------------------------------------------- */

.coverflow {
	position: relative;
	margin-top: var(--space-7);
	perspective: 1600px;
	perspective-origin: 50% 46%;
}

.coverflow__track {
	position: relative;
	height: var(--card-h);
	margin: 0;
	padding: 0;
	list-style: none;
	transform-style: preserve-3d;
	touch-action: pan-y;
}

/* Without JavaScript the cards simply line up and scroll. */
.coverflow:not(.is-live) .coverflow__track {
	display: flex;
	gap: var(--space-4);
	overflow-x: auto;
	padding-inline: var(--container-pad);
	height: auto;
}
.coverflow:not(.is-live) .coverflow__card { position: relative; flex: none; width: 78vw; max-width: 460px; height: var(--card-h); }

.coverflow.is-live .coverflow__card {
	position: absolute;
	top: 0;
	left: 50%;
	width: var(--card-w);
	height: 100%;
	margin-left: calc(var(--card-w) / -2);
	transform:
		translateX(calc(var(--o, 0) * 72%))
		translateZ(calc(var(--d, 0) * -190px))
		rotateY(calc(var(--o, 0) * -17deg))
		scale(calc(1 - var(--d, 0) * 0.05));
	opacity: calc(1 - var(--d, 0) * 0.3);
	transition: transform 760ms var(--ease-out-expo), opacity 520ms ease;
	will-change: transform;
}
.coverflow.is-live .coverflow__card[hidden] { display: none; }
/* Beyond the third neighbour a card is out of the frame entirely. */
.coverflow.is-live .coverflow__card.is-far { opacity: 0; pointer-events: none; }

.coverflow__link {
	position: absolute;
	inset: 0;
	display: block;
	color: var(--color-white);
	text-decoration: none;
	cursor: pointer;
}
.coverflow__link:focus-visible { outline-offset: 6px; }

/* The parallelogram, with the photograph counter-sheared inside it. */
.coverflow__shear {
	position: absolute;
	inset: 0;
	display: block;
	overflow: hidden;
	background: #0c1730;
	border: 1px solid rgba(255, 255, 255, 0.16);
	transform: skewX(-9deg);
}
.coverflow__media { position: absolute; inset: 0; overflow: hidden; }
.coverflow__media img {
	width: 100%;
	height: 100%;
	object-fit: cover;
	transform: skewX(9deg) scale(1.24);
	filter: saturate(0.72) brightness(0.55);
	transition: filter 600ms ease, transform 900ms var(--ease-out-expo);
}
.coverflow__card.is-active .coverflow__media img { filter: none; }
.coverflow__card.is-active .coverflow__link:hover .coverflow__media img { transform: skewX(9deg) scale(1.3); }

/* The plate signature: gold hairline and two registration ticks, on the
   active card only. */
.coverflow__shear::after {
	content: '';
	position: absolute;
	inset: 12px;
	border: 1px solid rgba(232, 163, 23, 0);
	transition: border-color 500ms ease;
	pointer-events: none;
}
.coverflow__card.is-active .coverflow__shear::after { border-color: rgba(232, 163, 23, 0.6); }
.coverflow__card.is-active .coverflow__shear { border-color: rgba(232, 163, 23, 0.55); }

.coverflow__tick {
	position: absolute;
	width: 20px;
	height: 20px;
	border: 0 solid var(--color-gold);
	opacity: 0;
	transition: opacity 500ms ease 120ms;
	pointer-events: none;
}
.coverflow__tick--tl { top: 22px; left: 22px; border-top-width: 2px; border-left-width: 2px; }
.coverflow__tick--br { bottom: 22px; right: 22px; border-bottom-width: 2px; border-right-width: 2px; }
.coverflow__card.is-active .coverflow__tick { opacity: 1; }


/* ---------------------------------------------------------------------
   Controls
   --------------------------------------------------------------------- */

.coverflow__controls {
	display: flex;
	align-items: center;
	gap: var(--space-5);
	margin-top: var(--space-6);
}
.coverflow__counter {
	margin: 0;
	font-family: var(--font-heading);
	font-variant-numeric: tabular-nums;
	font-size: 1.125rem;
	color: var(--color-white);
	white-space: nowrap;
}
.coverflow__counter-sep { margin-inline: 0.4em; color: var(--color-gold); }
[data-coverflow-total] { color: var(--color-muted-on-dark); }

.coverflow__dashes { display: flex; align-items: center; gap: 6px; flex: 1; flex-wrap: wrap; }
.coverflow__dash {
	display: block;
	width: 26px;
	height: 2px;
	background: rgba(255, 255, 255, 0.3);
	transform: scaleX(0.55);
	transform-origin: left center;
	transition: transform 450ms var(--ease-out-expo), background 450ms ease;
}
.coverflow__dash.is-on { background: var(--color-gold); transform: none; }

.coverflow__nav { display: flex; gap: var(--space-3); }
.coverflow__button {
	display: grid;
	place-items: center;
	width: 52px;
	height: 52px;
	border-radius: 50%;
	border: 1px solid rgba(255, 255, 255, 0.3);
	background: rgba(255, 255, 255, 0.04);
	color: var(--color-white);
	cursor: pointer;
	transition: background var(--transition-base), border-color var(--transition-base), color var(--transition-base), transform var(--transition-base);
}
.coverflow__button:hover { background: var(--color-white); color: var(--color-blue-dark); border-color: var(--color-white); }
.coverflow__button:disabled { opacity: 0.35; cursor: not-allowed; }

@media (prefers-reduced-motion: reduce) {
	.coverflow.is-live .coverflow__card,
	.coverflow__dash,
	.coverflow__media img { transition: none; }
}

@media (max-width: 1023px) {
	.gallery { --card-w: clamp(260px, 72vw, 520px); --card-h: clamp(300px, 62vw, 420px); }
	.coverflow.is-live .coverflow__card {
		transform:
			translateX(calc(var(--o, 0) * 62%))
			translateZ(calc(var(--d, 0) * -110px))
			rotateY(calc(var(--o, 0) * -10deg))
			scale(calc(1 - var(--d, 0) * 0.07));
	}
	.coverflow__controls { flex-wrap: wrap; }
	.coverflow__dashes { order: 3; width: 100%; flex-basis: 100%; }
	.coverflow__nav { margin-left: auto; }
}

@media (max-width: 767px) {
	.coverflow__tick { width: 15px; height: 15px; }
	.coverflow__tick--tl { top: 16px; left: 16px; }
	.coverflow__tick--br { bottom: 16px; right: 16px; }
	.coverflow__dash { width: 16px; }
}

/* ---------------------------------------------------------------------
   Lightbox
   --------------------------------------------------------------------- */

.lightbox {
	position: fixed;
	inset: 0;
	width: 100%;
	height: 100%;
	max-width: none;
	max-height: none;
	margin: 0;
	padding: 0;
	border: 0;
	background: transparent;
	color: var(--color-white);
	overflow: hidden;
}
.lightbox::backdrop { background: transparent; }
/* The backdrop and the controls fade; the photo itself is animated by JS
   (it flies out of the clicked tile), so the dialog never fades as a whole. */
.lightbox::before {
	content: '';
	position: absolute;
	inset: 0;
	background: rgba(5, 12, 26, 0.97);
	opacity: 0;
	transition: opacity 380ms ease;
}
.lightbox__bar,
.lightbox__nav,
.lightbox.is-visible::before { opacity: 1; }
.lightbox.is-visible .lightbox__bar,
.lightbox.is-visible .lightbox__nav,
.lightbox.is-visible html.has-lightbox { overflow: hidden; }

.lightbox__stage {
	position: absolute;
	inset: 72px 96px 32px;
	display: grid;
	place-items: center;
	touch-action: pan-y;
	user-select: none;
}
.lightbox__figure {
	margin: 0;
	display: flex;
	flex-direction: column;
	align-items: center;
	max-width: 100%;
	max-height: 100%;
}
.lightbox__img {
	display: block;
	width: auto;
	height: auto;
	max-width: 100%;
	max-height: calc(100vh - 72px - 48px);
	max-height: calc(100dvh - 72px - 48px);
	border-radius: var(--radius-sm);
	box-shadow: 0 30px 80px rgba(0, 0, 0, 0.5);
	transform-origin: 0 0;
	will-change: transform, opacity;
	-webkit-user-drag: none;
}

.lightbox__bar {
	position: absolute;
	top: 0;
	left: 0;
	right: 0;
	height: 72px;
	display: flex;
	align-items: center;
	gap: var(--space-5);
	padding-inline: var(--space-5);
}
.lightbox__counter {
	margin: 0;
	font-family: var(--font-heading);
	font-variant-numeric: tabular-nums;
	font-size: 1.25rem;
	white-space: nowrap;
}
.lightbox__counter-sep { margin-inline: 0.35em; opacity: 0.4; }
[data-lightbox-total] { opacity: 0.55; }
.lightbox__progress {
	flex: 1;
	height: 2px;
	background: rgba(255, 255, 255, 0.14);
	border-radius: 2px;
	overflow: hidden;
}
.lightbox__progress span {
	display: block;
	height: 100%;
	width: 100%;
	background: var(--color-red);
	transform: scaleX(0);
	transform-origin: left;
	transition: transform 500ms var(--ease-out-expo);
}

.lightbox__close,
.lightbox__nav {
	display: grid;
	place-items: center;
	border-radius: 50%;
	border: 1px solid rgba(255, 255, 255, 0.28);
	background: rgba(255, 255, 255, 0.06);
	color: var(--color-white);
	cursor: pointer;
	-webkit-backdrop-filter: blur(8px);
	backdrop-filter: blur(8px);
	transition: opacity 300ms ease, background var(--transition-base), color var(--transition-base), border-color var(--transition-base), transform var(--transition-base);
}
.lightbox__close { width: 44px; height: 44px; flex-shrink: 0; }
.lightbox__close:hover,
.lightbox__nav:hover { background: var(--color-white); color: var(--color-blue-dark); border-color: var(--color-white); }
.lightbox__close:hover { transform: rotate(90deg); }

.lightbox__nav {
	position: absolute;
	top: 50%;
	width: 56px;
	height: 56px;
	margin-top: -28px;
}
.lightbox__nav--prev { left: var(--space-5); }
.lightbox__nav--next { right: var(--space-5); }
.lightbox__nav--prev:hover { transform: translateX(-3px); }
.lightbox__nav--next:hover { transform: translateX(3px); }

@media (max-width: 767px) {
	.lightbox__stage { inset: 64px 12px 88px; }
	.lightbox__img {
		max-height: calc(100vh - 64px - 96px);
		max-height: calc(100dvh - 64px - 96px);
	}
	.lightbox__bar { height: 64px; padding-inline: var(--space-4); gap: var(--space-4); }
	.lightbox__nav { top: auto; bottom: var(--space-5); margin-top: 0; width: 52px; height: 52px; }
	.lightbox__nav--prev { left: calc(50% - 64px); }
	.lightbox__nav--next { right: calc(50% - 64px); }
}

/* ---------------------------------------------------------------------
   Reduced motion: everything visible, no curtains, no zooms.
   --------------------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
	.gallery.is-enhanced .gallery__link { clip-path: none; }
	.gallery.is-enhanced .gallery__media { transform: none; }
	.gallery__link:hover img { transform: none; }
}
