/* Grid */
.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 12px;
  padding-top: 1rem;
}
.thumb {
  display: block;
  border-radius: 6px;
  overflow: hidden;
  box-shadow: 0 1px 3px rgba(0,0,0,.1);
  transition: transform 0.3s ease, box-shadow 0.3s ease;
  cursor: pointer;
}

.thumb:hover {
  transform: scale(1.05);
  box-shadow: 0 4px 12px rgba(0,0,0,.2);
}

.thumb img {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  display: block;
  transition: transform 0.3s ease;
}

.thumb:hover img {
  transform: scale(1.1);
}

/* Lightbox overlay */
#lightbox {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0,0,0,.9);
  display: none;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  z-index: 1000;
  color: #fff;
}

/* Dark mode lightbox adjustments */
:root[data-theme="dark"] #lightbox {
  background: rgba(0,0,0,.95);
}
#lightbox[aria-hidden="false"] { display: flex; }

.lb-figure {
  margin: 0;
  max-width: min(96vw, 1400px);
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .5rem;
}
.lb-image {
  width: 100%;
  height: calc(90vh - 3rem);
  object-fit: contain;
  background: #000;
  border-radius: 6px;
}
.lb-caption {
  font-size: .95rem;
  color: #ddd;
  text-align: center;
  max-width: 90ch;
}

/* Controls */
.lb-close, .lb-prev, .lb-next {
  position: absolute;
  background: rgba(255,255,255,.12);
  color: #fff;
  border: 0;
  padding: .5rem .75rem;
  cursor: pointer;
  border-radius: 6px;
  backdrop-filter: blur(2px);
  transition: background .15s ease;
}
.lb-close:hover, .lb-prev:hover, .lb-next:hover { background: rgba(255,255,255,.2); }

.lb-close { top: 12px; right: 12px; font-size: 2rem; line-height: 1; }
.lb-prev { left: 12px; top: 50%; transform: translateY(-50%); font-size: 1.5rem; }
.lb-next { right: 12px; top: 50%; transform: translateY(-50%); font-size: 1.5rem; }

@media (max-width: 600px) {
  .lb-image { height: calc(80vh - 3rem); }
}

/* Accessibility: Respect reduced motion preferences */
@media (prefers-reduced-motion: reduce) {
  .thumb,
  .thumb img {
    transition: none;
  }

  .thumb:hover {
    transform: none;
  }

  .thumb:hover img {
    transform: none;
  }
}
