/* ============================================
   Animations — Gradient, PJD morph, grain, reveals
   ============================================ */

/* ---- Register gradient color properties for smooth interpolation ---- */
@property --grad-color-1 {
  syntax: '<color>';
  initial-value: #1a0a2e;
  inherits: false;
}

@property --grad-color-2 {
  syntax: '<color>';
  initial-value: #0d1b3e;
  inherits: false;
}

@property --grad-color-3 {
  syntax: '<color>';
  initial-value: #1a1040;
  inherits: false;
}

@property --grad-color-4 {
  syntax: '<color>';
  initial-value: #0a1628;
  inherits: false;
}

/* ---- Morphing Gradient Background ---- */

.hero__bg {
  position: absolute;
  inset: 0;
  z-index: 0;
  background:
    radial-gradient(ellipse at 25% 15%, var(--grad-color-1) 0%, transparent 50%),
    radial-gradient(ellipse at 75% 85%, var(--grad-color-2) 0%, transparent 50%),
    radial-gradient(ellipse at 50% 50%, var(--grad-color-3) 0%, transparent 60%),
    var(--grad-color-4);
  animation: morphGradient var(--duration-gradient) ease-in-out infinite alternate;
}

@keyframes morphGradient {
  0% {
    --grad-color-1: #1a0a2e;
    --grad-color-2: #0d1b3e;
    --grad-color-3: #1a1040;
    --grad-color-4: #0a1628;
  }
  33% {
    --grad-color-1: #0d1b3e;
    --grad-color-2: #1a1040;
    --grad-color-3: #12082a;
    --grad-color-4: #1a0a2e;
  }
  66% {
    --grad-color-1: #1a1040;
    --grad-color-2: #0a1628;
    --grad-color-3: #1a0a2e;
    --grad-color-4: #12082a;
  }
  100% {
    --grad-color-1: #0a1628;
    --grad-color-2: #1a0a2e;
    --grad-color-3: #12082a;
    --grad-color-4: #0d1b3e;
  }
}

/* Fallback for browsers without @property support */
@supports not (background: paint(id)) {
  .hero__bg {
    background: linear-gradient(
      -45deg,
      #1a0a2e,
      #0d1b3e,
      #1a1040,
      #0a1628,
      #12082a
    );
    background-size: 400% 400%;
    animation: gradientShift 20s ease infinite;
  }
}

@keyframes gradientShift {
  0%   { background-position: 0% 50%; }
  50%  { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}

/* ---- PJD Hero Title — Stroke Draw-On Reveal ---- */

.hero__title {
  font-family: var(--font-display);
  font-size: var(--fs-hero);
  font-weight: var(--fw-light);
  line-height: 1.25;
  letter-spacing: 0.06em;
  padding-bottom: 0.05em;
  display: flex;
  justify-content: center;
  gap: 0;
  animation: glowPulse 6s ease-in-out 3.5s infinite alternate;
  filter: drop-shadow(0 0 40px rgba(139, 126, 200, 0.05));
}

/* Individual letter styling */
.hero__letter {
  display: inline-block;
  color: transparent;
  -webkit-text-stroke: 1.5px var(--color-accent);
  paint-order: stroke fill;
  opacity: 0;
}

/* After draw-on completes: animate class added by JS */
.hero__letter.drawn {
  animation: strokeReveal 2s var(--ease-out-expo) forwards;
}

.hero__letter.drawn:nth-child(1) { animation-delay: 0s; }
.hero__letter.drawn:nth-child(2) { animation-delay: 0.4s; }
.hero__letter.drawn:nth-child(3) { animation-delay: 0.8s; }

@keyframes strokeReveal {
  0% {
    opacity: 0;
    -webkit-text-stroke-color: transparent;
    color: transparent;
    transform: translateY(10px);
    filter: blur(4px);
  }
  30% {
    opacity: 1;
    -webkit-text-stroke-color: var(--color-accent);
    color: transparent;
    transform: translateY(0);
    filter: blur(0px);
  }
  60% {
    opacity: 1;
    -webkit-text-stroke-color: var(--color-accent);
    color: transparent;
    filter: blur(0px);
  }
  100% {
    opacity: 1;
    -webkit-text-stroke-color: transparent;
    color: var(--color-text-primary);
    transform: translateY(0);
    filter: blur(0px);
  }
}

/* Post-reveal: subtle gradient shimmer on the filled letters */
.hero__letter.filled {
  opacity: 1;
  -webkit-text-stroke: 0;
  color: transparent;
  background: linear-gradient(
    120deg,
    var(--color-text-primary) 0%,
    var(--color-accent) 20%,
    rgba(196, 149, 106, 0.8) 40%,
    var(--color-text-primary) 55%,
    var(--color-accent) 70%,
    var(--color-text-primary) 100%
  );
  background-size: 300% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  animation: textGradientShift 12s ease-in-out infinite alternate;
  filter: blur(0px);
  transform: translateY(0);
}

@keyframes textGradientShift {
  0%   { background-position: 0% 50%; }
  100% { background-position: 100% 50%; }
}

@keyframes glowPulse {
  0%   { filter: drop-shadow(0 0 40px rgba(139, 126, 200, 0.1)); }
  50%  { filter: drop-shadow(0 0 80px rgba(139, 126, 200, 0.25)) drop-shadow(0 0 120px rgba(196, 149, 106, 0.1)); }
  100% { filter: drop-shadow(0 0 60px rgba(139, 126, 200, 0.15)); }
}

/* ---- Grain Overlay ---- */

.grain-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  pointer-events: none;
  opacity: var(--grain-opacity);
  background-image: url('../assets/noise.svg');
  background-repeat: repeat;
  mix-blend-mode: overlay;
}

/* ---- Scroll Reveal ---- */

.reveal {
  opacity: 0;
  transform: translateY(30px);
  transition:
    opacity var(--duration-reveal) var(--ease-out-expo),
    transform var(--duration-reveal) var(--ease-out-expo);
}

.reveal.revealed {
  opacity: 1;
  transform: translateY(0);
}

/* Staggered reveals for grid children */
.reveal:nth-child(2) { transition-delay: 0.1s; }
.reveal:nth-child(3) { transition-delay: 0.15s; }
.reveal:nth-child(4) { transition-delay: 0.2s; }
.reveal:nth-child(5) { transition-delay: 0.25s; }
.reveal:nth-child(6) { transition-delay: 0.3s; }
.reveal:nth-child(7) { transition-delay: 0.35s; }
.reveal:nth-child(8) { transition-delay: 0.4s; }

/* ---- Hero Scroll Hint ---- */

.hero__scroll-hint {
  position: absolute;
  bottom: var(--space-md);
  left: 50%;
  transform: translateX(-50%);
}

.hero__scroll-line {
  display: block;
  width: 2px;
  height: 72px;
  background: linear-gradient(to bottom, transparent, var(--color-text-muted));
  animation: scrollPulse 2s ease-in-out infinite;
}

@keyframes scrollPulse {
  0%, 100% { opacity: 0.5; transform: scaleY(0.6); transform-origin: top; }
  50%      { opacity: 1;   transform: scaleY(1);   transform-origin: top; }
}

/* ---- Ambient Floating Orbs (site-wide) ---- */

.ambient {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  overflow: hidden;
}

.ambient__orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(60px);
  opacity: 0;
  animation: orbFloat linear infinite;
}

.ambient__orb--1 {
  width: 600px;
  height: 600px;
  background: radial-gradient(circle, rgba(139, 126, 200, 0.35) 0%, transparent 70%);
  top: 10%;
  left: -10%;
  animation-duration: 35s;
  animation-name: orbDrift1;
}

.ambient__orb--2 {
  width: 500px;
  height: 500px;
  background: radial-gradient(circle, rgba(13, 27, 62, 0.45) 0%, transparent 70%);
  top: 40%;
  right: -5%;
  animation-duration: 28s;
  animation-name: orbDrift2;
}

.ambient__orb--3 {
  width: 450px;
  height: 450px;
  background: radial-gradient(circle, rgba(196, 149, 106, 0.25) 0%, transparent 70%);
  bottom: 20%;
  left: 20%;
  animation-duration: 32s;
  animation-name: orbDrift3;
}

.ambient__orb--4 {
  width: 700px;
  height: 700px;
  background: radial-gradient(circle, rgba(26, 10, 46, 0.4) 0%, transparent 70%);
  top: 60%;
  left: 50%;
  animation-duration: 40s;
  animation-name: orbDrift4;
}

.ambient__orb--5 {
  width: 400px;
  height: 400px;
  background: radial-gradient(circle, rgba(139, 126, 200, 0.2) 0%, transparent 70%);
  top: 80%;
  right: 20%;
  animation-duration: 25s;
  animation-name: orbDrift5;
}

@keyframes orbDrift1 {
  0%   { transform: translate(0, 0) scale(1);     opacity: 0.6; }
  25%  { transform: translate(15vw, 20vh) scale(1.1); opacity: 0.85; }
  50%  { transform: translate(5vw, 50vh) scale(0.9);  opacity: 0.5; }
  75%  { transform: translate(-10vw, 30vh) scale(1.2); opacity: 0.75; }
  100% { transform: translate(0, 0) scale(1);     opacity: 0.6; }
}

@keyframes orbDrift2 {
  0%   { transform: translate(0, 0) scale(1);       opacity: 0.5; }
  25%  { transform: translate(-20vw, -10vh) scale(1.15); opacity: 0.75; }
  50%  { transform: translate(-10vw, 15vh) scale(0.85);  opacity: 0.6; }
  75%  { transform: translate(5vw, -5vh) scale(1.1);   opacity: 0.85; }
  100% { transform: translate(0, 0) scale(1);       opacity: 0.5; }
}

@keyframes orbDrift3 {
  0%   { transform: translate(0, 0) scale(1);       opacity: 0.5; }
  33%  { transform: translate(20vw, -15vh) scale(1.2);  opacity: 0.75; }
  66%  { transform: translate(-5vw, -30vh) scale(0.9);  opacity: 0.6; }
  100% { transform: translate(0, 0) scale(1);       opacity: 0.5; }
}

@keyframes orbDrift4 {
  0%   { transform: translate(0, 0) scale(1);       opacity: 0.4; }
  25%  { transform: translate(-15vw, -20vh) scale(1.1); opacity: 0.65; }
  50%  { transform: translate(-25vw, 10vh) scale(0.8);  opacity: 0.5; }
  75%  { transform: translate(-5vw, -10vh) scale(1.15); opacity: 0.7; }
  100% { transform: translate(0, 0) scale(1);       opacity: 0.4; }
}

@keyframes orbDrift5 {
  0%   { transform: translate(0, 0) scale(1);       opacity: 0.45; }
  50%  { transform: translate(-15vw, -25vh) scale(1.3); opacity: 0.75; }
  100% { transform: translate(0, 0) scale(1);       opacity: 0.45; }
}

/* ---- Timeline Line Glow Pulse ---- */

@keyframes timelineGlow {
  0%, 100% { opacity: 0.3; }
  50%      { opacity: 0.6; }
}

/* ---- Section Title Subtle Gradient ---- */

.section__title {
  background: linear-gradient(
    90deg,
    var(--color-text-primary) 0%,
    var(--color-accent) 50%,
    var(--color-text-primary) 100%
  );
  background-size: 200% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  animation: sectionTitleShimmer 10s ease-in-out infinite alternate;
}

@keyframes sectionTitleShimmer {
  0%   { background-position: 0% 50%; }
  100% { background-position: 100% 50%; }
}

/* ---- Light Theme Overrides ---- */

[data-theme="light"] .hero__bg {
  animation-name: morphGradientLight;
}

@keyframes morphGradientLight {
  0% {
    --grad-color-1: #d8d0e8;
    --grad-color-2: #c8d4e8;
    --grad-color-3: #d0c8e0;
    --grad-color-4: #e0dce8;
  }
  33% {
    --grad-color-1: #c8d4e8;
    --grad-color-2: #d0c8e0;
    --grad-color-3: #e8e0d0;
    --grad-color-4: #d8d0e8;
  }
  66% {
    --grad-color-1: #d0c8e0;
    --grad-color-2: #e0dce8;
    --grad-color-3: #d8d0e8;
    --grad-color-4: #e8e0d0;
  }
  100% {
    --grad-color-1: #e0dce8;
    --grad-color-2: #d8d0e8;
    --grad-color-3: #e8e0d0;
    --grad-color-4: #c8d4e8;
  }
}

[data-theme="light"] .hero__title {
  filter: drop-shadow(0 0 40px rgba(107, 94, 170, 0.12));
}

[data-theme="light"] .hero__letter {
  -webkit-text-stroke-color: var(--color-accent);
}

[data-theme="light"] .hero__letter.filled {
  background: linear-gradient(
    120deg,
    var(--color-text-primary) 0%,
    var(--color-accent) 20%,
    var(--color-accent-warm) 40%,
    var(--color-text-primary) 55%,
    var(--color-accent) 70%,
    var(--color-text-primary) 100%
  );
  background-size: 300% 100%;
  -webkit-background-clip: text;
  background-clip: text;
}

[data-theme="light"] .ambient__orb--1 {
  background: radial-gradient(circle, rgba(107, 94, 170, 0.25) 0%, transparent 70%);
}

[data-theme="light"] .ambient__orb--2 {
  background: radial-gradient(circle, rgba(100, 130, 180, 0.3) 0%, transparent 70%);
}

[data-theme="light"] .ambient__orb--3 {
  background: radial-gradient(circle, rgba(160, 117, 72, 0.2) 0%, transparent 70%);
}

[data-theme="light"] .ambient__orb--4 {
  background: radial-gradient(circle, rgba(107, 94, 170, 0.2) 0%, transparent 70%);
}

[data-theme="light"] .ambient__orb--5 {
  background: radial-gradient(circle, rgba(100, 130, 180, 0.15) 0%, transparent 70%);
}

[data-theme="light"] .grain-overlay {
  mix-blend-mode: multiply;
}

/* ---- Theme Toggle Button ---- */

.theme-toggle {
  background: none;
  border: 1px solid var(--color-border);
  border-radius: 50%;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--color-text-muted);
  transition: color 0.3s ease, border-color 0.3s ease, transform 0.3s var(--ease-out-expo);
  padding: 0;
  flex-shrink: 0;
}

.theme-toggle:hover {
  color: var(--color-text-primary);
  border-color: var(--color-accent);
  transform: scale(1.1);
}

.theme-toggle svg {
  width: 18px;
  height: 18px;
  transition: transform 0.4s var(--ease-out-expo);
}

.theme-toggle:hover svg {
  transform: rotate(15deg);
}

.theme-toggle__icon--sun,
.theme-toggle__icon--moon {
  display: none;
}

/* Dark mode: show sun icon (to switch to light) */
:root .theme-toggle__icon--sun {
  display: block;
}

/* Light mode: show moon icon (to switch to dark) */
[data-theme="light"] .theme-toggle__icon--sun {
  display: none;
}

[data-theme="light"] .theme-toggle__icon--moon {
  display: block;
}

/* ---- Vibe Coded Toast ---- */

.toast {
  position: fixed;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: rgba(26, 10, 46, 0.9);
  border: 1px solid rgba(139, 126, 200, 0.25);
  border-radius: 8px;
  padding: 1rem 2rem;
  font-family: var(--font-body);
  font-size: var(--fs-body);
  font-weight: var(--fw-regular);
  color: var(--color-text-primary);
  z-index: 9998;
  opacity: 0;
  pointer-events: none;
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4), 0 0 20px rgba(139, 126, 200, 0.1);
  white-space: nowrap;
  transition: transform 0.6s var(--ease-out-expo), opacity 0.6s ease;
}

.toast--visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
  pointer-events: auto;
}

.toast--hiding {
  opacity: 0;
  transform: translateX(-50%) translateY(10px);
}

/* ---- Reduced Motion ---- */

@media (prefers-reduced-motion: reduce) {
  .reveal {
    opacity: 1;
    transform: none;
    transition: none;
  }

  .hero__title {
    animation: none;
    filter: none;
  }

  .hero__letter {
    opacity: 1;
    color: var(--color-text-primary);
    -webkit-text-stroke: 0;
    animation: none;
  }

  .hero__bg {
    animation: none;
  }

  .hero__scroll-line {
    animation: none;
    opacity: 0.5;
  }

  .ambient__orb {
    animation: none;
    opacity: 0.2;
  }

  .section__title {
    animation: none;
    -webkit-text-fill-color: var(--color-text-primary);
    background: none;
  }
}
