/* Fairy-tale opening book — sits above the game until the last page is chosen */

#story-book-scene {
  position: absolute;
  inset: 0;
  z-index: 80;
  overflow: hidden;
  font-family: 'IM Fell English', 'Palatino Linotype', Palatino, serif;
  color: #2c1810;
  -webkit-user-select: none;
  user-select: none;
}

#story-book-scene.hidden { display: none !important; }

#story-book-scene.leaving {
  pointer-events: none;
  animation: book-scene-leave 1.1s ease forwards;
}
@keyframes book-scene-leave {
  0% { opacity: 1; filter: brightness(1); }
  100% { opacity: 0; filter: brightness(0.15); }
}

.book-room {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  background: #0a0e18;
}

/* Late-night meadow / forest photo */
.book-night-bg {
  position: absolute;
  inset: 0;
  background:
    url('../assets/book/bg-room.jpg') center center / cover no-repeat;
  filter: saturate(0.85) brightness(0.72) contrast(1.05);
  transform: scale(1.03);
}
.book-night-bg::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(
    180deg,
    rgba(8, 12, 28, 0.55) 0%,
    rgba(12, 18, 36, 0.25) 35%,
    rgba(6, 10, 22, 0.45) 100%
  );
}

.book-moon-glow {
  position: absolute;
  top: 8%;
  right: 14%;
  width: 220px;
  height: 220px;
  border-radius: 50%;
  pointer-events: none;
  background: radial-gradient(circle, rgba(200, 220, 255, 0.14) 0%, transparent 68%);
  animation: moon-pulse 6s ease-in-out infinite;
}
@keyframes moon-pulse {
  0%, 100% { opacity: 0.6; transform: scale(1); }
  50% { opacity: 1; transform: scale(1.06); }
}

.book-vignette {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(ellipse at center, transparent 32%, rgba(4, 6, 14, 0.72) 100%);
  z-index: 4;
}

/* Fireflies */
.book-fireflies {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 5;
}
.firefly {
  position: absolute;
  border-radius: 50%;
  background: #d4ff72;
  box-shadow:
    0 0 6px 2px rgba(210, 255, 120, 0.9),
    0 0 18px 4px rgba(180, 255, 80, 0.45),
    0 0 32px 8px rgba(140, 220, 60, 0.2);
  animation:
    firefly-drift var(--dur, 8s) ease-in-out infinite alternate,
    firefly-twinkle var(--glow, 2s) ease-in-out infinite;
  opacity: 0;
}
@keyframes firefly-drift {
  0% { transform: translate(0, 0); }
  33% { transform: translate(var(--x1, 20px), var(--y1, -15px)); }
  66% { transform: translate(var(--x2, -25px), var(--y2, 10px)); }
  100% { transform: translate(calc(var(--x1, 20px) * -0.5), calc(var(--y2, 10px) * -0.8)); }
}
@keyframes firefly-twinkle {
  0%, 100% { opacity: 0.15; filter: brightness(0.6); }
  20% { opacity: 0.95; filter: brightness(1.4); }
  45% { opacity: 0.35; filter: brightness(0.8); }
  70% { opacity: 1; filter: brightness(1.6); }
}

.book-stage-wrap {
  position: relative;
  z-index: 6;
  width: min(1100px, 94vw);
  filter:
    drop-shadow(0 32px 40px rgba(0, 0, 0, 0.75))
    drop-shadow(0 0 48px rgba(180, 220, 255, 0.06));
}
.book-stage-wrap::before {
  content: '';
  position: absolute;
  left: 10%;
  right: 10%;
  bottom: -30px;
  height: 40px;
  background: radial-gradient(ellipse at center, rgba(0, 0, 0, 0.65), transparent 72%);
  pointer-events: none;
  z-index: -1;
}

#fairy-book {
  margin: 0 auto;
  width: 100%;
}

#story-book-scene.is-closed .page-cover {
  box-shadow:
    6px 0 0 -1px #5a1820,
    9px 0 0 -1px #4a1018,
    12px 0 0 -1px #3a0810,
    14px 0 0 -1px #2a060c,
    20px 18px 36px rgba(0, 0, 0, 0.65);
}

.book-hint {
  position: relative;
  z-index: 6;
  font-family: 'IM Fell English SC', 'IM Fell English', serif;
  font-size: clamp(14px, 2vw, 18px);
  letter-spacing: 0.18em;
  color: #d8e8c8;
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.85);
  opacity: 0.92;
  min-height: 1.4em;
  text-align: center;
  padding: 0 16px;
}
.book-hint kbd {
  font-family: inherit;
  letter-spacing: 0.08em;
  color: #e8f4d0;
}

.book-nav {
  position: relative;
  z-index: 6;
  display: flex;
  align-items: center;
  gap: 18px;
}
.book-nav button {
  font-family: 'Cinzel Decorative', serif;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: 1px solid #c9a227;
  background: radial-gradient(circle at 35% 30%, #5a1820, #2a080c);
  color: #f0d78c;
  font-size: 22px;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.55), inset 0 1px 0 rgba(255, 220, 150, 0.2);
  transition: transform 0.15s ease, filter 0.15s ease;
}
.book-nav button:hover { transform: scale(1.08); filter: brightness(1.15); }
.book-nav button:disabled { opacity: 0.35; cursor: default; transform: none; }
#book-folio {
  min-width: 90px;
  text-align: center;
  color: #c8dcc0;
  font-family: 'IM Fell English SC', serif;
  letter-spacing: 0.12em;
  font-size: 14px;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.8);
}

/* ---------- Page shells ---------- */
.page {
  background-color: #f1e2c0;
  overflow: hidden;
}

#story-book-scene.is-closed .stf__block {
  cursor: pointer;
}

.page-inner {
  position: absolute;
  inset: 0;
  padding: 6% 8% 7%;
  display: flex;
  flex-direction: column;
  z-index: 2;
}

.page-illustration {
  flex: 0 1 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 28%;
  max-height: 46%;
  margin: 0 0 10px;
}
.page-illustration img {
  display: block;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 220px;
  object-fit: contain;
  background: transparent;
  border: none;
  box-shadow: none;
  mix-blend-mode: multiply;
}
.page-illustration img.art-processed {
  opacity: 0.94;
}

.cover-art {
  flex: 0 1 auto;
  width: 100%;
  max-height: 52%;
  margin: 0 0 2px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.cover-art img {
  max-height: min(240px, 38vh);
  width: auto;
  max-width: 92%;
  background: transparent;
  border: none;
  box-shadow: none;
  object-fit: contain;
}
.cover-art img.art-processed {
  mix-blend-mode: normal;
  /* gold ink on dark leather */
  filter: invert(1) sepia(0.85) saturate(2.4) hue-rotate(355deg) brightness(1.15);
  opacity: 0.92;
}

.title-page-inner .page-illustration {
  flex: 0 0 auto;
  max-height: 34%;
  width: 100%;
  margin: 4px 0 8px;
}
.title-page-inner .page-illustration img {
  max-height: min(210px, 32vh);
  margin: 0 auto;
}
.title-page-inner .page-illustration img.art-processed {
  opacity: 0.92;
}

.endpaper-art {
  height: 100%;
  max-height: none;
  min-height: 70%;
  margin: 0;
}
.endpaper-art img {
  max-height: 80%;
  background: transparent;
  border: 1px solid rgba(232, 201, 90, 0.2);
}
.endpaper-art img.art-processed {
  mix-blend-mode: normal;
  filter: invert(1) sepia(0.85) saturate(2.4) hue-rotate(355deg) brightness(1.15);
  opacity: 0.92;
}

.page-inner.has-page-art {
  background: transparent;
}

.page-art-only .page-inner {
  display: flex;
}

.page-quiet .page-illustration {
  flex: 1;
  max-height: none;
  min-height: 0;
  margin: auto;
}
.page-quiet .page-illustration img {
  max-height: 85%;
}

.page-the-end .page-illustration {
  max-height: 38%;
  min-height: 22%;
}
.page-the-end .page-illustration img {
  max-height: 180px;
}

/* Parchment story pages */
.page-paper {
  background-color: #f3e4c4;
  background-image:
    radial-gradient(ellipse at 12% 8%, rgba(140, 90, 40, 0.1), transparent 42%),
    radial-gradient(ellipse at 88% 92%, rgba(120, 70, 30, 0.11), transparent 40%),
    repeating-linear-gradient(0deg, transparent, transparent 26px, rgba(90, 55, 20, 0.03) 27px);
  box-shadow: inset 0 0 40px rgba(90, 50, 20, 0.1);
}

.page.--left .page-paper {
  background-image:
    linear-gradient(90deg, rgba(70, 40, 16, 0.14) 0%, transparent 7%),
    radial-gradient(ellipse at 12% 8%, rgba(140, 90, 40, 0.1), transparent 42%),
    repeating-linear-gradient(0deg, transparent, transparent 26px, rgba(90, 55, 20, 0.03) 27px);
}
.page.--right .page-paper {
  background-image:
    linear-gradient(270deg, rgba(70, 40, 16, 0.14) 0%, transparent 7%),
    radial-gradient(ellipse at 88% 92%, rgba(120, 70, 30, 0.11), transparent 40%),
    repeating-linear-gradient(0deg, transparent, transparent 26px, rgba(90, 55, 20, 0.03) 27px);
}

.page-ornament {
  text-align: center;
  color: #8a5a28;
  font-size: 18px;
  letter-spacing: 0.4em;
  opacity: 0.75;
  margin-bottom: 8px;
}

.page-kicker {
  font-family: 'IM Fell English SC', serif;
  font-size: 13px;
  letter-spacing: 0.22em;
  text-align: center;
  color: #7a3a28;
  margin-bottom: 10px;
}

.story-body {
  flex: 1;
  font-size: clamp(15px, 1.55vw, 19px);
  line-height: 1.72;
  color: #2a160e;
  text-align: justify;
  hyphens: auto;
}
.story-body p { margin: 0 0 0.85em; }
.story-body em {
  font-style: italic;
  display: block;
  text-align: center;
  line-height: 1.85;
  color: #3a2010;
}
.story-body p:last-child { margin-bottom: 0; }

.drop-cap {
  float: left;
  font-family: 'Cinzel Decorative', serif;
  font-weight: 700;
  font-size: 4.6em;
  line-height: 0.78;
  padding: 4px 10px 0 0;
  color: #6a1018;
  text-shadow: 1px 1px 0 #e8c95a, 2px 2px 0 rgba(90, 40, 10, 0.2);
}

.folio {
  margin-top: auto;
  padding-top: 10px;
  text-align: center;
  font-family: 'IM Fell English SC', serif;
  font-size: 13px;
  letter-spacing: 0.16em;
  color: #8a6a40;
}

/* ---------- Auto-fit for text-heavy pages (classes applied by book.js) ---------- */
.page.art-sm .page-illustration { min-height: 16%; max-height: 34%; }
.page.art-sm .page-illustration img { max-height: 148px; }
.page.art-xs .page-illustration { min-height: 9%; max-height: 22%; margin-bottom: 6px; }
.page.art-xs .page-illustration img { max-height: 102px; }
.page.art-xs .page-ornament { font-size: 15px; margin-bottom: 4px; }
.page.art-hide .page-illustration { display: none; }
.page.text-sm .story-body { font-size: clamp(13px, 1.38vw, 17px); line-height: 1.58; }
.page.text-xs .story-body { font-size: clamp(12px, 1.22vw, 15.5px); line-height: 1.46; }

/* ---------- Dark red antique leather cover ---------- */
.page-cover {
  background: #3a0810;
}

.cover-leather {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse at 28% 12%, rgba(180, 60, 70, 0.12), transparent 40%),
    radial-gradient(ellipse at 75% 88%, rgba(0, 0, 0, 0.35), transparent 48%),
    linear-gradient(168deg, #6a1820 0%, #4a0c14 28%, #320810 52%, #4a1018 78%, #3a0810 100%);
  box-shadow:
    inset 0 0 0 10px #4a1018,
    inset 0 0 0 12px #c9a227,
    inset 0 0 0 14px #4a1018,
    inset 0 0 0 16px rgba(201, 162, 39, 0.35),
    inset 0 0 70px rgba(0, 0, 0, 0.5);
}

.cover-grain {
  position: absolute;
  inset: 0;
  opacity: 0.45;
  pointer-events: none;
  background-image:
    repeating-radial-gradient(circle at 17% 29%, rgba(255, 255, 255, 0.03) 0 1px, transparent 2px 5px),
    repeating-radial-gradient(circle at 63% 71%, rgba(0, 0, 0, 0.06) 0 1px, transparent 2px 4px),
    repeating-radial-gradient(circle at 41% 55%, rgba(120, 20, 30, 0.08) 0 1px, transparent 2px 6px);
  mix-blend-mode: overlay;
}

.cover-leather::after {
  content: '';
  position: absolute;
  inset: 26px;
  border: 1px solid rgba(232, 201, 90, 0.35);
  box-shadow:
    inset 0 0 0 5px rgba(50, 10, 14, 0.7),
    inset 0 0 0 6px rgba(201, 162, 39, 0.28);
  pointer-events: none;
  z-index: 1;
}

.cover-content {
  position: absolute;
  inset: 40px 32px 44px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  text-align: center;
  gap: 8px;
  z-index: 2;
}

.cover-ornament {
  position: absolute;
  inset: 20px;
  width: calc(100% - 40px);
  height: calc(100% - 40px);
  pointer-events: none;
  opacity: 0.85;
}

.cover-title {
  font-family: 'Cinzel Decorative', serif;
  font-weight: 700;
  font-size: clamp(22px, 3.6vw, 34px);
  line-height: 1.35;
  letter-spacing: 0.04em;
  max-width: 92%;
  padding: 0 8px;
  background: linear-gradient(180deg, #fff8d8 0%, #e8c95a 35%, #b8860b 50%, #f0d78c 72%, #c9a227 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 2px 0 rgba(30, 6, 8, 0.9)) drop-shadow(0 0 12px rgba(232, 201, 90, 0.25));
  text-transform: none;
}

.cover-subtitle {
  font-family: 'IM Fell English SC', serif;
  font-size: clamp(11px, 1.6vw, 14px);
  letter-spacing: 0.32em;
  color: #d4b56a;
  text-transform: uppercase;
  margin-top: 6px;
}

.cover-motto {
  margin-top: 8px;
  font-style: italic;
  color: #c9a860;
  font-size: 15px;
}

.page-back .cover-leather::after { opacity: 0.5; }
.back-cover-mark {
  font-family: 'Cinzel Decorative', serif;
  font-size: 42px;
  color: #e8c95a;
  opacity: 0.45;
}

/* ---------- Dark red endpapers (inside cover) ---------- */
.page-endpaper .page-inner,
.endpaper-inner {
  padding: 0;
}

.endpaper-red {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse at 30% 20%, rgba(120, 30, 40, 0.2), transparent 50%),
    radial-gradient(ellipse at 70% 80%, rgba(0, 0, 0, 0.25), transparent 45%),
    linear-gradient(175deg, #5a1420 0%, #420c14 40%, #320810 100%);
  box-shadow: inset 0 0 50px rgba(0, 0, 0, 0.45);
}
.endpaper-red::after {
  content: '';
  position: absolute;
  inset: 16px;
  border: 1px solid rgba(201, 162, 39, 0.22);
  pointer-events: none;
}

/* ---------- Title page ---------- */
.title-page-inner {
  align-items: center;
  justify-content: flex-start;
  text-align: center;
  gap: 8px;
  padding-top: 18px;
}
.title-page-inner h2 {
  font-family: 'Cinzel Decorative', serif;
  font-size: clamp(26px, 3.4vw, 36px);
  font-weight: 700;
  color: #5a1418;
  line-height: 1.25;
  letter-spacing: 0.04em;
}
.title-page-inner .tp-sub {
  font-style: italic;
  font-size: clamp(15px, 1.8vw, 18px);
  color: #5a3a22;
  max-width: 18em;
}
.title-rule {
  width: 40%;
  height: 2px;
  background: linear-gradient(90deg, transparent, #8a5a28 25%, #8a5a28 75%, transparent);
  opacity: 0.7;
}
.title-page-inner .tp-ded {
  margin-top: 18px;
  font-size: 16px;
  color: #7a4a28;
}
.title-page-inner .tp-year {
  font-family: 'IM Fell English SC', serif;
  letter-spacing: 0.2em;
  font-size: 13px;
  color: #8a6a40;
}

/* ---------- The End / enter the game ---------- */
.page-the-end .page-inner {
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 10px;
}
.the-end-heading {
  font-family: 'Cinzel Decorative', serif;
  font-size: clamp(36px, 5vw, 52px);
  color: #5a1418;
  letter-spacing: 0.08em;
  text-shadow: 1px 1px 0 #e8c95a;
}
.the-end-rule {
  color: #8a5a28;
  letter-spacing: 0.5em;
  font-size: 18px;
}
.enter-adventure-btn {
  appearance: none;
  margin-top: 18px;
  max-width: 16em;
  font-family: 'IM Fell English', serif;
  font-size: clamp(18px, 2.2vw, 22px);
  font-style: italic;
  line-height: 1.4;
  color: #5a2a08;
  background: linear-gradient(180deg, #f4e4b0, #e0c070);
  border: 2px solid #8a6a18;
  border-radius: 4px;
  padding: 16px 22px;
  cursor: pointer;
  box-shadow:
    0 0 0 4px rgba(90, 20, 16, 0.08),
    0 8px 18px rgba(60, 30, 8, 0.22),
    inset 0 1px 0 rgba(255, 255, 230, 0.7);
  animation: enter-glow 2.4s ease-in-out infinite;
  transition: transform 0.15s ease, filter 0.15s ease;
}
.enter-adventure-btn:hover {
  transform: translateY(-2px) scale(1.03);
  filter: brightness(1.06);
}
.enter-adventure-btn:active { transform: translateY(1px) scale(0.99); }
@keyframes enter-glow {
  0%, 100% { box-shadow: 0 0 0 4px rgba(90, 20, 16, 0.08), 0 8px 18px rgba(60, 30, 8, 0.22), 0 0 0 0 rgba(232, 201, 90, 0); }
  50% { box-shadow: 0 0 0 4px rgba(90, 20, 16, 0.08), 0 8px 18px rgba(60, 30, 8, 0.22), 0 0 18px 2px rgba(232, 201, 90, 0.45); }
}

.page-quiet .quiet-mark {
  margin: auto;
  font-family: 'Cinzel Decorative', serif;
  font-size: 48px;
  color: #8a5a28;
  opacity: 0.45;
  text-align: center;
}

@media (max-width: 700px) {
  .book-nav { gap: 10px; }
  .book-moon-glow { width: 120px; height: 120px; right: 8%; }
  .story-body { font-size: 14px; line-height: 1.62; text-align: left; }
  .drop-cap { font-size: 3.6em; }
  .cover-title { font-size: 20px; }
}

@media (max-height: 640px) {
  .book-hint { display: none; }
  .book-nav button { width: 38px; height: 38px; }
}
