/* ── SVG CANVAS ── */
#canvas { 
  width: 100vw; 
  height: 100vh; 
  height: 100dvh; 
  display: block; 
  touch-action: none;
}

/* ── NODES ── */
.node { cursor: pointer; }
.node text {
  pointer-events: none;
  text-shadow: 0 1px 6px rgba(0,0,0,0.9), 0 0 2px rgba(0,0,0,1);
}
.node.faded circle, .node.faded ellipse { opacity: 0.08; }
.node.faded text { opacity: 0.06; }

/* ── LINKS ── */
.link { fill: none; }
.link.faded { opacity: 0.03; }
.link.lit    { opacity: 1 !important; }
.link.inferred { stroke: #d4a040 !important; }

/* ── TOOLTIP ── */
#tip, #linkTip {
  position: fixed; 
  pointer-events: none;
  background: var(--bg-elevated);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md); 
  padding: 14px 16px;
  z-index: 5000; 
  opacity: 0; 
  transition: opacity 0.12s, visibility 0.12s;
  visibility: hidden;
  box-shadow: 0 12px 48px rgba(0,0,0,0.7);
  backdrop-filter: blur(12px);
}
#tip.show, #linkTip.show { 
  opacity: 1; 
  visibility: visible;
}

#tip { max-width: 310px; font-size: var(--font-sm); line-height: 1.55; }
#linkTip { max-width: 280px; font-size: 10.5px; line-height: 1.5; }

.tip-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 0.5rem;
}
.tip-close {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-size: 1.2rem;
  cursor: pointer;
  padding: 0 4px;
  display: none; /* Only show on mobile */
}

@media (max-width: 639px) {
  #tip, #linkTip { 
    max-width: 85vw; 
    width: 85vw;
    font-size: var(--font-md); 
    pointer-events: auto; /* Enable close button interaction */
    border: 1px solid var(--accent-blue);
    box-shadow: 0 0 20px rgba(110,159,255,0.25);
  }
  #tip .t { font-size: var(--font-lg); }
  .tip-close { display: block; }
}

#tip a { pointer-events: auto; }
#tip .t  { font-size: var(--font-md); font-weight: 700; color: #fff; margin-bottom: 5px; line-height: 1.3; }
#tip .a  { color: var(--text-secondary); font-size: var(--font-xs); margin-bottom: 7px; }
#tip .tags { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 8px; }
#tip .tag {
  padding: 2px 7px; border-radius: 10px;
  font-size: var(--font-xs); font-weight: 600; letter-spacing: 0.04em;
  background: var(--bg-interactive); color: var(--text-secondary);
}
#tip .tag.oli  { background: rgba(110,159,255,0.12); color: var(--accent-blue); }
#tip .tag.src  { background: rgba(255,200,80,0.1);   color: var(--accent-orange); }
#tip .abs  { color: var(--text-secondary); font-size: var(--font-sm); line-height: 1.5; }
#tip .lnk  { margin-top: 9px; }
#tip .lnk a { color: var(--accent-blue); font-size: var(--font-sm); text-decoration: none; }
#tip .lnk a:hover { text-decoration: underline; }

@media (max-width: 639px) {
  #tip { max-width: 85vw; font-size: var(--font-md); }
  #tip .t { font-size: var(--font-lg); }
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ── LINK TOOLTIP ── */
#linkTip .ltype {
  font-size: 9px; font-weight: 800; letter-spacing: 0.1em;
  text-transform: uppercase; margin-bottom: 5px;
}
#linkTip .lpath { color: #8898c0; margin-bottom: 6px; font-size: 10px; }
#linkTip .lroot { color: #4a5878; font-style: italic; font-size: 10px; }
#linkTip .lreason { color: #6878a0; margin-top: 5px; font-size: 10px; border-top: 1px solid rgba(255,255,255,0.05); padding-top: 5px; }

/* ── CHAT SUBGRAPH SPOTLIGHT ── */
svg.chat-subgraph .node.faded circle,
svg.chat-subgraph .node.faded ellipse { opacity: 0.018 !important; }
svg.chat-subgraph .node.faded text   { opacity: 0 !important; }
svg.chat-subgraph .link.faded        { opacity: 0.008 !important; }

svg.chat-subgraph .node:not(.faded) circle {
  filter: drop-shadow(0 0 7px currentColor);
}
svg.chat-subgraph .node:not(.faded) text {
  font-weight: 700;
  fill: #fff !important;
  text-shadow: 0 0 8px rgba(110,159,255,0.6), 0 1px 3px rgba(0,0,0,1);
}
svg.chat-subgraph .link:not(.faded) {
  opacity: 0.9 !important;
  stroke-width: 2 !important;
}

/* ── CLUSTER CONVEX HULLS ── */
.cluster-hull {
  fill-opacity: 0.04;
  stroke-opacity: 0.12;
  stroke-width: 2;
  pointer-events: none;
}

/* ── LIGHT THEME GRAPH OVERRIDES ── */
body.theme-light .node text {
  text-shadow: 0 1px 4px rgba(255,255,255,0.9), 0 0 2px rgba(255,255,255,1);
  fill: #1a1d2e;
}
/* Make light-mode graph colors legible against bright canvas */
body.theme-light .node:not(.oli) > circle:first-of-type {
  fill-opacity: 0.34 !important;
  stroke-opacity: 0.82 !important;
  stroke-width: 1.5 !important;
}
body.theme-light .node.oli > circle:nth-of-type(2) {
  fill-opacity: 0.42 !important;
  stroke-opacity: 0.96 !important;
}
body.theme-light .node.oli > circle:first-of-type {
  stroke-opacity: 0.35 !important;
}
body.theme-light .link {
  stroke-opacity: 0.72 !important;
}
body.theme-light .node.faded circle,
body.theme-light .node.faded ellipse { opacity: 0.15; }
body.theme-light .node.faded text { opacity: 0.12; }
body.theme-light .link.faded { opacity: 0.06; }
body.theme-light .cluster-hull {
  fill-opacity: 0.085;
  stroke-opacity: 0.2;
}
body.theme-light #tip, body.theme-light #linkTip {
  box-shadow: 0 8px 32px rgba(0,0,0,0.12);
}
body.theme-light #tip .t { color: #1a1d2e; }
body.theme-light #tip .abs { color: #4a5270; }
body.theme-light svg.chat-subgraph .node:not(.faded) text {
  fill: #1a1d2e !important;
  text-shadow: 0 0 6px rgba(59,111,216,0.4), 0 1px 3px rgba(255,255,255,0.8);
}
