/* The Story Book. Its layout (the fixed overlay, the room layers and the creature
   slot) is shared with the other rooms in potions.css; it has no benches, so the
   chamber has the whole screen. See STORYBOOK-PLAN.md. */

#storybook {
  --rock-far: #3a2219; --rock: #4d2f22; --rock-lit: #7a4a2e; --rock-edge: #a8703f; --rock-fore: #2a1812;
  --paper: #fbf3e0; --paper-edge: #e9dcbd; --ink-text: #3a2a22;
}

/* ---------------------------------------------------------------- the room */

.sb-ceiling    { fill: #4a2c20; }
.sb-chain      { stroke: #2a1812; stroke-width: 4; }
.sb-lampshade  { fill: #c4706e; stroke: #8a4a3e; stroke-width: 3; }
.sb-bulb       { fill: #fff3c8; }
.sb-shelf      { fill: #5a3524; }
.sb-spine      { stroke: rgba(0, 0, 0, 0.25); stroke-width: 2; opacity: 0.85; }
.sb-floor      { fill: #3e261c; }
.sb-table-top  { fill: #9a6a42; }
.sb-table-front { fill: #6e4a30; }
.sb-rug-rim    { fill: none; stroke: #f0c27a; stroke-width: 3; stroke-dasharray: 6 8; }

#storybook .creature-slot { width: 28%; pointer-events: none; }

/* ---------------------------------------------------------------- the book */

.sb-book {
  position: absolute; pointer-events: auto; touch-action: pan-y;
  display: grid; grid-template-columns: 1fr 1fr;
  filter: drop-shadow(0 14px 18px rgba(20, 8, 4, 0.5));
}
.sb-page {
  position: relative; overflow: hidden; background: var(--paper);
  box-shadow: inset 0 0 0 2px var(--paper-edge);
}
.sb-left  { border-radius: 18px 4px 4px 18px; background: linear-gradient(90deg, var(--paper) 82%, #eadfc4); }
.sb-right { border-radius: 4px 18px 18px 4px; background: linear-gradient(270deg, var(--paper) 82%, #eadfc4); }
.sb-spine {
  position: absolute; left: 50%; top: 0; bottom: 0; width: 6px; transform: translateX(-50%);
  background: linear-gradient(90deg, rgba(0, 0, 0, 0.18), rgba(0, 0, 0, 0.02), rgba(0, 0, 0, 0.18));
  pointer-events: none;
}

/* The words: as big as the page allows (fitText in storybook.js sets the size). */
.sb-text {
  position: absolute; left: 9%; right: 7%; top: 7%; bottom: 17%; overflow: hidden;
  font-family: Georgia, 'Times New Roman', serif; line-height: 1.45; color: var(--ink-text);
}
.sb-chunk { border-radius: 6px; transition: background-color 0.2s ease, color 0.2s ease; cursor: pointer; }
.sb-chunk.reading { background: #ffe39a; box-shadow: 0 0 0 3px #ffe39a; color: #1e140f; }
.sb-chunk.bear-big    { font-weight: 700; }
.sb-chunk.bear-middle { font-weight: 700; }
.sb-chunk.bear-little { font-weight: 700; }
.sb-num {
  position: absolute; bottom: 4%; font: 600 clamp(0.7rem, 1.2vw, 0.95rem)/1 Georgia, serif; color: #a08a6a;
  pointer-events: none;
}
.sb-num-left  { left: 9%; }
.sb-num-right { right: 9%; }

/* The cover and The End. */
.sb-cover {
  position: absolute; inset: 8% 9% 18%; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 4%; text-align: center;
}
.sb-title {
  font: 800 clamp(1.3rem, 3.4vw, 2.6rem)/1.15 var(--display), Georgia, serif; color: #8a3b36;
  background: none; border: 0; padding: 8px; border-radius: 14px;
}
.sb-title.sb-end { font-size: clamp(2rem, 5.4vw, 4rem); }
.sb-cover-icon { width: 34%; }
.sb-credit { margin: 0; font: italic 400 clamp(0.75rem, 1.4vw, 1.05rem)/1.3 Georgia, serif; color: #6e5a46; }
.sb-cover-art {
  position: absolute; inset: 0; display: flex; align-items: flex-end; justify-content: center; gap: 2%;
  padding-bottom: 26%;
}
.sb-cover-art img { filter: drop-shadow(0 4px 4px rgba(0, 0, 0, 0.25)); }
.sb-cover-art .cover-big { width: 38%; }
.sb-cover-art .cover-middle { width: 28%; }
.sb-cover-art .cover-little { width: 19%; }

/* The picture: her drawing in a frame, or an empty frame that asks for one. */
.sb-pic {
  position: absolute; left: 9%; right: 9%; top: 50%; aspect-ratio: 4 / 3; transform: translateY(-58%);
  padding: 0; border-radius: 10px; background: #fffdf6; overflow: hidden;
  border: 6px solid #c99a62; box-shadow: 0 6px 12px rgba(60, 30, 10, 0.25);
}
.sb-pic img { width: 100%; height: 100%; display: block; object-fit: cover; pointer-events: none; }
.sb-cover-pic { transform: translateY(-50%); }
.sb-pic.blank {
  border: 5px dashed #c99a62; background: rgba(255, 253, 246, 0.7); box-shadow: none;
  display: grid; place-items: center; animation: blank-breathe 2.4s ease-in-out infinite;
}
.sb-pic.blank img { position: absolute; width: auto; height: auto; }
.sb-pic-ink { width: 34% !important; left: 24%; top: 30%; }
.sb-pic-pencil { width: 30% !important; left: 48%; top: 18%; rotate: 25deg; animation: pencil-wiggle 1.6s ease-in-out infinite; }
@keyframes blank-breathe { 50% { background: rgba(255, 228, 160, 0.55); } }
@keyframes pencil-wiggle { 50% { rotate: 10deg; translate: -4% 4%; } }
.sb-pic.bump { animation: pic-bump 0.35s cubic-bezier(.3, 1.5, .5, 1); }
@keyframes pic-bump { 40% { scale: 1.05; } }

/* The End: every page's picture, small. */
.sb-gallery {
  position: absolute; inset: 8% 7% 14%; display: grid; grid-template-columns: repeat(3, 1fr); gap: 4%;
  align-content: center;
}
.sb-gallery img, .sb-gallery-blank {
  width: 100%; aspect-ratio: 4 / 3; border-radius: 6px; object-fit: cover;
  border: 3px solid #c99a62; background: #fffdf6;
}
.sb-gallery-blank { border-style: dashed; opacity: 0.6; }
.sb-gallery.many { grid-template-columns: repeat(4, 1fr); gap: 3%; }

/* ------------------------------------------------------------- the library */

/* The books button, over the creature: three books on a shelf. */
.sb-shelf-btn {
  position: absolute; transform: translate(-50%, -50%); z-index: 3; pointer-events: auto;
  width: max(60px, 7%); aspect-ratio: 1; border-radius: 50%; padding: 0; display: grid; place-items: center;
  background: radial-gradient(circle at 40% 35%, #fff3d6, #e8c58a); border: 3px solid #fff3c8;
  box-shadow: 0 6px 12px rgba(60, 30, 10, 0.4);
}
.sb-shelf-btn svg { width: 70%; height: 70%; }
.sb-shelf-btn.open { box-shadow: 0 0 0 5px rgba(255, 228, 154, 0.8), 0 6px 12px rgba(60, 30, 10, 0.4); }
.sb-shelf-btn.bump { animation: pic-bump 0.35s cubic-bezier(.3, 1.5, .5, 1); }

/* The shelf: each page holds its books, each a big cover with its name under it. */
.sb-shelf-page {
  position: absolute; inset: 7% 8%; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 5%;
}
.sb-shelf-book {
  width: 86%; display: flex; flex-direction: column; align-items: center; gap: 8px;
  padding: 4% 4% 3%; border-radius: 16px; background: none; border: 3px solid transparent;
  font: 700 clamp(0.85rem, 1.7vw, 1.3rem)/1.2 var(--display), Georgia, serif; color: #8a3b36;
}
.sb-shelf-book.open { border-color: #ffc46b; background: rgba(255, 228, 154, 0.35); }
.sb-shelf-cover {
  width: 100%; aspect-ratio: 4 / 3; display: grid; place-items: center; border-radius: 10px; overflow: hidden;
  background: #c4706e; border: 6px solid #8a3b36; box-shadow: 0 6px 12px rgba(60, 30, 10, 0.3);
}
.sb-shelf-cover img { width: 56%; filter: drop-shadow(0 4px 4px rgba(0, 0, 0, 0.3)); }
.sb-shelf-cover img.drawn { width: 100%; height: 100%; object-fit: cover; filter: none; background: #fffdf6; }
.sb-shelf-book.bump { animation: pic-bump 0.35s cubic-bezier(.3, 1.5, .5, 1); }

/* Arrows at the bottom corners, and the speaker in the left page's foot. */
.sb-arrow, .sb-play {
  position: absolute; bottom: 3%; width: max(56px, 8.5%); aspect-ratio: 1; border-radius: 50%; padding: 0;
  display: grid; place-items: center; z-index: 2;
  background: radial-gradient(circle at 40% 35%, #ffd27a, #e09a3a); border: 3px solid #fff3c8;
  box-shadow: 0 6px 12px rgba(60, 30, 10, 0.35);
}
.sb-arrow[hidden], .sb-play[hidden] { display: none; }
.sb-arrow svg, .sb-play svg { width: 60%; height: 60%; }
.sb-arrow path { fill: none; stroke: #5a2e12; stroke-width: 5; stroke-linecap: round; stroke-linejoin: round; }
.sb-prev { left: 2%; }
.sb-next { right: 2%; animation: arrow-nudge 2.6s ease-in-out infinite; }
@keyframes arrow-nudge { 50% { translate: 5px 0; } }
.sb-play { left: 25%; transform: translateX(-50%); background: radial-gradient(circle at 40% 35%, #b9e9ff, #5cb4e0); }
.sb-play path { fill: #1d3a5a; }
.sb-play .wave { fill: none; stroke: #1d3a5a; stroke-width: 3; stroke-linecap: round; }
.sb-arrow.bump, .sb-play.bump { animation: pic-bump 0.35s cubic-bezier(.3, 1.5, .5, 1); }
.sb-title.bump { animation: pic-bump 0.35s cubic-bezier(.3, 1.5, .5, 1); }

/* An upright iPad or a phone: the book takes the width and the creature stands
   in front of its lower left corner. */
@media (max-aspect-ratio: 5/6) {
  #storybook { grid-template-rows: minmax(0, 1fr); }
  #storybook .creature-slot { width: 30%; }
}
