/* ============================================================
   LITERARY BOOK READER — DESIGN SYSTEM
   Minimal, clean, distraction-free reading experience
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=Newsreader:ital,opsz,wght@0,6..72,400;0,6..72,500;0,6..72,600;1,6..72,400;1,6..72,500&display=swap');

:root {
  --font-serif: 'Newsreader', Georgia, 'Charter', 'Source Serif Pro', serif;
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  
  --bg-primary: #faf8f5;
  --bg-surface: #ffffff;
  --bg-surface-subtle: #f3efe8;
  --bg-hover: #ede8df;
  --text-primary: #23201d;
  --text-secondary: #57524c;
  --text-tertiary: #878077;
  --border-subtle: #e6e0d5;
  --border-strong: #d5ccbe;
  --accent: #2e4a62;
  --accent-soft: rgba(46, 74, 98, 0.08);
  --accent-text: #1d3345;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 4px 14px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 12px 30px rgba(0, 0, 0, 0.08);

  --font-reader: var(--font-serif);
  --reader-size: 1.1875rem;
  --reader-line-height: 1.8;
  --reader-max-width: 68ch;
}

/* Themes */
body.theme-paper {
  --bg-primary: #faf8f5;
  --bg-surface: #ffffff;
  --bg-surface-subtle: #f3efe8;
  --bg-hover: #ede8df;
  --text-primary: #23201d;
  --text-secondary: #57524c;
  --text-tertiary: #878077;
  --border-subtle: #e8e2d8;
  --border-strong: #d8cfc0;
  --accent: #37474f;
  --accent-soft: rgba(55, 71, 79, 0.08);
  --accent-text: #263238;
}

body.theme-light {
  --bg-primary: #ffffff;
  --bg-surface: #fbfbfb;
  --bg-surface-subtle: #f3f4f6;
  --bg-hover: #e5e7eb;
  --text-primary: #111827;
  --text-secondary: #4b5563;
  --text-tertiary: #9ca3af;
  --border-subtle: #e5e7eb;
  --border-strong: #d1d5db;
  --accent: #1e3a8a;
  --accent-soft: rgba(30, 58, 138, 0.06);
  --accent-text: #172554;
}

body.theme-sepia {
  --bg-primary: #f5eedb;
  --bg-surface: #fbf7ec;
  --bg-surface-subtle: #ebe2cb;
  --bg-hover: #e0d5ba;
  --text-primary: #382c1e;
  --text-secondary: #63533e;
  --text-tertiary: #8f7d66;
  --border-subtle: #e4d8be;
  --border-strong: #d3c4a4;
  --accent: #5c3b1e;
  --accent-soft: rgba(92, 59, 30, 0.08);
  --accent-text: #4a2c13;
}

body.theme-dark {
  --bg-primary: #151719;
  --bg-surface: #1e2024;
  --bg-surface-subtle: #272a30;
  --bg-hover: #31353c;
  --text-primary: #e6e8eb;
  --text-secondary: #a3a8b0;
  --text-tertiary: #717680;
  --border-subtle: #2b2e35;
  --border-strong: #393d46;
  --accent: #7ca8d9;
  --accent-soft: rgba(124, 168, 217, 0.12);
  --accent-text: #a8ccf3;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 14px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 12px 30px rgba(0, 0, 0, 0.5);
}

body.theme-oled {
  --bg-primary: #000000;
  --bg-surface: #0f0f10;
  --bg-surface-subtle: #17181a;
  --bg-hover: #222326;
  --text-primary: #d4d4d8;
  --text-secondary: #909099;
  --text-tertiary: #60606a;
  --border-subtle: #1f2024;
  --border-strong: #2c2d33;
  --accent: #89b4e6;
  --accent-soft: rgba(137, 180, 230, 0.12);
  --accent-text: #bad6fa;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.6);
  --shadow-md: 0 4px 14px rgba(0, 0, 0, 0.8);
  --shadow-lg: 0 12px 30px rgba(0, 0, 0, 0.9);
}

/* Font scale classes */
body.font-sans-mode {
  --font-reader: var(--font-sans);
}

body.font-size-sm {
  --reader-size: 0.9375rem;
  --reader-line-height: 1.7;
}
body.font-size-sm .reader-prose {
  font-size: 0.9375rem;
  line-height: 1.7;
}

body.font-size-md {
  --reader-size: 1.1875rem;
  --reader-line-height: 1.82;
}
body.font-size-md .reader-prose {
  font-size: 1.1875rem;
  line-height: 1.82;
}

body.font-size-lg {
  --reader-size: 1.375rem;
  --reader-line-height: 1.88;
}
body.font-size-lg .reader-prose {
  font-size: 1.375rem;
  line-height: 1.88;
}

body.font-size-xl {
  --reader-size: 1.625rem;
  --reader-line-height: 1.95;
}
body.font-size-xl .reader-prose {
  font-size: 1.625rem;
  line-height: 1.95;
}

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

html {
  font-size: 16px;
  scroll-behavior: smooth;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  background-color: var(--bg-primary);
  color: var(--text-primary);
  font-family: var(--font-sans);
  line-height: 1.5;
  min-height: 100vh;
  transition: background-color 0.25s ease, color 0.25s ease;
}

a {
  color: inherit;
  text-decoration: none;
}

button {
  font-family: inherit;
  border: none;
  background: none;
  cursor: pointer;
  color: inherit;
}

/* ---------------- Layout & Shell ---------------- */
.site-shell {
  max-width: 980px;
  margin: 0 auto;
  padding: 2.5rem 1.5rem 5rem;
}

@media (max-width: 640px) {
  .site-shell {
    padding: 1.5rem 1rem 4rem;
  }
}

/* ---------------- Home Header & Hero ---------------- */
.book-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 2rem;
  border-bottom: 1px solid var(--border-subtle);
  margin-bottom: 3.5rem;
}

.brand-title {
  font-size: 1.125rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}

.brand-badge {
  font-size: 0.75rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  background: var(--bg-surface-subtle);
  color: var(--text-secondary);
  border: 1px solid var(--border-subtle);
}

.hero-section {
  display: grid;
  grid-template-columns: 260px 1fr;
  gap: 3.5rem;
  align-items: center;
  max-width: 900px;
  margin: 0 auto 3.5rem;
  text-align: left;
}

@media (max-width: 768px) {
  .hero-section {
    grid-template-columns: 1fr;
    gap: 2rem;
    text-align: center;
  }
}

.book-cover-wrapper {
  display: flex;
  justify-content: center;
}

.book-cover-card {
  position: relative;
  width: 100%;
  max-width: 250px;
  border-radius: 10px;
  overflow: hidden;
  cursor: pointer;
  box-shadow: 
    0 4px 6px -1px rgba(0, 0, 0, 0.08),
    0 16px 32px -4px rgba(0, 0, 0, 0.16),
    0 0 0 1px var(--border-subtle);
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1), box-shadow 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.book-cover-card:hover {
  transform: translateY(-4px) rotate(-1deg);
  box-shadow: 
    0 8px 16px -2px rgba(0, 0, 0, 0.12),
    0 24px 48px -6px rgba(0, 0, 0, 0.24),
    0 0 0 1px var(--border-strong);
}

.book-cover-card img {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 2 / 3;
  object-fit: cover;
}

.cover-preview-badge {
  position: absolute;
  bottom: 0.625rem;
  right: 0.625rem;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.25rem 0.55rem;
  font-size: 0.6875rem;
  font-weight: 500;
  color: #ffffff;
  background: rgba(15, 17, 20, 0.82);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 0.2s ease, transform 0.2s ease;
  pointer-events: none;
}

.book-cover-card:hover .cover-preview-badge,
.book-cover-card:focus-visible .cover-preview-badge {
  opacity: 1;
  transform: translateY(0);
}

/* Image Preview Lightbox Modal */
.image-preview-modal {
  position: fixed;
  inset: 0;
  z-index: 250;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background: rgba(0, 0, 0, 0.86);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.25s ease, visibility 0.25s ease;
}

.image-preview-modal.open {
  opacity: 1;
  visibility: visible;
}

.image-preview-content {
  position: relative;
  max-width: 90vw;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.image-preview-img {
  max-width: 100%;
  max-height: 82vh;
  border-radius: 8px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
  object-fit: contain;
}

.image-preview-close {
  position: absolute;
  top: -2.75rem;
  right: 0;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: rgba(255, 255, 255, 0.15);
  color: #ffffff;
  border: 1px solid rgba(255, 255, 255, 0.25);
  padding: 0.4rem 0.85rem;
  border-radius: 9999px;
  font-size: 0.8125rem;
  cursor: pointer;
  transition: background 0.15s ease;
}

.image-preview-close:hover {
  background: rgba(255, 255, 255, 0.28);
}

.hero-content {
  display: flex;
  flex-direction: column;
}

.book-tagline {
  font-size: 0.8125rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--text-tertiary);
  margin-bottom: 0.75rem;
}

.book-title {
  font-family: var(--font-serif);
  font-size: clamp(2.5rem, 5vw, 3.75rem);
  font-weight: 500;
  line-height: 1.08;
  letter-spacing: -0.02em;
  color: var(--text-primary);
  margin-bottom: 0.5rem;
}

.book-motto {
  font-family: var(--font-serif);
  font-style: italic;
  font-size: 1.0625rem;
  color: var(--text-tertiary);
  margin-bottom: 1.25rem;
}

.book-synopsis {
  font-family: var(--font-serif);
  font-size: 1.1875rem;
  line-height: 1.65;
  color: var(--text-secondary);
  margin-bottom: 2rem;
}

.hero-actions {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

@media (max-width: 768px) {
  .hero-actions {
    justify-content: center;
  }
}

.btn-primary {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--text-primary);
  color: var(--bg-primary);
  padding: 0.875rem 1.75rem;
  border-radius: 8px;
  font-weight: 500;
  font-size: 1rem;
  transition: transform 0.15s ease, opacity 0.15s ease;
  box-shadow: var(--shadow-sm);
}

.btn-primary:hover {
  transform: translateY(-1px);
  opacity: 0.94;
}

.btn-secondary {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--bg-surface);
  color: var(--text-primary);
  border: 1px solid var(--border-strong);
  padding: 0.875rem 1.5rem;
  border-radius: 8px;
  font-weight: 500;
  font-size: 1rem;
  transition: background-color 0.15s ease;
}

.btn-secondary:hover {
  background: var(--bg-hover);
}

/* ---------------- Stats Grid ---------------- */
.stats-strip {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  padding: 1.5rem;
  margin-bottom: 4rem;
  box-shadow: var(--shadow-sm);
}

@media (max-width: 640px) {
  .stats-strip {
    grid-template-columns: repeat(2, 1fr);
    gap: 1.25rem;
  }
}

.stat-item {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.stat-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: var(--bg-surface-subtle);
  color: var(--text-secondary);
  margin-bottom: 0.6rem;
}

.stat-val {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text-primary);
}

.stat-lbl {
  font-size: 0.8125rem;
  color: var(--text-secondary);
  margin-top: 0.25rem;
}

/* ---------------- Chapter List / TOC Section ---------------- */
.toc-section {
  margin-top: 2rem;
}

.toc-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
  gap: 1rem;
}

.toc-heading {
  font-size: 1.5rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.search-box {
  position: relative;
  width: 100%;
  max-width: 320px;
}

.search-input {
  width: 100%;
  padding: 0.625rem 1rem 0.625rem 2.25rem;
  font-size: 0.875rem;
  font-family: inherit;
  border-radius: 8px;
  border: 1px solid var(--border-strong);
  background: var(--bg-surface);
  color: var(--text-primary);
  outline: none;
  transition: border-color 0.15s ease;
}

.search-input:focus {
  border-color: var(--accent);
}

.search-icon {
  position: absolute;
  left: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-tertiary);
  pointer-events: none;
  display: flex;
  align-items: center;
  justify-content: center;
}

.icon-inline {
  display: inline-block;
  vertical-align: middle;
  flex-shrink: 0;
}

.chapters-table {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.chapter-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border-subtle);
  transition: background-color 0.15s ease;
}

.chapter-row:last-child {
  border-bottom: none;
}

.chapter-row:hover {
  background: var(--bg-hover);
}

.cr-left {
  display: flex;
  align-items: baseline;
  gap: 1rem;
  flex: 1;
}

.cr-num {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-tertiary);
  min-width: 70px;
}

.cr-title {
  font-family: var(--font-serif);
  font-size: 1.0625rem;
  font-weight: 500;
  color: var(--text-primary);
}

.cr-right {
  font-size: 0.8125rem;
  color: var(--text-tertiary);
  margin-left: 1rem;
  white-space: nowrap;
}

/* ---------------- Reader Page Layout ---------------- */
.reader-chrome {
  position: sticky;
  top: 0;
  left: 0;
  right: 0;
  z-index: 50;
  background: var(--bg-primary);
  border-bottom: 1px solid var(--border-subtle);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  transition: background-color 0.25s ease, border-color 0.25s ease;
}

.reader-nav {
  max-width: 980px;
  margin: 0 auto;
  padding: 0.75rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.nav-left, .nav-right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.nav-center {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-secondary);
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 360px;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  padding: 0.45rem 0.75rem;
  font-size: 0.875rem;
  font-weight: 500;
  border-radius: 6px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  transition: all 0.15s ease;
}

.icon-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
  border-color: var(--border-strong);
}

.progress-indicator-bar {
  position: absolute;
  bottom: 0;
  left: 0;
  height: 2px;
  background: var(--accent);
  width: 0%;
  transition: width 0.1s ease-out;
}

/* ---------------- Reader Article ---------------- */
.reader-container {
  max-width: var(--reader-max-width);
  margin: 0 auto;
  padding: 3.5rem 1.5rem 6rem;
}

.reader-chapter-header {
  margin-bottom: 2.75rem;
  text-align: left;
  border-bottom: 1px solid var(--border-subtle);
  padding-bottom: 1.75rem;
}

.chapter-eyebrow {
  font-size: 0.8125rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-tertiary);
  margin-bottom: 0.5rem;
}

.chapter-headline {
  font-family: var(--font-serif);
  font-size: clamp(2rem, 4vw, 2.75rem);
  font-weight: 500;
  line-height: 1.2;
  letter-spacing: -0.02em;
  color: var(--text-primary);
}

.reader-prose {
  font-family: var(--font-reader);
  font-size: var(--reader-size);
  line-height: var(--reader-line-height);
  color: var(--text-primary);
}

.reader-prose p {
  margin-bottom: 1.4em;
  text-rendering: optimizeLegibility;
}

.reader-prose p:last-child {
  margin-bottom: 0;
}

.reader-prose em {
  font-style: italic;
}

.reader-prose strong {
  font-weight: 600;
}

/* ---------------- Chapter Footer Navigation ---------------- */
.chapter-footer {
  margin-top: 4.5rem;
  padding-top: 2.5rem;
  border-top: 1px solid var(--border-subtle);
}

.chapter-nav-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
}

@media (max-width: 600px) {
  .chapter-nav-grid {
    grid-template-columns: 1fr;
  }
}

.nav-card {
  display: flex;
  flex-direction: column;
  padding: 1.25rem;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  transition: all 0.15s ease;
}

.nav-card:hover {
  background: var(--bg-hover);
  border-color: var(--border-strong);
  transform: translateY(-1px);
}

.nav-card.nav-prev {
  text-align: left;
}

.nav-card.nav-next {
  text-align: right;
}

.nav-card-label {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-tertiary);
  margin-bottom: 0.35rem;
}

.nav-card-title {
  font-family: var(--font-serif);
  font-size: 1.0625rem;
  font-weight: 500;
  color: var(--text-primary);
}

/* ---------------- Drawers & Popovers ---------------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(4px);
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.modal-backdrop.open {
  opacity: 1;
  pointer-events: auto;
}

.toc-drawer {
  position: fixed;
  top: 0;
  bottom: 0;
  right: 0;
  width: 100%;
  max-width: 420px;
  background: var(--bg-primary);
  border-left: 1px solid var(--border-strong);
  z-index: 101;
  transform: translateX(100%);
  transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
}

.toc-drawer.open {
  transform: translateX(0);
}

.drawer-header {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.drawer-title {
  font-size: 1.125rem;
  font-weight: 600;
}

.drawer-search {
  padding: 0.75rem 1.5rem;
  border-bottom: 1px solid var(--border-subtle);
}

.drawer-list {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem 0;
}

.drawer-item {
  display: block;
  padding: 0.75rem 1.5rem;
  border-bottom: 1px solid var(--border-subtle);
  transition: background-color 0.15s ease;
}

.drawer-item:hover {
  background: var(--bg-hover);
}

.drawer-item.active {
  background: var(--accent-soft);
  color: var(--accent-text);
  font-weight: 600;
  border-left: 3px solid var(--accent);
}

.settings-panel {
  position: fixed;
  top: 4.25rem;
  right: 1.5rem;
  width: 290px;
  background: var(--bg-surface);
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  padding: 1.25rem;
  z-index: 101;
  box-shadow: var(--shadow-lg);
  display: none;
}

.settings-panel.open {
  display: block;
}

.setting-group {
  margin-bottom: 1.25rem;
}

.setting-group:last-child {
  margin-bottom: 0;
}

.setting-label {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-tertiary);
  margin-bottom: 0.65rem;
  display: block;
}

.theme-options {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 0.4rem;
}

.theme-dot {
  height: 36px;
  border-radius: 6px;
  border: 1px solid var(--border-strong);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.6875rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.15s ease;
}

.theme-dot:hover {
  transform: scale(1.05);
}

.theme-dot.active {
  box-shadow: 0 0 0 2px var(--accent);
}

.btn-group {
  display: flex;
  gap: 0.5rem;
}

.btn-choice {
  flex: 1;
  padding: 0.5rem 0.75rem;
  font-size: 0.8125rem;
  font-weight: 500;
  border-radius: 6px;
  background: var(--bg-surface-subtle);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  text-align: center;
}

.btn-choice.active {
  background: var(--accent-soft);
  color: var(--accent-text);
  border-color: var(--accent);
  font-weight: 600;
}

/* ---------------- Footer ---------------- */
.site-footer {
  text-align: center;
  padding: 3rem 1.5rem 2rem;
  font-size: 0.875rem;
  color: var(--text-tertiary);
  border-top: 1px solid var(--border-subtle);
  margin-top: 4rem;
}

.site-footer a {
  text-decoration: underline;
  text-underline-offset: 3px;
}

/* ---------------- Paper Texture Filter (All Themes) ---------------- */
.paper-texture-svg {
  position: absolute;
  width: 0;
  height: 0;
  pointer-events: none;
  opacity: 0;
}

.paper-texture-overlay {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  pointer-events: none;
  z-index: 1;
  filter: url(#roughpaper);
  opacity: 0.16;
  mix-blend-mode: multiply;
}

body.theme-sepia .paper-texture-overlay {
  opacity: 0.22;
  mix-blend-mode: multiply;
}

body.theme-light .paper-texture-overlay {
  opacity: 0.12;
  mix-blend-mode: multiply;
}

body.theme-dark .paper-texture-overlay {
  opacity: 0.12;
  mix-blend-mode: overlay;
}

body.theme-oled .paper-texture-overlay {
  opacity: 0.08;
  mix-blend-mode: overlay;
}

.site-shell,
.reader-container {
  position: relative;
  z-index: 2;
}

/* ---------------- Phone & Mobile Optimization ---------------- */
* {
  -webkit-tap-highlight-color: transparent;
}

button, a, input {
  touch-action: manipulation;
}

@media (max-width: 640px) {
  .site-shell {
    padding: 1.25rem 1rem max(3.5rem, calc(2rem + env(safe-area-inset-bottom, 0px)));
  }

  .book-header {
    padding-bottom: 1.25rem;
    margin-bottom: 2rem;
  }

  .hero-section {
    grid-template-columns: 1fr;
    gap: 1.75rem;
    text-align: center;
    margin-bottom: 2.75rem;
  }

  .book-cover-card {
    max-width: 190px;
  }

  .book-title {
    font-size: 2.25rem;
  }

  .book-motto {
    font-size: 0.9375rem;
    margin-bottom: 1rem;
  }

  .book-synopsis {
    font-size: 1.0625rem;
    line-height: 1.6;
    margin-bottom: 1.5rem;
  }

  .hero-actions {
    flex-direction: column;
    width: 100%;
    gap: 0.75rem;
  }

  .hero-actions .btn-primary,
  .hero-actions .btn-secondary {
    width: 100%;
    justify-content: center;
    padding: 0.9rem 1.25rem;
    min-height: 48px;
    font-size: 0.9375rem;
  }

  .stats-strip {
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem;
    padding: 1rem 0.75rem;
    margin-bottom: 2.5rem;
  }

  .stat-val {
    font-size: 1.25rem;
  }

  .stat-lbl {
    font-size: 0.75rem;
  }

  .toc-heading {
    font-size: 1.25rem;
  }

  .search-box {
    max-width: 100%;
  }

  .chapter-row {
    padding: 0.85rem 1rem;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.35rem;
    min-height: 56px;
  }

  .cr-left {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.15rem;
  }

  .cr-num {
    font-size: 0.75rem;
  }

  .cr-title {
    font-size: 0.9375rem;
  }

  .cr-right {
    margin-left: 0;
    font-size: 0.75rem;
  }

  /* Reader chrome on phones */
  .reader-nav {
    padding: 0.65rem 0.85rem;
  }

  .nav-center {
    display: none;
  }

  .nav-left, .nav-right {
    gap: 0.5rem;
  }

  .icon-btn {
    padding: 0.5rem 0.75rem;
    min-height: 40px;
    font-size: 0.8125rem;
  }

  .reader-container {
    padding: 1.75rem 1rem max(4.5rem, calc(2.5rem + env(safe-area-inset-bottom, 0px)));
  }

  .reader-chapter-header {
    margin-bottom: 2rem;
    padding-bottom: 1.25rem;
  }

  .chapter-headline {
    font-size: 1.75rem;
    line-height: 1.2;
  }


  .chapter-footer {
    margin-top: 3.5rem;
    padding-top: 1.75rem;
  }

  .chapter-nav-grid {
    grid-template-columns: 1fr;
    gap: 1rem;
  }

  .nav-card {
    padding: 1.1rem;
    min-height: 64px;
  }

  /* TOC drawer on phones */
  .toc-drawer {
    width: 100%;
    max-width: 100%;
  }

  .drawer-header {
    padding: 1rem 1.15rem;
  }

  .drawer-search {
    padding: 0.75rem 1.15rem;
  }

  .drawer-item {
    padding: 0.85rem 1.15rem;
    min-height: 54px;
  }

  /* Settings as a mobile bottom sheet */
  .settings-panel {
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    border-radius: 18px 18px 0 0;
    padding: 1.5rem 1.25rem max(1.75rem, calc(1rem + env(safe-area-inset-bottom, 0px)));
    box-shadow: 0 -12px 40px rgba(0, 0, 0, 0.35);
    border-bottom: none;
    animation: sheetSlideUp 0.22s cubic-bezier(0.16, 1, 0.3, 1);
  }

  @keyframes sheetSlideUp {
    from {
      transform: translateY(100%);
    }
    to {
      transform: translateY(0);
    }
  }

  .theme-dot {
    height: 42px;
  }

  .btn-choice {
    padding: 0.65rem 0.5rem;
    min-height: 40px;
  }
}
