/* ===== 色などの調整はここで ===== */
:root {
  --fb-bg: #e8e5e0; /* 背景色 */
  --fb-ui: #333; /* ボタン・文字色 */
  --fb-btn-bg: #fff; /* ボタン背景 */
  --fb-focus: #b0004e; /* キーボード操作時の枠線 */
}

html,
body {
  margin: 0;
  height: 100%;
}
body {
  background: var(--fb-bg);
  color: var(--fb-ui);
  font-family:
    system-ui,
    -apple-system,
    "Hiragino Sans",
    "Noto Sans JP",
    sans-serif;
}

/* JS が動かない環境：画像を縦に並べて表示 */
.flipbook:not(.is-ready) img {
  display: block;
  max-width: 100%;
  height: auto;
  margin: 0 auto 16px;
}
.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* ---------- レイアウト ---------- */
.fb {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}
.fb-viewport {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ---------- 本 ---------- */
.fb-book {
  position: relative;
  display: flex;
  width: calc(var(--pw) * var(--per));
  height: var(--ph);
  perspective: calc(var(--pw) * 4);
  touch-action: pan-y pinch-zoom;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.fb-slot {
  position: relative;
  width: var(--pw);
  height: var(--ph);
}

.fb-page {
  position: absolute;
  inset: 0;
  overflow: hidden;
  background: #fff;
  box-shadow: 0 3px 14px rgba(0, 0, 0, 0.18);
}
.fb-page img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  pointer-events: none;
}
.fb-page--blank {
  background: transparent;
  box-shadow: none;
}
.fb-shade {
  position: absolute;
  inset: 0;
  background: #000;
  opacity: 0;
  pointer-events: none;
}

/* 見開き中央の綴じ目の陰 */
.fb[data-mode="spread"] .fb-book::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  width: 6%;
  transform: translateX(-50%);
  background: linear-gradient(to right, transparent, rgba(0, 0, 0, 0.04) 40%, rgba(0, 0, 0, 0.04) 50%, rgba(0, 0, 0, 0.04) 60%, transparent);
  pointer-events: none;
  z-index: 5;
}
.fb-book:has(> .fb-slot > .fb-page--blank)::after {
  display: none;
}

/* めくれる紙 */
.fb-flipper {
  position: absolute;
  top: 0;
  width: var(--pw);
  height: var(--ph);
  transform-style: preserve-3d;
  z-index: 10;
  will-change: transform;
}
.fb-flipper--right {
  left: var(--pw);
  transform-origin: left center;
}
.fb-flipper--left {
  left: 0;
  transform-origin: right center;
}
.fb-flipper--full {
  left: 0;
  transform-origin: left center;
}
.fb-face {
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}
.fb-face--back {
  transform: rotateY(180deg);
}

/* ---------- 操作ボタン ---------- */
.fb-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 12px calc(12px + env(safe-area-inset-bottom));
}
.fb-btn {
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--fb-btn-bg);
  color: var(--fb-ui);
  display: grid;
  place-items: center;
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
  transition:
    transform 0.15s,
    opacity 0.15s;
}
.fb-btn svg {
  width: 22px;
  height: 22px;
}
.fb-btn:hover:not(:disabled) {
  transform: scale(1.06);
}
.fb-btn:disabled {
  opacity: 0.35;
  cursor: default;
}
.fb-btn:focus-visible {
  outline: 3px solid var(--fb-focus);
  outline-offset: 2px;
}
.fb-indicator {
  min-width: 6.5em;
  text-align: center;
  font-size: 15px;
  font-variant-numeric: tabular-nums;
}
.fb-zoom-btn {
  margin-left: 12px;
}

@media (max-width: 400px) {
  .fb-controls {
    gap: 4px;
  }
  .fb-btn {
    width: 40px;
    height: 40px;
  }
  .fb-indicator {
    min-width: 5.5em;
    font-size: 14px;
  }
  .fb-zoom-btn {
    margin-left: 4px;
  }
}

/* ---------- 拡大表示 ---------- */
.fb-zoom {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(20, 20, 20, 0.92);
}
.fb-zoom[hidden] {
  display: none;
}
.fb-zoom-scroll {
  position: absolute;
  inset: 0;
  overflow: auto;
  display: flex;
  overscroll-behavior: contain;
}
.fb-zoom-inner {
  margin: auto;
  display: flex;
  padding: 16px;
}
.fb-zoom-inner img {
  display: block;
  max-height: calc(100dvh - 32px);
  max-width: calc((100vw - 32px) / var(--count, 1));
  width: auto;
  height: auto;
  background: #fff;
  cursor: zoom-in;
  user-select: none;
  -webkit-user-select: none;
}
.fb-zoom.is-zoomed .fb-zoom-inner img {
  max-width: none;
  max-height: none;
  cursor: zoom-out;
}
.fb-zoom-close {
  position: fixed;
  top: 12px;
  right: 12px;
  z-index: 1;
}
.fb-zoom-hint {
  position: fixed;
  left: 50%;
  bottom: calc(12px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  margin: 0;
  padding: 6px 14px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.6);
  color: #fff;
  font-size: 13px;
  pointer-events: none;
  white-space: nowrap;
}
