/* ================================================================
   词汇树 · 样式
   - 白天/夜晚：body[data-mode="light" | "dark"]
   - 画布风格：body[data-theme="default" | "neon" | "pastel" | "forest"]
   ================================================================ */
* { box-sizing: border-box; margin: 0; padding: 0; }

/* ---------- 基础变量 ---------- */
body {
  /* mode 基础色 */
  --bg-0: #0b1120;
  --bg-1: #0f172a;
  --panel: rgba(15, 23, 42, 0.86);
  --panel-solid: #111a2e;
  --line: rgba(148, 163, 184, 0.22);
  --text: #e2e8f0;
  --text-dim: #94a3b8;
  --text-on: #ffffff;
  --accent: #38bdf8;
  --accent-2: #6366f1;
  --btn-bg: rgba(148, 163, 184, 0.1);
  --btn-bg-hover: rgba(148, 163, 184, 0.22);
  --input-bg: rgba(2, 6, 23, 0.55);
  --radius: 12px;
  /* theme 背景装饰（由下方各主题覆盖） */
  --bg-deco: radial-gradient(1100px 700px at 18% 8%, #1e293b 0%, transparent 60%),
    radial-gradient(900px 600px at 85% 90%, #172554 0%, transparent 55%),
    linear-gradient(160deg, var(--bg-1), var(--bg-0));
  --node-glow: 0 6px 18px rgba(0, 0, 0, 0.45);
  --line-color: rgba(148, 163, 184, 0.4);
  --node-btn-bg: rgba(2, 6, 23, 0.72);
}

body[data-mode="light"] {
  --bg-0: #eef2f7;
  --bg-1: #f8fafc;
  --panel: rgba(255, 255, 255, 0.9);
  --panel-solid: #ffffff;
  --line: rgba(51, 65, 85, 0.18);
  --text: #0f172a;
  --text-dim: #64748b;
  --text-on: #ffffff;
  --accent: #2563eb;
  --accent-2: #7c3aed;
  --btn-bg: rgba(15, 23, 42, 0.06);
  --btn-bg-hover: rgba(15, 23, 42, 0.12);
  --input-bg: rgba(255, 255, 255, 0.9);
  --node-glow: 0 6px 16px rgba(15, 23, 42, 0.18);
  --line-color: rgba(71, 85, 105, 0.4);
  --node-btn-bg: rgba(255, 255, 255, 0.85);
}

/* ---------- 画布风格 ---------- */
body[data-theme="default"] {
  --bg-deco: radial-gradient(1100px 700px at 18% 8%, #1e293b 0%, transparent 60%),
    radial-gradient(900px 600px at 85% 90%, #172554 0%, transparent 55%),
    linear-gradient(160deg, var(--bg-1), var(--bg-0));
}
body[data-mode="light"][data-theme="default"] {
  --bg-deco: radial-gradient(1000px 600px at 15% 10%, #dbeafe 0%, transparent 55%),
    radial-gradient(800px 500px at 88% 88%, #e9d5ff 0%, transparent 50%),
    linear-gradient(160deg, #f8fafc, #eef2f7);
}

body[data-theme="neon"] {
  --bg-deco: radial-gradient(1200px 800px at 20% 10%, rgba(255, 45, 149, 0.22) 0%, transparent 55%),
    radial-gradient(1000px 700px at 85% 90%, rgba(0, 229, 255, 0.18) 0%, transparent 50%),
    radial-gradient(700px 500px at 60% 40%, rgba(124, 77, 255, 0.14) 0%, transparent 60%),
    linear-gradient(160deg, #06060f, #020308);
  --line-color: rgba(0, 229, 255, 0.35);
  --node-glow: 0 0 18px rgba(0, 229, 255, 0.35), 0 6px 24px rgba(0, 0, 0, 0.5);
}
body[data-mode="light"][data-theme="neon"] {
  --bg-deco: radial-gradient(1000px 650px at 20% 12%, #f3e8ff 0%, transparent 55%),
    radial-gradient(900px 600px at 85% 88%, #cffafe 0%, transparent 50%),
    linear-gradient(160deg, #faf7ff, #eef2ff);
  --line-color: rgba(124, 77, 255, 0.3);
  --node-glow: 0 0 12px rgba(124, 77, 255, 0.25), 0 6px 16px rgba(15, 23, 42, 0.12);
}

body[data-theme="pastel"] {
  --bg-deco: radial-gradient(1100px 700px at 20% 15%, #fde68a 0%, transparent 55%),
    radial-gradient(900px 650px at 85% 85%, #fbcfe8 0%, transparent 55%),
    radial-gradient(700px 500px at 55% 30%, #bae6fd 0%, transparent 55%),
    linear-gradient(160deg, #fdf4ff, #fef9c3);
  --line-color: rgba(148, 110, 190, 0.35);
  --node-glow: 0 6px 18px rgba(180, 120, 220, 0.25);
  --node-btn-bg: rgba(255, 255, 255, 0.92);
}
body[data-mode="dark"][data-theme="pastel"] {
  --bg-deco: radial-gradient(1100px 700px at 20% 15%, rgba(253, 230, 138, 0.14) 0%, transparent 55%),
    radial-gradient(900px 650px at 85% 85%, rgba(251, 207, 232, 0.12) 0%, transparent 55%),
    linear-gradient(160deg, #171226, #0c0a16);
}

body[data-theme="forest"] {
  --bg-deco: radial-gradient(1100px 700px at 20% 12%, #14532d 0%, transparent 60%),
    radial-gradient(900px 600px at 85% 88%, #1e3a2f 0%, transparent 55%),
    linear-gradient(160deg, #0a1f14, #06120c);
  --line-color: rgba(74, 222, 128, 0.3);
  --node-glow: 0 0 16px rgba(52, 211, 153, 0.28), 0 6px 20px rgba(0, 0, 0, 0.45);
}
body[data-mode="light"][data-theme="forest"] {
  --bg-deco: radial-gradient(1000px 650px at 20% 12%, #dcfce7 0%, transparent 55%),
    radial-gradient(900px 600px at 85% 88%, #ccfbf1 0%, transparent 50%),
    linear-gradient(160deg, #f2fbf6, #e7f5ee);
  --line-color: rgba(21, 128, 61, 0.3);
  --node-glow: 0 6px 16px rgba(21, 128, 61, 0.15);
}

/* ---------- 布局 ---------- */
html, body { height: 100%; overflow: hidden; }
body {
  display: flex;
  flex-direction: column;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", Roboto, sans-serif;
  color: var(--text);
  background-color: var(--bg-0);
  background-image: var(--bg-deco);
  background-attachment: fixed;
  transition: background 0.4s ease, color 0.3s ease;
  user-select: none;
  -webkit-user-select: none;
}

/* ---------- 顶部栏 ---------- */
.topbar {
  position: relative;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  padding: 9px 14px;
  background: var(--panel);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: baseline; gap: 8px; }
.brand-icon { font-size: 22px; }
.brand-name { font-size: 17px; font-weight: 700; letter-spacing: 1px; }
.brand-sub { font-size: 12px; color: var(--text-dim); }

.toolbar { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.sep { width: 1px; height: 22px; background: var(--line); margin: 0 4px; }

/* ---------- 按钮 ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 12px;
  font-size: 13px;
  font-family: inherit;
  color: var(--text);
  background: var(--btn-bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.18s, border-color 0.18s, transform 0.12s, box-shadow 0.18s;
}
.btn:hover { background: var(--btn-bg-hover); border-color: rgba(56, 189, 248, 0.6); }
.btn:active { transform: scale(0.94); }
.btn svg { display: block; }

.btn-primary {
  background: linear-gradient(135deg, var(--accent-2), var(--accent));
  border-color: transparent;
  font-weight: 600;
  color: var(--text-on);
  box-shadow: 0 4px 18px rgba(99, 102, 241, 0.35);
}
.btn-primary:hover { background: linear-gradient(135deg, #7c5cf6, #4cc7ff); border-color: transparent; }

.btn-icon { width: 34px; height: 34px; padding: 0; font-size: 15px; }

.select-wrap {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px 6px 10px;
  background: var(--btn-bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  cursor: pointer;
}
.select-icon { display: flex; color: var(--text-dim); }
.select-wrap select {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  outline: none;
}
.select-wrap select option { color: initial; background: #fff; }

/* 云同步状态点 */
.sync-status {
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--text-dim);
  transition: background 0.3s, box-shadow 0.3s;
}
.sync-status[data-state="saving"] { background: #fbbf24; box-shadow: 0 0 8px rgba(251, 191, 36, 0.8); }
.sync-status[data-state="saved"] { background: #34d399; box-shadow: 0 0 8px rgba(52, 211, 153, 0.8); }
.sync-status[data-state="offline"] { background: #f87171; box-shadow: 0 0 8px rgba(248, 113, 113, 0.8); }

/* ---------- 画布 ---------- */
#canvasWrap { position: relative; flex: 1; min-height: 0; overflow: hidden; }
#canvas {
  position: absolute; inset: 0;
  width: 100%; height: 100%; display: block;
  cursor: grab; touch-action: none;
}
#canvas.dragging { cursor: grabbing; }

.empty-hint {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  text-align: center; font-size: 15px; color: var(--text-dim); line-height: 2.2;
  pointer-events: none;
}

/* ---------- 类别中心节点 ---------- */
.cat-pill { cursor: pointer; }
.cat-bg {
  stroke: rgba(255, 255, 255, 0.35);
  stroke-width: 1.5;
  filter: var(--node-glow);
  transition: filter 0.2s;
}
.cat-pill:hover .cat-bg { filter: var(--node-glow) brightness(1.15); }
.cat-pill.dragging { opacity: 0.85; }
.cat-label { font-size: 15px; font-weight: 700; fill: #fff; letter-spacing: 1px; pointer-events: none; }
.cat-count { font-size: 10.5px; fill: rgba(255, 255, 255, 0.85); opacity: 0.9; pointer-events: none; }

/* 类别节点操作按钮 */
.cat-actions { opacity: 0.9; transition: opacity 0.15s; }
.node-btn { cursor: pointer; }
.node-btn circle {
  fill: var(--node-btn-bg);
  stroke: rgba(255, 255, 255, 0.45);
  stroke-width: 1;
  transition: fill 0.15s, stroke 0.15s;
}
.node-btn:hover circle { fill: var(--accent); stroke: #fff; }
.node-btn svg { pointer-events: none; display: block; }

/* ---------- 单词分支 ---------- */
.word-line {
  stroke: var(--line-color);
  stroke-width: 1.5;
  animation: drawLine 0.5s ease backwards;
}
body[data-theme="neon"] .word-line { filter: drop-shadow(0 0 4px rgba(0, 229, 255, 0.5)); }
body[data-theme="forest"] .word-line { filter: drop-shadow(0 0 4px rgba(52, 211, 153, 0.4)); }

.word-wrap { cursor: pointer; }
.word-inner {
  transform-origin: 0 0;
  animation: popIn 0.35s cubic-bezier(0.34, 1.56, 0.64, 1) backwards;
}
.word-bg {
  stroke: rgba(255, 255, 255, 0.4);
  stroke-width: 1;
  transition: filter 0.15s, stroke 0.15s;
}
.word-wrap:hover .word-bg {
  filter: brightness(1.18);
  stroke: #fff;
  stroke-width: 1.5;
}
.word-text {
  font-size: 12.5px;
  fill: #fff;
  font-weight: 500;
  dominant-baseline: central;
  pointer-events: none;
}
/* 单词节点操作按钮：默认隐藏，hover 显示 */
.word-actions { opacity: 0; transition: opacity 0.15s; }
.word-wrap:hover .word-actions { opacity: 1; }

@keyframes popIn {
  from { transform: scale(0); opacity: 0; }
  to   { transform: scale(1); opacity: 1; }
}
@keyframes drawLine {
  from { stroke-dasharray: var(--len, 1000); stroke-dashoffset: var(--len, 1000); opacity: 0.2; }
  to   { stroke-dasharray: var(--len, 1000); stroke-dashoffset: 0; opacity: 1; }
}

/* ---------- 悬浮详情卡 ---------- */
.tooltip {
  position: fixed;
  z-index: 60;
  width: 340px;
  max-height: min(72vh, 560px);
  overflow-y: auto;
  padding: 14px 16px;
  font-size: 13px;
  color: var(--text);
  background: var(--panel-solid);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.55);
  user-select: text;
  -webkit-user-select: text;
  transition: opacity 0.12s ease;
}
.tooltip.hidden { display: none; }
.tooltip::-webkit-scrollbar { width: 6px; }
.tooltip::-webkit-scrollbar-thumb { background: rgba(148, 163, 184, 0.3); border-radius: 3px; }

.tt-loading, .tt-missing { padding: 6px 2px; color: var(--text-dim); }
.tt-msg { margin-top: 6px; font-size: 12px; color: var(--text-dim); }

.tt-header { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; margin-bottom: 6px; }
.tt-word { font-size: 20px; font-weight: 700; }
.tt-phonetic { font-size: 14px; color: var(--accent); font-family: "Segoe UI", "Noto Sans", sans-serif; }

.tt-audio { display: flex; gap: 8px; margin: 6px 0 10px; }
.tt-audio button {
  flex: 1;
  padding: 6px 0;
  font-size: 12px;
  font-family: inherit;
  color: var(--text);
  background: rgba(56, 189, 248, 0.12);
  border: 1px solid rgba(56, 189, 248, 0.4);
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s;
}
.tt-audio button:hover { background: rgba(56, 189, 248, 0.28); }

.tt-section {
  margin: 10px 0 5px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1px;
  color: var(--accent);
  text-transform: uppercase;
}
.tt-defs { list-style: none; display: flex; flex-direction: column; gap: 6px; }
.tt-defs li { line-height: 1.55; }
.tt-defs .pos {
  display: inline-block;
  padding: 1px 6px;
  margin-right: 6px;
  font-size: 11px;
  color: #a5b4fc;
  background: rgba(99, 102, 241, 0.18);
  border-radius: 5px;
}
.tt-affix { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; line-height: 1.8; }
.afx { padding: 2px 8px; border-radius: 6px; font-weight: 600; font-size: 12px; }
.afx.pre { color: #fbbf24; background: rgba(251, 191, 36, 0.12); border: 1px dashed rgba(251, 191, 36, 0.4); }
.afx.suf { color: #34d399; background: rgba(52, 211, 153, 0.12); border: 1px dashed rgba(52, 211, 153, 0.4); }
.afx.root { color: #93c5fd; background: rgba(147, 197, 253, 0.1); border: 1px dashed rgba(147, 197, 253, 0.35); }
.tt-note { margin-top: 4px; font-size: 11px; color: var(--text-dim); }
.tt-none { color: var(--text-dim); }
.tt-examples { list-style: none; display: flex; flex-direction: column; gap: 6px; }
.tt-examples li { color: var(--text-dim); line-height: 1.55; border-left: 2px solid rgba(56, 189, 248, 0.5); padding-left: 8px; }
.tt-etymo { margin-top: 8px; font-size: 12px; color: var(--text-dim); }

/* ---------- 浮动控件 ---------- */
.float-controls {
  position: absolute; z-index: 20;
  right: 18px; bottom: 18px;
  display: flex; flex-direction: column; gap: 8px;
  background: var(--panel);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 6px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}

/* ---------- Toast ---------- */
.toast {
  position: absolute; z-index: 50;
  left: 50%; bottom: 26px;
  transform: translateX(-50%);
  padding: 10px 20px;
  font-size: 13px;
  background: var(--panel-solid);
  border: 1px solid var(--line);
  border-radius: 999px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
  animation: toastIn 0.2s ease;
}
@keyframes toastIn {
  from { opacity: 0; transform: translate(-50%, 8px); }
  to   { opacity: 1; transform: translate(-50%, 0); }
}

/* ---------- 模态框 ---------- */
.modal-overlay {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
  animation: fadeIn 0.18s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal {
  width: min(420px, calc(100vw - 40px));
  background: var(--panel-solid);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 18px;
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.55);
  animation: modalIn 0.22s cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes modalIn { from { opacity: 0; transform: scale(0.94) translateY(8px); } to { opacity: 1; transform: none; } }

.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.modal-title { font-size: 15px; font-weight: 700; }
.modal-close { width: 28px; height: 28px; font-size: 12px; }

.modal-body { font-size: 13px; line-height: 1.7; }
.modal-body .modal-label { display: block; font-size: 12px; color: var(--text-dim); margin-bottom: 6px; }
.modal-body input {
  width: 100%;
  padding: 10px 12px;
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
  background: var(--input-bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  outline: none;
}
.modal-body input:focus { border-color: rgba(56, 189, 248, 0.7); box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.15); }
.modal-body .modal-hint { margin-top: 8px; font-size: 11.5px; color: var(--text-dim); }
.modal-body .modal-warn { margin-top: 4px; font-size: 12px; color: #f87171; }

.modal-foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

.hidden { display: none !important; }
