:root {
    /* Industrial Precision Theme */
    --app-bg: #0f172a;
    --panel-bg: #1e293b;
    --glass-border: rgba(148, 163, 184, 0.2);
    --text-primary: #e2e8f0;
    --text-secondary: #94a3b8;

    --accent-blue: #38bdf8;
    --accent-cyan: #06b6d4;
    --accent-silver: #cbd5e1;
    --accent-active: #00f0ff;

    --matrix-cell-bg: #334155;
    --matrix-cell-hover: #475569;
    --matrix-cell-active: rgba(6, 182, 212, 0.3);

    --node-fill: #1e293b;
    --node-stroke: #94a3b8;
    --edge-default: #475569;

    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.2);
    --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 20px 40px rgba(0, 0, 0, 0.4);

    --font-family: "Outfit", "Noto Serif SC", sans-serif;
    --font-title: "Ma Shan Zheng", cursive;
    --font-tech: "Orbitron", sans-serif;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: var(--font-family);
    background-color: var(--app-bg);
    color: var(--text-primary);
    height: 100vh;
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
    background-image:
        linear-gradient(rgba(15, 23, 42, 0.9), rgba(15, 23, 42, 0.9)),
        url('https://images.unsplash.com/photo-1581091226825-a6a2a5aee158?q=80&w=2670&auto=format&fit=crop');
    background-size: cover;
    background-position: center;
}

.app-container {
    width: 95vw;
    height: 90vh;
    max-width: 1600px;
    background: rgba(30, 41, 59, 0.8);
    backdrop-filter: blur(20px) saturate(120%);
    -webkit-backdrop-filter: blur(20px) saturate(120%);
    border-radius: 16px;
    border: 1px solid var(--glass-border);
    box-shadow: var(--shadow-lg);
    display: flex;
    overflow: hidden;
}

/* Left Panel: Topology */
.topology-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--glass-border);
    position: relative;
}

.panel-header {
    padding: 1.5rem;
    background: rgba(30, 41, 59, 0.95);
    border-bottom: 1px solid var(--glass-border);
    z-index: 10;
}

.window-controls {
    display: flex;
    gap: 8px;
    margin-bottom: 0.5rem;
}

.dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
}

.dot.red {
    background: #ff5f56;
}

.dot.yellow {
    background: #ffbd2e;
}

.dot.green {
    background: #27c93f;
}

h1 {
    font-family: var(--font-title);
    font-size: 1.8rem;
    font-weight: 400;
    color: var(--text-primary);
    letter-spacing: 0.05em;
}

.subtitle {
    font-family: var(--font-tech);
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-top: -5px;
    text-transform: uppercase;
    letter-spacing: 0.1em;
}

.highlight {
    color: var(--accent-cyan);
    text-shadow: 0 0 10px rgba(6, 182, 212, 0.5);
}

.visualizer-stage {
    flex-grow: 1;
    position: relative;
    background: #0f172a;
    overflow: hidden;
}

.grid-bg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image:
        linear-gradient(rgba(148, 163, 184, 0.05) 1px, transparent 1px),
        linear-gradient(90deg, rgba(148, 163, 184, 0.05) 1px, transparent 1px);
    background-size: 40px 40px;
    pointer-events: none;
}

.graph-title {
    position: absolute;
    top: 1rem;
    left: 1rem;
    background: rgba(30, 41, 59, 0.9);
    padding: 0.8rem 1.2rem;
    border-radius: 8px;
    border: 1px solid var(--glass-border);
    pointer-events: none;
}

.graph-title h2 {
    font-size: 1rem;
    color: var(--accent-blue);
    margin: 0;
}

.graph-title p {
    font-family: var(--font-tech);
    font-size: 0.7rem;
    color: var(--text-secondary);
    margin: 2px 0 0 0;
}

.legend {
    position: absolute;
    top: 1rem;
    right: 1rem;
    background: rgba(30, 41, 59, 0.9);
    padding: 0.8rem;
    border-radius: 8px;
    border: 1px solid var(--glass-border);
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    pointer-events: none;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.legend-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--node-fill);
    border: 1px solid var(--node-stroke);
}

.legend-line {
    width: 20px;
    height: 2px;
    background: var(--edge-default);
}

.legend-line.optimized {
    background: var(--accent-active);
    box-shadow: 0 0 5px var(--accent-active);
}

.controls-area {
    padding: 1rem;
    background: rgba(30, 41, 59, 0.95);
    border-top: 1px solid var(--glass-border);
    display: flex;
    gap: 1rem;
    justify-content: center;
}

.apple-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 10px 20px;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    border: 1px solid transparent;
    font-family: var(--font-family);
    gap: 8px;
    min-width: 140px;
}

.primary-btn {
    background: rgba(6, 182, 212, 0.1);
    color: var(--accent-cyan);
    border-color: var(--accent-cyan);
    box-shadow: 0 0 10px rgba(6, 182, 212, 0.2);
}

.primary-btn:hover {
    background: rgba(6, 182, 212, 0.2);
    box-shadow: 0 0 15px rgba(6, 182, 212, 0.4);
    transform: translateY(-1px);
}

.secondary-btn {
    background: rgba(148, 163, 184, 0.1);
    color: var(--text-secondary);
    border-color: var(--text-secondary);
}

.secondary-btn:hover {
    background: rgba(148, 163, 184, 0.2);
    color: var(--text-primary);
}

/* Right Panel: Matrix */
.matrix-panel {
    width: 500px;
    background: var(--panel-bg);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}

.matrix-tabs {
    display: flex;
    border-bottom: 1px solid var(--glass-border);
}

.tab-btn {
    flex: 1;
    padding: 1rem;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-family: var(--font-family);
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s;
    border-bottom: 2px solid transparent;
}

.tab-btn:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.02);
}

.tab-btn.active {
    color: var(--accent-cyan);
    border-bottom-color: var(--accent-cyan);
    background: rgba(6, 182, 212, 0.05);
}

.matrix-content {
    flex-grow: 1;
    padding: 1.5rem;
    overflow: auto;
    display: flex;
    justify-content: center;
    align-items: flex-start;
}

.matrix-container {
    display: grid;
    gap: 2px;
    /* Grid template columns set by JS */
}

.matrix-header-cell {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    color: var(--text-secondary);
    font-weight: 600;
    background: transparent;
}

.matrix-cell {
    width: 36px;
    height: 36px;
    background: var(--matrix-cell-bg);
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--font-tech);
    font-size: 0.8rem;
    color: var(--text-secondary);
    border-radius: 4px;
    cursor: default;
    transition: all 0.1s;
}

.matrix-cell:hover {
    background: var(--matrix-cell-hover);
    transform: scale(1.1);
    z-index: 5;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
    color: white;
}

.matrix-cell.active {
    background: var(--matrix-cell-active);
    color: var(--accent-active);
    border: 1px solid var(--accent-active);
    box-shadow: 0 0 10px rgba(6, 182, 212, 0.3);
}

.matrix-cell.highlight-row,
.matrix-cell.highlight-col {
    background: rgba(148, 163, 184, 0.3);
}

.analysis-info {
    padding: 1.5rem;
    border-top: 1px solid var(--glass-border);
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.info-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.info-group label {
    font-size: 0.75rem;
    color: var(--accent-blue);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 600;
}

.stats-row {
    display: flex;
    gap: 1rem;
    background: rgba(15, 23, 42, 0.5);
    padding: 0.8rem;
    border-radius: 8px;
}

.stat-item {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.stat-item .label {
    font-size: 0.7rem;
    color: var(--text-secondary);
}

.stat-item .value {
    font-family: var(--font-tech);
    font-size: 1rem;
    color: var(--text-primary);
}

.info-box {
    background: linear-gradient(135deg, rgba(6, 182, 212, 0.1), rgba(30, 41, 59, 0.5));
    padding: 1rem;
    border-radius: 8px;
    border: 1px solid rgba(6, 182, 212, 0.2);
}

.info-box h3 {
    font-size: 0.9rem;
    color: var(--accent-cyan);
    margin-bottom: 0.5rem;
    font-family: var(--font-family);
}

.info-box p {
    font-size: 0.75rem;
    line-height: 1.4;
    color: var(--text-secondary);
    margin-bottom: 0.4rem;
}

/* Graph Elements */
.edge-line {
    stroke: var(--edge-default);
    stroke-width: 1.5px;
    transition: all 0.2s;
    marker-end: url(#arrow);
}

.edge-line.active {
    stroke: var(--accent-active);
    stroke-width: 2.5px;
    filter: drop-shadow(0 0 5px var(--accent-active));
    marker-end: url(#arrow-active);
    opacity: 1;
}

.edge-line.dimmed {
    opacity: 0.2;
}

.node-group {
    cursor: pointer;
    transition: transform 0.2s ease;
}

.node-group:hover {
    transform: scale(1.1);
}

.node-circle {
    fill: var(--node-fill);
    stroke: var(--node-stroke);
    stroke-width: 2px;
    transition: all 0.2s;
}

.node-circle.active {
    stroke: var(--accent-active);
    fill: rgba(6, 182, 212, 0.2);
    box-shadow: 0 0 15px var(--accent-active);
    filter: drop-shadow(0 0 5px var(--accent-active));
}

.node-circle.dimmed {
    opacity: 0.3;
}

.node-text {
    font-family: var(--font-tech);
    font-size: 10px;
    fill: var(--text-secondary);
    pointer-events: none;
    user-select: none;
    font-weight: 600;
}

.node-group.active .node-text {
    fill: var(--accent-active);
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.1);
}

::-webkit-scrollbar-thumb {
    background: var(--accent-blue);
    border-radius: 3px;
    opacity: 0.5;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--accent-cyan);
}

/* Interactive Enhancements */
.matrix-cell.editable {
    cursor: pointer;
}

.matrix-cell.editable:hover {
    border: 1px solid var(--accent-cyan);
    background: rgba(6, 182, 212, 0.2);
}

.node-group {
    cursor: grab;
}

.node-group:active,
.node-group.dragging {
    cursor: grabbing;
}

.node-group.dragging .node-circle {
    stroke: var(--accent-active);
    stroke-width: 3px;
    filter: drop-shadow(0 0 8px var(--accent-active));
}