/* Launcher and player UI. The shared site owns buttons, ranges, dialogs and fullscreen. */

:root {
    --emulator-bg: #120837;
}

body > main > section:not(:has(.fullscreen__bg)) > [data-fullscreen-module],
.game-emulator-player > .game-emulator-player__stage > .game-emulator-player__mount > .ejs_game {
    background-color: var(--emulator-bg);
}

body.fullscreen [data-fullscreen-module] {
    justify-content: center;
}

[data-game-feedback][hidden],
[data-game-library-mode="landing"] [data-collection-browser-trigger][hidden],
[data-game-player-fallback][hidden],
[data-game-module] [hidden] {
    display: none !important;
}

/* Queued uploads stay visible on mobile without changing ordinary status rules. */
[data-game-library-dialog] .alternating-table__value > .alternating-table__status[data-game-upload-state] {
    display: flex;
}

[data-game-library-dialog][data-game-uploads-active] [data-item-title] {
    color: var(--clr-muted);
    cursor: default;
}

[data-game-library-dialog] [data-browser-row="item"]:not([data-browser-action="open-item"]) {
    cursor: default;
}

[data-game-library-dialog] [data-browser-row="item"] .dropdown__btn {
    cursor: pointer;
}

[data-game-feedback] {
    margin-block-start: 1rem;
}

[data-game-player-fallback] {
    display: inline-block;
    margin-block-start: .75rem;
}

.game-emulator-player {
    flex: 1;
    position: relative;
    display: flex;
    flex-direction: column;
    width: 100%;
    min-height: min(26rem, 80svh);
    min-width: 0;
    overflow: hidden;
    background: var(--emulator-bg);
    isolation: isolate;
}

.game-emulator-player__stage {
    position: relative;
    flex: 1 1 auto;
    width: 100%;
    min-height: 0;
    min-width: 0;
    aspect-ratio: 3 / 2;
}

.game-emulator-player__mount {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
}

.game-emulator-player__panel {
    position: absolute;
    inset: 0;
    z-index: 2;
    display: grid;
    place-content: center;
    justify-items: center;
    background: var(--emulator-bg);
    text-align: center;
}

.game-emulator-player__panel > * {
    max-width: 38rem;
    margin: 0;
}

.game-emulator-player__panel > .game-emulator-player__message {
    font-size: var(--fs-scalable-600);
    font-weight: var(--fw-500);
}

.game-emulator-player__actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 1rem;
}

.game-emulator-player__mount.ejs_parent {
    position: absolute;
    width: 100%;
    height: 100%;
}

[data-game-module] [data-fullscreen-body] {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

[data-game-notes] .module-notes__btn {
    color: var(--clr-secondary);
    cursor: pointer;
}

[data-game-module] .app-module-controls button:disabled,
[data-game-module] .app-module-controls input:disabled {
    cursor: default;
    color: var(--clr-muted);
}

.game-emulator-player__panel {
    padding: 1.5rem;
    overflow: auto;
}

/* Keep the vendor's DOM and methods; replace its visible toolbar/start screen.
   Do not hide its virtual gamepad, error nodes, or all popup content globally. */
[data-game-mount] .ejs_menu_bar,
[data-game-mount] .ejs_context_menu,
[data-game-mount] .ejs_virtualGamepad_open,
[data-game-mount] .ejs_start_button {
    display: none !important;
}

/* The app owns visibility, including the vendor's delayed resize measurements. */
[data-game-mount] .ejs_virtualGamepad_parent[data-game-touch-controls="enabled"] {
    display: block !important;
    opacity: 1 !important;
}

[data-game-mount] .ejs_virtualGamepad_parent[data-game-touch-controls="disabled"] {
    display: none !important;
}

body.fullscreen main:has([data-game-module]) {
    height: var(--app-height, 100svh);
    min-height: 0;
}

body.fullscreen [data-game-module] .game-emulator-player {
    flex: 1 1 0;
    min-height: 0;
}

body.fullscreen [data-game-module] .game-emulator-player__stage {
    flex: 1 1 auto;
    aspect-ratio: auto;
}

body.fullscreen [data-game-module] [data-fullscreen-body] > .scroll-module {
    flex: 0 0 auto;
    width: 100%;
}

/* The shared fullscreen controller supplies a generic content presentation.
   Keep the emulator's focused layout scoped to this app, including its CSS
   fallback when the browser does not offer element fullscreen. */
html:has(body.fullscreen[data-fullscreen-presentation="content"] [data-game-player][aria-busy="true"]) {
    --clr-meta-theme-fullscreen-content: var(--emulator-bg);
}

body.fullscreen[data-fullscreen-presentation="content"] [data-game-module] {
    padding: 0;
}

body.fullscreen[data-fullscreen-presentation="content"] [data-game-module] > [data-fullscreen-header],
body.fullscreen[data-fullscreen-presentation="content"] [data-game-module] > [data-fullscreen-footer],
body.fullscreen[data-fullscreen-presentation="content"] [data-game-module] [data-fullscreen-body] > .scroll-module {
    display: none;
}

body.fullscreen[data-fullscreen-presentation="content"] [data-game-player] {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    min-height: 0;
    max-width: none;
    max-height: none;
    margin: 0;
}

body.fullscreen[data-fullscreen-presentation="content"] [data-game-player] > [data-toggle-fullscreen] {
    z-index: 10000;
}

/* Match the existing Safari top strip with a small bottom sampling surface.
   It exists only during opted-in Game only fullscreen and never takes input. */
[data-game-player] > [data-fullscreen-edge-color="bottom"] {
    display: none;
}

body.fullscreen[data-fullscreen-presentation="content"] [data-game-player] > [data-fullscreen-edge-color="bottom"] {
    display: block;
    position: fixed;
    inset: auto 0 0;
    height: 12px;
    background-color: var(--clr-meta-theme-fullscreen-content);
    pointer-events: none;
    z-index: 9999;
}

/* Reserve the strip's space during gameplay so it cannot cover the canvas or
   touch controls. The loading panel keeps its existing size and layout. */
body.fullscreen[data-fullscreen-presentation="content"] [data-game-player]:has(> [data-fullscreen-edge-color="bottom"]):has([data-game-panel][hidden]) {
    padding-bottom: 12px;
}

/* Keep ready gameplay below Safari's top colour strip. Match the shared
   strip's browser-only visibility and reserve space only when it exists. */
@media (display-mode: browser) {
    body.fullscreen[data-fullscreen-presentation="content"]:has(> .browser-top-color) [data-game-player]:has([data-game-panel][hidden]) {
        padding-top: 12px;
    }
}

/* Ready gameplay uses the content palette around the canvas. The blue loading
   and failure panels keep their original background and styling. */
body.fullscreen[data-fullscreen-presentation="content"] [data-game-player]:has([data-game-panel][hidden]),
body.fullscreen[data-fullscreen-presentation="content"] [data-game-player]:has([data-game-panel][hidden]) .ejs_game {
    background-color: var(--clr-meta-theme-fullscreen-content);
}

/* In the installed PWA, keep Game only below the iOS status bar. Match the
   loading panel until it is hidden, then use black around ready gameplay. */
@media (display-mode: standalone) {
    html:has(> body.fullscreen[data-fullscreen-presentation="content"] [data-game-player]) {
        --clr-meta-theme-fullscreen-content: var(--emulator-bg);
    }

    html:has(> body.fullscreen[data-fullscreen-presentation="content"] [data-game-player] [data-game-panel][hidden]) {
        --clr-meta-theme-fullscreen-content: #000;
    }

    body.fullscreen[data-fullscreen-presentation="content"] [data-game-player] {
        padding-top: env(safe-area-inset-top, 0px);
        background-color: var(--clr-meta-theme-fullscreen-content);
    }
}
