:root {
    --bg-color: #0a0a14;
    --text-color: #ffffff;
    --accent-red: #ff4757;
    --accent-blue: #1e90ff;
    --accent-yellow: #ffa502;
    --accent-green: #2ed573;
    --glass-bg: rgba(10, 10, 20, 0.85);
    --glass-border: rgba(255, 255, 255, 0.08);
}

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

body {
    background-color: var(--bg-color);
    color: var(--text-color);
    font-family: 'Outfit', sans-serif;
    overflow: hidden;
    height: 100vh;
    width: 100vw;
    display: flex;
    justify-content: center;
    align-items: center;
}

#game-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
}

/* ── UI LAYER ── */
#ui-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 10;
    pointer-events: none;
    display: flex;
    justify-content: center;
    align-items: center;
}

.hidden {
    display: none !important;
}

/* ── WAITING ROOM ── */
#waiting-room,
#leaderboard {
    background: var(--glass-bg);
    padding: 50px 60px;
    border-radius: 24px;
    border: 1px solid var(--glass-border);
    text-align: center;
    pointer-events: auto;
    backdrop-filter: blur(20px);
    box-shadow: 0 25px 60px rgba(0, 0, 0, 0.6);
}

#waiting-room h1 {
    font-size: 3.5rem;
    margin-bottom: 10px;
    letter-spacing: 6px;
    background: linear-gradient(135deg, #ff4757, #ffa502, #2ed573, #1e90ff);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    animation: shimmer 3s ease-in-out infinite;
}

@keyframes shimmer {

    0%,
    100% {
        filter: brightness(1);
    }

    50% {
        filter: brightness(1.4);
    }
}

#waiting-room .subtitle {
    font-size: 1.1rem;
    color: rgba(255, 255, 255, 0.4);
    margin-bottom: 30px;
    letter-spacing: 2px;
}

.qr-grid {
    display: flex;
    gap: 20px;
    margin-bottom: 30px;
}

.player-slot {
    background: rgba(255, 255, 255, 0.03);
    padding: 20px 22px;
    border-radius: 16px;
    border: 1px solid rgba(255, 255, 255, 0.06);
    transition: all 0.4s cubic-bezier(0.23, 1, 0.32, 1);
    position: relative;
    overflow: hidden;
}

.player-slot::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 3px;
    background: currentColor;
    opacity: 0.3;
    transition: opacity 0.4s;
}

.player-slot.connected {
    background: rgba(46, 213, 115, 0.08);
    border-color: rgba(46, 213, 115, 0.3);
    box-shadow: 0 0 30px rgba(46, 213, 115, 0.15);
    transform: translateY(-4px);
}

.player-slot.connected::before {
    opacity: 1;
    background: #2ed573;
}

.player-slot.connected .qr-code {
    opacity: 0.15;
    filter: blur(2px);
}

.player-slot h2 {
    margin-bottom: 12px;
    font-size: 1.4rem;
    font-weight: 900;
    letter-spacing: 2px;
}

.qr-code {
    background: white;
    padding: 8px;
    border-radius: 10px;
    width: 146px;
    height: 146px;
    margin: 0 auto;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: all 0.4s;
}

.qr-code img {
    width: 130px;
    height: 130px;
}

.status {
    margin-top: 12px;
    font-weight: 700;
    font-size: 1rem;
    letter-spacing: 1px;
}

.player-slot.connected .status {
    color: #2ed573;
    text-shadow: 0 0 10px rgba(46, 213, 115, 0.5);
}

#start-btn,
#restart-btn {
    background: linear-gradient(135deg, #ff4757, #ffa502);
    color: white;
    font-family: 'Outfit', sans-serif;
    font-size: 1.5rem;
    font-weight: 900;
    padding: 16px 50px;
    border: none;
    border-radius: 50px;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.23, 1, 0.32, 1);
    pointer-events: auto;
    letter-spacing: 3px;
    box-shadow: 0 8px 30px rgba(255, 71, 87, 0.3);
}

#start-btn:hover,
#restart-btn:hover {
    transform: scale(1.08) translateY(-2px);
    box-shadow: 0 12px 40px rgba(255, 71, 87, 0.5);
}

.connecting-text {
    font-size: 1.1rem;
    color: #ffa502;
    animation: blink 1.5s infinite;
    letter-spacing: 1px;
}

@keyframes blink {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.4;
    }
}

/* ── COUNTDOWN ── */
#countdown {
    font-size: 16rem;
    font-weight: 900;
    color: white;
    text-shadow:
        0 0 40px rgba(255, 255, 255, 0.5),
        0 0 80px rgba(255, 71, 87, 0.3);
    animation: countPop 1s ease-out;
}

@keyframes countPop {
    0% {
        transform: scale(0.3);
        opacity: 0;
        filter: blur(10px);
    }

    40% {
        transform: scale(1.3);
        opacity: 1;
        filter: blur(0);
    }

    100% {
        transform: scale(1);
        opacity: 0;
    }
}

/* ── HUD ── */
#hud {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 60px;
    background: transparent;
    display: flex;
    gap: 12px;
    padding: 0 24px;
    align-items: center;
    pointer-events: none;
    z-index: 100;
}

.hud-player {
    background: rgba(10, 10, 20, 0.75);
    border: 1px solid rgba(255, 255, 255, 0.12);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    padding: 6px 14px;
    border-radius: 10px;
    font-size: 0.9rem;
    font-weight: 800;
    letter-spacing: 1px;
    display: flex;
    align-items: center;
    gap: 10px;
    white-space: nowrap;
    transition: all 0.3s ease;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35), inset 0 1px 1px rgba(255, 255, 255, 0.06);
}

.hud-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
    box-shadow: 0 0 12px currentColor;
    border: 2px solid rgba(255, 255, 255, 0.2);
}

.hud-lap {
    opacity: 0.5;
    font-weight: 500;
    font-size: 0.8rem;
    margin-left: 4px;
}

#race-timer {
    margin-left: auto;
    font-family: 'Outfit', sans-serif;
    font-size: 1.6rem;
    font-weight: 900;
    font-variant-numeric: tabular-nums;
    letter-spacing: 2px;
    color: #ffa502;
    text-shadow: 0 0 15px rgba(255, 165, 2, 0.4);
    background: rgba(10, 10, 20, 0.75);
    border: 1px solid rgba(255, 255, 255, 0.12);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    padding: 6px 18px;
    border-radius: 10px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35), inset 0 1px 1px rgba(255, 255, 255, 0.06);
}

/* ── LEADERBOARD ── */
#leaderboard h1 {
    font-size: 3rem;
    margin-bottom: 30px;
    letter-spacing: 4px;
    background: linear-gradient(135deg, #ffa502, #ff4757);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

#leaderboard-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 30px;
}

.lb-entry {
    font-size: 1.8rem;
    font-weight: 700;
    padding: 14px 24px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 14px;
    display: flex;
    align-items: center;
    gap: 15px;
    width: 480px;
    animation: slideIn 0.6s ease-out backwards;
    backdrop-filter: blur(5px);
}

@keyframes slideIn {
    from {
        transform: translateX(-40px);
        opacity: 0;
    }

    to {
        transform: translateX(0);
        opacity: 1;
    }
}

.lb-medal {
    font-size: 2.2rem;
}

.lb-name {
    flex: 1;
    letter-spacing: 2px;
}

.lb-time {
    font-variant-numeric: tabular-nums;
    opacity: 0.7;
    font-size: 1.4rem;
}