/**
 * MF Suite — Group decoration.
 *
 * Two layers on a group's own pseudo-elements: *Licht* paints `::before`, *Muster* paints
 * `::after` (D4). Both lie between the group's background — core's colour, gradient or
 * image, untouched (D5) — and its content. The server writes the classes and the custom
 * properties from the `mfDeco` attribute (`Mf_Deco_Attributes`); nothing here is in the
 * saved markup.
 *
 * Four rules in here are load-bearing, not style:
 *
 * 1. **`overflow: clip`, never `hidden`.** `hidden` makes the group a scroll container, and a
 *    section in a Slide Deck would become its own `view()` timeline and freeze every drift
 *    (docs/modules/slide-sections.md).
 * 2. **No `position: relative` on a sticky or fixed group.** Core's position support makes a
 *    group sticky with `.is-position-sticky`, and a sticky element already contains its
 *    absolutely positioned pseudo-elements — overriding it would unstick the group.
 * 3. **A layer the author did not pick gets no `content`.** A group with only a pattern keeps
 *    `::before` free for whatever else wants it.
 * 4. **No `container-type` on the group** (spec §6.4): inline-size containment makes a group
 *    sized by its content collapse. Narrow variants use the viewport instead.
 *
 * Every colour is `color-mix()` into `transparent`, scaled by `--k`, the layer's strength.
 * `--k` is set on the pseudo-element itself, so each layer has its own (D13).
 *
 * Catalogue: divb-hq/design/group-decoration.html · Spec: docs/SPEC-group-decoration.md
 */

/* ── 1. The site's colours: a fallback any theme or Additional CSS overrides (D12) ─────── */

:where(:root) {
	--mf-deco-a: #1d4f99;
	--mf-deco-b: #e35205;
	--mf-deco-scrim: #0a0a0c;
}

/*
 * Kapitelziffer counts through the whole article (D14). The nearest reset wins, and nothing
 * below the post content resets it — a reset on a group, a column or a deck is exactly the
 * restart that was ruled out. `:where()` so a theme's own `counter-reset` on these elements
 * is not clobbered.
 */
:where(html, .wp-block-post-content, .entry-content) {
	counter-reset: mf-deco;
}

/* ── 2. The base ───────────────────────────────────────────────────────────────────────── */

.mf-deco {
	isolation: isolate;
	overflow: clip;
}

.mf-deco:not(.is-position-sticky, .is-position-fixed) {
	position: relative;
}

.mf-deco--light::before,
.mf-deco--pattern::after {
	content: "";
	position: absolute;
	inset: 0;
	z-index: -1;
	pointer-events: none;
	--k: 1;
}

.mf-deco--light-low::before {
	--k: 0.45;
}

.mf-deco--light-high::before {
	--k: 1.6;
}

.mf-deco--pattern-low::after {
	--k: 0.45;
}

.mf-deco--pattern-high::after {
	--k: 1.6;
}

/* ── 3. Licht, on ::before ─────────────────────────────────────────────────────────────── */

/*
 * Each form names its colour stops as custom properties on the pseudo-element (`--c1`, …)
 * and its centre as `--at`, so a gradient fits on one line. `--k` is read where they are
 * declared — on the same pseudo-element — so the layer's strength reaches every stop.
 */

/* Orb pair (K01). The second orb mirrors the first, so a moved pair stays a pair. */
.mf-deco--orbs::before {
	--c1: color-mix(in srgb, var(--mf-deco-a) calc(35% * var(--k)), transparent);
	--c2: color-mix(in srgb, var(--mf-deco-a) calc(12% * var(--k)), transparent);
	--c3: color-mix(in srgb, var(--mf-deco-a) calc(20% * var(--k)), transparent);
	--c4: color-mix(in srgb, var(--mf-deco-a) calc(6% * var(--k)), transparent);
	--at: var(--mf-deco-lx, 88%) var(--mf-deco-ly, 8%);
	--at2: calc(100% - var(--mf-deco-lx, 94%)) calc(100% - var(--mf-deco-ly, 4%));
	background:
		radial-gradient(48% 75% at var(--at), var(--c1) 0%, var(--c2) 40%, transparent 70%),
		radial-gradient(38% 60% at var(--at2), var(--c3) 0%, var(--c4) 50%, transparent 70%);
}

/* Centred oval (K04). */
.mf-deco--oval::before {
	--c1: color-mix(in srgb, var(--mf-deco-a) calc(22% * var(--k)), transparent);
	--c2: color-mix(in srgb, var(--mf-deco-a) calc(8% * var(--k)), transparent);
	--at: var(--mf-deco-lx, 50%) var(--mf-deco-ly, 55%);
	background: radial-gradient(55% 60% at var(--at), var(--c1) 0%, var(--c2) 35%, transparent 62%);
}

/* Single orb (K05). */
.mf-deco--orb::before {
	--c1: color-mix(in srgb, var(--mf-deco-a) calc(18% * var(--k)), transparent);
	--at: var(--mf-deco-lx, 18%) var(--mf-deco-ly, 35%);
	background: radial-gradient(45% 70% at var(--at), var(--c1) 0%, transparent 60%);
}

/* Edge light (K07): a hairline along the top and the glow under it. */
.mf-deco--edge::before {
	--c1: color-mix(in srgb, var(--mf-deco-a) calc(70% * var(--k)), transparent);
	--c2: color-mix(in srgb, var(--mf-deco-a) calc(26% * var(--k)), transparent);
	background:
		linear-gradient(90deg, transparent 10%, var(--c1) 50%, transparent 90%) 0 0 / 100% 1px no-repeat,
		radial-gradient(45% 160px at 50% 0, var(--c2), transparent 100%);
}

/* Two tones (K08). */
.mf-deco--duo::before {
	--c1: color-mix(in srgb, var(--mf-deco-a) calc(28% * var(--k)), transparent);
	--c2: color-mix(in srgb, var(--mf-deco-b) calc(22% * var(--k)), transparent);
	background:
		radial-gradient(45% 70% at 10% 12%, var(--c1), transparent 70%),
		radial-gradient(45% 70% at 92% 90%, var(--c2), transparent 70%);
}

/* Light cone (K12). */
.mf-deco--cone::before {
	--c1: color-mix(in srgb, var(--mf-deco-a) calc(22% * var(--k)), transparent);
	--from: from 155deg at 50% -8%;
	background: conic-gradient(var(--from), transparent 0deg, var(--c1) 25deg, transparent 50deg);
	mask: linear-gradient(#000 30%, transparent 95%);
}

/* Horizon (K25): light rising from the lower edge. */
.mf-deco--horizon::before {
	--c1: color-mix(in srgb, var(--mf-deco-a) calc(32% * var(--k)), transparent);
	--c2: color-mix(in srgb, var(--mf-deco-a) calc(10% * var(--k)), transparent);
	--at: var(--mf-deco-lx, 50%) var(--mf-deco-ly, 100%);
	background: radial-gradient(70% 55% at var(--at), var(--c1) 0%, var(--c2) 45%, transparent 75%);
}

/* Raking light (K26): one soft diagonal band. */
.mf-deco--rake::before {
	--c1: color-mix(in srgb, var(--mf-deco-a) calc(16% * var(--k)), transparent);
	background: linear-gradient(115deg, transparent 35%, var(--c1) 50%, transparent 65%);
}

/* Glowing frame (K31): light along every edge. */
.mf-deco--frameglow::before {
	--c1: color-mix(in srgb, var(--mf-deco-a) calc(40% * var(--k)), transparent);
	--c2: color-mix(in srgb, var(--mf-deco-a) calc(22% * var(--k)), transparent);
	box-shadow: inset 0 0 0 1px var(--c1), inset 0 0 90px var(--c2);
}

/* Aurora (K32): three stretched lights along the top, in both colours. */
.mf-deco--aurora::before {
	--c1: color-mix(in srgb, var(--mf-deco-a) calc(30% * var(--k)), transparent);
	--c2: color-mix(in srgb, var(--mf-deco-b) calc(24% * var(--k)), transparent);
	--c3: color-mix(in srgb, var(--mf-deco-a) calc(22% * var(--k)), transparent);
	background:
		radial-gradient(40% 30% at 18% 0, var(--c1), transparent 70%),
		radial-gradient(35% 26% at 55% 4%, var(--c2), transparent 70%),
		radial-gradient(32% 30% at 88% 0, var(--c3), transparent 70%);
}

/* Side band (K35): a broad soft band on the right. */
.mf-deco--band::before {
	--c1: color-mix(in srgb, var(--mf-deco-a) calc(14% * var(--k)), transparent);
	--c2: color-mix(in srgb, var(--mf-deco-a) calc(6% * var(--k)), transparent);
	background: linear-gradient(90deg, transparent 58%, var(--c1) 82%, var(--c2) 100%);
}

/*
 * Veil over an image (K15). Deliberately outside `--k`: a strength setting must not be able
 * to weaken a legibility measure. Dense across the text column, open only beyond it; flat on
 * a narrow screen, where text runs wide.
 */
.mf-deco--scrim::before {
	--c1: color-mix(in srgb, var(--mf-deco-scrim) 88%, transparent);
	--c2: color-mix(in srgb, var(--mf-deco-scrim) 82%, transparent);
	--c3: color-mix(in srgb, var(--mf-deco-scrim) 25%, transparent);
	background: linear-gradient(90deg, var(--c1) 0%, var(--c2) 65%, var(--c3) 100%);
}

/* ── 4. Muster, on ::after ─────────────────────────────────────────────────────────────── */

/*
 * The pattern colour (divb-hq#354) is `--mf-deco-p`, written on the group only when one is
 * picked. Without it each form keeps the colour it was drawn in: `--ink` is the text colour,
 * so one rule serves dark and light grounds; `--ink-glow` is the light colour.
 *
 * Reset on every pattern group, so a nested one never takes its parent's pattern colour; the
 * group's own picked colour is inline and wins over this rule.
 */
.mf-deco--pattern {
	--mf-deco-p: initial;
}

.mf-deco--pattern::after {
	--ink: var(--mf-deco-p, currentcolor);
	--ink-glow: var(--mf-deco-p, var(--mf-deco-a));
}

/* Dot grid (K02). */
.mf-deco--dots::after {
	--c1: color-mix(in srgb, var(--ink) calc(12% * var(--k)), transparent);
	background: radial-gradient(var(--c1) 1px, transparent 1.5px) 0 0 / 28px 28px;
	mask: radial-gradient(80% 70% at 50% 40%, #000 20%, transparent 75%);
}

/* Noise (K03), as live on mayflower.de: fractal noise, 2.5 % at the default strength. */
.mf-deco--noise::after {
	opacity: calc(0.025 * var(--k));
	/* stylelint-disable-next-line max-line-length, function-url-quotes */
	background: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E") 0 0 / 256px 256px;
}

/* Blueprint (K09). */
.mf-deco--grid::after {
	--c1: color-mix(in srgb, var(--ink) calc(12% * var(--k)), transparent);
	background:
		linear-gradient(var(--c1) 1px, transparent 1px) 0 0 / 40px 40px,
		linear-gradient(90deg, var(--c1) 1px, transparent 1px) 0 0 / 40px 40px;
	mask: radial-gradient(70% 90% at 85% 30%, #000 10%, transparent 70%);
}

/* Rings (K10). */
.mf-deco--rings::after {
	--c1: color-mix(in srgb, var(--ink) calc(13% * var(--k)), transparent);
	background: repeating-radial-gradient(circle at 100% 0, transparent 0 46px, var(--c1) 46px 47px);
	mask: radial-gradient(60% 90% at 100% 0, #000 30%, transparent 80%);
}

/* Hatching (K11). */
.mf-deco--hatch::after {
	--c1: color-mix(in srgb, var(--ink-glow) calc(30% * var(--k)), transparent);
	background: repeating-linear-gradient(135deg, var(--c1) 0 1px, transparent 1px 11px);
	mask: linear-gradient(90deg, transparent 55%, #000 100%);
}

/* Crop marks (K27): four corners, 20px in. Strength fades them, never past solid. */
.mf-deco--marks::after {
	--c: var(--ink-glow);
	--h: linear-gradient(var(--c), var(--c));
	inset: 20px;
	background:
		var(--h) 0 0 / 24px 2px no-repeat,
		var(--h) 0 0 / 2px 24px no-repeat,
		var(--h) 100% 0 / 24px 2px no-repeat,
		var(--h) 100% 0 / 2px 24px no-repeat,
		var(--h) 0 100% / 24px 2px no-repeat,
		var(--h) 0 100% / 2px 24px no-repeat,
		var(--h) 100% 100% / 24px 2px no-repeat,
		var(--h) 100% 100% / 2px 24px no-repeat;
	opacity: min(1, var(--k));
}

/* Halftone fade (K30): dots that thin out towards the text. */
.mf-deco--halftone::after {
	--c1: color-mix(in srgb, var(--ink) calc(30% * var(--k)), transparent);
	background: radial-gradient(var(--c1) 1.6px, transparent 2.2px) 0 0 / 14px 14px;
	mask: linear-gradient(90deg, transparent 50%, #000 100%);
}

/* Cross grid (K34): plus signs at every intersection, fading out. */
.mf-deco--crosses::after {
	--fade: radial-gradient(70% 90% at 85% 40%, #000 15%, transparent 70%);
	background: color-mix(in srgb, var(--ink) calc(28% * var(--k)), transparent);
	/* stylelint-disable-next-line max-line-length, function-url-quotes */
	mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='48' height='48'%3E%3Cpath d='M24 19v11M18.5 24.5h11' stroke='%23000' stroke-width='1.5'/%3E%3C/svg%3E") 0 0 / 48px 48px, var(--fade);
	mask-composite: intersect;
}

/*
 * Chapter numeral (K13): counts the groups that carry it, through the whole article (D14).
 * The digits are decoration, so they are not read aloud: the `/ ""` alternative text. A
 * browser that does not know that form discards the whole declaration and keeps the first.
 */
.mf-deco--numeral {
	counter-increment: mf-deco;
}

/* stylelint-disable declaration-block-no-duplicate-properties */
.mf-deco--numeral::after {
	content: counter(mf-deco, decimal-leading-zero);
	content: counter(mf-deco, decimal-leading-zero) / "";
	inset: auto 3% -0.18em auto;
	font-family: inherit;
	font-size: clamp(120px, 24vw, 320px);
	font-weight: 700;
	line-height: 1;
	letter-spacing: -0.06em;
	color: color-mix(in srgb, var(--ink) calc(7% * var(--k)), transparent);
}

/* Quote mark (K28): a large opening quote behind the start of the text. Not read aloud. */
.mf-deco--quote::after {
	--left: max(4px, calc((100% - var(--wp--style--global--content-size, 1120px)) / 2 + 4px));
	content: "\201C";
	content: "\201C" / "";
	inset: -0.06em auto auto var(--left);
	font-family: Georgia, "Times New Roman", serif;
	font-size: clamp(140px, 20vw, 260px);
	font-weight: 400;
	line-height: 1;
	color: color-mix(in srgb, var(--ink-glow) calc(18% * var(--k)), transparent);
}
/* stylelint-enable declaration-block-no-duplicate-properties */

/* Margin rule (K14): a 2px rule beside the content column, fading out downwards. */
.mf-deco--rule::after {
	--left: max(16px, calc((100% - var(--wp--style--global--content-size, 1120px)) / 2 + 16px));
	--c1: color-mix(in srgb, var(--ink-glow) calc(100% * min(1, var(--k))), transparent);
	inset: 48px auto 48px var(--left);
	width: 2px;
	background: linear-gradient(var(--c1), transparent);
}

/* Arc (K29): one thin circle, partly off the edge. Its centre is the Muster position. */
.mf-deco--ring::after {
	--c1: color-mix(in srgb, var(--ink-glow) calc(55% * var(--k)), transparent);
	--at: var(--mf-deco-px, 86%) var(--mf-deco-py, 30%);
	--line: transparent 0 219px, var(--c1) 219.5px 221px, transparent 221.5px;
	background: radial-gradient(circle at var(--at), var(--line));
}

/* ── 5. Narrow screens (§6.4) ──────────────────────────────────────────────────────────── */

@media (max-width: 640px) {

	.mf-deco--scrim::before {
		background: color-mix(in srgb, var(--mf-deco-scrim) 86%, transparent);
	}

	.mf-deco--hatch::after {
		mask: linear-gradient(90deg, transparent 80%, #000 100%);
	}
}

/* ── 6. Motion (§8): one transform on the light, only when asked for ───────────────────── */

.mf-deco--drift::before {
	animation: mf-deco-drift 22s ease-in-out infinite;
}

@keyframes mf-deco-drift {

	0%,
	100% {
		transform: translate(0, 0) scale(1);
	}

	33% {
		transform: translate(3%, -2%) scale(1.04);
	}

	66% {
		transform: translate(-2%, 1.5%) scale(0.98);
	}
}

@media (prefers-reduced-motion: reduce) {

	.mf-deco--drift::before {
		animation: none;
	}
}
