/* ===========================================================================
   COVERFLOW — photographs in slanted panels, in a 3-D carousel, and the
   full-size view each opens (vub_coverflow() in inc/helpers.php; behaviour in
   assets/js/coverflow.js). Everything here is scoped to .vub-coverflow and
   .vub-lightbox.

   The panels are the homepage gallery's frames: tall parallelograms leaning
   about 23°, level tops and bottoms, sharp corners, thin white construction
   lines running on past the corners. The photograph inside stays upright;
   only the panel's clip is slanted.

   The arrangement is set here and placed by the script: these custom
   properties are its only numbers, read by coverflow.js on load and resize.
   Offsets are in panel widths, so the arrangement scales with the panels.
   =========================================================================== */
.vub-coverflow {
	position: relative;
	container-type: inline-size;
}

.vub-coverflow__stage {
	/* The panel: its width, and its shape — the gallery frame's box, about
	   27:29 — of which the clip below keeps the slanted 55%. */
	--vub-cf-w: min(58cqi, 32rem);
	--vub-cf-ratio: 27 / 29;

	/* The arrangement, in panel widths and fractions: how far out the first
	   and second panels to a side stand; how large they are; how dark (the
	   brightness) and how grey (the saturation) they are; how visible the
	   second pair is; and the turn of each side panel, in degrees.

	   A compact stack: each panel half hidden behind the one in front of it,
	   measured on the slanted panels themselves. Every panel leans the same
	   way, so the slanted part of each is a band 55% of its box wide whose
	   overlap with its neighbour's is the same at every height; at mid-height
	   it is centred on the panel. Half of a side panel's band is behind the
	   front one when its centre is 0.275 panel widths out (half of 55%), and
	   half of the outer one's behind the side one when it stands a further
	   0.275 x the side panel's scale beyond: 0.275 + 0.275 x 0.82 = 0.5. All
	   five then take about 1.66 panel widths, hence the width above. */
	--vub-cf-x1: 0.275;
	--vub-cf-x2: 0.5;
	--vub-cf-s1: 0.82;
	--vub-cf-s2: 0.66;
	--vub-cf-b1: 0.5;
	--vub-cf-b2: 0.34;
	--vub-cf-g1: 0.55;
	--vub-cf-g2: 0.45;
	--vub-cf-o2: 1;
	--vub-cf-tilt: 6;

	/* The time a move takes, in milliseconds. */
	--vub-cf-move: 580;

	position: relative;
	height: calc(var(--vub-cf-w) * 29 / 27);
	/* Room for the lines that run on past the panels' corners. */
	margin-block: var(--vub-space-md) var(--vub-space-xl);
	/* Sideways drags are the carousel's; up and down still scroll the page. */
	touch-action: pan-y;
	user-select: none;
	-webkit-user-select: none;
}

/* A phone: one large panel in front and its two neighbours, half hidden as
   above; the outer pair stays out of sight, so the front one can be larger
   (the three take about 1.37 panel widths). */
@container (max-width: 560px) {
	.vub-coverflow__stage {
		--vub-cf-w: 70cqi;
		--vub-cf-o2: 0;
	}
}

.vub-coverflow__track {
	position: absolute;
	inset: 0;
	margin: 0;
	padding: 0;
	list-style: none;
}

/* The card is a box larger than its panel; only the panel takes the pointer,
   and only within its slant (the clip is its hit area), so the part of a
   panel showing behind the one in front of it can always be clicked. */
.vub-coverflow__card {
	pointer-events: none;
	position: absolute;
	top: 0;
	left: 50%;
	width: var(--vub-cf-w);
	aspect-ratio: var(--vub-cf-ratio);
	margin: 0 0 0 calc(var(--vub-cf-w) / -2);
	transform-origin: 50% 50%;
	will-change: transform, filter, opacity;
}

/* Where each panel stands before the script takes over (and, without it, for
   good) — the same places it puts them, from the same numbers. */
.vub-coverflow__card[data-pos="0"] { z-index: 5; }

.vub-coverflow__card[data-pos="1"],
.vub-coverflow__card[data-pos="-1"] {
	z-index: 4;
	filter: brightness(var(--vub-cf-b1)) saturate(var(--vub-cf-g1));
}

.vub-coverflow__card[data-pos="2"],
.vub-coverflow__card[data-pos="-2"] {
	z-index: 3;
	opacity: var(--vub-cf-o2);
	filter: brightness(var(--vub-cf-b2)) saturate(var(--vub-cf-g2));
}

.vub-coverflow__card[data-pos="1"]  { transform: translateX(calc(var(--vub-cf-x1) * 100%)) scale(var(--vub-cf-s1)); }
.vub-coverflow__card[data-pos="-1"] { transform: translateX(calc(var(--vub-cf-x1) * -100%)) scale(var(--vub-cf-s1)); }
.vub-coverflow__card[data-pos="2"]  { transform: translateX(calc(var(--vub-cf-x2) * 100%)) scale(var(--vub-cf-s2)); }
.vub-coverflow__card[data-pos="-2"] { transform: translateX(calc(var(--vub-cf-x2) * -100%)) scale(var(--vub-cf-s2)); }

/* The panel: the photograph's rectangle, clipped to the parallelogram — the
   top edge from 45% across to the right, the bottom edge from the left to
   55% across. The photograph itself is never skewed. */
.vub-coverflow__panel {
	position: absolute;
	inset: 0;
	display: block;
	overflow: hidden;
	clip-path: polygon(45% 0, 100% 0, 55% 100%, 0 100%);
	background-color: var(--vub-surface-2);
	pointer-events: auto;
	cursor: pointer;
	-webkit-tap-highlight-color: transparent;
}

.vub-coverflow__card.is-active .vub-coverflow__panel { cursor: zoom-in; }

.vub-coverflow.is-dragging .vub-coverflow__panel { cursor: grabbing; }

.vub-coverflow__panel img {
	display: block;
	width: 100%;
	height: 100%;
	max-width: none;
	object-fit: cover;
	-webkit-user-drag: none;
	pointer-events: none;
}

/* The clip cuts away the focus ring, so the panel's own lines carry it. */
.vub-theme .vub-coverflow__panel:focus-visible { outline: none; }

/* The construction lines over each panel, stretched to its box. Quiet on the
   panels behind, a little brighter on the one in front, red with the
   keyboard on it. */
.vub-coverflow__lines {
	position: absolute;
	inset: 0;
	width: 100%;
	height: 100%;
	overflow: visible;
	pointer-events: none;
	fill: none;
	stroke: var(--vub-white);
	stroke-width: 1px;
	opacity: 0.32;
	transition: opacity var(--vub-duration-slow) var(--vub-ease), stroke var(--vub-duration) var(--vub-ease);
}

.vub-coverflow__lines path { vector-effect: non-scaling-stroke; }

.vub-coverflow__card.is-active .vub-coverflow__lines { opacity: 0.6; }

.vub-coverflow__card:has(.vub-coverflow__panel:focus-visible) .vub-coverflow__lines {
	stroke: var(--vub-red);
	stroke-width: 2px;
	opacity: 1;
}

/* The sign that the photograph in front opens: a small square in its top
   right corner, inside the slant. */
.vub-coverflow__expand {
	position: absolute;
	top: 5%;
	right: 8%;
	display: grid;
	place-items: center;
	width: 2.25rem;
	height: 2.25rem;
	border: 1px solid rgba(255, 255, 255, 0.4);
	background-color: rgba(8, 9, 10, 0.55);
	color: var(--vub-white);
	opacity: 0;
	pointer-events: none;
	transition: opacity var(--vub-duration-slow) var(--vub-ease), background-color var(--vub-duration) var(--vub-ease), border-color var(--vub-duration) var(--vub-ease);
}

.vub-coverflow__card.is-active .vub-coverflow__expand { opacity: 1; }

.vub-coverflow__card.is-active:hover .vub-coverflow__expand {
	border-color: var(--vub-red);
	background-color: var(--vub-red);
}

.vub-coverflow__expand svg {
	width: 1rem;
	height: 1rem;
	fill: none;
	stroke: currentColor;
	stroke-width: 1.6;
	stroke-linecap: square;
}

/* Previous, where you are, next. Kept in place but hidden until the script is
   running, so nothing moves when it arrives. */
.vub-coverflow__controls {
	display: flex;
	align-items: center;
	justify-content: center;
	gap: var(--vub-space-lg);
}

.vub-coverflow:not(.is-ready) .vub-coverflow__controls { visibility: hidden; }

/* Under .vub-theme throughout: Astra paints any focused or hovered <button>
   in its own blue, and this outranks it. */
.vub-theme .vub-coverflow__arrow {
	display: grid;
	place-items: center;
	flex: none;
	width: 3rem;
	height: 3rem;
	padding: 0;
	border: 1px solid var(--vub-border-strong);
	border-radius: var(--vub-radius-button);
	background-color: rgba(8, 9, 10, 0.55);
	color: var(--vub-white);
	cursor: pointer;
	transition: var(--vub-transition-color);
}

.vub-theme .vub-coverflow__arrow:hover,
.vub-theme .vub-coverflow__arrow:focus-visible {
	border-color: var(--vub-red);
	background-color: var(--vub-red);
}

.vub-coverflow__arrow svg {
	width: 1.25rem;
	height: 1.25rem;
	fill: none;
	stroke: currentColor;
	stroke-width: 1.8;
	stroke-linecap: square;
}

.vub-theme .vub-coverflow__status {
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: var(--vub-space-3xs);
	min-width: 12rem;
	margin: 0;
	text-align: center;
	/* Over the backdrop's red dots the red count would go: a dark halo. */
	text-shadow:
		0 1px 2px rgba(8, 9, 10, 0.9),
		0 0 12px rgba(8, 9, 10, 0.9);
}

.vub-coverflow__count {
	font-family: var(--vub-font-mono);
	font-size: var(--vub-text-xs);
	letter-spacing: var(--vub-tracking-wider);
	color: var(--vub-red);
}

.vub-coverflow__caption {
	font-size: var(--vub-text-sm);
	font-weight: var(--vub-weight-semibold);
	color: var(--vub-white);
}

/* ---------------------------------------------------------------------------
   The full-size view: the whole photograph, uncropped and unslanted, as large
   as the screen allows, on a dark veil. A native modal <dialog>, so the page
   behind cannot be reached; coverflow.js opens and closes it.
--------------------------------------------------------------------------- */
.vub-lightbox {
	position: fixed;
	inset: 0;
	width: 100%;
	height: 100%;
	max-width: none;
	max-height: none;
	margin: 0;
	padding: clamp(4rem, 8vh, 5.5rem) clamp(1rem, 4vw, 3rem) clamp(1.5rem, 4vh, 3rem);
	border: 0;
	background: transparent;
	color: var(--vub-white);
	/* It sits in the page's markup, inside sections whose words carry a dark
	   halo; the view needs none. */
	text-shadow: none;
	overflow: hidden;
}

.vub-lightbox[open] {
	display: flex;
	align-items: center;
	justify-content: center;
}

.vub-lightbox::backdrop {
	background-color: rgba(8, 9, 10, 0.9);
	-webkit-backdrop-filter: blur(6px);
	backdrop-filter: blur(6px);
	opacity: 0;
	transition: opacity 220ms var(--vub-ease);
}

.vub-lightbox.is-shown::backdrop { opacity: 1; }

.vub-lightbox__figure {
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: var(--vub-space-xs);
	max-width: 100%;
	max-height: 100%;
	margin: 0;
	opacity: 0;
	transform: scale(0.96);
	transition: opacity 220ms var(--vub-ease), transform 260ms var(--vub-ease-out);
}

.vub-lightbox.is-shown .vub-lightbox__figure {
	opacity: 1;
	transform: none;
}

/* The photograph at its own proportions: never wider or taller than the room
   left for it, never stretched, never cropped. */
.vub-lightbox__img {
	display: block;
	width: auto;
	height: auto;
	max-width: 100%;
	max-height: calc(100dvh - clamp(4rem, 8vh, 5.5rem) - clamp(1.5rem, 4vh, 3rem) - 2.5rem);
	object-fit: contain;
	box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6);
}

.vub-theme .vub-lightbox__caption {
	font-size: var(--vub-text-sm);
	color: var(--vub-text-muted);
	text-align: center;
}

.vub-theme .vub-lightbox__close {
	position: absolute;
	top: clamp(0.75rem, 2vh, 1.25rem);
	right: clamp(0.75rem, 2vw, 1.25rem);
	display: grid;
	place-items: center;
	width: 3rem;
	height: 3rem;
	padding: 0;
	border: 1px solid rgba(255, 255, 255, 0.45);
	border-radius: var(--vub-radius-button);
	background-color: rgba(8, 9, 10, 0.7);
	color: var(--vub-white);
	cursor: pointer;
	transition: var(--vub-transition-color);
}

.vub-theme .vub-lightbox__close:hover,
.vub-theme .vub-lightbox__close:focus-visible {
	border-color: var(--vub-red);
	background-color: var(--vub-red);
}

.vub-lightbox__close svg {
	width: 1.25rem;
	height: 1.25rem;
	fill: none;
	stroke: currentColor;
	stroke-width: 1.8;
}

/* The page under an open view holds still. The gutter is kept, so where a
   scrollbar takes room nothing shifts sideways when it goes. */
html.vub-lightbox-open {
	overflow: hidden;
	scrollbar-gutter: stable;
}

@media (prefers-reduced-motion: reduce) {
	.vub-lightbox::backdrop,
	.vub-lightbox__figure,
	.vub-coverflow__lines,
	.vub-coverflow__expand { transition: none; }

	.vub-lightbox__figure { transform: none; }
}
