@media (prefers-color-scheme: dark) {
    :root {
        --bg-color: #1a1a1a;
        --text-color: #e0e0e0;
        --canvas-bg: #2d2d30;
        --canvas-border: #666;
        --node-sender: #4caf50;
        --node-receiver: #ff9800;
        --node-normal: #2196f3;
        --node-broken: #f44336;
        --edge-color: #64b5f6;
        --path-highlight: #ffeb3b;
        --control-bg: #3a3a3a;
        --status-bg: #424242;
    }
}

@media (prefers-color-scheme: light) {
    :root {
        --bg-color: #ffffff;
        --text-color: #222222;
        --canvas-bg: #f8f9fa;
        --canvas-border: #333;
        --node-sender: #28a745;
        --node-receiver: #fd7e14;
        --node-normal: #17a2b8;
        --node-broken: #dc3545;
        --edge-color: #007bff;
        --path-highlight: #ffc107;
        --control-bg: #f8f9fa;
        --status-bg: #e9ecef;
    }
}

* {
    color-scheme: light dark;
    box-sizing: border-box;
}

body {
    font-family: Arial, sans-serif;
    margin: 20px;
    background: var(--bg-color);
    color: var(--text-color);
    transition: all 0.3s ease;
}

h1 {
    margin-top: 0;
}

canvas {
    border: 2px solid var(--canvas-border);
    display: block;
    margin: 10px 0;
    background: var(--canvas-bg);
    border-radius: 8px;
}

#controls {
    margin: 10px 0;
    background: var(--control-bg);
    padding: 15px;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

label {
    font-weight: bold;
    margin-right: 8px;
}

select,
button {
    padding: 8px 12px;
    margin: 5px;
    font-size: 16px;
    border: 1px solid var(--canvas-border);
    border-radius: 4px;
    background: var(--bg-color);
    color: var(--text-color);
    cursor: pointer;
    transition: all 0.2s;
}

select:focus,
button:focus {
    outline: 2px solid var(--edge-color);
    outline-offset: 2px;
}

button:hover {
    opacity: 0.9;
    transform: translateY(-1px);
}

button:active {
    transform: translateY(0);
}

#status {
    font-weight: bold;
    padding: 12px 16px;
    background: var(--status-bg);
    border-radius: 6px;
    margin: 10px 0;
    border-left: 4px solid var(--edge-color);
    transition: color 0.3s;
}

#status[style*="color: green"],
#status[style*="color: #28a745"] {
    border-left-color: #28a745;
}

#status[style*="color: red"],
#status[style*="color: #dc3545"] {
    border-left-color: #dc3545;
}

/* Game container layout */
.game-container {
    display: flex;
    gap: 20px;
    align-items: flex-start;
    margin-top: 10px;
}

/* Theory sidebar */
.theory-sidebar {
    flex: 0 0 450px;
    background: var(--control-bg);
    border-radius: 8px;
    padding: 20px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    align-self: flex-start;
    max-height: 600px;
    overflow-y: auto;
}

.theory-sidebar h2 {
    margin-top: 0;
    margin-bottom: 15px;
    color: var(--edge-color);
    border-bottom: 2px solid var(--edge-color);
    padding-bottom: 8px;
}

.theory-content h3 {
    margin-top: 20px;
    margin-bottom: 10px;
    color: var(--text-color);
}

.theory-content p {
    line-height: 1.6;
    margin-bottom: 15px;
}

.theory-content ul {
    margin: 10px 0 15px 20px;
}

.theory-content li {
    margin-bottom: 8px;
    line-height: 1.5;
}

/* Responsive design */
@media (max-width: 1200px) {
    .game-container {
        flex-direction: column;
    }
    
    .theory-sidebar {
        flex: 0 0 auto;
        max-height: none;
        width: 100%;
        order: 2;
    }
    
    canvas {
        order: 1;
    }
}

@media (max-width: 768px) {
    canvas {
        width: 100%;
        height: 400px;
        max-width: 900px;
    }

    #controls {
        display: flex;
        flex-wrap: wrap;
        gap: 10px;
    }

    select,
    button {
        flex: 1;
        min-width: 120px;
    }
    
    .theory-sidebar {
        padding: 15px;
    }
}
