/* --- GAME UI & PERFORMANCE --- */
canvas {
    display: block;
    position: fixed;
    top: 0;
    left: 0;
    z-index: 1;
}

#ui {
    position: fixed;
    top: 20px;
    left: 20px;
    z-index: 1000;
    /* Much higher to be on top */
    pointer-events: none;
    display: none;
}

.length-badge {
    background: var(--glass-bg);
    backdrop-filter: blur(5px);
    border: 1px dashed var(--neon-cyan);
    padding: 8px 15px;
    /* Reduced padding */
    border-radius: 12px;
    font-family: var(--font-heading);
    font-size: 14px;
    /* Reduced font size from 18px */
    box-shadow: 0 0 15px rgba(0, 242, 254, 0.2);
    display: flex;
    align-items: center;
    gap: 10px;
}

#leaderboard {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 1000;
    /* Same high level */
    background: var(--glass-bg);
    backdrop-filter: blur(10px);
    border: 1px solid var(--glass-border);
    padding: 15px;
    border-radius: 20px;
    width: 280px;
    display: none;
    max-height: 80vh;
    overflow-y: hidden;
    box-shadow: 0 0 30px rgba(0, 0, 0, 0.5);
}

.leader-title {
    color: #ffcc00;
    font-family: var(--font-heading);
    font-size: 14px;
    display: block;
    margin-bottom: 12px;
    text-align: center;
    letter-spacing: 2px;
    text-transform: uppercase;
}

.leader-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.leader-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 12px;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid transparent;
    transition: 0.3s;
}

.leader-item.rank-1 {
    background: rgba(255, 215, 0, 0.15);
    border-color: rgba(255, 215, 0, 0.4);
    transform: scale(1.05);
}

.leader-item.rank-1 span:first-child {
    color: #ffd700;
    font-weight: bold;
    font-size: 16px;
}

.leader-item.rank-2 {
    background: rgba(192, 192, 192, 0.15);
    border-color: rgba(192, 192, 192, 0.4);
    transform: scale(1.02);
}

.leader-item.rank-2 span:first-child {
    color: #c0c0c0;
    font-weight: bold;
    font-size: 15px;
}

.leader-item.rank-3 {
    background: rgba(205, 127, 50, 0.15);
    border-color: rgba(205, 127, 50, 0.4);
}

.leader-item.rank-3 span:first-child {
    color: #cd7f32;
    font-weight: bold;
    font-size: 14px;
}

.leader-item.is-player {
    border-left: 4px solid var(--neon-cyan);
    background: rgba(0, 242, 254, 0.1);
}

.leader-name {
    flex: 1;
    margin: 0 10px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 12px;
}

.leader-score {
    font-family: var(--font-heading);
    color: var(--neon-cyan);
    font-size: 12px;
}

.leader-toggle {
    display: none;
    text-align: center;
    cursor: pointer;
    font-size: 14px;
    color: var(--neon-cyan);
    margin-top: 10px;
    padding: 5px;
    transition: 0.3s;
    user-select: none;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
}

/* --- PAUSE & GAME OVER --- */
#pauseMenu,
#gameOver {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 200;
    background: rgba(10, 10, 18, 0.7);
    backdrop-filter: blur(8px);
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 20px;
}

.menu-panel {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    padding: 50px;
    border-radius: 30px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    box-shadow: 0 0 50px rgba(0, 0, 0, 0.5);
}

.pause-title {
    font-family: var(--font-heading);
    font-size: 32px;
    color: var(--neon-cyan);
    margin-bottom: 20px;
    text-shadow: 0 0 10px var(--neon-cyan);
}

#gameOver .pause-title {
    color: var(--neon-pink);
    text-shadow: 0 0 10px var(--neon-pink);
    font-size: 38px;
    line-height: 1.1;
    text-align: center;
}


/* --- MOBILE CONTROLS --- */
#mobileControls {
    position: fixed;
    bottom: 30px;
    left: 0;
    width: 100%;
    display: none;
    justify-content: space-between;
    padding: 0 30px;
    z-index: 1000;
    /* High level for joystick/boost */
    pointer-events: none;
}

.joystick-container {
    width: 120px;
    height: 120px;
    background: rgba(0, 242, 254, 0.05);
    border: 2px solid rgba(0, 242, 254, 0.3);
    border-radius: 50%;
    position: relative;
    pointer-events: auto;
    touch-action: none;
    box-shadow: 0 0 20px rgba(0, 242, 254, 0.1);
}

.joystick-stick {
    width: 50px;
    height: 50px;
    background: var(--neon-cyan);
    border-radius: 50%;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    box-shadow: 0 0 15px var(--neon-cyan);
    pointer-events: none;
}

.m-btn {
    pointer-events: auto;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--font-heading);
    cursor: pointer;
    transition: 0.3s;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.m-turbo {
    background: rgba(255, 0, 127, 0.1);
    border-color: var(--neon-pink);
    color: var(--neon-pink);
    width: 85px;
    height: 85px;
    font-size: 14px;
    font-weight: bold;
}

.m-menu {
    position: fixed;
    top: 15px;
    left: 50%;
    transform: translateX(-50%) !important;
    width: 80px;
    height: 34px;
    border-radius: 17px;
    font-size: 11px;
    font-weight: bold;
    border: 1px solid rgba(0, 242, 254, 0.4);
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(5px);
    color: white;
    z-index: 101;
    pointer-events: auto;
    display: none;
    align-items: center;
    justify-content: center;
}


@media (max-width: 900px) {
    #ui {
        top: 15px;
        left: 10px;
    }

    .length-badge {
        padding: 4px 8px;
        font-size: 10px;
        gap: 5px;
    }

    .m-menu {
        display: flex;
        top: 15px;
    }

    #leaderboard {
        top: 15px;
        right: 10px;
        width: 120px;
        padding: 6px;
    }

    .leader-title,
    .leader-name,
    .leader-score {
        font-size: 8px;
    }

    #leaderboard:not(.expanded) .leader-item:nth-child(n+3) {
        display: none;
    }

    .leader-toggle {
        display: block;
        padding: 2px;
        font-size: 10px;
    }

    #gameOver .pause-title {
        font-size: 34px;
    }

    .menu-panel {
        padding: 30px;
        width: 90%;
    }
}