/* The world fills the monitor. Reading surfaces and HUD remain in a central
   16:9 safe area: extra horizontal pixels reveal terrain, not larger letters. */
:root {
    --ui-safe-width: min(100vw, 177.77777778vh);
    --ui-safe-left: max(0px, calc((100vw - 177.77777778vh) / 2));
    --ui-vw: min(1vw, 1.7777777778vh);
}

@media (aspect-ratio > 16/9) {
    /* A local containing block keeps fixed controls aligned with the artwork.
       The opaque outer wash covers the rest of the display behind the menus. */
    :is([data-menu-screen="options"], [data-menu-screen="modes"], [data-menu-screen="worlds"],
        [data-menu-screen="difficulty"], [data-menu-screen="collection"], [data-menu-screen="progression"],
        [data-menu-screen="mortis"], [data-menu-screen="tome"], [data-menu-screen="packs"],
        [data-menu-screen="roster"], [data-menu-screen="achievements"], [data-menu-screen="leaderboard"],
        [data-menu-screen="briefing"], [data-menu-screen="coop"], [data-menu-screen="credits"],
        [data-menu-screen="hub"]) {
        left: var(--ui-safe-left) !important;
        right: auto !important;
        width: var(--ui-safe-width) !important;
        max-width: var(--ui-safe-width) !important;
        transform: translateZ(0) !important;
        box-shadow: 0 0 0 100vmax #09070d;
    }

    body.gameplay-hud #gameModeContainer { left: calc(var(--ui-safe-left) + var(--ui-vw)) !important; }
    body.gameplay-hud #notificationContainer { left: calc(var(--ui-safe-left) + 10 * var(--hud-pixel)) !important; }
    body.gameplay-hud #warningDisplay { left: var(--ui-safe-left) !important; right: var(--ui-safe-left) !important; }
    body.gameplay-hud .boss-hud-value { font-size: max(14px, var(--ui-vw)) !important; }
    body.gameplay-hud .xp-bar-player-hub .xp-bar-frame {
        width: calc((0.9 * var(--ui-safe-width) / var(--player-count, 1)) - 8vh);
    }
    #bossHPBarContainer { width: calc(50 * var(--ui-vw)) !important; }
    :is(#returnMeterContainer, #bloomingMeterContainer) { width: calc(50 * var(--ui-vw)) !important; }
    /* Temporary bars share the same player segments as XP and spell cards. */
    body.gameplay-hud :is(.chest-reel-container, .rune-pickup-container, .ritual-bar-container, .sandtomb-bar-container, .channel-bar-container)[data-total-players] {
        --hud-segment-index: 0;
        --hud-segment-width: 1;
        --hud-segment-inset: .1;
        left: calc(var(--ui-safe-left) + (var(--hud-segment-index) * var(--hud-segment-width) + var(--hud-segment-inset)) * var(--ui-safe-width));
        width: calc((var(--hud-segment-width) - 2 * var(--hud-segment-inset)) * var(--ui-safe-width));
    }
    body.gameplay-hud :is(.ritual-bar-container, .channel-bar-container)[data-total-players="1"] { --hud-segment-inset: .15; }
    body.gameplay-hud .sandtomb-bar-container[data-total-players="1"] { --hud-segment-inset: .25; }
    body.gameplay-hud :is(.chest-reel-container, .rune-pickup-container, .ritual-bar-container, .sandtomb-bar-container, .channel-bar-container)[data-total-players="2"] {
        --hud-segment-width: .5; --hud-segment-inset: .02;
    }
    body.gameplay-hud :is(.chest-reel-container, .rune-pickup-container, .ritual-bar-container, .sandtomb-bar-container, .channel-bar-container)[data-total-players="3"] {
        --hud-segment-width: .3333333333; --hud-segment-inset: .01;
    }
    body.gameplay-hud :is(.chest-reel-container, .rune-pickup-container, .ritual-bar-container, .sandtomb-bar-container, .channel-bar-container)[data-total-players="4"] {
        --hud-segment-width: .25; --hud-segment-inset: .01;
    }
    body.gameplay-hud :is(.chest-reel-container, .rune-pickup-container, .ritual-bar-container, .sandtomb-bar-container, .channel-bar-container)[data-segment-index="1"] { --hud-segment-index: 1; }
    body.gameplay-hud :is(.chest-reel-container, .rune-pickup-container, .ritual-bar-container, .sandtomb-bar-container, .channel-bar-container)[data-segment-index="2"] { --hud-segment-index: 2; }
    body.gameplay-hud :is(.chest-reel-container, .rune-pickup-container, .ritual-bar-container, .sandtomb-bar-container, .channel-bar-container)[data-segment-index="3"] { --hud-segment-index: 3; }
    #upgradeSelectionContainer .upgrade-options { max-width: var(--ui-safe-width); margin-inline: auto; }
    body:not(:has(#ecsGameFrame)) .souls-display-independent,
    body:has([data-menu-screen].active) .souls-display-independent { right: calc(var(--ui-safe-left) + 3 * var(--ui-vw)); }
    body:has(#ecsGameFrame):not(:has([data-menu-screen].active)) .souls-display-independent .souls-label { font-size: calc(1.7 * var(--ui-vw)); }
    body:has(#ecsGameFrame):not(:has([data-menu-screen].active)) .souls-display-independent #souls { font-size: var(--hud-wallet-value-size, calc(2.6 * var(--ui-vw))); }
}

/* A 2560x1080 monitor has the same vertical room as 1920x1080. */
@media (aspect-ratio > 16/9) and (max-height: 1080px) {
    body #mouseJoystick { --joystick-pixel: 2px; }
    body.gameplay-hud :is(.spell-bar-container, .player-spell-bar-container) {
        --spell-card-width: 68px;
        --spell-card-height: 92px;
    }
    #bossHPBarContainer { max-width: 650px !important; }
    :root { --ui-scale: 1; }
}
@media (aspect-ratio > 16/9) and (max-height: 800px) {
    body.gameplay-hud :is(.spell-bar-container, .player-spell-bar-container) {
        --spell-card-width: 58px;
        --spell-card-height: 78px;
    }
    #bossHPBarContainer { max-width: 500px !important; }
}
