/* 主题脑图：横向 tidy tree，复用 app.css 的纸面 token。 */

.topic-map-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin: 1rem 0 0.75rem;
}

.topic-map-figure {
  margin: 0 0 1.5rem;
}

.topic-map-surface {
  position: relative;
  width: 100%;
  height: min(70vh, 38rem);
  min-height: 22rem;
  overflow: hidden;
  border: 1px solid var(--rule);
  border-radius: 6px;
  background: var(--card);
  touch-action: none;
}

.topic-map-surface svg {
  display: block;
  width: 100%;
  height: 100%;
  cursor: default;
  user-select: none;
}

/* 只有真正拖动时才显示抓取手势；平时悬停不暗示「可拖」。 */
.topic-map-surface svg.is-panning {
  cursor: grabbing;
}

.topic-map-surface .topic-map-world a,
.topic-map-surface .topic-map-toggle {
  cursor: pointer;
}

.topic-map-surface .topic-map-node rect {
  fill: var(--card);
  stroke: var(--control-border);
  stroke-width: 1;
  rx: 6;
}

.topic-map-surface .topic-map-node--group rect {
  fill: var(--selection);
  stroke: var(--tab);
}

.topic-map-surface .topic-map-node text {
  fill: var(--ink);
  font-family: var(--body);
  font-size: 13px;
  dominant-baseline: central;
  pointer-events: none;
}

.topic-map-surface .topic-map-node .topic-map-counts {
  fill: var(--ink-muted);
  font-family: var(--mono);
  font-size: 11px;
}

/* 第三行：下一层由几个主题、几张卡片组成。空层不渲染，所以这条样式只作用于有下级的节点。 */
.topic-map-surface .topic-map-node .topic-map-children {
  fill: var(--ink-muted);
  font-family: var(--body);
  font-size: 10px;
  opacity: 0.85;
}

/* 加载中 / 失败：第三行改作状态提示。 */
.topic-map-surface .topic-map-node .topic-map-status {
  fill: var(--ink-muted);
  font-family: var(--body);
  font-size: 10px;
}

.topic-map-surface .topic-map-node--busy rect {
  opacity: 0.6;
}

.topic-map-surface .topic-map-node--error rect {
  stroke: var(--error);
  stroke-width: 1.5;
}

.topic-map-surface .topic-map-node--error .topic-map-status {
  fill: var(--error);
}

/* 卡片节点：虚线边框 + 实心左侧色条，和主题节点的实线矩形一眼可分。 */
.topic-map-surface .topic-map-node--card rect {
  fill: var(--card);
  stroke: var(--ink-muted);
  stroke-dasharray: 4 3;
}

/* 左侧色条：卡片节点与主题节点的第二重区分（色条不跟随虚线）。 */
.topic-map-surface .topic-map-node--card .topic-map-card-bar {
  fill: var(--tab);
  stroke: none;
  stroke-dasharray: none;
}

.topic-map-surface .topic-map-node--card text {
  font-size: 12px;
}

.topic-map-surface .topic-map-node .topic-map-subtitle {
  fill: var(--ink-muted);
  font-family: var(--body);
  font-size: 10px;
}

/* 「还有 N 张」：透明底 + 点线，暗示它是操作而不是内容。 */
.topic-map-surface .topic-map-node--more rect {
  fill: transparent;
  stroke: var(--rule);
  stroke-dasharray: 2 4;
}

.topic-map-surface .topic-map-node--more text {
  fill: var(--ink-muted);
  font-family: var(--body);
  font-size: 11px;
}

.topic-map-surface .topic-map-node--more:focus-visible rect {
  stroke: var(--ink);
  stroke-width: 2;
}

.topic-map-surface .topic-map-edge {
  fill: none;
  stroke: var(--control-border);
  stroke-width: 1;
}

.topic-map-surface .topic-map-alias-block rect {
  fill: var(--desk);
  stroke: var(--ink-muted);
  stroke-width: 1;
  stroke-dasharray: 4 3;
  rx: 5;
}

.topic-map-surface .topic-map-alias-block text {
  fill: var(--ink-muted);
  font-family: var(--body);
  font-size: 11px;
  dominant-baseline: central;
  pointer-events: none;
}

.topic-map-surface .topic-map-alias-edge {
  fill: none;
  stroke: var(--ink-muted);
  stroke-width: 1;
  stroke-dasharray: 4 3;
}

.topic-map-surface .topic-map-toggle circle {
  fill: var(--tab);
}

.topic-map-surface .topic-map-toggle text {
  fill: var(--card);
  font-family: var(--body);
  font-size: 12px;
  text-anchor: middle;
  dominant-baseline: central;
  pointer-events: none;
}

.topic-map-surface .topic-map-toggle:focus-visible circle {
  stroke: var(--ink);
  stroke-width: 2;
}

.topic-map-surface a:focus-visible rect,
.topic-map-surface a:focus-visible text {
  outline: none;
}

.topic-map-surface .topic-map-node a:focus-visible rect {
  stroke: var(--ink);
  stroke-width: 2;
}

/* 文本版层级：无 JS 时的可读降级，也作为屏幕阅读器的可靠结构。 */

.topic-map-text {
  margin-bottom: 2rem;
}

.topic-map-list {
  list-style: none;
  margin: 0.5rem 0 0;
  padding-left: 1.25rem;
  border-left: 1px solid var(--rule);
}

.topic-map-item {
  margin: 0.4rem 0;
}

.topic-map-link {
  font-weight: 500;
}

.topic-map-counts {
  color: var(--ink-muted);
  font-family: var(--mono);
  font-size: 0.85rem;
  margin-left: 0.4rem;
}

.topic-map-covered::before {
  content: "覆盖 ";
}

/* 文本版层级里的「N 个子主题」，与 SVG 卡片第三行对应。 */
.topic-map-childcount {
  color: var(--ink-muted);
  font-size: 0.8rem;
  margin-left: 0.4rem;
}

.topic-map-alias-note {
  color: var(--ink-muted);
  margin-left: 0.6rem;
  font-size: 0.9rem;
}

.topic-map-alias-note::before {
  content: "⇢ ";
}

.topic-map-alias-note a {
  margin-left: 0.35rem;
}

.topic-map-center {
  border-left: 3px solid var(--tab);
  padding-left: 1rem;
  margin-bottom: 0.5rem;
}

.topic-map-center h2 {
  margin-bottom: 0.25rem;
}

/* 首页：左侧根学科导航 + 右侧单棵脑图；下钻页无侧栏时自动单栏。 */
.topic-map-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 1.25rem;
  align-items: start;
}

.topic-map-layout.has-roots {
  grid-template-columns: 15rem minmax(0, 1fr);
}

@media (max-width: 860px) {
  .topic-map-layout.has-roots {
    grid-template-columns: minmax(0, 1fr);
  }
  /* 单列时侧栏在画布上方，sticky 会一直盖住往下滚的内容。 */
  .topic-map-roots {
    position: static;
    max-height: 16rem;
  }
}

.topic-map-main {
  min-width: 0;
}

.topic-map-roots {
  border: 1px solid var(--rule);
  border-radius: 6px;
  background: var(--card);
  padding: 0.75rem 0.5rem;
  position: sticky;
  top: 1rem;
  max-height: calc(100vh - 2rem);
  overflow-y: auto;
}

.topic-map-roots-title {
  margin: 0 0.55rem 0.5rem;
  font-size: 0.8rem;
  letter-spacing: 0.08em;
  color: var(--ink-muted);
}

.topic-map-roots ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

.topic-map-roots a {
  display: block;
  padding: 0.45rem 0.55rem;
  border-left: 3px solid transparent;
  border-radius: 3px;
  color: var(--ink);
  text-decoration: none;
}

.topic-map-roots a:hover {
  background: var(--selection);
}

.topic-map-roots a[aria-current="page"] {
  border-left-color: var(--tab);
  background: var(--selection);
  font-weight: 600;
}

.topic-map-root-name {
  display: block;
  font-size: 0.9rem;
}

.topic-map-root-meta {
  display: block;
  margin-top: 0.15rem;
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--ink-muted);
}

.topic-map-scope {
  margin-top: 0.5rem;
  font-size: 0.9rem;
  color: var(--ink-muted);
}

/* 过滤开关是链接：无 JS 时也能切换，样式与工具栏按钮对齐。 */
.topic-map-filter-link {
  display: inline-flex;
  align-items: center;
  padding: 0.35rem 0.7rem;
  border: 1px solid var(--control-border);
  border-radius: 4px;
  background: var(--card);
  color: var(--ink);
  font: inherit;
  font-size: 0.85rem;
  text-decoration: none;
  cursor: pointer;
}

.topic-map-filter-link[aria-pressed="true"] {
  border-color: var(--tab);
  background: var(--selection);
}

.topic-map-filter-link:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
}

/* 过滤后 0 卡的主题：保留骨架，但视觉弱化，避免误以为可展开。 */
.topic-map-surface .topic-map-node--empty rect {
  opacity: 0.55;
  stroke-dasharray: 3 3;
}

.topic-map-surface .topic-map-node--empty text {
  fill: var(--ink-muted);
}

