:root {
  --bg: #fdf6ec;
  --card: #ffffff;
  --ink: #3b2f2a;
  --soft: #8a7a70;
  --accent: #f08a4b;
  --accent-ink: #ffffff;
  --glow: #ffe3a3;
  --line: #efe2d2;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1d1a2b; --card: #2a2640; --ink: #f6efe6; --soft: #b7aec8;
    --accent: #f59a5f; --glow: #5b4a1f; --line: #3a3555; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #1d1a2b; --card: #2a2640; --ink: #f6efe6; --soft: #b7aec8;
  --accent: #f59a5f; --glow: #5b4a1f; --line: #3a3555; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--ink);
  font-family: "Chalkboard SE", "Comic Neue", "Baloo 2", ui-rounded, "Segoe UI", system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; cursor: pointer; }
[hidden] { display: none !important; }

/* Shelf */
.shelf { max-width: 960px; margin: 0 auto; padding: 24px 16px 48px; }
.shelf-head { text-align: center; margin: 8px 0 24px; }
.shelf-head h1 { font-size: clamp(28px, 6vw, 44px); margin: 0 0 6px; }
.shelf-head p { margin: 0; color: var(--soft); font-size: 18px; }
.books { list-style: none; padding: 0; margin: 0; display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
.book {
  width: 100%; border: 0; padding: 0; text-align: left; background: var(--card);
  border-radius: 20px; overflow: hidden; box-shadow: 0 6px 18px rgb(0 0 0 / .08);
  transition: transform .15s ease;
}
.book:active { transform: scale(.97); }
.book .cover { aspect-ratio: 3 / 4; width: 100%; display: block; object-fit: cover; background: var(--glow); }
.book .cover.blank { display: grid; place-items: center; font-size: 72px; }
.book .t { display: block; padding: 12px 14px 16px; font-size: 18px; font-weight: 700; line-height: 1.25; }
.page-link { display: block; text-align: center; padding: 10px 0 2px; color: var(--soft); font-size: 15px; }

/* Reader */
.reader { max-width: 760px; margin: 0 auto; padding: 12px 16px calc(24px + env(safe-area-inset-bottom)); min-height: 100dvh; display: flex; flex-direction: column; gap: 14px; }
.bar { display: flex; align-items: center; justify-content: space-between; }
.chip { border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: 10px 16px; font-size: 16px; }
.count { color: var(--soft); font-size: 16px; }
.pic { margin: 0; border-radius: 24px; overflow: hidden; background: var(--glow); aspect-ratio: 3 / 4; max-height: 52dvh; align-self: center; width: auto; height: 52dvh; max-width: 100%; display: grid; place-items: center; }
.pic img { width: 100%; height: 100%; object-fit: cover; display: block; }
.pic .emoji { font-size: 96px; }
.pic.turn { animation: turn .45s ease; }
@keyframes turn { from { opacity: .2; transform: translateX(16px); } to { opacity: 1; transform: none; } }
.words { font-size: clamp(22px, 4.6vw, 30px); line-height: 1.5; text-align: center; white-space: pre-line; min-height: 6em; padding: 0 4px; }
.words .s { border-radius: 8px; transition: background-color .2s ease; padding: 0 2px; }
.words .s.now { background: var(--glow); }
.words .end { display: block; margin-top: 12px; font-style: italic; color: var(--soft); }
.controls { display: flex; align-items: center; justify-content: center; gap: 16px; margin-top: auto; }
.nav { width: 64px; height: 64px; border-radius: 50%; border: 1px solid var(--line); background: var(--card); font-size: 40px; line-height: 1; }
.nav:disabled { opacity: .35; cursor: default; }
.read {
  display: inline-flex; align-items: center; gap: 12px; border: 0; border-radius: 999px;
  background: var(--accent); color: var(--accent-ink); padding: 18px 30px; font-size: 24px; font-weight: 700;
  box-shadow: 0 8px 20px rgb(240 138 75 / .35); min-width: 220px; justify-content: center;
}
.read:active { transform: scale(.97); }
.read .ico { font-size: 22px; }
.voice { align-self: center; color: var(--soft); font-size: 14px; display: flex; gap: 8px; align-items: center; }
.voice select { max-width: 220px; font-size: 14px; padding: 4px; border-radius: 8px; border: 1px solid var(--line); background: var(--card); color: var(--ink); }

@media (max-width: 420px) {
  .read { min-width: 0; padding: 16px 22px; font-size: 21px; }
  .nav { width: 54px; height: 54px; font-size: 34px; }
}
