/* ── Reset & base ─────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --night: #0d0b1e;
  --night-2: #13102b;
  --night-3: #1e1840;
  --surface: rgba(255,255,255,.07);
  --surface-solid: #1e1840;
  --ink: #f0eeff;
  --ink-soft: rgba(200,190,255,.6);
  --ink-dim: rgba(200,190,255,.4);
  --purple: #8b5cf6;
  --purple-bright: #a78bfa;
  --purple-mid: #7c3aed;
  --gold: #fbbf24;
  --gold-soft: #fde68a;
  --rose: #fb7185;
  --green: #34d399;
  --teal: #22d3ee;
  --r: 16px;
  --r-lg: 20px;
  --r-xl: 28px;
  --sh: 0 4px 20px rgba(0,0,0,.4);
  --sh-glow: 0 0 20px rgba(139,92,246,.3);
  --sh-card: 0 8px 32px rgba(0,0,0,.5);

  /* Semantic status colors — previously used as unnamed literals
     (#f87171, #f59e0b, #86efac) scattered across the stylesheet with no
     single place to look up "what's our error color". */
  --color-error: #f87171;
  --color-warning: #f59e0b;
  --color-success: #86efac;

  /* Spacing scale — new components should pick from this rather than an
     arbitrary px value; not retrofitted across the whole file at once. */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --space-7: 48px;
}

/* Generic hide/show utility. Previously `.hidden` only worked via a
   compound rule per element (`.mode-picker.hidden`, `.category-pill.hidden`,
   etc.) — a new hideable element silently stayed visible if you forgot to
   add its own compound rule, which happened twice in one evening (the
   WELCOME10 promo code box, then a "Forgot password?" link). The
   per-element rules below are now redundant but harmless; new code should
   just rely on this one. */
[hidden], .hidden { display: none !important; }
/* App Store guideline 3.1.1: no promo/redeem codes in the iOS app, since
   they unlock content outside Apple's in-app purchase. app.js adds
   html.platform-ios on the native iOS build only; Android and web keep them. */
html.platform-ios .ios-hide { display: none !important; }

/* Form controls don't inherit the page font by default, which also dropped
   the emoji fallback (flags showed as letters on the story language buttons). */
button, input, select, textarea { font-family: inherit; }

html, body {
  height: 100%; overflow: hidden;
  background: var(--night);
  /* Noto Color Emoji is a fallback only: Nunito has no emoji glyphs, so
     emoji fall through to it. Without it, Windows renders flag emoji as
     bare letters ("BR", "MX"), which broke the culture chips on web. */
  font-family: 'Nunito', system-ui, -apple-system, 'Noto Color Emoji', sans-serif;
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

/* Headline face: Quicksand for a storybook display feel, distinct from body text */
h1, h2, h3 {
  font-family: 'Quicksand', 'Nunito', system-ui, -apple-system, 'Noto Color Emoji', sans-serif;
}

/* ── Screens ─────────────────────────────────────────────── */
.screen {
  position: fixed; inset: 0;
  display: flex; flex-direction: column;
  background: var(--night);
  overflow-y: auto; -webkit-overflow-scrolling: touch;
  opacity: 0; pointer-events: none;
  transform: translateY(12px);
  transition: opacity .3s ease, transform .3s ease;
  padding-bottom: env(safe-area-inset-bottom, 0);
}
.screen.active { opacity: 1; pointer-events: auto; transform: none; }

/* ── Starfield background ─────────────────────────────────── */
.screen::before {
  content: '';
  position: fixed; inset: 0; z-index: 0;
  pointer-events: none;
  background-image:
    radial-gradient(1px 1px at 10% 15%, rgba(255,255,255,.7) 0%, transparent 100%),
    radial-gradient(1px 1px at 25% 40%, rgba(255,255,255,.5) 0%, transparent 100%),
    radial-gradient(1.5px 1.5px at 40% 8%, rgba(255,255,255,.8) 0%, transparent 100%),
    radial-gradient(1px 1px at 55% 55%, rgba(255,255,255,.4) 0%, transparent 100%),
    radial-gradient(1px 1px at 70% 20%, rgba(255,255,255,.7) 0%, transparent 100%),
    radial-gradient(1.5px 1.5px at 80% 75%, rgba(255,255,255,.5) 0%, transparent 100%),
    radial-gradient(1px 1px at 90% 35%, rgba(255,255,255,.6) 0%, transparent 100%),
    radial-gradient(1px 1px at 15% 70%, rgba(255,255,255,.4) 0%, transparent 100%),
    radial-gradient(1px 1px at 35% 85%, rgba(255,255,255,.5) 0%, transparent 100%),
    radial-gradient(1.5px 1.5px at 60% 92%, rgba(255,255,255,.6) 0%, transparent 100%),
    radial-gradient(1px 1px at 75% 50%, rgba(255,255,255,.3) 0%, transparent 100%),
    radial-gradient(1px 1px at 92% 80%, rgba(255,255,255,.5) 0%, transparent 100%),
    radial-gradient(1px 1px at 5% 50%, rgba(255,255,255,.4) 0%, transparent 100%),
    radial-gradient(1px 1px at 48% 28%, rgba(255,255,255,.6) 0%, transparent 100%);
}

/* Non-home screens don't need the starfield as much */
#screen-loading::before, #screen-reader::before, #screen-end::before { display: none; }

/* All content inside screens needs to be above the starfield */
.screen > * { position: relative; z-index: 1; }

/* ── Common header ─────────────────────────────────────────── */
.screen-header {
  display: flex; align-items: center; gap: 10px;
  padding: max(56px, calc(env(safe-area-inset-top) + 20px)) 20px 16px;
  position: sticky; top: 0; z-index: 10;
  background: linear-gradient(to bottom, var(--night) 70%, transparent);
}
.screen-header h2 {
  font-size: 1.4rem; font-weight: 800; color: var(--ink);
}
.back-btn {
  background: var(--surface); border: 1px solid rgba(255,255,255,.1);
  backdrop-filter: blur(12px); cursor: pointer;
  width: 40px; height: 40px; border-radius: 50%;
  font-size: 1.1rem; color: var(--ink);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; transition: background .15s;
}
.back-btn:active { background: rgba(255,255,255,.15); }

/* ── Buttons ─────────────────────────────────────────────── */
.primary-btn {
  display: block; width: 100%; padding: 16px;
  background: linear-gradient(135deg, var(--purple-mid), var(--purple));
  color: #fff;
  font-family: inherit; font-size: 1.05rem; font-weight: 800;
  border: none; border-radius: var(--r); cursor: pointer;
  box-shadow: 0 4px 20px rgba(139,92,246,.45);
  transition: transform .1s, box-shadow .1s;
}
.primary-btn:active { transform: scale(.97); box-shadow: 0 2px 8px rgba(139,92,246,.25); }

.ghost-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 11px 20px;
  background: rgba(255,255,255,.08);
  border: 1px solid rgba(255,255,255,.15);
  color: var(--ink); border-radius: var(--r);
  font-family: inherit; font-size: .95rem; font-weight: 700; cursor: pointer;
  text-align: center;
  backdrop-filter: blur(8px);
  transition: background .15s;
}

.danger-btn {
  display: block; width: 100%; padding: 13px 20px;
  background: rgba(248,113,113,.12);
  border: 1px solid rgba(248,113,113,.35);
  color: var(--color-error); border-radius: var(--r);
  font-family: inherit; font-size: .95rem; font-weight: 800; cursor: pointer;
  text-align: center;
  transition: background .15s, transform .1s;
}
.danger-btn:active { transform: scale(.97); }
.danger-btn:hover { background: rgba(248,113,113,.2); }
.ghost-btn:active { background: rgba(255,255,255,.15); }

/* ── HOME ────────────────────────────────────────────────── */
#screen-home {
  background: var(--night);
}
/* .screen::before already paints the starfield; layer the grain texture
   onto ::after instead so both effects coexist. */
#screen-home::after {
  content: '';
  position: fixed; inset: 0; z-index: 0; pointer-events: none;
  opacity: .05; mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

.home-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: max(20px, calc(env(safe-area-inset-top) + 12px)) 20px 12px;
  position: sticky; top: 0; z-index: 10;
  background: var(--night);
}
.home-title-wrap {
  display: flex; align-items: center; gap: 10px;
  /* The app name is the priority — it must never lose the space-splitting
     contest against the icon row (see the narrow-phone block below, which
     shrinks .home-header-actions instead so this never has to truncate). */
  flex-shrink: 0;
}
.home-star-icon {
  font-size: 2rem; line-height: 1;
  filter: drop-shadow(0 0 8px rgba(251,191,36,.8));
  animation: pulse-star 3s ease-in-out infinite;
}
@keyframes pulse-star {
  0%, 100% { transform: scale(1); filter: drop-shadow(0 0 8px rgba(251,191,36,.8)); }
  50% { transform: scale(1.12); filter: drop-shadow(0 0 16px rgba(251,191,36,1)); }
}
.home-title {
  font-size: 2rem; font-weight: 800; color: var(--ink);
  letter-spacing: -.02em;
  text-shadow: 0 0 30px rgba(139,92,246,.5);
  white-space: nowrap;
}

.home-header-actions {
  display: flex; align-items: center; gap: 8px; flex-shrink: 0;
}
/* Language switch: a labeled chip (globe + "EN") instead of a bare globe
   emoji, so it reads as the current setting rather than a mystery button. */
.header-lang-btn {
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 44px; padding: 0 14px;
  background: rgba(255,255,255,.08);
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 100px; cursor: pointer;
  color: var(--ink); font-family: inherit; font-size: .82rem; font-weight: 800;
  letter-spacing: .04em;
  transition: background .15s, transform .1s;
}
.header-lang-btn svg { width: 17px; height: 17px; flex-shrink: 0; color: var(--gold-soft); }
.header-lang-btn:active { background: rgba(255,255,255,.18); transform: scale(.95); }

@media (max-width: 420px) {
  .home-header { padding-left: 16px; padding-right: 16px; gap: 8px; }
  .home-title-wrap { gap: 6px; }
  .home-star-icon { font-size: 1.5rem; }
  .home-title { font-size: 1.5rem; }
}

/* ── Bottom tab bar (phones & tablets) ─────────────────────── */
/* #screen-home prefix: outranks the generic ".screen > *" position rule. */
#screen-home > .home-tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; justify-content: space-around;
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom, 0px));
  background: rgba(19,16,43,.94);
  backdrop-filter: blur(14px);
  border-top: 1px solid rgba(255,255,255,.08);
}
.home-tab {
  flex: 1; min-width: 0; min-height: 52px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  background: none; border: none; border-radius: 12px; cursor: pointer;
  color: var(--ink-soft); font-family: inherit; font-size: .7rem; font-weight: 800;
}
.home-tab svg { width: 22px; height: 22px; }
.home-tab.active { color: var(--gold-soft); }
.home-tab:active { background: rgba(255,255,255,.06); }
.home-tab:focus-visible { outline: 2px solid var(--gold); outline-offset: -2px; }
/* Keep the last shelf row clear of the tab bar */
.home-main { padding-bottom: calc(64px + env(safe-area-inset-bottom, 0px)); }


/* Setup banner */
.setup-banner {
  margin: 0 16px 4px;
  padding: 12px 14px;
  background: rgba(251,191,36,.12);
  border: 1px solid rgba(251,191,36,.35);
  border-radius: var(--r); display: flex; gap: 10px; align-items: center;
  cursor: pointer; backdrop-filter: blur(8px);
}
.setup-banner-icon { font-size: 1.2rem; flex-shrink: 0; }
.setup-banner-text { flex: 1; font-size: .82rem; font-weight: 700; color: var(--gold-soft); }
.setup-banner-arrow { color: var(--gold); font-size: .9rem; }
.setup-banner.hidden { display: none; }

.shelf-intro { padding: 2px 20px 6px; }
/* On phones the tagline cost a full row above the stories; the section
   headers on the shelf already say what's there. */
@media (max-width: 639px) { .shelf-intro { display: none; } }
.shelf-intro-text {
  font-size: .75rem; font-weight: 700; color: var(--ink-soft);
  text-align: center; letter-spacing: .03em;
}

/* ── Continue Reading (featured hero card) ─────────────────── */
.continue-reading { padding: 4px 20px 18px; }
.continue-reading.hidden { display: none; }
.cr-card {
  width: 100%; display: flex; align-items: stretch;
  background: linear-gradient(115deg, var(--night-3) 0%, #171029 100%);
  border: 1px solid rgba(255,255,255,.08);
  border-radius: 18px; overflow: hidden;
  box-shadow: 0 14px 34px -10px rgba(0,0,0,.6);
  cursor: pointer; font-family: inherit; padding: 0;
  transition: transform .15s ease;
}
.cr-card:active { transform: scale(.98); }
.cr-thumb {
  width: 84px; flex-shrink: 0; position: relative; overflow: hidden;
  background-size: cover; background-position: center;
}
.cr-thumb-img { width: 100%; height: 100%; object-fit: cover; display: block; }
.cr-info {
  flex: 1; min-width: 0; padding: 13px 14px;
  display: flex; flex-direction: column; justify-content: center; gap: 5px;
  text-align: left;
}
.cr-eyebrow {
  font-size: .62rem; font-weight: 800; color: var(--gold-soft);
  text-transform: uppercase; letter-spacing: .06em;
}
.cr-title {
  font-family: 'Quicksand', 'Noto Color Emoji', sans-serif; font-weight: 700; font-size: .96rem;
  color: var(--ink); line-height: 1.15;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.cr-progress-track {
  height: 4px; border-radius: 4px; background: rgba(255,255,255,.1); overflow: hidden;
}
.cr-progress-fill {
  height: 100%; border-radius: 4px;
  background: linear-gradient(90deg, #b45309, var(--gold));
}
.cr-sub { font-size: .68rem; color: var(--ink-dim); font-weight: 700; }
.cr-play {
  flex-shrink: 0; align-self: center; margin-right: 14px;
  width: 38px; height: 38px; border-radius: 50%;
  background: var(--purple);
  display: flex; align-items: center; justify-content: center;
}
.cr-play svg { width: 15px; height: 15px; }

/* ── SHELF GRID ─────────────────────────────────────────── */
.shelf-grid {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 12px; padding: 4px 14px 80px;
  width: 100%;
}
.shelf-loading {
  padding: 60px 20px; color: var(--ink-soft);
  text-align: center; font-size: .9rem;
  grid-column: 1 / -1;
}

/* ── Wide screens (tablet / desktop web) ──────────────────────
   Same components and tokens as mobile, just re-flowed. Below 900px,
   .home-sidebar stays hidden and .home-main behaves exactly like the
   mobile layout (full-width, page itself scrolls). At 900px+ a sidebar
   nav appears and .home-main becomes its own scroll region. */
.home-sidebar { display: none; }

@media (min-width: 640px) and (max-width: 899px) {
  .home-header, .shelf-intro, .continue-reading, .category-pills-bar, .age-pills-bar, .shelf-grid {
    max-width: 900px; margin-left: auto; margin-right: auto;
  }
  .shelf-grid { grid-template-columns: repeat(3, 1fr); }
}

@media (min-width: 900px) {
  /* Scrolling moves from the whole screen to just .home-main, so the
     sidebar stays put while shelf content scrolls beneath it. */
  #screen-home { flex-direction: row; overflow-y: hidden; }
  .home-sidebar {
    display: flex; flex-direction: column; gap: 2px;
    width: 240px; flex-shrink: 0;
    padding: 26px 14px;
    background: var(--night-2);
    border-right: 1px solid rgba(255,255,255,.07);
    position: relative; z-index: 1;
  }
  .home-sidebar-brand {
    display: flex; align-items: center; gap: 9px;
    padding: 0 10px 26px;
    font-family: inherit; font-weight: 800; font-size: 1.15rem; color: var(--ink);
  }
  .home-sidebar-link {
    display: flex; align-items: center; gap: 12px;
    padding: 11px 12px; border-radius: 11px;
    background: none; border: none; cursor: pointer;
    font-family: inherit; font-weight: 700; font-size: .9rem;
    color: var(--ink-soft); text-align: left;
  }
  .home-sidebar-link svg { width: 18px; height: 18px; flex-shrink: 0; }
  .home-sidebar-link:hover { background: rgba(255,255,255,.05); }
  .home-sidebar-link.active { background: var(--night-3); color: var(--ink); }
  .home-sidebar-link.active svg { color: var(--gold-soft); }

  /* The mobile header and bottom tab bar are replaced by the sidebar nav */
  .home-header { display: none; }
  #screen-home > .home-tabbar { display: none; }
  .home-main { padding-bottom: 0; }

  .home-main {
    flex: 1; min-width: 0; overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  .home-header, .shelf-intro, .continue-reading, .category-pills-bar, .age-pills-bar, .shelf-grid {
    max-width: 1000px; margin-left: auto; margin-right: auto;
  }
  .shelf-intro { padding-top: 26px; }
  .shelf-grid { grid-template-columns: repeat(4, 1fr); gap: 16px; }
}

@media (min-width: 1280px) {
  .home-header, .shelf-intro, .continue-reading, .category-pills-bar, .age-pills-bar, .shelf-grid {
    max-width: 1180px;
  }
  .shelf-grid { grid-template-columns: repeat(5, 1fr); }
}

/* Book-style portrait card */
.shelf-card {
  background: var(--night-3);
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 12px; cursor: pointer;
  overflow: hidden;
  box-shadow: 2px 0 0 rgba(255,255,255,0.12), 4px 0 0 rgba(0,0,0,0.4), 4px 8px 24px rgba(0,0,0,.6);
  transition: transform .18s ease, box-shadow .18s ease;
  aspect-ratio: 2 / 3;
  position: relative;
}
.shelf-card:active { transform: scale(.96); box-shadow: 2px 3px 10px rgba(0,0,0,.5); }

/* Cover fills the whole card */
.shelf-card-cover {
  position: absolute; inset: 0;
  overflow: hidden;
}
.shelf-card.locked .shelf-card-cover { filter: brightness(.6) saturate(.6); }

/* 3D Book Spine Left Shadow */
.shelf-card-cover::before {
  content: '';
  position: absolute; top: 0; bottom: 0; left: 0; width: 14px;
  background: linear-gradient(to right, rgba(0,0,0,.45) 0%, rgba(0,0,0,.15) 60%, transparent 100%);
  z-index: 2; pointer-events: none;
}

/* Gradient so title reads over art */
.shelf-card-cover::after {
  content: '';
  position: absolute; inset: 0;
  background: linear-gradient(180deg,
    rgba(0,0,0,.08) 0%,
    transparent 30%,
    rgba(0,0,0,.25) 55%,
    rgba(0,0,0,.85) 100%);
  z-index: 1;
}

/* Lock icon — top right */
/* Locked badge — a small bronze "seal" circle, not a bare emoji */
.shelf-lock {
  position: absolute; top: 9px; right: 9px;
  z-index: 3; width: 26px; height: 26px; border-radius: 50%;
  background: linear-gradient(135deg, #b45309, #92400e);
  border: 1px solid rgba(253,230,138,.4);
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 3px 8px rgba(0,0,0,.4);
}
.shelf-lock svg { width: 12px; height: 12px; display: block; }

/* Time badge — top left */
.shelf-badges {
  position: absolute; top: 10px; left: 10px; z-index: 3;
  display: flex; flex-direction: column; gap: 3px; align-items: flex-start;
}
.shelf-badge-age {
  background: rgba(0,0,0,.55); color: rgba(255,255,255,.9);
  font-size: .58rem; font-weight: 800; border-radius: 100px;
  padding: 2px 7px; backdrop-filter: blur(8px);
  letter-spacing: .04em; text-transform: uppercase;
}
/* Read-aloud time sits under the title, on the dark end of the cover
   gradient. Up top it was white text straight over light illustrations. */
.shelf-badge-time {
  color: rgba(255,255,255,.78);
  font-size: .68rem; font-weight: 800;
  display: flex; align-items: center; gap: 4px;
}
.shelf-badge-time::before {
  content: '';
  width: 10px; height: 10px; flex-shrink: 0;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='9'/%3E%3Cpath d='M12 7v5l3 3'/%3E%3C/svg%3E");
  background-size: contain; background-repeat: no-repeat;
  opacity: .85;
}
/* Free badge — a torn-ticket ribbon hanging off the card's left edge */
.shelf-badge-free {
  background: linear-gradient(135deg, #facc15, var(--color-warning));
  color: #3a2a03;
  font-size: .62rem; font-weight: 900;
  padding: 3px 9px 3px 11px;
  margin-left: -10px;
  letter-spacing: .03em;
  clip-path: polygon(0 0, 100% 0, 90% 50%, 100% 100%, 0 100%);
  box-shadow: 0 3px 8px rgba(0,0,0,.3);
}

/* Category filter chips — wrap onto multiple rows so every category is
   always visible without horizontal scrolling. */
.category-pills-bar {
  display: flex; flex-wrap: wrap; gap: 8px;
  padding: 4px 16px 10px;
}

.category-pill {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 0 14px;
  min-height: 40px;
  line-height: 1.2;
  background: var(--surface);
  border: 1px solid rgba(255,255,255,.1);
  border-radius: 100px;
  color: var(--ink-soft);
  font-family: inherit; font-size: 0.82rem; font-weight: 800;
  cursor: pointer;
  transition: color 0.2s, background 0.2s, border-color 0.2s;
  white-space: nowrap;
}
.category-pill.hidden { display: none; }
.category-pill:active { opacity: .7; }
.category-pill:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
.category-pill.active {
  color: #1a1433;
  background: var(--gold);
  border-color: var(--gold);
}

/* Reading Age Filter Pills */
.age-pills-bar {
  display: flex; gap: 6px; overflow-x: auto;
  align-items: center;
  min-height: 44px;
  padding: 0 16px 12px;
  margin-bottom: 4px;
  border-bottom: 1px solid rgba(255,255,255,.08);
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.age-pills-bar::-webkit-scrollbar { display: none; }

.age-pills-label {
  flex-shrink: 0;
  font-size: 0.72rem; font-weight: 700;
  color: var(--ink-soft);
  opacity: 0.6;
  letter-spacing: .03em;
  margin-right: 2px;
}

.age-pill {
  flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center;
  padding: 5px 14px;
  min-height: 38px;
  line-height: 1.2;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 100px;
  color: var(--ink-soft);
  font-family: inherit; font-size: 0.76rem; font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s, color 0.2s, transform 0.15s;
  white-space: nowrap;
}
.age-pill:active { transform: scale(0.96); }
.age-pill.active {
  background: rgba(251, 191, 36, 0.14);
  border-color: var(--gold);
  color: var(--gold-soft, var(--gold-soft));
}

/* Category Section Headers on Shelf Grid */
.shelf-section-header {
  grid-column: 1 / -1;
  display: flex; align-items: center; justify-content: space-between;
  margin: 20px 0 10px; padding: 0 4px 6px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}
.shelf-section-title {
  font-size: 1.05rem; font-weight: 800; color: var(--ink);
  display: flex; align-items: center; gap: 8px;
}
.shelf-section-count {
  font-size: 0.72rem; font-weight: 800; color: var(--ink-soft);
  background: rgba(255, 255, 255, 0.09); padding: 3px 10px; border-radius: 100px;
}

/* Category Card Badges */
.shelf-badge-cat {
  font-size: 0.58rem; font-weight: 800; border-radius: 100px;
  padding: 2px 7px; backdrop-filter: blur(8px);
  letter-spacing: 0.03em;
}
.shelf-badge-cat.brazilian {
  background: rgba(16, 185, 129, 0.9); color: #fff;
}
.shelf-badge-cat.spanish {
  background: rgba(245, 158, 11, 0.9); color: #fff;
}
.shelf-badge-cat.classic {
  background: rgba(139, 92, 246, 0.9); color: #fff;
}
.shelf-badge-cat.haitian {
  background: rgba(56, 189, 248, 0.9); color: #fff;
}
.shelf-badge-cat.anansi {
  background: rgba(217, 119, 6, 0.9); color: #fff;
}
.shelf-badge-origin {
  background: rgba(0, 0, 0, 0.55); color: rgba(255,255,255,.9);
  font-size: 0.58rem; font-weight: 700; border-radius: 100px;
  padding: 2px 7px; backdrop-filter: blur(8px);
  letter-spacing: 0.02em;
}

/* Cover photo */
.shelf-cover-img {
  position: absolute; inset: 0;
  width: 100%; height: 100%; object-fit: cover; object-position: center top;
  z-index: 0;
}

/* Title + read time overlaid at bottom of card */
.shelf-card-foot {
  position: absolute; bottom: 0; left: 0; right: 0;
  z-index: 2; padding: 8px 10px 11px;
  display: flex; flex-direction: column; gap: 4px;
}
.shelf-card-title {
  font-size: .82rem; font-weight: 800; color: #fff;
  line-height: 1.25; text-align: left;
  text-shadow: 0 1px 6px rgba(0,0,0,.9);
}
.shelf-card.locked .shelf-card-title { color: rgba(255,255,255,.65); }

/* ── LOADING ─────────────────────────────────────────────── */
#screen-loading {
  justify-content: center; align-items: center;
  background: radial-gradient(ellipse at center, #2d1270 0%, var(--night) 70%);
}
.loading-scene { text-align: center; padding: 40px 28px; }
.loading-star {
  font-size: 5rem; display: block; margin-bottom: 28px;
  animation: pulse-star 2.2s ease-in-out infinite;
}
.loading-message { font-size: 1.3rem; font-weight: 800; color: var(--ink); margin-bottom: 8px; }
.loading-sub { font-size: .85rem; color: var(--ink-soft); margin-bottom: 40px; }
.loading-dots { display: flex; justify-content: center; gap: 8px; }
.loading-dots span {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--purple-bright);
  animation: bounce 1.4s infinite ease-in-out both;
}
.loading-dots span:nth-child(1) { animation-delay: -.32s; }
.loading-dots span:nth-child(2) { animation-delay: -.16s; }
@keyframes bounce {
  0%, 80%, 100% { transform: scale(0); opacity: .4; }
  40% { transform: scale(1); opacity: 1; }
}

/* ── READER ──────────────────────────────────────────────── */
#screen-reader {
  background: #080613;
  overflow: hidden;
  display: flex; flex-direction: column;
  padding-bottom: 0;
}

/* Illustration: top 55% of screen */
.reader-illustration {
  flex: 0 0 55%;
  position: relative;
  overflow: hidden;
}
.scene-backdrop { position: absolute; inset: 0; transition: background 1s ease; }
#reader-img {
  position: absolute; inset: 0;
  width: 100%; height: 100%; object-fit: cover;
  transition: opacity .6s ease;
}

/* Header overlaid on illustration */
.reader-header {
  position: absolute; top: 0; left: 0; right: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(env(safe-area-inset-top, 44px) + 8px) 16px 16px;
  background: linear-gradient(to bottom, rgba(8,6,19,.9) 0%, rgba(8,6,19,.55) 60%, transparent 100%);
}
.reader-back-btn, .reader-bookmark-btn {
  background: rgba(255,255,255,.14); border: 1px solid rgba(255,255,255,.1);
  width: 48px; height: 48px; border-radius: 50%;
  color: #fff; cursor: pointer; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  padding: 0;
  backdrop-filter: blur(8px); transition: background .15s;
}
.reader-back-btn svg, .reader-bookmark-btn svg { width: 20px; height: 20px; display: block; }
.reader-back-btn:active, .reader-bookmark-btn:active { background: rgba(255,255,255,.25); }
.reader-mode-badge {
  font-size: .65rem; font-weight: 700; color: rgba(255,255,255,.7);
  background: rgba(255,255,255,.1); border: 1px solid rgba(255,255,255,.15);
  border-radius: 20px; padding: 3px 8px; white-space: nowrap; flex-shrink: 0;
}
.reader-title {
  flex: 1; margin: 0 8px;
  font-size: .8rem; font-weight: 800; color: #fff;
  text-shadow: 0 1px 6px rgba(0,0,0,.8);
  text-align: center;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden; line-height: 1.3;
}

/* Page dots at bottom of illustration */
.page-indicator {
  position: absolute; bottom: 10px; left: 0; right: 0;
  display: flex; justify-content: center; gap: 6px; z-index: 5;
  background: rgba(0,0,0,.25); border-radius: 20px;
  width: fit-content; margin: 0 auto;
  padding: 5px 10px;
  backdrop-filter: blur(4px);
}
.page-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: rgba(255,255,255,.35);
  transition: background .25s, transform .25s;
}
.page-dot.active {
  background: var(--gold);
  transform: scale(1.5);
  box-shadow: 0 0 8px rgba(251,191,36,.6);
}

/* Text panel: slides up over the illustration bottom with rounded top */
.reader-text-panel {
  flex: 1;
  display: flex; flex-direction: column;
  background: var(--night-2);
  border-radius: 24px 24px 0 0;
  margin-top: -28px;
  position: relative; z-index: 5;
  overflow: hidden;
  box-shadow: 0 -4px 20px rgba(0,0,0,.4);
}

.reader-text-area {
  flex: 1;
  padding: 18px 22px 6px;
  overflow-y: auto; -webkit-overflow-scrolling: touch;
  display: flex; align-items: flex-start;
}
.reader-text {
  font-size: 1.08rem; line-height: 1.75;
  color: rgba(255,255,255,.93); font-weight: 500;
}
#screen-reader.text-large .reader-text {
  font-size: 1.35rem; line-height: 1.8;
}
#screen-reader.text-xlarge .reader-text {
  font-size: 1.65rem; line-height: 1.85;
}
.rss-textsize-btn {
  background: rgba(255,255,255,.08); border: 1px solid rgba(255,255,255,.15);
  color: var(--ink-soft); padding: 5px 12px; border-radius: 8px;
  font-family: inherit; font-size: 0.85rem; font-weight: 800;
  cursor: pointer; transition: background .15s, color .15s;
}
.rss-textsize-btn.active {
  background: var(--purple-mid); border-color: var(--purple-bright); color: #fff;
}
.reader-text .word { transition: background .08s; border-radius: 3px; }
/* Warm storybook-yellow glow; the previous pale wash read as grey. */
.reader-text .word.highlight {
  background: rgba(251,191,36,.32);
  outline: 3px solid rgba(251,191,36,.18);
  outline-offset: 1px;
  color: rgba(255,255,255,.98);
  text-shadow: none;
}

/* Landscape: open-book side-by-side layout */
@media (orientation: landscape) {
  #screen-reader { flex-direction: row; }
  .reader-illustration {
    flex: 0 0 50%;
    height: 100%;
  }
  /* Illustrations are generated in a portrait book-page aspect ratio, which
     doesn't match this landscape column — object-fit:cover was cropping off
     a large chunk of every image. contain shows the full illustration,
     letterboxed against the scene backdrop color instead of cropped. */
  #reader-img { object-fit: contain; }
  .reader-text-panel {
    border-radius: 0;
    margin-top: 0;
    border-left: 1px solid rgba(255,255,255,.07);
    box-shadow: none;
  }
  .reader-text-area { padding: 20px 24px 6px; align-items: center; padding-top: 24px; }
}

.reader-controls {
  display: flex; align-items: center; justify-content: center; gap: 22px;
  padding: 10px 0 calc(14px + env(safe-area-inset-bottom, 0px));
  flex-shrink: 0;
}
.reader-nav-btn {
  width: 52px; height: 52px; border-radius: 50%;
  background: rgba(255,255,255,.1);
  border: 1px solid rgba(255,255,255,.1);
  color: rgba(255,255,255,.85); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  padding: 0; transition: background .12s;
}
.reader-nav-btn svg { width: 22px; height: 22px; display: block; }
.reader-nav-btn:active { background: rgba(255,255,255,.22); }
.reader-replay-btn {
  width: 44px; height: 44px; border-radius: 50%;
  background: rgba(255,255,255,.08);
  border: 1px solid rgba(255,255,255,.1);
  color: rgba(255,255,255,.75); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  padding: 0; transition: background .12s, transform .1s;
}
.reader-replay-btn svg { width: 18px; height: 18px; display: block; }
.reader-replay-btn:active { background: rgba(255,255,255,.2); transform: scale(.88); }
.reader-play-btn {
  width: 66px; height: 66px; border-radius: 50%;
  background: linear-gradient(135deg, var(--purple-mid), var(--purple));
  border: none; color: #fff; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  padding: 0;
  box-shadow: 0 4px 24px rgba(139,92,246,.6), 0 0 0 4px rgba(139,92,246,.15);
  transition: transform .12s, box-shadow .12s;
}
.reader-play-btn:active { transform: scale(.9); box-shadow: 0 2px 10px rgba(139,92,246,.4); }
.reader-play-btn svg, .reader-play-btn .icon-loading { display: none; width: 26px; height: 26px; }
.reader-play-btn[data-state="play"] .icon-play { display: block; }
.reader-play-btn[data-state="pause"] .icon-pause { display: block; }
.reader-play-btn[data-state="loading"] .icon-loading { display: block; }
.icon-loading {
  width: 26px; height: 26px; border-radius: 50%;
  border: 3px solid rgba(255,255,255,.35);
  border-top-color: #fff;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.reader-progress-row {
  display: flex; align-items: center; gap: 10px;
  padding: 0 20px 12px;
  flex-shrink: 0;
}
.reader-progress-bar {
  height: 3px; background: rgba(255,255,255,.08);
  flex: 1; border-radius: 100px; overflow: hidden;
}
.reader-progress-fill {
  height: 100%;
  background: linear-gradient(to right, var(--purple-mid), var(--purple-bright));
  transition: width .5s linear;
  box-shadow: 0 0 8px rgba(139,92,246,.5);
}
.reader-page-count {
  flex-shrink: 0;
  font-size: .72rem; font-weight: 700; color: var(--ink-soft);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* Auto-play countdown bar */
.reader-autoplay-bar {
  height: 2px; background: transparent; flex-shrink: 0;
}
.reader-autoplay-fill {
  height: 100%; width: 0%;
  background: linear-gradient(to right, var(--teal), var(--green));
  box-shadow: 0 0 6px rgba(34,211,238,.6);
}

/* ── READER SETTINGS SHEET ────────────────────────────────── */
/* Structural overlay/backdrop/handle mechanics now come from the shared
   .mode-picker/.mode-picker-backdrop/.mode-picker-sheet/.mode-picker-handle
   classes (applied alongside these in the HTML) — this used to be a
   parallel reimplementation of the exact same bottom-sheet pattern.
   .rss-panel only carries what's genuinely distinct: a slightly different
   panel background/radius and its own content layout (flex column with a
   consistent 20px gap between sections, vs. mode-picker's own default). */
.rss-panel {
  background: #1a1535;
  border-radius: 20px 20px 0 0;
  padding: 12px 20px calc(24px + env(safe-area-inset-bottom, 0px));
  display: flex; flex-direction: column; gap: 20px;
}
.rss-title {
  font-size: 1rem; font-weight: 700; color: var(--ink); text-align: center;
}
.rss-section {
  display: flex; flex-direction: column; gap: 10px;
  border-top: 1px solid rgba(255,255,255,.08); padding-top: 16px;
}
.rss-section:first-of-type { border-top: none; padding-top: 0; }
.rss-section-label {
  font-size: .73rem; font-weight: 700; letter-spacing: .06em;
  color: var(--ink-soft); text-transform: uppercase;
}

/* Toggle rows */
.rss-toggle-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.rss-row-label { font-size: .95rem; font-weight: 600; color: var(--ink); }
.rss-row-sub { font-size: .75rem; color: var(--ink-soft); margin-top: 2px; }
.rss-toggle {
  width: 48px; height: 28px; border-radius: 14px;
  background: rgba(255,255,255,.15); border: none; cursor: pointer;
  padding: 3px; flex-shrink: 0; transition: background .2s;
  display: flex; align-items: center;
}
.rss-toggle[data-on="true"] { background: var(--purple); }
.rss-toggle-knob {
  width: 22px; height: 22px; border-radius: 50%;
  background: #fff; display: block;
  transform: translateX(0); transition: transform .2s;
  box-shadow: 0 1px 4px rgba(0,0,0,.3);
}
.rss-toggle[data-on="true"] .rss-toggle-knob { transform: translateX(20px); }

/* Speed & Timer Pickers */
.rss-speed-picker, .rss-timer-picker {
  display: flex; gap: 4px; background: rgba(255,255,255,.08);
  padding: 3px; border-radius: 20px; border: 1px solid rgba(255,255,255,.1);
}
.rss-speed-btn, .rss-timer-btn, .rss-narrator-btn {
  background: transparent; border: none; color: var(--ink-soft);
  font-family: inherit; font-size: .8rem; font-weight: 700;
  padding: 5px 11px; border-radius: 16px; cursor: pointer;
  transition: background .15s, color .15s;
}
.rss-speed-btn.active, .rss-timer-btn.active, .rss-narrator-btn.active {
  background: var(--purple-mid); color: #fff;
  box-shadow: 0 2px 8px rgba(124,58,237,.4);
}

/* Sleepy Night Mode Overlay */
.sleepy-overlay {
  position: absolute; inset: 0; z-index: 40;
  background: rgba(251, 146, 60, 0.12);
  mix-blend-mode: multiply;
  pointer-events: none;
  opacity: 0; transition: opacity .4s ease;
}
#screen-reader.sleepy-mode .sleepy-overlay { opacity: 1; }
#screen-reader.sleepy-mode #reader-img { filter: brightness(.85) contrast(.95); }

/* ── END SCREEN ──────────────────────────────────────────── */
#screen-end {
  justify-content: center; align-items: center;
  background: radial-gradient(ellipse at center, #2d1270 0%, #080613 70%);
}
.end-scene { text-align: center; padding: 32px 28px; }
.end-stars {
  font-size: 2.2rem; letter-spacing: 16px; margin-bottom: 24px;
  filter: drop-shadow(0 0 10px rgba(251,191,36,.8));
  animation: pulse-star 2s ease-in-out infinite;
}
.end-title {
  font-size: 2.6rem; font-weight: 800; color: var(--ink);
  margin-bottom: 10px; text-shadow: 0 0 30px rgba(139,92,246,.5);
}
.end-sub { font-size: .92rem; color: var(--ink-soft); margin-bottom: 44px; font-style: italic; }
.end-actions { display: flex; flex-direction: column; align-items: center; gap: 12px; }
.end-actions .primary-btn { max-width: 280px; }

/* ── PAYWALL ─────────────────────────────────────────────── */
#screen-paywall { background: radial-gradient(ellipse at top, #1e1060 0%, var(--night) 65%); }
.paywall-body {
  display: flex; flex-direction: column; align-items: center;
  padding: 28px 28px 60px; gap: 20px; text-align: center;
}
.paywall-icon {
  font-size: 4.5rem; line-height: 1;
  filter: drop-shadow(0 0 16px rgba(251,191,36,.5));
}
.paywall-title { font-size: 1.6rem; font-weight: 800; color: var(--ink); }
.paywall-desc { font-size: .9rem; color: var(--ink-soft); line-height: 1.65; max-width: 300px; }
.paywall-coming {
  background: rgba(251,191,36,.1);
  border: 1px solid rgba(251,191,36,.3);
  border-radius: var(--r); padding: 16px 18px;
  display: flex; flex-direction: column; gap: 8px; width: 100%;
}
.paywall-coming-badge {
  display: inline-block;
  background: linear-gradient(135deg, var(--gold), #f97316);
  color: #fff;
  font-size: .72rem; font-weight: 800; border-radius: 100px;
  padding: 3px 12px; letter-spacing: .07em; text-transform: uppercase;
}
.paywall-coming p { font-size: .85rem; color: var(--gold-soft); font-weight: 600; line-height: 1.5; }
.paywall-body .primary-btn { max-width: 300px; }
.paywall-balance {
  margin: 10px auto 0; padding: 6px 14px; border-radius: 999px; display: inline-block;
  font-size: .85rem; font-weight: 700; color: var(--gold);
  background: rgba(251,191,36,.1); border: 1px solid rgba(251,191,36,.3);
}
.paywall-balance[hidden] { display: none; }
.paywall-legal { font-size: .72rem; color: var(--ink-soft); line-height: 1.55; max-width: 360px; margin: 16px auto 0; text-align: center; }
.paywall-legal-links { font-size: .75rem; color: var(--ink-soft); margin: 6px 0 0; display: flex; gap: 8px; justify-content: center; }
.paywall-legal-links a { color: var(--ink-soft); text-decoration: underline; }

/* ── LIBRARY ─────────────────────────────────────────────── */
.library-grid { padding: 8px 18px 60px; display: flex; flex-direction: column; gap: 10px; }
.library-card {
  display: flex; align-items: center; gap: 14px;
  padding: 14px;
  background: var(--surface);
  border: 1px solid rgba(255,255,255,.08);
  border-radius: var(--r-lg); cursor: pointer;
  transition: transform .1s, background .15s;
  backdrop-filter: blur(8px);
}
.library-card:active { transform: scale(.98); background: rgba(255,255,255,.1); }
.library-card { width: 100%; text-align: left; font-family: inherit; color: inherit; }
.library-card-thumb {
  width: 52px; height: 72px; border-radius: 8px; overflow: hidden;
  flex-shrink: 0; display: flex; align-items: center; justify-content: center;
}
.library-card-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.library-card-info .cr-progress-track { margin-top: 8px; }
.library-section-title {
  font-size: .8rem; font-weight: 800; color: var(--ink-soft);
  text-transform: uppercase; letter-spacing: .06em;
  margin: 10px 4px 2px;
}
.library-card-info { flex: 1; min-width: 0; }
.library-card-title {
  font-size: .95rem; font-weight: 800; color: var(--ink);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.library-card-meta { font-size: .75rem; color: var(--ink-soft); margin-top: 3px; }
.library-card-actions { display: flex; }
.lib-action-btn {
  background: none; border: none; cursor: pointer;
  font-size: 1.1rem; padding: 6px; border-radius: 8px;
  color: var(--ink-soft); transition: color .15s;
}
.lib-action-btn:active { color: var(--rose); }
.library-empty {
  text-align: center; padding: 60px 24px; color: var(--ink-soft);
}
.library-empty-icon { font-size: 3.5rem; display: block; margin-bottom: 14px; }
.resume-badge {
  display: inline-block; margin-top: 5px;
  background: rgba(139,92,246,.25); color: var(--purple-bright);
  font-size: .7rem; font-weight: 800; border-radius: 100px;
  padding: 2px 9px; border: 1px solid rgba(139,92,246,.3);
}

.loading-line { color: var(--ink-soft); font-size: .9rem; padding: 20px; }

/* ── MODE PICKER ─────────────────────────────────────────── */
.mode-picker {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: flex-end;
}
.mode-picker.hidden { display: none; }
.mode-picker-backdrop {
  position: absolute; inset: 0;
  background: rgba(0,0,0,.65); backdrop-filter: blur(4px);
}
.mode-picker-sheet {
  position: relative; z-index: 1;
  width: 100%;
  background: var(--night-3);
  border-top: 1px solid rgba(255,255,255,.1);
  border-radius: 28px 28px 0 0;
  padding: 12px 20px 40px;
  box-shadow: 0 -12px 40px rgba(0,0,0,.5);
  animation: slide-up .25s ease;
  /* Never taller than the screen: on short screens (iPad or phone in
     landscape) the sheet's top — and its close button — used to be pushed
     off the top edge. The sheet scrolls instead. */
  max-height: calc(100vh - 12px);
  max-height: calc(100dvh - env(safe-area-inset-top, 0px) - 12px);
  overflow-y: auto;
  overscroll-behavior: contain;
}
@keyframes slide-up {
  from { transform: translateY(100%); }
  to   { transform: translateY(0); }
}
/* Close button row at the top of every bottom sheet (replaced the drag
   handle, which suggested a swipe-to-close that never existed). */
.sheet-topbar { display: flex; justify-content: flex-end; margin: 8px 4px 2px; }
.sheet-close-x {
  width: 40px; height: 40px; border-radius: 50%; padding: 0; flex-shrink: 0;
  display: grid; place-items: center; cursor: pointer;
  background: rgba(255,255,255,.07); border: 1px solid rgba(255,255,255,.12); color: var(--ink-soft);
}
.sheet-close-x:hover { color: var(--ink); background: rgba(255,255,255,.12); }
.sheet-close-x svg { width: 18px; height: 18px; }
.mode-picker-title {
  font-size: 1rem; font-weight: 800; color: var(--ink);
  text-align: center; margin-bottom: 20px; letter-spacing: -.01em;
}
.mode-picker-options { display: flex; flex-direction: column; gap: 10px; }
.mode-option {
  display: flex; align-items: center; gap: 14px;
  padding: 16px;
  background: rgba(255,255,255,.06);
  border: 1px solid rgba(255,255,255,.1);
  border-radius: var(--r-lg); cursor: pointer;
  text-align: left; transition: background .12s, transform .1s;
  width: 100%;
}
.mode-option:active { background: rgba(255,255,255,.12); transform: scale(.98); }
.mode-option-icon { font-size: 1.8rem; flex-shrink: 0; line-height: 1; }
.mode-option-body { flex: 1; }
.mode-option-label { font-size: 1rem; font-weight: 800; color: var(--ink); }
.mode-option-sub { font-size: .8rem; color: var(--ink-soft); margin-top: 2px; }
.mode-option-arrow { font-size: 1.3rem; color: var(--ink-soft); }

/* ── STORY PREVIEW SHEET ─────────────────────────────────── */
.story-preview-sheet {
  padding: 0 0 calc(20px + env(safe-area-inset-bottom, 0px)) !important;
  overflow-x: hidden;
}
.story-preview-sheet .mode-picker-handle {
  position: absolute; top: 12px; left: 50%; transform: translateX(-50%); z-index: 2;
}
.sp-hero {
  position: relative; height: 260px; overflow: hidden;
  background: linear-gradient(160deg, #3b1f8c, #6d3fc4);
}
.sp-close-btn {
  position: absolute; top: 12px; right: 12px; z-index: 3;
  width: 44px; height: 44px; border-radius: 50%; padding: 0;
  background: rgba(8,6,19,.55); border: 1px solid rgba(255,255,255,.18);
  backdrop-filter: blur(8px); color: #fff; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.sp-close-btn svg { width: 18px; height: 18px; }
/* Short screens: a smaller cover so the whole sheet usually fits unscrolled. */
@media (max-height: 820px) {
  .sp-hero { height: clamp(140px, 30vh, 260px); }
}
.sp-cover {
  width: 100%; height: 100%; object-fit: cover; object-position: top;
  opacity: 0; transition: opacity .4s ease;
}
.sp-cover.loaded { opacity: 1; }
.sp-hero-grad {
  position: absolute; inset: 0;
  background: linear-gradient(to bottom, transparent 30%, rgba(13,11,30,.9) 100%);
}
.sp-body {
  padding: 16px 20px 8px;
}
.sp-title {
  font-size: 1.3rem; font-weight: 800; color: var(--ink); margin-bottom: 6px;
}
.sp-meta {
  display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px;
}
.sp-meta-chip {
  background: rgba(255,255,255,.09); border: 1px solid rgba(255,255,255,.12);
  border-radius: 20px; padding: 3px 10px;
  font-size: .75rem; color: var(--ink-soft); font-weight: 600;
}
.sp-summary {
  font-size: .9rem; color: var(--ink-soft); line-height: 1.6;
  margin-bottom: 4px;
}
.sp-actions { padding: 0 20px 4px; }

/* Per-story language selector */
.sp-lang-row {
  display: flex; align-items: center; gap: 8px;
  padding: 2px 20px 14px;
}
.sp-lang-label {
  font-size: .75rem; font-weight: 700; color: var(--ink-soft);
  letter-spacing: .02em; margin-right: 4px;
}
.sp-lang-btn {
  display: flex; align-items: center; gap: 5px;
  background: rgba(255,255,255,.08); border: 2px solid transparent;
  border-radius: 10px; padding: 6px 10px; cursor: pointer;
  flex-shrink: 0;
  transition: background .15s, border-color .15s, transform .1s;
}
.sp-lang-btn:active { transform: scale(.9); }
.sp-lang-btn.active {
  border-color: var(--purple);
  background: rgba(139,92,246,.2);
}
.sp-lang-bg-flag {
  font-size: 1.15rem; line-height: 1;
  user-select: none;
}
.sp-lang-code {
  font-size: .72rem; font-weight: 900; letter-spacing: .04em;
  color: rgba(255,255,255,.9);
  font-family: inherit;
}

/* Read Myself / Read Aloud cards (scoped so the shared .mode-option base
   used by the exit-sheet and language-sheet stays untouched) */
.sp-mode-icon {
  width: 46px; height: 46px; border-radius: 13px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
}
.sp-mode-icon svg { width: 21px; height: 21px; }
.sp-mode-icon-purple { background: linear-gradient(135deg, var(--purple-mid), var(--purple)); }
.sp-mode-icon-gold { background: linear-gradient(135deg, var(--color-warning), var(--gold)); }
.sp-mode-featured {
  position: relative;
  border-color: var(--gold);
  background: rgba(251,191,36,.08);
}
.sp-mode-ribbon {
  position: absolute; top: -9px; left: 16px;
  background: var(--gold); color: #3a2a03;
  font-size: .6rem; font-weight: 900; letter-spacing: .03em;
  padding: 2px 9px; border-radius: 100px;
}


/* ── EXIT CONFIRMATION SHEET ─────────────────────────────── */
.exit-sheet-panel {
  padding-bottom: calc(28px + env(safe-area-inset-bottom, 0px));
}
.exit-sheet-title {
  font-size: 1.1rem; font-weight: 700; color: var(--ink);
  text-align: center; margin: 4px 0 20px;
}
.exit-sheet-options { display: flex; flex-direction: column; gap: 10px; margin-bottom: 16px; }
.exit-sheet-cancel { width: 100%; }
.exit-icon { display: flex; align-items: center; justify-content: center; }
.exit-icon svg { width: 20px; height: 20px; display: block; }
.mode-option[data-locked="1"] { opacity: .55; }
.mode-option[data-locked="1"] .mode-option-arrow::after { content: ' 🔒'; font-size: .9rem; }

/* ── END-OF-STORY POPUP ─────────────────────────────────── */
.end-popup {
  position: fixed; inset: 0; z-index: 900;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.end-popup-backdrop {
  position: absolute; inset: 0;
  background: rgba(4,2,18,.75);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
.end-popup-card {
  position: relative; z-index: 1; overflow: hidden;
  background: linear-gradient(160deg, var(--night-3) 0%, #0d0828 100%);
  border: 1px solid rgba(139,92,246,.25);
  border-radius: 24px;
  padding: 36px 28px 32px;
  text-align: center;
  max-width: 340px; width: 100%;
  box-shadow: 0 24px 60px rgba(0,0,0,.6), 0 0 0 1px rgba(139,92,246,.15);
}
.end-popup-card::before {
  content: '';
  position: absolute; inset: 0; z-index: 0; pointer-events: none;
  opacity: .05; mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}
.end-popup-card > * { position: relative; z-index: 1; }
.end-popup-stars {
  font-size: 1.8rem; letter-spacing: 12px; margin-bottom: 18px;
  filter: drop-shadow(0 0 8px rgba(251,191,36,.8));
  animation: pulse-star 2s ease-in-out infinite;
}
.end-popup-title {
  font-size: 2.2rem; font-weight: 800; color: var(--ink);
  margin-bottom: 8px; text-shadow: 0 0 24px rgba(139,92,246,.5);
}
.end-popup-sub {
  font-size: .88rem; color: var(--ink-soft); margin-bottom: 32px; font-style: italic;
}
.end-popup-actions { display: flex; flex-direction: column; gap: 12px; }
.end-popup-actions .primary-btn, .end-popup-actions .ghost-btn { width: 100%; }

/* Deliberately subtler than the primary/ghost buttons above — this is an
   upsell offered at a high-intent moment, not the primary action, so it
   shouldn't visually compete with "Read again" / "Home screen". */
.end-popup-upsell {
  display: block; width: 100%; margin-top: 14px; padding: 10px;
  background: none; border: none; cursor: pointer;
  font-family: inherit; font-size: .82rem; font-weight: 700;
  color: var(--gold); text-align: center;
}
.end-popup-upsell:active { opacity: .7; }

.review-stars {
  display: flex; justify-content: center; gap: 4px;
  margin-bottom: 10px;
}
.review-stars svg {
  width: 26px; height: 26px;
  filter: drop-shadow(0 0 6px rgba(251,191,36,.6));
}

/* ── TOAST ───────────────────────────────────────────────── */
.toast {
  position: fixed; bottom: calc(96px + env(safe-area-inset-bottom, 0px)); left: 50%;
  transform: translateX(-50%) translateY(70px);
  background: rgba(30,24,64,.95);
  border: 1px solid rgba(255,255,255,.12);
  backdrop-filter: blur(16px);
  color: var(--ink);
  padding: 12px 24px; border-radius: 100px;
  font-size: .88rem; font-weight: 700;
  box-shadow: 0 8px 32px rgba(0,0,0,.5);
  opacity: 0; pointer-events: none; z-index: 999;
  transition: transform .3s ease, opacity .3s ease;
  white-space: nowrap;
}
.toast.show { transform: translateX(-50%) translateY(0); opacity: 1; }

/* ── CREDITS BADGE ──────────────────────────────────────── */
.credits-badge {
  display: flex; align-items: center; gap: 4px;
  background: rgba(251,191,36,.15);
  border: 1px solid rgba(251,191,36,.3);
  border-radius: 20px;
  padding: 4px 10px;
  font-size: .78rem; font-weight: 800; color: var(--gold);
  font-family: inherit; cursor: pointer; transition: background .15s, transform .1s;
  white-space: nowrap;
}
.credits-badge.hidden { display: none !important; }
.credits-badge:active { background: rgba(251,191,36,.28); transform: scale(.94); }

/* ── AUTH SHEET ─────────────────────────────────────────── */
.auth-sheet-panel {
  padding: 0 20px calc(32px + env(safe-area-inset-bottom, 0px));
  display: flex; flex-direction: column; gap: 0;
}
.auth-header { text-align: center; padding: 24px 0 20px; }
.auth-logo {
  font-size: 2rem; color: var(--gold); margin-bottom: 10px;
}
.auth-title { font-size: 1.3rem; font-weight: 800; color: var(--ink); margin-bottom: 6px; }
.auth-sub { font-size: .875rem; color: var(--ink-soft); line-height: 1.5; }
.auth-social { display: flex; flex-direction: column; gap: 10px; }
.auth-btn {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  width: 100%; padding: 14px 20px; border-radius: var(--r);
  font-size: .95rem; font-weight: 700; border: none; cursor: pointer;
  transition: opacity .15s;
}
.auth-btn:active { opacity: .8; }
.auth-btn-apple {
  background: #111; color: #fff;
}
.auth-btn-google {
  background: #fff; color: #1f1f1f;
  border: 1px solid rgba(0,0,0,.12);
}
.auth-btn-icon {
  width: 20px; height: 20px;
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 1rem;
}
.auth-divider {
  display: flex; align-items: center; gap: 12px;
  margin: 16px 0;
}
.auth-divider::before, .auth-divider::after {
  content: ''; flex: 1; height: 1px;
  background: rgba(255,255,255,.12);
}
.auth-divider span { font-size: .78rem; color: var(--ink-soft); font-weight: 600; }
.auth-email-form { display: flex; flex-direction: column; gap: 10px; }
.auth-input {
  width: 100%; padding: 13px 16px;
  background: rgba(255,255,255,.07);
  border: 1px solid rgba(255,255,255,.12);
  border-radius: var(--r);
  color: var(--ink); font-size: .95rem;
  outline: none; transition: border-color .2s;
}
.auth-input:focus { border-color: var(--purple); }
.auth-error {
  font-size: .82rem; color: var(--rose);
  min-height: 1em; text-align: center;
}
/* Shared by every plain-text button in the app (previously .auth-toggle-btn,
   .auth-dismiss-btn, and .auth-forgot-link each independently redeclared
   background:none/border:none/cursor:pointer/padding — the same small
   component reinvented three times, twice in the same auth sheet). New
   text-only buttons should add this class and override only what's
   actually distinct: color, alignment, underline, sizing. */
.text-link-btn { background: none; border: none; cursor: pointer; font-family: inherit; padding: 4px; }

.auth-toggle-btn {
  color: var(--ink-soft); font-size: .82rem;
  text-decoration: underline; text-underline-offset: 2px;
}
.auth-dismiss-btn {
  color: rgba(255,255,255,.3); font-size: .78rem;
  text-align: center; width: 100%; margin-top: 4px;
}
.auth-forgot-link {
  color: var(--ink-soft); font-size: .78rem; padding: 2px 4px 0;
  text-align: right; width: 100%; text-decoration: underline;
  text-underline-offset: 2px; margin-bottom: 4px;
}

/* ── ACCOUNT SHEET ──────────────────────────────────────── */
.account-sheet-panel {
  padding: 0 24px calc(20px + env(safe-area-inset-bottom, 0px));
  display: flex; flex-direction: column; gap: 14px;
}
/* Centered profile header: initial in a circle, email, plan. */
.account-info {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  padding: 0 0 6px; text-align: center;
}
.account-avatar {
  width: 68px; height: 68px;
  background: linear-gradient(135deg, var(--purple-mid), var(--purple-bright));
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.8rem; font-weight: 800; color: #fff; flex-shrink: 0;
  box-shadow: 0 8px 24px rgba(124, 58, 237, .35), inset 0 0 0 2px rgba(255,255,255,.15);
}
.account-plan-badge {
  font-size: .75rem; font-weight: 700; color: var(--gold);
  background: rgba(251, 191, 36, 0.12);
  border: 1px solid rgba(251, 191, 36, 0.25);
  padding: 3px 10px; border-radius: 12px;
  display: inline-block;
}

/* ── PARENT GATE SHEET ────────────────────────────────────── */
/* ── WELCOME BANNER ────────────────────────────────────────── */
.welcome-banner {
  background: linear-gradient(135deg, rgba(124, 58, 237, 0.3), rgba(251, 191, 36, 0.2));
  border: 1px solid rgba(251, 191, 36, 0.4);
  border-radius: 14px; margin: 0 16px 14px; padding: 10px 14px;
}
.welcome-banner.hidden { display: none; }
.welcome-banner-content {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  font-size: .82rem; color: var(--ink);
}
.welcome-banner-btn {
  background: var(--gold); color: #000; font-family: inherit; font-size: .78rem; font-weight: 800;
  border: none; border-radius: 12px; padding: 0 12px; min-height: 36px; cursor: pointer; flex-shrink: 0;
}
.welcome-banner-close {
  background: none; border: none; color: var(--ink-soft); font-size: 1rem; cursor: pointer;
  width: 44px; height: 44px; margin: -10px -12px -10px -6px; flex-shrink: 0;
}

/* ── HELP & KB SHEET ─────────────────────────────────────── */
.help-sheet-panel {
  padding: 0 20px calc(32px + env(safe-area-inset-bottom, 0px));
  display: flex; flex-direction: column; gap: 14px;
}
.help-header { text-align: center; padding-top: 12px; }
.help-icon { font-size: 2.2rem; margin-bottom: 4px; }
.help-title { font-size: 1.25rem; font-weight: 800; color: var(--ink); }
.help-sub { font-size: .85rem; color: var(--ink-soft); margin-top: 2px; }
.help-faq-list { display: flex; flex-direction: column; gap: 10px; margin: 10px 0; }
.help-faq-item {
  background: rgba(255,255,255,.05); border: 1px solid rgba(255,255,255,.1);
  border-radius: 12px; padding: 12px 14px; font-size: .88rem; text-align: left;
}
.help-faq-question { font-weight: 700; color: var(--ink); cursor: pointer; outline: none; }
.help-faq-answer { margin-top: 8px; color: var(--ink-soft); font-size: .82rem; line-height: 1.5; }
.help-code-box {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  background: rgba(251, 191, 36, 0.15); border: 1px solid rgba(251, 191, 36, 0.3);
  padding: 8px 12px; border-radius: 10px; margin-top: 8px;
}
.help-code-box.hidden { display: none; }
/* The rest of the app disables text selection (html, body user-select:none,
   near the top of this file) so normal navigation doesn't trigger accidental
   text-selection handles — but that also silently made this code
   uncopyable by long-press, defeating the point of "revealing" it. */
.help-code-text {
  font-family: monospace; font-size: 1.1rem; font-weight: 800; color: var(--gold);
  user-select: text; -webkit-user-select: text;
}
.help-apply-btn { font-size: .78rem; padding: 6px 12px; width: auto; }

/* ── FEEDBACK SHEET ──────────────────────────────────────── */
.feedback-sheet-panel {
  padding: 0 20px calc(32px + env(safe-area-inset-bottom, 0px));
  display: flex; flex-direction: column; gap: 4px;
}
.feedback-category-row {
  display: flex; flex-wrap: wrap; gap: 8px;
  justify-content: center; margin: 10px 0 4px;
}
.feedback-cat-btn {
  background: rgba(255,255,255,.06); border: 1px solid rgba(255,255,255,.14);
  color: var(--ink-soft); font-family: inherit; font-size: .78rem; font-weight: 700;
  padding: 7px 13px; border-radius: 100px; cursor: pointer;
  transition: background .15s, color .15s, border-color .15s;
}
.feedback-cat-btn.active {
  background: linear-gradient(135deg, var(--purple-mid), var(--purple));
  border-color: rgba(167,139,250,.5); color: #fff;
  box-shadow: 0 2px 10px rgba(139,92,246,.4);
}
.feedback-textarea {
  width: 100%; margin-top: 10px;
  background: rgba(255,255,255,.05); border: 1px solid rgba(255,255,255,.15);
  border-radius: var(--r); color: var(--ink);
  font-family: inherit; font-size: .92rem; line-height: 1.5;
  padding: 12px 14px; resize: vertical; min-height: 100px;
}
.feedback-textarea:focus { border-color: var(--purple); outline: none; }
.feedback-textarea::placeholder { color: var(--ink-soft); opacity: .6; }
.parent-gate-header { text-align: center; padding-top: 12px; }
.parent-gate-icon { font-size: 2.2rem; margin-bottom: 6px; }
.parent-gate-title { font-size: 1.25rem; font-weight: 800; color: var(--ink); }
.parent-gate-sub { font-size: .85rem; color: var(--ink-soft); margin-top: 4px; }
.delete-play-note {
  font-size: .8rem; line-height: 1.45; color: var(--ink-soft); text-align: left;
  background: rgba(251,191,36,.08); border: 1px solid rgba(251,191,36,.25);
  border-radius: 12px; padding: 10px 12px; width: 100%; margin: 6px 0 12px;
}
.delete-play-note strong { color: var(--gold-soft); }
.parent-gate-question {
  font-size: 1.4rem; font-weight: 800; color: var(--gold);
  background: rgba(255,255,255,.06); border: 1px solid rgba(255,255,255,.12);
  padding: 12px 24px; border-radius: var(--r); width: 100%;
}
.parent-gate-input { text-align: center; font-size: 1.2rem; font-weight: 800; letter-spacing: 2px; }
.parent-gate-panel .primary-btn, .parent-gate-panel .ghost-btn, .parent-gate-panel .danger-btn { width: 100%; }
.account-email {
  font-size: .95rem; font-weight: 700; color: var(--ink);
  word-break: break-all; max-width: 100%;
}
/* Balance card: the number is the point of this sheet. */
.account-credits-row {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  background: radial-gradient(ellipse at top, rgba(251,191,36,.14), rgba(255,255,255,.04) 70%);
  border: 1px solid rgba(251,191,36,.22);
  border-radius: var(--r-lg, 20px);
  padding: 18px 18px 16px;
}
.account-credits-icon { font-size: 1rem; color: var(--gold); opacity: .85; }
.account-credits-label { font-size: .8rem; color: var(--ink-soft); font-weight: 700; letter-spacing: .02em; }
.account-credits-value {
  font-size: 2.6rem; line-height: 1.05; font-weight: 800; color: var(--gold);
}
.account-links {
  display: flex; align-items: center; justify-content: center; gap: 4px;
  margin-top: 2px; padding-top: 12px;
  border-top: 1px solid rgba(255,255,255,.08);
}
.account-link {
  min-height: 44px; padding: 8px 14px; border: 0; background: none; cursor: pointer;
  color: var(--ink-soft); font-size: .88rem; font-weight: 700; border-radius: 12px;
}
.account-link:hover, .account-link:focus-visible { color: var(--ink); background: rgba(255,255,255,.06); }
.account-links-sep { width: 1px; height: 18px; background: rgba(255,255,255,.14); }
.promo-row {
  display: flex; gap: 8px; align-items: center;
}
.promo-input { flex: 1; margin: 0; }
.promo-btn {
  flex-shrink: 0; padding: 0 18px; height: 46px;
  background: rgba(255,255,255,.1); border: 1px solid rgba(255,255,255,.18);
  border-radius: var(--r); color: var(--ink); font-size: .88rem; font-weight: 600;
  cursor: pointer; transition: background .18s;
}
.promo-btn:hover { background: rgba(255,255,255,.17); }
.promo-btn:disabled { opacity: .45; cursor: default; }
.promo-msg {
  font-size: .82rem; min-height: 1em; text-align: center; margin-top: -4px;
}
/* No message yet: don't leave a blank gap under the promo field. */
.account-sheet-panel .promo-msg:empty { display: none; }
.promo-msg-ok { color: var(--sage, var(--color-success)); }
.promo-msg-err { color: var(--rose); }

/* ── STORY PREVIEW OFFLINE ROW ──────────────────────────── */
.sp-offline-row {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 0 4px;
}
.sp-offline-row.hidden { display: none; }
.sp-offline-status {
  font-size: .8rem; color: var(--ink-soft);
}
.sp-offline-status.sp-offline-cached { color: var(--sage, var(--color-success)); font-weight: 600; }
.sp-offline-status.sp-offline-error  { color: var(--rose); }
.sp-dl-btn {
  background: rgba(255,255,255,.09); border: 1px solid rgba(255,255,255,.15);
  border-radius: 20px; padding: 5px 14px;
  font-size: .8rem; font-weight: 600; color: var(--ink);
  cursor: pointer; transition: background .18s;
}
.sp-dl-btn:hover { background: rgba(255,255,255,.16); }
.sp-dl-btn:disabled { opacity: .5; cursor: default; }
.sp-dl-btn.hidden { display: none; }

/* ── UNLOCK CONFIRM SHEET ───────────────────────────────── */
.unlock-sheet-panel {
  padding: 0 20px calc(32px + env(safe-area-inset-bottom, 0px));
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  text-align: center;
}
.unlock-icon { font-size: 2.4rem; padding: 20px 0 4px; }
.unlock-title { font-size: 1.2rem; font-weight: 800; color: var(--ink); }
.unlock-desc { font-size: .88rem; color: var(--ink-soft); line-height: 1.5; }
.unlock-balance { font-size: .88rem; color: var(--ink-soft); }
.unlock-sheet-panel .primary-btn, .unlock-sheet-panel .ghost-btn { width: 100%; }

/* ── PAYWALL PACKS ──────────────────────────────────────── */
.paywall-packs {
  display: flex; flex-direction: column; gap: 10px;
  width: 100%; margin: 16px 0;
}
.paywall-pack {
  background: rgba(255,255,255,.06);
  border: 1px solid rgba(255,255,255,.1);
  border-radius: var(--r);
  padding: 14px 18px;
  display: flex; flex-direction: column; gap: 2px;
  position: relative;
}
.paywall-pack.featured {
  border-color: var(--purple);
  background: rgba(139,92,246,.12);
}
.pack-best {
  position: absolute; top: -10px; left: 16px;
  background: var(--purple); color: #fff;
  font-size: .7rem; font-weight: 800;
  padding: 3px 10px; border-radius: 20px;
}
.pack-label { font-size: 1rem; font-weight: 800; color: var(--ink); }
.pack-credits { font-size: .8rem; color: var(--ink-soft); }
.pack-price { font-size: 1.1rem; font-weight: 800; color: var(--gold); margin-top: 4px; }
.pack-coming {
  font-size: .72rem; color: var(--ink-soft);
  background: rgba(255,255,255,.06);
  border-radius: 20px; padding: 2px 8px;
  display: inline-block; margin-top: 4px; width: fit-content;
}

/* ── RESPONSIVE: wider screens (tablet / desktop) ────────────────────────── */

/* Shelf: 3 columns at tablet width, 4+ at desktop */
@media (min-width: 560px) {
  .shelf-grid {
    grid-template-columns: repeat(3, 1fr);
    max-width: 720px; margin: 0 auto;
    padding: 4px 20px 80px;
  }
  .screen-header { max-width: 720px; margin: 0 auto; width: 100%; }
  .shelf-intro { max-width: 720px; margin: 0 auto; }
}
@media (min-width: 860px) {
  .shelf-grid { grid-template-columns: repeat(4, 1fr); max-width: 960px; }
  .screen-header { max-width: 960px; }
  .shelf-intro { max-width: 960px; }
}

/* Mode picker / story preview: cap width so it doesn't span 1440px */
@media (min-width: 640px) {
  .mode-picker-sheet {
    max-width: 540px;
    margin: 0 auto;
    border-radius: 24px 24px 0 0;
  }
  .mode-picker-backdrop { border-radius: 0; }
}

/* Reader: improve landscape text layout on wide screens */
@media (orientation: landscape) {
  .reader-text-area { align-items: center; }
  .reader-text { max-width: 600px; font-size: 1.1rem; line-height: 1.8; }
}
@media (orientation: landscape) and (min-width: 900px) {
  .reader-illustration { flex: 0 0 52%; }
  .reader-text { font-size: 1.15rem; }
}

/* ── PARENTAL DASHBOARD ─────────────────────────────────────────────────── */
.dashboard-sheet-panel {
  max-width: 760px !important;
  background: #101415 !important;
  border-top: 1px solid rgba(248, 250, 252, 0.15);
  box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.6);
  padding: 24px 20px 28px !important;
}

.dashboard-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 20px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  padding-bottom: 14px;
}

.dashboard-title {
  font-family: 'Quicksand', 'Noto Color Emoji', sans-serif;
  font-size: 1.5rem;
  font-weight: 700;
  color: #f8fafc;
  margin: 0;
}

.dashboard-sub {
  font-size: 0.85rem;
  color: #909097;
  margin: 4px 0 0;
}

.dashboard-gate-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(52, 211, 153, 0.12);
  border: 1px solid rgba(52, 211, 153, 0.3);
  color: var(--green);
  font-size: 0.72rem;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 20px;
  white-space: nowrap;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.gate-dot {
  font-size: 0.6rem;
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

.dashboard-bento-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
  margin-bottom: 20px;
}

@media (min-width: 640px) {
  .dashboard-bento-grid {
    grid-template-columns: 1fr 1fr;
  }
  .dash-card-main {
    grid-column: span 2;
  }
}

.dash-card {
  background: rgba(29, 32, 34, 0.8);
  border: 1px solid rgba(248, 250, 252, 0.1);
  border-radius: 16px;
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.dash-card-danger {
  border-color: rgba(248,113,113,.25);
  background: rgba(248,113,113,.05);
}
.dash-card-danger .dash-card-title { color: var(--color-error); }

.dash-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.dash-card-title {
  font-family: 'Quicksand', 'Noto Color Emoji', sans-serif;
  font-size: 1.05rem;
  font-weight: 700;
  color: #f8fafc;
  margin: 0;
}

.dash-select {
  background: #101415;
  border: 1px solid rgba(144, 144, 151, 0.3);
  color: #c6c6cd;
  border-radius: 10px;
  padding: 4px 10px;
  font-size: 0.78rem;
  outline: none;
}

.dash-stats-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 16px;
}

.dash-stat-box {
  background: #101415;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  padding: 10px 8px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.dash-stat-label {
  font-size: 0.72rem;
  color: #909097;
  font-weight: 600;
  margin-bottom: 2px;
}

.dash-stat-value {
  font-family: 'Quicksand', 'Noto Color Emoji', sans-serif;
  font-size: 1.4rem;
  font-weight: 700;
  color: #f8fafc;
}
.dash-stat-value.text-green { color: var(--green); }
.dash-stat-value.text-purple { color: var(--purple-bright); }
.dash-stat-value small { font-size: 0.75rem; color: #909097; font-weight: 400; }

.dash-chart-container {
  background: #101415;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  padding: 14px 14px 8px;
}

.dash-chart-bars {
  height: 110px;
  display: flex;
  align-items: flex-end;
  justify-content: space-around;
  gap: 8px;
  padding-top: 20px;
}

.dash-bar-col {
  width: 14%;
  height: var(--height, 20%);
  position: relative;
  border-radius: 6px 6px 0 0;
  cursor: pointer;
}

.dash-bar-fill {
  width: 100%;
  height: 100%;
  background: rgba(190, 198, 224, 0.2);
  border-radius: 6px 6px 0 0;
  transition: background 0.2s;
}

.dash-bar-col:hover .dash-bar-fill {
  background: rgba(190, 198, 224, 0.4);
}

.dash-bar-col.active-bar .dash-bar-fill {
  background: var(--purple);
  box-shadow: 0 0 12px rgba(139, 92, 246, 0.5);
}

.dash-bar-tooltip {
  position: absolute;
  top: -22px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.68rem;
  font-weight: 700;
  color: #f8fafc;
  opacity: 0;
  transition: opacity 0.15s;
  white-space: nowrap;
}

.dash-bar-col:hover .dash-bar-tooltip,
.dash-bar-col.active-bar .dash-bar-tooltip {
  opacity: 1;
}

.dash-chart-labels {
  display: flex;
  justify-content: space-around;
  margin-top: 8px;
  font-size: 0.7rem;
  font-weight: 700;
  color: #909097;
}

.dash-balance-box {
  background: #101415;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  padding: 10px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 10px 0;
}

.dash-balance-val {
  font-family: 'Quicksand', 'Noto Color Emoji', sans-serif;
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--gold);
}

.dash-add-btn {
  padding: 6px 14px !important;
  font-size: 0.78rem !important;
  border-radius: 20px !important;
  background: var(--purple) !important;
}

.dash-card-desc {
  font-size: 0.78rem;
  color: #909097;
  line-height: 1.45;
  margin: 4px 0 10px;
}

.dash-link-btn {
  font-size: 0.75rem !important;
  color: var(--purple-bright) !important;
  padding: 4px 0 !important;
  text-align: left;
  width: fit-content;
}

.dash-account-item {
  background: #101415;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  padding: 10px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 10px 0;
}

.dash-item-label {
  font-size: 0.7rem;
  color: #909097;
  font-weight: 600;
}

.dash-item-sub {
  font-size: 0.85rem;
  color: #f8fafc;
  font-weight: 700;
}

.dash-item-badge {
  background: rgba(139, 92, 246, 0.15);
  border: 1px solid rgba(139, 92, 246, 0.3);
  color: #d0bcff;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 12px;
}

.dash-account-actions {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

.dash-account-actions button {
  flex: 1;
  font-size: 0.75rem !important;
  padding: 8px !important;
}

.dash-close-btn {
  width: 100%;
  margin-top: 6px;
  font-size: 0.85rem !important;
}

/* ── ACCESSIBILITY & KEYBOARD FOCUS RINGS ───────────────────────────────── */
*:focus-visible {
  outline: 2px solid var(--purple) !important;
  outline-offset: 3px !important;
  border-radius: 4px;
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 2px solid var(--purple) !important;
  outline-offset: 2px !important;
}


/* ── Accessibility ───────────────────────────────────────── */
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, summary:focus-visible {
  outline: 2px solid var(--gold); outline-offset: 2px;
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important; animation-iteration-count: 1 !important;
    transition-duration: .01ms !important; scroll-behavior: auto !important;
  }
}
.mode-picker-sheet:focus, .end-popup-card:focus { outline: none; }

/* Password field with show/hide eye button */
.pw-field { position: relative; }
.pw-field .auth-input { padding-right: 52px; }
.pw-toggle {
  position: absolute; top: 50%; right: 4px; transform: translateY(-50%);
  width: 44px; height: 44px; border: none; background: none; border-radius: 12px;
  color: var(--ink-soft); cursor: pointer; display: grid; place-items: center;
}
.pw-toggle:hover { color: var(--ink); }
.pw-toggle svg { width: 20px; height: 20px; }
.pw-toggle .pw-eye-off { display: none; }
.pw-toggle[aria-pressed="true"] .pw-eye { display: none; }
.pw-toggle[aria-pressed="true"] .pw-eye-off { display: block; }

/* "New" ribbon on recently added stories (same shape as the Free ribbon) */
.shelf-badge-new {
  background: linear-gradient(135deg, var(--teal), #0ea5e9);
  color: #04263a;
  font-size: .62rem; font-weight: 900;
  padding: 3px 9px 3px 11px;
  margin-left: -10px;
  letter-spacing: .03em;
  clip-path: polygon(0 0, 100% 0, 90% 50%, 100% 100%, 0 100%);
  box-shadow: 0 3px 8px rgba(0,0,0,.3);
}

/* First-launch hints */
.tour-root { position: fixed; inset: 0; z-index: 2000; }
.tour-spot {
  position: fixed; border-radius: 18px; pointer-events: none;
  box-shadow: 0 0 0 9999px rgba(8,6,20,.72), 0 0 0 2px var(--gold), 0 0 24px rgba(251,191,36,.45);
  transition: left .25s ease, top .25s ease, width .25s ease, height .25s ease;
}
.tour-card {
  position: fixed; background: var(--night-3); color: var(--ink);
  border: 1px solid rgba(167,139,250,.35); border-radius: var(--r-lg);
  padding: 18px 18px 14px; box-shadow: var(--sh-card);
  transition: top .25s ease, left .25s ease;
}
.tour-step { font-size: .72rem; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; color: var(--purple-bright); margin-bottom: 6px; }
.tour-title { font-family: 'Quicksand', 'Nunito', sans-serif; font-size: 1.1rem; font-weight: 700; margin: 0 0 6px; }
.tour-body { font-size: .9rem; color: var(--ink-soft); line-height: 1.5; margin: 0 0 14px; }
.tour-actions { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.tour-skip { background: none; border: none; color: var(--ink-soft); font: inherit; font-weight: 700; padding: 10px 6px; min-height: 44px; cursor: pointer; }
.tour-skip[hidden] { display: none; }
.tour-next { margin-left: auto; background: var(--purple-mid); color: #fff; border: none; border-radius: 999px; font: inherit; font-weight: 800; padding: 10px 22px; min-height: 44px; cursor: pointer; }
.tour-next:hover { background: var(--purple); }
@media (prefers-reduced-motion: reduce) {
  .tour-spot, .tour-card { transition: none; }
}

/* Parents dashboard: bedtime tips */
.dash-card-tips { grid-column: 1 / -1; }
.dash-tips { list-style: none; margin: 10px 0 0; padding: 0; display: grid; gap: 12px; }
.dash-tips li {
  font-size: .88rem; line-height: 1.5; color: var(--ink-soft);
  padding-left: 16px; border-left: 2px solid rgba(167,139,250,.45);
}
.dash-tips strong { color: var(--ink); font-weight: 800; }

/* Narrator chooser + narrator buttons in Story Settings */
.narrator-sheet-panel { outline: none; }
.narrator-sheet-title { font-family: 'Quicksand', 'Nunito', sans-serif; font-size: 1.2rem; font-weight: 700; text-align: center; margin: 4px 0 14px; color: var(--ink); }
.narrator-remember { display: flex; align-items: flex-start; gap: 10px; margin: 14px 4px 6px; font-size: .88rem; color: var(--ink-soft); cursor: pointer; line-height: 1.4; }
.narrator-remember input { width: 20px; height: 20px; margin-top: 1px; accent-color: var(--purple); flex-shrink: 0; }
.narrator-cancel { width: 100%; margin-top: 8px; }

/* Sign Out link at the bottom of the Account sheet */

/* ── Offline banner ───────────────────────────────────────── */
.offline-banner {
  position: fixed; z-index: 400; left: 50%; transform: translateX(-50%);
  top: calc(env(safe-area-inset-top, 0px) + 8px);
  max-width: calc(100% - 32px); padding: 8px 14px; border-radius: 999px;
  background: var(--surface-solid); border: 1px solid rgba(251,191,36,.45);
  color: var(--gold-soft); font-size: .8rem; font-weight: 700; text-align: center;
  box-shadow: var(--sh); pointer-events: none;
}

/* ── Notice sheet ─────────────────────────────────────────── */
.notice-body { line-height: 1.5; margin-top: 8px; }
#notice-sheet .primary-btn { margin-top: 18px; }
#notice-sheet .notice-ok { width: 100%; margin-top: 10px; }

/* ── Purchase card while Google Play is open ──────────────── */
.paywall-pack.busy { opacity: .6; pointer-events: none; }
.paywall-pack.busy::after {
  content: ''; position: absolute; top: 50%; right: 18px; width: 18px; height: 18px;
  margin-top: -9px; border-radius: 50%; border: 2.5px solid var(--gold);
  border-right-color: transparent; animation: pack-spin .8s linear infinite;
}
@keyframes pack-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .paywall-pack.busy::after { animation: none; } }

/* ── Shelf load error ─────────────────────────────────────── */
.shelf-retry-btn { margin: 14px auto 0; display: block; }

/* ── Picture-in-picture (Android, while narrating) ────────── */
/* The window is tiny: show just the page picture. */
html.pip .reader-text-panel, html.pip .reader-header, html.pip .page-indicator,
html.pip .toast, html.pip .offline-banner, html.pip .mode-picker { display: none !important; }
html.pip #screen-reader .reader-illustration { position: fixed; inset: 0; height: 100%; }
html.pip #reader-img { object-fit: cover; width: 100%; height: 100%; }
