/* Site-wide image viewer (js/dd-lightbox.js). */

img.ddz-able {
  cursor: zoom-in;
}
img.ddz-able:focus-visible {
  outline: 3px solid #eea676;
  outline-offset: 3px;
}

html.ddz-open,
html.ddz-open body {
  overflow: hidden !important;
}
/* The accessibility widget sits at the maximum z-index; hide it while the
   viewer is open so it doesn't cover the photo. */
html.ddz-open .uwy,
html.ddz-open .userway_buttons_wrapper,
html.ddz-open .uwif {
  display: none !important;
}

.ddz {
  position: fixed;
  inset: 0;
  z-index: 2147483600; /* above the sticky nav and the accessibility widget */
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  background: #03090f;
  color: #fff;
  opacity: 0;
  transition: opacity 180ms ease;
  -webkit-tap-highlight-color: transparent;
  font-family: "Figtree", system-ui, -apple-system, "Segoe UI", sans-serif;
}
.ddz[hidden] { display: none; }
.ddz.is-open { opacity: 1; }

/* Top bar: counter on the left, zoom + close on the right. */
.ddz__top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: max(0.6rem, env(safe-area-inset-top)) max(0.75rem, env(safe-area-inset-right)) 0.4rem max(1rem, env(safe-area-inset-left));
  position: relative;
  z-index: 2;
}
.ddz__count {
  font-size: 0.9rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: rgba(255, 255, 255, 0.8);
  font-variant-numeric: tabular-nums;
}
.ddz__actions { display: flex; gap: 0.5rem; }

.ddz__btn {
  display: inline-grid;
  place-items: center;
  width: 48px;
  height: 48px;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  cursor: pointer;
  transition: background 150ms ease, transform 150ms ease;
}
.ddz__btn:hover { background: rgba(255, 255, 255, 0.22); }
.ddz__btn:active { transform: scale(0.94); }
.ddz__btn:focus-visible { outline: 3px solid #eea676; outline-offset: 2px; }
.ddz__btn svg {
  width: 24px;
  height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.ddz__btn[hidden] { display: none; }

/* Stage: the photo fits the screen; zoomed, it grows and the stage scrolls. */
.ddz__stage {
  position: relative;
  min-height: 0;
  display: grid;
}
.ddz__scroller {
  min-height: 0;
  display: grid;
  place-items: center;
  overflow: hidden;
  padding: 0.25rem max(0.5rem, env(safe-area-inset-right)) 0.25rem max(0.5rem, env(safe-area-inset-left));
}
.ddz__img {
  display: block;
  /* Fill the stage and letterbox, so small source images are scaled up to
     the full screen instead of opening at their original size. */
  width: 100%;
  height: 100%;
  object-fit: contain;
  cursor: zoom-in;
  user-select: none;
  -webkit-user-drag: none;
  touch-action: manipulation;
}
.ddz.is-loading .ddz__img { opacity: 0; }

.ddz.is-zoomed .ddz__scroller {
  overflow: auto;
  place-items: start;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-x pan-y pinch-zoom;
}
.ddz.is-zoomed .ddz__img {
  max-width: none;
  max-height: none;
  height: auto;
  /* Zoom to the photo's full resolution, but at least 2.2x the screen width. */
  width: max(220vw, 1600px);
  border-radius: 0;
  cursor: zoom-out;
}
@media (min-width: 900px) {
  .ddz.is-zoomed .ddz__img { width: max(160vw, 2000px); }
}

.ddz__spinner {
  position: absolute;
  inset: 0;
  margin: auto;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.2);
  border-top-color: #eea676;
  animation: ddz-spin 800ms linear infinite;
  opacity: 0;
  pointer-events: none;
}
.ddz.is-loading .ddz__spinner { opacity: 1; }
@keyframes ddz-spin { to { transform: rotate(360deg); } }

/* Prev / next: large, vertically centred, clear of the edges. */
.ddz__nav {
  position: absolute;
  top: 50%;
  z-index: 2;
  transform: translateY(-50%);
  width: 52px;
  height: 52px;
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
.ddz__nav:active { transform: translateY(-50%) scale(0.94); }
.ddz__nav--prev { left: max(0.75rem, env(safe-area-inset-left)); }
.ddz__nav--next { right: max(0.75rem, env(safe-area-inset-right)); }
.ddz.is-zoomed .ddz__nav { display: none; }

.ddz__caption {
  margin: 0;
  padding: 0.7rem max(1.1rem, env(safe-area-inset-right)) max(0.9rem, env(safe-area-inset-bottom)) max(1.1rem, env(safe-area-inset-left));
  max-width: 70ch;
  justify-self: center;
  text-align: center;
  font-size: 0.95rem;
  line-height: 1.5;
  color: rgba(255, 255, 255, 0.86);
}
.ddz__caption[hidden] { display: none; }
.ddz.is-zoomed .ddz__caption { display: none; }

/* Phones: nav buttons sit at the bottom corners so they never cover the photo. */
@media (max-width: 640px) {
  .ddz__nav {
    top: auto;
    bottom: max(0.75rem, env(safe-area-inset-bottom));
    transform: none;
  }
  .ddz__nav:active { transform: scale(0.94); }
  .ddz__caption {
    padding-left: 4.25rem;
    padding-right: 4.25rem;
    font-size: 0.88rem;
    min-height: calc(52px + 1.5rem);
    display: grid;
    align-items: center;
  }
  .ddz__caption[hidden] { display: grid; visibility: hidden; }
}

@media (prefers-reduced-motion: reduce) {
  .ddz { transition: none; }
  .ddz__spinner { animation-duration: 2s; }
}
