*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box
}

:root {
    --bg: #0c1220;
    --bg2: #162032;
    --bg3: #1e2d44;
    --tx: #e2e8f0;
    --tx2: #64778c;
    --red: #ef4444;
    --red-d: #b91c1c;
    --blue: #0ea5e9;
    --blue-d: #0369a1;
    --cyan: #22d3ee;
    --gold: #fbbf24;
    --green: #22c55e;
    --r: 14px;
    --rs: 8px;
    --cell: min(14.5vw, 64px);
    --font: 'Segoe UI', system-ui, -apple-system, sans-serif;
}

html,
body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    font-family: var(--font);
    background: var(--bg);
    color: var(--tx);
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    -webkit-user-select: none
}

/* ── Screens ── */
.screen {
    position: fixed;
    inset: 0;
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 10;
    background: var(--bg)
}

.screen.active {
    display: flex
}

.screen-inner {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    padding: 20px;
    width: 100%;
    max-width: 400px;
    animation: fadeUp .35s ease both
}

/* ── Start ── */
.logo-icon {
    width: 64px;
    height: 64px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    color: var(--red);
    background: rgba(239, 68, 68, .08);
    border: 2px solid rgba(239, 68, 68, .15)
}

.game-title {
    font-size: clamp(42px, 11vw, 64px);
    font-weight: 800;
    line-height: 1.05;
    text-align: center;
    letter-spacing: -1.5px
}

.game-title span {
    color: var(--cyan)
}

.tagline {
    font-size: 13px;
    color: var(--tx2);
    text-align: center;
    letter-spacing: .5px
}

.progress-box {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    background: var(--bg2);
    padding: 12px 40px;
    border-radius: var(--r);
    border: 1px solid rgba(255, 255, 255, .04)
}

.progress-box .label,
.score-row .label {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: var(--tx2)
}

.progress-box .value {
    font-size: 26px;
    font-weight: 800;
    color: var(--gold);
    line-height: 1.2
}

/* ── Buttons ── */
.btn {
    border: none;
    outline: none;
    cursor: pointer;
    font-family: var(--font);
    font-weight: 700;
    border-radius: var(--r);
    transition: transform .1s, background .15s;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px
}

.btn:active {
    transform: scale(.93)
}

.btn-primary {
    padding: 15px 56px;
    font-size: 17px;
    color: #fff;
    background: var(--red);
    box-shadow: 0 4px 18px rgba(239, 68, 68, .2)
}

.btn-primary:hover {
    background: #f87171
}

.btn-secondary {
    padding: 11px 28px;
    font-size: 13px;
    color: var(--tx2);
    background: var(--bg2);
    border: 1px solid rgba(255, 255, 255, .05)
}

.btn-secondary:hover {
    background: var(--bg3);
    color: var(--tx)
}

.btn-outline {
    padding: 10px 22px;
    font-size: 13px;
    color: var(--tx2);
    background: transparent;
    border: 1px solid rgba(255, 255, 255, .07)
}

.btn-outline:hover {
    border-color: rgba(255, 255, 255, .15);
    color: var(--tx)
}

.btn-outline svg {
    opacity: .5
}

/* ── Level Select ── */
.level-select-inner {
    max-width: 360px;
    max-height: 100vh;
    overflow-y: auto
}

.section-title {
    font-size: 21px;
    font-weight: 800;
    letter-spacing: -.3px
}

.level-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 9px;
    width: 100%;
    padding: 6px 0
}

.level-cell {
    aspect-ratio: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--rs);
    font-weight: 700;
    font-size: 15px;
    cursor: pointer;
    position: relative;
    background: var(--bg2);
    border: 1px solid rgba(255, 255, 255, .04);
    color: var(--tx2);
    transition: transform .1s, background .15s
}

.level-cell:hover {
    background: var(--bg3)
}

.level-cell:active {
    transform: scale(.9)
}

.level-cell.done {
    color: var(--green);
    border-color: rgba(34, 197, 94, .18)
}

.level-cell.locked {
    opacity: .28;
    cursor: default;
    pointer-events: none
}

.level-cell .cell-star {
    position: absolute;
    top: 1px;
    right: 3px;
    font-size: 9px;
    color: var(--gold)
}

/* ── HUD ── */
.game-hud {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 30;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 5px 10px;
    height: 48px;
    background: rgba(12, 18, 32, .94);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px)
}

.hud-icon-btn {
    background: transparent;
    border: 1px solid rgba(255, 255, 255, .07);
    color: var(--tx2);
    width: 34px;
    height: 34px;
    border-radius: var(--rs);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background .15s
}

.hud-icon-btn:hover {
    background: var(--bg2);
    color: var(--tx)
}

.hud-group {
    display: flex;
    flex-direction: column;
    align-items: center
}

.hud-label {
    font-size: 9px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1.2px;
    color: var(--tx2)
}

.hud-value {
    font-size: 19px;
    font-weight: 800;
    line-height: 1.1
}

.hud-timer {
    font-size: 17px;
    font-weight: 800;
    font-variant-numeric: tabular-nums;
    color: var(--cyan);
    line-height: 1
}

.hud-timer.warn {
    color: var(--gold)
}

.hud-timer.danger {
    color: var(--red);
    animation: blink .5s ease infinite alternate
}

/* ── Timer Bar ── */
.timer-bar {
    position: fixed;
    top: 48px;
    left: 0;
    right: 0;
    z-index: 29;
    height: 3px;
    background: rgba(255, 255, 255, .03)
}

.timer-fill {
    height: 100%;
    width: 100%;
    background: var(--cyan);
    transition: width 1s linear;
    border-radius: 0 2px 2px 0
}

.timer-fill.warn {
    background: var(--gold)
}

.timer-fill.danger {
    background: var(--red)
}

/* ── Board ── */
.board-wrap {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding-top: 56px;
    padding-bottom: 58px
}

.board {
    position: relative;
    width: calc(var(--cell)*6);
    height: calc(var(--cell)*6);
    background: var(--bg2);
    border-radius: var(--r);
    border: 2px solid rgba(255, 255, 255, .04);
    box-shadow: 0 6px 32px rgba(0, 0, 0, .3), inset 0 1px 0 rgba(255, 255, 255, .02);
    overflow: visible
}

.grid-line-h,
.grid-line-v {
    position: absolute;
    background: rgba(255, 255, 255, .025)
}

.grid-line-h {
    height: 1px;
    left: 0;
    right: 0
}

.grid-line-v {
    width: 1px;
    top: 0;
    bottom: 0
}

.exit-marker {
    position: absolute;
    right: -26px;
    top: calc(var(--cell)*2);
    width: 24px;
    height: var(--cell);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--red);
    animation: nudgeR 1s ease infinite alternate
}

/* ── Cars ── */
.car {
    position: absolute;
    border-radius: 9px;
    cursor: grab;
    touch-action: none;
    z-index: 5;
    transition: filter .15s
}

.car:active {
    cursor: grabbing
}

.car.dragging {
    z-index: 20;
    filter: brightness(1.1)
}

.car-body {
    width: 100%;
    height: 100%;
    border-radius: 9px;
    position: relative;
    overflow: hidden;
    border: 2px solid transparent
}

.car.dragging .car-body {
    box-shadow: 0 6px 24px rgba(0, 0, 0, .4)
}

.car-shine {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 42%;
    background: linear-gradient(180deg, rgba(255, 255, 255, .2) 0%, transparent 100%);
    border-radius: 7px 7px 0 0;
    pointer-events: none
}

.car-stripe {
    position: absolute;
    background: rgba(255, 255, 255, .09);
    border-radius: 2px
}

.car.h .car-stripe {
    width: 50%;
    height: 2px;
    left: 25%;
    top: 50%;
    transform: translateY(-50%)
}

.car.v .car-stripe {
    height: 50%;
    width: 2px;
    top: 25%;
    left: 50%;
    transform: translateX(-50%)
}

.car-headlights {
    position: absolute;
    display: flex;
    gap: 3px
}

.car.h .car-headlights {
    right: 5px;
    top: 50%;
    transform: translateY(-50%);
    flex-direction: column
}

.car.v .car-headlights {
    bottom: 5px;
    left: 50%;
    transform: translateX(-50%);
    flex-direction: row
}

.headlight {
    width: 4px;
    height: 4px;
    border-radius: 50%;
    background: rgba(255, 255, 255, .4)
}

.car.main-car {
    z-index: 10
}

.car.main-car .car-body {
    box-shadow: 0 0 16px rgba(239, 68, 68, .2), 0 0 32px rgba(239, 68, 68, .08)
}

/* ── Bottom Bar ── */
.bottom-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 30;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 10px 16px;
    background: rgba(12, 18, 32, .9);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border-top: 1px solid rgba(255, 255, 255, .03)
}

/* ── Results ── */
.result-icon {
    width: 72px;
    height: 72px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    font-size: 36px;
    color: #fff;
    animation: popIn .35s cubic-bezier(.175, .885, .32, 1.275) both
}

.win-check {
    background: linear-gradient(135deg, var(--green), #16a34a);
    box-shadow: 0 4px 18px rgba(34, 197, 94, .2)
}

.gameover-x {
    background: rgba(239, 68, 68, .1);
    border: 2px solid rgba(239, 68, 68, .2);
    color: var(--red)
}

.done-star {
    background: linear-gradient(135deg, var(--gold), #f59e0b);
    box-shadow: 0 4px 18px rgba(251, 191, 36, .2);
    font-size: 40px
}

.result-title {
    font-size: clamp(24px, 7vw, 36px);
    font-weight: 800;
    text-align: center;
    letter-spacing: -.5px
}

.go-title {
    color: var(--red)
}

.score-card {
    background: var(--bg2);
    padding: 16px 40px;
    border-radius: var(--r);
    border: 1px solid rgba(255, 255, 255, .04);
    min-width: 200px;
    display: flex;
    flex-direction: column;
    gap: 8px
}

.score-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 24px
}

.score-row .val {
    font-size: 24px;
    font-weight: 800
}

.score-row .gold {
    color: var(--gold)
}

.divider {
    height: 1px;
    background: rgba(255, 255, 255, .04)
}

.star-row {
    display: flex;
    gap: 5px;
    font-size: 28px
}

.star-row .star {
    color: rgba(255, 255, 255, .08)
}

.star-row .star.lit {
    color: var(--gold);
    text-shadow: 0 0 8px rgba(251, 191, 36, .3)
}

/* ── Deco ── */
.deco-cars {
    position: absolute;
    inset: 0;
    overflow: hidden;
    pointer-events: none;
    z-index: -1
}

.deco-car {
    position: absolute;
    border-radius: 5px;
    opacity: .035;
    animation: floatCar linear infinite
}

@keyframes fadeUp {
    from {
        opacity: 0;
        transform: translateY(14px)
    }

    to {
        opacity: 1;
        transform: translateY(0)
    }
}

@keyframes popIn {
    from {
        opacity: 0;
        transform: scale(.5)
    }

    to {
        opacity: 1;
        transform: scale(1)
    }
}

@keyframes floatCar {
    0% {
        transform: translateY(110vh);
        opacity: 0
    }

    8% {
        opacity: .035
    }

    92% {
        opacity: .035
    }

    100% {
        transform: translateY(-10vh);
        opacity: 0
    }
}

@keyframes nudgeR {
    from {
        transform: translateX(0);
        opacity: .45
    }

    to {
        transform: translateX(4px);
        opacity: 1
    }
}

@keyframes blink {
    from {
        opacity: 1
    }

    to {
        opacity: .4
    }
}

@media(max-width:420px) {
    :root {
        --cell: min(15.5vw, 58px)
    }

    .btn-primary {
        padding: 14px 44px;
        font-size: 16px
    }

    .score-card {
        padding: 12px 24px;
        min-width: 180px
    }

    .exit-marker {
        right: -20px
    }
}

@media(min-width:600px) {
    :root {
        --cell: 64px
    }
}