/* Estilos modernos para la galería */
.gallery-container {
  /* rely on global .container rules for consistent horizontal gutters */
  max-width: var(--page-max-width);
  margin-left: auto;
  margin-right: auto;
  padding-left: var(--section-horizontal-gutter);
  padding-right: var(--section-horizontal-gutter);
  display: block;
}

/* Each gallery thumb is an anchor (.gallery-thumb) wrapping .gallery-wrap */
.gallery-thumb {
  display: block;
  outline: none;
}

.gallery-thumb:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--accent-color), transparent 10%);
  outline-offset: 4px;
  border-radius: 10px;
}

.gallery-wrap {
  position: relative;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.10);
  transition: transform 0.28s ease, box-shadow 0.28s ease;
  background-color: var(--surface-color);
  display: block;
}

.gallery-wrap:hover,
.gallery-thumb:focus .gallery-wrap {
  transform: translateY(-6px); /* lift the card slightly without scaling the image */
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.16);
}


.gallery-wrap img {
  display: block;
  width: 100%;
  height: auto;
  object-fit: cover; /* keep filling the box */
  object-position: center center;
  transition: none; /* avoid scaling transitions that can blur */
  background: var(--surface-color);
}

/* hide captions entirely as requested */
.gallery-overlay {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: auto;
  /* tiny fade at the bottom so center of the image stays clear */
  background: linear-gradient(0deg, rgba(0,0,0,0.36), rgba(0,0,0,0.0));
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0 0 8px 0;
  opacity: 0;
  transition: opacity 0.12s ease, transform 0.12s ease;
  transform: translateY(6px);
  pointer-events: none;
}

.gallery-wrap:hover .gallery-overlay,
.gallery-thumb:focus .gallery-wrap .gallery-overlay {
  display: none; /* completely hide overlay */
}

.gallery-info {
  width: 100%;
  max-width: 100%;
  text-align: center;
  color: var(--contrast-color);
  padding: 10px 14px;
  transform: translateY(8px);
  transition: transform 0.18s ease, opacity 0.18s ease;
  pointer-events: none;
  text-shadow: 0 1px 3px rgba(0,0,0,0.45);
  background: rgba(0,0,0,0.36);
  border-bottom-left-radius: 12px;
  border-bottom-right-radius: 12px;
  box-sizing: border-box;
}

.gallery-wrap:hover .gallery-info,
.gallery-thumb:focus .gallery-wrap .gallery-info {
  transform: translateY(0);
}

.gallery-info h4 {
  font-size: 1.125rem;
  font-weight: 600;
  margin-bottom: 8px;
  color: var(--contrast-color);
}

.gallery-info p {
  font-size: 0.95rem;
  color: color-mix(in srgb, var(--contrast-color), transparent 22%);
  margin: 0;
}

/* Integrate with AOS animations */
[data-aos="zoom-in"] {
  transform: scale(0.96);
  opacity: 0;
  transition-property: transform, opacity;
}

[data-aos="zoom-in"].aos-animate {
  transform: scale(1);
  opacity: 1;
}

/* Responsive tweaks */
@media (max-width: 768px) {
  .gallery-wrap img {
    aspect-ratio: 16/10;
  }

  .gallery-info h4 {
    font-size: 1rem;
  }

  .gallery-info p {
    font-size: 0.9rem;
  }
}

/* Use CSS Grid to create uniform square thumbnails and keep the grid centered */
.gallery-grid {
  display: grid;
  /* Desktop: 3x3 grid layout */
  grid-template-columns: repeat(3, minmax(220px, 1fr));
  grid-auto-rows: 1fr;
  gap: 20px;
  justify-content: center;
  align-items: center;
  max-width: var(--page-max-width);
  margin: 0 auto;
  padding: 0; /* container handles horizontal gutters */
  width: 100%;
}

.gallery-item {
  display: block;
}

/* Make thumbnails square and force the image to cover the area */
.gallery-item .gallery-wrap {
  width: 100%;
  aspect-ratio: 1/1; /* square */
  display: block;
  overflow: hidden;
  border-radius: 12px;
  margin: 0 auto; /* ensure each wrap is centered if cell is wider */
  max-width: 100%;
}

.gallery-item .gallery-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover; /* make all images fill the container uniformly */
  object-position: center center;
  display: block;
  aspect-ratio: 1/1; /* ensure perfect square shape */
  image-rendering: -webkit-optimize-contrast; /* improve sharpness in webkit */
  image-rendering: crisp-edges; /* improve overall image crispness */
  -webkit-backface-visibility: hidden; /* prevent blurry text on transforms */
  backface-visibility: hidden; /* standard property for compatibility */
  transform: translateZ(0); /* force GPU acceleration */
  will-change: transform; /* optimize performance */
  filter: brightness(1.02) contrast(1.02); /* subtle enhancement */
}

/* Improve photo rendering quality when images are scaled in the browser.
   These rules help avoid blurry upscaling in some browsers. */
.gallery-item .gallery-wrap img {
  image-rendering: auto;
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
  transform: translateZ(0); /* promote to its own layer to improve crispness */
  will-change: transform; /* hint for smoother rendering when hovered */
  max-width: 100%;
}

@media (max-width: 1200px) {
  .gallery-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 15px;
  }
}

@media (max-width: 768px) {
  .gallery-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
  }
  .gallery-info h4 { font-size: 0.95rem; }
}

@media (max-width: 576px) {
  /* Mobile: 1 column */
  .gallery-grid { grid-template-columns: 1fr; gap: 12px; max-width: 420px; }
  .gallery-item { margin-bottom: 0; }
  .gallery-info h4 { font-size: 0.95rem; }
}

/* Ensure anchors are keyboard-accessible and have visible focus */
.gallery-item a:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent-color), transparent 10%); outline-offset: 4px; }

/* Small visual tweak: captions only show on hover for clarity */
.gallery-overlay .gallery-info { opacity: 0; transition: opacity 0.22s ease, transform 0.22s ease; }
.gallery-wrap:hover .gallery-overlay .gallery-info,
.gallery-thumb:focus .gallery-wrap .gallery-info {
  opacity: 1;
  transform: translateY(0);
}

/* Ensure images center on their focal point */
.gallery-wrap img { object-position: center center; }