/**
 * Layout primitives.
 */

.wrap {
	width: 100%;
	max-width: var(--wrap);
	margin-inline: auto;
	padding-inline: var(--gutter);
}

.wrap--wide { max-width: var(--wrap-wide); }
.wrap--full { max-width: none; padding-inline: 0; }

.section { padding-block: var(--sp-16); }
.section--tight { padding-block: var(--sp-12); }
.section--alt { background: var(--surface-alt); }

.grid { display: grid; gap: var(--sp-6); }
.grid--2 { grid-template-columns: repeat(2, 1fr); }
.grid--3 { grid-template-columns: repeat(3, 1fr); }
.grid--4 { grid-template-columns: repeat(4, 1fr); }
.grid--6 { grid-template-columns: repeat(6, 1fr); }

/*
 * A short or unfinished row sits in the middle, under its centered heading,
 * instead of hugging the left. Flex so the leftover cards can center; each
 * card keeps the width it would have in the grid at the same column count.
 */
.grid--centered {
	--cols: 4; /* Capped below grid--6 so short and full rows stay close in width. */
	display: flex;
	flex-wrap: wrap;
	justify-content: center;
}

.grid--centered > * {
	flex: 0 0 calc((100% - (var(--cols) - 1) * var(--sp-6)) / var(--cols));
	min-width: 0;
}

/*
 * Three per row at the four-column card width: the row is three cards and
 * two gaps of the full-width grid, (3 x 100% - gap) / 4. Narrower screens
 * already run three columns or fewer, so this only applies at full width.
 */
@media (min-width: 1200px) {
	.grid--centered.grid--threes {
		--cols: 3;
		width: calc((300% - var(--sp-6)) / 4);
		margin-inline: auto;
	}
}

.split {
	display: grid;
	grid-template-columns: 42% 1fr;
	gap: var(--sp-12);
}

@media (max-width: 1199px) {
	.grid--6 { grid-template-columns: repeat(3, 1fr); }
	.grid--centered { --cols: 3; }
	.grid--4 { grid-template-columns: repeat(2, 1fr); }
	.split  { grid-template-columns: 1fr; gap: var(--sp-8); }
}

@media (max-width: 767px) {
	.grid--6, .grid--4, .grid--3, .grid--2 { grid-template-columns: repeat(2, 1fr); }
	.grid--centered { --cols: 2; }
	.section { padding-block: var(--sp-12); }
}
