:root {
  --bg: #F5F6F8;
  --panel: #FFFFFF;
  --border: #E3E6EA;
  --text: #2B2F36;
  --muted: #9AA0A6;
  --accent: #3B5BDB;
  --shadow: 0 4px 16px rgba(31, 41, 55, 0.10);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
}

/* ---- 画布区（占满全屏） ---- */
#canvasWrap {
  position: relative;
  height: 100vh;
  background: var(--panel);
}
#graphCanvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: grab;
}
#graphCanvas.dragging { cursor: grabbing; }

/* ---- 左上角菜单按钮 ---- */
#menuBtn {
  position: absolute;
  top: 14px;
  left: 14px;
  z-index: 21; /* 高于遮罩(20)；抽屉(40)打开时按钮仍在其覆盖区内，属正常 */
  width: 38px;
  height: 38px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--panel);
  box-shadow: var(--shadow);
  color: var(--text);
  font-size: 17px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease, transform 0.15s ease;
}
#menuBtn:hover { background: #F0F2F5; }
#menuBtn:active { transform: scale(0.94); }

/* ---- 侧边抽屉导航（默认隐藏，translateX 滑出） ---- */
#sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: 264px;
  z-index: 40;
  background: var(--panel);
  border-right: 1px solid var(--border);
  box-shadow: var(--shadow);
  padding: 18px 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  transform: translateX(-100%);
  transition: transform 0.25s ease;
}
#sidebar.open { transform: translateX(0); }

.brand {
  display: flex;
  align-items: baseline;
  gap: 8px;
  white-space: nowrap;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}
.brand-icon { font-size: 20px; }
.brand-name { font-size: 19px; font-weight: 700; letter-spacing: 1px; }
.brand-sub { font-size: 12px; color: var(--muted); }

.side-block {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.side-label {
  font-size: 12px;
  color: var(--muted);
  letter-spacing: 1px;
}

#librarySelect,
#searchInput {
  font: inherit;
  font-size: 13px;
  padding: 8px 10px;
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #FAFBFC;
  color: var(--text);
  outline: none;
}
#librarySelect { cursor: pointer; }
#librarySelect:focus,
#searchInput:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(59, 91, 219, 0.12);
}

.field.toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  user-select: none;
  font-size: 13px;
  color: var(--text);
}
.field.toggle input {
  width: 15px;
  height: 15px;
  accent-color: var(--accent);
  cursor: pointer;
  margin: 0;
}

.stat { font-size: 12px; color: var(--muted); line-height: 1.6; }
.stat.warn { color: #D64A45; }

/* ---- 遮罩：打开侧边栏时盖住画布，点击关闭 ---- */
#overlay {
  position: absolute;
  inset: 0;
  z-index: 20;
  background: rgba(31, 41, 55, 0.35);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}
#overlay.show {
  opacity: 1;
  pointer-events: auto;
}

/* ---- 图例 ---- */
#legend {
  position: absolute;
  top: 14px;
  right: 14px;
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow);
  padding: 10px 14px;
  font-size: 12px;
  line-height: 1.7;
  user-select: none;
  pointer-events: none;
}
.legend-title {
  font-weight: 600;
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 1px;
  margin: 4px 0 2px;
}
.legend-title:first-child { margin-top: 0; }
.legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
}
.legend-line {
  display: inline-block;
  width: 22px;
  height: 3px;
  border-radius: 2px;
}

/* ---- 底部提示 ---- */
#hint {
  position: absolute;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 12px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.85);
  padding: 5px 14px;
  border-radius: 20px;
  border: 1px solid var(--border);
  white-space: nowrap;
  user-select: none;
  pointer-events: none;
}

/* ---- 悬停卡片 ---- */
#tooltip {
  position: absolute;
  max-width: 280px;
  min-width: 180px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 12px 14px;
  font-size: 13px;
  pointer-events: none;
  z-index: 10;
}
#tooltip.hidden { display: none; }

.tt-head {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 4px;
}
.tt-word {
  font-size: 17px;
  font-weight: 700;
  color: var(--accent);
}
.tt-phone { font-size: 13px; color: var(--muted); }

.tt-sense {
  font-size: 13px;
  color: var(--text);
  padding: 3px 0;
  line-height: 1.5;
}
.tt-sense .tt-pos {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  color: var(--accent);
  background: rgba(59, 91, 219, 0.08);
  border-radius: 4px;
  padding: 1px 6px;
  margin-right: 6px;
  vertical-align: 1px;
}

.tt-example {
  font-size: 12px;
  color: #495057;
  font-style: italic;
  background: #F3F5F7;
  border-left: 3px solid var(--border);
  padding: 4px 8px;
  border-radius: 0 6px 6px 0;
  margin: 4px 0;
}

.tt-rel-title {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  margin: 8px 0 2px;
  letter-spacing: 1px;
}
.tt-rels {
  list-style: none;
  margin: 0;
  padding: 0;
}
.tt-rels li {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  padding: 2px 0;
}
.tt-rels em {
  font-style: normal;
  color: var(--muted);
  font-size: 11.5px;
  margin-left: auto;
  padding-left: 8px;
}
.tt-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex: none;
}
