:root {
  --bg-cream: rgb(250, 249, 246);
  --ink: #1a1a1a;
  --tap-min: 44px;
  /* 下部バー（進捗バー・ページ番号）の上に出しておく余白。画像はこの分だけ上に詰める */
  --bottom-ui-reserve: max(92px, calc(env(safe-area-inset-bottom) + 82px));
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg-cream);
  overscroll-behavior: none;
  touch-action: pan-y;
}

body {
  font-family: -apple-system, "Hiragino Sans", "Noto Sans JP", sans-serif;
  color: var(--ink);
}

.viewer {
  position: fixed;
  inset: 0;
  background: var(--bg-cream);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

/* 上部の TAXMEN ロゴ */
.viewer__logo {
  position: absolute;
  top: max(14px, env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  height: 22px;
  width: auto;
  z-index: 6;
  pointer-events: none;
}

/* 次の話へ（右上）。次の話があるときだけ js/viewer.js が表示する */
.viewer__next-episode {
  position: absolute;
  top: max(10px, env(safe-area-inset-top));
  right: 10px;
  z-index: 6;
  display: flex;
  align-items: center;
  gap: 2px;
  border: none;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  font-size: 14px;
  font-weight: 700;
  line-height: 1;
  padding: 0 14px;
  min-height: var(--tap-min);
  cursor: pointer;
}

.viewer__next-episode-arrow {
  font-size: 20px;
}

/* 進捗（Stories 風・コマ数ぶんのセグメント）。下部に配置（ページ番号の少し上） */
.viewer__progress {
  position: absolute;
  bottom: max(72px, calc(env(safe-area-inset-bottom) + 62px));
  left: 12px;
  right: 12px;
  display: flex;
  gap: 4px;
  z-index: 5;
  pointer-events: none;
}

.viewer__progress-seg {
  flex: 1 1 0;
  height: 4px;
  border-radius: 2px;
  background: rgba(0, 0, 0, 0.15);
  overflow: hidden;
}

.viewer__progress-seg.is-done {
  background: rgba(0, 0, 0, 0.55);
}

/* 画像。下部バー（進捗バー・ページ番号）に絵が被らないよう、その分だけ下に余白を取って上に詰める */
.viewer__stage {
  position: relative;
  width: 100%;
  height: 100%;
  padding-bottom: var(--bottom-ui-reserve);
  display: flex;
  align-items: center;
  justify-content: center;
}

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

/* 左右タップ／フリック領域（見た目は透明。実際の判定は js/viewer.js の #viewer で一本化） */
.viewer__zone {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 30%;
  border: none;
  background: transparent;
  padding: 0;
  margin: 0;
  cursor: pointer;
  z-index: 3;
}

.viewer__zone--prev { left: 0; }
.viewer__zone--next { left: 30%; width: 70%; }

/* ページ番号（大きい文字） */
.viewer__counter {
  position: absolute;
  bottom: max(20px, env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  z-index: 5;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  font-size: 20px;
  font-weight: 700;
  padding: 8px 20px;
  border-radius: 999px;
  min-height: var(--tap-min);
  display: flex;
  align-items: center;
  pointer-events: none;
}

.viewer__loading,
.viewer__error {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  text-align: center;
  padding: 0 24px;
  z-index: 10;
  background: var(--bg-cream);
}

.viewer__error { color: #a33; }

/* [hidden] 属性は必ず display:none にする（上の display:flex より後に来ないと上書きされない） */
[hidden] { display: none !important; }
