/*
 * Edrana shared CSS: reset, layout helpers, prose, heading spans, buttons, icons.
 * Loaded on the front end and in the editor iframe (inc/assets.php).
 * Values only from theme.json tokens; literal values only for breakpoints, 0, 1px
 * hairlines, percentages, icon geometry and the reveal timings (§ Motion, mirrored in motion.js).
 * Breakpoints: ≤767 mobile design, 768–1199 tablet (derived), ≥1200 desktop design.
 */

/* ---------- Reset ---------- */

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

/* Stop mobile browsers (and full-page captures) from enlarging long text blocks on their own. */
html {
	-webkit-text-size-adjust: 100%;
	text-size-adjust: 100%;
}

body {
	margin: 0;
	-webkit-font-smoothing: antialiased;
	-moz-osx-font-smoothing: grayscale;
	text-rendering: optimizeLegibility;
}

:where(h1, h2, h3, h4, h5, h6, p, figure, blockquote, dl, dd) {
	margin-block: 0;
}

:where(img, svg, video) {
	max-width: 100%;
	height: auto;
}

:where(button) {
	font: inherit;
	color: inherit;
}

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

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

@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;
	}
}

.rk-visually-hidden {
	position: absolute !important;
	width: 1px;
	height: 1px;
	overflow: hidden;
	clip-path: inset(50%);
	white-space: nowrap;
}

/* Header height for blocks that run under the header (e.g. a hero gradient). */
:root {
	--rk-header-height: var(--wp--custom--header--height-mobile);
}

@media (min-width: 1200px) {
	:root {
		--rk-header-height: var(--wp--custom--header--height);
	}
}

/* ---------- Layout ---------- */

/*
 * Sections run edge to edge with no block gap between them: template parts, main,
 * post content and every rekos/* section. (body prefix beats WordPress's 0-1-0 layout rules.)
 */
body .wp-site-blocks > *,
body :where(main, .wp-block-post-content, .is-root-container) > [class*="wp-block-rekos-"],
body :where(main) > :is(.wp-block-post-content, .wp-block-template-part, .rk-article) {
	margin-block: 0;
}

/* Content width inside a full-width section: 1296 px, side gutters from the root padding. */
.rk-inner {
	width: min(var(--wp--style--global--content-size), 100% - 2 * var(--wp--style--root--padding-left));
	margin-inline: auto;
}

/* Core blocks placed directly in a page (between sections) keep the content width. */
.wp-block-post-content:not(.rk-prose) > :not([class*="wp-block-rekos-"]),
.editor-styles-wrapper .is-root-container > :not([class*="wp-block-rekos-"]) {
	width: min(var(--wp--style--global--content-size), 100% - 2 * var(--wp--style--root--padding-left));
	margin-inline: auto;
}

/* ---------- Prose: article and policy bodies ---------- */

.rk-prose {
	width: min(var(--wp--custom--layout--prose), 100% - 2 * var(--wp--style--root--padding-left));
	margin-inline: auto;
	font-size: var(--wp--preset--font-size--md);
	line-height: 1.556;
}

/* Policy body 16/24 at 1440 and 375 (Figma 395:3271, 1032:9431), not the fluid 14–16 base. */
.rk-prose--policy {
	width: min(var(--wp--custom--layout--policy), 100% - 2 * var(--wp--style--root--padding-left));
	font-size: var(--wp--preset--font-size--h-6);
	line-height: 1.5;
}

/* Article and policy headings are Open Sans 700 in sentence case, not the mono H1/H2. */
.rk-prose :is(h1, h2, h3, h4, h5, h6) {
	font-family: var(--wp--preset--font-family--body);
	font-weight: 700;
	text-transform: none;
}

.rk-prose h1 {
	font-size: var(--wp--preset--font-size--3-xl);
	line-height: 1.4;
}

.rk-prose h2 {
	font-size: var(--wp--preset--font-size--2-xl);
	line-height: 1.2;
}

.rk-prose h3 {
	font-size: var(--wp--preset--font-size--xl);
	line-height: 1.333;
}

.rk-prose > :is(h2, h3, h4) {
	margin-block-start: var(--wp--preset--spacing--60);
}

/* Policy: every section starts with an H3 24/32 (mobile 20/28), 64 apart (mobile 48);
   24 to its text comes from the flow gap (Figma 395:3271, 1032:9431). */
.rk-prose--policy > h3:not(:first-child) {
	margin-block-start: calc(2 * var(--wp--preset--spacing--60));
}

/* Article rhythm (Figma 857:7121 / 465:1628, mobile 1029:8446): H3 20/28, 40 above an H2,
   24 above an H3, 12 from an H3 to its text. The policy keeps H3 24/32. */
.rk-article .rk-prose h3 {
	font-size: var(--wp--preset--font-size--lg);
	line-height: 1.4;
}

.rk-article .rk-prose > h2:not(:first-child) {
	margin-block-start: calc(var(--wp--preset--spacing--60) + var(--wp--preset--spacing--20));
}

.rk-article .rk-prose > h3:not(:first-child) {
	margin-block-start: var(--wp--preset--spacing--50);
}

.rk-article .rk-prose > h3 + * {
	margin-block-start: var(--wp--preset--spacing--30);
}

@media (max-width: 767px) {
	.rk-prose--policy > h3 {
		line-height: 1.4;
	}

	.rk-prose--policy > h3:not(:first-child) {
		margin-block-start: calc(var(--wp--preset--spacing--60) + var(--wp--preset--spacing--40));
	}

	/* Mobile article: body 16/24, H2 20/28, H3 16/24 (Figma 1029:8446, 1029:8614). */
	.rk-article .rk-prose {
		line-height: 1.5;
	}

	.rk-article .rk-prose h2 {
		font-size: var(--wp--preset--font-size--xl);
		line-height: 1.4;
	}

	.rk-article .rk-prose h3 {
		font-size: var(--wp--preset--font-size--h-6);
		line-height: 1.5;
	}
}

.rk-prose a {
	color: inherit;
	text-decoration: underline;
	text-underline-offset: 0.15em;
}

.rk-prose a:hover {
	color: var(--wp--preset--color--primary);
}

.rk-prose :is(ul, ol) {
	padding-inline-start: 1.5em;
}

.rk-prose :is(.wp-block-image img, .wp-block-embed iframe) {
	border-radius: var(--wp--custom--radius--media);
}

/* Tables (the imported cookie tables, D60; not in Figma): light rules, text from the top. */
.rk-prose .wp-block-table :is(thead, th, td) {
	border-color: var(--wp--preset--color--border);
}

.rk-prose .wp-block-table :is(th, td) {
	vertical-align: top;
}

/* Mobile: the table keeps the 756 px prose width and scrolls sideways in its figure, so the
   text column stays readable; long ids in the first column (cookie names) may break anywhere,
   so one long id does not widen the whole column. */
@media (max-width: 767px) {
	.rk-prose .wp-block-table table {
		min-inline-size: var(--wp--custom--layout--prose);
		font-size: var(--wp--preset--font-size--sm);
	}

	.rk-prose .wp-block-table td:first-child {
		overflow-wrap: anywhere;
	}
}

/* Article: text column 756 + side card 336 (Figma 391:2686). */
.rk-article {
	display: grid;
	gap: var(--wp--preset--spacing--70);
	align-items: start;
	width: min(var(--wp--style--global--content-size), 100% - 2 * var(--wp--style--root--padding-left));
	margin-inline: auto;
	/* 56 above the body; 80 (mobile 72) from the body to "Jus gali sudominti" (Figma 391:2686). */
	padding-block: var(--wp--preset--spacing--70) var(--wp--preset--spacing--80);
}

/* Mobile: 32 from the photo to the body or story card, 32 between them (Figma 1029:8433). */
@media (max-width: 767px) {
	.rk-article {
		padding-block-start: var(--wp--preset--spacing--60);
		gap: var(--wp--preset--spacing--60);
	}
}

/* body prefix: the group is .is-layout-flow, and global styles (printed after this file)
   give every child but the first a 24px top margin at the same 0-1-0 specificity. */
body .rk-article > * {
	margin-block: 0;
}

.rk-article > .rk-prose {
	width: auto;
	margin-inline: 0;
}

@media (min-width: 1200px) {
	.rk-article {
		grid-template-columns: minmax(0, var(--wp--custom--layout--prose)) var(--wp--custom--layout--aside);
		justify-content: space-between;
	}
}

/*
 * page-simple: title and text in the 1000 px policy column (Figma 395:3271, mobile 1032:9430).
 * 64 below the header (mobile 24), 80 / 72 at the bottom. Background "Rectangle 69"
 * (395:3321 / 1032:9450): white fading to surface-2 over the first 1200 px (mobile 2400;
 * Figma measures, not tokens), then flat surface-2 down to the footer.
 */
.rk-page--simple {
	padding-block: calc(2 * var(--wp--preset--spacing--60)) var(--wp--preset--spacing--80);
	background:
		var(--wp--preset--gradient--section-fade) 0 0 / 100% 1200px no-repeat,
		var(--wp--preset--color--surface-2);
}

.rk-page--simple > * {
	width: min(var(--wp--custom--layout--policy), 100% - 2 * var(--wp--style--root--padding-left));
	margin-inline: auto;
}

/* Title: the mono H1 (36/50, 800, uppercase via theme.json), centred, in cyan braces like
   rekos_heading(); 64 to the text (mobile 30/42 on two lines, 48). The braces are CSS so the
   page title, <title> and breadcrumbs stay plain; "" alt text keeps them out of screen readers. */
/* Mobile frame 1032:9430 has the title left-aligned; desktop 395:3270 centres it. */
.rk-page--simple .rk-page__title {
	margin-block-end: calc(2 * var(--wp--preset--spacing--60));
	text-align: start;
}

@media (min-width: 768px) {
	.rk-page--simple .rk-page__title {
		text-align: center;
	}
}

.rk-page--simple .rk-page__title::before,
.rk-page--simple .rk-page__title::after {
	color: var(--wp--preset--color--accent);
}

.rk-page--simple .rk-page__title::before {
	content: "{";
	content: "{" / "";
}

.rk-page--simple .rk-page__title::after {
	content: "}";
	content: "}" / "";
}

@media (max-width: 767px) {
	.rk-page--simple {
		padding-block-start: var(--wp--preset--spacing--50);
		background-size: 100% 2400px;
	}

	.rk-page--simple .rk-page__title {
		margin-block-end: calc(var(--wp--preset--spacing--60) + var(--wp--preset--spacing--40));
	}
}

/* ---------- Heading spans (rekos_heading()) ---------- */

.rk-brace {
	color: var(--wp--preset--color--accent);
}

.rk-punct {
	color: var(--wp--preset--color--accent-2);
}

/* ---------- Buttons ---------- */

/*
 * .rk-btn            navy pill (Figma 172:4347)
 * .rk-btn--ring      primary CTA: pill inside a 1px Edrana-gradient ring, 4px gap (1198:6230)
 * .rk-btn--outline   1px navy outline, transparent (408:4501)
 * .rk-btn--block     full width
 * Core Button blocks look like .rk-btn.rk-btn--ring. Hover/focus states are derived (not in Figma).
 * Selectors are 0-1-1 or more, so they beat the 0-1-0 theme.json link/button styles
 * whatever the stylesheet order.
 */
:is(a, button).rk-btn,
.wp-block-button .wp-block-button__link {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: var(--wp--preset--spacing--20);
	min-height: var(--wp--custom--button--height-mobile);
	padding: 0 var(--wp--preset--spacing--60);
	border: 1px solid var(--wp--preset--color--contrast);
	border-radius: var(--wp--custom--radius--pill);
	background: var(--wp--preset--color--contrast);
	color: var(--wp--preset--color--base);
	font-family: var(--wp--preset--font-family--mono);
	font-size: var(--wp--custom--typography--button-size);
	font-weight: 700;
	line-height: 1.4;
	text-align: center;
	text-decoration: none;
	text-transform: uppercase;
	cursor: pointer;
	transition:
		background-color var(--wp--custom--motion--duration) var(--wp--custom--motion--ease),
		border-color var(--wp--custom--motion--duration) var(--wp--custom--motion--ease),
		color var(--wp--custom--motion--duration) var(--wp--custom--motion--ease);
}

@media (min-width: 768px) {
	:is(a, button).rk-btn,
	.wp-block-button .wp-block-button__link {
		min-height: var(--wp--custom--button--height);
	}
}

:is(a, button).rk-btn:hover,
.wp-block-button .wp-block-button__link:hover {
	border-color: var(--wp--preset--color--primary);
	background: var(--wp--preset--color--primary);
	color: var(--wp--preset--color--base);
}

:is(a, button).rk-btn--outline {
	background: transparent;
	color: var(--wp--preset--color--contrast);
}

:is(a, button).rk-btn--outline:hover {
	border-color: var(--wp--preset--color--contrast);
	background: var(--wp--preset--color--contrast);
	color: var(--wp--preset--color--base);
}

:is(a, button).rk-btn--block {
	display: flex;
	width: 100%;
}

.rk-btn--ring,
.wp-block-button .wp-block-button__link {
	position: relative;
	margin: calc(var(--wp--custom--button--ring-gap) + var(--wp--custom--button--ring-width));
}

.rk-btn--ring::before,
.wp-block-button .wp-block-button__link::before {
	content: "";
	position: absolute;
	inset: calc(-1 * (var(--wp--custom--button--ring-gap) + var(--wp--custom--button--ring-width) + 1px));
	padding: var(--wp--custom--button--ring-width);
	border-radius: var(--wp--custom--radius--pill);
	background: var(--wp--preset--gradient--edrana);
	-webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
	-webkit-mask-composite: xor;
	mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
	mask-composite: exclude;
	pointer-events: none;
}

.rk-btn--ring:focus-visible,
.wp-block-button .wp-block-button__link:focus-visible {
	outline-offset: calc(var(--wp--custom--button--ring-gap) + var(--wp--custom--button--ring-width) + 2px);
}

/* ---------- Icons (rekos_icon()) ---------- */

.rk-icon {
	display: inline-block;
	flex: none;
	inline-size: 1em;
	block-size: 1em;
	background: currentColor;
	-webkit-mask: var(--rk-icon) center / contain no-repeat;
	mask: var(--rk-icon) center / contain no-repeat;
}

.rk-icon--brand {
	background: var(--wp--preset--gradient--edrana);
}

/* ---------- Motion (assets/js/motion.js) ---------- */

/*
 * Scroll reveals: opt-in and reversible (architecture § Motion).
 * - Every hidden start state below needs html.has-motion, which head.js adds only without
 *   prefers-reduced-motion. Without JavaScript or with reduced motion nothing here applies
 *   and every element shows its final state. Screen only: print shows everything.
 * - Markup: [data-rk-reveal] ("up" default, "fade"); [data-rk-reveal-stagger] ("fade" optional)
 *   reveals its direct children in turn (a nested stagger parent passes its children on).
 * - Before motion.js runs, the start state is an animation that holds 2 s and then shows the
 *   element anyway (safety if the script fails or comes late). motion.js then sets
 *   html.rk-motion-ready, .rk-reveal on each element it watches, .is-visible when it scrolls
 *   in and .is-revealed when its animation is over (from then on nothing here applies).
 * - Count-ups ([data-rk-countup]) are held at opacity 0 until motion.js sets html.rk-countup-ready
 *   (at most 600 ms, then the final number fades in and is not counted).
 * - Only opacity and translate change: no layout shift, and the text is always in the DOM.
 *   The element's own opacity / translate is the end value (e.g. a 30 % outline stays 30 %).
 * Calm brand motion: 600 ms ease-out, 16 px (mobile) / 24 px rise, each element once.
 */
:root {
	--rk-reveal-duration: 600ms;
	--rk-reveal-distance: var(--wp--preset--spacing--40);
	--rk-reveal-ease: var(--wp--custom--motion--ease);
}

@media (min-width: 768px) {
	:root {
		--rk-reveal-distance: var(--wp--preset--spacing--50);
	}
}

@media screen and (prefers-reduced-motion: no-preference) {
	html.has-motion :is([data-rk-reveal], [data-rk-reveal-stagger] > :not([data-rk-reveal-stagger])) {
		--rk-reveal-y: var(--rk-reveal-distance);
	}

	html.has-motion :is([data-rk-reveal="fade"], [data-rk-reveal-stagger="fade"] > :not([data-rk-reveal])) {
		--rk-reveal-y: 0px;
	}

	/* Safety before motion.js: hidden for 2 s, then shown (by the end of the 2.6 s animation). */
	html.has-motion:not(.rk-motion-ready) :is([data-rk-reveal], [data-rk-reveal-stagger] > :not([data-rk-reveal-stagger])) {
		animation: rk-reveal-failsafe 2600ms var(--rk-reveal-ease);
	}

	html.has-motion.rk-motion-ready .rk-reveal:not(.is-visible) {
		opacity: 0;
		translate: 0 var(--rk-reveal-y, 0px);
	}

	html.has-motion.rk-motion-ready .rk-reveal.is-visible:not(.is-revealed) {
		animation: rk-reveal-in var(--rk-reveal-duration) var(--rk-reveal-ease) var(--rk-reveal-delay, 0ms) backwards;
	}

	/* Count-ups wait for motion.js (which shows 0 and counts), so the first paint never shows the
	   final number and then 0. Safety: after 600 ms the final number fades in anyway and stays. */
	html.has-motion:not(.rk-countup-ready) [data-rk-countup] {
		animation: rk-countup-failsafe 900ms var(--rk-reveal-ease);
	}
}

/* No 100 % keyframe: both animations end on the element's own values. */
@keyframes rk-reveal-failsafe {
	0%,
	77% {
		opacity: 0;
		translate: 0 var(--rk-reveal-y, 0px);
	}
}

@keyframes rk-reveal-in {
	from {
		opacity: 0;
		translate: 0 var(--rk-reveal-y, 0px);
	}
}

@keyframes rk-countup-failsafe {
	0%,
	66% {
		opacity: 0;
	}
}

/* Count-up ([data-rk-countup]): while it counts, the final text is a visually hidden copy and
   the counting copy is aria-hidden; on paper only the final text shows. */
@media print {
	.rk-countup__live {
		display: none;
	}

	.rk-countup__final.rk-visually-hidden {
		position: static !important;
		width: auto;
		height: auto;
		overflow: visible;
		clip-path: none;
		white-space: inherit;
	}
}
