/**
 * Gallery page: masonry grid + lightbox (Fancybox-style full view).
 */

/* Masonry grid using CSS columns */
.gallery-masonry {
  column-count: 1;
  column-gap: 1rem;
  margin: 0 auto;
}

@media (min-width: 640px) {
  .gallery-masonry {
    column-count: 2;
  }
}

@media (min-width: 1024px) {
  .gallery-masonry {
    column-count: 3;
    column-gap: 1.25rem;
  }
}

.gallery-card {
  break-inside: avoid;
  margin-bottom: 1rem;
  border-radius: 12px;
  overflow: hidden;
  background: #fff;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
  transition: transform 0.2s ease, box-shadow 0.2s ease, opacity 0.3s ease;
  cursor: pointer;
}

/* Smooth fade-in when loading more (avoids flickering) */
.gallery-card-enter {
  opacity: 0;
  transform: translateY(12px);
}

.gallery-card-enter.gallery-card-visible {
  opacity: 1;
  transform: translateY(0);
}

.gallery-card-enter.gallery-card-visible:hover {
  transform: translateY(-4px);
}

.gallery-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 12px 24px rgba(0, 0, 0, 0.12);
}

/* Image wrapper: keeps layout stable and shows placeholder until image loads */
.gallery-card-img-wrap {
  position: relative;
  background: #e2e8f0;
  aspect-ratio: 4 / 3;
  overflow: hidden;
}

.gallery-card-img-wrap .gallery-card-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  transition: opacity 0.4s ease;
}

.gallery-card-img-wrap .gallery-card-img.gallery-img-loaded {
  opacity: 1;
}

.gallery-card img,
.gallery-card .gallery-card-poster {
  width: 100%;
  height: auto;
  display: block;
  vertical-align: middle;
}

.gallery-card .gallery-card-poster {
  position: relative;
  background: #1e293b;
  aspect-ratio: 16 / 10;
  overflow: hidden;
}

.gallery-card .gallery-card-poster .gallery-card-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  transition: opacity 0.4s ease;
}

.gallery-card .gallery-card-poster .gallery-card-img.gallery-img-loaded {
  opacity: 1;
}

.gallery-card .gallery-card-poster i {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 3rem;
  color: rgba(247, 223, 30, 0.9);
  z-index: 1;
}

.gallery-card-title {
  padding: 0.5rem 1rem 0.25rem;
  font-weight: 600;
  color: #334155;
  font-size: 0.95rem;
}

.gallery-card-topic {
  padding: 0 1rem 0.75rem;
  font-size: 0.8rem;
  color: #64748b;
  line-height: 1.35;
}

.gallery-tab-btn {
  border-radius: 9999px;
  font-weight: 500;
}

.gallery-tab-btn.btn-active {
  background: #323330;
  color: #F7DF1E;
}

/* Lightbox overlay */
.gallery-lightbox {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  visibility: hidden;
  opacity: 0;
  transition: opacity 0.25s ease, visibility 0.25s ease;
}

.gallery-lightbox.is-open {
  visibility: visible;
  opacity: 1;
}

.gallery-lightbox-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.92);
  cursor: pointer;
}

.gallery-lightbox-close,
.gallery-lightbox-prev,
.gallery-lightbox-next {
  position: absolute;
  z-index: 10002;
  background: rgba(255, 255, 255, 0.15);
  border: none;
  color: #fff;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.2s ease;
}

.gallery-lightbox-close:hover,
.gallery-lightbox-prev:hover,
.gallery-lightbox-next:hover {
  background: rgba(255, 255, 255, 0.25);
}

.gallery-lightbox-close {
  top: 1rem;
  right: 1rem;
  font-size: 1.5rem;
}

.gallery-lightbox-prev {
  left: 1rem;
  top: 50%;
  transform: translateY(-50%);
  font-size: 1.25rem;
}

.gallery-lightbox-next {
  right: 1rem;
  top: 50%;
  transform: translateY(-50%);
  font-size: 1.25rem;
}

.gallery-lightbox-content {
  position: relative;
  z-index: 10001;
  width: 95vw;
  max-width: 1340px;
  min-width: 320px;
  max-height: 90vh;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

/* Wrapper around iframe — must take full size so iframe can expand */
.gallery-lightbox-content .gallery-lightbox-media {
  width: 100%;
  max-width: 1340px;
  flex-shrink: 0;
}

.gallery-lightbox-content img {
  max-width: 100%;
  max-height: 85vh;
  width: auto;
  height: auto;
  object-fit: contain;
}

.gallery-lightbox-content iframe,
.gallery-lightbox-content video {
  display: block;
  width: 100%;
  height: auto;
  min-width: 320px;
  max-width: 1340px;
  aspect-ratio: 16 / 9;
  max-height: 90vh;
  border: none;
  border-radius: 8px;
}

/* Force large iframe size on big screens */
@media (min-width: 1400px) {
  .gallery-lightbox-content {
    width: 1340px;
  }
  .gallery-lightbox-content .gallery-lightbox-media {
    width: 1340px;
  }
  .gallery-lightbox-content iframe,
  .gallery-lightbox-content video {
    width: 1340px;
    height: 753.75px;
    max-height: none;
  }
}

.gallery-lightbox-caption {
  position: absolute;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10002;
  color: #fff;
  text-align: center;
  max-width: 80%;
  font-size: 0.95rem;
}

/* Load more button: spinner + smooth state */
.gallery-loadmore-loading {
  pointer-events: none;
}

.gallery-loadmore-loading .loading {
  margin-right: 0.5rem;
  vertical-align: middle;
}
