/**
 * The AI glow: a soft band of color behind an element, turning slowly.
 *
 * Four classes, which differ only in when the glow shows and when it turns:
 *
 * 1. `wfst-res-ai-glow` — turns once on load, then rests invisible; the
 *    pointer brings it back and keeps it turning.
 * 2. `wfst-res-ai-glow-hover` — the same without the turn on load.
 * 3. `wfst-res-ai-glow-on` — always there, always turning.
 * 4. `wfst-res-ai-glow-pause` — turns five times on load, then holds still
 *    and stays visible; the pointer starts it again.
 *
 * A name starting --_wfst-res- is this sheet's own working value; the two
 * without the underscore, the inset and the blur, are hooks a site may set and
 * are read ahead of them.
 *
 * Colors are the plugin's own, from tokens.css: the three band hues the
 * ramp shares with the glow, plus a gold and a fuchsia at opposite ends of
 * the loop. Each stop carries its literal here, so this sheet renders on
 * its own.
 *
 * The turn is the gradient's own ANGLE, animated through a registered
 * custom property. Turning it with `hue-rotate` instead — which is what
 * this did until the palette was settled — walks every stop around the
 * whole color wheel, so a chosen palette is only on screen for an instant
 * of each loop and the glow reads as a generic rainbow. The angle leaves
 * every stop its own color and moves where each one sits.
 *
 * Technique: an `::after` holding a conic gradient, blurred, at z-index -1
 * so it paints behind the element's own background — the middle is covered
 * and the color shows only past the edges. `overflow: visible` (and the
 * same on the direct parent) lets it out of a builder's own clipping.
 *
 * Two things it cannot do, both from the same cause. An element that makes
 * its own stacking context — anything with a z-index, a transform, an
 * `isolation`, an opacity below 1 — traps the pseudo above its background
 * rather than behind it, and an element that clips its own overflow for a
 * reason of its own (the fit card clips nothing now, but a card that did)
 * cuts the glow off at its edge. For either, put the class on a plain
 * wrapper around the element instead.
 *
 * @package AI_Resume_Contextualizer
 */

/*
 * The angle is this sheet's own working value, not a site's to set, and it has
 * to be REGISTERED to be animatable: an unregistered custom
 * property has no type, so a browser cannot work out what is halfway
 * between two of its values and the turn would jump from one keyframe to
 * the next. Registered as an angle, it interpolates.
 */
@property --_wfst-res-glow-angle {
	syntax: "<angle>";
	inherits: false;
	initial-value: 0deg;
}

/* ── Shared base ──────────────────────────────────────────────────────── */

.wfst-res-ai-glow,
.wfst-res-ai-glow-hover,
.wfst-res-ai-glow-on,
.wfst-res-ai-glow-pause {
	position: relative;
	overflow: visible !important;
}

/* Let the glow out of a scroll area, a toggle wrapper and the like, as far
   as the direct parent. */
*:has( > .wfst-res-ai-glow ),
*:has( > .wfst-res-ai-glow-hover ),
*:has( > .wfst-res-ai-glow-on ),
*:has( > .wfst-res-ai-glow-pause ) {
	overflow: visible !important;
}

/* ── The glow itself ──────────────────────────────────────────────────── */

.wfst-res-ai-glow::after,
.wfst-res-ai-glow-hover::after,
.wfst-res-ai-glow-on::after,
.wfst-res-ai-glow-pause::after {
	content: "";
	position: absolute;

	/* A card's own: far enough in that the color reads as a light behind
	   the box rather than as a border on it. A button takes the compact
	   halo below instead. */
	inset: var(--wfst-res-glow-inset, var(--_wfst-res-glow-inset, 4px));
	z-index: -1;
	border-radius: inherit;
	pointer-events: none;
	opacity: 0;
	/*
	 * The Design System's own duration and curve, which is what a button beside
	 * this glow transitions on. At 0.45s and plain `ease` the glow was longer
	 * overall but front-loaded, so for the first ~65ms it ran AHEAD of a button
	 * whose curve starts deliberately flat — 3.8% against 1.7% at 25ms. On a
	 * button with a transparent resting fill that reads as the glow flashing
	 * through before the fill arrives. Sharing the curve, it never leads.
	 */
	transition: opacity var(--ds-duration-base, 0.3s) var(--ds-ease, cubic-bezier(0.4, 0, 0.2, 1));

	/*
	 * The first stop is repeated at the end, or the loop closes on a hard
	 * seam between fuchsia and indigo. Each stop is mixed toward black by
	 * the depth, which is the whole difference between a light ground and
	 * a dark one; on a dark page the depth is 100% and every stop is
	 * itself.
	 */
	background: conic-gradient(
		from var(--_wfst-res-glow-angle, 0deg),
		color-mix(in oklch, var(--wfst-res-glow-1, #6e6ef0) var(--wfst-res-glow-depth, 72%), black),
		color-mix(in oklch, var(--wfst-res-glow-2, #2fa4f0) var(--wfst-res-glow-depth, 72%), black),
		color-mix(in oklch, var(--wfst-res-glow-3, #3ad29a) var(--wfst-res-glow-depth, 72%), black),
		color-mix(in oklch, var(--wfst-res-glow-4, #e9c74a) var(--wfst-res-glow-depth, 72%), black),
		color-mix(in oklch, var(--wfst-res-glow-5, #ec4899) var(--wfst-res-glow-depth, 72%), black),
		color-mix(in oklch, var(--wfst-res-glow-1, #6e6ef0) var(--wfst-res-glow-depth, 72%), black)
	);

	filter: blur( var(--wfst-res-glow-blur, var(--_wfst-res-glow-blur, 14px)) );
}

/*
 * A button or a link is small, and most of a card's blur would sit behind
 * the box where nobody can see it: a 48px button hides nearly all of a
 * 14px blur under itself. So the halo starts at the very edge and spreads
 * further, which is the same light read at a smaller size.
 */
.wfst-res-ai-glow:where( a, button, .ds-btn, .x-btn, [type="submit"], [type="button"] )::after,
.wfst-res-ai-glow-hover:where( a, button, .ds-btn, .x-btn, [type="submit"], [type="button"] )::after,
.wfst-res-ai-glow-on:where( a, button, .ds-btn, .x-btn, [type="submit"], [type="button"] )::after,
.wfst-res-ai-glow-pause:where( a, button, .ds-btn, .x-btn, [type="submit"], [type="button"] )::after {
	--_wfst-res-glow-inset: 0px;
	--_wfst-res-glow-blur: 16px;
}

/* ================================================================
   1. wfst-res-ai-glow — one turn on load, then the pointer
   ================================================================ */

.wfst-res-ai-glow:hover::after {
	opacity: 1;
	animation: wfst-res-glow-spin 3s linear infinite;
}

/* The script adds this on load and takes it off after one turn. */
.wfst-res-ai-glow--intro::after {
	opacity: 1;
	animation: wfst-res-glow-spin 3s linear 1;
}

/* ================================================================
   2. wfst-res-ai-glow-hover — the pointer only
   ================================================================ */

.wfst-res-ai-glow-hover:hover::after {
	opacity: 1;
	animation: wfst-res-glow-spin 3s linear infinite;
}

/* ================================================================
   3. wfst-res-ai-glow-on — always there, always turning
   ================================================================ */

.wfst-res-ai-glow-on::after {
	opacity: 1;
	animation: wfst-res-glow-spin 3s linear infinite;
}

/* ================================================================
   4. wfst-res-ai-glow-pause — five turns, then it holds still
   ================================================================ */

/* Visible and still, which is where it rests once the turns are done. */
.wfst-res-ai-glow-pause::after {
	opacity: 1;
}

/* The script adds this on load, for five turns. */
.wfst-res-ai-glow-pause--spinning::after {
	animation: wfst-res-glow-spin 3s linear 5;
}

.wfst-res-ai-glow-pause:hover::after {
	animation: wfst-res-glow-spin 3s linear infinite;
}

/* ================================================================
   The turn
   ================================================================ */

@keyframes wfst-res-glow-spin {
	from {
		--_wfst-res-glow-angle: 0deg;
	}

	to {
		--_wfst-res-glow-angle: -360deg;
	}
}

/*
 * A visitor who asked for less motion keeps the glow and loses the turn.
 * The color is what the glow says; the turning is decoration, and a large
 * slow rotation behind a card is exactly what that setting is asking about.
 */
@media (prefers-reduced-motion: reduce) {
	.wfst-res-ai-glow::after,
	.wfst-res-ai-glow-hover::after,
	.wfst-res-ai-glow-on::after,
	.wfst-res-ai-glow-pause::after,
	.wfst-res-ai-glow--intro::after,
	.wfst-res-ai-glow-pause--spinning::after {
		animation: none !important;
	}
}
