/* Base Gallery Item Style */
.image-box {
  display: inline-block;
  cursor: pointer;
  outline: none;
  position: relative;
}

/* Base Thumbnail Style */
.image-box img {
  display: block;  
  transition: transform 0.3s ease;
}

/* Subtle zoom effect on hover */
.image-box:hover img {
  transform: scale(1.03);
}

/* The Popup Magic: Triggered when the user clicks (.image-box is focused) */
.image-box:focus {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  z-index: 9999;
  background-color: rgba(0, 0, 0, 0.85); /* Dark background overlay */
  display: flex;
  justify-content: center;
  align-items: center;
  cursor: default;
}

/* Style for the Zoomed Image inside the focused container */
.image-box:focus img {
  position: relative;
  z-index: 10001; /* Sits above the invisible close overlay */
  
  /* CRITICAL FIXES FOR LARGE IMAGE ZOOM: */
  width: 100%;
  height: 100%;
  max-width: 90vw;   /* Fills 90% of screen width */
  max-height: 85vh;  /* Fills 85% of screen height */
  object-fit: contain; /* Prevents stretching, maintains crisp aspect ratio */
  
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.7);
  animation: popIn 0.25s cubic-bezier(0.1, 0.8, 0.3, 1);
  pointer-events: none; /* Allows clicks to pass through to the close-overlay behind it */
}

/* Full screen transparent anchor that strips focus when clicked */
.image-box .close-overlay {
  display: none;
}
.image-box:focus .close-overlay {
  display: block;
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  z-index: 10000; /* Placed exactly between background and image */
  cursor: zoom-out;
}

/* Hide the close button by default */
.image-box .close-btn {
  display: none;
}

/* Show and style the highlighted close button */
.image-box:focus .close-btn {
  display: flex;
  justify-content: center;
  align-items: center;
  
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 10002;
  
  width: 48px; /* Slightly larger for easier mobile tapping */
  height: 48px;
  
  /* Highlight styling */
  background-color: #ff3b30; /* High-visibility vibrant red */
  color: #ffffff;
  text-decoration: none;
  font-family: Arial, sans-serif;
  font-size: 28px;
  font-weight: bold;
  border-radius: 50%;
  border: 2px solid #ffffff; /* Crisp white border to stand out */
  
  /* Drop shadow to lift it off dark images */
  box-shadow: 0 4px 12px rgba(255, 60, 48, 0.4); 
  
  transition: background-color 0.2s ease, transform 0.2s ease, box-shadow 0.2s ease;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent; /* Removes ugly default mobile flash */
}

/* Hover/Active effects for the highlighted close button */
.image-box:focus .close-btn:hover,
.image-box:focus .close-btn:active {
  background-color: #e02e24; /* Darker red on press */
  transform: scale(1.1);
  box-shadow: 0 6px 16px rgba(255, 60, 48, 0.6);
}

/* Smooth pop-up animation entry */
@keyframes popIn {
  from {
    transform: scale(0.85); /* Starts slightly larger for a smoother pop-in */
    opacity: 0;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}
