/* Simple responsive masonry-style gallery with auto-filled tiles */
:root {
  --gap: 10px;
}

body {
  background: #fff;
}

#endlessGallerySection {
  padding: 1.5rem 1rem 4rem;
  margin-bottom: 2rem;
  margin-top: 2rem;
}

#endlessGallerySection .section-header {
  max-width: 1200px;
  margin: 0 auto 1.5rem;
  text-align: center;
}

#endlessGallerySection .section-header h2 {
  color: var(--gold);
  font-size: 2.4rem;
  margin: 0 0 0.25rem;
}

#endlessGallerySection .section-header p {
   color: var(--black); margin: 0 0 1rem; font-weight: 1000; font-size: 1.5rem;
}

.endless-tile {
  position: relative;
  overflow: hidden;
  border-radius: 8px;
  background: #eee;
  cursor: pointer;
  /* Optimization for smooth movement */
  transform: translateZ(0); 
}

/* Desktop: 4 images across */
#endlessGalleryGrid {
  max-width: 100%;
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--gap);
  align-items: start;
}

/* Enhanced Image Styles with smooth Hardware-Accelerated transitions */
#endlessGalleryGrid .endless-tile img {
  width: 100%;
  height: 360px;
  display: block;
  object-fit: cover;
  /* Smoother, longer transition for high-res images */
  transition: opacity 1.2s ease-in-out, filter 1.2s ease-in-out, transform 0.8s ease;
  /* Forces GPU rendering to stop flickering/glitching */
  backface-visibility: hidden;
  will-change: opacity, filter;
}

/* The "Swapping" state: added blur and slight zoom to hide the source change */
.endless-fade {
  opacity: 0 !important;
  filter: blur(10px);
  transform: scale(1.05);
}

.endless-tile:hover img {
  transform: scale(1.04);
}

.endless-caption {
  position: absolute;
  left: 8px;
  bottom: 8px;
  padding: 6px 10px;
  background: rgba(0, 0, 0, 0.5);
  color: #fff;
  font-weight: 600;
  border-radius: 6px;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  pointer-events: none;
}

/* Responsive breakpoints */
@media (max-width: 1200px) {
  #endlessGalleryGrid { grid-template-columns: repeat(3, 1fr); }
  #endlessGalleryGrid .endless-tile img { height: 300px; }
}

@media (max-width: 900px) {
  #endlessGalleryGrid { grid-template-columns: repeat(2, 1fr); }
  #endlessGalleryGrid .endless-tile img { height: 260px; }
}

/* Mobile Optimized Layout (Max 560px) */
@media (max-width: 560px) {
  #endlessGallerySection { padding: 1rem 0.5rem; }
  #endlessGalleryGrid { 
    grid-template-columns: 1fr; /* Single column for better detail */
    gap: 15px; /* More space between images on mobile */
  }
  #endlessGalleryGrid .endless-tile img { 
    height: 280px; /* Taller height on mobile so they don't look like tiny strips */
  }
  #endlessGallerySection .section-header h2 { font-size: 1.8rem; }
}

/* Modal overlay */
#endlessGalleryModal {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.85); /* Darker backdrop to focus on image */
  z-index: 3500;
  backdrop-filter: blur(4px);
}

#endlessGalleryModal.show { display: flex; }

#endlessGalleryModalInner {
  position: relative;
  max-width: 92vw;
  max-height: 92vh;
  width: min(1200px, 95%);
  display: flex;
  align-items: center;
  justify-content: center;
}

#endlessGalleryModalInner img {
  max-width: 100%;
  max-height: 90vh;
  border-radius: 6px;
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.6);
}

.endless-close {
  position: absolute;
  top: -20px;
  right: -10px;
  background: #fff;
  color: #000;
  border: none;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  font-size: 1.1rem;
  font-weight: bold;
  cursor: pointer;
  z-index: 3501;
}

/* Blur background when modal open */
body.endless-modal-open > *:not(#endlessGalleryModal) {
  filter: blur(8px);
  transition: filter 0.3s ease;
}

.endless-tile:focus {
  outline: 3px solid #c19636;
}