* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html,
body {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: #020604;
    color: #fff;
    font-family: Arial, Helvetica, sans-serif;
}

body {
    display: flex;
    align-items: center;
    justify-content: center;
    user-select: none;
}

#game {
    width: 100%;
    height: 100%;
    max-width: 500px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    position: relative;
    padding: 12px;
}

#topbar {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
}

.stat {
    flex: 1;
    min-width: 0;
    padding: 9px 6px;
    border: 1px solid rgba(0, 255, 80, 0.35);
    border-radius: 10px;
    background: rgba(0, 20, 8, 0.85);
    box-shadow:
        0 0 12px rgba(0, 255, 80, 0.08),
        inset 0 0 12px rgba(0, 255, 80, 0.04);
    text-align: center;
    font-size: 11px;
    color: #65ff8b;
}

.stat span {
    display: block;
    margin-top: 3px;
    font-size: 18px;
    font-weight: bold;
    color: #fff;
    text-shadow: 0 0 8px rgba(0, 255, 80, 0.6);
}

#canvas {
    display: block;
    width: min(100%, 440px);
    aspect-ratio: 1 / 1;
    border-radius: 18px;
    border: 2px solid rgba(0, 255, 80, 0.5);
    background: #020604;
    box-shadow:
        0 0 18px rgba(0, 255, 80, 0.18),
        0 0 50px rgba(0, 0, 0, 0.8);
    touch-action: none;
}

#message {
    width: 100%;
    min-height: 55px;
    margin-top: 10px;
    text-align: center;
    pointer-events: none;
}

#title {
    font-size: 20px;
    font-weight: 900;
    letter-spacing: 3px;
    color: #63ff83;
    text-shadow:
        0 0 5px #00ff44,
        0 0 15px rgba(0, 255, 70, 0.5);
}

#subtitle {
    margin-top: 5px;
    font-size: 10px;
    letter-spacing: 4px;
    color: #888;
}

#startBtn,
.restart {
    border: 0;
    outline: none;
    margin-top: 8px;
    padding: 13px 32px;
    border-radius: 12px;
    background: linear-gradient(
        135deg,
        #0d8f32,
        #00d94a
    );
    color: #fff;
    font-size: 14px;
    font-weight: 900;
    letter-spacing: 2px;
    box-shadow:
        0 0 15px rgba(0, 255, 70, 0.3),
        inset 0 0 10px rgba(255,255,255,0.08);
}

#startBtn:active,
.restart:active {
    transform: scale(0.96);
}

.levelup {
    color: #63ff83;
    font-size: 20px;
    font-weight: 900;
    letter-spacing: 3px;
    text-shadow:
        0 0 8px #00ff44,
        0 0 20px #00ff44;
    animation: levelFlash 0.7s infinite alternate;
}

.gameover {
    color: #ff3030;
    font-size: 24px;
    font-weight: 900;
    letter-spacing: 3px;
    text-shadow:
        0 0 8px #ff0000,
        0 0 20px rgba(255,0,0,0.7);
    animation: dangerPulse 0.7s infinite alternate;
}

.finalscore {
    margin-top: 5px;
    color: #aaa;
    font-size: 12px;
    letter-spacing: 2px;
}

.restart {
    margin-top: 10px;
    background: linear-gradient(
        135deg,
        #8b0000,
        #ff2020
    );
    box-shadow:
        0 0 15px rgba(255, 0, 0, 0.35);
}

@keyframes levelFlash {
    from {
        opacity: 0.55;
        transform: scale(0.98);
    }

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

@keyframes dangerPulse {
    from {
        opacity: 0.65;
        text-shadow:
            0 0 5px #ff0000;
    }

    to {
        opacity: 1;
        text-shadow:
            0 0 10px #ff0000,
            0 0 25px #ff0000;
    }
}

/* تاریک‌تر شدن فضای بازی در مراحل بالاتر */

body.level-2 {
    background: #020403;
}

body.level-3 {
    background: #010203;
}

body.level-4 {
    background: #010104;
}

body.level-5 {
    background: #000000;
}

/* موبایل */

@media (max-width: 420px) {

    #game {
        padding: 8px;
    }

    .stat {
        padding: 7px 4px;
        font-size: 9px;
    }

    .stat span {
        font-size: 16px;
    }

    #canvas {
        border-radius: 14px;
    }

    #title {
        font-size: 17px;
        letter-spacing: 2px;
    }
}

/* صفحه‌های خیلی کوتاه */

@media (max-height: 650px) {

    #game {
        padding-top: 5px;
    }

    #topbar {
        margin-bottom: 5px;
    }

    #message {
        margin-top: 5px;
    }

    #startBtn {
        margin-top: 4px;
        padding: 9px 25px;
    }
}
