/* Bottom sheet and responsive modal shell.
 *
 * Two audiences share one geometry: the sheet mounted by ui/js/bottom_sheet.js
 * (#bottom-sheet-modal) and ten existing dialogs, which pick it up only while
 * the new menu layout is active (<body data-menu-layout="new">). Nothing here
 * writes `display`: each modal's own open/close pair owns that inline state, and
 * ui/css/style.css keeps owning the classic layout. */

/* ---- Overlay alignment (desktop: centered) ---- */
#bottom-sheet-modal,
[data-menu-layout="new"] :is(#messages-modal, #preferences-modal, #wallet-modal, #subscribe-modal, #buy-credits-modal, #settings-modal, #bug-report-modal, #join-code-modal, #undo-confirm-modal, #trade-modal) {
    box-sizing: border-box;
    justify-content: center;
    align-items: center;
    padding: env(safe-area-inset-top, 0px) env(safe-area-inset-right, 0px) env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 0px);
}

/* ---- Dialog surface ---- */
#bottom-sheet-modal > .modal-content,
[data-menu-layout="new"] :is(#messages-modal, #preferences-modal, #wallet-modal, #subscribe-modal, #buy-credits-modal, #settings-modal, #bug-report-modal, #join-code-modal, #undo-confirm-modal, #trade-modal) > .modal-content {
    box-sizing: border-box;
    width: 92%;
    max-width: 520px;
    max-height: 85vh;
    max-height: 85dvh;
    padding: 20px 20px 0;
    overflow-y: auto;
    font-size: max(12px, 1em);
}

/* ---- Scrollable body ---- */
#bottom-sheet-modal .modal-scroll-area,
[data-menu-layout="new"] :is(#messages-modal, #preferences-modal, #wallet-modal, #subscribe-modal, #buy-credits-modal, #settings-modal, #bug-report-modal, #join-code-modal, #undo-confirm-modal, #trade-modal) .modal-scroll-area {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

/* ---- Docked action row ----
 * Covers direct footers (trade), footers inside the scroll area (subscribe,
 * whose inline display/justify-content/margin-top are left alone) and dialogs
 * with no scroll wrapper (the content element itself scrolls). */
#bottom-sheet-modal .modal-actions,
[data-menu-layout="new"] :is(#messages-modal, #preferences-modal, #wallet-modal, #subscribe-modal, #buy-credits-modal, #settings-modal, #bug-report-modal, #join-code-modal, #undo-confirm-modal, #trade-modal) .modal-actions {
    position: sticky;
    bottom: 0;
    z-index: 1;
    flex-shrink: 0;
    gap: 10px;
    padding: 12px 0 calc(12px + env(safe-area-inset-bottom, 0px));
    background-color: var(--bg-sidebar);
    border-top: 1px solid var(--border-color);
}

/* ---- Controls: 44x44 targets, 12px text floor ---- */
#bottom-sheet-modal .modal-actions button,
[data-menu-layout="new"] :is(#messages-modal, #preferences-modal, #wallet-modal, #subscribe-modal, #buy-credits-modal, #settings-modal, #bug-report-modal, #join-code-modal, #undo-confirm-modal, #trade-modal) .modal-actions button {
    min-width: 44px;
    min-height: 44px;
    font-size: max(12px, 1em);
}

/* One or two actions share the row. */
#bottom-sheet-modal .modal-actions > button,
[data-menu-layout="new"] :is(#messages-modal, #preferences-modal, #wallet-modal, #subscribe-modal, #buy-credits-modal, #settings-modal, #bug-report-modal, #join-code-modal, #undo-confirm-modal, #trade-modal) .modal-actions > button {
    flex: 1 1 0;
}

/* Three or more action buttons stack. */
#bottom-sheet-modal .modal-actions:has(> button:nth-child(3)),
[data-menu-layout="new"] :is(#messages-modal, #preferences-modal, #wallet-modal, #subscribe-modal, #buy-credits-modal, #settings-modal, #bug-report-modal, #join-code-modal, #undo-confirm-modal, #trade-modal) .modal-actions:has(> button:nth-child(3)) {
    flex-direction: column;
    align-items: stretch;
}

/* ---- Danger action ---- */
#bottom-sheet-modal .bottom-sheet-danger {
    background-color: var(--game-event-error);
    border-color: var(--game-event-error);
    color: #fff;
}

/* ---- Mobile portrait: bottom sheet ---- */
@media (max-width: 1024px) {
    #bottom-sheet-modal,
    [data-menu-layout="new"] :is(#messages-modal, #preferences-modal, #wallet-modal, #subscribe-modal, #buy-credits-modal, #settings-modal, #bug-report-modal, #join-code-modal, #undo-confirm-modal, #trade-modal) {
        align-items: flex-end;
    }

    #bottom-sheet-modal > .modal-content,
    [data-menu-layout="new"] :is(#messages-modal, #preferences-modal, #wallet-modal, #subscribe-modal, #buy-credits-modal, #settings-modal, #bug-report-modal, #join-code-modal, #undo-confirm-modal, #trade-modal) > .modal-content {
        width: 100%;
        max-width: none;
        max-height: 90vh;
        max-height: 90dvh;
        border-bottom-left-radius: 0;
        border-bottom-right-radius: 0;
    }
}

/* ---- Mobile landscape: right-docked, full height ---- */
@media (max-width: 1024px) and (orientation: landscape) {
    #bottom-sheet-modal,
    [data-menu-layout="new"] :is(#messages-modal, #preferences-modal, #wallet-modal, #subscribe-modal, #buy-credits-modal, #settings-modal, #bug-report-modal, #join-code-modal, #undo-confirm-modal, #trade-modal) {
        justify-content: flex-end;
        align-items: stretch;
    }

    #bottom-sheet-modal > .modal-content,
    [data-menu-layout="new"] :is(#messages-modal, #preferences-modal, #wallet-modal, #subscribe-modal, #buy-credits-modal, #settings-modal, #bug-report-modal, #join-code-modal, #undo-confirm-modal, #trade-modal) > .modal-content {
        width: min(480px, 100%);
        height: 100%;
        max-height: none;
        border-radius: 0;
    }
}
