:root {
  --bg: #111;
  --text: #eee;
  --node-bg: #1a1a1a;
  --node-border: #444;
  --edge: #2a2a2a;
  --edge-cross: #3a3a3a;
  --detail-bg: #161616;
  --detail-border: #2a2a2a;
  --tag-bg: #2a2a2a;
}

.light {
  --bg: #f5f5f5;
  --text: #222;
  --node-bg: #fff;
  --node-border: #ccc;
  --edge: #ddd;
  --edge-cross: #bbb;
  --detail-bg: #fff;
  --detail-border: #e0e0e0;
  --tag-bg: #e8e8e8;
}

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

body {
  font-family: system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: background 0.3s, color 0.3s;
}

/* ── Header ─────────────────────────────────────────────────────────────── */

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 20px;
  background: var(--bg);
  border-bottom: 1px solid var(--node-border);
  flex-shrink: 0;
  z-index: 10;
}

header h1 {
  font-size: 1.1rem;
  font-weight: 500;
  opacity: 0.6;
  letter-spacing: 0.06em;
}

.back-link {
  color: var(--text);
  text-decoration: none;
  padding: 5px 12px;
  border-radius: 8px;
  background: var(--node-border);
  font-size: 0.85rem;
  transition: background 0.2s;
}
.back-link:hover { background: #666; }

#toggleTheme {
  padding: 5px 12px;
  border-radius: 8px;
  border: none;
  background: var(--node-border);
  color: var(--text);
  cursor: pointer;
  font-size: 0.85rem;
}

/* ── SVG Canvas ─────────────────────────────────────────────────────────── */

#canvas-wrap {
  flex: 1;
  overflow: hidden;
  position: relative;
}

#graph {
  width: 100%;
  height: 100%;
  display: block;
}

#graph-layer {
  transition: transform 0.65s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ── Group Blobs ─────────────────────────────────────────────────────────── */

.blob {
  stroke-width: 1.5;
  transition: fill 0.35s, stroke 0.35s, opacity 0.35s;
}
.blob.dim { opacity: 0.25; }

.group-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  pointer-events: none;
  user-select: none;
  transition: fill 0.3s, opacity 0.3s;
}
.group-label.dim { opacity: 0.25; }

/* ── Edges ───────────────────────────────────────────────────────────────── */

.edge-intra {
  stroke: var(--edge);
  stroke-width: 1.5;
  transition: stroke 0.3s, opacity 0.3s, stroke-width 0.3s;
}

.edge-cross {
  stroke: var(--edge-cross);
  stroke-width: 1.5;
  stroke-dasharray: 5 4;
  transition: stroke 0.3s, opacity 0.3s, stroke-width 0.3s;
}

.edge.active {
  stroke-width: 2.5;
  opacity: 1;
}
.edge.dim { opacity: 0.06; }

/* ── Nodes ───────────────────────────────────────────────────────────────── */

.node { cursor: pointer; transition: opacity 0.3s; }
.node.dim { opacity: 0.12; }

.node circle {
  fill: var(--node-bg);
  stroke-width: 1.5;
  transition: fill 0.3s, stroke 0.3s, stroke-width 0.3s;
}
.node-optional circle { stroke-dasharray: 6 3; }
.node:hover circle { stroke-width: 2.5; }
.node.selected circle { stroke-width: 2.5; }
.node.connected circle { stroke-width: 2; }

.node text {
  fill: var(--text);
  font-size: 11px;
  font-family: system-ui, sans-serif;
  pointer-events: none;
  user-select: none;
}
.node.selected text { fill: #fff; font-weight: 600; }

/* ── Detail Panel ────────────────────────────────────────────────────────── */

#detail {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%) translateY(0);
  width: min(520px, 96vw);
  background: var(--detail-bg);
  border: 1px solid var(--detail-border);
  border-bottom: none;
  border-radius: 16px 16px 0 0;
  padding: 22px 26px 34px;
  box-shadow: 0 -8px 40px rgba(0,0,0,0.4);
  transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 20;
}
#detail.hidden { transform: translateX(-50%) translateY(100%); }

#detail-close {
  position: absolute;
  top: 12px;
  right: 14px;
  border: none;
  background: var(--tag-bg);
  color: var(--text);
  padding: 4px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.85rem;
  transition: background 0.2s;
}
#detail-close:hover { background: var(--node-border); }

#detail-title {
  font-size: 1.35rem;
  font-weight: 600;
  margin-bottom: 10px;
  transition: color 0.3s;
}

#detail-desc {
  font-size: 0.88rem;
  line-height: 1.65;
  opacity: 0.8;
  margin-bottom: 16px;
}

#detail-links {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.connections-label {
  font-size: 0.72rem;
  opacity: 0.5;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  width: 100%;
}

.conn-tag {
  padding: 4px 12px;
  border-radius: 20px;
  background: var(--tag-bg);
  font-size: 0.78rem;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background 0.2s, color 0.2s;
}
.conn-tag:hover { background: var(--node-border); }

.group-badge {
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  border: 1px solid;
  background: transparent;
  margin-left: auto;
}
