/* ==============================================================================
   LIGHTBOX (photo viewer of the gallery blocks)
   ============================================================================== */

/* Each gallery photo is wrapped in a link to its own file (gallery.html):
   block-level so the grid cell keeps the image's size, and the zoom
   cursor says a click enlarges it rather than leaving the page. The
   global :focus-visible ring of main.css outlines it; the radius makes
   that ring follow the image's rounded corners. */
.gallery__link {
  display: block;
  border-radius: var(--radius-md);
  cursor: zoom-in;
}

.gallery__link picture {
  display: block;
}

/* The dialog static/js/lightbox.js builds once and opens with showModal().
   It lives in the top layer, above everything else on the page, so it
   needs no z-index of its own. It stays dark in every skin and theme: it
   is a photo viewer, and a neutral black shows the photo's own colours
   without the red of the site tinting them. */
.lightbox {
  /* Near-black at 94 %, the same depth as caminarte's viewer; a token of
     the site would carry the skin's red into the frame. */
  --lightbox-bg: rgba(0, 0, 0, 0.94);
  --lightbox-control-bg: rgba(255, 255, 255, 0.12);
  --lightbox-control-bg-hover: rgba(255, 255, 255, 0.24);

  position: fixed;
  inset: 0;
  width: 100%;
  max-width: none;
  height: 100%;
  max-height: none;
  margin: 0;
  padding: var(--spacing-md);
  border: none;
  background: var(--lightbox-bg);
  color: var(--action-bar-text);
}

/* The dialog already covers the whole screen; the backdrop only matters
   for the instant before it paints. */
.lightbox::backdrop {
  background: rgba(0, 0, 0, 0.94);
}

/* Only an open dialog becomes a grid: setting display on the closed one
   would show it. The photo takes the free space, the bottom bar its own
   line underneath. */
.lightbox[open] {
  display: grid;
  grid-template-rows: 1fr auto;
}

/* The page behind the viewer must not scroll under a wheel or a swipe. */
html:has(.lightbox[open]) {
  overflow: hidden;
}

.lightbox-stage {
  display: grid;
  place-items: center;
  min-height: 0;

  /* Lets lightbox.js read a horizontal drag as a swipe; see the same rule
     on .slideshow__viewport. */
  touch-action: pan-y;
}

.lightbox-image {
  max-width: 90vw;
  max-height: 85vh;
  border-radius: var(--radius-sm);
  object-fit: contain;
}

.lightbox-close,
.lightbox-prev,
.lightbox-next {
  position: absolute;
  display: grid;
  place-items: center;
  padding: 0;
  border: none;
  border-radius: var(--radius-md);
  background: var(--lightbox-control-bg);
  color: var(--action-bar-text);
  line-height: 1;
  cursor: pointer;
}

.lightbox-close:hover,
.lightbox-prev:hover,
.lightbox-next:hover {
  background: var(--lightbox-control-bg-hover);
}

/* The author stylesheet sets display on these buttons, which would beat
   the browser's own [hidden] rule; lightbox.js hides the arrows in a
   gallery of one photo. */
.lightbox-prev[hidden],
.lightbox-next[hidden],
.lightbox-counter[hidden] {
  display: none;
}

.lightbox-close {
  top: var(--spacing-md);
  right: var(--spacing-md);
  width: 48px;
  height: 48px;
  font-size: 2rem;
}

.lightbox-prev,
.lightbox-next {
  top: 50%;
  width: 52px;
  height: 80px;
  font-size: 2.5rem;
  transform: translateY(-50%);
}

.lightbox-prev {
  left: var(--spacing-sm);
}

.lightbox-next {
  right: var(--spacing-sm);
}

.lightbox-bottom {
  margin: var(--spacing-sm) 0 0;
  color: var(--action-bar-text-muted);
  font-size: 0.95rem;
  text-align: center;
}

.lightbox-counter {
  margin-right: var(--spacing-md);
  color: var(--accent-blue);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.lightbox-caption {
  font-style: italic;
}

/* A short fade on open, the one bit of motion the viewer has; nothing
   moves at all for a visitor who asked for reduced motion. */
@media (prefers-reduced-motion: no-preference) {
  .lightbox[open] {
    animation: lightbox-fade-in 0.2s ease-out;
  }
}

@keyframes lightbox-fade-in {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

/* On a phone the arrows sit over the edges of the photo, so they shrink
   to the 44 px minimum touch target and hug the screen edge. */
@media (max-width: 640px) {
  .lightbox {
    padding: var(--spacing-sm);
  }

  .lightbox-prev,
  .lightbox-next {
    width: 44px;
    height: 60px;
    font-size: 2rem;
  }

  .lightbox-prev {
    left: var(--spacing-xs);
  }

  .lightbox-next {
    right: var(--spacing-xs);
  }

  .lightbox-close {
    top: var(--spacing-sm);
    right: var(--spacing-sm);
    width: 44px;
    height: 44px;
  }
}
