/* ==========================================================================
   ANIMATIONS.CSS — Atelier Polytech  ·  Keyframes & Animation Classes
   Dependencies: themes.css, style.css
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. SCROLL REVEAL  ·  Base + Directional Variants
   Elements start hidden, add .active via Intersection Observer in JS
   -------------------------------------------------------------------------- */
.reveal {
  opacity: 0;
  transform: translateY(40px);
  transition:
    opacity 0.7s cubic-bezier(0.4, 0, 0.2, 1),
    transform 0.7s cubic-bezier(0.4, 0, 0.2, 1);
  will-change: opacity, transform;
}

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

/* From left */
.reveal-left {
  opacity: 0;
  transform: translateX(-40px);
  transition:
    opacity 0.7s cubic-bezier(0.4, 0, 0.2, 1),
    transform 0.7s cubic-bezier(0.4, 0, 0.2, 1);
  will-change: opacity, transform;
}

.reveal-left.active {
  opacity: 1;
  transform: translateX(0);
}

/* From right */
.reveal-right {
  opacity: 0;
  transform: translateX(40px);
  transition:
    opacity 0.7s cubic-bezier(0.4, 0, 0.2, 1),
    transform 0.7s cubic-bezier(0.4, 0, 0.2, 1);
  will-change: opacity, transform;
}

.reveal-right.active {
  opacity: 1;
  transform: translateX(0);
}

/* Scale up */
.reveal-scale {
  opacity: 0;
  transform: scale(0.9);
  transition:
    opacity 0.7s cubic-bezier(0.4, 0, 0.2, 1),
    transform 0.7s cubic-bezier(0.4, 0, 0.2, 1);
  will-change: opacity, transform;
}

.reveal-scale.active {
  opacity: 1;
  transform: scale(1);
}

/* --------------------------------------------------------------------------
   2. STAGGER DELAYS  ·  .stagger-1 through .stagger-6
   Combine with .reveal (e.g. class="reveal stagger-2")
   -------------------------------------------------------------------------- */
.stagger-1 { transition-delay: 0.1s; }
.stagger-2 { transition-delay: 0.2s; }
.stagger-3 { transition-delay: 0.3s; }
.stagger-4 { transition-delay: 0.4s; }
.stagger-5 { transition-delay: 0.5s; }
.stagger-6 { transition-delay: 0.6s; }

/* --------------------------------------------------------------------------
   3. HERO TEXT REVEAL
   Slides text upward with a fade-in
   -------------------------------------------------------------------------- */
@keyframes heroTextReveal {
  0% {
    opacity: 0;
    transform: translateY(60px);
  }
  100% {
    opacity: 1;
    transform: translateY(0);
  }
}

.hero-text-reveal {
  animation: heroTextReveal 0.9s cubic-bezier(0.4, 0, 0.2, 1) forwards;
  opacity: 0; /* initial state before animation plays */
}

.hero-text-reveal--delay-1 { animation-delay: 0.15s; }
.hero-text-reveal--delay-2 { animation-delay: 0.3s; }
.hero-text-reveal--delay-3 { animation-delay: 0.5s; }
.hero-text-reveal--delay-4 { animation-delay: 0.7s; }

/* --------------------------------------------------------------------------
   4. FLOAT  ·  Subtle up-down for decorative elements
   -------------------------------------------------------------------------- */
@keyframes float {
  0%   { transform: translateY(0); }
  50%  { transform: translateY(-20px); }
  100% { transform: translateY(0); }
}

.float {
  animation: float 4s ease-in-out infinite;
  will-change: transform;
}

.float--slow  { animation-duration: 6s; }
.float--fast  { animation-duration: 2.5s; }

/* --------------------------------------------------------------------------
   5. SHIMMER  ·  Gradient sweep for accent elements
   -------------------------------------------------------------------------- */
@keyframes shimmer {
  0% {
    background-position: -200% center;
  }
  100% {
    background-position: 200% center;
  }
}

.shimmer {
  background: linear-gradient(
    90deg,
    var(--accent-dark) 0%,
    var(--accent-hover) 50%,
    var(--accent-dark) 100%
  );
  background-size: 200% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  animation: shimmer 3s ease-in-out infinite;
}

/* --------------------------------------------------------------------------
   6. PULSE GLOW  ·  CTA buttons
   -------------------------------------------------------------------------- */
@keyframes pulseGlow {
  0%   { box-shadow: 0 0 0 0 var(--accent-glow-strong); }
  50%  { box-shadow: 0 0 20px 6px var(--accent-glow); }
  100% { box-shadow: 0 0 0 0 var(--accent-glow-strong); }
}

.pulse-glow {
  animation: pulseGlow 2.5s ease-in-out infinite;
}

/* --------------------------------------------------------------------------
   7. COUNTER NUMBER  ·  Transition for counting animation
   Used with JS that updates the innerHTML. The CSS transition
   is on the wrapper for any transform-based effects.
   -------------------------------------------------------------------------- */
.counter-number {
  display: inline-block;
  transition: transform 0.3s ease;
}

.counter-number.counting {
  transform: scale(1.1);
}

/* --------------------------------------------------------------------------
   8. PARTICLE FLOAT  ·  Floating particles in hero background
   -------------------------------------------------------------------------- */
@keyframes particle-float {
  0% {
    transform: translate(0, 0) rotate(0deg);
    opacity: 0;
  }
  10% {
    opacity: 0.6;
  }
  90% {
    opacity: 0.6;
  }
  100% {
    transform: translate(var(--particle-dx, 120px), var(--particle-dy, -200px)) rotate(360deg);
    opacity: 0;
  }
}

.particle {
  position: absolute;
  width: var(--particle-size, 4px);
  height: var(--particle-size, 4px);
  border-radius: 50%;
  background: var(--accent);
  opacity: 0;
  pointer-events: none;
  animation: particle-float var(--particle-duration, 8s) linear infinite;
  animation-delay: var(--particle-delay, 0s);
  will-change: transform, opacity;
}

/* --------------------------------------------------------------------------
   9. CARD HOVER LIFT
   Smooth translateY(-8px) + enhanced shadow
   -------------------------------------------------------------------------- */
.card-lift {
  transition:
    transform 0.35s cubic-bezier(0.4, 0, 0.2, 1),
    box-shadow 0.35s ease;
  will-change: transform;
}

.card-lift:hover {
  transform: translateY(-8px);
  box-shadow: var(--shadow-lg), var(--shadow-glow);
}

/* --------------------------------------------------------------------------
   10. GRADIENT BORDER ANIMATION  ·  Rotating gradient border
   For featured cards — uses a pseudo-element trick
   -------------------------------------------------------------------------- */
@keyframes gradientBorderRotate {
  0%   { --border-angle: 0deg; }
  100% { --border-angle: 360deg; }
}

/* Fallback rotation via background-position */
@keyframes rotateBorder {
  0%   { background-position: 0% 50%; }
  50%  { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}

.gradient-border {
  position: relative;
  border: none !important;
  isolation: isolate;
}

.gradient-border::before {
  content: '';
  position: absolute;
  inset: -2px;
  border-radius: inherit;
  padding: 2px;
  background: linear-gradient(
    135deg,
    var(--accent),
    transparent 40%,
    transparent 60%,
    var(--accent-dark)
  );
  background-size: 300% 300%;
  animation: rotateBorder 4s ease infinite;
  -webkit-mask:
    linear-gradient(#fff 0 0) content-box,
    linear-gradient(#fff 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  z-index: -1;
  pointer-events: none;
}

/* --------------------------------------------------------------------------
   11. NAV LINK UNDERLINE  ·  Grows from center on hover
   (The transition itself is handled in style.css .navbar__link::after;
    this keyframe version is an alternative for more complex effects)
   -------------------------------------------------------------------------- */
@keyframes navUnderlineGrow {
  0% {
    width: 0;
    left: 50%;
  }
  100% {
    width: 100%;
    left: 0;
  }
}

/* --------------------------------------------------------------------------
   12. IMAGE ZOOM ON HOVER  ·  Smooth scale for gallery items
   -------------------------------------------------------------------------- */
.image-zoom {
  overflow: hidden;
}

.image-zoom img {
  transition: transform 0.55s cubic-bezier(0.4, 0, 0.2, 1);
  will-change: transform;
}

.image-zoom:hover img {
  transform: scale(1.08);
}

/* --------------------------------------------------------------------------
   13. TYPING CURSOR  ·  Blink animation
   -------------------------------------------------------------------------- */
@keyframes blink {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0; }
}

.typing-cursor::after {
  content: '|';
  display: inline-block;
  color: var(--accent);
  font-weight: 300;
  animation: blink 0.8s step-end infinite;
  margin-left: 2px;
}

/* --------------------------------------------------------------------------
   14. SPIN  ·  Loading states
   -------------------------------------------------------------------------- */
@keyframes spin {
  0%   { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

.spin {
  animation: spin 1s linear infinite;
}

.spinner {
  width: 28px;
  height: 28px;
  border: 3px solid var(--border-color);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

/* --------------------------------------------------------------------------
   15. SLIDE IN RIGHT  ·  Mobile navigation
   -------------------------------------------------------------------------- */
@keyframes slideInRight {
  0% {
    transform: translateX(100%);
    opacity: 0;
  }
  100% {
    transform: translateX(0);
    opacity: 1;
  }
}

.slide-in-right {
  animation: slideInRight 0.4s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

/* --------------------------------------------------------------------------
   16. INJECTION MOLDING ANIMATION STYLES
   SVG-based process animation for the molding cycle
   -------------------------------------------------------------------------- */

/* ── Container ── */
.molding-animation-container {
  position: relative;
  width: 100%;
  max-width: 800px;
  margin: 0 auto;
  aspect-ratio: 16 / 10;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 20px;
  overflow: hidden;
  box-shadow: var(--shadow-md);
}

.molding-animation-container svg {
  width: 100%;
  height: 100%;
}

/* Pause on hover */
.molding-animation-container:hover svg * {
  animation-play-state: paused !important;
}

/* ── Mold halves ── */
.mold-half-left,
.mold-half-right {
  fill: var(--bg-tertiary);
  stroke: var(--accent-dark);
  stroke-width: 1.5;
  transition: fill 0.3s ease;
}

/* ── Plastic flow element ── */
.plastic-flow {
  fill: #ff6b35;
  transform-origin: left center;
  opacity: 0;
}

/* ── Finished part ── */
.finished-part {
  fill: #94a3b8;
  opacity: 0;
}

/* ── Step labels (text inside SVG) ── */
.step-label {
  font-family: 'Inter', sans-serif;
  font-size: 11px;
  font-weight: 600;
  fill: var(--text-muted);
  text-anchor: middle;
  transition: fill 0.3s ease;
}

.step-label.active {
  fill: var(--accent);
}

/* ── Step indicator dots ── */
.step-indicator {
  display: flex;
  justify-content: center;
  gap: 0.8rem;
  padding: 1.2rem 0;
}

.step-indicator__dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--border-color);
  border: 1px solid var(--border-accent);
  transition: background-color 0.3s ease, transform 0.3s ease;
}

.step-indicator__dot.active {
  background: var(--accent);
  transform: scale(1.3);
  box-shadow: 0 0 10px var(--accent-glow);
}

/* ── Keyframes: Mold close ── */
@keyframes moldClose {
  0% {
    transform: translateX(var(--mold-open-offset, -30px));
  }
  100% {
    transform: translateX(0);
  }
}

/* ── Keyframes: Mold open ── */
@keyframes moldOpen {
  0% {
    transform: translateX(0);
  }
  100% {
    transform: translateX(var(--mold-open-offset, -30px));
  }
}

/* ── Keyframes: Plastic injection ── */
@keyframes plasticInject {
  0% {
    transform: scaleX(0);
    opacity: 1;
    fill: #ff6b35;
  }
  60% {
    transform: scaleX(1);
    fill: #ff6b35;
  }
  100% {
    transform: scaleX(1);
    opacity: 1;
    fill: #ff8c5a;
  }
}

/* ── Keyframes: Plastic cooling ── */
@keyframes plasticCool {
  0% {
    fill: #ff6b35;
  }
  40% {
    fill: #06b6d4;
  }
  100% {
    fill: #94a3b8;
  }
}

/* ── Keyframes: Part eject ── */
@keyframes partEject {
  0% {
    transform: translateY(0);
    opacity: 1;
  }
  40% {
    transform: translateY(-40px);
  }
  60% {
    transform: translateY(-35px); /* subtle bounce */
  }
  80% {
    transform: translateY(-45px);
  }
  100% {
    transform: translateY(-50px);
    opacity: 1;
  }
}

/* ── Keyframes: Full molding cycle (12s) ──
   Orchestrates the entire sequence:
   0%–8%    Mold closing
   8%–33%   Plastic injection
   33%–58%  Cooling (color transition)
   58%–66%  Mold opening
   66%–83%  Part ejection
   83%–100% Reset / idle
   ──────────────────────────────────────── */
@keyframes fullMoldingCycle {
  /* --- Mold close phase --- */
  0% {
    --mold-state: open;
    --plastic-opacity: 0;
    --part-opacity: 0;
  }
  8% {
    --mold-state: closed;
  }
  /* --- Injection phase --- */
  9% {
    --plastic-scale: 0;
    --plastic-opacity: 1;
    --plastic-color: #ff6b35;
  }
  33% {
    --plastic-scale: 1;
    --plastic-color: #ff6b35;
  }
  /* --- Cooling phase --- */
  45% {
    --plastic-color: #06b6d4;
  }
  58% {
    --plastic-color: #94a3b8;
  }
  /* --- Mold open phase --- */
  66% {
    --mold-state: open;
  }
  /* --- Eject phase --- */
  67% {
    --part-opacity: 1;
    --part-y: 0;
  }
  83% {
    --part-y: -50px;
  }
  /* --- Reset --- */
  90% {
    --plastic-opacity: 0;
    --part-opacity: 0;
  }
  100% {
    --mold-state: open;
    --plastic-opacity: 0;
    --part-opacity: 0;
  }
}

/* Apply full cycle to the SVG container */
.molding-animation-container--playing svg {
  animation: fullMoldingCycle 12s ease-in-out infinite;
}

/* Left mold half animation */
.molding-animation-container--playing .mold-half-left {
  animation: moldClose 0.96s ease-in-out forwards,
             moldOpen 0.96s ease-in-out 6.96s forwards;
  --mold-open-offset: -30px;
}

/* Right mold half animation (mirrored) */
.molding-animation-container--playing .mold-half-right {
  animation: moldClose 0.96s ease-in-out forwards,
             moldOpen 0.96s ease-in-out 6.96s forwards;
  --mold-open-offset: 30px;
}

/* Plastic flow animation */
.molding-animation-container--playing .plastic-flow {
  animation:
    plasticInject 3s ease-out 0.96s forwards,
    plasticCool 3s ease-in-out 3.96s forwards;
}

/* Part ejection animation */
.molding-animation-container--playing .finished-part {
  animation: partEject 2s cubic-bezier(0.34, 1.56, 0.64, 1) 7.92s forwards;
}

/* ── Process step cards beside the animation ── */
.process-step {
  position: relative;
}

.process-step::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  background: transparent;
  border-radius: 2px;
  transition: background-color 0.4s ease;
}

.process-step.active::before {
  background: var(--gradient-accent);
}

/* --------------------------------------------------------------------------
   17. PNG LOGO REFINED ANIMATION
   Smooth entrance, gentle continuous float, and subtle drop-shadow glow
   -------------------------------------------------------------------------- */
.logo-animated-img {
  height: 38px;
  width: auto;
  opacity: 0;
  transform: scale(0.85) translateY(10px);
  filter: drop-shadow(0 0 0 rgba(6, 182, 212, 0));
  transition: opacity 0.8s cubic-bezier(0.2, 0.8, 0.2, 1), transform 0.8s cubic-bezier(0.2, 0.8, 0.2, 1), filter 0.8s ease;
  will-change: transform, opacity, filter;
}

.logo-animated-img.logo-animate {
  opacity: 1;
  transform: scale(1) translateY(0);
  filter: drop-shadow(0 4px 12px rgba(6, 182, 212, 0.3));
  animation: logoRefinedFloat 5s ease-in-out 0.8s infinite alternate;
}

@keyframes logoRefinedFloat {
  0% {
    transform: scale(1) translateY(0);
    filter: drop-shadow(0 4px 12px rgba(6, 182, 212, 0.3));
  }
  100% {
    transform: scale(1.02) translateY(-3px);
    filter: drop-shadow(0 6px 18px rgba(6, 182, 212, 0.5));
  }
}

/* --------------------------------------------------------------------------
   18. PREFERS REDUCED MOTION
   Respects user's OS-level motion preferences
   -------------------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }

  .reveal,
  .reveal-left,
  .reveal-right,
  .reveal-scale {
    opacity: 1;
    transform: none;
  }

  .float,
  .shimmer,
  .pulse-glow,
  .spin,
  .particle {
    animation: none;
  }

  .card-lift:hover {
    transform: none;
  }

  .gradient-border::before {
    animation: none;
  }

  .molding-animation-container--playing svg,
  .molding-animation-container--playing .mold-half-left,
  .molding-animation-container--playing .mold-half-right,
  .molding-animation-container--playing .plastic-flow,
  .molding-animation-container--playing .finished-part {
    animation: none;
  }
}
