/**
 * Story Cards widget.
 * Design: Figma "why people sta" (hDnYALoz9b7tlb7gTrhfkI, node 615:392).
 * Hover motion: the stories module on Monarch's careers page.
 *
 * The widget's controls write the custom properties and declarations below
 * from Elementor's generated CSS; the values here are the Figma defaults and
 * only apply if that CSS is missing.
 *
 * Card structure: .sf-story-cards__card is a one-column grid with two rows.
 * The photo and the caption panel are both in-flow grid items, so a card is
 * always at least as tall as its photo proportions ask for AND as tall as its
 * fully expanded panel: long text can never be clipped.
 *
 * Two modes, switched by custom properties (the "Hover Text" control writes
 * them per device, and touch screens force the second one below):
 *
 *   Slide up on hover  photo and panel share both rows (panel over the photo,
 *                      pinned to the bottom); the panel is hidden until hover.
 *   Always show        photo in row 1, panel in row 2 under it, text visible.
 *
 * The slide is transform-only, with no measuring and no script. At rest:
 *   - the panel (caption + text) is pushed down by 100% of its own height, so
 *     it sits entirely below the card, clipped by the card's overflow;
 *   - the caption inside it is pulled back up by 100% of its own height, so
 *     just the caption bar shows over the bottom of the photo.
 * On hover both go to 0 with the same duration and easing. The caption's
 * on-screen offset is then (panel height - caption height) x (1 - progress),
 * which is exactly "slide up by the height of the extra text", whatever that
 * height is, and it stays correct when the caption wraps or the text is long.
 * --sf-hide (1 at rest, 0 when revealed) drives every piece of it.
 */

.sf-story-cards {
	--sf-intro-w: 30.2%; /* 502px of the 1662px design frame */
	--sf-cols: 2;
	--sf-gap-x: 35px;
	--sf-gap-y: 17px;
	--sf-ratio: 1.437; /* half card photo, width / height: 536 x 373 in the design */
	--sf-radius: 10px;
	--sf-bar-bg: var(--e-global-color-secondary, #007c85);
	--sf-pad-top: 15px;
	--sf-pad-right: 18px;
	--sf-pad-bottom: 21px;
	--sf-pad-left: 18px;
	--sf-ease: cubic-bezier(0.075, 0.82, 0.165, 1); /* expo out */

	/* Mode switches: "Slide up on hover". */
	--sf-photo-rows: 1 / -1;
	--sf-panel-rows: 1 / -1;
	--sf-panel-align: end;
	--sf-rest: 1;
	--sf-zoom: 0.025;

	/*
	 * Photo height: the width of one half card divided by the proportions, so
	 * it scales continuously with the cards column. 100cqi is the grid's width
	 * (the grid is the size container). A full card uses the same height.
	 */
	--sf-photo-h: var(--sf-photo-fixed, calc((100cqi - (var(--sf-cols) - 1) * var(--sf-gap-x)) / var(--sf-cols) / var(--sf-ratio)));

	display: grid;
	grid-template-columns: var(--sf-intro-w) minmax(0, 1fr);
	align-items: start;
	column-gap: 53px;
	row-gap: 40px;
}

/* Intro column */

.sf-story-cards__intro {
	min-width: 0;
	padding-top: 31px;
}

/* Doubled class so these beat theme and Elementor heading/paragraph resets. */
.sf-story-cards .sf-story-cards__eyebrow,
.sf-story-cards .sf-story-cards__heading {
	margin-top: 0;
	padding: 0;
	overflow-wrap: break-word;
}

/*
 * Colors fall back to the kit globals here because Elementor only writes a
 * color control's global default into the saved settings when the widget is
 * added in the editor. A widget saved any other way (imported, templated,
 * scripted) would otherwise inherit the body text color. The control output
 * is more specific, so an editor choice still wins.
 */
.sf-story-cards .sf-story-cards__eyebrow {
	margin-bottom: 26px;
	line-height: normal;
	color: var(--e-global-color-secondary, #007c85);
}

.sf-story-cards .sf-story-cards__heading {
	margin-bottom: 24px;
	text-wrap: balance;
	color: var(--e-global-color-primary, #1d355a);
}

.sf-story-cards .sf-story-cards__body {
	margin-bottom: 22px;
	color: var(--e-global-color-text, #111);
	max-width: 70ch; /* only bites when the intro is stacked full width */
}

.sf-story-cards__body > :first-child {
	margin-top: 0;
}

.sf-story-cards__body > :last-child {
	margin-bottom: 0;
}

.sf-story-cards .sf-story-cards__body p {
	margin-block: 0 1em;
}

.sf-story-cards .sf-story-cards__body p:last-child {
	margin-bottom: 0;
}

.sf-story-cards__intro > :last-child {
	margin-bottom: 0;
}

.sf-story-cards .sf-story-cards__button {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	max-width: 100%;
	padding: 14px 26px;
	border: 0;
	border-radius: 4px;
	background-color: var(--sf-btn-bg, var(--e-global-color-primary, #1d355a));
	color: var(--sf-btn-color, #fff);
	line-height: 16px;
	text-align: center;
	text-decoration: none;
	transition: background-color 0.2s ease, color 0.2s ease;
}

/*
 * Button colors run through custom properties that the widget's color controls
 * set on the button (--sf-btn-color, --sf-btn-bg, --sf-btn-hover-color,
 * --sf-btn-hover-bg), so specificity never decides which color shows. Each
 * var() falls back to the kit global, for the same reason as the text colors
 * above: a control whose default is a global is only saved when the widget is
 * added in the editor. So a custom resting color with the default hover still
 * gets the teal hover, and a custom hover color always wins.
 * :where(a) limits the hover to the real link; the editor-only <span> preview
 * shown when no link is set is not clickable, so it should not react to the
 * pointer.
 */
.sf-story-cards :where(a).sf-story-cards__button:hover,
.sf-story-cards :where(a).sf-story-cards__button:focus-visible {
	background-color: var(--sf-btn-hover-bg, var(--e-global-color-secondary, #007c85));
	color: var(--sf-btn-hover-color, var(--sf-btn-color, #fff));
}

.sf-story-cards .sf-story-cards__button:focus-visible {
	outline: 2px solid var(--e-global-color-primary, #1d355a);
	outline-offset: 3px;
}

/* Editor-only guidance (never rendered for visitors). */
.sf-story-cards .sf-story-cards__notice {
	margin: 10px 0 0;
	padding: 8px 12px;
	border-radius: 6px;
	background: #fff8e1;
	color: #3d2e00;
	font: 13px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
	box-shadow: 0 0 0 1px #f0d98c;
}

/* Card grid */

.sf-story-cards .sf-story-cards__grid {
	container-type: inline-size;
	display: grid;
	grid-template-columns: repeat(var(--sf-cols), minmax(0, 1fr));
	gap: var(--sf-gap-y) var(--sf-gap-x);
	min-width: 0;
	margin: 0;
	padding: 0;
	list-style: none;
}

.sf-story-cards--no-intro .sf-story-cards__grid {
	grid-column: 1 / -1;
}

.sf-story-cards .sf-story-cards__item {
	display: grid;
	min-width: 0;
	margin: 0;
	padding: 0;
}

.sf-story-cards .sf-story-cards__item::before,
.sf-story-cards .sf-story-cards__item::after {
	content: none;
}

.sf-story-cards__item--full {
	grid-column: 1 / -1;
}

/* Card */

.sf-story-cards .sf-story-cards__card {
	--sf-hide: var(--sf-rest);

	position: relative;
	display: grid;
	grid-template-columns: minmax(0, 1fr);
	grid-template-rows: auto 1fr;
	overflow: hidden;
	/*
	 * Round the corners with ONE clip over the whole card. With border-radius
	 * plus overflow: hidden, the browser anti-aliases each layer's curve on its
	 * own (the card background, the photo, the caption bar), and the layers
	 * underneath bleed through as a faint colored hairline on the corners.
	 * clip-path masks the finished card once, so the edge stays clean. The card
	 * paints no background of its own for the same reason.
	 */
	clip-path: inset(0 round var(--sf-radius));
	isolation: isolate; /* keeps the clip intact while the photo scales (Safari) */
	color: inherit;
	text-decoration: none;
}

.sf-story-cards .sf-story-cards__card:hover,
.sf-story-cards .sf-story-cards__card:focus-visible {
	--sf-hide: 0;
}

/* The ring goes on the list item: the card's clip-path would cut an outline off. */
.sf-story-cards__item {
	border-radius: var(--sf-radius);
}

.sf-story-cards__item:has(> a.sf-story-cards__card:focus-visible) {
	outline: 3px solid var(--e-global-color-primary, #1d355a);
	outline-offset: 3px;
}

.sf-story-cards__media {
	position: relative;
	grid-row: var(--sf-photo-rows);
	grid-column: 1;
	min-height: 260px; /* before container query units: very old browsers only */
	min-height: var(--sf-photo-h);
	overflow: hidden;
}

/* Only a card without a photo gets a fill; behind a photo it would show at the edges. */
.sf-story-cards__media--empty {
	background-color: var(--e-global-color-primary, #1d355a);
}

.sf-story-cards .sf-story-cards__img {
	position: absolute;
	inset: 0;
	display: block;
	width: 100%;
	height: 100%;
	max-width: none;
	margin: 0;
	border: 0;
	border-radius: 0;
	box-shadow: none;
	object-fit: cover;
	object-position: var(--sf-focus-x, 50%) var(--sf-focus-y, 50%);
	transform: scale(calc(1 + var(--sf-zoom) * (1 - var(--sf-hide))));
	transition: transform 0.5s ease-in;
}

.sf-story-cards__panel {
	position: relative;
	z-index: 1;
	grid-row: var(--sf-panel-rows);
	grid-column: 1;
	/*
	 * Slide up: pinned to the bottom of the photo. Always show: fills its row,
	 * because cards in a row stretch to the tallest one, and a bottom-pinned
	 * panel in a shorter card would leave a white gap under its photo.
	 */
	align-self: var(--sf-panel-align);
	background-color: var(--sf-bar-bg);
	transform: translateY(calc(var(--sf-hide) * 100%));
	transition: transform 1s var(--sf-ease);
}

/* The caption text sits in one inner span, so a line break in it stays a line break. */
.sf-story-cards .sf-story-cards__title {
	display: flex;
	align-items: center;
	box-sizing: border-box;
	min-height: 60px;
	margin: 0;
	padding: var(--sf-pad-top) var(--sf-pad-right) var(--sf-pad-bottom) var(--sf-pad-left);
	background-color: var(--sf-bar-bg);
	color: #fff;
	overflow-wrap: break-word;
	transform: translateY(calc(var(--sf-hide) * -100%));
	transition: transform 1s var(--sf-ease);
}

.sf-story-cards .sf-story-cards__text {
	padding: 0 var(--sf-pad-right) 21px var(--sf-pad-left);
	color: #fff;
	overflow-wrap: break-word;
	/*
	 * No fade of its own: the text is fully drawn and simply rides up with the
	 * panel, as on Monarch's page. At rest it sits below the card's bottom edge,
	 * clipped out of view.
	 */
}

/*
 * Once story-cards.js has measured the text (--sf-text-h), move the panel by
 * exactly that height and leave the caption alone, so caption and text rise
 * together as one block with no gap opening between them mid-slide.
 */
.sf-story-cards .sf-story-cards__card--measured .sf-story-cards__panel {
	transform: translateY(calc(var(--sf-hide) * var(--sf-text-h)));
}

.sf-story-cards .sf-story-cards__card--measured .sf-story-cards__title {
	transform: none;
}

.sf-story-cards .sf-story-cards__text p {
	margin: 0;
	font: inherit;
	color: inherit;
}

/*
 * Touch screens cannot hover, so the text is always shown under the photo.
 * Set on the card, which beats the per-device values Elementor writes on the
 * root (the card's own declaration wins over an inherited one).
 */
@media (hover: none) {
	.sf-story-cards .sf-story-cards__card {
		--sf-photo-rows: 1;
		--sf-panel-rows: 2;
		--sf-panel-align: stretch;
		--sf-rest: 0;
		--sf-zoom: 0;
	}
}

/*
 * Reduced motion: the reveal still works (the text is real content), but it
 * appears at once, with no slide or photo zoom.
 */
@media (prefers-reduced-motion: reduce) {
	.sf-story-cards .sf-story-cards__card {
		--sf-zoom: 0;
	}

	.sf-story-cards .sf-story-cards__img,
	.sf-story-cards__panel,
	.sf-story-cards .sf-story-cards__title,
	.sf-story-cards .sf-story-cards__button {
		transition: none;
	}
}
