/* ============================================================
   栖墨小说 · 设计系统
   Design Read: 中文网文阅读馆，暖纸/绿灯的编辑-图书馆气质。
   Dials: VARIANCE 5 / MOTION 3 / DENSITY 6。
   调色板: 松绿主色 + 暖骨白纸（taste-skill 认可的 Forest 家族），不用 AI 紫。
   字体: 宋体系衬线做正文/书名（阅读/出版语境），系统 CJK 无衬线做界面。
   圆角规则(锁定): 卡片 10px / 控件 8px / 封面 4px。
   主题锁: 整页只跟随一个主题（[data-theme] 或系统），区块不反色。
   ============================================================ */

:root {
  --font-serif: "Noto Serif SC", "Source Han Serif SC", "Source Han Serif CN", "Songti SC", "STSong", "SimSun", Georgia, "Times New Roman", serif;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", system-ui, sans-serif;

  --paper: #f2ede2;      /* 暖骨白 · 页面底 */
  --surface: #fbf7ee;    /* 卡片/浮层 */
  --surface-2: #ece5d6;  /* 次级填充 */
  --ink: #221d16;        /* 暖近黑正文（非纯黑） */
  --ink-soft: #6d6555;   /* 次级文字 */
  --ink-faint: #9a9080;  /* 弱化文字 */
  --line: #ddd4c2;       /* 分隔线 */
  --line-soft: #e7dfd0;
  --accent: #23574a;     /* 松绿主色（唯一强调色） */
  --accent-ink: #1a4136; /* 深松绿 · hover */
  --on-accent: #f6f2e8;  /* 主色上的文字 */
  --amber: #a86a1f;      /* 暖赭 · 极少量点缀（章节数/热度） */
  --shadow: 24px 40px -32px rgba(40, 32, 18, 0.45);
  --shadow-sm: 0 2px 10px -6px rgba(40, 32, 18, 0.35);

  --radius-card: 10px;
  --radius-ctrl: 8px;
  --radius-cover: 4px;
  --wrap: 1180px;
}

[data-theme="dark"] {
  --paper: #15120c;
  --surface: #1e1a12;
  --surface-2: #2a251b;
  --ink: #eae3d2;
  --ink-soft: #a59b86;
  --ink-faint: #7b7261;
  --line: #322c20;
  --line-soft: #29241a;
  --accent: #74b7a0;
  --accent-ink: #8fccb6;
  --on-accent: #10231d;
  --amber: #d3a15c;
  --shadow: 24px 40px -30px rgba(0, 0, 0, 0.7);
  --shadow-sm: 0 2px 12px -6px rgba(0, 0, 0, 0.6);
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  font-family: var(--font-sans);
  color: var(--ink);
  background: var(--paper);
  line-height: 1.6;
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

a { color: inherit; text-decoration: none; }
img { max-width: 100%; display: block; }
button { font-family: inherit; cursor: pointer; }

.wrap { width: 100%; max-width: var(--wrap); margin-inline: auto; padding-inline: 22px; }
main { flex: 1 0 auto; }

/* 细纹底：极淡的纸纹，固定层不参与滚动重绘 */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background-image: radial-gradient(rgba(120, 100, 60, 0.05) 1px, transparent 1px);
  background-size: 4px 4px;
  opacity: 0.6;
}

/* ---------------- 站头 ---------------- */
.site-head {
  position: sticky;
  top: 0;
  z-index: 40;
  background: color-mix(in srgb, var(--paper) 86%, transparent);
  backdrop-filter: saturate(140%) blur(10px);
  border-bottom: 1px solid var(--line-soft);
}
.head-inner { display: flex; align-items: center; gap: 20px; height: 66px; }
.brand-mark {
  font-family: var(--font-serif);
  font-weight: 700;
  letter-spacing: 0.14em;
  font-size: 24px;
  color: var(--ink);
}
.brand { display: inline-flex; align-items: center; }
.site-nav { display: flex; gap: 4px; margin-inline-start: 8px; }
.nav-link {
  font-size: 15px;
  color: var(--ink-soft);
  padding: 8px 12px;
  border-radius: var(--radius-ctrl);
  transition: color .2s, background .2s;
}
.nav-link:hover { color: var(--ink); background: var(--surface-2); }
.nav-link.is-active { color: var(--accent-ink); font-weight: 600; }
.theme-toggle {
  margin-inline-start: auto;
  width: 40px; height: 40px;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: var(--radius-ctrl);
  color: var(--ink-soft);
  font-size: 17px;
  line-height: 1;
  transition: color .2s, border-color .2s, transform .1s;
}
.theme-toggle:hover { color: var(--accent-ink); border-color: var(--accent); }
.theme-toggle:active { transform: translateY(1px); }

/* ---------------- 通用块 ---------------- */
.section { padding-block: 46px; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; margin-bottom: 22px; }
.section-title { font-family: var(--font-serif); font-size: 26px; font-weight: 700; margin: 0; letter-spacing: 0.02em; }
.section-more { font-size: 14px; color: var(--ink-soft); }
.section-more:hover { color: var(--accent-ink); }

.btn {
  display: inline-flex; align-items: center; gap: 8px;
  font-size: 15px; font-weight: 600;
  padding: 11px 20px;
  border-radius: var(--radius-ctrl);
  border: 1px solid transparent;
  transition: background .2s, color .2s, border-color .2s, transform .1s;
  white-space: nowrap;
}
.btn-primary { background: var(--accent); color: var(--on-accent); }
.btn-primary:hover { background: var(--accent-ink); }
.btn-primary:active { transform: translateY(1px); }
.btn-ghost { border-color: var(--line); color: var(--ink); background: var(--surface); }
.btn-ghost:hover { border-color: var(--accent); color: var(--accent-ink); }

/* ---------------- 首页 Hero（非居中，左内容 / 右真实封面书架）---------------- */
.hero { padding-block: 56px 30px; }
.hero-inner {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr);
  gap: 48px;
  align-items: center;
}
.hero-eyebrow { font-size: 13px; letter-spacing: 0.26em; text-transform: uppercase; color: var(--accent-ink); font-weight: 600; }
.hero h1 {
  font-family: var(--font-serif);
  font-size: clamp(34px, 5vw, 54px);
  line-height: 1.12;
  margin: 16px 0 0;
  letter-spacing: 0.01em;
}
.hero-lede { font-size: 17px; color: var(--ink-soft); max-width: 34ch; margin: 18px 0 26px; }
.hero-actions { display: flex; gap: 12px; flex-wrap: wrap; }
.hero-search { margin-top: 22px; max-width: 420px; }

/* 书架：真实封面交错排布 */
.shelf {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
}
.shelf .book-card:nth-child(3n+2) { transform: translateY(22px); }
.shelf .book-cover { box-shadow: var(--shadow); }
.shelf-skeleton { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.shelf-skeleton span { aspect-ratio: 3/4; border-radius: var(--radius-cover); background: var(--surface-2); }
.shelf-skeleton span:nth-child(3n+2) { transform: translateY(22px); }

/* ---------------- 分类导航条 ---------------- */
.cat-strip { display: flex; flex-wrap: wrap; gap: 10px; }
.cat-chip {
  display: inline-flex; align-items: baseline; gap: 8px;
  padding: 9px 16px;
  border: 1px solid var(--line);
  border-radius: 999px;   /* chip 是唯一的胶囊件，规则内单独说明 */
  background: var(--surface);
  color: var(--ink);
  font-size: 15px;
  transition: border-color .2s, color .2s, background .2s;
}
.cat-chip:hover { border-color: var(--accent); color: var(--accent-ink); }
.cat-chip .cat-count { font-size: 12px; color: var(--ink-faint); }
.cat-chip.is-active { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }
.cat-chip.is-active .cat-count { color: color-mix(in srgb, var(--on-accent) 70%, transparent); }

/* ---------------- 书卡网格 ---------------- */
.book-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 26px 22px;
}
.book-card { display: flex; flex-direction: column; gap: 10px; }
.book-cover {
  position: relative;
  display: block;
  aspect-ratio: 3 / 4;
  border-radius: var(--radius-cover);
  overflow: hidden;
  background: var(--surface-2);
  box-shadow: var(--shadow-sm);
  transition: transform .22s ease, box-shadow .22s ease;
}
.book-card:hover .book-cover { transform: translateY(-4px); box-shadow: var(--shadow); }
.cover-img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; z-index: 2; }
/* 兜底书脊：首字 + 侧封条，缺封面时的功能性占位 */
.cover-spine {
  position: absolute; inset: 0; z-index: 1;
  display: flex; align-items: center; justify-content: center;
  background:
    linear-gradient(135deg, color-mix(in srgb, var(--spine) 88%, #000 4%), var(--spine));
}
.cover-glyph {
  font-family: var(--font-serif);
  font-size: clamp(30px, 5vw, 46px);
  font-weight: 700;
  color: rgba(255, 255, 255, 0.92);
  text-shadow: 0 1px 2px rgba(0,0,0,0.25);
}
.cover-strip { position: absolute; inset-block: 0; inset-inline-start: 8%; width: 3px; background: rgba(255,255,255,0.14); }
.book-title {
  font-family: var(--font-serif);
  font-size: 16px; font-weight: 600; line-height: 1.35;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.book-card:hover .book-title { color: var(--accent-ink); }
.book-meta { font-size: 12.5px; color: var(--ink-soft); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.book-desc {
  font-size: 13px; color: var(--ink-faint); line-height: 1.5;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}

/* ---------------- 浏览/分类页控件 ---------------- */
.page-head { padding-block: 34px 8px; }
.page-title { font-family: var(--font-serif); font-size: 30px; margin: 0 0 6px; }
.page-sub { color: var(--ink-soft); font-size: 14.5px; }
.controls { display: flex; flex-wrap: wrap; gap: 14px; align-items: center; justify-content: space-between; margin: 22px 0 6px; }
.sort-tabs { display: inline-flex; gap: 4px; background: var(--surface-2); padding: 4px; border-radius: var(--radius-ctrl); }
.sort-tab { border: 0; background: transparent; color: var(--ink-soft); font-size: 14px; padding: 7px 14px; border-radius: 6px; }
.sort-tab.is-active { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-sm); font-weight: 600; }

.pager { display: flex; align-items: center; justify-content: center; gap: 16px; padding-block: 40px 8px; }
.pager .btn-ghost[disabled] { opacity: .4; pointer-events: none; }
.pager-info { font-size: 14px; color: var(--ink-soft); font-variant-numeric: tabular-nums; }

/* ---------------- 搜索 ---------------- */
.field {
  display: flex; align-items: center; gap: 10px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-ctrl);
  padding: 4px 4px 4px 16px;
  transition: border-color .2s, box-shadow .2s;
}
.field:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent); }
.field input {
  flex: 1; border: 0; background: transparent; color: var(--ink);
  font-family: inherit; font-size: 16px; padding: 10px 0; outline: none; min-width: 0;
}
.field input::placeholder { color: var(--ink-faint); }
.field .btn-primary { padding: 10px 20px; }
.search-status { margin: 20px 0 4px; font-size: 14px; color: var(--ink-soft); min-height: 20px; }
.search-scan { display: inline-block; height: 3px; width: 120px; background: var(--surface-2); border-radius: 2px; overflow: hidden; vertical-align: middle; margin-inline-start: 10px; }
.search-scan i { display: block; height: 100%; background: var(--accent); width: 0; transition: width .2s; }

/* ---------------- 详情页 ---------------- */
.detail-top { display: grid; grid-template-columns: 220px minmax(0,1fr); gap: 36px; padding-block: 38px 10px; }
.detail-cover { aspect-ratio: 3/4; border-radius: var(--radius-cover); overflow: hidden; position: relative; box-shadow: var(--shadow); background: var(--surface-2); }
.detail-cover .book-cover { position: absolute; inset: 0; box-shadow: none; }
.detail-title { font-family: var(--font-serif); font-size: clamp(28px, 4vw, 40px); line-height: 1.15; margin: 0 0 12px; }
.detail-meta { display: flex; flex-wrap: wrap; gap: 8px 18px; color: var(--ink-soft); font-size: 14.5px; margin-bottom: 20px; }
.detail-meta b { color: var(--ink); font-weight: 600; }
.tag { font-size: 13px; padding: 4px 11px; border-radius: 999px; background: var(--surface-2); color: var(--ink-soft); }
.tag-amber { color: var(--amber); background: color-mix(in srgb, var(--amber) 14%, transparent); }
.detail-actions { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 4px; }
.detail-desc { margin-top: 26px; }
.detail-desc h2, .detail-catalog h2, .detail-recs h2 { font-family: var(--font-serif); font-size: 20px; margin: 0 0 12px; }
.detail-desc p { font-family: var(--font-serif); color: var(--ink); line-height: 1.9; margin: 0; max-width: 70ch; white-space: pre-line; }
.detail-desc p.is-empty { color: var(--ink-faint); font-style: italic; }

.catalog-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 2px 24px; }
.catalog-list a {
  padding: 10px 4px; font-size: 14.5px; color: var(--ink-soft);
  border-bottom: 1px solid var(--line-soft);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  transition: color .18s;
}
.catalog-list a:hover { color: var(--accent-ink); }
.catalog-toggle { margin-top: 16px; }

/* ---------------- 阅读器 ---------------- */
body.reader-body { background: var(--paper); }
.reader-head {
  position: sticky; top: 0; z-index: 30;
  background: color-mix(in srgb, var(--paper) 90%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line-soft);
  transition: transform .3s ease;
}
.reader-head.hidden { transform: translateY(-100%); }
.reader-head-inner { display: flex; align-items: center; gap: 14px; height: 58px; }
.reader-back { color: var(--ink-soft); font-size: 15px; }
.reader-back:hover { color: var(--accent-ink); }
.reader-book { font-family: var(--font-serif); font-weight: 600; font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.reader-tools { margin-inline-start: auto; display: flex; gap: 8px; }
.rtool { border: 1px solid var(--line); background: var(--surface); border-radius: var(--radius-ctrl); color: var(--ink-soft); font-size: 14px; padding: 7px 12px; transition: color .2s, border-color .2s; }
.rtool:hover { color: var(--accent-ink); border-color: var(--accent); }

.reader-main { max-width: 760px; margin-inline: auto; padding: 40px 22px 20px; }
.chapter-title { font-family: var(--font-serif); font-size: clamp(24px, 3.4vw, 32px); line-height: 1.3; margin: 0 0 6px; text-align: center; }
.chapter-sub { text-align: center; color: var(--ink-faint); font-size: 13.5px; margin-bottom: 34px; }
.chapter-content {
  font-family: var(--font-serif);
  font-size: var(--reader-fs, 20px);
  line-height: var(--reader-lh, 2);
  color: var(--ink);
  letter-spacing: 0.01em;
}
.chapter-content p { margin: 0 0 1.1em; text-indent: 2em; }
.chapter-nav { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin: 46px 0 10px; }
.chapter-nav .btn-ghost { flex: 1; justify-content: center; }
.chapter-nav .btn-ghost[disabled] { opacity: .4; pointer-events: none; }

/* 阅读设置浮层 */
.settings-pop {
  position: fixed; right: 22px; top: 66px; z-index: 45;
  width: 260px; padding: 18px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius-card); box-shadow: var(--shadow);
  display: none;
}
.settings-pop.open { display: block; }
.settings-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.settings-row:last-child { margin-bottom: 0; }
.settings-row .label { font-size: 14px; color: var(--ink-soft); }
.stepper { display: inline-flex; gap: 6px; }
.stepper button { width: 30px; height: 30px; border: 1px solid var(--line); background: var(--paper); border-radius: 6px; color: var(--ink); font-size: 16px; line-height: 1; }
.stepper button:hover { border-color: var(--accent); color: var(--accent-ink); }
.seg { display: inline-flex; background: var(--surface-2); border-radius: var(--radius-ctrl); padding: 3px; }
.seg button { border: 0; background: transparent; color: var(--ink-soft); font-size: 13px; padding: 6px 12px; border-radius: 6px; }
.seg button.is-active { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-sm); }

/* 目录抽屉 */
.drawer-mask { position: fixed; inset: 0; z-index: 50; background: rgba(20,16,8,0.4); display: none; }
.drawer-mask.open { display: block; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 51;
  width: min(420px, 88vw);
  background: var(--surface); border-inline-start: 1px solid var(--line);
  transform: translateX(100%); transition: transform .28s ease;
  display: flex; flex-direction: column;
}
.drawer.open { transform: translateX(0); }
.drawer-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 20px; border-bottom: 1px solid var(--line-soft); }
.drawer-head h3 { font-family: var(--font-serif); margin: 0; font-size: 18px; }
.drawer-close { border: 0; background: transparent; font-size: 22px; color: var(--ink-soft); line-height: 1; }
.drawer-body { overflow-y: auto; padding: 8px 0; }
.drawer-body a {
  display: block; padding: 11px 20px; font-size: 14.5px; color: var(--ink-soft);
  border-bottom: 1px solid var(--line-soft);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.drawer-body a:hover { color: var(--accent-ink); background: var(--surface-2); }
.drawer-body a.is-current { color: var(--accent-ink); font-weight: 600; }

/* ---------------- 状态：加载/空/错误 ---------------- */
.state { text-align: center; color: var(--ink-soft); padding: 56px 20px; }
.state-title { font-family: var(--font-serif); font-size: 20px; color: var(--ink); margin: 0 0 8px; }
.skeleton-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 26px 22px; }
.skeleton-grid > span { display: block; }
.sk-cover { aspect-ratio: 3/4; border-radius: var(--radius-cover); background: var(--surface-2); }
.sk-line { height: 12px; border-radius: 4px; background: var(--surface-2); margin-top: 10px; }
.sk-line.short { width: 60%; }
.spin { display: inline-block; width: 22px; height: 22px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------------- 站脚 ---------------- */
.site-foot { margin-top: 40px; border-top: 1px solid var(--line-soft); background: var(--surface); }
.foot-inner { display: grid; grid-template-columns: 1fr auto; gap: 20px 40px; padding-block: 34px; align-items: start; }
.foot-brand .brand-mark { font-size: 22px; }
.foot-tag { color: var(--ink-soft); font-size: 14px; margin: 6px 0 0; }
.foot-links { display: flex; gap: 20px; align-items: center; font-size: 14px; color: var(--ink-soft); }
.foot-links a:hover { color: var(--accent-ink); }
.foot-note { grid-column: 1 / -1; color: var(--ink-faint); font-size: 12.5px; margin: 4px 0 0; }

/* ---------------- 入场动效（MOTION 3：仅轻量淡入，尊重减弱动效）---------------- */
@media (prefers-reduced-motion: no-preference) {
  .fade-up { animation: fadeUp .6s cubic-bezier(.16,1,.3,1) both; }
  @keyframes fadeUp { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
}

/* ---------------- 响应式 ---------------- */
@media (max-width: 900px) {
  .hero-inner { grid-template-columns: 1fr; gap: 30px; }
  .hero-visual { order: -1; }
  .shelf, .shelf-skeleton { grid-template-columns: repeat(3, 1fr); max-width: 420px; }
  .detail-top { grid-template-columns: 140px minmax(0,1fr); gap: 22px; }
}
@media (max-width: 640px) {
  .wrap { padding-inline: 16px; }
  .head-inner { gap: 10px; height: 60px; }
  .brand-mark { font-size: 21px; }
  .nav-link { padding: 8px 9px; font-size: 14px; }
  .book-grid, .skeleton-grid { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 20px 16px; }
  .section-title { font-size: 22px; }
  .detail-top { grid-template-columns: 110px minmax(0,1fr); gap: 16px; }
  .catalog-list { grid-template-columns: 1fr 1fr; }
  .foot-inner { grid-template-columns: 1fr; }
  .reader-main { padding: 28px 18px; }
}
