/*
 * Battlefy Zone — Application Shell Foundation
 */

.bz-app {
    min-height: 100vh;
    background: var(--bg-primary);
}

.bz-sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: var(--z-sidebar);
    width: var(--sidebar-width);
    display: flex;
    flex-direction: column;
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    border-right: 1px solid var(--sidebar-border);
}

.bz-sidebar__brand {
    min-height: 76px;
    display: flex;
    align-items: center;
    padding: 1rem 1.25rem;
}

.bz-sidebar__nav {
    flex: 1;
    overflow-y: auto;
    padding: .75rem;
    scrollbar-width: thin;
    scrollbar-color: color-mix(in srgb, var(--accent) 62%, var(--sidebar-border)) transparent;
}

.bz-sidebar__nav::-webkit-scrollbar {
    width: 6px;
}

.bz-sidebar__nav::-webkit-scrollbar-track {
    background: transparent;
    margin: .65rem 0;
}

.bz-sidebar__nav::-webkit-scrollbar-thumb {
    min-height: 42px;
    border-radius: 999px;
    background: color-mix(in srgb, var(--accent) 62%, var(--sidebar-border));
}

.bz-sidebar__nav::-webkit-scrollbar-thumb:hover {
    background: var(--accent);
}

.bz-sidebar__section {
    margin: 1.15rem .55rem .5rem;
    color: var(--sidebar-text-muted);
    font-size: .72rem;
    font-weight: var(--font-weight-bold);
    letter-spacing: .08em;
    text-transform: uppercase;
}

.bz-sidebar__link {
    display: flex;
    align-items: center;
    gap: .75rem;
    min-height: 44px;
    margin: .2rem 0;
    padding: .65rem .8rem;
    border-radius: var(--radius-md);
    color: var(--sidebar-text-muted);
    text-decoration: none;
    font-weight: var(--font-weight-semibold);
    transition:
        background-color var(--duration-fast) var(--ease-standard),
        color var(--duration-fast) var(--ease-standard),
        transform var(--duration-fast) var(--ease-standard);
}

.bz-sidebar__link:hover {
    color: var(--sidebar-text);
    background: var(--sidebar-surface);
    transform: translateX(2px);
}

.bz-sidebar__link[aria-current="page"],
.bz-sidebar__link.is-active {
    color: var(--sidebar-active-text);
    background: var(--sidebar-active-bg);
}

.bz-sidebar__link svg {
    width: 19px;
    height: 19px;
    flex: 0 0 auto;
}

/* [hidden] must win over the flex display above, or auth-gated links
   (Login/Register) stay visible after JS hides them. */
.bz-sidebar__link[hidden] {
    display: none !important;
}

.bz-main {
    min-height: 100vh;
    margin-left: var(--sidebar-width);
}

.bz-mobile-header {
    display: none;
}

/*
 * [hidden] is authoritative. The JS adds .is-open after removing hidden.
 * This prevents the drawer from being stuck at display:none.
 */
.bz-mobile-drawer[hidden] {
    display: none !important;
}

.bz-mobile-drawer.is-open {
    position: fixed;
    inset: 0;
    z-index: var(--z-drawer);
    display: flex;
    pointer-events: auto;
}

.bz-mobile-drawer__backdrop {
    position: absolute;
    inset: 0;
    background: var(--surface-overlay);
    backdrop-filter: blur(4px);
}

.bz-mobile-drawer__panel {
    position: relative;
    width: min(88vw, 320px);
    height: 100%;
    overflow-y: auto;
    padding: 1rem;
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    box-shadow: var(--shadow-lg);
    animation: bz-drawer-in var(--duration-normal) var(--ease-spring);
}

@keyframes bz-drawer-in {
    from { transform: translateX(-100%); }
    to { transform: translateX(0); }
}

/*
 * Global mobile navigation drawer.
 * It is intentionally above the mobile header while open so the drawer
 * never appears behind the header on pages such as blog.html.
 */
.bz-mobile-drawer {
    position: fixed;
    inset: 0;
    z-index: 1300;
    display: flex;
    pointer-events: none;
    visibility: hidden;
    opacity: 0;
    overflow: hidden;
    transition:
        opacity 240ms var(--ease-standard),
        visibility 0s linear 260ms;
}

.bz-mobile-drawer[hidden] {
    display: none !important;
}

.bz-mobile-drawer.is-open {
    pointer-events: auto;
    visibility: visible;
    opacity: 1;
    transition:
        opacity 240ms var(--ease-standard),
        visibility 0s linear 0s;
}

.bz-mobile-drawer__backdrop {
    position: absolute;
    inset: 0;
    background: var(--surface-overlay);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
    opacity: 0;
    transition: opacity 260ms var(--ease-standard);
}

.bz-mobile-drawer.is-open .bz-mobile-drawer__backdrop {
    opacity: 1;
}

.bz-mobile-drawer__panel {
    position: relative;
    z-index: 1;
    width: min(88vw, 390px);
    height: 100dvh;
    max-height: 100dvh;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    padding: max(1rem, env(safe-area-inset-top))
             1rem
             max(1rem, env(safe-area-inset-bottom));
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    box-shadow: var(--shadow-lg);
    transform: translateX(-104%);
    transition: transform 260ms var(--ease-spring);
    scrollbar-width: thin;
    scrollbar-color:
        color-mix(in srgb, var(--accent) 70%, var(--sidebar-border))
        transparent;
}

.bz-mobile-drawer__panel::-webkit-scrollbar {
    width: 6px;
}

.bz-mobile-drawer__panel::-webkit-scrollbar-thumb {
    min-height: 42px;
    border-radius: 999px;
    background: color-mix(in srgb, var(--accent) 62%, var(--sidebar-border));
}

.bz-mobile-drawer.is-open .bz-mobile-drawer__panel {
    transform: translateX(0);
}

@keyframes bz-drawer-in {
    from { transform: translateX(-100%); }
    to { transform: translateX(0); }
}

@media (max-width: 1023px) {
    :root {
        --bz-mobile-header-content-gap: 1.2rem;
    }

    .bz-sidebar {
        display: none;
    }

    .bz-main {
        margin-left: 0;
    }

    /*
     * One mobile header-to-content rhythm for every shell page. The shell
     * mounts #bzGlobalHeader immediately before .bz-main, so this replaces
     * the old collection of page-specific 68px compensation offsets.
     */
    #bzGlobalHeader + .bz-main {
        padding-block-start: var(--bz-mobile-header-content-gap) !important;
    }

    #bzGlobalHeader + .bz-main > :is(.bz-container, [class$="-shell"]) {
        padding-block-start: 0 !important;
    }

    /*
     * The global mobile header stays below the drawer while the drawer is open.
     * This prevents a logo/control from ever appearing above the navigation.
     */
    .bz-global-mobile-header,
    .bz-mobile-header {
        position: relative;
        z-index: 100 !important;
        min-height: 68px;
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 1rem;
        padding:
            max(.55rem, env(safe-area-inset-top))
            var(--page-padding)
            .55rem;
        background: transparent;
        backdrop-filter: none;
        -webkit-backdrop-filter: none;
        isolation: isolate;
    }

    .bz-mobile-header .bz-icon-button {
        position: relative;
        z-index: 2;
        width: 44px;
        height: 44px;
        min-width: 44px;
        border-radius: 50%;
        background: color-mix(in srgb, var(--surface) 82%, transparent);
        border-color: color-mix(in srgb, var(--border) 78%, transparent);
        box-shadow: 0 1px 0 color-mix(in srgb, var(--text-primary) 6%, transparent);
        backdrop-filter: blur(12px);
        -webkit-backdrop-filter: blur(12px);
    }

    /* Global mobile-header boundary line. */
    .bz-global-mobile-header::after,
    .bz-mobile-header::after {
        content: "";
        position: absolute;
        left: var(--page-padding);
        right: var(--page-padding);
        bottom: 0;
        height: 1px;
        background: color-mix(in srgb, var(--border) 82%, var(--text-primary) 8%);
        box-shadow: 0 1px 0 color-mix(in srgb, var(--surface) 55%, transparent);
        pointer-events: none;
        z-index: 20;
    }

    /*
     * Authoritative global drawer stacking.
     * The drawer must sit above the entire mobile header/logo/hero.
     */
    .bz-global-mobile-header ~ .bz-mobile-drawer,
    .bz-mobile-drawer {
        position: fixed !important;
        inset: 0 !important;
        z-index: 9999 !important;
    }

    .bz-mobile-drawer__panel {
        width: min(88vw, 390px);
        height: 100dvh;
        max-height: 100dvh;
    }

    /* ============================================================
       Global mobile navigation visual system
       Shared by index.html, blog.html and every future page.
       ============================================================ */

    .bz-global-mobile-panel {
        padding:
            max(1rem, env(safe-area-inset-top))
            1rem
            max(1rem, env(safe-area-inset-bottom));
    }

    .bz-global-mobile-panel .index-mobile-panel__header {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 1rem;
        padding: .15rem 0 .9rem;
        margin-bottom: .75rem;
        border-bottom: 1px solid var(--sidebar-border);
    }

    .bz-global-mobile-panel .index-mobile-panel__header > div {
        display: flex;
        flex-direction: column;
        gap: .2rem;
        min-width: 0;
    }

    .bz-global-mobile-panel .index-mobile-panel__eyebrow {
        color: var(--accent);
        font-size: .58rem;
        line-height: 1;
        font-weight: var(--font-weight-bold);
        letter-spacing: .12em;
        text-transform: uppercase;
    }

    .bz-global-mobile-panel .index-mobile-panel__header strong {
        color: var(--sidebar-text);
        font-size: .95rem;
        line-height: 1.2;
        font-weight: var(--font-weight-bold);
    }

    .bz-global-mobile-panel .index-mobile-panel__header .bz-icon-button {
        flex: 0 0 auto;
        width: 38px;
        height: 38px;
        min-width: 38px;
        border-radius: 50%;
        color: var(--sidebar-text);
        background: color-mix(in srgb, var(--sidebar-bg) 86%, var(--surface) 14%);
        border-color: color-mix(in srgb, var(--accent) 28%, var(--sidebar-border));
    }

    .bz-global-mobile-nav {
        display: flex;
        flex-direction: column;
        gap: 0;
    }

    .bz-global-mobile-nav .index-mobile-nav__group {
        padding: .85rem 0 .7rem;
        border-top: 1px solid var(--sidebar-border);
    }

    .bz-global-mobile-nav .index-mobile-nav__group--first {
        border-top: 0;
        padding-top: .1rem;
    }

    .bz-global-mobile-nav .index-mobile-nav__label {
        display: block;
        margin: 0 .55rem .42rem;
        color: var(--sidebar-text-muted);
        font-size: .62rem;
        line-height: 1.2;
        font-weight: var(--font-weight-bold);
        letter-spacing: .12em;
        text-transform: uppercase;
    }

    .bz-global-mobile-nav a {
        display: flex;
        align-items: center;
        gap: .72rem;
        min-height: 42px;
        margin: .16rem 0;
        padding: .62rem .72rem;
        border-radius: var(--radius-md);
        color: var(--sidebar-text-muted);
        text-decoration: none;
        font-size: .84rem;
        font-weight: var(--font-weight-semibold);
        transition:
            background-color var(--duration-fast) var(--ease-standard),
            color var(--duration-fast) var(--ease-standard),
            transform var(--duration-fast) var(--ease-standard);
    }

    /* Same fix as the desktop sidebar: [hidden] must win here too. */
    .bz-global-mobile-nav a[hidden] {
        display: none !important;
    }

    .bz-global-mobile-nav a:hover {
        color: var(--sidebar-text);
        background: var(--sidebar-surface);
        transform: translateX(2px);
    }

    .bz-global-mobile-nav a.is-active,
    .bz-global-mobile-nav a[aria-current="page"] {
        color: var(--sidebar-active-text);
        background: var(--sidebar-active-bg);
    }

    .bz-global-mobile-nav a svg {
        width: 18px;
        height: 18px;
        flex: 0 0 auto;
    }

    .bz-global-mobile-nav .index-mobile-nav__legal {
        width: 100%;
        min-height: 42px;
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: .75rem;
        padding: .62rem .72rem;
        border: 0;
        border-radius: var(--radius-md);
        background: transparent;
        color: var(--sidebar-text-muted);
        font: inherit;
        cursor: pointer;
    }

    .bz-global-mobile-nav .index-mobile-nav__legal-title {
        display: inline-flex;
        align-items: center;
        gap: .72rem;
    }

    .bz-global-mobile-nav .index-mobile-nav__legal-title svg {
        width: 18px;
        height: 18px;
    }

    .bz-global-mobile-nav .index-mobile-nav__submenu {
        padding: .15rem 0 0 .55rem;
    }

    .bz-global-mobile-nav .index-mobile-nav__submenu a {
        min-height: 38px;
        font-size: .8rem;
    }

    /* Keep the page underneath locked while the drawer is open. */
    body.is-scroll-locked {
        overflow: hidden !important;
        touch-action: none;
    }
}

@media (prefers-reduced-motion: reduce) {
    .bz-mobile-drawer,
    .bz-mobile-drawer__backdrop,
    .bz-mobile-drawer__panel {
        transition: none;
    }
}

.bz-main {
    position: relative;
}
