/*
 * Post gallery, Metro layout: the post template's grid (its Columns and Block spacing) with a repeating pattern of
 * larger tiles, filled densely. Tiles are square; a tile spanning two columns and two rows stays square, a wide or tall
 * tile takes the height of its rows. The featured image fills its tile (object-fit: cover); a caption below it (no
 * overlay effect) takes room from the image. The pattern counts the visible items only (`of :not([hidden])`), so the
 * instant filter keeps it. Under 37.5rem every tile is a single cell.
 */
.wp-block-rtthemes-post-gallery.is-gallery-metro .wp-block-post-template {
	grid-auto-flow: dense;
}

.wp-block-rtthemes-post-gallery.is-gallery-metro .wp-block-post {
	display: flex;
	flex-direction: column;
	aspect-ratio: 1;
	min-width: 0;
}

:where(.wp-block-rtthemes-post-gallery.is-gallery-metro .wp-block-post) > :has(> .wp-block-post-featured-image) {
	display: flex;
	flex: 1 1 auto;
	flex-direction: column;
	min-height: 0;
}

.wp-block-rtthemes-post-gallery.is-gallery-metro .wp-block-post-featured-image {
	flex: 1 1 auto;
	min-height: 0;
}

.wp-block-rtthemes-post-gallery.is-gallery-metro .wp-block-post-featured-image a {
	height: 100%;
}

/* Core prints the image's aspect ratio with an inline `height: auto`; in a metro tile the tile decides the shape. */
.wp-block-rtthemes-post-gallery.is-gallery-metro .wp-block-post-featured-image img {
	width: 100%;
	height: 100% !important;
	object-fit: cover;
}

@media (min-width: 37.5rem) {
	/* Feature: the first of every six items spans two columns and two rows. */
	.is-gallery-metro.is-metro-feature .wp-block-post:nth-child(6n + 1 of :not([hidden])) {
		grid-column: span 2;
		grid-row: span 2;
	}

	/* Mosaic: a wide item and a tall item in every six. */
	.is-gallery-metro.is-metro-mosaic .wp-block-post:nth-child(6n + 1 of :not([hidden])) {
		grid-column: span 2;
		aspect-ratio: auto;
	}

	.is-gallery-metro.is-metro-mosaic .wp-block-post:nth-child(6n + 4 of :not([hidden])) {
		grid-row: span 2;
		aspect-ratio: auto;
	}

	/* Rhythm: the first and the last of every four items span two columns. */
	.is-gallery-metro.is-metro-rhythm .wp-block-post:is(:nth-child(4n + 1 of :not([hidden])), :nth-child(4n of :not([hidden]))) {
		grid-column: span 2;
		aspect-ratio: auto;
	}
}
