/**
 * Motion effects for CW — The Dark
 * All effects are progressive enhancements that no-op under prefers-reduced-motion
 * and leave content fully visible if JS fails.
 *
 * Base state = visible (safe fallback). Hidden state only applies when JS is active.
 */

/* ============================================================
   PRELOADER
   Fullscreen loader with progress bar
   ============================================================ */

#cw-preloader {
	position: fixed;
	inset: 0;
	z-index: 100000;
	background: var(--wp--preset--color--base);
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	gap: clamp(20px, 4vh, 38px);
	transition: opacity 0.7s ease;
}

#cw-preloader.done {
	opacity: 0;
	pointer-events: none;
}

.cw-pre__logo {
	display: block;
	width: clamp(170px, 30vw, 300px);
}

.cw-pre__logo img {
	width: 100%;
	height: auto;
	filter: invert(1) sepia(0.16) brightness(0.98) saturate(0.7);
	animation: cw-pre-breathe 2.6s ease-in-out infinite;
}

.cw-pre__pct {
	font-family: var(--wp--preset--font-family--mono);
	font-size: 0.74rem;
	letter-spacing: 0.32em;
	text-transform: uppercase;
	color: var(--wp--preset--color--ash);
}

.cw-pre__bar {
	position: fixed;
	left: 0;
	bottom: 0;
	width: 100%;
	height: 1px;
	background: rgba(233, 227, 216, 0.13);
}

.cw-pre__bar span {
	display: block;
	height: 100%;
	width: 0;
	background: var(--wp--preset--color--accent);
	transition: width 0.1s linear;
}

@keyframes cw-pre-breathe {
	0%, 100% {
		opacity: 0.72;
	}
	50% {
		opacity: 1;
	}
}

/* ============================================================
   HERO FADE-IN SEQUENCE
   Choreography matches prototype: eyebrow + tagline rise, title focus-in with blur
   ============================================================ */

/* Visible end-state (default - works without JS) */
.cw-hero-eyebrow,
.cw-hero-title,
.cw-hero-tagline {
	opacity: 1;
	transform: none;
	filter: none;
}

/* Hidden pre-animation state (only when JS is active) */
html.js .cw-hero:not(.is-revealed) .cw-hero-eyebrow,
html.js .cw-hero:not(.is-revealed) .cw-hero-tagline,
html.js .cw-hero:not(.is-revealed) .cw-hero-title {
	opacity: 0;
	transform: translateY(28px);
}

/* Animated transitions when .is-revealed is added */
.cw-hero.is-revealed .cw-hero-eyebrow,
.cw-hero.is-revealed .cw-hero-title,
.cw-hero.is-revealed .cw-hero-tagline {
	opacity: 1;
	transform: translateY(0);
	/* Transitions are handled by GSAP in motion.js */
}

/* ============================================================
   BLUR FOCUS-IN ON SCROLL
   Elements sharpen as they enter viewport (sections below hero only)
   Target specific elements used in motion.js
   ============================================================ */

/* Blurred + faded state is now applied via INLINE STYLES in pattern files
   This ensures blur is applied immediately when HTML is parsed (no flash)
   CSS no longer needed here - inline styles take priority */

/* ============================================================
   REVEAL ON SCROLL (Generic rise + fade)
   ============================================================ */

/* Visible end-state */
.cw-reveal {
	opacity: 1;
	transform: none;
}

/* Hidden pre-animation state (only when JS is active) */
html.js .cw-reveal:not(.in) {
	opacity: 0;
	transform: translateY(26px);
}

/* Animated transition when .in is added */
.cw-reveal.in {
	opacity: 1;
	transform: translateY(0);
	transition: opacity 1.1s cubic-bezier(0.2, 0.7, 0.2, 1),
	            transform 1.1s cubic-bezier(0.2, 0.7, 0.2, 1);
}

/* ============================================================
   HERO MIST (CSS-based drifting fog)
   Layered radial gradients with slow animation, bottom-right placement
   No WebGL - pure CSS for lightweight implementation
   ============================================================ */

.cw-hero-mist {
	position: absolute;
	inset: 0;
	z-index: 2;
	pointer-events: none;
	mix-blend-mode: screen;
	opacity: 0;
	transition: opacity 2.6s ease-in-out;
	overflow: hidden;
}

.cw-hero-mist.is-visible {
	opacity: 0.28;
}

/* Layer 1: Large slow-moving fog bank (bottom-right, never above mid-height) */
.cw-hero-mist::before {
	content: "";
	position: absolute;
	width: 150%;
	height: 70%;
	bottom: -15%;
	right: -35%;
	background: radial-gradient(
		ellipse 55% 40% at 68% 72%,
		rgba(233, 227, 216, 0.18) 0%,
		rgba(233, 227, 216, 0.1) 30%,
		transparent 65%
	);
	filter: blur(45px);
	animation: cw-mist-drift-1 50s ease-in-out infinite alternate;
}

/* Layer 2: Wispy tendrils (bottom-right, offset) */
.cw-hero-mist::after {
	content: "";
	position: absolute;
	width: 130%;
	height: 60%;
	bottom: -10%;
	right: -30%;
	background: radial-gradient(
		ellipse 48% 35% at 72% 78%,
		rgba(233, 227, 216, 0.14) 0%,
		rgba(233, 227, 216, 0.07) 35%,
		transparent 70%
	);
	filter: blur(35px);
	animation: cw-mist-drift-2 65s ease-in-out infinite alternate-reverse;
}

@keyframes cw-mist-drift-1 {
	0% {
		transform: translate(0, 0) scale(1);
		opacity: 0.65;
	}
	100% {
		transform: translate(-6%, 3%) scale(1.06);
		opacity: 0.9;
	}
}

@keyframes cw-mist-drift-2 {
	0% {
		transform: translate(0, 0) scale(1);
		opacity: 0.75;
	}
	100% {
		transform: translate(5%, -2%) scale(1.04);
		opacity: 0.95;
	}
}

/* ============================================================
   PREFERS-REDUCED-MOTION: Force all effects visible/static
   ============================================================ */

@media (prefers-reduced-motion: reduce) {
	/* Hero elements always visible */
	html.js .cw-hero:not(.is-revealed) .cw-hero-eyebrow,
	html.js .cw-hero:not(.is-revealed) .cw-hero-title,
	html.js .cw-hero:not(.is-revealed) .cw-hero-tagline {
		opacity: 1 !important;
		transform: none !important;
		filter: none !important;
	}

	/* Focus elements always sharp (override inline styles from patterns) */
	.cw-statement__line,
	.cw-news__title,
	.cw-news__sub,
	.cw-discord__line,
	.cw-era__word,
	.cw-era__cap {
		filter: none !important;
		opacity: 1 !important;
		will-change: auto !important;
	}

	/* Reveal elements always visible */
	html.js .cw-reveal:not(.in) {
		opacity: 1 !important;
		transform: none !important;
	}

	/* Disable all transitions */
	.cw-hero.is-revealed .cw-hero-eyebrow,
	.cw-hero.is-revealed .cw-hero-title,
	.cw-hero.is-revealed .cw-hero-tagline,
	.cw-focus.is-sharp,
	.cw-reveal.in {
		transition: none !important;
	}

	/* Disable mist animations */
	.cw-hero-mist,
	.cw-hero-mist::before,
	.cw-hero-mist::after {
		animation: none !important;
		opacity: 0 !important;
	}
}
