body, html {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    background-color: #000;
    font-family: Arial, sans-serif;
}

#game-container {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
}

#game-canvas {
    width: 100%;
    height: 100%;
    display: block;
    object-fit: contain;
}

#ui-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none; /* Let clicks pass through unless on button */
}

#score-board {
    position: absolute;
    top: 20px;
    left: 20px;
    color: white;
    font-size: 24px;
    font-weight: bold;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.8);
}

#speed-meter {
    position: absolute;
    bottom: 20px;
    left: 20px;
    color: white;
    font-size: 24px;
    font-weight: bold;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.8);
}

#accel-btn {
    position: absolute;
    bottom: 30px;
    right: 30px;
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background: radial-gradient(circle, #ff5722, #d84315);
    border: 4px solid white;
    color: white;
    font-weight: bold;
    font-size: 16px;
    cursor: pointer;
    box-shadow: 0 4px 10px rgba(0,0,0,0.5);
    pointer-events: auto;
    transition: transform 0.1s, box-shadow 0.1s;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    z-index: 60; /* Above joystick */
}

#accel-btn:active {
    transform: scale(0.95);
    box-shadow: 0 2px 5px rgba(0,0,0,0.5);
}

#joystick-zone {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 50;
    touch-action: none; 
}

/* Start Screen */
#start-screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: url('photos/b1.jpg') no-repeat center center/cover;
    z-index: 200;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    color: white;
    text-shadow: 0 2px 10px rgba(0,0,0,0.8);
}

.start-car {
    width: 60%;
    max-width: 400px;
    margin-bottom: 20px;
    filter: drop-shadow(0 10px 20px rgba(0,0,0,0.5));
    animation: float 2s infinite ease-in-out;
}

@keyframes float {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-20px); }
}

.start-content h1 {
    font-size: 4rem;
    margin: 0;
    font-style: italic;
    background: linear-gradient(to bottom, #fff, #aaa);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.start-content p {
    font-size: 1.5rem;
    margin-top: 10px;
    animation: blink 1s infinite;
}

@keyframes blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* Modal */
.hidden {
    display: none !important;
}

#game-over-modal, #leaderboard-modal {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.85);
    z-index: 300;
    display: flex;
    justify-content: center;
    align-items: center;
    backdrop-filter: blur(5px);
}

.modal-content, .leaderboard-panel {
    background: linear-gradient(135deg, #1a1a1a, #333);
    padding: 40px;
    border-radius: 20px;
    text-align: center;
    color: white;
    border: 2px solid #555;
    box-shadow: 0 0 30px rgba(0,0,0,0.8);
    min-width: 300px;
    max-width: 90%;
    max-height: 90%;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.modal-content h2, .leaderboard-panel h2 {
    font-size: 2.5rem;
    margin: 0 0 20px 0;
    color: #ff5722;
    text-transform: uppercase;
    letter-spacing: 2px;
}

.score-display {
    font-size: 1.5rem;
    margin: 30px 0;
    background: rgba(255,255,255,0.1);
    padding: 15px;
    border-radius: 10px;
}

.score-label {
    display: block;
    font-size: 1rem;
    color: #aaa;
    margin-bottom: 5px;
}

#final-score {
    font-size: 3rem;
    font-weight: bold;
    color: #fff;
}

.button-group {
    display: flex;
    gap: 15px;
    justify-content: center;
    flex-wrap: wrap;
}

button {
    background: #ff5722;
    color: white;
    border: none;
    padding: 15px 30px;
    font-size: 1.1rem;
    border-radius: 30px;
    cursor: pointer;
    transition: transform 0.2s, background 0.2s;
    text-transform: uppercase;
    font-weight: bold;
    letter-spacing: 1px;
}

button:hover {
    background: #f4511e;
    transform: scale(1.05);
}

button:active {
    transform: scale(0.95);
}

/* Leaderboard Styles */
.leaderboard-list-wrapper {
    flex: 1;
    overflow-y: auto;
    margin-bottom: 20px;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 10px;
    padding: 10px;
    min-height: 200px;
}

#leaderboard-table {
    width: 100%;
    border-collapse: collapse;
    color: #eee;
}

#leaderboard-table th, #leaderboard-table td {
    padding: 10px;
    text-align: center;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

#leaderboard-table th {
    color: #ff5722;
    font-size: 1.1rem;
    position: sticky;
    top: 0;
    background: #222; /* Fallback */
    background: rgba(34, 34, 34, 0.95);
    z-index: 10;
}

#leaderboard-table tr:last-child td {
    border-bottom: none;
}

.rank-1 { color: #FFD700; font-weight: bold; }
.rank-2 { color: #C0C0C0; font-weight: bold; }
.rank-3 { color: #CD7F32; font-weight: bold; }

.leaderboard-controls {
    display: flex;
    justify-content: center;
    gap: 15px;
}

#lb-close {
    background: #555;
}
#lb-close:hover {
    background: #666;
}

#leaderboard-loading {
    padding: 20px;
    color: #aaa;
    font-style: italic;
}
