:root {
    /* Structural Red Theme */
    --app-bg: #fdfbf7;
    --sidebar-bg: rgba(255, 248, 240, 0.95);
    --glass-border: rgba(139, 0, 0, 0.1);
    --text-primary: #2c2c2c;
    --text-secondary: #5a5a5a;
    --accent-red: #d63b1d;
    --accent-gold: #c5a059;
    --accent-blue: #007aff;

    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.08);

    --font-family: "Noto Serif SC", "Outfit", serif;
    --font-mono: "JetBrains Mono", monospace;
    --font-title: "Ma Shan Zheng", cursive;
}

* {
    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: url('https://images.unsplash.com/photo-1506784983877-45594efa4cbe?q=80&w=2668&auto=format&fit=crop');
    /* Structure/Network abstract */
    background-size: cover;
    background-position: center;
}

.app-container {
    width: 90vw;
    height: 85vh;
    max-width: 1400px;
    background: rgba(255, 252, 245, 0.95);
    backdrop-filter: blur(20px);
    border-radius: 24px;
    border: 1px solid var(--glass-border);
    box-shadow: var(--shadow-md);
    display: flex;
    overflow: hidden;
}

/* Sidebar */
.sidebar {
    width: 380px;
    background: var(--sidebar-bg);
    border-right: 1px solid var(--glass-border);
    display: flex;
    flex-direction: column;
    padding: 1.5rem;
    gap: 1.5rem;
    flex-shrink: 0;
    overflow-y: auto;
}

.sidebar-header {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.window-controls {
    display: flex;
    gap: 8px;
}

.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: 2rem;
    font-weight: 400;
    color: var(--accent-red);
}

.subtitle {
    font-size: 0.8rem;
    color: var(--text-secondary);
    font-style: italic;
    margin-top: -5px;
}

.highlight {
    color: var(--text-primary);
}

.controls-wrapper {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    flex-grow: 1;
}

.control-group {
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
}

label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* Relation Menu */
.relation-menu {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.relation-btn {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background: #fff;
    border: 1px solid rgba(0, 0, 0, 0.1);
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: left;
}

.relation-btn:hover {
    background: #fffdf5;
    border-color: var(--accent-gold);
    transform: translateX(4px);
}

.relation-btn.active {
    background: var(--accent-red);
    color: white;
    border-color: var(--accent-red);
}

.relation-btn.active .btn-sub {
    color: rgba(255, 255, 255, 0.8);
}

.btn-icon {
    font-size: 1.4rem;
}

.btn-text {
    display: flex;
    flex-direction: column;
}

.btn-sub {
    font-size: 0.75rem;
    color: var(--text-secondary);
    font-family: var(--font-mono);
}

/* Insight Card */
.insight-card {
    background: #fffdf5;
    padding: 16px;
    border-radius: 12px;
    border: 1px solid rgba(197, 160, 89, 0.2);
    border-left: 4px solid var(--accent-gold);
    min-height: 120px;
}

.insight-card h3 {
    font-size: 1.1rem;
    color: var(--accent-red);
    margin-bottom: 8px;
    font-family: var(--font-title);
}

.insight-card p {
    font-size: 0.9rem;
    line-height: 1.6;
    color: var(--text-primary);
    margin-bottom: 12px;
}

.math-def {
    font-family: var(--font-mono);
    font-size: 0.8rem;
    color: var(--text-secondary);
    background: rgba(0, 0, 0, 0.05);
    padding: 8px;
    border-radius: 6px;
}

/* Footer */
.actions-footer {
    margin-top: auto;
}

.set-info {
    text-align: center;
    font-family: var(--font-mono);
    font-size: 0.9rem;
    color: var(--text-secondary);
    background: #fff;
    padding: 10px;
    border-radius: 8px;
    border: 1px solid rgba(0, 0, 0, 0.05);
}

/* Main Stage */
.visualizer-stage {
    flex-grow: 1;
    padding: 2rem;
    display: flex;
    justify-content: center;
    align-items: center;
}

.glass-pane {
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.8);
    border-radius: 16px;
    box-shadow: inset 0 0 30px rgba(255, 255, 255, 0.5);
    border: 1px solid rgba(255, 255, 255, 0.4);
    padding: 2rem;
    display: flex;
    flex-direction: column;
}

.stage-header {
    text-align: center;
    margin-bottom: 1rem;
}

.stage-header h2 {
    font-size: 2rem;
    color: var(--accent-red);
    font-family: var(--font-title);
}

.stage-header p {
    font-size: 1rem;
    color: var(--text-secondary);
    font-family: var(--font-mono);
    letter-spacing: 1px;
}

/* Graph Container */
.graph-container {
    flex-grow: 1;
    position: relative;
    border-radius: 16px;
    background: #f8f9fa;
    box-shadow: inset 0 0 20px rgba(0, 0, 0, 0.05);
    overflow: hidden;
}

.graph-svg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 5;
    pointer-events: none;
}

.nodes-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 10;
    pointer-events: none;
    /* Nodes themselves will have pointer-events */
}

/* Nodes */
.graph-node {
    position: absolute;
    width: 50px;
    height: 50px;
    background: #fff;
    border: 2px solid var(--accent-red);
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    font-family: var(--font-title);
    font-size: 1.5rem;
    color: var(--accent-red);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
    transition: all 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
    /* Bouncy transition */
    cursor: pointer;
    pointer-events: auto;
    z-index: 20;
}

.graph-node:hover {
    transform: scale(1.1);
    background: var(--accent-red);
    color: #fff;
}

/* Edges */
.edge {
    stroke: var(--accent-red);
    stroke-width: 2;
    fill: none;
    opacity: 0.6;
    marker-end: url(#arrowhead);
    transition: all 0.5s ease;
}

.edge.loop {
    stroke: var(--accent-gold);
    marker-end: url(#arrowhead-loop);
}

.edge:hover {
    stroke-width: 3;
    opacity: 1;
}