/* =================================================================
   tools/ds-advanced.css
   Auto-extracted from math.css (2026-05-11).
   Loaded via config/js-manifest.php → templates/partials/head-styles.php.
   ================================================================= */

/* =====================================================================
   Trees & Advanced Data Structures (ds-advanced) — V2 redesign
   BST · AVL · RBT · Trie · Heap · Union-Find · Hash · Graph
   ===================================================================== */

.math-ds-adv-panel {
    --adv-grad-tree-a:  #818cf8;
    --adv-grad-tree-b:  #4f46e5;
    --adv-grad-rbt-red:   #ef4444;
    --adv-grad-rbt-black: #1f2937;
    --adv-grad-trie-a:  #06b6d4;
    --adv-grad-trie-b:  #0e7490;
    --adv-grad-heap-a:  #f59e0b;
    --adv-grad-heap-b:  #d97706;
    --adv-grad-uf-a:    #a855f7;
    --adv-grad-uf-b:    #7e22ce;
    --adv-grad-hash-a:  #10b981;
    --adv-grad-hash-b:  #059669;
    --adv-grad-graph-a: #3b82f6;
    --adv-grad-graph-b: #1d4ed8;
    --adv-grad-found-a: #34d399;
    --adv-grad-found-b: #059669;
    --adv-grad-hl-a:    #fbbf24;
    --adv-grad-hl-b:    #d97706;
    --adv-grad-target-a:#f43f5e;
    --adv-grad-target-b:#be123c;

    --adv-tween: 0.55s;
    --adv-ease: cubic-bezier(0.34, 1.4, 0.64, 1);
    --adv-node-r: 22px;
    --adv-h-spacing: 56px;
    --adv-level-h: 70px;
}
/* --adv-tween is set inline by JS (MathDsCore.applySpeed), baseline 0.55s @ ×1.0. */

/* Type segment — Stage 14: fixed grid for 8 tabs (no overflow / no wrap collisions) */
.math-ds-adv-type-segment {
    display: grid;
    grid-template-columns: repeat(8, minmax(0, 1fr));
    gap: 6px;
    padding: 4px;
}
.math-ds-adv-type-segment .math-mode-segment-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 8px 6px;
    min-height: 40px;
    line-height: 1.1;
    text-align: center;
    overflow: hidden;
}
.math-ds-adv-type-segment .adv-seg-title {
    font-weight: 700;
    font-family: ui-monospace, monospace;
    font-size: 12.5px;
    letter-spacing: -0.01em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}
@media (max-width: 1024px) {
    .math-ds-adv-type-segment { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
@media (max-width: 520px) {
    .math-ds-adv-type-segment { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .math-ds-adv-type-segment .adv-seg-title { font-size: 12px; }
}

/* Info-card per-type */
.math-ds-adv-info-wrap {
    margin: 8px 0 4px;
    position: relative;
}
.math-ds-adv-info {
    display: none;
    padding: 14px 16px;
    border-radius: var(--math-radius-md);
    background: linear-gradient(135deg, rgba(99,102,241,0.06), rgba(79,70,229,0.04));
    border: 1px solid rgba(99,102,241,0.18);
}
.math-ds-adv-info.active { display: block; }
.math-ds-adv-info[data-type="trie"]       { background: linear-gradient(135deg, rgba(6,182,212,0.06), rgba(14,116,144,0.04));   border-color: rgba(6,182,212,0.20); }
.math-ds-adv-info[data-type="heap"]       { background: linear-gradient(135deg, rgba(245,158,11,0.06), rgba(217,119,6,0.04));   border-color: rgba(245,158,11,0.20); }
.math-ds-adv-info[data-type="union-find"] { background: linear-gradient(135deg, rgba(168,85,247,0.06), rgba(126,34,206,0.04));  border-color: rgba(168,85,247,0.20); }
.math-ds-adv-info[data-type="hash-table"] { background: linear-gradient(135deg, rgba(16,185,129,0.06), rgba(5,150,105,0.04));   border-color: rgba(16,185,129,0.20); }
.math-ds-adv-info[data-type="graph"]      { background: linear-gradient(135deg, rgba(59,130,246,0.06), rgba(29,78,216,0.04));   border-color: rgba(59,130,246,0.20); }
.math-ds-adv-info[data-type="rbt"]        { background: linear-gradient(135deg, rgba(31,41,55,0.06), rgba(239,68,68,0.04));     border-color: rgba(31,41,55,0.22); }

.adv-info-head {
    display: flex;
    gap: 12px;
    align-items: flex-start;
    margin-bottom: 10px;
}
.adv-info-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    flex: 0 0 36px;
    border-radius: 50%;
    color: #fff;
    font-size: 16px;
    background: linear-gradient(135deg, var(--adv-grad-tree-a), var(--adv-grad-tree-b));
    box-shadow: 0 2px 6px rgba(79,70,229,0.30);
}
.math-ds-adv-info[data-type="trie"]       .adv-info-icon { background: linear-gradient(135deg, var(--adv-grad-trie-a), var(--adv-grad-trie-b)); box-shadow: 0 2px 6px rgba(14,116,144,0.30); }
.math-ds-adv-info[data-type="heap"]       .adv-info-icon { background: linear-gradient(135deg, var(--adv-grad-heap-a), var(--adv-grad-heap-b)); box-shadow: 0 2px 6px rgba(217,119,6,0.30); }
.math-ds-adv-info[data-type="union-find"] .adv-info-icon { background: linear-gradient(135deg, var(--adv-grad-uf-a),   var(--adv-grad-uf-b));   box-shadow: 0 2px 6px rgba(126,34,206,0.30); }
.math-ds-adv-info[data-type="hash-table"] .adv-info-icon { background: linear-gradient(135deg, var(--adv-grad-hash-a), var(--adv-grad-hash-b)); box-shadow: 0 2px 6px rgba(5,150,105,0.30); }
.math-ds-adv-info[data-type="graph"]      .adv-info-icon { background: linear-gradient(135deg, var(--adv-grad-graph-a),var(--adv-grad-graph-b));box-shadow: 0 2px 6px rgba(29,78,216,0.30); }
.math-ds-adv-info[data-type="rbt"]        .adv-info-icon { background: linear-gradient(135deg, var(--adv-grad-rbt-red), var(--adv-grad-rbt-black)); box-shadow: 0 2px 6px rgba(31,41,55,0.30); }

.adv-info-title {
    font-weight: 700;
    font-size: 14px;
    color: var(--math-text);
    margin-bottom: 2px;
}
.adv-info-sub {
    font-size: 12.5px;
    color: var(--math-text-muted);
    line-height: 1.5;
}
.adv-info-sub code {
    background: rgba(99,102,241,0.10);
    color: #4338ca;
    padding: 1px 5px;
    border-radius: 3px;
    font-size: 11.5px;
    font-family: ui-monospace, monospace;
}
.adv-info-body {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 16px;
    align-items: center;
}
.adv-info-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 12.5px;
    line-height: 1.5;
    color: var(--math-text);
}
.adv-info-list li { padding-left: 0; }
.adv-info-list strong { color: #4338ca; }
.math-ds-adv-info[data-type="trie"]       .adv-info-list strong,
.math-ds-adv-info[data-type="trie"]       .adv-info-sub code { color: #0e7490; }
.math-ds-adv-info[data-type="heap"]       .adv-info-list strong,
.math-ds-adv-info[data-type="heap"]       .adv-info-sub code { color: #b45309; }
.math-ds-adv-info[data-type="union-find"] .adv-info-list strong,
.math-ds-adv-info[data-type="union-find"] .adv-info-sub code { color: #6b21a8; }
.math-ds-adv-info[data-type="hash-table"] .adv-info-list strong,
.math-ds-adv-info[data-type="hash-table"] .adv-info-sub code { color: #047857; }
.math-ds-adv-info[data-type="graph"]      .adv-info-list strong,
.math-ds-adv-info[data-type="graph"]      .adv-info-sub code { color: #1e40af; }
.math-ds-adv-info[data-type="rbt"]        .adv-info-list strong,
.math-ds-adv-info[data-type="rbt"]        .adv-info-sub code { color: #b91c1c; }

.adv-info-mini {
    display: flex;
    flex-direction: column;
    gap: 6px;
    align-items: flex-end;
}
.adv-info-legend {
    font-size: 10.5px;
    color: var(--math-text-muted);
    font-style: italic;
    text-align: right;
    max-width: 240px;
}

/* Mini-viz: tree (BST/AVL/RBT) */
.adv-mini-tree {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
    padding: 4px 0;
}
.adv-mini-row {
    display: flex;
    gap: 8px;
    justify-content: center;
}
.adv-mini-node {
    width: 28px;
    height: 28px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    position: relative;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--adv-grad-tree-a), var(--adv-grad-tree-b));
    color: #fff;
    font-family: ui-monospace, monospace;
    font-size: 11px;
    font-weight: 700;
}
.adv-mini-node sup {
    position: absolute;
    top: -7px;
    right: -6px;
    font-size: 8px;
    font-weight: 700;
    color: var(--math-text-muted);
    background: var(--math-surface);
    border: 1px solid var(--math-border);
    border-radius: 99px;
    padding: 0 3px;
    line-height: 1.2;
}
.adv-mini-node.rbt-red   { background: linear-gradient(135deg, #ef4444, #b91c1c); }
.adv-mini-node.rbt-black { background: linear-gradient(135deg, #1f2937, #111827); }
.adv-mini-spacer { display: inline-block; width: 28px; height: 28px; }

/* Mini-viz: trie */
.adv-mini-trie {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 2px 0;
}
.adv-trie-root {
    width: 22px;
    height: 22px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: var(--math-surface-subtle);
    border: 1.5px solid var(--adv-grad-trie-b);
    color: var(--adv-grad-trie-b);
    font-family: ui-monospace, monospace;
    font-weight: 700;
    font-size: 11px;
}
.adv-trie-edge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    border-radius: 4px;
    background: linear-gradient(135deg, var(--adv-grad-trie-a), var(--adv-grad-trie-b));
    color: #fff;
    font-family: ui-monospace, monospace;
    font-weight: 700;
    font-size: 11px;
    margin: 1px 0;
}
.adv-trie-branch { display: flex; flex-direction: column; align-items: center; }
.adv-trie-leaves { display: flex; gap: 4px; margin-top: 2px; }
.adv-trie-leaf {
    width: 22px;
    height: 22px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    background: rgba(6,182,212,0.10);
    border: 1px solid var(--adv-grad-trie-b);
    color: var(--adv-grad-trie-b);
    font-family: ui-monospace, monospace;
    font-weight: 700;
    font-size: 11px;
}
.adv-trie-leaf.is-word {
    background: linear-gradient(135deg, var(--adv-grad-trie-a), var(--adv-grad-trie-b));
    color: #fff;
    box-shadow: 0 0 0 2px rgba(6,182,212,0.25);
}

/* Mini-viz: heap */
.adv-mini-heap { display: flex; flex-direction: column; gap: 6px; align-items: center; }
.adv-mini-heap-tree { display: flex; flex-direction: column; gap: 4px; align-items: center; }
.adv-mini-heap-tree .adv-mini-node {
    background: linear-gradient(135deg, var(--adv-grad-heap-a), var(--adv-grad-heap-b));
}
.adv-mini-heap-root { box-shadow: 0 0 0 2px rgba(245,158,11,0.45); }
.adv-mini-heap-array { display: flex; gap: 2px; margin-top: 2px; }
.adv-mini-heap-cell {
    min-width: 26px;
    padding: 3px 5px;
    background: rgba(245,158,11,0.12);
    border-radius: 3px;
    font-family: ui-monospace, monospace;
    font-size: 10.5px;
    color: var(--math-text);
    font-weight: 700;
}
.adv-mini-heap-cell sup {
    color: var(--math-text-muted);
    font-size: 8.5px;
    margin-right: 1px;
}

/* Mini-viz: union-find */
.adv-mini-uf { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.adv-mini-uf-group {
    display: flex;
    align-items: center;
    gap: 3px;
    padding: 4px 6px;
    border: 1px dashed var(--adv-grad-uf-b);
    border-radius: 6px;
    background: rgba(168,85,247,0.06);
}
.adv-mini-uf-root {
    width: 22px; height: 22px;
    display: inline-flex; align-items: center; justify-content: center;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--adv-grad-uf-a), var(--adv-grad-uf-b));
    color: #fff;
    font-family: ui-monospace, monospace;
    font-weight: 700;
    font-size: 11px;
    box-shadow: 0 0 0 2px rgba(168,85,247,0.30);
}
.adv-mini-uf-leaf {
    width: 22px; height: 22px;
    display: inline-flex; align-items: center; justify-content: center;
    border-radius: 50%;
    background: rgba(168,85,247,0.12);
    border: 1px solid var(--adv-grad-uf-b);
    color: var(--adv-grad-uf-b);
    font-family: ui-monospace, monospace;
    font-weight: 700;
    font-size: 11px;
}

/* Mini-viz: hash */
.adv-mini-hash { display: flex; flex-direction: column; gap: 3px; }
.adv-mini-hash-row { display: flex; align-items: center; gap: 4px; min-height: 22px; }
.adv-mini-hash-idx {
    font-family: ui-monospace, monospace;
    font-size: 10px;
    color: var(--math-text-muted);
    min-width: 14px;
}
.adv-mini-hash-cell {
    min-width: 22px;
    padding: 2px 6px;
    background: linear-gradient(135deg, var(--adv-grad-hash-a), var(--adv-grad-hash-b));
    color: #fff;
    border-radius: 3px;
    font-family: ui-monospace, monospace;
    font-size: 10.5px;
    font-weight: 700;
}
.adv-mini-hash-arrow { color: var(--adv-grad-hash-b); font-weight: 700; font-size: 11px; }

/* Mini-viz: graph */
.adv-mini-graph {
    position: relative;
    width: 130px;
    height: 100px;
    background: rgba(59,130,246,0.04);
    border: 1px dashed rgba(59,130,246,0.30);
    border-radius: 6px;
}
.adv-mini-graph-node {
    position: absolute;
    width: 22px;
    height: 22px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transform: translate(-50%, -50%);
    border-radius: 50%;
    background: linear-gradient(135deg, var(--adv-grad-graph-a), var(--adv-grad-graph-b));
    color: #fff;
    font-family: ui-monospace, monospace;
    font-weight: 700;
    font-size: 10px;
    z-index: 2;
}
.adv-mini-graph-svg {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1;
}
.adv-mini-graph-svg line {
    stroke: var(--adv-grad-graph-a);
    stroke-width: 1.4;
    vector-effect: non-scaling-stroke;
}

/* Stats chip-bar */
.math-ds-adv-stats {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 8px 4px 10px;
    border-bottom: 1px dashed var(--math-border);
    margin-bottom: 8px;
    min-height: 30px;
}
.math-ds-adv-stats:empty { display: none; }
.adv-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 9px;
    font-size: 11.5px;
    font-family: ui-monospace, monospace;
    font-weight: 600;
    border-radius: 99px;
    background: rgba(99,102,241,0.08);
    color: var(--math-text);
    border: 1px solid rgba(99,102,241,0.20);
    white-space: nowrap;
}
.adv-chip-accent {
    background: linear-gradient(135deg, var(--adv-grad-tree-a), var(--adv-grad-tree-b));
    color: #fff;
    border-color: transparent;
}
.adv-chip-good {
    background: rgba(16,185,129,0.10);
    color: #047857;
    border-color: rgba(16,185,129,0.25);
}
.adv-chip-warn {
    background: rgba(244,63,94,0.10);
    color: #be123c;
    border-color: rgba(244,63,94,0.25);
}
.adv-chip-muted {
    background: rgba(100,116,139,0.10);
    color: var(--math-text-muted);
    border-color: rgba(100,116,139,0.20);
}
.adv-chip-empty {
    background: transparent;
    color: var(--math-text-muted);
    border: 1px dashed var(--math-border);
}

/* Viz container */
.math-ds-adv-viz {
    min-height: 220px;
    padding: 16px 8px 8px;
    position: relative;
}

/* Tree viz (BST/AVL/RBT) — wraps existing .math-ds-tree node/edge classes */
.math-ds-adv-viz .math-ds-tree { min-height: 240px; padding-top: 8px; }
.math-ds-adv-viz .math-ds-node {
    transition: left var(--adv-tween) var(--adv-ease),
                top var(--adv-tween) var(--adv-ease),
                background var(--adv-tween),
                box-shadow var(--adv-tween);
}
.math-ds-adv-viz .math-ds-node.adv-targeting {
    box-shadow: 0 0 0 3px rgba(244,63,94,0.45), 0 4px 12px rgba(190,18,60,0.25);
    z-index: 3;
}
.math-ds-adv-viz .math-ds-node.adv-found {
    background: linear-gradient(135deg, var(--adv-grad-found-a), var(--adv-grad-found-b)) !important;
    box-shadow: 0 0 0 3px rgba(16,185,129,0.40), 0 4px 12px rgba(5,150,105,0.30);
    animation: adv-node-pulse var(--adv-tween) ease-out;
    z-index: 3;
}
.math-ds-adv-viz .math-ds-node.adv-landing {
    animation: adv-node-land var(--adv-tween) var(--adv-ease);
}
/* Reserved-slot placeholder — shown for ~700-1000ms after descent so the user
   sees the leaf POSITION first, before the value materializes. Dashed hollow
   ring + soft glow pulse (box-shadow only — never transform/opacity, since the
   JS grow-in animation drives those for the entire phase). */
.math-ds-adv-viz .math-ds-node.adv-placeholder {
    background: transparent !important;
    color: transparent !important;
    border: 2px dashed rgba(99,102,241,0.85) !important;
    animation: adv-placeholder-pulse 0.95s ease-in-out infinite alternate;
}
@keyframes adv-placeholder-pulse {
    from {
        box-shadow:
            0 0 0 3px rgba(99,102,241,0.10),
            0 4px 14px rgba(79,70,229,0.10);
    }
    to {
        box-shadow:
            0 0 0 7px rgba(99,102,241,0.32),
            0 4px 18px rgba(79,70,229,0.36);
    }
}
.math-ds-adv-viz .math-ds-node.adv-leaving {
    animation: adv-node-leave var(--adv-tween) forwards;
    pointer-events: none;
}
.math-ds-adv-viz .math-ds-node.adv-rotating {
    box-shadow: 0 0 0 3px rgba(168,85,247,0.45), 0 4px 12px rgba(126,34,206,0.30);
    animation: adv-node-rotate var(--adv-tween) ease-in-out;
}
/* Step-by-step rotation rings — pivot (BLUE) and around (ORANGE) so the
   user can read which node plays which role. Each rotation step displays
   these for ~5–6s while the choreography plays out beat-by-beat. */
.math-ds-adv-viz .math-ds-node.adv-pivot-ring {
    box-shadow:
        0 0 0 4px rgba(59,130,246,0.55),
        0 0 0 7px rgba(59,130,246,0.18),
        0 6px 14px rgba(37,99,235,0.4);
    z-index: 4;
    animation: adv-pivot-pulse 1.0s ease-in-out infinite alternate;
}
.math-ds-adv-viz .math-ds-node.adv-around-ring {
    box-shadow:
        0 0 0 4px rgba(245,158,11,0.55),
        0 0 0 7px rgba(245,158,11,0.18),
        0 6px 14px rgba(217,119,6,0.4);
    z-index: 4;
    animation: adv-around-pulse 1.0s ease-in-out infinite alternate;
}
@keyframes adv-pivot-pulse {
    from { filter: brightness(1); }
    to   { filter: brightness(1.15); }
}
@keyframes adv-around-pulse {
    from { filter: brightness(1); }
    to   { filter: brightness(1.15); }
}
/* Pivot rise — visible bounce on the node that becomes the new subtree root
   during a rotation. Pairs with the FLIP transition + edge-sweep helper so
   the user reads the rotation choreography (rather than the snapshot just
   swapping). */
.math-ds-adv-viz .math-ds-node.adv-pivot-rise {
    animation: adv-pivot-rise 1.0s cubic-bezier(.2,.85,.3,1.05);
    z-index: 5;
}
@keyframes adv-pivot-rise {
    0%   { box-shadow: 0 0 0 4px rgba(59,130,246,0.55), 0 6px 14px rgba(37,99,235,0.4); }
    35%  { box-shadow: 0 0 0 9px rgba(59,130,246,0.45), 0 16px 28px rgba(37,99,235,0.55); filter: brightness(1.22); }
    100% { box-shadow: 0 0 0 4px rgba(59,130,246,0.55), 0 6px 14px rgba(37,99,235,0.4); filter: brightness(1); }
}
/* Ghost edges left behind after a rotation — fade out instead of disappearing. */
.math-ds-adv-viz svg .adv-edge-ghost {
    stroke: rgba(245,158,11,0.55);
    stroke-width: 2.4px;
    stroke-dasharray: 6 4;
    pointer-events: none;
}
/* UF path-compression — staggered per-node flash so each pointer flip is visible. */
.math-ds-adv-viz .math-ds-uf-cell.adv-compress {
    animation: adv-uf-compress 620ms ease-out;
    box-shadow: 0 0 0 3px rgba(168,85,247,0.55), 0 4px 14px rgba(126,34,206,0.40);
}
@keyframes adv-uf-compress {
    0%   { transform: translateY(0) scale(1); filter: brightness(1); }
    40%  { transform: translateY(-6px) scale(1.06); filter: brightness(1.18); }
    100% { transform: translateY(0) scale(1); filter: brightness(1); }
}
/* Graph BFS/DFS — newly visited node pops in, traced edges draw across. */
.math-ds-adv-viz .math-ds-graph-node.visited:not(.is-source) circle {
    animation: adv-graph-visit 580ms ease-out;
    transform-origin: center;
}
@keyframes adv-graph-visit {
    0%   { transform: scale(0.55); opacity: 0; }
    55%  { transform: scale(1.18); opacity: 1; }
    100% { transform: scale(1); }
}
.math-ds-adv-viz .math-ds-graph-edge.adv-tracing {
    animation: adv-graph-edge-trace 560ms ease-out;
}
@keyframes adv-graph-edge-trace {
    from { stroke-dashoffset: 240; stroke-dasharray: 240 240; }
    to   { stroke-dashoffset: 0;   stroke-dasharray: 240 240; }
}
/* Trie placeholder — same dashed empty slot pattern as tree placeholder, plus a
   slightly cooler hue so trie/tree feels distinct visually. */
.math-ds-adv-viz .math-ds-tree .math-ds-node.adv-placeholder {
    background: transparent !important;
    color: transparent !important;
    border: 2px dashed rgba(13,148,136,0.85) !important;
    animation: adv-trie-placeholder-pulse 0.95s ease-in-out infinite alternate;
}
@keyframes adv-trie-placeholder-pulse {
    from { box-shadow: 0 0 0 3px rgba(13,148,136,0.10), 0 4px 14px rgba(15,118,110,0.10); }
    to   { box-shadow: 0 0 0 7px rgba(13,148,136,0.32), 0 4px 18px rgba(15,118,110,0.36); }
}
/* Stage 14e: root/head/source badge — small pill above the first node of every
   ds-advanced structure. Static (no animation), survives all phases. */
.math-ds-adv-viz .adv-root-badge {
    position: absolute;
    top: -16px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 9px;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: #4f46e5;
    background: rgba(238, 242, 255, 0.96);
    border: 1px solid rgba(99, 102, 241, 0.4);
    border-radius: 6px;
    padding: 1px 5px;
    pointer-events: none;
    white-space: nowrap;
    z-index: 5;
}
.math-ds-adv-viz .math-ds-node.is-root .adv-root-badge,
.math-ds-adv-viz .math-ds-node.adv-root-marker .adv-root-badge { color: #4f46e5; }
/* Heap badge — orange to match heap palette */
.math-ds-adv-viz[data-type="heap"] .adv-root-badge { color: #c2410c; background: rgba(255, 247, 237, 0.96); border-color: rgba(234, 88, 12, 0.45); }
/* Hash bucket [0] head badge — cyan */
.math-ds-adv-viz[data-type="hash-table"] .adv-hash-bucket[data-bucket="0"] { position: relative; }
.math-ds-adv-viz[data-type="hash-table"] .adv-hash-bucket[data-bucket="0"]::before {
    content: 'head';
    position: absolute;
    top: -14px;
    left: 0;
    font-size: 9px;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: #0e7490;
    background: rgba(236, 254, 255, 0.96);
    border: 1px solid rgba(6, 182, 212, 0.4);
    border-radius: 6px;
    padding: 1px 5px;
    pointer-events: none;
}
/* Graph source badge — sits above the source node circle as a separate <text> */
.math-ds-adv-viz .adv-graph-source-badge {
    font-size: 9px;
    font-weight: 700;
    letter-spacing: 0.06em;
    fill: #1d4ed8;
    text-transform: uppercase;
    pointer-events: none;
}

.math-ds-adv-viz .math-ds-node.rbt-red   { background: linear-gradient(135deg, var(--adv-grad-rbt-red), #b91c1c); }
.math-ds-adv-viz .math-ds-node.rbt-black { background: linear-gradient(135deg, var(--adv-grad-rbt-black), #111827); }

.math-ds-adv-viz .math-ds-edge {
    transition: stroke var(--adv-tween), stroke-width var(--adv-tween), opacity var(--adv-tween);
}
.math-ds-adv-viz .math-ds-edge.adv-tracing {
    stroke: var(--adv-grad-hl-a);
    stroke-width: 3.2;
}
.math-ds-adv-viz .math-ds-edge.adv-found {
    stroke: var(--adv-grad-found-a);
    stroke-width: 3.2;
}

/* Heap viz — tree + array strip */
.math-ds-adv-heap-wrap { display: flex; flex-direction: column; gap: 8px; }
.math-ds-adv-heap-tree {
    position: relative;
    width: 100%;
    min-height: 220px;
}
.math-ds-adv-heap-array {
    display: flex;
    gap: 0;
    padding: 8px 0 4px;
    border-top: 1px dashed var(--math-border);
    overflow-x: auto;
}
.adv-heap-cell {
    min-width: 40px;
    height: 40px;
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: rgba(245,158,11,0.08);
    color: var(--math-text);
    font-family: ui-monospace, monospace;
    font-size: 12px;
    font-weight: 700;
    border: 1px solid rgba(245,158,11,0.20);
    border-right: none;
    transition: background var(--adv-tween), color var(--adv-tween), box-shadow var(--adv-tween);
    padding: 2px 4px;
}
.adv-heap-cell:last-child { border-right: 1px solid rgba(245,158,11,0.20); }
.adv-heap-cell .adv-heap-cell-idx {
    font-size: 9px;
    color: var(--math-text-muted);
    font-weight: 500;
}
.adv-heap-cell.is-root { background: linear-gradient(135deg, rgba(245,158,11,0.30), rgba(217,119,6,0.20)); }
.adv-heap-cell.adv-sift {
    background: linear-gradient(135deg, var(--adv-grad-uf-a), var(--adv-grad-uf-b));
    color: #fff;
    box-shadow: 0 0 0 2px rgba(168,85,247,0.30) inset;
}
.adv-heap-cell.adv-found {
    background: linear-gradient(135deg, var(--adv-grad-found-a), var(--adv-grad-found-b));
    color: #fff;
}
.math-ds-adv-heap-tree .math-ds-node {
    background: linear-gradient(135deg, var(--adv-grad-heap-a), var(--adv-grad-heap-b));
    box-shadow: 0 2px 8px rgba(217,119,6,0.25);
}
.math-ds-adv-heap-tree .math-ds-node.is-root {
    box-shadow: 0 0 0 3px rgba(245,158,11,0.40), 0 4px 12px rgba(217,119,6,0.30);
}
.math-ds-adv-heap-tree .math-ds-node.adv-sift {
    background: linear-gradient(135deg, var(--adv-grad-uf-a), var(--adv-grad-uf-b)) !important;
    box-shadow: 0 0 0 3px rgba(168,85,247,0.45), 0 4px 12px rgba(126,34,206,0.30);
    animation: adv-node-pulse var(--adv-tween) ease-in-out;
}
.adv-heap-empty {
    color: var(--math-text-muted);
    font-style: italic;
    font-size: 12.5px;
    text-align: center;
    padding: 30px 0;
}

/* Trie viz — reuses .math-ds-tree node/edge but recolors */
.math-ds-adv-viz[data-type="trie"] .math-ds-node {
    background: linear-gradient(135deg, var(--adv-grad-trie-a), var(--adv-grad-trie-b));
    box-shadow: 0 2px 6px rgba(14,116,144,0.25);
}
.math-ds-adv-viz[data-type="trie"] .math-ds-node.word-end {
    box-shadow: 0 0 0 3px rgba(6,182,212,0.45), 0 4px 12px rgba(14,116,144,0.30);
}
.math-ds-adv-viz[data-type="trie"] .math-ds-trie-label {
    fill: var(--adv-grad-trie-b);
    font-weight: 700;
}

/* Union-Find viz */
.math-ds-adv-viz .math-ds-uf-array { gap: 6px; padding: 4px 0; }
.math-ds-adv-viz .math-ds-uf-cell {
    transition: background var(--adv-tween), border-color var(--adv-tween), box-shadow var(--adv-tween);
}
.math-ds-adv-viz .math-ds-uf-cell.adv-targeting {
    border-color: var(--adv-grad-target-a);
    background: rgba(244,63,94,0.10);
    box-shadow: 0 0 0 2px rgba(244,63,94,0.25);
}
.math-ds-adv-viz .math-ds-uf-cell.adv-found {
    background: linear-gradient(135deg, var(--adv-grad-found-a), var(--adv-grad-found-b));
    border-color: var(--adv-grad-found-b);
    color: #fff;
}
.math-ds-adv-viz .math-ds-uf-cell.adv-found .idx,
.math-ds-adv-viz .math-ds-uf-cell.adv-found .val { color: #fff; }
.math-ds-adv-viz .math-ds-uf-cell.is-root {
    background: linear-gradient(135deg, var(--adv-grad-uf-a), var(--adv-grad-uf-b));
    border-color: var(--adv-grad-uf-b);
    color: #fff;
}
.math-ds-adv-viz .math-ds-uf-cell.is-root .idx,
.math-ds-adv-viz .math-ds-uf-cell.is-root .val { color: #fff; }
.math-ds-adv-viz .math-ds-uf-groups .grp.adv-found {
    background: linear-gradient(135deg, var(--adv-grad-found-a), var(--adv-grad-found-b));
    border-color: transparent;
    color: #fff;
}

/* Hash viz */
.math-ds-adv-hash {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 4px 0;
}
.adv-hash-row {
    display: flex;
    align-items: center;
    gap: 6px;
    min-height: 38px;
}
.adv-hash-idx {
    flex: 0 0 36px;
    text-align: right;
    font-family: ui-monospace, monospace;
    font-size: 11px;
    color: var(--math-text-muted);
    padding-right: 6px;
    border-right: 1px dashed var(--math-border);
}
.adv-hash-bucket {
    display: flex;
    align-items: center;
    gap: 4px;
    flex: 1;
    flex-wrap: wrap;
    min-height: 32px;
    padding: 3px 4px;
    border-radius: 4px;
    transition: background var(--adv-tween);
}
.adv-hash-bucket.adv-targeting { background: rgba(244,63,94,0.08); }
.adv-hash-bucket.adv-tracing   { background: rgba(251,191,36,0.10); }
.adv-hash-bucket-empty {
    color: var(--math-text-muted);
    font-style: italic;
    font-size: 11px;
}
.adv-hash-cell {
    min-width: 36px;
    height: 28px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--adv-grad-hash-a), var(--adv-grad-hash-b));
    color: #fff;
    font-family: ui-monospace, monospace;
    font-weight: 700;
    font-size: 12px;
    border-radius: 4px;
    box-shadow: 0 1px 4px rgba(5,150,105,0.20);
    transition: transform var(--adv-tween), box-shadow var(--adv-tween), opacity var(--adv-tween);
}
.adv-hash-cell.adv-landing  { animation: adv-cell-land var(--adv-tween) var(--adv-ease); }
.adv-hash-cell.adv-found    { box-shadow: 0 0 0 3px rgba(16,185,129,0.40), 0 4px 12px rgba(5,150,105,0.30); animation: adv-cell-pulse var(--adv-tween) ease-out; }
.adv-hash-cell.adv-targeting{ box-shadow: 0 0 0 3px rgba(244,63,94,0.40); }
.adv-hash-cell.adv-leaving  { animation: adv-cell-leave var(--adv-tween) forwards; }
.adv-hash-arrow {
    color: var(--adv-grad-hash-b);
    font-weight: 700;
    font-size: 13px;
    user-select: none;
}
.math-ds-adv-hash-meta {
    margin-top: 6px;
    font-family: ui-monospace, monospace;
    font-size: 11px;
    color: var(--math-text-muted);
}

/* Graph viz */
.math-ds-adv-viz .math-ds-graph {
    min-height: 360px;
}
.math-ds-adv-viz .math-ds-graph-node circle {
    fill: var(--math-surface-subtle);
    stroke: var(--adv-grad-graph-a);
    stroke-width: 2;
    transition: fill var(--adv-tween), stroke var(--adv-tween), stroke-width var(--adv-tween);
}
.math-ds-adv-viz .math-ds-graph-node text {
    font-family: ui-monospace, monospace;
    font-size: 13px;
    font-weight: 700;
    fill: var(--math-text);
    transition: fill var(--adv-tween);
}
.math-ds-adv-viz .math-ds-graph-node.visited circle {
    fill: var(--adv-grad-graph-b);
    stroke: var(--adv-grad-graph-b);
}
.math-ds-adv-viz .math-ds-graph-node.visited text {
    fill: #fff;
}
.math-ds-adv-viz .math-ds-graph-node.is-source circle {
    fill: var(--adv-grad-found-b);
    stroke: var(--adv-grad-found-b);
}
.math-ds-adv-viz .math-ds-graph-node.is-source text { fill: #fff; }
.math-ds-adv-viz .math-ds-graph-node.adv-pulse circle {
    animation: adv-circle-pulse var(--adv-tween) ease-out;
}
.math-ds-adv-viz .math-ds-graph-edge {
    stroke: rgba(59,130,246,0.30);
    stroke-width: 2;
    transition: stroke var(--adv-tween), stroke-width var(--adv-tween);
}
.math-ds-adv-viz .math-ds-graph-edge.adv-tracing {
    stroke: var(--adv-grad-hl-a);
    stroke-width: 3.5;
}
.math-ds-adv-viz .math-ds-graph-edge-arrow {
    fill: rgba(59,130,246,0.50);
    transition: fill var(--adv-tween);
}
.math-ds-adv-viz .math-ds-graph-edge-arrow.adv-tracing {
    fill: var(--adv-grad-hl-b);
}
.math-ds-adv-graph-order-pill {
    position: absolute;
    top: 8px;
    right: 8px;
    padding: 4px 10px;
    background: linear-gradient(135deg, var(--adv-grad-graph-a), var(--adv-grad-graph-b));
    color: #fff;
    border-radius: 99px;
    font-family: ui-monospace, monospace;
    font-size: 11px;
    font-weight: 700;
    box-shadow: 0 2px 6px rgba(29,78,216,0.30);
    z-index: 4;
}

.math-ds-adv-graph-order {
    fill: #fff;
    font-family: ui-monospace, monospace;
    font-size: 9px;
    font-weight: 800;
}

.math-ds-adv-meta {
    font-size: 11.5px;
    color: var(--math-text-muted);
    font-family: ui-monospace, monospace;
    margin-top: 8px;
    padding-top: 6px;
    border-top: 1px dashed var(--math-border);
}

/* Placeholder (empty) message */
.math-ds-adv-viz .math-ds-placeholder {
    color: var(--math-text-muted);
    font-style: italic;
    font-size: 12.5px;
    text-align: center;
    padding: 36px 8px;
}

/* Narrator */
.math-ds-adv-narrator {
    margin-top: 10px;
    padding: 10px 14px;
    border-left: 3px solid var(--adv-grad-tree-a);
    background: linear-gradient(90deg, rgba(99,102,241,0.06), transparent 80%);
    border-radius: 4px;
    font-size: 12.5px;
    line-height: 1.55;
    color: var(--math-text);
}
.math-ds-adv-narrator:empty { display: none; }
.math-ds-adv-narrator[data-type="trie"]       { border-left-color: var(--adv-grad-trie-b);  background: linear-gradient(90deg, rgba(6,182,212,0.06), transparent 80%); }
.math-ds-adv-narrator[data-type="heap"]       { border-left-color: var(--adv-grad-heap-b);  background: linear-gradient(90deg, rgba(245,158,11,0.06), transparent 80%); }
.math-ds-adv-narrator[data-type="union-find"] { border-left-color: var(--adv-grad-uf-b);    background: linear-gradient(90deg, rgba(168,85,247,0.06), transparent 80%); }
.math-ds-adv-narrator[data-type="hash-table"] { border-left-color: var(--adv-grad-hash-b);  background: linear-gradient(90deg, rgba(16,185,129,0.06), transparent 80%); }
.math-ds-adv-narrator[data-type="graph"]      { border-left-color: var(--adv-grad-graph-b); background: linear-gradient(90deg, rgba(59,130,246,0.06), transparent 80%); }
.math-ds-adv-narrator[data-type="rbt"]        { border-left-color: var(--adv-grad-rbt-red); background: linear-gradient(90deg, rgba(239,68,68,0.05), transparent 80%); }

.adv-narr-title {
    font-family: ui-monospace, monospace;
    font-weight: 700;
    color: #4338ca;
    font-size: 12px;
    margin-bottom: 4px;
}
.math-ds-adv-narrator[data-type="trie"]       .adv-narr-title { color: #0e7490; }
.math-ds-adv-narrator[data-type="heap"]       .adv-narr-title { color: #b45309; }
.math-ds-adv-narrator[data-type="union-find"] .adv-narr-title { color: #6b21a8; }
.math-ds-adv-narrator[data-type="hash-table"] .adv-narr-title { color: #047857; }
.math-ds-adv-narrator[data-type="graph"]      .adv-narr-title { color: #1e40af; }
.math-ds-adv-narrator[data-type="rbt"]        .adv-narr-title { color: #b91c1c; }

.adv-narr-body { color: var(--math-text); }
.adv-narr-body code {
    background: rgba(99,102,241,0.10);
    color: #4338ca;
    padding: 1px 5px;
    border-radius: 3px;
    font-size: 11.5px;
    font-family: ui-monospace, monospace;
}
.adv-narr-body strong { color: #4338ca; }
.math-ds-adv-narrator[data-type="trie"]       .adv-narr-body code,
.math-ds-adv-narrator[data-type="trie"]       .adv-narr-body strong { color: #0e7490; }
.math-ds-adv-narrator[data-type="heap"]       .adv-narr-body code,
.math-ds-adv-narrator[data-type="heap"]       .adv-narr-body strong { color: #b45309; }
.math-ds-adv-narrator[data-type="union-find"] .adv-narr-body code,
.math-ds-adv-narrator[data-type="union-find"] .adv-narr-body strong { color: #6b21a8; }
.math-ds-adv-narrator[data-type="hash-table"] .adv-narr-body code,
.math-ds-adv-narrator[data-type="hash-table"] .adv-narr-body strong { color: #047857; }
.math-ds-adv-narrator[data-type="graph"]      .adv-narr-body code,
.math-ds-adv-narrator[data-type="graph"]      .adv-narr-body strong { color: #1e40af; }
.math-ds-adv-narrator[data-type="rbt"]        .adv-narr-body code,
.math-ds-adv-narrator[data-type="rbt"]        .adv-narr-body strong { color: #b91c1c; }
.adv-narr-impact {
    margin-top: 4px;
    font-size: 11.5px;
    color: var(--math-text-muted);
    font-style: italic;
}

/* Progress chip */
.math-ds-adv-progress {
    margin-top: 8px;
    padding: 8px 12px;
    border-radius: var(--math-radius-md);
    background: rgba(99,102,241,0.06);
    border: 1px solid rgba(99,102,241,0.18);
    transition: opacity 0.4s;
}
.math-ds-adv-progress[hidden] { display: none; }
.adv-progress-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 5px;
    font-size: 11.5px;
    font-family: ui-monospace, monospace;
    color: var(--math-text);
}
.adv-progress-label { font-weight: 600; color: #4338ca; }
.adv-progress-counter { color: var(--math-text-muted); }
.adv-progress-track {
    height: 4px;
    background: rgba(99,102,241,0.15);
    border-radius: 2px;
    overflow: hidden;
}
.adv-progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--adv-grad-tree-a), var(--adv-grad-tree-b));
    border-radius: 2px;
    width: 0%;
    transition: width 0.3s ease-out;
}

/* Busy state during stagger */
.math-ds-adv-panel.is-busy .math-ds-adv-type-segment .math-mode-segment-btn,
.math-ds-adv-panel.is-busy .math-ds-adv-actions .math-btn,
.math-ds-adv-panel.is-busy #dsaValue,
.math-ds-adv-panel.is-busy #dsaIndex,
.math-ds-adv-panel.is-busy #dsaRandomBtn,
.math-ds-adv-panel.is-busy #dsaSpeed .math-mode-segment-btn {
    pointer-events: none;
    opacity: 0.55;
}

/* Animations */
@keyframes adv-node-land {
    0%   { transform: translate(-50%, -50%) scale(0.5); opacity: 0; }
    60%  { transform: translate(-50%, -50%) scale(1.15); opacity: 1; }
    100% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
}
@keyframes adv-node-leave {
    0%   { transform: translate(-50%, -50%) scale(1); opacity: 1; }
    100% { transform: translate(-50%, -50%) scale(0.3); opacity: 0; }
}
@keyframes adv-node-pulse {
    0%, 100% { transform: translate(-50%, -50%) scale(1); }
    50%      { transform: translate(-50%, -50%) scale(1.15); }
}
@keyframes adv-node-rotate {
    0%, 100% { transform: translate(-50%, -50%) scale(1) rotate(0deg); }
    50%      { transform: translate(-50%, -50%) scale(1.08) rotate(6deg); }
}
@keyframes adv-cell-land {
    0%   { transform: translateY(-12px) scale(0.7); opacity: 0; }
    60%  { transform: translateY(2px) scale(1.08); opacity: 1; }
    100% { transform: translateY(0) scale(1); opacity: 1; }
}
@keyframes adv-cell-pulse {
    0%, 100% { transform: scale(1); }
    50%      { transform: scale(1.10); }
}
@keyframes adv-cell-leave {
    0%   { transform: translateX(0) scale(1); opacity: 1; }
    100% { transform: translateX(-22px) scale(0.7); opacity: 0; }
}
@keyframes adv-circle-pulse {
    0%, 100% { stroke-width: 2; }
    50%      { stroke-width: 5; }
}

/* Mobile */
@media (max-width: 720px) {
    .math-ds-adv-type-segment .math-mode-segment-btn { flex: 1 1 calc(50% - 4px); min-height: 50px; padding: 6px 8px; }
    .math-ds-adv-type-segment .adv-seg-title { font-size: 12px; }
    .math-ds-adv-type-segment .adv-seg-sub   { font-size: 9.5px; }
    .adv-info-body { grid-template-columns: 1fr; }
    .adv-info-mini { align-items: flex-start; }
    .adv-info-legend { text-align: left; max-width: 100%; }
    .adv-rand-text-long { display: none; }
    .math-ds-adv-stats {
        flex-wrap: nowrap;
        overflow-x: auto;
        mask-image: linear-gradient(90deg, transparent, #000 12px, #000 calc(100% - 12px), transparent);
        -webkit-mask-image: linear-gradient(90deg, transparent, #000 12px, #000 calc(100% - 12px), transparent);
    }
    .math-ds-adv-viz { padding: 12px 4px 4px; }
    .math-ds-adv-heap-tree { min-height: 180px; }
    .math-ds-adv-viz .math-ds-graph { min-height: 280px; }
}

@media (prefers-reduced-motion: reduce) {
    .math-ds-adv-viz .math-ds-node,
    .math-ds-adv-viz .math-ds-edge,
    .math-ds-adv-viz .math-ds-uf-cell,
    .math-ds-adv-viz .math-ds-uf-cell.adv-compress,
    .math-ds-adv-viz .adv-hash-cell,
    .math-ds-adv-viz .math-ds-graph-node circle,
    .math-ds-adv-viz .math-ds-graph-edge,
    .math-ds-adv-viz .math-ds-node.adv-pivot-rise,
    .math-ds-adv-viz svg .adv-edge-ghost,
    .math-ds-adv-viz .math-ds-tree .math-ds-node.adv-placeholder,
    .math-ds-adv-progress .adv-progress-fill {
        animation: none !important;
        transition-duration: 0ms !important;
    }
}

/* ============================================================
   Stage 14 — ds-advanced redesign: narrator + step-banner +
   per-DS visual modifiers (BST/AVL/RBT/Trie/Heap/UF/Hash/Graph)
   ============================================================ */

/* ── Narrator card ── */
.math-ds-adv-narrator {
    margin-top: 12px;
    padding: 12px 14px 14px;
    border-left: 3px solid #6366f1;
    background: linear-gradient(135deg, rgba(99,102,241,0.04), rgba(99,102,241,0.01));
    border-radius: 0 10px 10px 0;
}
.math-ds-adv-narrator:empty { display: none; }
.math-ds-adv-narrator .adv-narr-title {
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 13px;
    font-weight: 700;
    color: var(--math-text-strong, #1f2937);
    margin-bottom: 6px;
    letter-spacing: -0.01em;
}
.math-ds-adv-narrator .adv-narr-body {
    font-size: 13px;
    line-height: 1.6;
    color: var(--math-text-strong, #1f2937);
    margin-bottom: 8px;
}
.math-ds-adv-narrator .adv-narr-body code {
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 12px;
    padding: 1px 5px;
    border-radius: 4px;
    background: rgba(99,102,241,0.10);
    color: #4338ca;
}
.math-ds-adv-narrator .adv-narr-body strong { color: #4f46e5; font-weight: 700; }
.math-ds-adv-narrator .adv-narr-body ol {
    margin: 6px 0 0 0;
    padding-left: 22px;
    counter-reset: narr;
}
.math-ds-adv-narrator .adv-narr-body ol li {
    margin: 3px 0;
    padding-left: 4px;
}
.math-ds-adv-narrator .adv-narr-impact {
    font-size: 12px;
    color: var(--math-text-muted, #6b7280);
    font-family: ui-monospace, monospace;
    padding-top: 6px;
    border-top: 1px dashed rgba(99,102,241,0.18);
}
.math-ds-adv-narrator[data-type="trie"]       { border-left-color: #06b6d4; background: linear-gradient(135deg, rgba(6,182,212,0.05), rgba(6,182,212,0.01)); }
.math-ds-adv-narrator[data-type="heap"]       { border-left-color: #f59e0b; background: linear-gradient(135deg, rgba(245,158,11,0.05), rgba(245,158,11,0.01)); }
.math-ds-adv-narrator[data-type="union-find"] { border-left-color: #a855f7; background: linear-gradient(135deg, rgba(168,85,247,0.05), rgba(168,85,247,0.01)); }
.math-ds-adv-narrator[data-type="hash-table"] { border-left-color: #10b981; background: linear-gradient(135deg, rgba(16,185,129,0.05), rgba(16,185,129,0.01)); }
.math-ds-adv-narrator[data-type="graph"]      { border-left-color: #3b82f6; background: linear-gradient(135deg, rgba(59,130,246,0.05), rgba(59,130,246,0.01)); }
.math-ds-adv-narrator[data-type="rbt"]        { border-left-color: #1f2937; }

/* ── Step banner pill ── */
.math-ds-adv-step-banner {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 14px;
    margin: 8px 0;
    border-radius: 999px;
    font-size: 12.5px;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-weight: 600;
    line-height: 1.3;
    background: rgba(100,116,139,0.10);
    color: #475569;
    border: 1px solid rgba(100,116,139,0.18);
    animation: adv-banner-fade 0.5s cubic-bezier(.2,.9,.3,1) both;
}
.math-ds-adv-step-banner[hidden] { display: none !important; }
.math-ds-adv-step-banner code {
    font-size: 12px;
    padding: 1px 5px;
    border-radius: 4px;
    background: rgba(255,255,255,0.55);
}
.math-ds-adv-step-banner::before {
    content: '';
    display: inline-block;
    width: 14px;
    height: 14px;
    border-radius: 999px;
    flex: 0 0 auto;
    background: currentColor;
    opacity: 0.55;
}
.math-ds-adv-step-banner.is-compare  { background: rgba(99,102,241,0.10); color: #4338ca; border-color: rgba(99,102,241,0.20); }
.math-ds-adv-step-banner.is-rotate   { background: rgba(245,158,11,0.12); color: #92400e; border-color: rgba(245,158,11,0.25); }
.math-ds-adv-step-banner.is-recolor  { background: rgba(168,85,247,0.12); color: #6b21a8; border-color: rgba(168,85,247,0.25); }
.math-ds-adv-step-banner.is-sift     { background: rgba(168,85,247,0.12); color: #6b21a8; border-color: rgba(168,85,247,0.25); }
.math-ds-adv-step-banner.is-pathcomp { background: rgba(16,185,129,0.12); color: #047857; border-color: rgba(16,185,129,0.25); }
.math-ds-adv-step-banner.is-rehash   { background: rgba(249,115,22,0.12); color: #c2410c; border-color: rgba(249,115,22,0.30); }
.math-ds-adv-step-banner.is-traverse { background: rgba(59,130,246,0.12); color: #1d4ed8; border-color: rgba(59,130,246,0.25); }
.math-ds-adv-step-banner.is-found    { background: rgba(16,185,129,0.12); color: #047857; border-color: rgba(16,185,129,0.25); }
.math-ds-adv-step-banner.is-target   { background: rgba(244,63,94,0.12);  color: #be123c; border-color: rgba(244,63,94,0.25); }
.math-ds-adv-step-banner.is-insert   { background: rgba(16,185,129,0.12); color: #047857; border-color: rgba(16,185,129,0.25); }

@keyframes adv-banner-fade {
    from { opacity: 0; transform: translateY(-4px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ── BST/AVL/RBT — comparison highlight + AVL bf badge + RBT recolor transition ── */
.math-ds-adv-viz .math-ds-node { transition: background-color 0.4s ease, color 0.4s ease, box-shadow 0.3s ease; }
.math-ds-adv-viz .math-ds-node.adv-compare-now {
    background: linear-gradient(135deg, #fbbf24, #d97706) !important;
    box-shadow: 0 0 0 4px rgba(251,191,36,0.42), 0 0 18px rgba(217,119,6,0.45);
    animation: adv-compare-pulse 0.9s ease-in-out infinite;
    z-index: 5;
}
@keyframes adv-compare-pulse {
    0%, 100% { box-shadow: 0 0 0 4px rgba(251,191,36,0.32), 0 4px 12px rgba(217,119,6,0.36); }
    50%      { box-shadow: 0 0 0 7px rgba(251,191,36,0.55), 0 4px 16px rgba(217,119,6,0.55); }
}

/* Descent cursor — chevron that hops between nodes during BST/AVL/RBT comparison */
.math-ds-adv-viz .math-ds-tree {
    position: relative;
}
.math-ds-adv-viz .adv-cursor {
    position: absolute;
    width: 56px;
    height: 56px;
    pointer-events: none;
    z-index: 10;
    transform: translate(-50%, -50%);
    transition: left 0.55s cubic-bezier(.2,.9,.3,1), top 0.55s cubic-bezier(.2,.9,.3,1), opacity .25s ease;
    opacity: 0;
}
.math-ds-adv-viz .adv-cursor.visible { opacity: 1; }
.math-ds-adv-viz .adv-cursor::before {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: 50%;
    border: 2.5px dashed rgba(99,102,241,0.85);
    animation: adv-cursor-spin 4s linear infinite;
    box-shadow: 0 0 14px rgba(99,102,241,0.45);
}
.math-ds-adv-viz .adv-cursor::after {
    content: '▾';
    position: absolute;
    top: -22px;
    left: 50%;
    transform: translateX(-50%);
    color: #4338ca;
    font-size: 18px;
    font-weight: 800;
    text-shadow: 0 1px 3px rgba(255,255,255,0.95);
    animation: adv-cursor-bob 1s ease-in-out infinite;
}
@keyframes adv-cursor-spin {
    to { transform: rotate(360deg); }
}
@keyframes adv-cursor-bob {
    0%, 100% { transform: translateX(-50%); }
    50%      { transform: translateX(-50%) translateY(-3px); }
}
.math-ds-adv-viz .math-ds-edge.adv-compare {
    stroke: #6366f1;
    stroke-width: 2.5;
}
.math-ds-adv-viz .adv-bf-badge {
    position: absolute;
    top: -8px;
    right: -10px;
    font-size: 9.5px;
    font-family: ui-monospace, monospace;
    font-weight: 700;
    line-height: 1;
    padding: 2px 5px;
    border-radius: 999px;
    background: #e2e8f0;
    color: #475569;
    border: 1px solid #cbd5e1;
    pointer-events: none;
    z-index: 6;
}
.math-ds-adv-viz .adv-bf-badge.bf-zero  { background: #e2e8f0; color: #475569; }
.math-ds-adv-viz .adv-bf-badge.bf-tilt  { background: #fef3c7; color: #92400e; border-color: #fcd34d; }
.math-ds-adv-viz .adv-bf-badge.bf-broken { background: #fee2e2; color: #991b1b; border-color: #fca5a5; animation: adv-node-pulse 0.7s ease-in-out infinite alternate; }
@keyframes adv-node-pulse {
    from { box-shadow: 0 0 0 0 rgba(239,68,68,0); }
    to   { box-shadow: 0 0 0 4px rgba(239,68,68,0.35); }
}

/* ── Trie — input-cursor strip ── */
.math-ds-adv-viz .adv-trie-input-strip {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 6px 10px;
    margin-bottom: 10px;
    background: rgba(6,182,212,0.06);
    border: 1px solid rgba(6,182,212,0.15);
    border-radius: 8px;
    font-family: ui-monospace, monospace;
}
.math-ds-adv-viz .adv-trie-input-strip .label {
    font-size: 11px;
    color: var(--math-text-muted, #6b7280);
    margin-right: 6px;
}
.math-ds-adv-viz .adv-trie-input-char {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 22px;
    padding: 3px 7px;
    border-radius: 5px;
    font-size: 13px;
    font-weight: 600;
    background: rgba(100,116,139,0.10);
    color: #6b7280;
    border: 1px solid transparent;
    transition: all 0.3s ease;
}
.math-ds-adv-viz .adv-trie-input-char.is-typed {
    background: rgba(16,185,129,0.15);
    color: #047857;
    border-color: rgba(16,185,129,0.30);
}
.math-ds-adv-viz .adv-trie-input-char.is-current {
    background: rgba(245,158,11,0.20);
    color: #92400e;
    border-color: rgba(245,158,11,0.45);
    transform: scale(1.12);
    box-shadow: 0 0 0 2px rgba(245,158,11,0.25);
}
.math-ds-adv-viz .adv-trie-input-char.is-missing {
    background: rgba(244,63,94,0.15);
    color: #be123c;
    border-color: rgba(244,63,94,0.30);
}

/* ── Heap — sift pair edge highlight ── */
.math-ds-adv-viz .math-ds-edge.adv-sift-pair {
    stroke: #f59e0b;
    stroke-width: 3;
    animation: adv-edge-pulse 0.7s ease-in-out infinite alternate;
}
.math-ds-adv-viz .math-ds-node.adv-sift-pair {
    box-shadow: 0 0 0 3px rgba(245,158,11,0.55), 0 0 14px rgba(245,158,11,0.40);
    z-index: 5;
}
.math-ds-adv-viz .adv-heap-cell.adv-sift-pair {
    background: linear-gradient(135deg, #fef3c7, #fde68a);
    border-color: #f59e0b;
    box-shadow: 0 0 0 2px rgba(245,158,11,0.40);
}
@keyframes adv-edge-pulse {
    from { stroke-opacity: 0.55; }
    to   { stroke-opacity: 1; }
}

/* ── Union-Find — find walk + path-compression flash + parent arrows ── */
.math-ds-adv-viz .math-ds-uf-cell { transition: background 0.35s ease, box-shadow 0.3s ease; position: relative; }
.math-ds-adv-viz .math-ds-uf-cell.adv-walking {
    box-shadow: 0 0 0 2px rgba(99,102,241,0.55);
    background: rgba(99,102,241,0.10);
}
.math-ds-adv-viz .math-ds-uf-cell.adv-arrived {
    box-shadow: 0 0 0 2px rgba(16,185,129,0.55);
    background: rgba(16,185,129,0.12);
}
.math-ds-adv-viz .math-ds-uf-cell.adv-compress {
    animation: adv-uf-compress-flash 0.7s ease-out;
    background: rgba(16,185,129,0.18);
}
@keyframes adv-uf-compress-flash {
    0%   { background: rgba(16,185,129,0.40); transform: scale(1.05); }
    100% { background: rgba(16,185,129,0.10); transform: scale(1); }
}
.math-ds-adv-viz .adv-uf-arrow-svg {
    position: absolute;
    pointer-events: none;
    overflow: visible;
}
.math-ds-adv-viz .adv-uf-arrow {
    stroke: #94a3b8;
    stroke-width: 1.5;
    fill: none;
    transition: stroke 0.3s ease, stroke-width 0.3s ease;
}
.math-ds-adv-viz .adv-uf-arrow.is-walked { stroke: #6366f1; stroke-width: 2.2; }
.math-ds-adv-viz .adv-uf-arrow.is-compressed { stroke: #10b981; stroke-width: 2; stroke-dasharray: 4 3; }

/* ── Hash — formula pill above buckets ── */
.math-ds-adv-viz .adv-hash-formula-pill {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    margin-bottom: 10px;
    border-radius: 999px;
    background: rgba(16,185,129,0.08);
    border: 1px solid rgba(16,185,129,0.20);
    font-family: ui-monospace, monospace;
    font-size: 12px;
    color: #047857;
}
.math-ds-adv-viz .adv-hash-formula-pill .hf-key { color: #1f2937; font-weight: 700; }
.math-ds-adv-viz .adv-hash-formula-pill .hf-arrow { color: #6b7280; }
.math-ds-adv-viz .adv-hash-formula-pill .hf-mod { color: #4338ca; }
.math-ds-adv-viz .adv-hash-formula-pill .hf-idx { font-weight: 700; color: #047857; padding: 1px 7px; background: rgba(16,185,129,0.15); border-radius: 5px; }
.math-ds-adv-viz .adv-hash-cell.adv-chain-walk {
    box-shadow: 0 0 0 2px rgba(100,116,139,0.45);
    background: rgba(100,116,139,0.10);
}
.math-ds-adv-viz .adv-hash-bucket.adv-rehash-shake {
    animation: adv-rehash-shake 0.45s cubic-bezier(.36,.07,.19,.97);
}
@keyframes adv-rehash-shake {
    10%, 90% { transform: translate3d(-1px, 0, 0); }
    20%, 80% { transform: translate3d(2px, 0, 0); }
    30%, 50%, 70% { transform: translate3d(-3px, 0, 0); }
    40%, 60% { transform: translate3d(3px, 0, 0); }
}

/* ── Graph — frontier strip (queue/stack mini-viz) ── */
.math-ds-adv-viz .adv-graph-frontier-strip {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 7px 12px;
    margin-top: 10px;
    background: rgba(59,130,246,0.06);
    border: 1px solid rgba(59,130,246,0.18);
    border-radius: 8px;
    font-family: ui-monospace, monospace;
    font-size: 12px;
    flex-wrap: wrap;
}
.math-ds-adv-viz .adv-graph-frontier-strip .label {
    color: #1d4ed8;
    font-weight: 700;
    margin-right: 4px;
}
.math-ds-adv-viz .adv-graph-frontier-strip .frontier-pill {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 22px;
    padding: 2px 8px;
    border-radius: 5px;
    background: rgba(59,130,246,0.15);
    color: #1d4ed8;
    font-weight: 600;
}
.math-ds-adv-viz .adv-graph-frontier-strip .frontier-pill.is-current {
    background: rgba(245,158,11,0.20);
    color: #92400e;
    box-shadow: 0 0 0 2px rgba(245,158,11,0.40);
}
.math-ds-adv-viz .adv-graph-frontier-strip .frontier-empty { color: var(--math-text-muted, #6b7280); font-style: italic; }
.math-ds-adv-viz .math-ds-graph-node.adv-current circle {
    stroke: #f59e0b;
    stroke-width: 3;
    filter: drop-shadow(0 0 6px rgba(245,158,11,0.55));
}

/* ── Reduced motion fallback for new components ── */
@media (prefers-reduced-motion: reduce) {
    .math-ds-adv-step-banner,
    .math-ds-adv-viz .adv-bf-badge.bf-broken,
    .math-ds-adv-viz .math-ds-edge.adv-sift-pair,
    .math-ds-adv-viz .math-ds-uf-cell.adv-compress,
    .math-ds-adv-viz .adv-hash-bucket.adv-rehash-shake,
    .math-ds-adv-viz .adv-trie-input-char {
        animation: none !important;
        transition-duration: 0ms !important;
    }
}

/* ── Mobile tweaks for new components ── */
@media (max-width: 640px) {
    .math-ds-adv-step-banner { font-size: 11.5px; padding: 6px 10px; }
    .math-ds-adv-narrator { padding: 10px 12px; }
    .math-ds-adv-narrator .adv-narr-title { font-size: 12px; }
    .math-ds-adv-narrator .adv-narr-body { font-size: 12px; line-height: 1.55; }
    .math-ds-adv-viz .adv-trie-input-strip { padding: 5px 8px; gap: 4px; }
    .math-ds-adv-viz .adv-trie-input-char { font-size: 12px; padding: 2px 6px; min-width: 18px; }
    .math-ds-adv-viz .adv-graph-frontier-strip { padding: 6px 10px; font-size: 11.5px; }
    .math-ds-adv-viz .adv-hash-formula-pill { font-size: 11.5px; padding: 5px 10px; }
}
