/* ==========================================================================
   喜乐猴 · 版权存证 —— 设计稿样式
   方向：accent-ladder（seed 1196212636）· open plane shell · light
   网格算术：1440 = 230 侧栏 + 32 边距 + [396 名录 + 24 间距 + 726 原件] + 32 边距
   ========================================================================== */

@font-face {
  font-family: "DM Sans";
  src: url("fonts/DMSans-latin.woff2") format("woff2");
  font-weight: 100 900;
  font-display: swap;
}
@font-face {
  font-family: "Serif SC";
  src: url("fonts/NotoSerifSC-subset.woff2") format("woff2");
  font-weight: 200 900;
  font-display: swap;
}
@font-face {
  font-family: "Sans SC";
  src: url("fonts/NotoSansSC-subset.woff2") format("woff2");
  font-weight: 100 900;
  font-display: swap;
}

:root {
  --ground: #f6f6f4;
  --surface: #ffffff;
  --raised: #f0efeb;
  --border: #e5e4df;
  --text: #1a1a1a;
  --muted: #65655f;

  --accent: #b3271e;
  --accent-soft: #fbf1ef;
  --accent-track: #f0d9d5;
  --accent-ink: #6f1a13;

  --serif: "Serif SC", "Songti SC", "STSong", "SimSun", serif;
  --sans: "DM Sans", "Sans SC", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;

  --radius-card: 8px;
  --radius-control: 6px;
  --gap: 24px;
  --pad: 32px;
  --maxw: 1080px; /* 内容最大宽度：屏幕更宽时收拢居中，更窄时自然全宽 */
  --row-h: 52px;
  --ctl-h: 32px;

  --fs-title: 32px;
  --fs-name: 22px;
  --fs-body: 14px;
  --fs-small: 12px;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--ground);
  color: var(--text);
  font: 400 var(--fs-body)/1.5 var(--sans);
  display: flex;
  flex-direction: column;
  height: 100vh;
  -webkit-font-smoothing: antialiased;
}

button, input, select { font: inherit; color: inherit; }
a { color: inherit; text-decoration: none; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  border-radius: var(--radius-control);
}

::selection { background: var(--accent-track); }

.num { font-variant-numeric: tabular-nums; }

/* ---------------------------------------------------------------- topbar */

.top {
  flex: none;
  display: flex;
  align-items: center;
  gap: 14px;
  height: 60px;
  /* 底部分隔线通栏，内容与下方名录区同宽对齐 */
  padding: 0 max(var(--pad), calc((100% - var(--maxw)) / 2));
  border-bottom: 1px solid var(--border);
}

.brand { display: flex; align-items: center; gap: 10px; }

.mark {
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  border: 1.5px solid var(--accent);
  border-radius: 4px;
  color: var(--accent);
  font: 600 14px/1 var(--serif);
  flex: none;
}

.brand-txt b {
  display: block;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.01em;
}
.brand-txt i {
  display: block;
  font-style: normal;
  font-size: 11px;
  color: var(--muted);
  margin-top: 1px;
}

.topnav { display: flex; align-items: center; gap: 24px; margin-left: auto; }
.topnav a {
  font-size: 13.5px;
  color: var(--muted);
  padding: 5px 0;
  border-bottom: 1.5px solid transparent;
}
.topnav a:hover { color: var(--accent); border-color: var(--accent-track); }
.topnav a[aria-current="page"] { color: var(--text); border-color: var(--accent); }

.foot {
  flex: none;
  display: flex;
  flex-wrap: wrap;
  gap: 6px 16px;
  padding: 12px max(var(--pad), calc((100% - var(--maxw)) / 2)) 0;
  border-top: 1px solid var(--border);
  font-size: 11.5px;
  color: var(--muted);
}
.foot b { font-weight: 500; color: var(--text); }

/* ---------------------------------------------------------------- canvas */

.canvas {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
  min-height: 0;
  padding: 20px max(var(--pad), calc((100% - var(--maxw)) / 2)) 14px;
  gap: 18px;
}

.title-row {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--gap);
  flex: none;
}

.title-row h1 {
  margin: 0;
  font: 600 var(--fs-title)/1.15 var(--serif);
  letter-spacing: 0.01em;
}

.title-row p {
  margin: 8px 0 0;
  font-size: 13px;
  color: var(--muted);
}
.title-row p .num { color: var(--text); }

.stamp {
  margin: 0;
  font-size: var(--fs-small);
  color: var(--muted);
  padding-bottom: 3px;
  white-space: nowrap;
}

/* ---------------------------------------------------------------- panes */

.panes {
  display: grid;
  grid-template-columns: minmax(300px, 380px) minmax(0, 1fr);
  gap: var(--gap);
  flex: 1;
  min-height: 0;
}

/* 名录：分类树与条目同框 */

.ledger {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  overflow: hidden;
}

.ledger-head {
  flex: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 12px 10px;
  border-bottom: 1px solid var(--border);
}

.search { position: relative; }
.search input {
  width: 100%;
  height: 32px;
  padding: 0 12px 0 32px;
  border: 1px solid var(--border);
  border-radius: var(--radius-control);
  background: var(--surface);
  font-size: 13.5px;
}
.search input::placeholder { color: #9a9a94; }
.search input:focus {
  outline: 2px solid var(--accent-track);
  outline-offset: 1px;
  border-color: var(--accent);
}
.search .lens {
  position: absolute;
  left: 10px;
  top: 9px;
  width: 15px;
  height: 15px;
  stroke: var(--muted);
  fill: none;
  stroke-width: 1.6;
  pointer-events: none;
}

.filters {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.filters select {
  flex: none;
  height: 26px;
  padding: 0 24px 0 8px;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: var(--surface) url("data:image/svg+xml;charset=utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='9' height='6'%3E%3Cpath d='M0 0l4.5 5L9 0' fill='none' stroke='%2365655f' stroke-width='1.4'/%3E%3C/svg%3E") no-repeat right 8px center;
  appearance: none;
  font-size: 12.5px;
  color: var(--text);
  cursor: pointer;
}

.link-btn {
  flex: none;
  border: 0;
  background: none;
  padding: 2px 4px;
  font-size: 12.5px;
  color: var(--muted);
  cursor: pointer;
  text-underline-offset: 3px;
}
.link-btn:hover { color: var(--accent); text-decoration: underline; }

.hits {
  margin: 0 0 0 auto;
  font-size: 11.5px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.hits b { font-weight: 500; color: var(--text); font-variant-numeric: tabular-nums; }
.hits em { font-style: normal; color: var(--text); }

/* 框内树：节点 + 叶子条目 */

.tree {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 8px 8px 14px;
  scrollbar-width: thin;
  scrollbar-color: #d7d6d0 transparent;
}
.tree::-webkit-scrollbar { width: 7px; }
.tree::-webkit-scrollbar-thumb { background: #d7d6d0; border-radius: 4px; }

.tn-group {
  font-family: var(--serif);
  font-size: 11.5px;
  letter-spacing: 0.08em;
  color: var(--muted);
  padding: 12px 8px 4px;
}
.tn-group:first-child { padding-top: 2px; }

/* 根节点吸顶：分类展开后条目很长，保证随时能一键回到「全部作品」 */
.tree > .tnode:first-child {
  position: sticky;
  top: -8px;
  z-index: 2;
  background: var(--surface);
  height: 32px;
  border-bottom: 1px solid var(--border);
  border-radius: 0;
}
.tree > .tnode:first-child.active { background: var(--accent-soft); }

.tnode {
  display: flex;
  align-items: center;
  gap: 6px;
  height: 30px;
  padding: 0 8px;
  border-radius: 5px;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
  user-select: none;
  transition: background-color 140ms ease, color 140ms ease;
}
.tnode:hover { background: var(--raised); }
.tnode.active { background: var(--accent-soft); color: var(--accent-ink); font-weight: 500; }

/* 折叠箭头：纯 CSS 三角，展开时旋转 90°，比替换字符更顺滑 */
.tn-caret {
  flex: none;
  position: relative;
  width: 11px;
  height: 11px;
  color: #c4c2bc;
  transition: color 140ms ease;
}
.tn-caret::before {
  content: "";
  position: absolute;
  left: 2px;
  top: 50%;
  width: 0;
  height: 0;
  border-left: 4.5px solid currentColor;
  border-top: 3.5px solid transparent;
  border-bottom: 3.5px solid transparent;
  transform: translateY(-50%);
  transform-origin: 20% 50%;
  transition: transform 180ms cubic-bezier(.4, 0, .2, 1), opacity 140ms ease;
}
.tnode[aria-expanded="true"] > .tn-caret::before { transform: translateY(-50%) rotate(90deg); }
.tnode[data-has-kids="0"] > .tn-caret::before { opacity: 0; }
.tnode:hover > .tn-caret { color: #98968f; }
.tnode.active > .tn-caret { color: var(--accent); }

.tn-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tn-n {
  flex: none;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  background: var(--raised);
  padding: 1px 6px;
  border-radius: 999px;
  transition: background-color 140ms ease, color 140ms ease;
}
.tnode.active .tn-n { background: #fff; color: var(--accent-ink); }

/* 子级容器：0fr ↔ 1fr 让浏览器自己算高度，嵌套层也不会被截断 */
.tn-kids {
  display: grid;
  grid-template-rows: 1fr;
  opacity: 1;
  padding-left: 12px;
  margin-left: 14px;
  border-left: 1px solid var(--border);
  transition: grid-template-rows 210ms cubic-bezier(.4, 0, .2, 1),
              opacity 160ms ease,
              border-color 210ms ease;
}
.tn-kids[data-open="0"] {
  grid-template-rows: 0fr;
  opacity: 0;
  border-left-color: transparent;
}
.tn-kids-in { min-height: 0; overflow: hidden; }

/* 首屏与整树重建时不播放展开动画 */
.tree.no-anim .tn-kids { transition: none; }

.tn-kids .tnode { height: 28px; font-size: 12.5px; }

.tn-hint { margin: 2px 0 8px; padding: 0 8px; font-size: 11.5px; color: var(--muted); }

.leaf-list { list-style: none; margin: 2px 0 6px; padding: 0; transition: opacity 140ms ease; }
.leaf-list.is-loading { opacity: .38; }

.row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  column-gap: 8px;
  align-items: center;
  width: 100%;
  text-align: left;
  border: 0;
  background: none;
  padding: 5px 8px;
  border-radius: 5px;
  cursor: pointer;
}
.row:hover { background: var(--raised); }

.row[aria-selected="true"] { background: var(--accent-soft); }
.row[aria-selected="true"] .t { color: var(--accent-ink); }

.row .t {
  display: block;
  font: 500 13.5px/1.35 var(--serif);
  letter-spacing: 0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.row .m {
  display: flex;
  align-items: center;
  gap: 5px;
  margin-top: 1px;
  font-size: 11.5px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
}
.row .m .rg { font-variant-numeric: tabular-nums; }
.row .m .au { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.row .m .dot { color: #c9c8c2; }

.row .d {
  grid-row: 1 / span 2;
  grid-column: 2;
  font-size: 11.5px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.01em;
}

.chip-doc {
  flex: none;
  font-size: 11px;
  line-height: 16px;
  height: 16px;
  padding: 0 5px;
  border-radius: 3px;
  background: var(--raised);
  color: var(--muted);
}

.empty {
  list-style: none;
  padding: 32px 12px;
  font-size: 12.5px;
  color: var(--muted);
  line-height: 1.8;
}
.empty b { display: block; color: var(--text); font-weight: 500; margin-bottom: 4px; }

/* 原件区 */

.viewer {
  background: var(--surface);
  border-radius: var(--radius-card);
  padding: 18px 24px 20px;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.doc-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
  flex: none;
}
.doc-head h2 {
  margin: 0;
  min-width: 0;
  font: 600 var(--fs-name)/1.3 var(--serif);
  letter-spacing: 0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.doc-head .spacer { flex: 1; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 34px;
  padding: 0 14px;
  border: 0;
  border-radius: var(--radius-control);
  background: var(--accent);
  color: #fff;
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
  flex: none;
}
.btn:hover { background: #9c211a; }
.btn:active { background: #861c16; }
.btn svg { width: 14px; height: 14px; stroke: currentColor; fill: none; stroke-width: 1.7; }

.btn-ghost {
  height: 34px;
  padding: 0 12px;
  border: 0;
  border-radius: var(--radius-control);
  background: var(--raised);
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  flex: none;
}
.btn-ghost:hover { background: #e7e6e1; }

/* 原件区：图片高度完全由容器决定，不再用 vh 硬算，避免撑破面板压住登记信息 */

.sheet {
  position: relative;
  background: var(--raised);
  border-radius: 6px;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}
.frame {
  position: absolute;
  inset: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 0;
}
.frame img {
  display: block;
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
}

.hl { position: absolute; inset: 0; pointer-events: none; }
.hl i {
  position: absolute;
  border: 1.5px solid var(--accent);
  background: rgba(179, 39, 30, 0.07);
  border-radius: 2px;
  animation: hl-in 220ms ease-out both;
}
@keyframes hl-in { from { opacity: 0; } to { opacity: 1; } }

.meta {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px 20px;
  margin: 16px 0 0;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  flex: none;
}
.meta div { min-width: 0; }
.meta dt { font-size: 12px; color: var(--muted); margin-bottom: 3px; }
.meta dd {
  margin: 0;
  font-size: 13px;
  line-height: 1.5;
  overflow-wrap: anywhere;
}
.meta .num dd { font-variant-numeric: tabular-nums; }
.meta .span2 { grid-column: span 2; }

/* ---------------------------------------------------------------- 手机 */

.only-mobile { display: none; }

@media (max-width: 1180px) {
  .panes { grid-template-columns: minmax(300px, 360px) minmax(0, 1fr); }
  .meta { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 900px) {
  :root { --pad: 16px; --gap: 16px; }

  body { height: auto; min-height: 100%; }

  .top {
    height: auto;
    padding: 10px 16px 0;
    flex-wrap: wrap;
    row-gap: 4px;
  }
  .topnav {
    margin-left: 0;
    width: 100%;
    gap: 20px;
    overflow-x: auto;
    scrollbar-width: none;
    padding-bottom: 4px;
  }
  .topnav::-webkit-scrollbar { display: none; }
  .topnav a { white-space: nowrap; }

  .canvas { padding: 14px 16px 20px; gap: 14px; height: auto; }
  .title-row { flex-direction: column; align-items: flex-start; gap: 6px; }
  /* column 方向下子项按内容收缩会撑出视口，必须显式占满可用宽度 */
  .title-row > div { width: 100%; min-width: 0; }
  .title-row h1 { font-size: 24px; }
  .stamp { padding: 0; }

  .panes { display: block; }
  /* 名录框占满一屏，树在框内滚动，避免整页跟着滚 */
  .ledger { height: calc(100vh - 260px); min-height: 340px; }

  .viewer { display: none; }
  .viewer[data-open="true"] {
    display: flex;
    position: fixed;
    inset: 0;
    z-index: 40;
    border-radius: 0;
    padding: 14px 14px 20px;
    overflow-y: auto;
  }
  .meta { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 16px; }
  .meta .span2 { grid-column: span 2; }

  /* 抽屉里的原件改为整宽自适应，不再依赖绝对定位 */
  .sheet { flex: none; padding: 10px; overflow: visible; }
  .frame { position: static; inset: auto; display: block; width: 100%; }
  .frame img { width: 100%; max-height: none; }

  .doc-head { flex-wrap: wrap; row-gap: 10px; margin-bottom: 12px; }
  .doc-head h2 { font-size: 18px; flex: 1 1 100%; order: 1; margin-bottom: 2px; }
  .doc-head .spacer { display: none; }
  .only-mobile { display: inline-flex; order: 2; }
  #copy { order: 3; }
  .doc-head .btn { order: 4; }

  .foot { font-size: 11px; }
}

@media (max-width: 900px) {
  .row { grid-template-columns: 1fr; }
  .row .d { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

/* ---------------------------------------------------------------- 类型 tab */
/* 由 /api/taxonomy 动态渲染，不写死类型名与个数；超过 5 个横向滚动 */

.tabs {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: none;
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }

.tab {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 32px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
  transition: border-color 120ms, color 120ms, background 120ms;
}
.tab:hover { border-color: var(--accent-track); color: var(--text); }
.tab.active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-ink);
}
.tab-n {
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--raised);
  color: var(--muted);
}
.tab.active .tab-n { background: #fff; color: var(--accent-ink); }

/* ---------------- 富文本阅读区（kind=rich） ---------------- */
.rich-body {
  flex: 1;
  min-height: 0;
  width: 100%;
  max-width: 680px;
  margin: 0 auto;
  padding: 8px 12px 48px 4px;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: #d7d6d0 transparent;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 16px;
  line-height: 1.8;
  color: var(--ink);
}
.rich-body::-webkit-scrollbar { width: 8px; }
.rich-body::-webkit-scrollbar-thumb { background: #d7d6d0; border-radius: 4px; }
.rich-body[hidden] { display: none; }

/* 正文一律不许撑破阅读栏：超长串断行、表格/代码块内部横向滚动 */
.rich-body .prose {
  max-width: 100%;
  overflow-wrap: anywhere;
  word-break: break-word;
}
.rich-body .prose img,
.rich-body .prose video,
.rich-body .prose iframe,
.rich-body .prose svg { max-width: 100%; }
.rich-body .prose pre,
.rich-body .prose table {
  display: block;
  max-width: 100%;
  overflow-x: auto;
  overscroll-behavior-x: contain;
}
.rich-body .prose pre { padding: 12px 14px; background: #f6f5f2; border-radius: 6px; font-size: 13px; }
.rich-body .prose table { border-collapse: collapse; }
.rich-body .prose th,
.rich-body .prose td { border: 1px solid var(--border, #e2e0db); padding: 6px 10px; font-size: 14px; }
.rich-cover {
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  border-radius: 10px;
  display: block;
  margin: 0 0 26px;
  background: #eee;
}
.rich-body .prose h2,
.rich-body .prose h3 {
  font-family: "Songti SC", "SimSun", serif;
  line-height: 1.35;
  margin: 1.6em 0 .6em;
}
.rich-body .prose h2 { font-size: 24px; }
.rich-body .prose h3 { font-size: 19px; }
.rich-body .prose p { margin: 0 0 1.2em; }
.rich-body .prose img,
.rich-body .prose video {
  max-width: 100%;
  height: auto;
  border-radius: 8px;
  display: block;
  margin: 1.2em auto;
  background: #eee;
}
.rich-body .prose video { width: 100%; aspect-ratio: 16 / 9; }
.rich-body .prose blockquote {
  margin: 1.4em 0;
  padding: .2em 0 .2em 16px;
  border-left: 2px solid var(--accent, #b3271e);
  color: #555;
}
.rich-body .prose ul,
.rich-body .prose ol { padding-left: 1.4em; margin: 0 0 1.2em; }
.rich-body .prose a { color: var(--accent, #b3271e); text-decoration: underline; }
.rich-body .prose hr { border: 0; border-top: 1px solid var(--border, #e2e0db); margin: 2em 0; }

/* [hidden] 必须压过组件自身的 display（.tabs/.meta/.btn 等设了 flex/grid） */
[hidden] { display: none !important; }

/* 右栏空态（板块无内容时） */
.viewer-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 60px 24px;
  text-align: center;
  color: var(--muted, #8a8a85);
  background: var(--raised, #fff);
  border-radius: 4px;
  min-height: 240px;
}
.viewer-empty b {
  font-family: "Songti SC", "SimSun", serif;
  font-size: 16px;
  font-weight: 600;
  color: var(--ink, #1c1b19);
}
.viewer-empty span { font-size: 13px; }

/* 组件的 display 可能压过 [hidden]，这里再兜一次底 */
.tabs[hidden], .sheet[hidden], .meta[hidden], .btn[hidden],
.doc-head[hidden], .viewer-empty[hidden], .chip-doc[hidden] { display: none !important; }

/* 移动端：防止任何内容把页面撑横向 */
html, body { max-width: 100%; overflow-x: hidden; }

@media (max-width: 900px) {
  .title-row p, .stamp { max-width: 100%; overflow-wrap: anywhere; }
  .tn-name { white-space: normal; line-height: 1.3; }
}
