/* ===== Base Variables ===== */
:root {
    --viz-font: 'Inter', 'Helvetica Neue', Arial, sans-serif;
    --viz-bg: #ffffff;
    --viz-text: #1f2937;
    --viz-border: #e5e7eb;
    --viz-accent: #3b82f6;
    --viz-node-bg: #eff6ff;
    --viz-node-border: #93c5fd;
    --viz-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

/* ===== Presets ===== */
/* Minimal */
.viz-preset-minimal {
    --viz-bg: #ffffff;
    --viz-text: #111827;
    --viz-border: #d1d5db;
    --viz-accent: #111827;
    --viz-node-bg: #ffffff;
    --viz-node-border: #d1d5db;
    --viz-shadow: none;
}

/* Dark Space */
.viz-preset-dark {
    --viz-bg: #0f172a;
    --viz-text: #f8fafc;
    --viz-border: #334155;
    --viz-accent: #38bdf8;
    --viz-node-bg: #1e293b;
    --viz-node-border: #475569;
    --viz-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.5);
}

/* Glassmorphism */
.viz-preset-glass {
    --viz-bg: rgba(255, 255, 255, 0.15);
    background-image: linear-gradient(135deg, rgba(255, 255, 255, 0.4) 0%, rgba(255, 255, 255, 0.1) 100%);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    --viz-text: #ffffff;
    --viz-border: rgba(255, 255, 255, 0.3);
    --viz-accent: #f472b6;
    --viz-node-bg: rgba(255, 255, 255, 0.2);
    --viz-node-border: rgba(255, 255, 255, 0.4);
    --viz-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.37);
}

/* Cyber Neon */
.viz-preset-neon {
    --viz-bg: #050510;
    --viz-text: #e0e7ff;
    --viz-border: #1e1e3f;
    --viz-accent: #00ffcc;
    --viz-node-bg: #0b0b1a;
    --viz-node-border: #00ffcc;
    --viz-shadow: 0 0 10px rgba(0, 255, 204, 0.5), inset 0 0 10px rgba(0, 255, 204, 0.2);
}

/* Prototyping (Sketch) */
.viz-preset-sketch {
    --viz-font: 'Comic Sans MS', 'Chalkboard SE', 'Caveat', cursive, sans-serif;
    --viz-bg: #fdfaf6;
    --viz-text: #2c2c2c;
    --viz-border: #888;
    --viz-accent: #d97706;
    --viz-node-bg: #ffffff;
    --viz-node-border: #444;
    --viz-shadow: 2px 2px 0px rgba(0, 0, 0, 0.8);
}

.viz-preset-sketch .viz-canvas svg {
    filter: url(#viz-rough-filter) drop-shadow(2px 2px 0px rgba(0, 0, 0, 0.3));
}

.viz-preset-sketch .node rect,
.viz-preset-sketch .node polygon,
.viz-preset-sketch .node circle {
    stroke-dasharray: 4, 2;
    stroke-width: 2px;
}

/* ===== Layout & UI ===== */
.viz-wrapper {
    display: flex;
    flex-direction: column;
    border: 1px solid var(--viz-border);
    border-radius: 12px;
    background: var(--viz-bg);
    color: var(--viz-text);
    box-shadow: var(--viz-shadow);
    overflow: hidden;
    font-family: var(--viz-font);
    margin-bottom: 2rem;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.viz-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background: rgba(0, 0, 0, 0.03);
    border-bottom: 1px solid var(--viz-border);
}

.viz-preset-dark .viz-header,
.viz-preset-neon .viz-header,
.viz-preset-glass .viz-header {
    background: rgba(255, 255, 255, 0.05);
}

.viz-title {
    font-weight: 600;
    font-size: 0.95rem;
    letter-spacing: 0.5px;
}

.viz-controls {
    display: flex;
    gap: 12px;
    align-items: center;
}

.viz-btn,
.viz-preset-selector {
    background: var(--viz-node-bg);
    color: var(--viz-text);
    border: 1px solid var(--viz-border);
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.2s;
    outline: none;
}

.viz-btn:hover,
.viz-preset-selector:hover {
    border-color: var(--viz-accent);
    box-shadow: 0 0 5px rgba(0, 0, 0, 0.1);
}

.viz-preset-neon .viz-btn:hover {
    box-shadow: 0 0 8px var(--viz-accent);
}

.viz-btn-render {
    background: var(--viz-accent);
    color: #fff;
    border: none;
    font-weight: bold;
}

.viz-preset-neon .viz-btn-render {
    color: #050510;
}

.viz-zoom-controls {
    display: flex;
    gap: 4px;
    background: rgba(0, 0, 0, 0.05);
    padding: 3px;
    border-radius: 8px;
}

.viz-preset-dark .viz-zoom-controls,
.viz-preset-neon .viz-zoom-controls {
    background: rgba(255, 255, 255, 0.05);
}

.viz-body {
    display: flex;
    flex-direction: column;
    height: var(--viz-height, 500px);
}

@media (min-width: 768px) {
    .viz-body {
        flex-direction: row;
    }
}

.viz-editor {
    flex: 1;
    min-width: 250px;
    padding: 20px;
    border: none;
    border-right: 1px solid var(--viz-border);
    background: rgba(0, 0, 0, 0.02);
    color: var(--viz-text);
    font-family: 'Fira Code', Consolas, monospace;
    font-size: 0.9rem;
    line-height: 1.6;
    resize: none;
}

.viz-preset-dark .viz-editor,
.viz-preset-neon .viz-editor {
    background: rgba(0, 0, 0, 0.2);
}

.viz-editor:focus {
    outline: none;
}

.viz-canvas-container {
    flex: 2;
    overflow: hidden;
    position: relative;
    cursor: grab;
    display: flex;
    justify-content: center;
    align-items: center;
}

.viz-canvas-container:active {
    cursor: grabbing;
}

.viz-canvas {
    transform-origin: 0 0;
    will-change: transform;
    /* transition is handled by JS dynamically, but default fallback below */
    transition: transform 0.1s ease-out;
    display: inline-block;
    position: relative;
}

.viz-canvas svg {
    overflow: visible;
}

.viz-canvas .edgeLabel,
.viz-canvas .edgeLabel * {
    pointer-events: all !important;
    user-select: none;
    cursor: pointer;
}

/* Cinematic zoom transition */
.viz-canvas.viz-cinematic {
    transition: transform 1.2s cubic-bezier(0.25, 1, 0.5, 1) !important;
}

/* Glassmorphism Tooltip */
.viz-tooltip {
    position: absolute;
    top: 0;
    left: 0;
    background: rgba(255, 255, 255, 0.7);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.5);
    padding: 8px 12px;
    border-radius: 8px;
    font-size: 0.8rem;
    color: #333;
    pointer-events: none;
    opacity: 0;
    transform: translateY(10px);
    transition: all 0.2s ease-out;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
    z-index: 100;
}

.viz-tooltip.viz-show {
    opacity: 1;
    transform: translateY(0);
}

.viz-preset-dark .viz-tooltip,
.viz-preset-neon .viz-tooltip {
    background: rgba(15, 23, 42, 0.8);
    color: #fff;
    border-color: rgba(255, 255, 255, 0.1);
}

/* Particle effect */
.viz-particle {
    position: absolute;
    width: 6px;
    height: 6px;
    background: var(--viz-accent);
    border-radius: 50%;
    pointer-events: none;
    animation: viz-particle-anim 0.6s ease-out forwards;
    z-index: 50;
    box-shadow: 0 0 6px var(--viz-accent);
}

@keyframes viz-particle-anim {
    0% {
        transform: scale(1) translate(0, 0);
        opacity: 1;
    }

    100% {
        transform: scale(0) translate(var(--tx), var(--ty));
        opacity: 0;
    }
}

/* Ripple effect */
.viz-ripple {
    position: absolute;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.4);
    transform: scale(0);
    animation: viz-ripple-anim 0.6s linear;
    pointer-events: none;
}

.viz-preset-dark .viz-ripple,
.viz-preset-neon .viz-ripple {
    background: rgba(255, 255, 255, 0.2);
}

@keyframes viz-ripple-anim {
    to {
        transform: scale(4);
        opacity: 0;
    }
}

/* Sequential Fade-in (Typing style) */
.viz-node-hidden {
    opacity: 0 !important;
    transform: translateY(-10px);
}

.viz-node-reveal {
    animation: viz-reveal-anim 0.4s ease-out forwards;
}

@keyframes viz-reveal-anim {
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ===== Node Custom Behaviors / Animations ===== */

/* Nodes dimming effect */
.viz-node-dimmed {
    opacity: 0.2 !important;
    filter: grayscale(80%) blur(1px);
    transition: all 0.3s ease;
}

.viz-edge-dimmed,
.viz-edge-dimmed path.path,
.viz-edge-dimmed path {
    opacity: 0.1 !important;
    transition: all 0.3s ease;
}

/* Active nodes */
.viz-node-active {
    transform-origin: center;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    filter: drop-shadow(0 0 10px var(--viz-accent));
}

/* Edge flow animation */
.viz-edge-animated,
.viz-edge-animated.path,
.viz-edge-animated path.path,
.viz-edge-animated path {
    stroke: var(--viz-accent) !important;
    stroke-width: 3.2px !important;
    stroke-linecap: round;
    stroke-dasharray: 18, 10 !important;
    filter: drop-shadow(0 0 6px var(--viz-accent));
    animation: viz-flow 0.9s linear infinite, viz-flow-glow 1.8s ease-in-out infinite;
}

@keyframes viz-flow {
    to {
        stroke-dashoffset: -56;
    }
}

@keyframes viz-flow-glow {

    0%,
    100% {
        opacity: 0.9;
        filter: drop-shadow(0 0 4px var(--viz-accent));
    }

    50% {
        opacity: 1;
        filter: drop-shadow(0 0 12px var(--viz-accent));
    }
}