/* Gallery controls and a native modal dialog; colours use the shared tokens. */
.p-shot {
  display: block; width: 100%; padding: 0; border: 0;
  color: var(--ink); font: inherit; cursor: pointer; text-align: left;
}
.p-shot-hint {
  position: absolute; right: 12px; bottom: 12px; z-index: 3;
  padding: 8px 12px; background: var(--bg); color: var(--ink);
  font-size: var(--fs-label); letter-spacing: .08em;
  pointer-events: none; opacity: 0; transition: opacity .35s ease;
}
@media (hover: hover) and (pointer: fine) {
  .p-shot:hover .p-shot-hint,
  .p-shot:focus-visible .p-shot-hint { opacity: 1; }
}
body.lightbox-open { position: fixed; left: 0; right: 0; width: 100%; }

.lightbox {
  --lightbox-scrim: rgb(0 0 0 / 0.8);
  --lightbox-blur: 16px;
  position: fixed; inset: 0; width: 100%; height: 100%; height: 100dvh;
  max-width: none; max-height: none; margin: 0; border: 0;
  padding: max(12px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  /* The dialog box sits above ::backdrop. A solid fill here would hide
     the scrim and the blur of the page behind it. */
  background: transparent; color: var(--bg); overscroll-behavior: contain;
  /* Transformed slides stick out of the frame. Clipping here, not on body,
     keeps that overflow off the viewport scrollbar. */
  overflow: hidden;
}
.lightbox[open] {
  display: grid; grid-template-rows: auto minmax(0, 1fr); gap: 12px;
}
.lightbox::backdrop {
  background: var(--lightbox-scrim);
  -webkit-backdrop-filter: blur(var(--lightbox-blur));
  backdrop-filter: blur(var(--lightbox-blur));
}

/* Open fades only: background, then the photo, then the controls.
   The delays overlap, so the photo starts before the background finishes
   and the controls start before the photo finishes. No scale.
   is-awaiting-open lasts only until that first photo fade starts.
   Leaving it on for the whole session hid every later slide, because
   playSlide removes the open-fade class when it swaps photos. */
@keyframes lightbox-fade {
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes lightbox-out {
  from { opacity: 1; }
  to { opacity: 0; }
}
.lightbox.is-opening::backdrop { animation: lightbox-fade .45s var(--ease) both; }
.lightbox.is-opening .lightbox-bar,
.lightbox.is-opening .lightbox-arrow { animation: lightbox-fade .45s var(--ease) .3s both; }
.lightbox-photo.is-show.is-awaiting-open { opacity: 0; transition: none; }
.lightbox-photo.is-photo-open { animation: lightbox-fade .5s var(--ease) both; transition: none; }
.lightbox-photo.is-photo-late { animation: lightbox-fade .4s var(--ease) both; transition: none; }
.lightbox.is-closing,
.lightbox.is-closing::backdrop { animation: lightbox-out .2s ease both; }

.lightbox-bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.lightbox-bar-lead { display: flex; align-items: center; gap: 12px; min-width: 0; }
.lightbox-count { font-size: var(--fs-meta); letter-spacing: .12em; }
.lightbox-status { display: flex; align-items: center; gap: 8px; margin: 0; min-height: 18px; font-size: var(--fs-meta); line-height: 1.4; }
.lightbox-spinner {
  display: block;
  width: 16px; height: 16px; flex: 0 0 auto;
  border: 1.5px solid rgb(250 249 246 / 0.35);
  border-top-color: var(--bg);
  border-radius: 50%;
  animation: lightbox-spin .7s linear infinite;
}
.lightbox-spinner[hidden] { display: none; }
@keyframes lightbox-spin { to { transform: rotate(360deg); } }
.lightbox-control, .lightbox-arrow {
  display: grid; place-items: center;
  min-width: 44px; min-height: 44px; padding: 0;
  border: 0; background: transparent; color: var(--bg);
  font: inherit; cursor: pointer;
}
.lightbox-control:hover, .lightbox-arrow:hover { color: var(--gold); }
.lightbox-control:focus-visible, .lightbox-arrow:focus-visible { outline-color: var(--bg); }
.lightbox-close { margin-left: auto; }

.lightbox-stage {
  position: relative;
  min-width: 0; min-height: 0;
  display: grid; grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center; gap: 8px;
  touch-action: pan-y pinch-zoom;
}
.lightbox-frame {
  min-width: 0; min-height: 0; width: 100%; height: 100%;
  display: grid; grid-template: 1fr / 1fr;
  overflow: hidden;
}
/* True crossfade: both layers share the same opacity transition. Incoming
   fades in on top (z 2) while outgoing fades out underneath (z 1), then
   JS parks the outgoing layer. No slide, no solid black fill — letterbox
   areas stay transparent so only ::backdrop (80% black + blur) shows
   through. is-pending is the layer that decodes next. */
.lightbox-photo {
  grid-area: 1 / 1;
  width: 100%; height: 100%; min-height: 0; object-fit: contain;
  /* Always transparent: never paint a solid/#000 letterbox or stage fill.
     Mid-crossfade you may see ::backdrop through both images — that is OK. */
  background: transparent;
  opacity: 0; transform: none;
  transition: opacity .45s var(--ease);
}
.lightbox-photo.is-pending { opacity: 0; transform: none; transition: none; z-index: 0; }
.lightbox-photo.is-show { opacity: 1; transform: none; z-index: 2; }
.lightbox-photo.is-leaving {
  opacity: 0; transform: none; z-index: 1;
  background: transparent;
}
.lightbox-photo.is-entering {
  opacity: 0; transform: none; transition: none; z-index: 2;
  background: transparent;
}
.lightbox-photo[hidden] { display: none; }
.lightbox-arrow svg, .lightbox-close svg { display: block; }

@media (max-width: 800px) {
  .lightbox-stage { grid-template-columns: minmax(0, 1fr); }
  .lightbox-arrow {
    position: absolute; top: 50%; z-index: 4;
    background: rgba(28, 26, 22, .35);
  }
  .lightbox-prev { left: 4px; transform: translateY(-50%); }
  .lightbox-next { right: 4px; transform: translateY(-50%); }
}

@media (prefers-reduced-motion: reduce) {
  .lightbox,
  .lightbox.is-opening,
  .lightbox.is-opening::backdrop,
  .lightbox.is-opening .lightbox-bar,
  .lightbox.is-opening .lightbox-arrow,
  .lightbox-photo.is-show.is-awaiting-open,
  .lightbox-photo,
  .lightbox-photo.is-show,
  .lightbox-photo.is-photo-open,
  .lightbox-photo.is-photo-late,
  .lightbox-photo.is-leaving,
  .lightbox-photo.is-entering,
  .lightbox.is-closing,
  .lightbox.is-closing::backdrop {
    transition: none;
    animation: none;
    transform: none;
    opacity: 1;
  }
  .lightbox-photo.is-pending,
  .lightbox-photo.is-entering { opacity: 0; }
  .lightbox-spinner { animation: none; }
  .lightbox,
  .lightbox.is-opening { background-color: transparent; }
  .lightbox::backdrop {
    background: var(--lightbox-scrim);
    -webkit-backdrop-filter: blur(var(--lightbox-blur));
    backdrop-filter: blur(var(--lightbox-blur));
  }
}
