/* Caption-safe presentation for the existing Canvas/Magnific image viewer.
 * The viewer still owns navigation, focus, dismissal and original image assets.
 * Reserve room for documentary captions; unusually long captions scroll within
 * that reserved space instead of extending below the browser viewport.
 */
.mfp-image-holder img.mfp-img {
  /* Magnific vertically centres the image without measuring the caption.
   * Reserve twice the caption's overhang, plus a small viewport margin. */
  max-height: calc(100vh - 256px) !important;
  max-height: calc(100dvh - 256px) !important;
}

.mfp-image-holder .mfp-bottom-bar {
  position: absolute;
  top: 100%;
  margin-top: -32px;
  max-height: 144px;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
}

.mfp-image-holder .mfp-title {
  overflow-wrap: anywhere;
}

@media (max-height: 480px) {
  .mfp-image-holder img.mfp-img {
    max-height: calc(100vh - 176px) !important;
    max-height: calc(100dvh - 176px) !important;
  }

  .mfp-image-holder .mfp-bottom-bar {
    max-height: 96px;
  }
}
