/* Scroll-driven Entry and Exit Animations based on Modern Web Guidance */

@media (prefers-reduced-motion: no-preference) {
  /* Only apply if the browser supports animation-timeline: view() and partial polyfill ranges */
  @supports ((animation-timeline: view()) and (animation-range: entry)) {
    
    @keyframes fade-in-up {
      from {
        opacity: 0;
        transform: translateY(40px);
      }
      to {
        opacity: 1;
        transform: translateY(0);
      }
    }

    @keyframes scale-up {
      from {
        opacity: 0;
        scale: 0.9;
      }
      to {
        opacity: 1;
        scale: 1;
      }
    }

    /* Animate on Scroll Entry classes */
    .animate-on-scroll {
      animation: fade-in-up auto ease-out backwards;
      animation-timeline: view();
      /* Run animation from when element enters scrollport until it is 20% in */
      animation-range: entry 0% cover 20%;
    }

    .animate-on-scroll-scale {
      animation: scale-up auto ease-out backwards;
      animation-timeline: view();
      animation-range: entry 0% cover 25%;
    }

    /* Staggered cards effect on grid */
    .stagger-scroll > *:nth-child(1) { animation-range: entry 0% cover 20%; }
    .stagger-scroll > *:nth-child(2) { animation-range: entry 5% cover 25%; }
    .stagger-scroll > *:nth-child(3) { animation-range: entry 10% cover 30%; }
    .stagger-scroll > *:nth-child(4) { animation-range: entry 15% cover 35%; }
    .stagger-scroll > *:nth-child(5) { animation-range: entry 20% cover 40%; }
    .stagger-scroll > *:nth-child(6) { animation-range: entry 25% cover 45%; }
  }

  /* Regular CSS animations for initial load */
  @keyframes hero-fade {
    0% { opacity: 0; transform: translateY(20px); }
    100% { opacity: 1; transform: translateY(0); }
  }
  
  .animate-hero {
    animation: hero-fade 0.8s ease-out both;
  }
  .animate-hero-delay-1 {
    animation: hero-fade 0.8s ease-out 0.2s both;
  }
  .animate-hero-delay-2 {
    animation: hero-fade 0.8s ease-out 0.4s both;
  }

  /* Micro interactions */
  @keyframes float {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-10px); }
  }
  .animate-float {
    animation: float 6s ease-in-out infinite;
  }

  @keyframes pulse-glow {
    0%, 100% { box-shadow: 0 0 15px rgba(59, 130, 246, 0.4); }
    50% { box-shadow: 0 0 30px rgba(59, 130, 246, 0.8); }
  }
  .animate-pulse-glow {
    animation: pulse-glow 3s infinite;
  }
}

/* Initial hidden state for the JS fallback observer */
.js-fallback-hidden {
  opacity: 0;
  transform: translateY(40px);
  transition: opacity 0.6s ease-out, transform 0.6s ease-out;
}
.js-fallback-hidden.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.js-fallback-hidden-scale {
  opacity: 0;
  transform: scale(0.9);
  transition: opacity 0.6s ease-out, transform 0.6s ease-out;
}
.js-fallback-hidden-scale.is-visible {
  opacity: 1;
  transform: scale(1);
}

/* ============================================================
   INTRO / SPLASH SCREEN  (GPU-optimised, zero-repaint)
   ============================================================ */

/* Overlay \u2014 always dark regardless of theme */
.intro-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #0a0e1a !important;
  overflow: hidden;
  /* contain tells the browser the overlay is an isolated painting scope */
  contain: layout style;
  /* Exit: opacity-only \u2014 avoids forcing a composite of every child */
  transition: opacity 0.7s cubic-bezier(0.4, 0, 0.2, 1),
              visibility 0.7s;
  will-change: opacity;
}

.intro-overlay.is-hidden {
  opacity: 0;
  pointer-events: none;
  visibility: hidden;
}

/* ── Grid background ───────────────────────────────────────────
   Animate a pseudo-element overlay instead of the element itself
   so the background-image never triggers a repaint on every tick.
────────────────────────────────────────────────────────────── */
.intro-bg-grid {
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(59, 130, 246, 0.08) 1px, transparent 1px),
    linear-gradient(90deg, rgba(59, 130, 246, 0.08) 1px, transparent 1px);
  background-size: 48px 48px;
  /* The grid itself stays static \u2014 no repaint */
}
.intro-bg-grid::after {
  content: '';
  position: absolute;
  inset: 0;
  background: inherit;
  animation: intro-grid-pulse 3s ease-in-out infinite;
  will-change: opacity;
}

@keyframes intro-grid-pulse {
  0%, 100% { opacity: 0.5; }
  50%       { opacity: 1;   }
}

/* ── Glow burst ────────────────────────────────────────────── */
.intro-glow-burst {
  position: absolute;
  width: 600px;
  height: 600px;
  border-radius: 50%;
  background: radial-gradient(
    circle,
    rgba(59, 130, 246, 0.22) 0%,
    rgba(99, 102, 241, 0.13) 40%,
    transparent 70%
  );
  /* transform + opacity are compositor-only \u2014 zero repaint */
  animation: intro-glow-expand 2s cubic-bezier(0.22, 1, 0.36, 1) forwards;
  pointer-events: none;
  will-change: transform, opacity;
}

@keyframes intro-glow-expand {
  from { transform: scale(0.4); opacity: 0; }
  to   { transform: scale(1);   opacity: 1; }
}

/* ── Content wrapper ───────────────────────────────────────── */
.intro-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2rem;
  position: relative;
  z-index: 1;
  will-change: transform, opacity;
}

/* ── Logo wrapper + rings ──────────────────────────────────── */
.intro-logo-wrapper {
  position: relative;
  width: 120px;
  height: 120px;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: intro-logo-pop 0.7s cubic-bezier(0.34, 1.56, 0.64, 1) 0.3s both;
  will-change: transform, opacity;
}

@keyframes intro-logo-pop {
  from { opacity: 0; transform: scale(0.5); }
  to   { opacity: 1; transform: scale(1);   }
}

/* Each ring gets its own GPU layer via will-change: transform */
.intro-logo-ring {
  position: absolute;
  border-radius: 50%;
  border: 1.5px solid transparent;
  /* Pre-promote to compositor layer \u2014 spin is now zero-cost */
  will-change: transform;
  /* Force layer creation before animation starts */
  transform: rotate(0deg);
}

.intro-logo-ring-1 {
  width: 100%;
  height: 100%;
  border-top-color: rgba(59, 130, 246, 0.75);
  border-right-color: rgba(59, 130, 246, 0.2);
  animation: intro-spin 2.4s linear infinite;
}

.intro-logo-ring-2 {
  width: 132%;
  height: 132%;
  border-bottom-color: rgba(99, 102, 241, 0.65);
  border-left-color: rgba(99, 102, 241, 0.15);
  animation: intro-spin 3.6s linear infinite reverse;
}

.intro-logo-ring-3 {
  width: 164%;
  height: 164%;
  border-top-color: rgba(168, 85, 247, 0.38);
  border-right-color: rgba(168, 85, 247, 0.1);
  animation: intro-spin 5.2s linear infinite;
}

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

/* ── Logo icon ─────────────────────────────────────────────── */
.intro-logo-icon {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: linear-gradient(135deg, rgba(30, 41, 59, 0.95), rgba(15, 23, 42, 0.98));
  border: 1px solid rgba(99, 102, 241, 0.4);
  /* box-shadow is GPU-friendly; drop-shadow filter is NOT */
  box-shadow:
    0 0 0 1px rgba(59, 130, 246, 0.12),
    0 0 24px rgba(59, 130, 246, 0.35),
    0 0 48px rgba(99, 102, 241, 0.15),
    inset 0 1px 0 rgba(255,255,255,0.06);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1;
}

.intro-logo-icon img {
  width: 38px;
  height: 38px;
  /* No filter: drop-shadow here \u2014 it causes per-frame GPU texture upload */
}

/* ── Title block ───────────────────────────────────────────── */
.intro-title-block {
  text-align: center;
  animation: intro-title-rise 0.8s cubic-bezier(0.22, 1, 0.36, 1) 1.1s both;
  will-change: transform, opacity;
}

@keyframes intro-title-rise {
  from { opacity: 0; transform: translateY(20px); }
  to   { opacity: 1; transform: translateY(0);    }
}

.intro-title {
  font-family: 'Inter', system-ui, sans-serif;
  font-size: clamp(3rem, 8vw, 5.5rem);
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1;
  margin: 0 0 0.5rem 0;
  background: linear-gradient(
    135deg,
    #e2e8f0 0%,
    #93c5fd 40%,
    #818cf8 70%,
    #c084fc 100%
  );
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.intro-tagline {
  font-family: 'Inter', system-ui, sans-serif;
  font-size: clamp(0.85rem, 2vw, 1.05rem);
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgba(148, 163, 184, 0.75);
  margin: 0;
  animation: intro-tagline-fade 0.8s ease-out 1.7s both;
  will-change: opacity, transform;
}

@keyframes intro-tagline-fade {
  /* opacity + translateY only — letter-spacing triggers layout reflow every frame */
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0);    }
}

/* ── Loader bar ────────────────────────────────────────────────
   Use scaleX instead of width: width change triggers layout
   recalculation every single frame on the main thread.
   scaleX is a pure compositor operation \u2014 60 fps guaranteed.
────────────────────────────────────────────────────────────── */
.intro-loader {
  width: 180px;
  height: 2px;
  background: rgba(255,255,255,0.07);
  border-radius: 999px;
  overflow: hidden;
  animation: intro-loader-appear 0.4s ease 2.0s both;
}

@keyframes intro-loader-appear {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.intro-loader-bar {
  height: 100%;
  width: 100%;                /* always full width now */
  border-radius: 999px;
  background: linear-gradient(90deg, #3b82f6, #818cf8, #c084fc);
  transform: scaleX(0);
  transform-origin: left center;
  /* scaleX = compositor-only, zero layout cost */
  animation: intro-loader-fill 2.2s cubic-bezier(0.4, 0, 0.2, 1) 2.2s forwards;
  will-change: transform;
}

@keyframes intro-loader-fill {
  from { transform: scaleX(0); }
  to   { transform: scaleX(1); }
}

/* Prevent scroll + prevent light-mode flash while intro is visible */
html:has(body.intro-active),
body.intro-active {
  overflow: hidden;
  background-color: #0a0e1a !important;
}
