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

html,
body {
    width: 100%;
    height: 100%;
    overflow: hidden;
}

body {
    touch-action: none;
    overscroll-behavior: none;
}

.carGame {
    width: 100%;
    height: 100%;
    min-height: 100dvh;
    background: url("./images/bg_image.webp") center center / cover no-repeat;
    display: flex;
    flex-direction: column;
    position: relative;
    overscroll-behavior: none;
}

.startScreen {
    position: fixed;
    inset: 0;
    z-index: 60;
    display: grid;
    place-items: center;
    padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
    background: rgba(3, 7, 18, 0.5);
    backdrop-filter: blur(10px) saturate(120%);
    -webkit-backdrop-filter: blur(10px) saturate(120%);
}

.gameOverOverlay {
    position: fixed;
    inset: 0;
    z-index: 70;
    display: grid;
    place-items: center;
    padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
    background: rgba(3, 7, 18, 0.56);
    backdrop-filter: blur(10px) saturate(120%);
    -webkit-backdrop-filter: blur(10px) saturate(120%);
    overflow-y: auto;
}

.overlayCard {
    width: min(620px, 94vw);
    border-radius: 22px;
    padding: clamp(20px, 3vw, 34px);
    text-align: center;
    color: #f8fafc;
    background: linear-gradient(145deg, rgba(10, 15, 30, 0.92) 0%, rgba(24, 33, 58, 0.88) 100%);
    border: 1px solid rgba(255, 255, 255, 0.2);
    box-shadow: 0 22px 52px rgba(0, 0, 0, 0.5), 0 0 26px rgba(34, 197, 94, 0.18);
}

.overlayCard h1,
.overlayCard h2 {
    margin: 0;
    font-size: clamp(30px, 5vw, 52px);
    line-height: 1.1;
    color: #fef08a;
    letter-spacing: 1px;
    text-shadow: 0 0 18px rgba(254, 240, 138, 0.28);
}

.overlaySubtitle {
    margin: 12px 0 16px;
    font-size: clamp(14px, 2vw, 19px);
    color: rgba(241, 245, 249, 0.92);
}

.leaderboardPanel {
    margin: 10px 0 0;
    padding: 14px;
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.14);
    text-align: left;
}

.leaderboardPanel h3 {
    margin: 0 0 10px;
    font-size: 13px;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    color: #fef08a;
}

.leaderboardList {
    list-style: none;
    margin: 0;
    padding: 0;
    display: grid;
    gap: 8px;
    max-height: 140px;
    overflow-y: auto;
    scrollbar-width: thin;
}

.leaderboardList li {
    display: grid;
    grid-template-columns: auto 1fr auto auto;
    gap: 10px;
    align-items: center;
    padding: 10px 12px;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: #f8fafc;
}

.leaderboardRank {
    color: #fef08a;
    font-weight: 700;
}

.leaderboardName {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.leaderboardScore {
    font-weight: 700;
}

.leaderboardMeta {
    color: rgba(241, 245, 249, 0.68);
    font-size: 0.84rem;
    white-space: nowrap;
}

.leaderboardEmpty {
    color: rgba(241, 245, 249, 0.72);
    font-size: 0.92rem;
    padding: 6px 2px;
    grid-column: 1 / -1;
    text-align: center;
}

.overlayInstructions {
    padding: 14px 14px 2px;
    border-radius: 14px;
    margin: 0 auto;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.15);
}

.overlayInstructions p {
    margin: 0 0 12px;
    font-size: clamp(13px, 1.7vw, 16px);
    line-height: 1.45;
}

.overlayActions {
    margin-top: 18px;
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 12px;
}

.overlayBtn {
    border: none;
    border-radius: 12px;
    padding: 12px 20px;
    min-height: 44px;
    font-size: 15px;
    font-weight: 700;
    letter-spacing: 0.25px;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    touch-action: manipulation;
}

.overlayBtn:hover {
    transform: translateY(-1px);
}

.overlayBtn.primary {
    color: #0f172a;
    background: linear-gradient(135deg, #fef08a 0%, #facc15 100%);
    box-shadow: 0 10px 24px rgba(250, 204, 21, 0.35);
}

.overlayBtn.secondary {
    color: #f8fafc;
    background: rgba(255, 255, 255, 0.12);
    border: 1px solid rgba(255, 255, 255, 0.24);
}

.gameStage {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: stretch;
    width: 100%;
    height: 100%;
    min-height: 0;
    touch-action: none;
}

.carGame.is-mobile .gameStage,
.carGame.is-mobile .gameArea {
    cursor: default;
}

.score {
    position: absolute;
    top: max(12px, env(safe-area-inset-top));
    left: 50%;
    transform: translateX(-50%);
    background: #123047;
    text-align: center;
    color: white;
    height: clamp(46px, 8vh, 70px);
    width: clamp(120px, 36vw, 150px);
    border: 2px solid #facc15;
    border-radius: 12px;
    font-size: clamp(0.95rem, 2.6vw, 1.5rem);
    box-shadow: 0 5px 16px rgba(3, 15, 28, 0.45), 0 0 12px rgba(250, 204, 21, 0.25);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 30;
    white-space: nowrap;
    pointer-events: none;
}

.hide {
    display: none !important;
}

.car,
.enemyCar {
    width: clamp(34px, 10vw, 40px);
    height: clamp(60px, 17vw, 70px);
    background-image: url("./images/car4.webp");
    background-size: 100% 100%;
    background-position: center;
    background-repeat: no-repeat;
    position: absolute;
    left: 50%;
    bottom: 120px;
}

.gameArea {
    width: min(400px, 100%);
    height: 100%;
    min-height: 100%;
    margin: 0 auto;
    background-color: #2d3436;
    position: relative;
    overflow: hidden;
    border-right: 7px dashed #c8d6e5;
    border-left: 7px dashed #c8d6e5;
    touch-action: none;
    flex-shrink: 0;
}

.line {
    width: 12px;
    height: 100px;
    background: white;
    position: absolute;
    left: calc(50% - 6px);
}

/* Mobile portrait — full-width road, touch steering only */
@media (max-width: 900px) and (max-aspect-ratio: 1/1) {
    .gameStage {
        width: 100%;
        min-height: 100dvh;
    }

    .gameArea {
        width: 100%;
        max-width: none;
        height: 100%;
        min-height: 100dvh;
        margin: 0;
        flex: 1;
    }

    .overlayCard {
        max-height: calc(100dvh - 32px);
        overflow-y: auto;
    }
}

/* Mobile landscape — full-width road, touch steering only */
@media (max-height: 600px) and (min-aspect-ratio: 1/1) {
    .carGame {
        min-height: 100dvh;
    }

    .gameStage {
        width: 100%;
        height: 100%;
        min-height: 100dvh;
    }

    .gameArea {
        width: 100%;
        max-width: none;
        height: 100%;
        min-height: 100dvh;
        margin: 0;
        flex: 1;
    }

    .score {
        height: 38px;
        font-size: 0.82rem;
        width: 108px;
    }

    .overlayCard {
        width: min(560px, 96vw);
        padding: 16px 18px;
    }

    .overlayCard h1,
    .overlayCard h2 {
        font-size: clamp(22px, 4vw, 36px);
    }

    .leaderboardList {
        max-height: 72px;
    }
}
