/* A steady camera-format frame, with room below for navigation and actions.
   svh keeps mobile browser chrome from changing its size between photographs. */
#preview-dialog:has(.photo-viewer){
  --viewer-padding:16px;
  --viewer-border:2px;
  --viewer-height:min(1000px,calc(100svh - 24px));
  --viewer-photo-height:calc(var(--viewer-height) - var(--viewer-padding) - var(--viewer-padding) - var(--viewer-border) - 52px - 36px - 44px - 64px - 24px);
  --viewer-photo-ratio:3/4;
  --viewer-photo-width:calc(var(--viewer-photo-height)*3/4);
  width:min(580px,calc(100vw - 24px));
  height:var(--viewer-height);
  max-width:calc(100vw - 24px);
  max-height:var(--viewer-height);
  padding:var(--viewer-padding);
  overflow:hidden;
  overscroll-behavior:contain;
}
html:has(#preview-dialog[open] .photo-viewer){overflow:hidden}
#preview-dialog[open]:has(.photo-viewer){display:grid;grid-template-rows:52px minmax(0,1fr)}
#preview-dialog:has(.photo-viewer) .dialog-heading{height:44px;min-height:44px;margin-bottom:8px;align-items:center}
#preview-dialog:has(.photo-viewer) .dialog-heading h2{max-height:2.2em;overflow:auto}
#preview-dialog:has(.photo-viewer) #dialog-content{min-height:0;overflow:hidden}
.photo-viewer{height:100%;min-height:0;display:grid;grid-template-rows:minmax(0,1fr) 36px 44px 64px;gap:8px}
.lightbox-stage{position:relative;width:min(100%,var(--viewer-photo-width));height:auto;aspect-ratio:var(--viewer-photo-ratio);min-width:0;min-height:0;align-self:center;justify-self:center;overflow:hidden;background:transparent;border:0;box-shadow:none}
.lightbox-stage>.lightbox-photo{position:absolute;inset:0;display:block;width:100%;height:100%;max-width:none;max-height:none;object-fit:contain;object-position:center;background:transparent;border:0;box-shadow:none}
#dialog-content .photo-viewer>.lightbox-caption{margin:0;overflow:auto;overscroll-behavior:contain;font-size:12px;line-height:18px}
.photo-viewer>.lightbox-controls{margin:0;min-width:0}
.photo-viewer-footer{min-width:0;min-height:0;overflow:auto;overscroll-behavior:contain}
.photo-viewer-footer .photo-album-actions{margin-top:0;padding-top:8px;gap:8px}
.photo-viewer-footer .photo-album-actions:empty{display:none}
#dialog-content .photo-viewer-footer>.dialog-hint{margin:8px 0 0!important;font-size:11px;line-height:1.5}
@media(max-width:979px){
  #preview-dialog:has(.photo-viewer){--viewer-padding:12px;--viewer-border:0px;--viewer-height:100svh;inset:0;margin:0;width:100vw;max-width:100vw;height:100svh;max-height:100svh;padding:var(--viewer-padding) 8px;border:0}
  #preview-dialog:has(.photo-viewer) .dialog-heading{padding-inline:8px}
  #preview-dialog:has(.photo-viewer) .dialog-heading h2{font-size:26px}
  .photo-viewer>.lightbox-caption,.photo-viewer>.lightbox-controls,.photo-viewer-footer{margin-inline:8px}
}
@media(min-width:980px){
  #preview-dialog:has(.photo-viewer){--viewer-photo-ratio:4/3;--viewer-photo-width:calc(var(--viewer-photo-height)*4/3);width:min(1100px,calc(100vw - 40px))}
}
@media(min-width:980px) and (min-height:521px){
  #preview-dialog:has(.photo-viewer){width:min(1100px,calc(100vw - 40px),calc(var(--viewer-photo-width) + 34px))}
}
/* Keep the full photo useful when the phone is held horizontally. */
@media(max-height:520px) and (min-width:560px){
  #preview-dialog:has(.photo-viewer){--viewer-photo-ratio:4/3;--viewer-photo-height:calc(var(--viewer-height) - var(--viewer-padding) - var(--viewer-padding) - var(--viewer-border) - 52px);--viewer-photo-width:calc(var(--viewer-photo-height)*4/3)}
  .photo-viewer{grid-template-columns:minmax(0,1fr) minmax(210px,30%);grid-template-rows:minmax(0,1fr) 44px 108px;column-gap:16px}
  .photo-viewer>.lightbox-stage{grid-column:1;grid-row:1/-1}
  .photo-viewer>.lightbox-caption,.photo-viewer>.lightbox-controls,.photo-viewer>.photo-viewer-footer{grid-column:2;margin-inline:0}
}

/* Only the seeded demo portraits and squares fill the frame. Real uploads keep contain. */
.lightbox-stage>.lightbox-photo[data-demo-fill="true"]{object-fit:cover;object-position:50% 35%}

/* Touch navigation and adjacent phone controls; desktop controls flank the image. */
.lightbox-stage{touch-action:pan-y pinch-zoom}
.lightbox-photo{-webkit-user-drag:none;user-select:none}
.photo-viewer>.lightbox-controls{display:flex;align-items:center;justify-content:center;gap:20px}
.lightbox-arrow-pair{display:flex;align-items:center;gap:8px}
.photo-viewer [data-photo-step]{width:44px;height:44px;flex:none}
.photo-viewer [data-photo-count]{min-width:58px;text-align:center}
@media(min-width:980px){
  #preview-dialog:has(.photo-viewer){--viewer-photo-height:calc(var(--viewer-height) - var(--viewer-padding) - var(--viewer-padding) - var(--viewer-border) - 52px - 36px - 44px - 64px - 24px);width:min(1100px,calc(100vw - 40px),calc(var(--viewer-photo-width) + 146px))}
  .photo-viewer{grid-template-columns:44px minmax(0,1fr) 44px;grid-template-rows:minmax(0,1fr) 36px 44px 64px;column-gap:12px}
  .photo-viewer>.lightbox-stage{grid-row:1;grid-column:2}
  .photo-viewer>.lightbox-caption{grid-row:2;grid-column:1/-1}
  .photo-viewer>.lightbox-controls,.photo-viewer .lightbox-arrow-pair{display:contents}
  .photo-viewer [data-photo-count]{grid-row:3;grid-column:1/-1;align-self:center}
  .photo-viewer [data-photo-step]{grid-row:1;align-self:center;justify-self:center}
  .photo-viewer [data-photo-step="-1"]{grid-column:1}
  .photo-viewer [data-photo-step="1"]{grid-column:3}
  .photo-viewer>.photo-viewer-footer{grid-row:4;grid-column:1/-1}
}
