/* Loading States and Resource Loading Optimization */

/* Hide content until fonts and critical resources are loaded */
html.font-loading {
  visibility: hidden;
}

html.font-loading body {
  opacity: 0;
  transition: opacity 0.3s ease;
}

/* Show content when fonts are loaded */
html.fonts-loaded body {
  opacity: 1;
  visibility: visible;
}

/* Prevent flash of unstyled content */
.hero-title,
.title-section,
.subtitle-section,
.pm__title,
.pm__title-section {
  font-display: swap;
  visibility: hidden;
}

html.fonts-loaded .hero-title,
html.fonts-loaded .title-section,
html.fonts-loaded .subtitle-section,
html.fonts-loaded .pm__title,
html.fonts-loaded .pm__title-section {
  visibility: visible;
  animation: fadeInText 0.6s ease forwards;
}

/* Loading animation for text elements */
@keyframes fadeInText {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Loading states for images */
img {
  opacity: 0;
  transition: opacity 0.3s ease;
}

/* Exception for critical images that should always be visible */
.projet-title-img,
.skill-image,
.footer-logo,
img[data-critical] {
  opacity: 1 !important;
}

/* Load images when ready, but exclude project background images which have their own hover behavior */
img.loaded,
html.js-loaded img:not(.projet-bg) {
  opacity: 1;
}

/* Ensure project background images maintain their hover-only behavior */
.projet-bg {
  opacity: 0 !important;
}

.projet-card:hover .projet-bg {
  opacity: 0.8 !important;
}

/* Skeleton loaders for critical content areas */
.hero-content::before,
.section_text-container::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(90deg, 
    rgba(255,255,255,0.1) 25%, 
    rgba(255,255,255,0.2) 50%, 
    rgba(255,255,255,0.1) 75%
  );
  background-size: 200% 100%;
  animation: shimmer 2s infinite;
  border-radius: 4px;
  z-index: -1;
}

html.fonts-loaded .hero-content::before,
html.fonts-loaded .section_text-container::before {
  display: none;
}

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

/* Icon loading states */
.material-symbols-rounded,
.material-symbols-outlined {
  opacity: 0;
  transition: opacity 0.3s ease;
}

html.fonts-loaded .material-symbols-rounded,
html.fonts-loaded .material-symbols-outlined {
  opacity: 1;
}

/* Critical above-the-fold content optimization */
.hero {
  min-height: 100vh;
  position: relative;
}

html.font-loading .hero {
  background: #000;
}

html.font-loading .hero::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 50px;
  height: 50px;
  border: 3px solid rgba(255,255,255,0.3);
  border-top: 3px solid #fff;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

html.fonts-loaded .hero::before {
  display: none;
}

@keyframes spin {
  0% { transform: translate(-50%, -50%) rotate(0deg); }
  100% { transform: translate(-50%, -50%) rotate(360deg); }
}

/* Progressive enhancement for JavaScript features */
html.js-loading .carousel-navigation,
html.js-loading .fancy-button,
html.js-loading .projet-card {
  pointer-events: none;
  opacity: 0.7;
}

html.js-loaded .carousel-navigation,
html.js-loaded .fancy-button,
html.js-loaded .projet-card {
  pointer-events: auto;
  opacity: 1;
  transition: opacity 0.3s ease;
}

/* Canvas loading states */
canvas {
  opacity: 0;
  transition: opacity 0.5s ease;
}

html.js-loaded canvas {
  opacity: 1;
}

/* Performance optimizations */
.projet-card .projet-bg,
.skill-image {
  will-change: transform;
  transform: translateZ(0);
}

/* Ensure project logos maintain their centering */
.projet-title-img {
  will-change: transform;
  /* Preserve existing centering transform */
}

/* Reduce motion for users who prefer it */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  
  html.font-loading body {
    transition: none;
  }
  
  .hero-title,
  .title-section,
  .subtitle-section,
  .pm__title,
  .pm__title-section {
    animation: none;
  }
} 