:root {
    --bg-color: #0a0e14;
    --bg-gradient: radial-gradient(ellipse at 50% 30%, #141b24, #0a0e14 70%);
    --text-primary: #e6edf3;
    --text-secondary: #8b949e;
    --glass-bg: rgba(18, 24, 32, 0.75);
    --glass-border: rgba(255, 255, 255, 0.08);
    --primary: #58a6ff;
    --primary-dark: #2d6abf;
    --success: #3fb950;
    --danger: #f85149;
    --warning: #ffa657;
    --purple: #a371f7;
    --cyan: #39d2e0;
}

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

body, html {
    width: 100%; height: 100%; overflow: hidden;
    font-family: 'Outfit', sans-serif;
    background: var(--bg-color); color: var(--text-primary);
    touch-action: none;
}

#game-container {
    position: relative; width: 100vw; height: 100vh;
    display: flex; justify-content: center; align-items: center;
    background: var(--bg-gradient);
}

canvas { display: block; }

#ui-layer {
    position: absolute; top: 0; left: 0; width: 100%; height: 100%;
    pointer-events: none;
}

/* HUD */
#hud {
    position: absolute; top: 16px; left: 16px; right: 16px;
    display: flex; justify-content: space-between; align-items: center;
    pointer-events: auto; z-index: 10;
    transition: opacity 0.3s;
}
#hud.hidden { opacity: 0; pointer-events: none; }
#hud-left, #hud-right { display: flex; gap: 8px; align-items: center; }

.hud-pill {
    font-size: 0.85rem; font-weight: 600;
    padding: 6px 14px; border-radius: 20px;
    background: var(--glass-bg); border: 1px solid var(--glass-border);
    backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
    box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}

.glass-btn {
    pointer-events: auto; font-size: 0.8rem; font-weight: 500;
    padding: 6px 12px; border-radius: 16px; cursor: pointer;
    background: var(--glass-bg); color: var(--text-primary);
    border: 1px solid var(--glass-border);
    backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
    font-family: 'Outfit', sans-serif; transition: background 0.2s;
}
.glass-btn:hover { background: rgba(255,255,255,0.1); }
.glass-btn:active { transform: scale(0.95); }

/* Screens */
.screen {
    position: absolute; top: 0; left: 0; width: 100%; height: 100%;
    display: flex; justify-content: center; align-items: center;
    background: rgba(0,0,0,0.55); backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    pointer-events: auto; z-index: 20;
    transition: opacity 0.35s ease;
}
.screen.hidden { opacity: 0; pointer-events: none !important; }
.screen.hidden * { pointer-events: none !important; }

/* Glass Panel */
.glass-panel {
    background: var(--glass-bg); border: 1px solid var(--glass-border);
    backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
    padding: 2.5rem; border-radius: 20px; text-align: center;
    min-width: 320px; max-width: 90vw;
    box-shadow: 0 12px 48px rgba(0,0,0,0.5);
    animation: panelIn 0.4s ease-out;
}
.wide-panel { min-width: 360px; max-width: 600px; }

@keyframes panelIn {
    from { opacity: 0; transform: translateY(24px) scale(0.94); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

.glass-panel h1 {
    font-size: 2.4rem; font-weight: 700; letter-spacing: 1px; margin-bottom: 0.4rem;
    background: linear-gradient(135deg, var(--primary), var(--purple));
    -webkit-background-clip: text; -webkit-text-fill-color: transparent;
    background-clip: text;
}
.glass-panel h1.success {
    background: linear-gradient(135deg, var(--success), #56d364);
    -webkit-background-clip: text; background-clip: text;
}
.glass-panel h1.danger {
    background: linear-gradient(135deg, var(--danger), var(--warning));
    -webkit-background-clip: text; background-clip: text;
}

.subtitle { color: var(--text-secondary); margin-bottom: 1.2rem; font-weight: 300; }

.instructions {
    background: rgba(0,0,0,0.3); padding: 1rem; border-radius: 10px;
    margin-bottom: 1.5rem; text-align: left; font-size: 0.9rem; line-height: 1.7;
}
.hint { color: var(--warning); margin-top: 0.5rem; }

/* Buttons */
.primary-btn {
    display: inline-block; pointer-events: auto;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: white; border: none; padding: 0.75rem 2rem;
    font-size: 1.05rem; font-family: 'Outfit', sans-serif; font-weight: 600;
    border-radius: 50px; cursor: pointer;
    box-shadow: 0 4px 16px rgba(88,166,255,0.3);
    transition: transform 0.2s, box-shadow 0.2s;
    margin: 0.4rem;
}
.primary-btn:hover { transform: translateY(-2px); box-shadow: 0 6px 24px rgba(88,166,255,0.4); }
.primary-btn:active { transform: translateY(1px); }

.secondary-btn {
    display: inline-block; pointer-events: auto;
    background: transparent; color: var(--text-secondary);
    border: 1px solid var(--glass-border); padding: 0.6rem 1.5rem;
    font-size: 0.9rem; font-family: 'Outfit', sans-serif; font-weight: 500;
    border-radius: 50px; cursor: pointer; transition: all 0.2s; margin: 0.4rem;
}
.secondary-btn:hover { color: var(--text-primary); border-color: rgba(255,255,255,0.2); }

/* Level Select Grid */
#level-grid {
    display: grid; grid-template-columns: repeat(5, 1fr);
    gap: 10px; margin: 1.5rem 0; max-height: 50vh; overflow-y: auto;
    padding: 4px;
}
.level-cell {
    aspect-ratio: 1; display: flex; flex-direction: column;
    justify-content: center; align-items: center;
    border-radius: 12px; cursor: pointer; font-weight: 600; font-size: 1.1rem;
    background: rgba(255,255,255,0.04); border: 1px solid var(--glass-border);
    transition: all 0.2s; position: relative;
}
.level-cell:hover { background: rgba(255,255,255,0.1); transform: scale(1.05); }
.level-cell.locked { opacity: 0.3; cursor: default; }
.level-cell.locked:hover { transform: none; background: rgba(255,255,255,0.04); }
.level-cell.completed { border-color: var(--success); }
.level-cell .stars { font-size: 0.6rem; margin-top: 2px; }

/* Win Stars */
.win-stars { font-size: 2rem; margin: 0.8rem 0; letter-spacing: 4px; }
#win-rating { color: var(--warning); font-weight: 500; margin-top: 0.3rem; }

/* Mobile touch area hint */
#touch-controls {
    position: absolute; bottom: 20px; left: 50%; transform: translateX(-50%);
    color: var(--text-secondary); font-size: 0.75rem; opacity: 0.5;
}

@media (max-width: 480px) {
    .glass-panel { padding: 1.5rem; min-width: 280px; }
    .glass-panel h1 { font-size: 1.8rem; }
    #level-grid { grid-template-columns: repeat(4, 1fr); }
    .hud-pill { font-size: 0.75rem; padding: 4px 10px; }
}
