:root {
    --bg-color: #0d0d15;
    --primary: #00ff88;
    --primary-dark: #00cc6a;
    --accent: #9d00ff;
    --danger: #ff4444;
    --text: #ffffff;
    --glass: rgba(22, 22, 30, 0.85);
    --glass-border: rgba(255, 255, 255, 0.1);
    --font-main: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

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

body {
    background-color: var(--bg-color);
    color: var(--text);
    font-family: var(--font-main);
    overflow: hidden;
    height: 100vh;
    width: 100vw;
    position: fixed;
    touch-action: none; /* Prevent pull-to-refresh and overscroll */
}

/* --- Canvas & Background --- */
#bg-canvas, #game-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    cursor: none; /* Hide cursor for immersion */
}

#bg-canvas { z-index: 0; }
#game-canvas { 
    z-index: 1; 
    display: block;
    /* Hardware acceleration */
    transform: translateZ(0);
    -webkit-transform: translateZ(0);
}

/* --- Shared UI Containers --- */
.container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    position: relative;
    z-index: 10;
    pointer-events: none;
}

.card, .btn, input { pointer-events: auto; }

.card {
    background: var(--glass);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
    padding: 2.5rem;
    border-radius: 20px;
    box-shadow: 0 0 30px rgba(0, 0, 0, 0.5), inset 0 0 20px rgba(255, 255, 255, 0.02);
    width: 90%;
    max-width: 420px;
    text-align: center;
    animation: fadeIn 0.5s ease-out;
}

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

h1 {
    font-size: 3.5rem;
    margin-bottom: 1.5rem;
    color: var(--text);
    text-shadow: 0 0 15px var(--primary), 0 0 30px var(--primary-dark);
    font-weight: 800;
    letter-spacing: 3px;
    font-style: italic;
}

h2 { 
    margin-bottom: 1.5rem; 
    color: var(--primary); 
    text-transform: uppercase; 
    letter-spacing: 2px; 
}

/* --- Inputs & Buttons --- */
.input-group { margin-bottom: 1.5rem; width: 100%; }

input[type="text"] {
    width: 100%;
    padding: 15px;
    border-radius: 12px;
    border: 2px solid var(--glass-border);
    background: rgba(0, 0, 0, 0.4);
    color: white;
    font-size: 1.2rem;
    text-align: center;
    outline: none;
    transition: 0.3s;
    font-weight: bold;
}

input[type="text"]:focus {
    border-color: var(--primary);
    box-shadow: 0 0 15px rgba(0, 255, 136, 0.2);
}

.btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    padding: 16px;
    margin-bottom: 12px;
    border: none;
    border-radius: 12px;
    font-size: 1.2rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
    color: #000;
    gap: 12px;
    text-transform: uppercase;
}

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

.btn-primary {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    box-shadow: 0 5px 15px rgba(0, 255, 136, 0.3);
}

.btn-primary:hover {
    filter: brightness(1.1);
    box-shadow: 0 8px 20px rgba(0, 255, 136, 0.5);
}

.btn-primary:disabled {
    filter: grayscale(1);
    cursor: not-allowed;
    opacity: 0.7;
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.05);
    border: 2px solid var(--glass-border);
    color: #fff;
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: var(--primary);
}

.btn-back {
    position: absolute;
    top: 20px;
    left: 20px;
    width: 50px;
    height: 50px;
    padding: 0;
    border-radius: 50%;
    background: rgba(0,0,0,0.6);
    color: white;
    border: 2px solid var(--glass-border);
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* --- HUD & Game UI --- */
#game-ui {
    position: absolute;
    top: 0; 
    left: 0;
    width: 100%; 
    height: 100%;
    pointer-events: none;
    z-index: 10;
    display: none;
}

.hud-panel {
    position: absolute;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    padding: 12px 20px;
    border-radius: 12px;
    color: #fff;
    border: 1px solid rgba(255,255,255,0.08);
    /* Performance */
    will-change: transform;
    transform: translateZ(0);
}

#leaderboard {
    top: 20px;
    right: 20px;
    text-align: right;
    min-width: 150px;
    max-width: 200px;
}

#leaderboard h3 {
    font-size: 0.9rem;
    color: var(--primary);
    text-transform: uppercase;
    margin-bottom: 5px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    padding-bottom: 5px;
}

#lb-list {
    list-style: none;
    padding: 0;
    font-size: 0.85rem;
    margin-top: 5px;
}

#lb-list li {
    padding: 2px 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

#score-board {
    bottom: 20px;
    left: 20px;
    font-size: 1.5rem;
    font-weight: bold;
}

#score-board span { 
    color: var(--primary); 
    text-shadow: 0 0 10px var(--primary);
}

#turbo-hint {
    position: absolute;
    bottom: 30px;
    right: 30px;
    color: rgba(255,255,255,0.4);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    display: none;
    padding: 8px 16px;
    background: rgba(0,0,0,0.3);
    border-radius: 8px;
    backdrop-filter: blur(4px);
    border: 1px solid rgba(255,255,255,0.05);
    animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 0.4; }
    50% { opacity: 0.7; }
}

/* --- Mobile Boost Indicator --- */
#boost-indicator {
    position: absolute;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%);
    display: none;
    width: 200px;
    height: 8px;
    background: rgba(0,0,0,0.5);
    border-radius: 10px;
    overflow: hidden;
    border: 1px solid rgba(255,255,255,0.1);
}

#boost-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--primary-dark), var(--primary));
    border-radius: 10px;
    transition: width 0.1s ease-out;
    box-shadow: 0 0 10px var(--primary);
}

/* --- Game Over Screen --- */
#game-over-screen {
    position: absolute;
    top: 0; 
    left: 0; 
    width: 100%; 
    height: 100%;
    background: rgba(13, 13, 21, 0.95);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    pointer-events: auto;
    z-index: 50;
    animation: zoomIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes zoomIn {
    from { transform: scale(0.8); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

#game-over-screen h1 {
    font-size: 4rem;
    color: var(--danger);
    text-shadow: 0 0 20px var(--danger);
    margin-bottom: 0.5rem;
    animation: shake 0.5s;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-10px); }
    75% { transform: translateX(10px); }
}

/* --- Shop Grid --- */
.shop-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    max-height: 45vh;
    overflow-y: auto;
    margin-bottom: 1.5rem;
    padding-right: 5px;
}

.shop-grid::-webkit-scrollbar { width: 5px; }
.shop-grid::-webkit-scrollbar-thumb { 
    background: var(--primary); 
    border-radius: 5px; 
}
.shop-grid::-webkit-scrollbar-track { 
    background: rgba(0,0,0,0.2); 
}

.skin-item {
    background: rgba(255,255,255,0.05);
    border: 2px solid transparent;
    border-radius: 12px;
    padding: 10px;
    cursor: pointer;
    transition: all 0.2s;
    position: relative;
    overflow: hidden;
}

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

.skin-item.selected { 
    border-color: var(--primary); 
    box-shadow: 0 0 15px rgba(0, 255, 136, 0.3); 
}

.skin-item.locked { 
    opacity: 0.4; 
    filter: grayscale(0.8); 
    cursor: not-allowed;
}

.skin-preview {
    height: 45px;
    width: 45px;
    border-radius: 50%;
    margin: 0 auto 8px auto;
    border: 2px solid rgba(255,255,255,0.2);
}

.stats-bar {
    display: flex;
    justify-content: space-between;
    width: 100%;
    background: rgba(0,0,0,0.3);
    padding: 10px 15px;
    border-radius: 8px;
    margin-bottom: 20px;
    font-weight: bold;
}

.stat-value { 
    color: var(--primary); 
}

/* --- Loading Indicator --- */
@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

.loading {
    animation: spin 1s linear infinite;
}

/* --- Mobile / Responsive --- */
@media (min-width: 768px) {
    #turbo-hint { display: block; }
    #game-canvas { cursor: crosshair; }
}

@media (max-width: 600px) {
    .card { 
        padding: 1.5rem; 
        width: 95%; 
    }
    
    h1 { 
        font-size: 2.5rem; 
    }
    
    .btn { 
        padding: 12px; 
        font-size: 1rem; 
    }
    
    .shop-grid { 
        grid-template-columns: repeat(2, 1fr); 
        max-height: 40vh; 
    }
    
    #leaderboard {
        top: 10px;
        right: 10px;
        padding: 8px 12px;
        font-size: 0.8rem;
        max-width: 140px;
    }
    
    #leaderboard h3 {
        font-size: 0.75rem;
    }
    
    #lb-list {
        font-size: 0.75rem;
    }
    
    #score-board {
        bottom: 10px;
        left: 10px;
        font-size: 1.2rem;
        padding: 8px 12px;
    }
    
    #game-over-screen h1 {
        font-size: 3rem;
    }
    
    #turbo-hint {
        bottom: 100px;
        right: 20px;
        left: 20px;
        text-align: center;
        font-size: 0.7rem;
        display: block;
    }
}

/* --- Performance Optimizations --- */
.hud-panel, .card, .btn {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Prevent text selection during gameplay */
#game-canvas, #game-ui {
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

/* iOS specific fixes */
@supports (-webkit-touch-callout: none) {
    body {
        /* Fix iOS bounce */
        position: fixed;
        width: 100%;
        height: 100%;
    }
}