#gallery-grid {
  box-sizing: border-box;
  position: fixed;
  top: 0;
  left: 0;
  height: 100%;
  z-index: 10000;
  display: flex;
  flex-direction: column;
  padding: 1em;
  margin: 2em;
  background-color: rgba(0, 0, 0, 0.727);
}

#gallery-grid .cs-toggle {
  /* 44px - 48px */
  width: clamp(2.75rem, 6vw, 3rem);
  height: clamp(2.75rem, 6vw, 3rem);
  margin: 0 0 0 auto;
  background-color: transparent;
  border: none;
  border-radius: 0.25rem;
  display: flex;
  justify-content: center;
  align-items: center;
}

#gallery-grid .cs-toggle {
  display: none;
}

#gallery-items-container {
  overflow-y: auto;
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-start;
  align-items: center;
  gap: 10px;
}

.gallery-closed {
  visibility: hidden;
}

#gallery-items-container a {
  flex: 0 0 100%;
}

#gallery-items-container img {
  width: 100%;
  height: auto;
  object-fit: cover;
  border-radius: 10px;
}

#close-gallery-btn {
  /* Position it relative to its parent (.modal-gallery-content) */
  top: 10px; /* Distance from the top */
  right: 10px; /* Distance from the right */

  background: none; /* No background color */
  border: none; /* No border */
  font-size: 3.5em; /* Make the X large enough to click */
  color: #fff; /* Dark gray color */
  cursor: pointer; /* Indicate it's clickable */
  padding: 0 5px; /* Small padding for easier clicking */
  line-height: 1; /* Prevent extra space around the X */
  font-weight: lighter; /* Make the X thinner */
  opacity: 0.7; /* Slightly transparent */
  transition: all 0.2s ease, color 0.2s ease; /* Smooth transition on hover */
  text-align: right;
}

#close-gallery-btn:hover {
  opacity: 1;
  font-size: 5em;
  color: var(--secondary); /* Darker on hover */
}

/* Ensure modal-gallery-content has position: relative; for absolute positioning */
.modal-gallery-content {
  background-color: white;
  padding: 20px;
  border-radius: 8px;
  max-width: 90%;
  max-height: 90%;
  overflow-y: auto;
  position: relative; /* THIS IS CRUCIAL for .close-modal-btn's absolute positioning */
}

/* Tablet and larger: Two images per row */
@media (min-width: 48rem) {
  /* 48rem = 768px (common tablet breakpoint) */
  #gallery-items-container a {
    flex: 0 0 calc(50% - 5px); /* Two items per row, accounting for gap */
    /* gap / number of items = 10px / 2 = 5px per side */
  }
}

/* Desktop and larger: Three images per row */
@media (min-width: 62rem) {
  /* 62rem = 992px (common desktop breakpoint) */
  #gallery-items-container a {
    flex: 0 0 calc(33.333% - 6.666px); /* Three items, accounting for gap */
    /* 2 * gap / 3 items = 20px / 3 = 6.666px */
  }
}

/* Large Desktop: Four images per row */
@media (min-width: 75rem) {
  /* 75rem = 1200px (common large desktop breakpoint) */
  #gallery-items-container a {
    flex: 0 0 calc(25% - 7.5px); /* Four items, accounting for gap */
    /* 3 * gap / 4 items = 30px / 4 = 7.5px */
  }
}
