/* Lazy-loaded masonry grid styles */
.lazy-masonry-container {
  margin: 5rem auto 0;
  padding: 2rem;
  width: 100%;
  max-width: var(--content-max-width);
  box-sizing: border-box;
}

.masonry-section-title {
  font-family: var(--font-serif);
  font-weight: 500;
  text-align: center;
  font-size: 2.5em;
  margin-top: 0.5em;
  margin-bottom: 0.5em;
  color: var(--color-text-primary);
}

.masonry-description {
  text-align: center;
  font-size: 1.1em;
  font-weight: 300;
  color: var(--color-text-secondary);
  max-width: 600px;
  margin: 0 auto 2em;
}

/* Masonry grid layout */
.lazy-masonry-grid {
  width: 100%;
  min-height: 500px; /* Prevent layout shifts when loading first items */
  position: relative;
}

/* Grid sizing element */
.grid-sizer,
.lazy-masonry-item {
  width: 31.333%; /* With gutters, fits 3 columns */
  margin: 1%;
}

/* Masonry item styling */
.lazy-masonry-item {
  opacity: 0;
  transform: translateY(20px);
  transition: opacity 0.4s ease, transform 0.4s ease;
  overflow: hidden;
  border-radius: 8px;
  box-shadow: var(--shadow-card);
  margin-bottom: 20px;
  position: relative;
  will-change: opacity, transform;
  background-color: var(--color-bg-secondary);
}

.lazy-masonry-item.visible {
  opacity: 1;
  transform: translateY(0);
}

.lazy-image-link {
  display: block;
  text-decoration: none;
  color: inherit;
  position: relative;
  overflow: hidden;
  height: 100%;
  transition: var(--transition-hover);
}

.lazy-image-link:hover {
  transform: var(--hover-scale);
}

.lazy-image-container {
  position: relative;
  width: 100%;
  height: 100%;
}

.lazy-loaded-image {
  width: 100%;
  height: auto;
  display: block;
  vertical-align: middle;
  transform: translateZ(0); /* Force GPU acceleration */
  backface-visibility: hidden; /* Performance optimization */
}

.lazy-image-overlay {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 15px;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.7));
  color: white;
  opacity: 0;
  transition: opacity 0.3s ease;
  pointer-events: none; /* Allow clicks to pass through to the link */
  /* Hide on touch devices by default */
  display: none;
}

/* Only show overlay on devices that support hover */
@media (hover: hover) {
  .lazy-image-overlay {
    display: block;
  }
}

.lazy-image-link:hover .lazy-image-overlay {
  opacity: 1;
}

.lazy-image-title {
  margin: 0;
  font-size: 0.9rem;
  font-weight: 400;
}

/* Loading indicator */
.loading-indicator {
  display: none;
  justify-content: center;
  margin: 2rem 0;
  width: 100%;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 4px solid rgba(0, 0, 0, 0.1);
  border-radius: 50%;
  border-top-color: var(--color-accent-default);
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* Media queries for responsive design */
@media (max-width: 1024px) {
  .grid-sizer,
  .lazy-masonry-item {
    width: 31.333%; /* Keep 3 columns */
  }
  
  .masonry-section-title {
    font-size: 2.5em;
  }
}

@media (max-width: 768px) {
  .grid-sizer,
  .lazy-masonry-item {
    width: 48%; /* Adjust to 2 columns */
  }
  
  .lazy-masonry-container {
    padding: 1.5rem;
    margin: 3rem auto 0;
  }
  
  .masonry-section-title {
    font-size: 2em;
    margin-bottom: 1em;
  }
  
  .masonry-description {
    font-size: 1em;
  }
}

@media (max-width: 480px) {
  .grid-sizer,
  .lazy-masonry-item {
    width: 48%; /* Keep 2 columns on mobile */
  }
  
  .lazy-masonry-item {
    margin-bottom: 10px;
  }
  
  .masonry-section-title {
    font-size: 1.5em;
  }
  
  .lazy-masonry-container {
    padding: 1rem;
  }
}