/* ===================================
   Smooth Page Transitions & Animations
   =================================== */

/* View Transitions API - Smooth fade */
::view-transition-old(root),
::view-transition-new(root) {
  animation-duration: 0.3s;
  animation-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
  mix-blend-mode: normal;
}

::view-transition-old(root) {
  animation-name: fade-out-content;
}

::view-transition-new(root) {
  animation-name: fade-in-content;
}

::view-transition-image-pair(root) {
  isolation: auto;
}

@keyframes fade-out-content {
  from {
    opacity: 1;
  }
  to {
    opacity: 0;
  }
}

@keyframes fade-in-content {
  from {
    opacity: 0;
    /* Remove transform to prevent shift */
  }
  to {
    opacity: 1;
  }
}

/* Preserve specific elements during transitions */
.fluid-gradient-container {
  view-transition-name: background;
}

/* Keep background always visible during transitions */
::view-transition-old(background),
::view-transition-new(background) {
  animation: none !important;
  opacity: 1 !important;
}

::view-transition-group(background) {
  animation-duration: 0s !important;
}

::view-transition-image-pair(background) {
  isolation: isolate;
}

.header {
  view-transition-name: header;
}

.main-nav {
  view-transition-name: navigation;
}

.footer {
  view-transition-name: footer;
}

/* Content Loading Animation */
.content-enter > *:not(.fluid-gradient-container):not(.menu-overlay) {
  /* animation: contentEnter 0.4s cubic-bezier(0.23, 1, 0.32, 1) forwards; */
  /* Disabled to prevent element flicker */
  opacity: 1;
}

/* Ensure FluidGradient stays fixed */
.fluid-gradient-container {
  animation: none !important;
  transform: none !important;
  position: fixed !important;
}

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

/* Staggered Content Animation */
.stagger-item {
  opacity: 0;
  transform: translateY(20px);
  animation: staggerIn 0.5s cubic-bezier(0.23, 1, 0.32, 1) forwards;
}

.stagger-item:nth-child(1) { animation-delay: 0.05s; }
.stagger-item:nth-child(2) { animation-delay: 0.1s; }
.stagger-item:nth-child(3) { animation-delay: 0.15s; }
.stagger-item:nth-child(4) { animation-delay: 0.2s; }
.stagger-item:nth-child(5) { animation-delay: 0.25s; }
.stagger-item:nth-child(6) { animation-delay: 0.3s; }
.stagger-item:nth-child(7) { animation-delay: 0.35s; }
.stagger-item:nth-child(8) { animation-delay: 0.4s; }
.stagger-item:nth-child(9) { animation-delay: 0.45s; }

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

/* Image Loading States */
.image-container {
  position: relative;
  overflow: hidden;
  background: linear-gradient(
    90deg,
    #f0f0f0 0%,
    #e0e0e0 50%,
    #f0f0f0 100%
  );
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
}

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

.image-loaded {
  animation: imageReveal 0.6s cubic-bezier(0.23, 1, 0.32, 1) forwards;
}

@keyframes imageReveal {
  from {
    opacity: 0;
    transform: scale(1.1);
    filter: blur(10px);
  }
  to {
    opacity: 1;
    transform: scale(1);
    filter: blur(0);
  }
}

/* Intersection Observer Animations */
.fade-up {
  opacity: 0;
  transform: translateY(20px);
  transition: opacity 0.4s ease-out,
              transform 0.4s ease-out;
}

.fade-up.visible {
  opacity: 1;
  transform: translateY(0);
}

.fade-left {
  opacity: 0;
  transform: translateX(40px);
  transition: opacity 0.8s cubic-bezier(0.23, 1, 0.32, 1),
              transform 0.8s cubic-bezier(0.23, 1, 0.32, 1);
}

.fade-left.visible {
  opacity: 1;
  transform: translateX(0);
}

.fade-right {
  opacity: 0;
  transform: translateX(-40px);
  transition: opacity 0.8s cubic-bezier(0.23, 1, 0.32, 1),
              transform 0.8s cubic-bezier(0.23, 1, 0.32, 1);
}

.fade-right.visible {
  opacity: 1;
  transform: translateX(0);
}

.scale-in {
  opacity: 0;
  transform: scale(0.9);
  transition: opacity 0.8s cubic-bezier(0.23, 1, 0.32, 1),
              transform 0.8s cubic-bezier(0.23, 1, 0.32, 1);
}

.scale-in.visible {
  opacity: 1;
  transform: scale(1);
}

/* Article Page Smooth Loading */
.article-header,
.article-eyecatch,
.article-content,
.article-tags,
.author-profile,
.table-of-contents {
  opacity: 0;
  animation: articleFadeIn 0.6s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

.article-header {
  animation-delay: 0s;
}

.article-eyecatch {
  animation-delay: 0.1s;
}

.table-of-contents {
  animation-delay: 0.2s;
}

.article-content {
  animation-delay: 0.3s;
}

.article-tags {
  animation-delay: 0.4s;
}

.author-profile {
  animation-delay: 0.5s;
}

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

/* Article Content Progressive Loading */
.article-content h2,
.article-content h3,
.article-content p,
.article-content ul,
.article-content ol,
.article-content blockquote,
.article-content img {
  opacity: 0;
  animation: contentItemFadeIn 0.5s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

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

/* Article Card Hover Effects */
.article-card {
  transition: all 0.4s cubic-bezier(0.23, 1, 0.32, 1);
  transform: translateZ(0);
  will-change: transform;
}

.article-card:hover {
  transform: translateY(-8px) translateZ(0);
}

.article-card img {
  transition: transform 0.6s cubic-bezier(0.23, 1, 0.32, 1);
}

.article-card:hover img {
  transform: scale(1.08);
}

/* Smooth Link Transitions */
a {
  transition: color 0.3s cubic-bezier(0.23, 1, 0.32, 1),
              opacity 0.3s cubic-bezier(0.23, 1, 0.32, 1);
}

/* Button Transitions */
button,
.btn {
  transition: all 0.3s cubic-bezier(0.23, 1, 0.32, 1);
  transform: translateZ(0);
}

button:hover,
.btn:hover {
  transform: translateY(-2px) translateZ(0);
}

button:active,
.btn:active {
  transform: translateY(0) translateZ(0);
}

/* Skeleton Loading */
.skeleton {
  position: relative;
  overflow: hidden;
  background: #f0f0f0;
}

.skeleton::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(
    90deg,
    transparent,
    rgba(255, 255, 255, 0.6),
    transparent
  );
  animation: skeleton-loading 1.5s infinite;
}

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

/* Micro Interactions */
.clickable {
  transition: transform 0.1s cubic-bezier(0.23, 1, 0.32, 1);
}

.clickable:active {
  transform: scale(0.98);
}

/* Performance Optimizations */
.gpu-accelerated {
  transform: translateZ(0);
  will-change: transform, opacity;
  backface-visibility: hidden;
  perspective: 1000px;
}

/* 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;
  }
  
  .image-loaded {
    animation: none;
    opacity: 1;
    transform: none;
    filter: none;
  }
  
  .fade-up,
  .fade-left,
  .fade-right,
  .scale-in {
    opacity: 1;
    transform: none;
  }
}