:root {
    --primary-hue: 250;
    --primary: hsl(var(--primary-hue), 80%, 60%);
    --primary-dark: hsl(var(--primary-hue), 80%, 50%);
    --accent: hsl(320, 80%, 60%);
    --bg-dark: #0f0f13;
    --text-main: #ffffff;
    --text-muted: #a0a0b0;
    --glass-bg: rgba(255, 255, 255, 0.05);
    --glass-border: rgba(255, 255, 255, 0.1);
    --glass-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Outfit', sans-serif;
    background-color: var(--bg-dark);
    color: var(--text-main);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    /* Prevent scroll from blobs */
}

/* Background Blobs */
.background-blobs {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -1;
    overflow: hidden;
}

.blob {
    position: absolute;
    border-radius: 50%;
    filter: blur(80px);
    opacity: 0.6;
    animation: float 20s infinite alternate;
}

.blob-1 {
    top: -10%;
    left: -10%;
    width: 50vw;
    height: 50vw;
    background: var(--primary);
    animation-delay: 0s;
}

.blob-2 {
    bottom: -10%;
    right: -10%;
    width: 40vw;
    height: 40vw;
    background: var(--accent);
    animation-delay: -5s;
}

.blob-3 {
    top: 40%;
    left: 40%;
    width: 30vw;
    height: 30vw;
    background: hsl(180, 70%, 50%);
    animation-delay: -10s;
}

@keyframes float {
    0% {
        transform: translate(0, 0) scale(1);
    }

    100% {
        transform: translate(30px, 50px) scale(1.1);
    }
}

/* Glass Container */
.glass-container {
    width: 90%;
    max-width: 1200px;
    height: 90vh;
    background: var(--glass-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--glass-border);
    border-radius: 24px;
    box-shadow: var(--glass-shadow);
    display: grid;
    grid-template-rows: auto 1fr;
    grid-template-columns: 300px 1fr;
    overflow: hidden;
}

/* Header */
.app-header {
    grid-column: 1 / -1;
    padding: 1.5rem 2rem;
    border-bottom: 1px solid var(--glass-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    color: var(--primary);
}

.logo h1 {
    font-size: 1.5rem;
    font-weight: 700;
    background: linear-gradient(to right, #fff, #ccc);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.subtitle {
    color: var(--text-muted);
    font-size: 0.9rem;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.github-link {
    color: var(--text-muted);
    transition: color 0.2s;
    display: flex;
    align-items: center;
    opacity: 0.8;
}

.github-link:hover {
    color: var(--text-main);
    opacity: 1;
}

/* Controls Section */
.controls-section {
    padding: 2rem;
    border-right: 1px solid var(--glass-border);
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    overflow-y: auto;
    /* Enable vertical scrolling */
    max-height: 100%;
    /* Ensure it respects container height */
}

.upload-box {
    border: 2px dashed var(--glass-border);
    border-radius: 16px;
    padding: 2rem;
    text-align: center;
    transition: all 0.3s ease;
    cursor: pointer;
    background: rgba(255, 255, 255, 0.02);
}

.upload-box:hover,
.upload-box.drag-over {
    border-color: var(--primary);
    background: rgba(255, 255, 255, 0.05);
}

.upload-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
}

.upload-icon {
    color: var(--text-muted);
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary), var(--accent));
    border: none;
    padding: 0.75rem 1.5rem;
    border-radius: 8px;
    color: white;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.2s;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.status-panel {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 12px;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.status-indicator {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 1rem;
    font-weight: 500;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: #4ade80;
    box-shadow: 0 0 8px #4ade80;
}

.stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
}

#reload-analysis:hover {
    background: rgba(255, 255, 255, 0.1) !important;
    border-color: rgba(255, 255, 255, 0.3) !important;
}

.stat-item {
    display: flex;
    flex-direction: column;
}

.stat-label {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.stat-value {
    font-size: 1.2rem;
    font-weight: 600;
}

/* Visualization Section */
.visualization-section {
    position: relative;
    background: rgba(0, 0, 0, 0.1);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.split-view {
    display: flex;
    gap: 0;
    height: 100%;
    position: relative;
}

.view-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    position: relative;
    transition: flex 0.8s cubic-bezier(0.4, 0, 0.2, 1);
    /* Smooth expansion */
}

.panel-divider {
    width: 4px;
    background: var(--glass-border);
    cursor: col-resize;
    position: relative;
    flex-shrink: 0;
    transition: background 0.2s;
}

.panel-divider:hover {
    background: var(--primary);
}

.panel-divider::before {
    content: '';
    position: absolute;
    left: -4px;
    right: -4px;
    top: 0;
    bottom: 0;
}

.view-panel.expanded {
    flex: 2.5;
    /* Expand to take more space */
}

.view-panel:last-child {
    border-right: none;
}

/* ... existing h3 styles ... */

/* Canonical Graph Styles */
.node.canonical circle {
    fill: #ff4757;
    stroke: #fff;
    stroke-width: 2px;
}

.edge.canonical {
    stroke: #ff4757;
    stroke-width: 2px;
    opacity: 0.8;
}

/* Conflict Styles */
.node.conflict-principal circle {
    fill: #ef4444;
    stroke: #fff;
    stroke-width: 2px;
    r: 8px;
    transition: all 0.3s ease;
}

.node.conflict-subdivision circle {
    fill: #1e293b;
    stroke: #ef4444;
    stroke-width: 2px;
    r: 5px;
    transition: all 0.3s ease;
}

.connector-line {
    stroke: #22d3ee;
    stroke-width: 1px;
    stroke-dasharray: 4, 4;
    opacity: 0.4;
    pointer-events: none;
}

.view-panel h3 {
    padding: 1rem;
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-muted);
    background: rgba(0, 0, 0, 0.2);
    border-bottom: 1px solid var(--glass-border);
    text-align: center;
}

/* Modal Styles */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    z-index: 1000;
    justify-content: center;
    align-items: center;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.modal.show {
    display: flex;
    opacity: 1;
}

.modal-content {
    background: rgba(20, 20, 25, 0.95);
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    padding: 2rem;
    width: 90%;
    max-width: 400px;
    text-align: center;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
    transform: translateY(20px);
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.modal.show .modal-content {
    transform: translateY(0);
}

.modal-header {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1rem;
}

.error-icon {
    color: #ef4444;
    width: 48px;
    height: 48px;
}

.modal-header h3 {
    color: #ef4444;
    font-size: 1.5rem;
}

#error-message {
    color: var(--text-muted);
    margin-bottom: 2rem;
    line-height: 1.5;
}

/* Animation Controls */
.hidden {
    display: none !important;
}

.btn-play-animation {
    position: absolute;
    top: 4rem;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1.5rem;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    border: none;
    border-radius: 8px;
    color: white;
    font-weight: 500;
    cursor: pointer;
    transition: transform 0.2s;
    z-index: 5;
}

.btn-play-animation:hover {
    transform: translateX(-50%) scale(1.05);
    filter: brightness(1.1);
}

.btn-reset-graph {
    position: absolute;
    bottom: 1rem;
    left: 1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1.5rem;
    background: linear-gradient(135deg, #64748b, #475569);
    border: none;
    border-radius: 8px;
    color: white;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    z-index: 5;
}

.btn-reset-graph:hover {
    transform: scale(1.05);
    filter: brightness(1.1);
}

.btn-cancel-animation {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    background: rgba(239, 68, 68, 0.2);
    border: 1px solid rgba(239, 68, 68, 0.5);
    border-radius: 8px;
    color: #ef4444;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-cancel-animation:hover {
    background: rgba(239, 68, 68, 0.3);
    transform: scale(1.05);
}

.animation-controls {
    position: absolute;
    top: 4rem;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 1rem;
    background: var(--glass-bg);
    padding: 1rem;
    border-radius: 12px;
    border: 1px solid var(--glass-border);
    z-index: 5;
    min-width: 400px;
}

.progress-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.progress-bar {
    width: 100%;
    height: 6px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary), var(--accent));
    width: 0%;
    transition: width 0.3s ease;
}

.step-counter {
    font-size: 0.85rem;
    color: var(--text-muted);
    text-align: center;
}

.graph-container {
    flex: 1;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    position: relative;
}

.empty-state {
    color: var(--text-muted);
    font-size: 1.1rem;
}

.viz-controls {
    position: absolute;
    bottom: 1rem;
    right: 1rem;
    left: auto;
    /* Reset previous centering */
    transform: none;
    /* Reset previous centering */
    display: flex;
    gap: 0.5rem;
    background: var(--glass-bg);
    padding: 0.5rem;
    border-radius: 8px;
    border: 1px solid var(--glass-border);
    z-index: 10;
}

.btn-icon {
    width: 36px;
    height: 36px;
    border-radius: 6px;
    border: 1px solid var(--glass-border);
    background: rgba(255, 255, 255, 0.1);
    color: white;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.2rem;
    transition: background 0.2s;
}

.btn-icon:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* D3 Elements */
.node circle {
    fill: var(--primary);
    stroke: #fff;
    stroke-width: 2px;
    transition: all 0.3s;
}

.node:hover circle {
    fill: var(--accent);
    r: 8px;
}

.node text {
    font-family: 'Outfit', sans-serif;
    font-size: 10px;
    fill: var(--text-main);
    pointer-events: none;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8);
}

.edge {
    stroke: rgba(255, 255, 255, 0.4);
    stroke-width: 2px;
    transition: stroke 0.3s;
}

.edge.conflict {
    stroke: #ff4757;
    stroke-width: 3px;
    stroke-dasharray: 5, 5;
}

.node.conflict circle {
    fill: #ff4757;
}

/* Responsive */
@media (max-width: 768px) {
    .glass-container {
        grid-template-columns: 1fr;
        grid-template-rows: auto auto 1fr;
        height: 100vh;
        width: 100%;
        border-radius: 0;
    }

    .controls-section {
        border-right: none;
        border-bottom: 1px solid var(--glass-border);
        padding: 1rem;
        flex-direction: row;
        align-items: center;
    }

    .upload-box {
        padding: 1rem;
        flex: 1;
    }
}

/* Editor Styles */
.editor-view {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    background: var(--glass-bg);
}

.editor-view.hidden {
    display: none;
}

.editor-header {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--glass-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(0, 0, 0, 0.2);
}

.editor-header h3 {
    margin: 0;
    font-size: 1.2rem;
    color: var(--text-main);
}

.editor-toolbar {
    display: flex;
    gap: 0.5rem;
    background: rgba(255, 255, 255, 0.05);
    padding: 0.5rem;
    border-radius: 8px;
    border: 1px solid var(--glass-border);
}

.tool-btn {
    width: 36px;
    height: 36px;
    border-radius: 6px;
    border: 1px solid transparent;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: all 0.2s;
}

.tool-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-main);
}

.tool-btn.active {
    background: var(--primary);
    color: white;
    box-shadow: 0 0 10px rgba(var(--primary-hue), 80%, 60%, 0.3);
}

.tool-btn.danger:hover {
    background: rgba(239, 68, 68, 0.2);
    color: #ef4444;
}

.editor-toolbar .divider {
    width: 1px;
    background: var(--glass-border);
    margin: 0 0.25rem;
}

.editor-actions {
    display: flex;
    gap: 0.75rem;
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.2);
    padding: 0.75rem 1.5rem;
    border-radius: 8px;
    color: white;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    font-family: inherit;
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.15);
    border-color: rgba(255, 255, 255, 0.4);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.btn-primary.small,
.btn-secondary.small {
    padding: 0.5rem 1rem;
    font-size: 0.9rem;
}

.editor-canvas-container {
    flex: 1;
    background: rgba(0, 0, 0, 0.3);
    position: relative;
    overflow: hidden;
    cursor: crosshair;
}

.editor-instructions {
    position: absolute;
    bottom: 1rem;
    left: 1rem;
    background: rgba(0, 0, 0, 0.5);
    padding: 1rem;
    border-radius: 8px;
    pointer-events: none;
    border: 1px solid var(--glass-border);
}

.editor-instructions p {
    margin: 0.25rem 0;
    font-size: 0.85rem;
    color: var(--text-muted);
}

/* Editor Graph Elements */
.editor-node circle {
    fill: var(--primary);
    stroke: #fff;
    stroke-width: 2px;
    cursor: pointer;
}

.editor-node.selected circle {
    fill: var(--accent);
    stroke: #fff;
    stroke-width: 3px;
    filter: drop-shadow(0 0 4px var(--accent));
}

.editor-edge {
    stroke: rgba(255, 255, 255, 0.6);
    stroke-width: 2px;
    cursor: pointer;
}

.editor-edge:hover {
    stroke: var(--accent);
    stroke-width: 4px;
}

.editor-edge.selected {
    stroke: var(--accent);
    stroke-width: 3px;
}

.temp-edge {
    stroke: var(--text-muted);
    stroke-width: 2px;
    stroke-dasharray: 5, 5;
    pointer-events: none;
}