/* ---------------------------------------------------------------- layer + stage */

.book-layer {
  z-index: 40;
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(ellipse at 50% 40%, rgba(255, 190, 90, 0.18), transparent 60%),
    radial-gradient(ellipse at 50% 120%, rgba(123, 77, 255, 0.45), transparent 60%),
    rgba(5, 4, 20, 0.88);
  backdrop-filter: blur(8px);
}

.book-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: max(12px, env(safe-area-inset-top)) 16px 8px;
}

#book-host {
  flex: 1;
  min-height: 0;
}

.book-stage {
  position: relative;
  height: 100%;
  perspective: 2400px;
  overflow: hidden;
}

.book {
  position: absolute;
  left: 50%;
  top: 50%;
  margin-left: calc(var(--pw) * -1);
  margin-top: calc(var(--ph) / -2);
  width: calc(var(--pw) * 2);
  height: var(--ph);
  transform-style: preserve-3d;
  transition: transform 0.8s var(--ease-out);
  font-size: calc(var(--pw) * 0.041);
}

.book-layer.is-open .book {
  animation: book-arrive 0.8s var(--ease-out);
}

@keyframes book-arrive {
  from {
    opacity: 0;
    translate: 0 60px;
    scale: 0.8;
  }
}

.book-nav {
  display: flex;
  justify-content: center;
  gap: 28px;
  padding: 10px 16px max(16px, env(safe-area-inset-bottom));
}

.nav-btn {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: 2px solid rgba(255, 212, 77, 0.6);
  background: rgba(26, 17, 80, 0.8);
  color: var(--gold);
  font-size: 34px;
  line-height: 1;
  transition: transform 0.2s var(--ease-pop), opacity 0.2s;
}

.nav-btn:hover:not(:disabled) {
  transform: scale(1.1);
}

.nav-btn:disabled {
  opacity: 0.3;
  cursor: default;
}

/* ---------------------------------------------------------------- leaves */

.leaf {
  position: absolute;
  top: 0;
  left: 50%;
  width: var(--pw);
  height: var(--ph);
  transform-origin: 0 50%;
  transform-style: preserve-3d;
  transition: transform 0.9s cubic-bezier(0.645, 0.045, 0.355, 1);
}

.leaf.is-flipped {
  transform: rotateY(-180deg);
}

.leaf.is-turning .face {
  box-shadow: 0 0 60px rgba(0, 0, 0, 0.45);
}

.face {
  position: absolute;
  inset: 0;
  overflow: hidden;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  color: var(--ink);
  font-family: var(--font-book);
  background:
    radial-gradient(ellipse at 30% 20%, rgba(255, 255, 255, 0.45), transparent 55%),
    radial-gradient(ellipse at 80% 90%, rgba(170, 120, 50, 0.18), transparent 60%),
    linear-gradient(180deg, var(--parchment), var(--parchment-deep));
}

.face.front {
  border-radius: 4px 14px 14px 4px;
  box-shadow: inset 18px 0 30px -18px rgba(90, 50, 10, 0.45), 6px 10px 24px rgba(0, 0, 0, 0.35);
}

.face.back {
  transform: rotateY(180deg);
  border-radius: 14px 4px 4px 14px;
  box-shadow: inset -18px 0 30px -18px rgba(90, 50, 10, 0.45), -6px 10px 24px rgba(0, 0, 0, 0.35);
}

.face:not(.is-visible) * {
  pointer-events: none;
}

/* ---------------------------------------------------------------- covers */

.cover {
  position: absolute;
  inset: 0;
  padding: 7%;
  background:
    radial-gradient(ellipse at 30% 25%, rgba(255, 255, 255, 0.18), transparent 50%),
    repeating-linear-gradient(45deg, rgba(255, 255, 255, 0.03) 0 2px, transparent 2px 6px),
    linear-gradient(160deg, #4a22b8, #26105e 60%, #170a3a);
}

.cover.back {
  background: linear-gradient(200deg, #4a22b8, #170a3a);
}

.cover-frame {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  text-align: center;
  padding: 7% 6%;
  border: 3px solid #e6b450;
  border-radius: 10px;
  box-shadow: inset 0 0 0 6px rgba(230, 180, 80, 0.25);
  color: #ffe7a8;
}

.cover-episode {
  font: 600 0.8em var(--font-ui);
  letter-spacing: 0.3em;
  text-transform: uppercase;
}

.cover-logo {
  width: 30%;
  filter: drop-shadow(0 0 18px rgba(255, 200, 90, 0.6));
}

.cover-title {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.55em;
  line-height: 1.15;
  background: linear-gradient(180deg, #fff6d6, #e6b450);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.cover-medallion {
  width: 40%;
  aspect-ratio: 1;
  border-radius: 50%;
  padding: 4%;
  border: 3px solid #e6b450;
  background: radial-gradient(circle, rgba(255, 210, 120, 0.25), rgba(0, 0, 0, 0.2));
}

.cover-medallion .art {
  width: 100%;
  height: 100%;
}

.cover-open {
  border: 0;
  border-radius: 999px;
  padding: 0.6em 1.4em;
  font: 700 0.85em var(--font-ui);
  color: #3a1d02;
  background: linear-gradient(180deg, #ffe58a, var(--gold-deep));
  animation: glow-pulse 1.8s ease-in-out infinite;
}

@keyframes glow-pulse {
  50% {
    box-shadow: 0 0 26px rgba(255, 212, 77, 0.85);
  }
}

/* ---------------------------------------------------------------- page content */

.page-inner {
  position: relative;
  height: 100%;
  padding: 9% 9% 11%;
  display: flex;
  flex-direction: column;
  gap: 0.55em;
}

.page-inner h2,
.page-inner h3 {
  margin: 0;
  font-family: var(--font-display);
  color: #4a2410;
  line-height: 1.15;
}

.page-inner h2 {
  font-size: 1.5em;
}

.page-inner h3 {
  font-size: 1.15em;
}

.page-inner p {
  margin: 0;
  font-size: 1.12em;
  line-height: 1.45;
}

.chapter {
  font: 600 0.72em var(--font-ui);
  letter-spacing: 0.24em;
  text-transform: uppercase;
  color: #a0521a;
}

.folio {
  position: absolute;
  bottom: 4.5%;
  left: 50%;
  translate: -50% 0;
  font-size: 0.85em;
  color: var(--ink-soft);
}

.flourish {
  font-size: 1.6em;
  color: #a0521a;
  text-align: center;
}

.drop-cap::first-letter {
  float: left;
  font-family: var(--font-display);
  font-size: 2.9em;
  line-height: 0.85;
  padding: 0.05em 0.1em 0 0;
  color: #b3122e;
}

.inside {
  justify-content: center;
}

.ex-libris {
  text-align: center;
  font-style: italic;
  color: var(--ink-soft);
}

.quest-steps {
  margin: 0;
  padding-left: 1.3em;
  font-size: 1.08em;
  line-height: 1.4;
}

.quest-steps li {
  margin-bottom: 0.45em;
}

.inside-teaser {
  margin-top: 0.4em !important;
  text-align: center;
  font-style: italic;
}

.title-page {
  align-items: center;
  justify-content: center;
  text-align: center;
}

.title-art {
  width: 72%;
  filter: drop-shadow(0 10px 18px rgba(90, 40, 0, 0.35));
}

.title-art .art,
.story-art .art {
  width: 100%;
  height: auto;
  display: block;
}

.story-art {
  width: 46%;
  align-self: center;
  border-radius: 14px;
  filter: drop-shadow(0 8px 14px rgba(90, 40, 0, 0.3));
}

.spark-word {
  display: inline;
  padding: 0 0.15em;
  border: 0;
  border-radius: 6px;
  font: inherit;
  font-weight: 700;
  color: #7a3a00;
  background: linear-gradient(180deg, transparent 55%, rgba(255, 200, 60, 0.55) 55%);
  animation: spark-glow 2.2s ease-in-out infinite;
}

.spark-word.is-found {
  animation: none;
  color: #b3122e;
  background: rgba(255, 200, 60, 0.35);
}

@keyframes spark-glow {
  50% {
    text-shadow: 0 0 10px rgba(255, 190, 40, 0.95);
  }
}

.spark-hint {
  font-size: 0.95em !important;
  font-style: italic;
  color: #a0521a;
}

.spark-note {
  padding: 0.6em 0.8em;
  border-radius: 10px;
  background: rgba(255, 220, 140, 0.45);
  border-left: 4px solid var(--gold-deep);
  font-size: 1em;
  line-height: 1.4;
  animation: note-in 0.5s var(--ease-pop);
}

@keyframes note-in {
  from {
    opacity: 0;
    transform: scale(0.9);
  }
}

/* gate */

.gate-page {
  align-items: center;
  text-align: center;
}

.seal-wrap {
  position: relative;
  width: 44%;
  aspect-ratio: 1;
}

.seal-wrap .art {
  width: 100%;
  height: 100%;
  filter: drop-shadow(0 8px 12px rgba(80, 0, 10, 0.4));
}

.seal-ring {
  position: absolute;
  inset: -7%;
  border-radius: 50%;
  background: conic-gradient(var(--gold) calc(var(--seal-progress) * 1%), rgba(160, 82, 26, 0.15) 0);
  -webkit-mask: radial-gradient(circle, transparent 64%, #000 65%);
  mask: radial-gradient(circle, transparent 64%, #000 65%);
}

.seal-wrap.broken {
  display: flex;
}

.seal-half {
  position: absolute;
  inset: 0;
}

.seal-half.left {
  clip-path: polygon(0 0, 52% 0, 44% 50%, 56% 100%, 0 100%);
  animation: crack-left 0.8s var(--ease-out) forwards;
}

.seal-half.right {
  clip-path: polygon(52% 0, 100% 0, 100% 100%, 56% 100%, 44% 50%);
  animation: crack-right 0.8s var(--ease-out) forwards;
}

@keyframes crack-left {
  to {
    transform: translate(-14%, 6%) rotate(-14deg);
  }
}

@keyframes crack-right {
  to {
    transform: translate(14%, 8%) rotate(12deg);
  }
}

.gate-page .btn-gold {
  font-size: 0.95em;
}

.secret-form {
  width: 100%;
  margin-top: 0.3em;
  font-family: var(--font-ui);
  font-size: 0.8em;
}

.secret-form label {
  display: block;
  margin-bottom: 0.4em;
  color: var(--ink-soft);
}

.secret-row {
  display: flex;
  gap: 0.4em;
}

.secret-row input {
  flex: 1;
  min-width: 0;
  padding: 0.6em 0.8em;
  border-radius: 10px;
  border: 2px solid #c9a46a;
  background: #fffaf0;
  font: 600 1em var(--font-ui);
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.secret-msg {
  min-height: 1.3em;
  margin-top: 0.4em !important;
  font-size: 0.95em !important;
  color: #b3122e;
}

/* quiz */

.quiz-page {
  justify-content: center;
}

.guardian {
  position: absolute;
  top: 5%;
  right: 7%;
  font-size: 2.6em;
  animation: owl 3s ease-in-out infinite;
}

.is-sleeping {
  text-align: center;
  align-items: center;
}

.guardian.sleeping {
  position: static;
  font-size: 3.4em;
  filter: grayscale(0.4);
  animation: owl 4s ease-in-out infinite;
}

.zzz {
  display: block;
  font: 700 0.3em var(--font-ui);
  letter-spacing: 0.3em;
  color: #a0521a;
}

@keyframes owl {
  50% {
    transform: rotate(-8deg) translateY(-4px);
  }
}

.choices {
  display: flex;
  flex-direction: column;
  gap: 0.5em;
  margin-top: 0.4em;
}

.choice {
  display: flex;
  align-items: center;
  gap: 0.6em;
  min-height: 44px;
  padding: 0.6em 0.8em;
  border-radius: 12px;
  border: 2px solid #c9a46a;
  background: rgba(255, 250, 240, 0.85);
  color: var(--ink);
  font: 600 0.88em var(--font-ui);
  text-align: left;
  transition: transform 0.2s var(--ease-pop), background 0.2s;
}

.choice:hover:not(:disabled) {
  transform: translateX(6px);
  background: #fff;
}

.choice-letter {
  flex: none;
  width: 1.8em;
  height: 1.8em;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--ink);
  color: var(--parchment);
}

.choice.is-right {
  border-color: #1f9d55;
  background: #d9f7e3;
}

.choice.is-right .choice-letter {
  background: #1f9d55;
}

.choice.is-wrong {
  border-color: #c62828;
  background: #fde0e0;
  opacity: 0.75;
}

.choice.is-wrong .choice-letter {
  background: #c62828;
}

.choice:disabled {
  cursor: default;
}

.quiz-explain {
  font-size: 1em !important;
  animation: note-in 0.5s var(--ease-pop);
}

.quiz-explain b {
  color: #1f7a45;
}

/* reward + end */

.reward-page,
.end-page {
  align-items: center;
  justify-content: center;
  text-align: center;
}

.card-back-btn {
  width: 52%;
  aspect-ratio: 5 / 7;
  padding: 0;
  border: 0;
  border-radius: 16px;
  background: none;
  animation: card-wiggle 2s ease-in-out infinite;
}

.card-back-face {
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  border-radius: 16px;
  border: 4px solid #e6b450;
  background:
    repeating-conic-gradient(from 0deg, rgba(255, 255, 255, 0.06) 0 10deg, transparent 10deg 20deg),
    radial-gradient(circle, #5a2ad8, #1a0a4a);
  box-shadow: 0 0 30px rgba(255, 200, 80, 0.6);
}

.card-back-face img {
  width: 60%;
}

@keyframes card-wiggle {
  0%,
  100% {
    transform: rotate(-3deg);
  }
  50% {
    transform: rotate(3deg) scale(1.04);
  }
}

.mini-card {
  width: 56%;
  font-size: 0.55em;
}

.end-page .for-now {
  font-style: italic;
  font-size: 1.3em !important;
  color: #a0521a;
}

.end-page .btn-gold,
.end-page .btn-ink {
  font-size: 0.85em;
  width: 86%;
}

.blank-page {
  align-items: center;
  justify-content: center;
}
