/* Main Game Styles */
:root {
    --primary-color: #3a86ff;
    --secondary-color: #ff006e;
    --accent-color: #fb5607;
    --dark-color: #1e1e24;
    --light-color: #f8f9fa;
    --correct-color: #38b000;
    --wrong-color: #d90429;
    --border-radius: 10px;
    --shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    --transition: all 0.3s ease;
    --road-color: #333333;
    --road-line-color: #ffffff;
    --grass-color: #38b000;
    --tree-color: #0a5e2c;
}

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

body {
    font-family: 'Exo 2', sans-serif;
    background: linear-gradient(135deg, #0f0c29, #302b63, #24243e);
    color: var(--light-color);
    height: 100vh;
    overflow: hidden;
}

.game-container {
    position: relative;
    width: 100%;
    height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Header Styles */
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 20px;
    background: rgba(30, 30, 36, 0.8);
    box-shadow: var(--shadow);
    z-index: 10;
}

.logo-container {
    display: flex;
    align-items: center;
    gap: 15px;
}

.main-logo {
    height: 40px;
}

.game-logo {
    height: 30px;
}

.large-logo {
    height: 80px;
    margin-bottom: 20px;
}

.game-controls {
    display: flex;
    gap: 10px;
}

.control-btn {
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: var(--light-color);
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: var(--transition);
}

.control-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: scale(1.1);
}

/* Menu Screen Styles */
.menu-screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, #0f0c29, #302b63, #24243e);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 20;
    opacity: 0;
    pointer-events: none;
    transition: var(--transition);
}

.menu-screen.active {
    opacity: 1;
    pointer-events: all;
}

.menu-content {
    width: 90%;
    max-width: 600px;
    background: rgba(255, 255, 255, 0.05);
    backdrop-filter: blur(10px);
    border-radius: var(--border-radius);
    padding: 30px;
    text-align: center;
    box-shadow: var(--shadow);
    border: 1px solid rgba(255, 255, 255, 0.1);
    animation: fadeIn 0.5s ease;
}

.game-modes {
    display: flex;
    justify-content: space-around;
    margin: 30px 0;
}

.mode-btn {
    background: var(--primary-color);
    color: white;
    border: none;
    padding: 12px 24px;
    border-radius: var(--border-radius);
    font-size: 1.1rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    box-shadow: var(--shadow);
}

.mode-btn:hover {
    transform: translateY(-3px);
    box-shadow: 0 6px 15px rgba(0, 0, 0, 0.2);
}

.theme-selection {
    margin: 20px 0;
}

.theme-options {
    display: flex;
    justify-content: space-around;
    margin-top: 15px;
}

.theme-option {
    display: flex;
    flex-direction: column;
    align-items: center;
    cursor: pointer;
    transition: var(--transition);
    padding: 10px;
    border-radius: var(--border-radius);
}

.theme-option.selected {
    background: rgba(255, 255, 255, 0.1);
    transform: scale(1.05);
}

.theme-img {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    margin-bottom: 10px;
    background-size: cover;
    background-position: center;
}

.car-theme {
    background-color: #3a86ff;
    position: relative;
    overflow: hidden;
}
.car-theme::after {
    content: 'Car';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: white;
    font-weight: bold;
}

.horse-theme {
    background-color: #ff006e;
    position: relative;
    overflow: hidden;
}
.horse-theme::after {
    content: 'Horse';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: white;
    font-weight: bold;
}

.boat-theme {
    background-color: #fb5607;
    position: relative;
    overflow: hidden;
}
.boat-theme::after {
    content: 'Boat';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: white;
    font-weight: bold;
}

.room-code-container {
    margin-top: 20px;
}

.room-code-container.hidden {
    display: none;
}

#roomCodeInput {
    padding: 10px 15px;
    border-radius: var(--border-radius);
    border: 1px solid rgba(255, 255, 255, 0.2);
    background: rgba(255, 255, 255, 0.1);
    color: var(--light-color);
    font-size: 1rem;
    margin-right: 10px;
    width: 150px;
}

/* Waiting Room Styles */
.waiting-room {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, #0f0c29, #302b63, #24243e);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 15;
    opacity: 0;
    pointer-events: none;
    transition: var(--transition);
}

.waiting-room.active {
    opacity: 1;
    pointer-events: all;
}

.room-info {
    display: flex;
    align-items: center;
    margin: 20px 0;
}

#roomCodeDisplay {
    font-size: 1.5rem;
    font-weight: bold;
    margin: 0 10px;
}

.players-list {
    width: 80%;
    max-width: 400px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: var(--border-radius);
    padding: 20px;
    margin: 20px 0;
}

#playersListContainer {
    list-style-type: none;
    margin-top: 10px;
}

#playersListContainer li {
    padding: 8px;
    margin: 5px 0;
    background: rgba(255, 255, 255, 0.1);
    border-radius: var(--border-radius);
    display: flex;
    align-items: center;
}

#startGameMultiBtn, #leaveRoomBtn {
    margin: 10px;
    padding: 12px 24px;
    border-radius: var(--border-radius);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
}

#startGameMultiBtn {
    background: var(--primary-color);
    color: white;
    border: none;
}

#startGameMultiBtn:disabled {
    background: #cccccc;
    cursor: not-allowed;
}

#leaveRoomBtn {
    background: transparent;
    border: 1px solid var(--light-color);
    color: var(--light-color);
}

/* Game Canvas Styles */
.game-canvas {
    flex: 1;
    position: relative;
    overflow: hidden;
    display: none;
}

.stats-bar {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    display: flex;
    justify-content: space-around;
    padding: 10px;
    background: rgba(30, 30, 36, 0.7);
    z-index: 5;
}

.race-track {
    width: 100%;
    height: 100%;
    position: relative;
    background: linear-gradient(to bottom, #141e30, #243b55);
    background-size: cover;
    perspective: 500px;
    overflow: hidden;
}

/* Road and Scenery Elements */
.road {
    position: absolute;
    left: 50%;
    top: 0;
    transform: translateX(-50%);
    width: 60%;
    height: 100%;
    background-color: var(--road-color);
    z-index: 1;
    box-shadow: 0 0 30px rgba(0, 0, 0, 0.5);
}

.road-line {
    position: absolute;
    left: 50%;
    top: 0;
    transform: translateX(-50%);
    width: 10px;
    height: 100%;
    z-index: 2;
}

.road-line::after {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background: repeating-linear-gradient(
        to bottom,
        var(--road-line-color) 0px,
        var(--road-line-color) 50px,
        transparent 50px,
        transparent 100px
    );
    z-index: 2;
}

.road-edge {
    position: absolute;
    top: 0;
    width: 15px;
    height: 100%;
    background-color: var(--road-line-color);
    z-index: 2;
}

.road-edge.left {
    left: 20%;
}

.road-edge.right {
    right: 20%;
}

.scenery-container {
    position: absolute;
    top: 0;
    width: 20%;
    height: 100%;
    z-index: 1;
}

.scenery-container.left {
    left: 0;
    background-color: var(--grass-color);
}

.scenery-container.right {
    right: 0;
    background-color: var(--grass-color);
}

.tree {
    position: absolute;
    width: 40px;
    height: 60px;
    z-index: 2;
}

.tree::before {
    content: '🌳';
    font-size: 40px;
}

.bush {
    position: absolute;
    width: 30px;
    height: 20px;
    z-index: 2;
}

.bush::before {
    content: '🌿';
    font-size: 30px;
}

.rock {
    position: absolute;
    width: 20px;
    height: 20px;
    z-index: 2;
}

.rock::before {
    content: '🪨';
    font-size: 20px;
}

.racer {
    position: absolute;
    width: 50px;
    height: 50px;
    background-size: contain;
    background-repeat: no-repeat;
    transition: all 0.3s ease;
    z-index: 3;
    transition: top 0.8s ease-in-out;
}

.player-racer {
    bottom: 5%;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: bold;
    font-size: 18px;
}



.player-racer.driving {
    animation: carDriving 0.3s infinite;
}

.player-racer.stopping {
    animation: carStop 0.5s;
}

.player-racer.correct-effect {
    animation: correctAnswer 1s;
    box-shadow: 0 0 15px 5px var(--correct-color);
}

.player-racer.wrong-effect {
    animation: wrongAnswer 1s;
    box-shadow: 0 0 15px 5px var(--wrong-color);
}

/* Ensure proper rendering of player and opponent racers */
.player-racer, .opponent-racer {
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: visible;
}

.player-racer svg, .opponent-racer svg {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

/* Adjust emoji size in racer elements */
.player-racer:not(:has(svg)), .opponent-racer:not(:has(svg)) {
    font-size: 24px;
    text-align: center;
}

.finish-line {
    position: absolute;
    left: 0;
    top: 5%;
    width: 100%;
    height: 10px;
    background: repeating-linear-gradient(
        to right,
        #000 0px,
        #000 20px,
        #fff 20px,
        #fff 40px
    );
    z-index: 2;
}

.obstacle {
    position: absolute;
    width: 60px;
    height: 60px;
    background-size: contain;
    background-repeat: no-repeat;
    z-index: 3;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: bold;
    border-radius: 50%;
    left: 50%;
    transform: translateX(-50%);
    transition: transform 0.3s, opacity 0.3s;
}

.obstacle.active {
    transform: translateX(-50%) scale(1.2);
    box-shadow: 0 0 15px 5px rgba(255, 255, 255, 0.5);
    z-index: 4;
}

/* Road Effects */
.road::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: repeating-linear-gradient(
        90deg,
        transparent 0,
        transparent 48%,
        var(--road-line-color) 48%,
        var(--road-line-color) 52%,
        transparent 52%,
        transparent 100%
    );
    background-size: 10px 10px;
    opacity: 0.1;
}

.tire-marks {
    position: absolute;
    bottom: 5%;
    left: 50%;
    transform: translateX(-50%);
    width: 20px;
    height: 0;
    background: rgba(0, 0, 0, 0.2);
    z-index: 2;
    transition: height 0.5s;
}

/* Car Animation Effects */
@keyframes carDriving {
    0% { transform: translateX(-50%) translateY(0); }
    25% { transform: translateX(-51%) translateY(-1px); }
    75% { transform: translateX(-49%) translateY(1px); }
    100% { transform: translateX(-50%) translateY(0); }
}

@keyframes wheelSpin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

@keyframes carStop {
    0% { transform: translateX(-50%) translateY(0); }
    20% { transform: translateX(-49%) translateY(-2px); }
    40% { transform: translateX(-51%) translateY(0); }
    60% { transform: translateX(-50%) translateY(1px); }
    80% { transform: translateX(-49%) translateY(0); }
    100% { transform: translateX(-50%) translateY(0); }
}

@keyframes correctAnswer {
    0% { box-shadow: 0 0 0 0 rgba(56, 176, 0, 0.7); }
    70% { box-shadow: 0 0 0 15px rgba(56, 176, 0, 0); }
    100% { box-shadow: 0 0 0 0 rgba(56, 176, 0, 0); }
}

@keyframes wrongAnswer {
    0% { box-shadow: 0 0 0 0 rgba(217, 4, 41, 0.7); }
    70% { box-shadow: 0 0 0 15px rgba(217, 4, 41, 0); }
    100% { box-shadow: 0 0 0 0 rgba(217, 4, 41, 0); }
}

/* Question Popup Styles */
.question-popup {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.9);
    width: 90%;
    max-width: 500px;
    background: rgba(30, 30, 36, 0.95);
    border-radius: var(--border-radius);
    padding: 25px;
    box-shadow: 0 15px 25px rgba(0, 0, 0, 0.3);
    z-index: 10;
    opacity: 0;
    pointer-events: none;
    transition: all 0.3s cubic-bezier(0.68, -0.55, 0.27, 1.55);
    border: 2px solid var(--primary-color);
}

.question-popup.active {
    opacity: 1;
    pointer-events: all;
    transform: translate(-50%, -50%) scale(1);
}

.popup-content h3 {
    margin-bottom: 20px;
    color: var(--light-color);
    text-align: center;
    font-size: 1.3rem;
}

.answer-options {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 15px;
    margin-bottom: 20px;
}

.answer-option {
    padding: 15px;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: var(--border-radius);
    cursor: pointer;
    transition: var(--transition);
    text-align: center;
}

.answer-option:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: translateY(-2px);
}

.answer-option.correct {
    background: var(--correct-color);
    color: white;
}

.answer-option.wrong {
    background: var(--wrong-color);
    color: white;
}

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

.timer-progress {
    height: 100%;
    width: 100%;
    background: var(--primary-color);
    transition: width 0.1s linear;
}

/* Game Over Screen Styles */
.game-over {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(30, 30, 36, 0.9);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 30;
    opacity: 0;
    pointer-events: none;
    transition: var(--transition);
}

.game-over.active {
    opacity: 1;
    pointer-events: all;
}

.result-content {
    width: 90%;
    max-width: 500px;
    background: rgba(255, 255, 255, 0.05);
    backdrop-filter: blur(10px);
    border-radius: var(--border-radius);
    padding: 30px;
    text-align: center;
    box-shadow: var(--shadow);
    border: 1px solid rgba(255, 255, 255, 0.1);
    animation: bounceIn 0.6s ease;
}

#gameResult {
    font-size: 2rem;
    margin-bottom: 20px;
    background: linear-gradient(90deg, var(--primary-color), var(--secondary-color));
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

.final-stats {
    margin: 25px 0;
}

.final-stats p {
    margin: 10px 0;
    font-size: 1.1rem;
}

.action-buttons {
    display: flex;
    justify-content: space-around;
    margin-top: 20px;
}

.action-buttons button {
    padding: 12px 24px;
    border-radius: var(--border-radius);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
}

#playAgainBtn {
    background: var(--primary-color);
    color: white;
    border: none;
}

#returnMenuBtn {
    background: transparent;
    border: 1px solid var(--light-color);
    color: var(--light-color);
}

/* Animations */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(-20px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes bounceIn {
    0% { opacity: 0; transform: scale(0.8); }
    70% { transform: scale(1.05); }
    100% { opacity: 1; transform: scale(1); }
}

/* Responsive Styles */
@media (max-width: 768px) {
    .theme-options {
        flex-direction: column;
        align-items: center;
        gap: 15px;
    }
    
    .answer-options {
        grid-template-columns: 1fr;
    }
    
    .game-modes {
        flex-direction: column;
        gap: 15px;
    }
    
    .mode-btn {
        width: 80%;
        margin: 0 auto;
    }
}

@media (max-width: 480px) {
    .menu-content, .result-content {
        width: 95%;
        padding: 20px;
    }
    
    .stats-bar {
        flex-direction: column;
        align-items: flex-start;
        padding: 5px 15px;
    }
    
    .stats-bar > div {
        margin: 2px 0;
    }
}
