/* MangaViewer — モーダル型ビューアーのスタイル
   すべて .mv- 接頭辞。親ページ（ニュースサイト）のCSSと衝突しないようにする。 */

.mv-root {
  --mv-ui: rgba(255, 255, 255, 0.92);
  --mv-ui-bg: rgba(12, 12, 16, 0.72);

  position: fixed;
  inset: 0;
  z-index: 2147483000;
  display: none;
  background: #0d0d10;
  color: var(--mv-ui);
  font-family: system-ui, -apple-system, 'Hiragino Sans', 'Noto Sans JP', sans-serif;
  overscroll-behavior: contain;
  /* iOS のセーフエリア */
  padding: 0;
}

.mv-root.is-open {
  display: block;
  animation: mv-fade 0.28s ease both;
  /* モーダル表示中はブラウザのダブルタップ/ピンチズームを全域で無効にする。
     ステージだけに限定すると、上下バーの上で発動したページズームを
     ステージ上のピンチで戻せず、再読み込みするしかなくなる（iOS Safari）。
     タップやクリック、自前のピンチ（Pointer Events）はこの設定の影響を受けない */
  touch-action: none;
}

@keyframes mv-fade {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

/* --- WebGL ステージ ------------------------------------------------------ */

.mv-stage {
  position: absolute;
  inset: 0;
  touch-action: none; /* スワイプ操作を横取りするのはモーダル内部だけ */
  cursor: pointer;
}

.mv-stage canvas {
  display: block;
  width: 100%;
  height: 100%;
}

/* --- 読み込み中 ---------------------------------------------------------- */

.mv-loading {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 16px;
  background: #0d0d10;
  z-index: 3;
  font-size: 14px;
}

.mv-loading[hidden] {
  display: none;
}

.mv-loading.is-error .mv-spinner {
  display: none;
}

.mv-spinner {
  width: 38px;
  height: 38px;
  border: 3px solid rgba(255, 255, 255, 0.2);
  border-top-color: #fff;
  border-radius: 50%;
  animation: mv-spin 0.9s linear infinite;
}

@keyframes mv-spin {
  to {
    transform: rotate(360deg);
  }
}

.mv-loading-text {
  margin: 0;
  opacity: 0.85;
}

/* --- 上部バー ------------------------------------------------------------ */

.mv-top {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: max(12px, env(safe-area-inset-top)) 14px 28px;
  background: linear-gradient(to bottom, rgba(0, 0, 0, 0.6), transparent);
  pointer-events: none;
}

.mv-title {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.02em;
  opacity: 0.9;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mv-mode {
  margin-left: auto;
  pointer-events: auto;
  border: 0;
  border-radius: 999px;
  padding: 9px 14px;
  font-size: 12px;
  font-weight: 600;
  color: var(--mv-ui);
  background: var(--mv-ui-bg);
  backdrop-filter: blur(6px);
  cursor: pointer;
  white-space: nowrap;
}

.mv-mode:hover {
  background: rgba(40, 40, 48, 0.9);
}

.mv-close {
  pointer-events: auto;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 0;
  background: var(--mv-ui-bg);
  color: var(--mv-ui);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  backdrop-filter: blur(6px);
}

.mv-close:hover {
  background: rgba(40, 40, 48, 0.9);
}

/* --- 下部バー ------------------------------------------------------------ */

.mv-bottom {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 2;
  padding: 34px 14px max(12px, env(safe-area-inset-bottom));
  background: linear-gradient(to top, rgba(0, 0, 0, 0.7), transparent);
  pointer-events: none;
}

.mv-caption {
  margin: 0 0 10px;
  font-size: 14px;
  font-weight: 600;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.6);
  min-height: 1.2em;
}

.mv-controls {
  display: flex;
  align-items: center;
  gap: 10px;
}

.mv-controls button {
  pointer-events: auto;
  border: 0;
  border-radius: 999px;
  padding: 11px 20px;
  font-size: 14px;
  font-weight: 600;
  color: var(--mv-ui);
  background: var(--mv-ui-bg);
  backdrop-filter: blur(6px);
  cursor: pointer;
  transition: transform 0.12s ease, background 0.12s ease;
}

.mv-controls button:hover:not(:disabled) {
  background: rgba(40, 40, 48, 0.92);
}

.mv-controls button:active:not(:disabled) {
  transform: scale(0.96);
}

.mv-controls button:disabled {
  opacity: 0.35;
  cursor: default;
}

.mv-next {
  margin-left: auto;
}

.mv-counter {
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  opacity: 0.8;
}

.mv-progress {
  position: relative;
  margin-top: 12px;
  height: 4px;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.18);
  pointer-events: auto; /* 親の .mv-bottom は none。バーだけ受け付ける */
  cursor: pointer;
  touch-action: none; /* ドラッグでのシークをブラウザに奪われない */
}

/* 4px のバーは指では狙えないので、見た目を変えずに当たり判定だけ広げる */
.mv-progress::before {
  content: '';
  position: absolute;
  left: -8px;
  right: -8px;
  top: -16px;
  bottom: -12px;
}

.mv-progress-bar {
  height: 100%;
  width: 0;
  background: #ff4b3e;
  border-radius: 3px;
  transition: width 0.4s ease;
}

/* ドラッグ中は指に吸い付くよう、遷移アニメーションを切る */
.mv-progress.is-scrubbing .mv-progress-bar {
  transition: none;
}

/* ドラッグ中に表示する「n / N ラベル」ツールチップ */
.mv-scrub-tip {
  position: absolute;
  bottom: 18px;
  transform: translateX(-50%);
  padding: 6px 10px;
  border-radius: 8px;
  background: rgba(20, 20, 26, 0.92);
  color: var(--mv-ui);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  pointer-events: none;
}

/* --- ページ読み込み待ち --------------------------------------------------- */

.mv-busy {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 2;
  padding: 14px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.5);
  pointer-events: none;
}

.mv-busy[hidden] {
  display: none;
}

.mv-busy .mv-spinner {
  display: block;
  width: 26px;
  height: 26px;
}

/* --- 初回ヒント ---------------------------------------------------------- */

.mv-hint {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 2;
  margin: 0;
  padding: 10px 18px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.6);
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.4s ease;
}

.mv-hint.is-visible {
  opacity: 1;
}

@media (prefers-reduced-motion: reduce) {
  .mv-root.is-open {
    animation: none;
  }
  .mv-progress-bar {
    transition: none;
  }
}
