.masonry {
  display: grid;
  grid-auto-flow: dense;
  gap: 15px;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  grid-auto-rows: 200px;
  padding: 100px; /* Reduced from 100px for better visibility on smaller screens */
}

.item {
  width: 100%;
  height: 100%;
  overflow: hidden;
  transition: .2s ease-in;
}

.item:hover {
  transform: scale(1.02);
  z-index: 2;
}

.item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* --- Aspect Ratio Classes --- */

/* Standard square-ish block */
.standard {
  grid-row: span 1;
  grid-column: span 1;
}

/* Vertical / Portrait Images */
.vertical {
  grid-row: span 2; /* Takes up two vertical cells */
  grid-column: span 1;
}

/* Horizontal / Landscape Images */
.horizontal {
  grid-row: span 1;
  grid-column: span 2; /* Takes up two horizontal cells */
}

/* Extra Large (Optional) */
.featured {
  grid-row: span 2;
  grid-column: span 2;
}

/* --- Responsive Behavior --- */

@media (max-width: 900px) {
  .masonry {
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    grid-auto-rows: 180px;
  }
}

@media (max-width: 600px) {
  .masonry {
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    grid-auto-rows: 140px;
    padding: 10px;
  }
  
  /* On mobile, we limit spans to prevent images from being cut off or too thin */
  .horizontal, .featured {
    grid-column: span 2; 
  }
  .vertical {
    grid-row: span 2;
  }
}

/* The Overlay Background */
.lightbox {
  display: none; /* Hidden by default */
  position: fixed;
  z-index: 1000;
  padding-top: 50px;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.9); /* Black with opacity */
  cursor: zoom-out;
}

/* The Image inside the pop-up */
.lightbox-content {
  margin: auto;
  display: block;
  max-width: 90%;
  max-height: 80vh;
  border-radius: 5px;
  box-shadow: 0 0 20px rgba(0,0,0,0.5);
  /* Animation */
  animation: zoom 0.3s;
}

@keyframes zoom {
  from {transform: scale(0.1)} 
  to {transform: scale(1)}
}

/* Close Button */
.close {
  position: absolute;
  top: 20px;
  right: 35px;
  color: #fff;
  font-size: 40px;
  font-weight: bold;
  cursor: pointer;
}

.item img {
  cursor: zoom-in; /* Shows the user the image is clickable */
}

/* Navigation Buttons */
.prev-btn, .next-btn {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(255, 255, 255, 0.1);
  color: white;
  border: none;
  padding: 20px 15px;
  font-size: 30px;
  cursor: pointer;
  transition: 0.3s;
  user-select: none;
  z-index: 10001; /* Higher than the image */
  border-radius: 5px;
}

.prev-btn:hover, .next-btn:hover {
  background: rgba(255, 255, 255, 0.3);
}

.prev-btn { left: 20px; }
.next-btn { right: 20px; }

/* Hide arrows on very small screens to avoid clutter */
@media (max-width: 500px) {
  .prev-btn, .next-btn {
    padding: 10px;
    font-size: 20px;
  }
}