/**
 * Photo Gallery block (template-parts/gallery/grid.php).
 *
 * Mosaic rhythm comes from tile classes (alston_late_gallery_tile_class(),
 * mirrored by assets/js/gallery.js when filtering):
 *   ≥ 1024px  12 columns: is-wide 8×2 rows, is-tall 4×2, others 4×1;
 *             a last tile that would leave a hole fills its row:
 *             is-full (2 rows), is-end-12, is-end-8.
 *   640–1023  2 columns: is-span spans both.
 *   < 640     1 column at 4:3.
 */

.gallery__filters {
	margin-bottom: var(--sp-8);
}

.gallery__chips {
	display: flex;
	flex-wrap: wrap;
	justify-content: center;
	gap: var(--sp-2);
	margin: 0;
	padding: 0;
	list-style: none;
}

.gallery__chip {
	appearance: none;
	padding: 10px 18px;
	border: 1px solid var(--brand-navy);
	border-radius: 999px;
	background: transparent;
	color: var(--brand-navy);
	font: 600 var(--fs-sm) / 1 var(--font-sans);
	letter-spacing: var(--tracking-wide);
	text-transform: uppercase;
	white-space: nowrap;
	cursor: pointer;
	transition: background-color 0.2s, color 0.2s;
}

.gallery__chip:hover,
.gallery__chip.is-active {
	background: var(--brand-navy);
	color: var(--ink-invert);
}

.gallery__chip:focus-visible {
	outline: 2px solid var(--brand-red);
	outline-offset: 2px;
}

.gallery__grid {
	display: grid;
	grid-template-columns: minmax(0, 1fr);
	gap: var(--sp-4);
	margin: 0;
	padding: 0;
	list-style: none;
}

.gallery__item[hidden] {
	display: none;
}

.gallery__link {
	position: relative;
	display: block;
	height: 100%;
	aspect-ratio: 4 / 3;
	overflow: hidden;
	background: var(--surface-alt);
	color: var(--ink-invert);
	text-decoration: none;
}

.gallery__link:focus-visible {
	outline: 3px solid var(--brand-red);
	outline-offset: 3px;
}

.gallery__img {
	display: block;
	width: 100%;
	height: 100%;
	object-fit: cover;
	transition: transform 0.6s cubic-bezier(0.2, 0.7, 0.2, 1);
}

.gallery__label {
	position: absolute;
	inset: auto 0 0;
	display: flex;
	flex-wrap: wrap;
	align-items: baseline;
	justify-content: space-between;
	gap: var(--sp-1) var(--sp-4);
	padding: var(--sp-8) var(--sp-5) var(--sp-4);
	background: linear-gradient(to top, rgb(17 17 17 / 0.65), rgb(17 17 17 / 0));
}

.gallery__name {
	font-family: var(--font-serif);
	font-size: var(--fs-lg);
	line-height: var(--lh-tight);
}

.gallery__cta {
	font-size: var(--fs-xs);
	font-weight: 600;
	letter-spacing: var(--tracking-wider);
	text-transform: uppercase;
}

.gallery__cta span {
	display: inline-block;
	transition: transform 0.2s;
}

.gallery__link:hover .gallery__img,
.gallery__link:focus-visible .gallery__img {
	transform: scale(1.04);
}

.gallery__link:hover .gallery__cta span,
.gallery__link:focus-visible .gallery__cta span {
	transform: translateX(4px);
}

.gallery__empty {
	text-align: center;
	color: var(--ink-muted);
}

/* Phones: the chips become one swipeable row. */
@media (max-width: 639px) {
	.gallery__chips {
		flex-wrap: nowrap;
		justify-content: flex-start;
		overflow-x: auto;
		scroll-snap-type: x proximity;
		scrollbar-width: none;
	}

	.gallery__chips::-webkit-scrollbar {
		display: none;
	}

	.gallery__chips li {
		scroll-snap-align: start;
	}
}

@media (min-width: 640px) {
	.gallery__grid {
		grid-template-columns: repeat(2, minmax(0, 1fr));
		grid-auto-rows: clamp(220px, 38vw, 360px);
	}

	.gallery__link {
		aspect-ratio: auto;
	}

	.gallery__item.is-span {
		grid-column: span 2;
	}
}

@media (min-width: 1024px) {
	.gallery__grid {
		grid-template-columns: repeat(12, minmax(0, 1fr));
		grid-auto-rows: clamp(220px, 22vw, 330px);
	}

	.gallery__item,
	.gallery__item.is-span {
		grid-column: span 4;
	}

	.gallery__item.is-tall {
		grid-row: span 2;
	}

	.gallery__item.is-wide {
		grid-column: span 8;
		grid-row: span 2;
	}

	.gallery__item.is-full {
		grid-column: 1 / -1;
		grid-row: span 2;
	}

	/* A last tile alone in a row of three takes the rest of the row. */
	.gallery__item.is-end-12 {
		grid-column: 1 / -1;
	}

	.gallery__item.is-end-8 {
		grid-column: span 8;
	}

	.gallery__name {
		font-size: var(--fs-xl);
	}

	.gallery__item:is(.is-wide, .is-full) .gallery__name {
		font-size: var(--fs-2xl);
	}
}

@media (prefers-reduced-motion: reduce) {
	.gallery__img,
	.gallery__cta span {
		transition: none;
	}

	.gallery__link:hover .gallery__img,
	.gallery__link:focus-visible .gallery__img,
	.gallery__link:hover .gallery__cta span,
	.gallery__link:focus-visible .gallery__cta span {
		transform: none;
	}
}
