/* Gallery Core */
.gallery {
  margin: 2.5rem auto;
  padding: 8px;
  padding-inline: clamp(10px, 3vw, 80px);
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  opacity: 0;
  transition: opacity 0.6s ease;
}

.gallery.loaded {
  opacity: 1;
}

.gallery * {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

.gallery figure {
  flex: 1 1 auto;
  overflow: hidden;
  position: relative;
  background: #111;
  transition: transform 0.4s ease;
  cursor: pointer;
}

.gallery figure:hover {
  z-index: 10;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}

/* Caption Overlays */
.gallery figure figcaption {
  padding: 2.5rem 1rem 1rem 1rem;
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 2;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.9));
  opacity: 0;
  color: #fff;
  transition: opacity 0.3s ease, transform 0.3s ease;
  transform: translateY(15px);
  pointer-events: none;
}

.gallery figure:hover figcaption {
  opacity: 1;
  transform: translateY(0);
}

.gallery figure figcaption h3 {
  margin-bottom: 0.3rem;
  font-size: 1.1rem;
  font-weight: 600;
}

.gallery figure figcaption p {
  font-size: 0.85rem;
  opacity: 0.8;
}

/* Media Image */
.gallery figure:has(img) img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
  /* Perfect fit because the container will match the media AR */
  transition: transform 0.8s ease;
}

.gallery figure:has(img):hover img {
  transform: scale(1.05);
}

/* Media Audio */
.gallery figure:has(audio) {
  background: #111;
  color: white;
  padding: 2rem 1.5rem;
  text-align: center;
  border: 1px solid rgba(255, 255, 255, 0.1);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}

.gallery figure:has(audio)::before {
  content: "🎵";
  font-size: 3rem;
  margin-bottom: 0.5rem;
}

/* Media Video */
.gallery figure:has(video) video {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
  transition: transform 0.8s ease;
}

.gallery figure:has(video):hover video {
  transform: scale(1.05);
}

.gallery figure:has(video)::after {
  content: "▶";
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(1);
  width: 60px;
  height: 60px;
  background: rgba(239, 68, 68, 0.95);
  /* Vibrant red shade */
  color: #fff;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  padding-left: 4px;
  /* Optical center adjustment for play triangle */
  z-index: 5;
  pointer-events: none;
  /* Let clicks pass down to trigger lightbox */
  transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.gallery figure:hover:has(video)::after {
  transform: translate(-50%, -50%) scale(1.15);
  background: rgba(0, 0, 0, 0.6);
  /* Black shade */
  color: #fff;
  border-color: rgba(255, 255, 255, 0.8);
}

/* Media Document */
.gallery figure:has(a) {
  background: #111;
  color: white;
  padding: 2rem 1.5rem;
  text-align: center;
  border: 1px solid rgba(255, 255, 255, 0.1);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}

.gallery figure:has(a)::before {
  content: "📄";
  font-size: 3rem;
  margin-bottom: 0.5rem;
}


/* Responsive */
@media (max-width: 768px) {
  .gallery {
    gap: 4px;
  }
}