/* --- ASTRAL THEME VARIABLES --- */
:root {
    --bg-deep: #0f172a;
    --bg-nebula: radial-gradient(circle at 50% 50%, #1e293b 0%, #020617 100%);
    --glow-primary: #38bdf8;
    --glow-accent: #f472b6;
    --glow-core: #fbbf24;
    --glass-panel: rgba(15, 23, 42, 0.85);
    --glass-border: rgba(56, 189, 248, 0.2);
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
}

body {
    background: var(--bg-nebula);
    color: var(--text-main);
    font-family: 'Inter', sans-serif;
    margin: 0;
}

#stage {
    display: flex;
    height: calc(100vh - 3.5rem);
    overflow: hidden;
    position: relative;
    flex-direction: row;
}

#viewport {
    flex: 1;
    position: relative;
    overflow: hidden;
    touch-action: none;
    cursor: grab;
}

#viewport:active {
    cursor: grabbing;
}

/* Responsive Scrollbars */
.no-scrollbar::-webkit-scrollbar {
    display: none;
}

.no-scrollbar {
    -ms-overflow-style: none;
    scrollbar-width: none;
}

.custom-scrollbar::-webkit-scrollbar {
    width: 6px;
}

.custom-scrollbar::-webkit-scrollbar-track {
    background: #0f172a;
}

.custom-scrollbar::-webkit-scrollbar-thumb {
    background: #334155;
    border-radius: 3px;
}

/* --- MAP LAYERS --- */
#world-layer,
#edge-svg {
    position: absolute;
    inset: 0;
    transform-origin: 0 0;
    will-change: transform;
}

#edge-svg {
    z-index: 0;
    overflow: visible;
    pointer-events: none;
}

#world-layer {
    z-index: 10;
    pointer-events: none;
}

.edge-vis {
    stroke: rgba(148, 163, 184, 0.6);
    stroke-width: 1.5px;
    transition: stroke 0.3s;
}

.node:hover~svg .edge-vis {
    stroke-opacity: 0.1;
}

/* --- NODES --- */
.node {
    position: absolute;
    width: 72px;
    height: 72px;
    background: rgba(30, 41, 59, 0.95);
    border: 1px solid var(--glass-border);
    border-radius: 50%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 10;
    cursor: pointer;
    touch-action: none;
    pointer-events: auto;
    transform: translate(-50%, -50%);
    transition: transform 0.15s ease-out, border-color 0.15s ease-out, box-shadow 0.15s ease-out, opacity 0.15s ease-out;
}

.node:hover {
    z-index: 15;
    border-color: var(--glow-primary);
    box-shadow: 0 0 15px rgba(56, 189, 248, 0.2);
}

.node.selected {
    border-color: var(--glow-core);
    background: rgba(251, 191, 36, 0.1);
    box-shadow: 0 0 30px rgba(251, 191, 36, 0.3);
    z-index: 20;
    transform: translate(-50%, -50%) scale(1.15);
}

.node.collapsed {
    border-style: dashed;
    border-color: var(--glow-accent);
}

.node-icon {
    font-size: 24px;
    margin-bottom: -2px;
    pointer-events: none;
}

.node-label {
    position: absolute;
    top: 110%;
    left: 50%;
    transform: translateX(-50%);
    font-size: 10px;
    font-weight: 700;
    color: var(--text-muted);
    background: rgba(15, 23, 42, 0.8);
    padding: 2px 6px;
    border-radius: 4px;
    white-space: nowrap;
    pointer-events: none;
}

#radial-menu {
    position: fixed;
    z-index: 45;
    width: 2px;
    height: 2px;
    overflow: visible;
    pointer-events: none;
    display: none;
}

/* --- MAGIC CIRCLE EFFECTS (Dr. Strange Style) --- */
.orbital-sun::before,
.orbital-sun::after {
    content: '';
    position: absolute;
    border-radius: 50%;
    pointer-events: none;
    opacity: 0;
    transform: scale(0.5);
    transition: opacity 0.4s ease-out, transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.orbital-sun.active::before {
    top: -130px;
    left: -130px;
    width: 260px;
    height: 260px;
    border: 2px solid rgba(244, 114, 182, 0.2);
    border-top-color: var(--glow-accent);
    border-bottom-color: var(--glow-accent);
    box-shadow: 0 0 25px rgba(244, 114, 182, 0.5), inset 0 0 15px rgba(244, 114, 182, 0.2);
    animation: spin-right 10s linear infinite;
    opacity: 0.7;
    transform: scale(1);
}

.orbital-sun.active::after {
    top: -100px;
    left: -100px;
    width: 200px;
    height: 200px;
    border: 2px dashed rgba(56, 189, 248, 0.4);
    border-left-color: var(--glow-primary);
    border-right-color: var(--glow-primary);
    box-shadow: 0 0 20px rgba(56, 189, 248, 0.6);
    animation: spin-left 15s linear infinite;
    opacity: 0.9;
    transform: scale(1);
}

@keyframes spin-right {
    0% { transform: rotate(0deg) scale(1); }
    50% { transform: rotate(180deg) scale(1.02); }
    100% { transform: rotate(360deg) scale(1); }
}

@keyframes spin-left {
    0% { transform: rotate(0deg) scale(1); }
    50% { transform: rotate(-180deg) scale(0.98); }
    100% { transform: rotate(-360deg) scale(1); }
}

/* Smart-action halo: breathing glow for nodes with a smart button action */
@keyframes smart-action-glow {
    0%   { box-shadow: 0 0 8px 2px var(--halo-color, rgba(99,102,241,0.35)), 0 0 0 0 var(--halo-color, rgba(99,102,241,0.15)); }
    50%  { box-shadow: 0 0 18px 6px var(--halo-color, rgba(99,102,241,0.6)), 0 0 0 4px var(--halo-color, rgba(99,102,241,0.08)); }
    100% { box-shadow: 0 0 8px 2px var(--halo-color, rgba(99,102,241,0.35)), 0 0 0 0 var(--halo-color, rgba(99,102,241,0.15)); }
}

.smart-action-halo {
    animation: smart-action-glow 2.4s ease-in-out infinite;
}

.radial-btn {
    position: absolute;
    width: 44px;
    height: 44px;
    margin-left: -22px;
    margin-top: -22px;
    background: rgba(15, 23, 42, 0.85);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1px solid rgba(56, 189, 248, 0.3);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--glow-primary);
    cursor: pointer;
    font-size: 16px;
    z-index: 50;
    opacity: 0;
    transform: translate(0, 0) scale(0.5);
    pointer-events: none !important;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

#radial-menu.active .radial-btn {
    opacity: 1;
    transform: translate(var(--tx), var(--ty)) scale(1);
}

#radial-menu.ready .radial-btn {
    pointer-events: auto !important;
}

.radial-btn:hover {
    background: var(--glow-primary) !important;
    color: #0f172a !important;
    border-color: white !important;
    z-index: 100;
    transform: translate(var(--tx), var(--ty)) scale(1.15) !important;
}

/* --- MOONS --- */
.moon-btn {
    position: absolute;
    width: 24px;
    height: 24px;
    background: rgba(30, 41, 59, 0.95);
    border: 1px solid rgba(148, 163, 184, 0.5);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    cursor: pointer;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
    transition: all 0.2s;
    z-index: 40;
    pointer-events: auto;
}

.moon-btn:hover {
    background: var(--glow-primary);
    transform: scale(1.3);
}

/* --- UNIVERSAL TOOL RAIL & SIDEBAR LOGIC --- */
#sidebar {
    width: 56px;
    /* Base is closed (Rail only) */
    transition: width 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    z-index: 48;
    overflow: hidden;
    /* Hides inspector panel smoothly when shrunk */
}

#sidebar.open {
    width: 312px;
    /* 56px rail + 256px panel */
}

#sidebar.data-manager-open {
    width: 506px;
    /* 56px rail + 450px panel */
}

.phase-btn.active {
    background: rgba(56, 189, 248, 0.15) !important;
    box-shadow: inset -4px 0 0 0 var(--glow-primary);
    border-radius: 0.5rem 0 0 0.5rem !important;
    /* Flat right edge connects to content */
}

@media (max-width: 768px) {
    #sidebar {
        position: absolute;
        top: 0;
        bottom: 0;
        left: 0;
        z-index: 48;
        box-shadow: 5px 0 20px rgba(0, 0, 0, 0.5);
    }

    #sidebar.open {
        width: 312px;
        max-width: 100vw;
    }

    #sidebar.data-manager-open {
        width: 100vw;
        max-width: 100vw;
    }

    /* Prevents the Rail from overlapping the Web Architect or spatial canvas */
    #viewport {
        margin-left: 56px;
    }
}

/* --- FLOWCHART NODES --- */
.node[data-type="flow-process"] {
    border-radius: 8px;
    width: 80px;
    height: 60px;
}
.node[data-type="flow-terminal"] {
    border-radius: 30px;
    width: 100px;
    height: 60px;
}
.node[data-type="flow-decision"] {
    border-radius: 8px;
    transform: translate(-50%, -50%) rotate(45deg);
}
.node[data-type="flow-decision"].selected {
    transform: translate(-50%, -50%) rotate(45deg) scale(1.15);
}
.node[data-type="flow-decision"] > .node-icon {
    transform: rotate(-45deg);
}
.node[data-type="flow-decision"] > .node-label {
    transform: translateX(-50%) rotate(-45deg);
    top: 130%;
    left: 130%;
}