/* Reset & base */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}
html, body {
  width: 100%;
  height: 100vh;
  background: black;
  overflow: hidden;
  cursor: default;
  touch-action: none;
  position: relative;
}

/* Stars container */
.stars {
  position: fixed;
  inset: 0;
  z-index: 1;
  transform-origin: center;
  transition: transform 0.3s ease;
}

/* Fullscreen canvas used during warp for high-performance streaks */
#warpCanvas {
  position: fixed;
  inset: 0;
  z-index: 2; /* above stars but below orb */
  display: none;
  opacity: 0;
  transition: opacity 400ms ease;
  pointer-events: none;
}

/* Warp zoom effect */
.stars.warp {
  /* longer, smoother warp to match canvas easing */
  animation: warpEffect 3.8s forwards;
}

/* Respect users who request reduced motion */
@media (prefers-reduced-motion: reduce) {
  .stars.warp { animation: none !important; }
  .twinkle { animation: none !important; }
  .orb, .orb::after { animation: none !important; }
}

/* Star streak animation */
.stars.warp .twinkle {
  /* animation properties (duration/delay) are set per-star in JS via inline styles */
  animation-name: stretchStar;
  animation-fill-mode: forwards;
  will-change: transform, opacity;
}

/* Use a pseudo-element for a smooth gradient overlay on each star so it can fade in/out */
.twinkle {
  position: absolute;
  background: white;
}
.twinkle::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, rgba(255,255,255,1) 0%, rgba(255,255,255,0.15) 100%);
  opacity: 0;
  transition: opacity 600ms ease;
  pointer-events: none;
  border-radius: inherit;
}
.stars.warp-enter {
  filter: blur(0.4px);
}
.stars.warp-enter .twinkle::before {
  opacity: 0.28; /* slight hint before full warp */
}
.stars.warp .twinkle::before {
  opacity: 1; /* full gradient during warp */
}

@keyframes warpEffect {
  0% {
    transform: scale(1) rotate(0deg);
    filter: blur(0px);
  }
  50% {
    transform: scale(2.5) rotate(12deg);
    filter: blur(1.5px);
  }
  100% {
    transform: scale(6) rotate(22deg);
    filter: blur(3px);
  }
}

@keyframes stretchStar {
  /* gather energy: subtle scale-up while stationary */
  0% {
    transform: translate(0, 0) rotate(var(--angle)) scale(1, 1);
    border-radius: 50%;
    opacity: 1;
  }
  15% {
    transform: translate(0, 0) rotate(var(--angle)) scale(1.1, 1);
    border-radius: 50%;
    opacity: 1;
  }
  /* hold gathered state briefly */
  25% {
    transform: translate(0, 0) rotate(var(--angle)) scale(1.05, 1);
    border-radius: 50%;
    opacity: 1;
  }
  /* begin stretching into a short line (slow, cinematic) */
  50% {
    transform: translate(calc(var(--tx) * 0.15), calc(var(--ty) * 0.15)) rotate(var(--angle)) scale(3, 1.05);
    border-radius: 8px;
    opacity: 0.95;
  }
  /* elongate further, flattening into a line (smooth progression) */
  75% {
    transform: translate(calc(var(--tx) * 0.5), calc(var(--ty) * 0.5)) rotate(var(--angle)) scale(9, 0.28);
    border-radius: 4px;
    opacity: 0.5;
  }
  /* near-final streak: almost transparent */
  90% {
    transform: translate(calc(var(--tx) * 0.85), calc(var(--ty) * 0.85)) rotate(var(--angle)) scale(11, 0.16);
    border-radius: 2px;
    opacity: 0.15;
  }
  /* full streak: long, thin, faded out */
  100% {
    transform: translate(var(--tx), var(--ty)) rotate(var(--angle)) scale(12, 0.14);
    border-radius: 2px;
    opacity: 0;
  }
}

/* Individual stars */
.twinkle {
  border-radius: 50%;
  opacity: 0;
  animation: fadeIn 2s ease-out forwards, twinkle 6s infinite ease-in-out;
  /* reduce heavy box-shadow for many elements to improve performance */
  box-shadow: 0 0 1px rgba(255, 255, 255, 0.2);
  will-change: transform, opacity;
  pointer-events: none;
}
/* Pause twinkle during warp so stretch is the only animation */
.stars.warp .twinkle {
  animation-play-state: paused;
}

/* Fade stars out during final gradient phase */
.stars.hide {
  opacity: 0;
  transition: opacity 2.5s ease-in-out;
}

/* Slightly reduce heavy blur/brightness during warp to help low-end GPUs */
.stars.warp { filter: saturate(1.05) blur(1px); }

@keyframes fadeIn {
  to { opacity: 1; }
}
@keyframes twinkle {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.2); }
}

@media (max-width: 600px) {
  .twinkle {
    width: 0.3px;
    height: 0.3px;
  }
}
@media (min-width: 601px) {
  .twinkle {
    width: 0.5px;
    height: 0.5px;
  }
}

/* Orb wrapper for mouse-follow */
.orb-wrapper {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 3;
}

/* Orb styling */
.orb {
  width: min(52vw, 300px);
  height: min(52vw, 300px);
  border-radius: 50%;
  background: radial-gradient(
    circle at 50% 50%,
    hsl(280, 100%, 15%) 0%,
    hsl(260, 100%, 30%) 30%,
    hsl(220, 100%, 50%) 60%,
    hsl(120, 100%, 70%) 85%,
    hsl(60, 100%, 90%) 100%
  );
  animation:
    hueShift 20s linear infinite,
    morph 16s ease-in-out infinite,
    glowPulse 10s ease-in-out infinite;
  filter: blur(1.5px) saturate(1.3);
  box-shadow:
    0 0 80px 40px rgba(255, 255, 255, 0.05),
    0 0 160px 80px rgba(255, 255, 255, 0.07);
  transition: filter 0.5s ease;
  position: relative;
  z-index: 3;
}

@media (max-width: 600px) {
  .orb {
    width: min(70vw, 280px);
    height: min(70vw, 280px);
    box-shadow:
      0 0 60px 30px rgba(255, 255, 255, 0.04),
      0 0 120px 60px rgba(255, 255, 255, 0.05);
    filter: blur(1px) saturate(1.25);
  }
}

/* Orb afterglow pulse */
.orb::after {
  content: '';
  position: absolute;
  width: 100%;
  height: 100%;
  background: inherit;
  border-radius: 50%;
  filter: blur(10px);
  opacity: 0.4;
  animation: pulse 3s infinite;
}

@media (max-width: 600px) {
  .orb::after {
    filter: blur(6px);
    opacity: 0.3;
  }
}

@keyframes pulse {
  0% { transform: scale(1); opacity: 0.4; }
  100% { transform: scale(1.3); opacity: 0; }
}

@keyframes hueShift {
  0% { filter: hue-rotate(0deg); }
  100% { filter: hue-rotate(360deg); }
}
@keyframes morph {
  0%, 100% { border-radius: 50%; }
  25% { border-radius: 51% 49% 52% 48%; }
  50% { border-radius: 49% 51% 48% 52%; }
  75% { border-radius: 52% 48% 51% 49%; }
}
@keyframes glowPulse {
  0%, 100% { filter: brightness(1); }
  50% { filter: brightness(1.05); }
}

/* Orb transform effects */
.orb.implode {
  animation: implode 1.3s cubic-bezier(0.42, 0, 1, 1) forwards;
}
.orb.zoom {
  animation: zoomIn 3s cubic-bezier(0.25, 0.46, 0.45, 0.94) forwards;
}

@keyframes implode {
  0% { transform: scale(1); opacity: 1; }
  100% { transform: scale(0.08); opacity: 0.6; }
}
@keyframes zoomIn {
  0% { transform: scale(0.08); opacity: 0.6; }
  15% { opacity: 0.7; }
  50% { opacity: 0.4; }
  80% { opacity: 0.1; }
  100% { transform: scale(100); opacity: 0; }
}

/* Lightfield overlay */
.lightfield {
  position: fixed;
  inset: 0;
  background: radial-gradient(
    circle at center,
    hsl(260, 100%, 15%) 0%,
    hsl(250, 100%, 30%) 30%,
    hsl(220, 100%, 50%) 60%,
    hsl(180, 100%, 70%) 85%,
    hsl(140, 100%, 90%) 100%
  );
  filter: blur(20px) saturate(1.3);
  animation: hueShift 20s linear infinite;
  opacity: 0;
  z-index: 0;
  pointer-events: none;
  transition: opacity 3s ease-in-out;
}
.lightfield.active {
  opacity: 1;
}

@media (max-width: 600px) {
  .lightfield {
    filter: blur(16px) saturate(1.2);
  }
}

/* Hide audio UI */
audio {
  display: none;
}