/* =============================================
   CMM — Animations
   Entrance effects, loading overlay, micro-interactions
   Respects prefers-reduced-motion
   ============================================= */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ========== Welcome / Loading Overlay ========== */
.welcome-loader {
  position: fixed;
  inset: 0;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  z-index: 10000;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #0c1222 0%, #1e2a47 60%, #1a2540 100%);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.4s cubic-bezier(0.4, 0, 0.2, 1), visibility 0.4s, filter 0.5s ease;
  pointer-events: none;
}

.welcome-loader.is-visible {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

.welcome-loader.is-complete {
  opacity: 0;
  visibility: hidden;
  filter: blur(6px);
  transform: scale(0.98);
  transition: opacity 0.5s ease-out, visibility 0.5s, filter 0.5s ease, transform 0.5s ease;
}

.welcome-loader__logo {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 80px;
  height: 80px;
  margin-bottom: 1.5rem;
}

.welcome-loader__logo img {
  width: 80px;
  height: 80px;
  aspect-ratio: 1;
  display: block;
  border-radius: 50%;
  object-fit: cover;
  filter: drop-shadow(0 0 12px rgba(34, 211, 238, 0.25));
}

.welcome-loader__text {
  font-family: 'Outfit', system-ui, sans-serif;
  font-size: clamp(1.5rem, 4vw, 2.25rem);
  font-weight: 600;
  color: #ffffff;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  opacity: 0;
  transform: translateY(8px);
  animation: loaderTextSlide 0.6s cubic-bezier(0.4, 0, 0.2, 1) 0.55s forwards;
}

.welcome-loader__subtitle {
  font-family: 'Literata', Georgia, serif;
  font-size: 0.9375rem;
  color: #94a3b8;
  margin-top: 0.5rem;
  opacity: 0;
  transform: translateY(6px);
  animation: loaderTextSlide 0.5s cubic-bezier(0.4, 0, 0.2, 1) 0.75s forwards;
}

.welcome-loader__bar {
  width: 140px;
  height: 4px;
  margin-top: 2rem;
  background: rgba(34, 211, 238, 0.15);
  border-radius: 2px;
  overflow: hidden;
  opacity: 0;
  animation: loaderFadeIn 0.4s ease-out 0.9s forwards;
}

.welcome-loader__bar-fill {
  width: 0;
  height: 100%;
  background: linear-gradient(90deg, #22d3ee, #67e8f9);
  border-radius: 2px;
  animation: loaderBar 1.6s cubic-bezier(0.4, 0, 0.2, 1) 1.1s forwards;
}

@keyframes loaderPathDraw {
  to { stroke-dashoffset: 0; }
}

@keyframes loaderTextReveal {
  to {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes loaderTextSlide {
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes loaderFadeIn {
  to { opacity: 1; }
}

@keyframes loaderBar {
  to { width: 100%; }
}

/* Page hero entrance (inner pages) */
.page-hero h1 { animation: slideUp 0.6s ease-out 0.1s both; }
.page-hero p { animation: slideUp 0.6s ease-out 0.2s both; }

/* ========== Page entrance animations (responsive-first) ========== */
.animate-on-scroll {
  opacity: 0;
  transform: translateY(clamp(12px, 3vw, 24px));
  transition: opacity 0.5s cubic-bezier(0.4, 0, 0.2, 1), transform 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

.animate-on-scroll.is-visible {
  opacity: 1;
  transform: translateY(0);
}

/* Stagger children when section becomes visible */
.animate-on-scroll.is-visible .links-grid .link-card { animation: slideUp 0.45s cubic-bezier(0.4, 0, 0.2, 1) forwards; }
.animate-on-scroll .links-grid .link-card { opacity: 0; }
.animate-on-scroll.is-visible .links-grid .link-card:nth-child(1) { animation-delay: 0.05s; }
.animate-on-scroll.is-visible .links-grid .link-card:nth-child(2) { animation-delay: 0.1s; }
.animate-on-scroll.is-visible .links-grid .link-card:nth-child(3) { animation-delay: 0.15s; }
.animate-on-scroll.is-visible .links-grid .link-card:nth-child(4) { animation-delay: 0.2s; }

/* Services cards use animate-from-left/right (see HTML) */
.animate-on-scroll .services__grid .card { opacity: 0; }
.animate-on-scroll.is-visible .services__grid .card:nth-child(1) { transition-delay: 0.05s; }
.animate-on-scroll.is-visible .services__grid .card:nth-child(2) { transition-delay: 0.15s; }
.animate-on-scroll.is-visible .services__grid .card:nth-child(3) { transition-delay: 0.25s; }

.animate-fade-in { animation: fadeIn 0.6s ease-out forwards; }
.animate-slide-up { animation: slideUp 0.6s ease-out forwards; }
.animate-stagger > * { animation: slideUp 0.5s ease-out forwards; }
.animate-stagger > *:nth-child(1) { animation-delay: 0.1s; }
.animate-stagger > *:nth-child(2) { animation-delay: 0.15s; }
.animate-stagger > *:nth-child(3) { animation-delay: 0.2s; }
.animate-stagger > *:nth-child(4) { animation-delay: 0.25s; }
.animate-stagger > *:nth-child(5) { animation-delay: 0.3s; }

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(16px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Hero entrance (index) */
.hero__content .hero__logo { animation: heroLogoIn 1s ease-out 0.2s both; }
.hero__content .hero__title { animation: slideUp 0.7s ease-out 0.4s both; }
.hero__content .hero__tagline { animation: slideUp 0.7s ease-out 0.6s both; }

@keyframes heroLogoIn {
  from {
    opacity: 0;
    transform: scale(0.9);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

/* ========== Parallax hero background ========== */
.hero__bg {
  will-change: transform;
  transform: translateY(calc(var(--scroll, 0) * 0.02px));
  transition: transform 0.1s linear;
}

/* ========== Alternating slide-in reveals ========== */
.animate-from-left {
  opacity: 0;
  transform: translateX(-30px);
  transition: opacity 0.5s cubic-bezier(0.4, 0, 0.2, 1), transform 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}
.animate-from-right {
  opacity: 0;
  transform: translateX(30px);
  transition: opacity 0.5s cubic-bezier(0.4, 0, 0.2, 1), transform 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}
.animate-on-scroll.is-visible .animate-from-left,
.animate-on-scroll.is-visible .animate-from-right {
  opacity: 1;
  transform: translateX(0);
}
.animate-on-scroll.is-visible .animate-from-left:nth-child(1) { transition-delay: 0.05s; }
.animate-on-scroll.is-visible .animate-from-left:nth-child(2) { transition-delay: 0.15s; }
.animate-on-scroll.is-visible .animate-from-right:nth-child(1) { transition-delay: 0.1s; }
.animate-on-scroll.is-visible .animate-from-right:nth-child(2) { transition-delay: 0.2s; }

/* ========== Section heading underline draw ========== */
.section h2,
.services .services__title,
.social-callout h2,
.contact-callout h2 {
  position: relative;
}
.section h2::after,
.services .services__title::after,
.social-callout h2::after,
.contact-callout h2::after {
  content: '';
  position: absolute;
  bottom: -0.35em;
  left: 0;
  width: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--cyan), var(--cyan-dim));
  border-radius: 2px;
  transition: width 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}
.animate-on-scroll.is-visible .section h2::after,
.animate-on-scroll.is-visible .services .services__title::after,
.animate-on-scroll.is-visible .social-callout h2::after,
.animate-on-scroll.is-visible .contact-callout h2::after {
  width: 100%;
}

/* Staggered social icons */
.animate-on-scroll .social-links a {
  opacity: 0;
  transform: translateY(12px);
  transition: opacity 0.4s cubic-bezier(0.4, 0, 0.2, 1), transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}
.animate-on-scroll.is-visible .social-links a:nth-child(1) { opacity: 1; transform: translateY(0); transition-delay: 0.1s; }
.animate-on-scroll.is-visible .social-links a:nth-child(2) { opacity: 1; transform: translateY(0); transition-delay: 0.2s; }
.animate-on-scroll.is-visible .social-links a:nth-child(3) { opacity: 1; transform: translateY(0); transition-delay: 0.3s; }

/* Link card scale on hover */
.link-card:hover {
  transform: translateY(-4px) scale(1.02);
}
.social-link:hover {
  transform: translateY(-2px) scale(1.02);
}

/* Link card hover lift */
.link-card:hover .link-card__arrow {
  transform: translateX(4px);
}
.link-card__arrow {
  transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Button micro-interaction */
.btn--primary:active,
.btn--outline:active {
  transform: scale(0.98);
}

/* Focus-visible for keyboard UX (responsive-safe) */
a:focus-visible,
button:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 2px;
}

/* Reduced tap delay on touch devices */
@media (hover: none) {
  .link-card, .social-link, .card .btn--dark {
    transition-duration: 0.2s;
  }

  /* Touch-active feedback for immediate tactile response */
  .link-card:active,
  .social-link:active,
  .card .btn--dark:active,
  .nav__toggle:active,
  .scroll-top:active {
    transform: scale(0.97);
  }
}
