/**
 * Consent interface.
 *
 * Plugin-owned on purpose. The theme's design tokens are read where they exist
 * and every one carries a fallback, so the banner keeps its shape and its
 * contrast on a default theme, on a staging copy, or the day somebody switches
 * the theme without telling anybody.
 *
 * Measured contrast, on the night surface #100e0c:
 *   canvas #f6f2ea   17.25:1  AAA
 *   dim    #a39b8e    7.00:1  AA
 * On the canvas surface #f6f2ea:
 *   ink    #14120f   16.75:1  AAA
 *   muted  #5c564b    6.51:1  AA
 */

.c-consent {
	--consent-night: var(--night, #100e0c);
	--consent-raised: var(--night-raised, #1c1917);
	--consent-canvas: var(--canvas, #f6f2ea);
	--consent-ink: var(--ink, #14120f);
	--consent-muted: var(--muted, #5c564b);
	--consent-dim: var(--dim, #a39b8e);
	--consent-line: var(--line, rgb(20 18 15 / 0.14));
	--consent-line-inverse: var(--line-inverse, rgb(246 242 234 / 0.18));
	--consent-radius: var(--radius-m, 10px);
	--consent-z: 350;
	--consent-font: var(--font-body, system-ui, -apple-system, "Segoe UI", sans-serif);
}

/* --- Layer one: the banner ------------------------------------------------ */

.c-consent__banner {
	position: fixed;
	inset-inline: 0;
	inset-block-end: 0;
	z-index: var(--consent-z);
	padding: clamp(1rem, 0.9286rem + 0.3571vw, 1.25rem);
	padding-block-end: max(clamp(1rem, 0.9286rem + 0.3571vw, 1.25rem), env(safe-area-inset-bottom));
	background: var(--consent-night);
	border-block-start: 1px solid var(--consent-line-inverse);
	box-shadow: 0 -4px 8px rgb(0 0 0 / 0.05), 0 -30px 60px rgb(0 0 0 / 0.25);
	color: var(--consent-canvas);
	font-family: var(--consent-font);
}

.c-consent__banner[hidden] {
	display: none;
}

.c-consent__banner-inner {
	display: flex;
	flex-direction: column;
	gap: clamp(1rem, 0.9286rem + 0.3571vw, 1.25rem);
	max-inline-size: var(--container, 82rem);
	margin-inline: auto;
}

.c-consent__banner-text {
	max-inline-size: 68ch;
}

/*
 * The colour is declared, not inherited. A theme that styles `h2` directly
 * beats inheritance from the banner, and the first thing a visitor reads must
 * never depend on losing that race.
 */
.c-consent__title {
	margin: 0 0 0.5rem;
	color: var(--consent-canvas);
	font-family: var(--font-display, Georgia, serif);
	font-size: var(--text-2, 1.425rem);
	font-weight: 600;
	line-height: var(--leading-snug, 1.12);
	letter-spacing: var(--tracking-tight, -0.03em);
}

.c-consent__title:focus-visible {
	outline: 2px solid currentColor;
	outline-offset: 4px;
}

.c-consent__lead {
	margin: 0;
	font-size: var(--text-0, 1rem);
	line-height: var(--leading-normal, 1.6);
	color: var(--consent-canvas);
}

.c-consent__links {
	margin: 0.75rem 0 0;
	font-size: var(--text-2xs, 0.8125rem);
	color: var(--consent-dim);
}

.c-consent__links a {
	color: var(--consent-canvas);
	text-underline-offset: 0.2em;
}

.c-consent__actions {
	display: flex;
	flex-wrap: wrap;
	gap: 0.75rem;
}

/*
 * Accept and reject are the same element with the same weight. Making the
 * refusal quieter than the acceptance is the single most common way a banner
 * stops being a free choice, so the two share one class and one size.
 */
.c-consent__btn {
	flex: 1 1 auto;
	min-block-size: 2.75rem;
	padding: 0.6875rem 1.25rem;
	border: 1px solid transparent;
	border-radius: var(--radius-pill, 100vmax);
	font: inherit;
	font-size: var(--text-2xs, 0.875rem);
	font-weight: 600;
	letter-spacing: var(--tracking-normal, -0.011em);
	cursor: pointer;
	transition: background-color var(--dur-fast, 180ms) ease, color var(--dur-fast, 180ms) ease;
}

.c-consent__btn--solid {
	background: var(--consent-canvas);
	color: var(--consent-night);
}

.c-consent__btn--solid:hover {
	background: #ffffff;
}

.c-consent__btn--ghost {
	background: transparent;
	border-color: var(--consent-canvas);
	color: var(--consent-canvas);
}

.c-consent__btn--ghost:hover {
	background: rgb(246 242 234 / 0.12);
}

.c-consent__btn:focus-visible {
	outline: 2px solid var(--consent-canvas);
	outline-offset: 3px;
}

@media (min-width: 48rem) {

	.c-consent__banner-inner {
		flex-direction: row;
		align-items: center;
		justify-content: space-between;
	}

	.c-consent__actions {
		flex: 0 0 auto;
		flex-wrap: nowrap;
	}

	.c-consent__btn {
		flex: 0 0 auto;
	}
}

/* --- Layer two: the preferences dialog ------------------------------------ */

.c-consent__overlay {
	position: fixed;
	inset: 0;
	z-index: calc(var(--consent-z) + 10);
	display: flex;
	align-items: flex-end;
	justify-content: center;
	padding: 0;
	background: rgb(16 14 12 / 0.72);
}

.c-consent__overlay[hidden] {
	display: none;
}

.c-consent__dialog {
	display: flex;
	flex-direction: column;
	gap: 1.25rem;
	inline-size: 100%;
	max-inline-size: 44rem;
	max-block-size: 92dvh;
	padding: clamp(1.5rem, 1.3571rem + 0.7143vw, 2rem);
	padding-block-end: max(clamp(1.5rem, 1.3571rem + 0.7143vw, 2rem), env(safe-area-inset-bottom));
	overflow-y: auto;
	overscroll-behavior: contain;
	background: var(--consent-canvas);
	border-start-start-radius: var(--radius-l, 20px);
	border-start-end-radius: var(--radius-l, 20px);
	color: var(--consent-ink);
	font-family: var(--consent-font);
}

@media (min-width: 48rem) {

	.c-consent__overlay {
		align-items: center;
		padding: 1.5rem;
	}

	.c-consent__dialog {
		max-block-size: 86dvh;
		border-radius: var(--radius-l, 20px);
	}
}

.c-consent__dialog-head {
	display: flex;
	align-items: flex-start;
	justify-content: space-between;
	gap: 1rem;
}

.c-consent__dialog .c-consent__title {
	margin: 0;
	color: var(--consent-ink);
}

.c-consent__close {
	flex: 0 0 auto;
	display: grid;
	place-items: center;
	inline-size: 2.75rem;
	block-size: 2.75rem;
	background: transparent;
	border: 1px solid var(--consent-line);
	border-radius: var(--radius-pill, 100vmax);
	color: var(--consent-ink);
	cursor: pointer;
}

.c-consent__close-mark {
	font-size: 1.5rem;
	line-height: 1;
}

.c-consent__close:focus-visible,
.c-consent__cta:focus-visible,
.c-consent__link:focus-visible {
	outline: 2px solid var(--consent-ink);
	outline-offset: 3px;
}

.c-consent__intro {
	margin: 0;
	max-inline-size: 68ch;
	font-size: var(--text-2xs, 0.875rem);
	line-height: var(--leading-normal, 1.6);
	color: var(--consent-muted);
}

.c-consent__categories {
	display: flex;
	flex-direction: column;
	gap: 0.75rem;
	margin: 0;
	padding: 0;
	list-style: none;
}

.c-consent__category {
	padding: 1rem;
	background: var(--canvas-raised, #fffdf8);
	border: 1px solid var(--consent-line);
	border-radius: var(--consent-radius);
}

.c-consent__category-head {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 1rem;
}

.c-consent__category-label {
	font-size: var(--text-1, 1.1875rem);
	font-weight: 600;
	letter-spacing: var(--tracking-normal, -0.011em);
}

.c-consent__always {
	flex: 0 0 auto;
	padding: 0.25rem 0.625rem;
	background: var(--canvas-sunken, #ece6da);
	border-radius: var(--radius-pill, 100vmax);
	font-size: var(--text-3xs, 0.7188rem);
	font-weight: 600;
	text-transform: uppercase;
	letter-spacing: var(--tracking-wide, 0.08em);
	color: var(--consent-muted);
}

.c-consent__category-text {
	margin: 0.5rem 0 0;
	font-size: var(--text-2xs, 0.875rem);
	line-height: var(--leading-normal, 1.6);
	color: var(--consent-muted);
}

/* --- The switch ----------------------------------------------------------- */

/*
 * State is carried by the thumb's position and by the native `switch` role,
 * never by colour alone: a visitor who cannot tell green from grey still has
 * to be able to see, and hear, which categories are on.
 */
.c-consent__switch {
	position: relative;
	flex: 0 0 auto;
	display: inline-flex;
	align-items: center;
	cursor: pointer;
}

.c-consent__switch-input {
	position: absolute;
	inline-size: 100%;
	block-size: 100%;
	margin: 0;
	opacity: 0;
	cursor: pointer;
}

.c-consent__switch-track {
	display: block;
	inline-size: 3.25rem;
	block-size: 1.875rem;
	padding: 0.1875rem;
	background: var(--canvas-sunken, #ece6da);
	border: 1px solid var(--line-strong, rgb(20 18 15 / 0.32));
	border-radius: var(--radius-pill, 100vmax);
	transition: background-color var(--dur-fast, 180ms) ease;
}

.c-consent__switch-thumb {
	display: block;
	inline-size: 1.375rem;
	block-size: 1.375rem;
	background: var(--consent-ink);
	border-radius: 50%;
	transition: transform var(--dur-fast, 180ms) var(--ease-out, ease);
}

.c-consent__switch-input:checked + .c-consent__switch-track {
	background: var(--consent-ink);
	border-color: var(--consent-ink);
}

.c-consent__switch-input:checked + .c-consent__switch-track .c-consent__switch-thumb {
	background: var(--consent-canvas);
	transform: translateX(1.375rem);
}

.c-consent__switch-input:focus-visible + .c-consent__switch-track {
	outline: 2px solid var(--consent-ink);
	outline-offset: 3px;
}

/* --- The declaration, folded away ----------------------------------------- */

.c-consent__details {
	margin-block-start: 0.75rem;
	font-size: var(--text-2xs, 0.875rem);
}

.c-consent__details > summary {
	padding: 0.25rem 0;
	color: var(--consent-muted);
	cursor: pointer;
}

.c-consent__details > summary:focus-visible {
	outline: 2px solid var(--consent-ink);
	outline-offset: 2px;
}

.c-consent__items {
	display: flex;
	flex-direction: column;
	gap: 0.75rem;
	margin: 0.75rem 0 0;
	padding: 0;
	list-style: none;
}

.c-consent__item {
	display: grid;
	gap: 0.125rem;
	padding-inline-start: 0.75rem;
	border-inline-start: 2px solid var(--consent-line);
}

.c-consent__item code {
	font-family: var(--font-mono, ui-monospace, Menlo, monospace);
	font-size: var(--text-3xs, 0.75rem);
	overflow-wrap: anywhere;
}

.c-consent__item-meta {
	font-size: var(--text-3xs, 0.75rem);
	text-transform: uppercase;
	letter-spacing: var(--tracking-wide, 0.08em);
	color: var(--consent-muted);
}

.c-consent__item-purpose {
	line-height: var(--leading-normal, 1.6);
	color: var(--consent-muted);
}

/*
 * The dialog scrolls, so its actions stick to the bottom of it. Four categories
 * already push "save" below the fold on a phone, and an action you have to go
 * looking for is an action a tired visitor skips.
 */
.c-consent__actions--dialog {
	position: sticky;
	inset-block-end: calc(-1 * clamp(1.5rem, 1.3571rem + 0.7143vw, 2rem));
	margin-block-start: auto;
	padding-block: 1rem;
	background: var(--consent-canvas);
	box-shadow: 0 -1px 0 var(--consent-line);
}

.c-consent__actions--dialog .c-consent__btn--solid {
	background: var(--consent-ink);
	color: var(--consent-canvas);
}

.c-consent__actions--dialog .c-consent__btn--solid:hover {
	background: var(--consent-night);
}

.c-consent__actions--dialog .c-consent__btn:focus-visible {
	outline-color: var(--consent-ink);
}

.c-consent__foot {
	margin: 0;
	font-size: var(--text-2xs, 0.875rem);
}

.c-consent__foot a {
	color: var(--consent-muted);
}

/* --- Controls that live outside the banner -------------------------------- */

/* The permanent way back, appended to the footer's legal menu. */
.c-consent__link {
	padding: 0;
	background: none;
	border: 0;
	color: inherit;
	font: inherit;
	text-decoration: underline;
	text-underline-offset: 0.2em;
	cursor: pointer;
}

/* The in-page call to action on the policy pages. */
.c-consent__cta {
	display: inline-flex;
	align-items: center;
	min-block-size: 2.75rem;
	padding: 0.6875rem 1.375rem;
	background: var(--consent-ink);
	border: 0;
	border-radius: var(--radius-pill, 100vmax);
	color: var(--consent-canvas);
	font: inherit;
	font-size: var(--text-2xs, 0.875rem);
	font-weight: 600;
	cursor: pointer;
}

.c-consent__cta:hover {
	background: var(--consent-night);
}

/* --- The clause beside a form --------------------------------------------- */

.c-privacy-notice {
	--consent-ink: var(--ink, #14120f);
	--consent-muted: var(--muted, #5c564b);
	--consent-line: var(--line, rgb(20 18 15 / 0.14));

	padding: var(--space-s, 1rem);
	background: var(--canvas-sunken, #ece6da);
	border-radius: var(--radius-m, 10px);
	color: var(--consent-muted);
	font-size: var(--text-2xs, 0.875rem);
	line-height: var(--leading-normal, 1.6);
}

.c-privacy-notice__title {
	margin: 0 0 0.75rem;
	color: var(--consent-ink);
	font-family: inherit;
	font-size: var(--text-3xs, 0.75rem);
	font-weight: 600;
	text-transform: uppercase;
	letter-spacing: var(--tracking-wide, 0.08em);
}

.c-privacy-notice__list {
	display: grid;
	gap: 0.5rem;
	margin: 0;
}

.c-privacy-notice__row {
	display: grid;
	gap: 0.125rem;
}

@media (min-width: 40rem) {

	.c-privacy-notice__row {
		grid-template-columns: minmax(0, 8rem) minmax(0, 1fr);
		gap: var(--space-s, 1rem);
		align-items: baseline;
	}
}

.c-privacy-notice__row dt {
	margin: 0;
	color: var(--consent-ink);
	font-weight: 600;
}

.c-privacy-notice__row dd {
	margin: 0;
}

.c-privacy-notice__more {
	margin: 0.75rem 0 0;
	padding-block-start: 0.75rem;
	border-block-start: 1px solid var(--consent-line);
}

/* --- Blocked third-party embeds ------------------------------------------- */

.c-consent-embed {
	position: relative;
	aspect-ratio: var(--embed-ratio, 16 / 9);
	overflow: hidden;
	background: var(--canvas-sunken, #ece6da);
	border-radius: var(--consent-radius);
}

.c-consent-embed__frame {
	inline-size: 100%;
	block-size: 100%;
	border: 0;
}

.c-consent-embed__notice {
	position: absolute;
	inset: 0;
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	gap: 1rem;
	padding: 1.5rem;
	text-align: center;
}

.c-consent-embed.is-loaded .c-consent-embed__notice {
	display: none;
}

.c-consent-embed__text {
	max-inline-size: 46ch;
	margin: 0;
	font-size: var(--text-2xs, 0.875rem);
	line-height: var(--leading-normal, 1.6);
	color: var(--consent-muted);
}

.c-consent-embed__button {
	min-block-size: 2.75rem;
	padding: 0.6875rem 1.25rem;
	background: var(--consent-ink);
	border: 0;
	border-radius: var(--radius-pill, 100vmax);
	color: var(--consent-canvas);
	font: inherit;
	font-weight: 600;
	cursor: pointer;
}

.c-consent-embed__button:focus-visible {
	outline: 2px solid var(--consent-ink);
	outline-offset: 3px;
}

/* --- Shared utilities ----------------------------------------------------- */

/*
 * A missing legal detail is loud on purpose, and it is styled here rather than
 * with the document pages because the same gap shows up in the form clause. A
 * quiet blank is a blank that ships, and a privacy policy with no controller in
 * it is worse than none.
 */
.c-privacy-pending {
	padding: 0.125rem 0.5rem;
	background: var(--danger-soft, #fbeceb);
	border-radius: var(--radius-s, 4px);
	color: var(--danger, #a3231d);
	font-size: 0.9em;
	font-weight: 600;
}

.c-consent__sr {
	position: absolute;
	inline-size: 1px;
	block-size: 1px;
	margin: -1px;
	padding: 0;
	overflow: hidden;
	clip-path: inset(50%);
	white-space: nowrap;
	border: 0;
}

@media (prefers-reduced-motion: reduce) {

	.c-consent__btn,
	.c-consent__switch-track,
	.c-consent__switch-thumb {
		transition: none;
	}
}

@media (forced-colors: active) {

	.c-consent__btn,
	.c-consent__cta,
	.c-consent__close {
		border: 1px solid ButtonBorder;
	}

	.c-consent__switch-track {
		border: 1px solid ButtonBorder;
	}

	.c-consent__switch-input:checked + .c-consent__switch-track {
		background: Highlight;
	}
}
