/* ===== ANIMATED BACKGROUND ===== */
@layer components {
  .animated-bg {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: -1;
    overflow: hidden;
    contain: layout style paint;
  }

  .floating-particles {
    position: absolute;
    width: 100%;
    height: 100%;
  }

  .particle {
    position: absolute;
    font-size: clamp(1.5rem, 3vw, 2.5rem);
    opacity: 0.08;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    will-change: transform, opacity;
    color: var(--color-primary);
    filter: blur(0.5px);
    transition: opacity var(--duration-300) var(--ease-out);
  }

  /* Dynamic particle positioning */
  .particle:nth-child(1) { 
    top: 10%; 
    left: 10%; 
    animation: float 20s ease-in-out infinite;
    animation-delay: 0s;
  }

  .particle:nth-child(2) { 
    top: 20%; 
    right: 15%; 
    animation: float 25s ease-in-out infinite;
    animation-delay: -5s;
  }

  .particle:nth-child(3) { 
    top: 60%; 
    left: 5%; 
    animation: float 18s ease-in-out infinite;
    animation-delay: -10s;
  }

  .particle:nth-child(4) { 
    bottom: 20%; 
    right: 10%; 
    animation: float 22s ease-in-out infinite;
    animation-delay: -15s;
  }

  .particle:nth-child(5) { 
    bottom: 10%; 
    left: 20%; 
    animation: float 30s ease-in-out infinite;
    animation-delay: -20s;
  }

  .particle:nth-child(6) { 
    top: 40%; 
    right: 25%; 
    animation: float 24s ease-in-out infinite;
    animation-delay: -25s;
  }

  .particle:nth-child(7) { 
    top: 80%; 
    left: 60%; 
    animation: float 28s ease-in-out infinite;
    animation-delay: -30s;
  }

  .particle:nth-child(8) { 
    bottom: 40%; 
    left: 80%; 
    animation: float 26s ease-in-out infinite;
    animation-delay: -35s;
  }

  .gradient-orb {
    position: absolute;
    border-radius: 50%;
    filter: blur(120px);
    opacity: 0.15;
    will-change: transform;
    contain: layout style paint;
    pointer-events: none;
  }

  .orb-1 {
    width: 400px;
    height: 400px;
    top: 15%;
    left: -15%;
    background: radial-gradient(circle, var(--color-primary) 0%, transparent 70%);
    animation: orb-drift 40s ease-in-out infinite;
    animation-delay: 0s;
  }

  .orb-2 {
    width: 500px;
    height: 500px;
    bottom: 5%;
    right: -20%;
    background: radial-gradient(circle, var(--color-accent-purple) 0%, transparent 70%);
    animation: orb-drift 50s ease-in-out infinite reverse;
    animation-delay: -15s;
  }

  .orb-3 {
    width: 300px;
    height: 300px;
    top: 55%;
    left: 45%;
    background: radial-gradient(circle, var(--color-accent-orange) 0%, transparent 70%);
    animation: orb-drift 35s ease-in-out infinite;
    animation-delay: -25s;
  }

  /* Mesh gradient overlay */
  .animated-bg::before {
    content: '';
    position: absolute;
    inset: 0;
    background: 
      radial-gradient(ellipse at 20% 20%, rgba(0, 255, 136, 0.05) 0%, transparent 50%),
      radial-gradient(ellipse at 80% 80%, rgba(157, 78, 221, 0.05) 0%, transparent 50%),
      radial-gradient(ellipse at 50% 50%, rgba(255, 107, 53, 0.03) 0%, transparent 50%);
    animation: mesh-shift 60s linear infinite;
  }

  /* Subtle noise texture */
  .animated-bg::after {
    content: '';
    position: absolute;
    inset: 0;
    background-image: 
      radial-gradient(circle, rgba(255, 255, 255, 0.01) 1px, transparent 1px);
    background-size: 30px 30px;
    background-position: 0 0, 15px 15px;
    opacity: 0.3;
    animation: noise-drift 120s linear infinite;
  }

  /* Animations */
  @keyframes float {
    0%, 100% {
      transform: translateY(0) translateX(0) rotate(0deg);
      opacity: 0.08;
    }
    25% {
      transform: translateY(-30px) translateX(20px) rotate(90deg);
      opacity: 0.12;
    }
    50% {
      transform: translateY(-10px) translateX(-15px) rotate(180deg);
      opacity: 0.06;
    }
    75% {
      transform: translateY(-40px) translateX(10px) rotate(270deg);
      opacity: 0.10;
    }
  }

  @keyframes orb-drift {
    0%, 100% {
      transform: translate(0, 0) scale(1);
    }
    25% {
      transform: translate(50px, -30px) scale(1.1);
    }
    50% {
      transform: translate(-30px, 40px) scale(0.9);
    }
    75% {
      transform: translate(20px, -20px) scale(1.05);
    }
  }

  @keyframes mesh-shift {
    0%, 100% {
      transform: translate(0, 0) rotate(0deg);
    }
    25% {
      transform: translate(30px, -20px) rotate(1deg);
    }
    50% {
      transform: translate(-20px, 30px) rotate(-1deg);
    }
    75% {
      transform: translate(15px, -15px) rotate(0.5deg);
    }
  }

  @keyframes noise-drift {
    0% { transform: translate(0, 0); }
    100% { transform: translate(60px, 60px); }
  }

  /* Performance optimization for mobile */
  @media (max-width: 768px) {
    .gradient-orb {
      filter: blur(80px);
      opacity: 0.1;
    }

    .particle:nth-child(n+6) {
      display: none;
    }

    .particle {
      font-size: clamp(1rem, 2vw, 1.5rem);
      opacity: 0.06;
    }

    .orb-1, .orb-2 {
      width: 300px;
      height: 300px;
    }

    .orb-3 {
      width: 200px;
      height: 200px;
    }

    /* Disable complex animations on mobile */
    .animated-bg::after {
      display: none;
    }
  }

  /* Ultra-low power mode */
  @media (max-width: 480px) {
    .gradient-orb {
      filter: blur(60px);
      opacity: 0.05;
    }

    .particle:nth-child(n+4) {
      display: none;
    }

    .animated-bg::before {
      opacity: 0.5;
    }
  }

  /* Respect user preferences */
  @media (prefers-reduced-motion: reduce) {
    .particle,
    .gradient-orb,
    .animated-bg::before,
    .animated-bg::after {
      animation-duration: 120s;
      animation-iteration-count: 1;
    }
  }

  /* High contrast mode */
  @media (prefers-contrast: high) {
    .particle {
      opacity: 0.02;
    }

    .gradient-orb {
      opacity: 0.05;
    }

    .animated-bg::before {
      opacity: 0.2;
    }
  }

  /* Battery saving mode */
  @media (prefers-reduced-data: reduce) {
    .animated-bg::after,
    .particle:nth-child(n+4),
    .orb-3 {
      display: none;
    }
  }
}