/* ========================================
   Animation Keyframes - Optimized
   ======================================== */

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translate3d(0, 30px, 0);
  }
  to {
    opacity: 1;
    transform: translate3d(0, 0, 0);
  }
}

@keyframes fadeInDown {
  from {
    opacity: 0;
    transform: translate3d(0, -30px, 0);
  }
  to {
    opacity: 1;
    transform: translate3d(0, 0, 0);
  }
}

@keyframes fadeInLeft {
  from {
    opacity: 0;
    transform: translate3d(-30px, 0, 0);
  }
  to {
    opacity: 1;
    transform: translate3d(0, 0, 0);
  }
}

@keyframes fadeInRight {
  from {
    opacity: 0;
    transform: translate3d(30px, 0, 0);
  }
  to {
    opacity: 1;
    transform: translate3d(0, 0, 0);
  }
}

@keyframes scaleIn {
  from {
    opacity: 0;
    transform: scale3d(0.9, 0.9, 1);
  }
  to {
    opacity: 1;
    transform: scale3d(1, 1, 1);
  }
}

@keyframes slideInUp {
  from {
    transform: translate3d(0, 100%, 0);
    visibility: visible;
  }
  to {
    transform: translate3d(0, 0, 0);
  }
}

@keyframes bounce {
  0%, 20%, 53%, 80%, 100% {
    animation-timing-function: cubic-bezier(0.215, 0.61, 0.355, 1);
    transform: translate3d(0, 0, 0);
  }
  40%, 43% {
    animation-timing-function: cubic-bezier(0.755, 0.05, 0.855, 0.06);
    transform: translate3d(0, -15px, 0);
  }
  70% {
    animation-timing-function: cubic-bezier(0.755, 0.05, 0.855, 0.06);
    transform: translate3d(0, -7px, 0);
  }
  90% {
    transform: translate3d(0, -2px, 0);
  }
}

@keyframes pulse {
  0% {
    transform: scale3d(1, 1, 1);
  }
  50% {
    transform: scale3d(1.05, 1.05, 1);
  }
  100% {
    transform: scale3d(1, 1, 1);
  }
}

@keyframes rotate {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

@keyframes shimmer {
  0% {
    background-position: -200% center;
  }
  100% {
    background-position: 200% center;
  }
}

@keyframes float {
  0% {
    transform: translate3d(0, 0, 0);
  }
  50% {
    transform: translate3d(0, -10px, 0);
  }
  100% {
    transform: translate3d(0, 0, 0);
  }
}

@keyframes glow {
  0% {
    box-shadow: 0 0 5px rgba(239, 68, 68, 0.2);
  }
  50% {
    box-shadow: 0 0 20px rgba(239, 68, 68, 0.4), 0 0 30px rgba(239, 68, 68, 0.2);
  }
  100% {
    box-shadow: 0 0 5px rgba(239, 68, 68, 0.2);
  }
}

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

@keyframes countUp {
  from {
    opacity: 0;
    transform: translate3d(0, 20px, 0) scale3d(0.8, 0.8, 1);
  }
  to {
    opacity: 1;
    transform: translate3d(0, 0, 0) scale3d(1, 1, 1);
  }
}

/* ========================================
   Scroll-triggered Animations
   ======================================== */

.animate-on-scroll {
  opacity: 0;
  transition: all 0.6s cubic-bezier(0.25, 0.46, 0.45, 0.94);
  will-change: opacity, transform;
}

.animate-on-scroll.animate {
  opacity: 1;
  will-change: auto;
}

/* Fade Animations */
.fade-up {
  transform: translate3d(0, 50px, 0);
}

.fade-up.animate {
  transform: translate3d(0, 0, 0);
}

.fade-down {
  transform: translate3d(0, -50px, 0);
}

.fade-down.animate {
  transform: translate3d(0, 0, 0);
}

.fade-left {
  transform: translate3d(-50px, 0, 0);
}

.fade-left.animate {
  transform: translate3d(0, 0, 0);
}

.fade-right {
  transform: translate3d(50px, 0, 0);
}

.fade-right.animate {
  transform: translate3d(0, 0, 0);
}

/* Scale Animations */
.scale-up {
  transform: scale3d(0.8, 0.8, 1);
}

.scale-up.animate {
  transform: scale3d(1, 1, 1);
}

/* ========================================
   Navigation Animations
   ======================================== */

.nav {
  animation: slideInFromTop 0.8s cubic-bezier(0.25, 0.46, 0.45, 0.94);
  transform: translateZ(0);
  backface-visibility: hidden;
}

@keyframes slideInFromTop {
  0% {
    transform: translate3d(0, -100px, 0);
    opacity: 0;
  }
  100% {
    transform: translate3d(0, 0, 0);
    opacity: 1;
  }
}

/* ========================================
   Button Animations
   ======================================== */

.btn {
  position: relative;
  overflow: hidden;
  transform: translate3d(0, 0, 0);
  transition: all 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94);
  backface-visibility: hidden;
}

.btn::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 5px;
  height: 5px;
  background: rgba(255, 255, 255, 0.5);
  opacity: 0;
  border-radius: 100%;
  transform: scale(1, 1) translate(-50%);
  transform-origin: 50% 50%;
}

@keyframes ripple {
  0% {
    transform: scale(0, 0);
    opacity: 1;
  }
  20% {
    transform: scale(25, 25);
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: scale(40, 40);
  }
}

.btn:focus:not(:active)::after {
  animation: ripple 1s ease-out;
}

/* ========================================
   Card Animations
   ======================================== */

.project-card,
.writeup-card,
.experience__item,
.cert-category {
  transition: all 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94);
  transform: translate3d(0, 0, 0);
  backface-visibility: hidden;
}

.project-card:hover,
.writeup-card:hover,
.experience__item:hover,
.cert-category:hover {
  transform: translate3d(0, -8px, 0);
}

/* ========================================
   Loading Animations
   ======================================== */

.loading-spinner {
  width: 40px;
  height: 40px;
  border: 4px solid var(--color-border);
  border-top: 4px solid var(--color-accent);
  border-radius: 50%;
  animation: rotate 1s linear infinite;
  transform: translateZ(0);
}

.loading-dots {
  display: inline-flex;
  gap: 4px;
}

.loading-dots span {
  width: 6px;
  height: 6px;
  background: var(--color-accent);
  border-radius: 50%;
  animation: bounce 1.4s infinite;
}

.loading-dots span:nth-child(2) {
  animation-delay: 0.2s;
}

.loading-dots span:nth-child(3) {
  animation-delay: 0.4s;
}

/* ========================================
   Skeleton Loading
   ======================================== */

.skeleton {
  position: relative;
  overflow: hidden;
  background: var(--color-surface);
}

.skeleton::after {
  content: '';
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  transform: translateX(-100%);
  background: linear-gradient(
    90deg,
    rgba(255, 255, 255, 0) 0,
    rgba(255, 255, 255, 0.2) 20%,
    rgba(255, 255, 255, 0.5) 60%,
    rgba(255, 255, 255, 0)
  );
  animation: skeleton-shimmer 2s infinite;
}

@keyframes skeleton-shimmer {
  100% {
    transform: translateX(100%);
  }
}

/* ========================================
   Hero Animations
   ======================================== */

.hero__content > * {
  animation: fadeInUp 0.8s cubic-bezier(0.25, 0.46, 0.45, 0.94) both;
  transform: translateZ(0);
}

.hero__badge { animation-delay: 0.1s; }
.hero__title { animation-delay: 0.2s; }
.hero__subtitle { animation-delay: 0.3s; }
.hero__description { animation-delay: 0.4s; }
.hero__cta { animation-delay: 0.5s; }
.hero__stats { animation-delay: 0.6s; }

.hero__visual {
  animation: fadeInRight 1s cubic-bezier(0.25, 0.46, 0.45, 0.94) 0.3s both;
}

.hero__image-container {
  animation: float 6s ease-in-out infinite;
  transform: translateZ(0);
  backface-visibility: hidden;
}

/* ========================================
   Staggered Animations
   ======================================== */

.stagger-animation > * {
  opacity: 0;
  transform: translate3d(0, 20px, 0);
  animation: fadeInUp 0.6s cubic-bezier(0.25, 0.46, 0.45, 0.94) both;
}

.stagger-animation > *:nth-child(1) { animation-delay: 0.1s; }
.stagger-animation > *:nth-child(2) { animation-delay: 0.2s; }
.stagger-animation > *:nth-child(3) { animation-delay: 0.3s; }
.stagger-animation > *:nth-child(4) { animation-delay: 0.4s; }
.stagger-animation > *:nth-child(5) { animation-delay: 0.5s; }
.stagger-animation > *:nth-child(6) { animation-delay: 0.6s; }
.stagger-animation > *:nth-child(7) { animation-delay: 0.7s; }
.stagger-animation > *:nth-child(8) { animation-delay: 0.8s; }

/* ========================================
   Theme Toggle Animation
   ======================================== */

.theme-toggle {
  transition: all 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

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

.theme-icon {
  display: block;
  transition: transform 0.5s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

/* ========================================
   Notification Animations
   ======================================== */

@keyframes slideInFromRight {
  0% {
    transform: translate3d(400px, 0, 0);
    opacity: 0;
  }
  100% {
    transform: translate3d(0, 0, 0);
    opacity: 1;
  }
}

@keyframes slideOutToRight {
  0% {
    transform: translate3d(0, 0, 0);
    opacity: 1;
  }
  100% {
    transform: translate3d(400px, 0, 0);
    opacity: 0;
  }
}

.notification {
  animation: slideInFromRight 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

.notification.removing {
  animation: slideOutToRight 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

/* ========================================
   Mobile Performance Optimizations
   ======================================== */

@media (max-width: 768px) {
  /* Reduce animation complexity on mobile */
  .hero__content > * {
    animation-duration: 0.4s;
  }
  
  .hero__image-container {
    animation: none;
  }
  
  /* Disable hover effects on touch devices */
  @media (hover: none) {
    .project-card:hover,
    .writeup-card:hover,
    .experience__item:hover,
    .cert-category:hover {
      transform: none;
    }
  }
  
  /* Simplify transforms */
  .btn:hover {
    transform: none;
  }
  
  .skill-tag:hover {
    transform: translateY(-1px);
  }
}

/* ========================================
   Reduced Motion Support
   ======================================== */

@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;
  }
  
  .hero__image-container {
    animation: none;
  }
  
  .animate-on-scroll {
    opacity: 1;
    transform: none;
  }
}

/* ========================================
   GPU Optimization Utilities
   ======================================== */

.gpu-accelerated {
  transform: translateZ(0);
  backface-visibility: hidden;
  perspective: 1000px;
}

.will-change-transform {
  will-change: transform;
}

.will-change-opacity {
  will-change: opacity;
}

.will-change-auto {
  will-change: auto;
}