/* Interactive motion layer, driven by js/motion.js.
   Every hidden or moved state is scoped to html.motion-on, which the script only sets once an
   IntersectionObserver has reported. Without it (no JS, reduced motion, stalled observer) the page is static and fully visible.
   Reveals use the individual translate/scale/rotate properties so they compose with hover transforms. */

/* ---------- Scroll reveals ---------- */
:is(.reveal-up, [data-reveal]) { --rv-x: 0px; --rv-y: 56px; --rv-scale: 1; --rv-rot: 0deg; --rv-blur: 0px; --rv-dir: 1; }
[data-from="above"] { --rv-dir: -1; }
[data-reveal="left"] { --rv-x: -72px; --rv-y: 0px; }
[data-reveal="right"] { --rv-x: 72px; --rv-y: 0px; }
[data-reveal="zoom"] { --rv-y: 40px; --rv-scale: .88; --rv-blur: 6px; }
[data-reveal="flip"] { --rv-y: 48px; --rv-rot: 24deg; }
.about-grid { perspective: 1400px; }
/* Side-entering cards start off screen; clip them without creating a scroll container. */
.studio-page { overflow-x: clip; }

html.motion-on :is(.reveal-up, [data-reveal]) {
    transition: opacity 900ms var(--motion-ease) var(--reveal-delay, 0ms), translate 1050ms var(--motion-ease) var(--reveal-delay, 0ms), scale 1050ms var(--motion-ease) var(--reveal-delay, 0ms), rotate 1050ms var(--motion-ease) var(--reveal-delay, 0ms), filter 900ms var(--motion-ease) var(--reveal-delay, 0ms), transform 450ms var(--motion-ease), box-shadow 300ms, border-color 300ms, background-color 300ms, color 300ms;
}
html.motion-on :is(.reveal-up, [data-reveal]):not([data-in]) {
    opacity: 0;
    translate: var(--rv-x) calc(var(--rv-y) * var(--rv-dir));
    scale: var(--rv-scale);
    rotate: x calc(var(--rv-rot) * var(--rv-dir));
    filter: blur(var(--rv-blur));
}

/* Headings stay put; their words rise out of individual clips instead. */
html.motion-on [data-reveal="words"]:not([data-in]) { opacity: 1; translate: none; scale: none; rotate: none; filter: none; }
.split-word { display: inline-block; overflow: hidden; vertical-align: bottom; padding: 0 .08em .16em; margin: 0 -.08em -.16em; }
.split-word > span { display: inline-block; }
html.motion-on [data-reveal="words"] .split-word > span { transition: translate 1000ms var(--motion-ease) calc(var(--word-index, 0) * 85ms + 60ms), rotate 1000ms var(--motion-ease) calc(var(--word-index, 0) * 85ms + 60ms); transform-origin: 0 100%; }
html.motion-on [data-reveal="words"]:not([data-in]) .split-word > span { translate: 0 calc(112% * var(--rv-dir)); rotate: calc(7deg * var(--rv-dir)); }
html.motion-on [data-reveal="words"] .section-description { transition: opacity 900ms var(--motion-ease) 380ms, translate 900ms var(--motion-ease) 380ms; }
html.motion-on [data-reveal="words"]:not([data-in]) .section-description { opacity: 0; translate: 0 calc(18px * var(--rv-dir)); }

/* ---------- Hero ---------- */
.hero-particles { position: absolute; inset: 0; z-index: 0; width: 100%; height: 100%; pointer-events: none; opacity: 0; }
.hero-particles[data-live] { opacity: calc(1 - var(--hero-p, 0) * .7); animation: particles-in 2.2s ease .4s backwards; }
html.motion-on .studio-hero .hero-content { translate: 0 calc(var(--hero-p, 0) * 130px); opacity: calc(1 - var(--hero-p, 0) * 1.2); }
html.motion-on .studio-hero::before { scale: calc(1 + var(--hero-p, 0) * .14); }
html.motion-on .hero-logo { translate: calc(var(--px, 0) * 16px) calc(var(--py, 0) * 10px); }
html.motion-on .hero-tagline { translate: calc(var(--px, 0) * -9px) calc(var(--py, 0) * -6px); }
html.motion-on .hero-aurora { translate: calc(var(--px, 0) * -28px) calc(var(--py, 0) * -20px); }
.studio-hero .hero-scroll { bottom: clamp(72px, 8vw, 116px); }
.hero-frame { bottom: clamp(66px, 7.6vw, 108px); }

.hero-wave { position: absolute; left: 0; right: 0; bottom: -1px; z-index: 1; height: clamp(54px, 7vw, 100px); pointer-events: none; }
.hero-wave svg { display: block; width: 100%; height: 100%; overflow: hidden; }
.wave-fill { fill: var(--background); }
.wave-line { fill: none; stroke: url(#hero-wave-line); stroke-width: 1.6; vector-effect: non-scaling-stroke; }
.wave-line-back { opacity: .5; animation: wave-drift 17s linear infinite reverse; }
.wave-fill, .wave-line-front { animation: wave-drift 12s linear infinite; }

/* ---------- Technology marquee ---------- */
.tech-marquee { position: relative; display: grid; gap: 12px; padding: 22px 0 30px; background: var(--background); overflow: hidden; user-select: none; -webkit-user-select: none; -webkit-mask-image: linear-gradient(90deg, transparent, #000 9%, #000 91%, transparent); mask-image: linear-gradient(90deg, transparent, #000 9%, #000 91%, transparent); }
.marquee-row { overflow: hidden; touch-action: pan-y; cursor: grab; }
.marquee-row[data-dragging] { cursor: grabbing; }
.marquee-track { display: flex; width: max-content; will-change: transform; animation: marquee-scroll 110s linear infinite; }
.marquee-row[data-direction="1"] .marquee-track { animation-direction: reverse; }
html.motion-on .marquee-track { animation: none; }
/* Spacing lives on each item (not flex gap) so half the track is exactly one loop. */
.marquee-item { display: inline-flex; align-items: center; gap: 10px; margin-right: 12px; padding: 10px 18px 10px 12px; border: 1px solid var(--studio-border); border-radius: 3px; background: var(--surface-container-low); color: var(--studio-muted); font-size: 12px; font-weight: 550; letter-spacing: .02em; white-space: nowrap; transition: color 300ms, border-color 300ms, background-color 300ms; }
.marquee-item img { width: 22px; height: 22px; object-fit: contain; pointer-events: none; }
.marquee-item:hover { color: var(--studio-ink); border-color: #8f6bff99; background: var(--surface-container); }
:root:not([data-theme="light"]) .marquee-item img:is([src$="/openai.svg"], [src$="/github.svg"], [src$="/unity.svg"], [src$="/filmora.svg"]) { filter: brightness(0) invert(1); }
:root:not([data-theme="light"]) .marquee-item img:is([src$="/dot-net-transparent.svg"], [src*="/generic-"], [src*="/testing-"]) { filter: brightness(1.9); }

/* ---------- Tilt cards with cursor glare and a glowing edge ---------- */
/* Registered so the centred-card glow can sweep around the edge on touch screens. */
@property --mx { syntax: "<percentage>"; inherits: true; initial-value: 50%; }
@property --my { syntax: "<percentage>"; inherits: true; initial-value: 50%; }
.studio-icon { transition: transform 900ms var(--motion-ease); }
html.motion-on [data-tilt] { position: relative; --glare: rgb(255 255 255 / 10%); }
:root[data-theme="light"] [data-tilt] { --glare: rgb(101 64 163 / 9%); }
html.motion-on [data-tilt]::after { content: ""; position: absolute; inset: 0; z-index: 3; pointer-events: none; border-radius: inherit; opacity: 0; background: radial-gradient(520px circle at var(--mx, 50%) var(--my, 50%), var(--glare), transparent 45%); transition: opacity 400ms; }
html.motion-on [data-tilt]::before { content: ""; position: absolute; inset: 0; z-index: 3; pointer-events: none; border-radius: inherit; padding: 1px; opacity: 0; background: radial-gradient(320px circle at var(--mx, 50%) var(--my, 50%), #4cc9ff, #8f6bff 38%, transparent 72%); -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 exclude, linear-gradient(#000 0 0); transition: opacity 400ms; }

/* Touch: the card tilts under the finger while pressed; the card centred on screen lights up. */
html.motion-on [data-tilt][data-press] { transform: perspective(900px) rotateX(var(--rx, 0deg)) rotateY(var(--ry, 0deg)) scale(.98); }
html.motion-on [data-tilt][data-press]::before, html.motion-on [data-tilt][data-press]::after, html.motion-on [data-tilt][data-center]::before { opacity: 1; }
html.motion-on [data-tilt][data-center]:not([data-press]) { animation: edge-sweep 3.2s linear infinite; }
html.motion-on [data-tilt][data-center] .studio-icon { transform: rotateY(360deg); }
html.motion-on :is([data-tilt], .project-card)[data-center] .photo-tint img, html.motion-on .project-card[data-center] .project-preview > img { transform: scale(1.05); }
html.motion-on .project-card[data-center] { border-color: #8f6bff70; box-shadow: 0 25px 55px #0002; }
.k23-ripple { position: fixed; left: 0; top: 0; z-index: 1999; width: 14px; height: 14px; margin: -7px 0 0 -7px; border-radius: 50%; pointer-events: none; background: radial-gradient(circle, #8f6bff80, #4cc9ff40 55%, transparent 70%); animation: tap-ripple 700ms var(--motion-ease) forwards; }

@media (hover: hover) and (pointer: fine) {
    html.motion-on [data-tilt]:hover { transform: perspective(1100px) rotateX(var(--rx, 0deg)) rotateY(var(--ry, 0deg)) translateY(-6px); }
    html.motion-on [data-tilt]:hover::before, html.motion-on [data-tilt]:hover::after { opacity: 1; }
    html.motion-on [data-tilt]:hover .studio-icon { transform: rotateY(360deg); }
    html.motion-on .capability-tile:hover img { animation: tile-pop 650ms var(--motion-ease); }
    html.motion-on .project-preview:hover > img { transform: scale(1.04); }
}

/* ---------- Sliding pill behind the active filter ---------- */
.capability-tabs { --pill-bg: #eceae3; }
:root[data-theme="light"] .capability-tabs { --pill-bg: #202630; }
.project-filters { --pill-bg: var(--studio-ink); }
html.motion-on [data-pill-group][data-pill-ready] { position: relative; isolation: isolate; }
html.motion-on [data-pill-group][data-pill-ready]::before { content: ""; position: absolute; left: 0; top: 0; z-index: -1; width: var(--pill-w); height: var(--pill-h); translate: var(--pill-x) var(--pill-y); border-radius: 3px; background: var(--pill-bg); box-shadow: 0 8px 24px #0000002e; transition: translate 550ms var(--motion-ease), width 550ms var(--motion-ease), height 550ms var(--motion-ease); }
html.motion-on [data-pill-group][data-pill-ready] > .is-active { background: transparent; }

/* ---------- Header that steps aside while reading ---------- */
html.motion-on .studio-header { transition: translate 450ms var(--motion-ease), background 400ms, border-color 400ms; }
html.motion-on .studio-header[data-hidden]:not(:focus-within) { translate: 0 calc(-100% - 4px); }

/* ---------- Back to top with scroll progress ring ---------- */
.back-to-top { position: fixed; right: max(20px, env(safe-area-inset-right)); bottom: max(20px, env(safe-area-inset-bottom)); z-index: 45; display: grid; place-items: center; width: 52px; height: 52px; padding: 0; border: 1px solid var(--studio-border); border-radius: 50%; background: var(--surface-container); color: var(--studio-ink); cursor: pointer; box-shadow: 0 12px 32px #0000004d; opacity: 0; visibility: hidden; translate: 0 18px; scale: .85; transition: opacity 350ms, translate 450ms var(--motion-ease), scale 450ms var(--motion-ease), border-color 250ms, visibility 0s 450ms; }
.back-to-top[data-show] { opacity: 1; visibility: visible; translate: 0 0; scale: 1; transition-delay: 0s; }
.back-to-top:hover { border-color: #8f6bff; }
.back-to-top svg { width: 100%; height: 100%; overflow: visible; }
.back-to-top-track, .back-to-top-progress { fill: none; stroke-width: 2.5; }
.back-to-top-track { stroke: transparent; }
.back-to-top-progress { stroke: #8f6bff; stroke-linecap: round; stroke-dasharray: 100; stroke-dashoffset: calc(100 - var(--progress, 0)); transform: rotate(-90deg); transform-origin: center; transform-box: fill-box; }
.back-to-top-arrow { fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; transition: translate 300ms var(--motion-ease); }
.back-to-top:hover .back-to-top-arrow { translate: 0 -3px; }

/* ---------- Cursor follower (fine pointers only; the native cursor stays) ---------- */
.k23-cursor { position: fixed; inset: 0; z-index: 2000; pointer-events: none; transition: opacity 250ms; }
.k23-cursor[data-state="hidden"] { opacity: 0; }
.k23-cursor-dot, .k23-cursor-ring { position: absolute; left: 0; top: 0; will-change: transform; }
.k23-cursor-dot::before { content: ""; position: absolute; width: 6px; height: 6px; margin: -3px 0 0 -3px; border-radius: 50%; background: #4cc9ff; box-shadow: 0 0 10px #4cc9ff; }
.k23-cursor-ring::before { content: ""; position: absolute; width: 36px; height: 36px; margin: -18px 0 0 -18px; border: 1.5px solid #8f6bffb3; border-radius: 50%; transition: scale 350ms var(--motion-ease), background-color 300ms, border-color 300ms; }
.k23-cursor[data-state="hover"] .k23-cursor-ring::before { scale: 1.55; background: #8f6bff1f; border-color: #8f6bff; }
.k23-cursor[data-state="label"] .k23-cursor-ring::before { scale: 2.3; background: linear-gradient(135deg, #1761dc, #6941d9 60%, #a830eb); border-color: transparent; }
.k23-cursor[data-down] .k23-cursor-ring::before { scale: .8; }
.k23-cursor-ring em { position: absolute; translate: -50% -50%; color: #fff; font: 650 10px/1 var(--font-body); font-style: normal; letter-spacing: .08em; text-transform: uppercase; opacity: 0; transition: opacity 250ms; }
.k23-cursor[data-state="label"] .k23-cursor-ring em { opacity: 1; }
.k23-cursor[data-state="label"] .k23-cursor-dot { opacity: 0; }

@keyframes particles-in { from { opacity: 0; } }
@keyframes wave-drift { to { transform: translateX(-1440px); } }
@keyframes marquee-scroll { to { transform: translateX(-50%); } }
@keyframes tile-pop { 30% { transform: scale(1.18) rotate(-8deg); } 60% { transform: scale(.96) rotate(5deg); } }
@keyframes tap-ripple { from { scale: 1; opacity: 1; } to { scale: 9; opacity: 0; } }
@keyframes edge-sweep { 0%, 100% { --mx: 0%; --my: 0%; } 25% { --mx: 100%; --my: 0%; } 50% { --mx: 100%; --my: 100%; } 75% { --mx: 0%; --my: 100%; } }

@media (max-width: 599px) {
    [data-reveal="left"] { --rv-x: -36px; }
    [data-reveal="right"] { --rv-x: 36px; }
    .tech-marquee { padding: 16px 0 24px; gap: 10px; }
    .marquee-item { padding: 8px 14px 8px 10px; font-size: 11px; }
    .back-to-top { width: 46px; height: 46px; }
}

/* Gentle mode (OS asks for reduced motion): content still fades in, but nothing travels, tilts or zooms.
   The older stylesheets switch off every transition with !important under reduced motion, so the fades
   restate theirs with !important and higher specificity. Particles and the marquee are script-driven and slowed there. */
html.motion-gentle :is(.reveal-up, [data-reveal]) { --rv-x: 0px; --rv-y: 0px; --rv-scale: 1; --rv-rot: 0deg; --rv-blur: 0px; }
html.motion-gentle [data-reveal="words"]:not([data-in]) .split-word > span { translate: none; rotate: none; opacity: 0; }
@media (prefers-reduced-motion: reduce) {
    .k23-cursor, .k23-ripple { display: none; }
    .wave-fill, .wave-line, .marquee-track { animation: none !important; }
    .back-to-top { transition: none; }
    html.motion-gentle :is(.reveal-up, [data-reveal]), html.motion-gentle [data-reveal="words"] :is(.split-word > span, .section-description) { transition: opacity 800ms ease var(--reveal-delay, 0ms) !important; }
    html.motion-gentle [data-reveal="words"] .split-word > span { transition-delay: calc(var(--word-index, 0) * 90ms) !important; }
    html.motion-gentle.motion-on :is(.reveal-up, [data-reveal]):not([data-in]) { opacity: 0 !important; }
    html.motion-gentle.motion-on [data-reveal="words"]:not([data-in]) { opacity: 1 !important; }
    html.motion-gentle.motion-on [data-reveal="words"]:not([data-in]) .split-word > span { opacity: 0 !important; }
    html.motion-gentle .hero-particles[data-live] { opacity: .8; }
    html.motion-gentle.motion-on .studio-hero .hero-content { translate: none; }
    html.motion-gentle.motion-on :is(.hero-logo, .hero-tagline, .hero-aurora) { translate: none; }
    html.motion-gentle.motion-on .studio-hero::before { scale: none; }
}
