:root {
    --bg-deep: #0d0f1a;
    --bg-mid: #141828;
    --bg-card: #1c2138;
    --bg-panel: #232a45;
    --accent-1: #7c5cfc;
    --accent-2: #f7477a;
    --accent-3: #38d9a9;
    --gold: #ffd166;
    --text-main: #e8eaf6;
    --text-muted: #ffff;
    --border: rgba(124, 92, 252, 0.25);
    --glow-purple: 0 0 24px rgba(124, 92, 252, 0.45);
    --glow-green: 0 0 24px rgba(56, 217, 169, 0.4);
    --glow-red: 0 0 24px rgba(247, 71, 122, 0.4);
}

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

body {
    background: var(--bg-deep);
    font-family: 'Nunito', sans-serif;
    overflow: hidden;
    touch-action: none;
    user-select: none;
}

/* ─── Ambient background orbs ─── */
body::before,
body::after {
    content: '';
    position: fixed;
    border-radius: 50%;
    pointer-events: none;
    z-index: 0;
}

body::before {
    width: 600px;
    height: 600px;
    background: radial-gradient(circle, rgba(124, 92, 252, 0.12) 0%, transparent 70%);
    top: -200px;
    left: -200px;
}

body::after {
    width: 500px;
    height: 500px;
    background: radial-gradient(circle, rgba(247, 71, 122, 0.1) 0%, transparent 70%);
    bottom: -150px;
    right: -150px;
}

#gameCanvas {
    display: block;
    width: 100vw;
    height: 100vh;
    position: relative;
    z-index: 1;
}

/* ─── HUD ─── */
.hud-container {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 64px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    background: linear-gradient(180deg, rgba(13, 15, 26, 0.95) 0%, transparent 100%);
    z-index: 5;
    pointer-events: none;
}

.hud-left {
    display: flex;
    align-items: center;
    gap: 10px;
    pointer-events: auto;
}

.hud-right {
    display: flex;
    align-items: center;
    gap: 10px;
    pointer-events: auto;
}

.level-badge {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    padding: 8px 18px;

    background: linear-gradient(180deg, #444f61 0%, #313b4a 100%);
    border: 2px solid #f7d86d;
    border-bottom: 5px solid #c99c24;
    border-radius: 16px;

    box-shadow:
        0 2px 0 #c99c24,
        0 4px 0 #b58518,
        0 8px 18px rgba(0, 0, 0, .35),
        inset 0 2px 0 rgba(255, 255, 255, .25),
        inset 0 -2px 0 rgba(0, 0, 0, .2);

    position: relative;
    overflow: hidden;
}

/* Glossy Shine */
.level-badge::before {
    content: "";
    position: absolute;
    top: 0;
    left: -70%;
    width: 50%;
    height: 100%;
    background: linear-gradient(120deg,
            transparent,
            rgba(255, 255, 255, .25),
            transparent);
    transform: skewX(-25deg);
}

.level-badge .label {
    font-size: 10px;
    font-weight: 900;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: #ffe7a8;
    text-shadow: 0 1px 2px rgba(0, 0, 0, .5);
}

.level-badge .value {
    font-family: 'Righteous', sans-serif;
    font-size: 24px;
    color: #ffffff;
    text-shadow:
        0 2px 0 rgba(0, 0, 0, .35),
        0 0 8px rgba(255, 230, 120, .45);
}

.level-badge .pip-bar {
    display: flex;
    gap: 5px;
    margin-left: 6px;
}

.level-badge .pip {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: linear-gradient(180deg, #7f8792, #555d68);
    border: 1px solid rgba(255, 255, 255, .2);
    box-shadow:
        inset 0 1px 2px rgba(255, 255, 255, .25),
        0 2px 3px rgba(0, 0, 0, .3);
}

.level-badge .pip.done {
    background: radial-gradient(circle at 35% 30%, #7dffb7, #22c55e);
    border-color: #b7ffd4;
    box-shadow:
        0 0 10px rgba(34, 197, 94, .9),
        0 0 20px rgba(34, 197, 94, .5),
        inset 0 1px 2px rgba(255, 255, 255, .4);
}

.level-badge .pip.active {
    background: radial-gradient(circle at 35% 30%, #fff6b0, #ffc107);
    border-color: #ffe07a;
    animation: levelPulse 1s infinite alternate;
    box-shadow:
        0 0 10px rgba(255, 193, 7, .9),
        0 0 20px rgba(255, 193, 7, .6),
        inset 0 1px 2px rgba(255, 255, 255, .5);
}

@keyframes levelPulse {
    from {
        transform: scale(1);
    }

    to {
        transform: scale(1.2);
    }
}

.icon-btn {
    width: 40px;
    height: 40px;
    background: var(--bg-card);
    border: 1.5px solid var(--border);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--text-muted);
    font-size: 16px;
    transition: all 0.2s;
}

.icon-btn:hover {
    border-color: var(--accent-1);
    color: var(--text-main);
    box-shadow: var(--glow-purple);
}

.icon-btn:active {
    transform: scale(0.92);
}

.reset-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;

    padding: 8px 18px;
    font-family: 'Nunito', sans-serif;
    font-weight: 900;
    font-size: 13px;
    letter-spacing: .5px;
    color: #fff;
    cursor: pointer;

    position: relative;
    overflow: hidden;
    transition: all .15s ease;

    background: linear-gradient(180deg, #6b7688 0%, #535d6d 60%, #404957 100%);
    border: 2px solid #98a4b5;
    border-bottom: 5px solid #2a313d;
    border-radius: 14px;

    box-shadow:
        0 2px 0 #2a313d,
        0 4px 0 #232933,
        0 8px 18px rgba(0, 0, 0, .35),
        inset 0 2px 0 rgba(255, 255, 255, .28),
        inset 0 -2px 0 rgba(0, 0, 0, .2);
}

/* Glossy Shine */
.reset-btn::before {
    content: "";
    position: absolute;
    top: 0;
    left: -120%;
    width: 60%;
    height: 100%;
    background: linear-gradient(120deg,
            transparent,
            rgba(255, 255, 255, .35),
            transparent);
    transform: skewX(-25deg);
    transition: left .5s ease;
}

.reset-btn:hover {
    transform: translateY(-2px);
    filter: brightness(1.08);
}

.reset-btn:hover::before {
    left: 160%;
}

.reset-btn:active {
    transform: translateY(3px);
    border-bottom-width: 2px;

    box-shadow:
        0 2px 8px rgba(0, 0, 0, .25),
        inset 0 2px 4px rgba(0, 0, 0, .25);
}

/* Optional icon animation */
.reset-btn i,
.reset-btn svg {
    transition: transform .25s ease;
}

.reset-btn:hover i,
.reset-btn:hover svg {
    transform: rotate(-180deg);
}

/* ─── Overlays ─── */
.overlay {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 10;
    transition: opacity 0.3s ease;
}

.overlay::before {
    content: '';
    position: absolute;
    inset: 0;
    background: rgba(5, 7, 15, 0.75);
    backdrop-filter: blur(8px);
}

.hidden {
    opacity: 0;
    pointer-events: none;
}

/* ─── Modal Card ─── */
.modal-card {
    position: relative;
    background: var(--bg-card);
    border: 1.5px solid var(--border);
    border-radius: 24px;
    padding: 40px 32px 36px;
    max-width: 400px;
    width: 88%;
    box-shadow: 0 32px 80px rgba(0, 0, 0, 0.6), var(--glow-purple);
    transform: scale(1) translateY(0);
    transition: transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275), opacity 0.3s;
}

.overlay.hidden .modal-card {
    transform: scale(0.85) translateY(20px);
}

.modal-icon {
    width: 72px;
    height: 72px;
    border-radius: 20px;
    margin: 0 auto 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 32px;
}

.modal-icon.purple {
    background: linear-gradient(135deg, #7c5cfc, #a07dff);
    box-shadow: var(--glow-purple);
}

.modal-icon.green {
    background: linear-gradient(135deg, #38d9a9, #20c997);
    box-shadow: var(--glow-green);
}

.modal-icon.red {
    background: linear-gradient(135deg, #f7477a, #e03570);
    box-shadow: var(--glow-red);
}

.modal-title {
    font-family: 'Righteous', sans-serif;
    font-size: 26px;
    color: var(--text-main);
    text-align: center;
    margin-bottom: 10px;
}

.modal-desc {
    font-size: 15px;
    color: var(--text-muted);
    text-align: center;
    line-height: 1.6;
    margin-bottom: 28px;
    font-weight: 600;
}

.modal-desc em {
    color: var(--gold);
    font-style: normal;
    font-weight: 800;
}

/* Tutorial chips */
.tutorial-steps {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 28px;
}

.step-chip {
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 10px 14px;
}

.step-num {
    width: 28px;
    height: 28px;
    border-radius: 8px;
    background: var(--accent-1);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 900;
    color: white;
    flex-shrink: 0;
}

.step-text {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-muted);
}

.step-text strong {
    color: var(--text-main);
}

/* Divider */
.modal-divider {
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--border), transparent);
    margin: 0 -32px 28px;
}

/* ─── Buttons ─── */
.btn-primary {
    width: 100%;
    background: linear-gradient(180deg, #b79cff 0%, #8d67ff 60%, #6e43ff 100%);
    border: 2px solid #d7c5ff;
    border-bottom: 6px solid #4f2bd9;
    border-radius: 16px;
    padding: 15px 28px;
    font-family: 'Nunito', sans-serif;
    font-weight: 900;
    font-size: 16px;
    color: #fff;
    cursor: pointer;
    letter-spacing: 0.5px;
    position: relative;
    overflow: hidden;
    transition: all 0.15s ease;

    /* 3D Game Shadow */
    box-shadow:
        0 2px 0 #4f2bd9,
        0 4px 0 #4f2bd9,
        0 6px 0 #4323b8,
        0 10px 20px rgba(79, 43, 217, 0.45),
        inset 0 2px 0 rgba(255, 255, 255, 0.45),
        inset 0 -2px 0 rgba(0, 0, 0, 0.18);
}

/* Shine Effect */
.btn-primary::before {
    content: "";
    position: absolute;
    top: 0;
    left: -120%;
    width: 60%;
    height: 100%;
    background: linear-gradient(120deg,
            transparent,
            rgba(255, 255, 255, 0.45),
            transparent);
    transform: skewX(-25deg);
    transition: left 0.5s ease;
}

.btn-primary:hover::before {
    left: 160%;
}

.btn-primary:hover {
    transform: translateY(-2px);
    filter: brightness(1.08);
}

/* Press Effect */
.btn-primary:active {
    transform: translateY(4px);
    border-bottom-width: 2px;
    box-shadow:
        0 2px 8px rgba(79, 43, 217, 0.35),
        inset 0 2px 4px rgba(0, 0, 0, 0.25);
}

/* ===========================
   GREEN GAME BUTTON
=========================== */

.btn-green {
    background: linear-gradient(180deg, #48e7b6 0%, #28d7a0 60%, #16b885 100%);
    border: 2px solid #8ff5d5;
    border-bottom: 6px solid #0c8f67;
    box-shadow:
        0 2px 0 #0c8f67,
        0 4px 0 #0c8f67,
        0 6px 0 #087554,
        0 10px 20px rgba(22, 184, 133, 0.4),
        inset 0 2px 0 rgba(255, 255, 255, 0.45),
        inset 0 -2px 0 rgba(0, 0, 0, 0.18);
}

.btn-green:hover {
    transform: translateY(-2px);
    filter: brightness(1.08);
}

.btn-green:active {
    transform: translateY(4px);
    border-bottom-width: 2px;
    box-shadow:
        0 2px 8px rgba(22, 184, 133, 0.35),
        inset 0 2px 4px rgba(0, 0, 0, 0.25);
}

/* ===========================
   RED GAME BUTTON
=========================== */

.btn-red {
    background: linear-gradient(180deg, #ff7b9d 0%, #f74b7a 60%, #df2f61 100%);
    border: 2px solid #ffb5ca;
    border-bottom: 6px solid #b71f4a;
    box-shadow:
        0 2px 0 #b71f4a,
        0 4px 0 #b71f4a,
        0 6px 0 #98153b,
        0 10px 20px rgba(223, 47, 97, 0.4),
        inset 0 2px 0 rgba(255, 255, 255, 0.45),
        inset 0 -2px 0 rgba(0, 0, 0, 0.18);
}

.btn-red:hover {
    transform: translateY(-2px);
    filter: brightness(1.08);
}

.btn-red:active {
    transform: translateY(4px);
    border-bottom-width: 2px;
    box-shadow:
        0 2px 8px rgba(223, 47, 97, 0.35),
        inset 0 2px 4px rgba(0, 0, 0, 0.25);
}

.btn-ghost {
    width: 100%;
    margin-top: 10px;
    padding: 12px 28px;
    font-family: 'Nunito', sans-serif;
    font-weight: 800;
    font-size: 14px;
    color: #f5f5f5;
    cursor: pointer;
    position: relative;
    overflow: hidden;
    transition: all 0.15s ease;

    background: linear-gradient(180deg, #5b6675 0%, #495564 60%, #3a4552 100%);
    border: 2px solid #8b98a8;
    border-bottom: 6px solid #232c37;
    border-radius: 16px;
    margin-top: 15px;
    box-shadow:
        0 2px 0 #232c37,
        0 4px 0 #232c37,
        0 6px 0 #1b222b,
        0 10px 20px rgba(0, 0, 0, 0.28),
        inset 0 2px 0 rgba(255, 255, 255, 0.25),
        inset 0 -2px 0 rgba(0, 0, 0, 0.18);
}

/* Shine Effect */
.btn-ghost::before {
    content: "";
    position: absolute;
    top: 0;
    left: -120%;
    width: 60%;
    height: 100%;
    background: linear-gradient(120deg,
            transparent,
            rgba(255, 255, 255, 0.35),
            transparent);
    transform: skewX(-25deg);
    transition: left 0.5s ease;
}

.btn-ghost:hover {
    transform: translateY(-2px);
    filter: brightness(1.08);
}

.btn-ghost:hover::before {
    left: 160%;
}

.btn-ghost:active {
    transform: translateY(4px);
    border-bottom-width: 2px;
    box-shadow:
        0 2px 8px rgba(0, 0, 0, 0.22),
        inset 0 2px 4px rgba(0, 0, 0, 0.25);
}

/* Win stats row */
.win-stats {
    display: flex;
    gap: 12px;
    margin-bottom: 28px;
}

.stat-pill {
    flex: 1;
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 12px 8px;
    text-align: center;
}

.stat-pill .s-val {
    font-family: 'Righteous', sans-serif;
    font-size: 22px;
    color: var(--gold);
}

.stat-pill .s-lbl {
    font-size: 11px;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-top: 2px;
}

/* ─── Preloader ─── */
#preloader{
    position:fixed;
    inset:0;
    display:flex;
    flex-direction:column;
    justify-content:center;
    align-items:center;
    overflow:hidden;
    background:
        radial-gradient(circle at top,#3748a8 0%,#20233b 45%,#121421 100%);
    z-index:9999;
}

/* Background Glow */

.loader-bg{
    position:absolute;
    width:420px;
    height:420px;
    border-radius:50%;
    background:radial-gradient(circle,
        rgba(124,92,252,.35),
        rgba(56,217,169,.18),
        transparent 70%);
    filter:blur(50px);
    animation:bgPulse 3s infinite ease-in-out;
}

/* Floating Balls */

.loader-balls{
    display:flex;
    gap:14px;
    margin-bottom:30px;
    z-index:2;
}

.ball{
    width:22px;
    height:22px;
    border-radius:50%;
    animation:bounce 1s infinite;
    box-shadow:0 0 18px rgba(255,255,255,.35);
}

.b1{
    background:#ff595e;
    animation-delay:0s;
}

.b2{
    background:#ffca3a;
    animation-delay:.15s;
}

.b3{
    background:#8ac926;
    animation-delay:.3s;
}

.b4{
    background:#1982c4;
    animation-delay:.45s;
}

.b5{
    background:#9d4edd;
    animation-delay:.6s;
}

@keyframes bounce{

    0%,100%{
        transform:translateY(0) scale(1);
    }

    50%{
        transform:translateY(-18px) scale(1.2);
    }

}

/* Logo */

.loader-logo{
    position:relative;
    z-index:2;
    font-family:'Righteous',sans-serif;
    font-size:42px;
    letter-spacing:3px;
    text-transform:uppercase;

    background:linear-gradient(
        90deg,
        #ff595e,
        #ffca3a,
        #8ac926,
        #1982c4,
        #9d4edd,
        #ff595e);

    background-size:300% auto;

    -webkit-background-clip:text;
    -webkit-text-fill-color:transparent;

    animation:gradientMove 4s linear infinite;
    text-shadow:0 0 30px rgba(255,255,255,.2);
}

/* Loading Bar */

.loader-bar-wrap{
    width:260px;
    height:16px;
    margin-top:28px;

    background:#2a2f49;
    border-radius:30px;
    overflow:hidden;

    border:2px solid rgba(255,255,255,.15);

    box-shadow:
        inset 0 3px 5px rgba(0,0,0,.4),
        0 8px 20px rgba(0,0,0,.35);

    z-index:2;
}

.loader-bar{
    height:100%;
    width:0;
    border-radius:30px;

    background:linear-gradient(
        90deg,
        #ff595e,
        #ffca3a,
        #8ac926,
        #1982c4,
        #9d4edd);

    background-size:300%;

    animation:
        loadFill 1.5s forwards,
        gradientMove 2s linear infinite;
}

/* Loading Text */

.loader-sub{
    margin-top:18px;
    font-size:14px;
    font-weight:800;
    color:#dfe5ff;
    letter-spacing:2px;
    text-transform:uppercase;
    z-index:2;
    animation:blink 1s infinite;
}

/* Animations */

@keyframes loadFill{

    from{width:0;}

    to{width:100%;}

}

@keyframes gradientMove{

    0%{background-position:0%;}

    100%{background-position:300%;}

}

@keyframes bgPulse{

    0%,100%{
        transform:scale(.9);
        opacity:.7;
    }

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

}

@keyframes blink{

    50%{
        opacity:.45;
    }

}
/* ─── Particles layer ─── */
#particles {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 2;
}

/* ─── Confetti burst keyframe ─── */
@keyframes confettiPop {
    0% {
        transform: translateY(0) rotate(0deg) scale(1);
        opacity: 1;
    }

    100% {
        transform: translateY(-120px) rotate(720deg) scale(0);
        opacity: 0;
    }
}