/**
 * global.css — base reset + accessibility utilities.
 *
 * Shared studio baseline. Loaded first; every other stylesheet in
 * assets/css/ depends on it. Per the methodology hard-constraints this file
 * sets NO font-size and NO gap — those belong to theme.json tokens and block
 * attributes. The one sanctioned margin here is the root blockGap reset below
 * (a reset that HANDS spacing to sections, not margin-for-spacing). Everything
 * else stays resets + a11y only.
 */

*,
*::before,
*::after {
	box-sizing: border-box;
}

img,
svg,
video {
	display: block;
	max-width: 100%;
	height: auto;
}

/* -----------------------------------------------
   Spacing system — sections own their vertical spacing.

   WP implements the root blockGap as margin-block-start on each top-level
   block. Zeroing it here kills the blank space between full-width sections
   on the front end, in the editor canvas, and inside post-content — so each
   section controls its own breathing room via the `section` padding preset
   + a per-section blockGap, and adjacent sections sit flush. Content NESTED
   inside a section still gets theme.json's blockGap rhythm; only the
   top-level margins are zeroed.
   ----------------------------------------------- */
.wp-site-blocks > *,
.editor-styles-wrapper > .is-root-container > *,
.entry-content > * {
	margin-block-start: 0;
	margin-block-end: 0;
}

/* Adjacent same-color section hairline fix.
   Fluid clamp() line-heights produce fractional section heights; at DPR >= 2,
   sub-pixel rounding can briefly open a 1-device-pixel seam between two
   sections of the same background. Overlap adjacent same-color sections by
   1px — invisible because the overlap is on matching colors. `secondary` and
   `white` slugs resolve to the same value in the default palette, so they're
   cross-paired here. Prune/extend pairs to match the project palette. */
/* Protomiq: scoped to top-level sections — unscoped, it also pulled any two
   adjacent white cards together by 1px and cancelled their blockGap. */
:is(.wp-site-blocks, .wp-block-post-content) > .has-primary-background-color + .has-primary-background-color,
:is(.wp-site-blocks, .wp-block-post-content) > .has-secondary-background-color + .has-secondary-background-color,
:is(.wp-site-blocks, .wp-block-post-content) > .has-secondary-background-color + .has-white-background-color,
:is(.wp-site-blocks, .wp-block-post-content) > .has-white-background-color + .has-secondary-background-color,
:is(.wp-site-blocks, .wp-block-post-content) > .has-white-background-color + .has-white-background-color,
:is(.wp-site-blocks, .wp-block-post-content) > .has-accent-background-color + .has-accent-background-color,
:is(.wp-site-blocks, .wp-block-post-content) > .has-muted-background-color + .has-muted-background-color {
	margin-top: -1px;
}

/* Prose opt-in — restore native block-gap rhythm for long-form content.
   Pages use section groups that manage their own spacing; article bodies
   contain paragraphs/headings that need vertical rhythm.

   Keyed on `.single`, NOT `.single-post`. WP adds `single` to every is_single()
   response — every custom post type included — and never to pages. Keying on
   `single-post` made this an allowlist that silently missed each new CPT:
   `single-insight`, `single-case_study` etc. render with the reset still in
   force and paragraphs butt together at 0. An allowlist that has to be extended
   per project is a bug generator; this covers CPTs on registration day.

   `:not(.alignfull)` keeps the other content model working: a CPT single built
   from full-width sections rather than prose still sits flush, because sections
   carry align: full. Both models, one rule, nothing to maintain.

   Editor parity: the editor canvas has no `.single` class, so this rule can't
   reach it. functions.php → atomic_editor_prose_rhythm() adds the same rule to
   the canvas whenever the editor opens a non-page post type — the same set of
   posts `.single` covers here. Never patch the gap with per-block margins in
   the editor: they are saved into the content and outlive the fix. */
.single .entry-content > * + *:not(.alignfull) {
	margin-block-start: var(--wp--style--block-gap);
	margin-block-end: 0;
}

/* Accessibility — visually hidden until focused (WP-standard). */
.screen-reader-text {
	border: 0;
	clip: rect(1px, 1px, 1px, 1px);
	clip-path: inset(50%);
	height: 1px;
	width: 1px;
	overflow: hidden;
	padding: 0;
	position: absolute !important;
	word-wrap: normal !important;
}

/* WordPress built-in skip link — brand its focus state (core emits the link). */
.skip-link.screen-reader-text:focus {
	background-color: var(--wp--preset--color--secondary);
	color: var(--wp--preset--color--primary);
	clip: auto;
	clip-path: none;
	display: block;
	height: auto;
	left: 8px;
	top: 8px;
	padding: 12px 20px;
	width: auto;
	z-index: 100000;
	outline: 2px solid var(--wp--preset--color--accent);
}

/* -----------------------------------------------
   Shared utilities — apply as block className.
   See ARCHITECTURE.md → Shared Utilities in global.css.
   ----------------------------------------------- */

/* Reveal — pre-paint start state (ACCESSIBILITY.md → Accessible scroll-reveal).
   Theme scripts load in the footer, so a start state set by JS lands AFTER
   first paint: the content flashes, blanks, then fades in. Anything a script
   will animate in starts hidden HERE instead, before first paint.

     .atomic-reveal       on a group: its direct children fade/rise in as one
                          staggered group when it scrolls in (reveal.js).
     .atomic-fouc-hide    an element YOUR script animates. The script must set
                          its own start state synchronously (gsap.set/from/
                          fromTo) — the blanket drops at DOMContentLoaded.

   Released by .atomic-reveal-ready (functions.php → atomic_js_class: added on
   DOMContentLoaded, after every footer script has set its inline start state,
   with a 4s failsafe). `filter: opacity(0)` ONLY — visibility/display/
   autoAlpha would drop the content from the accessibility tree and Tab order
   (the NISA WCAG failure), and the `opacity` property makes WAVE score every
   unrevealed block as "very low contrast" text (it folds opacity into the text
   colour; it ignores filter — Shack the Halls, 2026-10-19). Project scripts
   animating .atomic-fouc-hide fade `filter` too. Guards: html.js (no JS →
   nothing hidden), no-preference (reduced motion → nothing hidden), main (site
   chrome always paints). */
@media (prefers-reduced-motion: no-preference) {
	html.js:not(.atomic-reveal-ready) main :is(.atomic-reveal > *, .atomic-reveal--hero > :first-child:not(:only-child) > *, .atomic-fouc-hide) {
		filter: opacity(0);
	}
}

/* Printing a page mid-scroll must not print blank sections: GSAP's inline
   start states (filter opacity(0), a transform) would otherwise reach the paper. */
@media print {
	.atomic-reveal > *,
	.atomic-reveal--hero > :first-child:not(:only-child) > *,
	.atomic-fouc-hide {
		filter: none !important;
		opacity: 1 !important;
		transform: none !important;
	}
}

/* Restore heading color inheritance for raw HTML inside core/html blocks. */
.atomic-html-inherit h1,
.atomic-html-inherit h2,
.atomic-html-inherit h3,
.atomic-html-inherit h4,
.atomic-html-inherit h5,
.atomic-html-inherit h6 {
	color: inherit;
}

/* Flush-left for max-width text (editor-max-width.js control). Defeats WP
   constrained-layout's `margin-left/right: auto !important` auto-centering on
   narrower-than-contentSize children — FOOTGUNS.md #1. Inline margins ONLY
   (hard-constraints exception #2); margin-block stays with blockGap.

   The start margin is NOT 0. WP centres the contentSize column inside the
   section's padding box, so the column's own left edge already sits
   (100% - contentSize) / 2 inward. Zeroing the start margin flushes the text
   to the padding edge instead — left of every sibling, ~112px off in a
   full-width section. Reproducing the column offset is what keeps it aligned
   with the heading above it. max() collapses to 0 responsively: once the
   container is at or below contentSize the offset is gone.

   Blind spot: reads the ROOT contentSize. Inside a group carrying its own
   layout.contentSize, core emits a literal value instead of this var, so the
   offset computes against the wrong number — use the wrapper-group pattern
   there (PATTERNS.md → "Narrow copy, flush left").

   The class is DOUBLED on purpose. `!important` alone is not enough: core's
   rule is `.is-layout-constrained > :where(...)`, and `:where()` contributes
   nothing, so it lands at (0,1,0) — a dead tie with a single class. Among
   competing `!important` declarations the cascade decides on specificity
   first and only then on source order, so a tie leaves the winner up to which
   stylesheet loaded last. That is context-dependent: it can render flush on
   the front end and centred in the editor, from the same CSS. Repeating the
   class costs nothing, lifts this to (0,2,0), and settles it everywhere.

   Logical properties on purpose, but they resolve against the ELEMENT's
   writing mode: on a rotated (`vertical-rl`) element margin-inline is the
   vertical axis and can't touch core's physical margin-left/right. Rotated
   elements need .atomic-flush-left--physical below. */
.atomic-flush-left.atomic-flush-left {
	margin-inline: max(0px, calc((100% - var(--wp--style--global--content-size)) / 2)) auto !important;
}

/* Same cure for elements in a rotated writing mode — physical properties,
   because that is what core's constrained rule sets. */
.atomic-flush-left--physical.atomic-flush-left--physical {
	margin-left: max(0px, calc((100% - var(--wp--style--global--content-size)) / 2)) !important;
	margin-right: auto !important;
}

/* Pause/play accessibility shell (WCAG 2.2.2) — 44×44 minimum target,
   visible focus ring, no default chrome. JS injects the element, SVG icon,
   and dynamic aria-label. */
.atomic-pause-play {
	min-width: 44px;
	min-height: 44px;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	padding: 0;
	border: 0;
	background: none;
	color: inherit;
	cursor: pointer;
}

.atomic-pause-play:focus-visible {
	outline: 2px solid var(--wp--preset--color--accent);
	outline-offset: 2px;
}

/* Carousel tracks in the editor (.atomic-carousel) — put the class on the
   flex-row group whose children are the slides (Advanced → Additional CSS
   class). On the site, the project's carousel JS (Swiper or a transform
   track) scrolls them; in the editor a nowrap row just runs off the canvas
   and most slides can't be reached. Inside the editor canvas only, the track
   wraps into a grid of thumbnails with a label, so every slide can be
   clicked, replaced, reordered and added to. Thumbnail width is
   --atomic-carousel-thumb (default 200px). Selectors start with the editor's
   block-list class, so nothing here reaches the front end. Learned on Shack
   the Halls (2026-10-19) — "we run into this a lot". */
.block-editor-block-list__layout .atomic-carousel {
	position: relative;
	flex-wrap: wrap;
	align-items: flex-start;
	transform: none;
	overflow: visible;
	padding: 2.75rem 0.75rem 0.75rem;
	outline: 2px dashed var(--wp--preset--color--muted);
	outline-offset: -2px;
	border-radius: 12px;
}

.block-editor-block-list__layout .atomic-carousel::before {
	content: "Carousel · slides scroll on the live site. Click a slide to edit it, drag to reorder, + to add.";
	position: absolute;
	top: 0.6rem;
	left: 0.75rem;
	right: 0.75rem;
	padding: 0.3rem 0.7rem;
	border-radius: 999px;
	background: var(--wp--preset--color--white);
	color: var(--wp--preset--color--primary);
	font: 600 13px/1.3 system-ui, sans-serif; /* lint-allow: editor-chrome label, not site type */
	pointer-events: none;
}

/* !important: slide widths often arrive as inline styles from the block's own
   width/dimension settings; this is editor-canvas only, so it never fights the
   front end. */
.block-editor-block-list__layout .atomic-carousel > * {
	flex: 0 0 auto !important;
	width: var(--atomic-carousel-thumb, 200px) !important;
	max-width: 100%;
}

.block-editor-block-list__layout .atomic-carousel > * img {
	width: 100% !important;
	height: auto !important;
}

/* Honor reduced-motion globally. */
@media (prefers-reduced-motion: reduce) {
	*,
	*::before,
	*::after {
		animation-duration: 0.01ms !important;
		animation-iteration-count: 1 !important;
		transition-duration: 0.01ms !important;
		scroll-behavior: auto !important;
	}
	/* The reveal start state above sits inside `no-preference`, so reduced-
	   motion users never get hidden content — no override needed here. */
}
