/*
 * rekos/values-diagram (Figma Apie mus 496:2461 desktop 1440 × 803, 1028:4895 mobile 375 × 988).
 * Tokens only. The literal px values are the Figma geometry of this one diagram (canvas, card
 * width, circle), declared once as --rk-vd-* at the top; positions are Figma px / canvas px.
 *
 * Desktop "radial" (≥1024; the Figma frame at 1440): padding 80; a centred 889 × 643 canvas
 *   (Figma group 857:7513). Edrana-gradient circle 240 (857:7511) at 307, 202 with the H2
 *   (JetBrains Mono 800 36/1.4, white, uppercase). Five white cards 266 wide (radius 30 → card
 *   token 32, padding 16, gap 12): icon 28 (gradient) + title Open Sans 700 18/28, 12 apart;
 *   a 1px dashed rule (2 on / 2 off, border colour); text 16/24. Card places (x, y):
 *   1 (0, 90), 2 (471, 0), 3 (623, 243), 4 (21, 414), 5 (498, 483). Five connector lines
 *   (857:7466–857:7470): 1 px, Edrana gradient at 30 % opacity, elbow corners radius 30 (→ 32),
 *   running from under each card to under the circle.
 * Mobile (≤767): padding 72 / 16; a 266 wide column, centred: gradient bar 48 high (radius 20,
 *   24/1.4 label), then the cards 16 apart (radius 20, text 14/20). No lines.
 * Tablet (768–1023, derived) and the "grid" layout: the bar above the cards, cards in 2 columns
 *   (3 from 1024 in "grid"), 24 apart, an odd last card centred; desktop type sizes.
 * Background (both frames): white → surface-2 at 56 %, then flat (Figma: #E9F4FD 0 → 90 %).
 */

.rk-values-diagram {
	--rk-vd-canvas-w: 889px;
	--rk-vd-canvas-h: 643px;
	--rk-vd-card-w: 266px;
	--rk-vd-circle: 240px;
	--rk-vd-bar-h: 48px;
	--rk-vd-gap: var(--wp--preset--spacing--40);
	--rk-vd-ball: 1px; /* Light dot (view.js): as thick as a line (desktop: set from the line). */
	--rk-vd-ball-glow: 3px; /* Its faint, tight glow (blurred 0.75 in view.js). */

	padding-block: var(--wp--preset--spacing--80);
	background: linear-gradient(180deg, var(--wp--preset--color--base) 0%, var(--wp--preset--color--surface-2) 56%);
	color: var(--wp--preset--color--contrast);
}

.rk-values-diagram__diagram {
	display: flex;
	flex-direction: column;
	gap: var(--rk-vd-gap);
	width: min(100%, var(--rk-vd-card-w));
	margin-inline: auto;
}

/* ---------- Centre label (H2): bar on phones and tablets, circle in the radial layout ---------- */

/* .rk-values-diagram prefix: beats the theme.json h2 element styles whatever the order. */
.rk-values-diagram .rk-values-diagram__center {
	display: flex;
	align-items: center;
	justify-content: center;
	min-height: var(--rk-vd-bar-h);
	margin: 0;
	padding: 0 var(--wp--preset--spacing--40);
	border-radius: var(--wp--custom--radius--media);
	background: var(--wp--preset--gradient--edrana);
	color: var(--wp--preset--color--base);
	font-family: var(--wp--preset--font-family--mono);
	font-size: var(--wp--preset--font-size--2-xl);
	font-weight: 800;
	line-height: 1.4;
	text-align: center;
	text-transform: uppercase;
	overflow-wrap: anywhere;
}

/* Connector lines exist only in the radial layout (≥1024, below). */
.rk-values-diagram__lines {
	display: none;
}

/* Brace and punctuation colours would vanish on the gradient: keep them white. */
.rk-values-diagram__center :is(.rk-brace, .rk-punct) {
	color: inherit;
}

/* ---------- Cards ---------- */

.rk-values-diagram__items {
	display: grid;
	gap: var(--rk-vd-gap);
	margin: 0;
	padding: 0;
	list-style: none;
}

/* position: relative holds the outline (::after, below) and, below 1024, the light dot's loop
   (view.js, .rk-values-diagram__ball); the radial layout places the cards absolutely instead. */
.rk-values-diagram__item {
	position: relative;
	display: flex;
	flex-direction: column;
	gap: var(--wp--preset--spacing--30);
	min-width: 0;
	padding: var(--wp--preset--spacing--40);
	border-radius: var(--wp--custom--radius--media);
	background: var(--wp--preset--color--base);
}

/*
 * Outline ("gijos apvadas", designer 2026-10-07, part of the static design): a ring as thick as
 * the connector lines (1 px) in the Edrana gradient, the look of the small card's stroke in the
 * solution heroes (blocks/hero-split .rk-hero-split__ui-ring): the border area of a masked box
 * (the .rk-btn--ring technique), so it changes no layout. Decorative, no pointer events. In the
 * motion it is dim (20 %) until the light dot goes round the card and brightens it (below).
 */
.rk-values-diagram__item::after {
	content: "";
	position: absolute;
	inset: 0;
	padding: 1px;
	border-radius: inherit;
	background: var(--wp--preset--gradient--edrana);
	pointer-events: none;
	-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;
}

.rk-values-diagram__item-head {
	display: flex;
	align-items: flex-start;
	gap: var(--wp--preset--spacing--30);
}

/* 28 px icon in the Edrana gradient (rekos_icon() + .rk-icon--brand). */
.rk-values-diagram .rk-values-diagram__icon {
	font-size: 28px;
}

.rk-values-diagram .rk-values-diagram__item-title {
	flex: 1 1 auto;
	min-width: 0;
	margin: 0;
	color: inherit;
	font-family: var(--wp--preset--font-family--body);
	font-size: var(--wp--preset--font-size--lg);
	font-weight: 700;
	line-height: calc(28 / 18);
	overflow-wrap: break-word;
}

/* Figma "Vector 11": a 1 px dashed rule, 2 px dashes 2 px apart; a 0-height line in Figma,
   so it takes no layout height here either (the -1px margin). */
.rk-values-diagram__rule {
	display: block;
	flex: none;
	height: 1px;
	margin-block-end: -1px;
	background: repeating-linear-gradient(90deg, var(--wp--preset--color--border) 0 2px, transparent 2px 4px);
}

.rk-values-diagram .rk-values-diagram__item-text {
	margin: 0;
	font-size: var(--wp--preset--font-size--base);
	line-height: calc(20 / 14);
	overflow-wrap: break-word;
}

/* ---------- Tablet (derived) and the grid layout ---------- */

@media (min-width: 768px) {
	.rk-values-diagram {
		--rk-vd-gap: var(--wp--preset--spacing--50);
	}

	.rk-values-diagram__diagram {
		width: min(100%, var(--rk-vd-canvas-w));
	}

	.rk-values-diagram .rk-values-diagram__center {
		align-self: center;
		width: calc((100% - var(--rk-vd-gap)) / 2);
		border-radius: var(--wp--custom--radius--card);
	}

	.rk-values-diagram__items {
		display: flex;
		flex-wrap: wrap;
		justify-content: center;
	}

	.rk-values-diagram__item {
		flex: 0 1 calc((100% - var(--rk-vd-gap)) / 2);
		border-radius: var(--wp--custom--radius--card);
	}

	.rk-values-diagram .rk-values-diagram__item-title {
		font-size: var(--wp--preset--font-size--md);
	}

	.rk-values-diagram .rk-values-diagram__item-text {
		line-height: 1.5;
	}
}

@media (min-width: 1024px) {
	.rk-values-diagram--grid .rk-values-diagram__center {
		width: calc((100% - 2 * var(--rk-vd-gap)) / 3);
	}

	.rk-values-diagram--grid .rk-values-diagram__item {
		flex-basis: calc((100% - 2 * var(--rk-vd-gap)) / 3);
	}
}

/* ---------- Radial layout (5 cards, ≥1024): the Figma canvas ---------- */

@media (min-width: 1024px) {
	/* 889 px fits the content width from 1024 px (≈ 924 px there). */
	.rk-values-diagram--radial .rk-values-diagram__diagram {
		position: relative;
		display: block;
		width: var(--rk-vd-canvas-w);
		max-width: 100%;
		height: var(--rk-vd-canvas-h);
	}

	/* z-index 3: above the light balls' layer (2, view.js), which is above the cards (1). The
	   circle overlaps no card, so the static picture is the same. */
	.rk-values-diagram--radial .rk-values-diagram__center {
		position: absolute;
		z-index: 3;
		top: calc(202 / 643 * 100%);
		left: calc(307 / 889 * 100%);
		width: var(--rk-vd-circle);
		height: var(--rk-vd-circle);
		min-height: 0;
		padding: var(--wp--preset--spacing--30);
		border-radius: var(--wp--custom--radius--pill);
		font-size: var(--wp--preset--font-size--3-xl);
	}

	/* The list covers the canvas; each card is placed on it. */
	.rk-values-diagram--radial .rk-values-diagram__items {
		position: absolute;
		z-index: 1;
		inset: 0;
		display: block;
		pointer-events: none;
	}

	.rk-values-diagram--radial .rk-values-diagram__item {
		position: absolute;
		width: var(--rk-vd-card-w);
		pointer-events: auto;
	}

	.rk-values-diagram--radial .rk-values-diagram__item:nth-child(1) {
		top: calc(90 / 643 * 100%);
		left: 0;
	}

	.rk-values-diagram--radial .rk-values-diagram__item:nth-child(2) {
		top: 0;
		left: calc(471 / 889 * 100%);
	}

	.rk-values-diagram--radial .rk-values-diagram__item:nth-child(3) {
		top: calc(243 / 643 * 100%);
		left: calc(623 / 889 * 100%);
	}

	.rk-values-diagram--radial .rk-values-diagram__item:nth-child(4) {
		top: calc(414 / 643 * 100%);
		left: calc(21 / 889 * 100%);
	}

	.rk-values-diagram--radial .rk-values-diagram__item:nth-child(5) {
		top: calc(483 / 643 * 100%);
		left: calc(498 / 889 * 100%);
	}

	/*
	 * Connector lines: each box is the Figma vector's box; the 1 px stroke is the padding on
	 * the stroked sides, cut out with the same mask as the button ring in base.css, so the
	 * rounded corner keeps the gradient. Both ends sit under a card or the circle.
	 */
	.rk-values-diagram--radial .rk-values-diagram__lines {
		position: absolute;
		z-index: 0;
		inset: 0;
		display: block;
		pointer-events: none;
	}

	.rk-values-diagram__line {
		position: absolute;
		display: block;
		padding: 0;
		background: var(--wp--preset--gradient--edrana);
		opacity: 0.3;
		-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;
	}

	/* 857:7467: card 1 (bottom) → circle (left). */
	.rk-values-diagram__line--1 {
		top: calc(247 / 643 * 100%);
		left: calc(133 / 889 * 100%);
		width: calc(180 / 889 * 100%);
		height: calc(69 / 643 * 100%);
		padding: 0 0 1px 1px;
		border-end-start-radius: var(--wp--custom--radius--card);
	}

	/* 857:7469: card 2 (left) → circle (top). */
	.rk-values-diagram__line--2 {
		top: calc(66 / 643 * 100%);
		left: calc(394 / 889 * 100%);
		width: calc(81 / 889 * 100%);
		height: calc(182 / 643 * 100%);
		padding: 1px 0 0 1px;
		border-start-start-radius: var(--wp--custom--radius--card);
	}

	/* 857:7470: circle (right) → card 3 (left), straight. */
	.rk-values-diagram__line--3 {
		top: calc(321 / 643 * 100%);
		left: calc(537 / 889 * 100%);
		width: calc(91 / 889 * 100%);
		height: 1px;
		padding: 1px 0 0;
	}

	/* 857:7466: circle (bottom left) → card 4 (right). */
	.rk-values-diagram__line--4 {
		top: calc(389 / 643 * 100%);
		left: calc(282 / 889 * 100%);
		width: calc(78 / 889 * 100%);
		height: calc(117 / 643 * 100%);
		padding: 0 1px 1px 0;
		border-end-end-radius: var(--wp--custom--radius--card);
	}

	/* 857:7468: circle (bottom) → card 5 (left). */
	.rk-values-diagram__line--5 {
		top: calc(441 / 643 * 100%);
		left: calc(423 / 889 * 100%);
		width: calc(80 / 889 * 100%);
		height: calc(122 / 643 * 100%);
		padding: 0 0 1px 1px;
		border-end-start-radius: var(--wp--custom--radius--card);
	}
}

/*
 * ---------- Connector sequence (radial layout, view.js) ----------
 * The circle and the cards are never hidden, moved or scaled: no start state here touches them.
 * Only the connector lines wait, and only with html.has-motion (head.js: JS and no
 * prefers-reduced-motion) on screen. view.js sets .is-armed on the diagram when it takes over,
 * .is-drawn on each line as it starts drawing it (a clip-path animation from the circle to the
 * card; all five at once) and .is-done at the end. It never removes a class, so a passed state
 * can never match again. (Version 0.2 removed .is-armed at the end, which re-started its
 * failsafe and hid the whole diagram for 2 s.) The light balls (along each line, then round each
 * card) are SVGs view.js adds for the run and removes at the end.
 * Until view.js takes over, a hold keeps the lines hidden 2 s and then shows them anyway (script
 * missing, late or failed). It runs on the diagram itself, which is always rendered, and the
 * circle and the cards opt out of it: on the lines it would re-start each time the window
 * crosses 1024 (the lines layer is display: none below). Without JS or with reduced motion none
 * of this applies: the static design. Only visibility, clip-path and the balls change: no
 * layout shift.
 */
@media screen and (prefers-reduced-motion: no-preference) {
	html.has-motion [data-rk-vd-sequence]:not(.is-armed):not(.is-done) {
		animation: rk-vd-hold 2600ms;
	}

	html.has-motion [data-rk-vd-sequence]:not(.is-armed):not(.is-done) > :not(.rk-values-diagram__lines) {
		visibility: visible;
	}

	html.has-motion [data-rk-vd-sequence].is-armed:not(.is-done) .rk-values-diagram__line:not(.is-drawn) {
		visibility: hidden;
	}

	/* Card outlines: dim until the dot goes round (view.js adds .is-traced with the timing,
	   --rk-vd-ring-at / --rk-vd-ring-ms), then brighten to their own (static) value. */
	html.has-motion [data-rk-vd-sequence].is-armed:not(.is-done) .rk-values-diagram__item:not(.is-traced)::after {
		opacity: 0.2;
	}

	html.has-motion [data-rk-vd-sequence].is-armed:not(.is-done) .rk-values-diagram__item.is-traced::after {
		animation: rk-vd-ring var(--rk-vd-ring-ms, 1750ms) ease-in-out var(--rk-vd-ring-at, 0ms) backwards;
	}
}

/* No "to" keyframe: it ends on the outline's own opacity (1). */
@keyframes rk-vd-ring {
	from {
		opacity: 0.2;
	}
}

/*
 * The light dot (view.js): a small bright point as thick as the line (1 px; view.js sets it from
 * the line's stroke on desktop), in `accent`, over a faint, tight `accent` glow (3 px, blurred
 * by 0.75, 40 % opacity), so it reads as a point travelling on the line and round the card's
 * edge. Each dot is a zero-length dash that round caps draw as a dot as wide as the stroke.
 * Desktop: one SVG over the whole diagram (above the cards, under the circle, so the dots come
 * out from behind it) with one dot per line, along the line and then once round its card's
 * edge. Below 1024: one SVG in each card, the dot once round its edge. Removed when done;
 * decorative: aria-hidden, no pointer events, so clicks and text selection go through. Never
 * in the static design.
 */
.rk-values-diagram .rk-values-diagram__ball {
	position: absolute;
	top: 0;
	left: 0;
	width: 100%;
	max-width: none;
	height: 100%;
	overflow: visible;
	pointer-events: none;
	z-index: 1; /* Inside a card: above its outline (::after). */
}

.rk-values-diagram .rk-values-diagram__ball--lines {
	z-index: 2;
}

.rk-values-diagram__ball path {
	fill: none;
	stroke-linecap: round;
}

/* The glows' group (view.js: the blurred one), faint. A fixed opacity, never animated. */
.rk-values-diagram__ball > g {
	opacity: 0.4;
}

.rk-values-diagram__ball-glow {
	stroke: var(--wp--preset--color--accent);
	stroke-width: var(--rk-vd-ball-glow);
}

.rk-values-diagram__ball-core {
	stroke: var(--wp--preset--color--accent);
	stroke-width: var(--rk-vd-ball);
}

@media (prefers-reduced-motion: reduce), print {
	.rk-values-diagram .rk-values-diagram__ball {
		display: none;
	}
}

/* No 100 % keyframe: it ends on the diagram's own value (visible), at 2 s. */
@keyframes rk-vd-hold {
	0%,
	77% {
		visibility: hidden;
	}
}

/* Windows high contrast: gradients disappear, so outline the label and the cards. */
@media (forced-colors: active) {
	.rk-values-diagram .rk-values-diagram__center,
	.rk-values-diagram__item {
		border: 1px solid CanvasText;
	}

	.rk-values-diagram__item::after {
		display: none;
	}
}

/* Editor placeholder when every field is empty. */
.rk-values-diagram__empty {
	margin: 0;
	padding: var(--wp--preset--spacing--50);
	border: 1px dashed var(--wp--preset--color--border);
	color: var(--wp--preset--color--muted);
	font-size: var(--wp--preset--font-size--sm);
}
