/* ================================
   Gallery Page Styling
   ================================ */

/* Override theme width constraints */
body {
  overflow-x: hidden;
}

.page-gallery,
.page-gallery *,
body:has(.page-gallery) main,
body:has(.page-gallery) article,
body:has(.page-gallery) .container,
body:has(.page-gallery) .article-container,
body:has(.page-gallery) .article-content,
body:has(.page-gallery) .prose,
body:has(.page-gallery) .max-w-prose,
body:has(.page-gallery) .max-w-7xl,
body:has(.page-gallery) .max-w-5xl,
body:has(.page-gallery) .max-w-4xl,
body:has(.page-gallery) .max-w-3xl,
body:has(.page-gallery) .max-w-2xl,
body:has(.page-gallery) .mx-auto {
  max-width: none !important;
}

.page-gallery {
  max-width: 1600px !important;
  width: 100% !important;
  margin: 0 auto !important;
  padding: 2rem clamp(1rem, 5vw, 3rem) !important;
  animation: fadeIn 0.6s ease-in-out;
}

/* Heading */
.page-gallery h2 {
  text-align: center;
  margin: 0 0 1rem 0;
  font-size: clamp(1.75rem, 4vw, 2.25rem);
  color: var(--color-primary-500, #8b5cf6);
  font-weight: 700;
  letter-spacing: -0.02em;
}

.gallery-intro {
  text-align: center;
  margin: 0 auto 3rem;
  max-width: 600px;
  font-size: clamp(1rem, 2vw, 1.1rem);
  color: var(--color-neutral-700, #374151);
  line-height: 1.6;
}

/* ================================
   Masonry Layout
   ================================ */
.gallery-grid {
  column-count: 4;
  column-gap: 1rem;
  width: 100%;
  margin-bottom: 3rem;
}

@media (max-width: 1400px) {
  .gallery-grid { column-count: 3; }
}
@media (max-width: 1024px) {
  .gallery-grid { column-count: 2; }
}
@media (max-width: 640px) {
  .gallery-grid { column-count: 1; }
}

/* Each item behaves like a masonry block */
.gallery-item {
  position: relative;
  display: inline-block;
  margin-bottom: 1rem;
  width: 100%;
  overflow: hidden;
  border-radius: 1rem;
  cursor: zoom-in;
  background: transparent;
  transition: transform 0.35s ease, box-shadow 0.35s ease, filter 0.35s ease;
}

.gallery-item img {
  width: 100%;
  height: auto;
  display: block;
  border-radius: inherit;
  object-fit: cover;
  filter: blur(20px);
  transform: scale(1.05);
  opacity: 0.8;
  transition: filter 0.8s ease, opacity 0.8s ease, transform 0.8s ease;
}

/* Once high-res image loads */
.gallery-item img.loaded {
  filter: blur(0);
  opacity: 1;
  transform: scale(1);
}

/* Hover effects */
.gallery-item:hover img {
  transform: scale(1.06);
  filter: brightness(1.1) saturate(1.05);
}
.gallery-item:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.25);
}

/* Overlay (soft fade-in) */
.gallery-overlay {
  position: absolute;
  inset: 0;
  background: linear-gradient(to bottom, rgba(0,0,0,0) 60%, rgba(0,0,0,0.4) 100%);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-bottom: 1.25rem;
  opacity: 0;
  transition: opacity 0.3s ease;
  pointer-events: none;
}
.gallery-item:hover .gallery-overlay { opacity: 1; }

.view-text {
  color: white;
  font-size: 1rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.6rem 1.25rem;
  border: 1.5px solid white;
  border-radius: 0.5rem;
  background: rgba(0, 0, 0, 0.35);
  backdrop-filter: blur(6px);
}

/* ================================
   Lightbox Modal
   ================================ */
.lightbox {
  display: none;
  position: fixed;
  z-index: 9999;
  inset: 0;
  background-color: rgba(0, 0, 0, 0.9);
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.3s ease;
  flex-direction: column;
}

.lightbox-content {
  width: auto;
  height: auto;
  max-width: 90vw;
  max-height: 85vh;
  object-fit: contain;
  border-radius: 1rem;
  box-shadow: 0 10px 40px rgba(0,0,0,0.6);
  animation: zoomIn 0.3s ease;
  display: block;
}

.lightbox-caption {
  margin-top: 1rem;
  color: white;
  font-size: 1rem;
  text-align: center;
  background: rgba(0, 0, 0, 0.6);
  padding: 0.6rem 1.5rem;
  border-radius: 0.5rem;
  backdrop-filter: blur(6px);
  max-width: 80%;
}

/* Controls */
.lightbox-close,
.lightbox-prev,
.lightbox-next {
  position: fixed;
  color: white;
  font-size: 2.5rem;
  cursor: pointer;
  user-select: none;
  padding: 0.6rem 0.9rem;
  background: rgba(0, 0, 0, 0.5);
  border-radius: 50%;
  transition: all 0.3s ease;
  z-index: 10000;
}
.lightbox-close:hover,
.lightbox-prev:hover,
.lightbox-next:hover {
  background: rgba(255,255,255,0.25);
}
.lightbox-close { top: 1.5rem; right: 2rem; }
.lightbox-prev { left: 3rem; top: 50%; transform: translateY(-50%); scale(1.05);}
.lightbox-next { right: 3rem; top: 50%; transform: translateY(-50%); scale(1.05);}

/* ================================
   ✅ Improved Mobile Lightbox Scaling Fix
   ================================ */
@media (max-width: 768px) {
  .lightbox {
    padding: 1rem;
    align-items: center;
    justify-content: center;
  }

  .lightbox-content {
    width: auto !important;
    height: auto !important;
    max-width: 95vw !important;
    max-height: 80vh !important;
    object-fit: contain !important;
    border-radius: 0.75rem;
  }

  /* Force-fit both orientation types */
  .lightbox img,
  .lightbox-content img {
    width: auto !important;
    height: auto !important;
    max-width: 95vw !important;
    max-height: 80vh !important;
    object-fit: contain !important;
    display: block;
    margin: auto;
  }

  .lightbox-close {
    top: 0.75rem;
    right: 0.75rem;
    font-size: 1.8rem;
    padding: 0.4rem;
  }

  .lightbox-prev,
  .lightbox-next {
    font-size: 1.8rem;
    padding: 0.4rem 0.6rem;
    top: 50%;
    transform: translateY(-50%);
  }

  .lightbox-caption {
    font-size: 0.9rem;
    padding: 0.5rem 1rem;
    max-width: 90%;
    margin-top: 0.75rem;
  }
}

/* ================================
   Dark Mode + Animations
   ================================ */
@media (prefers-color-scheme: dark) {
  .gallery-intro { color: var(--color-neutral-300, #d1d5db); }
  .gallery-item:hover { box-shadow: 0 12px 28px rgba(0, 0, 0, 0.55); }
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes zoomIn { from { transform: scale(0.9); opacity: 0; } to { transform: scale(1); opacity: 1; } }

.gallery-item:focus-visible {
  outline: 3px solid var(--color-primary-500, #8b5cf6);
  outline-offset: 3px;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
