/* Immersive mobile-first chapter reader */
.reader-body {
  padding-bottom: 0 !important;
  background: var(--r-bg, #f7f2e9);
  color: var(--r-ink, #2b2b2b);
  transition: background .25s ease, color .25s ease;
}
.reader-body[data-rtheme="day"] { --r-bg: #f7f2e9; --r-ink: #2b2b2b; --r-muted: #7a7268; --r-panel: #fffdf8; --r-line: rgba(0,0,0,0.08); }
.reader-body[data-rtheme="sepia"] { --r-bg: #f0e6d2; --r-ink: #3b2f2f; --r-muted: #8a7a66; --r-panel: #f8efdc; --r-line: rgba(80,50,20,0.1); }
.reader-body[data-rtheme="night"] { --r-bg: #0f1115; --r-ink: #c9cdd4; --r-muted: #7d8490; --r-panel: #1a1d24; --r-line: rgba(255,255,255,0.08); }

.reader-progress {
  position: fixed; top: 0; left: 0; height: 2px; z-index: 60;
  background: var(--accent); width: 0; transition: width .15s linear;
}

.reader-top, .reader-bottom {
  position: fixed; left: 0; right: 0; z-index: 55;
  background: color-mix(in srgb, var(--r-panel) 94%, transparent);
  backdrop-filter: blur(14px);
  border-color: var(--r-line);
  transform: translateY(0);
  transition: transform .28s cubic-bezier(.2,.8,.2,1), opacity .2s;
}
.reader-top { top: 0; border-bottom: 1px solid var(--r-line); }
.reader-bottom {
  bottom: 0; border-top: 1px solid var(--r-line);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
.reader-chrome-hidden .reader-top { transform: translateY(-110%); }
.reader-chrome-hidden .reader-bottom { transform: translateY(110%); }

.reader-top-inner, .reader-bottom-inner {
  display: flex; align-items: center; gap: 8px;
  min-height: 52px; padding: 0 10px; width: min(100%, 820px); margin: 0 auto;
}
.reader-top-inner { justify-content: space-between; }
.r-icon {
  width: 44px; height: 44px; border-radius: 12px;
  display: grid; place-items: center; color: var(--r-ink); flex-shrink: 0;
}
.r-icon:active { background: var(--r-line); }
.r-title-wrap { flex: 1; min-width: 0; text-align: center; padding: 0 4px; }
.r-book { font-size: 0.78rem; color: var(--r-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.r-chapter { font-size: 0.92rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.reader-content {
  width: min(100% - 40px, 720px);
  margin: 0 auto;
  padding: 72px 0 120px;
  font-family: var(--font-serif);
  font-size: var(--r-size, 19px);
  line-height: var(--r-lh, 1.9);
  letter-spacing: 0.02em;
}
.reader-content h1 {
  font-family: var(--font-sans);
  font-size: 1.35em; text-align: center; margin: 0 0 28px;
  font-weight: 700; letter-spacing: 0.04em;
}
.reader-content .ai-note {
  text-align: center; font-family: var(--font-sans); font-size: 0.78rem;
  color: var(--ai); margin: -12px 0 24px; opacity: .9;
}
.reader-content p {
  text-indent: 2em; margin: 0 0 0.85em;
  word-break: break-word;
}
.reader-tap-zone {
  position: fixed; inset: 52px 0 72px 0; z-index: 10;
  display: grid; grid-template-columns: 1fr 1.2fr 1fr;
}
.reader-tap-zone > div { /* left / center / right */ }

.reader-bottom-inner { justify-content: space-around; }
.reader-bottom-inner a, .reader-bottom-inner button {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  min-width: 64px; min-height: 52px; justify-content: center;
  font-size: 0.7rem; color: var(--r-ink); opacity: .9;
}
.reader-bottom-inner a.disabled { opacity: .35; pointer-events: none; }
.reader-bottom-inner svg { width: 22px; height: 22px; }

/* Settings sheet */
.sheet-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.35); z-index: 70;
  opacity: 0; pointer-events: none; transition: opacity .2s;
}
.sheet-backdrop.open { opacity: 1; pointer-events: auto; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 80;
  background: var(--r-panel); color: var(--r-ink);
  border-radius: 20px 20px 0 0;
  padding: 12px 20px calc(20px + env(safe-area-inset-bottom, 0px));
  transform: translateY(110%); transition: transform .3s cubic-bezier(.2,.8,.2,1);
  max-height: 75dvh; overflow: auto;
  box-shadow: 0 -12px 40px rgba(0,0,0,0.18);
}
.sheet.open { transform: translateY(0); }
.sheet-handle {
  width: 40px; height: 4px; border-radius: 999px; background: var(--r-line);
  margin: 4px auto 16px;
}
.sheet h3 { font-size: 1rem; margin-bottom: 14px; }
.setting-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin-bottom: 16px; min-height: 44px;
}
.setting-row label { font-size: 0.9rem; color: var(--r-muted); }
.theme-pills, .size-pills { display: flex; gap: 8px; flex-wrap: wrap; }
.theme-pills button, .size-pills button {
  min-height: 40px; min-width: 64px; padding: 0 14px; border-radius: 999px;
  border: 1px solid var(--r-line); font-size: 0.86rem;
}
.theme-pills button.active, .size-pills button.active {
  background: var(--accent); color: #fff; border-color: transparent;
}
.theme-day { background: #f7f2e9 !important; color: #2b2b2b !important; }
.theme-sepia { background: #f0e6d2 !important; color: #3b2f2f !important; }
.theme-night { background: #0f1115 !important; color: #c9cdd4 !important; }
.theme-day.active, .theme-sepia.active, .theme-night.active {
  outline: 2px solid var(--accent); outline-offset: 2px;
}

/* TOC drawer */
.toc-drawer {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 80;
  width: min(86vw, 360px); background: var(--r-panel); color: var(--r-ink);
  transform: translateX(105%); transition: transform .28s cubic-bezier(.2,.8,.2,1);
  box-shadow: -8px 0 32px rgba(0,0,0,0.2);
  display: flex; flex-direction: column;
}
.toc-drawer.open { transform: translateX(0); }
.toc-head {
  padding: 16px; border-bottom: 1px solid var(--r-line);
  display: flex; align-items: center; justify-content: space-between;
}
.toc-list { overflow: auto; flex: 1; -webkit-overflow-scrolling: touch; }
.toc-list a {
  display: block; padding: 14px 16px; border-bottom: 1px solid var(--r-line);
  font-size: 0.92rem; min-height: 48px;
}
.toc-list a.current { color: var(--accent); font-weight: 600; background: color-mix(in srgb, var(--accent) 10%, transparent); }

@media (min-width: 900px) {
  .reader-content { padding-top: 88px; font-size: var(--r-size, 20px); }
  .reader-tap-zone { display: none; }
}
