/* ===== Theme variables — data-scheme on <html> drives all mode switching ===== */
:root,
html,
body {
	--ens-bg: light-dark(var(--wp--preset--color--base), #000);
	--ens-fg: light-dark(var(--wp--preset--color--contrast), #fff);
	--ens-muted: light-dark(#666666, #cccccc);
	--ens-primary: light-dark(var(--wp--preset--color--envision-blue), #fff);
	--ens-link: light-dark(var(--wp--preset--color--envision-blue), #fff);
	--ens-border: #818181;
	--ens-button: var(--wp--preset--color--envision-green);
	--ens-button-text: var(--wp--preset--color--ink);
	--ens-high-contrast-bg: #EAE80A;
}

/* Light values for browsers without light-dark() (mirrors style.css fallback) */
@supports not (color: light-dark(#fff, #000)) {
	:root,
	html,
	body {
		--ens-bg: var(--wp--preset--color--base);
		--ens-fg: var(--wp--preset--color--contrast);
		--ens-muted: #666666;
		--ens-primary: var(--wp--preset--color--envision-blue);
		--ens-link: var(--wp--preset--color--envision-blue);
	}
}

:is(html, body)[data-scheme="hc"] {
	--ens-bg: var(--ens-high-contrast-bg);
	--ens-fg: var(--wp--preset--color--ink);
	--ens-muted: var(--wp--preset--color--ink);
	--ens-primary: var(--wp--preset--color--ink);
	--ens-link: var(--wp--preset--color--ink);
	--ens-border: var(--wp--preset--color--ink);
	--ens-button: var(--wp--preset--color--ink);
	--ens-button-text: var(--ens-high-contrast-bg);
}

@media (prefers-contrast: more) {
	:is(html, body)[data-scheme="default"] {
		color-scheme: light;
		--ens-bg: var(--ens-high-contrast-bg);
		--ens-fg: var(--wp--preset--color--ink);
		--ens-muted: var(--wp--preset--color--ink);
		--ens-primary: var(--wp--preset--color--ink);
		--ens-link: var(--wp--preset--color--ink);
		--ens-border: var(--wp--preset--color--ink);
		--ens-button: var(--wp--preset--color--ink);
		--ens-button-text: var(--ens-high-contrast-bg);
	}
}

/* Dark mode: blocks with a fixed paper/ink palette colour follow the scheme.
   The block-level .has-*-color classes use !important and would otherwise
   override the light-dark() group style variations. */
[data-scheme="dark"] :is(.has-paper-background-color, .has-base-background-color) {
	background-color: var(--ens-bg) !important;
}

/* Sidebar labels (GenerateBlocks text, fixed blue) follow the link/primary colour. */
[data-scheme="dark"] .sidebar-label {
	color: var(--ens-primary);
}

/* Mirrors the light group variation in theme.json: light-dark(envision-gray, #222). */
[data-scheme="dark"] .has-envision-gray-background-color {
	background-color: #222 !important;
}

/* Coloured section fills follow the `navy` and `blue` group variations (light-dark(..., #222) / (..., #333)); goldenrod
   sections go dark like them. Buttons keep their own fill (below). */
[data-scheme="dark"] :is(.has-envision-navy-blue-background-color, .has-envision-goldenrod-background-color):not(.wp-element-button, .wp-block-button__link) {
	background-color: #222 !important;
}

[data-scheme="dark"] .has-envision-blue-background-color:not(.wp-element-button, .wp-block-button__link) {
	background-color: #333 !important;
}

/* A navy-filled button must never exist: it always renders as the standard button (theme.json default fill and text), in every mode. */
.wp-block-button__link.has-envision-navy-blue-background-color:not(:hover, :focus, :active) {
	background-color: var(--wp--preset--color--envision-green) !important;
	color: var(--wp--preset--color--envision-navy-blue) !important;
}

/* Blue filled buttons become the standard green button in dark, as in the comp (blue on #333 is 1.4:1). */
[data-scheme="dark"] .wp-block-button__link.has-envision-blue-background-color {
	background-color: var(--ens-button) !important;
	color: var(--ens-button-text) !important;
}

[data-scheme="dark"] :is(.has-ink-color, .has-contrast-color):not(.wp-element-button, .wp-block-button__link) {
	color: var(--ens-fg) !important;
}

/* Bright-blue section groups go dark like blue (inherited white text is 2.3:1 on #41B6E6). Small pills/labels keep their fill. */
[data-scheme="dark"] .wp-block-group.has-envision-bright-blue-background-color {
	background-color: #333 !important;
}

/* Default-fill (green) buttons keep ink text in dark; stored content sometimes sets paper text on them (white on green is 2.3:1). */
[data-scheme="dark"] .wp-block-button__link.has-paper-color:not([class*="-background-color"], .has-background) {
	color: var(--ens-button-text) !important;
}

/* Links coloured through a group's link colour (generated .wp-elements-* rule) follow the scheme. */
[data-scheme="dark"] .has-link-color a:where(:not(.wp-element-button)) {
	color: var(--ens-link);
}

/* Green headings are white in dark, as in the comp (BVI heading). Covers the preset class, hex/preset inline colours and GB
   headings (render filter adds the class). */
[data-scheme="dark"] :is(h1, h2, h3, h4, h5, h6):is(.has-envision-green-color, [style*="78BE21" i], [style*="envision-green" i]) {
	color: var(--ens-fg) !important;
}

/* Group-level heading colour overrides (block "heading" element colour, generated as `.wp-elements-N h2`) are white in dark too. */
[data-scheme="dark"] [class*="wp-elements-"] :is(h1, h2, h3, h4, h5, h6) {
	color: var(--ens-fg);
}

/* Core's default image caption colour (#555) fails contrast on the dark background. */
[data-scheme="dark"] .wp-block-image figcaption {
	color: var(--ens-muted);
}

/* The header search box stays white with ink text in every mode, as in the comps (color-scheme: dark would otherwise give it the
   browser's dark input fill). */
[data-scheme="dark"] .wp-block-search__input {
	background-color: #fff;
	color: var(--wp--preset--color--ink);
}

/* ===== High contrast (yellow): every section fill and fixed palette fill becomes the yellow page colour with ink text, as in the
   comp. Buttons and small pills keep their own fill; cards keep their white border (has-paper-border-color) on the yellow. ===== */
[data-scheme="hc"] :is(
	.wp-block-group:is(.is-style-primary, .is-style-white, .is-style-navy, .is-style-blue, .is-style-light),
	.has-paper-background-color,
	.has-base-background-color,
	.has-envision-gray-background-color,
	.has-envision-navy-blue-background-color,
	.has-envision-goldenrod-background-color,
	.has-envision-bright-blue-background-color
):not(.wp-element-button, .wp-block-button__link, .tag) {
	background-color: var(--ens-bg) !important;
	color: var(--ens-fg) !important;
}

/* Cover overlays follow the group variations: the visible overlay (inline hex or palette class) is flat yellow, so the ink text
   above stays readable. Covers with no overlay (dim 0, such as the video heroes) keep their own look (ENV051-300). */
[data-scheme="hc"] .wp-block-cover > .wp-block-cover__background:not(.has-background-dim-0) {
	background-color: var(--ens-bg) !important;
	background-image: none !important;
	opacity: 1 !important;
}

/* Text the generic rule below does not list (links, bare div/span copy, white `has-paper-color` text) is ink on that yellow too. */
[data-scheme="hc"] .wp-block-cover:has(> .wp-block-cover__background:not(.has-background-dim-0)) :is(a:not(.wp-block-button__link), .wp-block-cover__inner-container, :is(div, span).has-text-color:not(.wp-block-button__link)) {
	color: var(--ens-fg) !important;
}

/* Section frames: a group's 20px solid border in paper (white), navy or blue is spacing around the section. Its fill becomes yellow here,
   so the frame follows the yellow instead of showing as a stray white, navy or blue border (ENV051-275, ENV051-255, ENV051-177). */
[data-scheme="hc"] .wp-block-group:is(
	[style*="border-color:var(--wp--preset--color--paper)"],
	[style*="border-color:var(--wp--preset--color--base)"],
	[style*="border-color:var(--wp--preset--color--envision-navy-blue)"],
	[style*="border-color:var(--wp--preset--color--envision-blue)"]
):where([style*="border-style:solid"]) {
	border-color: var(--ens-bg) !important;
}

/* Text on those fills (headings coloured blue/green, white-on-navy copy) is ink. */
[data-scheme="hc"] :is(h1, h2, h3, h4, h5, h6, p, li, figcaption, label, time):not(.wp-element-button, .wp-block-button__link, .tag) {
	color: var(--ens-fg) !important;
}

/* Green text blocks (the number counters) are 1.75:1 on the yellow, so they take ink too. */
[data-scheme="hc"] .has-envision-green-color:not(.wp-element-button, .wp-block-button__link, .tag) {
	color: var(--ens-fg) !important;
}

/* Buttons stay green with dark text and no link underline, as in the comp. */
[data-scheme="hc"] :is(.wp-element-button, .wp-block-button__link) {
	background-color: var(--ens-button-fill, var(--wp--preset--color--envision-green)) !important;
	color: var(--wp--preset--color--envision-navy-blue) !important;
	text-decoration: none;
}

/* The footer wordmark and social icons are white artwork made for the navy footer; on the yellow they render solid ink. The
   partner logos (AbilityOne, NIB) are opaque and stay as they are. */
[data-scheme="hc"] footer.wp-block-template-part img[src*="env-logo-white"] {
	filter: brightness(0);
}

[data-scheme="hc"] footer.wp-block-template-part .social-icon {
	color: var(--ens-fg);
}

[data-scheme="hc"] footer.wp-block-template-part .social-icon :is(path, rect, circle) {
	fill: var(--ens-fg);
}

/* ===== Responsive base font size via classes ===== */
/* Scales :root so all rem-based sizes (headings, buttons, body) scale together */
html.text-m {
	font-size: 110%;
}

html.text-l {
	font-size: 120%;
}

html.text-xl {
	font-size: 130%;
}

/* The Blackbaud donation form is a cross-origin iframe, so rem never reaches it; zoom the frame by the same step instead (ENV051-232, ENV051-265). */
html:is(.text-m, .text-l, .text-xl) .blackbaud-form-loader iframe {
	min-width: 0 !important; /* the frame's inline 320px minimum would overflow a phone once zoomed */
}

html.text-m .blackbaud-form-loader iframe {
	zoom: 1.1;
}

html.text-l .blackbaud-form-loader iframe {
	zoom: 1.2;
}

html.text-xl .blackbaud-form-loader iframe {
	zoom: 1.3;
}

.sticky-sidebar {
	position: sticky;
	top: calc(var(--wp-admin--admin-bar--height) + 5px);
}

/* Optional heading rhythm */
/* h1,
h2,
h3 {
  line-height: 1.2;
} */

/* ===== Accessibility widget ===== */
.envision-accessibility-switcher {
	position: fixed;
	right: 1rem;
	bottom: 1rem;
	z-index: 10000;
	width: 18rem;
	max-width: calc(100vw - 2rem);
	max-height: calc(100dvh - 2rem);
	overflow-y: auto;
	font: inherit;
	border-radius: 0;
	background: transparent;
	display: grid;
	grid-template-columns: minmax(0, 1fr);
	gap: 0;
}

/* Text Size XL: bar labels wrap instead of overflowing the 256px widget (WCAG 1.4.4/1.4.10) */
.ens-a11y-bar {
	box-sizing: border-box;
	max-width: 100%;
	white-space: normal;
}

/* keep a little separation between ACCESSIBILITY bar and the CLOSE+panel stack */
.ens-a11y-toggle-bar {
	margin-bottom: 0.5rem;
}

/* no gap under CLOSE */
.ens-a11y-close-bar {
	margin-bottom: 0;
}

/* Bars (ACCESSIBILITY / CLOSE) */
.ens-a11y-toggle-bar[hidden],
.ens-a11y-close-bar[hidden] {
	display: none !important;
}

/* Panel */
.ens-a11y-panel {
	background: var(--ens-bg);
	color: var(--ens-fg);
	border: 2px solid var(--ens-border);
	border-radius: 0;
	box-shadow: 0 12px 24px rgba(0, 0, 0, 0.12);
	padding: 1rem 1rem 0.9rem;
	margin-top: 0;
	container-type: inline-size;
}

.ens-a11y-panel[hidden] {
	display: none !important;
}

/* Fields */
.ens-field {
	display: grid;
	grid-template-columns: max-content minmax(0, 1fr);
	align-items: center;
	gap: 0.75rem;
}

.ens-field+.ens-field {
	margin-top: 2rem;
}

.ens-label {
	font-size: var(--wp--preset--font-size--body-copy);
	font-weight: 700;
	letter-spacing: 0;
	line-height: 1.4;
	color: var(--ens-fg);
}

/* Text size select */
.ens-size-select {
	box-sizing: border-box;
	width: 100%;
	max-width: 100%;
	padding: 0.65rem 2.25rem 0.65rem 0.85rem;
	border-radius: 0;
	border: 2px solid var(--ens-border);
	background: var(--ens-bg);
	color: var(--ens-fg);
	font-weight: 700;
	font-family: inherit;
	font-size: var(--wp--preset--font-size--heading-5);
	line-height: 1.4;
	min-height: 44px;
	appearance: none;
}

.ens-select-wrap {
	position: relative;
	display: block;
	min-width: 0;
}

.ens-select-caret {
	pointer-events: none;
	position: absolute;
	right: 0.75rem;
	top: 50%;
	transform: translateY(-50%);
	width: 18px;
	height: 18px;
	color: var(--ens-fg);
}

/* Theme buttons */
.ens-mode-buttons {
	display: flex;
	align-items: center;
	justify-content: space-between;
	flex-wrap: wrap;
	gap: 0.5rem;
}

.ens-mode-btn {
	width: 44px;
	height: 44px;
	box-sizing: border-box;
	flex: 0 0 44px;
	border-radius: 999px;
	border: 2px solid var(--ens-fg);
	font-weight: 900;
	font-size: 1.25rem;
	line-height: 1;
	cursor: pointer;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	padding: 0;
}

.ens-mode-btn:focus-visible,
.ens-size-select:focus-visible {
	outline: 3px solid var(--ens-fg);
	outline-offset: 3px;
}

.ens-mode-btn[data-value="light"] {
	background: var(--wp--preset--color--paper);
	color: var(--wp--preset--color--ink);
}

.ens-mode-btn[data-value="dark"] {
	background: var(--wp--preset--color--ink);
	color: var(--wp--preset--color--paper);
}

.ens-mode-btn[data-value="high-contrast"] {
	background: var(--ens-high-contrast-bg);
	color: var(--wp--preset--color--ink);
}

.ens-mode-btn.selected {
	border-width: 3px;
}

/* Stack rows when text enlargement or a narrow viewport leaves too little room. */
@container (max-width: 13rem) {
	.ens-field {
		grid-template-columns: minmax(0, 1fr);
	}
	.ens-mode-buttons {
		justify-content: flex-start;
	}
}

/* Motion */
@media (prefers-reduced-motion: no-preference) {
	.ens-a11y-panel {
		transition:
			transform 0.16s ease,
			opacity 0.16s ease;
		transform: translateY(8px);
		opacity: 0.001;
	}

	.ens-a11y-panel.is-open {
		transform: translateY(0);
		opacity: 1;
	}
}

.reduce-motion * {
	animation: none !important;
	transition: none !important;
	scroll-behavior: auto !important;
}

/* Visually hidden utility for SR-only messages */
.ens-visually-hidden {
	position: absolute !important;
	width: 1px;
	height: 1px;
	overflow: hidden;
	clip: rect(1px, 1px, 1px, 1px);
	white-space: nowrap;
	border: 0;
	padding: 0;
	margin: -1px;
}

/* Dark mode: blue preset text colours set on blocks in stored content follow
   the scheme. Buttons are excluded; they keep their own fill/text pairing, (see the goldenrod
   rule below). */
[data-scheme="dark"] :is(.has-envision-blue-color, .has-envision-navy-blue-color):not(.wp-element-button, .wp-block-button__link) {
	color: var(--ens-primary) !important;
}

/* The Inline button style is a text link on the page background (theme.json fixes it to paper), so it follows the scheme. */
[data-scheme="dark"] .wp-block-button.is-style-inline > .wp-block-button__link {
	background-color: var(--ens-bg);
	color: var(--ens-primary);
}

/* Green fills stay green in dark, so their contrast text stays ink (white on #78BE21 is 2.3:1). */
[data-scheme="dark"] .has-envision-green-background-color.has-contrast-color:not(.wp-element-button, .wp-block-button__link) {
	color: var(--wp--preset--color--ink) !important;
}

/* Pills keep their light fill in dark, so their navy text stays navy (white on #41B6E6 is 2.3:1). */
[data-scheme="dark"] .has-envision-bright-blue-background-color.has-envision-navy-blue-color:not(.wp-block-group) {
	color: var(--wp--preset--color--envision-navy-blue) !important;
}

/* Unfilled link-style buttons (e.g. a card's Read more) follow the scheme link colour; filled buttons keep their pairing. */
[data-scheme="dark"] .wp-block-button__link:is(.has-envision-blue-color, .has-envision-navy-blue-color):not([class*="-background-color"], .has-background) {
	color: var(--ens-primary) !important;
}

[data-scheme="dark"] .has-charcoal-color:not(.wp-element-button, .wp-block-button__link) {
	color: var(--ens-muted) !important;
}

/* Links inside blue-coloured text blocks (GenerateBlocks text) and the news filter dropdown buttons follow the scheme. */
[data-scheme="dark"] :is(.has-envision-blue-color, .has-envision-navy-blue-color) a:where(:not(.wp-element-button, .wp-block-button__link)),
[data-scheme="dark"] .filter-container .components-button {
	color: var(--ens-primary);
}
