.tpf-modal,
[data-tpf-open] {
  -webkit-tap-highlight-color: transparent;
}

/*
 * 閉じているポップアップを描画・ヒットテスト対象から完全に外します。
 * 開発者ツールの要素選択で、非表示のiframeが選ばれることも防ぎます。
 */
.tpf-modal[hidden] {
  display: none !important;
}

[data-tpf-open] {
  cursor: pointer;
}

img[data-tpf-open] {
  display: block;
}

[data-tpf-open]:focus-visible {
  outline: 3px solid #1769aa;
  outline-offset: 4px;
}

.tpf-modal {
  position: fixed;
  inset: 0;
  z-index: 2147483000;
  display: grid;
  place-items: center;
  box-sizing: border-box;
  padding: clamp(16px, 4vw, 48px);
  visibility: hidden;
  pointer-events: none;
  transition: visibility 0s linear .28s;
}

.tpf-modal[aria-hidden="false"] {
  visibility: visible;
  pointer-events: auto;
  transition-delay: 0s;
}

.tpf-modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(5, 12, 24, .72);
  opacity: 0;
  -webkit-backdrop-filter: blur(0);
  backdrop-filter: blur(0);
  transition:
    opacity .22s ease,
    -webkit-backdrop-filter .28s ease,
    backdrop-filter .28s ease;
}

.tpf-modal[aria-hidden="false"] .tpf-modal__backdrop {
  opacity: 1;
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  transition-duration: .38s;
}

.tpf-modal__dialog {
  position: relative;
  z-index: 1;
  box-sizing: border-box;
  width: min(100%, var(--tpf-modal-width, 720px));
  height: var(--tpf-modal-height, auto);
  max-height: 90vh;
  max-height: 90dvh;
  overflow: hidden;
  color: #222;
  background: #f6f6f6;
  border-radius: 14px;
  box-shadow: 0 12px 36px rgba(0, 0, 0, .16);
  opacity: 0;
  filter: blur(5px);
  transform: translate3d(0, 30px, 0) scale(.94);
  transform-origin: 50% 55%;
  transition:
    opacity .18s ease,
    transform .22s ease,
    filter .18s ease,
    box-shadow .22s ease;
  will-change: transform, opacity;
}

.tpf-modal__inner {
  box-sizing: border-box;
  height: 100%;
  max-height: 90vh;
  max-height: 90dvh;
  padding: clamp(24px, 5vw, 48px);
  overflow: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: #a8b0b8 transparent;
}

.tpf-modal__inner::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

.tpf-modal__inner::-webkit-scrollbar-track {
  background: transparent;
  border-radius: 999px;
}

.tpf-modal__inner::-webkit-scrollbar-thumb {
  background: #a8b0b8;
  background-clip: padding-box;
  border: 2px solid transparent;
  border-radius: 999px;
}

.tpf-modal__inner::-webkit-scrollbar-thumb:hover {
  background: #7c8791;
  background-clip: padding-box;
}

.tpf-modal__iframe-wrap {
  position: relative;
  width: 100%;
  min-height: 160px;
}

.tpf-modal__iframe-wrap iframe {
  display: block;
  width: 100%;
  overflow: hidden;
  border: 0;
  transition: none;
}

.tpf-modal__iframe--waiting {
  pointer-events: none;
  opacity: 0;
}

.tpf-modal__iframe-loader {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  min-height: 160px;
  color: #555;
  font-size: 15px;
  font-weight: 500;
}

.tpf-modal__iframe-loader[hidden] {
  display: none !important;
}

.tpf-modal__spinner {
  width: 24px;
  height: 24px;
  border: 3px solid #d7dce1;
  border-top-color: #1769aa;
  border-radius: 50%;
  animation: tpf-spinner .8s linear infinite;
}

@keyframes tpf-spinner {
  to {
    transform: rotate(360deg);
  }
}

.tpf-modal[aria-hidden="false"] .tpf-modal__dialog {
  opacity: 1;
  filter: blur(0);
  transform: translate3d(0, 0, 0) scale(1);
  box-shadow: 0 30px 100px rgba(0, 0, 0, .42);
  transition:
    opacity .3s ease-out,
    transform .48s cubic-bezier(.16, 1, .3, 1),
    filter .3s ease-out,
    box-shadow .5s ease-out;
}

/* iframeの初回表示では変形・フェードを行わない。
 * 閉じるときだけ背景と同じ時間・イージングでフェードアウトする。
 */
.tpf-modal.tpf-modal--iframe .tpf-modal__dialog {
  filter: none;
  transform: none;
  opacity: 0;
  will-change: auto;
  transition: opacity .22s ease;
}

.tpf-modal.tpf-modal--iframe[aria-hidden="false"] .tpf-modal__dialog {
  opacity: 1;
  transition: none;
}

@media (prefers-reduced-motion: reduce) {
  .tpf-modal.tpf-modal--iframe .tpf-modal__dialog {
    transition: none !important;
  }
}

.tpf-modal__close {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 2;
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  margin: 0;
  padding: 0;
  color: #222;
  font: 28px/1 Arial, sans-serif;
  background: #fff;
  border: 0;
  border-radius: 999px;
  cursor: pointer;
  opacity: 0;
  transform: rotate(-12deg) scale(.82);
  transition:
    background .18s ease,
    transform .2s ease,
    opacity .18s ease;
}

.tpf-modal[aria-hidden="false"] .tpf-modal__close {
  opacity: 1;
  transform: rotate(0) scale(1);
  transition:
    background .18s ease,
    transform .42s cubic-bezier(.16, 1, .3, 1) .12s,
    opacity .24s ease .1s;
}

.tpf-modal__close:hover {
  background: #e2e6ea;
  transform: rotate(4deg) scale(1.08);
}

.tpf-modal__close:focus-visible,
.tpf-modal :focus-visible {
  outline: 3px solid #1769aa;
  outline-offset: 3px;
}

/* プログラムによる初期フォーカスではダイアログ枠を表示しません。 */
.tpf-modal .tpf-modal__dialog:focus,
.tpf-modal .tpf-modal__dialog:focus-visible {
  outline: none;
}

html.tpf-scroll-lock {
  overflow: hidden;
}

@media (prefers-reduced-motion: reduce) {
  .tpf-modal,
  .tpf-modal__backdrop,
  .tpf-modal__dialog,
  .tpf-modal__close {
    transition: none !important;
  }

  .tpf-modal__dialog {
    filter: none;
    transform: none;
  }

  .tpf-modal__spinner {
    animation-duration: 1.8s;
  }
}

@media (max-width: 640px) {
  .tpf-modal {
    padding: 12px;
  }

  .tpf-modal__dialog {
    width: 100%;
    max-height: calc(100dvh - 24px);
  }

  .tpf-modal__inner {
    max-height: calc(100dvh - 24px);
    padding: 24px;
  }
}
