/* ==========================================================================
   Mobile bottom navigation (loaded last). Markup + logic: js/app.js (renderShell, Bnav).
   Games · Rewards · [Cash desk] · Chat · Profile. Replaces the hamburger menu on phones.
   ========================================================================== */

/* Hidden on desktop. */
.bnav, .bn-scrim, .bn-sheet { display: none; }

@media (max-width: 920px) {
    :root {
        --bn-h: 60px;
        --bn-full: calc(var(--bn-h) + env(safe-area-inset-bottom, 0px)); /* the bar itself, always */
        --bn-total: var(--bn-full); /* what floats above it; 0 + safe area while the bar is slid away */
    }
    body.bn-hidden:not(.bn-sheet-open):not(.chat-open) { --bn-total: env(safe-area-inset-bottom, 0px); }

    /* The bar replaces the hamburger menu and the chat button in the top bar. */
    .topbar .menu-btn,
    .topbar .top-right .chat-toggle { display: none; }

    /* Keep page content (and the footer) clear of the bar. */
    body { padding-bottom: var(--bn-full); }
    body.chat-open,
    body.bn-sheet-open { overflow: hidden; }

    /* --- The bar -------------------------------------------------------------------------- */
    .bnav {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 55;
        display: grid;
        grid-template-columns: 1fr 1fr 88px 1fr 1fr;
        align-items: stretch;
        height: var(--bn-full);
        padding: 0 max(4px, env(safe-area-inset-right)) env(safe-area-inset-bottom, 0px) max(4px, env(safe-area-inset-left));
        background: var(--bg2);
        border-top: 1px solid color-mix(in srgb, var(--accent) 22%, var(--line));
        box-shadow: 0 -10px 30px rgba(0, 0, 0, .35);
        transition: transform .2s ease;
    }
    /* Soft keyboard open (typing in chat, bet fields…): the bar would only eat screen space. */
    body.kb-open .bnav { transform: translateY(calc(100% + 40px)); }
    /* Game pages: slides away while scrolling down. The extra 40px also hides the Cash desk button that sticks out. */
    body.bn-hidden:not(.bn-sheet-open):not(.chat-open) .bnav { transform: translateY(calc(100% + 40px)); }
    body.kb-open { padding-bottom: 0; }

    .bn-tab {
        position: relative;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 3px;
        min-width: 0;
        height: var(--bn-h);
        padding: 0;
        border: 0;
        background: none;
        color: var(--muted);
        font: 700 11px/1 var(--font);
        letter-spacing: .02em;
        cursor: pointer;
        text-decoration: none;
        touch-action: manipulation;
        -webkit-tap-highlight-color: transparent;
        transition: color .15s;
    }
    .bn-tab .ic { width: 24px; height: 24px; transition: transform .15s; }
    .bn-tab:active .ic { transform: scale(.88); }
    .bn-tab.active { color: var(--text); }
    .bn-tab.active .ic { color: var(--accent2); }
    .bn-tab::before {
        content: '';
        position: absolute;
        top: 0;
        left: 50%;
        width: 26px;
        height: 3px;
        border-radius: 0 0 4px 4px;
        background: var(--accent);
        box-shadow: 0 2px 10px var(--accent);
        transform: translateX(-50%) scaleX(0);
        transition: transform .18s ease;
    }
    .bn-tab.active::before { transform: translateX(-50%) scaleX(1); }

    /* --- Round Cash desk button in the middle -------------------------------------------- */
    .bn-cash {
        position: relative;
        display: flex;
        flex-direction: column;
        align-items: center;
        align-self: start;
        gap: 2px;
        margin-top: -24px;
        padding: 0;
        border: 0;
        background: none;
        color: var(--text);
        font: 800 11px/1 var(--font);
        letter-spacing: .02em;
        cursor: pointer;
        touch-action: manipulation;
        -webkit-tap-highlight-color: transparent;
    }
    .bn-coin {
        display: grid;
        place-items: center;
        width: 60px;
        height: 60px;
        border-radius: 50%;
        color: var(--on-accent);
        background: linear-gradient(160deg, var(--accent2), var(--accent) 60%);
        /* The ring in the bar colour makes it look cut out of the bar. */
        box-shadow:
            0 0 0 5px var(--bg2),
            0 0 0 6px color-mix(in srgb, var(--accent) 30%, var(--line)),
            0 8px 24px color-mix(in srgb, var(--accent) 55%, transparent),
            inset 0 1px 0 rgba(255, 255, 255, .35),
            inset 0 -3px 0 var(--accent-d, rgba(0, 0, 0, .25));
        transition: transform .12s ease, box-shadow .12s;
    }
    .bn-coin .ic { width: 28px; height: 28px; }
    .bn-cash:active .bn-coin { transform: scale(.93); }
    .bn-cash:focus-visible .bn-coin,
    .bn-tab:focus-visible { outline: 2px solid var(--accent2); outline-offset: 2px; border-radius: 12px; }
    .bn-cash .bn-lbl { color: var(--accent2); }

    /* --- Games sheet (opens above the bar) ----------------------------------------------- */
    .bn-scrim {
        display: block;
        position: fixed;
        left: 0;
        right: 0;
        top: 0;
        bottom: var(--bn-total);
        z-index: 52;
        background: rgba(3, 6, 18, .62);
        opacity: 0;
        pointer-events: none;
        transition: opacity .18s ease;
    }
    body.bn-sheet-open .bn-scrim { opacity: 1; pointer-events: auto; }

    .bn-sheet {
        display: block;
        position: fixed;
        left: 8px;
        right: 8px;
        /* Floats above the round Cash desk button, which sticks out of the bar. */
        bottom: calc(var(--bn-total) + 34px);
        z-index: 53;
        max-height: calc(var(--vh) - var(--top) - var(--bn-total) - 52px);
        overflow-y: auto;
        overscroll-behavior: contain;
        padding: 14px 12px 12px;
        border-radius: 22px;
        background: linear-gradient(170deg, var(--panel2), var(--bg2));
        border: 1px solid color-mix(in srgb, var(--accent) 26%, var(--line2));
        box-shadow: 0 30px 70px rgba(0, 0, 0, .7), 0 0 50px -16px color-mix(in srgb, var(--accent) 45%, transparent);
        opacity: 0;
        visibility: hidden;
        transform: translateY(14px);
        transition: opacity .18s ease, transform .18s ease, visibility 0s linear .18s;
    }
    body.bn-sheet-open .bn-sheet {
        opacity: 1;
        visibility: visible;
        transform: none;
        transition-delay: 0s;
    }
    .bn-sheet h4 {
        margin: 0 4px 10px;
        font-size: 11px;
        font-weight: 800;
        letter-spacing: .1em;
        text-transform: uppercase;
        color: var(--muted);
    }
    .bn-games {
        display: grid;
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 8px;
    }
    .bn-game {
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 7px;
        padding: 10px 4px 9px;
        border-radius: 14px;
        background: rgba(255, 255, 255, .04);
        border: 1px solid var(--line);
        color: var(--text);
        font-size: 12.5px;
        font-weight: 700;
        text-align: center;
        line-height: 1.15;
        text-decoration: none;
        touch-action: manipulation;
    }
    .bn-game:active { background: color-mix(in srgb, var(--accent) 16%, transparent); }
    .bn-art { width: 46px; height: 46px; border-radius: 12px; overflow: hidden; flex: none; }
    .bn-art img, .bn-art svg { width: 100%; height: 100%; object-fit: cover; display: block; filter: none; }

    .bn-more {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 6px;
        margin-top: 12px;
        padding-top: 12px;
        border-top: 1px solid var(--line);
    }
    .bn-more a {
        display: flex;
        align-items: center;
        gap: 10px;
        height: 46px;
        padding: 0 12px;
        border-radius: 12px;
        color: var(--text);
        font-size: 14px;
        font-weight: 700;
        text-decoration: none;
        background: rgba(255, 255, 255, .04);
        touch-action: manipulation;
    }
    .bn-more a:active { background: color-mix(in srgb, var(--accent) 16%, transparent); }
    .bn-more a .ic { width: 20px; height: 20px; color: var(--accent2); flex: none; }
    .bn-more a.owner { color: var(--gold); }
    .bn-more a.owner .ic { color: var(--gold); }
    .bn-more a[hidden] { display: none; }

    /* --- Chat becomes a full-screen panel between the top bar and the bar ---------------- */
    body.chat-open .chat {
        top: var(--top);
        bottom: var(--bn-total);
        left: 0;
        right: 0;
        width: 100%;
        height: auto;
        border-right: 0;
        box-shadow: none;
        z-index: 40;
        /* Opaque: on desktop the chat is a glass side panel, on a phone it covers the page. */
        background: var(--bg2);
        -webkit-backdrop-filter: none;
        backdrop-filter: none;
    }
    body.kb-open.chat-open .chat { bottom: 0; }
    /* The round Cash desk button sticks out above the bar: keep the message box clear of it. */
    body.chat-open:not(.kb-open) .chat-form { padding-bottom: 34px; }

    /* --- Things that floated at the bottom now float above the bar ----------------------- */
    #toasts:not([data-pos^="t"]) { bottom: calc(var(--bn-total) + 34px); transition: bottom .2s ease; }
    .verify-bar { bottom: calc(var(--bn-total) + 34px); }
    .ls-panel { bottom: calc(var(--bn-total) + 12px); }
    .settings .set-savebar { bottom: calc(var(--bn-total) + 12px); }
}

@media (max-width: 920px) and (max-height: 430px) {
    /* Landscape phones: slimmer bar. */
    :root { --bn-h: 50px; }
    .bn-tab .bn-lbl { display: none; }
    .bn-tab .ic { width: 22px; height: 22px; }
    .bn-cash { margin-top: -16px; }
    .bn-cash .bn-lbl { display: none; }
    .bn-coin { width: 52px; height: 52px; }
}

@media (prefers-reduced-motion: reduce) {
    .bnav, .bn-tab, .bn-tab .ic, .bn-tab::before, .bn-coin, .bn-scrim, .bn-sheet { transition: none; }
}
