/*
 * Final responsive layer for the cinematic lobby.
 * Load after style.css and cinematic-ui.css.
 */

/* Grid and flex descendants must be allowed to shrink at every breakpoint. */
.mm-lobby,
.mm-lobby-col,
.mm-hero,
.mm-hero > *,
.mm-practice-map-picker,
.mm-practice-map-options,
.lobby-private,
.lobby-private .lobby-map-options,
.lobby-chat {
    min-width: 0;
}

/* ---------- tablet: keep the command deck compact without overlapping ---------- */
@media (min-width: 769px) and (max-width: 999px) {
    .mm-hero {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        grid-template-areas:
            'art art'
            'eyebrow eyebrow'
            'intro intro'
            'quickplay practice'
            'story difficulty'
            'arena arena'
            'note note'
            'private-cta garage';
    }

    .mm-hero-wordmark { grid-area: art; }
    .mm-hero .mm-hero-eyebrow { grid-area: eyebrow; }
    .mm-hero .mm-hero-sub { grid-area: intro; }
    .mm-hero #mm-play-btn { grid-area: quickplay; }
    .mm-hero .mm-practice-btn { grid-area: practice; }
    .mm-hero .rr-btn--story { grid-area: story; }
    .mm-hero .mm-diff-seg {
        grid-area: difficulty;
        align-self: center;
        margin-top: 0;
    }
    .mm-hero .mm-practice-map-picker { grid-area: arena; }
    .mm-hero .mm-private-shortcut { grid-area: private-cta; }
    .mm-hero .mm-garage-btn {
        grid-area: garage;
        width: 100%;
        max-width: none;
        justify-self: stretch;
    }
    .mm-hero .mm-hero-note { grid-area: note; }
}

/* ---------- short landscape: useful above-the-fold controls and readable maps ---------- */
@media (min-width: 769px) and (max-width: 900px) and (max-height: 520px) {
    .mm-header {
        min-height: 58px;
        padding: 7px 12px;
    }

    .mm-content {
        padding: 12px 14px calc(var(--rr-nav-size) + 18px + env(safe-area-inset-bottom));
    }

    .mm-lobby,
    .mm-lobby-col {
        gap: 12px;
    }

    .mm-hero {
        grid-template-columns: minmax(0, 1.1fr) minmax(280px, .9fr);
        grid-template-areas:
            'art eyebrow'
            'art intro'
            'art quickplay'
            'art practice'
            'story difficulty'
            'arena arena'
            'note note'
            'private-cta garage';
        column-gap: 14px;
        row-gap: 10px;
        padding: 14px;
    }

    .mm-hero-wordmark {
        width: 100%;
        align-self: start;
    }

    .mm-hero .mm-hero-eyebrow,
    .mm-hero .mm-hero-sub {
        margin-inline: 0;
    }

    .mm-hero #mm-play-btn,
    .mm-hero .mm-practice-btn {
        min-height: 78px;
        padding: 12px 14px;
    }

    .mm-hero #mm-play-btn {
        font-size: clamp(22px, 3vw, 27px);
    }

    .mm-hero .mm-practice-btn {
        font-size: clamp(19px, 2.6vw, 23px);
    }

    .mm-hero .rr-btn-hero-icon,
    .mm-hero .mm-bot-icon {
        width: 44px;
        height: 44px;
        flex-basis: 44px;
    }

    .mm-hero .mm-practice-map-picker {
        margin-top: 0;
        padding-top: 10px;
    }

    .mm-hero .mm-practice-map-options {
        grid-template-columns: repeat(4, minmax(0, 1fr));
        gap: 8px;
    }

    .mm-hero .mm-practice-map-options .lobby-map-option {
        min-height: 158px;
    }

    .mm-hero .mm-practice-map-options .lobby-map-copy {
        min-height: 48px;
        padding: 8px;
    }

    .mm-hero .mm-practice-map-options .lobby-map-copy small {
        display: none;
    }

    .mm-hero .rr-btn--story,
    .mm-hero .mm-private-shortcut,
    .mm-hero .mm-garage-btn {
        min-height: 76px;
    }

    .mm-hero .mm-private-shortcut svg,
    .mm-hero .mm-garage-btn svg {
        width: 40px;
        height: 40px;
        flex-basis: 40px;
    }
}

/* ---------- narrow phones: retain the deliberate horizontal arena rail ---------- */
@media (max-width: 430px) {
    .mm-practice-map-picker {
        max-width: 100%;
    }

    .mm-practice-map-options {
        grid-template-columns: none;
        grid-auto-flow: column;
        grid-auto-columns: min(78vw, 280px);
        max-width: 100%;
        overflow-x: auto;
        overflow-y: hidden;
        overscroll-behavior-inline: contain;
        scroll-snap-type: x mandatory;
        touch-action: pan-x;
        -webkit-overflow-scrolling: touch;
    }

    .mm-practice-map-options .lobby-map-option {
        min-width: 0;
        scroll-snap-align: start;
    }
}

/*
 * lobbyChat.js treats short-landscape and coarse 769-900px devices as mobile.
 * Mirror that state in CSS so the floating entry and full-screen chat remain usable.
 */
@media (max-width: 900px) and (max-height: 520px),
       (pointer: coarse) and (max-width: 900px) {
    .mm-lobby-col--room {
        min-width: 0;
    }

    .lobby-chat[hidden] {
        display: none !important;
    }

    .lobby-chat.lobby-chat--mobile-open {
        position: fixed;
        z-index: 70;
        top: var(--chat-vv-top, 0px);
        right: 0;
        bottom: auto;
        left: 0;
        display: flex !important;
        width: 100%;
        height: var(--chat-vv-height, 100dvh);
        min-height: 0;
        max-height: none;
        padding: 0;
        overflow: hidden;
        border: 0;
        border-radius: 0;
        background:
            radial-gradient(circle at 50% 0, rgba(142, 45, 229, .16), transparent 34%),
            #03070c;
        box-shadow: none;
        overscroll-behavior: contain;
    }

    .lobby-chat-head {
        flex: 0 0 auto;
        align-items: center;
        padding: max(12px, env(safe-area-inset-top)) 14px 12px;
        background: rgba(20, 24, 29, .99);
        box-shadow: 0 2px 14px rgba(0, 0, 0, .35);
    }

    .lobby-chat-close,
    .lobby-chat-done {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        min-width: 72px;
        min-height: 44px;
        padding: 0 12px;
        border: 1px solid var(--rr-border, #303843);
        border-radius: 8px;
        background: rgba(255, 255, 255, .05);
        color: var(--rr-text, #e8edf2);
        font: 800 11px/1 var(--rr-font-mono, monospace);
        letter-spacing: .06em;
        touch-action: manipulation;
    }

    .lobby-chat-done {
        color: var(--rr-accent, #f97316);
    }

    .lobby-chat-done[hidden] {
        display: none !important;
    }

    .lobby-chat-log {
        min-height: 0;
        padding: 14px;
        overflow-y: auto;
        scroll-padding-bottom: 18px;
        overscroll-behavior-y: contain;
        -webkit-overflow-scrolling: touch;
    }

    .lobby-chat-message {
        gap: 4px;
        padding: 9px 11px;
        border-radius: 10px;
        background: rgba(255, 255, 255, .035);
    }

    .lobby-chat-message span {
        font-size: 15px;
        line-height: 1.35;
    }

    .lobby-chat-compose {
        flex: 0 0 auto;
        padding: 10px 12px max(10px, env(safe-area-inset-bottom));
        border-top: 1px solid var(--rr-border, #303843);
        background: rgba(20, 24, 29, .99);
    }

    .lobby-chat-compose .rr-input,
    .lobby-chat-compose .rr-btn {
        min-height: 46px;
        font-size: 16px;
    }

    .lobby-chat-backdrop:not([hidden]) {
        position: fixed;
        z-index: 69;
        inset: 0;
        display: block;
        border: 0;
        background: rgba(0, 0, 0, .6);
    }

    .lobby-chat-fab:not([hidden]) {
        position: fixed;
        z-index: 45;
        right: 18px;
        bottom: calc(var(--rr-nav-size, 66px) + 16px + env(safe-area-inset-bottom));
        display: grid;
        place-items: center;
        width: 56px;
        height: 56px;
        border: 1px solid #bd62ff;
        border-radius: 50%;
        background: linear-gradient(145deg, #b44dff, #6e20b0);
        color: #fff;
        font-size: 23px;
        box-shadow: 0 0 24px rgba(166, 55, 255, .38), 0 10px 24px rgba(0, 0, 0, .48);
    }

    .lobby-chat-unread {
        position: absolute;
        top: -4px;
        right: -4px;
        min-width: 20px;
        height: 20px;
        padding: 0 5px;
        border-radius: 10px;
        background: #ff394f;
        color: #fff;
        font: 800 10px/20px var(--rr-font-mono, monospace);
    }

    html.lobby-chat-open,
    html.lobby-chat-open body {
        overflow: hidden;
        overscroll-behavior: none;
    }
}
