theme-image-preview {
  position: absolute;
  inset-block-start: 0;
  inset-inline-start: 0;
  width: 1px;
  height: 1px;
}

/*
  Must beat [data-mount-modal] > summary + :not(...) (fit-content / bottom-sheet),
  otherwise landscape images flatten the PC modal and mobile never goes fullscreen.
*/
[data-theme-modal][data-popup-container] > details > summary + .image-preview__main,
[data-mount-modal] > summary + .image-preview__main,
.image-preview__main {
  --modal-animation-name: animation-fade-in;

  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  width: min(1200px, calc(100vw - 96px));
  height: calc(100vh - 170px);
  max-height: calc(100vh - 170px);
  margin: auto;
  padding: 55px 0;
  overflow: visible;
  background: #fff;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  transform: none;
}

.image-preview__stage {
  display: flex;
  flex: 1 1 auto;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 0;
  height: 100%;
  overflow: hidden;
  touch-action: none;
}

.image-preview__image {
  display: block;
  width: auto;
  max-width: 100%;
  height: auto;
  max-height: 100%;
  margin: auto;
  object-fit: contain;
  user-select: none;
  -webkit-user-drag: none;
}

.image-preview__video {
  display: block;
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  background: #000;
}

.image-preview__main > .modal__close-control.image-preview__close-control {
  position: absolute;
  inset-block-start: -36px;
  inset-inline-end: 12px;
  z-index: 4;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  padding: 0;
  color: #fff;
  cursor: pointer;
  background: none;
  border: 0;
  border-radius: 0;
}

.image-preview__close-icon {
  display: block;
  width: 16px;
  height: 16px;
}

.image-preview__side-arrow {
  position: absolute;
  inset-block-start: 50%;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 55px;
  height: 55px;
  padding: 0;
  color: #707070;
  cursor: pointer;
  background: none;
  border: 0;
  border-radius: 50%;
  transform: translateY(-50%);
  transition: opacity 0.2s;
}

.image-preview__side-arrow:hover {
  opacity: 0.7;
}

.image-preview__side-arrow .image-preview__icon {
  display: block;
  width: 55px;
  height: 55px;
}

.image-preview__side-arrow--previous {
  inset-inline-start: 16px;
}

.image-preview__side-arrow--next {
  inset-inline-end: 16px;
}

@media (max-width: 959.98px) {
  [data-theme-modal][data-popup-container] > details > summary + .image-preview__main,
  [data-mount-modal] > summary + .image-preview__main,
  .image-preview__main {
    inset: 0;
    width: 100vw;
    max-width: 100vw;
    height: 100vh;
    max-height: 100vh;
    margin: 0;
    padding: 52px 20px 76px;
    transform: none;
  }

  .image-preview__main > .modal__close-control.image-preview__close-control {
    inset-block-start: 24px;
    inset-inline-end: 16px;
    color: #000;
  }

  .image-preview__close-icon {
    filter: invert(1);
  }

  .image-preview__side-arrow {
    width: 32px;
    height: 32px;
  }

  .image-preview__side-arrow--previous {
    inset-inline-start: 8px;
  }

  .image-preview__side-arrow--next {
    inset-inline-end: 8px;
  }

  .image-preview__side-arrow .image-preview__icon {
    width: 32px;
    height: 32px;
  }
}

@media (min-width: 960px) {
  .image-preview__main > .modal__close-control.image-preview__close-control {
    inset-block-start: -36px;
    inset-inline-end: 12px;
    width: 28px;
    height: 28px;
  }
}
