/*
 * Project galleries: a mosaic (a large photo, then smaller ones), enlarged in the theme's
 * viewer. The :not(#individual-image) part matches the weight of core's gallery rules.
 */

.wp-block-gallery.has-nested-images.wm-gallery {
	display: grid;
	grid-template-columns: repeat(6, minmax(0, 1fr));
	grid-auto-rows: clamp(110px, 13vw, 190px);
	gap: 10px;
	margin: 0;
}

/* An empty gallery in the editor: its "Upload / Media Library" box takes the full width
   instead of one cell of the mosaic. */
.wp-block-gallery.has-nested-images.wm-gallery:not(:has(> figure.wp-block-image)) {
	display: block;
}

.wp-block-gallery.has-nested-images.wm-gallery figure.wp-block-image:not(#individual-image) {
	grid-column: span 2;
	width: auto;
	height: 100%;
	margin: 0;
	overflow: hidden;
	background: var(--wm-ink);
}

.wp-block-gallery.has-nested-images.wm-gallery figure.wp-block-image:nth-child(8n + 1):not(#individual-image) {
	grid-column: span 4;
	grid-row: span 2;
}

.wp-block-gallery.has-nested-images.wm-gallery figure.wp-block-image:nth-child(8n + 7):not(#individual-image),
.wp-block-gallery.has-nested-images.wm-gallery figure.wp-block-image:nth-child(8n + 8):not(#individual-image) {
	grid-column: span 3;
}

/* The pattern repeats every 8 photos: when the last row is not full, its photos stretch to
   the full width, so no hole is left whatever the number of photos. */
@media (min-width: 701px) {
	.wp-block-gallery.has-nested-images.wm-gallery figure.wp-block-image:nth-child(8n + 1):last-child:not(#individual-image),
	.wp-block-gallery.has-nested-images.wm-gallery figure.wp-block-image:nth-child(8n + 4):last-child:not(#individual-image),
	.wp-block-gallery.has-nested-images.wm-gallery figure.wp-block-image:nth-child(8n + 7):last-child:not(#individual-image) {
		grid-column: 1 / -1;
	}

	.wp-block-gallery.has-nested-images.wm-gallery figure.wp-block-image:nth-child(8n + 2):last-child:not(#individual-image) {
		grid-row: span 2;
	}

	.wp-block-gallery.has-nested-images.wm-gallery figure.wp-block-image:nth-child(8n + 4):nth-last-child(2):not(#individual-image),
	.wp-block-gallery.has-nested-images.wm-gallery figure.wp-block-image:nth-child(8n + 5):last-child:not(#individual-image) {
		grid-column: span 3;
	}
}

.wp-block-gallery.has-nested-images.wm-gallery figure.wp-block-image a,
.wp-block-gallery.has-nested-images.wm-gallery figure.wp-block-image img {
	display: block;
	width: 100%;
	height: 100%;
	object-fit: cover;
	transition: transform 0.6s;
}

.wp-block-gallery.has-nested-images.wm-gallery figure.wp-block-image a {
	cursor: zoom-in;
}

.wp-block-gallery.has-nested-images.wm-gallery figure.wp-block-image:hover img {
	transform: scale(1.05);
}

.wp-block-gallery.has-nested-images.wm-gallery figure.wp-block-image figcaption {
	display: none;
}

/* Photos side by side in an article, with the caption underneath. */
.wp-block-gallery.has-nested-images.wm-photo-row {
	display: grid;
	grid-template-columns: repeat(auto-fit, minmax(min(100%, 260px), 1fr));
	gap: 8px;
}

.wp-block-gallery.has-nested-images.wm-photo-row figure.wp-block-image:not(#individual-image) {
	width: 100%;
	margin: 0;
}

.wp-block-gallery.has-nested-images.wm-photo-row figure.wp-block-image img {
	width: 100%;
	height: auto;
	aspect-ratio: 4 / 5;
	object-fit: cover;
}

.wp-block-gallery.has-nested-images.wm-photo-row figure.wp-block-image a {
	display: block;
	cursor: zoom-in;
}

.wp-block-gallery.has-nested-images.wm-photo-row > figcaption {
	grid-column: 1 / -1;
	flex-grow: 0;
	justify-content: flex-start;
	text-align: left;
}

@media (max-width: 700px) {
	.wp-block-gallery.has-nested-images.wm-gallery {
		grid-template-columns: repeat(2, minmax(0, 1fr));
		grid-auto-rows: 140px;
	}

	.wp-block-gallery.has-nested-images.wm-gallery figure.wp-block-image:not(#individual-image),
	.wp-block-gallery.has-nested-images.wm-gallery figure.wp-block-image:nth-child(8n + 1):not(#individual-image),
	.wp-block-gallery.has-nested-images.wm-gallery figure.wp-block-image:nth-child(8n + 7):not(#individual-image),
	.wp-block-gallery.has-nested-images.wm-gallery figure.wp-block-image:nth-child(8n + 8):not(#individual-image) {
		grid-column: span 1;
		grid-row: span 1;
	}

	.wp-block-gallery.has-nested-images.wm-gallery figure.wp-block-image:nth-child(3n + 1):not(#individual-image) {
		grid-column: span 2;
		grid-row: span 2;
	}

	/* A photo alone on the last row takes the full width. */
	.wp-block-gallery.has-nested-images.wm-gallery figure.wp-block-image:nth-child(3n + 2):last-child:not(#individual-image) {
		grid-column: span 2;
	}
}
