:root {
    --bg-dark: #0f1219;
    --bg-panel: rgba(15, 18, 25, 0.7);
    --primary: #64748B;
    --secondary: #94A3B8;
    --accent: #38bdf8;
    --accent-glow: rgba(56, 189, 248, 0.5);
    --text-main: #f8fafc;
    --text-muted: #94A3B8;
    --success: #22c55e;
    --error: #ef4444;
    --glass-border: rgba(255, 255, 255, 0.1);
    --radius: 12px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

body {
    background-color: var(--bg-dark);
    color: var(--text-main);
    font-family: 'Inter', sans-serif;
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    width: 100vw;
    /* Cybernetic background grid */
    background-image: 
        linear-gradient(rgba(56, 189, 248, 0.05) 1px, transparent 1px),
        linear-gradient(90deg, rgba(56, 189, 248, 0.05) 1px, transparent 1px);
    background-size: 30px 30px;
    background-position: center center;
}

#app {
    position: relative;
    width: 100%;
    max-width: 800px;
    height: 100%;
    max-height: 900px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    padding: 20px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease, transform 0.3s ease;
    transform: translateY(20px);
}

.screen.active {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0);
}

.glass-panel {
    background: var(--bg-panel);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius);
    padding: 40px 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 20px;
    margin: auto;
    width: 90%;
    max-width: 400px;
    height: auto;
    box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
}

/* Typography */
h1, h2, h3 { text-align: center; }

h1.neon-text, h2.neon-text {
    font-weight: 800;
    font-size: 2.5rem;
    color: #fff;
    text-shadow: 0 0 5px #fff, 0 0 10px #fff, 0 0 20px var(--accent), 0 0 40px var(--accent);
    margin-bottom: 10px;
    line-height: 1.1;
    letter-spacing: 2px;
}
h2.neon-text { font-size: 2rem; }

.subtitle {
    color: var(--secondary);
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 30px;
    text-align: center;
}

/* Buttons */
.btn {
    padding: 14px 24px;
    border-radius: var(--radius);
    font-family: 'Inter', sans-serif;
    font-weight: 600;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.2s ease;
    width: 100%;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.btn:active { transform: scale(0.95); }

.primary-btn {
    background: var(--accent);
    color: #000;
    border: none;
    box-shadow: 0 0 15px var(--accent-glow);
}
.primary-btn:hover {
    box-shadow: 0 0 25px var(--accent-glow);
    background: #7dd3fc;
}

.outline-btn {
    background: transparent;
    color: var(--text-main);
    border: 1px solid var(--accent);
}
.outline-btn:hover {
    background: rgba(56, 189, 248, 0.1);
}

.icon-btn {
    background: transparent;
    border: 1px solid var(--glass-border);
    color: var(--text-main);
    width: 40px;
    height: 40px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    font-size: 1.2rem;
}
.icon-btn:hover { background: rgba(255,255,255,0.1); }

.menu-buttons {
    display: flex;
    flex-direction: column;
    gap: 15px;
    width: 100%;
}

/* Stats */
.stats-preview {
    display: flex;
    justify-content: space-between;
    width: 100%;
    margin-top: 20px;
    font-size: 0.9rem;
    color: var(--secondary);
}
.streak-text { color: #f97316; font-weight: bold; }

/* Level Grid */
.level-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 10px;
    width: 100%;
    margin-bottom: 20px;
}
.level-btn {
    aspect-ratio: 1;
    background: rgba(255,255,255,0.05);
    border: 1px solid var(--glass-border);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.2s;
}
.level-btn.completed {
    border-color: var(--accent);
    color: var(--accent);
    box-shadow: 0 0 10px rgba(56, 189, 248, 0.2);
}
.level-btn.locked {
    opacity: 0.5;
    cursor: not-allowed;
}
.level-btn:not(.locked):hover {
    background: rgba(56, 189, 248, 0.2);
}
.scroll-area {
    width: 100%;
    max-height: 50vh;
    overflow-y: auto;
    padding-right: 5px;
}
.scroll-area::-webkit-scrollbar { width: 6px; }
.scroll-area::-webkit-scrollbar-track { background: transparent; }
.scroll-area::-webkit-scrollbar-thumb { background: var(--secondary); border-radius: 3px; }

/* Game Screen */
#game-screen {
    padding: 10px;
    justify-content: flex-start;
    gap: 15px;
}
.game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--bg-panel);
    padding: 10px 15px;
    border-radius: var(--radius);
    border: 1px solid var(--glass-border);
}
.header-info {
    display: flex;
    flex-direction: column;
    align-items: center;
}
#level-title { font-weight: bold; font-size: 1.1rem; }
.time-text { color: var(--accent); font-family: 'Fira Code', monospace; }

.editor-layout {
    display: flex;
    flex-direction: column;
    flex: 1;
    gap: 15px;
    height: calc(100% - 150px);
}
@media (min-width: 600px) {
    .editor-layout { flex-direction: row; }
    .panels-container { flex-direction: column; width: 220px; }
}

.panels-container {
    display: flex;
    gap: 10px;
    justify-content: center;
}
.panel {
    background: rgba(0,0,0,0.3);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius);
    padding: 10px;
    display: flex;
    flex-direction: column;
    align-items: center;
}
.panel h3 { font-size: 0.8rem; color: var(--secondary); margin-bottom: 5px; text-transform: uppercase; }
canvas {
    background: #fff;
    border-radius: 4px;
    max-width: 100%;
    height: auto;
    aspect-ratio: 1;
    width: 150px;
}

.editor-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: #1e1e1e;
    border-radius: var(--radius);
    border: 1px solid var(--glass-border);
    overflow: hidden;
}
.editor-header {
    background: #2d2d2d;
    padding: 8px 15px;
    font-size: 0.8rem;
    color: var(--secondary);
    display: flex;
    justify-content: space-between;
    font-family: 'Fira Code', monospace;
}
#css-editor {
    flex: 1;
    background: transparent;
    border: none;
    color: #ce9178;
    font-family: 'Fira Code', monospace;
    font-size: 0.9rem;
    padding: 15px;
    resize: none;
    outline: none;
    line-height: 1.5;
}

.game-controls {
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.progress-bar-container {
    height: 30px;
    background: rgba(255,255,255,0.1);
    border-radius: 15px;
    position: relative;
    overflow: hidden;
    border: 1px solid var(--glass-border);
}
.progress-bar {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, #ef4444, #eab308, #22c55e);
    background-size: 200% 100%;
    transition: width 0.3s ease;
}
#match-percent {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-weight: bold;
    font-size: 0.9rem;
    text-shadow: 0 1px 2px rgba(0,0,0,0.8);
}

/* Juice & Animations */
.shake { animation: shake 0.4s cubic-bezier(.36,.07,.19,.97) both; }
@keyframes shake {
    10%, 90% { transform: translate3d(-1px, 0, 0); }
    20%, 80% { transform: translate3d(2px, 0, 0); }
    30%, 50%, 70% { transform: translate3d(-4px, 0, 0); }
    40%, 60% { transform: translate3d(4px, 0, 0); }
}
.flash { animation: flash 0.5s ease-out; }
@keyframes flash {
    0% { background-color: rgba(255,255,255,0.8); }
    100% { background-color: transparent; }
}

/* Particles */
#particle-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 999;
}

/* Toasts / Floating text */
#toast-container {
    position: absolute;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    flex-direction: column;
    gap: 10px;
    z-index: 1000;
    pointer-events: none;
}
.toast {
    background: rgba(0,0,0,0.8);
    color: var(--accent);
    padding: 10px 20px;
    border-radius: 20px;
    border: 1px solid var(--accent);
    font-weight: bold;
    animation: toast-in-out 2s forwards;
    text-align: center;
}
@keyframes toast-in-out {
    0% { opacity: 0; transform: translateY(-20px) scale(0.9); }
    15% { opacity: 1; transform: translateY(0) scale(1.1); }
    25% { transform: scale(1); }
    80% { opacity: 1; transform: translateY(0); }
    100% { opacity: 0; transform: translateY(-20px); }
}

/* Leaderboard Rows */
.lb-row {
    display: flex;
    justify-content: space-between;
    padding: 10px;
    border-bottom: 1px solid rgba(255,255,255,0.05);
}
.lb-row.header { font-weight: bold; color: var(--accent); text-transform: uppercase; }
.tabs { display: flex; width: 100%; gap: 10px; margin-bottom: 15px;}
.tab-btn {
    flex: 1; padding: 10px; background: transparent; color: var(--text-muted); border: none; border-bottom: 2px solid transparent; cursor: pointer;
}
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: bold; }

.stat-row { display: flex; justify-content: space-between; width: 100%; margin-bottom: 10px; font-family: 'Fira Code', monospace;}
.total-score { font-size: 1.2rem; font-weight: bold; color: var(--accent); margin-top: 15px; border-top: 1px dashed var(--glass-border); padding-top: 15px;}
