/* 灯下阅读器 — 墨蓝纸色，手机优先 */

:root {
  --bg: #d5dde6;
  --bg-deep: #c4ced9;
  --surface: rgba(255, 255, 255, 0.55);
  --ink: #1a2332;
  --ink-soft: #4a5568;
  --accent: #2f5d6e;
  --accent-soft: rgba(47, 93, 110, 0.12);
  --line: rgba(26, 35, 50, 0.12);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --font-size: 18px;
  --line-height: 1.9;
  --display: "ZCOOL XiaoWei", "Noto Serif SC", serif;
  --body: "Noto Serif SC", "Songti SC", "SimSun", serif;
  --ui: system-ui, -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
  --top-h: 52px;
  --nav-h: 56px;
  color-scheme: light;
}

[data-theme="paper"] {
  --bg: #ebe6db;
  --bg-deep: #ddd6c6;
  --surface: rgba(255, 252, 245, 0.65);
  --ink: #2a241c;
  --ink-soft: #6b5f4e;
  --accent: #7a4e2d;
  --accent-soft: rgba(122, 78, 45, 0.12);
  --line: rgba(42, 36, 28, 0.12);
}

[data-theme="night"] {
  --bg: #1a1f26;
  --bg-deep: #12161c;
  --surface: rgba(255, 255, 255, 0.04);
  --ink: #c8d0da;
  --ink-soft: #8a94a3;
  --accent: #6eb0c2;
  --accent-soft: rgba(110, 176, 194, 0.15);
  --line: rgba(200, 208, 218, 0.12);
  color-scheme: dark;
}

[data-theme="green"] {
  --bg: #c5d4c0;
  --bg-deep: #b3c4ad;
  --surface: rgba(255, 255, 255, 0.4);
  --ink: #1e2a1c;
  --ink-soft: #4d5c4a;
  --accent: #3d6b45;
  --accent-soft: rgba(61, 107, 69, 0.14);
  --line: rgba(30, 42, 28, 0.12);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--ui);
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}

body {
  background-image:
    radial-gradient(ellipse 120% 80% at 50% -20%, var(--bg-deep), transparent 55%),
    linear-gradient(180deg, var(--bg) 0%, var(--bg-deep) 100%);
  background-attachment: fixed;
}

#app {
  min-height: 100dvh;
  max-width: 720px;
  margin: 0 auto;
  position: relative;
}

.view {
  display: none;
  min-height: 100dvh;
}

.view-active {
  display: block;
}

.hidden {
  display: none !important;
}

/* —— 书架 —— */
.shelf-header {
  padding: calc(28px + var(--safe-top)) 22px 12px;
}

.eyebrow {
  margin: 0 0 6px;
  font-size: 13px;
  letter-spacing: 0.35em;
  text-indent: 0.35em;
  color: var(--accent);
  font-family: var(--display);
}

.shelf-header h1 {
  margin: 0;
  font-family: var(--display);
  font-size: 2.1rem;
  font-weight: 400;
  letter-spacing: 0.08em;
}

.shelf-sub {
  margin: 8px 0 0;
  font-size: 13px;
  color: var(--ink-soft);
}

.shelf-list {
  padding: 8px 16px calc(32px + var(--safe-bottom));
}

.book-group {
  margin-bottom: 22px;
}

.book-group-title {
  margin: 0 8px 10px;
  padding-bottom: 6px;
  font-family: var(--display);
  font-size: 1.15rem;
  font-weight: 400;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.book-group-title .book-label {
  font-family: var(--display);
  font-size: 1.15rem;
  color: var(--ink);
}

.book-group-title span:last-child {
  font-family: var(--ui);
  font-size: 12px;
  color: var(--ink-soft);
}

.file-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 14px 14px;
  margin-bottom: 6px;
  border: none;
  border-radius: 12px;
  background: var(--surface);
  color: var(--ink);
  text-align: left;
  font: inherit;
  cursor: pointer;
  transition: transform 0.15s ease, background 0.15s ease;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.file-item:active {
  transform: scale(0.985);
}

.file-item.is-progress {
  box-shadow: inset 3px 0 0 var(--accent);
}

.file-index {
  flex: 0 0 auto;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: var(--accent-soft);
  color: var(--accent);
  display: grid;
  place-items: center;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.file-meta {
  flex: 1;
  min-width: 0;
}

.file-name {
  display: block;
  font-size: 15px;
  line-height: 1.35;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.file-hint {
  display: block;
  margin-top: 3px;
  font-size: 11px;
  color: var(--ink-soft);
}

.error-banner {
  margin: 16px;
  padding: 12px 14px;
  border-radius: 10px;
  background: rgba(160, 40, 40, 0.12);
  color: #8b1e1e;
  font-size: 14px;
}

/* —— 阅读页 —— */
#reader {
  padding-top: calc(var(--top-h) + var(--safe-top));
  padding-bottom: calc(var(--nav-h) + var(--safe-bottom) + 8px);
}

.reader-top {
  position: fixed;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 720px;
  height: calc(var(--top-h) + var(--safe-top));
  padding: var(--safe-top) 8px 0;
  display: flex;
  align-items: center;
  gap: 4px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
  z-index: 20;
  transition: transform 0.25s ease, opacity 0.25s ease;
}

.reader-top.is-hidden {
  transform: translate(-50%, -110%);
  opacity: 0;
  pointer-events: none;
}

.reader-top-meta {
  flex: 1;
  min-width: 0;
  text-align: center;
}

.reader-book {
  margin: 0;
  font-size: 11px;
  color: var(--ink-soft);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.reader-title {
  margin: 1px 0 0;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.icon-btn {
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: var(--ink);
  font-size: 18px;
  cursor: pointer;
  flex-shrink: 0;
}

.icon-btn:active {
  background: var(--accent-soft);
}

.chapter {
  padding: 20px 22px 40px;
  outline: none;
}

.chapter-mark {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
  color: var(--accent);
  font-family: var(--display);
  font-size: 13px;
  letter-spacing: 0.12em;
}

.chapter-mark::before {
  content: "";
  width: 3px;
  height: 1.1em;
  background: var(--accent);
  border-radius: 2px;
}

.chapter-heading {
  margin: 0 0 1.4em;
  font-family: var(--display);
  font-size: calc(var(--font-size) * 1.35);
  font-weight: 400;
  line-height: 1.4;
  letter-spacing: 0.04em;
}

.chapter-body {
  font-family: var(--body);
  font-size: var(--font-size);
  line-height: var(--line-height);
  color: var(--ink);
}

.chapter-body p {
  margin: 0 0 0.85em;
  text-indent: 2em;
  word-break: break-word;
}

.chapter-body p.empty-line {
  text-indent: 0;
  height: 0.55em;
  margin: 0;
}

.chapter-nav {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 720px;
  height: calc(var(--nav-h) + var(--safe-bottom));
  padding: 0 10px var(--safe-bottom);
  display: flex;
  align-items: center;
  gap: 8px;
  background: color-mix(in srgb, var(--bg) 90%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
  z-index: 20;
  transition: transform 0.25s ease, opacity 0.25s ease;
}

.chapter-nav.is-hidden {
  transform: translate(-50%, 110%);
  opacity: 0;
  pointer-events: none;
}

.nav-btn {
  flex: 1;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--ink);
  font-size: 14px;
  font-family: var(--ui);
  cursor: pointer;
}

.nav-btn:disabled {
  opacity: 0.35;
  cursor: default;
}

.nav-btn-mid {
  flex: 0.7;
  border-color: transparent;
  background: var(--accent-soft);
  color: var(--accent);
}

.nav-btn:active:not(:disabled) {
  transform: scale(0.98);
}

/* —— 目录抽屉 —— */
.drawer {
  position: fixed;
  inset: 0;
  z-index: 40;
}

.drawer-backdrop,
.sheet-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(10, 14, 20, 0.4);
}

.drawer-panel {
  position: absolute;
  top: 0;
  right: 0;
  width: min(86vw, 340px);
  height: 100%;
  background: var(--bg);
  box-shadow: -8px 0 32px rgba(0, 0, 0, 0.18);
  display: flex;
  flex-direction: column;
  padding-top: var(--safe-top);
  animation: slideIn 0.22s ease;
}

@keyframes slideIn {
  from {
    transform: translateX(8%);
    opacity: 0.6;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 8px 8px 18px;
  border-bottom: 1px solid var(--line);
}

.drawer-head h3 {
  margin: 0;
  font-family: var(--display);
  font-weight: 400;
  font-size: 1.2rem;
}

.toc-list {
  list-style: none;
  margin: 0;
  padding: 8px 10px calc(24px + var(--safe-bottom));
  overflow-y: auto;
  flex: 1;
}

.toc-list li button {
  width: 100%;
  text-align: left;
  border: none;
  background: transparent;
  color: var(--ink);
  padding: 12px 10px;
  border-radius: 8px;
  font-size: 14px;
  font-family: var(--ui);
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.toc-list li button.is-current {
  background: var(--accent-soft);
  color: var(--accent);
}

.toc-list li button:active {
  background: var(--accent-soft);
}

/* —— 设置底栏 —— */
.sheet {
  position: fixed;
  inset: 0;
  z-index: 50;
}

.sheet-panel {
  position: absolute;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  width: 100%;
  max-width: 720px;
  padding: 18px 20px calc(20px + var(--safe-bottom));
  border-radius: 18px 18px 0 0;
  background: var(--bg);
  box-shadow: 0 -8px 40px rgba(0, 0, 0, 0.2);
  animation: sheetUp 0.22s ease;
}

@keyframes sheetUp {
  from {
    transform: translate(-50%, 20%);
  }
  to {
    transform: translate(-50%, 0);
  }
}

.sheet-panel h3 {
  margin: 0 0 16px;
  font-family: var(--display);
  font-weight: 400;
  font-size: 1.15rem;
  text-align: center;
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
  font-size: 14px;
}

.setting-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.chip {
  min-width: 44px;
  height: 36px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  font-size: 14px;
  cursor: pointer;
}

.chip.is-active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}

.chip-label {
  min-width: 28px;
  text-align: center;
  font-variant-numeric: tabular-nums;
  color: var(--ink-soft);
  font-size: 13px;
}

.theme-swatch {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 2px solid var(--line);
  background: var(--sw);
  cursor: pointer;
  padding: 0;
}

.theme-swatch.is-active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-soft);
}

/* —— 书架工具条 —— */
.shelf-tools {
  padding: 2px 22px 4px;
}

.search-input {
  width: 100%;
  height: 42px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  color: var(--ink);
  font-size: 15px;
  font-family: var(--ui);
  outline: none;
  -webkit-appearance: none;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.search-input:focus {
  border-color: var(--accent);
}

.search-input::placeholder {
  color: var(--ink-soft);
}

.up-btn {
  margin: 10px 0 0;
  padding: 6px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--accent);
  font-size: 13px;
  font-family: var(--ui);
  cursor: pointer;
}

/* —— 继续阅读 —— */
.resume-card {
  display: block;
  width: 100%;
  margin-bottom: 16px;
  padding: 14px 16px;
  border: none;
  border-radius: 14px;
  background: var(--accent-soft);
  box-shadow: inset 3px 0 0 var(--accent);
  color: var(--ink);
  text-align: left;
  font: inherit;
  cursor: pointer;
}

.resume-card:active {
  transform: scale(0.985);
}

.resume-label {
  display: block;
  font-size: 11px;
  letter-spacing: 0.2em;
  color: var(--accent);
}

.resume-name {
  display: block;
  margin-top: 5px;
  font-family: var(--display);
  font-size: 1.15rem;
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.resume-book {
  display: block;
  margin-top: 3px;
  font-size: 11px;
  color: var(--ink-soft);
}

/* —— 书卡 —— */
.book-card {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 14px;
  margin-bottom: 8px;
  border: none;
  border-radius: 14px;
  background: var(--surface);
  color: var(--ink);
  text-align: left;
  font: inherit;
  cursor: pointer;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  transition: transform 0.15s ease, background 0.15s ease;
}

.book-card:active {
  transform: scale(0.985);
}

.book-card-idx {
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: var(--accent-soft);
  color: var(--accent);
  display: grid;
  place-items: center;
  font-family: var(--display);
  font-size: 15px;
  font-variant-numeric: tabular-nums;
}

.book-card-main {
  flex: 1;
  min-width: 0;
}

.book-card-title {
  display: block;
  font-family: var(--display);
  font-size: 1.2rem;
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.book-card-hint {
  display: block;
  margin-top: 3px;
  font-size: 11px;
  color: var(--ink-soft);
}

.book-card-lib {
  flex: 0 0 auto;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 11px;
}

.book-card-arrow {
  flex: 0 0 auto;
  color: var(--ink-soft);
  font-size: 22px;
  line-height: 1;
}

/* —— 书内子栏目 —— */
.sub-group-title {
  margin: 20px 8px 8px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  font-family: var(--display);
  font-size: 1rem;
  font-weight: 400;
}

.sub-group-title span:last-child {
  font-family: var(--ui);
  font-size: 12px;
  color: var(--ink-soft);
}

.empty-hint {
  margin: 24px 8px;
  font-size: 13px;
  color: var(--ink-soft);
  text-align: center;
  line-height: 1.7;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }
}
