/**
 * "Join Our Community" modal
 * template-parts/community-modal.php, behaviour in assets/js/community-modal.js.
 *
 * Opened by the Subscribe button in the footer newsletter band, so it loads
 * site-wide (see inc/setup/community-modal.php).
 *
 * Figma: "modal template" (node 1126:25756), annotated "use this modal template
 * as an art direction for every modal" — 800px card, torn mountain ridge sitting
 * on the top edge, five fields, consent row, pill submit.
 *
 * The product-page popup (newsletter-popup.css) is a separate, narrower capture
 * with the ridge removed; the two share the signup table but not the markup.
 */

.dm-cmty {
	position: fixed;
	inset: 0;
	z-index: 100001; /* above the product-page popup, which is 100000 */
	display: flex;
	align-items: flex-end; /* anchored to the bottom edge, like the product popup */
	justify-content: center;
	padding: 84px 16px 0; /* top gutter leaves room for the ridge; flush at the bottom */
	overflow-y: auto;
}

.dm-cmty[hidden] {
	display: none;
}

.dm-cmty__backdrop {
	position: absolute;
	inset: 0;
	background: color-mix(in srgb, var(--color-forest) 55%, transparent);
	opacity: 0;
	transition: opacity 0.28s ease;
}

.dm-cmty.is-open .dm-cmty__backdrop {
	opacity: 1;
}

/* ------------------------------------------------------------------ Dialog */
.dm-cmty__dialog {
	position: relative;
	width: 100%;
	max-width: 800px;
	margin: 0 auto;
	transform: translateY(16px) scale(0.98);
	opacity: 0;
	transition: transform 0.3s ease, opacity 0.3s ease;
}

.dm-cmty.is-open .dm-cmty__dialog {
	transform: translateY(0) scale(1);
	opacity: 1;
}

/* The ridge is the card's top edge, so it must not be clipped by the card. */
.dm-cmty__ridge {
	position: absolute;
	left: 0;
	right: 0;
	bottom: 100%;
	width: 100%;
	height: 84px;
	display: block;
	pointer-events: none;
}

.dm-cmty__body {
	display: flex;
	flex-direction: column;
	gap: 24px;
	padding: 16px 24px 24px;
	max-height: calc(100vh - 84px); /* the ridge keeps its gutter; the rest scrolls */
	overflow-y: auto;
	background: var(--dm-bg-default-white);
}

/* The form is one child of the card, so the card's gap does not reach the
   fields inside it — they carry their own. */
.dm-cmty__form {
	display: flex;
	flex-direction: column;
	gap: 24px;
}

/* ------------------------------------------------------------- Title block */
.dm-cmty__top {
	display: flex;
	flex-direction: column;
	gap: 16px;
}

.dm-cmty__head {
	display: flex;
	align-items: center;
	justify-content: center;
	gap: 24px;
}

.dm-cmty__title {
	flex: 1 0 0;
	min-width: 0;
	margin: 0;
	font-family: 'IM FELL Double Pica', serif;
	font-weight: 400;
	font-size: 40px;
	line-height: 1.1;
	letter-spacing: -0.4px;
	color: var(--dm-fg-default-primary);
}

.dm-cmty__title-accent {
	font-style: italic;
}

.dm-cmty__close {
	flex: 0 0 auto;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 24px;
	height: 24px;
	padding: 0;
	background: transparent;
	border: 0;
	cursor: pointer;
}

.dm-cmty__close img {
	display: block;
	width: 24px;
	height: 24px;
}

.dm-cmty__sub {
	margin: 0;
	font-family: 'Roboto Condensed', sans-serif;
	font-weight: 400;
	font-size: 16px;
	line-height: 1.4;
	color: var(--dm-fg-default-primary);
}

/* ------------------------------------------------------------------ Fields */
.dm-cmty__field {
	position: relative;
	display: flex;
	flex-direction: column;
	gap: 6px;
}

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

.dm-cmty__input,
.dm-cmty__select {
	width: 100%;
	height: 48px;
	padding: 0 16px;
	font-family: 'Roboto Condensed', sans-serif;
	font-weight: 400;
	font-size: 16px;
	line-height: 1.4;
	color: var(--dm-fg-default-primary);
	background: var(--dm-bg-default-white);
	border: 1px solid var(--dm-border-default-dark);
	border-radius: 4px;
	appearance: none;
}

.dm-cmty__input::placeholder {
	color: var(--dm-fg-default-primary);
	opacity: 0.7;
}

.dm-cmty__input:focus-visible,
.dm-cmty__select:focus-visible {
	outline: 2px solid var(--dm-border-default-dark-strong);
	outline-offset: -2px;
}

/* A date input with nothing in it shows the UA's own placeholder, which does
   not match the others; this keeps it reading as placeholder text until the
   visitor picks a date. */
.dm-cmty__input[type='date']:not(:focus):placeholder-shown,
.dm-cmty__input[type='date']:not(:focus)[value=''] {
	color: color-mix(in srgb, var(--dm-fg-default-primary) 70%, transparent);
}

/* The country select keeps room for the chevron sitting over its right edge. */
.dm-cmty__select {
	padding-right: 48px;
}

.dm-cmty__select:invalid {
	color: color-mix(in srgb, var(--dm-fg-default-primary) 70%, transparent);
}

.dm-cmty__chevron {
	position: absolute;
	top: 50%;
	right: 16px;
	width: 16px;
	height: 16px;
	transform: translateY(-50%);
	pointer-events: none;
}

/* ----------------------------------------------------------------- Consent */
.dm-cmty__consent {
	display: flex;
	align-items: flex-start;
	gap: 8px;
	padding: 4px 0;
}

.dm-cmty__checkbox {
	flex: 0 0 auto;
	width: 16px;
	height: 16px;
	margin: 0;
	background: var(--dm-bg-default-white);
	border: 1px solid var(--dm-border-default-dark);
	border-radius: 2px;
	appearance: none;
	cursor: pointer;
}

.dm-cmty__checkbox:checked {
	background: var(--dm-bg-default-tertiary);
	border-color: var(--dm-bg-default-tertiary);
}

/* The tick is drawn rather than shipped: the design's checked state is a plain
   filled box, and this keeps the state readable without a second asset. */
.dm-cmty__checkbox:checked::after {
	content: '';
	display: block;
	width: 4px;
	height: 8px;
	margin: 1px auto 0;
	border: solid var(--dm-fg-default-white);
	border-width: 0 1.5px 1.5px 0;
	transform: rotate(45deg);
}

.dm-cmty__checkbox:focus-visible {
	outline: 2px solid var(--dm-border-default-dark-strong);
	outline-offset: 2px;
}

.dm-cmty__consent-text {
	flex: 1 0 0;
	min-width: 0;
	font-family: 'Roboto Condensed', sans-serif;
	font-weight: 400;
	font-size: 14px;
	line-height: 1.4;
	color: var(--dm-fg-default-primary);
	word-break: break-word;
}

.dm-cmty__consent-text a {
	color: inherit;
	text-decoration: underline;
}

/* ------------------------------------------------------------------ Submit */
.dm-cmty__submit {
	align-self: flex-start;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: 8px;
	width: 120px;
	height: 48px;
	padding: 0 24px;
	font-family: 'Roboto Condensed', sans-serif;
	font-weight: 400;
	font-size: 16px;
	line-height: 1.4;
	color: var(--dm-fg-default-white);
	white-space: nowrap;
	background: var(--dm-bg-default-tertiary);
	border: 0;
	border-radius: 9999px;
	cursor: pointer;
	transition: opacity 0.2s ease;
}

.dm-cmty__submit:hover {
	opacity: 0.88;
}

.dm-cmty__submit[disabled] {
	opacity: 0.6;
	cursor: default;
}

/* ---------------------------------------------------------------- Feedback */
.dm-cmty__feedback {
	margin: 0;
	font-family: 'Roboto Condensed', sans-serif;
	font-size: 14px;
	line-height: 1.4;
	color: var(--dm-fg-default-primary);
}

.dm-cmty__feedback[hidden] {
	display: none;
}

.dm-cmty__feedback.is-error {
	color: #a8321e;
}

/* The honeypot is never shown and never announced. */
.dm-cmty__hp {
	position: absolute;
	left: -9999px;
	width: 1px;
	height: 1px;
	opacity: 0;
	pointer-events: none;
}

/* ------------------------------------------------------------------ Mobile */
/* The sheet is bottom-anchored at every width; on a phone it also loses its
   side gutter and tightens the gaps so the submit stays reachable. */
@media (max-width: 768px) {
	.dm-cmty {
		padding: 84px 0 0; /* no side gutter: the sheet spans the screen */
	}

	.dm-cmty__dialog {
		max-width: none;
	}

	.dm-cmty__body,
	.dm-cmty__form {
		gap: 16px;
	}

	.dm-cmty__title {
		font-size: 32px;
	}

	.dm-cmty__submit {
		width: 100%;
	}
}

@media (prefers-reduced-motion: reduce) {
	.dm-cmty__backdrop,
	.dm-cmty__dialog {
		transition: none;
	}
}
