@import url('https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@300;400;600&family=Ma+Shan+Zheng&display=swap');

:root {
  --bg: #040810;
  --node-default: #1a3a5c;
  --node-stroke: #2a6aad;
  --node-highlight: #00d4ff;
  --node-ancestor: #ffd700;
  --node-descendant: #00ff9f;
  --link-default: rgba(42, 106, 173, 0.25);
  --link-highlight: rgba(0, 212, 255, 0.85);
  --text: #a0c4e8;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  background: var(--bg);
  font-family: 'Noto Serif SC', serif;
  overflow: hidden;
  width: 100vw;
  height: 100vh;
  color: var(--text);
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse at 20% 30%, rgba(0,80,180,0.12) 0%, transparent 60%),
    radial-gradient(ellipse at 80% 70%, rgba(0,180,120,0.08) 0%, transparent 60%);
  pointer-events: none;
  z-index: 0;
}

#canvas-container {
  position: relative;
  width: 100%;
  height: 100%;
}

svg {
  position: absolute;
  inset: 0;
  cursor: grab;
}
svg:active { cursor: grabbing; }

/* ── Links ── */
.link {
  fill: none;
  stroke: var(--link-default);
  stroke-width: 1px;
  transition: stroke 0.3s, stroke-width 0.3s;
}
/* 生父线 */
.link-bio { stroke: var(--link-default); }
.link-bio.highlighted {
  stroke: var(--link-highlight);
  stroke-width: 2px;
  filter: drop-shadow(0 0 4px rgba(0,212,255,0.9));
}
/* 嗣父线 */
.link-adopted {
  stroke: rgba(180,130,20,0.35);
  stroke-width: 1.2px;
}
.link-adopted.highlighted-adopted {
  stroke: #d4a017;
  stroke-width: 2px;
  filter: drop-shadow(0 0 5px rgba(212,160,23,0.85));
}
.link.dimmed,
.link-bio.dimmed,
.link-adopted.dimmed { stroke: rgba(20,40,60,0.1); filter: none; }

/* ── Nodes ── */
.node circle {
  fill: var(--node-default);
  stroke: var(--node-stroke);
  stroke-width: 1.5px;
  cursor: pointer;
  transition: all 0.3s ease;
}
.node circle:hover {
  stroke: var(--node-highlight);
  stroke-width: 2px;
  filter: drop-shadow(0 0 8px rgba(0,212,255,0.7));
}
.node.selected circle {
  fill: rgba(0,212,255,0.25);
  stroke: var(--node-highlight);
  stroke-width: 2.5px;
  filter: drop-shadow(0 0 14px rgba(0,212,255,1));
}
.node.ancestor circle {
  fill: rgba(255,215,0,0.2);
  stroke: var(--node-ancestor);
  stroke-width: 2px;
  filter: drop-shadow(0 0 10px rgba(255,215,0,0.8));
}
/* 嗣父脉络：琥珀橙 */
.node.adopted-ancestor circle {
  fill: rgba(212,160,23,0.18);
  stroke: #d4a017;
  stroke-width: 2px;
  filter: drop-shadow(0 0 9px rgba(212,160,23,0.75));
}
.node.adopted-ancestor text { fill: #f0c84a; font-weight: 600; font-size: 11px; }
.node.descendant circle {
  fill: rgba(0,255,159,0.15);
  stroke: var(--node-descendant);
  stroke-width: 2px;
  filter: drop-shadow(0 0 10px rgba(0,255,159,0.8));
}
.node.dimmed circle {
  fill: rgba(10,20,35,0.7);
  stroke: rgba(30,60,90,0.3);
  stroke-width: 1px;
  filter: none;
}

.node text {
  fill: var(--text);
  font-size: 10px;
  text-anchor: middle;
  pointer-events: none;
  transition: opacity 0.3s;
  font-family: 'Noto Serif SC', serif;
}
.node.dimmed text { opacity: 0.2; }
.node.selected text,
.node.ancestor text,
.node.descendant text {
  fill: #fff;
  font-weight: 600;
  font-size: 11px;
}

/* Pulse ring */
.node.selected .pulse-ring { animation: pulseRing 2s ease-out infinite; }
.pulse-ring {
  fill: none;
  stroke: var(--node-highlight);
  stroke-width: 1px;
  opacity: 0;
}
@keyframes pulseRing {
  0%   { r: 10px; opacity: 0.8; }
  100% { r: 30px; opacity: 0; }
}

/* Generation labels */
.gen-label {
  fill: rgba(100,150,200,0.3);
  font-size: 11px;
  font-family: 'Ma Shan Zheng', cursive;
  letter-spacing: 2px;
}

/* ── Info Panel ── */
#info-panel {
  position: fixed;
  top: 20px;
  right: 20px;
  width: 280px;
  background: rgba(4,15,30,0.92);
  border: 1px solid rgba(0,212,255,0.2);
  border-radius: 8px;
  padding: 20px;
  backdrop-filter: blur(12px);
  transition: opacity 0.3s, transform 0.3s;
  opacity: 0;
  transform: translateX(20px);
  pointer-events: none;
  z-index: 100;
}
#info-panel.visible {
  opacity: 1;
  transform: translateX(0);
  pointer-events: auto;
}
#info-panel::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--node-highlight), transparent);
  border-radius: 8px 8px 0 0;
}
.panel-gen {
  font-size: 11px;
  color: var(--node-highlight);
  letter-spacing: 3px;
  margin-bottom: 6px;
}
.panel-name {
  font-family: 'Ma Shan Zheng', cursive;
  font-size: 28px;
  color: #fff;
  margin-bottom: 10px;
  line-height: 1;
}
.panel-info {
  font-size: 12px;
  color: rgba(160,196,232,0.8);
  line-height: 1.6;
  border-top: 1px solid rgba(0,212,255,0.15);
  padding-top: 10px;
  margin-top: 4px;
}
.panel-relations {
  margin-top: 12px;
  display: flex;
  gap: 12px;
}
.relation-badge {
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 20px;
  letter-spacing: 1px;
}
.badge-ancestor {
  background: rgba(255,215,0,0.1);
  border: 1px solid rgba(255,215,0,0.4);
  color: var(--node-ancestor);
}
.badge-descendant {
  background: rgba(0,255,159,0.1);
  border: 1px solid rgba(0,255,159,0.4);
  color: var(--node-descendant);
}
.badge-adopted {
  background: rgba(212,160,23,0.1);
  border: 1px solid rgba(212,160,23,0.45);
  color: #d4a017;
}
.adoption-tag {
  display: inline-block;
  margin-left: 6px;
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 10px;
  background: rgba(212,160,23,0.12);
  border: 1px solid rgba(212,160,23,0.4);
  color: #d4a017;
  vertical-align: middle;
  letter-spacing: 1px;
}
#close-panel {
  position: absolute;
  top: 12px; right: 14px;
  background: none;
  border: none;
  color: rgba(160,196,232,0.5);
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  padding: 2px 6px;
  border-radius: 4px;
  transition: color 0.2s;
}
#close-panel:hover { color: var(--node-highlight); }

/* ── Title ── */
#title {
  position: fixed;
  top: 20px;
  left: 20px;
  z-index: 100;
}
#title h1 {
  font-family: 'Ma Shan Zheng', cursive;
  font-size: 22px;
  color: rgba(160,196,232,0.9);
  letter-spacing: 4px;
  line-height: 1.3;
}
#title p {
  font-size: 11px;
  color: rgba(100,140,180,0.6);
  letter-spacing: 2px;
  margin-top: 4px;
}

/* ── Legend ── */
#legend {
  position: fixed;
  bottom: 20px;
  left: 20px;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  color: rgba(120,160,200,0.7);
}
.legend-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  border: 2px solid;
  flex-shrink: 0;
}

/* ── Hint ── */
#hint {
  position: fixed;
  bottom: 20px;
  right: 20px;
  font-size: 11px;
  color: rgba(80,120,160,0.6);
  text-align: right;
  letter-spacing: 1px;
  line-height: 1.8;
  z-index: 100;
}

/* ── Search ── */
#search-box {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 200;
  width: 320px;
}
#search-wrap {
  position: relative;
  display: flex;
  align-items: center;
}
#search-icon {
  position: absolute;
  left: 12px;
  color: rgba(0,212,255,0.5);
  font-size: 14px;
  pointer-events: none;
  line-height: 1;
}
#search-input {
  width: 100%;
  padding: 10px 36px 10px 36px;
  background: rgba(4,15,30,0.92);
  border: 1px solid rgba(0,212,255,0.25);
  border-radius: 24px;
  color: #e0f0ff;
  font-family: 'Noto Serif SC', serif;
  font-size: 13px;
  letter-spacing: 1px;
  outline: none;
  backdrop-filter: blur(12px);
  transition: border-color 0.2s, box-shadow 0.2s;
}
#search-input::placeholder { color: rgba(100,150,200,0.4); }
#search-input:focus {
  border-color: rgba(0,212,255,0.6);
  box-shadow: 0 0 16px rgba(0,212,255,0.2);
}
#search-clear {
  position: absolute;
  right: 10px;
  background: none;
  border: none;
  color: rgba(100,150,200,0.4);
  cursor: pointer;
  font-size: 14px;
  padding: 4px;
  line-height: 1;
  display: none;
  transition: color 0.2s;
}
#search-clear:hover { color: var(--node-highlight); }
#search-clear.visible { display: block; }

#search-results {
  position: absolute;
  top: calc(100% + 6px);
  left: 0; right: 0;
  background: rgba(4,15,30,0.96);
  border: 1px solid rgba(0,212,255,0.2);
  border-radius: 12px;
  overflow: hidden;
  max-height: 240px;
  overflow-y: auto;
  display: none;
  backdrop-filter: blur(16px);
  box-shadow: 0 8px 32px rgba(0,0,0,0.6);
}
#search-results.visible { display: block; }
#search-results::-webkit-scrollbar { width: 4px; }
#search-results::-webkit-scrollbar-track { background: transparent; }
#search-results::-webkit-scrollbar-thumb { background: rgba(0,212,255,0.2); border-radius: 2px; }

.search-result-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 14px;
  cursor: pointer;
  border-bottom: 1px solid rgba(0,212,255,0.06);
  transition: background 0.15s;
}
.search-result-item:last-child { border-bottom: none; }
.search-result-item:hover,
.search-result-item.active { background: rgba(0,212,255,0.08); }
.result-name {
  font-family: 'Ma Shan Zheng', cursive;
  font-size: 16px;
  color: #e0f0ff;
  min-width: 52px;
}
.result-name mark {
  background: none;
  color: var(--node-highlight);
  font-weight: 600;
}
.result-gen {
  font-size: 10px;
  color: rgba(0,212,255,0.5);
  letter-spacing: 1px;
  border: 1px solid rgba(0,212,255,0.2);
  border-radius: 10px;
  padding: 1px 7px;
  white-space: nowrap;
}
.result-info {
  font-size: 11px;
  color: rgba(100,150,190,0.6);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}
.no-result {
  padding: 14px;
  text-align: center;
  font-size: 12px;
  color: rgba(100,140,180,0.5);
  letter-spacing: 1px;
}

/* ── Loading screen ── */
#loading {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 999;
  transition: opacity 0.6s ease;
}
#loading.hidden { opacity: 0; pointer-events: none; }
.loading-title {
  font-family: 'Ma Shan Zheng', cursive;
  font-size: 32px;
  color: rgba(160,196,232,0.8);
  letter-spacing: 6px;
  margin-bottom: 24px;
}
.loading-spinner {
  width: 40px; height: 40px;
  border: 2px solid rgba(0,212,255,0.1);
  border-top-color: var(--node-highlight);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}
.loading-tip {
  margin-top: 16px;
  font-size: 11px;
  color: rgba(100,140,180,0.4);
  letter-spacing: 2px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Error screen ── */
#error-screen {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 998;
}
#error-screen.visible { display: flex; }
.error-icon { font-size: 48px; margin-bottom: 16px; }
.error-msg {
  font-family: 'Ma Shan Zheng', cursive;
  font-size: 20px;
  color: rgba(255,100,100,0.8);
  margin-bottom: 8px;
}
.error-detail {
  font-size: 12px;
  color: rgba(150,150,180,0.5);
  letter-spacing: 1px;
  max-width: 400px;
  text-align: center;
  line-height: 1.8;
}
