:root {
  --bg:      #FDF6E3;
  --panel:   #FFFFFF;
  --panel-2: #F5EDD5;
  --panel-3: #EDE0C4;
  --ink:     #2B2318;
  --muted:   #5C4E3A;
  --faint:   #8C7B62;
  --line:    #E5D9C4;
  --gold:    #8C6914;
  --gold-2:  #F5EDD5;
  --gold-glow: rgba(140,105,20,.10);
  --teal:    #0B6B57;
  --teal-2:  #DCF0E8;
  --blue:    #315B83;
  --amber:   #B87516;
  --rust:    #A64F38;
  --shadow:  0 2px 12px rgba(43,35,24,.07), 0 12px 40px rgba(43,35,24,.06);
  --rail:    272px;
  font-family: Inter, 'Noto Sans SC', ui-sans-serif, system-ui, -apple-system, "Microsoft YaHei", sans-serif;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
button, input, select { font: inherit; }
button { border: 0; cursor: pointer; }
a { color: var(--teal); }

body {
  background:
    linear-gradient(90deg, rgba(140,105,20,.035) 1px, transparent 1px),
    linear-gradient(rgba(49,91,131,.025) 1px, transparent 1px),
    var(--bg);
  background-size: 36px 36px;
  color: var(--ink);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* ── App shell ──────────────────────────────────────────── */
.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: var(--rail) minmax(0,1fr);
}

/* ── Rail ───────────────────────────────────────────────── */
.rail {
  position: sticky; top: 0;
  height: 100vh; overflow-y: auto;
  padding: 20px 14px 24px;
  background: rgba(253,246,227,.96);
  border-right: 1px solid var(--line);
  backdrop-filter: blur(18px);
}
.rail::-webkit-scrollbar { width: 3px; }
.rail::-webkit-scrollbar-thumb { background: var(--line); border-radius: 2px; }

.brand {
  display: grid;
  grid-template-columns: 40px 1fr;
  gap: 11px; align-items: center;
  min-height: 52px;
  margin-bottom: 20px;
  cursor: pointer; border-radius: 8px;
  padding: 6px 8px;
  transition: background .15s;
}
.brand:hover { background: var(--panel-2); }
.brand-mark {
  width: 40px; height: 40px;
  display: grid; place-items: center;
  background: var(--ink); color: #fff;
  border-radius: 8px; font-weight: 800; font-size: .85rem;
  letter-spacing: .04em;
}
.brand-title  { font-weight: 700; font-size: .9rem; color: var(--ink); }
.brand-subtitle { color: var(--faint); font-size: .68rem; margin-top: 2px; letter-spacing: .02em; }

.primary-nav { display: grid; gap: 4px; margin-bottom: 20px; }

.nav-button, .module-button {
  width: 100%; display: flex; align-items: center;
  min-height: 36px; padding: 8px 10px;
  border-radius: 7px; background: transparent;
  color: var(--muted); text-align: left; font-size: .88rem;
  transition: background .12s, color .12s;
}
.nav-button:hover, .module-button:hover { background: var(--panel-2); color: var(--ink); }
.nav-button.active, .module-button.active {
  background: var(--gold-2); color: var(--gold); font-weight: 600;
}

.rail-section { border-top: 1px solid var(--line); padding-top: 16px; }
.rail-label {
  color: var(--faint); font-size: .68rem; font-weight: 700;
  letter-spacing: .09em; text-transform: uppercase; margin-bottom: 8px;
  padding-left: 4px;
}

.module-nav { display: grid; gap: 16px; }
.rail-group { display: grid; gap: 3px; }
.rail-group-title {
  color: var(--muted); font-size: .78rem; font-weight: 700;
  padding: 4px 10px 5px; letter-spacing: .02em;
}
.rail-link {
  justify-content: flex-start; min-height: 34px;
  color: var(--muted); font-size: .84rem; padding: 7px 10px;
}

/* ── Workspace ──────────────────────────────────────────── */
.workspace { min-width: 0; }

.topbar {
  position: sticky; top: 0; z-index: 50;
  min-height: 68px; display: flex; align-items: center; gap: 14px;
  padding: 12px 28px;
  background: rgba(253,246,227,.92);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(18px);
}

.search-box {
  flex: 1; min-width: 200px; height: 42px;
  display: flex; align-items: center; gap: 10px;
  padding: 0 14px; background: var(--panel);
  border: 1px solid var(--line); border-radius: 8px;
  transition: border-color .2s, box-shadow .2s;
}
.search-box:focus-within {
  border-color: rgba(140,105,20,.5);
  box-shadow: 0 0 0 4px rgba(140,105,20,.09);
}
.search-glyph {
  width: 14px; height: 14px; flex: none;
  border: 2px solid var(--faint); border-radius: 99px; position: relative;
}
.search-glyph::after {
  content: ""; position: absolute;
  right: -7px; bottom: -3px;
  width: 8px; height: 2px;
  background: var(--faint); transform: rotate(45deg);
}
.search-box input {
  width: 100%; border: 0; outline: 0; background: transparent;
  font-size: .9rem; color: var(--ink);
}
.search-box input::placeholder { color: var(--faint); }

.topbar-actions { display: flex; gap: 8px; }

.ghost-button, .solid-button, .chip-button {
  min-height: 36px; padding: 8px 14px;
  border-radius: 7px; white-space: nowrap; font-size: .85rem;
  transition: all .15s;
}
.ghost-button, .chip-button {
  background: var(--panel); color: var(--ink);
  border: 1px solid var(--line);
}
.ghost-button:hover { border-color: var(--gold); color: var(--gold); }
.solid-button {
  background: var(--teal); color: #fff;
  box-shadow: 0 4px 14px rgba(11,107,87,.22);
}
.solid-button:hover { background: #0a5e4c; }

main { padding: 28px; }
.view { display: none; }
.active-view { display: block; }

/* ── Typography helpers ─────────────────────────────────── */
.eyebrow {
  color: var(--faint); font-size: .7rem; font-weight: 800;
  letter-spacing: .1em; text-transform: uppercase;
}

/* ── Overview ───────────────────────────────────────────── */
.hero-grid {
  display: grid;
  grid-template-columns: minmax(0,1.4fr) minmax(280px,.6fr);
  gap: 16px; margin-bottom: 20px;
}
.hero-panel {
  min-height: 280px; padding: 28px 32px;
  display: flex; flex-direction: column; justify-content: space-between;
  position: relative; overflow: hidden;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 10px; box-shadow: var(--shadow);
}
.hero-panel::after {
  content: "";
  position: absolute; right: 0; bottom: 0;
  width: 45%; height: 6px;
  background: linear-gradient(90deg, var(--gold), var(--teal), var(--blue), var(--rust));
}
.hero-title {
  margin: 12px 0 14px;
  font-size: clamp(28px, 3.5vw, 48px);
  line-height: 1.06; font-weight: 800; color: var(--ink);
}
.hero-copy { color: var(--muted); font-size: .95rem; max-width: 640px; line-height: 1.7; }
.hero-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 20px; }

.metrics-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 12px;
}
.metric-card {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 10px; box-shadow: var(--shadow);
  min-height: 124px; padding: 18px 20px;
}
.metric-number { font-size: 36px; line-height: 1; font-weight: 800; color: var(--ink); }
.metric-label  { color: var(--muted); margin-top: 8px; font-size: .88rem; }
.metric-note   { color: var(--faint); font-size: .72rem; margin-top: 10px; line-height: 1.4; }

.section-row {
  display: grid;
  grid-template-columns: minmax(0,1fr) minmax(280px,.4fr);
  gap: 16px; margin-top: 20px;
}
.section-title {
  display: flex; justify-content: space-between; align-items: flex-end;
  gap: 12px; margin-bottom: 12px;
}
.section-title h2 { font-size: 1.15rem; font-weight: 700; color: var(--ink); }
.section-title p  { margin: 4px 0 0; color: var(--muted); font-size: .83rem; }

.path-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(200px,1fr)); gap: 10px;
}
.path-card {
  min-height: 190px; padding: 16px;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 10px; box-shadow: var(--shadow);
  cursor: pointer; transition: border-color .15s, transform .15s, box-shadow .15s;
}
.path-card:hover {
  border-color: rgba(140,105,20,.45);
  transform: translateY(-2px); box-shadow: 0 8px 28px rgba(43,35,24,.1);
}
.path-card-title { font-size: .95rem; font-weight: 700; color: var(--ink); }
.path-card-intent { min-height: 50px; margin-top: 8px; color: var(--muted); font-size: .8rem; line-height: 1.5; }
.mini-chain { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 12px; }
.mini-node {
  display: inline-flex; align-items: center; min-height: 22px;
  padding: 2px 7px; border-radius: 999px;
  background: var(--panel-2); color: var(--muted); font-size: .7rem;
}

.panel {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 10px; box-shadow: var(--shadow); padding: 18px 20px;
}
.signal-list { display: grid; gap: 8px; }
.signal-item {
  display: grid; grid-template-columns: 4px 1fr; gap: 12px;
  padding: 9px 0; border-bottom: 1px solid var(--line);
}
.signal-item:last-child { border-bottom: 0; padding-bottom: 0; }
.signal-bar { border-radius: 3px; background: var(--gold); }
.signal-item:nth-child(2) .signal-bar { background: var(--teal); }
.signal-item:nth-child(3) .signal-bar { background: var(--blue); }
.signal-item:nth-child(4) .signal-bar { background: var(--rust); }
.signal-title  { font-weight: 600; font-size: .88rem; }
.signal-meta   { color: var(--faint); font-size: .72rem; margin-top: 2px; }

/* ── Knowledge tree ─────────────────────────────────────── */
.view-heading {
  display: flex; justify-content: space-between;
  align-items: flex-end; gap: 16px; margin-bottom: 20px;
}
.view-heading h1 { font-size: 1.35rem; font-weight: 700; margin-top: 4px; }
.view-heading p  { margin: 4px 0 0; color: var(--muted); font-size: .85rem; }

.knowledge-tree { display: grid; gap: 16px; }
.tree-section {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 10px; box-shadow: var(--shadow); padding: 20px;
}
.tree-section-head {
  display: flex; justify-content: space-between; align-items: flex-end;
  padding-bottom: 14px; margin-bottom: 14px; border-bottom: 1px solid var(--line);
}
.tree-section-head h2 { font-size: 1.05rem; font-weight: 700; }
.tree-section-head p  { color: var(--muted); font-size: .82rem; }
.tree-columns {
  display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 10px;
}
.tree-column {
  min-height: 200px; padding: 12px;
  background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 8px;
}
.tree-column h3 { margin: 0 0 10px; font-size: .88rem; font-weight: 700; color: var(--muted); }
.tree-card-list { display: grid; gap: 6px; }
.tree-card {
  width: 100%; min-height: 50px;
  display: grid; gap: 2px; padding: 9px 10px;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 7px; text-align: left;
  color: var(--ink); cursor: pointer; font-size: .83rem;
  transition: border-color .12s, transform .12s;
}
.tree-card:hover { border-color: rgba(140,105,20,.4); transform: translateY(-1px); }
.tree-card small { color: var(--faint); font-size: .7rem; }

/* ── Workflow (research path) ───────────────────────────── */
.workflow-layout {
  display: grid; grid-template-columns: 260px minmax(0,1fr); gap: 16px;
}
.path-list, .workflow-chain, .related-list, .source-list, .toc-list { display: grid; gap: 7px; }
.path-select {
  min-height: 70px; padding: 12px 14px;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 8px; text-align: left; cursor: pointer;
  transition: border-color .15s, box-shadow .15s;
}
.path-select.active {
  border-color: rgba(11,107,87,.5);
  box-shadow: 0 0 0 3px rgba(11,107,87,.08);
}
.path-select strong, .path-select span { display: block; }
.path-select strong { font-size: .88rem; color: var(--ink); }
.path-select span   { color: var(--muted); font-size: .75rem; margin-top: 4px; line-height: 1.4; }

.workflow-card {
  display: grid; grid-template-columns: 80px minmax(0,1fr) 160px;
  gap: 14px; padding: 16px 18px;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 9px; cursor: pointer;
  transition: border-color .15s, transform .12s;
}
.workflow-card:hover { border-color: rgba(140,105,20,.4); transform: translateX(2px); }
.stage-label { color: var(--gold); font-size: .72rem; font-weight: 800; letter-spacing: .04em; }
.workflow-card h3 { margin: 4px 0 6px; font-size: .98rem; font-weight: 700; }
.workflow-card p  { margin: 0; color: var(--muted); font-size: .82rem; line-height: 1.5; }

/* ── Library ────────────────────────────────────────────── */
.library-tools {
  display: grid;
  grid-template-columns: minmax(220px,1fr) 180px 150px 140px;
  gap: 9px; margin-bottom: 14px;
}
.select-field, .input-field {
  min-height: 38px; padding: 0 12px;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 7px; color: var(--ink); font-size: .86rem;
}
.select-field:focus, .input-field:focus { outline: none; border-color: var(--gold); }

.library-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px,1fr));
  gap: 10px;
}
.library-card {
  padding: 14px 16px;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 9px; cursor: pointer;
  transition: border-color .15s, transform .12s, box-shadow .15s;
}
.library-card:hover {
  border-color: rgba(140,105,20,.45);
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(43,35,24,.08);
}
.card-topline {
  display: flex; justify-content: space-between;
  align-items: center; gap: 8px; margin-bottom: 8px;
}
.library-card h3 { margin: 0 0 7px; font-size: .95rem; font-weight: 700; color: var(--ink); }
.library-card p  { margin: 0; color: var(--muted); font-size: .8rem; line-height: 1.5;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card-foot { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 10px; }

/* ── Badges / pills ─────────────────────────────────────── */
.mini-node, .pill, .kind-badge, .grade-badge {
  display: inline-flex; align-items: center;
  min-height: 22px; padding: 2px 8px;
  border-radius: 999px; font-size: .7rem;
}
.kind-badge { background: var(--panel-2); color: var(--muted); }
.grade-badge { background: var(--panel-2); color: var(--faint); }
.grade-badge.grade-a { background: var(--teal-2); color: var(--teal); }
.grade-badge.grade-b { background: #e8eff8; color: var(--blue); }
.pill { background: var(--panel-2); color: var(--muted); border: 1px solid var(--line); }

/* ── Sources ────────────────────────────────────────────── */
.source-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px,1fr));
  gap: 10px;
}
.source-card {
  padding: 14px 16px;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 9px;
}
.source-title { font-weight: 700; font-size: .9rem; margin-bottom: 6px; }
.source-count { color: var(--muted); font-size: .8rem; margin-bottom: 10px; }

/* ── Detail view ────────────────────────────────────────── */
.detail-shell {
  display: grid; grid-template-columns: minmax(0,1fr) 320px;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 10px; overflow: hidden; box-shadow: var(--shadow);
}
.detail-main { min-width: 0; padding: 28px 36px; border-right: 1px solid var(--line); }
.detail-side { padding: 22px; background: var(--panel-2); overflow-y: auto; }

.detail-header { margin: 16px 0 22px; }
.detail-header h1 {
  margin: 8px 0 10px;
  font-size: clamp(24px, 3.5vw, 40px);
  line-height: 1.1; font-weight: 800;
}
.meta-row { display: flex; flex-wrap: wrap; gap: 6px; }

/* ── Markdown rendering ─────────────────────────────────── */
.markdown h1 { display: none; }
.markdown h2 {
  margin: 28px 0 12px; padding-top: 22px;
  border-top: 1px solid var(--line);
  font-size: 1.1rem; font-weight: 700; color: var(--gold);
}
.markdown h3 { margin: 18px 0 8px; font-size: .98rem; font-weight: 700; }
.markdown p  { color: var(--muted); margin-bottom: .7rem; line-height: 1.75; }
.markdown strong { color: var(--ink); font-weight: 600; }

.markdown table {
  width: 100%; border-collapse: collapse;
  margin: 14px 0 20px; font-size: .82rem;
  border: 1px solid var(--line);  border-radius: 6px; overflow: hidden;
}
.markdown th {
  background: var(--panel-2); padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left; font-size: .78rem; color: var(--muted);
}
.markdown td {
  padding: 8px 10px; border-bottom: 1px solid var(--line);
  vertical-align: top; color: var(--muted);
}
.markdown tr:last-child td { border-bottom: 0; }
.markdown tr:hover td { background: var(--panel-2); }

.markdown blockquote {
  margin: 14px 0; padding: 12px 16px;
  background: var(--gold-2); border-left: 3px solid var(--gold);
  border-radius: 0 6px 6px 0;
}
.markdown blockquote p { color: var(--ink); }

.markdown a {
  color: var(--teal); text-decoration: none;
  border-bottom: 1px dotted rgba(11,107,87,.45);
}
.markdown code {
  background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 4px; padding: 1px 5px; font-size: .82em; color: var(--teal);
}
.markdown pre {
  overflow-x: auto; padding: 14px 16px;
  background: #2B2318; color: #E8D9B8;
  border-radius: 8px; margin: 14px 0;
}
.markdown pre code {
  display: block; background: transparent; border: 0;
  padding: 0; color: inherit; font-size: .83rem; line-height: 1.7;
}
.markdown ul, .markdown ol { padding-left: 1.4rem; margin: .5rem 0; }
.markdown li { color: var(--muted); margin: .3rem 0; }
.markdown li::marker { color: var(--gold); }
.markdown hr { border: none; border-top: 1px solid var(--line); margin: 1.5rem 0; }

/* ── Sidebar detail ─────────────────────────────────────── */
.side-block {
  padding-bottom: 16px; margin-bottom: 16px;
  border-bottom: 1px solid var(--line);
}
.side-block:last-child { border-bottom: 0; margin-bottom: 0; padding-bottom: 0; }
.side-block h3 { margin: 0 0 10px; font-size: .82rem; font-weight: 700; color: var(--ink); }

.toc-item, .related-item, .source-item {
  padding: 8px 10px; color: var(--muted); font-size: .8rem;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 6px; line-height: 1.4;
}
.related-item { cursor: pointer; transition: border-color .12s, color .12s; }
.related-item:hover { border-color: rgba(140,105,20,.45); color: var(--ink); }
.source-item { word-break: break-all; }

.empty { padding: 36px; text-align: center; color: var(--faint); font-size: .9rem; }

/* ── Scrollbar ──────────────────────────────────────────── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--line); border-radius: 3px; }

/* ── Responsive ─────────────────────────────────────────── */
@media (max-width: 1200px) {
  .detail-shell { grid-template-columns: 1fr; }
  .detail-main  { border-right: 0; border-bottom: 1px solid var(--line); }
  .detail-side  { max-height: 400px; }
}
@media (max-width: 960px) {
  :root { --rail: 230px; }
  .hero-grid, .section-row, .workflow-layout { grid-template-columns: 1fr; }
  .library-tools { grid-template-columns: 1fr 1fr; }
  .tree-columns { grid-template-columns: repeat(2, minmax(0,1fr)); }
}
@media (max-width: 680px) {
  .app-shell { grid-template-columns: 1fr; }
  .rail { position: relative; height: auto; }
  .primary-nav { display: flex; overflow-x: auto; }
  .topbar { flex-direction: column; align-items: stretch; padding: 12px; }
  main { padding: 14px; }
  .library-tools, .tree-columns, .metrics-grid, .workflow-card { grid-template-columns: 1fr; }
}
