/* ============================================================
   墨卷 MoJuan — 设计系统
   美学方向：文人书卷 · 纸墨朱砂（editorial/classical Chinese）
   ============================================================ */

:root {
  /* 纸墨调色板 */
  --paper: #f6f1e7;
  --paper-deep: #efe7d7;
  --paper-card: #fbf8f1;
  --ink: #1c1917;
  --ink-soft: #4a443c;
  --ink-faint: #8a8177;
  --cinnabar: #b3372c;          /* 朱砂红 */
  --cinnabar-deep: #8f2a22;
  --gold: #a07b2d;
  --line: rgba(28, 25, 23, 0.14);
  --line-strong: rgba(28, 25, 23, 0.3);

  /* 字体：中文衬线为主体 */
  --font-display: "Songti SC", "SimSun", "Noto Serif CJK SC", "Source Han Serif SC", serif;
  --font-body: "Songti SC", "SimSun", "Noto Serif CJK SC", "Source Han Serif SC", Georgia, serif;
  --font-ui: "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;

  --radius: 4px;
  --shadow-card: 0 1px 2px rgba(28, 25, 23, 0.06), 0 8px 24px rgba(28, 25, 23, 0.07);
  --shadow-pop: 0 4px 12px rgba(28, 25, 23, 0.12), 0 24px 48px rgba(28, 25, 23, 0.16);
  --maxw: 1120px;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

/* ---------- 阅读器主题（由 data-theme 切换） ---------- */
[data-theme="paper"] {
  --r-bg: #f6f1e7; --r-ink: #1c1917; --r-faint: #8a8177;
  --r-line: rgba(28, 25, 23, 0.14); --r-chrome: rgba(246, 241, 231, 0.92);
}
[data-theme="night"] {
  --r-bg: #16151a; --r-ink: #c9c4bb; --r-faint: #6f6a62;
  --r-line: rgba(201, 196, 187, 0.16); --r-chrome: rgba(22, 21, 26, 0.92);
  --paper: #16151a; --paper-deep: #1d1c22; --paper-card: #1f1e25;
  --ink: #c9c4bb; --ink-soft: #a19b92; --ink-faint: #6f6a62;
  --line: rgba(201, 196, 187, 0.16); --line-strong: rgba(201, 196, 187, 0.3);
  --cinnabar: #d4574a;
  --shadow-card: 0 1px 2px rgba(0,0,0,0.4), 0 8px 24px rgba(0,0,0,0.4);
}
[data-theme="green"] {
  --r-bg: #e3ece0; --r-ink: #2b362a; --r-faint: #75806f;
  --r-line: rgba(43, 54, 42, 0.16); --r-chrome: rgba(227, 236, 224, 0.92);
}
[data-theme="sepia"] {
  --r-bg: #eee0c6; --r-ink: #46392a; --r-faint: #93815f;
  --r-line: rgba(70, 57, 42, 0.18); --r-chrome: rgba(238, 224, 198, 0.92);
}
[data-theme="slate"] {
  --r-bg: #e8ecef; --r-ink: #26313a; --r-faint: #77828c;
  --r-line: rgba(38, 49, 58, 0.16); --r-chrome: rgba(232, 236, 239, 0.92);
}

/* ---------- Reset & Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font-body);
  background: var(--paper);
  color: var(--ink);
  line-height: 1.7;
  min-height: 100dvh;
  /* 纸张纹理 */
  background-image:
    radial-gradient(ellipse at 20% -10%, rgba(160, 123, 45, 0.06), transparent 50%),
    radial-gradient(ellipse at 90% 110%, rgba(179, 55, 44, 0.05), transparent 45%);
}
a { color: inherit; text-decoration: none; }
img { max-width: 100%; display: block; }
button { font-family: inherit; cursor: pointer; }
::selection { background: rgba(179, 55, 44, 0.85); color: #fff; }

.container { max-width: var(--maxw); margin: 0 auto; padding: 0 20px; }

/* ---------- 站点头部 ---------- */
.site-header {
  position: sticky; top: 0; z-index: 50;
  backdrop-filter: blur(12px);
  background: var(--r-chrome, rgba(246, 241, 231, 0.9));
  border-bottom: 1px solid var(--line);
}
.site-header .container {
  display: flex; align-items: center; gap: 16px;
  height: 60px;
}
.brand {
  display: flex; align-items: center; gap: 10px;
  font-family: var(--font-display);
  font-size: 22px; font-weight: 700; letter-spacing: 0.12em;
  flex-shrink: 0;
}
.brand .seal {
  width: 34px; height: 34px; border-radius: 5px;
  background: var(--cinnabar); color: #fff;
  display: grid; place-items: center;
  font-size: 19px; letter-spacing: 0;
  box-shadow: inset 0 0 0 1.5px rgba(255,255,255,0.35), 0 2px 6px rgba(179,55,44,0.35);
  transform: rotate(-3deg);
  transition: transform 0.4s var(--ease);
}
.brand:hover .seal { transform: rotate(3deg) scale(1.05); }
.brand .latin {
  font-family: var(--font-ui); font-size: 10px; font-weight: 500;
  letter-spacing: 0.3em; color: var(--ink-faint);
  text-transform: uppercase; display: block; line-height: 1;
  margin-top: 3px;
}
.brand .name { line-height: 1; }

.search-box {
  flex: 1; max-width: 420px; margin-left: auto;
  position: relative;
}
.search-box input {
  width: 100%; height: 38px;
  padding: 0 14px 0 36px;
  font-family: var(--font-body); font-size: 15px;
  color: var(--ink);
  background: var(--paper-card);
  border: 1px solid var(--line);
  border-radius: 19px;
  outline: none;
  transition: border-color 0.25s, box-shadow 0.25s;
}
.search-box input::placeholder { color: var(--ink-faint); }
.search-box input:focus {
  border-color: var(--cinnabar);
  box-shadow: 0 0 0 3px rgba(179, 55, 44, 0.14);
}
.search-box .search-icon {
  position: absolute; left: 13px; top: 50%; transform: translateY(-50%);
  width: 15px; height: 15px; opacity: 0.45; pointer-events: none;
}

/* ---------- 页脚 ---------- */
.site-footer {
  margin-top: 72px;
  border-top: 1px solid var(--line);
  padding: 28px 0 40px;
  font-family: var(--font-ui); font-size: 13px;
  color: var(--ink-faint);
}
.site-footer .container { display: flex; flex-wrap: wrap; gap: 8px 24px; justify-content: space-between; }

/* ============================================================
   首页
   ============================================================ */
.hero {
  padding: 56px 0 40px;
  position: relative;
  overflow: hidden;
}
.hero-kicker {
  font-family: var(--font-ui); font-size: 12px; letter-spacing: 0.35em;
  color: var(--cinnabar); text-transform: uppercase; margin-bottom: 14px;
}
.hero h1 {
  font-family: var(--font-display);
  font-size: clamp(34px, 6vw, 58px);
  line-height: 1.25; margin: 0 0 16px;
  font-weight: 700; letter-spacing: 0.04em;
}
.hero h1 em {
  font-style: normal; color: var(--cinnabar);
  position: relative; white-space: nowrap;
}
.hero h1 em::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: 6px; height: 10px;
  background: rgba(179, 55, 44, 0.16); z-index: -1;
  transform: skewX(-12deg);
}
.hero p {
  max-width: 560px; margin: 0;
  color: var(--ink-soft); font-size: 17px;
}
.hero .stats {
  display: flex; gap: 32px; margin-top: 28px;
  font-family: var(--font-ui);
}
.hero .stats b {
  display: block; font-family: var(--font-display);
  font-size: 26px; color: var(--ink); line-height: 1.2;
}
.hero .stats span { font-size: 12px; color: var(--ink-faint); letter-spacing: 0.1em; }
.hero .big-char {
  position: absolute; right: -30px; top: -40px;
  font-family: var(--font-display);
  font-size: clamp(180px, 30vw, 340px);
  line-height: 1; color: var(--cinnabar);
  opacity: 0.06; pointer-events: none; user-select: none;
}

/* 章节区标题 */
.section-head {
  display: flex; align-items: baseline; gap: 14px;
  margin: 40px 0 22px;
}
.section-head h2 {
  font-family: var(--font-display);
  font-size: 22px; margin: 0; letter-spacing: 0.1em;
}
.section-head .rule { flex: 1; height: 1px; background: var(--line); }
.section-head .count { font-family: var(--font-ui); font-size: 12px; color: var(--ink-faint); }

/* ---------- 书籍网格 ---------- */
.book-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 28px 22px;
}
.book-card {
  display: block;
  animation: rise 0.6s var(--ease) both;
  animation-delay: calc(var(--i, 0) * 55ms);
}
@keyframes rise {
  from { opacity: 0; transform: translateY(18px); }
  to { opacity: 1; transform: none; }
}
.book-cover {
  position: relative;
  aspect-ratio: 3 / 4;
  border-radius: var(--radius);
  overflow: hidden;
  display: grid; place-items: center;
  background: linear-gradient(155deg, var(--c1, #3b3630), var(--c2, #17130f));
  box-shadow: var(--shadow-card);
  transition: transform 0.45s var(--ease), box-shadow 0.45s var(--ease);
}
.book-card:hover .book-cover {
  transform: translateY(-6px) rotate(-0.5deg);
  box-shadow: var(--shadow-pop);
}
.book-cover::before {
  content: ""; position: absolute; inset: 0;
  background:
    linear-gradient(105deg, rgba(255,255,255,0.14) 0%, transparent 28%),
    radial-gradient(circle at 80% 15%, rgba(255,255,255,0.1), transparent 45%);
}
.book-cover::after {
  content: ""; position: absolute; left: 10px; top: 0; bottom: 0;
  width: 1px; background: rgba(255,255,255,0.22);
}
.book-cover .title-v {
  writing-mode: vertical-rl;
  font-family: var(--font-display);
  font-size: clamp(20px, 2.4vw, 26px);
  letter-spacing: 0.28em;
  color: #f4efe4;
  text-shadow: 0 2px 8px rgba(0,0,0,0.4);
  z-index: 1;
  max-height: 78%;
}
.book-cover .cover-tag {
  position: absolute; top: 10px; right: 10px; z-index: 2;
  font-family: var(--font-ui); font-size: 10px;
  padding: 2px 7px; border-radius: 2px;
  background: rgba(0,0,0,0.35); color: #f0e9dc;
  backdrop-filter: blur(4px);
  border: 1px solid rgba(255,255,255,0.18);
}
.book-cover .cover-seal {
  position: absolute; bottom: 12px; right: 12px; z-index: 2;
  width: 26px; height: 26px; border-radius: 3px;
  background: var(--cinnabar); color: #fff;
  font-size: 13px; display: grid; place-items: center;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.4);
  transform: rotate(4deg);
}
.book-meta { padding-top: 10px; }
.book-meta .t {
  font-family: var(--font-display); font-size: 16px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.book-meta .a {
  font-family: var(--font-ui); font-size: 12px; color: var(--ink-faint);
  display: flex; gap: 8px; margin-top: 2px;
}

/* 空 / 加载状态 */
.empty-state {
  text-align: center; padding: 72px 20px; color: var(--ink-faint);
}
.empty-state .glyph { font-family: var(--font-display); font-size: 52px; opacity: 0.4; }
.skeleton {
  aspect-ratio: 3/4; border-radius: var(--radius);
  background: linear-gradient(100deg, var(--paper-deep) 40%, var(--paper-card) 50%, var(--paper-deep) 60%);
  background-size: 200% 100%;
  animation: shimmer 1.2s infinite linear;
}
@keyframes shimmer { to { background-position: -200% 0; } }

/* ============================================================
   书籍详情页
   ============================================================ */
.book-hero {
  display: grid; grid-template-columns: 220px 1fr; gap: 36px;
  padding: 48px 0 8px;
}
.book-hero .book-cover { width: 100%; }
.book-hero .info h1 {
  font-family: var(--font-display);
  font-size: clamp(28px, 4vw, 40px);
  margin: 0 0 6px; letter-spacing: 0.06em;
}
.book-hero .info .byline {
  font-family: var(--font-ui); color: var(--ink-faint); font-size: 14px;
  display: flex; flex-wrap: wrap; gap: 6px 16px; margin-bottom: 16px;
}
.book-hero .byline .pill {
  border: 1px solid var(--line-strong); border-radius: 999px;
  padding: 1px 10px; font-size: 12px; color: var(--ink-soft);
}
.book-hero .intro {
  color: var(--ink-soft); font-size: 15.5px;
  border-left: 3px solid var(--cinnabar);
  padding-left: 16px; margin: 18px 0 26px;
  max-width: 640px;
}
.actions { display: flex; flex-wrap: wrap; gap: 12px; }
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  height: 46px; padding: 0 26px;
  font-family: var(--font-display); font-size: 16px; letter-spacing: 0.14em;
  border-radius: var(--radius); border: 1px solid transparent;
  transition: transform 0.25s var(--ease), box-shadow 0.25s, background 0.25s;
}
.btn-primary {
  background: var(--cinnabar); color: #fff;
  box-shadow: 0 3px 10px rgba(179, 55, 44, 0.35);
}
.btn-primary:hover { background: var(--cinnabar-deep); transform: translateY(-2px); }
.btn-ghost {
  background: transparent; color: var(--ink);
  border-color: var(--line-strong);
}
.btn-ghost:hover { border-color: var(--ink); transform: translateY(-2px); }

/* 目录 */
.toc {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 10px;
}
.toc a {
  display: flex; align-items: baseline; gap: 12px;
  padding: 13px 16px;
  background: var(--paper-card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-size: 15px;
  transition: border-color 0.2s, transform 0.2s var(--ease), background 0.2s;
}
.toc a:hover {
  border-color: var(--cinnabar);
  background: var(--paper-card);
  transform: translateX(4px);
}
.toc a .no {
  font-family: var(--font-ui); font-size: 11px; color: var(--cinnabar);
  min-width: 30px; letter-spacing: 0.05em;
}
.toc a .tt {
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* ============================================================
   阅读器
   ============================================================ */
.reader-page { background: var(--r-bg); color: var(--r-ink); min-height: 100dvh; }
.reader-page .site-header { display: none; }

.reader-topbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 60;
  height: 52px;
  display: flex; align-items: center; gap: 8px;
  padding: 0 12px;
  background: var(--r-chrome);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--r-line);
  transform: translateY(0);
  transition: transform 0.3s var(--ease);
}
.reader-topbar.hidden { transform: translateY(-100%); }
.icon-btn {
  width: 40px; height: 40px; flex-shrink: 0;
  display: grid; place-items: center;
  background: transparent; border: none; border-radius: 8px;
  color: var(--r-ink);
  transition: background 0.2s;
}
.icon-btn:hover { background: rgba(127,127,127,0.14); }
.icon-btn svg { width: 20px; height: 20px; }
.reader-title {
  flex: 1; min-width: 0; text-align: center;
  font-family: var(--font-display); font-size: 15px; letter-spacing: 0.06em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  padding: 0 4px;
}
.reader-title .sub {
  display: block; font-family: var(--font-ui);
  font-size: 10.5px; color: var(--r-faint); letter-spacing: 0.08em;
  line-height: 1.2;
}

.reader-main {
  padding: 84px 20px 140px;
  max-width: var(--reader-width, 760px);
  margin: 0 auto;
}
.chapter-head { text-align: center; margin-bottom: 40px; }
.chapter-head .bk {
  font-family: var(--font-ui); font-size: 12px;
  color: var(--r-faint); letter-spacing: 0.2em; margin-bottom: 12px;
}
.chapter-head h1 {
  font-family: var(--font-display);
  font-size: clamp(22px, 4vw, 30px);
  margin: 0 0 16px; letter-spacing: 0.08em; font-weight: 700;
}
.chapter-head .divider {
  display: flex; align-items: center; gap: 12px;
  justify-content: center; color: var(--r-faint);
}
.chapter-head .divider::before,
.chapter-head .divider::after {
  content: ""; width: 56px; height: 1px; background: var(--r-line);
}
.chapter-head .diamond {
  width: 7px; height: 7px; background: var(--cinnabar);
  transform: rotate(45deg);
}

.chapter-body {
  font-size: var(--reader-fs, 19px);
  line-height: var(--reader-lh, 2);
  letter-spacing: 0.03em;
  text-align: justify;
}
.chapter-body p {
  margin: 0 0 1.1em;
  text-indent: 2em;
}
.chapter-body p:first-child { text-indent: 2em; }

/* 上下章 */
.pager {
  display: flex; gap: 14px; margin-top: 56px;
  font-family: var(--font-display);
}
.pager a {
  flex: 1; text-align: center;
  padding: 16px 10px;
  border: 1px solid var(--r-line); border-radius: var(--radius);
  font-size: 15px; letter-spacing: 0.1em;
  transition: border-color 0.2s, background 0.2s;
}
.pager a:hover { border-color: var(--cinnabar); color: var(--cinnabar); }
.pager a.disabled { opacity: 0.35; pointer-events: none; }
.pager .end-note {
  flex: 2; display: grid; place-items: center;
  font-family: var(--font-ui); font-size: 12.5px; color: var(--r-faint);
  border: 1px dashed var(--r-line); border-radius: var(--radius);
}

/* 阅读进度条 */
.read-progress {
  position: fixed; top: 0; left: 0; z-index: 70;
  height: 2px; background: var(--cinnabar);
  width: 0%; transition: width 0.1s linear;
}

/* ---------- 抽屉（目录 / 设置） ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 80;
  background: rgba(0,0,0,0.45);
  opacity: 0; pointer-events: none;
  transition: opacity 0.3s;
}
.overlay.open { opacity: 1; pointer-events: auto; }

.drawer {
  position: fixed; top: 0; bottom: 0; left: 0; z-index: 90;
  width: min(84vw, 340px);
  background: var(--r-bg);
  border-right: 1px solid var(--r-line);
  transform: translateX(-100%);
  transition: transform 0.35s var(--ease);
  display: flex; flex-direction: column;
}
.drawer.open { transform: none; }
.drawer-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 18px; border-bottom: 1px solid var(--r-line);
  font-family: var(--font-display); font-size: 17px; letter-spacing: 0.14em;
}
.drawer-list { overflow-y: auto; flex: 1; padding: 8px 0 24px; }
.drawer-list a {
  display: flex; gap: 12px; align-items: baseline;
  padding: 11px 20px; font-size: 14.5px;
  border-bottom: 1px solid transparent;
  color: var(--r-ink);
}
.drawer-list a:hover { background: rgba(127,127,127,0.09); }
.drawer-list a.active { color: var(--cinnabar); background: rgba(179,55,44,0.07); }
.drawer-list a .no {
  font-family: var(--font-ui); font-size: 11px; color: var(--r-faint);
  min-width: 28px;
}
.drawer-list a.active .no { color: var(--cinnabar); }
.drawer-list .tt { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* 设置面板 */
.settings-panel {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 90;
  background: var(--r-bg);
  border-top: 1px solid var(--r-line);
  border-radius: 16px 16px 0 0;
  padding: 10px 22px calc(22px + env(safe-area-inset-bottom));
  transform: translateY(110%);
  transition: transform 0.35s var(--ease);
  box-shadow: 0 -12px 40px rgba(0,0,0,0.2);
  max-width: 560px; margin: 0 auto;
}
.settings-panel.open { transform: none; }
.settings-panel .grip {
  width: 42px; height: 4px; border-radius: 2px;
  background: var(--r-line); margin: 4px auto 16px;
}
.set-row { margin-bottom: 18px; }
.set-label {
  font-family: var(--font-ui); font-size: 11.5px;
  letter-spacing: 0.2em; color: var(--r-faint);
  margin-bottom: 10px;
}
.theme-swatches { display: flex; gap: 14px; }
.swatch {
  width: 40px; height: 40px; border-radius: 50%;
  border: 2px solid transparent;
  position: relative;
  transition: transform 0.2s var(--ease), border-color 0.2s;
}
.swatch:hover { transform: scale(1.1); }
.swatch.active { border-color: var(--cinnabar); }
.swatch.active::after {
  content: ""; position: absolute; inset: -7px;
  border: 1px solid var(--cinnabar); border-radius: 50%;
}
.seg {
  display: flex; border: 1px solid var(--r-line); border-radius: 8px;
  overflow: hidden;
}
.seg button {
  flex: 1; height: 42px;
  background: transparent; border: none;
  color: var(--r-ink); font-family: var(--font-display); font-size: 15px;
  border-right: 1px solid var(--r-line);
  transition: background 0.2s;
}
.seg button:last-child { border-right: none; }
.seg button.active { background: rgba(179,55,44,0.12); color: var(--cinnabar); }
.seg button:hover:not(.active) { background: rgba(127,127,127,0.1); }

/* 底部工具栏 */
.reader-toolbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 60;
  display: flex; justify-content: space-around;
  padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
  background: var(--r-chrome);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--r-line);
}
.reader-toolbar button {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  background: none; border: none; color: var(--r-ink);
  font-family: var(--font-ui); font-size: 11px;
  padding: 4px 16px; border-radius: 8px;
  transition: color 0.2s, background 0.2s;
}
.reader-toolbar button:hover { color: var(--cinnabar); background: rgba(127,127,127,0.1); }
.reader-toolbar svg { width: 20px; height: 20px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 96px; z-index: 120;
  transform: translate(-50%, 20px);
  background: var(--ink); color: var(--paper);
  font-family: var(--font-ui); font-size: 13.5px;
  padding: 10px 20px; border-radius: 999px;
  opacity: 0; pointer-events: none;
  transition: opacity 0.3s, transform 0.3s var(--ease);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- 页面进入动画 ---------- */
.reveal { animation: rise 0.7s var(--ease) both; }

/* ============================================================
   响应式
   ============================================================ */
@media (max-width: 760px) {
  .hero { padding: 36px 0 28px; }
  .hero .big-char { display: none; }
  .hero .stats { gap: 22px; }
  .book-grid { grid-template-columns: repeat(auto-fill, minmax(124px, 1fr)); gap: 22px 14px; }
  .book-hero { grid-template-columns: 120px 1fr; gap: 18px; padding-top: 28px; }
  .book-hero .intro { grid-column: 1 / -1; }
  .book-hero .actions { grid-column: 1 / -1; }
  .search-box { max-width: none; }
  .brand .latin { display: none; }
  .toc { grid-template-columns: 1fr; }
  .reader-main { padding-left: 18px; padding-right: 18px; }
  .pager .end-note { display: none; }
}
@media (max-width: 420px) {
  .brand .name-txt { display: none; }
}
