/**
 * MRMC Elements — newsletter.
 *
 * One stylesheet for both placements. The card is written on its own, knowing
 * nothing about the overlay; the popup is the overlay, the scrim and the
 * animation around it. That is what lets the same markup sit in a page under a
 * heading and float over one on a timer without a single duplicated rule.
 *
 * Everything worth changing is a custom property, so the settings screen and
 * the Elementor Style tab both set one value rather than out-specifying a
 * selector. The layout is driven by a container query on the card, which means
 * a card in a narrow column stacks even when the window is wide — the case a
 * media query gets wrong.
 *
 * @package MRMC\Elements
 * @since   1.0.0
 */

/* ---------------------------------------------------------------------------
 * The overlay
 * ------------------------------------------------------------------------ */

.mrmc-popup {
	position: fixed;
	inset: 0;
	z-index: 999990;
	display: flex;
	align-items: center;
	justify-content: center;
	padding: clamp(16px, 4vw, 48px);
	box-sizing: border-box;

	/* Off until the script opens it. `hidden` is the state the markup ships in. */
	opacity: 0;
	visibility: hidden;
	transition: opacity var(--mrmc-duration, 400ms) var(--mrmc-ease, ease);
}

.mrmc-popup[hidden] {
	display: none;
}

.mrmc-popup.is-open {
	opacity: 1;
	visibility: visible;
}

.mrmc-popup__scrim {
	position: absolute;
	inset: 0;
	background: rgba(26, 33, 66, 0.55);
	backdrop-filter: blur(3px);
	-webkit-backdrop-filter: blur(3px);
	cursor: pointer;
}

.mrmc-popup__dialog {
	position: relative;
	width: 100%;
	max-width: var(--mrmc-width, 960px);
	max-height: calc(100vh - 32px);
	max-height: calc(100dvh - 32px);
	overflow: auto;
	overscroll-behavior: contain;
	border-radius: var(--mrmc-radius, 22px);
	background: var(--mrmc-surface, #fdf8f5);
	box-shadow: var(--mrmc-shadow-lg, 0 40px 90px -40px rgba(26, 33, 66, 0.55));

	/* The card is drawn from below and settles; see the reduced-motion block. */
	transform: translateY(18px) scale(0.98);
	opacity: 0;
	transition:
		transform var(--mrmc-duration, 400ms) var(--mrmc-ease, ease),
		opacity var(--mrmc-duration, 400ms) var(--mrmc-ease, ease);
}

.mrmc-popup.is-open .mrmc-popup__dialog {
	transform: translateY(0) scale(1);
	opacity: 1;
}

.mrmc-popup__close {
	position: absolute;
	top: 14px;
	right: 14px;
	z-index: 3;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 38px;
	height: 38px;
	padding: 0;
	border: 1px solid rgba(255, 255, 255, 0.5);
	border-radius: 999px;
	background: rgba(255, 255, 255, 0.86);
	color: var(--mrmc-heading, #1a2142);
	cursor: pointer;
	box-shadow: 0 4px 14px rgba(26, 33, 66, 0.14);
	transition: transform 200ms var(--mrmc-ease, ease), background-color 200ms ease;
	-webkit-backdrop-filter: blur(6px);
	backdrop-filter: blur(6px);
}

.mrmc-popup__close:hover,
.mrmc-popup__close:focus-visible {
	background: #fff;
	transform: rotate(90deg);
}

/* The page behind a modal does not scroll; the class is set by the script. */
body.mrmc-popup-locked {
	overflow: hidden;
}

/* ---------------------------------------------------------------------------
 * The card
 * ------------------------------------------------------------------------ */

/*
 * The element the container query measures. It has to be the card's parent
 * rather than the card itself: a container query asks about an ancestor, so an
 * element that declares itself a container cannot then respond to its own
 * width. With the container on the card, the split rules below match nothing
 * and every card stays stacked, however wide it is.
 */
.mrmc-news-shell {
	container-type: inline-size;
	container-name: mrmc-news;
	display: block;
	width: 100%;
}

.mrmc-news {
	--mrmc-media-width: 42%;
	--mrmc-field-bg: #fff;
	--mrmc-field-border: rgba(26, 33, 66, 0.14);
	--mrmc-hairline: rgba(26, 33, 66, 0.1);
	--mrmc-error: #b3261e;

	position: relative;
	display: grid;
	grid-template-columns: 1fr;
	overflow: hidden;
	border-radius: var(--mrmc-radius, 22px);
	background: var(--mrmc-surface, #fdf8f5);
	color: var(--mrmc-ink, #271d1d);
	font-family: var(--mrmc-font-body, inherit);
	box-sizing: border-box;
}

.mrmc-news *,
.mrmc-news *::before,
.mrmc-news *::after {
	box-sizing: border-box;
}

/* ---------------------------------------------------------------------------
 * The picture
 * ------------------------------------------------------------------------ */

/*
 * Stacked, the picture is a banner with a shape of its own; split, the rule in
 * the container query below hands it the full height of the card instead. Both
 * states give the image a definite box to cover, which is what stops a tall
 * photograph from either collapsing to nothing or pushing the card off screen.
 */
.mrmc-news__media {
	position: relative;
	margin: 0;
	aspect-ratio: 16 / 10;
	max-height: 34vh;
	overflow: hidden;
	background:
		linear-gradient(160deg, var(--mrmc-blush, #fbe6dd) 0%, var(--mrmc-mint-soft, #edf6f6) 100%);
}

/*
 * Absolutely placed rather than sized at 100%: the figure is the box, and the
 * image fills it on every axis without depending on a parent height that only
 * resolves in some layouts.
 */
.mrmc-news__image {
	position: absolute;
	inset: 0;
	display: block;
	width: 100%;
	height: 100%;
	object-fit: cover;
	/*
	 * Which part is never cropped away. A photograph goes into a tall panel on
	 * a desktop and a wide strip on a phone, so it is cropped on a different
	 * axis each time and one value has to hold for both; the default keeps
	 * heads and faces, which is where a viewer looks first.
	 */
	object-position: var(--mrmc-media-focus, 50% 35%);
}

/*
 * A wash at the foot of the picture, so the badge reads over a bright photo
 * without a box around it.
 */
.mrmc-news__media::after {
	content: "";
	position: absolute;
	inset: auto 0 0 0;
	height: 45%;
	background: linear-gradient(to top, rgba(26, 33, 66, 0.42), rgba(26, 33, 66, 0));
	pointer-events: none;
}

.mrmc-news__media--empty::after {
	display: none;
}

/* The monogram that stands in when no image has been chosen yet. */
.mrmc-news__media--empty::before {
	content: "";
	position: absolute;
	inset: 50% auto auto 50%;
	width: 120px;
	height: 120px;
	transform: translate(-50%, -50%) rotate(45deg);
	border: 1px solid rgba(255, 255, 255, 0.85);
	border-radius: 18px;
	background: rgba(255, 255, 255, 0.28);
}

.mrmc-news__badge {
	position: absolute;
	left: 18px;
	bottom: 18px;
	z-index: 2;
	display: inline-flex;
	align-items: center;
	gap: 8px;
	padding: 7px 14px;
	border: 1px solid rgba(255, 255, 255, 0.55);
	border-radius: 999px;
	background: rgba(255, 255, 255, 0.18);
	color: #fff;
	font-size: 11px;
	font-weight: 500;
	letter-spacing: 0.14em;
	text-transform: uppercase;
	-webkit-backdrop-filter: blur(8px);
	backdrop-filter: blur(8px);
}

.mrmc-news__media--empty .mrmc-news__badge {
	border-color: rgba(26, 33, 66, 0.16);
	background: rgba(255, 255, 255, 0.7);
	color: var(--mrmc-heading, #1a2142);
}

/* ---------------------------------------------------------------------------
 * The invitation
 * ------------------------------------------------------------------------ */

.mrmc-news__body {
	position: relative;
	padding: clamp(28px, 5vw, 52px);
	display: flex;
	flex-direction: column;
	justify-content: center;
}

.mrmc-news__eyebrow {
	display: flex;
	align-items: center;
	gap: 12px;
	margin: 0 0 14px;
	color: var(--mrmc-accent, #cfa190);
	font-size: 11px;
	font-weight: 500;
	letter-spacing: 0.22em;
	line-height: 1.4;
	text-transform: uppercase;
}

.mrmc-news__eyebrow-rule {
	display: block;
	width: 34px;
	height: 1px;
	flex: none;
	background: currentColor;
	opacity: 0.6;
}

.mrmc-news__title {
	margin: 0 0 14px;
	color: var(--mrmc-heading, #1a2142);
	font-family: var(--mrmc-font-display, serif);
	font-size: clamp(30px, 2.2vw + 20px, 46px);
	font-weight: 500;
	line-height: 1.06;
	letter-spacing: -0.01em;
}

.mrmc-news__title em,
.mrmc-news__title i {
	color: var(--mrmc-accent, #cfa190);
	font-style: italic;
}

.mrmc-news__text {
	margin: 0 0 20px;
	max-width: 46ch;
	color: var(--mrmc-ink, #271d1d);
	font-size: 15px;
	font-weight: 300;
	line-height: 1.65;
	opacity: 0.88;
}

.mrmc-news__points {
	list-style: none;
	margin: 0 0 24px;
	padding: 0;
	display: grid;
	gap: 9px;
}

.mrmc-news__point {
	display: flex;
	align-items: flex-start;
	gap: 10px;
	font-size: 13.5px;
	font-weight: 400;
	line-height: 1.5;
	color: var(--mrmc-ink, #271d1d);
}

.mrmc-news__point .mrmc-news__tick {
	flex: none;
	margin-top: 2px;
	color: var(--mrmc-accent, #cfa190);
}

/* ---------------------------------------------------------------------------
 * The form
 * ------------------------------------------------------------------------ */

.mrmc-news__form {
	margin: 0;
}

/*
 * The honeypot. Taken out of sight and out of the tab order without `display:
 * none`, which is the one thing a bot filling a form checks for.
 */
.mrmc-news__hp {
	position: absolute !important;
	left: -9999px !important;
	width: 1px;
	height: 1px;
	overflow: hidden;
}

.mrmc-news__fields {
	display: grid;
	gap: 12px;
}

.mrmc-news__field {
	min-width: 0;
}

.mrmc-news__label {
	position: absolute;
	width: 1px;
	height: 1px;
	margin: -1px;
	padding: 0;
	overflow: hidden;
	clip: rect(0, 0, 0, 0);
	white-space: nowrap;
	border: 0;
}

/*
 * Input and button in one pill. Two controls, one shape — the button sits
 * inside the field rather than beside it, which is what keeps a wide form from
 * looking like a search box with something bolted on.
 */
.mrmc-news__control {
	display: flex;
	align-items: center;
	gap: 6px;
	padding: 5px 5px 5px 6px;
	border: 1px solid var(--mrmc-field-border);
	border-radius: 999px;
	background: var(--mrmc-field-bg);
	box-shadow: var(--mrmc-shadow-sm, 0 2px 8px rgba(26, 33, 66, 0.06));
	transition: border-color 200ms ease, box-shadow 200ms ease;
}

.mrmc-news__control:focus-within {
	border-color: var(--mrmc-accent, #cfa190);
	box-shadow: 0 0 0 4px rgba(207, 161, 144, 0.18);
}

.mrmc-news__field--email .mrmc-news__input {
	border: 0;
	background: transparent;
	box-shadow: none;
	padding: 10px 6px 10px 12px;
}

.mrmc-news__input {
	flex: 1 1 auto;
	width: 100%;
	min-width: 0;
	padding: 13px 16px;
	border: 1px solid var(--mrmc-field-border);
	border-radius: 999px;
	background: var(--mrmc-field-bg);
	color: var(--mrmc-ink, #271d1d);
	font-family: inherit;
	font-size: 15px;
	font-weight: 300;
	line-height: 1.4;
	outline: none;
	appearance: none;
}

.mrmc-news__input::placeholder {
	color: rgba(39, 29, 29, 0.42);
}

.mrmc-news__input:focus-visible {
	border-color: var(--mrmc-accent, #cfa190);
}

.mrmc-news__submit {
	flex: none;
	display: inline-flex;
	align-items: center;
	gap: 8px;
	padding: 13px 24px;
	border: 0;
	border-radius: 999px;
	background: var(--mrmc-heading, #1a2142);
	color: #fff;
	font-family: inherit;
	font-size: 13px;
	font-weight: 500;
	letter-spacing: 0.08em;
	text-transform: uppercase;
	cursor: pointer;
	transition: background-color 260ms var(--mrmc-ease, ease), transform 200ms var(--mrmc-ease, ease);
}

.mrmc-news__submit:hover,
.mrmc-news__submit:focus-visible {
	background: var(--mrmc-accent, #cfa190);
}

.mrmc-news__submit:active {
	transform: translateY(1px);
}

.mrmc-news__submit[disabled] {
	opacity: 0.65;
	cursor: progress;
}

.mrmc-news__arrow {
	transition: transform 260ms var(--mrmc-ease, ease);
}

.mrmc-news__submit:hover .mrmc-news__arrow {
	transform: translateX(3px);
}

.mrmc-news__error {
	margin: 8px 0 0;
	padding-left: 18px;
	color: var(--mrmc-error);
	font-size: 12.5px;
	line-height: 1.4;
}

.mrmc-news__consent {
	display: flex;
	align-items: flex-start;
	gap: 9px;
	margin: 14px 0 0;
	font-size: 12.5px;
	font-weight: 300;
	line-height: 1.5;
	opacity: 0.85;
}

.mrmc-news__consent input {
	margin-top: 2px;
	accent-color: var(--mrmc-accent, #cfa190);
}

.mrmc-news__alert {
	margin: 14px 0 0;
	padding: 11px 16px;
	border-radius: 12px;
	border: 1px solid var(--mrmc-hairline);
	background: rgba(255, 255, 255, 0.7);
	font-size: 13px;
	line-height: 1.5;
}

.mrmc-news__alert--error {
	border-color: rgba(179, 38, 30, 0.25);
	background: rgba(179, 38, 30, 0.06);
	color: var(--mrmc-error);
}

.mrmc-news__alert[hidden] {
	display: none;
}

.mrmc-news__footnote {
	margin: 16px 0 0;
	font-size: 12px;
	font-weight: 300;
	line-height: 1.5;
	opacity: 0.6;
}

/* ---------------------------------------------------------------------------
 * After subscribing
 * ------------------------------------------------------------------------ */

.mrmc-news__done[hidden] {
	display: none;
}

.mrmc-news__done {
	animation: mrmc-rise 480ms var(--mrmc-ease, ease) both;
}

.mrmc-news__done-mark {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 46px;
	height: 46px;
	margin-bottom: 16px;
	border-radius: 999px;
	background: var(--mrmc-accent, #cfa190);
	color: #fff;
}

.mrmc-news__done-mark .mrmc-news__tick {
	width: 22px;
	height: 22px;
}

.mrmc-news__done-title {
	margin: 0 0 8px;
	color: var(--mrmc-heading, #1a2142);
	font-family: var(--mrmc-font-display, serif);
	font-size: clamp(26px, 1.6vw + 18px, 36px);
	font-weight: 500;
	line-height: 1.1;
}

.mrmc-news__done-text {
	margin: 0;
	max-width: 42ch;
	font-size: 14.5px;
	font-weight: 300;
	line-height: 1.6;
	opacity: 0.85;
}

@keyframes mrmc-rise {
	from {
		opacity: 0;
		transform: translateY(10px);
	}

	to {
		opacity: 1;
		transform: none;
	}
}

/* ---------------------------------------------------------------------------
 * Wide enough to split
 *
 * Measured against the card, not the window: the same card in a sidebar stays
 * stacked, which is the whole reason this is a container query.
 * ------------------------------------------------------------------------ */

@container mrmc-news (min-width: 760px) {
	.mrmc-news {
		grid-template-columns: var(--mrmc-media-width, 42%) 1fr;
		align-items: stretch;
	}

	.mrmc-news--image-right {
		grid-template-columns: 1fr var(--mrmc-media-width, 42%);
	}

	.mrmc-news--image-right .mrmc-news__media {
		order: 2;
	}

	/* Side by side, the picture takes the height of the card, whatever that is. */
	.mrmc-news__media {
		aspect-ratio: auto;
		max-height: none;
		height: 100%;
		min-height: 100%;
	}

	/* A hairline between the halves, on the text side of the seam. */
	.mrmc-news__body::before {
		content: "";
		position: absolute;
		top: 32px;
		bottom: 32px;
		left: 0;
		width: 1px;
		background: var(--mrmc-hairline);
	}

	.mrmc-news--image-right .mrmc-news__body::before {
		left: auto;
		right: 0;
	}
}

/* Browsers without container queries fall back to the viewport. */
@supports not (container-type: inline-size) {
	@media (min-width: 900px) {
		.mrmc-news {
			grid-template-columns: var(--mrmc-media-width, 42%) 1fr;
		}

		.mrmc-news--image-right {
			grid-template-columns: 1fr var(--mrmc-media-width, 42%);
		}

		.mrmc-news--image-right .mrmc-news__media {
			order: 2;
		}

		.mrmc-news__media {
			aspect-ratio: auto;
			max-height: none;
			height: 100%;
			min-height: 100%;
		}
	}
}

/* ---------------------------------------------------------------------------
 * Narrow
 * ------------------------------------------------------------------------ */

@media (max-width: 640px) {
	/* Shorter on a phone, so the heading and the field are both above the fold. */
	.mrmc-news__media {
		aspect-ratio: 16 / 9;
		max-height: 28vh;
	}

	.mrmc-news__control {
		flex-direction: column;
		align-items: stretch;
		gap: 8px;
		padding: 8px;
		border-radius: 20px;
	}

	.mrmc-news__field--email .mrmc-news__input {
		padding: 12px 14px;
		text-align: left;
	}

	.mrmc-news__submit {
		justify-content: center;
		width: 100%;
	}

	.mrmc-popup {
		padding: 12px;
		align-items: flex-end;
	}

	.mrmc-popup__dialog {
		max-height: 92vh;
		max-height: 92dvh;
	}
}

/* ---------------------------------------------------------------------------
 * Asked for less motion
 * ------------------------------------------------------------------------ */

@media (prefers-reduced-motion: reduce) {
	.mrmc-popup,
	.mrmc-popup__dialog,
	.mrmc-news__submit,
	.mrmc-news__arrow,
	.mrmc-popup__close {
		transition: none;
	}

	.mrmc-popup__dialog {
		transform: none;
	}

	.mrmc-news__done {
		animation: none;
	}
}

/* ---------------------------------------------------------------------------
 * Living inside a theme
 *
 * The popup renders in the footer of whatever theme is installed, and themes
 * style bare element selectors. These are the few places that has been seen to
 * matter — a global `input` rule, a global `button` rule, a `figure` margin.
 * ------------------------------------------------------------------------ */

.mrmc-news .mrmc-news__submit,
.mrmc-popup .mrmc-popup__close {
	text-decoration: none;
	box-shadow: none;
}

.mrmc-news .mrmc-news__input {
	max-width: none;
	height: auto;
	margin: 0;
}

/*
 * Only the elements this stylesheet does not give a margin to itself. A blanket
 * `.mrmc-news p` would out-specify every `.mrmc-news__*` rule above it and flatten
 * the spacing the design is built on.
 */
.mrmc-news > figure,
.mrmc-news__body > form > *:last-child {
	margin-bottom: 0;
}
