body {
    margin: 0;
    overflow: hidden;
    font-family: 'Orbitron', sans-serif; /* Modern font */
    background-color: #1a1a2e; /* Darker, modern background */
    color: #e0e0e0; /* Softer white for text */
}

#game-container {
    width: 100vw;
    height: 100vh;
    display: block;
}

canvas {
    display: block;
}

/* Base styles for modern UI elements */
.ui-panel {
    background-color: rgba(30, 30, 30, 0.7); /* Dark semi-transparent background */
    backdrop-filter: blur(5px); /* Frosted glass effect */
    border-radius: 12px; /* Rounded corners */
    padding: 10px 15px;
    color: #e0e0e0;
    font-weight: bold;
    text-shadow: 1px 1px 3px rgba(0, 0, 0, 0.5); /* Subtle text shadow for readability */
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3); /* Subtle depth */
    border: none;
    user-select: none;
}

/* Mobile controls */
#mobile-controls {
    position: absolute;
    bottom: 20px;
    left: 0;
    right: 0;
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    padding: 0 20px;
    z-index: 1000;
}

.control-group {
    display: flex;
    flex-direction: column;
    gap: 12px; /* Increased gap */
}

#right-controls {
    flex-direction: row;
    gap: 12px; /* Increased gap */
}

.control-btn {
    width: 85px; /* Slightly adjusted size */
    height: 65px;
    font-size: 28px; /* Larger icons */
    background-color: rgba(60, 60, 60, 0.8); /* Darker, sleek background */
    border: none;
    border-radius: 15px; /* More rounded */
    color: #c0c0c0; /* Softer color for icons */
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    user-select: none;
    -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
    padding: 5px;
    box-sizing: border-box;
    transition: background-color 0.2s ease, transform 0.1s ease; /* Smooth transitions */
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.2);
}

.pedal-btn {
    width: 95px; /* Slightly wider for pedals */
    height: 85px; /* Taller for pedals */
}

.control-btn:active {
    background-color: rgba(90, 90, 90, 0.9);
    transform: translateY(2px); /* Slight press effect */
    box-shadow: 0 1px 5px rgba(0, 0, 0, 0.3);
}

/* Hide controls on larger screens (e.g., desktops) */
@media (min-width: 768px) {
    #mobile-controls {
        display: none;
    }
}

/* Show controls on smaller screens (e.g., mobile devices) */
@media (max-width: 767px) {
    #mobile-controls {
        display: flex;
    }

    /* Make mobile control buttons circular and adjust size */
    #mobile-controls .control-btn {
        border-radius: 50%; /* Fully circular corners */
        width: 75px; /* Make square for circular shape */
        height: 75px; /* Make square for circular shape */
        padding: 5px; /* Adjust padding to fit the image */
    }

    #mobile-controls .pedal-btn {
        width: 85px; /* Slightly larger square for pedals */
        height: 85px; /* Slightly larger square for pedals */
    }

    /* Styling for the new arrow images */
    .arrow-icon {
        width: 100%;
        height: 100%;
        object-fit: contain; /* Ensure the arrow fits within the button */
        padding: 0; /* Remove padding from image itself, button padding handles it */
    }

    /* Rotate arrow icons for direction */
    .arrow-icon.up {
        transform: rotate(0deg); /* Upward-pointing */
    }

    .arrow-icon.down {
        transform: rotate(180deg); /* Downward-pointing */
    }

    .arrow-icon.left {
        transform: rotate(-90deg); /* Left-pointing */
    }

    .arrow-icon.right {
        transform: rotate(90deg); /* Right-pointing */
    }
}

/* Speedometer styling */
#speedometer {
    position: absolute;
    top: 20px;
    right: 20px;
    font-size: 32px; /* Larger font */
    min-width: 140px; /* Ensure it has a consistent width */
    text-align: center;
    background-color: rgba(30, 30, 30, 0.7);
    backdrop-filter: blur(5px);
    border-radius: 12px;
    padding: 10px 15px;
    color: #e0e0e0;
    font-weight: bold;
    text-shadow: 1px 1px 3px rgba(0, 0, 0, 0.5);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
    border: none;
    user-select: none;
}

/* Lap Counter styling */
#lap-counter {
    position: absolute;
    top: 20px;
    left: 20px;
    font-size: 24px;
    min-width: 130px;
    text-align: center;
    padding: 8px 12px;
    background-color: rgba(30, 30, 30, 0.7);
    backdrop-filter: blur(5px);
    border-radius: 12px;
    color: #e0e0e0;
    font-weight: bold;
    text-shadow: 1px 1px 3px rgba(0, 0, 0, 0.5);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
    border: none;
    user-select: none;
}

/* Jackson Storm Lap Counter styling */
#jackson-storm-lap-counter {
    position: absolute;
    top: 75px; /* Below player lap counter, adjusted for new padding */
    left: 20px;
    font-size: 24px;
    min-width: 130px;
    text-align: center;
    padding: 8px 12px;
    background-color: rgba(30, 30, 30, 0.7);
    backdrop-filter: blur(5px);
    border-radius: 12px;
    color: #e0e0e0;
    font-weight: bold;
    text-shadow: 1px 1px 3px rgba(0, 0, 0, 0.5);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
    border: none;
    user-select: none;
}

/* Sand Warning styling */
#sand-warning {
    position: absolute;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    background-color: rgba(255, 60, 60, 0.2); /* Soft red warning background */
    backdrop-filter: blur(5px);
    border: 2px solid #ff4d4d; /* Red border */
    border-radius: 12px;
    color: #ff4d4d; /* Bright red text */
    font-size: 36px; /* Larger and bolder */
    padding: 15px 30px;
    font-weight: 900; /* Extra bold */
    text-align: center;
    white-space: nowrap;
    z-index: 1000;
    text-shadow: 2px 2px 5px rgba(0, 0, 0, 0.7);
    box-shadow: 0 0 20px rgba(255, 60, 60, 0.5); /* Glow effect */
    animation: pulseGlow 1.5s infinite alternate; /* Subtle pulsing glow */
}

@keyframes pulseGlow {
    from {
        box-shadow: 0 0 10px rgba(255, 60, 60, 0.5);
    }
    to {
        box-shadow: 0 0 25px rgba(255, 60, 60, 0.8);
    }
}


/* Countdown Timer styling */
#countdown-timer {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: #00e676; /* Vibrant green for countdown */
    font-size: 80px; /* Very large font */
    font-weight: 900; /* Extra bold */
    text-align: center;
    z-index: 2000;
    white-space: nowrap;
    text-shadow: 0 0 15px rgba(0, 230, 118, 0.8), 0 0 30px rgba(0, 230, 118, 0.6); /* Glow text effect */
    -webkit-text-stroke: 2px #000; /* Black stroke */
    text-stroke: 2px #000;
    -webkit-text-fill-color: #00e676; /* Ensure inner color is vibrant green for webkit */
}

/* Race Result styling */
#race-result {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background-color: transparent; /* Changed to transparent */
    backdrop-filter: none; /* Removed backdrop-filter */
    color: white;
    font-size: 60px; /* Slightly smaller than countdown, still prominent */
    padding: 40px 80px;
    border-radius: 25px;
    font-weight: bold;
    text-align: center;
    z-index: 2000;
    white-space: nowrap;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 25px;
    text-shadow: 2px 2px 6px rgba(0, 0, 0, 0.8);
    box-shadow: none; /* Removed box-shadow */
}

.race-result-win {
    color: #00e676; /* Vibrant green for win */
    border: 5px solid #00e676;
    box-shadow: 0 0 40px rgba(0, 230, 118, 0.5); /* Kept a subtle glow for win state */
}

.race-result-lose {
    color: #ff4d4d; /* Bright red for loss */
    border: 5px solid #ff4d4d;
    box-shadow: 0 0 40px rgba(255, 77, 77, 0.5); /* Kept a subtle glow for lose state */
}

#race-result button {
    margin-top: 20px;
    padding: 18px 35px; /* Larger button */
    font-size: 26px;
    background-color: #007bff; /* Primary blue */
    color: white;
    border: none;
    border-radius: 12px; /* Rounded */
    cursor: pointer;
    transition: background-color 0.3s ease, transform 0.1s ease;
    font-family: 'Orbitron', sans-serif;
    font-weight: bold;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
}

#race-result button:hover {
    background-color: #0056b3;
    transform: translateY(-2px);
}

/* Utility class to hide elements */
.hidden {
    display: none;
}

/* Pause Button Styling */
#pause-btn {
    position: absolute;
    top: 20px;
    right: 250px; /* Positioned to the left of the speedometer, adjusted for new padding */
    z-index: 1000;
    width: 60px; /* Smaller, icon-focused button */
    height: 60px;
    background-color: rgba(60, 60, 60, 0.8);
    border-radius: 15px;
    transition: background-color 0.2s ease, transform 0.1s ease;
    backdrop-filter: blur(5px);
    padding: 0; /* Adjust padding for button's specific size needs */
    font-weight: bold;
    text-shadow: 1px 1px 3px rgba(0, 0, 0, 0.5);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
    border: none;
    user-select: none;
    display: flex; /* Ensure flex for centering icon */
    align-items: center;
    justify-content: center;
}

#pause-btn img {
    width: 100%;
    height: 100%;
    object-fit: contain; /* Ensure the image fits within the button without distortion */
    padding: 10px; /* Add padding to the image itself */
    box-sizing: border-box; /* Include padding in width/height */
}

#pause-btn:disabled {
    opacity: 0.4; /* Slightly more opaque disabled state */
    cursor: not-allowed;
    background-color: rgba(30, 30, 30, 0.6);
}

#pause-btn:active:not(:disabled) {
    background-color: rgba(90, 90, 90, 0.9);
    border-color: rgba(0, 0, 0, 0.8);
    transform: translateY(2px);
}

/* Adjust pause button for smaller screens */
@media (max-width: 767px) {
    #pause-btn {
        top: unset; 
        right: unset;
        bottom: 100px;
        left: 50%;
        transform: translateX(-50%);
        width: 70px; /* Slightly larger for touch */
        height: 70px;
        padding: 0; /* Ensure padding is 0 for mobile button as well */
    }
}

/* Pause Overlay Styling */
#pause-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.8); /* Darker overlay */
    backdrop-filter: blur(10px); /* Stronger blur for full screen overlay */
    display: none;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 3000;
    color: white;
    font-size: 60px; /* Larger text */
    font-weight: bold;
    text-shadow: 2px 2px 8px rgba(0, 0, 0, 0.9);
}

#pause-overlay h2 {
    margin-bottom: 40px; /* Increased margin */
    font-size: 80px; /* Very large PAUSED text */
    color: #ffffff;
    letter-spacing: 5px; /* Spaced out letters */
}

/* NEW: Settings panel styling */
#settings-panel {
    background-color: rgba(30, 30, 30, 0.9); /* Slightly darker for settings panel */
    border-radius: 12px;
    padding: 25px 40px;
    margin-bottom: 40px; /* Space between settings and resume button */
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.5);
    display: flex;
    flex-direction: column;
    gap: 20px; /* Space between setting items */
    min-width: 300px; /* Ensure a decent width */
    text-align: center;
}

#settings-panel h3 {
    font-size: 32px;
    color: #00e676; /* Green accent for heading */
    margin-top: 0;
    margin-bottom: 20px;
    text-shadow: 1px 1px 5px rgba(0, 230, 118, 0.3);
}

.setting-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 22px;
    color: #e0e0e0;
}

.setting-item label {
    flex-grow: 1;
    text-align: left;
    margin-right: 15px;
    font-weight: bold;
}

/* Style for select dropdowns */
.setting-item select {
    background-color: rgba(60, 60, 60, 0.8);
    border: 1px solid rgba(100, 100, 100, 0.5);
    border-radius: 8px;
    padding: 8px 12px;
    color: #e0e0e0;
    font-size: 18px;
    cursor: pointer;
    -webkit-appearance: none; /* Remove default arrow */
    -moz-appearance: none;
    appearance: none;
    background-image: url('data:image/svg+xml;charset=US-ASCII,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%22292.4%22%20height%3D%22292.4%22%3E%3Cpath%20fill%3D%22%23e0e0e0%22%20d%3D%22M287%2069.4a17.6%2017.6%200%200%200-13.6-6.4H19.6c-5.1%200-9.6%202-13.6%206.4-4%204.4-6.4%209.6-6.4%2016.4%200%206.8%202.4%2012%206.4%2016.4l128%20127.9c4%204.4%209.2%206.4%2013.6%206.4s9.6-2%2013.6-6.4L287%20102.2c4-4.4%206.4-9.6%206.4-16.4%200-6.8-2.4-12-6.4-16.4z%22%2F%3E%3C%2Fsvg%3E'); /* Custom arrow */
    background-repeat: no-repeat;
    background-position: right 10px center;
    background-size: 16px;
    padding-right: 30px; /* Make space for the arrow */
}

.setting-item select:focus {
    outline: none;
    border-color: #007bff;
    box-shadow: 0 0 0 3px rgba(0, 123, 255, 0.25);
}

/* Style for checkboxes (using custom styling for consistency) */
.setting-item input[type="checkbox"] {
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    width: 25px;
    height: 25px;
    border: 2px solid #00e676; /* Green border */
    border-radius: 6px;
    background-color: rgba(60, 60, 60, 0.8);
    cursor: pointer;
    position: relative;
    outline: none;
    transition: background-color 0.2s, border-color 0.2s;
}

.setting-item input[type="checkbox"]:checked {
    background-color: #00e676; /* Green when checked */
    border-color: #00e676;
}

.setting-item input[type="checkbox"]:checked::after {
    content: '✔'; /* Checkmark symbol */
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: #1a1a2e; /* Dark color for checkmark */
    font-size: 20px;
    line-height: 1;
    font-weight: bold;
}

.setting-item input[type="checkbox"]:focus {
    box-shadow: 0 0 0 3px rgba(0, 230, 118, 0.25);
}

#pause-overlay button {
    padding: 20px 40px; /* Larger button */
    font-size: 28px;
    background-color: #007bff;
    color: white;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    transition: background-color 0.3s ease, transform 0.1s ease;
    font-family: 'Orbitron', sans-serif;
    font-weight: bold;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
}

#pause-overlay button:hover {
    background-color: #0056b3;
    transform: translateY(-2px);
}