/* Full-size photo viewer. The one place in the app that goes dark: the point is the
   photograph, and a light frame around it competes. */

.lightbox {
  width: 100vw;
  max-width: 100vw;
  height: 100vh;
  max-height: 100vh;
  margin: 0;
  padding: 0;
  border: none;
  background: rgba(20, 26, 21, 0.96);
  color: #f2f4ee;
  /* Only the stage ever scrolls, so the controls and the counter cannot drift */
  overflow: hidden;
  overscroll-behavior: contain;
}

.lightbox::backdrop { background: rgba(20, 26, 21, 0.9); }

/* Flex, not grid: a percentage max-height on a grid item resolves against its grid
   AREA, which is auto-sized by the item itself — circular, so the cap is ignored and a
   tall photo overflows the screen. A flex container with a definite height gives the
   item something real to measure against. */
.lightbox-stage {
  display: flex;
  width: 100%;
  height: 100%;
  padding: calc(env(safe-area-inset-top) + 56px) 16px
           calc(env(safe-area-inset-bottom) + 56px);
  overflow: auto;
  overscroll-behavior: contain;
}

/* Shows only the crop rectangle — the picture that was framed, never the file it came
   from. Sized in px by lightbox.js, which knows the crop's pixel size and the room
   available; CSS cannot fit a box whose contents are positioned by crop maths.
   `margin: auto` rather than centring on the container, so the overflow stays reachable
   once zoomed. */
.lightbox-crop {
  position: relative;
  margin: auto;
  flex: none;
  overflow: hidden;
  border-radius: 6px;
}

/* Same offsets the cards use, and the same rotor inside — see .rotor in cards.css */
.lightbox-crop > .rotor {
  position: absolute;
  width: calc(100% / var(--cw, 1));
  height: auto;
  max-width: none;
  left: calc(var(--cx, 0) / var(--cw, 1) * -100%);
  top: calc(var(--cy, 0) / var(--ch, 1) * -100%);
  display: block;
}

/* Only offer zoom when the crop is actually being shown smaller than it really is */
.lightbox-crop.can-zoom { cursor: zoom-in; }

/* Zoomed: the crop at its own natural pixels, and the stage becomes a pannable window */
.lightbox-stage.is-zoomed .lightbox-crop {
  border-radius: 0;
  cursor: zoom-out;
}

/* Fixed, so nothing here shifts with the photo's shape or with panning while zoomed */
.lightbox-close,
.lightbox-prev,
.lightbox-next {
  position: fixed;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 50%;
  background: rgba(242, 244, 238, 0.14);
  color: #f2f4ee;
  font-size: 1.3rem;
  line-height: 1;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.lightbox-close:active,
.lightbox-prev:active,
.lightbox-next:active { transform: scale(0.94); }

.lightbox-close {
  top: calc(env(safe-area-inset-top) + 12px);
  right: 12px;
}

.lightbox-prev,
.lightbox-next {
  top: 50%;
  margin-top: -22px;
}

.lightbox-prev { left: 12px; }
.lightbox-next { right: 12px; }

.lightbox-prev[hidden],
.lightbox-next[hidden],
.lightbox-count[hidden] { display: none; }

.lightbox-count {
  position: fixed;
  left: 0;
  right: 0;
  bottom: calc(env(safe-area-inset-bottom) + 18px);
  text-align: center;
  font-size: 0.8rem;
  font-weight: 600;
  color: rgba(242, 244, 238, 0.75);
  pointer-events: none;
}
