/* =============================================================
   Novel Reader — styles
   ============================================================= */

:root {
  /* App chrome (light) */
  --app-bg: #f6f3ee;
  --app-bg-soft: #ffffff;
  --app-text: #23201c;
  --app-text-muted: #7a7166;
  --app-border: #e6dfd4;
  --accent: #9a3b2c;
  --accent-soft: #f2e5e0;
  --shadow-sm: 0 1px 2px rgba(35, 32, 28, 0.06), 0 1px 3px rgba(35, 32, 28, 0.08);
  --shadow-md: 0 6px 20px rgba(35, 32, 28, 0.12);
  --shadow-lg: 0 18px 50px rgba(35, 32, 28, 0.2);

  /* Reading surfaces */
  --reader-bg: #fbf7f0;
  --reader-text: #2b2620;
  --reader-muted: #8a8175;
  --reader-width: 42rem;
  --reader-font: Georgia, "Iowan Old Style", "Times New Roman", Charter, serif;
  --reader-size: 1.06rem;
  --reader-line-height: 1.85;
  --reader-paragraph-space: 1em;

  --radius: 14px;
  --radius-sm: 9px;
  --nav-height: 60px;
  --font-ui: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

[data-theme="dark"] {
  --app-bg: #141210;
  --app-bg-soft: #1e1b18;
  --app-text: #ece7e0;
  --app-text-muted: #9d948a;
  --app-border: #322d27;
  --accent: #d98a75;
  --accent-soft: #33241f;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.45);
  --shadow-lg: 0 20px 60px rgba(0, 0, 0, 0.55);

  --reader-bg: #1a1815;
  --reader-text: #e6dfd4;
  --reader-muted: #8f877b;
}

[data-theme="sepia"] {
  --reader-bg: #f4ecd8;
  --reader-text: #433522;
  --reader-muted: #8b7c5e;
}

/* ------------------------------------------------------------------
   Base
   ------------------------------------------------------------------ */
* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: var(--font-ui);
  background: var(--app-bg);
  color: var(--app-text);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  transition: background 0.3s ease, color 0.3s ease;
}

a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; }
img { display: block; }

::selection { background: var(--accent); color: #fff; }

/* Scrollbar */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: rgba(120, 110, 100, 0.35); border-radius: 20px; border: 2px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-thumb:hover { background: rgba(120, 110, 100, 0.55); background-clip: content-box; }
::-webkit-scrollbar-track { background: transparent; }

/* ------------------------------------------------------------------
   Top navigation (shared)
   ------------------------------------------------------------------ */
.site-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: color-mix(in srgb, var(--app-bg) 82%, transparent);
  backdrop-filter: saturate(180%) blur(14px);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid var(--app-border);
}

.nav {
  height: var(--nav-height);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 20px;
}

.nav .brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: "Baskerville", "Times New Roman", Georgia, serif;
  font-weight: 700;
  font-size: 1.25rem;
  letter-spacing: 0.01em;
  font-variant-numeric: lining-nums tabular-nums;
  color: var(--app-text);
  white-space: nowrap;
}
.brand .brand-lore { color: inherit; }
.brand .brand-365 { color: #c9a227; }
.brand .mark {
  width: 36px; height: 36px;
  display: block;
  object-fit: contain;
}

.nav .spacer { flex: 1; }

.icon-btn {
  width: 38px; height: 38px;
  display: grid; place-items: center;
  border: 1px solid var(--app-border);
  background: var(--app-bg-soft);
  color: var(--app-text);
  border-radius: 10px;
  transition: background 0.15s ease, transform 0.1s ease, border-color 0.15s ease;
}
.icon-btn:hover { background: var(--accent-soft); border-color: var(--accent); }
.icon-btn:active { transform: scale(0.94); }
.icon-btn svg { width: 19px; height: 19px; }
.icon-btn.speaking { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ------------------------------------------------------------------
   Search
   ------------------------------------------------------------------ */
.nav-tagline {
  display: none; /* desktop only */
  margin: 0;
  font-size: 0.85rem;
  font-weight: 400;
  color: var(--app-text-muted);
  white-space: nowrap;
  transform: translateY(3px); /* baseline-align with the LORE365 wordmark */
}

.tagline-mobile {
  display: none; /* mobile only */
  margin: 0;
  padding: 2px 16px 10px;
  text-align: center;
  font-family: var(--font-ui);
  font-size: 0.8rem;
  font-weight: 400;
  color: var(--app-text-muted);
}

.search-wrap {
  position: relative;
  flex: 1;
  max-width: 480px;
}
.search-mobile { display: none; } /* shown only on mobile (see responsive block) */
.search-wrap svg {
  position: absolute;
  left: 13px; top: 50%;
  transform: translateY(-50%);
  width: 17px; height: 17px;
  color: var(--app-text-muted);
  pointer-events: none;
}
.search-input {
  width: 100%;
  height: 40px;
  padding: 0 14px 0 40px;
  font-size: 0.95rem;
  color: var(--app-text);
  background: var(--app-bg-soft);
  border: 1px solid var(--app-border);
  border-radius: 999px;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.search-input::placeholder { color: var(--app-text-muted); }
.search-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent);
}

/* ------------------------------------------------------------------
   Hero
   ------------------------------------------------------------------ */
.hero {
  padding: 22px 20px 4px;
  max-width: 1200px;
  margin: 0 auto;
}
.hero h1 {
  font-family: var(--font-ui);
  font-size: 0.9rem;
  font-weight: 400;
  color: var(--app-text-muted);
  margin: 0;
}

/* ------------------------------------------------------------------
   Toolbar / filters
   ------------------------------------------------------------------ */
.toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 8px 20px 22px;
  max-width: 1200px;
  margin: 0 auto;
}
.toolbar .count {
  color: var(--app-text-muted);
  font-size: 0.9rem;
}
.toolbar .spacer { flex: 1; }

.chips {
  display: flex;
  gap: 8px;
  flex-wrap: nowrap;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto;
  padding: 7px 14px;
  border-radius: 999px;
  border: 1px solid var(--app-border);
  background: var(--app-bg-soft);
  color: var(--app-text-muted);
  font-size: 0.86rem;
  font-weight: 500;
  white-space: nowrap;
  transition: all 0.15s ease;
}
.chip:hover { border-color: var(--accent); color: var(--app-text); }
.chip.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.chip.more-chip { color: var(--accent); font-weight: 600; }
.chip.more-chip:hover { background: var(--accent-soft); }

/* ------------------------------------------------------------------
   Book grid
   ------------------------------------------------------------------ */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(148px, 1fr));
  gap: 22px 16px;
  max-width: 1200px;
  margin: 0 auto;
  padding: 8px 20px 80px;
}

.grid-sentinel { width: 100%; height: 1px; }
.card { display: block; cursor: pointer; }
.card .cover-frame {
  position: relative;
  aspect-ratio: 2 / 3;
  border-radius: 10px;
  overflow: hidden;
  background: linear-gradient(135deg, var(--app-border), var(--app-bg-soft));
  box-shadow: var(--shadow-sm);
  transition: transform 0.25s cubic-bezier(0.2, 0.8, 0.2, 1), box-shadow 0.25s ease;
}
.card .cover-frame img {
  width: 100%; height: 100%;
  object-fit: cover;
  transition: transform 0.4s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.card:hover .cover-frame {
  transform: translateY(-4px);
  box-shadow: var(--shadow-md);
}
.card:hover .cover-frame img { transform: scale(1.05); }

.card .cover-frame::after {
  content: "";
  position: absolute; inset: 0;
  background: linear-gradient(180deg, transparent 60%, rgba(0,0,0,0.25));
  opacity: 0;
  transition: opacity 0.25s ease;
}
.card:hover .cover-frame::after { opacity: 1; }

.card .meta { padding: 10px 2px 0; }
.card .title {
  font-family: Georgia, serif;
  font-weight: 600;
  font-size: 0.92rem;
  line-height: 1.3;
  color: var(--app-text);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.card .author {
  display: inline-block;
  max-width: 100%;
  margin-top: 3px;
  font-size: 0.8rem;
  color: var(--app-text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: color 0.12s ease;
}
.card .author:hover { color: var(--accent); text-decoration: underline; }

/* ------------------------------------------------------------------
   Empty / loading states
   ------------------------------------------------------------------ */
.empty {
  grid-column: 1 / -1;
  text-align: center;
  color: var(--app-text-muted);
  padding: 70px 20px;
}
.spinner {
  width: 34px; height: 34px;
  margin: 0 auto 16px;
  border: 3px solid var(--app-border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ------------------------------------------------------------------
   Footer
   ------------------------------------------------------------------ */
.site-footer {
  border-top: 1px solid var(--app-border);
  padding: 30px 20px;
  text-align: center;
  color: var(--app-text-muted);
  font-size: 0.85rem;
}

/* =============================================================
   Reader page
   ============================================================= */
.reader-body { height: 100vh; height: 100dvh; display: flex; flex-direction: column; overflow: hidden; }

.reader-nav {
  position: sticky; top: 0; z-index: 60;
  height: var(--nav-height);
  display: flex; align-items: center; gap: 10px;
  padding: 0 16px;
  background: color-mix(in srgb, var(--reader-bg) 86%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--app-border);
}
.reader-nav .book-label {
  min-width: 0;
  display: flex; flex-direction: column;
  justify-content: center;
}
.reader-nav .book-label .t {
  font-family: Georgia, serif;
  font-weight: 600;
  font-size: 0.92rem;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  color: var(--reader-text);
}
.reader-nav .book-label .a {
  font-size: 0.74rem; color: var(--reader-muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* Reading progress bar */
.progress-track {
  position: absolute;
  left: 0; bottom: -1px;
  height: 2px; width: 100%;
  background: transparent;
}
.progress-fill {
  height: 100%; width: 0%;
  background: var(--accent);
  transition: width 0.15s linear;
}

/* ------------------------------------------------------------------
   Reading layout
   ------------------------------------------------------------------ */
.reader-main {
  flex: 1;
  display: flex;
  min-height: 0;
}

.reader-stage {
  flex: 1;
  overflow-y: auto;
  min-width: 0;
}

.reader-scroll { padding: 40px 20px 120px; }

.reader-prose {
  max-width: var(--reader-width);
  margin: 0 auto;
  font-family: var(--reader-font);
  font-size: var(--reader-size);
  line-height: var(--reader-line-height);
  color: var(--reader-text);
}

.chapter-heading {
  font-family: var(--reader-font);
  font-size: 1.7em;
  line-height: 1.25;
  font-weight: 700;
  text-align: center;
  margin: 0 0 1.6em;
  letter-spacing: -0.01em;
}
.chapter-heading .book-title-top {
  display: block;
  font-size: 0.55em;
  color: var(--reader-muted);
  font-weight: 400;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  margin-bottom: 1.2em;
}

/* Typography of imported book content */
.reader-prose .chapter-content p { margin: 0 0 var(--reader-paragraph-space); text-indent: 0; text-align: justify; hyphens: auto; }
.reader-prose .chapter-content h1,
.reader-prose .chapter-content h2,
.reader-prose .chapter-content h3,
.reader-prose .chapter-content h4,
.reader-prose .chapter-content h5,
.reader-prose .chapter-content h6 {
  text-align: center;
  margin: 2em auto 1em;
  line-height: 1.3;
  font-weight: 700;
}
.reader-prose .chapter-content h1 { font-size: 1.6em; }
.reader-prose .chapter-content h2 { font-size: 1.4em; }
.reader-prose .chapter-content h3 { font-size: 1.2em; }
.reader-prose .chapter-content h4 { font-size: 1.05em; }
.reader-prose .chapter-content h5, .reader-prose .chapter-content h6 { font-size: 1em; }

.reader-prose .chapter-content blockquote {
  margin: 1.4em 0;
  padding: 0.2em 1.4em;
  border-left: 3px solid var(--accent);
  color: color-mix(in srgb, var(--reader-text) 88%, var(--reader-muted));
  font-style: italic;
}
.reader-prose .chapter-content pre {
  white-space: pre-wrap;
  font-family: var(--reader-font);
  margin: 1.4em 0;
  padding: 1em 1.2em;
  background: color-mix(in srgb, var(--reader-text) 5%, transparent);
  border-radius: 8px;
}
.reader-prose .chapter-content img {
  max-width: 100% !important;
  height: auto !important;
  display: block !important;
  margin: 1.6em auto !important;
  border-radius: 6px;
  float: none !important;
}
/* Center Gutenberg figure wrappers (`.fig` with inline width, e.g. 60%) so the
   image doesn't hug the left edge. */
.reader-prose .chapter-content .fig,
.reader-prose .chapter-content div[class*="fig"] {
  margin-left: auto !important;
  margin-right: auto !important;
}
/* Restore Gutenberg's centered-figure classes. */
.reader-prose .chapter-content .figcenter,
.reader-prose .chapter-content div[class*="figcenter"],
.reader-prose .chapter-content .figcenterwide,
.reader-prose .chapter-content div[class*="center"] {
  text-align: center;
}
.reader-prose .chapter-content div[class*="figleft"],
.reader-prose .chapter-content div[class*="figright"] {
  text-align: center;
}
.reader-prose .chapter-content div[class*="figleft"] img,
.reader-prose .chapter-content div[class*="figright"] img { margin-left: auto !important; margin-right: auto !important; }
.reader-prose .chapter-content table {
  display: block;
  overflow-x: auto;
  margin: 1.4em 0;
  border-collapse: collapse;
  font-size: 0.9em;
}
.reader-prose .chapter-content td, .reader-prose .chapter-content th {
  padding: 0.35em 0.6em;
  border: 1px solid color-mix(in srgb, var(--reader-text) 20%, transparent);
}
.reader-prose .chapter-content hr {
  border: none;
  border-top: 1px solid color-mix(in srgb, var(--reader-text) 22%, transparent);
  margin: 2em auto;
  width: 40%;
}
.reader-prose .chapter-content .pagenum, .reader-prose .chapter-content span[class*="pagenum"] {
  color: var(--reader-muted);
  font-size: 0.7em;
  float: right;
}
.reader-prose .chapter-content a { color: var(--accent); text-decoration: underline; }

/* Read-aloud: highlight the block currently being spoken */
.reader-prose .chapter-content .tts-highlight {
  background: color-mix(in srgb, var(--accent) 16%, transparent);
  border-radius: 5px;
  box-decoration-break: clone;
  transition: background 0.15s ease;
}

/* Chapter navigation footer */
.chapter-nav {
  max-width: var(--reader-width);
  margin: 3.5rem auto 0;
  display: flex;
  gap: 12px;
}
.chapter-nav--top { margin: 0 auto 2rem; }
.chapter-nav .nav-btn {
  flex: 1;
  padding: 13px 16px;
  border: 1px solid var(--app-border);
  background: var(--app-bg-soft);
  border-radius: 12px;
  transition: all 0.15s ease;
}
.chapter-nav .nav-btn:hover { border-color: var(--accent); box-shadow: var(--shadow-sm); }
.chapter-nav .nav-btn .dir {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--reader-muted);
}
.chapter-nav .nav-btn:hover .dir { color: var(--accent); }
.chapter-nav .nav-btn:disabled { opacity: 0.35; cursor: default; }

/* Left: collapsible table of contents (desktop) */
.toc-sidebar {
  flex: 0 0 auto;
  width: 48px;
  display: flex;
  flex-direction: column;
  background: var(--app-bg-soft);
  border-right: 1px solid var(--app-border);
  overflow: hidden;
  transition: width 0.25s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.toc-sidebar.expanded { width: 300px; }
.toc-sidebar-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  height: 52px;
  flex: 0 0 auto;
  padding: 0;
  border: none;
  border-bottom: 1px solid var(--app-border);
  background: none;
  color: var(--app-text-muted);
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
}
.toc-sidebar.expanded .toc-sidebar-toggle { justify-content: flex-start; padding: 0 18px; }
.toc-sidebar-toggle:hover { color: var(--accent); background: color-mix(in srgb, var(--accent) 7%, transparent); }
.toc-sidebar-toggle .ts-toggle-label { font-size: 0.82rem; font-weight: 600; display: none; }
.toc-sidebar.expanded .toc-sidebar-toggle .ts-toggle-label { display: inline; }
.toc-sidebar-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s ease;
}
.toc-sidebar.expanded .toc-sidebar-body { opacity: 1; visibility: visible; }

/* Right: recommended reading (desktop) */
.rec-sidebar {
  flex: 0 0 auto;
  width: 264px;
  display: flex;
  flex-direction: column;
  background: var(--app-bg-soft);
  border-left: 1px solid var(--app-border);
  overflow: hidden;
}
.rec-head {
  flex: 0 0 auto;
  padding: 17px 18px 11px;
  font-family: Georgia, serif;
  font-weight: 700;
  font-size: 0.95rem;
  border-bottom: 1px solid var(--app-border);
}
.rec-body { flex: 1; min-height: 0; overflow-y: auto; padding: 8px; }
.rec-item {
  display: flex;
  gap: 10px;
  padding: 8px;
  border-radius: 10px;
  text-decoration: none;
  transition: background 0.12s ease;
}
.rec-item:hover { background: color-mix(in srgb, var(--accent) 8%, transparent); }
.rec-item img {
  flex: 0 0 auto;
  width: 40px;
  aspect-ratio: 2 / 3;
  object-fit: cover;
  border-radius: 5px;
  background: var(--app-border);
}
.rec-info { min-width: 0; display: flex; flex-direction: column; gap: 2px; justify-content: center; }
.rec-title { font-size: 0.82rem; line-height: 1.25; color: var(--app-text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rec-author { font-size: 0.72rem; color: var(--app-text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rec-empty { color: var(--app-text-muted); font-size: 0.82rem; padding: 12px; }

/* Mobile recommendations (below chapter nav) */
.rec-mobile {
  display: none;
  max-width: var(--reader-width);
  margin: 2.5rem auto 0;
}
.rec-mobile .rec-head { padding: 0 0 10px; border-bottom: none; }
.rec-mobile-body {
  display: flex;
  gap: 14px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
}
.rec-mobile-body .rec-item {
  flex: 0 0 auto;
  width: 148px;
  flex-direction: column;
  gap: 8px;
  padding: 0;
}
.rec-mobile-body .rec-item img {
  width: 148px;
  aspect-ratio: 2 / 3;
  border-radius: 9px;
}
.rec-mobile-body .rec-info { gap: 3px; }
.rec-mobile-body .rec-title { font-size: 0.84rem; }
.rec-mobile-body .rec-author { font-size: 0.76rem; }

/* ------------------------------------------------------------------
   Drawer (TOC + settings)
   ------------------------------------------------------------------ */
.drawer-scrim {
  position: fixed; inset: 0; z-index: 70;
  background: rgba(0, 0, 0, 0.35);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
  backdrop-filter: blur(2px);
}
.drawer-scrim.open { opacity: 1; pointer-events: auto; }

.drawer {
  position: fixed;
  top: 0; bottom: 0; right: 0;
  z-index: 80;
  width: min(360px, 88vw);
  background: var(--app-bg-soft);
  border-left: 1px solid var(--app-border);
  box-shadow: var(--shadow-lg);
  transform: translateX(102%);
  transition: transform 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
  display: flex;
  flex-direction: column;
}
.drawer.open { transform: translateX(0); }
.drawer.left { right: auto; left: 0; transform: translateX(-102%); border-left: none; border-right: 1px solid var(--app-border); }
.drawer.left.open { transform: translateX(0); }

.drawer-head {
  display: flex; align-items: center; gap: 10px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--app-border);
}
.drawer-head h2 { margin: 0; font-family: Georgia, serif; font-size: 1.05rem; }
.drawer-head .spacer { flex: 1; }
.drawer-body { flex: 1; overflow-y: auto; padding: 10px 0; }

/* TOC list */
.toc-item {
  display: flex; align-items: center; gap: 10px;
  width: 100%;
  padding: 11px 18px;
  border: none; background: none;
  color: var(--app-text);
  text-align: left;
  font-size: 0.9rem;
  border-left: 3px solid transparent;
  transition: background 0.12s ease;
}
.toc-item:hover { background: color-mix(in srgb, var(--accent) 8%, transparent); }
.toc-item.active { border-left-color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, transparent); font-weight: 600; }
.toc-item .idx { color: var(--app-text-muted); font-size: 0.78rem; min-width: 30px; text-align: right; font-variant-numeric: tabular-nums; }
.toc-item .toc-title { flex: 1; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }

/* Settings panel */
.settings-group { padding: 16px 18px; border-bottom: 1px solid var(--app-border); }
.settings-group .label {
  font-size: 0.74rem; letter-spacing: 0.1em; text-transform: uppercase;
  color: var(--app-text-muted); margin-bottom: 12px; font-weight: 600;
}
.settings-row { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; }
.settings-row:last-child { margin-bottom: 0; }
.settings-row .key { flex: 1; font-size: 0.9rem; }
.settings-row .val { font-size: 0.8rem; color: var(--app-text-muted); min-width: 44px; text-align: right; font-variant-numeric: tabular-nums; }

.stepper { display: flex; align-items: center; gap: 6px; }
.stepper button {
  width: 30px; height: 30px; border-radius: 8px;
  border: 1px solid var(--app-border); background: var(--app-bg-soft); color: var(--app-text);
  font-size: 15px; line-height: 1;
}
.stepper button:hover { border-color: var(--accent); }

/* Theme swatches */
.theme-swatches { display: flex; gap: 10px; }
.swatch {
  flex: 1; padding: 10px;
  border: 2px solid var(--app-border);
  border-radius: 12px;
  background: none;
  text-align: center;
  font-size: 0.8rem;
  color: var(--app-text);
  transition: border-color 0.15s ease;
}
.swatch.active { border-color: var(--accent); }
.swatch .chip-box { height: 34px; border-radius: 7px; margin-bottom: 7px; border: 1px solid rgba(0,0,0,0.08); }
.swatch .chip-box.light { background: #fbf7f0; }
.swatch .chip-box.sepia { background: #f4ecd8; }
.swatch .chip-box.dark { background: #1a1815; }

/* Segmented font chooser */
.seg { display: flex; border: 1px solid var(--app-border); border-radius: 10px; overflow: hidden; }
.seg button { flex: 1; padding: 9px 4px; border: none; background: none; color: var(--app-text-muted); font-size: 0.85rem; }
.seg button.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

/* Book cover on reader (small hero at top of chapter list) */
.toc-cover { padding: 22px 18px 14px; text-align: center; border-bottom: 1px solid var(--app-border); }
.toc-cover img { width: 96px; aspect-ratio: 2/3; object-fit: cover; border-radius: 8px; margin: 0 auto 10px; box-shadow: var(--shadow-sm); }
.toc-cover .ct { font-family: Georgia, serif; font-weight: 600; font-size: 0.95rem; line-height: 1.3; }
.toc-cover .ca { font-size: 0.8rem; color: var(--app-text-muted); margin-top: 3px; }

/* ------------------------------------------------------------------
   Responsive
   ------------------------------------------------------------------ */
@media (max-width: 640px) {
  .nav { padding: 0 12px; gap: 8px; }
  .search-wrap { display: none; } /* search moves below "Continue reading" on mobile */
  .brand .brand-text { display: none; }
  .search-input { font-size: 16px; } /* avoid iOS auto-zoom on focus */
  .search-mobile {
    display: flex; align-items: center; gap: 8px;
    margin: 12px 16px 2px;
    padding: 0 16px;
    height: 42px;
    background: var(--app-bg-soft);
    border: 1px solid var(--app-border);
    border-radius: 999px;
    color: var(--app-text-muted);
  }
  .search-mobile .search-input { flex: 1; height: 100%; border: none; background: none; box-shadow: none; }
  .tagline-mobile { display: none; }
  /* Mobile: show the slogan inline, right after the logo, bottom-aligned to it. */
  .nav-tagline {
    display: inline;
    align-self: flex-end;
    margin-bottom: 12px; /* align slogan's bottom edge with the 36px logo bottom */
    transform: none;
    font-size: 0.78rem;
  }
  .toolbar { padding: 8px 16px 16px; }
  .chip { padding: 6px 12px; font-size: 0.8rem; }
  .toolbar .count { font-size: 0.82rem; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 16px 10px; padding: 8px 12px 60px; }
  .continue-item, .continue-item img { width: 96px; }
  .reader-scroll { padding: 24px 16px 100px; }
  .reader-prose { --reader-size: 1rem; }

  /* Compact reader nav so every action button fits on one line. */
  .reader-nav { gap: 5px; padding: 0 10px; }
  .reader-nav .icon-btn { width: 34px; height: 34px; }
  .reader-nav .icon-btn svg { width: 17px; height: 17px; }
  .reader-nav .book-label .a { display: none; }
  #themeBtn { display: none; } /* theme is in Settings > Appearance */
  #homeBtn { display: none; } /* "back" already returns to the book detail page */
  .chapter-indicator { font-size: 0.7rem; }
}

@media (min-width: 900px) {
  .grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
}

/* Desktop: show the tagline inline (after the brand) in the nav. */
@media (min-width: 641px) {
  .nav-tagline { display: inline; }
}



/* Hide the reader's desktop sidebars on smaller screens (drawer takes over). */
@media (max-width: 900px) {
  .toc-sidebar, .rec-sidebar { display: none; }
  .rec-mobile { display: block; }
}

/* On desktop the left sidebar replaces the nav's TOC button. */
@media (min-width: 900px) {
  #tocBtn { display: none; }
}

/* ------------------------------------------------------------------
   Category chips (home)
   ------------------------------------------------------------------ */
.cats {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 20px 20px;
}

/* ------------------------------------------------------------------
   Continue reading shelf (home)
   ------------------------------------------------------------------ */
.shelf {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 20px 26px;
}
.shelf-head { margin-bottom: 12px; }
.shelf-title {
  margin: 0;
  font-family: Georgia, serif;
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}
.shelf-row {
  display: flex;
  gap: 16px;
  overflow-x: auto;
  padding-bottom: 8px;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
}
.continue-item {
  flex: 0 0 auto;
  width: 132px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  text-decoration: none;
}
.continue-item img {
  width: 132px;
  aspect-ratio: 2 / 3;
  object-fit: cover;
  border-radius: 9px;
  box-shadow: var(--shadow-sm);
  background: var(--app-border);
}
.continue-item .ci-info { display: flex; flex-direction: column; gap: 5px; }
.continue-item .ci-title {
  font-size: 0.82rem;
  line-height: 1.3;
  color: var(--app-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ci-bar {
  height: 3px;
  border-radius: 3px;
  background: var(--app-border);
  overflow: hidden;
}
.continue-toggle {
  flex: 0 0 auto;
  align-self: center;
  padding: 10px 16px;
  border: 1px solid var(--app-border);
  background: var(--app-bg-soft);
  border-radius: 999px;
  color: var(--app-text-muted);
  font-size: 0.82rem;
  cursor: pointer;
  white-space: nowrap;
}
.continue-toggle:hover { border-color: var(--accent); color: var(--app-text); }
.shelf-row.expanded { flex-wrap: wrap; overflow-x: visible; }
.shelf-row.expanded .continue-toggle { flex-basis: 100%; }

/* Bookshelf banner + nav state (home) */
.shelf-banner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 20px 14px;
  display: flex;
  align-items: center;
  gap: 14px;
  font-size: 0.95rem;
  color: var(--app-text-muted);
}
.icon-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }

/* Detail page buttons — shared base so <a> and <button> align exactly. */
.read-btn,
.shelf-btn {
  font-family: inherit;
  font-size: 1rem;
  font-weight: 600;
  line-height: 1;
  height: 48px;
  padding: 0 26px;
  border-radius: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  transition: transform 0.12s ease, filter 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}
.shelf-btn {
  border: 1px solid var(--app-border);
  background: var(--app-bg-soft);
  color: var(--app-text);
}
.shelf-btn:hover { border-color: var(--accent); }
.shelf-btn.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.ci-bar span { display: block; height: 100%; background: var(--accent); }

/* ------------------------------------------------------------------
   Book detail page
   ------------------------------------------------------------------ */
.book-page {
  max-width: 960px;
  margin: 0 auto;
  padding: 40px 20px 80px;
}
.book-hero {
  display: flex;
  gap: 40px;
  align-items: flex-start;
}
.book-hero-cover {
  flex: 0 0 auto;
  width: 220px;
}
.book-hero-cover img {
  width: 220px;
  aspect-ratio: 2 / 3;
  object-fit: cover;
  border-radius: 12px;
  box-shadow: var(--shadow-md);
  background: var(--app-border);
}
.book-hero-info { flex: 1; min-width: 0; }
.book-category {
  display: inline-block;
  padding: 4px 12px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.76rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  margin-bottom: 14px;
}
.book-title {
  font-family: Georgia, serif;
  font-size: clamp(1.7rem, 4vw, 2.5rem);
  font-weight: 700;
  line-height: 1.15;
  letter-spacing: -0.02em;
  margin: 0 0 8px;
}
.book-author {
  font-size: 1.05rem;
  color: var(--app-text-muted);
  margin-bottom: 22px;
}
.book-stats {
  display: flex;
  gap: 28px;
  margin-bottom: 26px;
  flex-wrap: wrap;
}
.book-stats .stat { display: flex; flex-direction: column; gap: 2px; }
.book-stats .stat .v { font-weight: 700; font-size: 1.1rem; }
.book-stats .stat .k { font-size: 0.76rem; color: var(--app-text-muted); text-transform: uppercase; letter-spacing: 0.06em; }

.read-btn {
  border: 1px solid transparent;
  background: var(--accent);
  color: #fff;
}
.read-btn:hover { filter: brightness(1.08); }
.read-btn:active { transform: scale(0.98); }
.read-btn.ghost {
  background: transparent;
  color: var(--accent);
  border-color: var(--accent);
}
.read-btn.ghost:hover { background: var(--accent-soft); filter: none; }

.book-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-top: 16px;
}
.book-actions--secondary { margin-top: 10px; }

.book-progress {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 18px;
  max-width: 360px;
}
.book-progress .bar {
  flex: 1;
  height: 6px;
  border-radius: 6px;
  background: var(--app-border);
  overflow: hidden;
}
.book-progress .bar .fill { display: block; height: 100%; background: var(--accent); }
.book-progress .pct { font-size: 0.82rem; color: var(--app-text-muted); }

.book-subjects {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 26px;
}
.book-subjects .tag {
  padding: 6px 12px;
  border-radius: 8px;
  background: var(--app-bg-soft);
  border: 1px solid var(--app-border);
  color: var(--app-text-muted);
  font-size: 0.8rem;
}

@media (max-width: 640px) {
  .cats { padding: 0 16px 16px; }
  .shelf { padding: 0 16px 22px; }
  .book-page { padding: 24px 16px 60px; }
  .book-hero { flex-direction: column; gap: 24px; align-items: center; text-align: center; }
  .book-hero-cover { width: 168px; }
  .book-hero-cover img { width: 168px; }
  .book-stats { justify-content: center; }
  .book-progress { margin-inline: auto; }
  .book-subjects { justify-content: center; }
}

/* Read-aloud voice selector */
.voice-select {
  width: 100%;
  padding: 9px 10px;
  font-size: 0.88rem;
  color: var(--app-text);
  background: var(--app-bg);
  border: 1px solid var(--app-border);
  border-radius: 9px;
  outline: none;
}
.voice-select:focus { border-color: var(--accent); }
.voice-hint {
  margin-top: 7px;
  font-size: 0.74rem;
  color: var(--app-text-muted);
}
.rate-range {
  width: 100%;
  margin: 2px 0 12px;
  accent-color: var(--accent);
}

/* Toggle switch */
.switch { position: relative; display: inline-block; width: 42px; height: 24px; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .slider {
  position: absolute; inset: 0;
  background: var(--app-border);
  border-radius: 24px;
  transition: background 0.2s ease;
  cursor: pointer;
}
.switch .slider::before {
  content: "";
  position: absolute; left: 3px; top: 3px;
  width: 18px; height: 18px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.2s ease;
}
.switch input:checked + .slider { background: var(--accent); }
.switch input:checked + .slider::before { transform: translateX(18px); }

/* Chapter indicator (reader nav) */
.chapter-indicator {
  font-size: 0.78rem;
  color: var(--reader-muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  padding: 0 2px;
}

/* Book detail page description */
.book-desc {
  margin: 22px 0 0;
  max-width: 34rem;
  font-family: Georgia, serif;
  font-size: 1.02rem;
  line-height: 1.7;
  color: var(--app-text-muted);
}

/* Author page */
.author-page {
  max-width: 1200px;
  margin: 0 auto;
  padding: 40px 20px 80px;
}
.author-name {
  font-family: Georgia, serif;
  font-size: clamp(1.8rem, 4vw, 2.6rem);
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: 0 0 10px;
}
.author-bio {
  max-width: 46rem;
  font-family: Georgia, serif;
  font-size: 1.02rem;
  line-height: 1.7;
  color: var(--app-text-muted);
  margin: 0 0 10px;
}
.author-wiki {
  display: inline-block;
  margin-bottom: 30px;
  color: var(--accent);
  font-size: 0.9rem;
  font-weight: 600;
}
.author-books-head {
  font-family: Georgia, serif;
  font-size: 1.25rem;
  font-weight: 700;
  margin: 0 0 16px;
}
.author-page .grid { padding: 0; }
.book-author .author-link {
  color: var(--accent);
  font-weight: 600;
}
.book-author .author-link:hover { text-decoration: underline; }

/* Static pages (about / contact / privacy) */
.static-page {
  max-width: 46rem;
  margin: 0 auto;
  padding: 48px 20px 80px;
}
.static-page h1 {
  font-family: Georgia, serif;
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: 0 0 16px;
}
.static-page h2 {
  font-family: Georgia, serif;
  font-size: 1.3rem;
  margin: 32px 0 10px;
}
.static-page p {
  font-size: 1rem;
  line-height: 1.7;
  color: var(--app-text-muted);
  margin: 0 0 14px;
}
.static-page a { color: var(--accent); }

/* Ad slot spacing */
.reader-scroll ins.adsbygoogle, .hero + ins.adsbygoogle {
  margin: 20px auto;
  max-width: var(--reader-width, 42rem);
}

/* Mobile: make Continue-reading items match the 3-column grid size. */
@media (max-width: 640px) {
  .continue-item, .continue-item img { width: 96px; }
}

/* ------------------------------------------------------------------
   Share modal
   ------------------------------------------------------------------ */
.share-modal { display: none; }
.share-modal.open { display: block; }
.share-scrim {
  position: fixed; inset: 0; z-index: 90;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(2px);
}
.share-dialog {
  position: fixed; top: 50%; left: 50%; z-index: 91;
  transform: translate(-50%, -50%);
  width: min(360px, 92vw);
  max-height: 90vh;
  overflow-y: auto;
  background: var(--app-bg-soft);
  border: 1px solid var(--app-border);
  border-radius: 16px;
  box-shadow: var(--shadow-lg);
  padding: 16px;
}
.share-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 12px;
  font-weight: 700;
  font-size: 1rem;
}
.share-close {
  border: none; background: none; color: var(--app-text-muted);
  font-size: 1.6rem; line-height: 1; cursor: pointer;
}
.share-image { text-align: center; }
.share-image img {
  display: block; margin: 0 auto;
  width: 100%; max-width: 260px;
  aspect-ratio: 3 / 4;
  object-fit: contain;
  border-radius: 10px;
  background: var(--app-border);
}
.share-actions { display: flex; flex-direction: column; gap: 10px; margin-top: 16px; }
.share-actions-row { display: flex; gap: 8px; }

.share-action-btn {
  flex: 1;
  padding: 12px 14px;
  border: 1px solid var(--app-border);
  background: var(--app-bg-soft);
  border-radius: 12px; color: var(--app-text);
  font-size: 0.92rem; font-weight: 600;
  cursor: pointer; transition: all 0.12s ease;
}
.share-action-btn:hover { border-color: var(--accent); color: var(--accent); }
.share-action-btn.primary {
  background: var(--accent); border-color: var(--accent); color: #fff;
}
.share-action-btn.primary:hover { filter: brightness(1.08); }
.share-toast {
  position: fixed; left: 50%; bottom: 30px; z-index: 99;
  transform: translateX(-50%) translateY(20px);
  background: var(--app-text); color: var(--app-bg);
  padding: 9px 16px; border-radius: 999px; font-size: 0.85rem;
  opacity: 0; pointer-events: none; transition: all 0.2s ease;
}
.share-toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* Finished-reading card (reader, end of final chapter) */
.finished-card {
  margin: 48px auto 8px;
  max-width: 480px;
  text-align: center;
  padding: 32px 24px;
  border: 1px dashed var(--app-border);
  border-radius: 16px;
  background: var(--app-bg-soft);
}
.finished-title {
  font-family: Georgia, serif;
  font-size: 1.6rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--app-text);
}
.finished-sub {
  margin: 10px 0 20px;
  font-size: 0.9rem;
  color: var(--app-text-muted);
}

/* Text-selection context menu (reader) */
.sel-menu {
  position: fixed; z-index: 95;
  display: flex; flex-direction: column; gap: 2px;
  background: var(--app-bg-soft);
  border: 1px solid var(--app-border);
  border-radius: 10px; box-shadow: var(--shadow-lg);
  padding: 4px; min-width: 150px;
}
.sel-menu button {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px; border: none; background: none;
  color: var(--app-text); font-size: 0.88rem; text-align: left;
  border-radius: 7px; cursor: pointer;
}
.sel-menu button:hover { background: var(--accent-soft); color: var(--accent); }
.sel-menu .sel-sep { height: 1px; background: var(--app-border); margin: 4px 8px; }

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
  html { scroll-behavior: auto; }
}
