:root {
    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
    --bg-tertiary: #334155;
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --accent: #06b6d4;
    --accent-hover: #0891b2;
    --accent2: #d946ef;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --border: #475569;
}

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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
}

.sandpile-container {
    max-width: 1600px;
    margin: 0 auto;
    padding: 16px;
}

header {
    text-align: center;
    padding: 16px 0;
    border-bottom: 2px solid var(--border);
    margin-bottom: 16px;
}

header h1 {
    font-size: 2rem;
    background: linear-gradient(135deg, var(--accent), var(--accent2));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 6px;
}

.subtitle {
    color: var(--text-secondary);
    font-size: 1rem;
}

.main-layout {
    display: grid;
    grid-template-columns: 280px 1fr;
    gap: 16px;
}

/* Controls Panel */
.controls-panel {
    background: var(--bg-secondary);
    border-radius: 10px;
    padding: 16px;
    height: fit-content;
    position: sticky;
    top: 16px;
    overflow-y: auto;
    max-height: calc(100vh - 32px);
}

.control-section {
    margin-bottom: 18px;
    padding-bottom: 14px;
    border-bottom: 1px solid var(--border);
}

.control-section:last-child { border-bottom: none; margin-bottom: 0; }

.control-section h3 {
    font-size: 0.95rem;
    margin-bottom: 10px;
    color: var(--accent);
}

.control-group {
    margin-bottom: 12px;
}

.control-group label {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.val {
    background: var(--bg-tertiary);
    padding: 1px 6px;
    border-radius: 3px;
    font-family: 'Courier New', monospace;
    font-size: 0.8rem;
    color: var(--accent);
}

select {
    width: 100%;
    padding: 6px 10px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 5px;
    color: var(--text-primary);
    font-size: 0.85rem;
    cursor: pointer;
}

select:focus { outline: none; border-color: var(--accent); }

input[type="range"] {
    width: 100%;
    height: 5px;
    background: var(--bg-tertiary);
    border-radius: 3px;
    -webkit-appearance: none;
    outline: none;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    background: var(--accent);
    border-radius: 50%;
    cursor: pointer;
}

/* Mode Buttons */
.mode-buttons {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.mode-btn {
    padding: 8px 12px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 0.85rem;
    transition: all 0.2s;
}

.mode-btn:hover { border-color: var(--accent); color: var(--text-primary); }

.mode-btn.active {
    background: var(--accent);
    border-color: var(--accent);
    color: white;
    font-weight: 600;
}

/* Action Buttons */
.action-buttons {
    display: flex;
    gap: 8px;
}

.action-btn {
    flex: 1;
    padding: 10px 14px;
    border: none;
    border-radius: 7px;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.85rem;
    transition: all 0.2s;
}

.action-btn.primary {
    background: linear-gradient(135deg, var(--success), #059669);
    color: white;
}

.action-btn.primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 3px 10px rgba(16, 185, 129, 0.3);
}

.action-btn:not(.primary) {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border: 1px solid var(--border);
}

.action-btn:not(.primary):hover { background: var(--border); }

/* Stats */
.stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
}

.stat-item {
    background: var(--bg-tertiary);
    padding: 6px 10px;
    border-radius: 5px;
    text-align: center;
}

.stat-label {
    display: block;
    font-size: 0.7rem;
    color: var(--text-secondary);
    margin-bottom: 2px;
}

.stat-value {
    display: block;
    font-size: 0.85rem;
    font-weight: 700;
    font-family: 'Courier New', monospace;
    color: var(--accent);
}

/* Display Panel */
.display-panel {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.canvas-card {
    background: var(--bg-secondary);
    border-radius: 10px;
    padding: 10px 12px;
}

.canvas-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
}

.plot-label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.canvas-legend {
    display: flex;
    gap: 10px;
    font-size: 0.7rem;
    color: var(--text-secondary);
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 4px;
}

.legend-color {
    width: 12px;
    height: 12px;
    border-radius: 2px;
}

#sandpile-canvas {
    width: 100%;
    height: 500px;
    border-radius: 6px;
    background: var(--bg-primary);
    display: block;
    cursor: crosshair;
}

.bottom-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.plot-card {
    background: var(--bg-secondary);
    border-radius: 10px;
    padding: 10px 12px;
}

.plot-card canvas {
    width: 100%;
    height: 160px;
    border-radius: 6px;
    background: var(--bg-primary);
    display: block;
}

/* Education */
.education {
    margin-top: 20px;
}

.tabs {
    display: flex;
    gap: 6px;
    margin-bottom: 14px;
    border-bottom: 2px solid var(--border);
    padding-bottom: 10px;
}

.tab-btn {
    padding: 8px 16px;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 0.85rem;
    transition: all 0.2s;
}

.tab-btn:hover { background: var(--bg-tertiary); color: var(--text-primary); }

.tab-btn.active {
    background: var(--accent);
    border-color: var(--accent);
    color: white;
}

.tab-pane { display: none; }
.tab-pane.active {
    display: block;
    animation: fadeIn 0.3s;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

.edu-card {
    background: var(--bg-secondary);
    border-radius: 8px;
    padding: 16px;
    margin-bottom: 12px;
    border-left: 3px solid var(--accent);
}

.edu-card h3 {
    font-size: 1rem;
    margin-bottom: 8px;
    color: var(--accent);
}

.edu-card p {
    color: var(--text-secondary);
    line-height: 1.7;
    font-size: 0.9rem;
}

.edu-card ul {
    margin-left: 18px;
    color: var(--text-secondary);
}

.edu-card li {
    margin-bottom: 5px;
    line-height: 1.6;
    font-size: 0.9rem;
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--bg-tertiary); border-radius: 3px; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--accent); }

/* Responsive */
@media (max-width: 1024px) {
    .main-layout { grid-template-columns: 1fr; }
    .controls-panel {
        position: relative;
        top: 0;
        max-height: none;
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
        gap: 12px;
    }
    .control-section { border-bottom: none; margin-bottom: 0; padding-bottom: 0; }
    .bottom-row { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
    header h1 { font-size: 1.4rem; }
    .subtitle { font-size: 0.85rem; }
    .sandpile-container { padding: 10px; }
    #sandpile-canvas { height: 320px; }
    .mode-buttons { flex-direction: row; flex-wrap: wrap; }
    .tabs { flex-wrap: wrap; }
    .controls-panel { grid-template-columns: 1fr; }
}
