/* Rows of news and project cards (query loop in a grid): at most three cards
   per row, as the library's teaser D (3 × 400 px on the 1248 px grid), and the
   parts of the cards in one row lined up – picture, date with label, title,
   text and the foot bar each start at the same height in every card, even
   when a label wraps or a title is longer. Part of the RUB Chair theme. */

.wp-block-post-template.is-layout-grid:has(> li > .rub-card) {
	/* Three columns with the two gaps between them (the query's block gap, spacing 30). */
	grid-template-columns: repeat(auto-fill, minmax(max(min(17rem, 100%), (100% - 2 * var(--wp--preset--spacing--30, 1.5rem)) / 3), 1fr));
}

/* Each card (in its list item) takes five rows of the grid and shares them
   with its neighbours (subgrid); its body shares the middle three. Inside a
   card the rows have no gap of their own – the card keeps its padding and
   margins. */
@supports (grid-template-rows: subgrid) {
	.wp-block-post-template.is-layout-grid > li:has(> .rub-card),
	.wp-block-post-template.is-layout-grid > li > .rub-card {
		display: grid;
		grid-row: span 5;
		grid-template-rows: subgrid;
		row-gap: 0;
	}

	.wp-block-post-template.is-layout-grid > li > .rub-card > .rub-card__body {
		display: grid;
		grid-row: span 3;
		grid-template-rows: subgrid;
		row-gap: 0;
	}

	/* A card body with more than three parts has no rows of its own for the rest:
	   it stays one block in its three rows instead of piling parts on top of
	   each other (its row then lines up with the others only as a whole). */
	.wp-block-post-template.is-layout-grid > li > .rub-card > .rub-card__body:has(> :nth-child(4)) {
		display: block;
	}

	/* WordPress centres a group's parts with automatic side margins; in a grid
	   that would shrink and centre them (picture, body, date row, short titles). */
	.wp-block-post-template.is-layout-grid > li > .rub-card > *,
	.wp-block-post-template.is-layout-grid > li > .rub-card > .rub-card__body > * {
		margin-left: 0 !important;
		margin-right: 0 !important;
	}
}
