/* Free Kids Books Online
 * Hand-rolled styles for the shelf homepage + book-detail dialog.
 * Replaces Bootstrap. Mobile-first, iPad-friendly, PWA-ready.
 */

/* ---------- Tokens ---------- */
:root {
  --wood-dark: #6b3f22;
  --wood-mid: #8a5a32;
  --wood-light: #b58250;
  --wood-shelf: #c48a56;
  --wood-shelf-top: #d49966;
  --wood-shelf-edge: #5a3218;
  --wall: #e8d4b4;
  --ink: #3a2a18;

  --brand-red: #E54B3C;
  --brand-orange: #F39C2C;
  --brand-yellow: #F2C94C;
  --brand-green: #6BBE45;
  --brand-green-d: #1e6a2c;
  --brand-blue: #2E7AD1;
  --brand-brown: #8A5A32;

  --book-w: 138px;
  --radius-card: 22px;
  --radius-pill: 999px;

  --safe-top: env(safe-area-inset-top, 0);
  --safe-bot: env(safe-area-inset-bottom, 0);
}

/* ---------- Reset ---------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; overscroll-behavior-y: none; }
body {
  font-family: 'Baloo 2', 'Fredoka', system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: #e8d4b4;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; border: none; background: none; cursor: pointer; color: inherit; padding: 0; }
input, textarea { font: inherit; }
a { color: inherit; text-decoration: none; }
img, svg { display: block; max-width: 100%; }

/* Keep user-select on the detail dialog (for blurbs) but off on shelf chrome. */
.app { user-select: none; }
.detail-card, .detail-card * { user-select: text; }

/* ---------- App frame ---------- */
.app {
  min-height: 100vh;
  min-height: 100dvh;
  background:
    radial-gradient(ellipse at top, rgba(255,255,255,0.3), transparent 60%),
    linear-gradient(180deg, #f2dfbf 0%, #d8b888 100%);
  position: relative;
  overflow-x: hidden;
}

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 16px;
  padding: calc(14px + var(--safe-top)) 22px 14px;
  background: linear-gradient(180deg, #4a2f18 0%, #3a240f 100%);
  border-bottom: 3px solid #2a1808;
  box-shadow: 0 4px 20px rgba(0,0,0,0.25);
}
.topbar-brand {
  display: inline-flex; align-items: center; gap: 12px;
  color: #fff;
  font-weight: 800;
  font-size: 22px;
  letter-spacing: 0.01em;
  text-shadow: 0 2px 0 rgba(0,0,0,0.35);
}
.topbar-brand-icon {
  width: 44px; height: 44px;
  border-radius: 10px;
  background: linear-gradient(180deg, #F2C94C, #E8A93A);
  box-shadow: inset 0 2px 0 rgba(255,255,255,0.4), 0 3px 0 rgba(0,0,0,0.3);
  display: grid; place-items: center;
  color: #5a3218;
}
.topbar-spacer { flex: 1; }

.topbar-btn {
  background: linear-gradient(180deg, #d48856 0%, #a86230 100%);
  color: #fff;
  padding: 12px 18px;
  border-radius: 16px;
  font-weight: 700;
  font-size: 16px;
  display: inline-flex; align-items: center; gap: 8px;
  border: 2px solid #5a3218;
  box-shadow: 0 4px 0 #5a3218, inset 0 2px 0 rgba(255,255,255,0.25);
  transition: transform 0.08s, box-shadow 0.08s;
}
.topbar-btn:active { transform: translateY(3px); box-shadow: 0 1px 0 #5a3218, inset 0 2px 0 rgba(255,255,255,0.25); }
.topbar-btn.blue {
  background: linear-gradient(180deg, #4a9ee0 0%, #2a6ab0 100%);
  border-color: #1a447a;
  box-shadow: 0 4px 0 #1a447a, inset 0 2px 0 rgba(255,255,255,0.25);
}
.topbar-btn.blue:active { box-shadow: 0 1px 0 #1a447a, inset 0 2px 0 rgba(255,255,255,0.25); }

/* ---------- Shelf scroll area ---------- */
.shelf-scroll {
  position: relative;
  min-height: calc(100vh - 100px);
  background:
    linear-gradient(180deg, #e8d4b4 0%, #e0c89e 140px, transparent 180px),
    repeating-linear-gradient(
      90deg,
      #b07a44 0,
      #a86f38 4px,
      #b07a44 8px,
      #b87e48 14px,
      #a86f38 22px,
      #b07a44 30px
    ),
    linear-gradient(180deg, #b07a44, #8a5a32);
}
.shelf-top-bg {
  position: absolute; top: 0; left: 0; right: 0; height: 140px;
  background:
    radial-gradient(ellipse at 50% -20%, rgba(255,255,255,0.6), transparent 60%),
    linear-gradient(180deg, #f2dfbf 0%, #e0c89e 100%);
  pointer-events: none;
}

/* Search */
.shelf-search-row {
  position: relative; z-index: 2;
  padding: 22px 20px 0;
  display: flex; justify-content: center;
}
.shelf-search {
  width: 100%; max-width: 640px;
  background: #fff;
  border-radius: 22px;
  padding: 12px 18px;
  display: flex; align-items: center; gap: 12px;
  box-shadow: 0 6px 0 rgba(0,0,0,0.18), inset 0 2px 0 rgba(255,255,255,0.6);
  border: 3px solid #fff;
}
.shelf-search svg { flex-shrink: 0; color: #7A5A3A; }
.shelf-search input {
  flex: 1; border: none; outline: none; background: transparent;
  font-size: 20px; font-weight: 600; color: #5a3a18; min-width: 0;
}
.shelf-search input::placeholder { color: #b59070; }

/* Category chips */
.shelf-cats {
  position: relative; z-index: 2;
  display: flex; gap: 10px;
  padding: 18px 20px 18px;
  overflow-x: auto;
  scrollbar-width: none;
}
.shelf-cats::-webkit-scrollbar { display: none; }
.cat-chip {
  flex-shrink: 0;
  background: #fff;
  border: 3px solid #fff;
  color: #5a3a18;
  font-weight: 700;
  font-size: 16px;
  padding: 10px 18px;
  border-radius: var(--radius-pill);
  box-shadow: 0 4px 0 rgba(0,0,0,0.18);
  transition: transform 0.08s;
  white-space: nowrap;
  font-family: inherit;
}
.cat-chip:active { transform: translateY(2px); }
.cat-chip.active {
  color: #fff;
  border-color: rgba(0,0,0,0.15);
  box-shadow: 0 4px 0 rgba(0,0,0,0.3);
}

/* ---------- Shelves ---------- */
.shelves { position: relative; z-index: 1; padding: 10px 0 0; }
.shelf-row { position: relative; margin-bottom: 0; }
.shelf-books {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 18px;
  padding: 20px 30px 10px;
  min-height: 220px;
  align-items: end;
}
.book-slot {
  position: relative;
  display: flex; flex-direction: column; align-items: center;
  transition: transform 0.12s cubic-bezier(.34,1.56,.64,1);
  font-family: inherit;
}
.book-slot:hover { transform: translateY(-6px); }
.book-slot:active { transform: translateY(-2px) scale(0.97); }
.book-slot:focus-visible { outline: 3px solid var(--brand-yellow); outline-offset: 4px; border-radius: 6px; }

.book-shadow {
  position: absolute; bottom: -6px; left: 12%; right: 12%;
  height: 10px; border-radius: 50%;
  background: radial-gradient(ellipse, rgba(0,0,0,0.35), transparent 70%);
  filter: blur(2px);
  z-index: -1;
  pointer-events: none;
}

.shelf-plank {
  position: relative; height: 26px;
  background: linear-gradient(180deg, var(--wood-shelf-top) 0%, var(--wood-shelf) 40%, #9a6838 100%);
  box-shadow: 0 2px 0 #5a3218, inset 0 2px 0 rgba(255,255,255,0.25);
}
.shelf-plank::before {
  content: ''; position: absolute; left: 0; right: 0; top: -6px; height: 6px;
  background: linear-gradient(180deg, rgba(0,0,0,0.2), transparent);
}
.shelf-plank::after {
  content: ''; position: absolute; left: 0; right: 0; top: 0; height: 3px;
  background: rgba(255,255,255,0.4);
}
.shelf-front {
  position: absolute; left: 0; right: 0; bottom: -10px; height: 10px;
  background: linear-gradient(180deg, #5a3218, #3a1f0a);
  box-shadow: 0 3px 8px rgba(0,0,0,0.4);
}

.shelf-bottom-pad { height: 60px; }
.shelf-empty {
  text-align: center;
  padding: 80px 20px;
  color: #f4e4c8;
  font-size: 20px;
  font-weight: 700;
  text-shadow: 0 2px 0 rgba(0,0,0,0.3);
}

/* ---------- Book cover
 * Works for BOTH real cover images AND the SVG "ABC's of" fallback.
 * The binding (spine) + page-edge details are applied as ::before/::after on .bc
 * so they overlay any child content (image OR synthetic cover).
 */
.bc {
  position: relative;
  width: var(--book-w);
  aspect-ratio: 3 / 4;
  border-radius: 4px 8px 8px 4px;
  overflow: hidden;
  box-shadow:
    0 10px 14px rgba(0,0,0,0.35),
    inset 2px 0 0 rgba(255,255,255,0.15),
    inset -2px 0 0 rgba(0,0,0,0.15);
  background: #e8d4b4;
  color: #3a2a18;
  display: flex; flex-direction: column;
  line-height: 1;
}
/* Spine highlight — left-hand binding shadow */
.bc::before {
  content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 6px;
  background: linear-gradient(90deg, rgba(0,0,0,0.35), rgba(0,0,0,0) 100%);
  z-index: 3;
  pointer-events: none;
}
/* Page edge — stacked paper sheets on the right */
.bc::after {
  content: ''; position: absolute; right: 0; top: 2px; bottom: 2px; width: 3px;
  background: repeating-linear-gradient(
    180deg,
    rgba(255,255,255,0.9) 0 1px,
    rgba(0,0,0,0.12) 1px 2px
  );
  z-index: 3;
  pointer-events: none;
}

/* Cover image variant — fills the whole card */
.bc.bc-image { padding: 0; }
.bc-image img {
  width: 100%; height: 100%;
  object-fit: cover;
  display: block;
}

/* Synthetic / SVG-motif variant */
.bc.bc-synth { padding: 10px 8px 8px 12px; }
.bc-title {
  font-size: 11px; font-weight: 500; text-align: center;
  opacity: 0.9; letter-spacing: 0.02em;
}
.bc-main {
  font-size: 17px; font-weight: 800; line-height: 1;
  text-align: center; margin-top: 2px;
  text-shadow: 0 1px 0 rgba(0,0,0,0.2);
  font-family: 'Baloo 2', 'Fredoka', inherit;
  word-wrap: break-word;
}
.bc-art {
  flex: 1; display: flex; align-items: center; justify-content: center;
  margin: 4px 0;
}
.bc-art svg { width: 90%; height: 90%; }
.bc-foot { text-align: center; font-size: 8px; line-height: 1.3; opacity: 0.9; }
.bc-author { font-weight: 700; font-size: 9px; }
.bc-illus span { opacity: 0.7; }

.book-slot .book-title {
  margin-top: 10px;
  font-size: 12px;
  font-weight: 700;
  color: #3a1f0a;
  text-align: center;
  max-width: var(--book-w);
  line-height: 1.2;
  text-shadow: 0 1px 0 rgba(255,255,255,0.4);
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

/* ---------- Detail overlay (dialog) ---------- */
.detail-overlay {
  position: fixed; inset: 0; z-index: 40;
  background: rgba(30, 18, 8, 0.65);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  animation: fadeIn 0.18s ease;
  overflow-y: auto;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes popIn { from { opacity: 0; transform: scale(0.92) translateY(20px); } to { opacity: 1; transform: scale(1) translateY(0); } }

.detail-card {
  background: linear-gradient(180deg, #fff8e8 0%, #f4e4c8 100%);
  border-radius: 32px;
  width: 100%; max-width: 1100px;
  padding: 40px;
  display: grid; grid-template-columns: 320px 1fr;
  gap: 48px;
  position: relative;
  box-shadow: 0 30px 60px rgba(0,0,0,0.4), inset 0 2px 0 rgba(255,255,255,0.6);
  border: 6px solid #fff;
  animation: popIn 0.24s cubic-bezier(.34,1.56,.64,1);
  max-height: calc(100vh - 40px);
  overflow-y: auto;
}
.detail-close {
  position: absolute; top: 18px; right: 18px;
  width: 52px; height: 52px;
  border-radius: 50%;
  background: #fff;
  color: #8a5a32;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 0 #8a5a32, inset 0 2px 0 rgba(255,255,255,0.5);
  border: 3px solid #8a5a32;
  z-index: 2;
}
.detail-close:active { transform: translateY(2px); box-shadow: 0 2px 0 #8a5a32, inset 0 2px 0 rgba(255,255,255,0.5); }

.detail-left { display: flex; align-items: center; justify-content: center; }
.detail-cover-wrap { position: relative; transform: rotate(-2deg); }
.detail-cover-wrap .bc {
  width: 280px;
  box-shadow: 0 25px 40px rgba(0,0,0,0.35);
}
.detail-cover-shadow {
  position: absolute; bottom: -20px; left: 10%; right: 10%; height: 30px;
  background: radial-gradient(ellipse, rgba(0,0,0,0.3), transparent 70%);
  filter: blur(6px);
}

.detail-right { display: flex; flex-direction: column; justify-content: center; min-width: 0; }
.detail-kicker {
  font-weight: 700; text-transform: uppercase;
  color: var(--brand-orange); letter-spacing: 0.1em;
  font-size: 14px; margin-bottom: 8px;
}
.detail-title {
  font-size: 44px; font-weight: 800; line-height: 1.05;
  margin: 0 0 10px; color: #3a2a18;
  font-family: 'Baloo 2', 'Fredoka', inherit;
}
.detail-by { font-size: 17px; color: #7a5a3a; margin-bottom: 18px; }
.detail-link { color: var(--brand-blue); font-weight: 700; }
.detail-blurb { font-size: 18px; line-height: 1.45; color: #4a3a2a; margin: 0 0 24px; max-width: 54ch; }

.detail-meta-grid {
  display: grid; grid-template-columns: repeat(4, 1fr);
  gap: 10px; margin-bottom: 24px;
}
.meta {
  background: #fff;
  border-radius: 16px;
  padding: 12px 14px;
  border: 2px solid #f0d8a8;
}
.meta-k { font-size: 12px; color: #a87a4a; text-transform: uppercase; font-weight: 600; letter-spacing: 0.05em; }
.meta-v { font-size: 20px; font-weight: 800; color: #3a2a18; margin-top: 2px; line-height: 1.1; }

.detail-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 20px; }
.tag-chip {
  background: #fff;
  border: 2px solid #e8c898;
  color: #8a5a32;
  font-weight: 700;
  font-size: 13px;
  padding: 5px 12px;
  border-radius: var(--radius-pill);
}
.tag-chip.cat { background: var(--brand-orange); color: #fff; border-color: transparent; }

.btn-read {
  background: linear-gradient(180deg, #4aae5c 0%, #2a8a3c 100%);
  color: #fff;
  font-size: 22px; font-weight: 800;
  padding: 18px 28px;
  border-radius: 20px;
  display: inline-flex; align-items: center; justify-content: center; gap: 12px;
  border: 3px solid var(--brand-green-d);
  box-shadow: 0 6px 0 var(--brand-green-d), inset 0 2px 0 rgba(255,255,255,0.3);
  margin-bottom: 10px;
  transition: transform 0.08s, box-shadow 0.08s;
  font-family: inherit;
  text-align: center;
  cursor: pointer;
}
.btn-read:active { transform: translateY(4px); box-shadow: 0 2px 0 var(--brand-green-d), inset 0 2px 0 rgba(255,255,255,0.3); }
.btn-secondary {
  background: #fff; color: #8a5a32;
  font-size: 16px; font-weight: 700;
  padding: 12px 20px;
  border-radius: 16px;
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  border: 3px solid #e8c898;
  box-shadow: 0 4px 0 #e8c898;
  align-self: flex-start;
  font-family: inherit;
  cursor: pointer;
}

/* ---------- Detail page (stand-alone version of the card at /book.php) ---------- */
.detail-page-wrap {
  min-height: 100vh;
  padding: 40px 20px;
  display: flex; align-items: flex-start; justify-content: center;
  background:
    linear-gradient(180deg, #e8d4b4 0%, #d8b888 100%);
}
.detail-page-wrap .detail-card { animation: none; max-height: none; }

/* ---------- Author intro ---------- */
.author-intro {
  position: relative; z-index: 2;
  display: grid;
  grid-template-columns: 160px 1fr;
  gap: 28px;
  align-items: center;
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px 20px 8px;
}
.author-avatar {
  width: 160px; height: 160px;
  border-radius: 50%;
  background: #fff;
  display: grid; place-items: center;
  overflow: hidden;
  box-shadow: 0 8px 0 rgba(0,0,0,0.18), inset 0 2px 0 rgba(255,255,255,0.7);
  border: 4px solid #fff;
}
.author-avatar img { width: 100%; height: 100%; object-fit: cover; }
.author-avatar-initial {
  font-size: 72px; font-weight: 800;
  color: var(--brand-brown);
  font-family: 'Baloo 2', inherit;
}
.author-body .detail-title { font-size: 36px; margin: 0 0 8px; }
.author-body .detail-blurb { font-size: 17px; margin-bottom: 12px; max-width: 60ch; }

@media (max-width: 640px) {
  .author-intro { grid-template-columns: 1fr; text-align: center; padding-top: 20px; }
  .author-avatar { margin: 0 auto; width: 120px; height: 120px; }
  .author-avatar-initial { font-size: 56px; }
  .author-body .detail-blurb { margin-left: auto; margin-right: auto; }
  .author-body .detail-tags { justify-content: center; }
}

/* ---------- Footer ---------- */
.site-footer {
  padding: 24px 20px calc(24px + var(--safe-bot));
  text-align: center;
  color: #5a3a18;
  font-size: 14px;
  background: rgba(255,255,255,0.4);
  border-top: 1px solid rgba(0,0,0,0.05);
}
.site-footer a { color: var(--brand-blue); font-weight: 700; }

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
  .shelf-books { grid-template-columns: repeat(5, 1fr); }
}
@media (max-width: 900px) {
  .shelf-books { grid-template-columns: repeat(4, 1fr); gap: 14px; padding: 16px 18px 6px; }
  :root { --book-w: 120px; }
  .detail-card { grid-template-columns: 1fr; padding: 28px; gap: 24px; }
  .detail-cover-wrap .bc { width: 200px; }
  .detail-title { font-size: 30px; }
  .detail-meta-grid { grid-template-columns: repeat(2, 1fr); }
  .detail-blurb { font-size: 16px; }
  .topbar { padding-left: 16px; padding-right: 16px; gap: 10px; }
  .topbar-brand { font-size: 18px; }
  .topbar-brand-icon { width: 38px; height: 38px; }
  .topbar-btn { padding: 10px 14px; font-size: 14px; }
}
@media (max-width: 640px) {
  .shelf-books { grid-template-columns: repeat(3, 1fr); gap: 12px; padding: 14px 14px 6px; }
  :root { --book-w: 100px; }
  .topbar-btn .topbar-btn-label { display: none; }
  .topbar-btn { padding: 10px 12px; }
  .detail-card { padding: 22px; border-radius: 24px; }
  .detail-close { width: 44px; height: 44px; top: 12px; right: 12px; }
}
@media (max-width: 420px) {
  .shelf-books { grid-template-columns: repeat(2, 1fr); }
  :root { --book-w: 120px; }
}

/* ---------- Signed-in user chip (topbar) ---------- */
.user-chip {
  display: inline-flex; align-items: center; gap: 10px;
  background: linear-gradient(180deg, #4a9ee0 0%, #2a6ab0 100%);
  color: #fff;
  padding: 8px 16px 8px 8px;
  border-radius: 999px;
  font-weight: 700; font-size: 16px;
  border: 2px solid #1a447a;
  box-shadow: 0 4px 0 #1a447a, inset 0 2px 0 rgba(255,255,255,0.25);
  text-decoration: none;
}
.user-chip:active { transform: translateY(2px); box-shadow: 0 2px 0 #1a447a, inset 0 2px 0 rgba(255,255,255,0.25); }
.user-avatar {
  width: 36px; height: 36px; border-radius: 50%;
  background: linear-gradient(135deg, #F2C94C, #E54B3C);
  color: #fff; font-weight: 800; font-size: 15px;
  display: flex; align-items: center; justify-content: center;
  border: 2px solid #fff;
}

/* ---------- Login modal ---------- */
.login-overlay {
  position: fixed; inset: 0; z-index: 45;
  background: rgba(30, 18, 8, 0.7);
  backdrop-filter: blur(8px);
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
  animation: fadeIn 0.2s ease;
}
.login-card {
  background: linear-gradient(180deg, #fff8e8 0%, #f4e4c8 100%);
  border-radius: 32px;
  width: 100%; max-width: 480px;
  padding: 48px 40px 32px;
  position: relative;
  box-shadow: 0 30px 60px rgba(0,0,0,0.4), inset 0 2px 0 rgba(255,255,255,0.6);
  border: 6px solid #fff;
  animation: popIn 0.26s cubic-bezier(.34,1.56,.64,1);
  text-align: center;
  max-height: calc(100vh - 48px);
  overflow-y: auto;
}
.login-close {
  position: absolute; top: 16px; right: 16px;
  width: 44px; height: 44px;
  border-radius: 50%;
  background: #fff; color: #8a5a32;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 3px 0 #8a5a32, inset 0 2px 0 rgba(255,255,255,0.5);
  border: 2px solid #8a5a32;
}
.login-close:active { transform: translateY(2px); box-shadow: 0 1px 0 #8a5a32; }

.login-art {
  position: relative; height: 110px; margin: 6px 0 18px;
  display: flex; align-items: flex-end; justify-content: center; gap: 10px;
}
.login-book {
  width: 48px; aspect-ratio: 3/4;
  border-radius: 3px 6px 6px 3px;
  box-shadow: 0 6px 10px rgba(0,0,0,0.25),
              inset 2px 0 0 rgba(255,255,255,0.2),
              inset -2px 0 0 rgba(0,0,0,0.15);
  animation: bookBob 2.4s ease-in-out infinite;
}
.login-book.b1 { animation-delay: 0s;    transform: rotate(-6deg); background: #E54B3C; }
.login-book.b2 { animation-delay: 0.15s; transform: rotate(-2deg); background: #F39C2C; }
.login-book.b3 { animation-delay: 0.30s; transform: rotate(2deg);  background: #2E7AD1; }
.login-book.b4 { animation-delay: 0.45s; transform: rotate(6deg);  background: #6BBE45; }
@keyframes bookBob {
  0%, 100% { margin-bottom: 0; }
  50%      { margin-bottom: 10px; }
}

.login-title { font-size: 30px; font-weight: 800; color: #3a2a18; margin: 0 0 10px; }
.login-sub { font-size: 16px; color: #7a5a3a; line-height: 1.45; margin: 0 0 24px; }

.btn-google {
  width: 100%;
  background: #fff; color: #3a2a18;
  font-size: 17px; font-weight: 700;
  padding: 16px 22px;
  border-radius: 16px;
  display: inline-flex; align-items: center; justify-content: center; gap: 12px;
  border: 2px solid #dcdcdc;
  box-shadow: 0 4px 0 #c8c8c8;
  margin-bottom: 12px;
  transition: transform 0.08s, box-shadow 0.08s;
  cursor: pointer;
}
.btn-google:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 1px 0 #c8c8c8; }
.btn-google.loading { background: #f4f4f4; color: #7a5a3a; }
.btn-google:disabled { cursor: default; }
.google-g { flex-shrink: 0; }

.btn-apple {
  width: 100%;
  background: #111; color: #fff;
  font-size: 17px; font-weight: 700;
  padding: 16px 22px;
  border-radius: 16px;
  display: inline-flex; align-items: center; justify-content: center; gap: 12px;
  border: 2px solid #000;
  box-shadow: 0 4px 0 #000;
  margin-bottom: 16px;
  transition: transform 0.08s, box-shadow 0.08s;
  cursor: pointer;
}
.btn-apple:active { transform: translateY(3px); box-shadow: 0 1px 0 #000; }

.login-divider {
  display: flex; align-items: center; gap: 12px;
  color: #a87a4a; font-weight: 600; font-size: 14px;
  margin: 8px 0 14px;
}
.login-divider::before, .login-divider::after {
  content: ''; flex: 1; height: 2px; background: #e8c898; border-radius: 2px;
}
.btn-guest {
  color: var(--brand-blue);
  font-size: 16px; font-weight: 700;
  padding: 10px 16px;
  margin-bottom: 20px;
  background: none; border: 0; cursor: pointer;
}
.btn-guest:active { opacity: 0.7; }

.login-foot { border-top: 2px dashed #e8c898; padding-top: 16px; }
.login-parent {
  display: inline-flex; align-items: center; gap: 6px;
  color: #a87a4a; font-size: 13px; font-weight: 600;
  margin-bottom: 8px;
}
.login-legal { font-size: 12px; color: #a87a4a; line-height: 1.5; }
.login-legal a { color: var(--brand-blue); text-decoration: underline; cursor: pointer; }

.spinner {
  width: 22px; height: 22px;
  border: 3px solid #d8d8d8;
  border-top-color: var(--brand-blue);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ----- Kid setup stage ----- */
.setup-stage { text-align: left; }
.setup-step {
  display: inline-block;
  background: #fff2d4; color: #b07628;
  font-size: 12px; font-weight: 700;
  padding: 6px 12px; border-radius: 999px;
  letter-spacing: 0.05em; text-transform: uppercase;
  margin-bottom: 14px;
}
.setup-stage .login-title { text-align: left; font-size: 24px; margin-bottom: 6px; }
.setup-stage .login-sub { text-align: left; margin-bottom: 20px; font-size: 15px; }

.setup-field { display: block; margin-bottom: 18px; }
.setup-label {
  display: block;
  font-size: 14px; font-weight: 700; color: #5a3a18;
  margin-bottom: 10px;
}
.setup-input {
  width: 100%;
  background: #fff;
  border: 3px solid #e8c898;
  border-radius: 16px;
  padding: 14px 16px;
  font-size: 18px; font-weight: 600; color: #3a2a18;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.setup-input:focus {
  border-color: var(--brand-blue);
  box-shadow: 0 0 0 4px rgba(46, 122, 209, 0.2);
}
.setup-input::placeholder { color: #c09670; }

.age-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.age-btn {
  background: #fff;
  border: 3px solid #e8c898;
  border-radius: 14px;
  padding: 12px 4px;
  font-size: 17px; font-weight: 800; color: #5a3a18;
  transition: transform 0.08s;
  cursor: pointer;
}
.age-btn:active { transform: scale(0.96); }
.age-btn.active {
  background: var(--brand-blue);
  color: #fff;
  border-color: #1a447a;
  box-shadow: 0 3px 0 #1a447a;
}

.avatar-row { display: grid; grid-template-columns: repeat(6, 1fr); gap: 10px; }
.avatar-btn {
  aspect-ratio: 1;
  border-radius: 50%;
  border: 3px solid #fff;
  box-shadow: 0 3px 0 rgba(0,0,0,0.18);
  display: flex; align-items: center; justify-content: center;
  transition: transform 0.08s;
  position: relative; cursor: pointer;
}
.avatar-btn:active { transform: scale(0.92); }
.avatar-btn.active {
  border-color: var(--brand-blue);
  box-shadow: 0 0 0 4px rgba(46, 122, 209, 0.4), 0 3px 0 rgba(0,0,0,0.18);
}
.avatar-glyph { color: #fff; font-size: 22px; font-weight: 800; text-shadow: 0 1px 2px rgba(0,0,0,0.25); }

.btn-finish {
  width: 100%;
  background: linear-gradient(180deg, #4aae5c 0%, #2a8a3c 100%);
  color: #fff;
  font-size: 20px; font-weight: 800;
  padding: 16px 22px;
  border-radius: 18px;
  border: 3px solid #1e6a2c;
  box-shadow: 0 5px 0 #1e6a2c, inset 0 2px 0 rgba(255,255,255,0.3);
  margin-top: 4px;
  transition: transform 0.08s, box-shadow 0.08s, opacity 0.15s;
  cursor: pointer;
}
.btn-finish:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 2px 0 #1e6a2c, inset 0 2px 0 rgba(255,255,255,0.3); }
.btn-finish:disabled { opacity: 0.45; cursor: default; }

.btn-back {
  width: 100%;
  color: #8a5a32; font-weight: 700; font-size: 14px;
  padding: 12px;
  margin-top: 6px;
  background: none; border: 0; cursor: pointer;
}

.login-error {
  background: #fde2de; color: #8a2818;
  border: 2px solid #f2a090;
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 14px; font-weight: 600;
  margin-bottom: 12px;
  text-align: left;
}

/* ---------- Reader chrome (wraps legacy flipbook) ---------- */
.reader-chrome {
  position: fixed; inset: 0; z-index: 30;
  display: flex; flex-direction: column;
  background: radial-gradient(ellipse at 50% 40%, #e8c898 0%, #c09660 60%, #8a5a32 100%);
}
.reader-bar {
  display: flex; align-items: center; gap: 14px;
  padding: 12px 20px;
  background: rgba(255,255,255,0.96);
  border-bottom: 2px solid #e8c898;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
  z-index: 3;
}
.reader-title {
  flex: 1; min-width: 0;
  display: flex; align-items: center; gap: 12px;
  font-size: 20px; font-weight: 800; color: #3a2a18;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.reader-book-glyph {
  width: 26px; height: 32px; border-radius: 3px 5px 5px 3px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.25);
  flex-shrink: 0;
}
.reader-progress {
  color: #8a5a32; font-weight: 700; font-size: 14px;
  background: #f2e2c8; padding: 6px 14px; border-radius: 10px;
  white-space: nowrap;
}
.reader-close {
  width: 48px; height: 48px; border-radius: 50%;
  background: #fff; color: #8a5a32;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 3px 0 #8a5a32, inset 0 2px 0 rgba(255,255,255,0.5);
  border: 2px solid #8a5a32; cursor: pointer;
  flex-shrink: 0;
}
.reader-close:active { transform: translateY(2px); box-shadow: 0 1px 0 #8a5a32; }

.reader-stage {
  flex: 1;
  position: relative;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  min-height: 0;
}
.reader-stage .flip-mount {
  position: absolute; inset: 0;
}

.reader-arrow {
  position: absolute; top: 50%;
  width: 68px; height: 68px;
  border-radius: 50%;
  background: rgba(255,255,255,0.95);
  color: #8a5a32;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 6px 0 rgba(0,0,0,0.25), inset 0 2px 0 rgba(255,255,255,0.5);
  border: 3px solid #fff;
  flex-shrink: 0;
  transition: transform 0.08s;
  z-index: 4;
  transform: translateY(-50%);
  cursor: pointer;
}
.reader-arrow.left  { left: 16px;  }
.reader-arrow.right { right: 16px; }
.reader-arrow:active { transform: translateY(calc(-50% + 3px)); box-shadow: 0 3px 0 rgba(0,0,0,0.25); }
.reader-arrow:disabled { opacity: 0.45; cursor: default; }

.reader-dots {
  display: flex; justify-content: center; gap: 6px;
  padding: 10px 18px;
  background: rgba(255,255,255,0.9);
  flex-wrap: wrap;
  z-index: 3;
}
.reader-dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: #d8b888;
  transition: all 0.15s;
  border: 0; padding: 0; cursor: pointer;
}
.reader-dot.active { background: var(--brand-red); transform: scale(1.4); }

/* Hide the legacy flipbook plugin's own nav/menu/toolbar so our chrome is the only UI. */
.reader-chrome .flipbook-nav,
.reader-chrome .flipbook-menu,
.reader-chrome .flipbook-sub-menu,
.reader-chrome .flipbook-page-number,
.reader-chrome .flipbook-thumb-holder,
.reader-chrome .flipbook-toc-btn { display: none !important; }

@media (max-width: 640px) {
  .reader-bar { padding: 10px 12px; gap: 8px; }
  .reader-title { font-size: 16px; }
  .reader-progress { font-size: 12px; padding: 4px 10px; }
  .reader-close { width: 40px; height: 40px; }
  .reader-arrow { width: 52px; height: 52px; }
  .reader-arrow.left { left: 6px; }
  .reader-arrow.right { right: 6px; }
  .login-card { padding: 36px 24px 24px; }
  .login-title { font-size: 26px; }
}

/* ---------- A11y ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
