/* Reset and Global Styles */
body, html {
    background-color: #1a1a2e; /* Dark blue-gray background */
    margin: 0;
    padding: 0;
    font-family: 'Pixel', sans-serif; /* Custom pixel font */
    box-sizing: border-box;
    overflow: hidden; /* Prevent content overflow */
    touch-action: none; /* Prevent default touch behaviors */
    -webkit-tap-highlight-color: transparent; /* Remove tap highlight on mobile */
    transition: none; /* Prevent any background transitions */
}

/* Ensure game area has the same background */
#gameArea {
    background-color: #292939;
}

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

/* Font Import */
@font-face {
    font-family: 'Pixel';
    src: url(pics/Tickerbit-regular.woff2); /* Custom pixel font */
}

/* Color Variables */
:root {
    --black: #000;
    --gray: #979797;
    --darkGray: #1b1b1b;
    --white: #fff;
    --blue: #4c00ff;
    --red: #ff3131;
}

/* Utility Classes */
.Hide {
    display: none !important;
}

/* Game Container */
.Game {
    overflow: hidden; /* Prevent content overflow */
}

/* Info Bar - Banner at the top */
.info {
    background: linear-gradient(145deg, #2a2a3a, #1a1a25);
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.8rem 1.5rem;
    width: 100%;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
    position: relative;
    z-index: 50;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

/* Racer Title */
.Racer-txt {
    color: #fff;
    font-size: 24px;
    margin: 0;
    letter-spacing: 1.5px;
    font-weight: 800;
    text-transform: uppercase;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
    background: linear-gradient(45deg, #fff, #a8a8ff);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    position: relative;
    padding: 0 15px;
}

.Racer-txt::after {
    content: '';
    position: absolute;
    bottom: -5px;
    left: 15px;
    right: 15px;
    height: 3px;
    background: linear-gradient(90deg, #4c00ff, #00f7ff);
    border-radius: 3px;
}

/* Score Display */
.Score, .level {
    min-width: 100px;
    height: 40px;
    background: linear-gradient(145deg, #4c00ff, #3a00c2);
    color: #fff;
    font-size: 14px;
    font-weight: 600;
    padding: 0.6rem 1rem;
    border-radius: 12px;
    text-align: center;
    box-shadow: 0 4px 0 #2a0070, 0 4px 15px rgba(0, 0, 0, 0.2);
    border: none;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
    transition: all 0.2s ease;
}

.Score::before, .level::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 2px;
    background: rgba(255, 255, 255, 0.3);
}

.Score {
    margin-right: 15px;
}

/* Level Display */
.level {
    background: linear-gradient(145deg, #ff3131, #c22626);
    box-shadow: 0 4px 0 #8a1a1a, 0 4px 15px rgba(0, 0, 0, 0.2);
    margin-right: 15px;
}

/* Game Area */
.gameArea {
    border-right: 10px solid var(--gray);
    border-left: 10px solid var(--gray);
    background-color: var(--darkGray);
    width: 100%;
    max-width: 320px;
    height: calc(100vh - 60px); /* Full height minus info bar */
    max-height: calc(100vh - 60px); /* Prevent overflow */
    position: relative;
    margin: 0 auto; /* Center the game area */
    overflow: hidden;
    box-shadow: 0 8px 15px rgba(0, 0, 0, 0.3);
    z-index: 10; /* Lower than touch controls */
}

/* Road Line */
.line {
    background-color: var(--white);
    position: absolute;
    height: 120px; /* Slightly taller lines */
    width: 8px; /* Slightly thinner */
    left: 50%;
    transform: translateX(-50%);
    opacity: 0.9;
    border-radius: 4px; /* Rounded corners */
    box-shadow: 0 0 10px rgba(255, 255, 255, 0.5); /* Subtle glow */
}

/* Car and Enemy Styles */
.car, .enemy {
    position: absolute;
    height: 85px;
    width: 45px;
    border-radius: 10px;
    background-image: url(pics/BlackCar.svg);
    background-size: cover;
    z-index: 1;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

/* Start Screen */
.startScreen {
    background: rgba(20, 25, 35, 0.95);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    cursor: pointer;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 85%;
    max-width: 340px;
    min-height: 240px;
    padding: 2.5rem 1.5rem;
    border-radius: 18px;
    text-align: center;
    box-shadow: 0 15px 35px rgba(0, 0, 0, 0.4), 
                0 0 0 1px rgba(255, 255, 255, 0.05),
                inset 0 0 0 1px rgba(255, 255, 255, 0.1);
    z-index: 100;
    overflow: hidden;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    border: none;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

.startScreen::before {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: linear-gradient(90deg, #4e54c8, #8f94fb);
    animation: rainbow 4s linear infinite;
    background-size: 200% 100%;
}

.startScreen::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: radial-gradient(circle at 50% 0%, rgba(78, 84, 200, 0.15), transparent 60%);
    pointer-events: none;
}

/* Game over state uses same styles as regular state */

@keyframes rainbow {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

/* Start Text */
.starttext {
    font-size: 2.5rem;
    color: #fff;
    margin: 1rem 0;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 2px;
    text-shadow: 0 2px 10px rgba(0, 0, 0, 0.5);
    position: relative;
    padding: 1.5rem 0;
    background: linear-gradient(135deg, #fff 0%, #b8b8ff 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    line-height: 1.1;
    width: 100%;
}

.starttext::after {
    content: '';
    position: absolute;
    bottom: 0.5rem;
    left: 20%;
    right: 20%;
    height: 3px;
    background: linear-gradient(90deg, 
        transparent, 
        rgba(110, 69, 226, 0.8), 
        rgba(136, 211, 206, 0.8),
        transparent);
    border-radius: 3px;
    opacity: 0.8;
}

.starttext .highlight {
    display: block;
    font-size: 1rem;
    margin: 1.5rem auto 0;
    color: #b8b8ff;
    text-transform: none;
    letter-spacing: 1px;
    animation: pulse 2s infinite;
    font-weight: 500;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
    background: rgba(255, 255, 255, 0.15);
    padding: 0.8rem 1.5rem;
    border-radius: 25px;
    min-width: 180px;
    max-width: 90%;
    backdrop-filter: blur(5px);
    border: 1px solid rgba(255, 255, 255, 0.15);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
    transition: all 0.3s ease;
}

.starttext .highlight:active {
    transform: scale(0.98);
    background: rgba(255, 255, 255, 0.2);
}

/* Touch Controls */
.toch-controls{
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 16vh;
    max-height: 16vh;
    z-index: 10;
    display: none;
    pointer-events: auto; /* Changed to auto to allow button presses */
    padding: 0;
    background: transparent;
}

.left-controls, .right-controls {
    display: flex;
    gap: 15px;
    pointer-events: auto;
    transform: translateZ(0);
}

.left-controls {
    position: fixed;
    left: 15px;
    bottom: 15px;
    display: flex;
    gap: 10px;
}

.right-controls {
    position: fixed;
    right: 15px;
    bottom: 15px;
    display: flex;
    flex-direction: row;
    gap: 10px;
}

/* Control Buttons */
.control-button {
    width: 55px;
    height: 55px;
    border-radius: 15px;
    background: rgba(76, 0, 255, 0.2);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 2px solid rgba(255, 255, 255, 0.1);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    font-weight: bold;
    color: white;
    cursor: pointer;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    position: relative;
    overflow: hidden;
    transition: all 0.15s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.2);
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

/* Button specific styles */
/* All control buttons share the same style */
.control-button.left,
.control-button.right,
.control-button.gas,
.control-button.brake {
    background: rgba(0, 123, 255, 0.2);
    border-color: rgba(0, 123, 255, 0.3);
}

.control-button::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.1);
    opacity: 0;
    transition: opacity 0.2s;
}

/* Button active/pressed state */
.control-button:active {
    transform: translateY(3px) scale(0.95);
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
    opacity: 0.9;
}

/* Active state for all buttons */
.control-button.left:active,
.control-button.right:active,
.control-button.gas:active,
.control-button.brake:active {
    background: rgba(0, 123, 255, 0.4);
}

/* Button hover effect for devices with hover support */
@media (hover: hover) {
    .control-button:hover {
        transform: translateY(-2px);
        box-shadow: 0 8px 25px rgba(0, 0, 0, 0.3);
    }
    
    .control-button:active {
        transform: translateY(1px) scale(0.98);
    }
}


/* Flashing animation for all buttons */
@keyframes flash {
    0% { opacity: 0.8; }
    50% { opacity: 1; }
    100% { opacity: 0.8; }
}

.control-button::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.3);
    animation: flash 2s infinite;
    opacity: 0;
    pointer-events: none;
    border-radius: inherit;
}

.control-button.active::before {
    opacity: 0.7;
}

/* Touch controls */
.touch-controls {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    display: none;
    justify-content: space-between;
    padding: 8px 12px 18px;
    z-index: 1000;
    pointer-events: none;
    background: linear-gradient(to top, rgba(20, 25, 50, 0.92), rgba(20, 25, 50, 0.88));
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-top: 1px solid rgba(255, 255, 255, 0.12);
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.35);
    border-radius: 18px 18px 0 0;
    min-height: 100px;
}

/* Show touch controls only on mobile */
@media (hover: none) and (pointer: coarse) {
    .touch-controls {
        display: flex;
        animation: slideUp 0.3s ease-out;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
    }
    
    @keyframes slideUp {
        from { transform: translateY(100%); }
        to { transform: translateY(0); }
    }
    
    .gameArea {
        height: calc(100vh - 60px - 100px); /* Account for touch controls height */
        max-height: calc(100vh - 60px - 100px);
        margin-bottom: 100px; /* Space for touch controls */
    }
    
    .info {
        padding: 0.5rem 0.8rem;
        position: relative;
        z-index: 100;
    }
    
    .Racer-txt {
        font-size: 20px;
        padding: 0 8px;
    }
    
    body, html {
        overflow-x: hidden;
        position: fixed;
        width: 100%;
        height: 100%;
    }
    
    .Score, .level {
        min-width: 70px;
        height: 32px;
        font-size: 12px;
        padding: 0.4rem 0.6rem;
    }
    
    /* Compact Start Screen */
    .startScreen {
        width: 90%;
        max-width: 300px;
        min-height: 200px;
        padding: 1.5rem 1rem;
    }
    
    .starttext {
        font-size: 1.8rem;
        margin: 0.5rem 0;
        padding: 0.5rem 0;
    }
    
    .starttext .highlight {
        font-size: 0.9rem;
        margin: 1rem auto 0;
        padding: 0.6rem 1.2rem;
        min-width: 150px;
    }
    
    .carLogo {
        width: 40px !important;
        height: 70px !important;
    }
}

/* Bounce Animation for Car Logo */
@keyframes bounce {
    0%, 100% {
        transform: translateY(0);
    }
    50% {
        transform: translateY(-10px);
    }
}

/* Start Text */
.starttext {
    font-size: 26px;
    color: var(--white);
    animation: opatext 1s infinite;
}

/* Opacity Animation for Start Text */
@keyframes opatext {
    0%, 100% {
        opacity: 100%;
    }
    50% {
        opacity: 50%;
    }
}
