.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 20px;
  max-width: 1200px;
  width: 100%;
  margin: 0;
  list-style: none;
}

.thumbnail {
  position: relative;
  aspect-ratio: 1;
  overflow: hidden;
  border-radius: 8px;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
  cursor: pointer;
  transition:
    transform 0.2s ease,
    box-shadow 0.2s ease;
}

.thumbnail img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.view-transition-thumbnail {
  view-transition-name: thumbnail-view-transition;
}

dialog {
  border: none;
  padding: 0;
  margin: 0;
  background: rgba(0, 0, 0, 0);
  width: 100vw;
  height: 100svh;
  max-width: 100vw;
  max-height: 100svh;
}

dialog::backdrop {
  background-color: var(--modal-backdrop);
  backdrop-filter: blur(6px);
}

.modal-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  height: 100vh;
  max-width: 100%;
  max-height: 100vh;
  overflow-y: auto;
  overscroll-behavior-y: none;
  flex-shrink: 0;
  scrollbar-width: none;
  scroll-snap-type: y mandatory;
  pointer-events: none;
}

.pre-image {
  scroll-snap-align: start;
  height: 100vh;
  width: 1px;
  flex-shrink: 0;
  pointer-events: auto;
}

.post-image {
  scroll-snap-align: end;
  height: 100vh;
  width: 1px;
  flex-shrink: 0;
  pointer-events: auto;
}

.modal-image-container {
  scroll-snap-align: start;
  scroll-snap-stop: always;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100dvh;
  width: 100vw;
  flex-shrink: 0;
  pointer-events: none;
}

.modal-image {
  max-width: 90vw;
  max-height: 90vh;
  object-fit: contain;
  border-radius: 8px;
  touch-action: manipulation;
  view-transition-name: thumbnail-view-transition;
}

.modal-gallery {
  height: 100dvh;
  width: 100vw;
  overflow-x: scroll;
  overflow-y: hidden;
  display: flex;
  scrollbar-width: none;
  scroll-snap-type: x mandatory;
  pointer-events: none;
}

.modal-gallery-item {
  display: flex;
  align-items: center;
  justify-content: center;
  scroll-snap-align: start;
  scroll-snap-stop: always;
  height: 100dvh;
  width: 100vw;
  flex-shrink: 0;
  pointer-events: none;
}

.modal-gallery-image {
  max-width: 90vw;
  max-height: 90vh;
  object-fit: contain;
  border-radius: 8px;
  pointer-events: auto;
}

.close {
  position: fixed;
  top: 20px;
  right: 20px;
  color: white;
  font-size: 28px;
  font-weight: bold;
  cursor: pointer;
  background: none;
  border: none;
  padding: 8px;
  border-radius: 50%;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.2s ease;
  z-index: 1001;
}

.close:hover {
  background-color: rgba(255, 255, 255, 0.1);
}

.close:active {
  background-color: rgba(255, 255, 255, 0.2);
}

/* Responsive adjustments */
@media (max-width: 768px) {
  .gallery {
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 15px;
  }
}

@media (max-width: 480px) {
  .gallery {
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    gap: 10px;
  }
}
