/* ============================================================
   诸子百家典藏 · 样式主文件
   视觉语言：宣纸 · 玄墨 · 朱砂 · 青铜
   ============================================================ */

:root {
  /* 纸墨主色 */
  --paper: #f7f1e3;
  --paper-2: #fdfaf3;
  --paper-3: #efe7d4;
  --ink: #2b2620;
  --ink-2: #554c40;
  --ink-3: #7d7161;
  --line: #ddd0b4;
  --line-2: #c8b995;

  /* 朱砂 / 青铜 / 石青 / 赭石 */
  --zhu: #a03028;
  --zhu-2: #c2483c;
  --qing: #4e6e5a;
  --shi: #3b5a78;
  --zhe: #b8862f;

  /* 学派色 */
  --c-ru: #8c4a2f;
  --c-dao: #3f6b52;
  --c-mo: #4a5a78;
  --c-fa: #7a3b52;
  --c-bing: #8a6a2e;
  --c-ming: #5f4b7a;
  --c-zong: #2f6b7a;
  --c-nong: #4f7038;
  --c-za: #6b6255;
  --c-fo: #7a5a86;

  --serif: "Songti SC", "STSong", "Source Han Serif SC", "Noto Serif SC", "SimSun", serif;
  --kai: "STKaiti", "KaiTi", "Kaiti SC", "Kai", var(--serif);

  --shadow: 0 2px 10px rgba(58, 45, 25, .07);
  --shadow-lg: 0 8px 30px rgba(58, 45, 25, .13);
  --r: 3px;
  --maxw: 1180px;
}

* { box-sizing: border-box; }

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

html, body { max-width: 100%; }
body:not(.vertical-mode) { overflow-x: hidden; }

body {
  margin: 0;
  font-family: var(--serif);
  color: var(--ink);
  background-color: var(--paper);
  background-image:
    radial-gradient(circle at 18% 12%, rgba(184, 134, 47, .07), transparent 45%),
    radial-gradient(circle at 82% 84%, rgba(160, 48, 40, .06), transparent 45%),
    url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='120' height='120'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='.8' numOctaves='3'/><feColorMatrix values='0 0 0 0 .45  0 0 0 0 .38  0 0 0 0 .26  0 0 0 .05 0'/></filter><rect width='120' height='120' filter='url(%23n)'/></svg>");
  line-height: 1.9;
  min-height: 100vh;
  padding-bottom: env(safe-area-inset-bottom);
}

img { max-width: 100%; }
a { color: var(--zhu); text-decoration: none; }
a:hover { color: var(--zhu-2); text-decoration: underline; }

/* ---------------- 顶栏 ---------------- */
.topbar {
  position: sticky; top: 0; z-index: 60;
  background: linear-gradient(180deg, rgba(247, 241, 227, .98), rgba(247, 241, 227, .95));
  border-bottom: 1px solid var(--line);
  box-shadow: 0 1px 0 rgba(255, 255, 255, .6) inset;
}
.topbar-in {
  max-width: var(--maxw); margin: 0 auto; padding: 10px 16px;
  display: flex; align-items: center; gap: 18px;
}
.brand { display: flex; align-items: center; gap: 10px; flex: 0 0 auto; }
.brand-seal {
  width: 40px; height: 40px; display: grid; place-items: center;
  background: var(--zhu); color: #fdf6e6; font-family: var(--kai);
  font-size: 15px; line-height: 1.05; border-radius: 4px; letter-spacing: -1px;
  box-shadow: inset 0 0 0 2px rgba(253, 246, 230, .35), var(--shadow);
  text-align: center; padding: 3px;
}
.brand-name { font-family: var(--kai); font-size: 21px; font-weight: 700; letter-spacing: 3px; color: var(--ink); }
.brand-sub { font-size: 11px; color: var(--ink-3); letter-spacing: 2px; }

.nav { margin-left: auto; display: flex; gap: 4px; flex-wrap: wrap; }
.nav a {
  padding: 6px 11px; color: var(--ink-2); font-size: 15px; letter-spacing: 1px;
  border-radius: var(--r); position: relative;
}
.nav a:hover { color: var(--zhu); text-decoration: none; background: rgba(160, 48, 40, .06); }
.nav a.on { color: var(--zhu); font-weight: 700; }
.nav a.on::after {
  content: ""; position: absolute; left: 11px; right: 11px; bottom: 1px; height: 2px;
  background: var(--zhu); border-radius: 2px;
}

.tools { display: flex; gap: 6px; align-items: center; }
.tbtn {
  border: 1px solid var(--line); background: var(--paper-2); color: var(--ink-2);
  font-family: var(--serif); font-size: 13px; padding: 5px 10px; border-radius: var(--r);
  cursor: pointer; line-height: 1.5; white-space: nowrap;
}
.tbtn:hover { border-color: var(--zhe); color: var(--zhu); }
.tbtn.on { background: var(--zhu); color: #fff; border-color: var(--zhu); }
.zhuan-icon {
  font-family: "SimSun", "STSong", "STCaiyun", serif;
  font-weight: bold;
  font-size: 22px;
  margin-right: 6px;
}

/* ---------------- 布局 ---------------- */
.wrap { max-width: var(--maxw); margin: 0 auto; padding: 24px 16px 40px; }
.wrap-narrow { max-width: 860px; }

.section { margin-bottom: 34px; }
.sec-head { display: flex; align-items: baseline; gap: 12px; margin: 0 0 14px; flex-wrap: wrap; }
.sec-title {
  font-family: var(--kai); font-size: 22px; font-weight: 700; letter-spacing: 3px; margin: 0;
  position: relative; padding-left: 14px;
}
.sec-title::before {
  content: ""; position: absolute; left: 0; top: 6px; bottom: 6px; width: 4px;
  background: var(--zhu); border-radius: 2px;
}
.sec-more { margin-left: auto; font-size: 13px; color: var(--ink-3); }

/* ---------------- 首页 Hero ---------------- */
.hero {
  position: relative; overflow: hidden; border-radius: 6px;
  background:
    linear-gradient(115deg, rgba(43, 38, 32, .93), rgba(43, 38, 32, .82)),
    url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='400' height='400'><g fill='none' stroke='%23b8862f' stroke-width='1.2' opacity='.5'><path d='M0 40h40v40h40v40h40v40h40v40h40M40 0h40v40h40v40h40v40h40v40h40'/><circle cx='200' cy='200' r='90'/><circle cx='200' cy='200' r='60'/><circle cx='200' cy='200' r='30'/></g></svg>");
  background-size: auto, 400px;
  color: #f3e8d2; padding: 44px 34px; margin-bottom: 26px; box-shadow: var(--shadow-lg);
}
.hero::after {
  content: ""; position: absolute; right: -60px; bottom: -80px; width: 320px; height: 320px;
  background: radial-gradient(circle at 40% 40%, rgba(184, 134, 47, .3), transparent 62%);
  border-radius: 50%; pointer-events: none;
}
.hero h1 {
  font-family: var(--kai); font-size: 44px; letter-spacing: 12px; margin: 0 0 6px; font-weight: 700;
  text-shadow: 0 2px 14px rgba(0, 0, 0, .5);
}
.hero .sub { font-size: 14px; letter-spacing: 5px; color: #d9c9a8; margin-bottom: 18px; }
.hero p.desc { max-width: 640px; font-size: 15px; line-height: 2; color: #e6d9bd; margin: 0 0 20px; }
.hero-btns { display: flex; gap: 12px; flex-wrap: wrap; position: relative; z-index: 2; }
.hbtn {
  padding: 10px 22px; border: 1px solid rgba(243, 232, 210, .5); color: #f3e8d2;
  font-family: var(--kai); font-size: 16px; letter-spacing: 3px; border-radius: var(--r);
  background: rgba(160, 48, 40, .28); backdrop-filter: blur(3px);
}
.hbtn:hover { background: var(--zhu); color: #fff; text-decoration: none; border-color: var(--zhu); }
.hbtn.ghost { background: rgba(255, 255, 255, .06); }

.stat-row { display: flex; gap: 26px; flex-wrap: wrap; margin-top: 24px; position: relative; z-index: 2; }
.stat b { font-size: 26px; font-family: var(--kai); color: #e8c87a; display: block; line-height: 1.2; }
.stat span { font-size: 12px; color: #bfae8c; letter-spacing: 2px; }

/* ---------------- 通用卡片/网格 ---------------- */
.grid { display: grid; gap: 14px; }
.g2 { grid-template-columns: repeat(2, 1fr); }
.g3 { grid-template-columns: repeat(3, 1fr); }
.g4 { grid-template-columns: repeat(4, 1fr); }
.grid-auto { grid-template-columns: repeat(auto-fill, minmax(215px, 1fr)); }

.card {
  background: linear-gradient(180deg, var(--paper-2), var(--paper-3));
  border: 1px solid var(--line); border-radius: var(--r); padding: 16px;
  box-shadow: var(--shadow); position: relative; transition: transform .18s, box-shadow .18s;
}
.card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); border-color: var(--line-2); }

/* 典籍卡片 */
.bk {
  display: block; background: linear-gradient(180deg, var(--paper-2), var(--paper-3));
  border: 1px solid var(--line); border-left: 4px solid var(--q, var(--zhe));
  border-radius: var(--r); padding: 14px 16px; box-shadow: var(--shadow);
  position: relative; overflow: hidden; transition: transform .18s, box-shadow .18s;
}
.bk:hover { text-decoration: none; transform: translateY(-3px); box-shadow: var(--shadow-lg); }
.bk::after {
  content: ""; position: absolute; right: -22px; top: -22px; width: 74px; height: 74px;
  border: 1px solid rgba(184, 134, 47, .3); border-radius: 50%;
}
.bk-t {
  font-family: var(--kai); font-size: 21px; font-weight: 700; letter-spacing: 2px;
  color: var(--ink); margin-bottom: 3px; display: flex; align-items: center; gap: 8px;
}
.bk-m { font-size: 12.5px; color: var(--ink-3); margin-bottom: 8px; letter-spacing: .5px; }
.bk-d { font-size: 13px; color: var(--ink-2); line-height: 1.75; display: -webkit-box;
  -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.bk-f { margin-top: 10px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; font-size: 11.5px; color: var(--ink-3); }

.tag {
  display: inline-block; padding: 2px 8px; border-radius: 2px; font-size: 11.5px;
  border: 1px solid currentColor; letter-spacing: 1px; line-height: 1.6;
}
.tag-ru { color: var(--c-ru); } .tag-dao { color: var(--c-dao); } .tag-mo { color: var(--c-mo); }
.tag-fa { color: var(--c-fa); } .tag-bing { color: var(--c-bing); } .tag-ming { color: var(--c-ming); }
.tag-zong { color: var(--c-zong); } .tag-nong { color: var(--c-nong); } .tag-za { color: var(--c-za); }
.tag-fo { color: var(--c-fo); }

.pill {
  display: inline-block; padding: 2px 9px; background: rgba(184, 134, 47, .14); color: #8a6318;
  border-radius: 2px; font-size: 11.5px;
}

/* 名句卡 */
.qcard {
  background: linear-gradient(180deg, var(--paper-2), var(--paper-3));
  border: 1px solid var(--line); border-radius: var(--r); padding: 18px 18px 14px;
  box-shadow: var(--shadow); position: relative; display: flex; flex-direction: column;
}
.qcard::before {
  content: "“"; position: absolute; left: 8px; top: -2px; font-size: 42px;
  font-family: var(--kai); color: rgba(160, 48, 40, .16); line-height: 1;
}
.qtext { font-family: var(--kai); font-size: 19px; line-height: 1.95; color: var(--ink); position: relative; z-index: 1; }
.qsrc { margin-top: auto; padding-top: 10px; font-size: 12.5px; color: var(--ink-3); }
.qops { display: flex; gap: 8px; margin-top: 8px; opacity: .55; transition: opacity .2s; }
.qcard:hover .qops { opacity: 1; }
.qop { font-size: 12px; color: var(--ink-3); cursor: pointer; }
.qop:hover { color: var(--zhu); }
.qop.on { color: var(--zhu); }

/* 抽签卡 */
.draw {
  border: 1px solid var(--line-2); border-radius: 4px; padding: 30px 26px; text-align: center;
  background:
    repeating-linear-gradient(90deg, rgba(184, 134, 47, .05) 0 2px, transparent 2px 14px),
    linear-gradient(180deg, var(--paper-2), var(--paper-3));
  box-shadow: var(--shadow); position: relative;
}
.draw-seal {
  position: absolute; top: 12px; right: 14px; width: 40px; height: 40px; color: var(--zhu);
  border: 2px solid var(--zhu); border-radius: 3px; display: grid; place-items: center;
  font-family: var(--kai); font-size: 12px; line-height: 1.1; opacity: .55; transform: rotate(-6deg);
}
.draw-text { font-family: var(--kai); font-size: 26px; line-height: 2.1; color: var(--ink); margin: 6px 0 12px; }
.draw-src { font-size: 13px; color: var(--ink-3); }

/* ---------------- 学派 ---------------- */
.school-box {
  border: 1px solid var(--line); border-radius: var(--r); padding: 16px; background: var(--paper-2);
  box-shadow: var(--shadow); position: relative; overflow: hidden;
}
.school-box::before {
  content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 5px; background: var(--sc);
}
.sc-name { font-family: var(--kai); font-size: 20px; font-weight: 700; letter-spacing: 2px; margin-bottom: 2px; }
.sc-desc { font-size: 13px; color: var(--ink-3); margin-bottom: 10px; }
.sc-list { display: flex; flex-wrap: wrap; gap: 7px; }

/* ---------------- 阅读器 ---------------- */
.read-shell { display: flex; gap: 22px; align-items: flex-start; }
.side {
  width: 250px; flex: 0 0 250px; position: sticky; top: 74px; max-height: calc(100vh - 100px);
  overflow: auto; border: 1px solid var(--line); border-radius: var(--r);
  background: var(--paper-2); box-shadow: var(--shadow); padding: 10px 0;
}
.side h4 { margin: 0 0 6px; padding: 0 14px; font-family: var(--kai); font-size: 16px; letter-spacing: 2px; }
.side a {
  display: block; padding: 6px 14px; font-size: 14px; color: var(--ink-2); border-left: 3px solid transparent;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.side a:hover { background: rgba(160, 48, 40, .06); color: var(--zhu); text-decoration: none; }
.side a.on { border-left-color: var(--zhu); color: var(--zhu); font-weight: 700; background: rgba(160, 48, 40, .05); }

.read-main {
  flex: 1 1 auto; min-width: 0;
  background:
    repeating-linear-gradient(0deg, transparent 0 29px, rgba(184, 134, 47, .07) 29px 30px),
    var(--paper-2);
  border: 1px solid var(--line); border-radius: var(--r); padding: 34px 40px;
  box-shadow: var(--shadow); position: relative;
}
.read-main::before {
  content: ""; position: absolute; left: 22px; top: 0; bottom: 0; width: 1px; background: rgba(200, 185, 149, .55);
}
.ch-title { font-family: var(--kai); font-size: 27px; letter-spacing: 4px; margin: 0 0 4px; color: var(--ink); }
.ch-sub { font-size: 12.5px; color: var(--ink-3); margin-bottom: 20px; letter-spacing: 1px; }
.para { text-indent: 2em; margin: 0 0 .9em; line-height: 2.05; font-size: 18px; text-align: justify; }
.para-s { margin-bottom: 1.4em; }

/* 竖排模式 */
.vertical-mode .read-main { writing-mode: vertical-rl; max-height: 76vh; overflow-x: auto; padding: 30px 34px; }
.vertical-mode .para { text-indent: 0; line-height: 2.2; }
.vertical-mode .ch-title { writing-mode: vertical-rl; margin-left: 14px; }
.para { overflow-wrap: break-word; }

.read-bar {
  display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 12px;
  padding: 8px 12px; background: var(--paper-2); border: 1px solid var(--line); border-radius: var(--r);
}
.read-nav { display: flex; gap: 10px; justify-content: space-between; margin-top: 26px; padding-top: 16px; border-top: 1px dashed var(--line-2); }
.read-nav a { flex: 1; padding: 10px; text-align: center; border: 1px solid var(--line); border-radius: var(--r); font-size: 14px; color: var(--ink-2); background: var(--paper-2); }
.read-nav a:hover { text-decoration: none; border-color: var(--zhe); color: var(--zhu); }
.read-nav a.dis { opacity: .4; pointer-events: none; }

mark { background: rgba(184, 134, 47, .35); color: inherit; padding: 0 1px; border-radius: 2px; }

/* ---------------- 测验 ---------------- */
.quiz-box {
  border: 1px solid var(--line); border-radius: var(--r); padding: 24px; background: var(--paper-2);
  box-shadow: var(--shadow); max-width: 760px; margin: 0 auto;
}
.quiz-q { font-family: var(--kai); font-size: 21px; line-height: 1.9; margin: 6px 0 18px; }
.opt {
  display: block; border: 1px solid var(--line); border-radius: var(--r); padding: 11px 14px;
  margin-bottom: 10px; cursor: pointer; background: #fff; font-size: 15.5px; transition: .15s;
}
.opt:hover { border-color: var(--zhe); background: #fffdf6; }
.opt.right { border-color: var(--qing); background: rgba(78, 110, 90, .1); color: var(--qing); }
.opt.wrong { border-color: var(--zhu); background: rgba(160, 48, 40, .1); color: var(--zhu); }
.quiz-note { margin-top: 14px; padding: 12px 14px; background: rgba(184, 134, 47, .1); border-left: 3px solid var(--zhe); font-size: 14px; line-height: 1.85; }
.score-line { display: flex; gap: 18px; font-size: 14px; color: var(--ink-2); margin-bottom: 16px; flex-wrap: wrap; }
.score-line b { font-size: 22px; font-family: var(--kai); color: var(--zhu); }

/* ---------------- 时间轴 ---------------- */
.tl { position: relative; padding-left: 26px; }
.tl::before { content: ""; position: absolute; left: 7px; top: 6px; bottom: 6px; width: 2px; background: var(--line-2); }
.tl-item { position: relative; margin-bottom: 22px; }
.tl-item::before {
  content: ""; position: absolute; left: -23px; top: 8px; width: 10px; height: 10px; border-radius: 50%;
  background: var(--zhu); box-shadow: 0 0 0 3px rgba(160, 48, 40, .16);
}
.tl-era { font-family: var(--kai); font-size: 19px; letter-spacing: 3px; margin-bottom: 8px; }
.tl-books { display: flex; flex-wrap: wrap; gap: 8px; }

/* ---------------- 表格/清单 ---------------- */
.fig-card {
  border: 1px solid var(--line); border-radius: var(--r); background: var(--paper-2); padding: 16px;
  box-shadow: var(--shadow); position: relative;
}
.fig-name { font-family: var(--kai); font-size: 24px; letter-spacing: 3px; margin-bottom: 2px; }
.fig-meta { font-size: 12.5px; color: var(--ink-3); margin-bottom: 10px; }
.fig-d { font-size: 13.5px; color: var(--ink-2); line-height: 1.85; }
.fig-q { margin-top: 10px; font-family: var(--kai); font-size: 15px; color: var(--zhu); border-top: 1px dashed var(--line); padding-top: 8px; }

/* ---------------- 表单/筛选 ---------------- */
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; align-items: center; }
.chip {
  padding: 5px 13px; border: 1px solid var(--line); background: var(--paper-2); border-radius: 14px;
  font-size: 13.5px; color: var(--ink-2); cursor: pointer; transition: .15s;
}
.chip:hover { border-color: var(--zhe); }
.chip.on { background: var(--zhu); color: #fff; border-color: var(--zhu); }
input.search, select {
  font-family: var(--serif); font-size: 15px; padding: 9px 12px; border: 1px solid var(--line);
  border-radius: var(--r); background: var(--paper-2); color: var(--ink); outline: none;
}
input.search:focus, select:focus { border-color: var(--zhe); box-shadow: 0 0 0 3px rgba(184, 134, 47, .13); }
input.search { flex: 1 1 220px; }

.empty { text-align: center; padding: 40px 0; color: var(--ink-3); font-size: 14px; }

/* 底部导航（移动） */
.tabbar {
  display: none; position: fixed; left: 0; right: 0; bottom: 0; z-index: 80;
  background: rgba(247, 241, 227, .97); border-top: 1px solid var(--line);
  backdrop-filter: blur(8px); padding: 5px 2px calc(5px + env(safe-area-inset-bottom));
}
.tabbar a { flex: 1; text-align: center; font-size: 11px; color: var(--ink-3); padding: 3px 0; }
.tabbar a i { display: block; font-style: normal; font-size: 19px; line-height: 1.3; font-family: var(--kai); }
.tabbar a.on { color: var(--zhu); }

footer.site {
  border-top: 1px solid var(--line); margin-top: 40px; padding: 22px 16px 26px; text-align: center;
  font-size: 12.5px; color: var(--ink-3); line-height: 2;
}

/* 工具提示 */
.tip {
  position: fixed; left: 50%; bottom: 84px; transform: translateX(-50%);
  background: rgba(43, 38, 32, .92); color: #f3e8d2; padding: 9px 16px; border-radius: 4px;
  font-size: 13.5px; z-index: 200; opacity: 0; pointer-events: none; transition: opacity .25s;
}
.tip.show { opacity: 1; }

/* 返回顶部 */
.totop {
  position: fixed; right: 16px; bottom: 76px; width: 42px; height: 42px; border-radius: 50%;
  background: var(--zhu); color: #fff; display: grid; place-items: center; cursor: pointer;
  box-shadow: var(--shadow-lg); opacity: 0; pointer-events: none; transition: opacity .25s; z-index: 70;
  font-size: 18px; font-family: var(--kai);
}
.totop.show { opacity: .92; pointer-events: auto; }

/* ---------------- 响应式 ---------------- */
@media (max-width: 1024px) {
  .g4 { grid-template-columns: repeat(2, 1fr); }
  .g3 { grid-template-columns: repeat(2, 1fr); }
  .side { width: 200px; flex: 0 0 200px; }
  .read-main { padding: 26px 24px; }
}
@media (max-width: 720px) {
  body { padding-bottom: 104px; }
  .hero { padding: 30px 20px; }
  .hero h1 { font-size: 30px; letter-spacing: 6px; }
  .hero p.desc { font-size: 14px; }
  .topbar-in { padding: 8px 12px; gap: 10px; }
  .brand-sub { display: none; }
  .nav {
    position: fixed; left: 0; right: 0; bottom: 0; margin: 0; z-index: 80; display: flex;
    background: rgba(247, 241, 227, .98); border-top: 1px solid var(--line);
    padding: 4px 2px calc(4px + env(safe-area-inset-bottom)); overflow-x: auto; gap: 0;
    justify-content: space-around;
  }
  .nav::-webkit-scrollbar { display: none; }
  .nav a {
    flex: 0 0 auto; text-align: center; font-size: 11px; padding: 3px 9px; border-radius: 0; min-width: 56px;
  }
  .nav a i { display: block; font-style: normal; font-size: 17px; font-family: var(--kai); line-height: 1.25; }
  .nav a.on::after { display: none; }
  .g2, .g3, .g4 { grid-template-columns: repeat(2, 1fr); }
  .read-shell { display: block; }
  .side {
    width: auto; position: static; max-height: none; margin-bottom: 14px; max-height: 210px;
  }
  .read-main { padding: 22px 18px; }
  .read-main::before { left: 12px; }
  .para { font-size: 17px; }
  .draw-text { font-size: 21px; }
  .wrap { padding: 16px 12px 30px; }
  .tools .tbtn span { display: none; }
}
@media (max-width: 420px) {
  .g2, .g3, .g4, .grid-auto { grid-template-columns: 1fr; }
  .hero h1 { font-size: 26px; letter-spacing: 4px; }
}
