/* ==========================================================================
   墨读 · Modu — SillyTavern 小说化阅读器
   ========================================================================== */

:root {
  --sans: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Segoe UI", sans-serif;
  --serif: "Songti SC", "Noto Serif SC", "Source Han Serif SC", "STSong", "SimSun", serif;
  --reader-font: 19px;
  --reader-lh: 2.02;
  --measure: 680px;
  --shelf-w: 352px;

  --bg: #f3ede2;
  --bg-deep: #e9e0d0;
  --panel: #faf6ed;
  --panel-2: #f7f1e5;
  --ink: #2e2821;
  --ink-soft: #655b4e;
  --ink-faint: #94897a;
  --line: rgba(74, 60, 43, 0.13);
  --line-strong: rgba(74, 60, 43, 0.24);
  --accent: #9a6432;
  --accent-deep: #7a4a1f;
  --accent-soft: rgba(154, 100, 50, 0.11);
  --green: #537d5d;
  --amber: #a7782f;
  --red: #a34b3c;
  --shadow: 0 24px 70px rgba(70, 52, 30, 0.18);
  --shadow-soft: 0 8px 26px rgba(70, 52, 30, 0.1);
  --cover-shadow: 0 5px 16px rgba(60, 45, 28, 0.22);
  color-scheme: light;
}

[data-theme="night"] {
  --bg: #141210;
  --bg-deep: #0e0d0b;
  --panel: #1d1a16;
  --panel-2: #191713;
  --ink: #e8dfd1;
  --ink-soft: #b3a896;
  --ink-faint: #807666;
  --line: rgba(235, 220, 195, 0.1);
  --line-strong: rgba(235, 220, 195, 0.2);
  --accent: #d3a064;
  --accent-deep: #e4b57e;
  --accent-soft: rgba(211, 160, 100, 0.12);
  --green: #86b291;
  --amber: #d3a45f;
  --red: #c47a6b;
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.55);
  --shadow-soft: 0 8px 26px rgba(0, 0, 0, 0.35);
  --cover-shadow: 0 6px 18px rgba(0, 0, 0, 0.55);
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  padding: 0;
}

body {
  overflow: hidden;
  font-family: var(--sans);
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  transition: background-color 0.35s ease, color 0.35s ease;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background:
    radial-gradient(1200px 700px at 8% -10%, rgba(154, 100, 50, 0.07), transparent 60%),
    radial-gradient(900px 600px at 100% 0%, rgba(120, 95, 60, 0.05), transparent 60%),
    radial-gradient(800px 500px at 50% 120%, rgba(90, 70, 45, 0.05), transparent 60%);
}

[data-theme="night"] body::before {
  background:
    radial-gradient(1200px 700px at 8% -10%, rgba(211, 160, 100, 0.06), transparent 60%),
    radial-gradient(900px 600px at 100% 0%, rgba(90, 120, 140, 0.04), transparent 60%);
}

::selection {
  background: rgba(154, 100, 50, 0.24);
  color: inherit;
}

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

button { -webkit-tap-highlight-color: transparent; }

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

[hidden] { display: none !important; }

::-webkit-scrollbar { width: 11px; height: 11px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: color-mix(in srgb, var(--ink-faint) 38%, transparent);
  border: 3px solid transparent;
  background-clip: content-box;
  border-radius: 999px;
}
::-webkit-scrollbar-thumb:hover { background: var(--ink-faint); background-clip: content-box; border: 3px solid transparent; }

.ico { display: inline-grid; place-items: center; width: 18px; height: 18px; flex: none; }
.ico svg { width: 100%; height: 100%; }
[data-ico] { display: inline-grid; place-items: center; width: 18px; height: 18px; flex: none; }
[data-ico] svg { width: 100%; height: 100%; }
.icon-btn > svg { width: 18px; height: 18px; }
.icon-btn.spinning [data-ico] { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* --------------------------------------------------------------------------
   顶栏
   -------------------------------------------------------------------------- */

.topbar {
  position: relative;
  z-index: 60;
  height: 66px;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 20px;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(20px) saturate(1.2);
  -webkit-backdrop-filter: blur(20px) saturate(1.2);
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  text-decoration: none;
  color: inherit;
  min-width: 0;
  border-radius: 12px;
}

.brand-mark {
  width: 38px;
  height: 38px;
  flex: none;
  border-radius: 12px;
  display: grid;
  place-items: center;
  font-family: var(--serif);
  font-size: 22px;
  color: #f5e7cf;
  background:
    linear-gradient(145deg, rgba(255, 255, 255, 0.1), transparent 45%),
    linear-gradient(145deg, #3a2f23, #211a13);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.13), 0 6px 16px rgba(40, 28, 15, 0.24);
}

[data-theme="night"] .brand-mark {
  color: #2a2117;
  background:
    linear-gradient(145deg, rgba(255, 255, 255, 0.55), transparent 45%),
    linear-gradient(145deg, #dfb784, #b98a55);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.4), 0 6px 18px rgba(0, 0, 0, 0.35);
}

.brand-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.brand-text strong {
  font-family: var(--serif);
  font-size: 18px;
  font-weight: 600;
  letter-spacing: 0.24em;
  line-height: 1.1;
  white-space: nowrap;
}
.brand-text small {
  font-size: 8.5px;
  letter-spacing: 0.16em;
  color: var(--ink-faint);
  white-space: nowrap;
  text-transform: uppercase;
}

.top-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
}

.dir-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-width: 340px;
  padding: 8px 13px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: color-mix(in srgb, var(--panel) 75%, transparent);
  color: var(--ink-soft);
  font-size: 12px;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s, color 0.2s;
  min-width: 0;
}
.dir-chip:hover { border-color: var(--line-strong); color: var(--ink); background: var(--panel); }
.dir-chip .ico { width: 15px; height: 15px; opacity: 0.75; }
.dir-chip span:last-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 250px;
}

.icon-btn {
  width: 36px;
  height: 36px;
  flex: none;
  border: 1px solid transparent;
  border-radius: 10px;
  background: transparent;
  color: var(--ink-soft);
  display: inline-grid;
  place-items: center;
  cursor: pointer;
  transition: background 0.18s, border-color 0.18s, color 0.18s, transform 0.18s;
}
.icon-btn:hover { background: var(--panel); border-color: var(--line); color: var(--ink); }
.icon-btn:active { transform: scale(0.96); }
.icon-btn.small { width: 30px; height: 30px; border-radius: 8px; }
.icon-btn.small svg { width: 15px; height: 15px; }
.aa { font-family: var(--serif); font-size: 15px; letter-spacing: -0.02em; }

.menu-btn { display: inline-grid; }

.live-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid color-mix(in srgb, var(--green) 26%, transparent);
  background: color-mix(in srgb, var(--green) 8%, transparent);
  color: var(--green);
  font-size: 10.5px;
  letter-spacing: 0.08em;
  white-space: nowrap;
}
.live-pill i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  box-shadow: 0 0 0 0 currentColor;
  animation: livePulse 2.2s infinite;
}
.live-pill[data-state="reconnect"] {
  color: var(--amber);
  border-color: color-mix(in srgb, var(--amber) 28%, transparent);
  background: color-mix(in srgb, var(--amber) 8%, transparent);
}
.live-pill[data-state="reconnect"] i { animation-duration: 1s; }

@keyframes livePulse {
  0% { box-shadow: 0 0 0 0 color-mix(in srgb, currentColor 45%, transparent); }
  70% { box-shadow: 0 0 0 6px transparent; }
  100% { box-shadow: 0 0 0 0 transparent; }
}

/* --------------------------------------------------------------------------
   布局
   -------------------------------------------------------------------------- */

.shell {
  position: relative;
  z-index: 1;
  display: flex;
  height: calc(100dvh - 66px);
  min-height: 0;
}

.shelf {
  width: 352px;
  flex: none;
  min-height: 0;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--line);
  background:
    linear-gradient(180deg, color-mix(in srgb, var(--panel-2) 72%, transparent), color-mix(in srgb, var(--bg) 70%, transparent));
  position: relative;
  z-index: 30;
}

.shelf-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  padding: 22px 20px 0;
}

.eyebrow {
  margin: 0;
  font-family: var(--sans);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.34em;
  color: var(--ink-faint);
  text-transform: uppercase;
}

.shelf-head h1 {
  margin: 5px 0 0;
  font-family: var(--serif);
  font-size: 27px;
  font-weight: 600;
  letter-spacing: 0.1em;
  line-height: 1.2;
}

.shelf-stats {
  padding: 8px 21px 0;
  font-size: 10.5px;
  letter-spacing: 0.04em;
  color: var(--ink-faint);
  min-height: 26px;
}

.shelf-tools {
  display: flex;
  gap: 8px;
  padding: 12px 16px 0;
}

.search {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 7px;
  height: 34px;
  padding: 0 11px;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: color-mix(in srgb, var(--panel) 65%, transparent);
  color: var(--ink-faint);
  transition: border-color 0.2s, background 0.2s;
}
.search:focus-within { border-color: var(--line-strong); background: var(--panel); }
.search .ico { width: 15px; height: 15px; }
.search input {
  flex: 1;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  font-size: 12px;
  color: var(--ink);
}
.search input::placeholder { color: var(--ink-faint); }
.search input::-webkit-search-cancel-button { filter: grayscale(1); opacity: 0.5; }

#sortSelect {
  width: 92px;
  height: 34px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: color-mix(in srgb, var(--panel) 65%, transparent);
  font-size: 11px;
  color: var(--ink-soft);
  outline: none;
  cursor: pointer;
}

.filters {
  display: flex;
  gap: 4px;
  padding: 10px 16px 4px;
}
.filters button {
  border: 0;
  background: transparent;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 11px;
  color: var(--ink-faint);
  cursor: pointer;
  transition: background 0.18s, color 0.18s;
}
.filters button:hover { color: var(--ink-soft); }
.filters button.on {
  color: var(--accent-deep);
  background: var(--accent-soft);
  font-weight: 600;
}

.shelf-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 8px 10px 26px;
  scrollbar-gutter: stable;
}

.shelf-foot {
  flex: none;
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 10px 20px calc(12px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  font-size: 9.5px;
  letter-spacing: 0.06em;
  color: var(--ink-faint);
}
.lock-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--green);
  opacity: 0.8;
}

.main {
  flex: 1;
  min-width: 0;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  position: relative;
  scroll-behavior: smooth;
  outline: none;
}

.scrim { display: none; }

/* --------------------------------------------------------------------------
   书架卡片
   -------------------------------------------------------------------------- */

.book {
  position: relative;
  width: 100%;
  display: flex;
  gap: 13px;
  padding: 11px;
  margin-bottom: 2px;
  border: 1px solid transparent;
  border-radius: 14px;
  background: transparent;
  color: inherit;
  text-align: left;
  cursor: pointer;
  transition: background 0.18s, border-color 0.18s, box-shadow 0.18s, transform 0.18s;
}
.book:hover {
  background: color-mix(in srgb, var(--panel) 78%, transparent);
  border-color: var(--line);
}
.book.active {
  background: var(--panel);
  border-color: var(--line-strong);
  box-shadow: var(--shadow-soft);
}
.book:active { transform: scale(0.995); }

.cover {
  position: relative;
  width: 58px;
  height: 80px;
  flex: none;
  border-radius: 7px;
  overflow: hidden;
  background: linear-gradient(150deg, #6b533b, #3c2d20);
  box-shadow: var(--cover-shadow);
  isolation: isolate;
}
.cover::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.14), inset 8px 0 14px -10px rgba(0, 0, 0, 0.8);
  pointer-events: none;
}
.cover img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center 18%;
  transition: transform 0.4s ease, filter 0.3s;
}
.book:hover .cover img { transform: scale(1.035); }
.cover .initial {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-family: var(--serif);
  font-size: 25px;
  color: rgba(255, 246, 228, 0.92);
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
}

.book-body { flex: 1; min-width: 0; padding: 1px 0; display: flex; flex-direction: column; }
.book-top { display: flex; align-items: center; gap: 6px; min-width: 0; }
.book-title {
  font-family: var(--serif);
  font-size: 15.5px;
  font-weight: 600;
  letter-spacing: 0.03em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.branch {
  flex: none;
  padding: 1px 5px;
  border: 1px solid var(--line);
  border-radius: 4px;
  font-size: 8.5px;
  letter-spacing: 0.04em;
  color: var(--ink-faint);
}
.book-sub {
  margin-top: 2px;
  font-size: 10px;
  letter-spacing: 0.03em;
  color: var(--ink-faint);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.book-summary {
  margin: 5px 0 0;
  font-size: 11.5px;
  line-height: 1.55;
  color: var(--ink-soft);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  opacity: 0.85;
}
.book-foot {
  margin-top: auto;
  padding-top: 6px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 9.5px;
  letter-spacing: 0.02em;
  color: var(--ink-faint);
}
.book-progress {
  display: flex;
  align-items: center;
  gap: 5px;
  color: var(--accent);
}
.book-progress .mini-bar {
  width: 26px;
  height: 2px;
  border-radius: 2px;
  background: var(--line);
  overflow: hidden;
}
.book-progress .mini-bar i { display: block; height: 100%; background: var(--accent); }

.continue-card {
  width: calc(100% - 20px);
  margin: 6px 10px 12px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 12px;
  border: 1px solid var(--line-strong);
  border-radius: 15px;
  background:
    radial-gradient(120% 160% at 0% 0%, var(--accent-soft), transparent 55%),
    var(--panel);
  color: inherit;
  text-align: left;
  cursor: pointer;
  box-shadow: var(--shadow-soft);
  transition: transform 0.18s, box-shadow 0.18s;
}
.continue-card:hover { transform: translateY(-1px); box-shadow: var(--shadow); }
.continue-cover {
  width: 40px;
  height: 55px;
  flex: none;
  border-radius: 5px;
  overflow: hidden;
  position: relative;
  background: linear-gradient(145deg, #664e37, #342619);
  box-shadow: var(--cover-shadow);
}
.continue-cover img { width: 100%; height: 100%; object-fit: cover; object-position: center 18%; }
.continue-cover .initial {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-family: var(--serif);
  color: rgba(255, 246, 228, 0.9);
  font-size: 17px;
}
.continue-body { min-width: 0; flex: 1; }
.continue-kicker {
  font-size: 8.5px;
  letter-spacing: 0.22em;
  color: var(--accent);
  text-transform: uppercase;
}
.continue-title {
  margin-top: 3px;
  font-family: var(--serif);
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.continue-meta { margin-top: 3px; font-size: 10px; color: var(--ink-faint); }
.continue-arrow { color: var(--accent); flex: none; width: 16px; height: 16px; }

.shelf-empty {
  padding: 42px 26px;
  text-align: center;
  color: var(--ink-faint);
}
.shelf-empty .big { font-family: var(--serif); font-size: 34px; color: var(--line-strong); }
.shelf-empty p { font-size: 12px; line-height: 1.8; margin: 12px 0 18px; }

.skeleton-book { display: flex; gap: 13px; padding: 11px; }
.skeleton-book .cover { background: var(--panel-2); box-shadow: none; }
.skeleton-lines { flex: 1; padding-top: 6px; }
.skel {
  background: linear-gradient(90deg, var(--line) 25%, color-mix(in srgb, var(--line) 30%, transparent) 37%, var(--line) 63%);
  background-size: 400% 100%;
  animation: shimmer 1.5s ease infinite;
  border-radius: 5px;
}
.skel.line { height: 9px; margin-bottom: 9px; }
@keyframes shimmer {
  0% { background-position: 100% 50%; }
  100% { background-position: 0 50%; }
}

/* --------------------------------------------------------------------------
   欢迎页
   -------------------------------------------------------------------------- */

.welcome {
  position: relative;
  max-width: 940px;
  margin: 0 auto;
  padding: clamp(38px, 7vh, 84px) clamp(24px, 5vw, 64px) 80px;
  overflow: hidden;
}
.welcome::after {
  content: "读";
  position: absolute;
  right: -2%;
  top: 4%;
  z-index: -1;
  font-family: var(--serif);
  font-size: clamp(220px, 30vw, 400px);
  line-height: 1;
  color: var(--ink);
  opacity: 0.028;
  pointer-events: none;
  user-select: none;
}
.welcome-mark {
  display: inline-grid;
  place-items: center;
  width: 46px;
  height: 46px;
  border-radius: 14px;
  border: 1px solid var(--line-strong);
  font-family: var(--serif);
  font-size: 24px;
  color: var(--accent);
  background: color-mix(in srgb, var(--panel) 60%, transparent);
  margin-bottom: 22px;
}
.welcome h1 {
  margin: 14px 0 0;
  font-family: var(--serif);
  font-weight: 600;
  font-size: clamp(38px, 5.2vw, 64px);
  line-height: 1.24;
  letter-spacing: 0.015em;
}
.welcome h1 em {
  font-style: normal;
  color: var(--accent);
}
.welcome .lead {
  max-width: 580px;
  margin: 24px 0 0;
  font-size: 14.5px;
  line-height: 2;
  color: var(--ink-soft);
}
.welcome-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 11px;
  margin: 34px 0 0;
}
.welcome-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  max-width: 720px;
  margin-top: 56px;
}
.stat-card {
  padding: 18px 19px 16px;
  border: 1px solid var(--line);
  border-radius: 15px;
  background: color-mix(in srgb, var(--panel) 55%, transparent);
  backdrop-filter: blur(8px);
  position: relative;
  overflow: hidden;
}
.stat-card::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--accent);
  opacity: 0.55;
}
.stat-card b {
  display: block;
  font-family: var(--serif);
  font-size: clamp(24px, 3vw, 32px);
  font-weight: 600;
  letter-spacing: 0.01em;
  line-height: 1.1;
}
.stat-card span {
  display: block;
  margin-top: 7px;
  font-size: 10px;
  letter-spacing: 0.18em;
  color: var(--ink-faint);
  text-transform: uppercase;
}
.welcome-features {
  display: flex;
  flex-wrap: wrap;
  gap: 28px 40px;
  margin-top: 46px;
  padding-top: 26px;
  border-top: 1px solid var(--line);
  max-width: 720px;
}
.feature { display: flex; align-items: flex-start; gap: 10px; min-width: 180px; }
.feature .ico { color: var(--accent); margin-top: 2px; }
.feature b { display: block; font-size: 12px; font-weight: 600; letter-spacing: 0.04em; }
.feature p { margin: 4px 0 0; font-size: 11px; line-height: 1.65; color: var(--ink-faint); }

/* --------------------------------------------------------------------------
   按钮
   -------------------------------------------------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 9px 16px;
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  color: var(--ink-soft);
  font-size: 12.5px;
  letter-spacing: 0.02em;
  cursor: pointer;
  transition: background 0.18s, border-color 0.18s, color 0.18s, transform 0.18s, box-shadow 0.18s;
  white-space: nowrap;
}
.btn:hover { border-color: var(--line-strong); color: var(--ink); background: var(--panel); }
.btn:active { transform: translateY(1px); }
.btn.primary {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--bg);
  box-shadow: var(--shadow-soft);
}
.btn.primary:hover { opacity: 0.92; color: var(--bg); }
.btn.ghost { background: transparent; }
.btn.ghost:hover { background: var(--panel); }
.btn.soft { background: var(--accent-soft); border-color: transparent; color: var(--accent-deep); }
.btn.small { min-height: 30px; padding: 6px 11px; font-size: 11px; }
.btn:disabled { opacity: 0.35; cursor: default; transform: none; }
.btn .ico { width: 15px; height: 15px; }

/* --------------------------------------------------------------------------
   阅读器
   -------------------------------------------------------------------------- */

.reader {
  max-width: calc(var(--measure) + 220px);
  margin: 0 auto;
  padding: 40px clamp(22px, 5vw, 52px) 24px;
  min-height: 100%;
}

.reader-head {
  padding-bottom: 24px;
  border-bottom: 1px solid var(--line);
}

.crumb {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 18px;
  font-size: 10.5px;
  letter-spacing: 0.06em;
  color: var(--ink-faint);
}
.crumb button {
  border: 0;
  background: transparent;
  color: var(--ink-faint);
  padding: 0;
  cursor: pointer;
  font-size: inherit;
}
.crumb button:hover { color: var(--accent); }
.crumb .sep { opacity: 0.5; }

.reader-title-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
}
.reader-title-row > div:first-child { min-width: 0; }
.reader-title-row h2 {
  margin: 0;
  overflow-wrap: anywhere;
  font-family: var(--serif);
  font-size: clamp(30px, 4vw, 38px);
  font-weight: 600;
  letter-spacing: 0.04em;
  line-height: 1.3;
}
.reader-sub {
  margin-top: 7px;
  font-size: 11.5px;
  letter-spacing: 0.09em;
  color: var(--ink-faint);
}
.reader-actions { display: flex; flex-wrap: wrap; gap: 7px; padding-top: 5px; flex: none; }
.reader-actions .btn { min-height: 33px; padding: 7px 12px; font-size: 11px; background: transparent; }
.reader-actions .btn [data-ico] { width: 14px; height: 14px; }

.reader-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 7px 18px;
  margin-top: 18px;
  font-size: 10.5px;
  letter-spacing: 0.04em;
  color: var(--ink-faint);
}
.reader-meta b { color: var(--ink-soft); font-weight: 500; }
.reader-meta .dot { opacity: 0.45; }

.update-banner {
  position: fixed;
  left: calc(50% + var(--shelf-w) / 2);
  bottom: 92px;
  transform: translateX(-50%);
  z-index: 65;
  width: max-content;
  max-width: min(560px, calc(100vw - 28px));
  margin: 0;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border: 1px solid color-mix(in srgb, var(--green) 28%, var(--line));
  border-radius: 999px;
  background: var(--panel);
  color: var(--ink-soft);
  font-size: 11.5px;
  animation: bannerIn 0.3s ease both;
}
.update-banner .ico { color: var(--green); width: 16px; height: 16px; }
.update-banner [data-ico] { color: var(--green); width: 16px; height: 16px; }
.update-banner button {
  margin-left: auto;
  border: 0;
  background: transparent;
  color: var(--green);
  font-size: 11px;
  cursor: pointer;
  white-space: nowrap;
  padding: 2px 0;
}
@keyframes bannerIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.chapter-view {
  max-width: var(--measure);
  margin: 44px auto 0;
  animation: chapterIn 0.4s ease both;
}
@keyframes chapterIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.chapter-kicker {
  display: flex;
  align-items: center;
  gap: 13px;
  margin-bottom: 15px;
  font-size: 9px;
  letter-spacing: 0.4em;
  color: var(--accent);
  text-transform: uppercase;
}
.chapter-kicker::after {
  content: "";
  height: 1px;
  flex: 1;
  background: linear-gradient(90deg, var(--line-strong), transparent);
}
.chapter-title {
  margin: 0 0 30px;
  font-family: var(--serif);
  font-size: clamp(23px, 3vw, 30px);
  font-weight: 600;
  line-height: 1.4;
  letter-spacing: 0.02em;
}

.chapter-body {
  font-family: var(--serif);
  font-size: var(--reader-font);
  line-height: var(--reader-lh);
  color: var(--ink);
  text-align: justify;
  text-justify: inter-ideograph;
  overflow-wrap: break-word;
  font-kerning: normal;
}

.turn { margin: 0; }
.turn + .turn { margin-top: 0; }

.para {
  position: relative;
  margin: 0 0 0.66em;
  text-indent: 2em;
  overflow-wrap: break-word;
}
.para:last-child { margin-bottom: 0; }
.para.dialogue { color: var(--ink); }
.speaker-tag {
  display: block;
  margin-bottom: 0.45em;
  font-family: var(--sans);
  font-size: 8.5px;
  letter-spacing: 0.18em;
  color: var(--ink-faint);
  text-transform: uppercase;
}
.nav-btn [data-ico] { width: 14px; height: 14px; }
.para.thought {
  text-indent: 0;
  margin: 0.9em 0;
  padding: 0.05em 0 0.05em 1.1em;
  border-left: 1px solid var(--line-strong);
  color: var(--ink-soft);
  font-style: italic;
  font-size: 0.94em;
}

.turn-user {
  margin: 1.5em 0;
  padding: 0.7em 1.15em 0.7em 1.25em;
  border-left: 2px solid color-mix(in srgb, var(--accent) 62%, transparent);
  border-radius: 0 11px 11px 0;
  background: linear-gradient(90deg, var(--accent-soft), transparent 82%);
}
.turn-user .para {
  text-indent: 0;
  margin: 0.28em 0;
  font-size: 0.9em;
  line-height: 1.9;
  color: var(--ink-soft);
}
.turn-user .player-tag {
  display: none;
  margin-bottom: 0.5em;
  font-family: var(--sans);
  font-size: 8.5px;
  letter-spacing: 0.18em;
  color: var(--accent);
  text-transform: uppercase;
}
body[data-player="show"] .turn-user .player-tag { display: block; }
body[data-player="hide"] .turn-user { display: none; }
body[data-player="show"] .turn-user .para { color: var(--ink); }

.chapter-end {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  margin: 56px 0 10px;
  font-size: 9px;
  letter-spacing: 0.36em;
  color: var(--ink-faint);
}
.chapter-end::before,
.chapter-end::after {
  content: "";
  height: 1px;
  width: 54px;
  background: var(--line);
}

.reader-foot {
  position: sticky;
  bottom: 0;
  z-index: 10;
  max-width: var(--measure);
  margin: 54px auto 0;
  padding: 13px 0 calc(15px + env(safe-area-inset-bottom));
  display: flex;
  align-items: center;
  gap: 16px;
  background: linear-gradient(to top, var(--bg) 58%, color-mix(in srgb, var(--bg) 88%, transparent) 82%, transparent);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
.nav-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: color-mix(in srgb, var(--panel) 65%, transparent);
  color: var(--ink-soft);
  font-size: 11px;
  cursor: pointer;
  transition: border-color 0.18s, color 0.18s, background 0.18s;
  flex: none;
}
.nav-btn:hover { border-color: var(--line-strong); color: var(--ink); background: var(--panel); }
.nav-btn:disabled { opacity: 0.3; cursor: default; }
.nav-btn .ico { width: 14px; height: 14px; }

.chapter-progress { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.progress-bar {
  height: 3px;
  border-radius: 3px;
  background: var(--line);
  overflow: hidden;
}
.progress-bar i {
  display: block;
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent-deep), var(--accent));
  transition: width 0.25s ease;
}
.progress-label {
  display: flex;
  justify-content: space-between;
  font-size: 9px;
  letter-spacing: 0.08em;
  color: var(--ink-faint);
}
.progress-label b { color: var(--ink-soft); font-weight: 500; }

.reader-loading {
  max-width: 820px;
  margin: 0 auto;
  padding: 70px 40px;
}
.reader-loading .skel { margin-bottom: 14px; }

.error-panel {
  max-width: 520px;
  margin: 14vh auto;
  padding: 36px;
  text-align: center;
}
.error-panel .big { font-family: var(--serif); font-size: 46px; color: var(--line-strong); }
.error-panel h2 { font-family: var(--serif); font-size: 22px; margin: 16px 0 8px; font-weight: 600; }
.error-panel p { font-size: 12.5px; line-height: 1.8; color: var(--ink-soft); word-break: break-all; }
.error-panel .actions { margin-top: 24px; display: flex; justify-content: center; gap: 9px; }

/* --------------------------------------------------------------------------
   弹窗
   -------------------------------------------------------------------------- */

.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 24px;
}
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(30, 24, 16, 0.42);
  backdrop-filter: blur(7px);
  -webkit-backdrop-filter: blur(7px);
  animation: fadeIn 0.2s ease both;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal-card {
  position: relative;
  z-index: 1;
  width: min(720px, 100%);
  max-height: min(88vh, 820px);
  display: flex;
  flex-direction: column;
  padding: 26px 26px 0;
  border: 1px solid var(--line-strong);
  border-radius: 20px;
  background: var(--panel);
  box-shadow: var(--shadow);
  overflow: hidden;
  animation: modalIn 0.28s cubic-bezier(0.22, 0.8, 0.3, 1) both;
}
@keyframes modalIn {
  from { opacity: 0; transform: translateY(12px) scale(0.985); }
  to { opacity: 1; transform: none; }
}

.modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  flex: none;
}
.modal-head h2 {
  margin: 6px 0 0;
  font-family: var(--serif);
  font-size: 24px;
  font-weight: 600;
  letter-spacing: 0.04em;
}
.modal-desc {
  margin: 14px 0 16px;
  font-size: 11.5px;
  line-height: 1.8;
  color: var(--ink-faint);
  flex: none;
}
.modal-desc code {
  padding: 1px 5px;
  border-radius: 4px;
  background: var(--accent-soft);
  color: var(--accent-deep);
  font-size: 10.5px;
}

.path-form {
  display: flex;
  gap: 8px;
  flex: none;
}
.path-form input {
  flex: 1;
  min-width: 0;
  height: 39px;
  padding: 0 12px;
  border: 1px solid var(--line-strong);
  border-radius: 9px;
  background: var(--bg);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11.5px;
  color: var(--ink);
  outline: none;
}
.path-form input:focus { border-color: var(--accent); }

.browse {
  margin-top: 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  flex: none;
}
.browse-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg-deep) 40%, transparent);
}
.browse-path {
  flex: 1;
  min-width: 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 10.5px;
  color: var(--ink-faint);
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.browse-list {
  max-height: 286px;
  overflow-y: auto;
  padding: 6px;
}

.folder {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 9px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--ink);
  text-align: left;
  cursor: pointer;
  font-size: 12.5px;
  transition: background 0.15s;
}
.folder:hover { background: var(--accent-soft); }
.folder .ico { color: var(--ink-faint); width: 17px; height: 17px; }
.folder .fname {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.folder .badge {
  flex: none;
  padding: 2px 6px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 8.5px;
  letter-spacing: 0.05em;
}
.folder .badge.chats { background: color-mix(in srgb, var(--green) 12%, transparent); color: var(--green); }
.browse-empty { padding: 26px; text-align: center; font-size: 11.5px; color: var(--ink-faint); }
.browse-loading { padding: 8px; }

.shortcuts {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 12px 0 4px;
  flex: none;
}
.shortcut {
  padding: 5px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  color: var(--ink-faint);
  font-size: 10px;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}
.shortcut:hover { border-color: var(--line-strong); color: var(--ink); background: var(--bg); }

.modal-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-top: auto;
  padding: 14px 0 20px;
  border-top: 1px solid var(--line);
  flex: none;
}
.detect-hint {
  font-size: 10.5px;
  line-height: 1.5;
  color: var(--ink-faint);
  min-width: 0;
}
.detect-hint.ok { color: var(--green); }
.detect-hint.warn { color: var(--amber); }
.foot-actions { display: flex; gap: 8px; flex: none; }

/* --------------------------------------------------------------------------
   章节目录抽屉
   -------------------------------------------------------------------------- */

.drawer { position: fixed; inset: 0; z-index: 90; }
.drawer-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(30, 24, 16, 0.35);
  backdrop-filter: blur(4px);
  animation: fadeIn 0.2s ease both;
}
.drawer-panel {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(390px, 92vw);
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border-left: 1px solid var(--line-strong);
  box-shadow: -24px 0 70px rgba(30, 22, 12, 0.22);
  animation: drawerIn 0.3s cubic-bezier(0.22, 0.8, 0.3, 1) both;
}
@keyframes drawerIn {
  from { transform: translateX(30px); opacity: 0; }
  to { transform: none; opacity: 1; }
}
.drawer-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 24px 22px 0;
}
.drawer-head h2 {
  margin: 5px 0 0;
  font-family: var(--serif);
  font-size: 24px;
  font-weight: 600;
  letter-spacing: 0.06em;
}
.drawer-sub {
  padding: 8px 22px 16px;
  font-size: 10.5px;
  color: var(--ink-faint);
  border-bottom: 1px solid var(--line);
}
.chapter-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 10px 12px 30px;
}
.chapter-item {
  width: 100%;
  display: flex;
  align-items: flex-start;
  gap: 13px;
  padding: 10px 11px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: transparent;
  color: inherit;
  text-align: left;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.chapter-item:hover { background: var(--bg); }
.chapter-item.current {
  background: var(--accent-soft);
  border-color: color-mix(in srgb, var(--accent) 20%, transparent);
}
.chapter-item.read .ch-num { color: var(--ink-faint); opacity: 0.6; }
.ch-num {
  width: 27px;
  flex: none;
  padding-top: 1px;
  font-family: var(--serif);
  font-size: 12px;
  color: var(--accent);
  text-align: right;
}
.ch-body { min-width: 0; flex: 1; }
.ch-title {
  display: block;
  font-family: var(--serif);
  font-size: 13px;
  line-height: 1.55;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ch-meta {
  display: block;
  margin-top: 2px;
  font-size: 9.5px;
  letter-spacing: 0.03em;
  color: var(--ink-faint);
}
.chapter-item.current .ch-title { color: var(--accent-deep); font-weight: 600; }

/* --------------------------------------------------------------------------
   书情分析
   -------------------------------------------------------------------------- */

.analysis-card { width: min(760px, 100%); }
.analysis-body {
  overflow-y: auto;
  padding-bottom: 26px;
  margin-top: 20px;
  padding-right: 4px;
}
.analysis-book {
  display: flex;
  gap: 18px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background:
    radial-gradient(120% 160% at 0% 0%, var(--accent-soft), transparent 55%),
    color-mix(in srgb, var(--panel) 60%, transparent);
}
.analysis-cover {
  width: 76px;
  height: 104px;
  flex: none;
  border-radius: 8px;
  overflow: hidden;
  position: relative;
  background: linear-gradient(145deg, #6b533b, #3c2d20);
  box-shadow: var(--cover-shadow);
}
.analysis-cover img { width: 100%; height: 100%; object-fit: cover; object-position: center 18%; }
.analysis-cover .initial {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-family: var(--serif);
  font-size: 30px;
  color: rgba(255, 246, 228, 0.92);
}
.analysis-info { min-width: 0; display: flex; flex-direction: column; justify-content: center; }
.analysis-info h3 {
  margin: 0;
  font-family: var(--serif);
  font-size: 21px;
  font-weight: 600;
  letter-spacing: 0.04em;
}
.analysis-info .sub { margin-top: 5px; font-size: 10.5px; color: var(--ink-faint); letter-spacing: 0.05em; }
.analysis-info .sum { margin: 9px 0 0; font-size: 11.5px; line-height: 1.7; color: var(--ink-soft); }

.analysis-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 9px;
  margin-top: 16px;
}
.analysis-stat {
  padding: 13px 14px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: color-mix(in srgb, var(--panel) 50%, transparent);
}
.analysis-stat b { display: block; font-family: var(--serif); font-size: 20px; font-weight: 600; }
.analysis-stat span { display: block; margin-top: 4px; font-size: 9px; letter-spacing: 0.12em; color: var(--ink-faint); }

.analysis-section { margin-top: 22px; }
.analysis-section h4 {
  margin: 0 0 10px;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.28em;
  color: var(--ink-faint);
  text-transform: uppercase;
}
.chips { display: flex; flex-wrap: wrap; gap: 7px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--bg);
  font-size: 11px;
  color: var(--ink-soft);
}
.chip small { color: var(--ink-faint); font-size: 9px; }
.path-box {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--bg);
}
.path-box code {
  flex: 1;
  min-width: 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 9.5px;
  color: var(--ink-faint);
  overflow-wrap: anywhere;
}
.analysis-note {
  margin: 18px 0 0;
  padding-top: 14px;
  border-top: 1px solid var(--line);
  font-size: 10px;
  line-height: 1.7;
  color: var(--ink-faint);
}

/* --------------------------------------------------------------------------
   设置弹层
   -------------------------------------------------------------------------- */

.settings-pop {
  position: fixed;
  top: 74px;
  right: 20px;
  z-index: 120;
  width: min(340px, calc(100vw - 24px));
  max-height: calc(100dvh - 88px);
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 14px 16px 6px;
  border: 1px solid var(--line-strong);
  border-radius: 16px;
  background: var(--panel);
  box-shadow: var(--shadow);
  animation: popIn 0.2s ease both;
}
@keyframes popIn {
  from { opacity: 0; transform: translateY(-6px) scale(0.985); }
  to { opacity: 1; transform: none; }
}
.settings-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}
.settings-head strong { font-family: var(--serif); font-size: 15px; letter-spacing: 0.08em; }
.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 11px 0;
  border-bottom: 1px solid var(--line);
  font-size: 11.5px;
  color: var(--ink-soft);
}
.setting-row.no-line { border-bottom: 0; }

.width-setting { display: block; padding: 12px 0; }
.width-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  font-size: 11.5px;
  color: var(--ink-soft);
}
.width-head b {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.04em;
  color: var(--accent);
}
.width-range {
  -webkit-appearance: none;
  appearance: none;
  display: block;
  width: 100%;
  height: 16px;
  margin: 8px 0 3px;
  padding: 0;
  background: transparent;
  cursor: pointer;
  accent-color: var(--accent);
}
.width-range::-webkit-slider-runnable-track {
  height: 3px;
  border-radius: 3px;
  background: var(--line-strong);
}
.width-range::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  margin-top: -5.5px;
  border-radius: 50%;
  border: 2px solid var(--panel);
  background: var(--accent);
  box-shadow: 0 1px 4px rgba(30, 20, 10, 0.28);
}
.width-range::-moz-range-track {
  height: 3px;
  border-radius: 3px;
  background: var(--line-strong);
}
.width-range::-moz-range-thumb {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid var(--panel);
  background: var(--accent);
  box-shadow: 0 1px 4px rgba(30, 20, 10, 0.28);
}
.width-range:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  border-radius: 4px;
}
.width-presets {
  display: flex;
  gap: 4px;
  margin-top: 5px;
}
.width-presets button {
  flex: 1;
  padding: 4px 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: transparent;
  color: var(--ink-faint);
  font-size: 9.5px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.width-presets button:hover { border-color: var(--line-strong); color: var(--ink); }
.width-presets button.on {
  border-color: transparent;
  background: var(--accent-soft);
  color: var(--accent-deep);
  font-weight: 600;
}
.width-tip,
.width-mobile-note {
  display: none;
  margin-top: 7px;
  font-size: 9px;
  color: var(--ink-faint);
}
@media (min-width: 981px) {
  .width-tip { display: block; }
  body.shelf-collapsed { --shelf-w: 0px; }
  body.shelf-collapsed .width-tip { display: none; }
  body.shelf-collapsed .shelf { display: none; }
  body.shelf-collapsed .menu-btn {
    color: var(--accent);
    background: var(--accent-soft);
    border-color: transparent;
  }
}
body[data-reading="narrow"] .reader-title-row {
  flex-direction: column;
  align-items: flex-start;
  gap: 14px;
}
body[data-reading="narrow"] .reader-actions { padding-top: 0; }
.setting-row > span { display: flex; flex-direction: column; gap: 2px; }
.setting-row > span small { font-size: 9px; color: var(--ink-faint); }
.seg {
  display: flex;
  gap: 2px;
  padding: 2px;
  border-radius: 8px;
  background: var(--bg-deep);
  flex: none;
}
.seg button {
  border: 0;
  background: transparent;
  padding: 5px 8px;
  border-radius: 6px;
  font-size: 10px;
  color: var(--ink-faint);
  cursor: pointer;
  transition: background 0.15s, color 0.15s, box-shadow 0.15s;
  white-space: nowrap;
}
.seg button:hover { color: var(--ink); }
.seg button.on {
  background: var(--panel);
  color: var(--ink);
  box-shadow: 0 1px 4px rgba(30, 20, 10, 0.1);
  font-weight: 600;
}
.switch {
  width: 36px;
  height: 20px;
  flex: none;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: var(--line-strong);
  position: relative;
  cursor: pointer;
  transition: background 0.2s;
}
.switch i {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
  transition: left 0.2s;
}
.switch[aria-checked="true"] { background: var(--accent); }
.switch[aria-checked="true"] i { left: 18px; }

/* --------------------------------------------------------------------------
   Toast
   -------------------------------------------------------------------------- */

#toast {
  position: fixed;
  left: 50%;
  bottom: 88px;
  z-index: 200;
  transform: translate(-50%, 16px);
  max-width: min(82vw, 540px);
  padding: 10px 18px;
  border-radius: 999px;
  background: var(--ink);
  color: var(--bg);
  font-size: 11.5px;
  line-height: 1.5;
  letter-spacing: 0.02em;
  text-align: center;
  box-shadow: 0 12px 36px rgba(30, 20, 10, 0.28);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
body[data-view="reader"] #toast { left: calc(50% + var(--shelf-w) / 2); }

/* --------------------------------------------------------------------------
   响应式
   -------------------------------------------------------------------------- */

@media (max-width: 1180px) {
  .shelf { width: 322px; }
  :root { --shelf-w: 322px; }
  .brand-text small { display: none; }
  .dir-chip { max-width: 270px; }
}

@media (max-width: 980px) {
  :root { --shelf-w: 0px; }
  .menu-btn { display: inline-grid; }
  .shelf {
    position: fixed;
    top: 66px;
    left: 0;
    bottom: 0;
    width: min(360px, 90vw);
    transform: translateX(-102%);
    transition: transform 0.3s cubic-bezier(0.22, 0.8, 0.3, 1);
    box-shadow: 24px 0 70px rgba(30, 22, 12, 0.28);
    background: var(--panel);
    z-index: 75;
  }
  body.shelf-open .shelf { transform: none; }
  body.shelf-open .scrim {
    display: block;
    position: fixed;
    inset: 66px 0 0;
    z-index: 70;
    background: rgba(30, 24, 16, 0.34);
    backdrop-filter: blur(3px);
  }
  .reader { padding-top: 30px; }
  .welcome { padding-top: 46px; }
}

@media (max-width: 700px) {
  .topbar { height: 58px; padding: 0 12px; gap: 8px; }
  .shell { height: calc(100dvh - 58px); }
  .brand-mark { width: 34px; height: 34px; font-size: 20px; border-radius: 10px; }
  .brand-text strong { font-size: 16px; letter-spacing: 0.18em; }
  .brand-text small { display: none; }
  .dir-chip { max-width: 150px; padding: 7px 10px; font-size: 10.5px; }
  .live-pill { display: none !important; }
  .theme-btn { display: none; }
  .dir-chip { max-width: 118px; }
  .shelf { top: 58px; }
  body.shelf-open .scrim { inset: 58px 0 0; }
  .reader { padding: 24px 18px 16px; }
  .reader-head { padding-bottom: 20px; }
  .reader-title-row { flex-direction: column; gap: 14px; }
  .reader-actions { padding-top: 0; }
  .reader-title-row h2 { font-size: 30px; }
  .chapter-view { margin-top: 30px; }
  .chapter-title { margin-bottom: 24px; }
  .chapter-body { text-align: left; font-size: max(17px, calc(var(--reader-font) - 1px)); }
  .reader-foot { gap: 10px; margin-top: 40px; }
  .nav-btn .nav-label { display: none; }
  .nav-btn { width: 34px; height: 34px; padding: 0; justify-content: center; border-radius: 9px; }
  .reader-meta .dot { display: none; }
  .reader-meta { gap: 6px 14px; }
  .welcome { padding: 34px 20px 60px; }
  .welcome h1 { font-size: 38px; }
  .welcome .lead { font-size: 13px; }
  .welcome-stats { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin-top: 40px; }
  .stat-card { padding: 13px 11px; }
  .stat-card b { font-size: 22px; }
  .stat-card span { font-size: 8px; letter-spacing: 0.1em; }
  .welcome-features { gap: 18px; }
  .feature { min-width: 140px; }
  .modal { padding: 0; align-items: end; }
  .modal-card {
    width: 100%;
    max-height: 93dvh;
    border-radius: 20px 20px 0 0;
    padding: 20px 18px 0;
  }
  .browse-list { max-height: 240px; }
  .modal-foot { flex-direction: column; align-items: stretch; gap: 10px; padding-bottom: calc(16px + env(safe-area-inset-bottom)); }
  .foot-actions { justify-content: flex-end; }
  .detect-hint { width: 100%; }
  .analysis-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .settings-pop { top: 64px; right: 8px; max-height: calc(100dvh - 76px); }
  .width-mobile-note { display: block; }
  #toast { bottom: 86px; }
  .update-banner { bottom: 84px; border-radius: 12px; font-size: 11px; padding: 9px 12px; }
}

@media (max-width: 520px) {
  .welcome-actions { flex-direction: column; align-items: stretch; }
  .welcome-actions .btn { justify-content: center; }
}

@media (max-width: 360px) {
  .brand-text { display: none; }
  .dir-chip { max-width: 104px; }
}

@media (max-width: 420px) {
  .dir-chip span:last-child { max-width: 88px; }
  .top-actions { gap: 2px; }
  .welcome h1 { font-size: 34px; }
  .welcome-stats { grid-template-columns: 1fr; }
  .stat-card { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
  .stat-card b { font-size: 24px; }
  .stat-card span { margin-top: 0; }
  .analysis-book { flex-direction: column; align-items: flex-start; }
  .analysis-cover { width: 58px; height: 79px; }
}

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

/* --------------------------------------------------------------------------
   局域网访问 / 访问密钥
   -------------------------------------------------------------------------- */

#authModal { z-index: 210; }
.auth-card { width: min(540px, 100%); padding-bottom: 24px; }
.auth-card .modal-desc { margin-top: 16px; }
.auth-error {
  min-height: 18px;
  margin-top: 10px;
  font-size: 11px;
  color: var(--red);
}
.auth-note {
  margin: 18px 0 0;
  padding-top: 13px;
  border-top: 1px solid var(--line);
  font-size: 10px;
  line-height: 1.75;
  color: var(--ink-faint);
}
.auth-note code, .lan-card code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.lan-card { width: min(640px, 100%); }
.lan-body {
  overflow-y: auto;
  padding: 6px 0 4px;
  min-height: 80px;
}
.lan-loading { padding: 20px 0; font-size: 11.5px; color: var(--ink-faint); }
.lan-empty {
  padding: 18px;
  border: 1px dashed var(--line-strong);
  border-radius: 11px;
  font-size: 11.5px;
  line-height: 1.8;
  color: var(--ink-faint);
  text-align: center;
}
.lan-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 0;
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
.lan-row:last-child { border-bottom: 0; }
.lan-address { flex: 1; min-width: 190px; }
.lan-address code {
  display: block;
  font-size: 11px;
  color: var(--ink);
  overflow-wrap: anywhere;
}
.lan-address small {
  display: block;
  margin-top: 3px;
  font-size: 9px;
  color: var(--ink-faint);
  letter-spacing: 0.04em;
}
.lan-key {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 14px;
  padding: 11px 13px;
  border: 1px solid var(--line-strong);
  border-radius: 11px;
  background: var(--accent-soft);
}
.lan-key > span {
  font-size: 10px;
  letter-spacing: 0.12em;
  color: var(--ink-faint);
  white-space: nowrap;
}
.lan-key code {
  flex: 1;
  font-size: 14px;
  letter-spacing: 0.06em;
  color: var(--accent-deep);
  overflow-wrap: anywhere;
}
.lan-tip {
  margin: 14px 0 0;
  font-size: 10px;
  line-height: 1.7;
  color: var(--ink-faint);
}
.lan-warn { color: var(--amber); }

@media (max-width: 700px) {
  .lan-row { align-items: flex-start; }
  .lan-row .btn { padding: 6px 9px; font-size: 10px; }
  .lan-key { flex-wrap: wrap; }
  .lan-key code { width: 100%; order: 3; }
}


/* --------------------------------------------------------------------------
   有声阅读
   -------------------------------------------------------------------------- */

.tts-audio { display: none; }
.tts-start.on {
  color: var(--accent-deep);
  background: var(--accent-soft);
  border-color: transparent;
}

.para-tts {
  position: absolute;
  left: -1.55em;
  top: 0.28em;
  width: 1.18em;
  height: 1.18em;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--ink-faint);
  display: grid;
  place-items: center;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s, background 0.15s, color 0.15s;
}
.para-tts svg { width: 0.62em; height: 0.62em; }
.para:hover .para-tts,
.para.tts-current .para-tts,
.para-tts:focus-visible {
  opacity: 1;
}
.para-tts:hover { background: var(--accent-soft); color: var(--accent-deep); }
.para.thought .para-tts { left: -1.9em; top: 0.2em; }
.para.tts-current {
  background: linear-gradient(90deg, var(--accent-soft), transparent 72%);
  border-radius: 6px;
  box-shadow: inset 2px 0 0 color-mix(in srgb, var(--accent) 75%, transparent);
}
.para.tts-current .para-tts { color: var(--accent-deep); }

.tts-bar {
  position: fixed;
  left: calc(50% + var(--shelf-w) / 2);
  bottom: calc(20px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 68;
  width: min(880px, calc(100vw - var(--shelf-w) - 32px));
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--line-strong);
  border-radius: 16px;
  background: var(--panel);
  box-shadow: var(--shadow);
  animation: bannerIn 0.24s ease both;
}
.tts-play {
  width: 40px;
  height: 40px;
  flex: none;
  border: 0;
  border-radius: 50%;
  background: var(--ink);
  color: var(--bg);
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: transform 0.16s, opacity 0.16s;
}
.tts-play:hover { transform: scale(1.04); }
.tts-play:active { transform: scale(0.97); }
.tts-play svg { width: 16px; height: 16px; }
.tts-play.loading svg { animation: ttsBreath 1.1s ease-in-out infinite; }
@keyframes ttsBreath {
  0%, 100% { opacity: 0.45; }
  50% { opacity: 1; }
}
.tts-main { flex: 1; min-width: 0; }
.tts-line {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  font-size: 9px;
  letter-spacing: 0.08em;
  color: var(--ink-faint);
}
#ttsKicker { color: var(--accent); }
#ttsTime { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 9px; white-space: nowrap; }
.tts-preview {
  margin-top: 3px;
  font-family: var(--serif);
  font-size: 12.5px;
  color: var(--ink-soft);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tts-seek {
  -webkit-appearance: none;
  appearance: none;
  display: block;
  width: 100%;
  height: 14px;
  margin: 6px 0 0;
  padding: 0;
  background: transparent;
  cursor: pointer;
  accent-color: var(--accent);
}
.tts-seek::-webkit-slider-runnable-track { height: 3px; border-radius: 3px; background: var(--line-strong); }
.tts-seek::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 11px;
  height: 11px;
  margin-top: -4px;
  border-radius: 50%;
  border: 2px solid var(--panel);
  background: var(--accent);
}
.tts-seek::-moz-range-track { height: 3px; border-radius: 3px; background: var(--line-strong); }
.tts-seek::-moz-range-thumb {
  width: 9px; height: 9px; border-radius: 50%;
  border: 2px solid var(--panel); background: var(--accent);
}
.tts-actions { display: flex; align-items: center; gap: 4px; flex: none; }
.tts-icon {
  width: 30px;
  height: 30px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--ink-faint);
  display: grid;
  place-items: center;
  cursor: pointer;
}
.tts-icon:hover { background: var(--bg); color: var(--ink); }
.tts-icon:disabled { opacity: 0.3; cursor: default; }
.tts-icon svg { width: 14px; height: 14px; }
#ttsVoice {
  height: 28px;
  max-width: 118px;
  padding: 0 5px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--panel);
  color: var(--ink-soft);
  font-size: 10px;
  cursor: pointer;
}
.tts-rate {
  height: 28px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: transparent;
  color: var(--ink-soft);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 10px;
  cursor: pointer;
  white-space: nowrap;
}
.tts-rate:hover { border-color: var(--line-strong); color: var(--ink); }

body.tts-on .reader-foot { visibility: hidden; pointer-events: none; }
body.tts-on .reader { padding-bottom: 130px; }
body.tts-on .update-banner { bottom: 112px; }
body.tts-on #toast { bottom: 112px; }

@media (hover: none) {
  .para-tts { opacity: 0.34; }
}

@media (max-width: 700px) {
  .para-tts { left: 0.05em; top: 0.05em; width: 1.75em; height: 1.75em; opacity: 0.32; }
  .para-tts svg { width: 0.72em; height: 0.72em; }
  .para.thought .para-tts { display: none; }
  .tts-bar {
    left: 50%;
    bottom: calc(12px + env(safe-area-inset-bottom));
    width: calc(100vw - 20px);
    display: grid;
    grid-template-columns: 40px minmax(0, 1fr);
    grid-template-areas: "play main" "actions actions";
    gap: 8px 10px;
    padding: 10px;
    border-radius: 15px;
  }
  .tts-play { grid-area: play; width: 38px; height: 38px; }
  .tts-main { grid-area: main; }
  .tts-actions { grid-area: actions; justify-content: flex-end; }
  .tts-preview { font-size: 12px; }
  #ttsVoice { max-width: 132px; }
  body.tts-on .reader { padding-bottom: 180px; }
  body.tts-on .update-banner { bottom: 148px; }
  body.tts-on #toast { bottom: 148px; }
}

@media (max-width: 420px) {
  #ttsVoice { max-width: 120px; }
  .tts-actions { gap: 2px; }
  .tts-icon { width: 28px; height: 28px; }
  .tts-rate { padding: 0 6px; }
}
