:root {
    color-scheme: dark;
    --app: #151518;
    --sidebar: #18191d;
    --card: #1d1d21;
    --border: #34343c;
    --text: #f1f1f5;
    --muted: #b0afbd;
    --accent: #b0384b;
    --button: #101014;
    --chamfer: none;
    --r-lg: 22px;
    --r-md: 16px;
    --r-sm: 12px;
    --top-space: 70px; /* пустое место под кнопки Telegram Mini App */
}

body {
    min-height: 100vh;
    padding: var(--top-space) 0 calc(88px + env(safe-area-inset-bottom));
    color: var(--text);
    background: var(--app);
    isolation: isolate;
    font: 400 15px/1.5 "Segoe UI", Arial, sans-serif;
}

body::before {
    content: "";
    position: fixed;
    inset: 0;
    z-index: -1;
    background: linear-gradient(125deg, #13151ae6, #151518be), url("assets/tracker-background.jpg") center / cover;
}

.demo-label { margin: 10px auto 0; padding-inline: 16px; width: min(100%, 1120px); color: var(--muted); font-size: 12px; }
.loading-container { height: 38vh; }
.pulsing-logo { width: 64px; }
.main-content-wrapper { max-width: 1120px; margin-inline: auto; padding: 16px; overflow: visible; }
.app-tab-page.active { animation: tracker-enter .18s ease-out; }
@keyframes tracker-enter { from { opacity: .65; translate: 0 4px; } to { opacity: 1; translate: 0; } }

.glass-panel, .card.glass-panel {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    box-shadow: 0 6px 20px #0004;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    margin-inline: 0;
}
#error-info { max-width: 520px; margin: 24px auto; }
#user-info { gap: 12px; grid-template-columns: minmax(0, 1fr); }
#user-info > .card { margin: 0 !important; }
.profile-header {
    text-align: left;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    grid-template-rows: 1fr 1fr;
    column-gap: 15px;
    align-items: center;
    position: relative;
    padding: 18px 76px 18px 18px;
    margin: 0;
    min-height: 108px;
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    background: var(--card);
}
.profile-header h2 { align-self: end; margin: 0; font-size: clamp(18px, 4vw, 26px); overflow-wrap: anywhere; }
.avatar-red { grid-row: 1 / 3; width: 56px; height: 56px; border: 1px solid #555360; border-radius: 50%; box-shadow: none; object-fit: cover; }
#rank-badge { justify-self: start; align-self: start; margin-top: 4px !important; padding: 2px 8px !important; border-color: #61333e !important; color: #f2a8b4 !important; border-radius: 999px !important; }
.quiz-island { top: 28px; right: 18px; border-radius: var(--r-md); background: var(--button); border-color: var(--border); color: var(--text); box-shadow: none; z-index: 2; }
.quiz-island, .quiz-island:active:not(.cooldown),
.work-btn-container, .work-btn-container.active, .work-btn-container.active:hover,
.top-btn-container, .top-btn-container:hover {
    border-radius: var(--r-md) !important;
    border: 1px solid var(--border) !important;
    background: var(--button) !important;
    box-shadow: none !important;
    backdrop-filter: none !important;
}
.quiz-island svg, .top-btn-container svg { color: var(--text); stroke: currentColor; }
.work-btn-container {
    width: auto;
    min-width: 76px;
    min-height: 40px;
    height: auto;
    padding: 7px 10px;
    font: 600 13px/1.2 "Segoe UI", Arial, sans-serif;
    color: var(--text);
    clip-path: var(--chamfer);
}
.work-btn-container.disabled { color: var(--muted); }
.balance-label, .progress-info, .mileage-month { color: var(--muted); }
.balance-value { color: var(--text); font-size: clamp(22px, 5vw, 32px); font-variant-numeric: tabular-nums; }
#balance { color: #e0b773; }
.progress-container { height: 8px; border-radius: 999px; overflow: hidden; background: #303039; box-shadow: none; }
.progress-bar { border-radius: 999px; }
.progress-bar.orange, .progress-bar.green { background: var(--accent); box-shadow: none; }
.progress-bar.green { background: #ce7585; }
.top-nav-island, .dynamic-island { border-radius: var(--r-lg); box-shadow: none; }
.shop-btn.news-open-btn, .mobile-shop-btn, .mobile-quiz-btn {
    background: var(--button);
    color: var(--text);
    border-radius: var(--r-md);
    border-color: var(--border);
    box-shadow: none;
}
.mobile-quiz-btn.correct { border-color: #5a9d71; }
.mobile-quiz-btn.wrong { border-color: #be5466; }
.news-thumb { aspect-ratio: 16 / 9; object-fit: cover; border-radius: var(--r-md); }

.bottom-nav-container { bottom: 0; padding: 0; }
.bottom-dynamic-island {
    max-width: none;
    height: auto;
    gap: 4px;
    padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
    background: var(--sidebar);
    border: 0;
    border-top: 1px solid var(--border);
    border-radius: var(--r-lg) var(--r-lg) 0 0;
    box-shadow: none;
    backdrop-filter: none;
}
.bottom-nav-btn {
    min-width: 0;
    min-height: 49px;
    border: 0;
    border-radius: var(--r-sm);
    padding: 6px 4px;
    background: #131316;
    color: var(--muted);
    clip-path: var(--chamfer);
    transition: background-color .16s ease, color .16s ease;
}
.bottom-nav-btn.active { background: var(--accent); color: #fff; text-shadow: none; }
.bottom-nav-btn.active .nav-svg { filter: none; transform: none; }
.bottom-nav-btn:not(.active):hover { background: #292931; color: var(--text); }
.bottom-nav-btn span { text-transform: none; letter-spacing: 0; font-size: 11px; }
.nav-svg { width: 18px; height: 18px; flex-shrink: 0; }

.release-dialog {
    width: min(700px, calc(100vw - 28px));
    max-height: calc(100dvh - 28px);
    padding: 0;
    border: 1px solid #47424b;
    border-radius: var(--r-lg);
    overflow: hidden;
    background: #17171c;
    color: var(--text);
    box-shadow: 0 24px 80px #0009;
}
.release-dialog::backdrop { background: #09090bc9; }
.release-dialog[open] { animation: release-enter .38s cubic-bezier(.2,.75,.25,1) both; }
.release-dialog[open]::backdrop { animation: release-backdrop .28s ease-out both; }
@keyframes release-enter {
    from { opacity: 0; transform: translateY(16px) scale(.98); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes release-backdrop { from { opacity: 0; } to { opacity: 1; } }
.release-copy {
    position: relative;
    padding: clamp(23px, 5vw, 44px);
    min-height: 315px;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    justify-content: center;
    background: linear-gradient(90deg, #151519 8%, #151519f2 39%, #15151925 100%),
        url("assets/tracker-release.jpg") right center / auto 100% no-repeat;
}
.release-label { color: #ed9cab; font-size: 11px; font-weight: 700; letter-spacing: .14em; margin: 0 0 9px; }
.release-copy h1 { margin: 0; font-size: clamp(28px, 5vw, 46px); line-height: 1.08; letter-spacing: -.025em; }
.release-text { max-width: 32ch; margin: 14px 0 23px; color: #d0ced8; font-size: 14px; }
.release-link {
    display: inline-flex;
    align-items: center;
    gap: 12px;
    padding: 11px 17px;
    border-radius: var(--r-sm);
    background: var(--accent);
    color: #fff;
    text-decoration: none;
    font-size: 14px;
    font-weight: 600;
}
.release-link:hover { background: #c7485e; }
.release-close {
    position: absolute;
    top: 10px;
    right: 10px;
    z-index: 2;
    width: 38px;
    height: 38px;
    background: #121216;
    border: 1px solid var(--border);
    border-radius: 50%;
    color: var(--text);
    font-size: 24px;
    line-height: 1;
    cursor: pointer;
}
button:focus-visible, a:focus-visible { outline: 2px solid #f1a4b2; outline-offset: 2px; }
.bottom-nav-btn:focus-visible, .release-link:focus-visible { outline-offset: -4px; }

@media (min-width: 800px) {
    body { padding: 78px 0 32px 216px; }
    .main-content-wrapper { padding: 24px 32px; }
    .demo-label { padding-inline: 32px; }
    .bottom-nav-container {
        top: 0;
        width: 216px;
        padding: 90px 17px 20px;
        background: var(--sidebar);
        border-right: 1px solid var(--border);
        pointer-events: auto;
    }
    .bottom-dynamic-island { flex-direction: column; align-items: stretch; padding: 0; border: 0; gap: 9px; }
    .bottom-nav-btn { flex: none; flex-direction: row; justify-content: flex-start; padding: 0 12px; gap: 13px; }
    .bottom-nav-btn span { font-size: 13px; }
    #user-info { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
    .profile-header, #user-info > .profile-header + .card { grid-column: 1 / -1; }
    #news-feed-container, #convoys-list-container, #shop-list-container {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        align-items: stretch;
        gap: 14px;
    }
    #news-feed-container > *, #convoys-list-container > *, #shop-list-container > * { min-width: 0; }
}

@media (max-width: 580px) {
    .release-copy {
        padding-top: 126px;
        background: linear-gradient(0deg, #151519 47%, #15151900 100%),
            url("assets/tracker-release.jpg") center top / 100% auto no-repeat;
    }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

#work-btn {
    width: 44px;
    min-width: 44px;
    height: 42px;
    padding: 0;
    color: var(--muted);
}
#work-btn.active { color: #f1c37c; }
#work-btn.active:hover { background: #29232a !important; color: #ffe3ac; }

#leaderboard-section .dynamic-island {
    gap: 5px;
    padding: 0;
    height: auto;
    border: 0;
    background: transparent;
    backdrop-filter: none;
}
#leaderboard-section .nav-btn {
    width: auto;
    min-height: 36px;
    padding: 7px 13px;
    border-radius: var(--r-sm);
    background: var(--button);
    clip-path: var(--chamfer);
    color: var(--muted);
    font-family: inherit;
    font-size: 12px;
    font-weight: 600;
    line-height: 1.3;
    text-shadow: none;
    transition: background-color .16s ease, color .16s ease;
}
#leaderboard-section .nav-btn:hover { background: #292931; color: var(--text); }
#leaderboard-section .nav-btn.active { background: var(--accent) !important; color: #fff !important; }
#leaderboard-section .top-nav-island { margin-inline: 0; padding-inline: 42px; }
#leaderboard-section .island-close-btn {
    right: 0;
    border-radius: 50% !important;
    background: var(--button);
    border-color: var(--border);
    color: var(--text);
}
#leaderboard-section .nav-btn:focus-visible { outline-offset: -4px; }

.app-tab-page.active { animation: tracker-enter .26s cubic-bezier(.2,.75,.25,1); }
#tab-content-profile.active .profile-header,
#tab-content-profile.active #user-info > .card {
    animation: tracker-card-enter .32s cubic-bezier(.2,.75,.25,1) both;
}
#tab-content-profile.active #user-info > .card:nth-of-type(2) { animation-delay: .025s; }
#tab-content-profile.active #user-info > .card:nth-of-type(3) { animation-delay: .055s; }
#tab-content-profile.active #user-info > .card:nth-of-type(4) { animation-delay: .085s; }
#tab-content-profile.active #user-info > .card:nth-of-type(5) { animation-delay: .115s; }
@keyframes tracker-card-enter {
    from { opacity: .25; translate: 0 9px; }
    to { opacity: 1; translate: 0; }
}

.bottom-nav-btn, .release-link, #leaderboard-section .nav-btn {
    transition: background-color .18s ease, color .18s ease, scale .14s ease;
}
.bottom-nav-btn .nav-svg { transition: translate .18s ease; }
.bottom-nav-btn:active, .release-link:active, #leaderboard-section .nav-btn:active {
    scale: .97;
}
@media (hover: hover) {
    .bottom-nav-btn:hover .nav-svg { translate: 0 -2px; }
}

@media (prefers-reduced-motion: reduce) {
    #tab-content-profile.active .profile-header,
    #tab-content-profile.active #user-info > .card { animation-delay: 0s !important; }
}

html, body { overflow-x: clip; }
.app-tab-page.active { animation-name: tracker-tab-swap; }
@keyframes tracker-tab-swap {
    from { opacity: .55; translate: var(--tab-offset, 0) 3px; }
    to { opacity: 1; translate: 0; }
}

#tab-content-shop, #shop-list-container, #shop-list-container > .card {
    min-width: 0;
    max-width: 100%;
}
#shop-list-container .news-card-title, #shop-list-container .news-card-summary {
    overflow-wrap: anywhere;
}
#shop-list-container .mobile-shop-btn { max-width: 100%; white-space: normal; }
#mobile-shop-modal-content { max-height: calc(100dvh - 24px); overflow-y: auto; }
#shop-list-container, #news-feed-container, #convoys-list-container,
#news-opened-view, #top-drivers-container { padding-bottom: 0 !important; }
#leaderboard-section { margin-bottom: 0 !important; }

@media (max-width: 799px) {
    .bottom-nav-container {
        bottom: calc(12px + env(safe-area-inset-bottom, 0px));
        padding-inline: 12px;
    }
    .bottom-dynamic-island {
        --nav-index: 0;
        --nav-edge: 5px;
        --nav-gap: 4px;
        --nav-slot: calc((100% - 2 * var(--nav-edge) - 3 * var(--nav-gap)) / 4);
        position: relative;
        isolation: isolate;
        display: grid;
        grid-template-columns: repeat(4, minmax(0, 1fr));
        max-width: 460px;
        gap: var(--nav-gap);
        padding: var(--nav-edge);
        border: 1px solid #474750;
        border-radius: 17px;
        background: #1a1a20;
        box-shadow: 0 8px 26px #0008;
        transform-origin: bottom center;
        transition: transform .23s cubic-bezier(.25,.8,.3,1), box-shadow .23s ease;
    }
    .bottom-dynamic-island.is-compact {
        transform: scale(.92);
        box-shadow: 0 6px 18px #0008;
    }
    .bottom-dynamic-island::before {
        content: "";
        position: absolute;
        top: var(--nav-edge);
        bottom: var(--nav-edge);
        left: calc(var(--nav-edge) + var(--nav-index) * (var(--nav-slot) + var(--nav-gap)));
        width: var(--nav-slot);
        z-index: -1;
        border-radius: 11px;
        background: var(--accent);
        transition: left .26s cubic-bezier(.25,.8,.3,1);
    }
    .bottom-nav-btn, .bottom-nav-btn.active {
        border-radius: 11px;
        background: transparent;
        clip-path: none;
    }
}
