@font-face { font-family: "Andika"; font-weight: 400; font-display: swap; src: url(fonts/andika-400.woff2) format("woff2"); }
@font-face { font-family: "Andika"; font-weight: 700; font-display: swap; src: url(fonts/andika-700.woff2) format("woff2"); }
@font-face { font-family: "Fredoka"; font-weight: 300 700; font-display: swap; src: url(fonts/fredoka-500.woff2) format("woff2"); }

:root {
  --paper: #fff8ec;
  --paper-2: #fff1dc;
  --ink: #3a2a1e;
  --ink-soft: #7a6352;
  --pink: #ff5da2;
  --purple: #8b5cf6;
  --teal: #14b8a6;
  --sun: #ffc83d;
  --sky: #38bdf8;
  --leaf: #4ade80;
  --orange: #fb923c;
  --wood: #b9784a;
  --wood-dark: #8a5530;
  --highlight: #ffe066;
  --shadow: 0 10px 24px rgba(90, 50, 20, .18);
  --radius: 22px;
  --ui: "Fredoka", "Chalkboard SE", "Comic Sans MS", system-ui, sans-serif;
  --read: "Andika", "Chalkboard SE", system-ui, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--paper);
  background-image:
    radial-gradient(circle at 12% 18%, rgba(255, 93, 162, .10) 0 120px, transparent 121px),
    radial-gradient(circle at 88% 8%, rgba(56, 189, 248, .12) 0 160px, transparent 161px),
    radial-gradient(circle at 80% 92%, rgba(255, 200, 61, .14) 0 180px, transparent 181px);
  background-attachment: fixed;
  color: var(--ink);
  font-family: var(--ui);
  -webkit-user-select: none; user-select: none;
  overscroll-behavior: none;
}
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; }
a { color: inherit; text-decoration: none; }

/* ───────────── Shelf ───────────── */
.shelf-page { min-height: 100%; padding: max(18px, env(safe-area-inset-top)) 16px 40px; }
.shelf-head { text-align: center; margin: 8px auto 6px; }
.shelf-title { font-size: clamp(40px, 7vw, 72px); font-weight: 700; letter-spacing: .5px; margin: 0; line-height: 1.05; }
.shelf-title span { display: inline-block; text-shadow: 0 3px 0 rgba(0,0,0,.08); }
.shelf-title span:nth-child(6n+1) { color: var(--pink); transform: rotate(-4deg); }
.shelf-title span:nth-child(6n+2) { color: var(--orange); transform: rotate(3deg); }
.shelf-title span:nth-child(6n+3) { color: var(--sun); transform: rotate(-2deg); }
.shelf-title span:nth-child(6n+4) { color: var(--leaf); transform: rotate(4deg); }
.shelf-title span:nth-child(6n+5) { color: var(--sky); transform: rotate(-3deg); }
.shelf-title span:nth-child(6n+6) { color: var(--purple); transform: rotate(2deg); }
.shelf-sub { margin: 8px 0 0; font-size: 20px; color: var(--ink-soft); }

.section-label { max-width: 1100px; margin: 34px auto 4px; font-size: 24px; font-weight: 600; color: var(--ink-soft); padding: 0 6px; }

.shelf { max-width: 1100px; margin: 0 auto; }
.shelf-row {
  position: relative;
  display: flex; align-items: flex-end; justify-content: center; gap: clamp(14px, 3vw, 34px);
  padding: 26px 12px 0;
  margin-bottom: 44px;
}
.shelf-row::after {           /* the wooden plank */
  content: ""; position: absolute; left: 0; right: 0; bottom: -22px; height: 26px;
  background: linear-gradient(var(--wood) 0 60%, var(--wood-dark) 60% 100%);
  border-radius: 6px;
  box-shadow: 0 12px 18px rgba(90, 50, 20, .25), inset 0 2px 0 rgba(255,255,255,.25);
}

.book {
  position: relative; width: clamp(130px, 22vw, 190px); flex: 0 0 auto;
  text-align: left; transform-origin: bottom center;
  transition: transform .18s ease;
}
.book:active { transform: scale(.96) rotate(-1deg); }
@media (hover: hover) { .book:hover { transform: translateY(-8px) rotate(-1.5deg); } }
.book-cover {
  position: relative; aspect-ratio: 4 / 5; border-radius: 6px 14px 14px 6px; overflow: hidden;
  background: var(--book-color, var(--pink));
  box-shadow: var(--shadow), inset 0 0 0 3px rgba(255,255,255,.35);
}
.book-cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.book-cover::before {          /* spine */
  content: ""; position: absolute; inset: 0 auto 0 0; width: 14px; z-index: 2;
  background: linear-gradient(90deg, rgba(0,0,0,.28), rgba(0,0,0,.05) 70%, rgba(255,255,255,.25));
}
.book-title {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 2;
  padding: 26px 12px 10px 20px;
  background: linear-gradient(transparent, rgba(30, 15, 5, .78));
  color: #fff; font-weight: 600; font-size: clamp(15px, 2.4vw, 19px); line-height: 1.15;
  text-shadow: 0 1px 2px rgba(0,0,0,.5);
}
.no-cover .book-title { top: 0; display: flex; align-items: center; justify-content: center; text-align: center; background: none; font-size: 22px; }
.badge {
  position: absolute; top: 8px; right: 8px; z-index: 3;
  background: #fff; border-radius: 999px; padding: 4px 9px; font-size: 15px; font-weight: 600;
  box-shadow: 0 2px 6px rgba(0,0,0,.18);
}
.ribbon {
  position: absolute; top: 14px; left: -6px; z-index: 3;
  background: var(--sun); color: var(--ink); font-weight: 700; font-size: 14px;
  padding: 5px 12px 5px 14px; border-radius: 0 999px 999px 0; box-shadow: 0 3px 6px rgba(0,0,0,.2);
}
.empty { text-align: center; font-size: 22px; color: var(--ink-soft); margin: 60px auto; max-width: 520px; line-height: 1.5; }

/* ───────────── Reader ───────────── */
.reader { position: fixed; inset: 0; background: var(--paper); overflow: hidden; }
.topbar {                      /* floating corner buttons, no bar */
  position: absolute; top: 0; left: 0; right: 0; z-index: 10;
  display: flex; align-items: center; gap: 10px;
  padding: max(10px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) 0 max(12px, env(safe-area-inset-left));
  pointer-events: none;
}
.topbar > * { pointer-events: auto; }
.round-btn {
  width: 56px; height: 56px; border-radius: 50%; flex: 0 0 auto;
  display: grid; place-items: center; font-size: 26px;
  background: rgba(255,255,255,.92); box-shadow: 0 4px 12px rgba(90, 50, 20, .18);
  transition: transform .12s;
}
.round-btn:active { transform: scale(.92); }
.round-btn[disabled] { opacity: .3; pointer-events: none; }
.round-btn.big { width: 80px; height: 80px; font-size: 38px; background: var(--pink); color: #fff; }
.round-btn.big.paused { background: var(--teal); }
.top-title { flex: 1; }

.stage {
  position: absolute; inset: 0;
  padding: calc(max(10px, env(safe-area-inset-top)) + 62px) max(10px, env(safe-area-inset-right)) max(22px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
  display: flex; align-items: center; justify-content: center;
}
.page {
  width: 100%; height: 100%;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
  animation: pageIn .45s cubic-bezier(.2, .8, .2, 1);
}
.page.back { animation-name: pageInBack; }
@keyframes pageIn { from { opacity: 0; transform: translateX(60px) rotateY(-12deg); } to { opacity: 1; transform: none; } }
@keyframes pageInBack { from { opacity: 0; transform: translateX(-60px) rotateY(12deg); } to { opacity: 1; transform: none; } }
.page-img {
  display: block; min-height: 0; min-width: 0; flex: 0 1 auto;
  max-width: 100%; max-height: 66vh; object-fit: contain;
  border-radius: var(--radius); background: #fff; box-shadow: var(--shadow); border: 5px solid #fff;
}
.page-side { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; flex: 0 0 auto; }
.page-text {
  font-family: var(--read); font-size: clamp(26px, 4vw, 44px); line-height: 1.4;
  text-align: center; max-width: 32ch; margin: 0; padding: 0 6px;
}
.word { display: inline-block; padding: 0 .08em; border-radius: 10px; transition: background-color .12s, transform .12s; cursor: pointer; }
.word.active { background: var(--highlight); transform: translateY(-2px) scale(1.06); box-shadow: 0 2px 0 rgba(0,0,0,.06); }

.page.long .page-img { max-height: 40vh; }
.page-side { max-height: 100%; min-height: 0; }
@media (orientation: portrait) {
  .page-img { flex-shrink: 0; }
  .page-side { flex: 1 1 auto; overflow-y: auto; justify-content: flex-start; }
  .page:not(.long) .page-side { justify-content: center; flex-grow: 0; }
  .page.long .page-img { max-height: 34vh; }
}
@media (orientation: landscape) {
  .page { flex-direction: row; gap: 28px; }
  .page-img { max-height: 100%; max-width: 66%; }
  .page-side { flex: 1 1 0; min-width: 0; }
  .page-text { font-size: clamp(24px, 3.3vw, 46px); max-width: 15ch; }
  .page.long .page-img { max-height: 100%; max-width: 50%; }
  .page.long .page-text { max-width: 30ch; text-align: left; }
}
@media (orientation: landscape) and (max-height: 500px) {   /* phone sideways */
  .page-text { font-size: 22px; }
  .round-btn.big { width: 60px; height: 60px; font-size: 28px; }
}

.controls { display: flex; align-items: center; justify-content: center; gap: 18px; }
.dots { position: absolute; left: 0; right: 0; bottom: max(6px, env(safe-area-inset-bottom)); display: flex; gap: 6px; justify-content: center; pointer-events: none; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: rgba(0,0,0,.14); }
.dot.on { background: var(--pink); transform: scale(1.3); }

/* Cover + end screens */
.cover-screen, .end-screen {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 16px; padding: 10px 20px 24px; text-align: center; animation: pageIn .5s ease;
  max-height: 100%; overflow-y: auto;
}
.cover-img { max-height: min(44vh, 460px); max-width: 90%; border-radius: var(--radius); box-shadow: var(--shadow); border: 8px solid #fff; transform: rotate(-1.5deg); }
.cover-title { font-size: clamp(34px, 6vw, 60px); font-weight: 700; color: var(--purple); margin: 0; line-height: 1.1; }
.cover-by { font-size: clamp(20px, 3vw, 28px); color: var(--ink-soft); margin: 0; }
.choice-row { display: flex; gap: 18px; flex-wrap: wrap; justify-content: center; margin-top: 6px; }
.choice {
  min-width: 230px; padding: 20px 28px; border-radius: 999px; font-size: 26px; font-weight: 600;
  background: #fff; box-shadow: var(--shadow); transition: transform .12s;
}
.choice:active { transform: scale(.95); }
.choice.primary { background: var(--pink); color: #fff; }
.end-title { font-size: clamp(56px, 10vw, 110px); font-weight: 700; margin: 0; color: var(--pink); animation: bounce 1.2s ease infinite; }
@keyframes bounce { 0%, 100% { transform: translateY(0) rotate(-2deg); } 50% { transform: translateY(-12px) rotate(2deg); } }
.confetti { position: fixed; inset: 0; pointer-events: none; overflow: hidden; }
.confetti span { position: absolute; top: -60px; font-size: 34px; animation: fall linear forwards; }
@keyframes fall { to { transform: translateY(115vh) rotate(540deg); } }

.toast { z-index: 100; pointer-events: none; position: fixed; left: 50%; bottom: 120px; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 12px 20px; border-radius: 999px; font-size: 18px; opacity: 0; transition: opacity .3s; }
.toast.show { opacity: .92; }

/* Pages with no separate words (how-to books): picture centered, buttons underneath */
.page.no-text { flex-direction: column !important; gap: 10px; }
.page.no-text .page-img { max-height: calc(100% - 96px) !important; max-width: 100% !important; flex-shrink: 1; }
.page.no-text .page-side { flex: 0 0 auto; }

/* ───────────── Voice settings sheet ───────────── */
.voice-btn { margin-top: 2px; padding: 12px 22px; border-radius: 999px; font-size: 20px; font-weight: 600;
  background: #fff; box-shadow: 0 4px 12px rgba(90,50,20,.15); color: var(--purple); }
.voice-btn:active { transform: scale(.95); }
.sheet-back { position: fixed; inset: 0; z-index: 50; background: rgba(60, 35, 20, .35); display: flex; align-items: flex-end; justify-content: center; animation: fadeIn .2s ease; }
@keyframes fadeIn { from { opacity: 0; } }
.sheet {
  width: min(760px, 100%); max-height: 92vh; overflow-y: auto; background: var(--paper);
  border-radius: 28px 28px 0 0; padding: 22px 18px max(22px, env(safe-area-inset-bottom));
  box-shadow: 0 -10px 30px rgba(0,0,0,.2); animation: slideUp .3s cubic-bezier(.2,.8,.2,1);
}
@keyframes slideUp { from { transform: translateY(40px); opacity: 0; } }
.sheet h2 { margin: 0 0 4px; font-size: 30px; color: var(--purple); text-align: center; }
.sheet h3 { margin: 22px 4px 10px; font-size: 22px; color: var(--ink-soft); }
.sheet .hint { text-align: center; color: var(--ink-soft); margin: 0 0 6px; font-size: 18px; }
.voice-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }
.voice-card {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: 20px; background: #fff;
  box-shadow: 0 3px 10px rgba(90,50,20,.12); border: 4px solid transparent; text-align: left;
}
.voice-card.on { border-color: var(--pink); background: #fff0f6; }
.voice-card .who { flex: 1; min-width: 0; }
.voice-card .name { font-size: 22px; font-weight: 700; }
.voice-card .about { font-size: 15px; color: var(--ink-soft); }
.play-sample { width: 52px; height: 52px; border-radius: 50%; background: var(--teal); color: #fff; font-size: 22px; display: grid; place-items: center; flex: 0 0 auto; }
.play-sample.busy { background: var(--sun); animation: pulse 1s ease infinite; }
@keyframes pulse { 50% { transform: scale(.9); } }
.chips { display: flex; flex-wrap: wrap; gap: 10px; }
.chip { padding: 12px 18px; border-radius: 999px; background: #fff; font-size: 19px; font-weight: 600; box-shadow: 0 3px 8px rgba(90,50,20,.1); border: 3px solid transparent; }
.chip.on { border-color: var(--pink); background: #fff0f6; }
.sheet-actions { display: flex; gap: 12px; justify-content: center; margin-top: 24px; }
.progress { height: 18px; border-radius: 999px; background: #fff; overflow: hidden; box-shadow: inset 0 1px 3px rgba(0,0,0,.15); margin: 18px 6px 4px; }
.progress > div { height: 100%; width: 0; background: linear-gradient(90deg, var(--pink), var(--purple)); transition: width .4s; }
.voice-status { min-height: 26px; text-align: center; font-size: 19px; font-weight: 600; color: var(--purple); margin: 4px 0 10px; }
.voice-status.bad { color: #c2410c; }
.voice-card { cursor: pointer; }
.voice-card.playing { border-color: var(--teal); }

/* ───────────── Online: sign-in + share landing ───────────── */
.signin { position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; padding: 16px; background: var(--paper); }
.signin-card { width: min(520px, 100%); background: #fff; border-radius: 28px; padding: 28px 22px; box-shadow: var(--shadow); text-align: center; }
.signin-title { margin: 0 0 10px; font-size: clamp(30px, 6vw, 42px); color: var(--purple); }
.signin-hint { font-size: 20px; color: var(--ink-soft); margin: 6px 0 16px; }
.signin form { display: flex; flex-direction: column; gap: 14px; align-items: center; }
.signin input { width: 100%; font: inherit; font-size: 24px; text-align: center; padding: 14px 16px; border-radius: 18px; border: 3px solid #f1dfcb; background: var(--paper); color: var(--ink); }
.signin input:focus { outline: none; border-color: var(--pink); }
.signin .choice { min-width: 0; width: 100%; }
.signin-msg { min-height: 1.4em; margin: 14px 0 0; font-size: 18px; color: var(--ink-soft); }
.link-btn { background: none; color: var(--ink-soft); font-size: 17px; text-decoration: underline; }
.share-landing { min-height: 100vh; justify-content: center; }
