:root {
  --bg: #f4f1ea;
  --card: #ffffff;
  --primary: #c0392b;
  --primary-dark: #9c2c20;
  --ink: #2b2622;
  --muted: #8a8074;
  --border: #e7e1d6;
  --topbar-h: 64px;
  --serif: "Noto Serif SC", "Songti SC", "SimSun", "STSong", serif;
  --sans: "PingFang SC", "Microsoft YaHei", "Hiragino Sans GB", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--sans);
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

/* 顶栏 */
.topbar {
  position: sticky; top: 0; z-index: 50;
  background: rgba(255,255,255,.96);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: 1280px; margin: 0 auto;
  display: flex; align-items: center; gap: 16px;
  padding: 12px 18px;
}
.brand {
  font-family: var(--serif);
  font-weight: 700; font-size: 22px;
  color: var(--primary); text-decoration: none;
  letter-spacing: 2px; white-space: nowrap;
}
.search {
  flex: 1; position: relative; display: flex; align-items: center;
  background: #f1ece1; border-radius: 22px; padding: 0 14px;
  border: 1px solid transparent; transition: border-color .15s;
}
.search:focus-within { border-color: var(--primary); background:#fff; }
.search-ico { font-size: 14px; opacity: .6; }
.search input {
  flex: 1; border: 0; background: transparent; outline: none;
  padding: 10px 8px; font-size: 15px; color: var(--ink);
}
.btn-primary {
  border: 0; background: var(--primary); color: #fff;
  font-size: 15px; font-weight: 600; padding: 10px 18px;
  border-radius: 22px; cursor: pointer; white-space: nowrap;
  transition: background .15s, transform .1s;
}
.btn-primary:hover { background: var(--primary-dark); }
.btn-primary:active { transform: scale(.97); }
.btn-ghost {
  border: 1px solid var(--border); background: #fff; color: var(--ink);
  font-size: 15px; padding: 10px 18px; border-radius: 22px; cursor: pointer;
}

/* 分类标签 */
.tabs {
  max-width: 1280px; margin: 14px auto 0; padding: 0 18px;
  display: flex; gap: 10px;
}
.tab {
  border: 0; background: #fff; color: var(--muted);
  font-size: 14px; padding: 8px 18px; border-radius: 20px;
  cursor: pointer; border: 1px solid var(--border);
  transition: all .15s;
}
.tab.active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* 瀑布流 */
.feed {
  max-width: 1280px; margin: 16px auto; padding: 0 18px;
  column-count: 4; column-gap: 16px;
}
@media (max-width: 1100px){ .feed { column-count: 3; } }
@media (max-width: 760px){ .feed { column-count: 2; } }
@media (max-width: 480px){ .feed { column-count: 1; } }

.card {
  background: var(--card); border-radius: 14px; overflow: hidden;
  margin-bottom: 16px; break-inside: avoid; cursor: pointer;
  box-shadow: 0 1px 4px rgba(0,0,0,.06);
  transition: transform .15s, box-shadow .15s;
}
.card:hover { transform: translateY(-3px); box-shadow: 0 8px 22px rgba(0,0,0,.12); }
.card .cover { width: 100%; display: block; object-fit: cover; }
.card .cover.placeholder {
  height: 150px; display: flex; align-items: center; justify-content: center;
  color: #fff; font-family: var(--serif); font-size: 46px; font-weight: 700;
}
.card .body { padding: 12px 14px 14px; }
.card .title { font-size: 15px; font-weight: 600; line-height: 1.45; }
.card .excerpt {
  font-size: 13px; color: var(--muted); margin-top: 6px; line-height: 1.55;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}
.card .meta { display: flex; justify-content: space-between; align-items: center; margin-top: 10px; }
.card .meta .who { font-size: 12px; color: #9a8f80; }

.badge { font-size: 11px; padding: 3px 9px; border-radius: 20px; font-weight: 600; }
.badge.history { background: #f6e2d8; color: #b2562f; }
.badge.user { background: #e3ecf6; color: #3a6ea5; }

.loading { text-align: center; color: var(--muted); padding: 24px; font-size: 14px; }
.empty { text-align: center; color: var(--muted); padding: 60px 20px; font-size: 15px; }

/* 弹窗 */
.modal { position: fixed; inset: 0; z-index: 100; display: flex; align-items: flex-start; justify-content: center; }
.modal[hidden] { display: none; }
.modal-mask { position: absolute; inset: 0; background: rgba(30,24,20,.5); backdrop-filter: blur(2px); }
.modal-card {
  position: relative; background: #fff; border-radius: 16px;
  margin: 5vh auto; max-width: 720px; width: calc(100% - 32px);
  max-height: 90vh; overflow-y: auto; padding: 26px 28px;
  box-shadow: 0 20px 60px rgba(0,0,0,.3);
}
.modal-close {
  position: absolute; top: 12px; right: 14px; border: 0; background: transparent;
  font-size: 28px; line-height: 1; color: var(--muted); cursor: pointer;
}
.modal-close:hover { color: var(--ink); }

/* 分享面板 */
.share-box { max-width: 420px; }
.share-head { display: flex; align-items: center; justify-content: space-between; font-family: var(--serif); font-size: 18px; font-weight: 600; color: var(--ink); margin-bottom: 16px; }
.share-head .modal-close { position: static; font-size: 24px; }
.share-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.share-opt {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 6px; padding: 14px 8px; border: 1px solid var(--border); border-radius: 12px;
  background: #fff; color: var(--ink); cursor: pointer; font-size: 14px;
  transition: border-color .15s, background .15s;
}
.share-opt:hover { border-color: var(--primary); background: #fbeae7; color: var(--primary); }
.share-qr { text-align: center; margin: 16px 0 8px; }
.share-qr img { width: 180px; height: 180px; }
.share-msg { margin-top: 12px; font-size: 13px; color: var(--muted); text-align: center; line-height: 1.6; }

/* 详情 */
.detail-card h2 { font-family: var(--serif); font-size: 24px; margin: 0 8px 8px 0; line-height: 1.4; }
.detail-meta { font-size: 13px; color: var(--muted); display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.detail-tags { margin: 12px 0 4px; display: flex; flex-wrap: wrap; gap: 8px; }
.tag { font-size: 12px; color: var(--primary); background: #fbeae7; padding: 3px 10px; border-radius: 16px; }
.detail-gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; margin: 14px 0; }
.detail-gallery img { width: 100%; border-radius: 10px; object-fit: cover; max-height: 320px; }
.detail-section { margin-top: 18px; }
.sec-label {
  display: inline-flex; align-items: center; gap: 10px; font-size: 13px; font-weight: 700; color: #fff;
  background: var(--primary); padding: 3px 12px; border-radius: 14px; margin-bottom: 8px;
}
.read-btn {
  font-family: var(--sans); font-size: 12px; font-weight: 600; cursor: pointer;
  background: rgba(255,255,255,.92); color: var(--primary); border: none;
  padding: 3px 10px; border-radius: 12px; transition: background .15s, transform .1s; white-space: nowrap;
}
.read-btn:hover { background: #fff; }
.read-btn:active { transform: scale(.96); }
.read-btn[data-active="1"] { background: #fff; color: var(--primary-dark); }
.detail-section p { font-size: 15px; line-height: 1.85; margin: 0; white-space: pre-wrap; }
pre.classical {
  font-family: var(--serif); font-size: 16px; line-height: 2; margin: 0;
  white-space: pre-wrap; background: #fbf7ee; border-left: 4px solid var(--primary);
  padding: 14px 16px; border-radius: 8px; color: #3a2f25;
}

/* 发帖表单 */
.compose-title { font-family: var(--serif); margin: 0 0 16px; font-size: 20px; }
.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.field input, .field textarea, .field select {
  width: 100%; border: 1px solid var(--border); border-radius: 10px;
  padding: 10px 12px; font-size: 14px; font-family: inherit; outline: none;
  transition: border-color .15s; background: #fcfbf8;
}
.field input:focus, .field textarea:focus, .field select:focus { border-color: var(--primary); background:#fff; }
.field textarea { resize: vertical; }
.preview { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.preview .thumb {
  position: relative; width: 72px; height: 72px; border-radius: 8px; overflow: hidden;
  border: 1px solid var(--border);
}
.preview .thumb img { width: 100%; height: 100%; object-fit: cover; }
.preview .thumb .del {
  position: absolute; top: 2px; right: 2px; background: rgba(0,0,0,.6); color: #fff;
  border: 0; border-radius: 50%; width: 18px; height: 18px; font-size: 12px; cursor: pointer; line-height: 1;
}
.compose-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 6px; }
.form-msg { font-size: 13px; margin-top: 10px; min-height: 18px; }
.form-msg.err { color: var(--primary); }
.form-msg.ok { color: #2e7d32; }

.site-footer { text-align: center; color: var(--muted); font-size: 12px; padding: 30px 16px 40px; }

/* 顶栏占位 + 返回 */
.topbar-inner .spacer { flex: 1; }

/* 卡片元信息微调 */
.card .meta .right { display: flex; gap: 8px; align-items: center; }
.card .meta .cmt { font-size: 12px; color: #9a8f80; }

/* 发帖：标签行 + Markdown 预览 */
.label-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.label-row > span { font-size: 13px; color: var(--muted); }
.btn-mini {
  border: 1px solid var(--border); background: #fff; color: var(--primary);
  font-size: 13px; padding: 4px 12px; border-radius: 16px; cursor: pointer;
}
.btn-mini:hover { background: #fbeae7; }
.md-preview { margin-top: 10px; padding: 12px 14px; border: 1px dashed var(--border); border-radius: 10px; background: #fcfbf8; }

/* ═══ Markdown 分栏编辑器 ═══ */
.md-editor { border: 1px solid var(--border); border-radius: 12px; overflow: hidden; background: #fff; }
.md-toolbar {
  display: flex; flex-wrap: wrap; gap: 5px;
  padding: 8px 10px; border-bottom: 1px solid var(--border);
  background: #faf8f5;
}
.md-tool {
  min-width: 32px; padding: 5px 9px; font-size: 13px; line-height: 1.2;
  border: 1px solid var(--border); background: #fff; color: #555;
  border-radius: 7px; cursor: pointer; transition: .12s; font-weight: 600;
}
.md-tool:hover { background: var(--primary); color: #fff; border-color: var(--primary); }
.md-tool:active { transform: scale(.94); }

/* 分栏主体：左编辑 + 右预览 */
.md-editor-body {
  display: flex; min-height: 160px;
}
.md-editor-pane {
  flex: 1; display: flex; flex-direction: column; min-height: inherit;
  overflow: hidden;
}
.md-editor-input textarea {
  width: 100%; height: 100%; min-height: 150px;
  border: none; padding: 12px 14px;
  font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
  font-size: 14px; line-height: 1.7; color: var(--ink);
  resize: vertical; outline: none; background: #fefefe;
  box-sizing: border-box; tab-size: 2;
}
.md-editor-preview {
  border-left: 1px solid var(--border);
  background: #fdfcfa; overflow-y: auto;
}
.md-preview-body {
  padding: 12px 16px; font-size: 15px; line-height: 1.85;
  color: var(--ink);
  word-wrap: break-word; overflow-wrap: break-word;
}
.md-empty-hint {
  display: block; text-align: center;
  color: #ccc; padding: 40px 0; font-size: 14px;
}

/* 评论区的编辑器可以紧凑些 */
.comment-form .md-editor-body { min-height: 120px; }
.comment-form .md-editor-input textarea { min-height: 110px; }
.comment-form .md-toolbar { padding: 6px 8px; }

/* 二级详情页 */
.detail-page { max-width: 820px; margin: 18px auto; padding: 0 18px; }
.detail-card-page {
  background: var(--card); border-radius: 16px; padding: 28px 30px;
  box-shadow: 0 1px 4px rgba(0,0,0,.06);
}
.detail-head { display: flex; align-items: flex-start; gap: 12px; justify-content: space-between; margin-bottom: 10px; }
.detail-title { font-family: var(--serif); font-size: 26px; line-height: 1.4; margin: 0; flex: 1; }
.btn-share {
  flex: none; margin-top: 2px;
  display: inline-flex; align-items: center; gap: 4px;
  padding: 7px 14px; border: 1px solid var(--border); border-radius: 999px;
  background: var(--card); color: var(--primary); cursor: pointer;
  font-size: 14px; font-weight: 600; white-space: nowrap;
  transition: background .15s, border-color .15s;
}
.btn-share:hover { background: var(--primary); border-color: var(--primary); color: #fff; }
.detail-meta .src { color: var(--muted); }
.detail-meta .time { color: #b3a89a; font-size: 12px; }
.detail-meta .who { font-size: 13px; color: var(--ink); }

/* 渲染后的 Markdown 内容（帖子正文 / 白话 / 评论通用） */
.md { font-size: 15px; line-height: 1.85; color: var(--ink); word-break: break-word; }
.md > *:first-child { margin-top: 0; }
.md > *:last-child { margin-bottom: 0; }
.md h1, .md h2, .md h3, .md h4 { font-family: var(--serif); line-height: 1.4; margin: .9em 0 .5em; }
.md h1 { font-size: 22px; } .md h2 { font-size: 19px; } .md h3 { font-size: 17px; }
.md p { margin: .6em 0; }
.md ul, .md ol { padding-left: 1.5em; margin: .5em 0; }
.md li { margin: .3em 0; }
.md code { background: #f1ece1; padding: .12em .4em; border-radius: 4px; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .9em; }
.md pre { background: #2b2622; color: #f4f1ea; padding: 12px 14px; border-radius: 8px; overflow: auto; }
.md pre code { background: transparent; color: inherit; padding: 0; }
.md blockquote { border-left: 4px solid var(--primary); margin: .6em 0; padding: .2em 1em; color: var(--muted); background: #fbf7ee; }
.md a { color: var(--primary); text-decoration: underline; }
.md img { max-width: 100%; border-radius: 8px; margin: .4em 0; }
.md table { border-collapse: collapse; margin: .6em 0; }
.md th, .md td { border: 1px solid var(--border); padding: 6px 10px; }

/* 评论区 */
.comments { max-width: 820px; margin: 16px auto 0; padding: 22px 18px 0; }
.comments-title { font-family: var(--serif); font-size: 18px; margin: 0 0 14px; }
.comments-title span { color: var(--primary); }
.comment-form { background: #fff; border-radius: 14px; padding: 16px; box-shadow: 0 1px 4px rgba(0,0,0,.06); }
.comment-form .cmt-author {
  width: 260px; max-width: 100%; border: 1px solid var(--border); border-radius: 10px;
  padding: 9px 12px; font-size: 14px; font-family: inherit; outline: none; background: #fcfbf8;
}
.comment-form .cmt-author:focus { border-color: var(--primary); background: #fff; }
.comment-form .cmt-content {
  width: 100%; border: 1px solid var(--border); border-radius: 10px; margin-top: 10px;
  padding: 10px 12px; font-size: 14px; font-family: inherit; outline: none; resize: vertical; background: #fcfbf8;
}
.comment-form .cmt-content:focus { border-color: var(--primary); background: #fff; }
.cmt-actions { display: flex; justify-content: flex-end; align-items: center; gap: 10px; margin-top: 10px; }
.cmt-actions .form-msg { margin: 0; margin-right: auto; }
.comment-list { list-style: none; padding: 0; margin: 18px 0 0; }
.comment { background: #fff; border-radius: 12px; padding: 14px 16px; margin-bottom: 12px; box-shadow: 0 1px 3px rgba(0,0,0,.05); }
.cmt-head { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.cmt-name { color: var(--ink); font-weight: 600; }
.cmt-body { font-size: 14.5px; line-height: 1.7; }
.cmt-empty { color: var(--muted); text-align: center; padding: 22px; }

/* ============ 书籍目录页 ============ */
.book-page {
  display: flex; gap: 0; align-items: flex-start;
  max-width: 1080px; margin: 0 auto; padding: 18px 14px 40px;
}

/* ── 左侧粘性导航栏 ── */
.book-sidebar {
  flex: none; width: 180px;
  position: sticky; top: calc(var(--topbar-h) + 4px);
  background: #fff; border: 1px solid var(--border); border-radius: 16px;
  padding: 18px 12px 14px; margin-right: 20px;
  box-shadow: 0 2px 10px rgba(0,0,0,.05);
}
.sidebar-title {
  font-size: 13px; font-weight: 700; color: var(--muted);
  text-transform: uppercase; letter-spacing: .5px;
  margin-bottom: 10px; padding-left: 4px;
}
.sidebar-nav { display: flex; flex-direction: column; gap: 2px; }
.sidebar-link {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 10px; border-radius: 10px;
  text-decoration: none; font-size: 14px;
  color: #555; transition: all .15s;
  cursor: pointer;
}
.sidebar-link:hover { background: #f5f0e8; color: var(--primary); }
.sidebar-link.active {
  background: linear-gradient(135deg, #fdf6ed, #fbeae7);
  color: var(--primary); font-weight: 600;
  box-shadow: inset 0 0 0 1px rgba(200,120,80,.15);
}
.sidebar-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: #ccc; flex: none; transition: background .15s;
}
.sidebar-link:hover .sidebar-dot,
.sidebar-link.active .sidebar-dot {
  background: var(--primary);
}
.sidebar-label { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-badge {
  flex: none; font-size: 11px; font-weight: 700;
  background: #f0ece4; color: #888; border-radius: 99px;
  padding: 1px 7px; line-height: 1.5;
}
.sidebar-link.active .sidebar-badge {
  background: var(--primary); color: #fff;
}

/* ── 右侧内容区 ── */
.book-content { flex: 1; min-width: 0; }
.book-head {
  display: flex; gap: 18px; align-items: flex-start;
  background: #fff; border: 1px solid var(--border); border-radius: 16px;
  padding: 22px; margin-bottom: 22px; box-shadow: 0 2px 10px rgba(0,0,0,.05);
}
.book-cover {
  flex: none; width: 88px; height: 120px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-family: var(--serif); font-size: 40px; font-weight: 700;
  box-shadow: 0 4px 14px rgba(0,0,0,.18);
}
.book-meta { flex: 1; min-width: 0; }
.book-title { font-family: var(--serif); font-size: 28px; margin: 0 0 8px; line-height: 1.2; }
.book-sub { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.book-author { font-size: 14px; color: var(--muted); }
.book-count { font-size: 13px; color: var(--primary); font-weight: 600; }
.book-intro { font-size: 14px; line-height: 1.75; color: #555; margin: 0 0 14px; }
.book-search {
  width: 100%; border: 1px solid var(--border); border-radius: 10px; padding: 10px 14px;
  font-size: 14px; font-family: inherit; outline: none; background: #fcfbf8;
}
.book-search:focus { border-color: var(--primary); background: #fff; }

.book-body { }
.toc-section { margin-bottom: 26px; scroll-margin-top: calc(var(--topbar-h) + 16px); }
.toc-sec-title {
  font-family: var(--serif); font-size: 19px; margin: 0 0 12px; color: var(--ink);
  display: flex; align-items: center; gap: 9px; padding-bottom: 8px;
  border-bottom: 2px solid var(--border);
}
.toc-sec-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--primary); flex: none; }
.toc-sec-count { font-size: 12px; color: var(--muted); font-weight: 400; font-family: inherit; }
.toc-list { list-style: none; margin: 0; padding: 0; }
.toc-item { border-bottom: 1px solid #f0ece4; }
.toc-item:last-child { border-bottom: none; }
.toc-link {
  display: flex; flex-direction: column; gap: 3px; padding: 12px 8px;
  text-decoration: none; color: inherit; border-radius: 8px; transition: background .12s;
}
.toc-link:hover { background: #f7f3ec; }
.toc-name { font-size: 16px; font-weight: 600; color: var(--ink); font-family: var(--serif); }
.toc-excerpt { font-size: 13px; color: var(--muted); line-height: 1.5; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 1; -webkit-box-orient: vertical; }

@media (max-width: 768px) {
  .book-page { flex-direction: column; }
  .book-sidebar {
    width: 100%; position: static; margin-right: 0; margin-bottom: 16px;
    padding: 12px 14px;
  }
  .sidebar-nav {
    flex-direction: row; flex-wrap: wrap; gap: 6px;
  }
  .sidebar-link { padding: 7px 12px; font-size: 13px; border-radius: 99px; background: #f8f4ef; }
  .sidebar-link:hover,
  .sidebar-link.active { background: var(--primary); color: #fff; }
  .sidebar-dot, .sidebar-badge { display: none; }
}
@media (max-width: 560px) {
  .book-head { flex-direction: column; align-items: center; text-align: center; }
  .book-sub { justify-content: center; }
  .book-intro { text-align: left; }
}
