:root {
    /* Torch 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-1542202229-7d93c33f5d07?q=80&w=2672&auto=format&fit=crop');
    /* Forest/Path 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;
}

/* Ops Grid (Domain/Range) */
.ops-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.full-width {
    grid-column: span 2;
}

/* Ops List */
.ops-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.op-btn {
    padding: 12px;
    background: #fff;
    border: 1px solid rgba(0, 0, 0, 0.1);
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: left;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.ops-list .op-btn {
    justify-content: flex-start;
}

.op-btn:hover {
    background: #fffdf5;
    border-color: var(--accent-gold);
    transform: translateY(-2px);
}

.op-btn.active {
    background: var(--accent-red);
    color: white;
    border-color: var(--accent-red);
}

.op-btn.active .btn-sub {
    color: rgba(255, 255, 255, 0.8);
}

.btn-content {
    display: flex;
    align-items: center;
    gap: 12px;
}

.btn-icon {
    font-size: 1.2rem;
}

.btn-text {
    display: flex;
    flex-direction: column;
}

.btn-sub {
    font-size: 0.75rem;
    color: var(--text-secondary);
    font-family: var(--font-mono);
}

/* Log Card */
.log-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;
}

.log-card h3 {
    font-size: 1.1rem;
    color: var(--accent-red);
    margin-bottom: 8px;
    font-family: var(--font-title);
}

.log-card p {
    font-size: 0.9rem;
    line-height: 1.6;
    color: var(--text-primary);
    margin-bottom: 12px;
}

.math-display {
    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;
    word-break: break-all;
}

/* Footer */
.actions-footer {
    margin-top: auto;
}

.secondary-btn {
    width: 100%;
    padding: 12px;
    background: #fff;
    border: 1px solid rgba(0, 0, 0, 0.1);
    border-radius: 12px;
    color: var(--text-primary);
    font-weight: 600;
    cursor: pointer;
}

.secondary-btn:hover {
    background: #f5f5f5;
}

/* 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 */
.graph-node {
    position: absolute;
    width: 50px;
    height: 50px;
    background: #fff;
    border: 2px solid #ccc;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    font-family: var(--font-title);
    font-size: 1.5rem;
    color: var(--text-secondary);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
    transition: all 0.5s ease;
    z-index: 20;
}

.graph-node.active-domain {
    border-color: var(--accent-red);
    color: var(--accent-red);
    box-shadow: 0 0 20px rgba(214, 59, 29, 0.4);
    transform: scale(1.1);
}

.graph-node.active-range {
    border-color: var(--accent-gold);
    color: var(--accent-gold);
    box-shadow: 0 0 20px rgba(197, 160, 89, 0.4);
    transform: scale(1.1);
}

.graph-node.active-field {
    border-color: var(--accent-blue);
    color: var(--accent-blue);
    box-shadow: 0 0 20px rgba(0, 122, 255, 0.4);
    transform: scale(1.1);
}

/* Edges */
.edge {
    stroke: #ccc;
    stroke-width: 2;
    fill: none;
    marker-end: url(#arrowhead);
    transition: all 0.5s ease;
}

.edge.active {
    stroke: var(--accent-red);
    stroke-width: 3;
    filter: drop-shadow(0 0 2px rgba(214, 59, 29, 0.5));
}

.edge.inverse {
    stroke: var(--accent-blue);
    marker-end: url(#arrowhead-blue);
}

.edge.composite {
    stroke: var(--accent-gold);
    stroke-dasharray: 5, 5;
    stroke-width: 3;
    marker-end: url(#arrowhead-gold);
    animation: dash 20s linear infinite;
}

@keyframes dash {
    to {
        stroke-dashoffset: -1000;
    }
}