/*
	enhance.css — premium interaction layer for the Big Picture portfolio.

	Purely additive: nothing here changes the existing layout, palette or
	typography. It adds motion, depth and micro-interactions on top of the
	current design, using only GPU-friendly properties (transform / opacity /
	filter). Every effect degrades gracefully:

	  - prefers-reduced-motion  -> all motion is disabled, content shown as-is
	  - no JS / JS disabled      -> none of the .js-* hooks are added, so the
	                                site renders exactly as before
	  - coarse pointers (touch)  -> custom cursor, tilt and magnet are skipped

	Two-color system is preserved throughout: navy #273254, paper #ffffff,
	tints #7a7f90 / #d8dae0 / #f2f3f5. No new hues.
*/

/* ------------------------------------------------------------------ *
   1. Scroll progress bar
 * ------------------------------------------------------------------ */

.scroll-progress {
	position: fixed;
	top: 0;
	left: 0;
	height: 2px;
	width: 100%;
	transform: scaleX(0);
	transform-origin: 0 50%;
	background: #273254;
	z-index: 10002; /* above the fixed header (which sits below poptrox) */
	pointer-events: none;
	will-change: transform;
}

/* On the navy cover the paper header is navy too — flip the bar to white so
   it stays visible against the dark band. */
.scroll-progress.on-cover {
	background: #ffffff;
}

/* ------------------------------------------------------------------ *
   2. Scroll reveal (added by JS as .reveal, promoted to .is-in on enter)
 * ------------------------------------------------------------------ */

.js-enhance .reveal {
	opacity: 0;
	transform: translateY(2em);
	transition:
		opacity 0.8s cubic-bezier(0.16, 1, 0.3, 1),
		transform 0.8s cubic-bezier(0.16, 1, 0.3, 1);
	transition-delay: var(--reveal-delay, 0s);
	will-change: opacity, transform;
}

.js-enhance .reveal.is-in {
	opacity: 1;
	transform: none;
}

/* Figures reveal with a gentle image "settle" — the frame fades/slides while
   the image inside eases out of a soft zoom. */
.js-enhance .case-figure.reveal img,
.js-enhance figure.reveal img {
	transform: scale(1.06);
	transition: transform 1.1s cubic-bezier(0.16, 1, 0.3, 1);
	transition-delay: var(--reveal-delay, 0s);
	will-change: transform;
}

.js-enhance .case-figure.reveal.is-in img,
.js-enhance figure.reveal.is-in img {
	transform: scale(1);
}

/* ------------------------------------------------------------------ *
   3. Split text (headings broken into lines / characters by JS)
 * ------------------------------------------------------------------ */

.js-enhance .split-line {
	display: block;
	overflow: hidden; /* mask so chars rise from behind the line box */
}

.js-enhance .split-word {
	display: inline-block;
	white-space: pre; /* preserve spaces between words */
}

/* Base state is VISIBLE. The entrance is a pure animation layered on top, so
   if the animation never runs (disabled, throttled tab, old engine) the text
   simply shows — it can never stay hidden. */
.js-enhance .split-char {
	display: inline-block;
	will-change: transform, opacity;
}

.js-enhance .split-ready .split-char {
	animation: split-rise 0.62s cubic-bezier(0.22, 1, 0.36, 1) var(--char-delay, 0s) both;
}

@keyframes split-rise {
	from { opacity: 0; transform: translateY(0.9em); }
	to   { opacity: 1; transform: none; }
}

/* JS pins this resting state shortly after the animation should have finished,
   guaranteeing the final visible state regardless of what the animation did. */
.js-enhance .split-done .split-char {
	opacity: 1 !important;
	transform: none !important;
	animation: none !important;
}


/* ------------------------------------------------------------------ *
   4. Custom cursor (fine pointers only; native cursor hidden by JS class)
 * ------------------------------------------------------------------ */

.cursor-dot,
.cursor-ring {
	position: fixed;
	top: 0;
	left: 0;
	z-index: 10050;
	pointer-events: none;
	border-radius: 50%;
	opacity: 0;
	transition: opacity 0.3s ease;
	will-change: transform;
}

.cursor-dot {
	width: 6px;
	height: 6px;
	margin: -3px 0 0 -3px;
	background: #273254;
}

.cursor-ring {
	width: 34px;
	height: 34px;
	margin: -17px 0 0 -17px;
	border: 1px solid rgba(39, 50, 84, 0.55);
	transition:
		opacity 0.3s ease,
		width 0.25s ease,
		height 0.25s ease,
		margin 0.25s ease,
		background-color 0.25s ease,
		border-color 0.25s ease;
}

/* Visible once JS confirms a fine pointer and has a first position. */
.cursor-active .cursor-dot,
.cursor-active .cursor-ring {
	opacity: 1;
}

/* Over the navy cover, invert so the cursor stays legible on dark. */
.cursor-on-dark .cursor-dot {
	background: #ffffff;
}

.cursor-on-dark .cursor-ring {
	border-color: rgba(255, 255, 255, 0.6);
}

/* Hovering a clickable element — ring blooms and fills faintly. */
.cursor-hover .cursor-ring {
	width: 54px;
	height: 54px;
	margin: -27px 0 0 -27px;
	background: rgba(39, 50, 84, 0.08);
	border-color: rgba(39, 50, 84, 0.7);
}

.cursor-on-dark.cursor-hover .cursor-ring {
	background: rgba(255, 255, 255, 0.12);
	border-color: rgba(255, 255, 255, 0.8);
}

/* Pressing down — quick contract. */
.cursor-down .cursor-ring {
	width: 26px;
	height: 26px;
	margin: -13px 0 0 -13px;
}

/* Only hide the system cursor when the custom one is actually running. */
.cursor-enabled,
.cursor-enabled a,
.cursor-enabled button,
.cursor-enabled input,
.cursor-enabled textarea,
.cursor-enabled label,
.cursor-enabled .strip-item,
.cursor-enabled .project-tile,
.cursor-enabled .case-card,
.cursor-enabled .tool-card {
	cursor: none;
}

/* ------------------------------------------------------------------ *
   5. Magnetic elements (JS translates them via --mx / --my)
 * ------------------------------------------------------------------ */

.js-enhance .magnetic {
	transform: translate3d(var(--mx, 0), var(--my, 0), 0);
	transition: transform 0.35s cubic-bezier(0.16, 1, 0.3, 1);
}

/* While actively tracking the pointer, drop the ease so it feels attached. */
.js-enhance .magnetic.is-tracking {
	transition: transform 0.08s linear;
}

/* ------------------------------------------------------------------ *
   6. 3D tilt + soft glare on cards/tiles (fine pointers)
 * ------------------------------------------------------------------ */

.js-enhance .tilt {
	transform-style: preserve-3d;
	transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1);
	will-change: transform;
}

.js-enhance .tilt.is-tilting {
	transition: transform 0.12s ease-out;
}

/* Moving highlight — a soft light source following the pointer. Sits above
   the tile art but below its text overlay (overlays are position:absolute
   with their own stacking; glare is inserted as the first child by JS). */
.js-enhance .tilt-glare {
	position: absolute;
	inset: 0;
	border-radius: inherit;
	pointer-events: none;
	opacity: 0;
	background: radial-gradient(
		circle at var(--gx, 50%) var(--gy, 0%),
		rgba(255, 255, 255, 0.35),
		rgba(255, 255, 255, 0) 55%
	);
	transition: opacity 0.4s ease;
	z-index: 3;
	mix-blend-mode: soft-light;
}

.js-enhance .tilt.is-tilting .tilt-glare {
	opacity: 1;
}

/* The white BIM+AI tile and paper cards read better with a subtle navy
   shadow-light rather than a white glare. */
.js-enhance .project-tile-logos .tilt-glare,
.js-enhance .case-card .tilt-glare,
.js-enhance .tool-card .tilt-glare {
	background: radial-gradient(
		circle at var(--gx, 50%) var(--gy, 0%),
		rgba(39, 50, 84, 0.10),
		rgba(39, 50, 84, 0) 55%
	);
	mix-blend-mode: normal;
}

/* ------------------------------------------------------------------ *
   7. Mouse parallax layers (cover title/meta, hero image)
 * ------------------------------------------------------------------ */

.js-enhance .parallax-layer {
	transform: translate3d(var(--px, 0), var(--py, 0), 0);
	transition: transform 0.5s cubic-bezier(0.16, 1, 0.3, 1);
	will-change: transform;
}

/* ------------------------------------------------------------------ *
   8. Header glassmorphism once scrolled off the cover
 * ------------------------------------------------------------------ */

/* Only on pages where the header floats over paper content (i.e. not the
   navy over-cover state). Adds depth without altering the paper identity. */
#header.is-scrolled:not(.over-cover) {
	background-color: rgba(255, 255, 255, 0.72);
	-webkit-backdrop-filter: saturate(160%) blur(12px);
	backdrop-filter: saturate(160%) blur(12px);
	box-shadow: 0 6px 24px rgba(39, 50, 84, 0.08);
}

/* On the navy cover, a matching frosted navy. */
#header.over-cover.is-scrolled {
	background-color: rgba(39, 50, 84, 0.82);
	-webkit-backdrop-filter: saturate(140%) blur(12px);
	backdrop-filter: saturate(140%) blur(12px);
}

/* ------------------------------------------------------------------ *
   9. Animated sheen on the navy cover (soft lighting / depth)
 * ------------------------------------------------------------------ */

.cover {
	position: relative;
}

.cover .cover-sheen {
	position: absolute;
	inset: -40%;
	pointer-events: none;
	z-index: 0;
	background:
		radial-gradient(60% 60% at 20% 20%, rgba(255, 255, 255, 0.06), rgba(255, 255, 255, 0) 60%),
		radial-gradient(50% 50% at 85% 80%, rgba(255, 255, 255, 0.05), rgba(255, 255, 255, 0) 60%);
	animation: cover-sheen-drift 18s ease-in-out infinite alternate;
}

/* The sheen is the cover's first child at z-index 0, so the real content
   (which comes later in the DOM) already paints above it — no need to touch
   the content's own positioning. */

@keyframes cover-sheen-drift {
	0%   { transform: translate3d(-4%, -3%, 0) scale(1); }
	100% { transform: translate3d(4%, 3%, 0) scale(1.08); }
}

/* ------------------------------------------------------------------ *
   9b. Gallery strip — replace the hard "mandatory" scroll-snap (which
       causes the robotic snapping) with a gentle proximity snap, so both
       the continuous auto-drift and manual scrolling stay fluid.
 * ------------------------------------------------------------------ */

.js-enhance .gallery-strip-track {
	scroll-snap-type: none;
	/* The template sets scroll-behavior:smooth, which animates every
	   per-frame scroll write and stalls the continuous auto-drift. Force
	   auto here; the arrow buttons still scroll smoothly because they pass
	   behavior:'smooth' explicitly to scrollBy(). */
	scroll-behavior: auto;
}

/* Tiles ease their scale a touch more softly to match the fluid drift. */
.js-enhance .strip-item {
	transition:
		transform 0.45s cubic-bezier(0.16, 1, 0.3, 1),
		box-shadow 0.45s cubic-bezier(0.16, 1, 0.3, 1);
}

@media (prefers-reduced-motion: reduce) {
	.js-enhance .gallery-strip-track {
		scroll-snap-type: x proximity; /* keep snap when motion is reduced */
	}
}

/* ------------------------------------------------------------------ *
   10. Small hover refinements consistent with the existing card motion
 * ------------------------------------------------------------------ */

/* Buttons already lift on the site; add a soft glow-shadow in the navy tint
   on the primary buttons for a touch of depth (no color/shape change). */
.js-enhance .button,
.js-enhance input[type="submit"] {
	transition:
		background-color 0.25s ease,
		color 0.25s ease,
		box-shadow 0.3s ease,
		transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.js-enhance .button:hover,
.js-enhance input[type="submit"]:hover {
	box-shadow: 0 10px 26px rgba(39, 50, 84, 0.18);
}

/* ------------------------------------------------------------------ *
   11. Reduced-motion + touch fallbacks
 * ------------------------------------------------------------------ */

@media (prefers-reduced-motion: reduce) {
	.js-enhance .reveal,
	.js-enhance .reveal img,
	.js-enhance .split-char {
		opacity: 1 !important;
		transform: none !important;
		transition: none !important;
	}

	.cover .cover-sheen {
		animation: none;
	}

	.scroll-progress {
		display: none;
	}

	.js-enhance .magnetic,
	.js-enhance .tilt,
	.js-enhance .parallax-layer {
		transform: none !important;
		transition: none !important;
	}

	.cursor-dot,
	.cursor-ring {
		display: none !important;
	}
}

/* Coarse pointers (touch) never get the custom cursor. JS also skips it, but
   this is a hard guarantee. */
@media (pointer: coarse) {
	.cursor-dot,
	.cursor-ring {
		display: none !important;
	}

	.cursor-enabled,
	.cursor-enabled * {
		cursor: auto;
	}
}

/* ------------------------------------------------------------------ *
   12. Final creative layer — page transitions, cursor "View" label,
       film grain on the hero, and a scroll-linked hero.
 * ------------------------------------------------------------------ */

/* 12a. Cross-document page transitions (View Transitions API). Supporting
   browsers crossfade between page loads automatically; others just navigate
   normally — nothing to fall back to, no JS, no risk. */
@view-transition { navigation: auto; }

::view-transition-old(root),
::view-transition-new(root) {
	animation-duration: 0.45s;
	animation-timing-function: cubic-bezier(0.16, 1, 0.3, 1);
}

/* 12b. Cursor "View" label shown over project imagery. */
.cursor-label {
	position: fixed;
	top: 0;
	left: 0;
	z-index: 10051;
	pointer-events: none;
	display: flex;
	align-items: center;
	gap: 0.4em;
	padding: 0.7em 1.05em;
	background: #ffffff;
	color: #273254;
	font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
	font-size: 11px;
	font-weight: 700;
	letter-spacing: 0.1em;
	text-transform: uppercase;
	white-space: nowrap;
	border-radius: 999px;
	box-shadow: 0 8px 24px rgba(39, 50, 84, 0.28);
	opacity: 0;
	transform: translate(-50%, -50%) scale(0.5);
	transition: opacity 0.25s ease, transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
	will-change: transform, opacity;
}

.cursor-view .cursor-label {
	opacity: 1;
	transform: translate(-50%, -50%) scale(1);
}

/* While the label is showing, the dot + ring step aside. */
.cursor-view .cursor-dot,
.cursor-view .cursor-ring {
	opacity: 0;
}

/* 12c. Film grain over the navy hero — sits behind the content (inserted as
   a leading child of .cover), very low opacity, blended into the navy. */
.cover-grain {
	position: absolute;
	inset: -15%;
	z-index: 0;
	pointer-events: none;
	opacity: 0.09;
	mix-blend-mode: overlay;
	background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
	background-size: 200px 200px;
	will-change: transform;
	animation: grain-jitter 0.6s steps(4) infinite;
}

@keyframes grain-jitter {
	0%   { transform: translate(0, 0); }
	25%  { transform: translate(-3%, 2%); }
	50%  { transform: translate(2%, -3%); }
	75%  { transform: translate(-2%, -2%); }
	100% { transform: translate(0, 0); }
}

/* 12d. Scroll-linked hero — compositor hint for the JS-driven scale/fade. */
.cover--cinema .cover-center {
	will-change: transform, opacity;
}

@media (prefers-reduced-motion: reduce) {
	.cover-grain { animation: none; }

	::view-transition-group(*),
	::view-transition-old(*),
	::view-transition-new(*) { animation: none !important; }
}
