/* Atomic WP Interaction Effects V1 — frontend-only CSS.
 *
 * Canonical z-ladder (mirrors blocks.css):
 *   z0 = substrate / bg-media
 *   z1 = surface texture
 *   z2 = decorations
 *   z3 = content
 *   z4 = shapes / edge overlays
 *   z5 = interaction effect layers  ← WE ARE HERE
 *
 * VISUAL LAYER OWNERSHIP (§21 atomic-visual-system.md):
 *   Surface owns ::before + ::after only (z0/z1).
 *   Decorations own explicit .awp-dec-layer children (z2).
 *   Shapes own explicit .awp-group-shape SVG wrappers (z4).
 *   Interaction Effects own explicit .awp-fx-layer children only (z5).
 *   THIS MODULE NEVER WRITES TO HOST ::before / ::after.
 *
 * MOTION OWNERSHIP (§29):
 *   V1 is CSS-only (CSS transitions + @keyframes only).
 *   No JS. No RAF. No IO. No matchMedia bootstrap.
 *   Reduced-motion handled entirely by @media (prefers-reduced-motion: reduce).
 *   Motion module remains unique lifecycle owner; not enqueued by FX V1.
 * ========================================================================== */

/* ---------- Base layer ---------- */

.awp-has-effect {
	position: relative;
	isolation: isolate;
}

.awp-fx-layer {
	box-sizing: border-box;
	position: absolute;
	inset: 0;
	border-radius: inherit;
	pointer-events: none;
	z-index: 5;
	opacity: 0;
	-webkit-mask-repeat: no-repeat;
	mask-repeat: no-repeat;
	-webkit-mask-size: 100% 100%;
	mask-size: 100% 100%;
	transform: translateZ(0);
	transition:
		opacity var(--awp-fx-exit-ms, 420ms) var(--awp-fx-easing, cubic-bezier(0.22, 1, 0.36, 1)),
		box-shadow var(--awp-fx-exit-ms, 420ms) var(--awp-fx-easing, cubic-bezier(0.22, 1, 0.36, 1)),
		filter var(--awp-fx-exit-ms, 420ms) var(--awp-fx-easing, cubic-bezier(0.22, 1, 0.36, 1)),
		background-position var(--awp-fx-exit-ms, 420ms) linear;
	will-change: opacity, background-position, box-shadow;
}

/* Host activates layer on hover (pointer) or focus (keyboard).
 * focus-within propagates nested keyboard focus to the host container,
 * satisfying the "hover must have a keyboard equivalent" accessibility rule. */
.awp-has-effect:hover > .awp-fx-layer,
.awp-has-effect:focus-within > .awp-fx-layer,
.awp-has-effect:focus-visible > .awp-fx-layer {
	opacity: 1;
	transition:
		opacity var(--awp-fx-entry-ms, 380ms) var(--awp-fx-easing, cubic-bezier(0.22, 1, 0.36, 1)),
		box-shadow var(--awp-fx-entry-ms, 380ms) var(--awp-fx-easing, cubic-bezier(0.22, 1, 0.36, 1)),
		filter var(--awp-fx-entry-ms, 380ms) var(--awp-fx-easing, cubic-bezier(0.22, 1, 0.36, 1)),
		background-position var(--awp-fx-entry-ms, 380ms) linear;
}

/* Resting state: very subtle baseline so the layer "exists" for discharge,
 * but is imperceptible except in direct focus.
 * The opacity curve intentionally has a non-zero rest floor so the exit
 * transition has a visible starting point. */
.awp-has-effect > .awp-fx-layer {
	opacity: 0.04;
}

/* ==========================================================================
   EFFECT #1 — ENERGY BORDER
   Visual intent: premium, restrained, medical/mineral border interaction.
   NOT cyberpunk / HUD / gaming RGB / neon overload.

   Technique — CSS-only perimeter:
     • Full-box conic-gradient at 1.5px thickness
     • mask-composite:exclude (xor) strips everything except the 1.5px edge
     • @keyframes rotate the angle for entry charge
     • Sustained state: slow, low-amplitude mineral oscillation
     • Exit: transition the gradient back to a subtle uniform mineral rest
   Brand tokens (child/site owns them):
     --awp-effect-energy-color   primary mineral accent (default blue-slate)
     --awp-effect-energy-color-2 secondary cool highlight (default softer)
     --awp-effect-energy-thickness  (default 1.5px)
   ========================================================================== */

.awp-fx-layer--energy-border {
	--awp-energy-thickness: var(--awp-effect-energy-thickness, 1.5px);
	--awp-energy-c1: var(--awp-effect-energy-color, hsl(206 72% 52% / 0.28));
	--awp-energy-c2: var(--awp-effect-energy-color-2, hsl(198 60% 70% / 0.22));
	--awp-energy-c3: hsl(208 40% 82% / 0.08);

	padding: var(--awp-energy-thickness);
	background:
		conic-gradient(
			from var(--awp-energy-angle, 0deg),
			var(--awp-energy-c3) 0deg,
			var(--awp-energy-c1) 18deg,
			var(--awp-energy-c2) 52deg,
			var(--awp-energy-c3) 96deg,
			var(--awp-energy-c3) 210deg,
			var(--awp-energy-c1) 248deg,
			var(--awp-energy-c2) 292deg,
			var(--awp-energy-c3) 340deg,
			var(--awp-energy-c3) 360deg
		);
	background-size: 100% 100%;

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

	opacity: 0.05;
	filter: blur(0.15px);
}

/* Entry charge: angle sweeps once (~1.8s) while opacity ramps to the
 * premium sustained state (0.22 hover, 0.35 focus-visible). */
@keyframes awp-energy-charge {
	0%   { --awp-energy-angle: 0deg;   }
	100% { --awp-energy-angle: 360deg; }
}

/* Sustained dwell: ultra-slow, sub-perceptible mineral drift.
 * 8.5s full loop, 18% amplitude, no full revolution. */
@keyframes awp-energy-dwell {
	0%   { --awp-energy-dwell: 0deg;   }
	50%  { --awp-energy-dwell: 65deg;  }
	100% { --awp-energy-dwell: 0deg;   }
}

/* Custom property value declarations (no @property global polyfill risk).
 * Browsers that support @property animate the gradient angle; others
 * gracefully fall back to opacity+color transitions which still delivers
 * the premium "charge" intent without the full travel. */
.awp-has-effect:hover > .awp-fx-layer--energy-border,
.awp-has-effect:focus-within > .awp-fx-layer--energy-border {
	animation:
		awp-energy-charge 1.75s cubic-bezier(0.22, 1, 0.36, 1) 0s 1 normal both,
		awp-energy-dwell 8.5s ease-in-out 1.75s infinite normal both;
	opacity: 0.22;
}
.awp-has-effect:focus-within > .awp-fx-layer--energy-border {
	opacity: 0.32;
}

/* ==========================================================================
   EFFECT #2 — SOFT GLOW
   Proof that the registry is not hard-coded for Energy Border.
   Subtle aura shadow, restrained intensity, CSS-only transition.
   Brand tokens (child/site owns):
     --awp-effect-glow-color   (default: slate blue aura)
     --awp-effect-glow-radius  (default: 28px spread)
     --awp-effect-glow-opacity (default: 0.22)
   ========================================================================== */

.awp-fx-layer--soft-glow {
	--awp-glow-c: var(--awp-effect-glow-color, hsl(206 70% 62% / 0.18));
	--awp-glow-r: var(--awp-effect-glow-radius, 32px);
	--awp-glow-y: 10px;

	border-radius: inherit;
	inset: -1px;
	box-shadow:
		0 0 0 0 transparent;
	opacity: 0.06;
}

.awp-has-effect:hover > .awp-fx-layer--soft-glow,
.awp-has-effect:focus-within > .awp-fx-layer--soft-glow {
	box-shadow:
		0 var(--awp-glow-y) var(--awp-glow-r) calc(var(--awp-glow-r) / -4) var(--awp-glow-c);
	opacity: 0.82;
}

.awp-has-effect:focus-within > .awp-fx-layer--soft-glow {
	box-shadow:
		0 var(--awp-glow-y) var(--awp-glow-r) calc(var(--awp-glow-r) / -4) var(--awp-glow-c),
		0 0 0 2px var(--awp-effect-glow-color-stroke, hsl(206 80% 60% / 0.14));
}

/* ==========================================================================
   REDUCED MOTION FALLBACK
   Static, non-animated visual states only — no travel, no dwell loop,
   no conic sweep. Energy Border becomes a static solid 1.5px mineral
   stroke; Soft Glow becomes a static low-intensity aura.
   ========================================================================== */

@media (prefers-reduced-motion: reduce) {
	.awp-fx-layer,
	.awp-has-effect:hover > .awp-fx-layer,
	.awp-has-effect:focus-within > .awp-fx-layer,
	.awp-has-effect:focus-visible > .awp-fx-layer {
		animation: none !important;
		transition: opacity 180ms linear !important;
	}

	/* Energy → static solid 1.5px stroke. */
	.awp-fx-layer--energy-border,
	.awp-has-effect:hover > .awp-fx-layer--energy-border,
	.awp-has-effect:focus-within > .awp-fx-layer--energy-border {
		animation: none !important;
		background: transparent;
		background-color: transparent;
		padding: 0;
		-webkit-mask: none;
		mask: none;
		border: var(--awp-energy-thickness, 1.5px) solid
			var(--awp-effect-energy-color-static, hsl(206 62% 48% / 0.28));
		border-radius: inherit;
		box-shadow: none;
		filter: none;
	}
	.awp-has-effect > .awp-fx-layer--energy-border          { opacity: 0.08; }
	.awp-has-effect:hover > .awp-fx-layer--energy-border    { opacity: 0.22; }
	.awp-has-effect:focus-within > .awp-fx-layer--energy-border { opacity: 0.30; }

	/* Soft Glow → static aura at half intensity. */
	.awp-has-effect > .awp-fx-layer--soft-glow {
		box-shadow:
			0 var(--awp-glow-y) calc(var(--awp-glow-r) * 0.55) calc(var(--awp-glow-r) / -5)
			var(--awp-effect-glow-color, hsl(206 70% 62% / 0.10));
		opacity: 0.55;
	}
	.awp-has-effect:hover > .awp-fx-layer--soft-glow,
	.awp-has-effect:focus-within > .awp-fx-layer--soft-glow {
		box-shadow:
			0 var(--awp-glow-y) calc(var(--awp-glow-r) * 0.72) calc(var(--awp-glow-r) / -5)
			var(--awp-effect-glow-color, hsl(206 70% 62% / 0.16));
		opacity: 0.9;
	}
}

/* ==========================================================================
   EFFECT DESIGNER V2 — host-transform effects (Slice 2C)
   lift | tilt-3d (CSS fallback) | animated-shadow

   Composition model:
   - Every host-transform effect contributes CSS custom properties on the host.
   - A single `transform` is composed from --awp-lift-distance + --awp-tilt-rotateX/Y.
   - animated-shadow owns the host box-shadow (no transform conflict).
   - z5-explicit effects (soft-glow, energy-border) reuse the V1 .awp-fx-layer
     markup + CSS unchanged; the host carries awp-has-effect so the V1
     hover/focus-within activation rules apply automatically.
   - No JS, no rAF, no matchMedia. Reduced-motion: transforms and box-shadow
     are neutralised; z5 layers fall back to their V1 reduced-motion state.
   ========================================================================== */

.awp-v2 {
	--awp-v2-easing: cubic-bezier(0.22, 1, 0.36, 1);
	--awp-tilt-rotateX: 0deg;
	--awp-tilt-rotateY: 0deg;
	transform:
		translateY(0)
		rotateX(var(--awp-tilt-rotateX))
		rotateY(var(--awp-tilt-rotateY));
	transition:
		transform var(--awp-lift-duration, 380ms) var(--awp-v2-easing),
		box-shadow var(--awp-lift-duration, 380ms) var(--awp-v2-easing);
	will-change: transform, box-shadow;
}

/* Hover + keyboard focus all compose the same lift + tilt state.
 * focus-within propagates nested keyboard focus to the host container. */
.awp-v2:hover,
.awp-v2:focus-within,
.awp-v2:focus-visible {
	transform:
		translateY(calc(var(--awp-lift-distance, 0px) * -1))
		rotateX(var(--awp-tilt-rotateX))
		rotateY(var(--awp-tilt-rotateY));
}

/* ----- tilt-3d : CSS fallback (no Motion runtime yet) -----
 * Light, fixed-direction tilt on hover; pointer-following tilt is owned by
 * Motion R3 and will replace this fallback once integrated. */
.awp-v2-effect--tilt-3d {
	perspective: var(--awp-tilt-perspective, 1000px);
	transform-style: preserve-3d;
}
.awp-v2-effect--tilt-3d:hover,
.awp-v2-effect--tilt-3d:focus-within,
.awp-v2-effect--tilt-3d:focus-visible {
	--awp-tilt-rotateX: calc(var(--awp-tilt-max, 5deg) * -0.4);
	--awp-tilt-rotateY: calc(var(--awp-tilt-max, 5deg) * 0.5);
}

/* ----- animated-shadow : host box-shadow on hover ----- */
.awp-v2-effect--animated-shadow {
	box-shadow: 0 0 0 0 transparent;
}
.awp-v2-effect--animated-shadow:hover,
.awp-v2-effect--animated-shadow:focus-within,
.awp-v2-effect--animated-shadow:focus-visible {
	box-shadow:
		0
		calc(var(--awp-shadow-distance, 12px) * 1.2)
		calc(var(--awp-shadow-distance, 12px) * 1.6)
		calc(var(--awp-shadow-distance, 12px) * -0.6)
		hsl(220 30% 18% / calc(var(--awp-shadow-intensity, 0.25) * 0.45));
}

/* ----- V2 reduced motion ----- */
@media (prefers-reduced-motion: reduce) {
	.awp-v2,
	.awp-v2:hover,
	.awp-v2:focus-within,
	.awp-v2:focus-visible {
		transition: none !important;
		transform: none !important;
		--awp-tilt-rotateX: 0deg;
		--awp-tilt-rotateY: 0deg;
	}
	.awp-v2-effect--animated-shadow,
	.awp-v2-effect--animated-shadow:hover,
	.awp-v2-effect--animated-shadow:focus-within,
	.awp-v2-effect--animated-shadow:focus-visible {
		box-shadow: 0 0 0 0 transparent !important;
	}
}
