/**
 * Global stylesheet: reset, kivora- prefixed token aliases (mapped from
 * theme.json's WordPress-generated --wp--preset--/--wp--custom-- variables,
 * see 02-development/04-css-architecture.md and 02-naming-conventions.md §6),
 * and base element styles.
 */

/* 1. Reset and base styles */
*,
*::before,
*::after {
	box-sizing: border-box;
}

body {
	margin: 0;
}

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

/*
 * Embedded players carry fixed pixel dimensions (a YouTube iframe is 580px
 * wide), which scrolls narrow viewports sideways. Browsers derive the aspect
 * ratio from the width/height attributes, so capping the width keeps the
 * ratio while fitting the column.
 */
iframe,
embed,
object {
	max-width: 100%;
	height: auto;
}

/*
 * 2. Design tokens (kivora- aliases over WordPress-generated custom properties)
 *
 * Slugs mirror the v1 token tables exactly: colors from
 * 03-ui-system/06-color-system.md §3, spacing from 07-spacing-system.md §4,
 * and type steps from 05-typography.md §5.
 */
:root {
	--kivora-color-primary: var(--wp--preset--color--primary);
	--kivora-color-secondary: var(--wp--preset--color--secondary);
	--kivora-color-foreground: var(--wp--preset--color--foreground);
	--kivora-color-background: var(--wp--preset--color--background);
	--kivora-color-border-muted: var(--wp--preset--color--border-muted);
	--kivora-color-success: var(--wp--preset--color--success);
	--kivora-color-error: var(--wp--preset--color--error);
	--kivora-color-warning: var(--wp--preset--color--warning);

	--kivora-spacing-xxs: var(--wp--preset--spacing--xxs);
	--kivora-spacing-xs: var(--wp--preset--spacing--xs);
	--kivora-spacing-sm: var(--wp--preset--spacing--sm);
	--kivora-spacing-md: var(--wp--preset--spacing--md);
	--kivora-spacing-lg: var(--wp--preset--spacing--lg);
	--kivora-spacing-xl: var(--wp--preset--spacing--xl);
	--kivora-spacing-xxl: var(--wp--preset--spacing--xxl);
	--kivora-spacing-huge: var(--wp--preset--spacing--huge);

	--kivora-font-size-small: var(--wp--preset--font-size--small);
	--kivora-font-size-base: var(--wp--preset--font-size--base);
	--kivora-font-size-h6: var(--wp--preset--font-size--h-6);
	--kivora-font-size-h5: var(--wp--preset--font-size--h-5);
	--kivora-font-size-h4: var(--wp--preset--font-size--h-4);
	--kivora-font-size-h3: var(--wp--preset--font-size--h-3);
	--kivora-font-size-h2: var(--wp--preset--font-size--h-2);
	--kivora-font-size-h1: var(--wp--preset--font-size--h-1);

	--kivora-radius-sm: var(--wp--custom--radius--sm);
	--kivora-radius-md: var(--wp--custom--radius--md);
	--kivora-radius-lg: var(--wp--custom--radius--lg);
	--kivora-radius-pill: var(--wp--custom--radius--pill);

	--kivora-border-width: var(--wp--custom--border--width);
	--kivora-transition-base: var(--wp--custom--transition--base);
}

/* 3. Layout styles */
.kivora-container,
.kivora-layout {
	width: 100%;
	max-width: var(--wp--style--global--content-size, 720px);
	margin-inline: auto;
	padding-inline: var(--kivora-spacing-sm);
}

/*
 * Wide container: templates whose main column carries a multi-column grid
 * (blog, archive, search) or a sidebar column, per the contentSize/wideSize
 * pair declared in theme.json (03-ui-system/02-template-system.md §5).
 */
.kivora-layout--wide {
	max-width: var(--wp--style--global--wide-size, 1200px);
}

.kivora-layout {
	padding-block: var(--kivora-spacing-lg);
}

/*
 * Sidebar columns only split at the md breakpoint (782px,
 * 03-ui-system/08-responsive-system.md §2); below that the sidebar reflows
 * underneath the content rather than being hidden (§8).
 */
@media (min-width: 782px) {
	.kivora-layout--sidebar-left,
	.kivora-layout--sidebar-right {
		display: grid;
		gap: var(--kivora-spacing-lg);
		align-items: start;
	}

	/* The sidebar never exceeds a third of the container
	   (04-content-areas/10-sidebar-system.md §9). */
	.kivora-layout--sidebar-right {
		grid-template-columns: minmax(0, 1fr) minmax(0, 18rem);
	}

	.kivora-layout--sidebar-left {
		grid-template-columns: minmax(0, 18rem) minmax(0, 1fr);
	}

	/* Source order stays content-first for screen readers and keyboard
	   users; only the visual column order flips. */
	.kivora-layout--sidebar-left .kivora-layout__main {
		order: 2;
	}

	.kivora-layout--sidebar-left .kivora-sidebar {
		order: 1;
	}
}

.kivora-layout__main {
	min-width: 0;
}

/*
 * Stretched layout: no container at all, so full-bleed blocks and page-builder
 * sections reach the viewport edges (04-content-areas/07-page-system.md §2).
 * Inner blocks still get their own widths from theme.json's layout settings.
 */
.kivora-layout--stretched {
	width: 100%;
}

/*
 * Page-builder content (inc/compatibility/page-builder.php) lays out its own
 * sections at full width, so the theme drops its container and reading-width
 * cap rather than boxing the builder's output inside them.
 */
.kivora-has-page-builder .kivora-layout {
	max-width: none;
	padding-inline: 0;
	padding-block: 0;
}

/*
 * A transparent header overlays the content, so a page that has a hero to
 * overlay starts its first section at the top of the viewport rather than
 * below a header that no longer takes up space in the flow.
 */
.kivora-header-over-hero .kivora-layout--stretched > .kivora-entry > .kivora-entry__content > :first-child {
	margin-block-start: 0;
}

/*
 * ...but only a full-bleed first section can sit *under* the header. A page
 * that shows its title, or that is contained rather than stretched, has
 * nothing to hide behind, so the title would render inside the header band, on
 * top of the branding. Those pages reserve the header's height instead. The
 * header is position:absolute in this state, so nothing else pushes the
 * content down.
 */
.kivora-has-transparent-header:not(.kivora-header-over-hero) .kivora-layout {
	padding-block-start: calc(var(--kivora-header-height, 5rem) + var(--kivora-spacing-lg));
}

.kivora-has-transparent-header:not(.kivora-header-over-hero) .kivora-layout--stretched {
	padding-block-start: var(--kivora-header-height, 5rem);
}

/* 4. Component styles: see assets/css/components/ (enqueued conditionally) */

/*
 * 5. WordPress core classes
 *
 * Markup WordPress generates itself — classic alignment, captions, galleries,
 * sticky posts, post-author comments — which the theme does not control but
 * must style. Required by the WordPress.org review and exercised by the Theme
 * Unit Test data (05-ux-and-quality/24-wordpress-org-review.md).
 */
.alignleft {
	float: left;
	margin-inline-end: var(--kivora-spacing-md);
	margin-block-end: var(--kivora-spacing-sm);
}

.alignright {
	float: right;
	margin-inline-start: var(--kivora-spacing-md);
	margin-block-end: var(--kivora-spacing-sm);
}

.aligncenter {
	display: block;
	margin-inline: auto;
	margin-block-end: var(--kivora-spacing-sm);
}

.alignnone {
	margin-block-end: var(--kivora-spacing-sm);
}

/* Floats are cleared at the end of any element that can contain them, so a
   floated image never escapes its entry and overlap the next one. */
.kivora-entry__content::after,
.comment-content::after {
	content: "";
	display: table;
	clear: both;
}

.wp-caption {
	max-width: 100%;
	margin-block-end: var(--kivora-spacing-sm);
}

.wp-caption img {
	margin-block-end: var(--kivora-spacing-xxs);
}

.wp-caption-text,
.gallery-caption {
	margin: 0;
	font-size: var(--kivora-font-size-small);
	color: var(--kivora-color-foreground);
	text-align: center;
	opacity: 0.8;
}

/*
 * core/latest-posts in its grid layout, which the Latest Posts pattern uses.
 * Core sizes each thumbnail to its own proportions, so a row of posts whose
 * featured images differ in shape comes out ragged, with every title starting
 * at a different height. Only the grid is touched; a list keeps core's sizing.
 */
.wp-block-latest-posts.is-grid .wp-block-latest-posts__featured-image img {
	width: 100%;
	aspect-ratio: 16 / 9;
	object-fit: cover;
}

/* Sticky posts are marked, not restyled — the badge is added by the blog
   template; this keeps the card itself distinguishable without colour alone. */
.sticky {
	border-inline-start: 3px solid var(--kivora-color-secondary);
}

/* A comment left by the post's own author. */
.bypostauthor > .comment-body {
	border-inline-start: 3px solid var(--kivora-color-primary);
	padding-inline-start: var(--kivora-spacing-sm);
}

/*
 * Core emits .screen-reader-text in markup the theme does not own (comment
 * navigation, the password form, core widgets), so it must be styled here even
 * though the theme's own markup uses .kivora-sr-only.
 */
.screen-reader-text,
.kivora-sr-only {
	position: absolute;
	width: 1px;
	height: 1px;
	padding: 0;
	margin: -1px;
	overflow: hidden;
	clip: rect(1px, 1px, 1px, 1px);
	clip-path: inset(50%);
	white-space: nowrap;
	border: 0;
	word-wrap: normal !important;
}

/* Core's own skip links and "skip to comment" links use this class and must
   become visible when focused. */
.screen-reader-text:focus {
	position: static;
	width: auto;
	height: auto;
	margin: 0;
	overflow: visible;
	clip: auto;
	clip-path: none;
	white-space: normal;
}

/* 6. Utility classes */
.kivora-skip-link {
	position: absolute;
	top: -100%;
	inset-inline-start: 0;
	z-index: 100000;
	padding: var(--kivora-spacing-xs) var(--kivora-spacing-sm);
	background: var(--kivora-color-background);
	color: var(--kivora-color-foreground);
}

.kivora-skip-link:focus {
	top: 0;
}

/*
 * A two-tone ring. A single primary ring disappeared on primary surfaces
 * (announcement bar, primary buttons, dark heroes) at 1:1, and a ring in the
 * element's own text colour disappears once the 2px offset puts it on the
 * surrounding surface instead. Drawing both means one of them always sits
 * against a contrasting colour: the light outline hugs the element, the dark
 * spread ring sits on the page.
 */
:focus-visible {
	outline: 2px solid var(--kivora-color-background);
	outline-offset: 0;
	box-shadow: 0 0 0 4px var(--kivora-color-foreground);
}

/*
 * Set by assets/js/modules/background-inert.js while the mobile menu or the
 * search dialog is open: the page behind an overlay must not scroll under it.
 */
.kivora-overlay-open,
.kivora-overlay-open body {
	overflow: hidden;
}

/*
 * Older iOS Safari ignores overflow on the root for touch scrolling, and a
 * drag that reaches the end of the panel chains on to the page. Containing
 * overscroll on the panels themselves stops that chain on every engine.
 */
.kivora-search-modal,
.kivora-primary-nav {
	overscroll-behavior: contain;
}

/*
 * Motion is decoration here, never a requirement: honour the operating
 * system's "reduce motion" preference for every transition and animation.
 * The hero slider stops autoplaying in script; this covers the CSS side
 * (the mobile panel slide, hover fades) that the script cannot reach.
 */
@media (prefers-reduced-motion: reduce) {
	*,
	*::before,
	*::after {
		animation-duration: 0.01ms !important;
		animation-iteration-count: 1 !important;
		transition-duration: 0.01ms !important;
		transition-delay: 0s !important;
		scroll-behavior: auto !important;
	}
}
