/* Loaded last. Preserve state-controlled visibility and disabled controls. */
:where(button, input[type=button], input[type=submit]) {
    -webkit-appearance:none;
    appearance:none;
    touch-action:manipulation;
}
.mobile-nav-close { display:none; }
@media (max-width:860px), (pointer:coarse) {
    :where(button:not(.chess-square):not(.arcade-mine-tile)) {
        background-color:#192638;
        color:#edf3ff;
        border:1px solid #35475f;
        border-radius:8px;
    }
    button:not(.chess-square):not(.arcade-mine-tile) {
        min-height:44px;
        min-width:44px;
        box-sizing:border-box;
        white-space:normal;
        -webkit-tap-highlight-color:#ffbf3333;
    }
    button:disabled { cursor:not-allowed; }
    button:focus-visible, [role=button]:focus-visible { outline:2px solid #ffd166; outline-offset:3px; }
    button > :where(i,svg) { pointer-events:none; }
    .btn-ghost, .toggle-group button:not(.active), .history-filters button:not(.active),
    .trading-chart-tools button, .tme-drawer-toggle-btn {
        background:#182436; color:#d9e5f5; border:1px solid #35475f;
    }
    .nav-tabs .tab-btn { background:#1b293b; color:#dbe5f4; border:1px solid #30415a; }
    .nav-tabs .tab-btn.active { background:#3c3018; color:#ffd166; border-color:#926f27; }
    .modal-content :is(input,select,textarea), .view-page :is(input,select,textarea) { font-size:16px; }
    .warn-actions, .result-actions, .bj-actions, .trading-chart-toolbar,
    .trading-timeframes, .chess-search-form, .crash-bet-panel { flex-wrap:wrap; gap:8px; }
    .warn-actions > button, .result-actions > button { flex:1 1 120px; }
    .trading-position-item { flex-wrap:wrap; }
    #view-trading #trading-chart-container { height:auto; }
    #view-trading #lwchart-wrapper { height:390px; }
    #view-trading #trading-chart-position-tools {
        position:relative; top:auto; right:auto; max-width:100%;
        width:100%; box-sizing:border-box; margin:0 0 10px;
        flex-wrap:wrap; box-shadow:none;
    }
    #view-trading #trading-chart-position-tools select { min-width:0; max-width:100%; min-height:44px; font-size:14px; }
    #view-trading #trading-chart-position-tools button { font-size:13px; }
    #view-trading #trading-chart-position-tools strong { overflow-wrap:anywhere; }
    #trading-risk-dialog { max-height:85vh; max-height:85dvh; overflow-y:auto; }
    #trading-risk-dialog input { font-size:16px; }
    #toast-container { pointer-events:none; max-width:calc(100vw - 24px); }
}
@media(max-width:860px) {
    /* The drawer is portalled to body by mobile-controls.js. */
    body > .nav-tabs {
        position:fixed; inset:0 auto 0 0; width:min(84vw,320px); max-width:320px;
        height:100vh; height:100dvh; box-sizing:border-box;
        padding:76px 16px max(20px,env(safe-area-inset-bottom));
        overflow-y:auto; overscroll-behavior:contain;
        background:#101b2b; z-index:920; visibility:hidden;
        pointer-events:none; align-items:stretch; justify-content:flex-start;
    }
    body > .nav-tabs.open { visibility:visible; pointer-events:auto; transform:translateX(0); }
    .nav-overlay-backdrop.show { z-index:910; }
    .mobile-nav-close { display:flex; align-items:center; justify-content:center;
        position:absolute; top:max(16px,env(safe-area-inset-top)); right:16px;
        padding:8px 14px; color:#ffd166; background:#233147; border:1px solid #46546a; }
    .modal-overlay { box-sizing:border-box; height:100vh; height:100dvh;
        padding:12px; padding-bottom:max(12px,env(safe-area-inset-bottom)); overflow-y:auto; }
    .modal-content { max-height:calc(100vh - 32px); max-height:calc(100dvh - 32px);
        max-width:100%; box-sizing:border-box; overscroll-behavior:contain; }
    .navbar { padding:10px; gap:8px; }
    .user-profile-nav { gap:6px; min-width:0; max-width:100%; }
    .chess-request-row { flex-wrap:wrap; gap:8px; }
    .chess-search-form > input { width:120px; flex:1 1 120px; }
    .chess-search-form > button { flex:1 1 100%; }
    #view-trading .trading-market-explorer { position:static; transform:none; width:auto; max-height:none; }
    #view-trading .tme-drawer-toggle-btn { display:none; }
    #view-trading .trading-position-item { display:flex; }
    #view-trading .trading-close-btn { flex:1 1 100%; }
    .chat-fab { bottom:max(16px,env(safe-area-inset-bottom)); }
}
@media(prefers-reduced-motion:reduce) { body > .nav-tabs { transition:none; } }
