/* =========================================================
   Library Chronicles page slideshow
   Preserve portrait & landscape photo proportions
   ========================================================= */

/* Common slideshow image containers used by the Chronicle reader */
#chronicleGalleryModal .chronicle-gallery-stage,
#chronicleGalleryModal .gallery-stage,
#chronicleGalleryModal .modal-gallery-stage,
.chronicle-gallery-lightbox .chronicle-gallery-stage,
.chronicle-gallery-lightbox .gallery-stage{
  min-width:0!important;
  min-height:0!important;
  overflow:hidden!important;
  background:#070c17!important;
}

/* Give the image room but never force cropping */
#chronicleGalleryModal .chronicle-gallery-image-wrap,
#chronicleGalleryModal .gallery-image-wrap,
#chronicleGalleryModal .modal-gallery-image-wrap,
.chronicle-gallery-lightbox .chronicle-gallery-image-wrap,
.chronicle-gallery-lightbox .gallery-image-wrap{
  width:100%!important;
  height:100%!important;
  min-width:0!important;
  min-height:0!important;
  display:flex!important;
  align-items:center!important;
  justify-content:center!important;
  overflow:auto!important;
  box-sizing:border-box!important;
  padding:22px 76px!important;
}

/* Support the different IDs/classes used in the page's existing gallery modal */
#chronicleGalleryModal img,
#chronicleGalleryImage,
#galleryModalImage,
.chronicle-gallery-lightbox img{
  display:block!important;
  width:auto!important;
  height:auto!important;
  max-width:100%!important;
  max-height:100%!important;
  object-fit:contain!important;
  object-position:center center!important;
  margin:auto!important;
  transform-origin:center center!important;
}

/* Portrait images: prioritize available height */
#chronicleGalleryModal img.is-portrait,
#chronicleGalleryImage.is-portrait,
#galleryModalImage.is-portrait,
.chronicle-gallery-lightbox img.is-portrait{
  width:auto!important;
  height:100%!important;
  max-width:100%!important;
  max-height:100%!important;
}

/* Landscape images: prioritize available width */
#chronicleGalleryModal img.is-landscape,
#chronicleGalleryImage.is-landscape,
#galleryModalImage.is-landscape,
.chronicle-gallery-lightbox img.is-landscape{
  width:100%!important;
  height:auto!important;
  max-width:100%!important;
  max-height:100%!important;
}

/* Square / near-square images */
#chronicleGalleryModal img.is-square,
#chronicleGalleryImage.is-square,
#galleryModalImage.is-square,
.chronicle-gallery-lightbox img.is-square{
  width:auto!important;
  height:auto!important;
  max-width:100%!important;
  max-height:100%!important;
}

/* Also keep thumbnails proportional rather than distorted */
#chronicleReaderGallery img,
.chronicle-reader-gallery img,
.chronicle-gallery-grid img{
  object-fit:cover!important;
  object-position:center!important;
}

/* On smaller screens, let both orientations fit naturally */
@media(max-width:650px){
  #chronicleGalleryModal .chronicle-gallery-image-wrap,
  #chronicleGalleryModal .gallery-image-wrap,
  #chronicleGalleryModal .modal-gallery-image-wrap,
  .chronicle-gallery-lightbox .chronicle-gallery-image-wrap,
  .chronicle-gallery-lightbox .gallery-image-wrap{
    padding:14px 48px!important;
  }

  #chronicleGalleryModal img.is-portrait,
  #chronicleGalleryModal img.is-landscape,
  #chronicleGalleryModal img.is-square,
  #chronicleGalleryImage.is-portrait,
  #chronicleGalleryImage.is-landscape,
  #chronicleGalleryImage.is-square,
  #galleryModalImage.is-portrait,
  #galleryModalImage.is-landscape,
  #galleryModalImage.is-square,
  .chronicle-gallery-lightbox img.is-portrait,
  .chronicle-gallery-lightbox img.is-landscape,
  .chronicle-gallery-lightbox img.is-square{
    width:auto!important;
    height:auto!important;
    max-width:100%!important;
    max-height:100%!important;
  }
}
