html, body {
  margin: 0;
  overflow: hidden;
}

.stage {
  box-sizing: border-box;
  min-height: 100vh;
  display: grid;
  place-items: center;
  margin: 0;
  background: #17141a;
  font-family: -apple-system, "Segoe UI", "Noto Sans KR", sans-serif;
  padding: clamp(8px, 4vw, 24px);
}

.stage {
  padding: clamp(8px, 2.4vw, 16px);
}

.lightbox-demo {
  position: relative;
}

.gallery {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  list-style: none;
  margin: 0;
  padding: 0;
  width: 148px;
  max-width: 100%;
}

.thumb {
  display: block;
  width: 100%;
  aspect-ratio: 1/1;
  padding: 0;
  border: 0;
  border-radius: 8px;
  overflow: hidden;
  cursor: pointer;
  box-shadow: 0 6px 12px rgba(23, 20, 26, 0.32);
  background: none;
  transition: transform 300ms ease-out;
}

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

.thumb:hover, .thumb:focus-visible, .thumb:active {
  transform: scale(1.05);
}

.lightbox {
  position: fixed;
  inset: 0;
  margin: auto;
  width: min(180px, 60vw);
  aspect-ratio: 1/1;
  padding: 0;
  border: 0;
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 14px 24px rgba(23, 20, 26, 0.32);
  opacity: 0;
  transform: scale(0.8);
  transition: opacity 300ms ease-out, transform 300ms ease-out, overlay 300ms ease-out allow-discrete, display 300ms ease-out allow-discrete;
}
@starting-style {
  .lightbox {
    opacity: 0;
    transform: scale(0.8);
  }
}

.lightbox:popover-open {
  opacity: 1;
  transform: scale(1);
}

.lightbox::backdrop {
  background: rgba(23, 20, 26, 0.7);
  opacity: 0;
  transition: opacity 300ms ease-out, overlay 300ms ease-out allow-discrete, display 300ms ease-out allow-discrete;
}
@starting-style {
  .lightbox::backdrop {
    opacity: 0;
  }
}

.lightbox:popover-open::backdrop {
  opacity: 1;
}

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

.lightbox__close {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 22px;
  height: 22px;
  border: 0;
  border-radius: 999px;
  background: rgba(23, 20, 26, 0.6);
  color: #ffffff;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
}

.preview-backdrop {
  position: absolute;
  inset: 0;
  border-radius: 16px;
  background: rgba(23, 20, 26, 0.7);
  opacity: 0;
  pointer-events: none;
}

.preview-panel {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 84px;
  height: 84px;
  border-radius: 12px;
  object-fit: cover;
  box-shadow: 0 14px 24px rgba(23, 20, 26, 0.32);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, -50%) scale(0.8);
}

.gallery.is-demo ~ .preview-backdrop {
  animation: backdrop-loop 2s ease-out infinite;
}

.gallery.is-demo ~ .preview-panel {
  animation: panel-loop 2s ease-out infinite;
}

@keyframes backdrop-loop {
  0%, 35% {
    opacity: 0;
  }
  50%, 80% {
    opacity: 1;
  }
  100% {
    opacity: 0;
  }
}
@keyframes panel-loop {
  0%, 35% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.8);
  }
  50%, 80% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.8);
  }
}
@media (prefers-reduced-motion: reduce) {
  .lightbox, .lightbox::backdrop, .thumb {
    transition: none;
  }
  .gallery.is-demo ~ .preview-backdrop, .gallery.is-demo ~ .preview-panel {
    animation: none;
  }
}
