/* Shared image and video viewer; loaded only on pages that use it. */

.media-viewer {
  width: min(1100px, 94vw);
  max-width: none;
  max-height: 94svh;
  padding: 55px 18px 18px;
  border: 1px solid #ffffff30;
  border-radius: 16px;
  background: #100d25;
  color: var(--paper);
}

.media-viewer::backdrop {
  background: #080615ed;
  backdrop-filter: blur(14px);
}

.close-dialog {
  position: absolute;
  right: 18px;
  top: 8px;
  display: flex;
  min-height: 44px;
  gap: 20px;
  align-items: center;
  background: transparent;
  font-size: 15px;
}

.close-dialog span {
  font-size: 25px;
}

.viewer-content img {
  max-height: 73svh;
  object-fit: contain;
  margin: auto;
}

.viewer-content p {
  margin: 14px 0 0;
  color: #bdb6d2;
  font-size: var(--label-size);
  text-align: center;
}

.video-stage {
  display: grid;
  place-items: center;
  min-height: 0;
}

.video-frame {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
}

.video-frame iframe {
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
}

.video-fallback a {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  text-decoration: underline;
}

/* A shared full-screen media stage on phones, including landscape orientation. */
@media (max-width: 650px), (max-height: 500px) {
  .media-viewer {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100vh;
    height: 100dvh;
    max-height: none;
    margin: 0;
    padding: calc(64px + env(safe-area-inset-top, 0px))
      max(8px, env(safe-area-inset-right, 0px))
      max(16px, env(safe-area-inset-bottom, 0px))
      max(8px, env(safe-area-inset-left, 0px));
    overflow: hidden;
    overscroll-behavior: contain;
    border: 0;
    border-radius: 0;
    background: #0b0b12;
  }

  .media-viewer .close-dialog {
    top: max(8px, env(safe-area-inset-top, 0px));
    right: max(12px, env(safe-area-inset-right, 0px));
    gap: 12px;
    padding: 0 14px;
    border: 1px solid #ffffff20;
    border-radius: 30px;
    background: #ffffff08;
    font-size: 16px;
  }

  .media-viewer .viewer-content {
    display: grid;
    grid-template-rows: minmax(0, 1fr) auto;
    gap: 16px;
    height: 100%;
    min-height: 0;
  }

  .media-viewer img {
    width: 100%;
    height: 100%;
    min-height: 0;
    max-height: none;
    margin: 0;
    object-fit: contain;
  }

  .media-viewer .viewer-content > p {
    margin: 0;
    padding-inline: 8px;
    color: var(--muted);
    font-size: 14px;
    line-height: 1.5;
    text-wrap: balance;
  }

  .media-viewer .video-frame {
    max-width: calc(
      (
          100vh - 140px - env(safe-area-inset-top, 0px) -
            env(safe-area-inset-bottom, 0px)
        ) *
        16 / 9
    );
  }

  @supports (width: 1cqh) {
    .video-stage {
      container-type: size;
    }

    .media-viewer .video-frame {
      max-width: calc(100cqh * 16 / 9);
    }
  }
}

@media print {
  .media-viewer {
    display: none;
  }
}
