/* ===== modal.css — モーダル共通・画像・各種モーダル ===== */

.modal-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 100vh;
  height: 100dvh; /* キーボード表示時に自動縮小（dvh 対応ブラウザ） */
  background: transparent;
  z-index: 50;
  align-items: center;
  justify-content: center;
}

.modal-overlay.is-open {
  display: flex;
}

.modal-box {
  background: var(--paper);
  border: 2px solid #000;
  width: min(calc(100% - 48px), 400px);
  max-height: 80vh;
  overflow-y: auto;
  padding: 20px;
  position: relative;
}

.modal-loader {
  position: absolute;
  inset: 0;
  background: var(--paper);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
}

.modal-loader.hidden {
  display: none;
}

/* modal-body内ローダー表示中は後続コンテンツを非表示にしてサイズを揃える */
/* About・Writerモーダル限定（ランダムモーダルに影響しないよう明示スコープ） */
#aboutModal .random-modal-loader:not(.hidden) ~ *,
#writerModal .random-modal-loader:not(.hidden) ~ * {
  display: none;
}

/* .hidden クラスでローダー自体を非表示 */
.random-modal-loader.hidden {
  display: none;
}

/* About/Writer: ローダー表示中はヘッダー下マージンをboxの下パディング(20px)と揃える
   → ヘッダー下線〜loader上端 = loader下端〜modal下辺 になり pixel-loader が縦中央に */
#aboutModal .modal-box:has(.random-modal-loader:not(.hidden)) .modal-header,
#writerModal .modal-box:has(.random-modal-loader:not(.hidden)) .modal-header {
  margin-bottom: 20px;
}

.modal-header {
  position: relative;
  z-index: 11;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
  border-bottom: 1px solid #000;
  padding-bottom: 10px;
}

.modal-title {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.modal-body {
  font-size: 0.9rem;
  color: var(--muted);
  line-height: 1.8;
}

.modal-confirm-text {
  margin: 0;
  color: #000;
}

.modal-actions {
  display: flex;
  justify-content: center;
  gap: 14px;
  margin-top: 18px;
}

.modal-btn {
  min-width: 58px;
  height: 28px;
  padding: 0 12px;
  border: 1px solid #888;
  background: #ddd;
  color: #000;
  font-family: inherit;
  font-size: 0.82rem;
  cursor: pointer;
  letter-spacing: 0.04em;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.modal-btn:hover {
  background: #bbb;
  border-color: #000;
}

.modal-btn:active {
  transform: translate(1px, 1px);
}

.modal-btn-primary {
  background: #ddd;
  color: #000;
  border-color: #888;
}

.modal-btn-primary:hover {
  background: #bbb;
  border-color: #000;
}

/* 読者プロフィールモーダル */

.reader-profile-field {
  margin-bottom: 14px;
}

.reader-profile-label {
  display: block;
  font-size: 0.72rem;
  color: var(--muted);
  margin-bottom: 4px;
}

.reader-profile-input {
  width: 100%;
  box-sizing: border-box;
  border: 1px solid #888;
  background: #f5f5f5;
  padding: 6px 8px;
  font-family: inherit;
  font-size: 0.88rem;
  color: #000;
  outline: none;
}

.reader-profile-input:focus {
  border-color: #000;
  background: #fff;
}

.reader-profile-save-note {
  margin: 10px 0 0;
  font-size: 0.74rem;
  color: var(--muted);
}

#readerProfileSave:disabled {
  background: #cfcfcf;
  color: #666;
  border-color: #aaa;
  cursor: not-allowed;
}

/* すれ違いモーダルの読者情報 */

.reader-crossed-profile {
  margin-top: 12px;
  padding: 8px 10px;
  border-left: 2px solid #ccc;
}

.reader-crossed-name {
  font-size: 0.82rem;
  font-weight: bold;
  margin: 0 0 4px;
}

.reader-crossed-msg {
  font-size: 0.78rem;
  color: var(--muted);
  margin: 0;
}

#readerCrossedModal .modal-box {
  position: relative;
  overflow: hidden;
}

.reader-crossed-steps {
  position: absolute;
  right: 2px;
  bottom: -40px;
  width: 88px;
  height: 120px;
  pointer-events: none;
  opacity: 1;
}

.reader-crossed-steps svg {
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
  transform: rotate(30deg);
  transform-origin: center;
}

.reader-crossed-step {
  fill: #1f1f1f;
  opacity: 0;
  animation: readerCrossedFootsteps 2.7s steps(1, end) infinite;
}

.reader-crossed-step.step-1 { animation-delay: 0s; }
.reader-crossed-step.step-2 { animation-delay: 0.28s; }
.reader-crossed-step.step-3 { animation-delay: 0.56s; }
.reader-crossed-step.step-4 { animation-delay: 0.84s; }
.reader-crossed-step.step-5 { animation-delay: 1.12s; }
.reader-crossed-step.step-6 { animation-delay: 1.4s; }

@keyframes readerCrossedFootsteps {
  0% {
    opacity: 0;
    transform: scale(0.92);
  }
  8% {
    opacity: 1;
  }
  20% {
    opacity: 1;
  }
  24% {
    opacity: 0;
    transform: scale(1);
  }
  100% {
    opacity: 0;
    transform: scale(1);
  }
}

/* 画像モーダル */
#imageModal {
  z-index: 60;
  background: transparent;
  pointer-events: none;
}

#imageModal.is-open {
  pointer-events: auto;
}

#imageModal .modal-box {
  width: min(calc(100% - 28px), 620px);
  max-height: 95vh;
  overflow: visible;
  padding: 12px;
  background: var(--paper);
  border: 2px solid #000;
  box-shadow: none;
}

#imageModal .modal-body {
  padding: 0;
  position: relative;
}

#imageModal .modal-body img {
  display: block;
  width: 100%;
  max-width: 100%;
  height: auto;
  border: 0;
}

#imageModalClose,
#randomPreviewClose {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 10;
}

#imageModalClose {
  top: 0px;
  right: 0px;
}

#imageModalClose:active {
  transform: translate(1px, 1px);
}

.image-modal-loader {
  position: absolute;
  inset: -4px;
  z-index: 2;
}

.image-modal-loader.hidden {
  display: none;
}

@keyframes imgReveal {
  0%   { transform: scaleY(1);    }
  28%  { transform: scaleY(0.7);  } /* ~30% で到着 */
  37%  { transform: scaleY(0.7);  } /* 一瞬停止 */
  83%  { transform: scaleY(0.15); } /* スムーズに ~85% へ */
  90%  { transform: scaleY(0.15); } /* カクッと停止 */
  100% { transform: scaleY(0);    } /* 完了 */
}

.img-reveal-overlay {
  position: absolute;
  inset: 0;
  background: var(--paper);
  transform-origin: bottom;
  animation: imgReveal 650ms linear forwards;
}

/* ランダム投稿プレビュー */

#randomPreview .preview-bubble {
  padding: 9px 0;
  margin-bottom: 12px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}

#randomPreview .bubble::after {
  display: none;
}

#randomPreview .entry-media {
  cursor: default;
  display: inline-block;
  width: auto;
  max-width: 100%;
  margin: 10px 0;
}

#randomPreview .entry-media img {
  display: block;
  width: auto;
  max-width: 100%;
  max-height: min(46vh, 420px);
  height: auto;
  object-fit: contain;
}
.random-go-btn {
  display: block;
  width: 100%;
  background: #ddd;
  color: #000;
  border: 1px solid #888;
  font-size: 0.82rem;
  letter-spacing: 0.04em;
  font-family: inherit;
  cursor: pointer;
}

.random-go-btn:hover {
  background: #bbb;
  border-color: #000;
}

.random-go-btn:active {
  transform: translate(1px, 1px);
}

.modal-login-btn {
  width: 18px;
  height: 18px;
  padding: 0;
  border: 0;
  background: transparent;
  color: #b0b0b0;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.modal-login-btn:hover {
  background: transparent;
  color: #8f8f8f;
}

.modal-login-btn:active {
  transform: translate(1px, 1px);
}

.modal-login-btn svg {
  width: 14px;
  height: 14px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.9;
}

.modal-login-btn[hidden] {
  display: none !important;
}

.image-modal-author {
  display: flex;
  gap: 4px;
  font-size: 0.78rem;
  color: var(--muted);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  flex-shrink: 0;
  padding-top: 2px;
  box-sizing: border-box;
}

.image-modal-author svg {
  width: 13px;
  height: 13px;
  flex-shrink: 0;
}
