:root {
  --sky-1: #f7dcc4;
  --sky-2: #f3b785;
  --sky-3: #f6ead5;
  --paper: #fff8ec;
  --paper-deep: #f6ead9;
  --ink: #2d1d16;
  --muted: #765644;
  --accent: #b7482c;
  --accent-deep: #7f2e1d;
  --frame: #d7b899;
  --shadow: rgba(36, 18, 12, 0.2);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Nunito", sans-serif;
  color: var(--ink);
  display: block;
  padding: 1rem;
  background: linear-gradient(150deg, var(--sky-1) 0%, var(--sky-2) 45%, var(--sky-3) 100%);
  overflow-x: hidden;
}

.sky-gradient {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(circle at 20% 15%, rgba(255, 255, 255, 0.5), transparent 30%),
    radial-gradient(circle at 82% 20%, rgba(255, 244, 211, 0.6), transparent 32%),
    radial-gradient(circle at 50% 100%, rgba(255, 255, 255, 0.25), transparent 45%);
}

.confetti {
  position: fixed;
  width: 220px;
  height: 220px;
  pointer-events: none;
  opacity: 0.5;
  border-radius: 40% 60% 55% 45%;
  filter: blur(1px);
}

.confetti-a {
  top: -45px;
  left: -30px;
  background: radial-gradient(circle at 30% 30%, #fff3c8 0%, #ffd898 45%, transparent 70%);
  transform: rotate(-16deg);
}

.confetti-b {
  right: -50px;
  bottom: -70px;
  background: radial-gradient(circle at 65% 40%, #ffd5b7 0%, #ffb57f 45%, transparent 72%);
  transform: rotate(24deg);
}

.book-shell {
  position: relative;
  z-index: 1;
  width: min(1280px, 100%);
  min-height: calc(100vh - 2rem);
  margin: 0 auto;
  background: linear-gradient(180deg, rgba(255, 250, 243, 0.96), rgba(253, 243, 230, 0.96));
  border-radius: 28px;
  border: 2px solid var(--frame);
  box-shadow: 0 28px 60px var(--shadow), inset 0 0 0 1px rgba(255, 255, 255, 0.7);
  padding: clamp(1rem, 2.5vw, 2rem) clamp(1rem, 3vw, 2.5rem);
  display: flex;
  flex-direction: column;
}

.book-spine {
  position: absolute;
  left: 1rem;
  top: 1rem;
  bottom: 1rem;
  width: 18px;
  border-radius: 12px;
  background: linear-gradient(180deg, #d4825e, #b6553a 55%, #8f3b27);
  box-shadow: inset 0 0 0 2px rgba(255, 228, 208, 0.4);
}

.hero {
  text-align: center;
  padding-left: 1.25rem;
}

.eyebrow {
  margin: 0;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  font-weight: 700;
  font-size: 0.75rem;
  color: var(--muted);
}

h1,
.page-title {
  font-family: "Fraunces", serif;
}

h1 {
  margin: 0.35rem 0;
  font-size: clamp(2rem, 5.6vw, 3.2rem);
  line-height: 1.03;
  color: #3b261c;
}

.subtitle {
  margin: 0;
  color: var(--muted);
  font-size: clamp(0.98rem, 2.4vw, 1.16rem);
}

.book-stage {
  margin-top: 1.2rem;
  padding-left: 1.25rem;
  flex: 1;
}

.page-card {
  position: relative;
  background:
    linear-gradient(transparent 0, transparent 31px, rgba(195, 130, 92, 0.09) 32px),
    linear-gradient(90deg, rgba(206, 119, 79, 0.12) 0, rgba(206, 119, 79, 0.12) 2px, transparent 2px),
    var(--paper);
  background-size: 100% 33px, 100% 100%, 100% 100%;
  border-radius: 20px;
  border: 2px solid #e7ccb0;
  box-shadow: 0 10px 24px rgba(84, 47, 33, 0.16);
  min-height: clamp(430px, 58vh, 720px);
  padding: clamp(1rem, 3vw, 1.8rem);
}

.tape {
  position: absolute;
  width: 110px;
  height: 24px;
  background: rgba(255, 244, 198, 0.68);
  border: 1px solid rgba(162, 125, 56, 0.2);
}

.tape-left {
  top: -12px;
  left: 1.2rem;
  transform: rotate(-8deg);
}

.tape-right {
  top: -10px;
  right: 1.4rem;
  transform: rotate(11deg);
}

.page-label {
  margin: 0;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
  font-size: 0.82rem;
}

.page-image-wrap {
  margin: 0.65rem 0 0.9rem;
  text-align: center;
}

.page-image-wrap.is-hidden {
  display: none;
}

.page-canvas {
  display: block;
  width: 90%;
  height: auto;
  max-height: none;
  margin: 0 auto;
  border-radius: 14px;
  border: 2px solid #ead3bc;
  box-shadow: 0 8px 18px rgba(55, 27, 16, 0.14);
  background: #f5e6d3;
}

.page-loading {
  margin: 0.7rem 0 0;
  font-size: 0.92rem;
  color: var(--muted);
}

.is-hidden {
  display: none;
}

.page-title {
  margin: 0.25rem 0 0.6rem;
  font-size: clamp(1.45rem, 3.6vw, 2.1rem);
  line-height: 1.15;
}

.page-body {
  margin: 0;
  white-space: pre-line;
  line-height: 1.72;
  font-size: clamp(1rem, 2.45vw, 1.18rem);
}

.controls {
  margin-top: 1rem;
  padding-left: 1.25rem;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 0.7rem;
}

button {
  border: 0;
  border-radius: 999px;
  padding: 0.62rem 1.08rem;
  font-family: inherit;
  font-weight: 800;
  color: #fff;
  letter-spacing: 0.01em;
  cursor: pointer;
  background: linear-gradient(180deg, #cf5b3c 0%, #ad4228 100%);
  box-shadow: 0 10px 16px rgba(140, 51, 26, 0.28);
  transition: transform 0.14s ease, filter 0.14s ease, opacity 0.14s ease;
}

button:hover {
  transform: translateY(-1px);
  filter: brightness(1.03);
}

button:disabled {
  opacity: 0.35;
  transform: none;
  cursor: not-allowed;
}

.counter-pill {
  min-width: 84px;
  text-align: center;
  font-weight: 800;
  font-size: 0.94rem;
  color: var(--accent-deep);
  background: #ffe8c6;
  border: 1px solid #e6bd95;
  border-radius: 999px;
  padding: 0.45rem 0.7rem;
}

.footer-note {
  padding-left: 1.25rem;
  margin-top: 1rem;
  text-align: center;
  color: var(--muted);
  font-size: 0.95rem;
}

@media (max-width: 640px) {
  .book-shell {
    border-radius: 20px;
    padding: 1rem;
    min-height: auto;
  }

  .book-spine {
    display: none;
  }

  .hero,
  .book-stage,
  .controls,
  .footer-note {
    padding-left: 0;
  }

  .page-card {
    min-height: 280px;
  }

  .tape {
    width: 84px;
    height: 20px;
  }
}
