/* Mobile match shell, preparation, and battle. Load after mobile.css,
   which provides the shared mobile navigation, base styles, and tokens. */

/* Hide the mobile match back link before the UI mode is selected. */
.mobile-play-back { display: none; }

html[data-ui-mode="mobile"] body.site-shell:is([data-route="/play"], [data-route="/tceam"]) {
    grid-template-areas: "play-header" "workspace" !important;
}

html[data-ui-mode="mobile"] .play-header .app-auth-controls {
    inline-size: auto !important;
    display: flex;
    align-items: center;
    gap: 6px !important;
}

/* Unified Compact 56px Header on /play Route */
html[data-ui-mode="mobile"] .play-header:not([hidden]) {
    grid-area: play-header;
    position: sticky;
    top: 0;
    z-index: 60;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px !important;
    height: var(--m-header-h) !important;
    min-height: var(--m-header-h) !important;
    padding: 0 12px !important;
    background: rgba(15, 15, 20, 0.95);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border-bottom: 1px solid var(--m-border);
}

html[data-ui-mode="mobile"] .play-header .play-nav,
html[data-ui-mode="mobile"] .play-header .play-menu,
html[data-ui-mode="mobile"] .play-header .play-header-launch {
    display: none !important;
}

html[data-ui-mode="mobile"] .play-header [data-play-brand] {
    width: auto !important;
    max-width: 118px;
}

html[data-ui-mode="mobile"] .play-header .app-brand {
    height: 40px !important;
    min-height: 40px !important;
    padding: 0 !important;
}

html[data-ui-mode="mobile"] .play-header .app-brand img {
    height: 34px !important;
    max-height: 34px !important;
    width: auto !important;
}

html[data-ui-mode="mobile"] .play-header .m-search-trigger {
    display: none !important;
}

@media (orientation: landscape) {
    html[data-ui-mode="mobile"] body[data-route="/play"]:is([data-match-screen="fighters"], [data-match-screen="maps"]) .mobile-play-back {
        display: inline-flex;
        align-items: center;
        min-height: 44px;
        color: var(--m-text);
        font-size: 12px;
        touch-action: manipulation;
    }
}

html[data-ui-mode="mobile"] body.site-shell[data-route="/play"] .workspace {
    min-height: 0;
    scroll-padding-bottom: calc(var(--m-nav-h) + 12px + env(safe-area-inset-bottom));
}

html[data-ui-mode="mobile"] body[data-route="/play"] .site-footer {
    display: none;
}

/* ==========================================================================
   MATCH SETUP LOBBY (/play) — 2-TIER MOBILE FLOW
   ========================================================================== */
html[data-ui-mode="mobile"] body.site-shell:is([data-route="/tceam"], [data-route="/play"]) main {
    padding: 10px 12px calc(var(--m-nav-h) + 86px + env(safe-area-inset-bottom)) !important;
}

html[data-ui-mode="mobile"] .match-hero {
    gap: 10px;
    margin-bottom: 10px;
}

html[data-ui-mode="mobile"] .match-hero .match-kicker {
    display: none;
}

html[data-ui-mode="mobile"] .match-hero h1 {
    font-size: 24px !important;
    margin: 0 0 4px !important;
}

html[data-ui-mode="mobile"] .match-hero p:last-child {
    font-size: 11px;
}

html[data-ui-mode="mobile"] .match-collection {
    padding-left: 12px;
}

html[data-ui-mode="mobile"] .match-collection strong {
    font-size: 24px;
}

html[data-ui-mode="mobile"] .match-collection small {
    display: none;
}

/* Step Pills */
html[data-ui-mode="mobile"] .match-steps {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--m-border);
}

html[data-ui-mode="mobile"] .match-steps button,
html[data-ui-mode="mobile"] .match-final-step {
    min-height: 38px;
    padding: 6px 8px;
    border-radius: 10px;
    font-size: 11px;
    text-align: center;
}

/* Tier 1: Compact VS Team Strip */
html[data-ui-mode="mobile"] .match-draft {
    grid-template-columns: minmax(0, 1fr) !important;
    gap: 10px;
    margin-bottom: 12px;
}

html[data-ui-mode="mobile"] .match-format {
    display: grid !important;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
}

html[data-ui-mode="mobile"] .match-format select {
    min-height: 40px;
    border-radius: 10px;
    font-size: 13px;
}

html[data-ui-mode="mobile"] .match-teams {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
}

html[data-ui-mode="mobile"] .match-team {
    border-radius: 12px;
    padding: 8px;
    background: var(--m-surface);
}

html[data-ui-mode="mobile"] .match-team-slots {
    flex-direction: column;
    gap: 5px;
}

html[data-ui-mode="mobile"] .match-lobby .match-team-slot {
    min-height: 40px;
    border-radius: 8px;
    padding: 4px 6px;
}

html[data-ui-mode="mobile"] .match-team-slot .match-sprite {
    width: 30px;
    height: 30px;
}

html[data-ui-mode="mobile"] .match-pick-name > span {
    font-size: 11px;
}

html[data-ui-mode="mobile"] .match-assist-row .match-sprite {
    display: none;
}

html[data-ui-mode="mobile"] .match-assist-row select {
    min-height: 34px;
    border-radius: 8px;
    font-size: 11.5px;
}

/* Tier 2: Series Filter + 3-Col Fighter Grid + Dossier */
html[data-ui-mode="mobile"] .match-selection {
    grid-template-columns: minmax(0, 1fr) !important;
    gap: 10px;
}

html[data-ui-mode="mobile"] .match-sidebar {
    grid-column: 1 / -1;
    padding: 10px;
    border-radius: 12px;
    background: var(--m-surface);
}

html[data-ui-mode="mobile"] .match-sidebar h2,
html[data-ui-mode="mobile"] .match-sidebar .match-kicker,
html[data-ui-mode="mobile"] .match-series-list {
    display: none !important;
}

html[data-ui-mode="mobile"] .match-sidebar > select {
    display: block !important;
    min-height: 44px;
    border-radius: 10px;
    font-size: 14px;
}

html[data-ui-mode="mobile"] .match-browser {
    padding: 12px;
    border-radius: 12px;
    background: var(--m-surface);
}

html[data-ui-mode="mobile"] .match-browser-heading h2 {
    font-size: 17px;
}

html[data-ui-mode="mobile"] .match-search input {
    min-height: 42px;
    border-radius: 10px;
    font-size: 16px;
}

html[data-ui-mode="mobile"] .match-fighters {
    grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
    gap: 8px !important;
}

@media (min-width: 540px) {
    html[data-ui-mode="mobile"] .match-fighters {
        grid-template-columns: repeat(4, minmax(0, 1fr)) !important;
    }
}

html[data-ui-mode="mobile"] .match-lobby .match-fighter-card {
    border-radius: 10px;
}

html[data-ui-mode="mobile"] .match-lobby .match-fighter-card:hover {
    transform: none;
}

html[data-ui-mode="mobile"] .match-card-name {
    font-size: 10.5px;
    padding: 6px 4px;
    min-height: 32px;
}

html[data-ui-mode="mobile"] .match-pagination button {
    min-height: 40px;
    min-width: 78px;
    border-radius: 10px;
    font-size: 12px;
}

/* Fighter Dossier with 44px P1 / P2 Assign Buttons */
html[data-ui-mode="mobile"] .match-dossier {
    display: grid;
    grid-template-columns: 112px minmax(0, 1fr);
    border-radius: 12px;
    background: var(--m-surface);
    overflow: hidden;
}

html[data-ui-mode="mobile"] .match-dossier-top {
    grid-column: 1 / -1;
    padding: 9px 12px;
    font-size: 10.5px;
}

html[data-ui-mode="mobile"] .match-render {
    height: 180px;
    border-bottom: 0;
    border-right: 1px solid var(--m-border);
}

html[data-ui-mode="mobile"] .match-dossier-copy {
    padding: 12px;
}

html[data-ui-mode="mobile"] .match-dossier h2 {
    font-size: 18px;
    margin: 6px 0 4px;
}

html[data-ui-mode="mobile"] .match-assign {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    padding: 10px 12px 12px;
    margin-top: 0;
    border-top: 1px solid var(--m-border);
}

html[data-ui-mode="mobile"] .match-assign button {
    min-height: 44px;
    border-radius: 10px;
    font-size: 13px;
    font-weight: 700;
}

html[data-ui-mode="mobile"] .match-assign p {
    grid-column: 1 / -1;
}

/* Stage Selection */
html[data-ui-mode="mobile"] .match-map-layout {
    grid-template-columns: minmax(0, 1fr) !important;
    gap: 14px;
}

html[data-ui-mode="mobile"] .match-stage-preview {
    aspect-ratio: 16 / 9;
    border-radius: 12px;
}

html[data-ui-mode="mobile"] .match-stage-preview h2 {
    font-size: 22px;
}

html[data-ui-mode="mobile"] .match-map-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 8px;
}

@media (min-width: 500px) {
    html[data-ui-mode="mobile"] .match-map-grid {
        grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
    }
}

html[data-ui-mode="mobile"] .match-rules-panel {
    border-radius: 12px;
    padding: 14px;
}

html[data-ui-mode="mobile"] .match-rules {
    grid-template-columns: minmax(0, 1fr) !important;
    gap: 12px;
}

html[data-ui-mode="mobile"] .match-lobby[data-ui-shell="choose-fighter"] .match-rules > label:not([data-match-cpu-control]) {
    grid-template-columns: minmax(0, 1fr);
}

html[data-ui-mode="mobile"] .match-lobby[data-ui-shell="choose-fighter"] .match-rules select {
    width: 100%;
    min-width: 0;
    min-height: 44px;
    border-radius: 10px;
    font-size: max(16px, 1rem);
}

html[data-ui-mode="mobile"] .match-rule-label {
    overflow-wrap: anywhere;
}

html[data-ui-mode="mobile"] .match-lobby[data-ui-shell="choose-fighter"] .match-rule-label small,
html[data-ui-mode="mobile"] .match-rule-note {
    font-size: 0.8125rem;
    line-height: 1.45;
    overflow-wrap: anywhere;
}

/* Sticky Bottom CTA floating cleanly above the 5-Tab Bar */
html[data-ui-mode="mobile"] .match-flow-footer {
    position: fixed;
    left: 10px;
    right: 10px;
    bottom: calc(var(--m-nav-h) + 8px + env(safe-area-inset-bottom));
    z-index: 55;
    margin: 0;
    padding: 10px 12px;
    border-radius: 14px;
    border: 1px solid rgba(255, 209, 107, 0.4);
    background: rgba(18, 18, 24, 0.96);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    box-shadow: 0 10px 28px rgba(0, 0, 0, 0.65);
    flex-wrap: nowrap;
    gap: 10px;
}

html[data-ui-mode="mobile"] .match-flow-footer p {
    flex: 1 1 auto;
    min-width: 0;
    font-size: 11.5px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

html[data-ui-mode="mobile"] .match-flow-footer > button,
html[data-ui-mode="mobile"] .match-launch > button {
    min-height: 44px;
    border-radius: 10px;
    padding: 0 16px;
    font-size: 13px;
}

/* Keep the stage actions in the workspace so neither the rules nor their
   final note can end up underneath a fixed confirmation bar. */
html[data-ui-mode="mobile"] .match-launch {
    position: static;
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 10px;
    padding: 10px 12px;
    border-radius: 12px;
}

html[data-ui-mode="mobile"] .match-launch p {
    grid-column: 1 / -1;
    grid-row: 1;
    overflow-wrap: anywhere;
}

html[data-ui-mode="mobile"] .match-launch > button {
    min-width: 0;
    max-width: 100%;
    padding-block: 8px;
    font-size: 0.875rem;
    white-space: normal;
    overflow-wrap: anywhere;
}

/* Two-panel match setup for a phone held sideways. Each view owns the
   workspace height, with scrolling confined to the list that needs it. */
@media (orientation: landscape) {
    html[data-ui-mode="mobile"] body[data-route="/play"]:is([data-match-screen="fighters"], [data-match-screen="maps"]) {
        --m-header-h: 44px;
        grid-template-rows: calc(var(--m-header-h) + env(safe-area-inset-top)) minmax(0, 1fr) !important;
        height: 100dvh;
        min-height: 0;
        overflow: hidden;
    }

    html[data-ui-mode="mobile"] body[data-route="/play"]:is([data-match-screen="fighters"], [data-match-screen="maps"]) #mobile-bottom-nav {
        display: none !important;
    }

    html[data-ui-mode="mobile"] body[data-route="/play"]:is([data-match-screen="fighters"], [data-match-screen="maps"]) .play-header:not([hidden]) {
        height: calc(var(--m-header-h) + env(safe-area-inset-top)) !important;
        min-height: 0 !important;
        padding: env(safe-area-inset-top) max(10px, env(safe-area-inset-right)) 0 max(10px, env(safe-area-inset-left)) !important;
    }

    html[data-ui-mode="mobile"] body[data-route="/play"]:is([data-match-screen="fighters"], [data-match-screen="maps"]) .workspace {
        min-height: 0;
        overflow: hidden;
        scroll-padding: 0;
    }

    html[data-ui-mode="mobile"] body.site-shell[data-route="/play"]:is([data-match-screen="fighters"], [data-match-screen="maps"]) main {
        display: flex;
        min-height: 0;
        padding: 6px max(10px, env(safe-area-inset-right)) max(6px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left)) !important;
    }

    html[data-ui-mode="mobile"] .match-lobby[data-ui-shell]:is([data-screen="fighters"], [data-screen="maps"]),
    html[data-ui-mode="mobile"] body[data-route="/play"]:is([data-match-screen="fighters"], [data-match-screen="maps"]) [data-page="/play"] {
        flex: 1;
        display: flex;
        flex-direction: column;
        min-width: 0;
        min-height: 0;
    }

    html[data-ui-mode="mobile"] .match-lobby[data-ui-shell]:is([data-screen="fighters"], [data-screen="maps"]) {
        gap: 6px;
        touch-action: manipulation;
    }

    html[data-ui-mode="mobile"] .match-lobby[data-ui-shell]:is([data-screen="fighters"], [data-screen="maps"]) :is(.match-hero, .match-steps) {
        display: none;
    }

    html[data-ui-mode="mobile"] .match-lobby[data-ui-shell]:is([data-screen="fighters"], [data-screen="maps"]) > .match-status {
        flex: 0 0 auto;
        min-height: 0;
        margin: 0;
        font-size: 11px;
        line-height: 1.25;
    }

    html[data-ui-mode="mobile"] .match-lobby[data-ui-shell]:is([data-screen="fighters"], [data-screen="maps"]) > fieldset {
        flex: 1 1 0;
        display: flex;
        flex-direction: column;
        min-height: 0;
        gap: 6px;
    }

    html[data-ui-mode="mobile"] .match-lobby[data-screen="fighters"] .match-top-controls {
        --match-toolbar-height: 38px;
        --match-toolbar-font: 700 12px/1.25 'Barlow', sans-serif;
        --match-toolbar-label-font: 700 10px/1.2 'Barlow', sans-serif;
        display: flex !important;
        flex: 0 0 auto;
        flex-wrap: nowrap;
        gap: 8px;
        padding: 0 0 4px;
        overflow-x: auto;
        overflow-y: hidden;
        overscroll-behavior-x: contain;
    }

    html[data-ui-mode="mobile"] .match-lobby[data-screen="fighters"] .match-top-controls > label,
    html[data-ui-mode="mobile"] .match-lobby[data-screen="fighters"] :is(.match-roster-control-group, .match-ownership-control-group) {
        flex: 0 0 auto;
        gap: 2px;
        padding: 0;
        border: 0;
    }

    html[data-ui-mode="mobile"] .match-lobby[data-screen="fighters"] .match-top-controls .match-roster-tools {
        flex-wrap: nowrap;
        gap: 4px;
    }

    html[data-ui-mode="mobile"] .match-lobby[data-screen="fighters"] .match-top-controls :is(.match-segmented,.match-assist-toggle,.match-kind-switch) button {
        padding-inline: 7px;
    }

    html[data-ui-mode="mobile"] .match-lobby[data-screen="fighters"] [data-match-panel="fighters"] {
        flex: 1;
        display: flex;
        flex-direction: column;
        min-height: 0;
    }

    .match-mobile-pick-layout {
        flex: 1;
        display: grid;
        grid-template: auto auto minmax(0, 1fr) auto / minmax(0, 2fr) minmax(0, 3fr) minmax(195px, 34%);
        gap: 5px 7px;
        min-height: 0;
        position: relative;
    }

    html[data-ui-mode="mobile"] .match-lobby[data-screen="fighters"] .match-sidebar {
        grid-area: 1 / 1;
        padding: 0;
        border: 0;
        background: transparent;
    }

    html[data-ui-mode="mobile"] .match-lobby[data-screen="fighters"] .match-search-row { grid-area: 1 / 2; }

    html[data-ui-mode="mobile"] .match-lobby[data-screen="fighters"] :is(.match-sidebar select, .match-search input) {
        height: 38px;
        min-height: 38px;
        max-width: 100%;
        font-size: 16px;
    }

    html[data-ui-mode="mobile"] .match-lobby[data-screen="fighters"] :is(.match-browser-heading, .match-browser-meta > span, .match-search kbd) {
        display: none;
    }

    html[data-ui-mode="mobile"] .match-lobby[data-screen="fighters"] .match-browser-meta {
        grid-area: 2 / 1 / 3 / 3;
        margin: 0;
    }

    html[data-ui-mode="mobile"] .match-lobby[data-screen="fighters"] .match-browser-meta:not(:has([data-match-assist-none]:not([hidden]))) {
        display: none;
    }

    html[data-ui-mode="mobile"] .match-lobby[data-ui-shell][data-screen="fighters"] .match-fighters {
        grid-area: 3 / 1 / 4 / 3;
        grid-template-columns: repeat(var(--match-columns, 4), minmax(0, 1fr)) !important;
        grid-template-rows: repeat(var(--match-rows, 2), minmax(52px, 1fr));
        grid-auto-rows: minmax(52px, 1fr);
        gap: 6px !important;
        min-height: 0;
        margin: 0;
        padding: 0;
        overflow: auto;
        overscroll-behavior: contain;
    }

    html[data-ui-mode="mobile"] .match-lobby[data-ui-shell][data-screen="fighters"] .match-fighter-tile {
        min-height: 0;
        min-width: 0;
    }

    html[data-ui-mode="mobile"] .match-lobby[data-ui-shell][data-screen="fighters"] .match-fighter-card {
        display: flex;
        flex-direction: column;
        width: 100%;
        height: 100%;
        min-height: 0;
    }

    html[data-ui-mode="mobile"] .match-lobby[data-ui-shell][data-screen="fighters"] .match-card-visual {
        flex: 1;
        width: 100%;
        min-height: 0;
        aspect-ratio: auto;
    }

    html[data-ui-mode="mobile"] .match-lobby[data-screen="fighters"] .match-card-visual :is(.match-sprite, .match-render-art) {
        position: absolute;
        inset: 0;
        width: 100%;
        height: 100%;
        max-height: none;
        padding: 2px;
    }

    html[data-ui-mode="mobile"] .match-lobby[data-screen="fighters"] .match-card-name {
        width: 100%;
        min-height: 0;
        padding: 3px 2px;
        overflow: hidden;
        white-space: nowrap;
        text-overflow: ellipsis;
        font-size: 11px;
    }

    html[data-ui-mode="mobile"] .match-lobby[data-screen="fighters"] .match-pagination {
        grid-area: 4 / 1 / 5 / 3;
        margin: 0;
        gap: 8px;
    }

    html[data-ui-mode="mobile"] .match-lobby[data-screen="fighters"] .match-pagination button {
        min-height: 36px;
        min-width: 54px;
        padding: 4px 8px;
    }

    html[data-ui-mode="mobile"] .match-lobby[data-ui-shell][data-screen="fighters"] .match-dossier {
        grid-area: 1 / 3 / 3 / 4;
        display: grid;
        grid-template-columns: minmax(0, .8fr) minmax(0, 1.2fr);
        align-items: center;
        position: static;
        align-content: center;
        gap: 4px;
        border: 0;
        border-radius: 0;
        background: transparent;
        box-shadow: none;
        overflow: visible;
    }

    html[data-ui-mode="mobile"] .match-lobby[data-screen="fighters"] .match-dossier :is(.match-dossier-top, .match-render, .match-series-tag, .match-dossier-copy > p, .match-owned-note, .match-assign p) {
        display: none;
    }

    html[data-ui-mode="mobile"] .match-lobby[data-screen="fighters"] .match-dossier-copy {
        display: flex;
        flex-direction: column;
        align-items: flex-start;
        gap: 2px;
        min-width: 0;
        max-height: none;
        overflow: visible;
        padding: 0 3px;
        background: transparent;
    }

    html[data-ui-mode="mobile"] .match-lobby[data-screen="fighters"] .match-dossier h2 {
        max-width: 100%;
        margin: 0;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        font-size: 14px;
    }

    html[data-ui-mode="mobile"] .match-lobby[data-screen="fighters"] .match-form-details {
        flex: 0 0 auto;
        margin: 0;
        padding: 0;
        border: 0;
    }

    html[data-ui-mode="mobile"] .match-lobby[data-screen="fighters"] .match-form-details summary { padding-block: 2px; }

    html[data-ui-mode="mobile"] .match-lobby[data-screen="fighters"] .match-form-inspection {
        position: absolute;
        top: 44px;
        right: 0;
        z-index: 7;
        display: grid;
        gap: 4px;
        width: min(290px, 65vw);
        max-height: calc(100% - 54px);
        padding: 8px;
        overflow: auto;
        border: 1px solid var(--m-border-strong);
        border-radius: 8px;
        background: var(--m-surface);
    }

    html[data-ui-mode="mobile"] .match-lobby[data-ui-shell][data-screen="fighters"] .match-assign {
        grid-column: 2;
        display: flex;
        margin: 0;
        padding: 0;
        border: 0;
        gap: 5px;
        background: transparent;
    }

    html[data-ui-mode="mobile"] .match-lobby[data-screen="fighters"] .match-assign button {
        flex: 1 1 0;
        min-width: 0;
        min-height: 38px;
        padding: 4px;
        font-size: 11px;
        line-height: 1.15;
    }

    html[data-ui-mode="mobile"] .match-lobby[data-ui-shell][data-screen="fighters"] .match-draft {
        grid-area: 3 / 3 / 5 / 4;
        display: grid;
        grid-template-rows: minmax(0, 1fr) auto;
        gap: 5px;
        min-height: 0;
        margin: 0;
        padding: 6px;
    }

    html[data-ui-mode="mobile"] .match-lobby[data-ui-shell][data-screen="fighters"] .match-dock-heading { display: contents; }
    html[data-ui-mode="mobile"] .match-lobby[data-screen="fighters"] .match-dock-heading > div:first-child { display: none; }

    html[data-ui-mode="mobile"] .match-lobby[data-ui-shell][data-screen="fighters"] .match-dock-tools {
        grid-area: 2 / 1;
        display: grid;
        grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1.4fr);
        gap: 4px;
    }

    html[data-ui-mode="mobile"] .match-lobby[data-ui-shell][data-screen="fighters"] .match-dock-tools button {
        min-height: 44px;
        min-width: 0;
        padding: 4px 5px;
        line-height: 1.15;
        overflow-wrap: anywhere;
    }

    html[data-ui-mode="mobile"] .match-lobby[data-screen="fighters"] [data-match-next-step] > span { display: none; }

    html[data-ui-mode="mobile"] .match-lobby[data-ui-shell][data-screen="fighters"] .match-teams {
        grid-area: 1 / 1;
        grid-template-columns: minmax(0, 1fr);
        align-content: start;
        gap: 5px;
        min-height: 0;
        overflow: auto;
        overscroll-behavior: contain;
    }

    html[data-ui-mode="mobile"] .match-lobby[data-screen="fighters"] .match-teams::before { display: none; }
    html[data-ui-mode="mobile"] .match-lobby[data-screen="fighters"] .match-team h3 { margin-bottom: 3px; }
    html[data-ui-mode="mobile"] .match-lobby[data-screen="fighters"] .match-team-lineup { flex-wrap: nowrap; gap: 4px; }

    html[data-ui-mode="mobile"] .match-lobby[data-screen="fighters"] .match-team-slots {
        flex: 1 1 0;
        flex-direction: row;
        gap: 3px;
    }

    html[data-ui-mode="mobile"] .match-lobby[data-ui-shell][data-screen="fighters"] .match-team-slot {
        flex-direction: column;
        justify-content: center;
        min-height: 42px;
        padding: 2px;
        gap: 2px;
    }

    html[data-ui-mode="mobile"] .match-lobby[data-ui-shell][data-screen="fighters"] .match-team-slot .match-sprite {
        width: 22px;
        height: 23px;
        border: 0;
        padding: 0;
    }

    html[data-ui-mode="mobile"] .match-lobby[data-screen="fighters"] :is(.match-team-slot .match-pick-name small, .match-order-badge) { display: none; }
    html[data-ui-mode="mobile"] .match-lobby[data-screen="fighters"] .match-team-slot .match-pick-name { max-width: 100%; text-align: center; }
    html[data-ui-mode="mobile"] .match-lobby[data-ui-shell][data-screen="fighters"] .match-team-slot .match-pick-name > span { font-size: 10px; }
    html[data-ui-mode="mobile"] .match-lobby[data-screen="fighters"] .match-assist-row { flex-basis: 46px; }

    html[data-ui-mode="mobile"] .match-lobby[data-screen="maps"] [data-match-panel="maps"] {
        flex: 1 1 0;
        min-height: 0;
    }

    .match-mobile-stage-layout {
        display: grid;
        grid-template-columns: minmax(0, 1.12fr) minmax(0, 1fr);
        grid-template-rows: minmax(0, 1fr);
        height: 100%;
        min-height: 0;
        gap: 8px;
        padding: 0;
    }

    html[data-ui-mode="mobile"] .match-lobby[data-ui-shell][data-screen="maps"] :is(.match-stage-column, .match-rules-panel) {
        min-height: 0;
        padding: 7px;
        border-radius: 8px;
        box-shadow: none;
    }

    html[data-ui-mode="mobile"] .match-lobby[data-ui-shell][data-screen="maps"] .match-stage-column {
        display: grid;
        grid-template-rows: minmax(0, 1fr);
    }

    html[data-ui-mode="mobile"] .match-lobby[data-screen="maps"] :is(.match-stage-heading, .match-stage-caption .match-kicker, .match-rules-header .match-kicker) {
        display: none;
    }

    html[data-ui-mode="mobile"] .match-lobby[data-ui-shell][data-screen="maps"] .match-stage-preview {
        width: 100%;
        height: 100%;
        aspect-ratio: auto;
        border-radius: 6px;
    }

    html[data-ui-mode="mobile"] .match-lobby[data-screen="maps"] .match-stage-caption { padding: 24px 8px 8px; }
    html[data-ui-mode="mobile"] .match-lobby[data-ui-shell][data-screen="maps"] .match-stage-caption h2 { font-size: clamp(15px, 2.6vw, 23px); }
    html[data-ui-mode="mobile"] .match-lobby[data-screen="maps"] .match-stage-nav { min-width: 40px; min-height: 44px; }

    html[data-ui-mode="mobile"] .match-lobby[data-ui-shell][data-screen="maps"] .match-rules-panel {
        display: flex;
        gap: 5px;
        overflow: auto;
        overscroll-behavior: contain;
    }

    html[data-ui-mode="mobile"] .match-lobby[data-ui-shell][data-screen="maps"] .match-rules-header { padding-bottom: 4px; }
    html[data-ui-mode="mobile"] .match-lobby[data-ui-shell][data-screen="maps"] .match-rules-header h2 { font-size: 17px; }
    html[data-ui-mode="mobile"] .match-lobby[data-screen="maps"] .match-rule-mode { margin: 2px 0 0; font-size: 10px; }
    html[data-ui-mode="mobile"] .match-lobby[data-ui-shell][data-screen="maps"] .match-rules { gap: 4px; margin: 0; }

    html[data-ui-mode="mobile"] .match-lobby[data-ui-shell][data-screen="maps"] .match-rules > label:not([data-match-cpu-control]) {
        grid-template-columns: minmax(0, 1fr) minmax(108px, 43%);
        gap: 4px;
        padding: 3px 5px;
    }

    html[data-ui-mode="mobile"] .match-lobby[data-ui-shell][data-screen="maps"] .match-rules select {
        min-height: 36px;
        padding: 2px 4px;
        font-size: 16px;
    }

    html[data-ui-mode="mobile"] .match-lobby[data-ui-shell][data-screen="maps"] .match-rules > label[data-match-cpu-control] {
        gap: 3px;
        padding: 4px 5px;
    }

    html[data-ui-mode="mobile"] .match-lobby[data-ui-shell][data-screen="maps"] .match-confirm-section {
        margin-top: 0;
        padding-top: 5px;
    }

    html[data-ui-mode="mobile"] .match-lobby[data-screen="maps"] .match-launch {
        flex: 0 0 auto;
        grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
        gap: 6px;
        margin: 0;
        padding: 4px;
    }

    html[data-ui-mode="mobile"] .match-lobby[data-screen="maps"] .match-launch p { display: none; }
    html[data-ui-mode="mobile"] .match-lobby[data-screen="maps"] .match-launch > button { min-height: 44px; padding: 5px 8px; }
}

/* Safari's landscape tab and address bars can leave less room than the
   setup needs. Keep the two columns and scroll the workspace as a fallback. */
@media (orientation: landscape) and (max-height: 360px) {
    html[data-ui-mode="mobile"] body[data-route="/play"]:is([data-match-screen="fighters"], [data-match-screen="maps"]) .workspace {
        overflow-y: auto;
        scroll-padding-block: 8px;
    }

    html[data-ui-mode="mobile"] body.site-shell[data-route="/play"]:is([data-match-screen="fighters"], [data-match-screen="maps"]) main {
        min-height: 336px;
    }
}

/* ==========================================================================
   ACTIVE BATTLE ARENA (LANDSCAPE FULLSCREEN + 6-BUTTON FIGHTING ARC)
   ========================================================================== */
html[data-ui-mode="mobile"] body[data-route="/play"][data-match-screen="game"] .game-surface {
    max-width: none;
    border-radius: 12px;
}

/* Hide bottom nav whenever an active match is running or paused */
html[data-ui-mode="mobile"] body[data-route="/play"][data-match-screen="game"]:has(#game-surface:is([data-state="running"], [data-state="paused"])) #mobile-bottom-nav {
    display: none !important;
}

/* Use the full browser viewport on phones, including the landscape safe areas. */
@media (orientation: landscape) and (max-height: 620px),
       (pointer: coarse) and (orientation: landscape) and (max-width: 1024px) {
    html[data-ui-mode="mobile"] body[data-route="/play"][data-match-screen="game"] .play-header,
    html[data-ui-mode="mobile"] body[data-route="/play"][data-match-screen="game"] #mobile-bottom-nav {
        display: none !important;
    }

    html[data-ui-mode="mobile"] body[data-route="/play"][data-match-screen="game"] #game-surface:is([data-state="loading"], [data-state="running"], [data-state="paused"]) {
        position: fixed;
        inset: 0;
        z-index: 400;
        width: 100%;
        max-width: none;
        height: 100dvh;
        display: flex;
        margin: 0;
        border: 0;
        border-radius: 0;
        background: #1c1c1c;
        touch-action: manipulation;
    }

    html[data-ui-mode="mobile"] body[data-route="/play"][data-match-screen="game"] #game-surface:is([data-state="loading"], [data-state="running"], [data-state="paused"]) #arena {
        flex: 1;
        height: 100%;
        min-height: 0;
        aspect-ratio: auto;
        background:
            linear-gradient(#10101038, #10101070),
            var(--battle-stage-art, none) center / cover no-repeat,
            url("/images/ui/home-feature.webp") center / cover no-repeat #1c1c1c;
    }

    html[data-ui-mode="mobile"]:has(body[data-route="/play"][data-match-screen="game"] #game-surface[data-state="running"]) {
        overflow: hidden;
        overscroll-behavior: none;
    }

    html[data-ui-mode="mobile"] body[data-route="/play"][data-match-screen="game"] #game-surface[data-state="running"],
    html[data-ui-mode="mobile"] body[data-route="/play"][data-match-screen="game"] #game-surface[data-state="running"] #arena {
        touch-action: none;
        overscroll-behavior: none;
        user-select: none;
        -webkit-user-select: none;
        -webkit-touch-callout: none;
    }

    /* TCEAM's SWF is 1066×600. Keeping its viewport at that ratio preserves
       the native HUD and lets the stage art, instead of Ruffle's bars, fill
       the remaining width on taller phones turned sideways. */
    html[data-ui-mode="mobile"] body[data-route="/play"][data-match-screen="game"] #arena ruffle-player {
        --battle-top: env(safe-area-inset-top, 0px);
        --battle-right: env(safe-area-inset-right, 0px);
        --battle-bottom: env(safe-area-inset-bottom, 0px);
        --battle-left: env(safe-area-inset-left, 0px);
        --battle-width: calc(100dvw - var(--battle-left) - var(--battle-right));
        --battle-height: calc(100dvh - var(--battle-top) - var(--battle-bottom));
        inset: var(--battle-top) var(--battle-right) var(--battle-bottom) var(--battle-left) !important;
        width: min(var(--battle-width), calc(var(--battle-height) * 1066 / 600)) !important;
        height: min(var(--battle-height), calc(var(--battle-width) * 600 / 1066)) !important;
        margin: auto;
    }

    html[data-ui-mode="mobile"] body[data-route="/play"][data-match-screen="game"] #game-surface:is([data-state="loading"], [data-state="running"], [data-state="paused"]) :is(.game-toolbar, .game-statusbar, #input-hud) {
        display: none !important;
    }

    /* Setup stays reachable while the match is paused. */
    html[data-ui-mode="mobile"] body[data-route="/play"][data-match-screen="game"] #game-surface:is([data-state="running"], [data-state="paused"]) #mobile-battle-back {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        position: absolute;
        z-index: 30;
        top: calc(6px + env(safe-area-inset-top));
        left: calc(10px + env(safe-area-inset-left));
        min-height: 44px;
        padding: 0 14px;
        border-radius: 999px;
        border: 1px solid rgba(255, 255, 255, 0.25);
        background: #121212c9;
        color: #f4f4f8;
        font-size: 12px;
        font-weight: 700;
        backdrop-filter: blur(8px);
        -webkit-backdrop-filter: blur(8px);
    }

    html[data-ui-mode="mobile"] body[data-route="/play"][data-match-screen="game"] #game-surface[data-state="running"] #mobile-battle-back {
        display: none;
    }

    /* Left D-pad and right action buttons stay over the stage. */
    html[data-ui-mode="mobile"] #game-surface[data-state="running"] #mobile-battle-pad {
        --tap: clamp(44px, 13.5dvh, 54px);
        --ctap: clamp(48px, 15dvh, 60px);
        position: absolute;
        z-index: 20;
        inset: auto calc(10px + env(safe-area-inset-right)) calc(10px + env(safe-area-inset-bottom)) calc(10px + env(safe-area-inset-left));
        display: grid;
        grid-template-columns: repeat(3, var(--tap)) minmax(0, 1fr) repeat(2, var(--ctap));
        grid-template-rows: repeat(3, var(--ctap));
        grid-template-areas:
            ".    up   .     . dash   jump"
            "left .    right . skill  attack"
            ".    down .     . assist super";
        gap: 6px;
        align-items: center;
        justify-items: center;
        pointer-events: none;
        user-select: none;
        -webkit-user-select: none;
        -webkit-touch-callout: none;
    }

    html[data-ui-mode="mobile"] #mobile-battle-pad button {
        pointer-events: auto;
        touch-action: none;
        user-select: none;
        -webkit-user-select: none;
        -webkit-touch-callout: none;
        -webkit-tap-highlight-color: transparent;
        width: 100%;
        height: 100%;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 2px;
        border: 1.5px solid rgba(255, 255, 255, 0.42);
        border-radius: 50%;
        background: rgba(18, 20, 28, 0.64);
        color: #ffffff;
        font: 700 15px/1 Inter, system-ui, sans-serif;
        padding: 0;
        box-shadow: 0 4px 14px rgba(0, 0, 0, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.16);
        transition: transform 0.06s ease, background-color 0.06s ease, border-color 0.06s ease;
    }

    html[data-ui-mode="mobile"] #mobile-battle-pad button b {
        font-size: clamp(14px, 3.8dvh, 18px);
        line-height: 1;
        font-weight: 800;
    }

    html[data-ui-mode="mobile"] #mobile-battle-pad button span {
        font-size: clamp(8.5px, 2.2dvh, 10px);
        line-height: 1;
        font-weight: 700;
        letter-spacing: 0.02em;
        opacity: 0.92;
        text-transform: uppercase;
    }

    /* One touch zone behind the four directions: sliding a thumb across it
       changes direction without lifting, and its corners press diagonals. */
    html[data-ui-mode="mobile"] #mobile-battle-pad [data-touch-zone="dpad"] {
        grid-column: 1 / 4;
        grid-row: 1 / 4;
        width: 100%;
        height: 100%;
        border-radius: 50%;
        pointer-events: auto;
        touch-action: none;
        background: radial-gradient(circle, rgba(255, 255, 255, 0.07) 0 34%, rgba(18, 20, 28, 0.32) 35% 70%, transparent 71%);
        box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.1);
    }

    /* D-pad rounded directional pills */
    html[data-ui-mode="mobile"] #mobile-battle-pad [data-touch-dpad="true"] {
        border-radius: 14px;
        height: var(--tap);
        background: #222c;
        font-size: 16px;
    }

    /* Combat Arc Positioning & Color Cues */
    html[data-ui-mode="mobile"] #mobile-battle-pad [data-touch-action="up"] { grid-area: up; }
    html[data-ui-mode="mobile"] #mobile-battle-pad [data-touch-action="down"] { grid-area: down; }
    html[data-ui-mode="mobile"] #mobile-battle-pad [data-touch-action="left"] { grid-area: left; }
    html[data-ui-mode="mobile"] #mobile-battle-pad [data-touch-action="right"] { grid-area: right; }

    /* Hero Attack button — largest, primary gold ring */
    html[data-ui-mode="mobile"] #mobile-battle-pad [data-touch-action="attack"] {
        grid-area: attack;
        width: var(--ctap);
        height: var(--ctap);
        border-color: rgba(255, 209, 107, 0.85);
        background: rgba(58, 42, 16, 0.72);
        color: #ffe8a8;
    }

    /* Jump button */
    html[data-ui-mode="mobile"] #mobile-battle-pad [data-touch-action="jump"] {
        grid-area: jump;
        width: var(--ctap);
        height: var(--ctap);
        border-color: rgba(147, 197, 253, 0.72);
        background: rgba(22, 34, 54, 0.68);
    }

    /* Dash button */
    html[data-ui-mode="mobile"] #mobile-battle-pad [data-touch-action="dash"] {
        grid-area: dash;
        width: var(--ctap);
        height: var(--ctap);
        border-color: rgba(167, 243, 208, 0.65);
        background: rgba(18, 42, 38, 0.68);
    }

    /* Skill button */
    html[data-ui-mode="mobile"] #mobile-battle-pad [data-touch-action="skill"] {
        grid-area: skill;
        width: var(--ctap);
        height: var(--ctap);
        border-color: rgba(253, 186, 116, 0.78);
        background: rgba(52, 30, 18, 0.7);
    }

    /* Super / Ultimate button */
    html[data-ui-mode="mobile"] #mobile-battle-pad [data-touch-action="super"] {
        grid-area: super;
        width: var(--ctap);
        height: var(--ctap);
        border-color: rgba(251, 113, 133, 0.85);
        background: rgba(68, 18, 28, 0.76);
        color: #ffd0d8;
    }

    /* Assist button */
    html[data-ui-mode="mobile"] #mobile-battle-pad [data-touch-action="assist"] {
        grid-area: assist;
        width: var(--ctap);
        height: var(--ctap);
        border-color: rgba(83, 223, 241, 0.78);
        background: rgba(16, 44, 52, 0.72);
        color: #c8f7ff;
    }

    /* Keep Pause clear of the arena when the device has a side cutout. */
    html[data-ui-mode="mobile"] #mobile-battle-pad [data-touch-action="pause"] {
        position: fixed;
        top: calc(6px + env(safe-area-inset-top));
        right: calc(10px + env(safe-area-inset-right));
        width: 44px;
        height: 44px;
        border-radius: 999px;
        border: 1px solid rgba(255, 255, 255, 0.25);
        background: #121212c9;
        font-size: 13px;
        backdrop-filter: blur(8px);
        -webkit-backdrop-filter: blur(8px);
    }

    /* Instant Press Feedback */
    html[data-ui-mode="mobile"] #mobile-battle-pad button.pressed,
    html[data-ui-mode="mobile"] #mobile-battle-pad button:active {
        background: #ffd16b !important;
        border-color: #fff3cf !important;
        color: #171108 !important;
        transform: scale(0.93);
    }
}

html[data-ui-mode="mobile"] #mobile-rotate {
    width: calc(100vw - 24px);
    max-width: 420px;
    border-radius: 18px;
    border-color: var(--m-border-strong);
    background: #16161d;
    padding: 20px;
}

html[data-ui-mode="mobile"] #mobile-rotate button {
    width: 100%;
    min-height: 46px;
    border-radius: 12px;
}

/* Zoom lock for a phone match (see touch-pad.mjs). */
html[data-zoom-locked],
html[data-zoom-locked] body {
    touch-action: none;
    overscroll-behavior: none;
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}
