/* =========================================================
   MATHFORGE APP-STYLE BOTTOM NAVIGATION — JULY 21, 2026
   Shared mobile + desktop dock, active glow, and profile sheet.
========================================================= */

:root {
    --mf-tabbar-height: 82px;
    --mf-tabbar-gap: 18px;
    --mf-tabbar-side: 18px;
    --mf-tabbar-width: 720px;
}

.mf-app-tabbar,
.mf-profile-sheet,
.mf-profile-sheet-backdrop {
    display: none;
}

/* =========================================================
   SHARED APP SHELL — PHONE, TABLET, AND DESKTOP
========================================================= */
body:not(.mf-legacy-native-shell) {
    padding-bottom: calc(136px + env(safe-area-inset-bottom)) !important;
}

body:not(.mf-legacy-native-shell) .page-shell,
body:not(.mf-legacy-native-shell) main,
body:not(.mf-legacy-native-shell) .main-content {
    padding-bottom: calc(144px + env(safe-area-inset-bottom)) !important;
}

/* The top bar becomes a quiet brand bar. Main destinations live below. */
body:not(.mf-legacy-native-shell) .mobile-menu-toggle,
body:not(.mf-legacy-native-shell) .main-nav-links,
body:not(.mf-legacy-native-shell) .navbar-links,
body:not(.mf-legacy-native-shell) .nav-links,
body:not(.mf-legacy-native-shell) .player-navbar-chip {
    display: none !important;
}

body:not(.mf-legacy-native-shell) .navbar,
body:not(.mf-legacy-native-shell) .main-navbar,
body:not(.mf-legacy-native-shell) .top-navbar,
body:not(.mf-legacy-native-shell) .setup-mini-header {
    justify-content: space-between !important;
}

body:not(.mf-legacy-native-shell) .navbar-logo,
body:not(.mf-legacy-native-shell) .logo,
body:not(.mf-legacy-native-shell) .mobile-brand {
    max-width: calc(100vw - 92px) !important;
}

.mf-app-tabbar {
    position: fixed;
    left: 50%;
    bottom: max(var(--mf-tabbar-gap), env(safe-area-inset-bottom));
    z-index: 11000;
    width: min(var(--mf-tabbar-width), calc(100vw - (var(--mf-tabbar-side) * 2)));
    height: var(--mf-tabbar-height);
    padding: 9px 12px 8px;
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    align-items: end;
    gap: 7px;
    transform: translateX(-50%);
    border: 1px solid rgba(148, 163, 184, 0.19);
    border-radius: 29px;
    background:
        linear-gradient(180deg, rgba(20, 30, 55, 0.93), rgba(7, 12, 26, 0.965));
    box-shadow:
        0 28px 72px rgba(0, 0, 0, 0.46),
        0 8px 24px rgba(10, 18, 38, 0.32),
        inset 0 1px 0 rgba(255, 255, 255, 0.09);
    backdrop-filter: blur(25px) saturate(155%);
    -webkit-backdrop-filter: blur(25px) saturate(155%);
    isolation: isolate;
}

.mf-app-tabbar::before {
    content: "";
    position: absolute;
    inset: 0;
    z-index: -1;
    border-radius: inherit;
    pointer-events: none;
    background:
        radial-gradient(circle at 50% 0%, rgba(59, 130, 246, 0.19), transparent 50%),
        radial-gradient(circle at 86% 100%, rgba(124, 58, 237, 0.15), transparent 43%),
        radial-gradient(circle at 12% 90%, rgba(14, 165, 233, 0.08), transparent 42%);
}

.mf-app-tab {
    position: relative;
    min-width: 0;
    height: 66px;
    padding: 0 5px 6px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
    gap: 4px;
    border: 0;
    border-radius: 19px;
    color: #8090ad;
    background: transparent;
    text-decoration: none;
    font: inherit;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    transition: color 0.2s ease, transform 0.2s ease, background 0.2s ease;
}

.mf-app-tab::after {
    content: "";
    position: absolute;
    bottom: 0;
    width: 4px;
    height: 4px;
    border-radius: 999px;
    background: transparent;
    box-shadow: none;
    transition: width 0.2s ease, background 0.2s ease, box-shadow 0.2s ease;
}

.mf-app-tab-icon {
    position: relative;
    width: 43px;
    height: 43px;
    display: grid;
    place-items: center;
    border: 1px solid transparent;
    border-radius: 15px;
    background: rgba(255, 255, 255, 0.038);
    transition:
        transform 0.22s cubic-bezier(.2,.8,.2,1),
        color 0.2s ease,
        background 0.2s ease,
        border-color 0.2s ease,
        box-shadow 0.2s ease;
}

.mf-app-tab-icon svg {
    width: 23px;
    height: 23px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.9;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.mf-app-tab-center .mf-app-tab-icon svg {
    fill: currentColor;
    stroke-width: 1.45;
}

.mf-app-avatar {
    font-size: 1.38rem;
    line-height: 1;
}

.mf-app-tab-label {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 0.73rem;
    line-height: 1;
    font-weight: 850;
    letter-spacing: 0.012em;
}

.mf-app-tab:hover,
.mf-app-tab:focus-visible {
    color: #e8f3ff;
    outline: none;
}

.mf-app-tab:hover:not(.is-active) {
    background: rgba(255, 255, 255, 0.035);
    transform: translateY(-2px);
}

.mf-app-tab:hover:not(.is-active) .mf-app-tab-icon {
    color: #bfdbfe;
    border-color: rgba(125, 211, 252, 0.16);
    background: rgba(59, 130, 246, 0.09);
}

.mf-app-tab:focus-visible .mf-app-tab-icon {
    outline: 2px solid rgba(125, 211, 252, 0.95);
    outline-offset: 3px;
}

.mf-app-tab.is-active {
    color: #f8fbff;
}

.mf-app-tab.is-active .mf-app-tab-icon {
    transform: translateY(-11px) scale(1.1);
    color: #ffffff;
    border-color: rgba(191, 219, 254, 0.52);
    background: linear-gradient(145deg, #2563eb 0%, #7c3aed 100%);
    box-shadow:
        0 0 0 6px rgba(59, 130, 246, 0.11),
        0 0 31px rgba(59, 130, 246, 0.74),
        0 14px 25px rgba(17, 24, 39, 0.54),
        inset 0 1px 0 rgba(255, 255, 255, 0.34);
}

.mf-app-tab.is-active::after {
    width: 19px;
    background: #7dd3fc;
    box-shadow: 0 0 12px rgba(125, 211, 252, 0.98);
}

.mf-app-tab.is-pressed .mf-app-tab-icon {
    transform: translateY(-7px) scale(0.95);
}

.mf-tab-alert {
    position: absolute;
    top: -2px;
    right: -2px;
    width: 10px;
    height: 10px;
    border: 2px solid #0b1326;
    border-radius: 50%;
    background: #fb7185;
    box-shadow: 0 0 10px rgba(251, 113, 133, 0.88);
}

/* Existing web Back/Home control becomes one floating Back action. */
body:not(.mf-legacy-native-shell) .mf-global-controls {
    position: fixed !important;
    left: max(18px, calc(50% - 425px)) !important;
    right: auto !important;
    bottom: calc(35px + env(safe-area-inset-bottom)) !important;
    z-index: 10950 !important;
    width: auto !important;
    min-height: 0 !important;
    padding: 0 !important;
    display: block !important;
    transform: none !important;
    border: 0 !important;
    border-radius: 0 !important;
    background: transparent !important;
    box-shadow: none !important;
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
}

body:not(.mf-legacy-native-shell) .mf-global-controls .mf-global-control:last-child {
    display: none !important;
}

body:not(.mf-legacy-native-shell) .mf-global-controls .mf-global-control:first-child {
    position: relative !important;
    width: 50px !important;
    height: 50px !important;
    min-height: 50px !important;
    padding: 0 !important;
    display: grid !important;
    place-items: center !important;
    border: 1px solid rgba(148, 163, 184, 0.2) !important;
    border-radius: 17px !important;
    color: #e2e8f0 !important;
    background: rgba(11, 18, 35, 0.9) !important;
    box-shadow: 0 14px 32px rgba(0,0,0,0.32) !important;
    backdrop-filter: blur(17px) !important;
    -webkit-backdrop-filter: blur(17px) !important;
    transition: transform 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease !important;
}

body:not(.mf-legacy-native-shell) .mf-global-controls .mf-global-control:first-child:hover {
    transform: translateY(-3px) !important;
    border-color: rgba(125, 211, 252, 0.38) !important;
    box-shadow: 0 16px 34px rgba(0,0,0,0.36), 0 0 20px rgba(59,130,246,0.18) !important;
}

body:not(.mf-legacy-native-shell) .mf-global-controls .mf-global-control:first-child span {
    font-size: 1.9rem !important;
    transform: translateY(-1px);
}

body:not(.mf-legacy-native-shell) .mf-global-controls .mf-global-control:first-child strong {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    overflow: hidden !important;
    clip: rect(0, 0, 0, 0) !important;
    white-space: nowrap !important;
}

/* =========================================================
   PROFILE PANEL — FLOATING CARD ON DESKTOP
========================================================= */
.mf-profile-sheet-backdrop {
    position: fixed;
    inset: 0;
    z-index: 13990;
    display: block;
    opacity: 0;
    visibility: hidden;
    background: rgba(2, 6, 23, 0.58);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
    transition: opacity 0.22s ease, visibility 0.22s ease;
}

.mf-profile-sheet-backdrop[hidden] {
    display: block;
}

.mf-profile-sheet {
    position: fixed;
    left: 50%;
    bottom: calc(112px + env(safe-area-inset-bottom));
    z-index: 14000;
    width: min(660px, calc(100vw - 40px));
    max-height: min(72dvh, 720px);
    padding: 14px 18px 20px;
    display: flex;
    flex-direction: column;
    color: #f8fafc;
    border: 1px solid rgba(148, 163, 184, 0.2);
    border-radius: 30px;
    background:
        linear-gradient(180deg, rgba(19, 29, 54, 0.988), rgba(6, 11, 24, 0.995));
    box-shadow: 0 28px 85px rgba(0, 0, 0, 0.58);
    opacity: 0;
    transform: translate(-50%, 28px) scale(0.965);
    visibility: hidden;
    transform-origin: 86% 100%;
    transition:
        opacity 0.22s ease,
        transform 0.28s cubic-bezier(.2,.85,.2,1),
        visibility 0.28s ease;
}

body.mf-profile-sheet-open {
    overflow: hidden !important;
}

body.mf-profile-sheet-open .mf-profile-sheet {
    opacity: 1;
    transform: translate(-50%, 0) scale(1);
    visibility: visible;
}

body.mf-profile-sheet-open .mf-profile-sheet-backdrop {
    opacity: 1;
    visibility: visible;
}

.mf-sheet-handle {
    width: 46px;
    height: 5px;
    margin: 0 auto 10px;
    flex: 0 0 auto;
    border-radius: 999px;
    background: rgba(203, 213, 225, 0.34);
}

.mf-sheet-header {
    padding: 2px 2px 14px;
    display: grid;
    grid-template-columns: 52px minmax(0, 1fr) 44px;
    align-items: center;
    gap: 12px;
    flex: 0 0 auto;
}

.mf-sheet-player-avatar {
    width: 52px;
    height: 52px;
    display: grid;
    place-items: center;
    border: 1px solid rgba(191, 219, 254, 0.4);
    border-radius: 18px;
    font-size: 1.72rem;
    background: linear-gradient(145deg, rgba(37,99,235,0.87), rgba(124,58,237,0.87));
    box-shadow: 0 0 26px rgba(59,130,246,0.33);
}

.mf-sheet-player-copy {
    min-width: 0;
}

.mf-sheet-player-copy span {
    display: block;
    color: #7dd3fc;
    font-size: 0.68rem;
    font-weight: 900;
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

.mf-sheet-player-copy h2 {
    margin: 2px 0 0;
    overflow: hidden;
    color: #ffffff;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 1.3rem;
    line-height: 1.15;
}

.mf-sheet-close {
    width: 44px;
    height: 44px;
    display: grid;
    place-items: center;
    border: 1px solid rgba(148, 163, 184, 0.16);
    border-radius: 15px;
    color: #dbeafe;
    background: rgba(255,255,255,0.06);
    font-size: 1.6rem;
    line-height: 1;
    cursor: pointer;
    transition: transform 0.2s ease, background 0.2s ease;
}

.mf-sheet-close:hover {
    transform: rotate(4deg) scale(1.05);
    background: rgba(59,130,246,0.13);
}

.mf-sheet-scroll {
    min-height: 0;
    padding: 0 2px 4px;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
}

.mf-sheet-quick-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
}

.mf-sheet-quick-grid a {
    min-width: 0;
    min-height: 88px;
    padding: 12px 8px 9px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border: 1px solid rgba(148, 163, 184, 0.13);
    border-radius: 18px;
    color: #e5eefc;
    background: rgba(255,255,255,0.045);
    text-align: center;
    text-decoration: none;
    transition: transform 0.18s ease, background 0.18s ease, border-color 0.18s ease;
}

.mf-sheet-quick-grid a:hover {
    transform: translateY(-3px);
    border-color: rgba(125,211,252,0.24);
    background: rgba(59,130,246,0.1);
}

.mf-sheet-quick-grid a span {
    width: 38px;
    height: 38px;
    display: grid;
    place-items: center;
    border-radius: 13px;
    background: rgba(59,130,246,0.15);
    font-size: 1.2rem;
}

.mf-sheet-quick-grid a strong {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 0.75rem;
}

.mf-sheet-section {
    margin-top: 18px;
}

.mf-sheet-section h3 {
    margin: 0 0 8px 4px;
    color: #8da0bd;
    font-size: 0.7rem;
    font-weight: 900;
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

.mf-sheet-link-list {
    overflow: hidden;
    border: 1px solid rgba(148, 163, 184, 0.13);
    border-radius: 19px;
    background: rgba(255,255,255,0.035);
}

.mf-sheet-link-list a,
.mf-sheet-link-list button {
    width: 100%;
    min-height: 49px;
    padding: 11px 15px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    border: 0;
    border-bottom: 1px solid rgba(148, 163, 184, 0.09);
    color: #e5eefc;
    background: transparent;
    text-align: left;
    text-decoration: none;
    font: inherit;
    font-size: 0.86rem;
    cursor: pointer;
    transition: background 0.18s ease, padding-left 0.18s ease;
}

.mf-sheet-link-list > :last-child {
    border-bottom: 0;
}

.mf-sheet-link-list a:hover,
.mf-sheet-link-list button:hover {
    padding-left: 19px;
    background: rgba(59,130,246,0.09);
}

.mf-sheet-link-list b {
    color: #7dd3fc;
    font-size: 0.8rem;
    font-weight: 850;
}

/* =========================================================
   LIGHT THEME
========================================================= */
body.theme-light .mf-app-tabbar {
    border-color: rgba(15, 23, 42, 0.1);
    background: rgba(248, 250, 252, 0.95);
    box-shadow: 0 22px 55px rgba(15, 23, 42, 0.2), inset 0 1px 0 #ffffff;
}

body.theme-light .mf-app-tab {
    color: #64748b;
}

body.theme-light .mf-app-tab:hover:not(.is-active) {
    background: rgba(15,23,42,0.035);
}

body.theme-light .mf-app-tab.is-active {
    color: #0f172a;
}

body.theme-light .mf-app-tab-icon {
    background: rgba(15,23,42,0.03);
}

body.theme-light .mf-app-tab.is-active .mf-app-tab-icon {
    color: #ffffff;
}

body.theme-light:not(.mf-legacy-native-shell) .mf-global-controls .mf-global-control:first-child {
    color: #0f172a !important;
    border-color: rgba(15,23,42,0.1) !important;
    background: rgba(255,255,255,0.95) !important;
}

body.theme-light .mf-profile-sheet {
    color: #0f172a;
    border-color: rgba(15,23,42,0.1);
    background: linear-gradient(180deg, rgba(255,255,255,0.996), rgba(241,245,249,0.996));
}

body.theme-light .mf-sheet-player-copy h2,
body.theme-light .mf-sheet-close,
body.theme-light .mf-sheet-quick-grid a,
body.theme-light .mf-sheet-link-list a,
body.theme-light .mf-sheet-link-list button {
    color: #0f172a;
}

body.theme-light .mf-sheet-close,
body.theme-light .mf-sheet-quick-grid a,
body.theme-light .mf-sheet-link-list {
    border-color: rgba(15,23,42,0.09);
    background: rgba(255,255,255,0.75);
}

body.theme-light .mf-sheet-section h3 {
    color: #64748b;
}

/* =========================================================
   TABLET / SMALL LAPTOP
========================================================= */
@media (max-width: 900px) {
    :root {
        --mf-tabbar-width: 640px;
        --mf-tabbar-side: 14px;
    }

    body:not(.mf-legacy-native-shell) .mf-global-controls {
        left: 14px !important;
        bottom: calc(112px + env(safe-area-inset-bottom)) !important;
    }
}

/* =========================================================
   MOBILE
========================================================= */
@media (max-width: 760px) {
    :root {
        --mf-tabbar-height: 72px;
        --mf-tabbar-gap: 8px;
        --mf-tabbar-side: 8px;
        --mf-tabbar-width: 520px;
    }

    body:not(.mf-legacy-native-shell) {
        padding-bottom: calc(112px + env(safe-area-inset-bottom)) !important;
    }

    body:not(.mf-legacy-native-shell) .page-shell,
    body:not(.mf-legacy-native-shell) main,
    body:not(.mf-legacy-native-shell) .main-content {
        padding-bottom: calc(128px + env(safe-area-inset-bottom)) !important;
    }

    .mf-app-tabbar {
        padding: 7px 7px 6px;
        gap: 2px;
        border-radius: 25px;
    }

    .mf-app-tab {
        height: 58px;
        padding: 0 2px 4px;
        gap: 3px;
        border-radius: 17px;
    }

    .mf-app-tab-icon {
        width: 38px;
        height: 38px;
        border-radius: 14px;
    }

    .mf-app-tab-icon svg {
        width: 21px;
        height: 21px;
    }

    .mf-app-avatar {
        font-size: 1.28rem;
    }

    .mf-app-tab-label {
        font-size: 0.63rem;
    }

    .mf-app-tab.is-active .mf-app-tab-icon {
        transform: translateY(-10px) scale(1.08);
    }

    body:not(.mf-legacy-native-shell) .mf-global-controls {
        left: 12px !important;
        bottom: calc(88px + env(safe-area-inset-bottom)) !important;
    }

    body:not(.mf-legacy-native-shell) .mf-global-controls .mf-global-control:first-child {
        width: 44px !important;
        height: 44px !important;
        min-height: 44px !important;
        border-radius: 15px !important;
    }

    /* The profile card becomes a native-style bottom sheet on phones. */
    .mf-profile-sheet {
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        max-height: min(82dvh, 760px);
        padding: 9px 14px calc(18px + env(safe-area-inset-bottom));
        border-bottom: 0;
        border-radius: 30px 30px 0 0;
        opacity: 1;
        transform: translateY(105%);
        transform-origin: 50% 100%;
    }

    body.mf-profile-sheet-open .mf-profile-sheet {
        transform: translateY(0);
    }

    .mf-sheet-header {
        grid-template-columns: 48px minmax(0, 1fr) 42px;
        gap: 11px;
    }

    .mf-sheet-player-avatar {
        width: 48px;
        height: 48px;
        border-radius: 17px;
        font-size: 1.65rem;
    }

    .mf-sheet-player-copy h2 {
        font-size: 1.2rem;
    }

    .mf-sheet-close {
        width: 42px;
        height: 42px;
        border-radius: 14px;
    }

    .mf-sheet-quick-grid {
        gap: 8px;
    }

    .mf-sheet-quick-grid a {
        min-height: 82px;
        padding: 10px 5px 8px;
        border-radius: 17px;
    }

    .mf-sheet-quick-grid a span {
        width: 35px;
        height: 35px;
        border-radius: 12px;
        font-size: 1.15rem;
    }

    .mf-sheet-quick-grid a strong {
        font-size: 0.69rem;
    }

    .mf-sheet-link-list a,
    .mf-sheet-link-list button {
        min-height: 47px;
        padding: 10px 14px;
        font-size: 0.82rem;
    }
}

@media (max-width: 370px) {
    .mf-app-tabbar {
        border-radius: 22px;
    }

    .mf-app-tab-label {
        font-size: 0.57rem;
    }

    .mf-app-tab-icon {
        width: 35px;
        height: 35px;
        border-radius: 13px;
    }

    .mf-sheet-quick-grid {
        gap: 6px;
    }

    .mf-sheet-quick-grid a {
        min-height: 76px;
    }
}

/* Keep the submitted/native legacy shell on its existing toolbar. */
body.mf-legacy-native-shell .mf-app-tabbar,
body.mf-legacy-native-shell .mf-profile-sheet,
body.mf-legacy-native-shell .mf-profile-sheet-backdrop {
    display: none !important;
}

@media (prefers-reduced-motion: reduce) {
    .mf-app-tab,
    .mf-app-tab-icon,
    .mf-app-tab::after,
    .mf-profile-sheet,
    .mf-profile-sheet-backdrop,
    .mf-sheet-quick-grid a,
    .mf-sheet-link-list a,
    .mf-sheet-link-list button {
        transition: none !important;
    }
}


/* =========================================================
   PROFILE SHEET CLOSE — PHONE RELIABILITY FIX
========================================================= */
.mf-sheet-header {
    position: sticky;
    top: 0;
    z-index: 20;
}

.mf-sheet-close {
    position: relative !important;
    z-index: 30 !important;
    display: grid !important;
    visibility: visible !important;
    opacity: 1 !important;
    pointer-events: auto !important;
    touch-action: manipulation;
}

@media (max-width: 760px) {
    .mf-sheet-header {
        margin: -2px -4px 4px;
        padding: 4px 4px 10px;
        border-radius: 22px 22px 14px 14px;
        background: linear-gradient(180deg, rgba(9, 15, 30, 0.98) 72%, rgba(9, 15, 30, 0));
    }

    body.theme-light .mf-sheet-header {
        background: linear-gradient(180deg, rgba(248, 250, 252, 0.98) 72%, rgba(248, 250, 252, 0));
    }

    .mf-sheet-close {
        width: 44px !important;
        height: 44px !important;
        min-width: 44px !important;
        font-size: 1.75rem !important;
        background: rgba(255, 255, 255, 0.10) !important;
        border-color: rgba(255, 255, 255, 0.22) !important;
    }
}
