:root {
    /* 2026 Vibrant Palette */
    --primary: #6c5ce7;
    --secondary: #a29bfe;
    --accent: #fdcb6e;
    --bg-gradient: linear-gradient(135deg, #74ebd5 0%, #9face6 100%);
    --glass: rgba(255, 255, 255, 0.25);
    --glass-border: rgba(255, 255, 255, 0.4);
    --shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.2);
}

body {
    margin: 0;
    padding: 0;
    font-family: 'Fredoka', 'Quicksand', 'Comic Sans MS', sans-serif;
    background: var(--bg-gradient);
    height: 100vh;
    overflow: hidden;
    color: white;
    touch-action: none; /* Prevents accidental zooming on tablets */
}

/* --- Screen Transitions --- */
.screen {
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: space-around;
    height: 100vh;
    width: 100vw;
    animation: fadeIn 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

.screen.active { display: flex; }

@keyframes fadeIn {
    from { 
        opacity: 0; 
        transform: scale(1.05); 
    }
    to { 
        opacity: 1; 
        transform: scale(1); 
    }
}

/* Optimized Track Card Layout */
.track-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 140px; /* Defined width for consistency */
    height: 120px;
    padding: 10px !important;
    background: white;
    border-radius: 20px;
    box-shadow: 0 8px 15px rgba(0,0,0,0.1);
}

.track-card img {
    width: 100px;
    height: 55px;
    object-fit: cover; /* Use cover to fill the 100x55 space perfectly */
    border-radius: 10px;
    margin-bottom: 8px;
    pointer-events: none;
    border: 2px solid #eee;
}

.track-card small {
    color: #2d3436;
    font-size: 1.2rem;
    font-weight: bold;
    text-transform: uppercase;
}

#screen-game {
    justify-content: flex-start; 
    padding-top: 80px;
}

#screen-game.active {
    display: block; 
    position: relative;
    padding: 0;
    margin: 0;
}

#race-track {
    position: absolute; /* Take over the whole screen */
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: 1; /* Sit behind the buttons/score */
    background-size: cover; /* Fill screen without stretching */
    background-position: center bottom; /* Keep the road at the bottom */
    border: none; /* Remove the old gray road bar */
}

#race-track.track-city {
    background: url('https://pojokutty.com/giggle-gears/assets/bg/city-bg.jpg') no-repeat center bottom;
    background-size: cover !important;
}

#race-track.track-desert {
    background: url('https://pojokutty.com/giggle-gears/assets/bg/desert-bg.jpg') no-repeat center bottom;
    background-size: cover !important;
}

#race-track.track-space {
    background: url('https://pojokutty.com/giggle-gears/assets/bg/space-bg.jpg') no-repeat center bottom;
    background-size: cover !important;
}

/* Car Positioning Fixes */
.anchor { position: absolute; font-size: 2.5rem; z-index: 10; }
.slot-roof-rear { top: -20px; left: 20%; }
.slot-roof-front { top: -25px; left: 50%; }
.slot-front { right: 10px; top: 40px; }
#driver-slot { position: absolute; top: -35px; left: 40%; font-size: 4rem; z-index: 3; }
.wheels-container { position: absolute; bottom: 20px; width: 100%; display: flex; justify-content: space-around; }
.headlight-beam { display: none; width: 120px; height: 50px; background: radial-gradient(circle at left, rgba(255,255,150,0.7), transparent); position: absolute; left: 40px; top: 0; }
.lights-on .headlight-beam { display: block; }

/* --- High-Quality Typography --- */
h1 {
    font-size: clamp(3rem, 10vw, 5rem);
    text-transform: uppercase;
    letter-spacing: 2px;
    filter: drop-shadow(0 5px 0 rgba(0,0,0,0.2));
    margin-bottom: 20px;
}

h2 {
    font-size: 2.5rem;
    background: rgba(255,255,255,0.2);
    padding: 10px 30px;
    border-radius: 50px;
    backdrop-filter: blur(4px);
}

/* --- Premium Buttons --- */
button, .item-btn {
    all: unset;
    cursor: pointer;
    background: var(--accent);
    padding: 20px 50px;
    border-radius: 25px;
    font-size: 2rem;
    font-weight: bold;
    color: #2d3436;
    box-shadow: 0 10px 0 #e17055, 0 15px 20px rgba(0,0,0,0.2);
    transition: all 0.1s ease;
    text-align: center;
}

button:active, .item-btn:active {
    transform: translateY(6px);
    box-shadow: 0 4px 0 #e17055, 0 5px 10px rgba(0,0,0,0.2);
}

/* --- The Bento-Box Controls --- */
.controls {
    background: var(--glass);
    backdrop-filter: blur(12px);
    border: 2px solid var(--glass-border);
    border-radius: 40px;
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 15px;
    padding: 25px;
    width: 90%;
    max-height: 50vh;
    overflow-y: auto;
    box-shadow: var(--shadow);
}

.control-group {
    background: rgba(255, 255, 255, 0.15);
    padding: 15px;
    border-radius: 25px;
    border: 1px solid rgba(255,255,255,0.2);
}

.selection-grid {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px;
}

/* Ensure the selection boxes fit images correctly */
.selection-grid .item {
    padding: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden; /* Keeps icons within the rounded borders */
}

/* Make icons fill the box without distorting */
.selection-grid .item img {
    width: 100%;
    height: 100%;
    object-fit: contain; /* Prevents stretching */
    pointer-events: none; /* Ensures clicking the image triggers the parent div's onclick */
}

/* Large Driver Icons */
.item {
    font-size: 6rem;
    background: white;
    width: 120px;
    height: 120px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 30px;
    box-shadow: 0 8px 15px rgba(0,0,0,0.1);
    transition: transform 0.2s;
}

.item:hover img {
    filter: drop-shadow(0 0 5px #00ffff) brightness(1.2);
}

/* --- The Car Preview --- */
#car-preview-container {
    width: 350px;
    height: 200px;
    position: relative;
    filter: drop-shadow(0 20px 30px rgba(0,0,0,0.3));
}

/* Ensure the body is visible and has a shape */
.car-base {
    position: absolute;
    bottom: 50px;
    width: 350px; /* Fixed width for the base */
    height: 80px;
    background-color: var(--car-color);
    border: 6px solid #2d3436;
    z-index: 2;
}

/* Classic car shape */
.body-classic { 
    border-radius: 80px 180px 20px 20px; 
}

/* Truck shape - make it taller */
.body-truck { 
    border-radius: 20px 20px 5px 5px; 
    height: 120px !important; 
    width: 300px; 
}

/* Wheels with spinning animation */
.wheel {
    width: 65px;
    height: 65px;
    background: #2d3436;
    border: 6px dashed #636e72;
    border-radius: 50%;
    position: relative;
    animation: drive 0.5s linear infinite;
}

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

/* --- Racing Scene HUD --- */
#score-display {
    position: fixed;
    top: 30px;
    left: 30px;
    font-size: 2.5rem;
    background: var(--accent);
    color: #2d3436;
    padding: 10px 30px;
    border-radius: 50px;
    box-shadow: 0 8px 0 #e17055;
    z-index: 100;
}

#exit-btn {
    position: fixed;
    top: 30px;
    right: 30px;
    padding: 10px 25px;
    font-size: 1.5rem;
    background: #ff7675;
    box-shadow: 0 6px 0 #d63031;
    z-index: 100;
}

/* Sticker & Extra Visual Polish */
.sticker-instance, .extra-item {
    filter: drop-shadow(2px 2px 0 rgba(0,0,0,0.2));
    z-index: 5;
}

/* Scrollbar for the Controls (Kid-friendly width) */
.controls::-webkit-scrollbar { width: 10px; }
.controls::-webkit-scrollbar-thumb { background: var(--accent); border-radius: 10px; }

/* Ensure the cloned container maintains its size */
#racing-car {
    width: 350px;
    height: 200px;
    position: absolute;
    bottom: 10%;
    left: -400px;
    z-index: 10;
    transform: scale(0.8);
    transform-origin: bottom left;
    transition: none; /* Prevent CSS transitions from fighting the JS loop */
}


/* Ensure children (body, wheels) don't collapse */
#racing-car .car-base {
    width: 100%;
    position: absolute;
    bottom: 50px;
}

#racing-car .wheels-container {
    width: 100%;
    bottom: 20px;
}

.main-btn {
    position: relative;
    z-index: 10;
    pointer-events: auto;
}

/* --- Fix Positioning of Car Parts --- */
.anchor {
    position: absolute;
    font-size: 2.5rem;
    z-index: 10;
}

.slot-roof-rear { top: -20px; left: 20%; }
.slot-roof-front { top: -25px; left: 50%; }
.slot-front { right: 10px; top: 40px; }

#driver-slot {
    position: absolute;
    top: -35px;
    left: 50%; /* Changed from 40% */
    transform: translateX(-50%); /* Ensures true center regardless of icon size */
    width: 100px; /* Set a fixed size for your custom icons */
    height: 100px;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 3;
}

#driver-slot img {
    width: 100%;
    height: auto;
}

#sticker-layer {
    position: absolute;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.sticker-instance {
    position: absolute;
    font-size: 1.5rem;
}

/* --- Wheel Positioning --- */
.wheels-container {
    position: absolute;
    bottom: 20px;
    width: 100%;
    display: flex;
    justify-content: space-around;
    z-index: 4;
}

/* --- Headlights Logic --- */
.headlight-beam {
    display: none;
    width: 100px;
    height: 40px;
    background: radial-gradient(circle at left, rgba(255,255,100,0.8), transparent);
    position: absolute;
    left: 40px;
    top: 0;
}

.lights-on .headlight-beam {
    display: block;
}


#screen-menu {
    background: 
        linear-gradient(rgba(0, 0, 0, 0.2), rgba(0, 0, 0, 0.2)), /* Darkens image slightly for contrast */
        url('https://pojokutty.com/giggle-gears/cover.jpg') no-repeat center center;
    background-size: cover;
    width: 100vw;
    height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

/* Make the title pop against the busy background */
#screen-menu h1 {
    color: #fff;
    text-shadow: 4px 4px 0px #ff4757, 8px 8px 15px rgba(0,0,0,0.5);
    margin-bottom: 40px;
}
