/* Gallery page styles */

.gallery {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1.5rem;
  justify-items: center;
  padding: 1rem 0;
}

.gallery-header {
  width: 100%;
}

.gallery-header-spacer {
  height: 1.5rem;
}

.gallery img {
  max-width: 300px;
  border: 4px solid #000;
  cursor: zoom-in;
  transition: transform 0.2s ease;
}

.gallery img:hover {
  transform: scale(1.05);
}

/* Lightbox */
.lightbox {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(8, 12, 18, 0.44);
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 20000;
  flex-direction: column;
  padding: clamp(1rem, 3vw, 2rem) clamp(0.75rem, 2.5vw, 2rem) clamp(4.25rem, 8vh, 5.5rem);
}

.lightbox.hidden {
  display: none;
}

.lightbox-stage {
  --stage-max-width: min(96vw, 2200px);
  --stage-max-height: calc(100vh - clamp(7.75rem, 16vh, 9.5rem));
  width: fit-content;
  height: fit-content;
  max-width: var(--stage-max-width);
  max-height: var(--stage-max-height);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  touch-action: none;
  user-select: none;
  cursor: zoom-in;
  background: #000;
  outline: 4px solid #000;
  outline-offset: 0;
  box-shadow: 0 0 18px rgba(0, 0, 0, 0.45);
}

.lightbox-stage.is-zoomed {
  cursor: grab;
}

.lightbox-stage.is-dragging {
  cursor: grabbing;
}

.lightbox-stage img {
  max-width: var(--stage-max-width);
  max-height: var(--stage-max-height);
  width: auto;
  height: auto;
  object-fit: contain;
  display: block;
  border: 0;
  box-shadow: none;
  transform-origin: center center;
  transition: opacity 0.16s ease;
  will-change: transform;
}

.lightbox .close {
  position: absolute;
  top: 0.85rem;
  right: 1rem;
  font-size: 1.6rem;
  color: white;
  font-family: 'Press Start 2P', 'Minecraftia', monospace;
  line-height: 1;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.9);
  cursor: pointer;
  background: transparent;
  border: 0;
  padding: 0.3rem;
}

.lightbox.is-loading .lightbox-stage img {
  opacity: 0.25;
}

.lightbox-controls {
  position: absolute;
  bottom: 1rem;
  left: 50%;
  transform: translateX(-50%);
  display: inline-flex;
  justify-content: center;
  gap: 1rem;
}

.lightbox-controls button {
  background: #7a7a7a;
  color: white;
  font-family: 'Press Start 2P', 'Minecraftia', monospace;
  border: 2px solid #000;
  min-width: 10rem;
  padding: 0.65rem 1rem;
  cursor: pointer;
}

.lightbox-controls button:hover {
  background: #999;
}

.lightbox .close:focus-visible,
.lightbox-controls button:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 2px;
}

.lightbox-open {
  overflow: hidden;
}

.lightbox-open .controls-bar,
.lightbox-open .scroll-top {
  opacity: 0;
  pointer-events: none;
}

.frame {
  width: min(300px, 90vw);
  aspect-ratio: 1 / 1;
  background-image: url('../assets/frame.png');
  background-image: image-set(
    url('../assets/frame.webp') type('image/webp'),
    url('../assets/frame.png') type('image/png')
  );
  background-size: cover;
  background-position: center;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  box-sizing: border-box;
}

.frame img {
  width: 70%;
  height: 70%;
  object-fit: cover;
}

@media (max-width: 1024px) {
  .gallery {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 768px) {
  .gallery {
    grid-template-columns: 1fr;
    gap: 1rem;
  }

  .gallery img {
    max-width: 90%;
  }

  .lightbox-stage {
    --stage-max-width: 94vw;
    --stage-max-height: calc(100vh - 8.75rem);
  }

  .lightbox-controls button {
    min-width: 8.5rem;
    font-size: 0.75rem;
  }
}

@media (max-width: 600px) {
  .gallery-header-spacer {
    height: 1rem;
  }

  .lightbox .close {
    top: 1rem;
    right: 1rem;
  }

  .lightbox {
    padding-bottom: 4.25rem;
  }

  .lightbox-controls {
    width: calc(100% - 1.5rem);
    gap: 0.5rem;
  }
}

@media (max-width: 420px) {
  .frame {
    width: min(260px, 88vw);
  }

  .lightbox-controls button {
    min-width: 0;
    width: 100%;
  }
}
