/* =========================================================================
 * Gallery grid + lightbox.
 *
 * Loaded only on pages that actually render a [gallery] (the renderer enqueues
 * it from inside the post_gallery filter), so nothing here costs a page that
 * has no photos on it.
 *
 * SPECIFICITY, ON PURPOSE
 *
 * Astra paints bare <button> -- background, border, padding, a hover colour --
 * and it does so from selectors that out-weigh a single class. The map plugin
 * hit exactly this and lost the legend's colours on the live site while the
 * local preview rendered them correctly (fix 29). Every rule that has to beat
 * a theme rule therefore repeats its own class. Do not "tidy" those repeats
 * away: the fix would be invisible locally and would only break in production.
 * ========================================================================= */

/* --- 1. tokens ---------------------------------------------------------- */

.g2v-gallery {
	--g2v-gal-gap: 10px;
	--g2v-gal-radius: 10px;
	--g2v-gal-ink: #1c1c1c;
	--g2v-gal-accent: #da8c27;
}

/* --- 2. the grid -------------------------------------------------------- */

/* Two columns on a phone whatever the setting says: three 110px-wide tiles of
 * a landscape photo are three unreadable smudges, and this grid replaced a
 * core one that was fixed-percentage and could not reflow at all. The site-wide
 * column count takes over once there is room for it to mean something. */
.g2v-gallery {
	display: grid;
	grid-template-columns: repeat(2, minmax(0, 1fr));
	gap: var(--g2v-gal-gap);
	margin: 1.6em 0;
	padding: 0;
	clear: both;
}

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

@media (min-width: 960px) {
	.g2v-gallery {
		grid-template-columns: repeat(var(--g2v-gal-cols, 3), minmax(0, 1fr));
	}
}

.g2v-gallery-item {
	margin: 0;
	padding: 0;
	min-width: 0; /* or a wide image forces its grid track past 1fr */
}

.g2v-gallery-link,
.g2v-gallery .g2v-gallery-img {
	display: block;
	width: 100%;
}

.g2v-gallery-link {
	position: relative;
	overflow: hidden;
	border-radius: var(--g2v-gal-radius);
	background: #ececec;
	line-height: 0;
	box-shadow: none;
	text-decoration: none;
}

.g2v-gallery .g2v-gallery-img {
	height: 100%;
	aspect-ratio: var(--g2v-gal-ratio, 4 / 3);
	/* cover, never contain: these are 4:3 and 16:9 phone photos mixed in one
	 * gallery, and contain letterboxes half of them into a grey frame. */
	object-fit: cover;
	object-position: center;
	transition: transform .35s ease;
	border-radius: inherit;
	margin: 0;
}

/* "Natural" keeps each photo's own shape -- a row is then as tall as its
 * tallest member, which is the honest trade for not cropping anything. */
.g2v-gallery.is-natural .g2v-gallery-img {
	aspect-ratio: auto;
	height: auto;
	object-fit: contain;
}

.g2v-gallery.has-lightbox .g2v-gallery-link { cursor: zoom-in; }

@media (hover: hover) {
	.g2v-gallery.has-lightbox .g2v-gallery-link:hover .g2v-gallery-img { transform: scale(1.045); }
}

.g2v-gallery-link:focus-visible {
	outline: 3px solid var(--g2v-gal-accent);
	outline-offset: 3px;
}

/* The magnifier badge. A grid of photos with no affordance reads as decoration;
 * this is the one hint that a tile is a control. */
.g2v-gallery.has-lightbox .g2v-gallery-link::after {
	content: "";
	position: absolute;
	right: 8px;
	bottom: 8px;
	width: 26px;
	height: 26px;
	border-radius: 50%;
	background: rgba(20, 20, 20, .58) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%23fff'%3E%3Cpath d='M15.5 14h-.8l-.3-.3a6.5 6.5 0 1 0-.7.7l.3.3v.8l5 5 1.5-1.5-5-5zm-6 0a4.5 4.5 0 1 1 0-9 4.5 4.5 0 0 1 0 9zM12 10H10v2H9v-2H7V9h2V7h1v2h2v1z'/%3E%3C/svg%3E") center / 15px 15px no-repeat;
	opacity: 0;
	transition: opacity .2s ease;
	pointer-events: none;
}

.g2v-gallery.has-lightbox .g2v-gallery-link:hover::after,
.g2v-gallery.has-lightbox .g2v-gallery-link:focus-visible::after { opacity: 1; }

/* On a touch screen there is no hover to reveal it, so it is simply always on. */
@media (hover: none) {
	.g2v-gallery.has-lightbox .g2v-gallery-link::after { opacity: .85; }
}

.g2v-gallery-caption {
	margin: 6px 2px 0;
	font-size: .82em;
	line-height: 1.4;
	color: #4a4a4a;
	text-align: left;
}

/* --- 3. the lightbox ---------------------------------------------------- */

.g2v-lb {
	position: fixed;
	inset: 0;
	/* Measured, not guessed. Two fixed/positioned things on this site already
	 * sit up here: TranslatePress's floating language switcher at 99999 (fix 20
	 * put it there and it is on every page), and the map plugin's menu panel at
	 * 100000. At 99999 the overlay tied with the switcher and won only on
	 * document order -- a full-screen photo with a language dropdown floating
	 * over it, one DOM change away. This clears both by a margin, and still sits
	 * under the WSL lab's own switcher bar (2147483000), which is furniture that
	 * exists on no real site. */
	z-index: 2000000;
	display: none;
	align-items: center;
	justify-content: center;
	/* The overlay must not inherit the article's font metrics for its counter. */
	font-family: inherit;
	-webkit-tap-highlight-color: transparent;
}

.g2v-lb.is-open { display: flex; }

.g2v-lb-backdrop {
	position: absolute;
	inset: 0;
	background: rgba(11, 11, 13, .94);
}

.g2v-lb-stage {
	position: relative;
	z-index: 1;
	display: flex;
	align-items: center;
	justify-content: center;
	width: 100%;
	height: 100%;
	padding: 60px 16px 74px;
	box-sizing: border-box;
	overflow: hidden;
	touch-action: pan-y;
}

.g2v-lb.is-zoomed .g2v-lb-stage { touch-action: none; }

.g2v-lb-figure {
	margin: 0;
	max-width: 100%;
	max-height: 100%;
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	transition: transform .18s ease-out;
}

.g2v-lb.is-dragging .g2v-lb-figure { transition: none; }

.g2v-lb-img {
	display: block;
	max-width: 100%;
	max-height: 100%;
	width: auto;
	height: auto;
	object-fit: contain;
	border-radius: 4px;
	transition: transform .22s ease-out;
	cursor: zoom-in;
	user-select: none;
	-webkit-user-drag: none;
}

.g2v-lb.is-zoomed .g2v-lb-img { cursor: zoom-out; }
.g2v-lb.is-dragging .g2v-lb-img { transition: none; }

.g2v-lb-caption {
	max-width: min(900px, 92vw);
	margin: 12px auto 0;
	/* #d9d9d9 on #0b0b0d is 12.6:1 -- comfortably past the 7:1 body-text bar,
	 * which matters because a caption is often the only text on the screen. */
	color: #d9d9d9;
	font-size: .92rem;
	line-height: 1.45;
	text-align: center;
}

.g2v-lb-caption[hidden] { display: none; }

.g2v-lb-bar {
	position: absolute;
	z-index: 2;
	top: 0;
	left: 0;
	right: 0;
	display: flex;
	align-items: center;
	gap: 6px;
	padding: 10px 12px;
	box-sizing: border-box;
}

.g2v-lb-counter {
	flex: 1 1 auto;
	margin: 0;
	color: #e6e6e6;
	font-size: .95rem;
	font-variant-numeric: tabular-nums;
	letter-spacing: .02em;
}

/* --- 4. the controls ---------------------------------------------------- */

/* Triple-repeated class = (0,4,0). See the header note: Astra's own button
 * rules out-weigh a single class and would otherwise repaint every one of
 * these with the theme's link colour and a visible plate. */
.g2v-lb.g2v-lb.g2v-lb .g2v-lb-btn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	/* 44px is the tap-target floor, and these sit over a photo where a miss
	 * means an accidental zoom rather than a no-op. */
	width: 44px;
	height: 44px;
	padding: 0;
	border: 0;
	border-radius: 50%;
	background: rgba(255, 255, 255, .10);
	color: #fff;
	box-shadow: none;
	text-decoration: none;
	line-height: 0;
	cursor: pointer;
	transition: background-color .18s ease, transform .18s ease;
}

.g2v-lb.g2v-lb.g2v-lb .g2v-lb-btn svg {
	width: 22px;
	height: 22px;
	fill: currentColor;
	pointer-events: none;
}

.g2v-lb.g2v-lb.g2v-lb .g2v-lb-btn:hover,
.g2v-lb.g2v-lb.g2v-lb .g2v-lb-btn:focus-visible {
	background: var(--g2v-gal-accent, #da8c27);
	color: #fff;
}

.g2v-lb.g2v-lb.g2v-lb .g2v-lb-btn:focus-visible {
	outline: 3px solid #fff;
	outline-offset: 2px;
}

.g2v-lb.g2v-lb.g2v-lb .g2v-lb-btn:active { transform: scale(.93); }

.g2v-lb.g2v-lb.g2v-lb .g2v-lb-prev,
.g2v-lb.g2v-lb.g2v-lb .g2v-lb-next {
	position: absolute;
	z-index: 2;
	top: 50%;
	transform: translateY(-50%);
	width: 50px;
	height: 50px;
	background: rgba(0, 0, 0, .42);
}

.g2v-lb.g2v-lb.g2v-lb .g2v-lb-prev:active,
.g2v-lb.g2v-lb.g2v-lb .g2v-lb-next:active { transform: translateY(-50%) scale(.93); }

.g2v-lb.g2v-lb.g2v-lb .g2v-lb-prev { left: 12px; }
.g2v-lb.g2v-lb.g2v-lb .g2v-lb-next { right: 12px; }

.g2v-lb .g2v-lb-btn[hidden] { display: none; }

/* Zoomed in, the arrows sit on top of the part you zoomed in to look at. */
.g2v-lb.is-zoomed .g2v-lb-prev,
.g2v-lb.is-zoomed .g2v-lb-next { opacity: .25; }

/* On a phone the arrows are redundant -- swipe is the gesture, and 50px discs
 * over a 390px-wide photo cover a sixth of it. They move to the bottom, small,
 * as a hint that the gallery has more in it, not as the way through it. */
@media (max-width: 600px) {
	.g2v-lb-stage { padding: 56px 8px 92px; }

	.g2v-lb.g2v-lb.g2v-lb .g2v-lb-prev,
	.g2v-lb.g2v-lb.g2v-lb .g2v-lb-next {
		top: auto;
		bottom: 18px;
		transform: none;
		width: 44px;
		height: 44px;
	}

	.g2v-lb.g2v-lb.g2v-lb .g2v-lb-prev:active,
	.g2v-lb.g2v-lb.g2v-lb .g2v-lb-next:active { transform: scale(.93); }

	.g2v-lb.g2v-lb.g2v-lb .g2v-lb-prev { left: 24px; }
	.g2v-lb.g2v-lb.g2v-lb .g2v-lb-next { right: 24px; }

	.g2v-lb-caption { font-size: .85rem; margin-top: 8px; }
}

/* --- 5. loading --------------------------------------------------------- */

.g2v-lb.is-loading .g2v-lb-img { opacity: .25; }

.g2v-lb.is-loading .g2v-lb-stage::after {
	content: "";
	position: absolute;
	top: 50%;
	left: 50%;
	width: 34px;
	height: 34px;
	margin: -17px 0 0 -17px;
	border: 3px solid rgba(255, 255, 255, .28);
	border-top-color: #fff;
	border-radius: 50%;
	animation: g2v-lb-spin .8s linear infinite;
}

@keyframes g2v-lb-spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
	.g2v-lb-img,
	.g2v-lb-figure,
	.g2v-gallery .g2v-gallery-img,
	.g2v-lb.g2v-lb.g2v-lb .g2v-lb-btn { transition: none; }

	.g2v-lb.is-loading .g2v-lb-stage::after { animation-duration: 2.4s; }
}
