:root {
    --o: #ff7a1a;
    --gold: #ffd23a;
    --k: #111;
    --bg: #0c0f14;
    --panel: #171b24;
    --muted: #aeb6c5
}
* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
    user-select: none
}
html,
body {
    height: 100%;
    margin: 0;
    background: var(--bg);
    overflow: hidden;
    font-family: Anton, Impact, 'Arial Black', sans-serif;
    color: #fff;
    letter-spacing: 1px;
    touch-action: none;
    -webkit-touch-callout: none;
    overscroll-behavior: none
}

/* FIX: scope the fullscreen canvas rule to the game canvas only,
   so garage-preview <canvas> elements stay inline inside their cards */
#c {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    display: block
}

.scr,
.mod {
    position: fixed;
    inset: 0;
    display: none;
    align-items: center;
    justify-content: safe center;
    flex-direction: column;
    gap: 14px;
    text-align: center;
    padding: calc(14px + env(safe-area-inset-top)) 12px calc(14px + env(safe-area-inset-bottom));
    overflow-y: auto;
    touch-action: pan-y;
    z-index: 5
}

.scr.on,
.mod.on {
    display: flex;
    animation: fi .35s ease-out
}

.scr>* {
    flex-shrink: 0
}

.scr {
    background: linear-gradient(180deg, rgba(4, 7, 15, .24), rgba(4, 7, 15, .68));
    backdrop-filter: none
}

#pre {
    background: radial-gradient(ellipse at 50% 40%, #2e4a7a 0%, #18223b 48%, #080b12 100%);
    z-index: 9
}

#menu {
    background: linear-gradient(180deg, rgba(4, 7, 15, .16), rgba(4, 7, 15, .74))
}

.mod {
    background: rgba(0, 0, 0, .72);
    backdrop-filter: blur(5px);
    z-index: 7
}

.box {
    background: linear-gradient(145deg, #202631, #0a0b10);
    border: 3px solid #ffb04a;
    border-radius: 18px;
    padding: 22px 26px;
    max-width: 560px;
    width: min(100%, 560px);
    box-shadow: inset 0 1px 0 #ffffff20, 0 0 0 5px #090a0d, 0 22px 65px #000b;
    animation: pop .4s ease-out
}

h1 {
    font-size: clamp(48px, 11vw, 110px);
    line-height: .98;
    margin: 0 0 8px;
    color: #ffd23a;
    -webkit-text-stroke: 3px #111;
    paint-order: stroke fill;
    text-shadow: 0 6px 0 #c4570a, 0 12px 0 #111, 0 22px 30px #0008;
    transform: rotate(-3deg);
    animation: bob 2.5s ease-in-out infinite
}

h1 span {
    color: #fff
}

h2 {
    margin: 0 0 8px;
    font-size: 34px;
    color: var(--gold);
    text-shadow: 0 3px 0 #9c430a;
    letter-spacing: 1px
}

h3 {
    font-family: Anton, Impact, sans-serif
}

.btn {
    font: inherit;
    font-size: 26px;
    letter-spacing: 2px;
    color: #fff;
    background: linear-gradient(#ffb04a, #ff7a1a 55%, #e5530a);
    border: 3px solid #111;
    border-radius: 12px;
    padding: 9px 34px;
    min-width: 230px;
    cursor: pointer;
    box-shadow: inset 0 3px 0 #fff7, 0 6px 0 #7a2a00, 0 12px 18px #0007;
    text-shadow: 0 2px 0 #0006;
    transition: transform .12s, filter .12s;
    touch-action: manipulation
}

.btn:hover {
    transform: translateY(-3px) scale(1.025);
    filter: brightness(1.08)
}

.btn:active {
    transform: translateY(3px);
    box-shadow: inset 0 2px 0 #fff5, 0 1px 0 #7a2a00
}

.btn.g {
    background: linear-gradient(#5b6575, #2a303a 60%, #1a1e25);
    box-shadow: inset 0 3px 0 #fff3, 0 6px 0 #000, 0 12px 18px #0007
}

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

.bar {
    width: min(420px, 80vw);
    height: 22px;
    border: 3px solid #fff;
    border-radius: 12px;
    position: relative;
    background: #000;
    box-shadow: 0 5px 18px #0008
}

#bf {
    height: 100%;
    width: 0;
    background: repeating-linear-gradient(45deg, #ff7a1a, #ff7a1a 10px, #ffb04a 10px, #ffb04a 20px);
    border-radius: 8px
}

#bi {
    position: absolute;
    top: -34px;
    left: 0;
    font-size: 34px;
    transform: translateX(-50%) scaleX(-1)
}

#grid {
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 10px;
    max-width: 640px;
    width: min(100%, 640px)
}

.lt {
    font: inherit;
    font-size: 26px;
    color: #fff;
    background: linear-gradient(#2d3748, #141a24);
    border: 2px solid #d9e1ef;
    border-radius: 12px;
    padding: 8px 0;
    cursor: pointer;
    transition: .15s;
    animation: pop .4s both;
    box-shadow: inset 0 2px 0 #fff3, 0 4px 0 #000;
    touch-action: manipulation
}

.lt:hover:not(.lk) {
    transform: scale(1.06) rotate(-2deg);
    background: linear-gradient(#ff9a3a, #e5530a);
    border-color: #ffce82
}

.lt.lk {
    opacity: .4;
    cursor: not-allowed
}

.lt small {
    display: block;
    font-size: 13px;
    color: #9ca8ba
}

.lt small b {
    color: #ffc928;
    font-weight: 400
}

.tag {
    position: absolute;
    top: calc(8px + env(safe-area-inset-top));
    background: #0a0a0c;
    color: #fff;
    padding: 10px 22px;
    font: 34px Anton, Impact, sans-serif;
    letter-spacing: 1px;
    display: flex;
    align-items: center;
    gap: 10px;
    filter: drop-shadow(0 4px 0 #0006);
    clip-path: polygon(0 20%, 5% 2%, 18% 10%, 36% 0, 57% 9%, 78% 0, 94% 8%, 100% 24%, 97% 55%, 100% 82%, 90% 100%, 66% 90%, 45% 100%, 24% 88%, 8% 100%, 2% 78%, 4% 50%);
    pointer-events: none
}

#t1 {
    left: 4px
}

#t2 {
    left: 50%;
    transform: translateX(-50%);
    padding: 10px 30px
}

#t3 {
    right: 4px;
    gap: 18px;
    pointer-events: auto
}

#hl,
#ht {
    position: static;
    margin: 0;
    min-width: 0;
    background: none;
    padding: 0;
    transform: none;
    border: 0;
    font-size: inherit
}

.ic {
    width: 36px;
    height: 36px;
    flex-shrink: 0
}

#t3 button {
    width: 34px;
    height: 34px;
    padding: 0;
    background: none;
    border: 0;
    cursor: pointer;
    pointer-events: auto;
    touch-action: manipulation
}

#t3 svg {
    width: 100%;
    height: 100%
}

#bm.off .w {
    display: none
}

#hud {
    position: fixed;
    inset: 0;
    pointer-events: none;
    display: none;
    z-index: 3
}

#hud.on {
    display: block
}

#pop {
    position: fixed;
    left: 0;
    right: 0;
    top: 28%;
    text-align: center;
    font-size: clamp(40px, 9vw, 90px);
    color: #ffd23a;
    text-shadow: 4px 4px 0 #000, 0 0 20px #ff8a00;
    opacity: 0;
    pointer-events: none;
    z-index: 4
}

#pop.go {
    animation: pp 1.3s
}

.star {
    font-size: 62px;
    color: #333;
    display: inline-block
}

.star.on {
    color: #ffc928;
    text-shadow: 0 0 20px #ff9a00;
    animation: pop .6s both
}

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

.bk {
    border: 3px solid #444;
    border-radius: 12px;
    padding: 8px;
    width: 150px;
    cursor: pointer;
    background: linear-gradient(#252a34, #101217);
    touch-action: manipulation
}

.bk.sel {
    border-color: var(--o);
    box-shadow: 0 0 18px #ff7a1a66
}

.bk.lk {
    opacity: .5
}

/* FIX: keep garage-preview canvases inline inside their cards */
.bk canvas {
    display: block;
    width: 100%;
    height: auto;
    margin: 0 auto 6px;
    border-radius: 8px;
    background: radial-gradient(ellipse at 50% 35%, #2a3140, #10131a)
}

#tc {
    position: fixed;
    inset: auto 0 calc(14px + env(safe-area-inset-bottom)) 0;
    display: none;
    justify-content: space-between;
    padding: 0 calc(14px + env(safe-area-inset-right)) 0 calc(14px + env(safe-area-inset-left));
    z-index: 3;
    pointer-events: none
}

#tc div {
    display: flex;
    gap: 10px
}

#tc button {
    pointer-events: auto;
    width: 84px;
    height: 84px;
    border-radius: 50%;
    border: 3px solid #fff;
    background: rgba(0, 0, 0, .45);
    color: #fff;
    font: 34px/1 Anton, Impact;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(4px);
    touch-action: none;
    padding: 0
}

#tc small {
    font: 13px Anton;
    letter-spacing: 1px;
    opacity: .85
}

#tc button[data-k=up] {
    width: 104px;
    height: 104px;
    border-color: #ffb04a;
    background: rgba(255, 122, 26, .55)
}

#tc button.p {
    transform: scale(.92);
    background: rgba(255, 176, 74, .85)
}

.touch #hud.on~#tc {
    display: flex
}

#hint {
    position: fixed;
    bottom: calc(14px + env(safe-area-inset-bottom));
    left: 50%;
    transform: translateX(-50%);
    display: none;
    align-items: center;
    gap: 30px;
    background: #0a0a0c;
    padding: 14px 56px;
    font: 30px Anton, Impact;
    z-index: 3;
    clip-path: polygon(0 30%, 10% 4%, 30% 14%, 55% 0, 80% 10%, 96% 2%, 100% 40%, 96% 80%, 100% 100%, 70% 92%, 40% 100%, 12% 90%, 2% 100%, 4% 60%);
    animation: fi .6s
}

#hint.on {
    display: flex
}

.kc {
    display: grid;
    grid-template-columns: repeat(3, 34px);
    gap: 3px
}

.kc b {
    background: #2b2b2b;
    border: 2px solid #bbb;
    border-radius: 3px;
    text-align: center;
    font: 20px Anton;
    line-height: 30px;
    box-shadow: 0 2px 0 #000
}

.touch #hint .kc {
    display: none
}

p {
    margin: 6px 0;
    font: 22px/1.35 Arial, sans-serif;
    letter-spacing: 0;
    color: #f0f2f8
}

kbd {
    min-width: 30px;
    height: 30px;
    padding: 0 7px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 7px;
    background: linear-gradient(145deg, #3a3a48, #191923);
    border: 1px solid #ffffff2e;
    border-bottom: 3px solid #0008;
    color: #fff;
    font: 900 12px Anton, Impact, sans-serif;
    box-shadow: 0 3px 6px #0006
}

#rot {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 20;
    background: #0a0d14;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    font-size: 36px;
    text-align: center
}

#rot p {
    font-size: 18px
}

@media(orientation:portrait) and (pointer:coarse) {
    body.play #rot {
        display: flex
    }
}

/* How-to modal */
.how-box {
    width: min(680px, 92vw);
    max-height: 88vh;
    overflow-y: auto;
    padding: 26px;
    border-radius: 24px;
    background: linear-gradient(145deg, rgba(25, 25, 45, .98), rgba(10, 10, 20, .98));
    border: 2px solid #ffffff1f;
    box-shadow: 0 25px 70px #000a, inset 0 1px 0 #ffffff1f;
    scrollbar-width: thin;
    touch-action: pan-y
}

.how-header {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 22px;
    padding-bottom: 18px;
    border-bottom: 1px solid #ffffff1a;
    text-align: left
}

.how-icon {
    width: 62px;
    height: 62px;
    flex-shrink: 0;
    display: grid;
    place-items: center;
    font-size: 32px;
    border-radius: 18px;
    background: linear-gradient(145deg, #ff9d00, #ff4d00);
    box-shadow: 0 8px 25px #ff640059, inset 0 2px 0 #ffffff4d
}

.how-header h2 {
    margin: 0;
    font-size: clamp(24px, 5vw, 32px);
    font-weight: 900
}

.how-header p {
    margin: 4px 0 0;
    opacity: .65;
    font-size: 13px
}

.how-section {
    margin-bottom: 20px;
    text-align: left
}

.how-section h3 {
    margin: 0 0 12px;
    font-size: 14px;
    letter-spacing: 1px;
    font-weight: 900;
    color: #ffd166
}

.control-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px
}

.control-card {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    border-radius: 14px;
    background: #ffffff0e;
    border: 1px solid #ffffff14;
    transition: .2s
}

.control-card:hover {
    transform: translateY(-2px);
    background: #ffffff17
}

.keys {
    display: flex;
    gap: 4px
}

.control-card span {
    font-size: 16px;
    font-weight: 700;
    opacity: .85
}

.mobile-controls {
    padding: 15px;
    border-radius: 16px;
    background: linear-gradient(135deg, #00d2ff14, #7846ff14);
    border: 1px solid #00d2ff26
}

.mobile-controls p {
    margin: 0 0 13px;
    font-size: 14px;
    line-height: 1.5;
    opacity: .8
}

.mobile-keys {
    display: flex;
    justify-content: center;
    gap: 10px;
    flex-wrap: wrap
}

.mobile-keys span {
    min-width: 62px;
    padding: 9px 10px;
    text-align: center;
    border-radius: 12px;
    background: #ffffff14;
    border: 1px solid #ffffff1a;
    font-size: 20px;
    font-weight: 900
}

.mobile-keys small {
    display: block;
    margin-top: 2px;
    font: 8px Anton, Impact;
    letter-spacing: .7px;
    opacity: .55
}

.tip-list {
    display: grid;
    gap: 8px
}

.tip {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 10px 12px;
    border-radius: 12px;
    background: #ffffff0b
}

.tip>span {
    width: 30px;
    text-align: center;
    font-size: 20px
}

.tip p {
    margin: 0;
    font-size: 13px;
    line-height: 1.45;
    opacity: .82
}

.tip b {
    color: #fff
}

.tip.danger {
    border: 1px solid #ff505026;
    background: #ff3c3c0e
}

.rewards {
    text-align: center;
    padding: 16px;
    border-radius: 16px;
    background: linear-gradient(135deg, #ffc10714, #ff78000f);
    border: 1px solid #ffc1072e
}

.rewards h3 {
    margin-bottom: 6px
}

.rewards p {
    margin: 5px 0;
    font-size: 13px;
    opacity: .8
}

.stars {
    color: #ffd166;
    font-size: 20px;
    letter-spacing: 3px;
    text-shadow: 0 0 12px #ffd16680
}

.unlock {
    color: #ffd166
}

.quick-controls {
    display: flex;
    justify-content: center;
    gap: 25px;
    margin: 17px 0;
    font: 12px Arial, sans-serif;
    opacity: .7
}

.quick-controls kbd {
    min-width: 25px;
    height: 25px;
    font-size: 10px
}

.how-btn {
    width: 100%;
    min-height: 48px;
    border-radius: 14px;
    font-size: 15px;
    font-weight: 900;
    letter-spacing: .7px;
    cursor: pointer;
    transition: .2s
}

.how-btn:hover {
    transform: translateY(-2px)
}

.how-btn:active {
    transform: translateY(1px)
}

@keyframes fi {
    from {
        opacity: 0
    }
}

@keyframes pop {
    0% {
        transform: scale(.3);
        opacity: 0
    }

    70% {
        transform: scale(1.12)
    }

    100% {
        transform: scale(1);
        opacity: 1
    }
}

@keyframes bob {
    50% {
        transform: rotate(-1deg) translateY(-8px)
    }
}

@keyframes pp {
    0% {
        transform: scale(.4);
        opacity: 0
    }

    20% {
        transform: scale(1.1);
        opacity: 1
    }

    80% {
        opacity: 1
    }

    100% {
        transform: translateY(-40px);
        opacity: 0
    }
}

@media(max-width:560px) {
    #grid {
        grid-template-columns: repeat(4, minmax(0, 1fr))
    }

    .tag {
        font-size: 24px;
        padding: 6px 18px
    }

    .ic {
        width: 26px;
        height: 26px
    }

    #t3 {
        gap: 12px
    }

    #t3 button {
        width: 28px;
        height: 28px
    }

    .box {
        padding: 14px
    }

    .btn {
        min-width: 200px
    }

    h1 {
        font-size: 56px
    }

    .how-box {
        width: 94vw;
        padding: 18px;
        border-radius: 20px
    }

    .how-header {
        gap: 12px
    }

    .how-icon {
        width: 50px;
        height: 50px;
        font-size: 26px;
        border-radius: 14px
    }

    .control-grid {
        grid-template-columns: 1fr
    }

    .control-card {
        padding: 10px
    }

    .mobile-keys {
        gap: 6px
    }

    .mobile-keys span {
        min-width: 55px;
        padding: 7px
    }
}

@media(max-height:430px) {
    h1 {
        font-size: 46px;
        transform: none;
        animation: none
    }

    .scr {
        gap: 8px
    }

    .btn {
        font-size: 20px;
        padding: 5px 22px;
        min-width: 170px
    }

    .tag {
        font-size: 22px;
        padding: 6px 22px 6px 14px
    }

    .ic {
        width: 24px;
        height: 24px
    }

    #t3 button {
        width: 26px;
        height: 26px
    }

    #t3 {
        gap: 12px
    }

    #t2 {
        padding: 6px 28px
    }

    .box {
        padding: 12px 18px
    }

    .box p {
        font-size: 15px;
        margin: 3px 0
    }

    h2 {
        font-size: 26px !important;
        margin-bottom: 4px
    }

    #grid {
        grid-template-columns: repeat(8, minmax(0, 1fr));
        gap: 6px;
        max-width: 640px
    }

    .lt {
        font-size: 20px;
        padding: 2px 0
    }

    .lt small {
        font-size: 12px
    }

    .star {
        font-size: 40px
    }

    #tc button {
        width: 68px;
        height: 68px;
        font-size: 28px
    }

    #tc button[data-k=up] {
        width: 84px;
        height: 84px
    }

    #hint {
        padding: 8px 36px;
        font-size: 20px;
        bottom: 92px
    }

    #pop {
        top: 20%;
        font-size: 44px
    }

    .bk {
        width: 120px
    }

    .how-box {
        max-height: 94vh;
        padding: 14px
    }

    .how-section {
        margin-bottom: 12px
    }

    .how-header {
        margin-bottom: 12px;
        padding-bottom: 10px
    }
}