:root {
    --ui-bg: rgba(2, 10, 24, .90);
    --ui-border: rgba(80, 190, 240, .22);
    --ui-text: #e0f4ff;
    --ui-pale: #8dc8e8;
    --ui-accent: #5bc8f5;
    --ui-gold: #ffd166;
    --free: #12284d;
    --wall: #c3cde0;
    --paint: #22d3ee;
    --hero: #ff4f7b;
    --font: 'Fredoka', 'Nunito', 'Trebuchet MS', 'Segoe UI', system-ui, sans-serif;
}

*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html,
body {
    height: 100%;
    overflow: hidden;
    overscroll-behavior: none;
    font-family: var(--font);
    background: linear-gradient(0deg, rgb(12, 34, 73), rgb(4, 18, 46) 50%, rgb(1, 5, 15));
    color: var(--ui-text);
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
    touch-action: none;
}

[hidden] {
    display: none !important;
}

.boot {
    visibility: hidden;
}

.hud {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 100;
    height: calc(52px + env(safe-area-inset-top));
    padding: env(safe-area-inset-top) 12px 0;
    background: var(--ui-bg);
    border-bottom: 1px solid var(--ui-border);
    backdrop-filter: blur(12px);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.hud-left,
.hud-right {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 88px;
}

.hud-right {
    justify-content: flex-end;
    gap: 10px;
}

.hud-center {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1px;
}

.score-label {
    font-size: 11px;
    text-transform: uppercase;
    color: var(--ui-pale);
    letter-spacing: .6px;
}

.score-value {
    font-size: 24px;
    font-weight: 700;
    color: var(--ui-accent);
    line-height: 1;
    font-variant-numeric: tabular-nums;
}

.coins {
    font-weight: 700;
    color: var(--ui-gold);
    font-size: 17px;
    font-variant-numeric: tabular-nums;
}

.icon-btn {
    background: rgba(91, 200, 245, .12);
    border: 1px solid var(--ui-border);
    color: var(--ui-text);
    width: 40px;
    height: 40px;
    border-radius: 10px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    text-decoration: none;
}

.icon-btn:active {
    background: rgba(91, 200, 245, .3);
}

.icon-btn svg {
    pointer-events: none;
}

:is(button, a):focus-visible {
    outline: 2px solid var(--ui-gold);
    outline-offset: 2px;
}

.play {
    position: fixed;
    inset: 0;
    padding-top: calc(52px + env(safe-area-inset-top));
    display: flex;
    flex-direction: column;
    touch-action: none;
}

.stage {
    flex: 1;
    min-height: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    touch-action: none;
}

.board {
    --h: calc(var(--cs, 32px) * .3);
    --sx: calc(var(--cs, 32px) * .14);
    --pt: calc(var(--cs, 32px) * .6);
    display: grid;
    border: 4px solid;
    border-color: #e6ecf8 #a9b6d2 #6f7d9e #bcc8e0;
    border-radius: 12px;
    padding: var(--pt) var(--sx) 0;
    background: linear-gradient(180deg, #0b1f44, var(--free));
    position: relative;
    overflow: hidden;
    box-shadow: 0 10px 40px rgba(0, 0, 0, .55), inset 0 0 32px rgba(0, 0, 0, .55);
}

.c {
    position: relative;
    background-color: var(--free);
    background-image: linear-gradient(150deg, rgba(255, 255, 255, .07), rgba(0, 0, 0, .2));
    box-shadow: inset 0 0 0 1px rgba(120, 190, 255, .09);
    transition: background-color .1s linear;
}

.c::after {
    content: '';
    position: absolute;
    inset: 0;
    opacity: 0;
    pointer-events: none;
    transition: opacity .12s linear;
    transition-delay: inherit;
}

.c.p {
    background-color: var(--paint);
    background-image: linear-gradient(150deg, rgba(255, 255, 255, .32), rgba(0, 0, 0, .16));
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .28);
}

.c.p::after {
    opacity: 1;
}

.c.w {
    background: #091831;
    box-shadow: none;
    transition: none;
}

.c.w::before {
    content: '';
    position: absolute;
    inset: 0;
    z-index: 1;
    box-shadow: calc(var(--sx) * 1.4) calc(var(--h) * .7) calc(var(--h) * .6) rgba(0, 0, 0, .5);
}

.c.w b,
.hero b {
    position: absolute;
    display: block;
}

.wf {
    z-index: 1;
    left: calc(var(--sx) * -1);
    top: calc(100% - var(--h));
    width: calc(100% + var(--sx));
    height: var(--h);
    clip-path: polygon(0 0, 87.72% 0, 100% 100%, 12.28% 100%);
    background: linear-gradient(180deg, #a8b5d0, #6d7ca0);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, .55);
}

.ws {
    z-index: 1;
    left: calc(100% - var(--sx));
    top: calc(var(--h) * -1);
    width: var(--sx);
    height: calc(100% + var(--h));
    clip-path: polygon(0 0, 100% 23.08%, 100% 100%, 0 76.92%);
    background: linear-gradient(180deg, #8190b2, #4d5b80);
}

.wt {
    z-index: 3;
    left: calc(var(--sx) * -1);
    top: calc(var(--h) * -1);
    width: 100%;
    height: 100%;
    background: linear-gradient(150deg, #fbfdff, var(--wall) 55%, #a3b0cd);
    box-shadow: inset 1px 1px 0 rgba(255, 255, 255, .85), inset -1px -1px 0 rgba(60, 75, 115, .35);
}

.hero {
    position: absolute;
    left: var(--sx);
    top: var(--pt);
    z-index: 2;
    pointer-events: none;
    transition-property: transform;
    transition-timing-function: linear;
    will-change: transform;
}

.hero::before,
.hero::after {
    content: '';
    position: absolute;
}

.hero::before {
    left: 8%;
    right: 8%;
    top: 8%;
    bottom: 8%;
    box-shadow: calc(var(--sx) * 1.3) calc(var(--h) * .6) calc(var(--h) * .7) rgba(0, 0, 0, .55);
}

.hero::after {
    left: calc(8% - var(--sx));
    right: calc(8% + var(--sx));
    top: calc(8% - var(--h));
    bottom: calc(8% + var(--h));
    background: linear-gradient(145deg, var(--p-hi), var(--paint) 55%, var(--p-lo));
    box-shadow: inset 0 0 0 2px rgba(255, 255, 255, .75), inset -1px -1px 0 rgba(0, 0, 0, .2);
}

.hf {
    left: calc(8% - var(--sx));
    top: calc(92% - var(--h));
    width: calc(84% + var(--sx));
    height: var(--h);
    clip-path: polygon(0 0, 85.71% 0, 100% 100%, 14.29% 100%);
    background: linear-gradient(180deg, var(--f0), var(--f1));
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, .35);
}

.hs {
    left: calc(92% - var(--sx));
    top: calc(8% - var(--h));
    width: var(--sx);
    height: calc(84% + var(--h));
    clip-path: polygon(0 0, 100% 26.32%, 100% 100%, 0 73.68%);
    background: linear-gradient(180deg, var(--s0), var(--s1));
}

.gear {
    position: absolute;
    z-index: 1;
    left: calc(8% - var(--sx));
    right: calc(8% + var(--sx));
    top: calc(8% - var(--h));
    bottom: calc(8% + var(--h));
}

.gear svg {
    position: absolute;
    left: -30%;
    top: -70%;
    width: 160%;
    height: 170%;
    overflow: visible;
}

.pu {
    transform: translate(calc(var(--ex, 0) * 3.5px), calc(var(--ey, .6) * 3.5px));
    transition: transform .12s linear;
}

:root {
    --star: polygon(50% 0, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%);
}

[data-fx=stripes] .c.p::after {
    background: repeating-linear-gradient(45deg, rgba(255, 255, 255, .3) 0 16%, transparent 16% 32%);
}

[data-fx=dots] .c.p::after {
    background: radial-gradient(circle, rgba(255, 255, 255, .6) 0 18%, transparent 20%);
}

[data-fx=checker] .c.p.o::after {
    background: rgba(255, 255, 255, .2);
}

[data-fx=bricks] .c.p::after {
    background: linear-gradient(rgba(0, 0, 0, .4), rgba(0, 0, 0, .4)) 0 100% / 100% 2px no-repeat, linear-gradient(rgba(0, 0, 0, .4), rgba(0, 0, 0, .4)) 0 0 / 2px 100% no-repeat;
}

[data-fx=bricks] .c.p.o::after {
    background-position: 0 100%, 50% 0;
}

[data-fx=neon] .c.p::after {
    box-shadow: inset 0 0 0 2px rgba(255, 255, 255, .9), inset 0 0 8px rgba(255, 255, 255, .7);
}

[data-fx=stars] .c.p.s::after {
    inset: 18%;
    background: #fff;
    clip-path: var(--star);
    animation: tw 1.6s ease-in-out infinite alternate;
    animation-delay: calc(var(--k) * -.3s);
}

[data-fx=glitter] .c.p.s::after {
    inset: 38%;
    background: #fff;
    border-radius: 50%;
    box-shadow: 0 0 6px #fff;
    animation: tw 1s ease-in-out infinite alternate;
    animation-delay: calc(var(--k) * -.25s);
}

[data-fx=candy] .c.p::after {
    background: repeating-linear-gradient(45deg, #ff5c9a 0 25%, #fff5fa 25% 50%);
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .3);
}

[data-fx=ocean] .c.p::after {
    background: linear-gradient(180deg, #38bdf8, #0369a1);
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .25);
    animation: flick .9s ease-in-out infinite alternate;
    animation-delay: calc(var(--k) * -.25s);
}

[data-fx=fire] .c.p::after {
    background: linear-gradient(0deg, #dc2626, #f97316 55%, #fde047);
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .25);
    animation: flick .7s ease-in-out infinite alternate;
    animation-delay: calc(var(--k) * -.17s);
}

[data-fx=rainbow] .c.p::after {
    background: hsl(calc(var(--k) * 26), 85%, 55%);
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .3);
    animation: hue 4s linear infinite;
    animation-delay: calc(var(--k) * -.3s);
}

@keyframes tw {
    from {
        opacity: .3;
        transform: scale(.7);
    }

    to {
        opacity: 1;
        transform: scale(1.15);
    }
}

@keyframes flick {
    from {
        filter: brightness(.8);
    }

    to {
        filter: brightness(1.25);
    }
}

@keyframes hue {
    to {
        filter: hue-rotate(360deg);
    }
}

.pt {
    position: absolute;
    z-index: 1;
    pointer-events: none;
    width: var(--ps);
    height: var(--ps);
    margin: calc(var(--ps) / -2) 0 0 calc(var(--ps) / -2);
    border-radius: 50%;
    background: var(--pc);
    animation: pt var(--pd) ease-out forwards;
}

.pt.sq {
    border-radius: 18%;
}

.pt.ring {
    background: none;
    border: 2px solid var(--pc);
}

.pt.star {
    border-radius: 0;
    clip-path: var(--star);
}

.pt.heart {
    width: auto;
    height: auto;
    margin: calc(var(--ps) / -2.2) 0 0 calc(var(--ps) / -2);
    background: none;
    border-radius: 0;
    color: var(--pc);
    font: 700 var(--ps) / 1 sans-serif;
}

@keyframes pt {
    from {
        opacity: 1;
        transform: translate(0, 0) rotate(0) scale(1);
    }

    to {
        opacity: 0;
        transform: translate(var(--dx), var(--dy)) rotate(var(--r)) scale(.3);
    }
}

.overlay {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 300;
    background: rgba(1, 6, 18, .87);
    backdrop-filter: blur(8px);
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.overlay.open {
    display: flex;
}

.modal {
    position: relative;
    background: linear-gradient(160deg, #0a1f3a, #030f22);
    border: 1px solid var(--ui-border);
    border-radius: 22px;
    padding: 30px 26px;
    max-width: 380px;
    width: 100%;
    max-height: 90dvh;
    overflow-y: auto;
    touch-action: pan-y;
    box-shadow: 0 24px 64px rgba(0, 0, 0, .7);
}

.modal-close {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 40px;
    height: 40px;
    background: none;
    border: none;
    color: var(--ui-pale);
    font-size: 20px;
    cursor: pointer;
    border-radius: 8px;
}

.modal-close:active {
    background: rgba(255, 255, 255, .1);
}

.start-modal {
    text-align: center;
}

.gameover-emoji {
    font-size: 56px;
    text-align: center;
    margin-bottom: 4px;
}

.start-title {
    font-size: 30px;
    font-weight: 700;
    color: var(--ui-accent);
    letter-spacing: 1px;
    margin-bottom: 12px;
}

.start-text {
    font-size: 15px;
    line-height: 1.6;
    color: var(--ui-pale);
    margin-bottom: 10px;
}

.start-text strong {
    color: var(--ui-text);
}

.start-keys {
    font-size: 12px;
    line-height: 1.6;
    color: var(--ui-pale);
    opacity: .7;
    margin-bottom: 18px;
}

.menu-msg {
    margin: 12px 0 0;
    min-height: 19px;
}

.modal h2 {
    font-size: 22px;
    color: var(--ui-accent);
    margin-bottom: 18px;
}

.modal h3 {
    font-size: 15px;
    color: var(--ui-accent);
    margin: 14px 0 6px;
}

.modal section {
    border-bottom: 1px solid rgba(255, 255, 255, .07);
    padding-bottom: 12px;
    margin-bottom: 4px;
}

.modal ul {
    padding-left: 18px;
}

.modal li {
    font-size: 14px;
    line-height: 1.6;
    margin-bottom: 4px;
    color: var(--ui-pale);
}

.modal li strong {
    color: var(--ui-text);
}

#pauseOverlay .modal h2 {
    text-align: center;
    margin-top: 10px;
    margin-bottom: 28px;
    letter-spacing: 1px;
}

.start-modal h2.start-title {
    font-size: 30px;
    margin-bottom: 12px;
}

.pause-menu {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-top: 10px;
}

.gameover-title {
    font-size: 28px;
    font-weight: 700;
    text-align: center;
    margin-bottom: 12px;
}

.win-record {
    text-align: center;
    font-weight: 700;
    color: var(--ui-gold);
    margin-bottom: 12px;
}

.final-stats {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 16px;
}

.stat-row {
    display: flex;
    justify-content: space-between;
    font-size: 15px;
    padding: 8px 12px;
    background: rgba(255, 255, 255, .05);
    border-radius: 10px;
}

.stat-row.total {
    border: 1px solid rgba(255, 209, 102, .5);
}

.stat-row.total .stat-val {
    color: var(--ui-gold);
}

.stat-val {
    font-weight: 700;
    color: var(--ui-accent);
    font-variant-numeric: tabular-nums;
}

.x2 {
    display: inline-block;
    background: var(--ui-gold);
    color: #1a1a1a;
    border-radius: 6px;
    padding: 0 6px;
}

.shop-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    padding: 14px;
    margin: 6px 0 4px;
    background: rgba(255, 255, 255, .05);
    border: 2px solid #5ef5a0;
    border-radius: 16px;
}

.swatch {
    width: 64px;
    height: 64px;
    border-radius: 14px;
    background: var(--paint);
    border: 2px solid rgba(255, 255, 255, .6);
}

.shop-name {
    font-weight: 700;
    font-size: 17px;
}

.btn-sky {
    width: 100%;
    min-height: 48px;
    padding: 12px;
    border-radius: 14px;
    border: none;
    font-family: var(--font);
    font-size: 17px;
    font-weight: 700;
    color: #fff;
    cursor: pointer;
    background: linear-gradient(135deg, #0077b6, #023e8a);
    box-shadow: 0 6px 18px rgba(0, 119, 182, .4);
}

.btn-sky:active {
    transform: scale(.98);
}

.btn-sky:disabled {
    opacity: .6;
    cursor: default;
}

.btn-sky.secondary {
    background: rgba(255, 255, 255, .07);
    box-shadow: none;
    border: 1px solid rgba(255, 255, 255, .12);
}

.btn-sky.btn-resume {
    background: rgba(91, 200, 245, .12);
    border: 1px solid rgba(91, 200, 245, .32);
    color: var(--ui-accent);
    box-shadow: none;
}

.btn-sky.danger {
    color: #ffb3c4;
    border-color: rgba(239, 71, 111, .35);
}

.btn-sky.danger.confirm {
    color: #fff;
    background: linear-gradient(135deg, #c1274d, #8f1636);
    border-color: transparent;
    box-shadow: 0 6px 18px rgba(239, 71, 111, .35);
}

.btn-sky.on {
    background: #5ef5a0;
    color: #05231d;
    box-shadow: none;
    opacity: 1;
}

.tabs {
    display: flex;
    gap: 6px;
    margin: 12px 0;
}

.tab {
    flex: 1;
    min-height: 40px;
    border-radius: 12px;
    border: 1px solid var(--ui-border);
    background: rgba(255, 255, 255, .05);
    color: var(--ui-pale);
    font-family: var(--font);
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
}

.tab.on {
    background: linear-gradient(180deg, #1aa0e0, #0077b6);
    color: #fff;
    border-color: transparent;
}

.shop-modal {
    max-width: min(100%, 820px);
}

.shop-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(112px, 1fr));
    gap: 10px;
}

.shop-grid .shop-item {
    margin: 0;
    padding: 10px 8px;
    gap: 6px;
    border: 2px solid rgba(255, 255, 255, .1);
}

.shop-grid .shop-item.eq {
    border-color: #5ef5a0;
}

.shop-grid .shop-name {
    font-size: 14px;
}

.shop-grid .btn-sky {
    min-height: 40px;
    padding: 8px;
    font-size: 14px;
}

.btn-sky.gold {
    background: linear-gradient(180deg, #ffd978, #ffc13d);
    color: #1a1a1a;
    box-shadow: none;
}

.pvbox {
    height: 86px;
    display: grid;
    place-items: end center;
}

.pv {
    --cs: 48px;
    --h: calc(var(--cs) * .3);
    --sx: calc(var(--cs) * .14);
    position: relative;
    width: var(--cs);
    height: var(--cs);
}

.pv .hero {
    position: relative;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

.pvfx {
    position: relative;
    width: 66px;
    height: 66px;
    border-radius: 10px;
    overflow: hidden;
    display: grid;
    grid: repeat(3, 1fr) / repeat(3, 1fr);
    align-self: center;
}

@media (prefers-reduced-motion: reduce) {

    *,
    *::before,
    *::after {
        transition: none !important;
        animation: none !important;
    }
}