/* Lobby V6 — mobile-first corrections loaded after every lobby stylesheet. */

@media (max-width: 900px) {
    body.console-page {
        min-width: 0;
        overflow-x: hidden;
    }

    body.console-page .page-overlay {
        background-attachment: scroll;
        background-position: center top;
    }

    body.console-page #hud-fx-canvas {
        display: none;
    }

    body.console-page .console-grid-texture {
        opacity: 0.48;
        background-size: 34px 34px;
    }

    body.rail-page .console-layout {
        display: block;
        min-width: 0;
    }

    body.rail-page .console-rail {
        position: sticky;
        top: 0;
        z-index: 55;
        width: 100%;
        height: auto;
        min-height: 0;
        display: grid;
        grid-template-columns: minmax(0, 1fr) 44px;
        grid-template-areas:
            "modes modes"
            "nav logout";
        align-items: stretch;
        gap: 6px;
        padding: max(7px, env(safe-area-inset-top)) 8px 7px;
        border-right: 0;
        border-bottom: 1px solid var(--lobby-border);
        overflow: hidden;
        background: rgba(4, 9, 18, 0.97);
        box-shadow: 0 10px 28px rgba(0, 0, 0, 0.38);
        backdrop-filter: none;
    }

    body.rail-page .console-rail::before,
    body.rail-page .console-rail .console-brand {
        display: none;
    }

    body.rail-page .console-modes-rail {
        grid-area: modes;
        width: 100%;
        display: grid;
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 5px;
        margin: 0;
        overflow: visible;
    }

    body.rail-page .console-modes-rail button {
        width: 100%;
        min-width: 0;
        min-height: 42px;
        display: flex;
        flex-direction: row;
        align-items: center;
        justify-content: center;
        gap: 5px;
        padding: 7px 6px;
        white-space: nowrap;
        text-align: center;
        touch-action: manipulation;
    }

    body.rail-page .console-modes-rail button.is-locked {
        display: none;
    }

    body.rail-page .console-modes-rail .mode-index {
        font-size: 9px;
    }

    body.rail-page .console-modes-rail .mode-label {
        min-width: 0;
        overflow: hidden;
        text-overflow: ellipsis;
        font-size: 11px;
    }

    body.rail-page .console-modes-rail .mode-label[data-mobile-label] {
        font-size: 0;
    }

    body.rail-page .console-modes-rail .mode-label[data-mobile-label]::after {
        content: attr(data-mobile-label);
        font-size: 11px;
    }

    body.rail-page .console-nav-rail {
        grid-area: nav;
        width: 100%;
        min-width: 0;
        display: grid;
        grid-template-columns: repeat(5, minmax(42px, 1fr));
        gap: 5px;
        align-content: stretch;
        overflow: visible;
    }

    body.rail-page .console-nav-rail button,
    body.rail-page .console-rail-logout {
        position: relative;
        width: 100%;
        min-width: 0;
        min-height: 44px;
        display: grid;
        place-items: center;
        padding: 0;
        margin: 0;
        border: 1px solid rgba(90, 155, 255, 0.16);
        border-radius: 8px;
        background: rgba(255, 255, 255, 0.025);
        clip-path: none;
        touch-action: manipulation;
    }

    body.rail-page .console-nav-rail .console-nav-label,
    body.rail-page .console-rail-logout .console-nav-label {
        display: none;
    }

    body.rail-page .console-nav-rail .console-nav-icon,
    body.rail-page .console-rail-logout .console-nav-icon {
        font-size: 17px;
        line-height: 1;
    }

    body.rail-page .console-nav-rail .chat-launcher-badge {
        position: absolute;
        top: -4px;
        right: -3px;
        z-index: 2;
        margin: 0;
    }

    body.rail-page .console-rail-logout {
        grid-area: logout;
        color: #ffb7bf;
        background: rgba(145, 39, 52, 0.22);
        border-color: rgba(224, 97, 110, 0.32);
    }

    body.rail-page .console-main {
        width: 100%;
        min-width: 0;
    }

    body.rail-page .console-status {
        width: auto;
        min-width: 0;
        margin: 9px 8px 0;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        clip-path: polygon(8px 0, calc(100% - 8px) 0, 100% 8px, 100% calc(100% - 8px), calc(100% - 8px) 100%, 8px 100%, 0 calc(100% - 8px), 0 8px);
    }

    body.console-page .status-item {
        min-width: 0;
        padding: 8px 10px;
        border-bottom: 1px solid rgba(90, 155, 255, 0.1);
    }

    body.console-page .status-item:nth-child(odd) {
        border-right: 1px solid rgba(90, 155, 255, 0.1);
    }

    body.console-page .status-item + .status-item::before {
        display: none;
    }

    body.console-page .status-label {
        font-size: 8.5px;
    }

    body.console-page .status-value,
    body.console-page .status-sub {
        max-width: 100%;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    body.console-page .status-value {
        font-size: 12.5px;
    }

    body.console-page .status-sub {
        font-size: 9px;
    }

    body.console-page .status-rank-pill,
    body.console-page .status-friends-online,
    body.console-page .status-live {
        grid-column: 1 / -1;
        min-height: 34px;
        height: auto;
        padding: 6px 10px;
        border-left: 0;
        border-top: 1px solid rgba(90, 155, 255, 0.12);
    }

    body.rail-page .console-shell {
        width: auto;
        min-width: 0;
        margin: 9px 8px calc(34px + env(safe-area-inset-bottom));
    }

    body.lobby-page .panel-shell,
    body.lobby-page .console-panel {
        min-width: 0;
        backdrop-filter: none;
    }

    body.console-page .console-panel {
        padding: 16px 15px;
    }

    .chat-drawer {
        width: 100dvw;
        max-width: none;
        padding: max(14px, env(safe-area-inset-top)) 14px max(12px, env(safe-area-inset-bottom));
    }

    .chat-drawer-backdrop {
        backdrop-filter: none;
    }

    .prestige-modal {
        padding: max(8px, env(safe-area-inset-top)) 8px max(8px, env(safe-area-inset-bottom));
    }

    .prestige-modal-card,
    .prestige-modal .bento-prestige {
        max-height: calc(100dvh - 16px);
    }
}

@media (max-width: 820px) {
    body.console-page .console-bento:not(.console-bento-parties):not(.console-bento-worlds-view),
    body.console-page .console-bento-parties,
    body.console-page .console-bento-worlds-view {
        display: grid;
        grid-template-columns: minmax(0, 1fr) !important;
        grid-template-areas: none !important;
        gap: 10px;
    }

    body.console-page .console-bento:not(.console-bento-parties):not(.console-bento-worlds-view) > *,
    body.console-page .console-bento-parties > *,
    body.console-page .console-bento-worlds-view > * {
        grid-area: auto !important;
        min-width: 0;
    }

    body.console-page .selector-card {
        grid-template-columns: minmax(0, 1fr);
        gap: 10px;
    }

    body.console-page .bento-command-grid {
        gap: 13px;
    }

    body.console-page .bento-command-head h1 {
        font-size: clamp(19px, 6vw, 23px);
    }

    body.console-page .hero-description {
        font-size: 12.5px;
    }

    body.console-page .bento-power,
    body.console-page .bento-parties-hero,
    body.console-page .bento-parties-cta,
    body.console-page .bento-parties-header {
        padding: 17px 15px;
    }

    body.console-page .empire-power-score strong {
        font-size: 31px;
    }

    body.console-page .parties-cta-copy {
        min-width: 0;
        flex-basis: 100%;
    }

    body.console-page .bento-parties-cta .parties-cta-actions,
    body.console-page .speed-hub-actions {
        width: 100%;
        display: grid;
        grid-template-columns: minmax(0, 1fr);
    }

    body.console-page .bento-parties-cta .parties-cta-actions button,
    body.console-page .speed-hub-actions button,
    body.console-page .world-action-row button {
        width: 100%;
    }

    body.console-page .bento-parties-hero .speed-ranked-mini-main {
        gap: 12px;
    }

    body.console-page .bento-parties-hero .speed-ranked-mini-emblem {
        width: 58px;
        height: 58px;
        font-size: 24px;
    }

    body.console-page .bento-parties-hero .speed-ranked-mini-stats {
        gap: 6px;
    }

    body.console-page .bento-parties-hero .speed-ranked-mini-stats span {
        min-width: 0;
        padding: 9px 5px;
    }

    body.console-page .speed-ranked-mini-footer {
        align-items: stretch;
        flex-direction: column;
    }

    body.console-page .speed-ranked-mini-footer button {
        width: 100%;
    }

    body.console-page .parties-matches-col .speed-quick-worlds {
        min-height: 0;
    }

    body.console-page .news-list,
    body.console-page .prestige-grid,
    body.console-page .social-list {
        max-height: 340px;
    }

    body.console-page .profile-widget,
    body.console-page .profile-widget-avatar,
    body.console-page .profile-emblem-showcase {
        align-items: flex-start;
    }

    body.console-page .profile-widget-lg .profile-avatar-circle {
        width: 72px;
        height: 72px;
    }

    body.console-page .steam-friends-list .social-row {
        align-items: flex-start;
    }

    body.console-page .steam-friends-list .social-row-actions {
        flex-direction: column;
    }

    body.console-page .friend-request-form,
    body.console-page .referral-link-row {
        align-items: stretch;
        flex-direction: column;
    }

    body.console-page .friend-request-form button,
    body.console-page .referral-link-row button {
        width: 100%;
    }
}

@media (max-width: 520px) {
    body.rail-page .console-modes-rail .mode-index {
        display: none;
    }

    body.rail-page .console-modes-rail .mode-label,
    body.rail-page .console-modes-rail .mode-label[data-mobile-label]::after {
        font-size: 10.5px;
    }

    body.console-page .console-panel {
        padding: 14px 12px;
    }

    body.console-page .panel-head.between,
    body.console-page .speed-hub-module-head {
        align-items: flex-start;
        flex-direction: column;
    }

    body.console-page .panel-head.between .status-pill,
    body.console-page .news-head-actions {
        align-self: stretch;
    }

    body.console-page .news-head-actions {
        justify-content: space-between;
    }

    body.console-page .resume-game-button {
        min-height: 76px;
        grid-template-columns: 42px minmax(0, 1fr) 30px;
        gap: 10px;
        padding: 11px !important;
    }

    body.console-page .resume-game-icon {
        width: 42px;
        height: 42px;
        border-radius: 12px;
        font-size: 1.4rem;
    }

    body.console-page .resume-game-copy strong {
        font-size: 1rem;
    }

    body.console-page .resume-game-copy em {
        display: none;
    }

    body.console-page .resume-game-arrow {
        width: 30px;
        height: 30px;
    }

    body.console-page .empire-power-metrics {
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 5px;
    }

    body.console-page .empire-power-metrics > div {
        min-width: 0;
        display: grid;
        justify-items: center;
        gap: 5px;
        padding: 8px 4px;
        text-align: center;
    }

    body.console-page .empire-power-metric-icon {
        width: 27px;
        height: 27px;
        font-size: 15px;
    }

    body.console-page .empire-power-metrics strong,
    body.console-page .empire-power-metrics small {
        max-width: 100%;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    body.console-page .empire-power-metrics strong {
        font-size: 12px;
    }

    body.console-page .empire-power-metrics small {
        font-size: 8px;
    }

    body.console-page .world-card {
        padding: 12px;
    }

    body.console-page .world-meta-grid {
        grid-template-columns: minmax(0, 1fr);
    }

    body.console-page .news-card {
        grid-template-columns: 48px minmax(0, 1fr);
        gap: 9px;
    }

    body.console-page .account-chat-form {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        gap: 7px;
    }

    body.console-page .account-chat-form button {
        width: auto;
        min-width: 72px;
        padding: 0 11px;
    }

    #dm-drawer .chat-message-content {
        max-width: calc(100% - 48px);
    }
}

@media (max-width: 360px) {
    body.rail-page .console-rail {
        grid-template-columns: minmax(0, 1fr) 40px;
        padding-inline: 5px;
    }

    body.rail-page .console-nav-rail {
        grid-template-columns: repeat(5, minmax(38px, 1fr));
        gap: 3px;
    }

    body.rail-page .console-nav-rail button,
    body.rail-page .console-rail-logout {
        min-height: 40px;
    }

    body.rail-page .console-nav-rail .console-nav-icon,
    body.rail-page .console-rail-logout .console-nav-icon {
        font-size: 15px;
    }

    body.console-page .status-item {
        padding-inline: 8px;
    }
}

@media (prefers-reduced-motion: reduce) {
    body.console-page *,
    body.console-page *::before,
    body.console-page *::after {
        scroll-behavior: auto !important;
    }
}

/* Lobby V6.1a — tiroirs chat/amis réellement utilisables sur petit écran. */
@media (max-width: 900px) {
    .chat-drawer {
        inset: 0 0 auto auto;
        width: 100dvw;
        max-width: 100dvw;
        height: 100dvh;
        max-height: 100dvh;
        min-height: 0;
        box-sizing: border-box;
        overflow: hidden;
        overscroll-behavior: contain;
    }

    .chat-drawer-head,
    .chat-room-bar-top,
    .chat-channel-tabs,
    .chat-room-bar,
    .account-chat-reply,
    .account-chat-form {
        flex: 0 0 auto;
    }

    .account-chat-messages,
    #dm-drawer #dm-messages {
        flex: 1 1 0;
        min-height: 0;
        overflow-y: auto;
        overscroll-behavior: contain;
        -webkit-overflow-scrolling: touch;
    }

    #friends-drawer .friends-drawer-body {
        flex: 1 1 0;
        min-height: 0;
        overflow-y: auto;
        overscroll-behavior: contain;
        -webkit-overflow-scrolling: touch;
    }

    #friends-drawer .social-friends-card {
        flex: 0 0 auto;
        min-height: 0;
    }

    #friends-drawer .social-friends-card .social-list,
    #friends-drawer .dm-conversation-list {
        flex: none;
        max-height: none;
        overflow: visible;
    }

    .chat-channel-tabs {
        display: flex;
        flex-wrap: nowrap;
        overflow-x: auto;
        padding-bottom: 3px;
        scrollbar-width: thin;
        -webkit-overflow-scrolling: touch;
    }

    .chat-channel-tabs button {
        flex: 0 0 auto;
        white-space: nowrap;
    }

    .account-chat-form textarea {
        min-width: 0;
        max-height: 96px;
    }
}

/* Lobby V6.1b — compacité verticale et clavier mobile. */
@media (max-width: 520px), (max-height: 700px) {
    .chat-drawer {
        padding: max(9px, env(safe-area-inset-top)) 10px max(8px, env(safe-area-inset-bottom));
    }

    .chat-drawer-head {
        align-items: center;
        margin-bottom: 6px;
    }

    .chat-drawer-head p,
    #account-chat-room-help {
        display: none;
    }

    .chat-room-bar-top,
    .chat-channel-tabs,
    .chat-room-bar {
        margin-bottom: 6px;
    }

    .chat-room-bar {
        padding-bottom: 6px;
    }

    .account-chat-messages {
        margin-bottom: 6px;
    }

    .account-chat-form {
        grid-template-columns: minmax(0, 1fr) auto;
    }

    .account-chat-form textarea {
        padding: 8px 9px;
    }
}

@supports not (height: 100dvh) {
    @media (max-width: 900px) {
        .chat-drawer {
            height: 100vh;
            max-height: 100vh;
        }
    }
}

/* Lobby V6.2 — chat compact et clavier mobile stable. */
@media (max-width: 900px) {
    #chat-drawer-backdrop { display: none !important; }
    #chat-drawer {
        inset: auto 8px 64px auto;
        width: min(390px, calc(100dvw - 16px));
        max-width: calc(100dvw - 16px);
        height: min(520px, 72dvh, calc(var(--chat-visual-height, 100dvh) - 92px));
        max-height: calc(var(--chat-visual-height, 100dvh) - 92px);
        min-height: min(360px, calc(var(--chat-visual-height, 100dvh) - 92px));
        border: 1px solid var(--lobby-border-strong);
        border-radius: 14px;
        padding: 10px;
    }
    #chat-drawer.is-keyboard-open {
        inset: auto 6px 6px auto;
        width: calc(100dvw - 12px);
        max-width: calc(100dvw - 12px);
        height: calc(var(--chat-visual-height, 100dvh) - 12px);
        max-height: calc(var(--chat-visual-height, 100dvh) - 12px);
        min-height: 0;
    }
    #chat-drawer .chat-drawer-head { margin-bottom: 5px; }
    #chat-drawer .chat-drawer-head .eyebrow,
    #chat-drawer .chat-drawer-head h2 + p,
    #chat-drawer #account-chat-room-help { display: none; }
    #chat-drawer .chat-room-bar-top,
    #chat-drawer .chat-channel-tabs,
    #chat-drawer .chat-room-bar { margin-bottom: 5px; }
    #chat-drawer .account-chat-messages { min-height: 105px; margin-bottom: 5px; }
    #chat-drawer .account-chat-form { flex: 0 0 auto; gap: 6px; padding-top: 5px; }
    #chat-drawer .account-chat-form textarea { min-height: 40px; max-height: 78px; font-size: 16px; }
}