/**
 * MSS-style newsletter overlay prompt.
 *
 * Everything is scoped to .mss-prompt (a class on the outer Group block in the
 * prompt content) so nothing here can affect the rest of the site. Selectors
 * inside the form deliberately target plain elements -- input[type="email"],
 * button -- rather than Newspack's own class names, because those class names
 * change between plugin versions and the form block may be either
 * newspack/reader-registration or newspack-newsletters/subscribe.
 *
 * Tweak the custom properties in the first block to restyle the whole prompt.
 */

.mss-prompt {
	/* Palette, sampled from the Mountain State Spotlight overlay. */
	--mss-navy: #20386a;
	--mss-gold: #f4bb4c;
	--mss-gold-hover: #e2a731;
	--mss-ink: #111111;
	--mss-paper: #ffffff;
	--mss-placeholder: #6e6e6e;

	/* Type. */
	--mss-sans: "Archivo", "Helvetica Neue", Helvetica, Arial, sans-serif;
	--mss-serif: "PT Serif", Georgia, "Times New Roman", serif;
	--mss-headline-size: clamp(1.5rem, 1rem + 2.2vw, 2.5rem);
	--mss-dek-size: clamp(1rem, 0.85rem + 0.7vw, 1.3rem);

	/* Box metrics. */
	--mss-pad-block: clamp(2rem, 4vw, 3.25rem);
	--mss-pad-inline: clamp(1.25rem, 5vw, 3.5rem);
	--mss-field-height: 3.4rem;
	--mss-gap: 1rem;

	box-sizing: border-box;
	max-width: none;
	padding: var(--mss-pad-block) var(--mss-pad-inline);
	background-color: var(--mss-navy);
	color: var(--mss-paper);
	font-family: var(--mss-sans);
	text-align: center;
}

/*
 * Newspack Campaigns wraps the prompt content in its own container and paints
 * the background from the prompt's own background_color setting. deploy.sh sets
 * that to the same navy, and these rules are the belt-and-braces version so the
 * box still looks right if that setting is ever cleared.
 */
.newspack-popup:has(.mss-prompt),
.newspack-popup__content-wrapper:has(.mss-prompt),
.newspack-lightbox:has(.mss-prompt) .newspack-popup {
	background-color: var(--mss-navy, #20386a);
}

.mss-prompt > * {
	margin-left: auto;
	margin-right: auto;
}

/* --- Headline ------------------------------------------------------------ */

.mss-prompt__headline {
	max-width: 40ch;
	margin: 0 auto;
	font-family: var(--mss-sans);
	font-size: var(--mss-headline-size);
	font-weight: 700;
	line-height: 1.15;
	letter-spacing: -0.01em;
	color: var(--mss-paper);
	text-wrap: balance;
}

/* --- Deck ---------------------------------------------------------------- */

.mss-prompt__dek {
	max-width: 72ch;
	margin: 1.25rem auto 0;
	font-family: var(--mss-serif);
	font-size: var(--mss-dek-size);
	font-weight: 400;
	line-height: 1.55;
	color: var(--mss-paper);
}

/* --- Form ---------------------------------------------------------------- */
/*
 * Notes on specificity, from reading Newspack's own stylesheets:
 *
 *   .newspack-ui input[type=email]          (0,2,1)  newspack-ui.css
 *   .newspack-ui .newspack-ui__button--primary (0,2,0)  newspack-ui.css
 *   .newspack-registration__inputs          (0,1,0)  reader-registration-block.css
 *
 * So every rule below is anchored on `.mss-prompt__form form ...`, which lands
 * at (0,2,2) or higher and wins outright rather than relying on load order.
 */

.mss-prompt__form {
	margin-top: clamp(1.5rem, 3vw, 2.25rem);
}

.mss-prompt__form form {
	margin: 0;
}

/*
 * The block nests the email input and the submit button four divs deep, and
 * styles their immediate parent as a stacked grid. Rather than hard-code that
 * class name -- it has changed between versions, and the newsletters subscribe
 * block uses a different one -- find whichever element actually holds the email
 * input and make that element the flex row.
 */
.mss-prompt__form form div:has( > input[type="email"]:not( .nphp ) ) {
	display: flex;
	flex-wrap: wrap;
	gap: var(--mss-gap);
	align-items: stretch;
	justify-content: center;
}

/* --- Email field --------------------------------------------------------- */

.mss-prompt__form form input[type="email"]:not( .nphp ),
.mss-prompt__form form input[type="text"] {
	flex: 1 1 18rem;
	min-width: 0;
	width: auto;
	height: var(--mss-field-height);
	padding: 0 1rem;
	border: 0;
	border-radius: 0;
	background: var(--mss-paper);
	color: var(--mss-ink);
	font-family: var(--mss-serif);
	font-size: 1.15rem;
	line-height: var(--mss-field-height);
	box-shadow: none;
}

.mss-prompt__form form input[type="email"]::placeholder,
.mss-prompt__form form input[type="text"]::placeholder {
	color: var(--mss-placeholder);
	opacity: 1;
}

.mss-prompt__form form input[type="email"]:focus-visible,
.mss-prompt__form form input[type="text"]:focus-visible {
	outline: 3px solid var(--mss-gold);
	outline-offset: 2px;
}

/*
 * The honeypot field is hidden by Newspack with position:absolute !important,
 * so it stays out of the flex row. Excluded above as well, so it can never pick
 * up the visible field's styling if that ever changes upstream.
 */

/* --- Submit button ------------------------------------------------------- */

.mss-prompt__form form button,
.mss-prompt__form form button[type="submit"],
.mss-prompt__form form input[type="submit"] {
	flex: 0 0 auto;
	min-width: 9.5rem;
	height: var(--mss-field-height);
	margin: 0;
	padding: 0 1.75rem;
	border: 0;
	border-radius: 0;
	background: var(--mss-gold);
	color: var(--mss-ink);
	font-family: var(--mss-sans);
	font-size: 1.1rem;
	font-weight: 700;
	line-height: 1;
	cursor: pointer;
	transition: background-color 0.15s ease;
}

.mss-prompt__form form button:hover,
.mss-prompt__form form button[type="submit"]:hover,
.mss-prompt__form form input[type="submit"]:hover {
	background: var(--mss-gold-hover);
	color: var(--mss-ink);
}

.mss-prompt__form form button:focus-visible,
.mss-prompt__form form input[type="submit"]:focus-visible {
	outline: 3px solid var(--mss-paper);
	outline-offset: 2px;
}

/* The button label is wrapped in a span; keep it inheriting the button's type. */
.mss-prompt__form form button span {
	font: inherit;
	color: inherit;
}

/* --- Supporting text ----------------------------------------------------- */

/* Consent line, "already have an account", list descriptions. */
.mss-prompt__form form label,
.mss-prompt__form form p,
.mss-prompt__form form small,
.mss-prompt__form form a {
	color: var(--mss-paper);
	font-family: var(--mss-sans);
	font-size: 0.85rem;
	line-height: 1.5;
}

.mss-prompt__form form a {
	text-decoration: underline;
}

/* Response and success panels rendered after submit. */
.mss-prompt__form .newspack-registration__response,
.mss-prompt__form .newspack-registration__registration-success,
.mss-prompt__form [class*="__response"],
.mss-prompt__form [class*="success"] {
	color: var(--mss-paper);
	font-family: var(--mss-serif);
}

.mss-prompt__form .newspack-registration__registration-success p {
	font-family: var(--mss-serif);
	font-size: 1.05rem;
}

/* Never override Newspack's own hiding of these panels. */
.mss-prompt__form .newspack-registration--hidden {
	display: none;
}

/* --- Close button -------------------------------------------------------- */

.newspack-lightbox:has(.mss-prompt) button.newspack-lightbox__close,
.newspack-popup:has(.mss-prompt) button.newspack-lightbox__close,
.newspack-popup:has(.mss-prompt) .newspack-lightbox__close {
	top: 0.75rem;
	right: 0.75rem;
	color: var(--mss-paper, #fff);
	background: transparent;
	border: 0;
}

.newspack-popup:has(.mss-prompt) .newspack-lightbox__close svg {
	fill: currentColor;
	width: 2rem;
	height: 2rem;
}

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

@media ( max-width: 600px ) {
	/* Extra head-room so the Campaigns close button cannot crowd the headline. */
	.mss-prompt {
		padding-top: calc( var(--mss-pad-block) + 1.25rem );
	}

	.mss-prompt__form form input[type="email"]:not( .nphp ),
	.mss-prompt__form form input[type="text"],
	.mss-prompt__form form button,
	.mss-prompt__form form button[type="submit"],
	.mss-prompt__form form input[type="submit"] {
		flex: 1 0 100%;
		width: 100%;
	}
}
