/**
 * Gallery block style "Carousel".
 *
 * Active once assets/js/gallery-carousel.js has added .is-carousel-ready, or
 * already from the first paint when JavaScript is on (the head script in
 * functions.php adds .ueno-child-js to <html>), so the page never shows the
 * grid first and the browser doesn't download every photo for it. In the
 * editor and without JavaScript the gallery stays a normal grid.
 * The `:not(#individual-image)` parts match core's gallery selectors in strength.
 */

/*
 * Photo area height: at most 640px, and never taller than the screen minus
 * room for the header (above) and the "‹ 1/23 ›" controls (below), so the
 * arrows are visible without scrolling (at least 320px tall). Phones/tablets
 * get more room subtracted below, where the header is taller and the current
 * project title sits above the carousel. Photos keep their proportions.
 */
.wp-block-gallery.is-style-carousel:is(.is-carousel-ready, :root.ueno-child-js *) {
	--carousel-height: clamp(320px, calc(100svh - 280px), 640px);

	flex-wrap: nowrap;
	gap: 0;
	overflow-x: auto;
	overscroll-behavior-x: contain;
	scroll-behavior: smooth;
	scroll-snap-type: x mandatory;
	scrollbar-width: none;
}

.wp-block-gallery.is-style-carousel:is(.is-carousel-ready, :root.ueno-child-js *)::-webkit-scrollbar {
	display: none;
}

.wp-block-gallery.is-style-carousel:is(.is-carousel-ready, :root.ueno-child-js *):focus-visible {
	outline: 1px solid currentColor;
	outline-offset: 4px;
}

/* One photo per view. */
.wp-block-gallery.has-nested-images.is-style-carousel:is(.is-carousel-ready, :root.ueno-child-js *) figure.wp-block-image:not(#individual-image) {
	flex: 0 0 100%;
	width: 100%;
	margin: 0;
	align-items: center;
	justify-content: center;
	scroll-snap-align: center;
	scroll-snap-stop: always;
}

/*
 * The gallery can be a fraction of a pixel wider than the scroll steps (e.g.
 * 342.4px on a phone), which left a 1px sliver of the next photo at the right
 * edge. Each slide hides half a pixel at its sides, which nobody sees on the
 * current photo.
 */
.wp-block-gallery.is-style-carousel:is(.is-carousel-ready, :root.ueno-child-js *) > figure {
	clip-path: inset(0 0.5px);
}

/*
 * Every photo as large as fits (full width, at most --carousel-height tall),
 * never cropped (overrides "Crop images"). The row is as tall as the tallest
 * photo, and each photo is centred in it, so the controls don't jump.
 */
.wp-block-gallery.has-nested-images.is-style-carousel:is(.is-carousel-ready, :root.ueno-child-js *) figure.wp-block-image:not(#individual-image) img,
.wp-block-gallery.has-nested-images.is-cropped.is-style-carousel:is(.is-carousel-ready, :root.ueno-child-js *) figure.wp-block-image:not(#individual-image) img {
	flex: 0 0 auto;
	width: auto;
	max-width: 100%;
	height: auto;
	max-height: var(--carousel-height);
	object-fit: contain;
}

/*
 * Photos far from the current one aren't rendered yet, so the browser doesn't
 * download them (lazy images wait until rendered). gallery-carousel.js removes
 * .is-far when the carousel gets close. The slide keeps its width.
 */
.wp-block-gallery.has-nested-images.is-style-carousel:is(.is-carousel-ready, :root.ueno-child-js *) figure.wp-block-image.is-far:not(#individual-image) img {
	display: none;
}

.wp-block-gallery.has-nested-images.is-style-carousel:is(.is-carousel-ready, :root.ueno-child-js *) figure.wp-block-image:not(#individual-image) > a {
	flex: 0 0 auto;
	max-width: 100%;
}

/*
 * "Expand on click" button: 16px inside the photo's top-right corner. Core
 * writes its own (wrong, for centred photos) top/right inline, hence
 * !important; the offsets come from gallery-carousel.js.
 */
.wp-block-gallery.is-style-carousel:is(.is-carousel-ready, :root.ueno-child-js *) figure .lightbox-trigger {
	top: var(--carousel-trigger-top, 16px) !important;
	right: var(--carousel-trigger-right, 16px) !important;
}

/* Photo captions are never shown (they stay in the content). */
.wp-block-gallery.has-nested-images.is-style-carousel:is(.is-carousel-ready, :root.ueno-child-js *) figure.wp-block-image figcaption {
	display: none;
}

/*
 * Core draws a blurred strip (::before, backdrop-filter) behind a caption at
 * the bottom of each photo. The captions are hidden, so remove the strip too,
 * otherwise the bottom ~42px of every captioned photo looks blurry.
 */
.wp-block-gallery.has-nested-images.is-style-carousel:is(.is-carousel-ready, :root.ueno-child-js *) figure.wp-block-image:has(figcaption)::before {
	content: none;
}

/*
 * A video slide (an Embed block placed directly above the gallery, moved in by
 * ueno_child_carousel_video_slide()): one slide wide, the player as large as
 * fits at its aspect ratio (at most --carousel-height tall), at the top of the
 * carousel like the film pages' player (the photos stay centred), so it lines
 * up with the titles column. Without the carousel (editor, no JS) it's the
 * first grid item.
 */
.wp-block-gallery.has-nested-images.is-style-carousel figure.wp-block-embed {
	flex: 0 0 100%;
	width: 100%;
	margin: 0;
}

.wp-block-gallery.has-nested-images.is-style-carousel:is(.is-carousel-ready, :root.ueno-child-js *) figure.wp-block-embed {
	--carousel-video-ratio: 16 / 9;

	display: flex;
	flex-direction: column;
	align-self: flex-start;
	align-items: center;
	justify-content: flex-start;
	scroll-snap-align: center;
	scroll-snap-stop: always;
}

.wp-block-gallery.has-nested-images.is-style-carousel:is(.is-carousel-ready, :root.ueno-child-js *) figure.wp-block-embed.wp-embed-aspect-4-3 {
	--carousel-video-ratio: 4 / 3;
}

.wp-block-gallery.has-nested-images.is-style-carousel:is(.is-carousel-ready, :root.ueno-child-js *) figure.wp-block-embed .wp-block-embed__wrapper {
	width: min(100%, var(--carousel-height) * (var(--carousel-video-ratio)));
}

.wp-block-gallery.has-nested-images.is-style-carousel:is(.is-carousel-ready, :root.ueno-child-js *) figure.wp-block-embed figcaption {
	display: none;
}

/* Controls under the photo: "‹ 1/23 ›" on the right. */
.gallery-carousel-controls {
	display: flex;
	align-items: center;
	justify-content: flex-end;
	margin-top: var(--wp--preset--spacing--20, 8px);
}

.gallery-carousel-nav {
	display: flex;
	flex: 0 0 auto;
	align-items: center;
	margin-left: auto;
}

/*
 * Fast taps on ‹ › (here and in the full-screen view) are never taken as a
 * double-tap zoom on a phone.
 */
.gallery-carousel-controls button,
.wp-lightbox-overlay .wp-lightbox-navigation-button {
	touch-action: manipulation;
}

.gallery-carousel-controls button {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	min-width: 32px;
	min-height: 44px;
	margin: 0;
	padding: 0;
	border: 0;
	background: none;
	color: inherit;
	font: inherit;
	cursor: pointer;
}

.gallery-carousel-controls button:focus-visible {
	outline: 1px solid currentColor;
	outline-offset: -6px;
}

.gallery-carousel-arrow {
	font-size: 20px;
	line-height: 1;
}

.gallery-carousel-arrow:disabled {
	opacity: 0.25;
	cursor: default;
}

.gallery-carousel-counter {
	min-width: 3.5em;
	text-align: center;
	font-variant-numeric: tabular-nums;
}

/*
 * Logged in, the admin bar (32px) pushes the carousel down: reserve that too,
 * so the arrows stay on screen (visitors don't have the bar).
 */
.admin-bar .wp-block-gallery.is-style-carousel:is(.is-carousel-ready, :root.ueno-child-js *) {
	--carousel-height: clamp(320px, calc(100svh - 312px), 640px);
}

/*
 * Phones/tablets (≤781px): a square frame (screen width minus the page's 24px
 * side padding, at most 560px), as on the product page. Every slide is
 * centred in it, so nothing moves while swiping and the arrows sit close
 * under a short slide such as a 16:9 video (since 2026-11-11; before, the row
 * was as tall as the tallest portrait photo and a video left a big white gap).
 * On short screens it gets lower than square, so the arrows stay on screen:
 * at most the screen height minus 330px (header, a two-line project title
 * such as "say yes…" and the arrows; 376px with the admin bar), at least 180px.
 */
@media (max-width: 781px) {
	.wp-block-gallery.is-style-carousel:is(.is-carousel-ready, :root.ueno-child-js *) {
		--carousel-height: min(calc(100vw - 48px), 560px, max(180px, calc(100svh - 330px)));
		height: var(--carousel-height);
	}

	.admin-bar .wp-block-gallery.is-style-carousel:is(.is-carousel-ready, :root.ueno-child-js *) {
		--carousel-height: min(calc(100vw - 48px), 560px, max(180px, calc(100svh - 376px)));
	}

	.wp-block-gallery.has-nested-images.is-style-carousel:is(.is-carousel-ready, :root.ueno-child-js *) figure.wp-block-embed {
		align-self: center;
		justify-content: center;
	}
}

@media (prefers-reduced-motion: reduce) {
	.wp-block-gallery.is-style-carousel:is(.is-carousel-ready, :root.ueno-child-js *) {
		scroll-behavior: auto;
	}
}

/*
 * Full-screen view on phones/tablets: core puts the ‹ › buttons at the bottom
 * below 960px; here they sit halfway up at the left and right edge, as on
 * desktop. There the photo fills the width, so the icon gets a small white
 * round background to stay visible on dark and light photos.
 */
@media (max-width: 959px) {
	.wp-lightbox-overlay .wp-lightbox-navigation-button-prev,
	.wp-lightbox-overlay .wp-lightbox-navigation-button-next {
		bottom: 50%;
		transform: translateY(50%);
	}

	.wp-lightbox-overlay .wp-lightbox-navigation-icon {
		display: flex;
		align-items: center;
		justify-content: center;
		width: 32px;
		height: 32px;
		border-radius: 50%;
		background: rgba(255, 255, 255, 0.85);
	}
}
