/**
 * Revita: global styles (foundation layer).
 *
 * Loaded on every page and, through add_editor_style(), in the editor.
 * 1. Surface context tokens   5. Skip link and visually hidden text
 * 2. Base and typography      6. Form controls, button height and search text on touch screens
 * 3. Selection                7. Reduced motion
 * 4. Focus
 * Colours, fonts and sizes come from theme.json (--wp--preset--*, --wp--custom--*).
 */

/* 1. Surface context tokens --------------------------------------------------
 * Block styles read these with a light-surface fallback, for example
 * color: var(--revita-kicker, var(--wp--preset--color--primary)).
 * Dark and honey surfaces set them, light surfaces reset them, and the nearest
 * surface wins through inheritance. :where() keeps the specificity at zero, so
 * section styles and style variations can override any of them.
 *
 * The focus ring (section 4) is set everywhere, light surfaces included, so every
 * component that uses the two focus tokens gets the ring of its surface:
 * --revita-focus is the 2px outer ring, --revita-focus-ring the 3px band inside it.
 */
:root {
	--revita-focus: var(--wp--preset--color--primary-deep);
	--revita-focus-ring: var(--wp--preset--color--base);
}

:where(
	.is-style-section-purple,
	.is-style-section-deep,
	.has-primary-background-color,
	.has-primary-deep-background-color,
	.has-primary-dark-background-color,
	.has-contrast-background-color,
	.has-royal-gradient-background,
	.has-royal-glow-gradient-background,
	.has-night-gradient-background,
	.wp-block-cover:not(.is-light),
	.revita-dark
) {
	/* Honey Cream for small text: plain honey is 3.8:1 on Revita purple. */
	--revita-kicker: var(--wp--preset--color--accent-soft);
	--revita-emphasis: var(--wp--preset--color--accent);
	--revita-icon: var(--wp--preset--color--accent);
	--revita-on-icon: var(--wp--custom--color--on-accent);
	--revita-mark: var(--wp--preset--color--accent);
	/* Honey Cream ring (4.5:1 on the royal gradient, 9.6:1 on deep purple) around a night band. */
	--revita-focus: var(--wp--preset--color--accent-soft);
	--revita-focus-ring: var(--wp--preset--color--primary-dark);
	--revita-pill-purple: var(--wp--preset--color--primary-deep);
	--revita-pill-purple-hover: var(--wp--preset--color--primary-dark);
}

/* Night surfaces are dark enough for honey small text (9:1 and more). */
:where(
	.is-style-section-deep,
	.has-primary-deep-background-color,
	.has-primary-dark-background-color,
	.has-contrast-background-color,
	.has-night-gradient-background
) {
	--revita-kicker: var(--wp--preset--color--accent);
}

:where(
	.is-style-section-honey,
	.has-accent-background-color,
	.has-accent-deep-background-color,
	.has-honey-gradient-background,
	.revita-honey
) {
	--revita-kicker: var(--wp--custom--color--on-accent);
	--revita-emphasis: var(--wp--preset--color--primary);
	--revita-icon: var(--wp--custom--color--on-accent);
	--revita-on-icon: var(--wp--preset--color--accent);
	--revita-mark: var(--wp--custom--color--on-accent);
	--revita-focus: var(--wp--custom--color--on-accent);
	--revita-focus-ring: var(--wp--preset--color--base);
	--revita-pill-purple: initial;
	--revita-pill-purple-hover: initial;
}

/* Light surfaces inside dark ones go back to the defaults (cards only with their own surface). */
:where(
	.is-style-section-lavender,
	.is-style-section-cream,
	.is-style-card:not(.has-background),
	.is-style-card-lavender:not(.has-background),
	.is-style-glass:not(.has-background),
	.has-base-background-color,
	.has-lavender-background-color,
	.has-lavender-strong-background-color,
	.has-cream-background-color,
	.has-accent-soft-background-color,
	.has-lavender-mist-gradient-background,
	.has-sunrise-gradient-background,
	.wp-block-cover.is-light,
	.revita-light
) {
	--revita-kicker: initial;
	--revita-emphasis: initial;
	--revita-icon: initial;
	--revita-on-icon: initial;
	--revita-mark: initial;
	--revita-focus: var(--wp--preset--color--primary-deep);
	--revita-focus-ring: var(--wp--preset--color--base);
	--revita-pill-purple: initial;
	--revita-pill-purple-hover: initial;
}

/* Links on purple or dark backgrounds chosen in the editor (section styles set their own). */
:where(
	.has-primary-background-color,
	.has-royal-gradient-background,
	.has-royal-glow-gradient-background,
	.wp-block-cover:not(.is-light),
	.revita-dark
) a:where(:not(.wp-element-button)) {
	color: var(--wp--preset--color--accent-soft);
}

:where(
	.has-primary-deep-background-color,
	.has-primary-dark-background-color,
	.has-contrast-background-color,
	.has-night-gradient-background
) a:where(:not(.wp-element-button)) {
	color: var(--wp--preset--color--accent);
}

/* 2. Base and typography ----------------------------------------------------- */
html {
	-webkit-text-size-adjust: 100%;
	text-size-adjust: 100%;
}

@media (prefers-reduced-motion: no-preference) {
	html {
		scroll-behavior: smooth;
	}
}

/* Anchored headings stop below the sticky header. */
:root:has(body.revita-sticky-header) {
	scroll-padding-block-start: calc(var(--wp--custom--header--height-compact, 60px) + var(--wp-admin--admin-bar--height, 0px) + 1rem);
}

body {
	-webkit-font-smoothing: antialiased;
	-moz-osx-font-smoothing: grayscale;
	font-optical-sizing: auto;
	text-rendering: optimizeLegibility;
}

/* Decorative layers never cause sideways scrolling (clip keeps position: sticky working). */
.wp-site-blocks {
	overflow-x: clip;
}

:where(h1, h2, h3, h4, h5, h6, .wp-block-post-title) {
	text-wrap: balance;
	/* A word longer than the line (long Macedonian compounds on phones) breaks instead of
	 * running past the screen edge, where it would be clipped without any sign. */
	overflow-wrap: break-word;
}

/* Phones: hyphenate long words in headings where the browser knows the language. */
@media (max-width: 599px) {
	:where(h1, h2, h3, h4, h5, h6, .wp-block-post-title) {
		-webkit-hyphens: auto;
		hyphens: auto;
		hyphenate-limit-chars: 10 4 4;
	}
}

/* Two-column card grids on phones: an odd last item is centred under the row above instead
 * of sitting alone at the start. Benefit hexagons (9rem columns) are two across from 340 to
 * 479px; the About values (16rem columns) from 576 to 839px. These ranges, and the ones below, are
 * in em (16px each by default), so they move with the rem-sized columns when the browser's default
 * text size is larger: a card is never narrower than its longest word, and a one-column grid is
 * never treated as two. */
@media (min-width: 21.25em) and (max-width: 29.999em) {
	.wp-block-group.is-layout-grid.revita-reveal--hex-pop > :last-child:nth-child(odd) {
		grid-column: 1 / -1;
		justify-self: center;
		inline-size: calc((100% - var(--wp--preset--spacing--40)) / 2);
	}
}

@media (min-width: 36em) and (max-width: 52.499em) {
	.wp-block-group.is-layout-grid.revita-values > :last-child:nth-child(odd) {
		grid-column: 1 / -1;
		justify-self: center;
		inline-size: calc((100% - var(--wp--preset--spacing--40)) / 2);
	}
}

/* Grids of five cards on phones and tablets: never four above one, or the last cards at the start
 * of their row. Three above two is a six-column grid with every card two columns wide and the fourth
 * one starting in column 2; two above two above one is the same with four columns. In the
 * five-across range the grid's own columns are repeated, so a scrollbar or a landscape phone a few
 * pixels short of fitting them no longer gets four above one. From 1024px nothing changes.
 * - Service tiles (usp-tiles: five cards, 9rem columns): two above two above one from 332 to 479px
 *   (one column below), three above two from 480 to 811px, five across from 812px.
 * - Benefit hexagons (9rem columns, phones above): three above two from 480 to 839px, five across
 *   from 840px. */
@media (min-width: 20.75em) and (max-width: 29.999em) {
	.wp-block-group.is-layout-grid.revita-stagger:has(> .is-style-card:nth-child(5):last-child) {
		grid-template-columns: repeat(4, minmax(0, 1fr));
	}

	.wp-block-group.is-layout-grid.revita-stagger:has(> .is-style-card:nth-child(5):last-child) > * {
		grid-column: span 2;
	}

	.wp-block-group.is-layout-grid.revita-stagger:has(> .is-style-card:nth-child(5):last-child) > :nth-child(5) {
		grid-column: 2 / span 2;
	}
}

@media (min-width: 30em) and (max-width: 50.749em) {
	.wp-block-group.is-layout-grid.revita-stagger:has(> .is-style-card:nth-child(5):last-child) {
		grid-template-columns: repeat(6, minmax(0, 1fr));
	}

	.wp-block-group.is-layout-grid.revita-stagger:has(> .is-style-card:nth-child(5):last-child) > * {
		grid-column: span 2;
	}

	.wp-block-group.is-layout-grid.revita-stagger:has(> .is-style-card:nth-child(5):last-child) > :nth-child(4) {
		grid-column: 2 / span 2;
	}
}

@media (min-width: 50.75em) and (max-width: 63.999em) {
	.wp-block-group.is-layout-grid.revita-stagger:has(> .is-style-card:nth-child(5):last-child) {
		grid-template-columns: repeat(5, minmax(0, 1fr));
	}
}

@media (min-width: 30em) and (max-width: 52.499em) {
	.wp-block-group.is-layout-grid.revita-reveal--hex-pop:has(> :nth-child(5):last-child) {
		grid-template-columns: repeat(6, minmax(0, 1fr));
	}

	.wp-block-group.is-layout-grid.revita-reveal--hex-pop:has(> :nth-child(5):last-child) > * {
		grid-column: span 2;
	}

	.wp-block-group.is-layout-grid.revita-reveal--hex-pop:has(> :nth-child(5):last-child) > :nth-child(4) {
		grid-column: 2 / span 2;
	}
}

@media (min-width: 52.5em) and (max-width: 63.999em) {
	.wp-block-group.is-layout-grid.revita-reveal--hex-pop:has(> :nth-child(5):last-child) {
		grid-template-columns: repeat(5, minmax(0, 1fr));
	}
}

:where(p, li, dd, figcaption) {
	text-wrap: pretty;
}

/* Kicker (paragraph or post terms, class revita-kicker): small caps with a honey hexagon.
 * Used in page header bands and on post cards, so it lives here. */
.revita-kicker {
	font-family: var(--wp--preset--font-family--heading);
	font-size: var(--wp--preset--font-size--x-small);
	font-weight: 700;
	line-height: 1.3;
	letter-spacing: 0.14em;
	text-transform: uppercase;
	color: var(--wp--preset--color--primary);
}

.revita-kicker::before {
	content: "";
	display: inline-block;
	inline-size: 0.95em;
	block-size: 0.82em;
	margin-inline-end: 0.6em;
	vertical-align: -0.05em;
	background-color: var(--wp--preset--color--accent);
	clip-path: polygon(25% 0, 75% 0, 100% 50%, 75% 100%, 25% 100%, 0 50%);
}

/* A taller hit area around the short link, without changing the layout (WCAG 2.5.8). */
.revita-kicker a {
	display: inline-block;
	padding-block: 0.375rem;
	margin-block: -0.375rem;
	color: inherit;
	text-decoration: none;
}

/* Phones and touch screens: a 44px tall target with the text in the middle (THEME_SPEC section 16).
 * It still reaches 0.375rem past its row above and below, which stays inside the space around it
 * (the card image's margin and the card's gap; the page header's gaps), so it never overlaps the
 * image, the title or the breadcrumb links above it. */
@media (max-width: 781.98px), (pointer: coarse) {
	.revita-kicker a {
		padding-block: calc((2.75rem - 1lh) / 2);
	}
}

a:where(:not(.wp-element-button)) {
	text-decoration-thickness: 1px;
	text-underline-offset: 0.18em;
}

a:where(:not(.wp-element-button)):hover {
	text-decoration-thickness: 2px;
}

@media (prefers-reduced-motion: no-preference) {
	a:where(:not(.wp-element-button)) {
		transition:
			color var(--wp--custom--motion--duration--fast) var(--wp--custom--motion--easing--standard),
			text-decoration-color var(--wp--custom--motion--duration--fast) var(--wp--custom--motion--easing--standard);
	}

	:where(.wp-element-button, .wp-block-button__link) {
		transition:
			background-color var(--wp--custom--motion--duration--fast) var(--wp--custom--motion--easing--standard),
			border-color var(--wp--custom--motion--duration--fast) var(--wp--custom--motion--easing--standard),
			box-shadow var(--wp--custom--motion--duration--base) var(--wp--custom--motion--easing--standard),
			color var(--wp--custom--motion--duration--fast) var(--wp--custom--motion--easing--standard);
	}
}

:where(:not(pre)) > code {
	padding: 0.12em 0.4em;
	border-radius: var(--wp--custom--radius--xs);
	background-color: var(--wp--preset--color--lavender);
	color: var(--wp--preset--color--primary-deep);
	font-size: 0.9em;
}

mark:where(:not(.has-inline-color)) {
	padding-inline: 0.2em;
	border-radius: var(--wp--custom--radius--xs);
	background-color: var(--wp--preset--color--accent-soft);
	color: inherit;
}

/* 3. Selection ---------------------------------------------------------------- */
::selection {
	background-color: var(--wp--preset--color--accent);
	color: var(--wp--custom--color--on-accent);
}

/* 4. Focus -------------------------------------------------------------------
 * Keyboard focus, one style everywhere: a 2px ring 3px away from the element, with the
 * gap filled by a 3px band in a contrasting colour. The colours come from the surface
 * (section 1), so the outer ring always stands out from what is around it and the band
 * keeps it apart from the element itself:
 * - white, cream, lavender (and cards): Deep Purple ring (7:1 or more) on a white band;
 * - purple, deep and night surfaces, dark covers: Honey Cream ring (4.5:1 or more) on a
 *   night-purple band;
 * - honey surfaces: Deep Purple ring (5:1 or more) on a white band.
 * The two colours of each pair differ by 10:1 or more (WCAG technique C40), so the ring
 * also shows over photos. Mouse clicks on buttons do not leave a ring behind.
 */
:where(
	a[href],
	button,
	input:is([type="checkbox"], [type="radio"], [type="submit"], [type="button"], [type="reset"], [type="range"], [type="file"]),
	select,
	summary,
	[tabindex]:not([tabindex="-1"], .wp-block)
):focus-visible {
	outline: 2px solid var(--revita-focus, var(--wp--preset--color--primary-deep));
	outline-offset: 3px;
	box-shadow: 0 0 0 3px var(--revita-focus-ring, var(--wp--preset--color--base));
}

:root :is(.wp-element-button, .wp-block-button__link):focus-visible {
	outline: 2px solid var(--revita-focus, var(--wp--preset--color--primary-deep));
	outline-offset: 3px;
	box-shadow: 0 0 0 3px var(--revita-focus-ring, var(--wp--preset--color--base));
}

:root :is(.wp-element-button, .wp-block-button__link):focus:not(:focus-visible) {
	outline: none;
}

/* 5. Skip link and visually hidden text --------------------------------------- */
:root .skip-link.screen-reader-text:focus {
	inset-block-start: calc(var(--wp-admin--admin-bar--height, 0px) + 0.75rem);
	inset-inline-start: 0.75rem;
	padding: 0.85em 1.5em;
	border-radius: var(--wp--custom--radius--pill);
	background-color: var(--wp--preset--color--accent);
	box-shadow: var(--wp--preset--shadow--lifted);
	color: var(--wp--custom--color--on-accent);
	font-family: var(--wp--preset--font-family--heading);
	font-size: var(--wp--preset--font-size--small);
	font-weight: 600;
	line-height: 1.2;
	outline: 2px solid var(--wp--preset--color--primary-deep);
	outline-offset: 3px;
	text-decoration: none;
	z-index: 100000;
}

/* Hidden on screen, still read by screen readers. The -focusable version shows on focus. */
.revita-visually-hidden,
.revita-visually-hidden-focusable:not(:focus, :focus-within) {
	position: absolute !important;
	inline-size: 1px !important;
	block-size: 1px !important;
	margin: -1px !important;
	padding: 0 !important;
	overflow: hidden !important;
	clip: rect(0 0 0 0) !important;
	clip-path: inset(50%) !important;
	border: 0 !important;
	white-space: nowrap !important;
}

/* 6. Form controls ------------------------------------------------------------
 * Zero specificity, so WooCommerce and plugin field styles win where they exist.
 */
:where(
	input:not([type]),
	input:is([type="text"], [type="email"], [type="url"], [type="tel"], [type="number"], [type="password"], [type="search"], [type="date"]),
	select,
	textarea
) {
	box-sizing: border-box;
	max-inline-size: 100%;
	padding: 0.7em 1em;
	border: 1.5px solid var(--wp--preset--color--border);
	border-radius: var(--wp--custom--radius--sm);
	background-color: var(--wp--custom--color--surface);
	color: var(--wp--preset--color--contrast);
	font: inherit;
	line-height: 1.4;
}

:where(
	input:not([type]),
	input:is([type="text"], [type="email"], [type="url"], [type="tel"], [type="number"], [type="password"], [type="search"], [type="date"]),
	select,
	textarea
):hover {
	border-color: var(--wp--preset--color--lavender-strong);
}

:where(
	input:not([type]),
	input:is([type="text"], [type="email"], [type="url"], [type="tel"], [type="number"], [type="password"], [type="search"], [type="date"]),
	select,
	textarea
):focus {
	border-color: var(--wp--preset--color--primary);
	outline: 3px solid color-mix(in srgb, var(--wp--preset--color--primary) 28%, transparent);
	outline-offset: 0;
}

:where(input, textarea)::placeholder {
	color: var(--wp--preset--color--muted);
	opacity: 1;
}

:where(textarea) {
	min-block-size: 8em;
	resize: vertical;
}

:where(input[type="checkbox"], input[type="radio"], input[type="range"], progress) {
	accent-color: var(--wp--preset--color--primary);
}

/* Contact Form 7 submit button, matched to the theme button (a 44px touch target). */
:where(.wpcf7-submit) {
	box-sizing: border-box;
	min-block-size: 2.75rem;
	padding: 0.9em 1.7em;
	border: 0;
	border-radius: var(--wp--custom--radius--pill);
	background-color: var(--wp--preset--color--accent);
	color: var(--wp--custom--color--on-accent);
	cursor: pointer;
	font-family: var(--wp--preset--font-family--heading);
	font-size: var(--wp--preset--font-size--small);
	font-weight: 600;
	letter-spacing: 0.01em;
}

:where(.wpcf7-submit):hover {
	background-color: var(--wp--preset--color--accent-deep);
}

/* Buttons on phones and touch screens: at least 44px tall (THEME_SPEC section 16). The button
 * padding (0.9em above and below, theme.json) and a 1.35 line height add up to 3.15em, which is
 * 44px from the 14px button text up, with the label still centred. Outline pills keep the same
 * height (their 2px border comes off the padding). Desktop keeps the 1.2 line height. Icon-only
 * search buttons keep core's line height (0); components that set their own line height with a
 * more specific selector (shop cards) keep it. */
@media (max-width: 781.98px), (pointer: coarse) {
	:root :is(.wp-element-button, .wp-block-button__link, .wpcf7-submit):not(:where(.has-icon)) {
		line-height: 1.35;
	}
}

/* Search fields on phones and touch screens: 16px text, the minimum for inputs (THEME_SPEC section
 * 16), so iOS does not zoom in when the field gets focus. theme.json gives the search block the small
 * size (14 to 15px), which desktop keeps. */
@media (max-width: 781.98px), (pointer: coarse) {
	.wp-block-search .wp-block-search__input {
		font-size: max(1rem, 16px);
	}
}

/* Contact Form 7 fields: each field sits inside its visible label (the form template is set by
 * dev/cutover/40-content.php), so the label stays above the field while typing (MC-09, A11Y-11). */
.wpcf7 label {
	display: block;
	color: var(--wp--preset--color--primary-deep);
	font-weight: 600;
}

.wpcf7 label .wpcf7-form-control-wrap {
	display: block;
	margin-block-start: 0.35rem;
}

.wpcf7 :is(input:is([type="text"], [type="email"], [type="tel"], [type="url"]), textarea) {
	inline-size: 100%;
	font-weight: 400;
}

.wpcf7 .revita-form-note {
	color: var(--wp--preset--color--muted);
}

/* The consent line: a normal sentence beside a 24px checkbox (WCAG 2.5.8), without the list
 * indent. The checkbox look itself is shared with WooCommerce (woocommerce.css). */
.wpcf7 .wpcf7-list-item {
	margin-inline: 0;
}

.wpcf7 .wpcf7-list-item label {
	display: inline-flex;
	align-items: flex-start;
	gap: 0.6em;
	color: inherit;
	font-weight: 400;
	cursor: pointer;
}

.wpcf7 .wpcf7-acceptance input[type="checkbox"] {
	inline-size: 1.5rem;
	block-size: 1.5rem;
	margin: 0.15em 0 0;
}

/* Comment form, "save my name" line: the 24px checkbox never shrinks beside a long label, and
 * the label (which also ticks it) is a row at least 44px tall. The checkbox sits on the first
 * line: (44 - 24) / 2 = 10px from the top, whatever the line height. Core sets the checkbox
 * margin with its ID, hence the ID here. */
.comment-form-cookies-consent {
	align-items: flex-start;
}

:root .comment-form-cookies-consent #wp-comment-cookies-consent {
	flex: none;
	inline-size: 1.5rem;
	block-size: 1.5rem;
	margin-block: 0.625rem 0;
}

.comment-form-cookies-consent label {
	padding-block: calc((2.75rem - 1lh) / 2);
	cursor: pointer;
}

/* 7. Reduced motion ------------------------------------------------------------
 * The device setting always wins: animations and transitions finish at once.
 */
@media (prefers-reduced-motion: reduce) {
	*,
	*::before,
	*::after {
		animation-duration: 0.01ms !important;
		animation-iteration-count: 1 !important;
		scroll-behavior: auto !important;
		transition-duration: 0.01ms !important;
	}
}
