@import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;700&family=Inter:wght@400;600;800&display=swap');

:root {
    --bg-dark: #0a0a0f;
    --bg-panel: rgba(20, 20, 30, 0.9);
    --glass-border: rgba(255, 255, 255, 0.1);
    --accent: #00d4ff;
    --accent-glow: rgba(0, 212, 255, 0.3);
    --success: #00ff88;
    --error: #ff4466;
    --text: #e0e0e0;
    --text-dim: #888;
    --code-font: 'JetBrains Mono', monospace;
    --ui-font: 'Inter', sans-serif;
}

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

body {
    background: var(--bg-dark);
    color: var(--text);
    font-family: var(--ui-font);
    height: 100vh;
    overflow: hidden;
}

/* === SCREENS === */
.screen {
    position: absolute;
    inset: 0;
    display: none;
    flex-direction: column;
}
.screen.active { display: flex; }

/* === MENU SCREEN === */
#menu-screen {
    background: linear-gradient(135deg, #0a0a1a 0%, #1a1a2e 50%, #0a0a1a 100%);
    justify-content: center;
    align-items: center;
    z-index: 200;
}

.menu-content { text-align: center; }

.logo {
    margin-bottom: 48px;
    animation: fadeInUp 0.8s ease;
}
.logo-icon {
    font-size: 64px;
    color: var(--accent);
    display: block;
    margin-bottom: 16px;
    animation: pulse 2s ease infinite;
}
.logo h1 {
    font-size: 56px;
    font-weight: 800;
    background: linear-gradient(90deg, var(--accent), #00ff88, var(--accent));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-size: 200% 100%;
    animation: shimmer 3s ease infinite;
}
.tagline {
    margin-top: 8px;
    color: var(--text-dim);
    font-size: 16px;
}

.menu-buttons {
    display: flex;
    gap: 24px;
    justify-content: center;
    animation: fadeInUp 0.8s ease 0.2s both;
}

.menu-btn {
    background: var(--bg-panel);
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    padding: 32px 48px;
    cursor: pointer;
    transition: all 0.3s;
    text-align: center;
    min-width: 200px;
}
.menu-btn:hover {
    border-color: var(--accent);
    transform: translateY(-4px);
    box-shadow: 0 12px 40px rgba(0, 212, 255, 0.2);
}
.btn-icon { font-size: 48px; display: block; margin-bottom: 12px; color: var(--accent); }
.btn-text { font-size: 24px; font-weight: 600; color: var(--text); display: block; }
.btn-desc { font-size: 12px; color: var(--text-dim); display: block; margin-top: 8px; }

/* === LEVEL SELECT === */
#level-screen {
    background: var(--bg-dark);
    z-index: 150;
    padding: 24px;
    overflow-y: auto;
}

.level-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
}
.level-header h2 { font-size: 24px; }

.back-btn {
    background: transparent;
    border: 1px solid var(--glass-border);
    color: var(--text);
    padding: 8px 16px;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
}
.back-btn:hover { border-color: var(--accent); color: var(--accent); }

#progress-display { color: var(--accent); font-weight: 600; }

.level-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 16px;
    max-width: 900px;
    margin: 0 auto;
}

.level-card {
    background: var(--bg-panel);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    padding: 12px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
    position: relative;
}
.level-preview {
    display: block;
    margin: 0 auto 8px;
    border-radius: 8px;
    background: #0a0a1a;
}
.level-card:hover { border-color: var(--accent); transform: scale(1.05); }
.level-card.locked { opacity: 0.4; cursor: not-allowed; }
.level-card.completed { border-color: var(--success); }
.level-card.completed::after {
    content: '✓';
    position: absolute;
    top: 8px;
    right: 8px;
    color: var(--success);
    font-size: 14px;
}

.level-num { font-size: 28px; font-weight: 700; color: var(--accent); }
.level-title { font-size: 11px; color: var(--text-dim); margin-top: 8px; }

/* === GAME SCREEN === */
#game-screen { z-index: 100; }

#header {
    height: 48px;
    background: var(--bg-panel);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--glass-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    z-index: 100;
}

.header-left { display: flex; align-items: center; gap: 12px; }
.logo-small { font-weight: 600; font-size: 14px; }
.logo-small span { color: var(--accent); }

.level-badge {
    background: var(--accent);
    color: #000;
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
}

.level-nav {
    display: flex;
    gap: 4px;
}
.nav-btn {
    background: transparent;
    border: 1px solid var(--glass-border);
    color: var(--text);
    width: 28px;
    height: 28px;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}
.nav-btn:hover:not(:disabled) {
    border-color: var(--accent);
    color: var(--accent);
}
.nav-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.hint-btn {
    background: transparent;
    border: 1px solid var(--accent);
    color: var(--accent);
    padding: 4px 10px;
    border-radius: 8px;
    font-size: 11px;
    cursor: pointer;
    transition: all 0.2s;
}
.hint-btn:hover {
    background: var(--accent);
    color: #000;
}

.toolbar { display: flex; align-items: center; gap: 16px; }
.toolbar-item { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-dim); }
.toolbar-item input[type="range"] { width: 60px; accent-color: var(--accent); }

#main {
    flex: 1;
    display: flex;
    position: relative;
    overflow: hidden;
}

.panel {
    display: flex;
    flex-direction: column;
    background: var(--bg-panel);
    backdrop-filter: blur(10px);
    border-right: 1px solid var(--glass-border);
    position: relative;
    z-index: 10;
    pointer-events: auto;
}
.panel:last-child { border-right: none; }

.viewport {
    background: transparent !important;
    backdrop-filter: none !important;
}

.panel-header {
    padding: 8px 12px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-dim);
    border-bottom: 1px solid var(--glass-border);
    display: flex;
    justify-content: space-between;
}

#editor-panel { width: 35%; min-width: 250px; }
#editor-container { flex: 1; display: flex; overflow: hidden; }

#line-numbers {
    width: 40px;
    min-width: 40px;
    padding: 12px 8px;
    text-align: right;
    font-family: var(--code-font);
    font-size: 13px;
    line-height: 19.5px;
    color: var(--text-dim);
    background: rgba(0,0,0,0.3);
    user-select: none;
    overflow-y: hidden;
}

#code-input {
    flex: 1;
    border: none;
    resize: none;
    outline: none;
    padding: 12px;
    font-family: var(--code-font);
    font-size: 13px;
    line-height: 19.5px;
    background: transparent;
    color: var(--text);
    tab-size: 2;
    word-wrap: break-word;
    white-space: pre-wrap;
    overflow-y: auto;
}

#editor-footer {
    padding: 8px 12px;
    border-top: 1px solid var(--glass-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.btn {
    padding: 6px 14px;
    border: 1px solid var(--accent);
    border-radius: 4px;
    background: transparent;
    color: var(--accent);
    font-family: var(--ui-font);
    font-weight: 600;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s;
}
.btn:hover { background: var(--accent); color: #000; }
.btn-secondary { border-color: var(--text-dim); color: var(--text-dim); }
.btn-secondary:hover { background: var(--text-dim); color: #000; }

#error-console {
    display: none;
    padding: 8px 12px;
    background: rgba(255, 68, 102, 0.15);
    border-top: 1px solid var(--error);
    font-family: var(--code-font);
    font-size: 11px;
    color: var(--error);
}

.h-resizer {
    width: 4px;
    background: transparent;
    cursor: col-resize;
    z-index: 50;
    transition: background 0.15s;
}
.h-resizer:hover, .h-resizer.active { background: var(--accent); }

.viewport { flex: 1; cursor: grab; }
.viewport:active { cursor: grabbing; }

.stats {
    position: absolute;
    bottom: 8px;
    left: 8px;
    padding: 6px 10px;
    background: var(--bg-panel);
    border: 1px solid var(--glass-border);
    border-radius: 4px;
    font-family: var(--code-font);
    font-size: 11px;
    z-index: 10;
    pointer-events: none;
}
.stats .shape { color: var(--success); }
.stats .total { color: var(--accent); }

#validate-container {
    position: fixed;
    bottom: 120px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 500;
    pointer-events: none;
}

.validate-btn {
    padding: 12px 24px;
    background: var(--success);
    border: none;
    border-radius: 8px;
    color: #000;
    font-weight: 700;
    font-size: 14px;
    cursor: pointer;
    animation: pulse 1.5s ease infinite;
    pointer-events: auto;
    box-shadow: 0 4px 20px rgba(0, 255, 136, 0.4);
}

#canvas-container {
    position: absolute;
    top: 48px;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 0;
    pointer-events: none;
}

/* === MODAL === */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.8);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 300;
}
.modal.active { display: flex; }

.modal-content {
    background: var(--bg-panel);
    border: 1px solid var(--glass-border);
    border-radius: 20px;
    padding: 40px;
    text-align: center;
    min-width: 320px;
    animation: fadeInUp 0.3s ease;
}
.modal-icon { font-size: 64px; margin-bottom: 16px; }
.modal-content h2 { margin-bottom: 24px; }

.modal-stats { margin-bottom: 24px; }
.stat-row {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    border-bottom: 1px solid var(--glass-border);
}
.stat-row:last-child { border-bottom: none; }
.stat-row span:last-child { color: var(--accent); font-weight: 600; }

.modal-buttons { display: flex; gap: 12px; justify-content: center; }

/* Reference Modal */
.ref-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
    margin-bottom: 20px;
    text-align: left;
}
.ref-section h3 {
    margin-top: 0;
    margin-bottom: 12px;
    color: var(--accent);
    font-size: 14px;
    border-bottom: 1px solid var(--glass-border);
    padding-bottom: 8px;
}
.color-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
    gap: 8px;
}
.color-item {
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(255, 255, 255, 0.05);
    padding: 6px;
    border-radius: 6px;
    font-size: 11px;
    font-family: 'Fira Code', monospace;
}
.color-swatch {
    width: 20px;
    height: 20px;
    border-radius: 4px;
    border: 1px solid rgba(255,255,255,0.2);
}
.math-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    gap: 8px;
}
.math-item {
    background: rgba(255, 255, 255, 0.05);
    padding: 6px 10px;
    border-radius: 6px;
    font-size: 11px;
    font-family: 'Fira Code', monospace;
    color: var(--text-dim);
}
.math-item span {
    color: var(--keyword);
    font-weight: 600;
}

/* Hint Modal */
.hint-content {
    max-width: 90vw;
    width: 800px;
    text-align: left;
}
.hint-content h2 { text-align: center; }
#hint-code {
    background: rgba(0,0,0,0.4);
    border: 1px solid var(--glass-border);
    border-radius: 8px;
    padding: 16px;
    margin: 16px 0;
    font-family: var(--code-font);
    font-size: 13px;
    line-height: 1.5;
    color: var(--accent);
    overflow-x: auto;
    white-space: pre-wrap;
    max-height: 300px;
    overflow-y: auto;
}

/* === ANIMATIONS === */
@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}
@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}
@keyframes shimmer {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

/* === MOBILE === */
@media (max-width: 900px) {
    .menu-buttons { flex-direction: column; }
    .menu-btn { min-width: unset; width: 100%; max-width: 280px; }
    #main { flex-direction: column; }
    .panel { width: 100% !important; border-right: none; }
    #editor-panel { height: 40%; min-width: unset; }
    .viewport { height: 30%; }
    .h-resizer { display: none; }
}
