/*
 * Image + Text (cis/image-text). Loaded with the block, front end and editor canvas.
 *
 * A wide image with a white card laid over its lower part. The card hangs below the image and sits on the left or
 * the right. Mobile first: the card is nearly as wide as the image. From 37.5rem of block width it is narrower
 * (about 63%) and inset from its side.
 *
 * Card side: automatic alternation (the first block's card on the left, the next on the right) by nth-child among
 * the Image + Text blocks, no JS. A block can override it with --card-left / --card-right.
 *
 * The block is its own container; its parts query it, so they follow the column the article sits in, not the
 * viewport. Plain stylesheet, not compiled by Etch, so lengths are in rem and ACSS variables directly (no to-rem()).
 *
 * Measured from the design screenshot (inferred, not given): image about 3:2 with a 16px radius, card about 63% wide,
 * overlapping the image by about 60px and inset about 32px from its side, a 1px tan border, a 50px by 3px orange bar.
 */

.bw-image-text {
	/* Default (odd): card on the left. */
	--bw-card-align: flex-start;
	container-type: inline-size;
	/* Needed: a size-contained flex item whose parent is a flex column (the article body) otherwise reports an
	 * enormous height, because its aspect-ratio image has no width to resolve against while the parent sizes it. */
	inline-size: 100%;
	display: flex;
	flex-direction: column;
	margin-block: var(--space-l);
}

/* Even blocks flip. :where() keeps this rule at one class of specificity: nth-child(... of S) would otherwise add the specificity of S
 * and beat the explicit-side rules below. */
/* Even blocks flip. Counts the Image + Text blocks among their siblings, so paragraphs between them are ignored. */
.bw-image-text:where(:nth-child(even of .bw-image-text)) {
	--bw-card-align: flex-end;
}

/* Explicit side. Two classes: same specificity as the even rule and declared after it, so they win either way. */
.bw-image-text.bw-image-text--card-left {
	--bw-card-align: flex-start;
}

.bw-image-text.bw-image-text--card-right {
	--bw-card-align: flex-end;
}

.bw-image-text__media {
	position: relative;
	overflow: hidden;
	border-radius: var(--radius-m);
	aspect-ratio: 3 / 2;
	/* The image block's own margins (the editor adds some) must not push the card around. */
	margin: 0;

	/* The image fills the box, so it is taken out of flow. core/image only (articles); !important beats the
	 * aspect-ratio / object-fit style the image block can carry inline. */
	& figure {
		position: absolute;
		inset: 0;
		margin: 0;
		border-radius: inherit;
	}

	& img {
		display: block;
		inline-size: 100%;
		block-size: 100% !important;
		aspect-ratio: auto !important;
		object-fit: cover;
		border-radius: inherit;
	}

	/* A caption would have nowhere to sit inside the card layout. */
	& figcaption {
		display: none;
	}
}

.bw-image-text__card {
	position: relative;
	z-index: 1;
	box-sizing: border-box;
	align-self: var(--bw-card-align);
	/* Stacked: nearly the full width of the image, pulled up over its lower part. */
	inline-size: 90%;
	margin-inline: var(--space-xs);
	margin-block: calc(-1 * var(--space-l)) 0;
	padding: var(--space-m);
	background-color: var(--white);
	border: 0.0625rem solid var(--accent-light);
	border-radius: var(--radius-m);

	@container (min-width: 37.5rem) {
		inline-size: 63%;
		margin-inline: var(--space-m);
	}

	/* The short orange bar above the heading. Decorative, so it is a pseudo-element. */
	&::before {
		content: "";
		display: block;
		inline-size: 3.125rem;
		block-size: 0.1875rem;
		margin-block-end: var(--space-s);
		background-color: var(--secondary);
	}

	/* Spacing between the blocks inside the card, whatever the page around it does. */
	& > * {
		margin-block: 0;
	}

	& > * + * {
		margin-block-start: var(--space-xs);
	}

	/* The page's body text is weight 300, so <strong> only reaches 400 and Georgia has no face between 400 and
	 * 700. Ask for the real bold face. */
	& :is(strong, b) {
		font-weight: 700;
	}

	/* The site lowercases every heading with a rule of two classes' specificity (bmda-components.css), so the
	 * uppercase needs !important to win. The size is a token; the face (Tanker) comes from the site. */
	& :is(h2, h3, h4, h5, h6) {
		font-size: var(--text-xxl);
		line-height: 1;
		text-transform: uppercase !important;
		color: var(--neutral);
	}

	/* The button sits a little further from the text than a paragraph would. */
	& > .bw-button,
	& > .wp-block-cis-bw-button {
		margin-block-start: var(--space-s);
	}

	/* Editor only: keep the add button below the last block instead of floating over it. */
	& > .block-list-appender {
		position: static;
		inline-size: auto;
		block-size: auto;
		align-self: flex-start;
	}
}

/* No image: the card is the whole block, in normal flow. */
.bw-image-text.bw-image-text--no-image > .bw-image-text__card {
	margin-block-start: 0;
	inline-size: 100%;
	margin-inline: 0;
}
