.menu-toggle,
.tabbar,
.turn-gate,
.who-avatar,
.side-logout,
.pwa-install,
.pwa-ios {
    display: none;
}

@media (max-width: 900px) {
    html, body {
        height: 100%;
        height: 100dvh;
        overflow: hidden;
        overscroll-behavior: none;
    }

    .topbar {
        position: sticky;
        top: 0;
        z-index: 40;
        min-height: calc(3.5rem + env(safe-area-inset-top, 0px));
        height: auto;
        padding: env(safe-area-inset-top, 0px) 0.75rem 0 0.7rem;
        gap: 0.55rem;
    }

    .menu-toggle {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        width: 2.6rem;
        height: 2.6rem;
        padding: 0;
        border: 1px solid var(--line);
        border-radius: 0.75rem;
        background: var(--paper);
        color: var(--ink);
        cursor: pointer;
        flex: none;
        -webkit-tap-highlight-color: transparent;
        touch-action: manipulation;
    }

    .menu-icon { width: 1.25rem; height: 1.25rem; }
    .menu-toggle[aria-expanded="true"] .menu-icon-open { display: none; }
    .menu-toggle[aria-expanded="true"] .menu-icon-close { display: block; }
    .menu-icon-close { display: none; }

    .brand { font-size: 1.2rem; min-width: 0; }
    .who-name, .who-logout, .who-guest { display: none; }
    .who-avatar {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        width: 2.15rem;
        height: 2.15rem;
        border-radius: 999px;
        background: var(--accent);
        color: #fffaf3;
        font-size: 0.78rem;
        font-weight: 600;
        letter-spacing: 0.02em;
    }

    .workspace { min-height: 0; }

    .nav-backdrop {
        position: fixed;
        z-index: 30;
        top: var(--app-header, 3.5rem);
        right: 0;
        bottom: var(--app-tab, 4rem);
        left: 0;
        background: rgba(28, 36, 48, 0.38);
    }

    .side {
        position: fixed;
        z-index: 35;
        top: var(--app-header, 3.5rem);
        bottom: var(--app-tab, 4rem);
        left: 0;
        width: min(20rem, 88vw);
        max-height: none;
        transform: translateX(-105%);
        transition: transform 0.22s ease;
        box-shadow: 8px 0 24px rgba(28, 36, 48, 0.18);
    }

    .side.is-open { transform: translateX(0); }

    .side-logout {
        display: block;
        margin-top: 0.7rem;
        padding-top: 0.7rem;
        border-top: 1px solid #d4c6b2;
    }

    .side-logout button {
        width: 100%;
        justify-content: flex-start;
        background: transparent;
        color: var(--accent);
        border: 0;
        border-radius: 0.65rem;
        padding: 0.55rem 0.7rem;
        font: inherit;
        font-weight: 600;
        cursor: pointer;
    }

    .pwa-install {
        display: flex;
        width: 100%;
        margin-top: 0.45rem;
        border: 0;
        background: transparent;
        text-align: left;
        cursor: pointer;
        font: inherit;
    }

    .pwa-ios {
        display: block;
        margin: 0.45rem 0.2rem 0;
        color: var(--muted);
        font-size: 0.82rem;
    }

    .stage {
        overflow: auto;
        -webkit-overflow-scrolling: touch;
        padding: 0.85rem 0.85rem calc(1.15rem + var(--app-tab, 4rem));
    }

    body.app-nav-open .stage { overflow: hidden; }

    .fill, .player, .summary, .admin, #player-mount, .step, .unit-grid, .choice-grid {
        flex: none;
        min-height: auto;
        overflow: visible;
    }

    .tabbar {
        display: flex;
        position: fixed;
        z-index: 40;
        left: 0;
        right: 0;
        bottom: 0;
        min-height: calc(3.9rem + env(safe-area-inset-bottom, 0px));
        padding-bottom: env(safe-area-inset-bottom, 0px);
        align-items: stretch;
        justify-content: space-around;
        background: var(--card);
        border-top: 1px solid var(--line);
    }

    .tabbar-item {
        display: flex;
        flex: 1;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 0.15rem;
        min-width: 0;
        min-height: 3.4rem;
        padding: 0.3rem 0.1rem;
        border: 0;
        background: transparent;
        color: var(--muted);
        font: inherit;
        font-size: 0.68rem;
        font-weight: 600;
        text-decoration: none;
        cursor: pointer;
        -webkit-tap-highlight-color: transparent;
        touch-action: manipulation;
    }

    .tabbar-item svg { width: 1.25rem; height: 1.25rem; }
    .tabbar-item span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    .tabbar-item.is-active { color: var(--accent); }
}

@media (hover: none) and (pointer: coarse) and (orientation: landscape) {
    .turn-gate {
        display: flex;
        position: fixed;
        z-index: 80;
        inset: 0;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 0.35rem;
        padding: 1.5rem;
        background: var(--paper);
        color: var(--ink);
        text-align: center;
    }

    .turn-gate p { margin: 0; }
    .turn-gate strong { font-family: Fraunces, Georgia, serif; font-size: 1.6rem; font-weight: 560; }
}
