:root {
    --bg-color: #0a0a12;
    --game-bg: #11111a;
    --primary-color: #00ff88;
    /* Neon Green */
    --secondary-color: #ff0055;
    /* Neon Red */
    --text-color: #ffffff;
    --grid-color: rgba(255, 255, 255, 0.05);
    --font-heading: 'Orbitron', sans-serif;
    --font-body: 'Roboto', sans-serif;
}

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

body {
    background-color: var(--bg-color);
    color: var(--text-color);
    font-family: var(--font-body);
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    overflow-x: hidden;
    padding: 20px;
}

.main-wrapper {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    /* Symmetrical flexible layout */
    align-items: center;
    /* Vertically center the whole dashboard */
    gap: 20px;
    width: 100%;
    max-width: 1800px;
    /* Limit ultra-wide screens but keep it relative */
    padding: 0 40px;
}

/* UI Panels */
.side-panel {
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--grid-color);
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(10px);
}

.panel-header {
    background: rgba(255, 255, 255, 0.05);
    padding: 12px;
    font-family: var(--font-heading);
    font-size: 0.9rem;
    color: var(--primary-color);
    letter-spacing: 2px;
    border-bottom: 1px solid var(--grid-color);
    text-align: center;
    text-shadow: 0 0 5px var(--primary-color);
}

/* Stats Panel (Left) */
.stats-panel {
    display: flex;
    flex-direction: column;
    justify-self: start;
    /* Push to the far left */
    width: 250px;
}

.stat-group {
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.stat-card {
    display: flex;
    flex-direction: column;
    gap: 5px;
    padding: 15px;
    background: rgba(255, 255, 255, 0.03);
    border-radius: 4px;
    border-left: 2px solid #333;
}

.stat-card.highlighted {
    border-left-color: var(--primary-color);
}

.stat-label {
    font-size: 0.7rem;
    color: #666;
    font-family: var(--font-heading);
}

.stat-value {
    font-family: var(--font-heading);
    font-size: 1.8rem;
    color: var(--text-color);
}

#score {
    color: white;
}

#high-score {
    color: var(--primary-color);
}

/* Game Container (Center) */
.game-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
}

h1 {
    font-family: var(--font-heading);
    font-size: 2.5rem;
    color: var(--primary-color);
    text-shadow: 0 0 10px var(--primary-color);
    letter-spacing: 4px;
    margin-bottom: 5px;
}

.game-area {
    position: relative;
    box-shadow: 0 0 40px rgba(0, 255, 136, 0.15);
    border: 4px solid #1a1a2e;
    border-radius: 4px;
}

canvas {
    background-color: var(--game-bg);
    display: block;
    background-image: linear-gradient(var(--grid-color) 1px, transparent 1px),
        linear-gradient(90deg, var(--grid-color) 1px, transparent 1px);
    background-size: 20px 20px;
}

/* Overlays */
.overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(5, 5, 10, 0.9);
    backdrop-filter: blur(8px);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    transition: opacity 0.4s ease;
    z-index: 10;
}

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

.overlay h2 {
    font-family: var(--font-heading);
    font-size: 2.8rem;
    margin-bottom: 30px;
    color: var(--text-color);
    text-shadow: 0 0 15px var(--text-color);
}

/* Leaderboard Panel (Right) */
.leaderboard-panel {
    max-height: 520px;
    justify-self: end;
    /* Push to the far right */
    width: 320px;
}

#leaderboard-list {
    padding: 15px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    overflow-y: auto;
}

.leaderboard-entry {
    display: grid;
    grid-template-columns: 35px 1fr 60px;
    align-items: center;
    padding: 10px 12px;
    background: rgba(255, 255, 255, 0.02);
    border-radius: 4px;
    border: 1px solid transparent;
    transition: all 0.2s ease;
}

.leaderboard-entry:hover {
    background: rgba(0, 255, 136, 0.05);
    border-color: rgba(0, 255, 136, 0.1);
    transform: translateX(3px);
}

.leaderboard-entry .rank {
    color: #555;
    font-family: var(--font-heading);
    font-size: 0.8rem;
}

.leaderboard-entry .player-name {
    font-size: 0.9rem;
    color: #ccc;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.leaderboard-entry .player-score {
    color: var(--secondary-color);
    font-family: var(--font-heading);
    font-size: 0.9rem;
    text-align: right;
}

/* Controls & Buttons */
.controls-hint {
    padding: 20px;
    border-top: 1px solid var(--grid-color);
    color: #444;
    font-size: 0.75rem;
    text-align: center;
    font-family: var(--font-heading);
}

button {
    background: transparent;
    border: 1px solid var(--primary-color);
    color: var(--primary-color);
    padding: 12px 25px;
    font-family: var(--font-heading);
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.2s ease;
    text-transform: uppercase;
    letter-spacing: 2px;
}

button:hover {
    background: var(--primary-color);
    color: var(--bg-color);
    box-shadow: 0 0 20px rgba(0, 255, 136, 0.4);
}

button.secondary {
    border-color: #666;
    color: #666;
}

button.secondary:hover {
    background: #666;
    color: white;
    box-shadow: 0 0 10px rgba(255, 255, 255, 0.1);
}

.save-score-container {
    width: 250px;
    margin-bottom: 20px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

#player-name {
    background: #000;
    border: 1px solid #333;
    color: #00ff88;
    padding: 10px;
    font-family: var(--font-heading);
    text-align: center;
    width: 100%;
    outline: none;
}

.loading {
    text-align: center;
    color: #444;
    padding: 40px 20px;
    font-size: 0.8rem;
    font-family: var(--font-heading);
}

/* Animations */
.glitch {
    color: var(--secondary-color) !important;
    text-shadow: 2px 2px #00ffff, -2px -2px #ff00ff !important;
}

/* User Profile */
.user-profile {
    display: flex;
    flex-direction: column;
    /* Stack vertically */
    gap: 15px;
    padding: 20px;
    background: rgba(0, 255, 136, 0.05);
    border-bottom: 1px solid var(--grid-color);
}

.user-profile.hidden {
    display: none;
}

.user-top {
    display: flex;
    align-items: center;
    gap: 15px;
}

#user-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 1px solid var(--primary-color);
}

.user-details {
    display: flex;
    flex-direction: column;
    flex-grow: 1;
}

#display-name {
    font-size: 0.9rem;
    font-weight: bold;
    color: white;
}

#logout-btn {
    background: transparent;
    border: 1px solid var(--secondary-color);
    color: var(--secondary-color);
    font-size: 0.7rem;
    cursor: pointer;
    padding: 8px 12px;
    border-radius: 4px;
    transition: all 0.2s;
    width: 100%;
    /* Full width in the column */
    font-family: var(--font-heading);
    letter-spacing: 2px;
    box-shadow: 0 0 5px rgba(255, 0, 85, 0.2);
}

#logout-btn:hover {
    background: var(--secondary-color);
    color: white;
    box-shadow: 0 0 10px var(--secondary-color);
}

/* Auth Box */
.auth-box {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
    margin-top: 20px;
}

.auth-box.hidden {
    display: none;
}

.auth-box p {
    font-family: var(--font-heading);
    font-size: 0.8rem;
    color: #666;
    letter-spacing: 2px;
}

.login-btn {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 240px;
    padding: 10px 20px;
    font-size: 0.9rem;
    background: rgba(255, 255, 255, 0.05);
    border-color: #333;
    pointer-events: auto;
}

.login-btn img {
    width: 18px;
    height: 18px;
}

.login-btn.google:hover {
    background: #4285F4;
    border-color: #4285F4;
    color: white;
}

.save-status {
    font-size: 0.8rem;
    font-family: var(--font-heading);
    margin: 15px 0;
    letter-spacing: 1px;
    height: 1.2rem;
    /* Keep space even when empty */
}

/* Mobile D-Pad */
.mobile-controls {
    display: none;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    margin-top: 30px;
    margin-bottom: 20px;
    z-index: 20;
}

.middle-row {
    display: flex;
    gap: 10px;
}

.control-btn {
    width: 70px;
    height: 70px;
    background: rgba(255, 255, 255, 0.05);
    border: 2px solid var(--primary-color);
    color: var(--primary-color);
    border-radius: 50%;
    font-size: 1.8rem;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    transition: all 0.1s;
    box-shadow: 0 0 10px rgba(0, 255, 136, 0.1);
}

.control-btn:active {
    background: var(--primary-color);
    color: var(--bg-color);
    transform: scale(0.9);
    box-shadow: 0 0 20px var(--primary-color);
}

/* Mobile HUD & Modal (hidden on desktop) */
.mobile-hud {
    display: none;
}

.mobile-modal {
    display: none;
}

.mobile-top5 {
    display: none;
}

@media (max-width: 768px) {
    body {
        padding: 0;
        overflow: hidden;
        /* Prevent page scroll while swiping */
        align-items: flex-start;
    }

    .main-wrapper {
        grid-template-columns: 1fr;
        justify-items: center;
        gap: 0;
        padding: 0;
        height: 100vh;
    }

    /* Hide side panels on small mobile screens */
    .stats-panel,
    .leaderboard-panel {
        display: none;
    }

    .game-container {
        width: 100vw;
        height: 100vh;
        gap: 0;
        justify-content: center;
    }

    header {
        display: none;
        /* Hide title to save space */
    }

    .game-area {
        width: 100vw;
        height: 100vw;
        /* Square canvas area */
        max-height: 100vh;
        border: none;
        box-shadow: none;
    }

    canvas {
        width: 100% !important;
        height: 100% !important;
    }

    /* Mobile HUD */
    .mobile-hud {
        display: flex;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        height: 48px;
        background: rgba(10, 10, 18, 0.92);
        border-bottom: 1px solid var(--grid-color);
        backdrop-filter: blur(10px);
        align-items: center;
        justify-content: space-between;
        padding: 0 16px;
        z-index: 100;
    }

    .mobile-hud-score {
        display: flex;
        flex-direction: column;
        line-height: 1.1;
    }

    .mobile-hud-label {
        font-size: 0.55rem;
        font-family: var(--font-heading);
        color: #555;
        letter-spacing: 2px;
    }

    #mobile-score {
        font-family: var(--font-heading);
        font-size: 1.1rem;
        color: var(--primary-color);
        text-shadow: 0 0 8px var(--primary-color);
    }

    .mobile-hud-actions {
        display: flex;
        gap: 8px;
    }

    .mobile-hud-actions button {
        background: transparent;
        border: 1px solid #333;
        color: #aaa;
        font-size: 1.2rem;
        width: 38px;
        height: 38px;
        border-radius: 50%;
        padding: 0;
        display: flex;
        align-items: center;
        justify-content: center;
        letter-spacing: 0;
    }

    .mobile-hud-actions button:hover {
        background: rgba(255, 255, 255, 0.08);
        color: white;
        box-shadow: none;
    }

    /* Push canvas down below HUD */
    .game-container {
        padding-top: 48px;
    }

    /* Mobile Modal */
    .mobile-modal {
        position: fixed;
        inset: 0;
        background: rgba(5, 5, 15, 0.96);
        backdrop-filter: blur(12px);
        z-index: 200;
        display: flex;
        align-items: flex-end;
        justify-content: center;
    }

    .mobile-modal.hidden {
        display: none;
    }

    .mobile-modal-content {
        width: 100%;
        max-height: 80vh;
        background: #0d0d1a;
        border-top: 1px solid var(--grid-color);
        border-radius: 16px 16px 0 0;
        padding: 20px;
        overflow-y: auto;
    }

    .mobile-modal-header {
        display: flex;
        justify-content: space-between;
        align-items: center;
        font-family: var(--font-heading);
        font-size: 0.9rem;
        color: var(--primary-color);
        letter-spacing: 2px;
        margin-bottom: 16px;
        padding-bottom: 12px;
        border-bottom: 1px solid var(--grid-color);
    }

    .mobile-modal-header button {
        background: transparent;
        border: none;
        color: #666;
        font-size: 1.2rem;
        padding: 0;
        width: auto;
        letter-spacing: 0;
    }

    .mobile-leaderboard-list {
        display: flex;
        flex-direction: column;
        gap: 10px;
    }

    /* Top 5 inside game-over */
    .mobile-top5 {
        display: block;
        width: 100%;
        margin: 12px 0;
        text-align: left;
        font-size: 0.8rem;
        font-family: var(--font-heading);
        color: #666;
        letter-spacing: 1px;
        border-top: 1px solid #1a1a2e;
        padding-top: 12px;
    }

    .mobile-top5 .top5-title {
        color: var(--primary-color);
        font-size: 0.65rem;
        margin-bottom: 8px;
        letter-spacing: 2px;
    }

    .mobile-top5 .top5-entry {
        display: flex;
        justify-content: space-between;
        padding: 5px 0;
        border-bottom: 1px solid #111;
        color: #aaa;
    }

    .mobile-top5 .top5-entry .top5-score {
        color: var(--secondary-color);
    }

}

@media (min-width: 769px) and (max-width: 1100px) {
    .main-wrapper {
        grid-template-columns: 1fr;
        justify-items: center;
    }

    .stats-panel,
    .leaderboard-panel {
        width: 450px;
    }
}