/* Base Styles */
body {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  background: #f0f2f5;
  color: #333;
  margin: 0;
  padding: 20px;
}

h1 {
  text-align: center;
  font-weight: 300;
  color: #444;
  margin-bottom: 40px;
}

/* Gallery Grid */
.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 25px;
  padding: 0 10px;
  max-width: 1400px;
  margin: 0 auto;
}

/* Image Cards */
.image-card {
  background: white;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
  transition: transform 0.3s ease, box-shadow 0.3s ease;
  cursor: pointer;
  display: flex;
  flex-direction: column;
}

.image-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 12px 20px rgba(0,0,0,0.15);
}

.image-card img {
  width: 100%;
  height: 220px;
  object-fit: cover;
  display: block;
}

.caption {
  padding: 12px 15px;
  font-size: 0.9em;
  color: #666;
  text-align: right;
  background: #fff;
  border-top: 1px solid #eee;
}

/* --- MODAL / LIGHTBOX STYLES (UPDATED) --- */
#modal {
  display: none; /* JS toggles this to flex */
  position: fixed;
  z-index: 1000;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: rgba(0,0,0,0.95); /* Darker background */
  backdrop-filter: blur(5px);
  animation: fadeIn 0.3s;

  /* Center the .modal-content wrapper */
  align-items: center;
  justify-content: center;
}

/* The wrapper is forced to take up 95% of width and 90% of height.
   This ensures the image has a large "frame" to expand into.
*/
.modal-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;

  width: 95vw;  /* 95% of viewport width */
  height: 90vh; /* 90% of viewport height (leave room for caption) */
  position: relative;
}

#modalImg {
  display: block;
  /* Force image to fill the .modal-content wrapper */
  width: 100%;
  height: 100%;

  /* This ensures the image keeps its aspect ratio and doesn't stretch weirdly,
     but still grows as large as possible within the box. */
  object-fit: contain;

  /* Flex settings to play nice with the caption */
  flex: 1;
  min-height: 0; /* Important CSS fix for flex containers */

  border-radius: 4px;
  box-shadow: 0 0 20px rgba(0,0,0,0.5);
}

#modalCaption {
  flex-shrink: 0; /* Prevents caption from being squished */
  color: #fff;
  margin-top: 15px;
  font-size: 1.2em;
  font-weight: 400;
  text-shadow: 0 1px 3px rgba(0,0,0,0.8);
  text-align: center;
  width: 100%;
}

/* Navigation Arrows */
.nav {
  cursor: pointer;
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  padding: 20px;
  color: rgba(255,255,255,0.7);
  font-weight: bold;
  font-size: 60px;
  transition: 0.3s;
  user-select: none;
  z-index: 1001;
}

.nav:hover {
  color: white;
  background-color: rgba(0,0,0,0.2);
  border-radius: 5px;
}

.prev { left: 20px; }
.next { right: 20px; }

/* Close Button */
.close-btn {
  position: absolute;
  top: 15px;
  right: 30px;
  color: #f1f1f1;
  font-size: 50px;
  font-weight: bold;
  cursor: pointer;
  z-index: 1002; /* Higher than nav to ensure clickable */
  line-height: 1;
  opacity: 0.7;
  transition: 0.3s;
}

.close-btn:hover {
  opacity: 1;
  color: #fff;
}

@keyframes fadeIn {
  from {opacity: 0;}
  to {opacity: 1;}
}

/* Mobile Adjustments */
@media (max-width: 600px) {
    .nav { font-size: 40px; padding: 10px; }
    .close-btn { right: 15px; top: 10px; font-size: 40px; }
    .modal-content { width: 100vw; height: 85vh; }
}