:root {
  --paper: #f5f1e8;
  --paper-2: #efe6d3;
  --ink: #2b2118;
  --ink-soft: #5c4a36;
  --maroon: #7a2e1d;
  --maroon-d: #5c1e12;
  --gold: #c9a96e;
  --gold-d: #b08d4f;
  --green: #2e7d32;
  --amber: #b8860b;
  --red: #c62828;
  --line: #e0d4ba;
  --card: #fffdf8;
  --shadow: 0 4px 18px rgba(92, 30, 18, 0.10);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: "Noto Serif CJK SC", "Songti SC", "Source Han Serif SC", "STSong", serif;
  line-height: 1.7;
}

/* ===== 顶栏 ===== */
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 14px 24px;
  background: linear-gradient(135deg, var(--maroon), var(--maroon-d));
  color: #f3e9d8;
  box-shadow: 0 2px 10px rgba(0,0,0,0.18);
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 14px; }
.seal {
  width: 46px; height: 46px;
  display: grid; place-items: center;
  background: #f3e9d8;
  color: var(--maroon-d);
  font-size: 26px; font-weight: 700;
  border-radius: 8px;
  box-shadow: inset 0 0 0 2px var(--gold);
}
.brand-text h1 { margin: 0; font-size: 21px; letter-spacing: 3px; }
.brand-text p { margin: 2px 0 0; font-size: 12.5px; opacity: 0.8; }

.search-wrap {
  position: relative;
  flex: 1 1 320px;
  max-width: 560px;
  display: flex;
  align-items: center;
}
.search-icon { position: absolute; left: 14px; color: var(--maroon); opacity: 0.7; }
#search {
  width: 100%;
  padding: 11px 38px 11px 42px;
  border: none;
  border-radius: 24px;
  font-size: 15px;
  font-family: inherit;
  background: #fbf7ef;
  color: var(--ink);
  outline: none;
  box-shadow: inset 0 0 0 1px var(--gold);
}
#search:focus { box-shadow: inset 0 0 0 2px var(--gold-d); }
.clear-btn {
  position: absolute; right: 10px;
  border: none; background: transparent;
  font-size: 22px; color: var(--ink-soft); cursor: pointer;
  line-height: 1;
}
.result-count {
  font-size: 13px; color: #f3e9d8;
  white-space: nowrap; opacity: 0.9;
}

/* ===== 布局 ===== */
.layout {
  display: grid;
  grid-template-columns: 248px 1fr;
  gap: 0;
  max-width: 1320px;
  margin: 0 auto;
  align-items: start;
}

/* ===== 侧栏 ===== */
.sidebar {
  position: sticky;
  top: 76px;
  align-self: start;
  max-height: calc(100vh - 90px);
  overflow-y: auto;
  padding: 18px 12px 40px 16px;
}
.sidebar h3 {
  font-size: 13px; color: var(--maroon);
  margin: 6px 8px 10px; letter-spacing: 2px;
}
.cat-btn {
  display: flex; align-items: center; justify-content: space-between;
  width: 100%;
  padding: 9px 12px;
  margin-bottom: 4px;
  border: none;
  background: transparent;
  border-radius: 8px;
  font-family: inherit;
  font-size: 14.5px;
  color: var(--ink);
  cursor: pointer;
  text-align: left;
  transition: background 0.15s;
}
.cat-btn:hover { background: var(--paper-2); }
.cat-btn.active { background: var(--maroon); color: #f3e9d8; }
.cat-btn .cnt {
  font-size: 12px;
  color: var(--maroon);
  background: var(--paper-2);
  border-radius: 10px;
  padding: 1px 8px;
}
.cat-btn.active .cnt { background: rgba(255,255,255,0.2); color: #f3e9d8; }
.cat-btn .miss { color: var(--red); }

/* ===== 内容区 ===== */
.content { padding: 22px 26px 60px; min-width: 0; }

.cat-section { margin-bottom: 38px; }
.cat-head {
  display: flex; align-items: baseline; gap: 12px;
  border-bottom: 3px double var(--gold);
  padding-bottom: 8px; margin-bottom: 16px;
}
.cat-head h2 { margin: 0; color: var(--maroon); font-size: 22px; letter-spacing: 2px; }
.cat-head .sub { color: var(--ink-soft); font-size: 13px; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 16px;
}

/* ===== 喝形卡片 ===== */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  cursor: pointer;
  display: flex; flex-direction: column;
  transition: transform 0.18s, box-shadow 0.18s, border-color 0.18s;
}
.card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow);
  border-color: var(--gold-d);
}
.card-img {
  height: 150px;
  background: #15110d;
  display: grid; place-items: center;
  overflow: hidden;
}
.card-img img { width: 100%; height: 100%; object-fit: contain; }
.card-img .noimg {
  color: #9a8f7d; font-size: 13px;
}
.card-body { padding: 10px 12px 12px; }
.card-name { font-size: 16px; font-weight: 700; color: var(--maroon-d); }
.card-poem {
  font-size: 12.5px; color: var(--ink-soft);
  margin-top: 4px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden;
}
.card-foot {
  display: flex; align-items: center; justify-content: space-between;
  margin-top: 8px; font-size: 11.5px; color: #977;
}
.badge {
  font-size: 11px; padding: 1px 8px; border-radius: 10px;
}
.badge.high { background: #e0f2e0; color: var(--green); }
.badge.mid { background: #fff4d6; color: var(--amber); }
.badge.low { background: #fde0e0; color: var(--red); }
.badge.none { background: #eee; color: #999; }

/* ===== 对比表 ===== */
.comp-table {
  width: 100%; border-collapse: collapse; margin: 10px 0 18px;
  font-size: 13px; background: #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}
.comp-table th { background: var(--maroon); color: #f3e9d8; padding: 7px 10px; text-align: left; }
.comp-table td { padding: 7px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.comp-table tr:nth-child(even) td { background: #faf6ed; }

/* ===== 分类论述文档 ===== */
.cat-doc {
  background: linear-gradient(180deg, #fbf6ea, #f6efe0);
  border: 1px solid var(--line);
  border-left: 5px solid var(--maroon);
  border-radius: 10px;
  padding: 18px 24px 22px;
  margin: 4px 0 22px;
  box-shadow: var(--shadow);
}
.cat-doc h3 {
  color: var(--maroon); font-size: 18px; letter-spacing: 1px;
  margin: 20px 0 8px; padding-bottom: 5px;
  border-bottom: 1px solid var(--gold);
}
.cat-doc h3:first-child { margin-top: 0; }
.cat-doc h4 {
  color: var(--maroon-d); font-size: 15.5px;
  margin: 16px 0 6px; letter-spacing: 1px;
}
.cat-doc p { margin: 8px 0; color: var(--ink); }
.cat-doc ul {
  margin: 8px 0 10px; padding-left: 22px;
}
.cat-doc li { margin: 4px 0; color: var(--ink); }
.cat-doc blockquote {
  margin: 12px 0; padding: 10px 16px;
  background: rgba(122,46,29,0.05);
  border-left: 3px solid var(--gold-d);
  color: var(--ink-soft); font-style: italic;
  border-radius: 0 6px 6px 0;
}
.cat-doc blockquote + blockquote { margin-top: -6px; }
.doc-table {
  width: 100%; border-collapse: collapse; margin: 10px 0 16px;
  font-size: 13px; background: #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
  table-layout: fixed;
}
.doc-table th {
  background: var(--maroon-d); color: #f3e9d8;
  padding: 7px 10px; text-align: left; font-weight: 600;
}
.doc-table td {
  padding: 7px 10px; border-bottom: 1px solid var(--line);
  vertical-align: top; word-break: break-word;
}
.doc-table tr:nth-child(even) td { background: #faf6ed; }
.doc-hint {
  font-size: 13px; color: var(--ink-soft);
  margin: 0 0 14px; padding: 8px 12px;
  background: var(--paper-2); border-radius: 6px;
  border: 1px dashed var(--gold-d);
}

/* ===== 弹窗 ===== */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(30, 18, 10, 0.55);
  display: grid; place-items: center;
  z-index: 50; padding: 20px;
}
.modal-backdrop[hidden] { display: none; }
.modal {
  position: relative;
  background: var(--paper);
  border-radius: 14px;
  max-width: 820px; width: 100%;
  max-height: 88vh; overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,0.4);
  border: 1px solid var(--gold);
}
.modal-close {
  position: absolute; top: 12px; right: 14px;
  width: 34px; height: 34px; border-radius: 50%;
  border: none; background: var(--maroon); color: #fff;
  font-size: 22px; cursor: pointer; line-height: 1;
}
.modal-body { padding: 26px 30px 34px; }
.modal h2 { margin: 0 0 4px; color: var(--maroon); font-size: 26px; letter-spacing: 2px; }
.modal .chips { display: flex; gap: 8px; flex-wrap: wrap; margin: 8px 0 16px; }
.chip { font-size: 12px; background: var(--paper-2); color: var(--maroon-d); padding: 3px 10px; border-radius: 12px; }

.gallery {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px;
  margin: 14px 0;
}
.gallery figure {
  margin: 0; border: 1px solid var(--line); border-radius: 8px; overflow: hidden;
  background: #15110d;
}
.gallery img { width: 100%; display: block; max-height: 280px; object-fit: contain; background: #15110d; }
.gallery figcaption { padding: 7px 9px; font-size: 12px; background: #fff; color: var(--ink-soft); }
.gallery .conf { float: right; font-weight: 700; }

.fields { margin-top: 10px; }
.field-row { display: grid; grid-template-columns: 84px 1fr; gap: 10px; padding: 8px 0; border-bottom: 1px dashed var(--line); }
.field-row .k { color: var(--maroon); font-weight: 700; font-size: 14px; }
.field-row .v { font-size: 14.5px; }

.empty { text-align: center; color: var(--ink-soft); padding: 60px 20px; font-size: 16px; }

.foot {
  text-align: center; color: var(--ink-soft);
  font-size: 12.5px; padding: 18px; border-top: 1px solid var(--line);
}

/* ===== 基础形峦总论入口（侧栏置顶） ===== */
.ref-btn {
  background: linear-gradient(135deg, #fbf3e2, #f3e6cb);
  border: 1px solid var(--gold-d) !important;
  color: var(--maroon-d) !important;
  font-weight: 700;
}
.ref-btn.active {
  background: linear-gradient(135deg, var(--maroon), var(--maroon-d));
  color: #f3e9d8 !important;
  border-color: var(--maroon) !important;
}

/* ===== 基础形峦总论页 ===== */
.ref-page { max-width: 960px; margin: 0 auto; }
.ref-head { margin-bottom: 18px; }
.ref-head h2 { color: var(--maroon); margin: 0 0 6px; font-size: 24px; }
.ref-head .sub { color: var(--ink-soft); font-size: 14px; margin: 0; background: #fffdf8; border-left: 3px solid var(--gold); padding: 10px 14px; border-radius: 0 6px 6px 0; }

.ref-section { background: #fffdf8; border: 1px solid var(--line); border-radius: 10px; padding: 18px 22px; margin-bottom: 18px; box-shadow: var(--shadow); }
.ref-title { color: var(--maroon); font-size: 18px; margin: 0 0 12px; border-bottom: 2px solid var(--gold); padding-bottom: 6px; display: inline-block; }

/* 常见形峦列表 */
.common-list { list-style: none; margin: 8px 0 0; padding: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 10px 18px; }
.common-item { display: flex; gap: 10px; align-items: baseline; padding: 8px 10px; border: 1px solid var(--line); border-radius: 7px; background: #faf6ed; }
.common-item.linked { cursor: pointer; border-color: var(--gold-d); transition: transform .08s, box-shadow .12s; }
.common-item.linked:hover { transform: translateY(-1px); box-shadow: 0 3px 10px rgba(92,30,18,.16); background: #fff; }
.common-item .ct { font-weight: 700; color: var(--maroon); flex: 0 0 auto; }
.common-item .cd { font-size: 13px; color: var(--ink-soft); flex: 1 1 auto; }
.common-item .clink, .ref-result .clink { color: var(--gold-d); font-size: 12px; font-weight: 700; flex: 0 0 auto; }

/* 搜索中的基础/常见形结果 */
.ref-results { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 18px; }
.ref-result { padding: 9px 12px; border: 1px solid var(--line); border-radius: 7px; background: #faf6ed; }
.ref-result.linked { cursor: pointer; border-color: var(--gold-d); }
.ref-result.linked:hover { background: #fff; box-shadow: 0 3px 10px rgba(92,30,18,.16); }
.rr-head { display: flex; align-items: center; gap: 8px; }
.rr-term { font-weight: 700; color: var(--maroon); }
.rr-desc { font-size: 13px; color: var(--ink-soft); margin-top: 3px; }

/* ===== 响应式 ===== */
@media (max-width: 820px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar {
    position: static; max-height: none;
    display: flex; flex-wrap: wrap; gap: 6px;
    padding: 12px 14px;
    border-bottom: 1px solid var(--line);
  }
  .sidebar h3 { width: 100%; }
  .cat-btn { width: auto; }
  .content { padding: 16px 14px 50px; }
  .common-list, .ref-results { grid-template-columns: 1fr; }
}
