:root {
    --primary: #FF5757;
    /* Bulli Red */
    --secondary: #FFFFFF;
    /* Bulli White */
    --accent: #2D3436;
    /* Dark Asphalt */
    --glass: rgba(255, 255, 255, 0.1);
    --glass-border: rgba(255, 255, 255, 0.2);
    --text: #ffffff;
    --font-main: 'Outfit', sans-serif;
}

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

body {
    overflow: hidden;
    background-color: #1a1a1a;
    font-family: var(--font-main);
    color: var(--text);
}

canvas {
    display: block;
    width: 100vw;
    height: 100vh;
}

/* Loading Screen */
#loading-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #111;
    z-index: 9999;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: opacity 0.5s ease;
}

.loader {
    text-align: center;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: var(--primary);
    animation: spin 1s ease-in-out infinite;
    margin: 0 auto 1rem;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* Splash Screen */
#splash-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, #1a1a1a 0%, #2d3436 100%);
    z-index: 9000;
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 1;
    /* Transition only applied when hiding */
}

#splash-screen.hidden {
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.5s ease;
}

.splash-content {
    text-align: center;
    background: rgba(255, 255, 255, 0.05);
    padding: 3rem;
    border-radius: 20px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
    box-shadow: 0 20px 50px rgba(0,0,0,0.5);
    max-width: 90%;
    width: 400px;
}

.splash-content h1 {
    font-size: 3rem;
    margin-bottom: 2rem;
    background: linear-gradient(45deg, var(--primary), #FF8E53);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    font-weight: 800;
    letter-spacing: -1px;
}

.input-group {
    margin-bottom: 2rem;
}

#splash-name-input {
    width: 100%;
    background: rgba(0, 0, 0, 0.3);
    border: 2px solid rgba(255, 255, 255, 0.1);
    border-radius: 50px;
    padding: 1rem 1.5rem;
    color: white;
    font-size: 1.1rem;
    font-family: var(--font-main);
    text-align: center;
    transition: all 0.3s ease;
    outline: none;
}

#splash-name-input:focus {
    border-color: var(--primary);
    background: rgba(0, 0, 0, 0.5);
}

#start-btn {
    background: var(--primary);
    color: white;
    border: none;
    padding: 1rem 2.5rem;
    font-size: 1.2rem;
    font-weight: 700;
    border-radius: 50px;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 10px 20px rgba(255, 87, 87, 0.3);
    font-family: var(--font-main);
    letter-spacing: 1px;
}

#start-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 15px 30px rgba(255, 87, 87, 0.4);
    filter: brightness(1.1);
}

#start-btn:active {
    transform: translateY(1px);
}

/* Powerup Panel */
#powerup-panel {
    position: fixed;
    top: 2rem;
    left: 2rem;
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
    pointer-events: none;
    z-index: 20;
}

.powerup-indicator {
    background: var(--glass);
    backdrop-filter: blur(10px);
    border: 1px solid var(--glass-border);
    border-radius: 50px; /* Pill shape */
    padding: 0.5rem 1rem;
    display: flex;
    align-items: center;
    gap: 0.8rem;
    color: white;
    font-weight: 600;
    font-size: 0.9rem;
    animation: slideIn 0.3s ease-out;
    box-shadow: 0 4px 15px rgba(0,0,0,0.1);
}

.powerup-icon {
    font-size: 1.2rem;
}

.powerup-bar-bg {
    width: 80px;
    height: 6px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 3px;
    overflow: hidden;
}

.powerup-bar-fill {
    height: 100%;
    background: white;
    transform-origin: left;
    /* transition: width 0.1s linear; */ /* Will use transform scaleX for performance */
    border-radius: 3px;
}

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

/* UI Overlay */
#ui-overlay {
    position: fixed;
    bottom: 2rem;
    left: 2rem;
    pointer-events: none;
    z-index: 10;
}

/* Score Display */
#score-container {
    position: fixed;
    top: 1rem;
    left: 50%;
    transform: translateX(-50%);
    background: var(--glass);
    backdrop-filter: blur(10px);
    border: 1px solid var(--glass-border);
    padding: 0.5rem 1.5rem;
    border-radius: 50px;
    display: flex;
    align-items: center;
    gap: 0.8rem;
    z-index: 100;
}

.score-label {
    font-size: 0.8rem;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.6);
    letter-spacing: 1px;
}

#score-display {
    font-size: 1.5rem;
    font-weight: 700;
    color: #FFD700;
    text-shadow: 0 0 10px rgba(255, 215, 0, 0.5);
}

.controls-hint {
    background: var(--glass);
    backdrop-filter: blur(10px);
    border: 1px solid var(--glass-border);
    padding: 1rem;
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
}

.row {
    display: flex;
    gap: 0.5rem;
}

.key {
    width: 40px;
    height: 40px;
    background: rgba(0, 0, 0, 0.5);
    border-radius: 8px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-weight: 700;
    border-bottom: 3px solid rgba(255, 255, 255, 0.2);
    color: white;
}

/* Interaction Prompt */
#interaction-prompt {
    position: fixed;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%);
    background: var(--primary);
    color: white;
    padding: 1rem 2rem;
    border-radius: 50px;
    font-weight: 500;
    box-shadow: 0 10px 30px rgba(255, 87, 87, 0.4);
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.27), opacity 0.3s;
    z-index: 20;
}

#interaction-prompt.hidden {
    transform: translate(-50%, 100px);
    opacity: 0;
}

.key-small {
    background: rgba(0, 0, 0, 0.2);
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
    font-weight: 700;
    margin: 0 0.2rem;
}

/* Modal */
#modal-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 100;
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 1;
    transition: opacity 0.3s ease;
}

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

.modal-backdrop {
    position: absolute;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(5px);
}

.modal-content {
    position: relative;
    width: 90%;
    max-width: 600px;
    background: rgba(30, 30, 30, 0.95);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 20px;
    padding: 2rem;
    transform: scale(1);
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.27);
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
}

#modal-container.hidden .modal-content {
    transform: scale(0.9);
}

.close-btn {
    position: absolute;
    top: 1rem;
    right: 1rem;
    background: none;
    border: none;
    color: rgba(255, 255, 255, 0.5);
    font-size: 2rem;
    cursor: pointer;
    transition: color 0.2s;
}

.close-btn:hover {
    color: white;
}

#modal-title {
    font-size: 2rem;
    margin-bottom: 1rem;
    background: linear-gradient(45deg, var(--primary), #FF8E53);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

#modal-body {
    line-height: 1.6;
    color: rgba(255, 255, 255, 0.8);
}

/* Nametags */
.nametag {
    position: absolute;
    top: 0;
    left: 0;
    background: rgba(0, 0, 0, 0.6);
    color: white;
    padding: 0.2rem 0.6rem;
    border-radius: 12px;
    font-size: 0.9rem;
    font-weight: 500;
    pointer-events: none;
    transform: translate(-50%, -100%);
    white-space: nowrap;
    opacity: 0.8;
}

.nametag.local {
    background: var(--primary);
    opacity: 1;
}

/* Player List / Scoreboard */
#player-list {
    position: fixed;
    top: 2rem;
    right: 2rem;
    background: var(--glass);
    backdrop-filter: blur(10px);
    border: 1px solid var(--glass-border);
    padding: 1rem;
    border-radius: 12px;
    z-index: 10;
    min-width: 220px;
    pointer-events: auto;
}

#player-list h3 {
    margin-bottom: 0.5rem;
    font-size: 1.1rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    padding-bottom: 0.5rem;
}

#scoreboard-list {
    list-style: none;
    max-height: 300px;
    overflow-y: auto;
}

.scoreboard-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.3rem 0.2rem;
    border-radius: 4px;
    font-size: 0.85rem;
}

.scoreboard-row.me {
    background: rgba(255, 87, 87, 0.2);
}

.scoreboard-row .rank {
    width: 20px;
    text-align: center;
    font-weight: 700;
    color: rgba(255, 255, 255, 0.5);
}

.scoreboard-row.me .rank {
    color: var(--primary);
}

.player-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    display: inline-block;
    flex-shrink: 0;
}

.player-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.player-score {
    font-weight: 700;
    color: #FFD700;
    min-width: 35px;
    text-align: right;
}

/* Name Change UI */
.name-change {
    margin-top: 0.8rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    padding-top: 0.8rem;
}

.name-toggle-btn {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    width: 28px;
    height: 28px;
    color: rgba(255, 255, 255, 0.7);
    cursor: pointer;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.name-toggle-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    color: white;
}

.name-form {
    display: flex;
    gap: 0.4rem;
    flex: 1;
    overflow: hidden;
    transition: all 0.25s ease;
}

.name-form.hidden {
    max-width: 0;
    opacity: 0;
    pointer-events: none;
}

#name-input {
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 4px;
    color: white;
    padding: 0.3rem 0.5rem;
    font-size: 0.8rem;
    flex: 1;
    min-width: 0;
    outline: none;
    user-select: auto;
}

#name-input:focus {
    border-color: var(--primary);
}

#name-submit {
    background: var(--primary);
    border: none;
    border-radius: 4px;
    color: white;
    padding: 0.3rem 0.6rem;
    cursor: pointer;
    font-size: 0.8rem;
    font-weight: 700;
}

#name-submit:hover {
    filter: brightness(1.1);
}
/* Mobile Controls */
#mobile-controls {
    display: none; /* Hidden by default, shown via media query */
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 50;
    /* Safe area for notched phones */
    padding: env(safe-area-inset-top, 0) env(safe-area-inset-right, 0) env(safe-area-inset-bottom, 0) env(safe-area-inset-left, 0);
}

/* Joystick Zones */
.joystick-zone {
    position: absolute;
    bottom: max(20px, env(safe-area-inset-bottom, 20px));
    pointer-events: auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.joystick-zone.left {
    left: max(20px, env(safe-area-inset-left, 20px));
}

.joystick-zone.right {
    right: max(20px, env(safe-area-inset-right, 20px));
}

.joystick-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.joystick-base {
    width: 140px;
    height: 140px;
    background: rgba(0, 0, 0, 0.3);
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    backdrop-filter: blur(5px);
    position: relative;
}

.joystick-base.small {
    width: 90px;
    height: 90px;
}

.joystick-stick {
    width: 60px;
    height: 60px;
    background: radial-gradient(circle at 30% 30%, rgba(255, 255, 255, 0.4), rgba(255, 87, 87, 0.8));
    border: 2px solid rgba(255, 255, 255, 0.5);
    border-radius: 50%;
    position: absolute;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
    transition: transform 0.05s ease-out;
}

.joystick-stick.small {
    width: 40px;
    height: 40px;
}

.joystick-label {
    font-size: 0.7rem;
    color: rgba(255, 255, 255, 0.6);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
}

/* Action Buttons */
.action-buttons {
    position: absolute;
    right: max(20px, env(safe-area-inset-right, 20px));
    bottom: calc(180px + env(safe-area-inset-bottom, 0px));
    display: flex;
    flex-direction: column;
    gap: 15px;
    pointer-events: auto;
}

.control-btn {
    background: rgba(0, 0, 0, 0.4);
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    color: white;
    display: flex;
    justify-content: center;
    align-items: center;
    backdrop-filter: blur(5px);
    cursor: pointer;
    touch-action: manipulation;
    transition: all 0.1s ease;
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.control-btn:active, .control-btn.active {
    background: rgba(255, 87, 87, 0.7);
    transform: scale(0.92);
    border-color: rgba(255, 255, 255, 0.8);
    box-shadow: 0 0 20px rgba(255, 87, 87, 0.5);
}

.control-btn.action {
    width: 70px;
    height: 70px;
    font-size: 1.8rem;
}

.control-btn.action.honk {
    background: rgba(255, 200, 0, 0.3);
    border-color: rgba(255, 200, 0, 0.5);
}

.control-btn.action.honk:active, .control-btn.action.honk.active {
    background: rgba(255, 200, 0, 0.7);
    box-shadow: 0 0 25px rgba(255, 200, 0, 0.6);
}

.control-btn.action.flip {
    background: rgba(0, 150, 255, 0.3);
    border-color: rgba(0, 150, 255, 0.5);
}

.control-btn.action.flip:active, .control-btn.action.flip.active {
    background: rgba(0, 150, 255, 0.7);
    box-shadow: 0 0 25px rgba(0, 150, 255, 0.6);
}

/* Landscape Mode Tweaks */
@media (max-width: 900px) and (orientation: landscape) {
    .joystick-base {
        width: 100px;
        height: 100px;
    }
    
    .joystick-stick {
        width: 45px;
        height: 45px;
    }
    
    .joystick-base.small {
        width: 65px;
        height: 65px;
    }
    
    .joystick-stick.small {
        width: 30px;
        height: 30px;
    }
    
    .control-btn.action {
        width: 55px;
        height: 55px;
        font-size: 1.3rem;
    }
    
    .action-buttons {
        bottom: calc(120px + env(safe-area-inset-bottom, 0px));
        gap: 8px;
    }
    
    .joystick-zone {
        bottom: max(10px, env(safe-area-inset-bottom, 10px));
    }
    
    .joystick-zone.left {
        left: max(10px, env(safe-area-inset-left, 10px));
    }
    
    .joystick-zone.right {
        right: max(10px, env(safe-area-inset-right, 10px));
    }
    
    #score-container {
        top: 0.5rem;
        padding: 0.3rem 1rem;
    }
    
    #score-display {
        font-size: 1.2rem;
    }
    
    .score-label {
        font-size: 0.7rem;
    }
}

/* Show mobile controls on touch devices */
@media (max-width: 768px), (pointer: coarse) {
    #mobile-controls {
        display: block;
    }

    .controls-hint {
        display: none;
    }

    #player-list {
        top: max(0.5rem, env(safe-area-inset-top, 0.5rem));
        right: max(0.5rem, env(safe-area-inset-right, 0.5rem));
        transform: scale(0.75);
        transform-origin: top right;
        padding: 0.6rem;
        min-width: 150px;
    }
    
    #player-list h3 {
        font-size: 0.9rem;
    }
    
    #score-container {
        top: max(0.5rem, env(safe-area-inset-top, 0.5rem));
    }
}
