/* Mobile BLS focus (body.mobile-bls-focus-enabled).
   Full-width animation; top-corner mini PiPs (portrait) or left-stack (landscape);
   audio + BLE on phone; USB tapper hidden. */

/* iOS Safari pull-to-refresh reloads the page on a hard downward swipe — disable
   during client BLS so accidental swipes do not interrupt a set. */
html:has(body.client.mobile-bls-active),
html:has(body.client .video-section.fullscreen) {
    overscroll-behavior-y: none;
}

body.client.mobile-bls-active,
body.client:has(.video-section.fullscreen) {
    overscroll-behavior-y: none;
}

body.mobile-bls-focus-enabled.client.mobile-bls-narrow.mobile-bls-active .video-section:not(.fullscreen) .video-container:first-child,
body.mobile-bls-focus-enabled.client.mobile-bls-narrow.mobile-bls-active .video-section:not(.fullscreen) .video-container:last-child {
    top: calc(96px + env(safe-area-inset-top, 0px)) !important;
    bottom: auto !important;
    width: 108px !important;
    height: 81px !important;
    min-width: 96px !important;
    min-height: 72px !important;
    max-width: 120px !important;
    max-height: 90px !important;
    border-width: 1px !important;
    border-radius: 6px !important;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.45) !important;
}

body.mobile-bls-focus-enabled.client.mobile-bls-narrow.mobile-bls-active .video-section:not(.fullscreen) .video-container:first-child {
    left: max(8px, env(safe-area-inset-left, 0px)) !important;
    right: auto !important;
}

body.mobile-bls-focus-enabled.client.mobile-bls-narrow.mobile-bls-active .video-section:not(.fullscreen) .video-container:last-child {
    right: max(8px, env(safe-area-inset-right, 0px)) !important;
    left: auto !important;
}

/* Full animation band between compact top PiPs and bottom bar (portrait) */
body.mobile-bls-focus-enabled.client.mobile-bls-narrow.mobile-bls-active .main-content {
    top: calc(88px + env(safe-area-inset-top, 0px)) !important;
    bottom: calc(64px + env(safe-area-inset-bottom, 0px)) !important;
}

body.mobile-bls-focus-enabled.client.mobile-bls-narrow.mobile-bls-active .emdr-canvas-container {
    max-height: none !important;
}

/* Undo legacy 768px squeeze on client BLS layout (sandbox experiment) */
@media (max-width: 768px) {
    body.mobile-bls-focus-enabled.client .video-section:not(.fullscreen) {
        height: auto !important;
        flex-direction: row !important;
        top: 100px !important;
        bottom: 0 !important;
    }

    body.mobile-bls-focus-enabled.client.mobile-bls-narrow.mobile-bls-active:not(.mobile-bls-landscape) .main-content {
        top: calc(88px + env(safe-area-inset-top, 0px)) !important;
    }

    /* Undo legacy 768px header offset during landscape BLS (header hidden above). */
    @media (orientation: landscape) and (max-height: 480px) {
        body.mobile-bls-focus-enabled.client.mobile-bls-narrow.mobile-bls-active .video-section:not(.fullscreen) {
            top: env(safe-area-inset-top, 0px) !important;
        }
    }
}

/* Phone bottom bar: show BLS audio + BLE tapper; hide USB (not supported on most phones) */
@media (max-width: 480px) {
    body.mobile-bls-focus-enabled.client .bottom-video-controls .bls-control-group {
        display: inline-flex !important;
        visibility: visible !important;
        pointer-events: auto !important;
        position: relative !important;
        width: auto !important;
        height: auto !important;
        margin: 0 !important;
        padding: 0 !important;
        overflow: visible !important;
        clip: auto !important;
        flex-wrap: nowrap !important;
        gap: 4px !important;
    }

    body.mobile-bls-focus-enabled.client .bottom-video-controls #bottomTapBLS {
        display: none !important;
    }

    body.mobile-bls-focus-enabled.client .bottom-video-controls #bottomBallAudio,
    body.mobile-bls-focus-enabled.client .bottom-video-controls #bottomTapBLE,
    body.mobile-bls-focus-enabled.client .bottom-video-controls #bottomTapperSettings {
        display: inline-flex !important;
    }

    body.mobile-bls-focus-enabled.client .bottom-video-controls .bls-group-btn .bottom-btn-label {
        font-size: 9px !important;
    }
}

/* Coach banner — one compact tip above the bottom bar; auto-fades via JS */
.mobile-bls-focus-banners {
    position: fixed;
    left: max(8px, env(safe-area-inset-left, 0px));
    right: max(8px, env(safe-area-inset-right, 0px));
    top: auto;
    bottom: calc(76px + env(safe-area-inset-bottom, 0px));
    z-index: 1135;
    pointer-events: none;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

body:not(.client) .mobile-bls-focus-banners,
body:not(.mobile-bls-active) .mobile-bls-focus-banners {
    display: none !important;
}

.mobile-bls-focus-banner {
    pointer-events: auto;
    background: rgba(12, 18, 30, 0.88);
    color: #f4f7fb;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 10px;
    padding: 8px 10px;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.28);
    font-size: 12px;
    line-height: 1.3;
    opacity: 1;
    transition: opacity 0.4s ease;
}

.mobile-bls-focus-banner--fading {
    opacity: 0;
    pointer-events: none;
}

.mobile-bls-focus-banner__text {
    margin: 0 0 6px;
}

.mobile-bls-focus-banner__actions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: center;
}

.mobile-bls-focus-banner__primary {
    background: #28a745;
    color: #fff;
    border: none;
    border-radius: 8px;
    padding: 5px 10px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
}

.mobile-bls-focus-banner__dismiss {
    background: transparent;
    color: #cbd5e0;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 8px;
    padding: 4px 8px;
    font-size: 11px;
    cursor: pointer;
}

.mobile-bls-focus-banner[hidden] {
    display: none !important;
}

/* Client BLS: solid bar briefly, then dim; brighten on touch */
body.mobile-bls-focus-enabled.client.mobile-bls-active .bottom-video-controls {
    opacity: 0.92 !important;
    background: rgba(0, 0, 0, 0.82) !important;
    border-color: rgba(255, 255, 255, 0.18) !important;
    transition: opacity 0.45s ease, background 0.45s ease, box-shadow 0.45s ease !important;
}

body.mobile-bls-focus-enabled.client.mobile-bls-active.mobile-bls-bar-dimmed .bottom-video-controls {
    opacity: 0.28 !important;
    background: rgba(0, 0, 0, 0.45) !important;
    box-shadow: none !important;
}

body.mobile-bls-focus-enabled.client.mobile-bls-active.mobile-bls-bar-dimmed .bottom-video-controls:focus-within,
body.mobile-bls-focus-enabled.client.mobile-bls-active .bottom-video-controls:active {
    opacity: 0.92 !important;
    background: rgba(0, 0, 0, 0.82) !important;
}

/*
 * Landscape phone: immersive ball band — no header, full-height canvas;
 * PiPs stay bottom corners above slim overlay bar (see mobile-bls-focus.js).
 */
@media (orientation: landscape) and (max-height: 480px) {
    body.mobile-bls-focus-enabled.client.mobile-bls-narrow.mobile-bls-active {
        --client-bls-anim-top: env(safe-area-inset-top, 0px);
        --client-bls-anim-bottom: calc(44px + env(safe-area-inset-bottom, 0px));
    }

    body.mobile-bls-focus-enabled.client.mobile-bls-narrow.mobile-bls-active:not(:has(.video-section.fullscreen)) .emdr-header,
    body.mobile-bls-focus-enabled.client.mobile-bls-narrow.mobile-bls-active .video-section:not(.fullscreen) ~ .emdr-header {
        display: none !important;
        visibility: hidden !important;
        opacity: 0 !important;
        pointer-events: none !important;
        height: 0 !important;
        overflow: hidden !important;
    }

    body.mobile-bls-focus-enabled.client.mobile-bls-narrow.mobile-bls-active .main-content {
        top: env(safe-area-inset-top, 0px) !important;
        bottom: calc(44px + env(safe-area-inset-bottom, 0px)) !important;
        left: env(safe-area-inset-left, 0px) !important;
        right: env(safe-area-inset-right, 0px) !important;
        flex-direction: column !important;
        align-items: stretch !important;
        justify-content: flex-start !important;
    }

    body.mobile-bls-focus-enabled.client.mobile-bls-narrow.mobile-bls-active .video-section:not(.fullscreen) {
        top: env(safe-area-inset-top, 0px) !important;
        bottom: env(safe-area-inset-bottom, 0px) !important;
        height: auto !important;
    }

    body.mobile-bls-focus-enabled.client.mobile-bls-narrow.mobile-bls-active .emdr-canvas-container {
        height: 100% !important;
        min-height: 0 !important;
        max-height: none !important;
        flex: 1 1 auto !important;
        align-self: stretch !important;
    }

    body.mobile-bls-focus-enabled.client.mobile-bls-narrow.mobile-bls-active .video-section:not(.fullscreen) .video-container:first-child,
    body.mobile-bls-focus-enabled.client.mobile-bls-narrow.mobile-bls-active .video-section:not(.fullscreen) .video-container:last-child {
        top: auto !important;
        bottom: max(8px, env(safe-area-inset-bottom, 0px)) !important;
        width: 84px !important;
        height: 63px !important;
        min-width: 72px !important;
        min-height: 54px !important;
    }

    body.mobile-bls-focus-enabled.client.mobile-bls-narrow.mobile-bls-active .video-section:not(.fullscreen) .video-container:first-child {
        left: max(8px, env(safe-area-inset-left, 0px)) !important;
        right: auto !important;
    }

    body.mobile-bls-focus-enabled.client.mobile-bls-narrow.mobile-bls-active .video-section:not(.fullscreen) .video-container:last-child {
        left: auto !important;
        right: max(8px, env(safe-area-inset-right, 0px)) !important;
    }

    body.mobile-bls-focus-enabled.client.mobile-bls-narrow.mobile-bls-active .bottom-video-controls {
        padding: 2px 8px !important;
        gap: 4px !important;
        bottom: max(2px, env(safe-area-inset-bottom, 0px)) !important;
        border-radius: 14px !important;
        z-index: 2100 !important;
    }

    body.mobile-bls-focus-enabled.client.mobile-bls-narrow.mobile-bls-active .bottom-video-controls .bls-group-btn .bottom-btn-label {
        display: none !important;
    }

    body.mobile-bls-focus-enabled.client.mobile-bls-narrow.mobile-bls-active .bottom-video-controls .bottom-control-btn,
    body.mobile-bls-focus-enabled.client.mobile-bls-narrow.mobile-bls-active .bottom-video-controls .bls-group-btn {
        min-width: 36px !important;
        min-height: 36px !important;
        padding: 4px !important;
    }

    body.mobile-bls-focus-enabled.client.mobile-bls-landscape.mobile-bls-active .mobile-bls-focus-banners {
        bottom: calc(48px + env(safe-area-inset-bottom, 0px));
    }

    body.mobile-bls-focus-enabled.client.mobile-bls-landscape.mobile-bls-active .video-section:not(.fullscreen) .video-container .pip-menu-button,
    body.mobile-bls-focus-enabled.client.mobile-bls-landscape.mobile-bls-active .video-section:not(.fullscreen) .video-container .pip-dropdown-menu,
    body.mobile-bls-focus-enabled.client.mobile-bls-landscape.mobile-bls-active .video-section:not(.fullscreen) .video-container .pip-controls,
    body.mobile-bls-focus-enabled.client.mobile-bls-landscape.mobile-bls-active .video-section:not(.fullscreen) .video-container .pip-drag-indicator {
        display: none !important;
        visibility: hidden !important;
        pointer-events: none !important;
    }
}

/* Class hook (JS mobile-bls-landscape) — same as landscape @media above; wins over inline PiP geometry. */
body.mobile-bls-focus-enabled.client.mobile-bls-landscape.mobile-bls-active:not(:has(.video-section.fullscreen)) .emdr-header,
body.mobile-bls-focus-enabled.client.mobile-bls-landscape.mobile-bls-active .video-section:not(.fullscreen) ~ .emdr-header {
    display: none !important;
    visibility: hidden !important;
    opacity: 0 !important;
    pointer-events: none !important;
    height: 0 !important;
    overflow: hidden !important;
}

body.mobile-bls-focus-enabled.client.mobile-bls-landscape.mobile-bls-active {
    --client-bls-anim-top: env(safe-area-inset-top, 0px);
    --client-bls-anim-bottom: calc(44px + env(safe-area-inset-bottom, 0px));
}

body.mobile-bls-focus-enabled.client.mobile-bls-landscape.mobile-bls-active .main-content {
    top: env(safe-area-inset-top, 0px) !important;
    bottom: calc(44px + env(safe-area-inset-bottom, 0px)) !important;
    left: env(safe-area-inset-left, 0px) !important;
    right: env(safe-area-inset-right, 0px) !important;
    flex-direction: column !important;
    align-items: stretch !important;
    justify-content: flex-start !important;
    height: auto !important;
}

body.mobile-bls-focus-enabled.client.mobile-bls-landscape.mobile-bls-active .video-section:not(.fullscreen) {
    top: env(safe-area-inset-top, 0px) !important;
    bottom: env(safe-area-inset-bottom, 0px) !important;
    height: auto !important;
}

body.mobile-bls-focus-enabled.client.mobile-bls-landscape.mobile-bls-active .emdr-canvas-container {
    height: 100% !important;
    min-height: 0 !important;
    max-height: none !important;
    flex: 1 1 auto !important;
    align-self: stretch !important;
}

body.mobile-bls-focus-enabled.client.mobile-bls-landscape.mobile-bls-active .video-section:not(.fullscreen) .video-container:first-child,
body.mobile-bls-focus-enabled.client.mobile-bls-landscape.mobile-bls-active .video-section:not(.fullscreen) .video-container:last-child {
    top: auto !important;
    bottom: max(8px, env(safe-area-inset-bottom, 0px)) !important;
    width: 84px !important;
    height: 63px !important;
    min-width: 72px !important;
    min-height: 54px !important;
}

body.mobile-bls-focus-enabled.client.mobile-bls-landscape.mobile-bls-active .video-section:not(.fullscreen) .video-container:first-child {
    left: max(8px, env(safe-area-inset-left, 0px)) !important;
    right: auto !important;
}

body.mobile-bls-focus-enabled.client.mobile-bls-landscape.mobile-bls-active .video-section:not(.fullscreen) .video-container:last-child {
    left: auto !important;
    right: max(8px, env(safe-area-inset-right, 0px)) !important;
}

/* Landscape BLS: hide PiP chrome (⋮ menu, drag handle) — bottom bar has controls. */
body.mobile-bls-focus-enabled.client.mobile-bls-landscape.mobile-bls-active .video-section:not(.fullscreen) .video-container .pip-menu-button,
body.mobile-bls-focus-enabled.client.mobile-bls-landscape.mobile-bls-active .video-section:not(.fullscreen) .video-container .pip-dropdown-menu,
body.mobile-bls-focus-enabled.client.mobile-bls-landscape.mobile-bls-active .video-section:not(.fullscreen) .video-container .pip-controls,
body.mobile-bls-focus-enabled.client.mobile-bls-landscape.mobile-bls-active .video-section:not(.fullscreen) .video-container .pip-drag-indicator {
    display: none !important;
    visibility: hidden !important;
    pointer-events: none !important;
}

@media (orientation: landscape) and (max-height: 480px) {
    body.mobile-bls-focus-enabled.therapist.bls-rail-collapse-enabled.bls-rail-ui-active .video-section:not(.fullscreen) > .emdr-canvas-container,
    body.mobile-bls-focus-enabled.therapist.bls-rail-collapse-enabled.bls-rail-ui-active .video-section:not(.fullscreen) .emdr-canvas-container {
        width: 96px !important;
        height: 72px !important;
        min-width: 96px !important;
        min-height: 72px !important;
        bottom: max(6px, env(safe-area-inset-bottom, 0px)) !important;
        left: max(6px, env(safe-area-inset-left, 0px)) !important;
    }
}

/* Therapist phone: keep animation preview PiP smaller so client video stays usable */
@media (max-width: 480px) {
    body.mobile-bls-focus-enabled.therapist.bls-rail-collapse-enabled.bls-rail-ui-active .video-section:not(.fullscreen) > .emdr-canvas-container,
    body.mobile-bls-focus-enabled.therapist.bls-rail-collapse-enabled.bls-rail-ui-active .video-section:not(.fullscreen) .emdr-canvas-container {
        width: 120px !important;
        height: 90px !important;
        min-width: 120px !important;
        min-height: 90px !important;
        bottom: max(12px, env(safe-area-inset-bottom, 0px)) !important;
        left: max(8px, env(safe-area-inset-left, 0px)) !important;
    }
}
