/**
 * Frontend styles for Animated Gallery Block
 */

.wp-block-cecmm-gallery {
  position: relative;
  width: 100%;
  margin: 0 auto;
}

.animated-gallery {
  position: relative;
  width: 100%;
}

.gallery-grid {
  display: grid;
  width: 100%;
  position: relative;
  justify-items: center;
  align-items: center;
  place-items: center;
}

.gallery-slot {
  position: relative;
  overflow: hidden;
  background: transparent !important;
  border-radius: 4px;
  transition: all 0.3s ease;
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  aspect-ratio: 1/1;
}

.gallery-slot .background-blur {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-size: cover;
  background-position: center;
  filter: blur(20px) brightness(1.5) opacity(0.3);
  z-index: 1;
  opacity: 0;
  transition: opacity 0.3s ease, transform 0.5s ease;
}

.gallery-slot.contain-mode .background-blur {
  opacity: 1;
}

.gallery-slot img {
  width: 100%;
  height: 100%;
  object-position: center;
  transition: all 0.5s ease;
  display: block;
  position: relative;
  z-index: 2;
}

/* Animation classes for image transitions */
.gallery-slot.fade-out {
  opacity: 0;
  transform: scale(0.95);
}

.gallery-slot.fade-in {
  opacity: 1;
  transform: scale(1);
}

.gallery-slot.animating {
  transition: all 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Grid reorganization animation */
.gallery-grid.reorganizing {
  transition: grid-template-columns 0.6s ease, grid-template-rows 0.6s ease;
}

.gallery-slot.moving {
  transition: all 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Image fitting modes */
.gallery-slot.crop-mode img {
  object-fit: cover;
  object-position: center center;
}

.gallery-slot.contain-mode img {
  object-fit: contain;
  object-position: center center;
}

/* Loading state */
.gallery-slot.loading {
  background: transparent !important;
  position: relative;
}

.gallery-slot.loading::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(90deg, rgba(240,240,240,0.5) 25%, rgba(224,224,224,0.5) 50%, rgba(240,240,240,0.5) 75%);
  background-size: 200% 100%;
  animation: gallery-loading 1.5s infinite;
  border-radius: 4px;
}

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

/* Caption styles */
.image-caption {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(255, 255, 255, 0.15);
  color: white;
  padding: 10px 14px;
  font-family: var(--wp--preset--font-family--nunito-sans);
  font-size: var(--wp--preset--font-size--caption);
  font-weight: 500;
  line-height: 1.4;
  opacity: 0;
  transform: translateY(100%);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 4;
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border-top: 1px solid rgba(255, 255, 255, 0.2);
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
}

/* Hover effects */
.gallery-slot:hover {
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
}

.gallery-slot:hover img,
.gallery-slot:hover .background-blur {
  transform: scale(1.05);
}

.gallery-slot:hover .image-caption {
  opacity: 1;
  transform: translateY(0);
}

/* Focus states for accessibility */
.gallery-slot:focus-within {
  outline: 2px solid #007cba;
  outline-offset: 2px;
}

/* Error state */
.gallery-slot.error {
  background: transparent !important;
  border: 1px solid #dc3545;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #dc3545;
  font-size: 14px;
}

.gallery-slot.error::before {
  content: "⚠ Invalid image";
  font-size: 12px;
  text-align: center;
}

/* Responsive design */
@media (max-width: 768px) {
  .gallery-grid {
    gap: 8px !important;
  }

  .gallery-slot:hover img,
  .gallery-slot:hover .background-blur {
    transform: none;
  }

  .image-caption {
    font-size: var(--wp--preset--font-size--caption);
    padding: 8px 12px;
    font-weight: 500;
  }
}

@media (max-width: 480px) {
  .gallery-grid {
    gap: 4px !important;
    grid-template-columns: repeat(2, 1fr) !important;
  }

  .gallery-slot {
    border-radius: 2px;
  }
}

/* Print styles */
@media print {
  .animated-gallery {
    break-inside: avoid;
  }

  .gallery-slot {
    break-inside: avoid;
    transition: none;
  }

  .gallery-slot img {
    transition: none;
  }
}

/* High contrast mode */
@media (prefers-contrast: high) {
  .gallery-slot {
    border: 1px solid currentColor;
  }

  .gallery-slot.loading {
    background: repeating-linear-gradient(
      45deg,
      transparent,
      transparent 10px,
      currentColor 10px,
      currentColor 20px
    );
  }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  .gallery-slot,
  .gallery-slot img,
  .gallery-grid {
    transition: none;
    animation: none;
  }

  .gallery-slot.fade-out,
  .gallery-slot.fade-in {
    transition: opacity 0.1s ease;
  }

  .image-caption {
    transition: none;
  }

  .gallery-slot.loading::after {
    animation: none;
  }
}

/* Dark mode */
@media (prefers-color-scheme: dark) {
  .gallery-slot {
    background: transparent !important;
  }

  .gallery-slot.loading::after {
    background: linear-gradient(90deg, rgba(42,42,42,0.5) 25%, rgba(58,58,58,0.5) 50%, rgba(42,42,42,0.5) 75%);
    background-size: 200% 100%;
  }

  .gallery-slot.error {
    background: transparent !important;
    border: 1px solid #dc3545;
    color: #ff6b6b;
  }

  .image-caption {
    background: rgba(0, 0, 0, 0.25);
    border-top: 1px solid rgba(255, 255, 255, 0.15);
    backdrop-filter: blur(20px) saturate(150%);
    -webkit-backdrop-filter: blur(20px) saturate(150%);
  }
}

/* Animation keyframes */
@keyframes gallery-slot-enter {
  from {
    opacity: 0;
    transform: scale(0.8) translateY(20px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

@keyframes gallery-slot-exit {
  from {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
  to {
    opacity: 0;
    transform: scale(0.8) translateY(-20px);
  }
}

/* Staggered animations */
.gallery-slot.animate-enter {
  animation: gallery-slot-enter 0.5s ease forwards;
}

.gallery-slot.animate-exit {
  animation: gallery-slot-exit 0.5s ease forwards;
}

.gallery-slot.animate-enter:nth-child(1) { animation-delay: 0ms; }
.gallery-slot.animate-enter:nth-child(2) { animation-delay: 100ms; }
.gallery-slot.animate-enter:nth-child(3) { animation-delay: 200ms; }
.gallery-slot.animate-enter:nth-child(4) { animation-delay: 300ms; }
.gallery-slot.animate-enter:nth-child(5) { animation-delay: 400ms; }
.gallery-slot.animate-enter:nth-child(6) { animation-delay: 500ms; }