:root {
  --bg: #fbf6ef;
  --bg-card: #fffdf9;
  --sidebar-bg: #f5ebd9;
  --ink: #3a2f24;
  --ink-soft: #6b5b48;
  --ink-light: #9b8871;
  --accent: #c96442;
  --accent-dark: #a94a2c;
  --accent-light: #fef3e8;
  --border: #e6d9c7;
  --border-strong: #d4c4ad;
  --l1: #8b4513;
  --l2: #c96442;
  --l3: #d4906e;
  --l4: #a67c52;
  --l5: #6b7c5f;
  --sidebar-w: 288px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Noto Sans SC", "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; }
img { max-width: 100%; display: block; }

/* ========== SIDEBAR ========== */
.sidebar {
  position: fixed;
  top: 0; left: 0; bottom: 0;
  width: var(--sidebar-w);
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  z-index: 10;
}
.sidebar-inner { padding: 20px 18px; }

.brand {
  display: flex; align-items: center; gap: 10px;
  text-decoration: none; color: var(--ink);
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
}
.brand-dot {
  width: 34px; height: 34px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-dark) 100%);
  position: relative;
  flex-shrink: 0;
}
.brand-dot::after {
  content: 'D';
  color: white;
  font-family: Georgia, serif;
  font-weight: 700;
  font-size: 20px;
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
}
.brand strong { display: block; font-size: 15px; }
.brand em { font-style: normal; font-size: 12px; color: var(--ink-light); }

.tabs {
  display: flex;
  gap: 4px;
  margin: 16px 0 14px;
  background: var(--bg-card);
  padding: 3px;
  border-radius: 8px;
  border: 1px solid var(--border);
}
.tab {
  flex: 1; text-align: center;
  padding: 7px 10px;
  border-radius: 6px;
  font-size: 13px;
  text-decoration: none;
  color: var(--ink-soft);
  transition: all .15s;
}
.tab.active {
  background: var(--accent);
  color: white;
  font-weight: 500;
}
.tab:not(.active):hover { background: var(--accent-light); color: var(--accent); }

.stats {
  display: flex; gap: 14px;
  font-size: 12px; color: var(--ink-light);
  margin-bottom: 14px;
}
.stats strong { color: var(--ink); font-size: 14px; }

.search-wrap { position: relative; margin-bottom: 16px; }
#search {
  width: 100%;
  padding: 8px 12px;
  font-size: 13px;
  border: 1px solid var(--border-strong);
  border-radius: 7px;
  background: var(--bg-card);
  color: var(--ink);
}
#search:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 2px rgba(201,100,66,.12); }
#results {
  position: absolute;
  top: calc(100% + 4px);
  left: 0; right: 0;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 6px 20px rgba(0,0,0,.08);
  max-height: 320px;
  overflow-y: auto;
  z-index: 20;
  display: none;
}
#results.active { display: block; }
.result-item {
  padding: 8px 12px;
  border-bottom: 1px solid rgba(0,0,0,.04);
  cursor: pointer;
  text-decoration: none;
  color: var(--ink);
  display: block;
}
.result-item:hover { background: var(--accent-light); }
.result-item:last-child { border-bottom: none; }
.result-name { font-weight: 500; font-size: 13px; }
.result-cat { font-size: 11px; color: var(--ink-light); margin-left: 6px; }
.result-body { font-size: 11px; color: var(--ink-soft); margin-top: 2px; line-height: 1.45; }

/* ========== FILTERS (graph page) ========== */
.filters {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  margin-bottom: 16px;
}
.filter-title { font-size: 11px; color: var(--ink-light); letter-spacing: .1em; margin-bottom: 8px; text-transform: uppercase; }
.filter-item {
  display: flex; align-items: center; gap: 8px;
  padding: 4px 0;
  font-size: 13px;
  cursor: pointer;
  user-select: none;
}
.filter-item input { margin: 0; accent-color: var(--accent); }
.filter-item em { margin-left: auto; color: var(--ink-light); font-style: normal; font-size: 11px; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.dot-concept { background: var(--accent); }
.dot-person { background: #4a5568; border-radius: 2px; transform: rotate(45deg); }
.dot-trade { background: var(--l5); border-radius: 3px; }
.dot-topic { background: #2d3748; clip-path: polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%); border-radius: 0; }

/* ========== TOC ========== */
.toc { font-size: 13px; }
.toc-loading { color: var(--ink-light); font-size: 12px; }
.toc-section { margin-bottom: 14px; }
.toc-title {
  display: flex; justify-content: space-between; align-items: baseline;
  padding: 6px 4px;
  font-weight: 600;
  color: var(--ink);
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  margin-bottom: 6px;
  font-size: 13px;
}
.toc-title-count { color: var(--ink-light); font-weight: 400; font-size: 12px; }
.toc-group { margin-bottom: 8px; }
.toc-group-name {
  font-size: 11px;
  color: var(--ink-light);
  text-transform: uppercase;
  letter-spacing: .05em;
  padding: 4px 4px 2px;
}
.toc-items {
  display: flex; flex-direction: column; gap: 2px;
  padding: 4px;
}
.toc-item {
  font-size: 12px;
  color: var(--ink-soft);
  text-decoration: none;
  padding: 2px 6px;
  border-radius: 4px;
  transition: all .1s;
  line-height: 1.4;
}
.toc-item:hover {
  background: var(--accent-light);
  color: var(--accent);
}

/* ========== MAIN CONTENT ========== */
.main {
  margin-left: var(--sidebar-w);
  padding: 40px 48px 48px;
  min-height: 100vh;
  max-width: 1040px;
}

.kicker {
  font-size: 11px;
  letter-spacing: .22em;
  color: var(--ink-light);
  margin-bottom: 10px;
}

.hero h1 {
  font-size: clamp(40px, 5.2vw, 64px);
  margin: 0 0 12px;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.08;
  color: var(--ink);
}
.hero h1 .accent { color: var(--accent); }
.tagline {
  color: var(--accent-dark);
  font-style: italic;
  font-size: 18px;
  margin: 0 0 10px;
  max-width: 640px;
}
.hero .meta {
  color: var(--ink-light);
  font-size: 14px;
  margin: 0 0 32px;
}

.lead { color: var(--ink-soft); font-size: 15px; max-width: 640px; }

.path { margin-top: 40px; }
.layer-rail {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px;
  margin-top: 24px;
}
.layer-chip {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-left: 4px solid var(--l2);
  border-radius: 8px;
  padding: 14px 16px;
  cursor: pointer;
  transition: all .15s;
  text-decoration: none;
  display: block;
}
.layer-chip:hover { border-color: var(--accent); transform: translateY(-1px); box-shadow: 0 4px 14px rgba(0,0,0,.05); }
.layer-chip.l1 { border-left-color: var(--l1); }
.layer-chip.l2 { border-left-color: var(--l2); }
.layer-chip.l3 { border-left-color: var(--l3); }
.layer-chip.l4 { border-left-color: var(--l4); }
.layer-chip.l5 { border-left-color: var(--l5); }
.layer-chip .num {
  font-family: Georgia, serif;
  font-size: 11px;
  color: var(--ink-light);
  letter-spacing: .1em;
}
.layer-chip h3 { margin: 4px 0 2px; font-size: 15px; font-weight: 600; }
.layer-chip .desc { font-size: 12px; color: var(--ink-soft); line-height: 1.5; }
.layer-chip .kcount { font-size: 11px; color: var(--ink-light); margin-top: 6px; }

.layer-full { margin-top: 48px; }
.layer-section {
  margin-bottom: 48px;
  scroll-margin-top: 20px;
}
.layer-heading {
  display: flex; align-items: baseline; gap: 12px;
  border-bottom: 2px solid var(--border);
  padding-bottom: 8px;
  margin-bottom: 16px;
}
.layer-heading .num {
  font-family: Georgia, serif;
  font-size: 22px;
  color: var(--accent);
  font-weight: 700;
}
.layer-heading h2 { margin: 0; font-size: 22px; }
.layer-heading .kcount { font-size: 13px; color: var(--ink-light); margin-left: auto; }

.layer-intro {
  color: var(--ink-soft);
  font-size: 14px;
  margin: -6px 0 18px;
  max-width: 640px;
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 10px;
}
.node-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  text-decoration: none;
  color: inherit;
  transition: all .12s;
  display: block;
}
.node-card:hover { border-color: var(--accent); transform: translateY(-1px); box-shadow: 0 4px 14px rgba(201,100,66,.08); }
.node-card h4 { margin: 0 0 4px; font-size: 14px; font-weight: 600; }
.node-card p { margin: 0; font-size: 12px; color: var(--ink-soft); line-height: 1.5; }

.cta-section {
  margin-top: 56px;
  padding: 28px;
  background: linear-gradient(135deg, var(--accent-light) 0%, var(--sidebar-bg) 100%);
  border-radius: 12px;
  text-align: center;
  display: flex; gap: 12px; justify-content: center; flex-wrap: wrap;
}

.btn {
  display: inline-block;
  padding: 10px 22px;
  border-radius: 8px;
  text-decoration: none;
  font-weight: 500;
  border: 1px solid var(--border-strong);
  background: var(--bg-card);
  color: var(--ink);
  transition: all .15s;
  font-size: 15px;
  cursor: pointer;
}
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn.primary { background: var(--accent); color: white; border-color: var(--accent); }
.btn.primary:hover { background: var(--accent-dark); color: white; }

.site-footer {
  margin-top: 64px;
  padding-top: 24px;
  border-top: 1px solid var(--border);
  color: var(--ink-soft);
  font-size: 13px;
}
.site-footer a { color: var(--accent); text-decoration: none; }
.site-footer a:hover { text-decoration: underline; }
.small { font-size: 12px; color: var(--ink-light); }

.sidebar-footer {
  margin-top: 20px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  font-size: 11px;
  color: var(--ink-soft);
}
.sidebar-footer ul { list-style: none; padding: 0; margin: 6px 0 0; }
.sidebar-footer li { padding: 2px 0; }

/* ========== GRAPH PAGE ========== */
.body-graph { overflow: hidden; }
.body-graph .main { padding: 0; max-width: none; }
.graph-main {
  height: 100vh;
  display: flex;
  flex-direction: column;
}
.graph-header {
  padding: 20px 32px 16px;
  border-bottom: 1px solid var(--border);
  display: flex; justify-content: space-between; align-items: flex-end;
  background: var(--bg-card);
}
.graph-header h2 { margin: 4px 0 0; font-size: 22px; }
.graph-controls { display: flex; gap: 6px; }
.mini-btn {
  padding: 6px 12px;
  border: 1px solid var(--border-strong);
  background: white;
  border-radius: 6px;
  font-size: 13px;
  color: var(--ink);
  cursor: pointer;
  transition: all .12s;
}
.mini-btn:hover { border-color: var(--accent); color: var(--accent); }
.graph-canvas { flex: 1; position: relative; background: var(--bg); }
#cy { width: 100%; height: 100%; }

.legend {
  position: absolute; top: 16px; right: 16px;
  background: rgba(255,255,255,.95); border: 1px solid var(--border);
  border-radius: 10px; padding: 12px 14px; font-size: 12px;
  box-shadow: 0 4px 16px rgba(0,0,0,.06); max-width: 200px;
  backdrop-filter: blur(4px);
}
.legend h4 { margin: 0 0 8px; font-size: 12px; font-weight: 600; color: var(--ink); }
.legend-item { display: flex; align-items: center; gap: 8px; margin: 3px 0; color: var(--ink-soft); }
.legend-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }

.detail-panel {
  position: absolute; right: 16px; bottom: 16px;
  background: white; border: 1px solid var(--border); border-radius: 10px;
  padding: 16px 18px; max-width: 320px; max-height: 46vh; overflow-y: auto;
  box-shadow: 0 8px 28px rgba(0,0,0,.12);
  display: none;
}
.detail-panel.active { display: block; }
.detail-panel h3 { margin: 0 0 8px; color: var(--accent); font-size: 18px; }
.layer-tag {
  display: inline-block; padding: 2px 10px; background: var(--accent-light);
  color: var(--accent); border-radius: 4px; font-size: 11px; margin-bottom: 10px; font-weight: 500;
}
.detail-panel p { font-size: 13px; line-height: 1.55; color: var(--ink-soft); margin: 0 0 10px; }
.view-full {
  display: inline-block; margin-top: 4px;
  color: var(--accent); text-decoration: none; font-weight: 500; font-size: 13px;
}
.view-full:hover { text-decoration: underline; }
.detail-panel .close {
  float: right; cursor: pointer; color: var(--ink-light); font-size: 20px;
  line-height: 1; padding: 0 4px;
}

/* ========== NOTE PAGE ========== */
.note-main { max-width: 780px; }
.back { color: var(--ink-soft); text-decoration: none; font-size: 13px; display: inline-block; padding: 4px 0; }
.back:hover { color: var(--accent); }
.note-main article { margin-top: 16px; }
.note-main h1 { font-size: 36px; margin: 12px 0 6px; letter-spacing: -0.01em; line-height: 1.15; }
.note-main .tag {
  display: inline-block; padding: 3px 12px; background: var(--accent-light);
  color: var(--accent); border-radius: 4px; font-size: 12px; font-weight: 500;
}
.note-main .one-liner { font-size: 18px; color: var(--ink-soft); margin: 12px 0 24px; font-style: italic; }
.note-main h3 {
  font-size: 17px; margin: 28px 0 10px; color: var(--accent-dark);
  border-bottom: 1px solid var(--border); padding-bottom: 6px; font-weight: 600;
}
.note-main blockquote {
  border-left: 3px solid var(--accent);
  padding: 6px 16px;
  margin: 14px 0;
  background: var(--accent-light);
  border-radius: 0 6px 6px 0;
  font-size: 14px;
}
.note-main blockquote cite { display: block; font-size: 12px; color: var(--ink-light); margin-top: 6px; font-style: normal; }
.note-main ul, .note-main ol { padding-left: 22px; }
.note-main li { margin: 3px 0; font-size: 14px; }
.note-main .related { margin-top: 40px; padding-top: 20px; border-top: 1px solid var(--border); }
.note-main .related h3 { border: none; padding: 0; }
.related-links { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.related-links a {
  padding: 5px 10px; background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 6px; text-decoration: none; color: var(--ink); font-size: 13px;
}
.related-links a:hover { border-color: var(--accent); color: var(--accent); }
.rel-type { font-size: 10px; color: var(--ink-light); margin-left: 4px; }
.loading { color: var(--ink-light); }

/* ========== MOBILE ========== */
@media (max-width: 900px) {
  :root { --sidebar-w: 0px; }
  .sidebar {
    transform: translateX(-100%);
    transition: transform .2s;
    width: 280px;
  }
  .sidebar.open { transform: translateX(0); box-shadow: 4px 0 20px rgba(0,0,0,.1); }
  .main { padding: 24px 20px; max-width: 100%; }
  .hero h1 { font-size: 32px; }
  .layer-rail { grid-template-columns: 1fr 1fr; }
  .graph-header { padding: 14px 20px; }
  .body-graph .main { height: 100vh; }
  .mobile-menu-btn {
    position: fixed; top: 10px; left: 10px; z-index: 30;
    background: var(--accent); color: white;
    border: none; border-radius: 8px;
    padding: 8px 12px; font-size: 14px;
    cursor: pointer;
    box-shadow: 0 2px 10px rgba(0,0,0,.15);
  }
}
.mobile-menu-btn { display: none; }
@media (max-width: 900px) { .mobile-menu-btn { display: block; } }

/* ========== PROFILE PAGE ========== */
.profile-main { max-width: 880px; margin: 0 auto; padding: 56px 48px 80px; }
.profile { font-size: 16px; }
.profile-header {
  display: flex; gap: 32px; align-items: center; margin-bottom: 32px;
}
.profile-portrait {
  width: 160px; height: 200px; flex-shrink: 0;
  border-radius: 4px; overflow: hidden;
  background: var(--bg-soft, #f5ebd9);
  position: relative;
  box-shadow: 0 4px 18px rgba(139,69,19,0.12);
}
.profile-portrait img { width: 100%; height: 100%; object-fit: cover; display: block; }
.profile-portrait .portrait-fallback {
  position: absolute; inset: 0; display: none;
  align-items: center; justify-content: center;
  font-family: "Songti SC", Georgia, serif;
  font-size: 84px; font-weight: 700; color: var(--accent);
  background: linear-gradient(135deg, #f5ebd9 0%, #e8d9be 100%);
}
.profile-title h1 {
  font-family: "Songti SC", Georgia, serif;
  font-size: 38px; line-height: 1.2; margin: 10px 0 14px;
  font-weight: 700;
}
.profile-title h1 .zh { font-size: 22px; color: var(--ink-soft); font-weight: 500; }
.tag-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-block; padding: 3px 10px;
  background: var(--accent-light, rgba(201,100,66,0.08));
  color: var(--accent); font-size: 12px; border-radius: 12px;
  letter-spacing: 0.02em;
}

.tldr {
  border-left: 3px solid var(--accent);
  background: var(--sidebar-bg, #f5ebd9);
  padding: 18px 22px; margin: 28px 0;
  font-size: 15.5px; line-height: 1.75; color: var(--ink);
  border-radius: 0 4px 4px 0;
}
.tldr strong { color: var(--accent); }
.tldr b { color: var(--accent-deep, #8b4513); }

.rule { border: none; border-top: 1px dashed var(--border); margin: 36px 0; }

.bio-section h2 {
  font-family: "Songti SC", Georgia, serif;
  font-size: 24px; font-weight: 700; margin: 0 0 18px;
  padding-bottom: 8px; border-bottom: 1px solid var(--border);
}
.bio-section h3 {
  font-size: 16px; font-weight: 600; margin: 22px 0 8px;
  color: var(--accent-deep, #8b4513);
}
.bio-section p { margin: 0 0 12px; line-height: 1.75; color: var(--ink); }
.bio-section ul, .bio-section ol { margin: 8px 0 0 20px; line-height: 1.8; }
.bio-section li { margin-bottom: 6px; }
.bio-section b { color: var(--accent-deep, #8b4513); }

/* Tables */
.kv, .scorecard, .judgments {
  width: 100%; border-collapse: collapse; margin: 14px 0;
  font-size: 14px; background: var(--bg-card, #fff);
  border: 1px solid var(--border); border-radius: 4px; overflow: hidden;
}
.kv th, .scorecard th, .judgments th {
  text-align: left; padding: 10px 14px;
  background: var(--sidebar-bg, #f5ebd9);
  font-weight: 600; color: var(--ink);
  border-bottom: 1px solid var(--border);
}
.kv td, .scorecard td, .judgments td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  line-height: 1.65;
}
.kv tr:last-child td, .scorecard tr:last-child td, .judgments tr:last-child td {
  border-bottom: none;
}
.kv th { width: 110px; }
.scorecard td.stars { color: var(--accent); letter-spacing: 1px; white-space: nowrap; font-size: 14px; }
.judgments td { vertical-align: top; }
.judgments .result.win { color: #2d7a4a; font-weight: 600; }
.judgments .result.mixed { color: #c07030; }
.judgments .result.pending { color: var(--ink-soft); }

.single-entry { font-size: 16px; }
.single-entry a { color: var(--accent); font-weight: 600; border-bottom: 1px solid var(--accent); }

.enter-cta {
  margin-top: 48px; padding-top: 32px; border-top: 1px solid var(--border);
  display: flex; gap: 14px; flex-wrap: wrap;
}

@media (max-width: 720px) {
  .profile-main { padding: 32px 20px 60px; }
  .profile-header { flex-direction: column; text-align: center; gap: 20px; }
  .profile-portrait { width: 140px; height: 180px; }
  .profile-title h1 { font-size: 30px; }
  .tag-chips { justify-content: center; }
  .kv th { width: 80px; font-size: 12px; }
  .bio-section { font-size: 14px; }
}
