/* ==========================================================================
   Photo lightbox
   Loaded after style.css and paired with js/lightbox.js. Kept in its own
   file so the main stylesheet stays the layout system and this stays the
   one overlay. Tokens come from style.css.
   ========================================================================== */

/* --- Trigger state ------------------------------------------------------- */
/* Photos only get this class once the script has wired them up, so nothing
   advertises a click that won't happen. */
.is-viewable {
  cursor: zoom-in;
}

.is-viewable:focus-visible {
  outline: 3px solid var(--accent-deep);
  outline-offset: 3px;
}

/* --- Page state ---------------------------------------------------------- */
.has-lightbox,
.has-lightbox body {
  overflow: hidden;
}

/* --- Overlay ------------------------------------------------------------- */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  /* Top pad clears the close button, which is pinned to the viewport corner. */
  padding: clamp(3.75rem, 8vw, 4.75rem) clamp(1rem, 4vw, 3rem) clamp(1.25rem, 4vw, 3rem);
}

.lightbox__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(18, 25, 26, 0.94);
  cursor: zoom-out;
}

/* Rows rather than a fixed image height: the figure takes whatever is left
   after the caption and counter, and the photo scales to fit inside it. */
.lightbox__dialog {
  position: relative;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  grid-template-rows: minmax(0, 1fr) auto;
  align-items: center;
  gap: clamp(0.5rem, 2vw, 1.5rem);
  width: 100%;
  height: 100%;
  max-width: var(--shell);
  animation: lightbox-in 0.28s var(--ease) both;
}

@keyframes lightbox-in {
  from { opacity: 0; transform: scale(0.985); }
  to   { opacity: 1; transform: none; }
}

/* --- The photo ----------------------------------------------------------- */
.lightbox__figure {
  grid-column: 2;
  grid-row: 1;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  justify-items: center;
  align-content: center;
  margin: 0;
  min-width: 0;
  min-height: 0;
  height: 100%;
  text-align: center;
}

.lightbox__img {
  display: block;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: var(--radius-sm);
  background: var(--ink);
}

.lightbox__caption {
  margin: 1rem auto 0;
  max-width: 60ch;
  color: rgba(255, 255, 255, 0.82);
  font-size: 0.95rem;
  line-height: 1.5;
}

.lightbox__count {
  grid-column: 2;
  grid-row: 2;
  margin: 0.45rem 0 0;
  color: rgba(255, 255, 255, 0.72);
  font-size: 0.92rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  text-align: center;
}

/* --- Controls ------------------------------------------------------------ */
.lightbox__nav,
.lightbox__close {
  position: relative;
  display: grid;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  cursor: pointer;
  transition: background 0.2s var(--ease), border-color 0.2s var(--ease);
}

.lightbox__nav:hover,
.lightbox__close:hover {
  background: rgba(255, 255, 255, 0.18);
  border-color: rgba(255, 255, 255, 0.4);
}

.lightbox__nav:focus-visible,
.lightbox__close:focus-visible {
  outline: 3px solid var(--accent-bright);
  outline-offset: 2px;
}

.lightbox__nav {
  width: clamp(2.75rem, 6vw, 3.25rem);
  aspect-ratio: 1;
}

.lightbox__nav svg { width: 55%; }

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

/* Pinned to the viewport corner, not the photo — a photo-relative corner
   moves with every image and ends up somewhere different each time. */
.lightbox__close {
  position: fixed;
  top: clamp(0.75rem, 2vw, 1.5rem);
  right: clamp(0.75rem, 2vw, 1.5rem);
  width: 2.75rem;
  aspect-ratio: 1;
}

.lightbox__close svg { width: 50%; }

/* --- Narrow screens ------------------------------------------------------ */
/* Arrows drop under the photo — at phone width there's no side room, and a
   floating arrow over the image covers the thing you opened it to see. */
@media (max-width: 720px) {
  .lightbox__dialog {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: minmax(0, 1fr) auto auto;
    justify-items: center;
  }

  .lightbox__figure { grid-column: 1 / -1; grid-row: 1; }
  .lightbox__count  { grid-column: 1 / -1; grid-row: 3; }

  .lightbox__nav--prev { grid-column: 1; grid-row: 2; justify-self: end; }
  .lightbox__nav--next { grid-column: 2; grid-row: 2; justify-self: start; }
}

@media (prefers-reduced-motion: reduce) {
  .lightbox__dialog { animation: none; }
}
