/*
 * Alternating Row (cis/alternating-row). Loaded with the block, front end and editor canvas.
 *
 * A standalone row of two sides. Mobile first: the sides stack, first side on top. From a row width of 800px (50rem, the
 * `--container-query-large` / `--block-query-large` of the site) they sit side by side in two equal columns, and every even row
 * (counted among the rows in the same content area) reverses so the image alternates left and right.
 *
 * The look is copied from the Things to Do row (the Etch styles .bw-things__row, __row-media and __row-content, with the Layout block
 * that held them: grid of 2, gap var(--space-m), centred):
 *   - two equal columns, gap var(--space-m), items centred;
 *   - the text side gets padding-inline var(--space-m) from 800px, the image side does not;
 *   - an image on either side: radius var(--radius-m), clipped (the 16/10 ratio is set on the image block itself).
 *
 * The row is its own container. A container can't be queried by itself, so the sides do the querying: each side is full width until the
 * row is wide enough, then they share the line. That is also why the row never needs to change flex-direction for mobile, and why a
 * reversed row still stacks first side on top.
 *
 * Plain stylesheet, not compiled by Etch, so lengths are written in rem directly (no to-rem()).
 */

.bw-alt-row {
	container-type: inline-size;
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: var(--space-m);
	inline-size: 100%;
}

/* Alignment options. Center is the default above, so only the other two need a class. */
.bw-alt-row--align-start {
	align-items: flex-start;
}

.bw-alt-row--align-end {
	align-items: flex-end;
}

/* Every other row flips. "of .bw-alt-row" counts only the rows among their siblings. */
.bw-alt-row:nth-child(even of .bw-alt-row) {
	flex-direction: row-reverse;
}

.bw-alt-row__side {
	display: flex;
	flex-direction: column;
	gap: var(--space-s);
	box-sizing: border-box;
	min-inline-size: 0;
	flex: 1 1 100%;

	/* Two EQUAL columns, padding included (the Etch grid gave each side 1fr). A flex-basis of 0 would add the padding of the text
	 * side on top of its share, so the basis is half the row minus half the gap (a hair less, so rounding never wraps the pair). */
	@container (inline-size >= 50rem) {
		flex: 0 1 calc((100% - var(--space-m)) / 2 - 0.02px);
	}

	/* The image on either side: cis/image's wrapper (an Etch component class, so scoped here rather than redefined) or core/image. */
	& .image-component__wrapper,
	& .wp-block-image {
		border-radius: var(--radius-m);
		overflow: hidden;
		margin: 0;
	}
}

/* The text side is padded from a wide row. The side that holds an image is not. */
@container (inline-size >= 50rem) {
	.bw-alt-row__side:not(:has(.image-component__wrapper, .wp-block-image)) {
		padding-inline: var(--space-m);
	}
}

/* ---- Editor only: the class is added by editor.js, never printed on the front end. ---- */
.bw-alt-row.wp-block {
	margin-block: 0;
	max-inline-size: none;
}

.bw-alt-row__side.is-editing {
	outline: 1px dashed color-mix(in srgb, currentcolor 35%, transparent);
	outline-offset: 0.25rem;
	min-block-size: 4rem;
	max-inline-size: none;
	margin-block: 0;

	/* .block-list-appender is WordPress's. By default it floats over the bottom right of the content; keep the add-block
	 * button below the content instead. */
	& > .block-list-appender {
		position: static;
		inline-size: auto;
		block-size: auto;
		align-self: flex-start;
	}
}
