@import url('https://fonts.googleapis.com/css2?family=Righteous&family=Ubuntu:wght@500;700&display=swap');

:root {
    --modal-padding-x: 60px;
    --modal-padding-y: 40px;
    --modal-radius: 20px;
    --title-size: 4rem;
    --game-over-title-size: 3.5rem;
    --sub-text-size: 1.1rem;
    --stats-text-size: 1.5rem;
    --btn-font-size: 1.5rem;
    --btn-padding-y: 15px;
    --btn-padding-x: 50px;
    --home-btn-size: 40px;
    --home-btn-offset: 8px;
    --hud-top: 8px;
    --hud-width: calc(100% - 120px);
    --progress-bar-width: 400px;
    --progress-bar-height: 10px;
    --modal-max-width: 520px;
    --logo-max-width: 340px;
}

body, html {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    background-color: #060d24;
    overflow: hidden;
    font-family: 'Ubuntu', sans-serif;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
}

#game-container {
    position: relative;
    width: 100vw;
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
}

canvas {
    display: block;
    width: 100%;
    height: 100%;
    background: #060d24;
}

#ui-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 20;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(4px);
    transition: opacity 0.3s ease, background 0.3s ease;
}

#ui-layer.game-over-overlay {
    background: rgba(0, 0, 0, 0.7);
}

.popup-modal {
    pointer-events: auto;
    background: linear-gradient(160deg, #1a3a6e 0%, #0c1a3d 50%, #081228 100%);
    border: 2px solid #22d3ee;
    border-radius: var(--modal-radius);
    padding: var(--modal-padding-y) var(--modal-padding-x);
    max-width: var(--modal-max-width);
    width: calc(100% - 32px);
    box-sizing: border-box;
    text-align: center;
    box-shadow:
        0 25px 50px -12px rgba(0, 0, 0, 0.85),
        0 0 40px rgba(34, 211, 238, 0.25) inset,
        0 0 30px rgba(34, 211, 238, 0.35);
    opacity: 0;
    transform: scale(0.8);
    animation: popIn 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

@keyframes popIn {
    to {
        opacity: 1;
        transform: scale(1);
    }
}

#ui-layer.hidden {
    display: none !important;
}

.home-btn {
    position: absolute;
    top: var(--home-btn-offset);
    left: var(--home-btn-offset);
    z-index: 30;
    width: var(--home-btn-size);
    height: var(--home-btn-size);
    padding: calc(var(--home-btn-size) * 0.2);
    border: 2px solid rgba(34, 211, 238, 0.7);
    border-radius: 10px;
    background: linear-gradient(145deg, rgba(26, 58, 110, 0.95), rgba(8, 18, 40, 0.95));
    color: #22d3ee;
    cursor: pointer;
    pointer-events: auto;
    box-shadow:
        0 0 14px rgba(34, 211, 238, 0.4),
        0 4px 12px rgba(0, 0, 0, 0.5);
    transition: transform 0.15s, box-shadow 0.15s, border-color 0.15s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.home-btn svg {
    width: 100%;
    height: 100%;
    filter: drop-shadow(0 0 5px rgba(34, 211, 238, 0.9));
}

.home-btn:hover {
    border-color: #67e8f9;
    color: #67e8f9;
    box-shadow:
        0 0 22px rgba(34, 211, 238, 0.6),
        0 4px 12px rgba(0, 0, 0, 0.5);
}

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

.home-btn.hidden {
    display: none !important;
}

h1.game-logo {
    margin: 0 0 15px 0;
    line-height: 0;
}

.game-logo__img {
    display: block;
    width: min(100%, var(--logo-max-width));
    height: auto;
    margin: 0 auto;
    object-fit: contain;
    filter: drop-shadow(0 4px 12px rgba(0, 0, 0, 0.55));
    user-select: none;
    -webkit-user-drag: none;
}

h1.game-over-title {
    font-family: 'Righteous', cursive;
    margin: 0 0 15px 0;
    font-size: var(--game-over-title-size);
    background: linear-gradient(to bottom, #ffffff, #ef4444);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.5));
}

.sub-text {
    color: #93c5fd;
    font-size: var(--sub-text-size);
    margin-bottom: 30px;
    line-height: 1.5;
}

.accent-text {
    color: #22d3ee;
}

.stats-text {
    color: #f8fafc;
    font-size: var(--stats-text-size);
    font-weight: 700;
    margin-bottom: 5px;
}

.action-btn {
    background: linear-gradient(180deg, #39ff14, #22c55e);
    color: #081228;
    border: none;
    border-radius: 12px;
    padding: var(--btn-padding-y) var(--btn-padding-x);
    font-size: var(--btn-font-size);
    font-family: 'Righteous', cursive;
    letter-spacing: 1px;
    cursor: pointer;
    box-shadow: 0 6px 0 #15803d, 0 0 20px rgba(57, 255, 20, 0.35);
    transition: transform 0.1s, box-shadow 0.1s;
}

.action-btn--retry {
    background: linear-gradient(180deg, #22d3ee, #0284c7);
    color: #fff;
    box-shadow: 0 6px 0 #0369a1, 0 0 20px rgba(34, 211, 238, 0.4);
}

.action-btn--retry:active {
    box-shadow: 0 0 0 #0369a1, 0 4px 10px rgba(0, 0, 0, 0.4);
}

.action-btn:active {
    transform: translateY(6px);
    box-shadow: 0 0 0 #15803d, 0 4px 10px rgba(0, 0, 0, 0.4);
}

#top-hud {
    position: absolute;
    top: var(--hud-top);
    left: 50%;
    transform: translateX(-50%);
    width: var(--hud-width);
    display: flex;
    justify-content: center;
    z-index: 10;
    opacity: 0;
    transition: opacity 0.3s;
    pointer-events: none;
}

#progress-bar-container {
    width: var(--progress-bar-width);
    max-width: 100%;
    height: var(--progress-bar-height);
    background: rgba(8, 18, 40, 0.92);
    border: 2px solid rgba(34, 211, 238, 0.55);
    border-radius: 20px;
    padding: 2px;
    box-shadow: 0 0 12px rgba(34, 211, 238, 0.25), 0 4px 10px rgba(0, 0, 0, 0.5);
}

#progress-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, #39ff14, #22d3ee, #af52de);
    border-radius: 10px;
    box-shadow: 0 0 14px rgba(34, 211, 238, 0.8);
    transition: width 0.1s linear;
}

.hidden {
    display: none !important;
}

/* ─── Mobile restriction overlay ─────────────────────────────────────── */

#mobile-restrict-overlay {
    position: fixed;
    inset: 0;
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    box-sizing: border-box;
    background: rgba(6, 13, 36, 0.97);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}

#mobile-restrict-overlay .mobile-restrict-modal {
    animation: popIn 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

.mobile-restrict-icon {
    width: 72px;
    height: 72px;
    margin: 0 auto 20px;
    color: #22d3ee;
    filter: drop-shadow(0 0 12px rgba(34, 211, 238, 0.6));
}

.mobile-restrict-icon svg {
    width: 100%;
    height: 100%;
}

h1.mobile-restrict-title {
    font-family: 'Righteous', cursive;
    margin: 0 0 16px;
    font-size: var(--title-size);
    letter-spacing: 1px;
    background: linear-gradient(to bottom, #ffffff, #f59e0b);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.6));
}

.mobile-restrict-text {
    margin-bottom: 0;
}

body.mobile-restricted #game-container {
    pointer-events: none;
    user-select: none;
}

body.mobile-restricted #game-container canvas {
    filter: blur(6px) brightness(0.4);
}

/* ─── Responsive breakpoints ─────────────────────────────────────────── */

/* Desktop (≥1025px) — default :root values */

/* Tablet Landscape (769px – 1024px) */
@media screen and (min-width: 769px) and (max-width: 1024px) {
    :root {
        --modal-padding-x: 48px;
        --modal-padding-y: 36px;
        --title-size: 3.2rem;
        --game-over-title-size: 2.8rem;
        --sub-text-size: 1.05rem;
        --stats-text-size: 1.35rem;
        --btn-font-size: 1.35rem;
        --btn-padding-x: 44px;
        --home-btn-size: 38px;
        --progress-bar-width: 360px;
        --modal-max-width: 480px;
        --logo-max-width: 310px;
    }
}

/* Tablet Portrait (641px – 768px) */
@media screen and (min-width: 641px) and (max-width: 768px) {
    :root {
        --modal-padding-x: 36px;
        --modal-padding-y: 32px;
        --modal-radius: 18px;
        --title-size: 2.8rem;
        --game-over-title-size: 2.4rem;
        --sub-text-size: 1rem;
        --stats-text-size: 1.25rem;
        --btn-font-size: 1.25rem;
        --btn-padding-y: 13px;
        --btn-padding-x: 40px;
        --home-btn-size: 36px;
        --home-btn-offset: 10px;
        --hud-width: calc(100% - 100px);
        --progress-bar-width: 320px;
        --progress-bar-height: 9px;
        --modal-max-width: 440px;
        --logo-max-width: 275px;
    }
}

/* Mobile (≤640px) */
@media screen and (max-width: 640px) {
    :root {
        --modal-padding-x: 28px;
        --modal-padding-y: 28px;
        --modal-radius: 16px;
        --title-size: 2.2rem;
        --game-over-title-size: 2rem;
        --sub-text-size: 0.95rem;
        --stats-text-size: 1.15rem;
        --btn-font-size: 1.15rem;
        --btn-padding-y: 12px;
        --btn-padding-x: 36px;
        --home-btn-size: 34px;
        --home-btn-offset: 10px;
        --hud-top: 10px;
        --hud-width: calc(100% - 80px);
        --progress-bar-width: 280px;
        --progress-bar-height: 8px;
        --modal-max-width: 400px;
        --logo-max-width: 245px;
    }

    h1.game-over-title,
    h1.mobile-restrict-title {
        letter-spacing: 1px;
    }

    .sub-text {
        margin-bottom: 24px;
        line-height: 1.45;
    }

    .mobile-restrict-icon {
        width: 60px;
        height: 60px;
        margin-bottom: 16px;
    }
}

/* Small Mobile (≤480px) */
@media screen and (max-width: 480px) {
    :root {
        --modal-padding-x: 22px;
        --modal-padding-y: 24px;
        --modal-radius: 14px;
        --title-size: 1.75rem;
        --game-over-title-size: 1.6rem;
        --sub-text-size: 0.88rem;
        --stats-text-size: 1.05rem;
        --btn-font-size: 1.05rem;
        --btn-padding-y: 11px;
        --btn-padding-x: 30px;
        --home-btn-size: 32px;
        --home-btn-offset: 8px;
        --hud-width: calc(100% - 64px);
        --progress-bar-width: 240px;
        --progress-bar-height: 7px;
        --modal-max-width: 340px;
        --logo-max-width: 215px;
    }

    .action-btn {
        border-radius: 10px;
        box-shadow: 0 5px 0 #15803d, 0 0 16px rgba(57, 255, 20, 0.3);
    }

    .action-btn--retry {
        box-shadow: 0 5px 0 #0369a1, 0 0 16px rgba(34, 211, 238, 0.35);
    }

    .mobile-restrict-icon {
        width: 52px;
        height: 52px;
    }
}

/* Landscape Mobile (orientation: landscape, short height) */
@media screen and (orientation: landscape) and (max-height: 500px) {
    :root {
        --modal-padding-x: 32px;
        --modal-padding-y: 20px;
        --modal-radius: 14px;
        --title-size: 1.8rem;
        --game-over-title-size: 1.6rem;
        --sub-text-size: 0.85rem;
        --stats-text-size: 1rem;
        --btn-font-size: 1rem;
        --btn-padding-y: 10px;
        --btn-padding-x: 32px;
        --home-btn-size: 30px;
        --home-btn-offset: 6px;
        --hud-top: 6px;
        --hud-width: calc(100% - 72px);
        --progress-bar-width: 260px;
        --progress-bar-height: 7px;
        --modal-max-width: 480px;
        --logo-max-width: 230px;
    }

    #ui-layer {
        justify-content: center;
        padding: 8px 0;
        overflow-y: auto;
    }

    .popup-modal {
        padding: var(--modal-padding-y) var(--modal-padding-x);
    }

    h1.game-logo {
        margin-bottom: 8px;
    }

    h1.game-over-title,
    h1.mobile-restrict-title {
        margin-bottom: 8px;
    }

    .sub-text {
        margin-bottom: 16px;
        line-height: 1.35;
    }

    .mobile-restrict-icon {
        width: 48px;
        height: 48px;
        margin-bottom: 10px;
    }

    #mobile-restrict-overlay {
        padding: 12px;
        overflow-y: auto;
    }
}

/* Safe-area insets for notched devices */
@supports (padding: env(safe-area-inset-top)) {
    .home-btn {
        top: calc(var(--home-btn-offset) + env(safe-area-inset-top, 0px));
        left: calc(var(--home-btn-offset) + env(safe-area-inset-left, 0px));
    }

    #top-hud {
        top: calc(var(--hud-top) + env(safe-area-inset-top, 0px));
        width: calc(var(--hud-width) - env(safe-area-inset-left, 0px) - env(safe-area-inset-right, 0px));
    }

    #mobile-restrict-overlay {
        padding-top: calc(20px + env(safe-area-inset-top, 0px));
        padding-bottom: calc(20px + env(safe-area-inset-bottom, 0px));
        padding-left: calc(20px + env(safe-area-inset-left, 0px));
        padding-right: calc(20px + env(safe-area-inset-right, 0px));
    }
}
