/* ==========================================================================
   1. CORE STRUCTURE FOR GALLERY GRID
   ========================================================================== */
.gallery-grid {
  display: grid;
  gap: 20px;
  margin-top: 30px;
  margin-bottom: 20px;
  width: 100%;
  align-items: stretch;
}

/* 4 columns wide for Section 2 */
.grid-4-cols {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

/* Perfect alignment centering for your final lonely image row */
.grid-single {
  grid-template-columns: 1fr;
}
.grid-single figure {
  max-width: 400px;
  margin: 0 auto;
}

/* Fix: limit the image inside the single grid */
.grid-single figure img {
  width: 100%;
  max-width: 400px;
  height: auto;
  display: block;
}

/* Make each figure a flex box that fills the grid cell */
.gallery-grid figure {
  display: flex;
  flex-direction: column;
  margin: 0;
  height: 100%;
}

/* Let the anchor/image wrapper fill the top space */
.gallery-grid figure > a {
  display: flex;
  flex-direction: column;
  flex-grow: 1;
  text-decoration: none;
}

/* Fix thumbnail image height so all frames match perfectly */
.gallery-grid figure img {
  width: 100%;
  height: 200px;
  object-fit: cover;
  display: block;
}

/* Push captions to the bottom and align them */
.gallery-grid figure figcaption,
.gallery-grid figure .caption {
  margin-top: auto;
  padding-top: 10px;
  text-align: center;
}

.empty-placeholder {
  display: block !important;
  min-height: 200px !important;
  width: 100% !important;
  visibility: hidden !important;
  pointer-events: none;
}

/* ==========================================================================
   2. FOOTER NOTES & UTILITIES
   ========================================================================== */
.red-footer-note,
.red-footer-note a {
  clear: both;
  display: block;
  color: #ff0000 !important;
  font-style: italic;
  font-weight: bold;
  margin-top: 20px;
  text-align: left;
  font-size: 2rem;
}

.blue-footer-note,
.blue-footer-note a {
  clear: both;
  display: block;
  color: #0064e6 !important;
  font-weight: bold;
  font-style: italic;
  margin-top: 20px;
  text-align: left;
  font-size: 2rem;
}

/* ==========================================================================
   3. GLOBAL LIGHTBOX SYSTEM (Desktop First)
   ========================================================================== */
.image-lightbox {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  z-index: 99999;
}

/* Triggers when matching thumbnail is clicked */
.image-lightbox:target {
  display: flex;
  justify-content: center;
  align-items: center;
}

/* Full screen overlay mask behind the picture */
.close-overlay-area {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: #ffffff;
  cursor: zoom-out;
}

/* Lightbox container box sizing - Now expands up to 90% of screen width */
.lightbox-content {
  position: relative;
  max-width: 90%;
  max-height: 90%;
  text-align: center;
  margin: 0 auto;
}

/* Lightbox Image: Restrains giant images, upscales small files to fit comfortably */
.lightbox-content img {
  width: auto;
  min-width: 600px;        /* Forces smaller images like sailboat to scale out to a large size */
  max-width: 90vw;         /* Keeps large images from overflowing wide desktop screens */
  height: auto !important; /* Force natural height proportions */
  max-height: 90vh;        /* Loosened constraint to prevent vertical clipping */
  object-fit: contain;
  display: block;
  margin: 0 auto;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
}

.close-button {
  display: inline-block;
  margin-top: 15px;
  color: #333333;
  text-decoration: none;
  font-family: sans-serif;
  font-size: 16px;
  font-weight: bold;
}
.close-button:hover {
  color: #ff0000;
}

/* ==========================================================================
   4. RESPONSIVE MEDIA QUERIES (Mobile Adjustments)
   ========================================================================== */
@media screen and (max-width: 768px) {
  .grid-4-cols {
    grid-template-columns: repeat(2, 1fr);
  }

  .gallery-grid figure img {
    width: 100%;
    height: 200px;
    object-fit: cover;
  }

  .empty-placeholder {
    display: none !important;
  }

  /* 1. Mobile screen lightbox window constraint track */
  .image-lightbox {
    display: none !important;
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    max-width: 100vw !important;
    max-height: 100vh !important;
    z-index: 999999 !important;
    margin: 0 !important;
    padding: 0 !important;
    box-sizing: border-box !important;
  }

  .image-lightbox:target {
    display: flex !important;
    justify-content: center !important;
    align-items: center !important;
  }

  /* 2. Container setup: Sets overflow auto to facilitate mobile touch scroll expansions */
  .lightbox-content {
    position: relative !important;
    width: 100vw !important;
    max-width: 100vw !important;
    height: 100vh !important;
    max-height: 100vh !important;
    overflow: auto !important;
    -webkit-overflow-scrolling: touch !important;
    padding: 60px 20px 20px 20px !important;
    box-sizing: border-box !important;
  }

  /* 3. Image sizing logic for Mobile: Lets images layout wide/scrollable */
  .lightbox-content img {
    width: auto !important;
    min-width: 0 !important; /* Strips desktop scale constraints on mobile touch view */
    max-width: none !important;
    height: auto !important;
    max-height: none !important;
    display: block !important;
    margin: 0 auto !important;
  }

  /* 4. Fixed placement for mobile close button so it stays visible while panning */
  .lightbox-content .close-button {
    position: fixed !important;
    top: 15px !important;
    right: 15px !important;
    margin-top: 0 !important;
    z-index: 1000000 !important;
    background-color: #ffffff;
    padding: 8px 14px;
    border: 1px solid #333333;
    border-radius: 4px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
  }
}
