/* CSS Custom Properties for consistency */
:root {
  --overlay-bg: rgba(0, 0, 0, 0.5);
  --text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.8);
  --transition-duration: 0.3s;
  --transition-easing: ease-in-out;
  --hover-scale: 1.05;
  --border-radius: 8px;
  --image-height: 200px;
}

/* Grid overlay container */
.grid_overlay {
    color: #fff;
    margin: 3rem 0 0;
}

.grid_overlay .block {
  padding: 0;
  text-align: center;
}

/* Title styling */
.grid_overlay h3 {
  font-size: clamp(1rem, 4vw, 1.25rem);
  line-height: 1.2;
  text-shadow: var(--text-shadow);
  position: relative;
  z-index: 2;
  color: #fff;
  margin: 0 0.5rem;
}

/* Improved centering with modern approach */
.centered {
  position: absolute;
  inset: 0;
  background: var(--overlay-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity var(--transition-duration) var(--transition-easing);
}

/* Image animation container */
.animate-img {
  position: relative;
  overflow: hidden;
  border-radius: var(--border-radius);
  box-shadow: 0 4px 6px rgb(0 0 0 / 25%);
  transition: transform var(--transition-duration) var(--transition-easing);
}

.animate-img .inner-block {
  border: 2px solid transparent;
  border-radius: var(--border-radius);
  overflow: hidden;
}

.animate-img figure {
  margin: 0;
  position: relative;
  overflow: hidden;
}

.animate-img img {
  display: block;
  height: var(--image-height);
  width: 100%;
  object-fit: cover;
  transition: transform var(--transition-duration) var(--transition-easing);
}

/* Hover and focus states */
.animate-img:hover,
.animate-img:focus-within {
  transform: translateY(-4px);
  box-shadow: 0 8px 16px rgba(0, 0, 0, 0.2);
}

.animate-img:hover img,
.animate-img:focus-within img {
  transform: scale(var(--hover-scale));
}

.animate-img:hover .centered,
.animate-img:focus-within .centered {
  opacity: 1;
}

/* Focus accessibility */
.animate-img a:focus {
  outline: 2px solid #fff;
  outline-offset: 2px;
}

/* Reduced motion preference */
@media (prefers-reduced-motion: reduce) {
  .animate-img,
  .animate-img img,
  .centered {
    transition: none;
  }
  
  .animate-img:hover img,
  .animate-img:focus-within img {
    transform: none;
  }
}

/* Responsive design improvements */
@media (max-width: 575px) {
  :root {
    --image-height: 150px;
  }
  
  .grid_overlay .block {
    padding: 0.5rem 0;
  }
}

@media (min-width: 576px) and (max-width: 768px) {
  :root {
    --image-height: 180px;
  }
}

@media (min-width: 1200px) {
  :root {
    --image-height: 220px;
    --hover-scale: 1.08;
  }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
  .animate-img .inner-block {
    border-color: currentColor;
  }
  
  .centered {
    background: rgba(0, 0, 0, 0.8);
  }
}