:root {
  --bg: #f4f6fa;
  --panel: #ffffff;
  --ink: #1e293b;
  --muted: #718096;
  --line: #e3e8f0;
  --accent: #315efb;
  --accent-soft: #edf1ff;
  --chapter: #233b70;
  --concept: #315efb;
  --warm: #b7791f;
  --shadow: 0 10px 28px rgba(31, 45, 78, .07);
  font-family: "Segoe UI", "Microsoft YaHei", system-ui, sans-serif;
  color-scheme: light;
}
* { box-sizing: border-box; }
html { min-width: 320px; background: var(--bg); }
body { margin: 0; min-width: 320px; background: var(--bg); color: var(--ink); }
button, input { font: inherit; }
button { cursor: pointer; -webkit-tap-highlight-color: transparent; }
button:focus-visible, a:focus-visible, [tabindex="0"]:focus-visible { outline: 3px solid rgba(49,94,251,.32); outline-offset: 2px; }

.app-shell { min-height: 100svh; }
.topbar {
  min-height: 68px; display: flex; align-items: center; gap: 18px; padding: 10px clamp(14px, 3vw, 32px);
  background: #f8fafc; border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 245px; color: var(--ink); text-decoration: none; }
.brand-mark { width: 36px; height: 36px; display: grid; place-items: center; border-radius: 11px; color: white; background: var(--chapter); font-size: 23px; font-weight: 800; }
.brand strong { display:block; font-size: 15px; letter-spacing: .01em; }
.brand small { display:block; margin-top: 2px; color: var(--muted); font-size: 11px; }
.search-wrap { height: 42px; flex: 1; display: flex; align-items: center; padding: 0 9px 0 12px; border: 1px solid var(--line); border-radius: 12px; background: white; }
.search-icon { color: #8290a8; font-size: 21px; line-height: 1; }
.search-wrap input { width: 100%; height: 40px; border: 0; outline: 0; color: var(--ink); background: transparent; padding: 0 10px; font-size: 13px; }
.search-wrap input::placeholder { color: #9aa6b8; }
.icon-button, .ghost-button { min-height: 38px; border: 0; color: #66758e; background: transparent; }
.icon-button { min-width: 38px; padding: 0 6px; font-size: 22px; }
.ghost-button { padding: 7px 12px; border: 1px solid var(--line); border-radius: 10px; font-size: 12px; background: white; }
.ghost-button:hover, .icon-button:hover { color: var(--accent); }

.workspace { display: grid; grid-template-columns: 210px minmax(0, 1fr) 336px; gap: 16px; width: min(1680px, 100%); margin: 0 auto; padding: 16px; }
.panel, .graph-card { border: 1px solid var(--line); border-radius: 15px; background: var(--panel); box-shadow: var(--shadow); }
.chapter-panel { min-height: calc(100svh - 100px); padding: 16px 12px; display: flex; flex-direction: column; }
.panel-heading { display:flex; align-items:center; justify-content:space-between; padding: 0 6px 12px; font-size: 13px; font-weight: 800; }
.count-badge { min-width: 54px; padding: 4px 6px; border-radius: 99px; color: #5d6a7f; background: #f0f3f8; text-align: center; font-size: 11px; font-weight: 700; }
.chapter-list { display: grid; gap: 5px; }
.chapter-item { width: 100%; min-height: 44px; display: flex; align-items: center; gap: 9px; padding: 8px 9px; border: 1px solid transparent; border-radius: 10px; color: #58667d; background: transparent; text-align: left; font-size: 12px; }
.chapter-item:hover, .chapter-item.active { color: var(--accent); border-color: #ccd7ff; background: var(--accent-soft); }
.chapter-index { width: 24px; height: 24px; display: grid; place-items: center; flex: 0 0 auto; border-radius: 7px; color: white; background: var(--chapter); font-size: 10px; font-weight: 800; }
.chapter-item.active .chapter-index { background: var(--accent); }
.legend { margin-top: auto; padding: 14px 8px 4px; border-top: 1px solid var(--line); color: var(--muted); font-size: 11px; line-height: 1.7; }
.legend strong { display:block; margin-bottom: 4px; color: var(--ink); }
.legend p { margin: 0 0 8px; }
.legend-line { width: 17px; height: 2px; display:inline-block; margin: 0 7px 3px 0; background: var(--chapter); }
.legend-line.related { background: #a9b6cd; }

.main-stage { min-width: 0; }
.stage-toolbar { min-height: 51px; display:flex; align-items:center; justify-content:space-between; gap: 12px; padding: 0 2px 11px; }
.stage-heading { min-width: 0; }
.stage-heading strong { display: inline-block; font-size: 16px; }
.stage-heading span { display: inline-block; margin-left: 8px; color: var(--muted); font-size: 12px; }
.toolbar-actions { display:flex; gap:5px; flex: 0 0 auto; }
.view-button { min-height: 36px; padding: 7px 10px; border: 1px solid var(--line); border-radius: 9px; color: #62718a; background: white; font-size: 11px; }
.view-button.active, .view-button:hover { color: var(--accent); border-color: #c1ceff; background: var(--accent-soft); }

.graph-card { position: relative; min-height: 600px; overflow: hidden; }
.graph-scroller { height: clamp(500px, calc(100svh - 178px), 760px); overflow: auto; overscroll-behavior: contain; touch-action: pan-x pan-y; }
#graph { display:block; min-width: 280px; background: linear-gradient(135deg, #ffffff 0%, #f8faff 100%); }
.edge { fill: none; stroke: #d3dbea; stroke-width: 1.5; }
.edge.relation { stroke: #b8c4d8; stroke-dasharray: 3 5; }
.edge.active-edge { stroke: #7590ea; stroke-width: 2.4; }
.node { cursor: pointer; }
.node-surface { fill: #fff; stroke: #dce3ee; stroke-width: 1; filter: drop-shadow(0 4px 8px rgba(39,55,90,.08)); }
.node.chapter .node-surface { fill: var(--chapter); stroke: var(--chapter); }
.node.concept .node-surface { fill: #fff; }
.node.selected .node-surface { stroke: #f4b740; stroke-width: 3; }
.node.neighbor:not(.selected) .node-surface { stroke: #aebdf1; }
.node-accent { fill: var(--concept); }
.node-title { fill: #27344c; font-size: 12px; font-weight: 800; }
.node-subtitle { fill: #748198; font-size: 10px; }
.chapter-label { fill: #fff; font-size: 12px; font-weight: 800; }
.empty-state { position:absolute; inset:0; display:grid; place-items:center; color:var(--muted); font-size:13px; background:rgba(255,255,255,.75); }
.hidden { display:none; }
.stage-note { padding: 8px 2px 0; color: #8a95a6; font-size: 11px; }

.detail-panel { min-height: calc(100svh - 100px); padding: 18px; overflow: hidden; }
.detail-heading { display:flex; align-items:flex-start; justify-content:space-between; gap:10px; }
.detail-kicker { color: var(--accent); font-size: 10px; font-weight: 800; letter-spacing: .08em; }
.detail-heading h1 { margin: 5px 0 0; font-size: 20px; line-height: 1.3; }
.favorite-button { min-width: 42px; min-height: 42px; border: 1px solid var(--line); border-radius: 10px; color: #7b8799; background: white; font-size: 19px; }
.favorite-button.active { color: #b7791f; border-color: #efd49f; background: #fff8e9; }
.detail-tabs { display:flex; gap: 5px; margin: 16px -2px 12px; padding-bottom: 7px; border-bottom: 1px solid var(--line); overflow-x:auto; scrollbar-width:none; }
.detail-tabs::-webkit-scrollbar { display:none; }
.detail-tabs button { min-height: 38px; flex: 0 0 auto; padding: 6px 10px; border: 0; border-radius: 8px; color: #68768b; background: transparent; font-size: 12px; }
.detail-tabs button[aria-selected="true"] { color: var(--accent); background: var(--accent-soft); font-weight: 800; }
.detail-body { height: calc(100svh - 226px); min-height: 300px; overflow-y:auto; padding-right: 3px; overscroll-behavior: contain; }
.chapter-intro { margin: 0 0 15px; color: #5d6b81; font-size: 13px; line-height: 1.7; }
.section-title { margin: 18px 0 9px; padding-top: 14px; border-top:1px solid var(--line); font-size:12px; }
.section-title.first { margin-top: 0; padding-top: 0; border-top:0; }
.formula-card, .condition-card, .reference-card { padding: 12px; border: 1px solid #e8edf4; border-radius: 11px; background: #fbfcfe; }
.formula-card h3, .condition-card h3 { margin: 0 0 8px; font-size: 11px; }
.condition-card { margin-top: 9px; }
.condition-card p, .reference-card p, .understanding p { margin:0; color:#596880; font-size:12px; line-height:1.75; }
.math-scroll { max-width:100%; overflow-x:auto; overflow-y:hidden; padding: 4px 3px; -webkit-overflow-scrolling: touch; }
.math-scroll .katex-display { margin: .25em 0; min-width: max-content; text-align:left; }
.theorem-formula { margin: 3px 0 2px; }
.theorem-formula .katex-display { text-align: left; }
.theorem-list, .method-list { margin: 0; padding-left: 19px; }
.theorem-list li, .method-list li { margin: 0 0 8px; color: #596880; font-size: 12px; line-height: 1.7; }
.theorem-list .math-scroll { margin-left: -3px; }
.prerequisite-list, .related-list { display:flex; flex-wrap:wrap; gap: 7px; }
.prerequisite-list span { padding: 6px 9px; border-radius: 99px; color: #53627a; background: #f0f3f8; font-size:11px; }
.related-list { display:grid; gap: 7px; }
.related-button { width: 100%; min-height: 40px; display:flex; align-items:center; justify-content:space-between; padding: 8px 10px; border:1px solid var(--line); border-radius:9px; color:#53627a; background:#fff; text-align:left; font-size:12px; }
.related-button:hover { color:var(--accent); border-color:#c4d0ff; background:var(--accent-soft); }
.related-button span { color:#98a6ba; }
.reference-label { margin-bottom: 6px; color:var(--accent); font-size:10px; font-weight:800; letter-spacing:.05em; }
.reference-card + .reference-card { margin-top:10px; }
.reference-card h3 { margin: 0 0 7px; font-size:13px; }
.understanding { margin-top: 16px; border-top: 1px solid var(--line); padding-top: 13px; }
.understanding summary { cursor:pointer; color: var(--ink); font-size: 12px; font-weight:800; }
.muted { color: var(--muted); font-size: 12px; }

@media (max-width: 1180px) {
  .workspace { grid-template-columns: 180px minmax(0, 1fr) 300px; gap: 12px; padding: 12px; }
  .chapter-panel, .detail-panel { min-height: calc(100svh - 92px); }
  .detail-panel { padding: 15px; }
  .brand { min-width: 215px; }
}
@media (max-width: 900px) {
  .topbar { flex-wrap:wrap; gap: 9px 12px; padding: 10px 14px; }
  .brand { min-width: 0; flex: 1 1 auto; }
  .search-wrap { order: 3; flex-basis: 100%; }
  .workspace { grid-template-columns: 164px minmax(0, 1fr); }
  .detail-panel { grid-column: 1 / -1; min-height: 0; }
  .detail-body { height: min(430px, 48svh); }
}
@media (max-width: 639px) {
  .topbar { min-height: 63px; }
  .brand strong { font-size: 14px; }
  .brand small { font-size: 10px; }
  .ghost-button { padding-inline: 9px; }
  .workspace { display:flex; flex-direction:column; gap: 10px; padding: 10px; }
  .chapter-panel { order: 0; min-height: 0; padding: 10px; }
  .panel-heading { padding-bottom: 8px; }
  .chapter-list { display:flex; gap: 7px; overflow-x:auto; padding-bottom: 2px; scrollbar-width:none; }
  .chapter-list::-webkit-scrollbar { display:none; }
  .chapter-item { width: auto; min-width: max-content; min-height: 42px; padding: 7px 9px; }
  .chapter-index { width: 22px; height: 22px; }
  .legend { display:none; }
  .main-stage { order: 1; }
  .detail-panel { order: 2; padding: 14px; }
  .stage-toolbar { align-items:flex-start; flex-direction:column; padding-bottom: 8px; }
  .stage-heading span { display:block; margin: 3px 0 0; }
  .toolbar-actions { width:100%; }
  .view-button { flex:1; }
  .graph-card { min-height: 460px; }
  .graph-scroller { height: min(500px, 64svh); }
  .detail-body { height: 400px; }
  .detail-heading h1 { font-size: 18px; }
}
@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; }
}

