:root {
  --bg: #0f1419;
  --bg-elev: #1a2332;
  --bg-panel: #151c27;
  --ink: #e8eef7;
  --muted: #8b9bb4;
  --line: #2a3548;
  --accent: #5b8def;
  --accent-soft: rgba(91, 141, 239, 0.15);
  --shadow: 0 8px 24px rgba(0,0,0,.35);
  --radius: 14px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Noto Sans CJK SC", "Microsoft YaHei", sans-serif;
  --branch-pi: #f59e0b;
  --branch-open: #22c55e;
  --branch-repr: #a78bfa;
  --branch-meet: #38bdf8;
  --branch-proj: #f472b6;
  --branch-ind: #fb7185;
  --branch-concept: #94a3b8;
  --branch-root: #5b8def;
}
[data-theme="light"] {
  --bg: #f4f6f9;
  --bg-elev: #ffffff;
  --bg-panel: #ffffff;
  --ink: #1a2332;
  --muted: #64748b;
  --line: #e2e8f0;
  --accent: #2563eb;
  --accent-soft: #eff6ff;
  --shadow: 0 4px 16px rgba(15,23,42,.08);
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  font-size: 14.5px;
  line-height: 1.5;
}
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0); border: 0;
}
.app { display: flex; flex-direction: column; height: 100%; min-height: 100dvh; }
.topbar {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between;
  gap: 0.75rem 1rem; padding: 0.75rem 1rem;
  background: var(--bg-elev); border-bottom: 1px solid var(--line);
  box-shadow: var(--shadow);
  z-index: 10;
}
.brand { display: flex; align-items: center; gap: 0.7rem; }
.logo {
  width: 2.2rem; height: 2.2rem; border-radius: 10px;
  display: grid; place-items: center;
  background: linear-gradient(135deg, #5b8def, #a78bfa);
  color: #fff; font-size: 1.1rem; font-weight: 700;
}
.brand h1 { margin: 0; font-size: 1.1rem; font-weight: 720; letter-spacing: -0.02em; }
.subtitle { margin: 0.1rem 0 0; color: var(--muted); font-size: 12.5px; }
.toolbar { display: flex; flex-wrap: wrap; gap: 0.45rem; align-items: center; }
.search-wrap input, .toolbar select, .toolbar button {
  font: inherit; border-radius: 999px; border: 1px solid var(--line);
  background: var(--bg); color: var(--ink); padding: 0.4rem 0.85rem;
}
.search-wrap input { min-width: 12rem; }
.toolbar button { cursor: pointer; background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.toolbar button:hover { filter: brightness(1.08); }
.main { flex: 1; display: grid; grid-template-columns: 1fr min(360px, 38vw); min-height: 0; }
.graph-pane {
  position: relative; min-height: 0; background:
    radial-gradient(ellipse at 30% 20%, rgba(91,141,239,.08), transparent 50%),
    radial-gradient(ellipse at 80% 80%, rgba(167,139,250,.06), transparent 45%),
    var(--bg);
}
.mm-svg { width: 100%; height: 100%; display: block; }
.graph-hint {
  position: absolute; left: 1rem; bottom: 1rem;
  color: var(--muted); font-size: 12px; pointer-events: none;
  background: color-mix(in srgb, var(--bg-elev) 85%, transparent);
  padding: 0.25rem 0.6rem; border-radius: 999px; border: 1px solid var(--line);
}
.stats {
  position: absolute; right: 1rem; bottom: 1rem;
  color: var(--muted); font-size: 12px;
  background: color-mix(in srgb, var(--bg-elev) 85%, transparent);
  padding: 0.25rem 0.6rem; border-radius: 999px; border: 1px solid var(--line);
}
.detail-pane {
  border-left: 1px solid var(--line); background: var(--bg-panel);
  overflow: auto; padding: 1rem 1.05rem 1.5rem;
}
.detail-empty h2 { margin: 0 0 0.4rem; font-size: 1.05rem; }
.detail-empty p { color: var(--muted); margin: 0 0 1rem; }
.legend { list-style: none; padding: 0; margin: 0; display: grid; gap: 0.4rem; }
.legend li {
  display: flex; align-items: center; gap: 0.5rem;
  font-size: 12.5px; color: var(--muted);
}
.legend .swatch {
  width: 0.85rem; height: 0.85rem; border-radius: 999px;
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--ink) 8%, transparent);
}
.detail-body { position: relative; }
.detail-body.hidden, .detail-empty.hidden { display: none; }
.close-detail {
  position: absolute; right: 0; top: 0; border: none; background: transparent;
  color: var(--muted); font-size: 1.4rem; cursor: pointer; line-height: 1;
}
.detail-header { padding-right: 1.5rem; }
.badge {
  display: inline-flex; padding: 0.15rem 0.55rem; border-radius: 999px;
  font-size: 11.5px; font-weight: 700; background: var(--accent-soft); color: var(--accent);
}
.detail-header h2 { margin: 0.4rem 0 0.15rem; font-size: 1.2rem; }
.detail-label { margin: 0; color: var(--muted); font-size: 12.5px; }
.summary { margin: 0.75rem 0; color: var(--ink); }
.tags { display: flex; flex-wrap: wrap; gap: 0.35rem; margin-bottom: 0.85rem; }
.tags span {
  font-size: 11.5px; padding: 0.12rem 0.5rem; border-radius: 999px;
  background: var(--bg); border: 1px solid var(--line); color: var(--muted);
}
.block { margin: 0.9rem 0; }
.block h3 { margin: 0 0 0.4rem; font-size: 0.85rem; color: var(--muted); text-transform: none; letter-spacing: 0.02em; }
.papers, .neighbors { list-style: none; padding: 0; margin: 0; display: grid; gap: 0.35rem; }
.papers a, .neighbors button, .deepread-cta a {
  color: var(--accent); text-decoration: none; font-weight: 600;
}
.papers a:hover, .deepread-cta a:hover { text-decoration: underline; }
.neighbors button {
  appearance: none; border: 1px solid var(--line); background: var(--bg);
  border-radius: 999px; padding: 0.25rem 0.65rem; cursor: pointer; font: inherit;
  color: var(--ink); text-align: left;
}
.neighbors button:hover { border-color: var(--accent); color: var(--accent); }
.deepread-cta {
  margin: 0.5rem 0 0.85rem; padding: 0.65rem 0.8rem;
  border-radius: 12px; background: var(--accent-soft); border: 1px solid color-mix(in srgb, var(--accent) 35%, var(--line));
}
.notion-link a { color: var(--muted); font-size: 12.5px; }
.notion-link a:hover { color: var(--accent); }

/* Markmap node polish via foreignObject / text */
.mm-svg .markmap-node foreignObject > div,
.mm-svg .markmap-node text {
  font-family: var(--font) !important;
}
.mm-svg a { color: inherit; text-decoration: none; }

@media (max-width: 860px) {
  .main { grid-template-columns: 1fr; grid-template-rows: minmax(55vh, 1fr) auto; }
  .detail-pane { border-left: none; border-top: 1px solid var(--line); max-height: 42vh; }
  .search-wrap input { min-width: 8rem; }
}

.mm-viewport {
  width: 100%;
  height: 100%;
  overflow: hidden;
  cursor: grab;
  touch-action: none;
}
.mm-viewport.dragging { cursor: grabbing; }
.mm-svg { width: 100%; height: 100%; display: block; }
.mm-svg .link {
  fill: none;
  stroke-width: 2.2;
  opacity: 0.55;
}
.mm-svg .node-pill {
  cursor: pointer;
  filter: drop-shadow(0 3px 8px rgba(0,0,0,.22));
}
.mm-svg .node-pill:hover rect {
  stroke-width: 2.5;
  filter: brightness(1.08);
}
.mm-svg .node-pill text {
  font-family: var(--font);
  fill: var(--ink);
  pointer-events: none;
  user-select: none;
}
.mm-svg .node-pill.dim { opacity: 0.28; }
.mm-svg .link.dim { opacity: 0.08; }
