/* D3 Semantic Graph Renderer — dark theme styles */

.d3-graph-card {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

svg.d3-semantic-graph {
    display: block;
    width: 100%;
    height: 100%;
    overflow: visible;
}

/* Nodes are clickable — show the hand cursor over the whole node (cursor is
   inherited, so the bg shapes / labels / hit target all pick it up). */
.d3sg-node { cursor: pointer; }

/* Variable nodes — fill/stroke set by theme via inline attributes */
.d3sg-var-bg {
    stroke-width: 1.5px;
    transition: filter 0.12s ease-out;
}
.d3sg-node:hover .d3sg-var-bg {
    filter: brightness(1.3);
}

/* Operator nodes — fill/stroke set by theme via inline attributes */
.d3sg-op-bg {
    stroke-width: 1.5px;
    transition: filter 0.12s ease-out;
}
.d3sg-node:hover .d3sg-op-bg {
    filter: brightness(1.3);
}

/* Live-terms hover halo — driven by highlightNodeById() when a learner hovers
   the LINKED term in a docked proof animation. Mirrors a real mouse hover (the
   same brightness lift) plus a coloured glow so the cross-highlight reads as a
   halo, matching the term's own halo in the proof box. Green for data nodes,
   blue for operators — same hues as the .selected glow. */
.d3sg-node.d3sg-live-hover .d3sg-var-bg {
    filter: brightness(1.25) drop-shadow(0 0 6px rgba(109, 240, 142, 0.65));
}
.d3sg-node.d3sg-live-hover .d3sg-op-bg {
    filter: brightness(1.25) drop-shadow(0 0 6px rgba(126, 168, 255, 0.65));
}
.d3sg-node.d3sg-live-hover .d3sg-tile-bg {
    filter: brightness(1.2) drop-shadow(0 0 6px rgba(126, 168, 255, 0.6));
}

/* Collapsed tile — fill/stroke set by theme via inline attributes */
.d3sg-tile-bg {
    stroke-width: 2px;
    transition: filter 0.12s ease-out;
}
.d3sg-node:hover .d3sg-tile-bg {
    filter: brightness(1.25);
}

/* Node labels */
.d3sg-label {
    fill: #dde6ff;
    pointer-events: none;
    user-select: none;
}

.d3sg-katex-host {
    color: #dde6ff;
    font-size: 17px;
    pointer-events: none;
    user-select: none;
}

.d3sg-katex-host .katex {
    font-size: 0.9em;
}

/* Edge labels */
.d3sg-edge-label {
    fill: #aebbd1;
    font-size: 11px;
    paint-order: stroke;
    stroke: #131a2c;
    stroke-width: 4px;
    pointer-events: auto;   /* so the hand cursor shows over edge text */
    cursor: pointer;
}
.d3sg-role-label {
    fill: #8fa8c8;
    font-size: 10px;
    font-style: italic;
}
.d3sg-role-lhs,
.d3sg-role-rhs {
    stroke-dasharray: none;
}

/* Chevron (collapse/expand button) */
.d3sg-chevron {
    opacity: 0;
    cursor: pointer;
    pointer-events: all;
    transition: opacity 0.12s ease-out;
}
.d3sg-node:hover .d3sg-chevron {
    opacity: 0.7;
}
.d3sg-chevron:hover {
    opacity: 1 !important;
}

/* Invisible hit target for flat themes */
.d3sg-hit-target {
    transition: stroke 0.12s ease-out, stroke-opacity 0.12s ease-out;
}
.d3sg-node:hover .d3sg-hit-target {
    stroke: #7ea8ff !important;
    stroke-width: 1.5px !important;
    stroke-opacity: 0.4;
}

/* Active node ring */
.d3sg-node.active .d3sg-var-bg {
    stroke: #6df08e;
    stroke-width: 2.5px;
}
.d3sg-node.active .d3sg-op-bg {
    stroke: #7ea8ff;
    stroke-width: 2.5px;
}
.d3sg-node.active .d3sg-tile-bg {
    stroke: #7ea8ff;
    stroke-width: 2.5px;
}

/* Multi-selected node ring */
.d3sg-node.selected .d3sg-var-bg {
    stroke: #6df08e;
    stroke-width: 2.5px;
    filter: drop-shadow(0 0 6px rgba(109, 240, 142, 0.5));
}
.d3sg-node.selected .d3sg-op-bg {
    stroke: #7ea8ff;
    stroke-width: 2.5px;
    filter: drop-shadow(0 0 6px rgba(126, 168, 255, 0.5));
}
.d3sg-node.selected .d3sg-tile-bg {
    stroke: #7ea8ff;
    stroke-width: 2.5px;
    filter: drop-shadow(0 0 6px rgba(126, 168, 255, 0.5));
}
.d3sg-node.selected .d3sg-hit-target {
    stroke: #7ea8ff !important;
    stroke-width: 2px !important;
    stroke-opacity: 0.6;
}

/* Annotation overlay — stacked at bottom of graph viewport */
.d3sg-annotation-overlay {
    position: absolute;
    bottom: 12px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    flex-direction: column;
    gap: 6px;
    pointer-events: none;
    z-index: 10;
    max-width: min(90%, 420px);
}

.d3sg-anno-card {
    position: relative;
    pointer-events: all;
    border: 1px dashed;
    border-radius: 8px;
    padding: 10px 36px 10px 18px;
    font-size: 0.78rem;
    font-style: italic;
    line-height: 1.45;
    backdrop-filter: blur(8px);
    opacity: 0.92;
    text-align: center;
    min-width: 0;
    max-width: 100%;
    box-sizing: border-box;
}

.d3sg-anno-content {
    display: block;
    text-align: center;
}

.d3sg-anno-card .katex {
    font-size: 1.1em;
}

.d3sg-anno-ai-btn {
    position: absolute;
    top: 50%;
    right: 6px;
    transform: translateY(-50%);
    width: 20px;
    height: 20px;
    border: none;
    border-radius: 50%;
    background: rgba(100, 110, 255, 0.15);
    color: rgba(160, 170, 255, 0.8);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    opacity: 0;
    transition: opacity 0.15s, background 0.15s, color 0.15s;
}

.d3sg-anno-card:hover .d3sg-anno-ai-btn,
.d3sg-anno-card:focus-within .d3sg-anno-ai-btn {
    opacity: 1;
}

.d3sg-anno-ai-btn:hover {
    background: rgba(100, 110, 255, 0.35);
    color: #c0c8ff;
}

/* Edge semantics legend — bottom-right corner of graph viewport.
   The chart legend panel docks to its left and the enrichment-progress
   indicator stacks on top (see sg-chart.css / graph-view.js). */
.d3sg-edge-legend {
    position: absolute;
    right: 8px;
    bottom: 8px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 8px 10px;
    background: rgba(10, 12, 26, 0.75);
    border: 1px solid rgba(110, 124, 180, 0.35);
    border-radius: 6px;
    font-size: 0.72rem;
    color: rgba(210, 218, 245, 0.92);
    letter-spacing: 0.02em;
    z-index: 2;
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    pointer-events: none;
    user-select: none;
}
.d3sg-edge-legend.hidden { display: none; }
.d3sg-edge-legend-title {
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    opacity: 0.65;
    margin-bottom: 2px;
}
.d3sg-edge-legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
}
.d3sg-edge-legend-swatch {
    --legend-stroke: currentColor;
    --legend-stroke-width: 2px;
    position: relative;
    display: inline-block;
    width: 30px;
    height: 12px;
    flex-shrink: 0;
}
.d3sg-edge-legend-swatch::before {
    content: "";
    position: absolute;
    left: 0;
    top: 50%;
    width: 22px;
    height: var(--legend-stroke-width);
    background: var(--legend-stroke);
    transform: translateY(-50%);
}
.d3sg-edge-legend-swatch[data-arrow="-.->"]::before,
.d3sg-edge-legend-swatch[data-arrow="-.-"]::before {
    background: none;
    border-top: var(--legend-stroke-width) dotted var(--legend-stroke);
    height: 0;
}
.d3sg-edge-legend-swatch[data-arrow="==>"]::before,
.d3sg-edge-legend-swatch[data-arrow="==="]::before {
    box-shadow: 0 -2px 0 var(--legend-stroke), 0 2px 0 var(--legend-stroke);
}
.d3sg-edge-legend-swatch::after {
    content: "";
    position: absolute;
    right: 0;
    top: 50%;
    width: 0;
    height: 0;
    border-top: 5px solid transparent;
    border-bottom: 5px solid transparent;
    border-left: 8px solid var(--legend-stroke);
    transform: translateY(-50%);
}
.d3sg-edge-legend-swatch[data-arrow="---"]::after,
.d3sg-edge-legend-swatch[data-arrow="==="]::after,
.d3sg-edge-legend-swatch[data-arrow="-.-"]::after {
    display: none;
}
