/*
 * Styles for the Justin Reed blocks (Media Card, Media Card Row, Navigation Card).
 * Loaded on the front end and in the block editor.
 */

/* ---------- Media Card ---------- */

.jr-media-card {
	display: flex;
	flex-direction: column;
	gap: 0.85rem;
	min-width: 0;
}

/* Photo on top, always cropped to a square. */
.jr-media-card__media {
	margin: 0;
	aspect-ratio: 1 / 1;
	overflow: hidden;
}

.jr-media-card__media img {
	display: block;
	width: 100%;
	height: 100%;
	max-width: 100%;
	object-fit: cover;
	object-position: center;
}

.jr-media-card .components-placeholder {
	aspect-ratio: 1 / 1;
	min-height: 0;
}

.jr-media-card__body {
	display: flex;
	flex-direction: column;
	gap: 0.35rem;
	min-width: 0;
}

.jr-media-card__body > * {
	margin: 0;
}

/* Leave no gap for a heading or paragraph left empty. */
.jr-media-card__body > :empty {
	display: none;
}

/* H5: photo copyright. */
.jr-media-card__credit {
	font-size: 0.8rem;
	font-weight: 400;
	line-height: 1.4;
	letter-spacing: 0;
	opacity: 0.75;
}

/* H3: image title (usually a link to an external resource). */
.jr-media-card__title {
	font-size: 1.2rem;
	line-height: 1.3;
	overflow-wrap: anywhere;
}

.jr-media-card__description {
	font-size: 0.95rem;
	line-height: 1.5;
}

/* ---------- Media Card Row ----------
 * Reflow is based on the width of the row itself (container queries), so it behaves
 * the same on a phone, in a narrow column, or full width.
 *   3 cards: 1 across -> 2 across -> 3 across
 *   4 cards: 1 across -> 2 across (2 x 2) -> 4 across
 * A lone last card is centred rather than left stranded.
 */

.jr-media-card-row {
	container-type: inline-size;
	container-name: jr-media-cards;
	--jr-card-gap: clamp(1rem, 2.5vw, 1.75rem);
}

.jr-media-card-row__grid {
	display: grid;
	grid-template-columns: minmax(0, 1fr);
	gap: var(--jr-card-gap);
}

/* Editor only: the "add card" button spans the whole row. */
.jr-media-card-row__grid > .block-list-appender {
	grid-column: 1 / -1;
}

@container jr-media-cards (min-width: 28rem) {
	.jr-media-card-row__grid {
		grid-template-columns: repeat(2, minmax(0, 1fr));
	}

	.jr-media-card-row__grid > .jr-media-card:last-child:nth-child(odd) {
		grid-column: 1 / -1;
		justify-self: center;
		width: calc((100% - var(--jr-card-gap)) / 2);
	}
}

/* Exactly 3 cards: three across. */
@container jr-media-cards (min-width: 40rem) {
	.jr-media-card-row__grid:has(> .jr-media-card:nth-child(3)):not(:has(> .jr-media-card:nth-child(4))) {
		grid-template-columns: repeat(3, minmax(0, 1fr));
	}

	.jr-media-card-row__grid:has(> .jr-media-card:nth-child(3)):not(:has(> .jr-media-card:nth-child(4))) > .jr-media-card:last-child:nth-child(odd) {
		grid-column: auto;
		justify-self: stretch;
		width: auto;
	}
}

/* 4 (or more) cards: four across. */
@container jr-media-cards (min-width: 56rem) {
	.jr-media-card-row__grid:has(> .jr-media-card:nth-child(4)) {
		grid-template-columns: repeat(4, minmax(0, 1fr));
	}

	.jr-media-card-row__grid:has(> .jr-media-card:nth-child(4)) > .jr-media-card:last-child:nth-child(odd) {
		grid-column: auto;
		justify-self: stretch;
		width: auto;
	}
}

/* ---------- Navigation Card ---------- */

.jr-nav-card {
	--jr-nav-card-bg: #4d4d4d;
	box-sizing: border-box;
	position: relative;
	height: 100%;
	padding: var(--wp--preset--spacing--40, 1.5rem);
	border-radius: 20px;
	background-color: var(--jr-nav-card-bg);
	color: #fff;
}

.jr-nav-card > * {
	margin-top: 0;
	margin-bottom: 0;
	color: inherit;
}

.jr-nav-card__title {
	font-size: var(--wp--preset--font-size--medium, 1.125rem);
	line-height: 1.3;
}

.jr-nav-card__text {
	margin-top: 0.4rem;
	font-size: var(--wp--preset--font-size--small, 0.875rem);
	line-height: 1.5;
}

.jr-nav-card a {
	color: inherit;
}

/* A linked title makes the whole card clickable. */
.jr-nav-card__title a::after {
	content: "";
	position: absolute;
	inset: 0;
	border-radius: inherit;
}

.jr-nav-card:has(.jr-nav-card__title a:hover) {
	background-color: #3a3a3a;
}

.jr-nav-card:has(.jr-nav-card__title a:focus-visible) {
	outline: 3px solid currentColor;
	outline-offset: 3px;
}
