:root {
    --bg-color: #fdf2f8;
    --board-bg: #2d3748; /* Asphalt Road color */
    
    /* Variables driven by JS now */
    --accent-color: #fb7185;
    /* Vibrant skin/rose accent */
    --accent-glow: rgba(251, 113, 133, 0.4);
    --glass-bg: rgba(255, 255, 255, 0.6);
    --glass-border: rgba(0, 0, 0, 0.05);
    --text-primary: #881337;
    /* Rosewood for high contrast */
    --text-secondary: #be123c;

    /* Classic Car Palette - Glossy and Solid */
    --car-red: linear-gradient(135deg, #f43f5e 0%, #9f1239 100%);
    --car-blue: linear-gradient(135deg, #0ea5e9 0%, #075985 100%);
    --car-green: linear-gradient(135deg, #10b981 0%, #064e3b 100%);
    --car-yellow: linear-gradient(135deg, #f59e0b 0%, #78350f 100%);
    --car-purple: linear-gradient(135deg, #8b5cf6 0%, #4c1d95 100%);
    --car-orange: linear-gradient(135deg, #f97316 0%, #7c2d12 100%);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Outfit', sans-serif;
}

body {
    background-color: #1a1025;
    color: var(--text-primary);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    overflow-y: auto;
    overflow-x: hidden;
}

/* Screen Management */
.screen {
    display: none;
    width: 100%;
    min-height: 100vh;
    flex-direction: column;
    padding: 1.5rem 2rem;
    gap: 1.2rem;
    animation: fadeIn 0.5s ease-out;
    position: relative;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
}

.screen.active {
    display: flex;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

#game-container {
    background-image:
        linear-gradient(180deg, rgba(26,16,37,0.92) 0%, rgba(30,20,50,0.88) 100%),
        url('images/level_select_bg.png');
    background-size: cover;
    background-position: center;
    max-width: 100%;
    padding: 0;
    gap: 0;
}

/* ── Gameplay Header ── */
.game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    padding: 0.8rem 1.2rem;
    background: rgba(0,0,0,0.4);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid rgba(255,255,255,0.07);
    position: sticky;
    top: 0;
    z-index: 50;
    flex-shrink: 0;
    flex-wrap: wrap;
    gap: 0.4rem;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

.icon-button-sm {
    width: 38px;
    height: 38px;
    font-size: 0.9rem;
    flex-shrink: 0;
}

/* Loading Screen */
#loading-screen {
    justify-content: center;
    align-items: center;
    gap: 4rem;
    background-image:
        linear-gradient(180deg, rgba(26,16,37,0.55) 0%, rgba(20,10,35,0.75) 100%),
        url('images/loading_bg.png');
    background-size: cover;
    background-position: center;
    max-width: 100%;
}

.logo-large {
    font-size: 3.5rem;
    text-align: center;
    line-height: 1.1;
    color: #fff;
    text-shadow:
        0 0 30px var(--accent-glow),
        0 0 60px var(--accent-glow),
        0 4px 8px rgba(0,0,0,0.5);
    letter-spacing: 2px;
}

.loader-container {
    width: 100%;
    max-width: 380px;
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.5rem;
    background: rgba(0,0,0,0.45);
    border: 1.5px solid rgba(255,255,255,0.08);
    border-radius: 24px;
    padding: 3rem 2.5rem 2rem;
    backdrop-filter: blur(16px);
    box-shadow: 0 15px 50px rgba(0,0,0,0.3);
}

.loader-car {
    position: absolute;
    bottom: 70px;
    left: 0;
    width: 80px;
    height: 40px;
    background: var(--car-blue);
    transform: translateX(-50%);
    transition: left 0.3s linear;
}

.loader-bar {
    width: 100%;
    height: 14px;
    background: rgba(255,255,255,0.15);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 7px;
    overflow: hidden;
    box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.3);
}

.loader-progress {
    width: 0%;
    height: 100%;
    background: linear-gradient(90deg, var(--accent-color), #f43f5e, #fb923c);
    border-radius: 7px;
    box-shadow: 0 0 20px var(--accent-glow);
    transition: width 0.3s linear;
}

.loader-text {
    font-weight: 800;
    color: rgba(255,255,255,0.9);
    font-size: 1.2rem;
    letter-spacing: 3px;
    text-shadow: 0 2px 6px rgba(0,0,0,0.4);
}

/* Level Select Screen */
#level-select-screen {
    justify-content: flex-start;
    align-items: stretch;
}

#level-select-screen {
    padding-bottom: 1.5rem;
    background-image:
        linear-gradient(180deg, rgba(26,16,37,0.82) 0%, rgba(30,20,50,0.9) 100%),
        url('images/level_select_bg.png');
    background-size: cover;
    background-position: center;
    max-width: 100%;
}

#level-select-screen .level-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    max-width: 650px;
    margin: 0 auto;
    flex-shrink: 0;
}

#level-select-screen .level-header .logo {
    color: #fff;
    text-shadow: 0 2px 10px rgba(0,0,0,0.5);
}

.levels-wrapper {
    flex-grow: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    width: 100%;
    max-width: 650px;
    margin: 0 auto;
    background: rgba(0,0,0,0.35);
    border: 1.5px solid rgba(255,255,255,0.06);
    border-radius: 20px;
    padding: 1.5rem;
    backdrop-filter: blur(10px);
    box-shadow: 0 10px 40px rgba(0,0,0,0.2);
}

.levels-grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 10px;
    width: 100%;
    transition: opacity 0.3s ease, transform 0.3s ease;
}

/* ── Bottom Pagination Bar ── */
.level-pagination-bar {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1.5rem;
    width: 100%;
    max-width: 650px;
    margin: 0 auto;
    padding: 0.75rem 1rem;
    background: rgba(255,255,255,0.08);
    border: 1.5px solid rgba(255,255,255,0.1);
    border-radius: 20px;
    backdrop-filter: blur(12px);
    box-shadow: 0 4px 20px rgba(0,0,0,0.15);
    flex-shrink: 0;
}

.page-dots {
    display: flex;
    align-items: center;
    gap: 8px;
}

.page-dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    border: 1px solid rgba(255, 255, 255, 0.25);
    background: rgba(255, 255, 255, 0.2);
    cursor: pointer;
    transition: all 0.25s ease;
}

.page-dot.active {
    width: 18px;
    border-radius: 10px;
    background: var(--accent-color);
    border-color: rgba(255, 255, 255, 0.4);
    box-shadow: 0 0 14px var(--accent-glow);
}

.pagination-arrow-btn {
    background: linear-gradient(135deg, var(--accent-color), #f43f5e);
    border: none;
    color: #fff;
    width: 46px;
    height: 46px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1rem;
    cursor: pointer;
    box-shadow: 0 4px 14px var(--accent-glow);
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    flex-shrink: 0;
}

.pagination-arrow-btn:hover {
    transform: scale(1.15) translateY(-2px);
    box-shadow: 0 8px 24px var(--accent-glow);
}

.pagination-arrow-btn:active {
    transform: scale(0.95);
}

.pagination-arrow-btn:disabled {
    background: rgba(255,255,255,0.15);
    box-shadow: none;
    cursor: not-allowed;
    transform: none;
    opacity: 0.4;
}

.page-indicator {
    font-size: 1rem;
    font-weight: 700;
    color: rgba(255,255,255,0.7);
    letter-spacing: 1px;
    text-transform: uppercase;
    min-width: 80px;
    text-align: center;
}

.level-btn {
    aspect-ratio: 1 / 1.1;
    border-radius: 14px;
    background: rgba(255,255,255,0.08);
    border: 1.5px solid rgba(255,255,255,0.1);
    backdrop-filter: blur(8px);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    font-size: 1.2rem;
    font-weight: 800;
    color: rgba(255,255,255,0.9);
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.level-stars {
    display: flex;
    gap: 2px;
    margin-top: 4px;
}

.mini-star {
    font-size: 0.6rem;
    color: rgba(255,255,255,0.25);
}

.mini-star.earned {
    color: #fbbf24;
}

.level-btn:hover:not(.locked) {
    transform: translateY(-5px) scale(1.05);
    box-shadow: 0 15px 30px rgba(0, 0, 0, 0.25);
    border-color: var(--accent-glow);
    background: rgba(251,113,133,0.15);
    color: #fff;
}

.level-btn.locked {
    opacity: 0.4;
    cursor: not-allowed;
    background: rgba(255, 255, 255, 0.03);
    color: transparent;
    position: relative;
}

.level-btn.locked::after {
    content: '\f023';
    font-family: 'Font Awesome 6 Free';
    font-weight: 900;
    position: absolute;
    font-size: 1rem;
    color: rgba(255,255,255,0.35);
}

.level-btn.completed {
    background: linear-gradient(135deg, rgba(16,185,129,0.15), rgba(16,185,129,0.25));
    border-color: rgba(16, 185, 129, 0.4);
}

.icon-button {
    background: rgba(255,255,255,0.1);
    border: 1.5px solid rgba(255,255,255,0.15);
    width: 48px;
    height: 48px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.1rem;
    color: #fff;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    backdrop-filter: blur(8px);
}

.icon-button:hover {
    transform: scale(1.12) translateY(-2px);
    box-shadow: 0 8px 20px rgba(251,113,133,0.3);
    background: rgba(251,113,133,0.2);
    color: #fb7185;
}

/* Confetti particles */
#particles-container {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 999;
}

.confetti {
    position: absolute;
    width: 10px;
    height: 10px;
    background-color: var(--accent-color);
    animation: fall 3s linear forwards;
}

@keyframes fall {
    to {
        transform: translateY(100vh) rotate(720deg);
        opacity: 0;
    }
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.logo {
    font-size: 1.5rem;
    font-weight: 800;
    letter-spacing: -0.5px;
    color: #fff;
}

.logo span {
    color: var(--accent-color);
    text-shadow: 0 0 20px var(--accent-glow);
}

header .stats {
    display: flex;
    align-items: center;
    gap: 1.5rem;
    font-size: 1.1rem;
    font-weight: 700;
    color: rgba(255,255,255,0.7);
    text-transform: uppercase;
}

.lives-indicator {
    display: flex;
    gap: 6px;
    align-items: center;
    margin-right: 15px;
    padding-right: 15px;
    border-right: 2px solid rgba(255,255,255,0.15);
}

.life-dot {
    width: 14px;
    height: 14px;
    background: radial-gradient(circle, #fb7185, #e11d48);
    border-radius: 50%;
    box-shadow: 0 0 8px rgba(251, 113, 133, 0.8), inset 0 -2px 4px rgba(0,0,0,0.3);
    transition: all 0.3s ease;
}

.life-dot.lost {
    background: #4b5563;
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.5);
    opacity: 0.4;
}

.stat-item {
    font-size: 0.9rem;
    color: rgba(255,255,255,0.6);
    text-transform: uppercase;
    font-weight: 600;
}

.stat-item span {
    color: #fff;
    font-size: 1.1rem;
    margin-left: 0.5rem;
}

#board-wrapper {
    flex-grow: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    perspective: 1200px;
    width: 100%;
    max-width: 650px;
    margin: 0 auto;
}

#game-board {
    width: 95vw;
    max-width: 80vh;
    height: 95vw;
    max-height: 80vh;
    aspect-ratio: 1 / 1;
    background-color: #262c36;
    background-image: url('https://www.transparenttextures.com/patterns/asfalt-light.png');
    border-radius: 20px;
    position: relative;
    box-shadow:
        0 15px 45px rgba(0, 0, 0, 0.4),
        0 0 80px rgba(251,113,133,0.08),
        inset 0 0 20px rgba(0, 0, 0, 0.5);
    border: 3px solid rgba(255,255,255,0.08);
    padding: 12px;
    margin: auto;
}

/* REMOVE grid lines to mimic pure road */
#game-board::before {
    display: none;
}

/* STATIC OBSTACLES */
.obstacle {
    position: absolute;
    width: calc(var(--cell-size) - 8px);
    height: calc(var(--cell-size) - 8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 5;
    border-radius: 8px;
}

.obstacle.stone {
    background: radial-gradient(circle at 30% 30%, #9ca3af, #4b5563);
    box-shadow: 
        inset 2px 2px 5px rgba(255,255,255,0.2),
        inset -2px -2px 5px rgba(0,0,0,0.5),
        2px 5px 10px rgba(0,0,0,0.4);
    border: 1px solid #374151;
}

.obstacle.box {
    background: linear-gradient(135deg, #d97706, #92400e);
    box-shadow: 
        inset 2px 2px 4px rgba(255,255,255,0.3),
        inset -2px -2px 5px rgba(0,0,0,0.6),
        2px 5px 10px rgba(0,0,0,0.4);
    border: 1px solid #78350f;
    border-radius: 4px;
}

/* Wood grain lines for box */
.obstacle.box::before {
    content: '';
    position: absolute;
    inset: 4px;
    border: 1px dashed rgba(0,0,0,0.3);
}

/* CLASSIC CAR BODY STYLING */
.car {
    position: absolute;
    cursor: pointer;
    transition: left 0.15s linear, top 0.15s linear, transform 0.15s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    touch-action: none;
    filter: drop-shadow(0 10px 10px rgba(0, 0, 0, 0.15));
}

.car:active {
    transform: scale(0.95);
}

/* CRASH ANIMATION */
@keyframes crashShake {
    0% { transform: translate(0, 0) scale(1); filter: brightness(1) drop-shadow(0 0 0 red); }
    20% { transform: translate(-3px, 2px) scale(0.98); filter: brightness(1.5) drop-shadow(0 0 10px red); }
    40% { transform: translate(3px, -2px) scale(0.98); }
    60% { transform: translate(-3px, -2px) scale(0.98); }
    80% { transform: translate(3px, 2px) scale(0.98); }
    100% { transform: translate(0, 0) scale(1); filter: brightness(1) drop-shadow(0 0 0 red); }
}

.car.crash-shake {
    animation: crashShake 0.4s ease-in-out;
}

/* Base Body - Rounded Classic Shape */
.car-body {
    position: absolute;
    inset: 0;
    border-radius: 16px;
    border: 1.5px solid rgba(255, 255, 255, 0.25);
    box-shadow:
        inset 0 4px 8px rgba(255, 255, 255, 0.3),
        inset 0 -4px 8px rgba(0, 0, 0, 0.3);
}

/* Hood/Trunk lines */
.car-body::after {
    content: '';
    position: absolute;
    background: rgba(0, 0, 0, 0.15);
}

.car.horizontal .car-body::after {
    width: 2px;
    height: 70%;
    right: 25%;
    top: 15%;
}

.car.vertical .car-body::after {
    width: 70%;
    height: 2px;
    bottom: 25%;
    left: 15%;
}

/* Classic Cabin - Top Down */
.car-cabin {
    position: absolute;
    background: #0a0a0a;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.4);
    z-index: 5;
    overflow: hidden;
}

/* Windshield/Rear Window gloss */
.car-cabin::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.1) 0%, transparent 50%, rgba(255, 255, 255, 0.05) 100%);
}

.car.horizontal .car-cabin {
    width: 50%;
    height: 80%;
    left: 15%;
}

.car.vertical .car-cabin {
    width: 80%;
    height: 50%;
    top: 15%;
}

/* CLASSIC CHROME DETAILS */
.mirror {
    position: absolute;
    width: 6px;
    height: 4px;
    background: #e2e8f0;
    border-radius: 2px;
    z-index: -1;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.car.horizontal .m-left {
    top: -2px;
    left: 35%;
}

.car.horizontal .m-right {
    bottom: -2px;
    left: 35%;
}

.car.vertical .m-left {
    left: -2px;
    top: 35%;
}

.car.vertical .m-right {
    right: -2px;
    top: 35%;
}

/* CLASSIC LARGE WHEELS */
.wheel {
    position: absolute;
    width: calc(var(--cell-size) * 0.23);
    height: calc(var(--cell-size) * 0.33);
    background: #111;
    border-radius: calc(var(--cell-size) * 0.05);
    z-index: -2;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.car.horizontal .wheel {
    width: calc(var(--cell-size) * 0.33);
    height: calc(var(--cell-size) * 0.23);
}

.car.horizontal .w-tl { top: calc(var(--cell-size) * -0.03); left: 10%; }
.car.horizontal .w-tr { top: calc(var(--cell-size) * -0.03); right: 10%; }
.car.horizontal .w-bl { bottom: calc(var(--cell-size) * -0.03); left: 10%; }
.car.horizontal .w-br { bottom: calc(var(--cell-size) * -0.03); right: 10%; }

.car.vertical .w-tl { left: calc(var(--cell-size) * -0.03); top: 10%; }
.car.vertical .w-tr { left: calc(var(--cell-size) * -0.03); bottom: 10%; }
.car.vertical .w-bl { right: calc(var(--cell-size) * -0.03); top: 10%; }
.car.vertical .w-br { right: calc(var(--cell-size) * -0.03); bottom: 10%; }

/* CLASSIC ROUND LIGHTS */
.lights-front,
.lights-back {
    position: absolute;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 15;
}

.lights-front::before,
.lights-front::after {
    content: '';
    position: absolute;
    width: calc(var(--cell-size) * 0.16);
    height: calc(var(--cell-size) * 0.16);
    background: radial-gradient(circle, #fff 0%, #cbd5e1 100%);
    border-radius: 50%;
    box-shadow: 0 0 calc(var(--cell-size) * 0.15) #fff;
}

.lights-back::before,
.lights-back::after {
    content: '';
    position: absolute;
    width: calc(var(--cell-size) * 0.13);
    height: calc(var(--cell-size) * 0.06);
    background: #ef4444;
    border-radius: calc(var(--cell-size) * 0.03);
    box-shadow: 0 0 calc(var(--cell-size) * 0.2) #ef4444;
}

/* Horizontal Light Placements */
.car.horizontal .lights-front::before {
    right: calc(var(--cell-size) * -0.03);
    top: 18%;
}

.car.horizontal .lights-front::after {
    right: calc(var(--cell-size) * -0.03);
    bottom: 18%;
}

.car.horizontal .lights-back::before {
    left: calc(var(--cell-size) * 0.06);
    top: 22%;
    width: calc(var(--cell-size) * 0.06);
    height: calc(var(--cell-size) * 0.13);
}

.car.horizontal .lights-back::after {
    left: calc(var(--cell-size) * 0.06);
    bottom: 22%;
    width: calc(var(--cell-size) * 0.06);
    height: calc(var(--cell-size) * 0.13);
}

/* Vertical Light Placements */
.car.vertical .lights-front::before {
    bottom: calc(var(--cell-size) * -0.03);
    left: 18%;
}

.car.vertical .lights-front::after {
    bottom: calc(var(--cell-size) * -0.03);
    right: 18%;
}

.car.vertical .lights-back::before {
    top: calc(var(--cell-size) * 0.06);
    left: 22%;
}

.car.vertical .lights-back::after {
    top: calc(var(--cell-size) * 0.06);
    right: 22%;
}

footer {
    display: flex;
    justify-content: center;
    gap: 1.5rem;
    width: 100%;
    padding: 0.9rem 1rem 1.2rem;
}

.glass-button {
    background: rgba(255,255,255,0.1);
    border: 1px solid rgba(255,255,255,0.15);
    color: #fff;
    padding: 0.9rem 2rem;
    border-radius: 16px;
    font-weight: 600;
    cursor: pointer;
    backdrop-filter: blur(12px);
    transition: all 0.3s ease;
    text-transform: uppercase;
    letter-spacing: 1px;
    font-size: 0.85rem;
}

.back-level-button {
    border-color: rgba(251, 113, 133, 0.45);
    background: rgba(251, 113, 133, 0.16);
}

.glass-button:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: translateY(-3px);
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.15);
}

.glow-button {
    background: linear-gradient(135deg, var(--accent-color), #f43f5e);
    border: none;
    color: #fff;
    padding: 1.4rem 3rem;
    border-radius: 20px;
    font-weight: 800;
    text-transform: uppercase;
    cursor: pointer;
    box-shadow: 0 0 40px var(--accent-glow);
    transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    margin-top: 1.5rem;
    letter-spacing: 2px;
}

.glow-button:hover {
    transform: scale(1.08) translateY(-4px);
    box-shadow: 0 0 60px var(--accent-glow);
}

#ui-overlay {
    position: fixed;
    inset: 0;
    background-image:
        linear-gradient(180deg, rgba(10,5,20,0.55) 0%, rgba(10,5,20,0.65) 100%),
        url('images/congrats_bg.png');
    background-size: cover;
    background-position: center;
    backdrop-filter: blur(6px);
    z-index: 100;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: opacity 0.5s ease;
}

#ui-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.glass-card {
    background: rgba(255,255,255,0.08);
    border: 1.5px solid rgba(255,255,255,0.12);
    padding: 3rem 0.5rem;
    border-radius: 30px;
    text-align: center;
    box-shadow: 0 30px 80px rgba(0, 0, 0, 0.3);
    width: 90%;
    max-width: 520px;
    backdrop-filter: blur(20px);
}

.glass-card h2 {
    font-size: 1.8rem;
    font-weight: 900;
    margin-bottom: 1rem;
    background: linear-gradient(to bottom, #fbbf24, #f97316);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    letter-spacing: 1px;
    text-shadow: none;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.glass-card p {
    color: rgba(255,255,255,0.7);
    margin-bottom: 2.5rem;
    font-size: 1.2rem;
    font-weight: 500;
}

.overlay-buttons {
    display: flex;
    justify-content: center;
    gap: 1rem;
    margin-top: 1.5rem;
}

.overlay-buttons button {
    margin-top: 0;
}

/* Star Rating Styles */
.star-rating {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin: 1.5rem 0;
}

.star {
    font-size: 3rem;
    color: #cbd5e1;
    /* off color */
    text-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
    transition: all 0.3s ease;
}

.star.active {
    color: #fbbf24;
    /* gold */
    text-shadow: 0 0 20px rgba(251, 191, 36, 0.6);
    transform: scale(1.1);
}

@keyframes exiting-right {
    to {
        transform: translateX(500px);
        opacity: 0;
    }
}

@keyframes exiting-left {
    to {
        transform: translateX(-500px);
        opacity: 0;
    }
}

@keyframes exiting-up {
    to {
        transform: translateY(-500px);
        opacity: 0;
    }
}

@keyframes exiting-down {
    to {
        transform: translateY(500px);
        opacity: 0;
    }
}

.car.exiting-right {
    animation: exiting-right 0.6s forwards cubic-bezier(0.45, 0.05, 0.55, 0.95);
}

.car.exiting-left {
    animation: exiting-left 0.6s forwards cubic-bezier(0.45, 0.05, 0.55, 0.95);
}

.car.exiting-up {
    animation: exiting-up 0.6s forwards cubic-bezier(0.45, 0.05, 0.55, 0.95);
}

.car.exiting-down {
    animation: exiting-down 0.6s forwards cubic-bezier(0.45, 0.05, 0.55, 0.95);
}

@media (max-width: 960px) {
    .screen {
        padding: 1rem;
    }

    .logo-large {
        font-size: 2.6rem;
    }

    .loader-container {
        max-width: 360px;
        padding: 2.6rem 1.6rem 1.6rem;
    }

    #loading-screen {
        gap: 2rem;
    }

    #level-select-screen .level-header,
    .levels-wrapper,
    .level-pagination-bar,
    #board-wrapper {
        max-width: 96vw;
    }

    #game-board {
        width: min(94vw, 92vh);
        height: min(94vw, 92vh);
    }
}

@media (max-width: 640px) {
    body {
        align-items: flex-start;
    }

    .screen {
        min-height: 100dvh;
        padding: 0.8rem;
        gap: 0.8rem;
    }

    .logo {
        font-size: 1.1rem;
    }

    .logo-large {
        font-size: 1.9rem;
        letter-spacing: 1px;
    }

    .loader-container {
        max-width: 100%;
        border-radius: 18px;
        padding: 2rem 1rem 1.2rem;
        gap: 0.9rem;
    }

    .loader-car {
        width: 68px;
        height: 34px;
        bottom: 50px;
    }

    .loader-text {
        font-size: 1rem;
    }

    #level-select-screen .level-header {
        padding: 0 0.2rem;
    }

    .levels-wrapper {
        padding: 0.7rem;
        border-radius: 16px;
    }

    .levels-grid {
        grid-template-columns: repeat(5, minmax(0, 1fr));
        gap: 7px;
    }

    .level-btn {
        border-radius: 10px;
        font-size: 0.95rem;
        min-height: 48px;
    }

    .mini-star {
        font-size: 0.52rem;
    }

    .level-pagination-bar {
        gap: 0.8rem;
        padding: 0.55rem 0.65rem;
        border-radius: 16px;
    }

    .pagination-arrow-btn {
        width: 40px;
        height: 40px;
        font-size: 0.9rem;
    }

    .page-indicator {
        font-size: 0.83rem;
        min-width: 74px;
    }

    .icon-button {
        width: 40px;
        height: 40px;
        font-size: 0.95rem;
    }

    .game-header {
        padding: 0.6rem 0.7rem;
        gap: 0.35rem;
    }

    header .stats {
        gap: 0.65rem;
        font-size: 0.82rem;
        width: 100%;
        justify-content: flex-end;
    }

    .lives-indicator {
        margin-right: 0;
        padding-right: 0.5rem;
    }

    .life-dot {
        width: 10px;
        height: 10px;
    }

    .stat-item {
        font-size: 0.75rem;
    }

    .stat-item span {
        font-size: 0.95rem;
        margin-left: 0.25rem;
    }

    #board-wrapper {
        align-items: flex-start;
        padding-top: 0.2rem;
    }

    #game-board {
        width: min(96vw, 520px);
        height: min(96vw, 520px);
        border-radius: 14px;
        padding: 10px;
    }

    footer {
        gap: 0.6rem;
        padding: 0.6rem 0.7rem 0.9rem;
    }

    .glass-button {
        padding: 0.72rem 1.25rem;
        border-radius: 12px;
        font-size: 0.73rem;
    }

    .glass-card {
        width: calc(100% - 1.2rem);
        padding: 2rem 1rem;
        border-radius: 20px;
    }

    .glass-card h2 {
        font-size: 1.45rem;
    }

    .glass-card p {
        margin-bottom: 1.25rem;
        font-size: 1rem;
    }

    .star {
        font-size: 2.2rem;
    }

    .overlay-buttons {
        flex-direction: row;
        gap: 0.7rem;
    }

    .overlay-buttons .glass-button,
    .overlay-buttons .glow-button {
        margin: 0;
        padding: 0.8rem 1rem;
        border-radius: 14px;
        letter-spacing: 1px;
    }
}

@media (max-width: 360px) {
    .screen {
        padding: 0.55rem;
    }

    .logo-large {
        font-size: 1.62rem;
    }

    .loader-container {
        padding: 1.8rem 0.8rem 1rem;
    }

    .loader-bar {
        height: 11px;
    }

    .levels-grid {
        gap: 5px;
    }

    .level-btn {
        font-size: 0.82rem;
        min-height: 42px;
        border-radius: 8px;
    }

    .page-indicator {
        font-size: 0.72rem;
        min-width: 60px;
    }

    #game-board {
        width: 98vw;
        height: 98vw;
        padding: 8px;
        border-radius: 12px;
    }

    .glass-button {
        padding: 0.68rem 0.95rem;
        font-size: 0.68rem;
    }

    .stat-item {
        font-size: 0.67rem;
    }

    .stat-item span {
        font-size: 0.84rem;
    }
}
