/*
 * `nomon/gallery` — aspect-ratio cropping and justified-mode positioning.
 *
 * Shared PhotoSwipe chrome lives in `assets/lightbox/global-styles.css`.
 */

.nomon-gallery {
	margin-block: 1.5rem;
}

.nomon-gallery__item {
	position: relative;
	display: block;
	cursor: pointer;
	overflow: hidden;
}

/* Past the image cap: still in the DOM so PhotoSwipe counts them as slides. */
.nomon-gallery__item--hidden {
	display: none;
}

/* Reuses `.nomon-gallery__item` so both layout algorithms size it like a real thumbnail. */
.nomon-gallery__more {
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 1rem;
	border: none;
	background: var(--wp--preset--color--dark);
	color: var(--wp--preset--color--white);
	font-family: inherit;
	font-size: 1rem;
	font-weight: 600;
	line-height: 1.3;
	text-align: center;
	transition: background 0.15s ease;
}

.nomon-gallery__more:hover,
.nomon-gallery__more:focus-visible {
	background: color-mix(in srgb, var(--wp--preset--color--dark) 85%, var(--wp--preset--color--white));
}

.nomon-gallery__more:focus {
	outline: none;
}

.nomon-gallery__more:focus-visible {
	outline: 2px solid color-mix(in srgb, var(--wp--preset--color--white) 80%, transparent);
	outline-offset: -2px;
}

.nomon-gallery__item img {
	display: block;
	width: 100%;
	height: 100%;
	object-fit: cover;
}

/* Leaves ~4rem clear on the right for the zoom-icon badge; text-shadow avoids needing a backdrop. */
.nomon-gallery__title {
	position: absolute;
	left: 0.75rem;
	bottom: 0.75rem;
	max-width: calc(100% - 4rem);
	color: var(--wp--preset--color--white);
	font-size: 0.875rem;
	line-height: 1.3;
	text-shadow:
		0 1px 2px var(--wp--preset--color--dark),
		0 0 8px var(--wp--preset--color--dark);
	pointer-events: none;
}

.nomon-gallery--title-hover .nomon-gallery__title {
	opacity: 0;
	transition: opacity 0.15s ease;
}

.nomon-gallery--title-hover .nomon-gallery__item:hover .nomon-gallery__title,
.nomon-gallery--title-hover .nomon-gallery__item:focus-visible .nomon-gallery__title {
	opacity: 1;
}

.nomon-gallery--grid .nomon-gallery__item {
	aspect-ratio: 1 / 1;
}

@container (min-width: 42rem) {
	.nomon-gallery--cols-3,
	.nomon-gallery--cols-4 {
		grid-template-columns: repeat(3, minmax(0, 1fr));
	}
}

@container (min-width: 56rem) {
	.nomon-gallery--cols-4 {
		grid-template-columns: repeat(4, minmax(0, 1fr));
	}
}

/* Hidden until `data-justified-ready`, so the browser can measure width without flashing a stack. */
.nomon-gallery--justified {
	position: relative;
	line-height: 0;
}

.nomon-gallery--justified:not([data-justified-ready]) {
	visibility: hidden;
}

.nomon-gallery--justified .nomon-gallery__item {
	position: absolute;
	/* top, left, width, height — set per-item by script.js */
}
