/* Base & Reset */
:root {
    --bg-dark: #0f0f13;
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    
    --accent-primary: #00f0ff; /* Neon cyan */
    --accent-secondary: #ff0055; /* Neon pink/red */
    --accent-tertiary: #facc15; /* Coin gold */
    
    --danger: #ef4444;
    --success: #22c55e;
    
    --glass-bg: rgba(15, 15, 19, 0.75);
    --glass-border: rgba(255, 255, 255, 0.1);
    
    --font-main: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    --font-mono: 'JetBrains Mono', 'Courier New', Courier, monospace;
}

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

body, html {
    width: 100%;
    height: 100%;
    background-color: var(--bg-dark);
    color: var(--text-main);
    font-family: var(--font-main);
    overflow: hidden;
    touch-action: none;
}

#game-container {
    position: relative;
    width: 100vw;
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: #050510;
    perspective: 1000px;
}

/* Parallax Background */
.parallax-bg {
    position: absolute;
    top: 0;
    left: 0;
    width: 200vw;
    height: 200vh;
    z-index: 0;
    pointer-events: none;
    background-image: 
        radial-gradient(circle at center, rgba(0, 240, 255, 0.03) 0%, transparent 50%),
        linear-gradient(rgba(255, 255, 255, 0.02) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255, 255, 255, 0.02) 1px, transparent 1px);
    background-size: 100% 100%, 40px 40px, 40px 40px;
}

#bg-layer-2 {
    background-image: 
        linear-gradient(rgba(255, 0, 85, 0.02) 2px, transparent 2px),
        linear-gradient(90deg, rgba(255, 0, 85, 0.02) 2px, transparent 2px);
    background-size: 120px 120px;
    opacity: 0.5;
}

canvas {
    display: block;
    z-index: 1;
    image-rendering: pixelated;
    box-shadow: 0 0 40px rgba(0, 240, 255, 0.1), inset 0 0 20px rgba(0, 0, 0, 0.8);
    transition: transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    background-color: #111116;
}

/* UI Layer */
#ui-layer {
    position: absolute;
    inset: 0;
    z-index: 10;
    pointer-events: none;
    display: flex;
    flex-direction: column;
}

.screen {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    background: var(--glass-bg);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    pointer-events: auto;
    transition: opacity 0.3s ease;
    padding: 2rem;
}

.hidden {
    opacity: 0;
    pointer-events: none !important;
}

/* HUD */
#hud {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    padding: 1rem 2rem;
    pointer-events: none;
    display: flex;
    justify-content: center;
    transition: opacity 0.3s ease;
}

.hud-top {
    display: flex;
    gap: 2rem;
    background: rgba(15, 15, 19, 0.6);
    padding: 0.75rem 2rem;
    border-radius: 999px;
    border: 1px solid var(--glass-border);
    backdrop-filter: blur(4px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}

.stat-box {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
}

.stat-box .label {
    font-size: 0.65rem;
    text-transform: uppercase;
    color: var(--text-muted);
    letter-spacing: 0.1em;
    font-weight: 600;
}

.stat-box span:not(.label) {
    font-family: var(--font-mono);
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--accent-primary);
    text-shadow: 0 0 10px rgba(0, 240, 255, 0.4);
}

#coin-display { color: var(--accent-tertiary); text-shadow: 0 0 10px rgba(250, 204, 21, 0.4); }
#death-display { color: var(--accent-secondary); text-shadow: 0 0 10px rgba(255, 0, 85, 0.4); }

/* Typography & Visuals */
h1 {
    font-size: 5rem;
    font-weight: 900;
    letter-spacing: -0.02em;
    margin-bottom: 0px;
    line-height: 1;
    color: var(--text-main);
}

h1.outline {
    color: transparent;
    -webkit-text-stroke: 2px var(--accent-primary);
    margin-bottom: 1rem;
}

h2 {
    font-size: 2rem;
    font-weight: 700;
    color: var(--text-main);
    margin-bottom: 2rem;
    text-align: center;
}

.subtitle {
    color: var(--accent-primary);
    letter-spacing: 0.25em;
    font-size: 1.25rem;
    margin-bottom: 4rem;
    text-shadow: 0 0 10px rgba(0, 240, 255, 0.5);
}

.txt-accent {
    color: var(--accent-secondary);
    text-shadow: 0 0 15px rgba(255, 0, 85, 0.5);
    -webkit-text-stroke: 0px;
}

/* Glitch Effect */
.glitch {
    position: relative;
    display: inline-block;
}

.glitch::before, .glitch::after {
    content: attr(data-text);
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0.8;
}

.glitch::before {
    left: 2px;
    text-shadow: -2px 0 var(--accent-secondary);
    clip: rect(24px, 550px, 90px, 0);
    animation: glitch-anim 3s infinite linear alternate-reverse;
}

.glitch::after {
    left: -2px;
    text-shadow: -2px 0 var(--accent-primary);
    clip: rect(85px, 550px, 140px, 0);
    animation: glitch-anim 2.5s infinite linear alternate-reverse;
}

@keyframes glitch-anim {
    0% { clip: rect(10px, 9999px, 86px, 0); }
    5% { clip: rect(69px, 9999px, 57px, 0); }
    10% { clip: rect(38px, 9999px, 51px, 0); }
    15% { clip: rect(15px, 9999px, 11px, 0); }
    20% { clip: rect(59px, 9999px, 63px, 0); }
    25% { clip: rect(74px, 9999px, 54px, 0); }
    30% { clip: rect(66px, 9999px, 98px, 0); }
    35% { clip: rect(32px, 9999px, 51px, 0); }
    40% { clip: rect(81px, 9999px, 45px, 0); }
    45% { clip: rect(66px, 9999px, 4px, 0); }
    50% { clip: rect(32px, 9999px, 32px, 0); }
    55% { clip: rect(60px, 9999px, 14px, 0); }
    60% { clip: rect(79px, 9999px, 58px, 0); }
    65% { clip: rect(85px, 9999px, 73px, 0); }
    70% { clip: rect(82px, 9999px, 44px, 0); }
    75% { clip: rect(64px, 9999px, 41px, 0); }
    80% { clip: rect(98px, 9999px, 20px, 0); }
    85% { clip: rect(9px, 9999px, 7px, 0); }
    90% { clip: rect(21px, 9999px, 39px, 0); }
    95% { clip: rect(51px, 9999px, 87px, 0); }
    100% { clip: rect(23px, 9999px, 20px, 0); }
}

/* Buttons */
.menu-buttons {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    width: 100%;
    max-width: 300px;
    margin-bottom: 2rem;
}

.btn {
    padding: 1rem 2rem;
    font-size: 1.1rem;
    font-weight: 700;
    font-family: var(--font-main);
    letter-spacing: 0.1em;
    border-radius: 8px;
    border: none;
    cursor: pointer;
    transition: all 0.2s ease;
    text-transform: uppercase;
    position: relative;
    overflow: hidden;
    backdrop-filter: blur(4px);
}

.btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.2), transparent);
    transition: all 0.4s ease;
}

.btn:hover::before {
    left: 100%;
}

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

.btn.primary {
    background: var(--accent-primary);
    color: #000;
    box-shadow: 0 0 20px rgba(0, 240, 255, 0.4);
}

.btn.primary:hover {
    background: #fff;
    box-shadow: 0 0 30px rgba(0, 240, 255, 0.6);
}

.btn.secondary {
    background: transparent;
    color: var(--text-main);
    border: 2px solid var(--accent-primary);
}

.btn.secondary:hover {
    background: rgba(0, 240, 255, 0.1);
    box-shadow: inset 0 0 10px rgba(0, 240, 255, 0.2);
}

.back-btn {
    margin-top: 2rem;
    width: 100%;
    max-width: 200px;
}

/* Level Select */
.level-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 1rem;
    max-width: 600px;
    width: 100%;
    overflow-y: auto;
    max-height: 60vh;
    padding: 1rem;
    scrollbar-width: thin;
    scrollbar-color: var(--accent-primary) var(--bg-dark);
}

.level-grid::-webkit-scrollbar {
    width: 6px;
}
.level-grid::-webkit-scrollbar-track {
    background: var(--bg-dark);
}
.level-grid::-webkit-scrollbar-thumb {
    background: var(--accent-primary);
    border-radius: 3px;
}

.level-item {
    aspect-ratio: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    background: rgba(255,255,255,0.05);
    border: 1px solid var(--glass-border);
    border-radius: 8px;
    font-size: 1.5rem;
    font-family: var(--font-mono);
    font-weight: 700;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.2s;
    position: relative;
}

.level-item:hover {
    background: rgba(255,255,255,0.1);
    transform: translateY(-2px);
}

.level-item.unlocked {
    color: var(--text-main);
    border-color: rgba(0, 240, 255, 0.3);
}

.level-item.unlocked:hover {
    border-color: var(--accent-primary);
    box-shadow: 0 0 15px rgba(0, 240, 255, 0.3);
}

.level-item.completed {
    background: rgba(0, 240, 255, 0.1);
    color: var(--accent-primary);
    border-color: var(--accent-primary);
}

.level-item.locked {
    cursor: not-allowed;
    opacity: 0.5;
}

.level-item.locked::after {
    content: '🔒';
    position: absolute;
    bottom: 5px;
    right: 5px;
    font-size: 0.8rem;
}

.level-item .stars {
    position: absolute;
    bottom: 4px;
    display: flex;
    gap: 2px;
    font-size: 0.6rem;
    color: var(--accent-tertiary);
}

/* Stats Panel */
.stats-panel {
    background: rgba(0,0,0,0.5);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    padding: 2rem;
    margin-bottom: 2rem;
    width: 100%;
    max-width: 400px;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.stat-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 1.2rem;
}

.stat-row span:last-child {
    font-family: var(--font-mono);
    color: var(--accent-primary);
    font-weight: 700;
}

/* Controls Info */
.controls-info {
    text-align: center;
    color: var(--text-muted);
    font-size: 0.9rem;
    line-height: 1.6;
}

kbd {
    display: inline-block;
    padding: 3px 6px;
    font-family: var(--font-mono);
    font-size: 0.8rem;
    color: var(--text-main);
    background-color: rgba(255,255,255,0.1);
    border: 1px solid rgba(255,255,255,0.2);
    border-radius: 4px;
    box-shadow: 0 2px 0 rgba(0,0,0,0.2);
    margin: 0 2px;
}

/* Mobile Controls */
#mobile-controls {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    padding: 20px;
    display: flex;
    justify-content: space-between;
    pointer-events: none;
    z-index: 20;
}

.d-pad, .action-pad {
    display: flex;
    gap: 10px;
    pointer-events: auto;
}

.control-btn {
    width: 70px;
    height: 70px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.1);
    border: 2px solid rgba(255, 255, 255, 0.2);
    color: rgba(255, 255, 255, 0.6);
    font-size: 1.5rem;
    display: flex;
    justify-content: center;
    align-items: center;
    backdrop-filter: blur(4px);
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    transition: all 0.1s;
}

.control-btn:active {
    background: rgba(255, 255, 255, 0.3);
    transform: scale(0.9);
}

.action-btn {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    font-size: 1rem;
    font-weight: 700;
    letter-spacing: 1px;
    border-color: rgba(0, 240, 255, 0.3);
    color: var(--accent-primary);
}

.action-btn:active {
    background: rgba(0, 240, 255, 0.3);
}

/* Media Queries for Mobile/Responsive */
@media (max-width: 768px) {
    h1 { font-size: 3.5rem; }
    h2 { font-size: 1.5rem; }
    
    #hud { padding: 0.5rem; }
    .hud-top { gap: 1rem; padding: 0.5rem 1rem; }
    
    .level-grid { grid-template-columns: repeat(4, 1fr); }
    
    .controls-info { display: none; }
}

@media (max-width: 480px) {
    h1 { font-size: 2.5rem; }
    
    .hud-top { gap: 0.5rem; padding: 0.25rem 0.5rem; }
    .stat-box .label { font-size: 0.5rem; }
    .stat-box span:not(.label) { font-size: 0.9rem; }
    
    .level-grid { grid-template-columns: repeat(3, 1fr); }
}

@media (pointer: fine) {
    #mobile-controls {
        display: none !important;
    }
}
