/* ==========================================================================
   ANIMATIONS
   Keyframes, scroll-reveal states, page transitions.
   Everything here is switched off for users who prefer reduced motion
   (see the bottom of this file).
   ========================================================================== */

/* Registered property so the portrait's conic border can rotate smoothly */
@property --angle {
  syntax: "<angle>";
  initial-value: 0deg;
  inherits: false;
}

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes rotate-angle { to { --angle: 360deg; } }

@keyframes fade-up {
  from { opacity: 0; transform: translateY(24px); }
  to   { opacity: 1; transform: none; }
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

@keyframes word-in {
  from { opacity: 0; transform: translateY(0.6em) rotateX(-40deg); filter: blur(6px); }
  to   { opacity: 1; transform: none; filter: blur(0); }
}

@keyframes blink { 50% { opacity: 0; } }

@keyframes float {
  0%, 100% { transform: translateY(0) translateZ(60px); }
  50%      { transform: translateY(-12px) translateZ(60px); }
}
@keyframes float-soft {
  0%, 100% { translate: 0 0; }
  50%      { translate: 0 -18px; }
}

@keyframes cube-spin {
  from { transform: rotateX(-20deg) rotateY(0deg); }
  to   { transform: rotateX(-20deg) rotateY(360deg); }
}
@keyframes ring-tilt {
  from { transform: rotateX(68deg) rotateZ(0deg); }
  to   { transform: rotateX(68deg) rotateZ(360deg); }
}
@keyframes orb-pulse {
  0%, 100% { transform: scale(1); opacity: 0.85; }
  50%      { transform: scale(1.08); opacity: 1; }
}

@keyframes marquee { to { transform: translateX(-50%); } }

@keyframes scroll-cue {
  0%   { top: -40%; }
  100% { top: 100%; }
}

@keyframes orb-drift {
  0%, 100% { transform: translate(0, 0) scale(1); }
  50%      { transform: translate(-4vw, 3vw) scale(1.1); }
}

@keyframes glitch-a {
  0%, 92%, 100% { transform: none; opacity: 0; }
  93% { transform: translate(-4px, 2px); opacity: 0.7; }
  95% { transform: translate(4px, -2px); opacity: 0.7; }
  97% { transform: translate(-2px, 0); opacity: 0.5; }
}

/* --- Page enter (pure CSS, so content is never hidden if JS fails) --- */
main { animation: fade-in 0.6s var(--ease-out) both; }

/* --- Page leave transition overlay (created by navigation.js) --- */
.page-transition {
  position: fixed;
  inset: 0;
  z-index: 500;
  pointer-events: none;
  background: var(--bg);
  transform: scaleY(0);
  transform-origin: bottom;
  transition: transform 0.45s var(--ease-io);
}
.page-transition::after {
  content: "";
  position: absolute;
  left: 0; right: 0; top: 0;
  height: 2px;
  background: var(--grad-primary);
  box-shadow: 0 0 20px var(--c-sky);
}
.page-transition.is-active { transform: scaleY(1); pointer-events: all; }

/* --- Scroll reveal ---
   Elements get [data-reveal]. They are only hidden once JS has confirmed it
   is running (html.js), so nothing is ever invisible without JavaScript. */
.js [data-reveal] {
  opacity: 0;
  transform: translateY(32px);
  transition: opacity 0.9s var(--ease-out), transform 0.9s var(--ease-out);
  transition-delay: var(--reveal-delay, 0s);
}
.js [data-reveal="left"]  { transform: translateX(-40px); }
.js [data-reveal="right"] { transform: translateX(40px); }
.js [data-reveal="zoom"]  { transform: scale(0.94); }
.js [data-reveal].is-revealed { opacity: 1; transform: none; }

/* Hero headline words (split by animations.js) */
.js .hero__title .word {
  opacity: 0;
  animation: word-in 0.9s var(--ease-out) forwards;
  animation-delay: calc(0.25s + var(--i, 0) * 0.08s);
  transform-origin: 50% 100%;
}

/* Hero entrance */
.hero__content > *:not(.hero__title) { animation: fade-up 0.9s var(--ease-out) both; }
.hero__content > *:nth-child(1) { animation-delay: 0.1s; }
.hero__content > *:nth-child(3) { animation-delay: 0.7s; }
.hero__content > *:nth-child(4) { animation-delay: 0.85s; }
.hero__content > *:nth-child(5) { animation-delay: 1s; }
.hero__visual { animation: fade-up 1.1s var(--ease-out) 0.4s both; }

.caret { animation: blink 1s steps(1) infinite; }

/* Portrait */
.portrait__frame::before { animation: rotate-angle 6s linear infinite; }
.portrait__chip--a { animation: float 6s ease-in-out infinite; }
.portrait__chip--b { animation: float 7s ease-in-out -2s infinite; }

/* Background */
.bg-orb--1 { animation: orb-drift 18s ease-in-out infinite; }
.bg-orb--2 { animation: orb-drift 22s ease-in-out -6s infinite reverse; }

/* CSS 3D shapes */
.cube { animation: cube-spin 18s linear infinite; }
.shape--ring { animation: ring-tilt 24s linear infinite; }
.shape--orb { animation: orb-pulse 7s ease-in-out infinite; }
.shape--diamond { animation: float-soft 6s ease-in-out infinite; }
.shape--cube { animation: float-soft 8s ease-in-out infinite; }

.marquee__track { animation: marquee 40s linear infinite; }
.marquee:hover .marquee__track { animation-play-state: paused; }

.scroll-cue__line::after { animation: scroll-cue 2s var(--ease-io) infinite; }

.error-code::before { animation: glitch-a 4s infinite; color: var(--c-sky); }
.error-code::after { animation: glitch-a 4s 0.15s infinite reverse; }

/* ==========================================================================
   REDUCED MOTION — respect the user's OS setting
   ========================================================================== */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    animation-delay: 0s !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
  .js [data-reveal] { opacity: 1; transform: none; }
  .js .hero__title .word { opacity: 1; }
  .marquee__track { animation: none !important; }
  .page-transition { display: none; }
  [data-tilt] { transform: none !important; }
}
