/*
 * Card (cis/card). Loaded with the block, front end and editor canvas.
 *
 * Moved here from the Etch styles of the Card component (.bw-card, .bw-card__media, .bw-card__body) and of its image
 * (.bw-card-minimal__item-media), flattened:
 *   - every selector is wrapped in :where(), so the whole file has ZERO specificity. The block registers the same Etch styles
 *     (see bw_render_card()), so Etch prints its own copy on the page in its own order, together with the page classes that tweak
 *     the card (for example `.bw-district-life__card[data-layout='minimal'] { ... }`). This file is the fallback for where Etch's
 *     copy is not there (the editor canvas) and it can never override Etch's copy or a page class, whatever the load order.
 *   - Etch's nested rules have higher specificity than the plain ones (`.bw-card[data-layout='minimal'] .bw-card__body` beats
 *     `.bw-card__body`). With :where() they tie, so the rules are written in Etch's CASCADE order: the base rules first, the
 *     layout rules that refine them last.
 *   - the Etch @custom-media token is written out:  --block-query-large = inline-size >= 800px  (50rem).
 *
 * The card is a named size container (`card`): the media and body rules query it, and so do the layouts inside the body.
 * The unnamed container query on the card itself measures the nearest ancestor container (the card is not its own container).
 * Left out on purpose: `&.etch-builder-block a::after` (Etch's builder-only rule; the editor rule at the bottom replaces it).
 */

/* ---- .bw-card ---- */
:where(.bw-card) {
	display: flex;
	flex-direction: column;
	overflow: var(--card-overflow, hidden);
	position: relative;
	container-type: inline-size;
	container-name: card;
	gap: var(--card-gap, 0);
	padding-block: var(--card-padding, 0);
	padding-inline: var(--card-padding, 0);
	border-radius: var(--card-radius, var(--radius-m));
	background-color: var(--card-bg, transparent);
	border: var(--card-border, none);
	transition: var(--transition);
}

:where(.bw-card .bw-card__body .heading-component a) {
	text-decoration: unset;
}

/* Clickable parent: the first link in the card covers the whole card. */
:where(.bw-card a)::after {
	content: '';
	position: absolute;
	inset: 0;
	z-index: 10;
}

@media (hover: hover) and (pointer: fine) {
	:where(.bw-card:hover) {
		transform: var(--card-hover-transform, none);
		box-shadow: var(--card-hover-shadow, none);
	}
}

@media (prefers-reduced-motion: reduce) {
	:where(.bw-card) {
		transition: none;
	}
}

@container (inline-size >= 50rem) {
	:where(.bw-card) {
		justify-content: var(--card-justify-content-large, flex-start);
		align-items: var(--card-align-items-large, stretch);
	}
}

/* ---- .bw-card__media ---- */
:where(.bw-card__media) {
	position: relative;
	overflow: hidden;
	order: var(--card-media-order, 0);
	aspect-ratio: var(--card-media-aspect-ratio, 4/3);
	border-radius: var(--card-media-radius, 0);
}

@container card (inline-size >= 50rem) {
	:where(.bw-card__media) {
		position: var(--card-media-position-large, relative);
		inset: var(--card-media-inset-large, auto);
		aspect-ratio: var(--card-media-aspect-ratio-large, var(--card-media-aspect-ratio, 4/3));
	}
}

/* ---- .bw-card-minimal__item-media (the image) ---- */
:where(.bw-card-minimal__item-media) {
	position: absolute;
	inset: 0;
	inline-size: 100%;
	block-size: 100%;
	object-fit: cover;
}

/* ---- .bw-card__body ---- */
:where(.bw-card__body) {
	display: flex;
	flex-direction: column;
	order: var(--card-body-order, 1);
	gap: var(--card-body-gap, var(--space-xs));
	padding: var(--card-body-padding, var(--space-m));
	border-radius: var(--card-body-radius, 0);
	background-color: var(--card-body-bg, transparent);
	z-index: 1;
}

@container card (inline-size >= 50rem) {
	:where(.bw-card__body) {
		margin: var(--card-body-margin-large, 0);
		max-inline-size: var(--card-body-max-inline-size-large, none);
		border-radius: var(--card-body-radius-large, 0);
		background-color: var(--card-body-bg-large, transparent);
		box-shadow: var(--card-body-shadow-large, none);
		padding: var(--card-body-padding-large, var(--card-body-padding, var(--space-m)));
	}
}

/* ---- the three layouts (these refine the rules above, so they come last) ---- */
:where(.bw-card[data-layout='tile']) {
	--card-padding: 0;
	--card-bg: var(--accent);
	--card-media-order: 2;
	--card-hover-transform: translateY(to-rem(-4px));
	--card-hover-shadow: 0 to-rem(8px) to-rem(24px) rgba(0, 0, 0, 0.12);
	--card-body-padding: var(--space-s);
	--card-gap: 0;
	--card-media-aspect-ratio: 16/9;
	justify-content: space-between;
}

:where(.bw-card[data-layout='spotlight']) {
	--card-bg: var(--base);
	--card-gap: 0;
	--card-padding: var(--space-s);
	--card-body-bg: var(--white);
	--card-body-radius: var(--radius);
	--card-body-gap: var(--space-m);
}

:where(.bw-card[data-layout='spotlight'] .bw-card__body) {
	border-top-left-radius: 0;
	border-top-right-radius: 0;
	position: relative;
}

:where(.bw-card[data-layout='spotlight'] .bw-card__media > img) {
	border-bottom-left-radius: 0;
	border-bottom-right-radius: 0;
}

@container (inline-size >= 50rem) {
	:where(.bw-card[data-layout='spotlight']) {
		--card-bg: var(--white);
		--card-gap: var(--grid-gap);
		--card-padding: 0;
		--card-justify-content-large: center;
		--card-align-items-large: flex-end;
		--card-body-margin-large: var(--space-m);
		--card-body-max-inline-size-large: 52.5%;
		--card-body-radius-large: var(--radius-m);
		--card-body-bg-large: var(--white);
		--card-body-shadow-large: 0 to-rem(8px) to-rem(32px) rgba(0, 0, 0, 0.18);
		--card-media-position-large: absolute;
		--card-media-inset-large: 0;
		--card-media-aspect-ratio-large: auto;
	}

	:where(.bw-card[data-layout='spotlight'] .bw-card__body) {
		border-top-left-radius: var(--card-body-radius-large);
		border-top-right-radius: var(--card-body-radius-large);
	}

	:where(.bw-card[data-layout='spotlight'] .bw-card__media > img) {
		border-bottom-left-radius: var(--radius);
		border-bottom-right-radius: var(--radius);
	}
}

@container (inline-size >= 1000px) {
	:where(.bw-card[data-layout='spotlight']) {
		--card-body-max-inline-size-large: 40.3%;
	}
}

:where(.bw-card[data-layout='minimal']) {
	--card-padding: 0;
	--card-gap: var(--space-s);
	--card-radius: 0;
	--card-overflow: visible;
	--card-body-padding: 0;
	--card-media-aspect-ratio: 16/9;
	--card-media-radius: var(--radius-m);
}

:where(.bw-card[data-layout='minimal'] .bw-card__body) {
	padding-inline: var(--space-xs);
	padding-block-end: var(--space-s);
}

/* ---- Design change from the Etch card (2026-11-19, the user's request) ---------------------------------
 * In the tile layout the body sits ABOVE the image, and the image's global rounded corners (a site-wide `img` radius) showed as
 * notches where the two meet. The image's top-left and top-right corners are square here. This rule is NOT in :where() on
 * purpose: it has to beat the global img radius. The card still clips the bottom corners with its own radius.
 * (The Etch card of the same layout is unchanged.) */
.bw-card[data-layout='tile'] .bw-card__media > img {
	border-top-left-radius: 0;
	border-top-right-radius: 0;
}

/* ---- Editor canvas only ---------------------------------------------------------------------------
 * The block wrapper is the card element itself. The editor adds its own margins and a content width to every block; the card
 * and the blocks in its body lay themselves out, so those are removed. The clickable-parent overlay would cover the links in
 * the body and make them impossible to select, so it is off here (Etch turned it off in its builder too). */
.bw-card.wp-block {
	margin-block: 0;
	max-inline-size: none;
}

.bw-card__body > .wp-block {
	max-inline-size: none;
}

.bw-card.wp-block a::after {
	display: none;
}

.bw-card__placeholder {
	order: 0;
	display: flex;
	align-items: center;
	justify-content: center;
	min-block-size: 6rem;
	padding: 1rem;
	border: 1px dashed currentcolor;
	border-radius: var(--card-media-radius, 0);
	font-size: 0.875rem;
	opacity: 0.7;
}
