:root {
  color-scheme: light dark;

  &:has(> head > meta[name="color-scheme"][content="dark"]) {
    color-scheme: dark;
  }
  &:has(> head > meta[name="color-scheme"][content="light"]) {
    color-scheme: light;
  }

  /* Raw Light / Dark editorial ink-and-paper palette */
  --bg-light: #f7f4ee;
  --bg-dark: #121417;
  --surface-light: #ffffff;
  --surface-dark: #1a1d22;
  --surface-soft-light: #efeae0;
  --surface-soft-dark: #23272e;
  --surface-glass-light: rgba(247, 244, 238, 0.9);
  --surface-glass-dark: rgba(18, 20, 23, 0.9);

  --ink-light: #1e1b18;
  --ink-dark: #e8e3d9;
  --ink-muted-light: #6a6258;
  --ink-muted-dark: #9c958a;
  --ink-faint-light: #998f82;
  --ink-faint-dark: #6f6960;

  --border-light: rgba(45, 34, 20, 0.11);
  --border-dark: rgba(235, 224, 204, 0.11);
  --border-strong-light: rgba(45, 34, 20, 0.22);
  --border-strong-dark: rgba(235, 224, 204, 0.22);

  --accent-light: #b83b2a;
  --accent-dark: #e06d58;
  --accent-soft-light: rgba(184, 59, 42, 0.1);
  --accent-soft-dark: rgba(224, 109, 88, 0.16);
  --accent-ink-light: #ffffff;
  --accent-ink-dark: #1a0d0a;

  --gold-light: #a67c37;
  --gold-dark: #d8b064;
  --gold-soft-light: rgba(166, 124, 55, 0.13);
  --gold-soft-dark: rgba(216, 176, 100, 0.16);

  --scrollbar-track-light: #ece7dc;
  --scrollbar-track-dark: #191c21;
  --scrollbar-thumb-light: #9e9384;
  --scrollbar-thumb-dark: #5e5a54;

  --shadow-sm-light: 0 2px 8px rgba(30, 22, 12, 0.06);
  --shadow-sm-dark: 0 2px 10px rgba(0, 0, 0, 0.32);
  --shadow-md-light: 0 12px 32px rgba(30, 22, 12, 0.1);
  --shadow-md-dark: 0 14px 36px rgba(0, 0, 0, 0.48);

  /* Fallback defaults for browsers without light-dark() */
  --bg: var(--bg-light);
  --surface: var(--surface-light);
  --surface-soft: var(--surface-soft-light);
  --surface-glass: var(--surface-glass-light);
  --ink: var(--ink-light);
  --ink-muted: var(--ink-muted-light);
  --ink-faint: var(--ink-faint-light);
  --border: var(--border-light);
  --border-strong: var(--border-strong-light);
  --accent: var(--accent-light);
  --accent-soft: var(--accent-soft-light);
  --accent-ink: var(--accent-ink-light);
  --gold: var(--gold-light);
  --gold-soft: var(--gold-soft-light);
  --scrollbar-track: var(--scrollbar-track-light);
  --scrollbar-thumb: var(--scrollbar-thumb-light);
  --shadow-sm: var(--shadow-sm-light);
  --shadow-md: var(--shadow-md-light);

  @media (prefers-color-scheme: dark) {
    --bg: var(--bg-dark);
    --surface: var(--surface-dark);
    --surface-soft: var(--surface-soft-dark);
    --surface-glass: var(--surface-glass-dark);
    --ink: var(--ink-dark);
    --ink-muted: var(--ink-muted-dark);
    --ink-faint: var(--ink-faint-dark);
    --border: var(--border-dark);
    --border-strong: var(--border-strong-dark);
    --accent: var(--accent-dark);
    --accent-soft: var(--accent-soft-dark);
    --accent-ink: var(--accent-ink-dark);
    --gold: var(--gold-dark);
    --gold-soft: var(--gold-soft-dark);
    --scrollbar-track: var(--scrollbar-track-dark);
    --scrollbar-thumb: var(--scrollbar-thumb-dark);
    --shadow-sm: var(--shadow-sm-dark);
    --shadow-md: var(--shadow-md-dark);
  }

  @supports (color: light-dark(white, black)) {
    --bg: light-dark(var(--bg-light), var(--bg-dark));
    --surface: light-dark(var(--surface-light), var(--surface-dark));
    --surface-soft: light-dark(var(--surface-soft-light), var(--surface-soft-dark));
    --surface-glass: light-dark(var(--surface-glass-light), var(--surface-glass-dark));
    --ink: light-dark(var(--ink-light), var(--ink-dark));
    --ink-muted: light-dark(var(--ink-muted-light), var(--ink-muted-dark));
    --ink-faint: light-dark(var(--ink-faint-light), var(--ink-faint-dark));
    --border: light-dark(var(--border-light), var(--border-dark));
    --border-strong: light-dark(var(--border-strong-light), var(--border-strong-dark));
    --accent: light-dark(var(--accent-light), var(--accent-dark));
    --accent-soft: light-dark(var(--accent-soft-light), var(--accent-soft-dark));
    --accent-ink: light-dark(var(--accent-ink-light), var(--accent-ink-dark));
    --gold: light-dark(var(--gold-light), var(--gold-dark));
    --gold-soft: light-dark(var(--gold-soft-light), var(--gold-soft-dark));
    --scrollbar-track: light-dark(var(--scrollbar-track-light), var(--scrollbar-track-dark));
    --scrollbar-thumb: light-dark(var(--scrollbar-thumb-light), var(--scrollbar-thumb-dark));
    --shadow-sm: light-dark(var(--shadow-sm-light), var(--shadow-sm-dark));
    --shadow-md: light-dark(var(--shadow-md-light), var(--shadow-md-dark));
  }

  /* Reader typography & layout defaults */
  --reader-font-size: 19px;
  --reader-line-height: 1.9;
  --reader-font-family: 'Songti SC', 'Noto Serif CJK SC', 'Source Han Serif SC', 'STSong', 'SimSun', Georgia, serif;
  --reader-indent: 2em;
  --reader-max-width: 740px;

  --reader-bg: var(--bg);
  --reader-surface: var(--surface);
  --reader-ink: var(--ink);

  --ui-font: 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 'Noto Sans CJK SC', system-ui, -apple-system, sans-serif;
  --serif-font: 'Songti SC', 'Noto Serif CJK SC', 'Source Han Serif SC', 'STSong', 'SimSun', Georgia, serif;

  accent-color: var(--accent);
  scrollbar-color: var(--scrollbar-thumb) var(--scrollbar-track);
}

/* Explicit paper theme presets */
:root[data-paper="paper"] {
  --bg: #f9f7f2;
  --surface: #ffffff;
  --surface-soft: #f0ece3;
  --surface-glass: rgba(249, 247, 242, 0.92);
  --reader-bg: #faf8f4;
  --reader-surface: #ffffff;
  --reader-ink: #1e1b18;
}

:root[data-paper="sepia"] {
  --bg: #f1e6cf;
  --surface: #f7eedb;
  --surface-soft: #e6d7b9;
  --surface-glass: rgba(241, 230, 207, 0.92);
  --ink: #382b1e;
  --ink-muted: #6b5843;
  --ink-faint: #927e66;
  --reader-bg: #f1e6cf;
  --reader-surface: #f6ebd5;
  --reader-ink: #33261a;
}

:root[data-paper="mint"] {
  --bg: #dfeadf;
  --surface: #eaf3ea;
  --surface-soft: #cfe0cf;
  --surface-glass: rgba(223, 234, 223, 0.92);
  --ink: #1d2e22;
  --ink-muted: #4b6151;
  --ink-faint: #6f8776;
  --reader-bg: #dfeadf;
  --reader-surface: #e8f1e8;
  --reader-ink: #1a2b1f;
}

:root[data-paper="night"] {
  --bg: #121417;
  --surface: #1a1d22;
  --surface-soft: #23272e;
  --surface-glass: rgba(18, 20, 23, 0.92);
  --ink: #e2ddd2;
  --ink-muted: #9c958a;
  --ink-faint: #6f6960;
  --reader-bg: #111316;
  --reader-surface: #181b20;
  --reader-ink: #d7d2c8;
}

@supports not (scrollbar-color: auto) {
  :root {
    scrollbar-width: auto;
  }
  ::-webkit-scrollbar {
    width: 10px;
    height: 10px;
  }
  ::-webkit-scrollbar-thumb {
    background: var(--scrollbar-thumb);
    border-radius: 999px;
  }
  ::-webkit-scrollbar-track {
    background: var(--scrollbar-track);
  }
}

*, *::before, *::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }
}

body {
  margin: 0;
  min-height: 100dvh;
  font-family: var(--ui-font);
  background: var(--bg);
  color: var(--ink);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  overflow-x: clip;
}

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

button, input {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  border: 0;
  background: transparent;
  -webkit-tap-highlight-color: transparent;
}

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

/* Prevent underlying page scrolling while a modal dialog is open */
dialog:modal {
  overscroll-behavior: contain;
}

dialog::backdrop {
  overflow: hidden;
  overscroll-behavior: contain;
}

/* ============================================================
   Scroll Progress Indicator
   ============================================================ */
#reading-progress {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 3px;
  z-index: 70;
  background: linear-gradient(90deg, var(--accent), var(--gold));
  transform-origin: 0 50%;
  transform: scaleX(0);
  pointer-events: none;
  opacity: 0;
}

html.is-reader #reading-progress {
  opacity: 1;
}

@media (prefers-reduced-motion: no-preference) {
  @supports (animation-timeline: scroll()) {
    @keyframes grow-reading-progress {
      from { transform: scaleX(0); }
      to { transform: scaleX(1); }
    }

    html.is-reader #reading-progress {
      animation: grow-reading-progress auto linear;
      animation-timeline: scroll(root block);
    }
  }
}

/* ============================================================
   Shared Shell & Header Navigation
   ============================================================ */
.site-header {
  position: sticky;
  top: 0;
  z-index: 30;
  background: var(--surface-glass);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
  padding-top: env(safe-area-inset-top);
}

.site-header-inner {
  max-width: 1120px;
  margin: 0 auto;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-seal {
  width: 34px;
  height: 34px;
  flex-shrink: 0;
  border-radius: 9px;
  background: var(--accent);
  color: var(--accent-ink);
  display: grid;
  place-items: center;
  font-family: 'Kaiti SC', 'STKaiti', var(--serif-font);
  font-size: 19px;
  font-weight: 700;
  box-shadow: var(--shadow-sm);
}

.brand-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.brand-name {
  font-family: var(--serif-font);
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 0.04em;
  line-height: 1.2;
}

.brand-sub {
  font-size: 11px;
  color: var(--ink-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.nav-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.nav-pill {
  min-height: 40px;
  padding: 0 13px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  font-weight: 500;
  color: var(--ink-muted);
  transition: background-color 0.16s ease, color 0.16s ease;
}

.nav-pill:hover,
.nav-pill.is-active {
  background: var(--surface-soft);
  color: var(--ink);
}

.nav-pill.is-active {
  color: var(--accent);
  font-weight: 600;
}

.icon-btn {
  min-width: 44px;
  min-height: 44px;
  padding: 0 10px;
  border-radius: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--ink);
  transition: background-color 0.15s ease;
}

.icon-btn:hover {
  background: var(--surface-soft);
}

.page-container {
  max-width: 1120px;
  margin: 0 auto;
  padding: 18px 16px calc(32px + env(safe-area-inset-bottom));
}

/* ============================================================
   Search Bar & Quick Continue Banner
   ============================================================ */
.search-bar-wrap {
  margin-bottom: 18px;
}

.search-box {
  position: relative;
  display: flex;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 4px 10px 4px 14px;
  box-shadow: var(--shadow-sm);
}

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

.search-icon {
  color: var(--ink-faint);
  flex-shrink: 0;
  margin-right: 8px;
}

.search-input {
  width: 100%;
  min-height: 40px;
  border: 0;
  background: transparent;
  font-size: 15px;
  outline: none;
}

.search-input::placeholder {
  color: var(--ink-faint);
}

.search-clear-btn {
  min-width: 36px;
  min-height: 36px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  color: var(--ink-muted);
}

.search-clear-btn:hover {
  background: var(--surface-soft);
}

.continue-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  margin-bottom: 20px;
  border-radius: 16px;
  background: linear-gradient(135deg, var(--accent-soft), var(--gold-soft));
  border: 1px solid var(--border);
}

.continue-info {
  min-width: 0;
}

.continue-kicker {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--accent);
  text-transform: uppercase;
}

.continue-title {
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.continue-sub {
  font-size: 12px;
  color: var(--ink-muted);
}

.btn-primary {
  min-height: 44px;
  padding: 0 20px;
  border-radius: 12px;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 14px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  white-space: nowrap;
  flex-shrink: 0;
  box-shadow: var(--shadow-sm);
  transition: transform 0.12s ease, opacity 0.15s ease;
}

.btn-primary:hover {
  opacity: 0.92;
}

.btn-primary:active {
  transform: scale(0.98);
}

.btn-secondary {
  min-height: 44px;
  padding: 0 18px;
  border-radius: 12px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  color: var(--ink);
  font-size: 14px;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  white-space: nowrap;
}

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

.btn-ghost {
  min-height: 44px;
  padding: 0 16px;
  border-radius: 10px;
  color: var(--ink-muted);
  font-size: 14px;
  font-weight: 500;
}

.btn-ghost:hover {
  background: var(--surface-soft);
  color: var(--ink);
}

/* ============================================================
   Hero Spotlight & Book Cards
   ============================================================ */
.hero-card {
  display: grid;
  grid-template-columns: 112px 1fr;
  gap: 18px;
  padding: 18px;
  border-radius: 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-md);
  margin-bottom: 24px;
}

@media (min-width: 720px) {
  .hero-card {
    grid-template-columns: 168px 1fr;
    gap: 28px;
    padding: 26px;
  }
}

.book-cover-frame {
  position: relative;
  aspect-ratio: 3 / 4;
  border-radius: 10px;
  overflow: hidden;
  background: var(--surface-soft);
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.22);
  flex-shrink: 0;
}

.book-cover-frame img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.hero-body {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.badge-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  background: var(--accent-soft);
  color: var(--accent);
}

.meta-pill {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  background: var(--surface-soft);
  color: var(--ink-muted);
}

.hero-title {
  margin: 0 0 6px;
  font-family: var(--serif-font);
  font-size: clamp(22px, 4.5vw, 30px);
  line-height: 1.25;
  font-weight: 700;
}

.hero-quote {
  margin: 0 0 10px;
  font-size: 13.5px;
  color: var(--gold);
  font-weight: 500;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.hero-synopsis {
  margin: 0 0 14px;
  font-size: 14px;
  color: var(--ink-muted);
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 16px;
}

.tag-chip {
  padding: 3px 9px;
  border-radius: 6px;
  font-size: 12px;
  background: var(--surface-soft);
  color: var(--ink-muted);
}

.hero-actions {
  margin-top: auto;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin: 22px 0 12px;
}

.section-title {
  margin: 0;
  font-family: var(--serif-font);
  font-size: 19px;
  font-weight: 700;
}

.section-sub {
  font-size: 12.5px;
  color: var(--ink-muted);
}

.book-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
}

@media (min-width: 680px) {
  .book-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

.book-card {
  display: grid;
  grid-template-columns: 84px 1fr;
  gap: 14px;
  padding: 14px;
  border-radius: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  transition: transform 0.14s ease, border-color 0.14s ease;
}

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

.book-card-info {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.book-card-title {
  margin: 0 0 4px;
  font-family: var(--serif-font);
  font-size: 17px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.book-card-meta {
  font-size: 12px;
  color: var(--ink-muted);
  margin-bottom: 6px;
}

.book-card-desc {
  margin: 0;
  font-size: 13px;
  color: var(--ink-muted);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* Latest Chapters Feed */
.feed-list {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

@media (min-width: 720px) {
  .feed-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

.feed-item {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 14px 16px;
  border-radius: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  transition: border-color 0.14s ease;
}

.feed-item:hover {
  border-color: var(--accent);
}

.feed-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 12px;
  color: var(--ink-muted);
}

.feed-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--ink);
}

.feed-excerpt {
  font-size: 13px;
  color: var(--ink-muted);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ============================================================
   Book Detail View & Tabs
   ============================================================ */
.breadcrumb-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 14px;
  font-size: 13px;
  color: var(--ink-muted);
}

.breadcrumb-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-height: 36px;
  padding: 0 8px 0 0;
}

.breadcrumb-link:hover {
  color: var(--accent);
}

.detail-header-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 18px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 18px;
}

@media (min-width: 720px) {
  .detail-header-card {
    padding: 24px;
  }
}

.detail-top-grid {
  display: grid;
  grid-template-columns: 108px 1fr;
  gap: 16px;
}

@media (min-width: 720px) {
  .detail-top-grid {
    grid-template-columns: 156px 1fr;
    gap: 24px;
  }
}

.detail-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin: 16px 0;
  padding: 12px;
  border-radius: 14px;
  background: var(--surface-soft);
}

.stat-cell {
  text-align: center;
}

.stat-val {
  display: block;
  font-size: 17px;
  font-weight: 700;
  color: var(--ink);
}

.stat-lbl {
  font-size: 11.5px;
  color: var(--ink-muted);
}

.detail-synopsis {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  font-size: 14.5px;
  line-height: 1.75;
  color: var(--ink-muted);
}

.detail-synopsis p {
  margin: 0 0 10px;
}

.detail-synopsis p:last-child {
  margin-bottom: 0;
}

.realm-pill-bar {
  margin-top: 12px;
  padding: 10px 14px;
  border-radius: 12px;
  background: var(--gold-soft);
  color: var(--ink);
  font-size: 13px;
}

.detail-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 8px;
}

.tab-btn {
  min-height: 44px;
  padding: 0 18px;
  border-radius: 12px;
  font-size: 15px;
  font-weight: 600;
  color: var(--ink-muted);
  transition: background-color 0.14s ease, color 0.14s ease;
}

.tab-btn.is-active {
  background: var(--accent);
  color: var(--accent-ink);
}

.toc-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
}

.toc-filter-input {
  flex: 1 1 200px;
  min-height: 42px;
  padding: 0 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 14px;
}

.pill-btn {
  min-height: 40px;
  padding: 0 14px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 13px;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

.pill-btn:hover {
  background: var(--surface-soft);
}

.volume-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 14px;
  margin-bottom: 16px;
}

.volume-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 4px 12px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 10px;
}

.volume-title {
  margin: 0;
  font-family: var(--serif-font);
  font-size: 16px;
  font-weight: 700;
}

.volume-count {
  font-size: 12px;
  color: var(--ink-muted);
}

.chapter-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 6px;
}

@media (min-width: 680px) {
  .chapter-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }
}

.chapter-link-row {
  min-height: 46px;
  padding: 9px 12px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border: 1px solid transparent;
  transition: background-color 0.12s ease, border-color 0.12s ease;
}

.chapter-link-row:hover {
  background: var(--surface-soft);
}

.chapter-link-row.is-current {
  background: var(--accent-soft);
  border-color: var(--accent);
}

.chapter-link-row.is-read .ch-name {
  color: var(--ink-muted);
}

.ch-left {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.ch-num {
  font-size: 12px;
  color: var(--ink-faint);
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
}

.ch-name {
  font-size: 14.5px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ch-words {
  font-size: 11.5px;
  color: var(--ink-faint);
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
}

/* Codex / Lore Cards */
.codex-category {
  margin-bottom: 20px;
}

.codex-cat-title {
  margin: 0 0 10px;
  font-size: 15px;
  font-weight: 700;
  color: var(--ink-muted);
}

.codex-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

@media (min-width: 680px) {
  .codex-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

.codex-card {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 14px 16px;
  border-radius: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  transition: border-color 0.14s ease;
}

.codex-card:hover {
  border-color: var(--accent);
}

.codex-card-title {
  font-weight: 600;
  font-size: 15px;
}

.codex-card-excerpt {
  font-size: 13px;
  color: var(--ink-muted);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.codex-card-meta {
  font-size: 11.5px;
  color: var(--ink-faint);
}

/* ============================================================
   Reader Mode (Immersive Mobile & Desktop Typography)
   ============================================================ */
html.is-reader body {
  background: var(--reader-bg);
  color: var(--reader-ink);
}

.reader-shell {
  min-height: 100dvh;
  padding-top: calc(64px + env(safe-area-inset-top));
  padding-bottom: calc(88px + env(safe-area-inset-bottom));
}

.reader-topbar,
.reader-bottombar {
  position: fixed;
  left: 0;
  right: 0;
  z-index: 40;
  background: var(--surface-glass);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  transition: transform 0.22s ease, opacity 0.22s ease;
}

.reader-topbar {
  top: 0;
  border-bottom: 1px solid var(--border);
  padding-top: env(safe-area-inset-top);
}

.reader-bottombar {
  bottom: 0;
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}

html.chrome-hidden .reader-topbar {
  transform: translateY(-105%);
  opacity: 0;
  pointer-events: none;
}

html.chrome-hidden .reader-bottombar {
  transform: translateY(105%);
  opacity: 0;
  pointer-events: none;
}

.reader-topbar-inner {
  max-width: 900px;
  margin: 0 auto;
  padding: 6px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.reader-topbar-center {
  flex: 1;
  min-width: 0;
  text-align: center;
}

.reader-topbar-book-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: 0;
}

.reader-topbar-book {
  font-size: 12px;
  color: var(--ink-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

.reader-topbar-pct {
  flex-shrink: 0;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--surface-soft);
  color: var(--ink-muted);
}

.reader-topbar-chapter {
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.reader-bottombar-inner {
  max-width: 740px;
  margin: 0 auto;
  padding: 6px 8px;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 4px;
}

.bar-action-btn {
  min-height: 48px;
  padding: 4px 2px;
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  font-size: 11px;
  color: var(--ink);
}

.bar-action-btn:hover:not(:disabled) {
  background: var(--surface-soft);
}

.bar-action-btn:disabled {
  opacity: 0.36;
  cursor: not-allowed;
}

.bar-action-btn.is-bookmarked {
  color: var(--accent);
}

.reader-article {
  max-width: var(--reader-max-width);
  margin: 0 auto;
  padding: 18px 20px 28px;
}

@media (min-width: 720px) {
  .reader-article {
    margin-top: 16px;
    padding: 36px 48px 44px;
    background: var(--reader-surface);
    border: 1px solid var(--border);
    border-radius: 18px;
    box-shadow: var(--shadow-sm);
  }
}

.chapter-head {
  padding-bottom: 20px;
  margin-bottom: 24px;
  border-bottom: 1px solid var(--border);
}

.chapter-kicker {
  font-size: 12.5px;
  color: var(--gold);
  font-weight: 600;
  letter-spacing: 0.04em;
  margin-bottom: 6px;
}

.chapter-title {
  margin: 0 0 10px;
  font-family: var(--serif-font);
  font-size: clamp(22px, 5vw, 29px);
  line-height: 1.32;
  font-weight: 700;
}

.chapter-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  font-size: 12.5px;
  color: var(--ink-muted);
}

.chapter-prose {
  font-family: var(--reader-font-family);
  font-size: var(--reader-font-size);
  line-height: var(--reader-line-height);
  color: var(--reader-ink);
  letter-spacing: 0.015em;
  overflow-wrap: break-word;
  word-break: break-word;
}

.chapter-p {
  margin: 0 0 0.88em;
  text-align: justify;
  text-indent: var(--reader-indent);
}

.chapter-sub {
  margin: 1.5em 0 0.7em;
  font-size: 1.12em;
  font-weight: 700;
  text-indent: 0;
}

.chapter-quote {
  margin: 1.1em 0;
  padding: 10px 14px;
  border-left: 3px solid var(--gold);
  background: var(--surface-soft);
  border-radius: 0 10px 10px 0;
  font-size: 0.94em;
}

.chapter-quote p {
  margin: 0 0 0.4em;
  text-indent: 0;
}

.chapter-quote p:last-child {
  margin-bottom: 0;
}

.scene-break {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  margin: 1.5em 0;
  color: var(--gold);
  font-size: 13px;
  opacity: 0.78;
}

.chapter-pager {
  max-width: var(--reader-max-width);
  margin: 20px auto 0;
  padding: 0 16px;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.pager-btn {
  min-height: 48px;
  padding: 8px 12px;
  border-radius: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 2px;
  font-size: 13.5px;
  font-weight: 600;
}

.pager-btn:hover:not(:disabled) {
  border-color: var(--accent);
}

.pager-btn:disabled {
  opacity: 0.38;
  cursor: not-allowed;
}

.pager-btn-primary {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: transparent;
}

.pager-sub {
  font-size: 11px;
  font-weight: 400;
  opacity: 0.85;
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ============================================================
   Lore / Codex Document Viewer & Responsive Tables
   ============================================================ */
.doc-layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 18px;
}

@media (min-width: 900px) {
  .doc-layout {
    grid-template-columns: 240px 1fr;
    align-items: start;
  }
}

.doc-sidebar {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 12px;
}

@media (min-width: 900px) {
  .doc-sidebar {
    position: sticky;
    top: 76px;
  }
}

.doc-nav-group {
  margin-bottom: 12px;
}

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

.doc-nav-heading {
  font-size: 11.5px;
  font-weight: 700;
  color: var(--ink-faint);
  padding: 4px 8px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.doc-nav-link {
  display: block;
  padding: 8px 10px;
  border-radius: 10px;
  font-size: 13.5px;
  color: var(--ink-muted);
}

.doc-nav-link:hover {
  background: var(--surface-soft);
  color: var(--ink);
}

.doc-nav-link.is-active {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}

.doc-article {
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 20px 18px;
  box-shadow: var(--shadow-sm);
}

@media (min-width: 720px) {
  .doc-article {
    padding: 28px 34px;
  }
}

.doc-prose {
  font-size: 15.5px;
  line-height: 1.8;
  overflow-wrap: break-word;
}

.doc-prose h1 {
  margin: 0 0 14px;
  font-family: var(--serif-font);
  font-size: clamp(21px, 4.5vw, 27px);
  line-height: 1.3;
}

.doc-prose h2 {
  margin: 26px 0 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
  font-family: var(--serif-font);
  font-size: 19px;
}

.doc-prose h3 {
  margin: 20px 0 8px;
  font-size: 16.5px;
  color: var(--accent);
}

.doc-prose h4,
.doc-prose h5,
.doc-prose h6 {
  margin: 16px 0 6px;
  font-size: 15px;
}

.doc-prose p {
  margin: 0 0 12px;
}

.doc-prose ul,
.doc-prose ol {
  margin: 0 0 14px;
  padding-left: 22px;
}

.doc-prose li {
  margin-bottom: 6px;
}

.doc-prose blockquote {
  margin: 14px 0;
  padding: 10px 14px;
  border-left: 3px solid var(--accent);
  background: var(--surface-soft);
  border-radius: 0 10px 10px 0;
  color: var(--ink-muted);
}

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

.doc-prose hr {
  border: 0;
  border-top: 1px solid var(--border);
  margin: 20px 0;
}

.doc-prose code {
  padding: 2px 6px;
  border-radius: 6px;
  background: var(--surface-soft);
  font-size: 0.88em;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

.doc-pre {
  margin: 14px 0;
  padding: 14px;
  border-radius: 12px;
  background: var(--surface-soft);
  border: 1px solid var(--border);
  overflow-x: auto;
  font-size: 13px;
  line-height: 1.6;
}

.doc-pre code {
  padding: 0;
  background: transparent;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
  margin: 16px 0;
  border: 1px solid var(--border);
  border-radius: 12px;
  -webkit-overflow-scrolling: touch;
}

.table-wrap table {
  width: 100%;
  min-width: 520px;
  border-collapse: collapse;
  font-size: 13.5px;
}

.table-wrap th,
.table-wrap td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

.table-wrap thead th {
  background: var(--surface-soft);
  font-weight: 700;
  white-space: nowrap;
}

.table-wrap tbody tr:last-child td {
  border-bottom: 0;
}

/* ============================================================
   Swipeable Modal Navigation Drawer (#toc-drawer)
   ============================================================ */
.Drawer {
  --drawer-width: min(22rem, 84dvw, 100dvw - 24px);
  --drawer-backdrop: 0;

  inset: 0;
  width: auto;
  height: auto;
  max-width: none;
  max-height: none;
  margin: 0;
  padding: 0;
  background: transparent;
  border: 0;
  overflow: visible;
  color: var(--ink);
}

.Drawer::backdrop {
  background: #000;
  opacity: calc(var(--drawer-backdrop) / 2);
}

.Drawer-scroller {
  position: relative;
  display: grid;
  grid-template-columns: var(--drawer-width) 100%;
  overflow-x: scroll;
  overscroll-behavior: none;
  scrollbar-width: none;
  scroll-snap-type: x mandatory;
}

@media (prefers-reduced-motion: no-preference) {
  .Drawer-scroller {
    scroll-behavior: smooth;
  }
}

.Drawer-scroller::after {
  content: '';
  scroll-snap-align: end;
  scroll-initial-target: nearest;
}

.Drawer-sheet {
  display: grid;
  grid-template-rows: auto auto auto 1fr;
  height: 100svh;
  background: var(--surface);
  color: var(--ink);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  overscroll-behavior: contain;
  scroll-snap-align: start;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
}

@supports (animation-timeline: scroll()) {
  .Drawer {
    timeline-scope: --drawer-fade;
    animation: fade-drawer-backdrop linear both;
    animation-timeline: --drawer-fade;
  }

  .Drawer-scroller {
    scroll-timeline: --drawer-fade x;
  }

  @property --drawer-backdrop {
    syntax: '<number>';
    inherits: true;
    initial-value: 0;
  }

  @keyframes fade-drawer-backdrop {
    0% { --drawer-backdrop: 1; }
    100% { --drawer-backdrop: 0; }
  }
}

.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 14px 12px 10px 16px;
  border-bottom: 1px solid var(--border);
}

.drawer-title-group {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.drawer-book-label {
  font-family: var(--serif-font);
  font-size: 16px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.drawer-book-sub {
  font-size: 12px;
  color: var(--ink-muted);
}

.drawer-tabs {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
  padding: 10px 14px 6px;
}

.drawer-tab {
  min-height: 38px;
  border-radius: 10px;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--ink-muted);
  background: var(--surface-soft);
}

.drawer-tab.is-active {
  background: var(--accent);
  color: var(--accent-ink);
}

.drawer-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border-bottom: 1px solid var(--border);
}

.drawer-filter {
  flex: 1;
  min-width: 0;
  min-height: 38px;
  padding: 0 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  font-size: 13.5px;
}

.drawer-body {
  position: relative;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 8px 10px 24px;
}

.drawer-vol-label {
  padding: 10px 8px 6px;
  font-size: 12px;
  font-weight: 700;
  color: var(--gold);
}

.drawer-ch-item {
  width: 100%;
  min-height: 44px;
  padding: 8px 10px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  text-align: left;
  font-size: 13.5px;
}

.drawer-ch-item:hover {
  background: var(--surface-soft);
}

.drawer-ch-item.is-active {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}

.drawer-bm-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px;
  border-radius: 12px;
  border: 1px solid var(--border);
  margin-bottom: 8px;
}

.drawer-bm-main {
  flex: 1;
  min-width: 0;
  text-align: left;
}

.drawer-bm-title {
  font-size: 14px;
  font-weight: 600;
}

.drawer-bm-snippet {
  font-size: 12px;
  color: var(--ink-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ============================================================
   Modal Settings Sheet Dialog (#settings-dialog)
   ============================================================ */
.SheetDialog {
  width: min(460px, 100vw);
  max-width: 100vw;
  max-height: 90svh;
  margin: auto auto 0;
  padding: 0;
  border: 0;
  border-radius: 22px 22px 0 0;
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-md);
}

@media (min-width: 640px) {
  .SheetDialog {
    margin: auto;
    border-radius: 20px;
  }
}

.SheetDialog::backdrop {
  background: rgba(0, 0, 0, 0.48);
}

.sheet-panel {
  padding: 16px 18px calc(20px + env(safe-area-inset-bottom));
}

.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.sheet-head h2 {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
}

.setting-group {
  margin-bottom: 16px;
}

.setting-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 13.5px;
  font-weight: 600;
  margin-bottom: 8px;
}

.setting-hint {
  font-size: 12px;
  font-weight: 400;
  color: var(--ink-muted);
}

.theme-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
}

.theme-chip {
  min-height: 60px;
  padding: 8px 4px;
  border-radius: 12px;
  border: 1.5px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-size: 11px;
}

.theme-chip.is-active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}

.theme-swatch {
  width: 24px;
  height: 24px;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
}

.swatch-system {
  background: linear-gradient(135deg, #f9f7f2 50%, #15181c 50%);
}
.swatch-paper { background: #faf8f4; }
.swatch-sepia { background: #f1e6cf; }
.swatch-mint { background: #dfeadf; }
.swatch-night { background: #14171c; }

.range-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.range-row input[type="range"] {
  flex: 1;
  min-height: 36px;
}

.range-cap {
  font-size: 13px;
  color: var(--ink-muted);
}

.range-cap-lg {
  font-size: 18px;
  font-weight: 600;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.seg-btn {
  min-height: 40px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  font-size: 13.5px;
  font-weight: 500;
}

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

.setting-width-group {
  display: none;
}

@media (min-width: 720px) {
  .setting-width-group {
    display: block;
  }
}

.setting-row-switch {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 0;
  border-top: 1px solid var(--border);
}

.setting-switch-title {
  font-size: 14px;
  font-weight: 600;
}

.setting-switch-sub {
  font-size: 12px;
  color: var(--ink-muted);
}

.switch-control {
  position: relative;
  display: inline-flex;
  align-items: center;
  cursor: pointer;
}

.switch-control input {
  position: absolute;
  opacity: 0;
  width: 48px;
  height: 28px;
  margin: 0;
}

.switch-track {
  width: 48px;
  height: 28px;
  border-radius: 999px;
  background: var(--border-strong);
  position: relative;
  transition: background-color 0.16s ease;
}

.switch-track::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 22px;
  height: 22px;
  border-radius: 999px;
  background: #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.25);
  transition: transform 0.16s ease;
}

.switch-control input:checked + .switch-track {
  background: var(--accent);
}

.switch-control input:checked + .switch-track::after {
  transform: translateX(20px);
}

.switch-control input:focus-visible + .switch-track {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.sheet-footer {
  display: flex;
  justify-content: flex-end;
  padding-top: 8px;
}

/* ============================================================
   Empty States, Skeletons & Toast
   ============================================================ */
.empty-state {
  text-align: center;
  padding: 44px 20px;
  border-radius: 18px;
  background: var(--surface);
  border: 1px dashed var(--border-strong);
  color: var(--ink-muted);
}

.empty-state h3 {
  margin: 0 0 8px;
  color: var(--ink);
}

.Toast {
  position: fixed;
  left: 50%;
  bottom: calc(82px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(16px);
  z-index: 80;
  padding: 10px 18px;
  border-radius: 999px;
  background: #1e1b18;
  color: #f7f4ee;
  font-size: 13.5px;
  font-weight: 500;
  box-shadow: var(--shadow-md);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.Toast.is-visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.search-results-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 16px;
  margin-bottom: 20px;
  box-shadow: var(--shadow-sm);
}

.search-hit {
  display: block;
  padding: 10px 12px;
  border-radius: 10px;
  border-bottom: 1px solid var(--border);
}

.search-hit:last-child {
  border-bottom: 0;
}

.search-hit:hover {
  background: var(--surface-soft);
}

.search-hit-title {
  font-weight: 600;
  font-size: 14.5px;
}

.search-hit-sub {
  font-size: 12.5px;
  color: var(--ink-muted);
  margin-top: 2px;
}

.bookshelf-card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.loading-box {
  padding: 64px 16px;
  text-align: center;
  color: var(--ink-muted);
}
