/*  ==========================================================================
Theme contrast
Keeps text readable when an editor changes a block's colours (Appearance fields) or the Site Settings theme.

Classes come from blockStyle() in src/components/blocks/util.tsx. Nothing here matches a block whose
Appearance fields are empty, so the default site looks exactly like the prototype.

  .u-bg / .u-bg-<preset> / .u-bg-custom   a background colour was chosen (inline var --blk-bg)
  .u-on-dark / .u-on-light                 tone behind the text; defines the --blk-* colour vars
  .u-contrast                              text, headings and links use --blk-fg / --blk-heading / --blk-link
  .u-accent                                chevrons, arrows, underlines, heading stripes use --blk-accent

Everything is driven by inherited custom properties, so a nested block with its own background simply
redefines the vars and its descendants follow the nearest one.

`:not(#_)` adds one ID of specificity (it matches every element), so these rules beat the stylesheets'
class-based colour rules (e.g. `.section--dark .link-list a`, `.link-list--alt a`, `.content a`) and the
theme's content-link rule, without !important. Buttons and components with their own surface are excluded
(the :where(:not(...)) list, zero specificity) and keep their own colours.

Load after legacy-secondary.css. Keep the exclusion list / heading list in sync with util.tsx
(OWN_SURFACE / HEADINGS), which re-uses the same rules for theme-role flips.
==========================================================================  */

/* Root defaults for button contrast */
:root {
	--theme-button-dark-section-text: var(--color-primary-usfgreen, #006747);
	--theme-button-dark-section-hover-text: var(--color-text-dark, #1b1b1b);
}

/* Tone defaults (the --theme-*-on-* fallbacks are emitted by themeCss() only when a theme role would clash) */
.u-on-dark {
	--blk-fg: var(--color-text-light, #fff);
	--blk-heading: var(--blk-fg);
	--blk-link: var(--blk-fg);
	--blk-accent: var(--theme-accent-on-dark, var(--color-accent-apple, #9ccb3b));
}
.u-on-light {
	--blk-fg: var(--color-text-dark, #1b1b1b);
	--blk-heading: var(--theme-heading-on-light, var(--color-secondary-evergreen, #005432));
	--blk-link: var(--theme-link-on-light, var(--color-primary-usfgreen, #006747));
	--blk-accent: var(--theme-accent-on-light, var(--color-primary-usfgreen, #006747));
}

/* Homepage overlay sections: the text box takes the chosen background instead of white */
.section--image-overlay.u-bg .section__text {
	background-color: var(--blk-bg);
}

/*  --------------------------------------------------------------------------
Text, headings, links
--------------------------------------------------------------------------  */
.u-contrast:not(#_) {
	color: var(--blk-fg);
}

/* Everything that sets its own colour in the stylesheets follows its parent instead
   (so spans inside links take the link colour, spans inside headings the heading colour) */
.u-contrast:not(#_) :is(h1, h2, h3, h4, h5, h6, p, li, dt, dd, blockquote, figcaption, caption, label, small, strong, em, b, i, span, div, abbr, time, cite, q, address):where(:not(.card,.card *,.card__category,.card__category *,.c-calloutText,.c-calloutText *,table,table *,.dateItem_block,.dateItem_block *,.at-a-glance,.at-a-glance *,.widget_calIcon,.widget_calIcon *,.calendar-feed__date,.calendar-feed__date *,.c-blockquote_icon,.c-blockquote_icon *,.video-grid-icon,.video-grid-icon *,.snippetLinkGrid_item,.snippetLinkGrid_item *,.warning,.warning *,.dialog,.dialog *,.u-rotator_navigation,.u-rotator_navigation *,.snippetRotator_navigation,.snippetRotator_navigation *,.audience-gateway__select,.audience-gateway__select *,[class*="button"],[class*="button"] *,[class*="btn"],[class*="btn"] *,button,button *,input,input *,select,select *,textarea,textarea *)) {
	color: inherit;
}

/* A nested block with its own tone starts from its own text colour */
.u-contrast:not(#_) :is(.u-on-dark, .u-on-light) {
	color: var(--blk-fg);
}

.u-contrast:not(#_) :is(h1, h2, h3, h4, h5, h6, .section__heading, .stylized-header, .snippetHeading, .mainContent_heading, .widget_name, .widgetRegion_heading, .secondaryContent_heading, .infoSection_heading, .highlighted-content_heading, .cta_headline, .sectionHeading_text, .c-calloutText_heading, .u-jumbotron_heading, .hero_heading):where(:not(.card,.card *,.card__category,.card__category *,.c-calloutText,.c-calloutText *,table,table *,.dateItem_block,.dateItem_block *,.at-a-glance,.at-a-glance *,.widget_calIcon,.widget_calIcon *,.calendar-feed__date,.calendar-feed__date *,.c-blockquote_icon,.c-blockquote_icon *,.video-grid-icon,.video-grid-icon *,.snippetLinkGrid_item,.snippetLinkGrid_item *,.warning,.warning *,.dialog,.dialog *,.u-rotator_navigation,.u-rotator_navigation *,.snippetRotator_navigation,.snippetRotator_navigation *,.audience-gateway__select,.audience-gateway__select *,[class*="button"],[class*="button"] *,[class*="btn"],[class*="btn"] *,button,button *,input,input *,select,select *,textarea,textarea *)) {
	color: var(--blk-heading);
}

/* All link states, incl. link lists (chevrons-list, link-list--alt/inline), arrow links, CTA tiles, .u-more */
.u-contrast:not(#_) a:where(:not(.card,.card *,.card__category,.card__category *,.c-calloutText,.c-calloutText *,table,table *,.dateItem_block,.dateItem_block *,.at-a-glance,.at-a-glance *,.widget_calIcon,.widget_calIcon *,.calendar-feed__date,.calendar-feed__date *,.c-blockquote_icon,.c-blockquote_icon *,.video-grid-icon,.video-grid-icon *,.snippetLinkGrid_item,.snippetLinkGrid_item *,.warning,.warning *,.dialog,.dialog *,.u-rotator_navigation,.u-rotator_navigation *,.snippetRotator_navigation,.snippetRotator_navigation *,.audience-gateway__select,.audience-gateway__select *,[class*="button"],[class*="button"] *,[class*="btn"],[class*="btn"] *,button,button *,input,input *,select,select *,textarea,textarea *)) {
	color: var(--blk-link);
}

/* In-text link hover: the stylesheet's evergreen/gold "chip" may vanish on a custom colour; underline instead */
.u-contrast:not(#_) :is(p, li) a:where(:not([class*="button"], [class*="btn"])):is(:hover, :focus, :active) {
	background-color: transparent;
	text-decoration-line: underline;
	text-decoration-color: currentColor;
}

/*  --------------------------------------------------------------------------
Buttons on dark sections / surfaces:
Primary buttons inside .section--dark or .u-on-dark take a white background (#fff)
and must never have invisible white text when secondary or theme colors are changed.
Always use high-contrast dark text on the white button surface.
--------------------------------------------------------------------------  */
:is(.section--dark, .u-on-dark) :is(.button--primary, .button--primary:visited):not(:hover, :focus, :active) {
	background-color: #fff;
	color: var(--theme-button-dark-section-text, var(--theme-link-on-light, var(--color-primary-usfgreen, #006747)));
}

:is(.section--dark, .u-on-dark) :is(.button--primary, .button--secondary, .button):is(:hover, :focus, :active) {
	background-color: var(--color-primary-gold, #CFC493);
	border-color: var(--color-primary-gold, #CFC493);
	color: var(--theme-button-dark-section-hover-text, var(--color-text-dark, #1b1b1b));
}

:is(.section--dark, .u-on-dark) :is(.button--secondary, .button--secondary:visited, .button--ghost, .button--ghost:visited):not(:hover, :focus, :active) {
	border-color: var(--color-text-light, #fff);
	color: var(--color-text-light, #fff);
}

/* Outline buttons on light surfaces follow contrasting text/link colour */
.u-on-light:not(#_) :is(.button--secondary, .button--ghost):not(:hover, :focus, :active) {
	border-color: var(--theme-link-on-light, var(--color-primary-usfgreen, #006747));
	color: var(--theme-link-on-light, var(--color-primary-usfgreen, #006747));
}

/* Outline buttons are transparent: follow the text colour */
.u-contrast:not(#_) :is(.button--secondary, .button--ghost):not(:hover, :focus, :active) {
	border-color: var(--blk-fg);
	color: var(--blk-fg);
}

/* Components with their own light surface: don't inherit light text from the block */
.u-contrast:not(#_) :where(.card:not(.card--usfgreen)) {
	color: var(--color-neutral-slate, #466069);
}
.u-contrast:not(#_) :where(.c-calloutText, table) {
	color: var(--color-text-dark, #1b1b1b);
}
.u-on-dark.u-contrast:not(#_) :where(table) {
	background-color: #fff; /* striped tables only paint odd rows */
}

/*  --------------------------------------------------------------------------
Accents: chevrons, arrows, underlines, heading stripes, list separators
--------------------------------------------------------------------------  */
.u-accent:not(#_) :is(.chevrons-list, .square-arrow-list) a::before {
	background-color: var(--blk-accent);
}
.u-accent:not(#_) :is(.u-more_icon, .arrow-link__icon, .cta_icon, .snippetToggle_icon) {
	color: var(--blk-accent);
}
.u-accent:not(#_) .arrow-link__text {
	border-bottom-color: var(--blk-accent);
}
.u-accent:not(#_) .link-list--alt li + li {
	border-top-color: var(--blk-accent);
}
.u-accent:not(#_) .link-list--inline a {
	text-decoration-color: var(--blk-accent);
}
.u-accent:not(#_) .section__heading::before {
	background: repeating-linear-gradient(-45deg, var(--blk-accent), var(--blk-accent) 1px, transparent 2px, transparent 5px);
}
.u-accent:not(#_) .stat + .stat::before {
	background-image: linear-gradient(to top left, transparent calc(50% - 2px), var(--blk-accent), transparent calc(50% + 2px));
}
