:root {
    --app-max-width: 560px;
    --app-side-padding: 12px;
    --screen-gap: 10px;
    --menu-gap: 12px;
    --menu-height: 84px;
    --menu-safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-right: env(safe-area-inset-right, 0px);
    --safe-left: env(safe-area-inset-left, 0px);
    --app-height: 100dvh;
    --content-bottom-space: calc(var(--menu-height) + var(--menu-gap) + var(--menu-safe-bottom) + 24px);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: system-ui, -apple-system, sans-serif;
}

html,
body {
    width: 100%;
    min-height: 100%;
}

html {
    height: 100%;
}

body {
    min-height: 100vh;
    min-height: var(--app-height);
    color: #ffffff;
    overflow-x: hidden;
    background:
        linear-gradient(rgba(5, 10, 18, 0.50), rgba(5, 10, 18, 0.72)),
        url("../assets/backgrounds/background_main.png") center center / cover no-repeat fixed;
}

body::before {
    content: "";
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 0;
    background:
        radial-gradient(circle at 50% 20%, rgba(120, 220, 255, 0.16), transparent 28%),
        radial-gradient(circle at 78% 18%, rgba(255, 235, 140, 0.12), transparent 14%),
        radial-gradient(circle at 50% 70%, rgba(0, 255, 170, 0.08), transparent 34%);
}

body.telegram-webapp {
    overscroll-behavior: none;
    -webkit-tap-highlight-color: transparent;
}

#loading-screen {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    padding:
        max(12px, var(--safe-top))
        max(12px, var(--safe-right))
        max(12px, var(--menu-safe-bottom))
        max(12px, var(--safe-left));
    background:
        linear-gradient(rgba(5, 10, 18, 0.20), rgba(5, 10, 18, 0.40)),
        url("../assets/backgrounds/background_main.png") center center / cover no-repeat;
    transition: opacity 0.4s ease, visibility 0.4s ease;
}

#loading-screen.loading-hidden {
    opacity: 0;
    visibility: hidden;
}

.loading-visual {
    width: 100%;
    max-width: 420px;
    display: flex;
    justify-content: center;
}

.loading-image-wrap {
    position: relative;
    width: 100%;
}

.loading-image {
    width: 100%;
    display: block;
    border-radius: 26px;
    box-shadow: 0 22px 48px rgba(0, 0, 0, 0.28);
}

.loading-progress-overlay {
    position: absolute;
    left: 50%;
    bottom: 11.5%;
    transform: translateX(-50%);
    width: 72%;
    display: flex;
    align-items: center;
    gap: 10px;
}

.loading-progress-bar {
    flex: 1;
    height: 16px;
    border-radius: 999px;
    overflow: hidden;
    background: rgba(10, 18, 30, 0.40);
    box-shadow:
        inset 0 2px 8px rgba(0, 0, 0, 0.25),
        0 0 16px rgba(94, 255, 105, 0.12);
}

.loading-progress-fill {
    width: 0%;
    height: 100%;
    border-radius: 999px;
    background: linear-gradient(90deg, #32d9ff 0%, #43ff7e 45%, #d8ff3c 100%);
    box-shadow: 0 0 16px rgba(67, 255, 126, 0.34);
    transition: width 0.28s ease;
}

.loading-progress-text {
    min-width: 54px;
    text-align: right;
    font-size: 28px;
    font-weight: 900;
    color: #ffd95f;
    text-shadow:
        0 3px 10px rgba(0, 0, 0, 0.36),
        0 0 10px rgba(255, 221, 95, 0.18);
}

#app {
    position: relative;
    z-index: 1;
    width: min(100%, var(--app-max-width));
    min-height: var(--app-height);
    margin: 0 auto;
    padding:
        max(10px, var(--safe-top))
        max(var(--app-side-padding), var(--safe-right))
        var(--content-bottom-space)
        max(var(--app-side-padding), var(--safe-left));
    display: flex;
    flex-direction: column;
    gap: var(--screen-gap);
}

main,
#game {
    width: 100%;
}

#game {
    flex: 1 1 auto;
    min-height: 0;
}

.screen {
    display: none;
    width: 100%;
    min-width: 0;
    padding-bottom: 0;
}

.screen:not(.hidden),
.screen.active-screen {
    display: block;
}

.hidden {
    display: none !important;
}

.panel.card {
    width: 100%;
    min-width: 0;
    overflow: hidden;
    background: linear-gradient(
        180deg,
        rgba(14, 24, 44, 0.58) 0%,
        rgba(10, 18, 34, 0.72) 100%
    );
    border: 1px solid rgba(255, 255, 255, 0.09);
    border-radius: 24px;
    padding: 16px;
    box-shadow:
        0 14px 34px rgba(0, 0, 0, 0.18),
        inset 0 1px 0 rgba(255, 255, 255, 0.05);
    backdrop-filter: blur(6px);
}

.panel.card h2 {
    margin-bottom: 14px;
    text-align: center;
    font-size: 24px;
    font-weight: 900;
    color: #ffffff;
}

button {
    font: inherit;
}

img {
    display: block;
    max-width: 100%;
}

#zooList,
#shopList,
#boxesList,
#missionsList,
#rankingList {
    width: 100%;
    min-width: 0;
}

@media (max-width: 520px) {
    :root {
        --app-side-padding: 8px;
        --screen-gap: 8px;
        --menu-gap: 10px;
        --menu-height: 82px;
        --content-bottom-space: calc(var(--menu-height) + var(--menu-gap) + var(--menu-safe-bottom) + 22px);
    }

    .loading-visual {
        max-width: 360px;
    }

    .loading-progress-overlay {
        width: 73%;
        bottom: 11%;
        gap: 8px;
    }

    .loading-progress-bar {
        height: 13px;
    }

    .loading-progress-text {
        min-width: 44px;
        font-size: 22px;
    }

    .panel.card {
        border-radius: 20px;
        padding: 14px;
    }

    .panel.card h2 {
        font-size: 22px;
    }
}

@media (max-width: 380px) {
    :root {
        --app-side-padding: 6px;
        --menu-gap: 8px;
        --menu-height: 78px;
        --content-bottom-space: calc(var(--menu-height) + var(--menu-gap) + var(--menu-safe-bottom) + 20px);
    }

    .panel.card {
        padding: 12px;
        border-radius: 18px;
    }

    .panel.card h2 {
        font-size: 20px;
    }
}