/* ==========================================================================
   Lightbox — styles for sporpund/js/lightbox.js.

   Loaded only on the gallery page. Replaces gallery.css, which styled a
   vendored 2015 lightbox and pulled in four sprite images (close.png,
   prev.png, next.png and an animated loading.gif) that are no longer needed:
   the arrows are inline SVG and the spinner is a CSS animation.
   ========================================================================== */

/* A <dialog> is display:none until it is opened -- but that comes from the UA
   stylesheet, and *any* author `display` declaration beats it. Without this
   rule the closed dialog renders as a full-viewport dark block on the page,
   which is exactly what it did. Must stay above the .lightbox rule's own
   display: grid, and more specific than it. */
.lightbox:not([open]) {
  display: none;
}

.lightbox {
  width: 100vw;
  max-width: 100vw;
  height: 100dvh;
  max-height: 100dvh;
  margin: 0;
  padding: 0;
  border: 0;
  color: #fff;
  overflow: hidden;

  /* The scrim is on the dialog rather than only on ::backdrop. Both are drawn
     in the top layer and either would do visually, but ::backdrop is the one
     that varies between engines and screenshot pipelines -- and a lightbox
     whose background silently fails to darken is unreadable. The backdrop then
     only has to supply the blur. */
  background: rgba(10, 9, 12, .93);

  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: clamp(0.25rem, 2vw, 1.5rem);
}

.lightbox::backdrop {
  background: rgba(10, 9, 12, .8);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

.lightbox:focus-visible,
.lightbox:focus {
  outline: none;
}

/* ---------- the photograph ------------------------------------------------ */

.lightbox__figure {
  grid-column: 2;
  margin: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.85rem;
  min-height: 0;
  max-height: 100dvh;
  padding-block: clamp(3.5rem, 8vh, 5rem) clamp(1rem, 3vh, 2rem);
}

.lightbox__image {
  max-width: 100%;
  /* Leaves room for the caption and the close button above it. */
  max-height: calc(100dvh - 10rem);
  width: auto;
  height: auto;
  object-fit: contain;
  border-radius: 0.5rem;
  box-shadow: 0 24px 60px rgba(0, 0, 0, .5);
  transition: opacity 140ms ease;
}

.lightbox.is-loading .lightbox__image {
  opacity: 0;
}

/* A CSS spinner rather than the animated GIF the old bundle shipped. */
.lightbox.is-loading .lightbox__figure::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 2.25rem;
  height: 2.25rem;
  margin: -1.125rem 0 0 -1.125rem;
  border: 2px solid rgba(255, 255, 255, .25);
  border-top-color: #fff;
  border-radius: 50%;
  animation: lightbox-spin 700ms linear infinite;
}

@keyframes lightbox-spin {
  to { transform: rotate(360deg); }
}

/* ---------- caption ------------------------------------------------------- */

.lightbox__caption {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: center;
  gap: 0.75rem;
  max-width: 60ch;
  text-align: center;
  font-size: 0.9375rem;
  line-height: 1.45;
  text-wrap: pretty;
}

.lightbox__count {
  color: rgba(255, 255, 255, .6);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* ---------- controls ------------------------------------------------------ */

.lightbox__nav,
.lightbox__close {
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, .1);
  color: #fff;
  cursor: pointer;
  transition: background-color 160ms ease, transform 160ms ease;
}

.lightbox__nav {
  width: clamp(2.5rem, 6vw, 3.25rem);
  aspect-ratio: 1;
  margin-inline: clamp(0.25rem, 1.5vw, 1rem);
}

.lightbox__nav--prev { grid-column: 1; }
.lightbox__nav--next { grid-column: 3; }

.lightbox__nav svg {
  width: 45%;
  height: 45%;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.25;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.lightbox__close {
  position: absolute;
  top: clamp(0.75rem, 2vh, 1.25rem);
  right: clamp(0.75rem, 2vw, 1.25rem);
  width: 2.75rem;
  height: 2.75rem;
  font-size: 1.75rem;
  line-height: 1;
}

.lightbox__nav:hover,
.lightbox__close:hover {
  background: rgba(255, 255, 255, .22);
}

.lightbox__nav:active,
.lightbox__close:active {
  transform: scale(0.94);
}

.lightbox__nav:focus-visible,
.lightbox__close:focus-visible {
  outline: 3px solid #fff;
  outline-offset: 3px;
}

.lightbox__nav[hidden] {
  display: none;
}

/* On a phone the arrows would leave the photograph a sliver of the screen, so
   they sit over it instead. Swiping works too. */
@media (max-width: 575.98px) {
  .lightbox {
    grid-template-columns: minmax(0, 1fr);
  }

  .lightbox__figure {
    grid-column: 1;
  }

  .lightbox__nav {
    position: absolute;
    bottom: clamp(1rem, 4vh, 2rem);
    grid-column: 1;
  }

  .lightbox__nav--prev { left: 22%; }
  .lightbox__nav--next { right: 22%; }
}

@media (prefers-reduced-motion: reduce) {
  .lightbox__image,
  .lightbox__nav,
  .lightbox__close {
    transition: none;
  }

  .lightbox.is-loading .lightbox__figure::before {
    animation-duration: 1.4s;
  }
}
