@property --pct {
  syntax: '<percentage>';
  inherits: false;
  initial-value: 0%;
}

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

/* Global hidden utility — !important overrides inline display:flex/block */
.hidden { display: none !important; }

:root {
  --bg:          #111113;
  --surface:     #1c1c1f;
  --surface-hi:  #28282c;
  --border:      #38383c;
  --accent:      #d4a853;
  --accent-dim:  #c49a3c;
  --accent-glow: rgba(212,168,83,.15);
  --text:        #f0f0eb;
  /* Bug-bash round 5 a11y P1 #8: --text-3 was #8a8a85, ~4.05:1 on
   * --bg = WCAG AA fail. Lifted to #a4a49e (~5.1:1) so secondary
   * labels, timestamps, placeholders stay readable. --text-2 stays at
   * the prior #9a9a94 (~4.4:1) — still AA, but the most fragile token. */
  --text-2:      #9a9a94;
  --text-3:      #a4a49e;
  --danger:      #e05252;
  --success:     #52c87a;
  --warn:        #f0a040;

  --r-sm:  6px;
  --r-md:  12px;
  --r-lg:  18px;
  --r-xl:  24px;

  --font-ui:   system-ui, -apple-system, sans-serif;
  --font-book: Georgia, 'Times New Roman', serif;

  --player-h: 88px;
  --nav-h:    60px;
}

html { height: 100%; }
@media (prefers-reduced-motion: no-preference) {
  html { scroll-behavior: smooth; }
}

body {
  font-family: var(--font-ui);
  background: var(--bg);
  color: var(--text);
  height: 100%;
  display: flex; flex-direction: column;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; border: none; background: none; }
input, select { font-family: inherit; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ── Scrollbar ────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
html {
  scrollbar-width: thin;
  scrollbar-color: var(--border) var(--bg);
}

/* ── Nav ──────────────────────────────────────────────────────── */
.nav {
  position: sticky; top: 0; z-index: 100;
  height: var(--nav-h);
  background: rgba(17,17,19,.88);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center;
  padding: 0 24px; gap: 16px;
}

.nav-logo {
  font-size: 1.2rem; font-weight: 700; letter-spacing: -.02em;
  color: var(--accent);
  display: flex; align-items: center; gap: 8px;
}
.nav-logo svg { width: 22px; height: 22px; }

.nav-spacer { flex: 1; }

.search-bar {
  display: flex; align-items: center; gap: 8px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-xl); padding: 8px 14px;
  width: clamp(180px, 30vw, 380px);
  transition: border-color .2s;
}
.search-bar:focus-within { border-color: var(--accent); }
.search-bar input {
  background: none; border: none; outline: none;
  color: var(--text); width: 100%; font-size: .9rem;
}
.search-bar input::placeholder { color: var(--text-3); }
.search-bar svg { color: var(--text-3); flex-shrink: 0; }

/* ── Buttons ──────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 9px 18px; border-radius: var(--r-md);
  font-size: .88rem; font-weight: 600;
  transition: opacity .15s, transform .1s;
}
.btn:active { transform: scale(.97); }
.btn:hover { opacity: .88; }

.btn-primary { background: var(--accent); color: #1a1200; }
.btn-ghost   { background: transparent; border: 1px solid var(--border); color: var(--text-2); }
.btn-danger  { background: var(--danger); color: #fff; }
.btn-sm      { padding: 6px 12px; font-size: .8rem; }
.btn:disabled { opacity: .35; pointer-events: none; cursor: not-allowed; }

/* ── Page wrapper ─────────────────────────────────────────────── */
.page {
  flex: 1;   /* fills remaining body height in the flex-column layout */
  padding: 32px 24px calc(var(--player-h) + 32px);
  max-width: 1200px; margin: 0 auto; width: 100%;
}
.page--standalone {
  padding-bottom: 32px;
}

/* ── Section header ───────────────────────────────────────────── */
.section-header {
  display: flex; align-items: baseline; gap: 12px; margin-bottom: 24px;
}
.section-header h2 { font-size: 1.4rem; font-weight: 700; }
.section-header .count { color: var(--text-3); font-size: .85rem; }
.section-header .actions { margin-left: auto; display: flex; gap: 8px; }

/* ── Library search/filter bar ────────────────────────────────── */
.library-search {
  display: flex; align-items: center; gap: 8px;
  margin-bottom: 20px;
}
.library-search svg { color: var(--text-3); flex-shrink: 0; }
.library-search input {
  background: var(--surface-hi);
  border: 1px solid var(--border);
  padding: 8px 14px;
  border-radius: var(--r-md);
  width: clamp(180px, 40%, 320px);
  color: var(--text);
  outline: none;
  font-size: .88rem;
  transition: border-color .2s;
}
.library-search input::placeholder { color: var(--text-3); }
.library-search input:focus { border-color: var(--accent); }

/* Category filter pills */
.category-pills {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
  padding: .5rem 0 .25rem;
}
.category-pills:empty { display: none; }
.category-pill {
  padding: .25rem .75rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-2);
  font-size: .8rem;
  cursor: pointer;
  transition: background .15s, color .15s, border-color .15s;
}
.category-pill:hover {
  background: var(--surface-hi);
  color: var(--text);
}
.category-pill.active {
  background: var(--accent);
  color: #000;
  border-color: var(--accent);
}

/* ── Book grid ────────────────────────────────────────────────── */
/* auto-fit (not auto-fill) collapses empty tracks so a short library doesn't
   leave a wide blank column on the right. Capping at 220px keeps cards from
   ballooning to silly sizes when there are only 2-3 books. */
.book-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 220px));
  gap: 20px;
  justify-content: center;
}

.book-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  overflow: hidden;
  cursor: pointer;
  position: relative;
  transition: border-color .2s, transform .2s, box-shadow .2s;
}
.book-card:hover {
  border-color: var(--accent-dim);
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(0,0,0,.4);
}
/* Visible focus ring for keyboard nav — book cards use role=button + tabindex=0
   but the global focus ring on real <button> didn't apply. */
.book-card:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent), 0 8px 24px rgba(0,0,0,.4);
}

/* ── Admin card actions (edit / delete overlays) ─────────────────────────────── */
.card-admin-actions {
  position: absolute;
  top: 6px;
  left: 6px;
  display: flex;
  gap: 4px;
  opacity: 0;
  transition: opacity .15s;
  z-index: 2;
}
.book-card:hover .card-admin-actions { opacity: 1; }
.btn-xs {
  padding: 2px 6px;
  font-size: .7rem;
  min-width: 0;
  line-height: 1.4;
}

.book-cover {
  aspect-ratio: 2/3; background: var(--surface-hi);
  display: flex; align-items: center; justify-content: center;
  overflow: hidden; position: relative;
}
.book-cover img { width: 100%; height: 100%; object-fit: cover; }
.book-cover-placeholder {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  color: var(--text-3); font-size: .75rem; text-align: center; padding: 16px;
}
.book-cover-placeholder svg { width: 40px; height: 40px; opacity: .4; }

.book-badge {
  position: absolute; top: 8px; right: 8px;
  background: rgba(17,17,19,.85); -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px);
  border-radius: 20px; padding: 3px 8px; font-size: .7rem; font-weight: 600;
}
.badge-done    { color: var(--success); }
.badge-partial { color: var(--warn); }
.badge-pending { color: var(--text-3); }
/* G.3.5: staging badge for admin-only unlisted books. Positioned below
   the main status badge so they don't overlap. */
.book-badge--draft {
  top: 36px;
  background: rgba(74, 32, 32, .92);
  color: #f7c08a;
  letter-spacing: .04em;
}
.book-card--draft { opacity: .82; }
.book-card--draft:hover { opacity: 1; }

.book-info { padding: 12px; }
.book-info h3 {
  font-size: .9rem; font-weight: 600; margin-bottom: 2px; line-height: 1.3;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.book-info .author { font-size: .78rem; color: var(--text-2); }
.book-category {
  font-size: .68rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase;
  color: var(--accent-dim); margin-top: 4px;
}

/* ── Progress bar ─────────────────────────────────────────────── */
.progress-bar {
  height: 3px; background: var(--surface-hi); border-radius: 2px;
  margin-top: 10px; overflow: hidden;
}
.progress-fill {
  height: 100%; background: var(--accent); border-radius: 2px;
  transition: width .4s;
}

/* ── Import modal ─────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(0,0,0,.7); -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
/* .modal-overlay.hidden — superseded by global .hidden rule */

.modal {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-xl); width: 100%; max-width: 540px;
  max-height: 80vh; min-height: 300px; display: flex; flex-direction: column;
}
.modal-header {
  display: flex; align-items: center; padding: 20px 24px;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 1.1rem; font-weight: 700; flex: 1; }
.modal-close { color: var(--text-3); padding: 4px; border-radius: var(--r-sm); }
.modal-close:hover { color: var(--text); background: var(--surface-hi); }
.modal-body { padding: 20px 24px; overflow-y: auto; flex: 1; }
.modal-footer { padding: 16px 24px; border-top: 1px solid var(--border); display: flex; gap: 8px; justify-content: flex-end; }

.search-results-list { display: flex; flex-direction: column; gap: 10px; margin-top: 16px; }
.search-result-item {
  display: flex; gap: 12px; align-items: center;
  background: var(--surface-hi); border: 1px solid var(--border);
  border-radius: var(--r-md); padding: 12px;
}
.search-result-item img { width: 44px; height: 66px; object-fit: cover; border-radius: 4px; flex-shrink: 0; }
.search-result-item .no-img {
  width: 44px; height: 66px; background: var(--border);
  border-radius: 4px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; color: var(--text-3);
}
.result-meta { flex: 1; min-width: 0; }
.result-meta strong { display: block; font-size: .9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.result-meta span { font-size: .78rem; color: var(--text-2); }

/* ── Toast ────────────────────────────────────────────────────── */
.toast-container { position: fixed; bottom: calc(var(--player-h) + 16px); right: 16px; z-index: 300; display: flex; flex-direction: column; gap: 8px; }
/* On pages without a visible player, reset toast position to bottom of viewport */
body:not(.player-active) .toast-container {
  bottom: 16px;
}
/* JS-toggled in player.js when the completion banner shows; avoids :has()
   which we keep out of the codebase for Firefox-compat reasons (CLAUDE.md §8). */
body.completion-active .toast-container {
  bottom: calc(var(--player-h) + 96px);
}
.toast {
  background: var(--surface-hi); border: 1px solid var(--border);
  border-radius: var(--r-md); padding: 12px 16px;
  font-size: .85rem; max-width: 320px;
  animation: toast-in .2s ease;
}
.toast.toast-error  { border-color: var(--danger);  color: var(--danger); }
.toast.toast-success{ border-color: var(--success); color: var(--success); }
.toast.toast-info   { border-color: var(--accent-dim); color: var(--text-2); }
@keyframes toast-in { from { opacity:0; transform: translateY(8px); } to { opacity:1; transform: none; } }

/* ── Empty state ──────────────────────────────────────────────── */
.empty-state {
  text-align: center; padding: 48px 0;
  color: var(--text-2);
  display: flex; flex-direction: column; align-items: center; gap: 16px;
}
.empty-state svg { width: 64px; height: 64px; opacity: .2; }
.empty-state h3 { font-size: 1.1rem; color: var(--text); }
.empty-state p  { font-size: .9rem; }
.empty-state .spinner { margin: 0 auto; }
.empty-state .btn { margin-top: 8px; }

/* ── Loading state ────────────────────────────────────────────── */
.loading-state {
  display: flex; flex-direction: column; align-items: center; gap: 16px;
  padding: 48px 0;
}

/* ── Skeleton shimmer ─────────────────────────────────────────── */
@keyframes shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.skeleton-block,
.skeleton-line {
  background: linear-gradient(
    90deg,
    var(--surface) 25%,
    var(--surface-hi) 50%,
    var(--surface) 75%
  );
  background-size: 200% 100%;
  animation: shimmer 1.4s linear infinite;
  border-radius: var(--r-sm);
  will-change: background-position;
}

/* Skeleton book card */
.book-card.skeleton {
  pointer-events: none;
}
.book-card.skeleton .book-cover.skeleton-block {
  border-radius: 0;
}
.book-card.skeleton .skeleton-line {
  height: 12px; margin-bottom: 8px;
}
.book-card.skeleton .skeleton-line:last-child { margin-bottom: 0; }

/* Skeleton chapter item */
.chapter-item.skeleton {
  pointer-events: none;
}
.chapter-item.skeleton .skeleton-line {
  height: 11px;
}

/* ── Loading spinner ──────────────────────────────────────────── */
.spinner {
  width: 20px; height: 20px;
  border: 2px solid var(--border); border-top-color: var(--accent);
  border-radius: 50%; animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ═══════════════════════════════════════════════════════════════ */
/* ── BOOK PAGE ──────────────────────────────────────────────────*/
/* ═══════════════════════════════════════════════════════════════ */

/* book-page uses flex:1 so it fills whatever space remains after nav + any banners.
   min-height:0 lets flex children (sidebar, reader) independently scroll. */
.book-page { display: flex; flex: 1; min-height: 0; overflow: hidden; }

/* Sidebar */
.sidebar {
  width: 280px; flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  overflow: hidden;
}
.sidebar-header {
  padding: 16px; border-bottom: 1px solid var(--border);
}
.sidebar-header h2, .sidebar-book-title { font-size: 1rem; font-weight: 700; line-height: 1.3; margin-bottom: 2px; }
.sidebar-header .author { font-size: .8rem; color: var(--text-2); margin-bottom: 12px; }
.sidebar-header .gen-btn { width: 100%; justify-content: center; }
.sidebar-header .sidebar-share-btn {
  display: inline-flex; align-items: center; gap: 6px;
  margin-bottom: 12px; padding: 4px 10px; font-size: .8rem;
}

.chapter-list { flex: 1; overflow-y: auto; padding: 8px; list-style: none; margin: 0; }
.chapter-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px; border-radius: var(--r-sm);
  cursor: pointer; transition: background .15s;
  font-size: .85rem;
}
.chapter-item:hover   { background: var(--surface-hi); }
.chapter-item.active  { background: var(--accent-glow); color: var(--accent); }
.chapter-item:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.chapter-item .ch-num { width: 28px; text-align: right; color: var(--text-3); font-size: .75rem; flex-shrink: 0; }
.chapter-item .ch-title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chapter-item .ch-status { flex-shrink: 0; width: 8px; height: 8px; border-radius: 50%; }

/* Phase 23 freemium markers in the chapter list (hidden for subscribers). */
.chapter-item .ch-badge {
  flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: .65rem; font-weight: 600;
  padding: 1px 6px; border-radius: 999px;
  letter-spacing: .04em;
}
.ch-badge-free {
  background: var(--accent-glow);
  color: var(--accent);
  text-transform: uppercase;
}
.ch-badge-locked {
  background: transparent;
  color: var(--text-3);
  padding: 1px 2px;
}
.chapter-item.active .ch-badge-free { background: transparent; }
.status-done       { background: var(--success); }
.status-processing { background: var(--warn); animation: pulse 1s infinite; }
.status-pending    { background: var(--border); }
.status-failed     { background: var(--danger); }
.ch-status.status-failed {
  animation: pulse 1.5s ease-in-out infinite;
}

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

/* Main reading area */
.reader {
  flex: 1; overflow-y: auto;
  padding: 40px 40px calc(var(--player-h) + 40px);
}
.reader-chapter-title {
  font-size: 1.5rem; font-weight: 700;
  padding-bottom: 20px; border-bottom: 1px solid var(--border);
  max-width: 68ch; margin: 0 auto 12px;
}
.chapter-meta {
  font-size: .8rem; color: var(--text-2);
  margin-bottom: 28px;
  max-width: 68ch; margin-left: auto; margin-right: auto;
}

.chapter-text {
  font-family: var(--font-book);
  font-size: 1.1rem; line-height: 1.85;
  color: var(--text);
  max-width: 68ch; margin: 0 auto;
}
.chapter-text p { margin-bottom: 1.2em; }

/* Reading-progress ring — floats top-right of the reader viewport.
   Hidden when at top (scrollTop < ~100px); fades in once the user is
   actually into the chapter. Click anywhere on the ring scrolls back
   to top. Replaced the prior `position: sticky` 2px bar which sat
   across the top edge of the reader and covered the first line of
   chapter text. */
.reading-progress {
  position: fixed;
  top: calc(var(--nav-h) + 14px);
  right: 18px;
  width: 36px; height: 36px;
  padding: 0;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: rgba(17, 17, 19, 0.85);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  z-index: 50;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease, transform .15s ease;
}
.reading-progress.visible {
  opacity: 1;
  pointer-events: auto;
}
.reading-progress:hover {
  transform: scale(1.06);
  border-color: var(--accent-dim);
}
.reading-progress svg {
  /* Rotate so the fill arc starts at 12 o'clock and grows clockwise. */
  transform: rotate(-90deg);
}
.reading-progress-track {
  fill: none;
  stroke: var(--surface-hi);
  stroke-width: 3;
}
.reading-progress-fill {
  fill: none;
  stroke: var(--accent);
  stroke-width: 3;
  stroke-linecap: round;
  /* Circumference of a 15-px-radius circle: 2π × 15 ≈ 94.25.
     stroke-dasharray = circumference makes the entire stroke one dash;
     stroke-dashoffset shifts where that dash starts. Setting offset to
     the full circumference hides the stroke; 0 shows it fully. JS
     updates only the offset. */
  stroke-dasharray: 94.25;
  stroke-dashoffset: 94.25;
  transition: stroke-dashoffset .08s linear;
}

/* ═══════════════════════════════════════════════════════════════ */
/* ── AUDIO PLAYER ───────────────────────────────────────────────*/
/* ═══════════════════════════════════════════════════════════════ */

.audio-player {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 150;
  height: var(--player-h);
  background: rgba(17,17,19,.95);
  -webkit-backdrop-filter: blur(16px);
  backdrop-filter: blur(16px);
  border-top: 1px solid var(--border);
  display: flex; align-items: center;
  padding: 0 24px; gap: 16px;
}
/* .audio-player.hidden — superseded by global .hidden rule */

.player-track {
  min-width: 0; flex: 1; display: flex; flex-direction: column; gap: 4px;
}
.player-track .track-title { font-size: .8rem; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.player-track .track-book  { font-size: .72rem; color: var(--text-3); }

.player-controls {
  display: flex; align-items: center; gap: 4px; flex-shrink: 0;
}
.ctrl-btn {
  width: 36px; height: 36px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-2); transition: color .15s, background .15s;
}
.ctrl-btn:hover { color: var(--text); background: var(--surface-hi); }
.ctrl-btn-sm { width: 28px; height: 28px; }
.ctrl-btn.play-btn {
  width: 44px; height: 44px;
  background: var(--accent); color: #1a1200;
}
.ctrl-btn.play-btn:hover { background: var(--accent-dim); color: #1a1200; }
.play-btn.buffering {
  opacity: 0.6;
  animation: pulse 1s ease-in-out infinite;
}

/* Locked paywall state — player chrome stays visible so the user doesn't
   lose context, but secondary controls are dimmed and the play button shows
   a lock icon (set inline by _renderLockedPlayer). Clicking it scrolls to
   the in-page paywall CTA. */
.audio-player.locked .ctrl-btn:not(.play-btn),
.audio-player.locked .speed-select,
.audio-player.locked .volume-slider,
.audio-player.locked .seek-bar,
.audio-player.locked .time-label,
.audio-player.locked #mute-btn {
  opacity: .35;
  pointer-events: none;
}
.audio-player.locked .play-btn {
  background: var(--surface-hi);
  color: var(--accent);
}
.audio-player.locked .play-btn:hover {
  background: var(--accent-dim);
  color: #1a1200;
}

.player-seek { flex: 2; display: flex; align-items: center; gap: 10px; }
.time-label { font-size: .72rem; color: var(--text-3); width: 38px; flex-shrink: 0; }
.time-label.right { text-align: right; }

input[type="range"] {
  flex: 1; height: 4px;
  appearance: none; -webkit-appearance: none; background: var(--surface-hi);
  border-radius: 2px; outline: none; cursor: pointer;
}
input[type="range"]:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 4px;
  border-radius: 2px;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--accent);
  box-shadow: none;
}
input[type="range"]::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  border: none;
  cursor: pointer;
}
input[type="range"]::-moz-range-progress {
  background: var(--accent);
  height: 4px;
  border-radius: 2px;
}
input[type="range"].seek-bar { background: linear-gradient(to right, var(--accent) var(--pct, 0%), var(--surface-hi) var(--pct, 0%)); }

.player-extras { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.player-extras .volume-slider { width: 72px; flex: none; }
.speed-select {
  background: var(--surface-hi); border: 1px solid var(--border);
  color: var(--text); border-radius: var(--r-sm);
  padding: 4px 8px; font-size: .8rem; cursor: pointer;
}

/* ── Book completion banner ──────────────────────────────────────────────────── */
.book-completion {
  position: fixed;
  bottom: var(--player-h);
  left: 0;
  right: 0;
  z-index: 149;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 20px;
  background: var(--surface-hi);
  border-top: 1px solid var(--border);
  font-size: .9rem;
  flex-wrap: wrap;
}
.book-completion .completion-icon { font-size: 1.5rem; flex-shrink: 0; }
.book-completion .completion-text { flex: 1; min-width: 0; }
.book-completion .completion-text strong { display: block; color: var(--text); }
.book-completion .completion-text span  { color: var(--text-3); font-size: .8rem; }
.book-completion .completion-actions { display: flex; gap: 8px; flex-shrink: 0; }

/* ── Nav auth slot ────────────────────────────────────────────── */
.nav-auth { display: flex; align-items: center; gap: 8px; position: relative; }

.nav-user {
  /* Reset button defaults — bug-bash round 5: .nav-user is now a <button>
   * (a11y P1 #5) so it gets keyboard focus + ARIA without extra wiring.
   * Clear UA styles so the visual is unchanged. */
  appearance: none; background: transparent; border: 0;
  font-family: inherit;
  display: flex; align-items: center; gap: 8px;
  padding: 6px 10px; border-radius: var(--r-md);
  cursor: pointer; transition: background .15s;
  color: var(--text-2); font-size: .85rem;
}
.nav-user:hover { background: var(--surface-hi); }
.nav-user:focus-visible { outline: 2px solid var(--accent-glow); outline-offset: 2px; }
.nav-avatar {
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--accent); color: #1a1200;
  display: flex; align-items: center; justify-content: center;
  font-size: .75rem; font-weight: 700; flex-shrink: 0;
}
.nav-user-name { max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.nav-dropdown {
  position: absolute; top: calc(100% + 8px); right: 0;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-md); min-width: 200px;
  box-shadow: 0 8px 24px rgba(0,0,0,.5); z-index: 210;
  overflow: hidden;
}
/* .nav-dropdown.hidden — superseded by global .hidden rule */
.nav-dropdown-email { padding: 12px 16px; font-size: .78rem; color: var(--text-3); word-break: break-all; }
.nav-dropdown-divider { height: 1px; background: var(--border); }
.nav-dropdown-item {
  display: block; width: 100%;
  padding: 10px 16px; text-align: left;
  font-size: .88rem; color: var(--text-2);
  transition: background .15s;
}
.nav-dropdown-item:hover { background: var(--surface-hi); color: var(--text); }
.nav-dropdown-meta {
  padding: 4px 16px;
  font-size: .75rem;
  color: var(--text-3);
}

/* ── Trial banner ─────────────────────────────────────────────── */
.trial-banner {
  display: flex; align-items: center; justify-content: center; gap: 16px;
  background: rgba(212,168,83,.12); border-bottom: 1px solid rgba(212,168,83,.3);
  padding: 10px 24px; font-size: .85rem; color: var(--accent);
}

.trial-banner--urgent {
  background: rgba(220, 38, 38, 0.12);
  border-color: var(--danger);
}
.trial-banner--urgent span {
  color: var(--danger);
}

/* ── Floating trial CTA ───────────────────────────────────────── */
/* Persistent bottom-anchored offer shown on chapter 1 to non-subscribers.
   Slides up when shown, slides down when hidden so the appearance/dismiss
   transitions feel intentional rather than abrupt. */
.trial-floating-cta {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 90;  /* above content, below auth modal (z=1000) */
  background: linear-gradient(180deg, rgba(20,20,22,.96) 0%, rgba(20,20,22,1) 100%);
  border-top: 1px solid rgba(212,168,83,.45);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  box-shadow: 0 -8px 24px rgba(0,0,0,.4);
  padding: 14px 16px;
  transform: translateY(0);
  transition: transform .25s ease-out;
}
.trial-floating-cta.hidden {
  /* Note: this overrides the generic .hidden { display: none } so the slide
     animation can play. We do BOTH (display:none after a delay would also
     work but is more code; transform is the visual hide, .hidden is
     belt-and-braces for a11y and click-through). */
  transform: translateY(105%);
  pointer-events: none;
}
.trial-floating-cta-inner {
  display: flex;
  align-items: center;
  gap: 14px;
  max-width: 760px;
  margin: 0 auto;
  flex-wrap: wrap;
  justify-content: center;
}
.trial-floating-cta-text {
  color: var(--text);
  font-size: .92rem;
  line-height: 1.4;
}
.trial-floating-cta-text strong { color: var(--accent); }
.trial-floating-cta-btn {
  flex-shrink: 0;
  white-space: nowrap;
}
.trial-floating-cta-dismiss {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-3);
  font-size: 22px;
  line-height: 1;
  width: 32px; height: 32px;
  padding: 0;
  border-radius: 6px;
  cursor: pointer;
  flex-shrink: 0;
  transition: background .12s, color .12s;
}
.trial-floating-cta-dismiss:hover,
.trial-floating-cta-dismiss:focus-visible {
  background: rgba(255,255,255,.06);
  color: var(--text);
  outline: none;
  border-color: rgba(255,255,255,.1);
}

/* Mobile: stack to full-width column. */
@media (max-width: 600px) {
  .trial-floating-cta-inner {
    flex-direction: column;
    gap: 10px;
    text-align: center;
  }
  .trial-floating-cta-btn { width: 100%; }
  .trial-floating-cta-dismiss {
    position: absolute;
    top: 4px;
    right: 8px;
  }
}

/* When player is active, bump the floating CTA above the player bar so it
   doesn't overlap. .player-active is set on body when audio player is open. */
body.player-active .trial-floating-cta {
  bottom: 90px;  /* approx player height; tune if player shape changes */
}

/* ── Continue Listening banner ────────────────────────────────── */
/* #continue-banner uses .visible opt-in (not .hidden opt-out) — see library.js renderContinueBanner */
#continue-banner {
  display: none; /* shown via JS when resume data is available */
}
#continue-banner.visible {
  display: block;
}
.continue-card {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  background: var(--surface);
  border-left: 3px solid var(--accent);
  border-bottom: 1px solid var(--border);
  padding: 12px 24px;
  flex-wrap: wrap;
}
.continue-info {
  display: flex; flex-direction: column; gap: 2px;
  min-width: 0;
}
.continue-label {
  font-size: .72rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase;
  color: var(--accent-dim);
}
.continue-title {
  font-size: .95rem; font-weight: 600; color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.continue-meta {
  font-size: .8rem; color: var(--text-2);
}
/* .trial-banner.hidden — superseded by global .hidden rule */

/* ── Auth modal ───────────────────────────────────────────────── */
.auth-modal-inner { max-width: 420px; }

.auth-tabs {
  display: flex; gap: 4px; flex: 1;
}
.auth-tab {
  padding: 6px 14px; border-radius: var(--r-sm);
  font-size: .88rem; font-weight: 600; color: var(--text-3);
  transition: background .15s, color .15s;
}
.auth-tab:hover { color: var(--text); }
.auth-tab.active { background: var(--surface-hi); color: var(--text); }

.auth-form { display: flex; flex-direction: column; gap: 16px; }
/* .auth-form.hidden — superseded by global .hidden rule */

.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group label {
  font-size: .82rem; font-weight: 600; color: var(--text-2);
  display: flex; justify-content: space-between; align-items: center;
}
.form-group input {
  background: var(--surface-hi); border: 1px solid var(--border);
  border-radius: var(--r-md); padding: 10px 14px;
  color: var(--text); font-size: .9rem; outline: none;
  transition: border-color .2s;
}
.form-group input:focus { border-color: var(--accent); }
.form-group input::placeholder { color: var(--text-3); }
.form-group.has-error input,
.form-group.has-error select {
  border-color: var(--danger);
}

.form-link {
  font-size: .78rem; color: var(--accent); font-weight: 500;
  background: none; border: none; cursor: pointer; padding: 0;
}
.form-link:hover { text-decoration: underline; }

.auth-submit { width: 100%; justify-content: center; padding: 11px; font-size: .92rem; }

/* .auth-error.hidden — superseded by global .hidden rule */
.auth-error {
  font-size: .82rem; padding: 8px 12px;
  border-radius: var(--r-sm);
  background: rgba(224,82,82,.12); color: var(--danger); border: 1px solid rgba(224,82,82,.3);
}
.auth-error.auth-success {
  color: var(--success, #4caf50);
  border-color: var(--success, #4caf50);
}
.auth-error:empty,
.auth-success:empty {
  display: none;
}
.auth-success { font-size: .82rem; padding: 8px 12px; border-radius: var(--r-sm); background: rgba(82,200,122,.12); color: var(--success); border: 1px solid rgba(82,200,122,.3); }

.auth-switch { font-size: .82rem; color: var(--text-3); text-align: center; }
.auth-fine-print { color: var(--text-3); font-size: .78rem; text-align: center; margin-top: -4px; }
.auth-desc { font-size: .88rem; color: var(--text-2); }

.password-hint { font-size: .75rem; padding: 4px 0; transition: color .2s; }
.password-hint.hint-weak   { color: var(--danger); }
.password-hint.hint-ok     { color: var(--warn); }
.password-hint.hint-strong { color: var(--success); }

/* Cloudflare Turnstile widget slot — empty until config arrives, then ~300x65 */
.turnstile-slot:empty { display: none; }
.turnstile-slot { display: flex; justify-content: center; min-height: 0; }

@keyframes shake {
  0%,100% { transform: translateX(0); }
  20%,60%  { transform: translateX(-6px); }
  40%,80%  { transform: translateX(6px); }
}
.shake { animation: shake .35s ease; }

.auth-modal-inner { animation: modal-in .2s ease; }
@keyframes modal-in {
  from { opacity: 0; transform: translateY(12px) scale(.97); }
  to   { opacity: 1; transform: none; }
}

/* ── Account page ─────────────────────────────────────────────── */
.account-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 24px;
  max-width: 560px;
  margin-bottom: 20px;
}

.account-card-header {
  display: flex; align-items: center; gap: 16px;
}

.account-avatar {
  width: 48px; height: 48px;
  font-size: 1.1rem; flex-shrink: 0;
}

.account-name {
  font-size: 1rem; font-weight: 700; color: var(--text);
}

.account-email {
  font-size: .85rem; color: var(--text-2); margin-top: 2px;
}

.account-card-title {
  font-size: .75rem; font-weight: 700; letter-spacing: .06em;
  text-transform: uppercase; color: var(--text-3);
  margin-bottom: 16px;
}

.account-desc {
  font-size: .88rem; color: var(--text-2);
  margin: 12px 0 20px;
  line-height: 1.55;
}

/* Trust line under the Subscribe CTA — small lock icon + Stripe attribution.
   Sized below the button so it doesn't compete visually; signals "card form on
   the next screen is hosted by Stripe, not us". */
.checkout-trust {
  display: inline-flex; align-items: center; gap: 6px;
  margin: 10px 0 0;
  font-size: .75rem; color: var(--text-3);
}
.checkout-trust svg { flex-shrink: 0; color: var(--text-3); }

/* Pulse the Subscribe button briefly when the user returns from a canceled
   Stripe Checkout, so they see *exactly* where to retry. */
@keyframes pulse-cta {
  0%, 100% { box-shadow: 0 0 0 0 rgba(212, 168, 83, 0); }
  50%      { box-shadow: 0 0 0 6px rgba(212, 168, 83, .35); }
}
.pulse-cta { animation: pulse-cta 1.4s ease-in-out 2; }
@media (prefers-reduced-motion: reduce) {
  .pulse-cta { animation: none; outline: 2px solid var(--accent); }
}

.billing-status {
  display: inline-flex; align-items: center; gap: 8px;
  font-size: .88rem; font-weight: 600;
  padding: 6px 12px; border-radius: 20px;
}

.billing-status-trial {
  background: rgba(212,168,83,.12);
  color: var(--accent);
  border: 1px solid rgba(212,168,83,.3);
}

.billing-status-active {
  background: rgba(82,200,122,.12);
  color: var(--success);
  border: 1px solid rgba(82,200,122,.3);
}

.billing-status-none {
  background: var(--surface-hi);
  color: var(--text-2);
  border: 1px solid var(--border);
}

.billing-status-warning {
  background: rgba(240, 160, 64, .12);
  color: var(--warn);
  border: 1px solid rgba(240, 160, 64, .3);
}

.verify-notice {
  display: flex;
  align-items: center;
  gap: .5rem;
  margin-top: .5rem;
  font-size: .85rem;
  color: var(--warn);
}
.cancel-notice {
  font-size: .875rem;
  margin-top: .5rem;
  color: var(--warn);
}

.account-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
  margin-top: 12px;
  border-top: 1px solid var(--border);
}
.account-row-label {
  font-size: .85rem;
  color: var(--text-2);
}

/* ── Screen-reader only utility ──────────────────────────────────── */
.sr-only {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}

/* ── Skip-to-content link ─────────────────────────────────────────
 * Bug-bash round 5 a11y P2 #9: visually hidden until focused. The
 * first Tab on any page lands here, letting keyboard users jump past
 * the nav instead of tabbing through every header link. Adopts the
 * accent color so it's obvious when surfaced.
 */
.skip-link {
  position: absolute;
  top: 8px; left: 8px;
  z-index: 1000;
  padding: 10px 16px;
  background: var(--accent);
  color: #1a1200;
  font-weight: 600;
  border-radius: var(--r-sm);
  text-decoration: none;
  transform: translateY(-200%);
  transition: transform .15s;
}
.skip-link:focus {
  transform: translateY(0);
  outline: 2px solid var(--accent-glow);
  outline-offset: 2px;
}

/* ── Responsive ───────────────────────────────────────────────── */
/* Bug-bash P2 #66: drawer behavior used to start at ≤560px; the 561-768
 * range left the 240px in-flow sidebar competing with the reader and the
 * audio player on tablets. Pushed the drawer up to ≤768px so portrait
 * tablets get the full reader width + a slide-in chapter list. */
@media (max-width: 768px) {
  .reader { padding: 20px 20px calc(var(--player-h) + 20px); }
  .player-seek .time-label { display: none; }
  /* Keep speed selector visible on tablets; hide volume (system volume controls exist) */
  .player-extras .volume-slider { display: none; }
  .book-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
  .sidebar {
    position: fixed; left: -100%; top: var(--nav-h); bottom: 0;
    width: 280px;  /* wider than mobile drawer — tablets have room */
    z-index: 145; transition: left .25s;
    box-shadow: 4px 0 24px rgba(0,0,0,.5);
  }
  body.player-active .sidebar {
    bottom: var(--player-h);
  }
  .sidebar.open { left: 0; }
  /* Overlay behind open sidebar (z-index 140) — sidebar itself is z-index 145, player is 150 */
  .sidebar-overlay {
    display: none; position: fixed;
    top: var(--nav-h); bottom: 0; left: 0; right: 0;
    z-index: 140;
    background: rgba(0,0,0,.5);
  }
  .sidebar-overlay.visible { display: block; }
}

@media (max-width: 560px) {
  /* Mobile-specific tightening (was previously combined with the drawer
   * rules above). */
  .sidebar { width: 240px; }

  /* Mobile audio player */
  .audio-player { padding: 0 8px; gap: 6px; }
  .player-extras { gap: 6px; }
  .time-label { font-size: .7rem; }
  .player-track { font-size: .7rem; min-width: 0; }
  .player-track .track-title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 140px; }
  .player-controls { gap: 2px; }
  /* Bug-bash round 5 a11y P1 #6: 30×30 was below WCAG AA 44×44 touch
   * target on mobile. Lifted to 40×40 (tightest size that still fits
   * the player bar at ≤360px without overflow) and 44×44 play. AA
   * recommends 44 minimum, so we accept the 40 trade-off only for
   * non-primary controls — the spec also permits "sufficient spacing"
   * compensation, which the 2px gap on .player-controls provides. */
  #rewind-btn, #forward-btn { width: 40px; height: 40px; font-size: .8rem; }
  #prev-btn, #next-btn { width: 40px; height: 40px; }
  #play-btn { width: 44px; height: 44px; }

}

@media (max-width: 480px) {
  .book-completion { padding: 10px 12px; gap: 8px; }
  .book-completion .completion-actions { gap: 6px; }
  /* Reader text cramps on narrow phones; 16px sides give the prose room to breathe. */
  .reader { padding: 16px 16px calc(var(--player-h) + 16px); }
  /* Bigger seek-bar drag target on touch screens — 4px is fiddly to hit with a thumb. */
  input[type="range"].seek-bar { height: 8px; }
  /* Account-card padding tightens on small phones (was max-width: 560px with 32px padding). */
  .account-card { padding: 16px; }
}

@media (max-width: 360px) {
  #prev-btn, #next-btn { display: none; }
  .player-track { display: none; }
  .audio-player { padding: 0 8px; }
}

/* Sidebar toggle button — hidden on desktop */
/* Bug-bash P2 #66: visible at ≤768px so portrait tablets get the drawer
 * toggle (sidebar is now off-canvas through that range too). */
.sidebar-toggle { display: none; }
@media (max-width: 768px) {
  .sidebar-toggle { display: inline-flex; }
}

/* Auth gate pitch */
.auth-gate-pitch {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 3rem 1.5rem;
  gap: 1rem;
  max-width: 480px;
  margin: 0 auto;
}
.auth-gate-pitch h3 { font-size: 1.25rem; font-weight: 600; }
.auth-gate-pitch p { color: var(--text-2); line-height: 1.6; }

@media (max-width: 400px) {
  .auth-gate-pitch { padding: 2rem 1rem; }
  .auth-gate-pitch h3 { font-size: 1.1rem; }
}

/* Guest hero */
.guest-hero { padding: 4rem 1.5rem 2rem; text-align: center; }
.hero-inner { max-width: 720px; margin: 0 auto; }
.hero-headline { font-size: clamp(1.8rem, 5vw, 2.8rem); font-weight: 700; line-height: 1.2; margin-bottom: 1rem; }
.hero-sub { color: var(--text-2); font-size: 1.1rem; line-height: 1.6; max-width: 520px; margin: 0 auto 2rem; }
.hero-ctas { display: flex; flex-direction: column; align-items: center; gap: .5rem; margin: 1.5rem 0 2.5rem; }
.btn-lg { padding: .875rem 2rem; font-size: 1rem; }
.hero-fine { color: var(--text-3); font-size: .8rem; }

/* Hero sample player ─────────────────────────────────────────── */
.hero-sample {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 1.25rem 1.25rem 1rem;
  max-width: 480px;
  margin: 0 auto 1.5rem;
  text-align: left;
  display: flex; flex-direction: column; gap: .75rem;
}
.hero-sample-meta { display: flex; flex-direction: column; gap: .15rem; }
.hero-sample-label { color: var(--accent); font-size: .7rem; text-transform: uppercase; letter-spacing: .1em; font-weight: 600; }
.hero-sample-meta strong { font-size: .95rem; line-height: 1.3; }
.hero-sample-author { color: var(--text-3); font-size: .8rem; }
.hero-sample-controls { display: flex; align-items: center; gap: .75rem; }
.hero-sample-play {
  width: 40px; height: 40px; border-radius: 50%;
  background: var(--accent); color: #000; border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; transition: transform .1s, opacity .15s;
}
.hero-sample-play:hover { transform: scale(1.05); }
.hero-sample-play:disabled { opacity: .5; pointer-events: none; }
.hero-sample-progress {
  flex: 1; height: 4px; background: var(--surface-hi); border-radius: 2px;
  overflow: hidden; position: relative;
}
.hero-sample-progress > div {
  height: 100%; width: 0; background: var(--accent);
  border-radius: 2px; transition: width .15s linear;
}
.hero-sample-time { font-variant-numeric: tabular-nums; color: var(--text-3); font-size: .8rem; flex-shrink: 0; }

/* Featured carousel ─────────────────────────────────────────── */
/* Right-edge fade hints "there's more to scroll" — native scrollbars are too
   subtle on touch devices to register at a glance. */
.hero-featured {
  margin-top: 1.5rem; text-align: left; position: relative;
  -webkit-mask-image: linear-gradient(to right, #000 0, #000 calc(100% - 32px), transparent 100%);
          mask-image: linear-gradient(to right, #000 0, #000 calc(100% - 32px), transparent 100%);
}
.hero-featured-label { color: var(--text-3); font-size: .75rem; text-transform: uppercase; letter-spacing: .12em; margin-bottom: .75rem; text-align: center; }
.hero-featured-row {
  display: flex; gap: 12px;
  overflow-x: auto; scroll-snap-type: x mandatory;
  padding-bottom: .5rem; margin: 0 -1.5rem; padding-inline: 1.5rem;
  scrollbar-width: thin; scrollbar-color: var(--surface-hi) transparent;
}
.hero-featured-row::-webkit-scrollbar { height: 6px; }
.hero-featured-row::-webkit-scrollbar-thumb { background: var(--surface-hi); border-radius: 3px; }
.hero-featured-card {
  flex: 0 0 auto; width: 110px; scroll-snap-align: start;
  cursor: pointer; text-decoration: none; color: inherit;
  transition: transform .15s;
}
.hero-featured-card:hover { transform: translateY(-3px); }
.hero-featured-card img,
.hero-featured-card .hero-featured-placeholder {
  width: 110px; height: 165px; object-fit: cover; border-radius: 6px;
  background: var(--surface-hi); border: 1px solid var(--border);
  display: block;
}
.hero-featured-card .hero-featured-title {
  font-size: .75rem; color: var(--text-2); margin-top: .35rem;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

@media (max-width: 400px) {
  .hero-sub { font-size: 1rem; }
  .guest-hero { padding: 2.5rem 1rem 1.5rem; }
  .hero-sample { padding: 1rem; }
}

/* Shared auth/verify/reset page card */
.auth-page-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 40px 32px;
  max-width: 420px;
  margin: 0 auto;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
  html { scroll-behavior: auto !important; }
}

/* ── Site footer (P1 #16: Privacy + Terms required by Stripe Checkout) ──── */
.site-footer {
  border-top: 1px solid var(--border);
  margin-top: 4rem;
  padding: 1.5rem 1.5rem 2rem;
  text-align: center;
  font-size: .85rem;
  color: var(--text-3);
}
.site-footer a {
  color: var(--text-2);
  text-decoration: none;
  margin: 0 .5rem;
}
.site-footer a:hover, .site-footer a:focus-visible {
  color: var(--text);
  text-decoration: underline;
}
.site-footer .footer-divider {
  color: var(--text-3);
  margin: 0 .25rem;
}

body.player-active .site-footer { display: none; }

/* ── Phase 24: sleep timer ─────────────────────────────────────── */
.sleep-timer-wrap { position: relative; display: flex; align-items: center; }
#sleep-btn { position: relative; }
#sleep-btn.sleep-active { color: var(--accent); }
.sleep-timer-remaining {
  position: absolute; top: -4px; right: -6px;
  background: var(--accent); color: #111113;
  font-size: .58rem; font-weight: 700; line-height: 1;
  border-radius: 8px; padding: 2px 4px; pointer-events: none;
}
.sleep-menu {
  position: absolute; bottom: calc(100% + 10px); right: 0;
  background: var(--surface); border: 1px solid var(--surface-hi);
  border-radius: var(--r-md); padding: 6px; min-width: 150px;
  box-shadow: 0 8px 28px rgba(0,0,0,.5); z-index: 60;
}
.sleep-menu-title {
  font-size: .68rem; font-weight: 700; letter-spacing: .06em;
  text-transform: uppercase; color: var(--text-3); padding: 6px 10px 4px;
}
.sleep-menu-item {
  display: block; width: 100%; text-align: left;
  background: none; border: none; color: var(--text);
  font-size: .85rem; padding: 8px 10px; border-radius: var(--r-sm);
  cursor: pointer;
}
.sleep-menu-item:hover, .sleep-menu-item:focus-visible { background: var(--surface-hi); }
.sleep-menu-item.active { color: var(--accent); font-weight: 600; }

/* ── Phase 24: listening stats strip (library) ─────────────────── */
.stats-strip { max-width: 1200px; margin: 0 auto; padding: 0 24px; }
.stats-strip.hidden { display: none; }
.stats-strip-inner {
  display: flex; align-items: center; flex-wrap: wrap; gap: 6px;
  font-size: .82rem; color: var(--text-2);
  background: var(--surface); border: 1px solid var(--surface-hi);
  border-radius: var(--r-md); padding: 9px 14px; margin-top: 12px;
}
.stats-strip-inner svg { color: var(--accent); flex-shrink: 0; margin-right: 2px; }
.stats-strip-inner strong { color: var(--text); font-weight: 600; }
.stats-strip-divider { color: var(--text-3); margin: 0 2px; }

/* ── Phase 24: save-for-later heart ────────────────────────────── */
.book-save-btn {
  position: absolute; top: 8px; left: 8px;
  display: flex; align-items: center; justify-content: center;
  width: 28px; height: 28px; border-radius: 50%;
  background: rgba(17,17,19,.7); -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px);
  border: none; color: var(--text-2); cursor: pointer;
  opacity: 0; transition: opacity .15s, color .15s, transform .1s;
}
.book-card:hover .book-save-btn,
.book-card:focus-within .book-save-btn,
.book-save-btn.saved { opacity: 1; }
.book-save-btn:hover { color: var(--text); transform: scale(1.1); }
.book-save-btn.saved { color: var(--accent); }
/* Touch devices have no hover — always show the heart. */
@media (hover: none) {
  .book-save-btn { opacity: 1; }
}
.category-pill--saved { color: var(--accent); }

/* ── Phase 24: account listening stats card ────────────────────── */
.listening-stats {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
  gap: 12px; margin-top: 12px;
}
.listening-stat {
  background: var(--surface-hi); border-radius: var(--r-md);
  padding: 14px 12px; text-align: center;
}
.listening-stat-value {
  font-size: 1.4rem; font-weight: 700; color: var(--accent);
  line-height: 1.2;
}
.listening-stat-label {
  font-size: .72rem; color: var(--text-2); margin-top: 4px;
}

/* ── Phase 25: library controls (search + sort) ────────────────── */
.library-controls {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  margin-bottom: 20px;
}
.library-controls .library-search { margin-bottom: 0; }
.library-sort {
  background: var(--surface-hi); border: 1px solid var(--border);
  color: var(--text); padding: 8px 10px; border-radius: var(--r-md);
  font-size: .85rem; cursor: pointer; outline: none;
}
.library-sort:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.library-sort.hidden { display: none; }

/* ── Phase 25: category shelves ────────────────────────────────── */
.book-grid.shelf-mode { display: block; }
.shelf { margin-bottom: 28px; }
.shelf-header {
  display: flex; align-items: baseline; gap: 10px; margin-bottom: 12px;
}
.shelf-title { font-size: 1.05rem; font-weight: 700; }
.shelf-count { font-size: .78rem; color: var(--text-3); }
.shelf-see-all {
  margin-left: auto; background: none; border: none; cursor: pointer;
  color: var(--accent); font-size: .8rem; font-weight: 600;
  padding: 4px 6px; border-radius: var(--r-sm);
}
.shelf-see-all:hover, .shelf-see-all:focus-visible { background: var(--surface-hi); }
.shelf-row {
  display: flex; gap: 16px; overflow-x: auto;
  scroll-snap-type: x proximity; padding-bottom: 8px;
  -webkit-overflow-scrolling: touch;
}
.shelf-row .book-card {
  flex: 0 0 180px; scroll-snap-align: start;
}
/* Slim scrollbar on shelf rows (WebKit + Firefox) */
.shelf-row::-webkit-scrollbar { height: 6px; }
.shelf-row::-webkit-scrollbar-thumb { background: var(--surface-hi); border-radius: 3px; }
.shelf-row { scrollbar-width: thin; scrollbar-color: var(--surface-hi) transparent; }

/* ── Phase 25: related books (book page sidebar) ───────────────── */
.related-block {
  padding: 14px 16px 18px; border-top: 1px solid var(--border);
}
.related-block.hidden { display: none; }
.related-group + .related-group { margin-top: 18px; }
.related-title {
  font-size: .68rem; font-weight: 700; letter-spacing: .06em;
  text-transform: uppercase; color: var(--text-3); margin-bottom: 10px;
}
.related-item {
  display: flex; align-items: center; gap: 10px;
  padding: 6px; margin: 0 -6px; border-radius: var(--r-sm);
  color: var(--text); text-decoration: none;
}
.related-item:hover, .related-item:focus-visible { background: var(--surface-hi); }
.related-item img {
  width: 30px; height: 45px; object-fit: cover; border-radius: 3px; flex-shrink: 0;
}
.related-item-placeholder {
  width: 30px; height: 45px; display: flex; align-items: center; justify-content: center;
  background: var(--surface-hi); border-radius: 3px; flex-shrink: 0; font-size: .9rem;
}
.related-item-text { display: flex; flex-direction: column; min-width: 0; }
.related-item-title {
  font-size: .8rem; font-weight: 600; line-height: 1.25;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.related-item-author { font-size: .72rem; color: var(--text-2); }

/* ── Phase 25: "Up next" in the completion banner ──────────────── */
.book-completion { flex-wrap: wrap; }
.completion-related {
  flex-basis: 100%;
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding-top: 10px; margin-top: 2px;
  border-top: 1px solid var(--border);
}
.completion-related.hidden { display: none; }
.completion-related-label {
  font-size: .78rem; font-weight: 700; color: var(--text-2);
}
.completion-related-item {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 20px; padding: 4px 12px 4px 4px;
  color: var(--text); text-decoration: none; font-size: .8rem;
}
.completion-related-item:hover, .completion-related-item:focus-visible {
  border-color: var(--accent);
}
.completion-related-item img {
  width: 22px; height: 33px; object-fit: cover; border-radius: 3px;
}
