:root {
  --paper: #FBF7EC;
  --paper-deep: #F1E8D2;
  --ink: #3E3428;
  --ink-soft: #6B5D49;
  --accent: #BC5233;
  --accent-ink: #A03E22;
  --wood: #8A6844;
  --card: #FFFDF6;
  --line: #E3D7BC;
  --btn-bg: #FFFDF6;
  --btn-line: #D8C9A6;
  --shadow: rgba(94, 70, 38, 0.35);
  --page-edge: #FFFDF4;
  --page-edge-line: #D9CBA6;
  --board: #7A5A38;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #1B1510;
    --paper-deep: #120E0A;
    --ink: #F0E5CE;
    --ink-soft: #C4B294;
    --accent: #E07856;
    --accent-ink: #E88A68;
    --wood: #A97F52;
    --card: #2A211A;
    --line: #4A3A28;
    --btn-bg: #2A211A;
    --btn-line: #57452F;
    --shadow: rgba(0, 0, 0, 0.6);
    --page-edge: #3A2E20;
    --page-edge-line: #241B12;
    --board: #4A3620;
  }
}
* { box-sizing: border-box; }
html, body { overflow-x: hidden; }
body {
  margin: 0;
  background:
    radial-gradient(120% 60% at 50% 0%, var(--paper) 0%, var(--paper-deep) 100%);
  color: var(--ink);
  font-family: "Zen Maru Gothic", "Hiragino Maru Gothic ProN", "Hiragino Sans", sans-serif;
  -webkit-font-smoothing: antialiased;
}
button { min-height: 2.75rem; font-family: inherit; }
main {
  max-width: 920px;
  margin: 0 auto;
  padding: clamp(14px, 3.5vw, 34px) clamp(12px, 3vw, 28px) 40px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* ---------- 机の上の絵本 ---------- */
.stage {
  position: relative;
  width: 100%;
  max-width: min(860px, max(300px, calc((100dvh - 300px) * 1.7781)));
  margin: 0 auto;
}
.stage::after {
  /* 机に落ちる本の影 */
  content: "";
  position: absolute;
  left: 3%;
  right: 3%;
  bottom: -16px;
  height: 34px;
  background: var(--shadow);
  filter: blur(18px);
  border-radius: 50%;
  z-index: 0;
}
.book {
  position: relative;
  z-index: 1;
  width: 100%;
  aspect-ratio: 1467 / 825;
  perspective: 2400px;
  touch-action: pan-y;
  user-select: none;
  -webkit-user-select: none;
  cursor: grab;
}
.book.grabbing { cursor: grabbing; }
.book::before {
  /* 右側面：積み重なったページの束（紙の厚み） */
  content: "";
  position: absolute;
  top: 4px;
  bottom: 2px;
  right: -7px;
  width: 7px;
  border-radius: 0 3px 3px 0;
  background: repeating-linear-gradient(to right, var(--page-edge) 0, var(--page-edge) 1px, var(--page-edge-line) 1px, var(--page-edge-line) 2px);
  box-shadow: 2px 3px 6px rgba(94, 70, 38, 0.25);
  z-index: 0;
}
.book::after {
  /* 下側面：ページの束 */
  content: "";
  position: absolute;
  left: 4px;
  right: 2px;
  bottom: -6px;
  height: 6px;
  border-radius: 0 0 3px 3px;
  background: repeating-linear-gradient(to bottom, var(--page-edge) 0, var(--page-edge) 1px, var(--page-edge-line) 1px, var(--page-edge-line) 2px);
  box-shadow: 0 3px 6px rgba(94, 70, 38, 0.22);
  z-index: 0;
}
.board {
  /* 表紙の台紙（本のいちばん下） */
  position: absolute;
  inset: 0;
  border-radius: 3px 12px 12px 3px;
  background: var(--board);
  box-shadow: 0 14px 30px rgba(94, 70, 38, 0.30);
  z-index: 0;
}
.turn-shadow {
  /* めくれている紙が、下のページに落とす影 */
  position: absolute;
  inset: 0;
  border-radius: 3px 12px 12px 3px;
  pointer-events: none;
  opacity: 0;
  z-index: 0;
}
.leaf {
  position: absolute;
  inset: 0;
  transform-origin: left center;
  transform-style: preserve-3d;
  transition: transform 1.05s cubic-bezier(0.22, 0.9, 0.26, 1);
  will-change: transform;
}
.leaf.dragging .seg { will-change: transform; }
/* 紙は1枚の板ではなく、背から先へ14本の縦帯（セグメント）に分けて連動させる。
   帯ごとに角度差をつけることで、紙全体がしなって見える */
.seg {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: calc(100% / 14);
  transform-origin: left center;
  transform-style: preserve-3d;
}
/* めくり口のカールヒント：右下の角がほんの少し浮いて「つかめる」ことを伝える */
.peel {
  position: absolute;
  right: 0;
  bottom: 0;
  width: clamp(46px, 9%, 76px);
  aspect-ratio: 1;
  z-index: 500;
  pointer-events: none;
  transition: opacity 0.3s ease;
  filter: drop-shadow(-3px -3px 5px rgba(70, 48, 20, 0.28));
}
.peel .peel-fold {
  position: absolute;
  inset: 0;
  background: linear-gradient(315deg, var(--paper-deep) 0%, #FFFDF4 55%, #EFE6CC 100%);
  clip-path: polygon(100% 0, 0 100%, 100% 100%);
  border-radius: 0 0 12px 0;
  transform-origin: bottom right;
  animation: peelLift 3.4s ease-in-out infinite alternate;
}
.peel .peel-under {
  position: absolute;
  inset: 0;
  background: linear-gradient(315deg, rgba(70,48,20,0.30) 0%, rgba(70,48,20,0) 62%);
  clip-path: polygon(100% 0, 0 100%, 100% 100%);
}
@keyframes peelLift {
  from { transform: scale(1) rotate(0deg); }
  to { transform: scale(1.10) rotate(-1.6deg); }
}
@media (prefers-color-scheme: dark) {
  .peel .peel-fold { background: linear-gradient(315deg, #241B12 0%, #4A3A26 55%, #332818 100%); }
}
.leaf.flipped { transform: rotateY(-180deg); }
.leaf.dragging { transition: none !important; }
.face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  overflow: hidden;
  background: var(--paper-deep);
}
.seg.first .face.front { border-radius: 3px 0 0 3px; }
.seg.last .face.front { border-radius: 0 12px 12px 0; }
.seg.first .face.back { border-radius: 0 3px 3px 0; }
.seg.last .face.back { border-radius: 12px 0 0 12px; }
.face img {
  position: absolute;
  top: 0;
  left: 0;
  display: block;
  width: calc(14 * 100%);
  max-width: none;
  height: 100%;
  object-fit: cover;
  pointer-events: none;
}
.edge {
  /* 背の綴じ影・紙のふち（帯の端だけに置く静かな陰） */
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 2;
}
.seg.first .face.front .edge {
  background: linear-gradient(to right, rgba(70, 48, 20, 0.30) 0%, rgba(70, 48, 20, 0.10) 34%, rgba(255,255,255,0.10) 52%, rgba(0,0,0,0) 88%);
}
.seg.last .face.front .edge {
  background: linear-gradient(to left, rgba(70, 48, 20, 0.16) 0%, rgba(0,0,0,0) 55%);
}
.seg.first .face.back .edge {
  background: linear-gradient(to left, rgba(70, 48, 20, 0.22) 0%, rgba(0,0,0,0) 70%);
}
.grain {
  /* 紙のざらつき */
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0.055;
  mix-blend-mode: multiply;
  background-image: url("../ehon/noise.svg");
  z-index: 2;
}
.shade {
  /* 帯ごとの光と影（めくり中にJSが帯ごとに濃さを変える。
     影が紙の上を流れて見えることが、面ではなく「しなり」の決め手） */
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  z-index: 3;
  background: #2E1E08;
}
.face.back {
  transform: rotateY(180deg);
  background: #F4EDD9;
}
.face.back img {
  opacity: 0.16;
  filter: sepia(0.35);
}
.face.back .veil {
  /* 裏面は紙そのもの（うっすら透ける絵）の地の色 */
  position: absolute;
  inset: 0;
  background: radial-gradient(90% 90% at 50% 45%, rgba(255,255,255,0.25) 0%, rgba(120, 96, 54, 0.10) 100%);
  pointer-events: none;
  z-index: 1;
}
@media (prefers-color-scheme: dark) {
  .face.back { background: #3A2E1E; }
}
.zone {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 50%;
  z-index: 600;
  background: transparent;
  border: 0;
  padding: 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.zone-prev { left: 0; cursor: w-resize; }
.zone-next { right: 0; cursor: e-resize; }
.zone:focus-visible { outline: 3px solid var(--accent); outline-offset: -3px; }

/* ---------- 本文 ---------- */
.page-text {
  margin-top: clamp(26px, 5vw, 42px);
  max-width: 640px;
  min-height: 4.2em;
  text-align: center;
  font-size: clamp(1.13rem, 1rem + 1.4vw, 1.5rem);
  font-weight: 500;
  line-height: 1.95;
  letter-spacing: 0.02em;
  transition: opacity 0.22s ease;
}
.page-text.fading { opacity: 0; }
.page-text .cover-title {
  display: block;
  font-size: 1.28em;
  font-weight: 900;
  line-height: 1.5;
}
.page-text .cover-sub {
  display: block;
  font-size: 0.82em;
  font-weight: 700;
  color: var(--accent-ink);
  margin-bottom: 0.4em;
}

.end-note {
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}
.end-note[hidden] { display: none; }
.end-mark {
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 0.5em;
  text-indent: 0.5em;
  color: var(--ink-soft);
}

/* ---------- 操作ボタン ---------- */
.controls {
  margin-top: clamp(20px, 4vw, 30px);
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  justify-content: center;
}
.nav-btn {
  border: 1.5px solid var(--btn-line);
  background: var(--btn-bg);
  color: var(--ink);
  border-radius: 999px;
  padding: 8px 20px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(94, 70, 38, 0.12);
  transition: transform 0.12s ease, opacity 0.2s ease, background 0.2s ease;
}
.nav-btn:hover:not(:disabled) { background: var(--paper-deep); }
.nav-btn:active:not(:disabled) { transform: scale(0.96); }
.nav-btn:disabled { opacity: 0.35; cursor: default; box-shadow: none; }
.counter {
  font-size: 1rem;
  font-weight: 700;
  color: var(--ink-soft);
  min-width: 4.2em;
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.narrate-btn {
  border: 0;
  background: var(--accent);
  color: #FFF8EC;
  border-radius: 999px;
  padding: 10px 26px;
  font-size: 1.05rem;
  font-weight: 900;
  letter-spacing: 0.03em;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(160, 62, 34, 0.35);
  transition: transform 0.12s ease, background 0.2s ease;
}
.narrate-btn:hover { filter: brightness(1.06); }
.narrate-btn:active { transform: scale(0.96); }
.narrate-btn.playing { background: var(--wood); box-shadow: 0 4px 14px rgba(94, 70, 38, 0.35); }
.restart-btn {
  border: 1.5px solid var(--accent);
  background: transparent;
  color: var(--accent-ink);
  border-radius: 999px;
  padding: 8px 22px;
  font-size: 1rem;
  font-weight: 900;
  cursor: pointer;
}
.restart-btn:active { transform: scale(0.96); }
.hint {
  margin-top: 16px;
  font-size: 0.82rem;
  color: var(--ink-soft);
  text-align: center;
  line-height: 1.7;
}

/* ---------- 横向き（高さの低い画面）：本と文章を横に並べる ---------- */
@media (orientation: landscape) and (max-height: 620px) {
  main {
    max-width: none;
    height: 100dvh;
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(210px, 300px);
    grid-template-rows: repeat(5, auto);
    align-content: center;
    align-items: center;
    column-gap: clamp(14px, 3vw, 28px);
    padding: 10px clamp(12px, 2.5vw, 24px);
  }
  .stage {
    grid-column: 1;
    grid-row: 1 / -1;
    max-width: calc((100dvh - 20px) * 1.7781);
  }
  .page-text {
    grid-column: 2;
    margin-top: 0;
    text-align: left;
    font-size: clamp(0.98rem, 0.9rem + 0.8vw, 1.15rem);
    line-height: 1.85;
    min-height: 0;
  }
  .end-note { grid-column: 2; align-items: flex-start; margin-top: 6px; }
  .controls { grid-column: 2; margin-top: 12px; justify-content: flex-start; gap: 10px; }
  .hint { grid-column: 2; margin-top: 10px; text-align: left; font-size: 0.76rem; }
}

@media (prefers-reduced-motion: reduce) {
  .peel .peel-fold { animation: none; }
  .leaf { transition-duration: 0.12s; }
  .page-text { transition: none; }
  .nav-btn, .narrate-btn, .restart-btn { transition: none; }
}
    

/* ---------- HP組み込み用：見出しと戻り導線 ---------- */
.ehon-head {
  max-width: 920px;
  margin: 0 auto;
  padding: clamp(18px, 4vw, 34px) clamp(12px, 3vw, 28px) 0;
  text-align: center;
}
.ehon-back {
  display: inline-block;
  color: var(--accent-ink);
  font-weight: 700;
  font-size: 0.92rem;
  text-decoration: none;
  border: 1.5px solid var(--btn-line);
  background: var(--btn-bg);
  border-radius: 999px;
  padding: 6px 16px;
  box-shadow: 0 2px 6px rgba(94, 70, 38, 0.12);
}
.ehon-back:hover { background: var(--paper-deep); }
.ehon-kicker {
  margin: 20px 0 4px;
  font-size: 0.85rem;
  font-weight: 700;
  letter-spacing: 0.18em;
  color: var(--ink-soft);
}
.ehon-title {
  margin: 0;
  font-size: clamp(1.55rem, 1.2rem + 2.4vw, 2.3rem);
  font-weight: 900;
  line-height: 1.4;
}
.ehon-sub {
  margin: 6px 0 0;
  font-size: clamp(0.98rem, 0.9rem + 0.7vw, 1.12rem);
  font-weight: 700;
  color: var(--accent-ink);
}
/* 机の上に置かれた絵本の情景（上部は透過でページ背景に溶ける） */
.ehon-desk {
  margin: clamp(8px, 2vw, 18px) auto 0;
  padding: 0 12px;
  text-align: center;
}
.ehon-desk img {
  display: block;
  width: min(620px, 92vw);
  height: auto;
  margin: 0 auto;
}
.ehon-foot {
  margin: 0 auto;
  padding: 0 16px 34px;
  text-align: center;
  font-size: 0.92rem;
  font-weight: 700;
  color: var(--ink-soft);
}
.ehon-foot a { color: var(--accent-ink); text-decoration: none; }
.ehon-foot a:hover { text-decoration: underline; }
.ehon-foot span { margin: 0 8px; }

/* 横向き（高さの低い画面）では見出しを細くし、本の領域を確保する */
@media (orientation: landscape) and (max-height: 620px) {
  .ehon-head {
    display: flex;
    align-items: baseline;
    gap: 14px;
    padding: 8px 16px 0;
    text-align: left;
    max-width: none;
  }
  .ehon-kicker { display: none; }
  .ehon-title { font-size: 1.05rem; }
  .ehon-sub { margin: 0; font-size: 0.9rem; }
  .ehon-desk { margin-top: 2px; padding: 0 8px; }
  .ehon-desk img { width: min(150px, 26vw); }
  main { height: calc(100dvh - 48px); }
  .ehon-foot { display: none; }
}

