/*
 * Block style: Curved edge.
 *
 * The end edge (right, in left-to-right languages) is part of a circle. It
 * leaves the top end corner going straight down and meets the bottom edge at
 * 72% of the width, as in the Figma design. For a column w wide and h tall the
 * radius is r = ((0.28 w)^2 + h^2) / (0.56 w), centred on the top edge, r in
 * from the end edge (2026-12-05; before, a quarter ellipse that squashed flat
 * in short columns).
 *
 * CSS cannot read a column's height, so curved-edge.js measures each column
 * and sets --uwcm-curved-edge-r plus the attribute data-uwcm-curved-edge on the
 * element that carries the background. Until then, and without JavaScript,
 * the old quarter ellipse shows (border-end-end-radius).
 *
 * Drawing: the column's own background (preset class, custom color or
 * gradient) is inherited by a ::before layer behind the content and masked to
 * the circle plus the strip before it. The column itself paints its
 * background only behind its text (background-clip: text), where the text
 * covers it, so the content is never cut off by the curve.
 *
 * With no background chosen, the column falls back to the design's light blue.
 */

/* Core Column: the background sits on the column itself. */
.wp-block-column.is-style-uwcm-curved-edge {
	border-end-end-radius: 28% 100%;
}

.wp-block-column.is-style-uwcm-curved-edge:not(.has-background) {
	background-color: var(--wp--preset--color--soft-blue-overlay, rgba(167, 210, 255, 0.3));
}

/*
 * Genesis Blocks "Advanced Columns" column: the style class lands on the
 * outer element, but the background sits on the inner element.
 * Background classes there are has-<slug>-background-color or
 * gb-has-custom-background-color; there is no has-background.
 */
.gb-block-layout-column.is-style-uwcm-curved-edge > .gb-block-layout-column-inner {
	border-end-end-radius: 28% 100%;
}

.gb-block-layout-column.is-style-uwcm-curved-edge > .gb-block-layout-column-inner:not([class*="-background-color"]) {
	background-color: var(--wp--preset--color--soft-blue-overlay, rgba(167, 210, 255, 0.3));
}

/*
 * Fill the full row height, as in the design. Genesis Blocks aligns a column
 * vertically by shrinking the whole column (align-self), which would shrink
 * the background and the curve to the content. Here the column always
 * stretches, the inner element fills it, and the column's vertical alignment
 * setting moves the content inside instead.
 * The extra wp-block-genesis-blocks-gb-column class outranks Genesis Blocks'
 * own .gb-block-layout-column.gb-is-vertically-aligned-* rules.
 */
.wp-block-genesis-blocks-gb-column.gb-block-layout-column.is-style-uwcm-curved-edge {
	align-self: stretch;
	display: flex;
	flex-direction: column;
}

.wp-block-genesis-blocks-gb-column.is-style-uwcm-curved-edge > .gb-block-layout-column-inner {
	flex: 1 1 auto;
	display: flex;
	flex-direction: column;
	justify-content: flex-start;
}

.wp-block-genesis-blocks-gb-column.gb-is-vertically-aligned-center.is-style-uwcm-curved-edge > .gb-block-layout-column-inner {
	justify-content: center;
}

.wp-block-genesis-blocks-gb-column.gb-is-vertically-aligned-bottom.is-style-uwcm-curved-edge > .gb-block-layout-column-inner {
	justify-content: flex-end;
}

/* ---- The circle, once curved-edge.js has measured the column ---- */
.wp-block-column.is-style-uwcm-curved-edge[data-uwcm-curved-edge],
.gb-block-layout-column.is-style-uwcm-curved-edge > .gb-block-layout-column-inner[data-uwcm-curved-edge] {
	position: relative;
	isolation: isolate;
	border-end-end-radius: 0;
	-webkit-background-clip: text;
	background-clip: text;
}

.wp-block-column.is-style-uwcm-curved-edge[data-uwcm-curved-edge]::before,
.gb-block-layout-column.is-style-uwcm-curved-edge > .gb-block-layout-column-inner[data-uwcm-curved-edge]::before {
	--uwcm-curved-edge-mask:
		radial-gradient(circle var(--uwcm-curved-edge-r) at calc(100% - var(--uwcm-curved-edge-r)) 0, #000 calc(var(--uwcm-curved-edge-r) - 0.5px), transparent var(--uwcm-curved-edge-r)),
		linear-gradient(to right, #000 calc(100% - var(--uwcm-curved-edge-r)), transparent 0);

	content: "";
	position: absolute;
	z-index: -1;
	inset: 0;
	border-radius: inherit;
	background: inherit;
	-webkit-background-clip: border-box;
	background-clip: border-box;
	pointer-events: none;
	-webkit-mask-image: var(--uwcm-curved-edge-mask);
	mask-image: var(--uwcm-curved-edge-mask);
	-webkit-mask-repeat: no-repeat;
	mask-repeat: no-repeat;
}

/* Right-to-left languages: the circle on the left edge, as the old curve did. */
.wp-block-column.is-style-uwcm-curved-edge[data-uwcm-curved-edge]:dir(rtl)::before,
.gb-block-layout-column.is-style-uwcm-curved-edge > .gb-block-layout-column-inner[data-uwcm-curved-edge]:dir(rtl)::before {
	--uwcm-curved-edge-mask:
		radial-gradient(circle var(--uwcm-curved-edge-r) at var(--uwcm-curved-edge-r) 0, #000 calc(var(--uwcm-curved-edge-r) - 0.5px), transparent var(--uwcm-curved-edge-r)),
		linear-gradient(to left, #000 calc(100% - var(--uwcm-curved-edge-r)), transparent 0);
}
