.game-surface { isolation: isolate; overflow: hidden; overscroll-behavior: contain; }
#mobile-battle-pad, #mobile-battle-back { display: none; }
#mobile-rotate {
    width: min(340px, calc(100% - 32px));
    color: var(--text);
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 20px;
}
#mobile-rotate::backdrop { background: #000b; }
#mobile-rotate h2 { margin: 0 0 8px; }
#mobile-rotate p { margin: 0 0 16px; color: var(--muted); }
#mobile-rotate button { min-height: 44px; }
@media (pointer: coarse) and (max-width: 1024px) and (max-height: 1024px) and (orientation: landscape) {
    body[data-route="/play"][data-match-screen="game"] #game-surface:is([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: #000;
    }
    body[data-route="/play"][data-match-screen="game"] #game-surface:is([data-state="running"], [data-state="paused"]) #arena {
        flex: 1;
        height: 100%;
        min-height: 0;
        aspect-ratio: auto;
    }
    body[data-route="/play"][data-match-screen="game"] #game-surface:is([data-state="running"], [data-state="paused"]) :is(.game-toolbar, .game-statusbar, #input-hud) { display: none; }
    body[data-route="/play"][data-match-screen="game"] #game-surface:is([data-state="running"], [data-state="paused"]) #mobile-battle-back {
        display: inline-flex;
        position: absolute;
        z-index: 30;
        inset-block-start: max(5px, env(safe-area-inset-top));
        left: 50%;
        transform: translateX(-50%);
        min-height: 44px;
        align-items: center;
    }
    #game-surface[data-state="running"] #mobile-battle-pad {
        --tap: clamp(44px, 12dvh, 58px);
        position: absolute;
        z-index: 8;
        inset: auto max(8px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
        display: grid;
        grid-template-columns: repeat(3, var(--tap)) minmax(0, 1fr) repeat(3, var(--tap));
        grid-template-rows: repeat(3, var(--tap));
        grid-template-areas: ". up . . . skill ." "left . right . dash . attack" ". down . pause . jump .";
        gap: 3px;
        pointer-events: none;
        user-select: none;
        -webkit-user-select: none;
        -webkit-touch-callout: none;
    }
    #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;
        border: 1px solid #ffffff88;
        border-radius: 50%;
        background: #1c1d24a8;
        color: #fff;
        font: 700 16px/1 system-ui, sans-serif;
        padding: 0;
    }
    #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; }
    #mobile-battle-pad button.pressed, #mobile-battle-pad button:active { background: #ffe0a1; color: #20180b; }
    #mobile-battle-pad [data-touch-action="up"] { grid-area: up; }
    #mobile-battle-pad [data-touch-action="down"] { grid-area: down; }
    #mobile-battle-pad [data-touch-action="left"] { grid-area: left; }
    #mobile-battle-pad [data-touch-action="right"] { grid-area: right; }
    #mobile-battle-pad [data-touch-action="attack"] { grid-area: attack; }
    #mobile-battle-pad [data-touch-action="jump"] { grid-area: jump; }
    #mobile-battle-pad [data-touch-action="dash"] { grid-area: dash; }
    #mobile-battle-pad [data-touch-action="skill"] { grid-area: skill; }
    #mobile-battle-pad [data-touch-action="pause"] { grid-area: pause; width: var(--tap); justify-self: center; }
}
.series-filters, .directory-forms, .panel-scroll { overscroll-behavior: contain; }
.directory-sidebar { min-width: 0; }
.directory-grid { align-items: stretch; grid-auto-rows: 1fr; gap: 16px; }
.directory-grid.is-grouped { align-items: start; grid-auto-rows: auto; }
.directory-card { position: relative; border-radius: 8px; border-color: #3a3a3a; box-shadow: 0 3px 14px #0004; }
.directory-portrait { flex: 0 0 auto; height: 168px; padding: 24px; background: linear-gradient(155deg, #242424, #141414); }
.directory-card-copy { padding: 13px; }
.directory-grid.is-grouped .directory-card-copy { min-height: 132px; }
.directory-card h3 { min-height: 4.5em; margin: 0; color: #f5f5f5; font-size: 14px; line-height: 1.4; }
.directory-card > .directory-note { position: absolute; top: 8px; right: 8px; margin: 0; padding: 4px 8px; background: #161616; border: 1px solid #d8b887; border-radius: 4px; }
.directory-forms { margin-top: 12px; color: #dcdcdc; }
.directory-forms summary { cursor: pointer; padding: 8px 0; font-size: 12px; color: #ffd09a; }
.directory-form-row { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-top: 1px solid #ffffff10; font-size: 11px; }
.directory-form-portrait { width: 42px; height: 42px; object-fit: contain; image-rendering: pixelated; flex: 0 0 auto; }
.roster-tools .roster-view { min-width: 160px; }

.touch-layout-editor { display: grid; gap: 12px; }
.touch-layout-editor :is(h2, p) { margin: 0; }
.touch-layout-editor p { color: var(--muted); }
.touch-layout-editor .v2-tabs { margin: 0; }
.touch-layout-editor :is(button, select) { min-height: 44px; }
.touch-layout-preview {
    position: relative;
    width: min(100%, 520px);
    aspect-ratio: 16 / 9;
    container-type: inline-size;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: #171717;
    overflow: hidden;
}
.touch-layout-preview-control {
    --touch-size: clamp(36px, calc(14cqw * var(--touch-scale, 1)), 60px);
    z-index: 1;
    width: var(--touch-size);
    height: var(--touch-size);
    min-height: 0 !important;
    border: 1px solid #ffffff75;
    border-radius: 50%;
    padding: 2px;
    background: #323232;
    color: #fff;
    opacity: var(--touch-opacity, 1);
    font: 700 clamp(9px, 2.6cqw, 13px)/1.1 system-ui, sans-serif;
    touch-action: none;
    user-select: none;
    cursor: grab;
}
.touch-layout-preview-control[data-touch-target="dpad"] {
    --touch-size: clamp(55px, calc(27cqw * var(--touch-scale, 1)), 130px);
    border-radius: 28%;
}
.touch-layout-preview[data-touch-direction="joystick"] [data-touch-target="dpad"] { border-radius: 50%; }
.touch-layout-preview-control:active { z-index: 2; cursor: grabbing; }
.touch-layout-preview-control:focus-visible { z-index: 2; outline: 2px solid #ffd16b; }
.touch-layout-fields {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 176px), 1fr));
    align-items: end;
    gap: 10px 16px;
}
.touch-layout-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: 44px;
}
.touch-layout-editor input[type="range"] { min-width: 0; min-height: 44px; accent-color: #ffd16b; }
.touch-layout-preview-control,
#mobile-battle-pad[data-touch-layout] > [data-touch-index],
#mobile-battle-pad[data-touch-layout] > .touch-layout-dpad {
    position: absolute;
    left: clamp(calc(var(--touch-size) / 2), var(--touch-x), calc(100% - var(--touch-size) / 2));
    top: clamp(calc(var(--touch-size) / 2), var(--touch-y), calc(100% - var(--touch-size) / 2));
    translate: -50% -50%;
}
@media (orientation: landscape) {
    html[data-ui-mode="mobile"] #game-surface[data-state="running"] #mobile-battle-pad[data-touch-layout] {
        --touch-action-size: clamp(44px, calc(clamp(44px, 14dvh, 56px) * var(--touch-scale)), clamp(44px, 17.5dvh, 76px));
        --touch-dpad-size: clamp(136px, calc(42dvh * var(--touch-scale)), clamp(136px, 55dvh, 210px));
        display: block;
        inset: max(60px, calc(14dvh + env(safe-area-inset-top)))
            calc(10px + env(safe-area-inset-right)) calc(10px + env(safe-area-inset-bottom)) calc(10px + env(safe-area-inset-left));
    }
    html[data-ui-mode="mobile"] #mobile-battle-pad[data-touch-layout] > [data-touch-index] {
        --touch-size: var(--touch-action-size);
        width: var(--touch-size);
        height: var(--touch-size);
        opacity: var(--touch-opacity);
    }
    html[data-ui-mode="mobile"] #mobile-battle-pad[data-touch-layout] > .touch-layout-dpad {
        --touch-size: var(--touch-dpad-size);
        width: var(--touch-size);
        height: var(--touch-size);
        display: grid;
        grid-template:
            ". up ." minmax(0, 1fr)
            "left . right" minmax(0, 1fr)
            ". down ." minmax(0, 1fr) / repeat(3, minmax(0, 1fr));
        gap: 2px;
        opacity: var(--touch-opacity);
    }
    html[data-ui-mode="mobile"] #mobile-battle-pad[data-touch-layout] .touch-layout-dpad button {
        position: relative;
        width: 100%;
        height: 100%;
    }
    #mobile-battle-pad[data-touch-layout][data-touch-direction="joystick"] [data-touch-dpad] { display: none !important; }
    #mobile-battle-pad[data-touch-layout][data-touch-direction="joystick"] [data-touch-zone="dpad"] {
        position: relative;
        background: #151515b0;
        box-shadow: inset 0 0 0 2px #ffffff66;
    }
    #mobile-battle-pad[data-touch-layout][data-touch-direction="joystick"] [data-touch-zone="dpad"]::after {
        content: "";
        position: absolute;
        width: 38%;
        height: 38%;
        top: 50%;
        left: 50%;
        border-radius: 50%;
        background: #595959;
        box-shadow: inset 0 0 0 1px #ffffff88;
        transform: translate(calc(-50% + var(--stick-x, 0px)), calc(-50% + var(--stick-y, 0px)));
        pointer-events: none;
    }
}
@media (prefers-reduced-motion: no-preference) {
    .directory-card { animation: roster-reveal .14s ease-out; }
    @keyframes roster-reveal { from { opacity: .35; } to { opacity: 1; } }
}
@media (max-width: 700px) { .directory-portrait { height: 140px; padding: 18px; } }

.play-session-card { min-width: 0; }
.play-session-card .session-row { min-width: 0; align-items: flex-start !important; }
.play-session-card .session-label { flex: 0 0 auto; }
.play-session-card .session-val { flex: 1 1 0; min-width: 0; white-space: normal; overflow-wrap: anywhere; }
body.user-mode .play-session-card .session-row.dev-only { display: none !important; }
