/**
 * Reusable in-game controls, settings, fullscreen and touch shell.
 */

.bgf-shell-controls {
    position: absolute;
    z-index: 28;
    right: max(12px, var(--boost-game-safe-area-right));
    bottom: max(12px, var(--boost-game-safe-area-bottom));
    display: flex;
    align-items: flex-end;
    gap: 8px;
}

.bgf-game-funnel[data-bgf-settings-open="true"] .bgf-shell-controls,
.bgf-game-funnel[data-bgf-paused="true"] .bgf-shell-controls {
    z-index: 36;
}

.bgf-game-funnel[data-bgf-mode="result"] .bgf-shell-controls,
.bgf-game-funnel[data-bgf-mode="pre-game"] .bgf-shell-controls,
.bgf-game-funnel[data-bgf-decision-open="true"] .bgf-shell-controls {
    display: none;
}

.bgf-shell-audio {
    position: relative;
    display: inline-grid;
    place-items: center;
}

.bgf-shell-audio__popover {
    position: absolute;
    left: 50%;
    bottom: calc(100% + 12px);
    display: grid;
    grid-template-rows: auto 1fr;
    justify-items: center;
    gap: 8px;
    width: 54px;
    min-height: 154px;
    padding: 10px 8px 12px;
    border: 1px solid color-mix(in srgb, var(--boost-ui-secondary) 20%, var(--boost-ui-border));
    border-radius: 16px;
    background: color-mix(in srgb, var(--boost-ui-surface) 97%, transparent);
    box-shadow: 0 16px 34px color-mix(in srgb, var(--boost-ui-secondary) 16%, transparent);
    opacity: 0;
    visibility: hidden;
    transform: translate(-50%, 6px);
    transition: opacity 120ms ease, transform 120ms ease, visibility 120ms;
    pointer-events: none;
}

.bgf-shell-audio__popover::after {
    position: absolute;
    bottom: -6px;
    left: 50%;
    width: 10px;
    height: 10px;
    border-right: 1px solid color-mix(in srgb, var(--boost-ui-secondary) 20%, var(--boost-ui-border));
    border-bottom: 1px solid color-mix(in srgb, var(--boost-ui-secondary) 20%, var(--boost-ui-border));
    background: var(--boost-ui-surface);
    content: "";
    transform: translateX(-50%) rotate(45deg);
}

.bgf-shell-audio[data-bgf-volume-open="true"] .bgf-shell-audio__popover {
    opacity: 1;
    visibility: visible;
    transform: translate(-50%, 0);
    pointer-events: auto;
}

.bgf-shell-audio__popover[data-bgf-muted="true"] .bgf-shell-audio__slider {
    opacity: 0.62;
}

.bgf-shell-audio__value {
    min-width: 36px;
    color: var(--boost-ui-text);
    font-size: 0.68rem;
    font-weight: 800;
    font-variant-numeric: tabular-nums;
    line-height: 1;
    text-align: center;
}

.bgf-shell-audio__slider {
    display: grid;
    place-items: center;
    width: 32px;
    height: 112px;
}

.bgf-shell-audio__slider input[type="range"] {
    width: 24px;
    height: 112px;
    margin: 0;
    padding: 0;
    background: transparent;
    accent-color: var(--boost-ui-primary);
    cursor: pointer;
    direction: rtl;
    writing-mode: vertical-lr;
}

.bgf-icon-button {
    display: grid;
    place-items: center;
    width: 42px;
    height: 42px;
    padding: 8px;
}

.bgf-icon-button svg {
    display: block;
    width: 100%;
    height: 100%;
    fill: none;
    stroke: currentColor;
    stroke-width: 2.2;
    stroke-linecap: square;
    stroke-linejoin: miter;
}

.bgf-profile-card:focus-visible,
.bgf-character-carousel__arrow:focus-visible,
.bgf-icon-button:focus-visible,
.bgf-pixel-button:focus-visible {
    border-color: var(--boost-ui-accent);
    outline: none;
}

.bgf-game-canvas:focus-visible,
.bgf-settings-panel input:focus-visible,
.bgf-settings-panel select:focus-visible {
    outline: 4px solid var(--boost-ui-accent);
    outline-offset: 3px;
}


.bgf-pause-panel {
    position: absolute;
    z-index: 31;
    inset: 0;
    display: grid;
    place-items: center;
    padding: 20px;
    background: color-mix(in srgb, var(--boost-ui-secondary) 36%, transparent);
    backdrop-filter: blur(2px);
}

.bgf-pause-panel[hidden] {
    display: none;
}

.bgf-pause-panel__card {
    display: grid;
    gap: 12px;
    width: min(92%, 430px);
    padding: 18px;
    border: 1px solid color-mix(in srgb, var(--boost-ui-secondary) 22%, var(--boost-ui-border));
    border-radius: 20px;
    background: var(--boost-ui-surface);
    color: var(--boost-ui-text);
    box-shadow: 0 26px 60px color-mix(in srgb, var(--boost-ui-secondary) 20%, transparent);
}

.bgf-pause-panel__card h3,
.bgf-pause-panel__card p {
    margin: 0;
}

.bgf-pause-panel__card h3 {
    font-size: clamp(1.2rem, 3vw, 1.7rem);
}

.bgf-settings-panel {
    position: absolute;
    z-index: 30;
    inset: 50% auto auto 50%;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto;
    width: min(92%, 760px);
    max-height: min(88%, 680px);
    overflow: hidden;
    border: 1px solid color-mix(in srgb, var(--boost-ui-secondary) 22%, var(--boost-ui-border));
    border-radius: 22px;
    background: var(--boost-ui-surface);
    color: var(--boost-ui-text);
    box-shadow: 0 26px 60px color-mix(in srgb, var(--boost-ui-secondary) 18%, transparent);
    transform: translate(-50%, -50%);
}

.bgf-settings-panel__header,
.bgf-settings-panel__actions {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 16px;
    background: var(--boost-ui-bg-alt);
}

.bgf-settings-panel__header {
    justify-content: space-between;
    border-bottom: 2px solid var(--boost-ui-border);
}

.bgf-settings-panel__header h3 {
    margin: 0;
    font-size: clamp(1rem, 2.3vw, 1.35rem);
}

.bgf-settings-panel__body {
    display: grid;
    grid-template-columns: 1fr;
    gap: 14px;
    overflow: auto;
    padding: 16px;
    overscroll-behavior: contain;
}

.bgf-settings-group,
.bgf-settings-help {
    min-width: 0;
    margin: 0;
    padding: 14px;
    border: 1px solid color-mix(in srgb, var(--boost-ui-secondary) 14%, var(--boost-ui-border));
    border-radius: 16px;
    background: var(--boost-ui-surface);
}

.bgf-settings-group legend,
.bgf-settings-help h4 {
    padding-inline: 5px;
    color: var(--boost-ui-primary);
    font-weight: 800;
}

.bgf-settings-help {
    grid-column: auto;
}

.bgf-settings-help h4,
.bgf-settings-help p {
    margin: 0 0 8px;
}

.bgf-setting-row,
.bgf-setting-stack {
    display: flex;
    gap: 12px;
    margin-block: 10px;
}

.bgf-setting-row {
    align-items: center;
    justify-content: space-between;
}

.bgf-setting-stack {
    flex-direction: column;
}

.bgf-setting-row input[type="checkbox"] {
    width: 22px;
    height: 22px;
    accent-color: var(--boost-ui-primary);
}

.bgf-setting-stack input[type="range"],
.bgf-setting-stack select {
    width: 100%;
}

.bgf-setting-stack select {
    min-height: 40px;
    padding: 7px;
    border: 2px solid var(--boost-ui-border);
    background: var(--boost-ui-surface);
    color: var(--boost-ui-text);
}

.bgf-settings-panel__actions {
    flex-wrap: wrap;
    border-top: 2px solid var(--boost-ui-border);
}

.bgf-reset-confirmation {
    display: flex;
    flex: 1 1 100%;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    padding-top: 10px;
    border-top: 2px solid var(--boost-ui-border);
}

.bgf-reset-confirmation p {
    flex: 1 1 260px;
    margin: 0;
}

.bgf-orientation-hint {
    display: none;
}

body.bgf-fullscreen-lock {
    overflow: hidden;
}

.bgf-canvas-frame:fullscreen,
.bgf-canvas-frame[data-bgf-fullscreen="fallback"] {
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    aspect-ratio: auto;
    margin: 0;
    border: 0;
    background: var(--boost-ui-bg-alt);
    box-shadow: none;
}

.bgf-canvas-frame[data-bgf-fullscreen="fallback"] {
    position: fixed;
    z-index: 2147483000;
    inset: 0;
}

.bgf-canvas-frame:fullscreen .bgf-game-canvas,
.bgf-canvas-frame[data-bgf-fullscreen="fallback"] .bgf-game-canvas {
    object-fit: contain;
}

@media (max-width: 640px) {
    .bgf-settings-panel {
        width: calc(100% - 20px);
        max-height: calc(100% - 20px);
        box-shadow: 0 18px 36px color-mix(in srgb, var(--boost-ui-secondary) 14%, transparent);
    }

    .bgf-settings-panel__body {
        grid-template-columns: 1fr;
        padding: 12px;
    }

    .bgf-settings-help {
        grid-column: auto;
    }

    .bgf-settings-panel__actions {
        max-height: 34vh;
        overflow: auto;
    }

    .bgf-settings-panel__actions .bgf-pixel-button {
        flex: 1 1 180px;
    }

    .bgf-shell-controls {
        gap: 6px;
    }

    .bgf-icon-button {
        width: 38px;
        height: 38px;
        padding: 7px;
    }
}



@media (prefers-reduced-motion: reduce) {
    .bgf-icon-button,
    .bgf-pixel-button,
    .bgf-shell-audio__popover {
        transition: none;
    }
}

@media (pointer: coarse) {
    .bgf-shell-audio__popover {
        width: 62px;
        min-height: 174px;
        padding: 12px 10px 14px;
    }

    .bgf-shell-audio__slider,
    .bgf-shell-audio__slider input[type="range"] {
        height: 128px;
    }

    .bgf-shell-audio__slider input[type="range"] {
        width: 30px;
    }
}

.bgf-icon,
.bgf-inline-icon {
    display: block;
    width: 100%;
    height: 100%;
}

.bgf-icon-button .bgf-icon--image,
.bgf-icon.bgf-icon--image {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
}

/* HUD life visuals must stay metric-sized even though generic icon buttons use 100% icons. */
.bgf-hud .bgf-hud__life-icons {
    display: inline-flex;
    align-items: center;
    justify-content: flex-end;
    gap: 2px;
    max-width: 100%;
    overflow: hidden;
}

.bgf-hud .bgf-hud__life-icon,
.bgf-hud .bgf-hud__life-icon.bgf-icon,
.bgf-hud .bgf-hud__life-icon.bgf-inline-icon,
.bgf-hud .bgf-hud__life-icon.bgf-icon--image {
    width: 1em;
    height: 1em;
    max-width: 1em;
    max-height: 1em;
    min-width: 0;
    min-height: 0;
    flex: 0 0 1em;
    object-fit: contain;
}


.bgf-touch-controls {
    position: absolute;
    z-index: 26;
    inset: auto max(14px, var(--boost-game-safe-area-right)) max(16px, var(--boost-game-safe-area-bottom)) max(14px, var(--boost-game-safe-area-left));
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 18px;
    pointer-events: none;
    opacity: 0.92;
}

.bgf-touch-controls[hidden] {
    display: none;
}

.bgf-touch-controls[data-bgf-touch-position="left"] {
    right: auto;
    justify-content: flex-start;
}

.bgf-touch-controls[data-bgf-touch-position="right"] {
    left: auto;
    justify-content: flex-end;
}

.bgf-touch-controls[data-bgf-touch-position="bottom"] {
    justify-content: center;
}

.bgf-touch-controls__dpad,
.bgf-touch-controls__buttons {
    display: grid;
    gap: 8px;
    pointer-events: auto;
}

.bgf-touch-controls__dpad {
    grid-template-areas:
        ". up ."
        "left . right"
        ". down .";
    grid-template-columns: repeat(3, 52px);
    grid-template-rows: repeat(3, 52px);
}

.bgf-touch-controls__buttons {
    grid-auto-flow: column;
    grid-auto-columns: 62px;
    align-items: end;
}

.bgf-touch-control {
    display: grid;
    place-items: center;
    width: 52px;
    height: 52px;
    padding: 0;
    border: 2px solid color-mix(in srgb, var(--boost-ui-primary) 40%, var(--boost-ui-border));
    border-radius: 18px;
    background: color-mix(in srgb, var(--boost-ui-surface) 88%, transparent);
    color: var(--boost-ui-text);
    box-shadow: 0 14px 32px color-mix(in srgb, var(--boost-ui-secondary) 18%, transparent);
    font: inherit;
    font-size: 1.2rem;
    font-weight: 900;
    line-height: 1;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
}

.bgf-touch-control[data-bgf-touch-kind="button"] {
    width: 62px;
    height: 62px;
    border-radius: 999px;
    background: color-mix(in srgb, var(--boost-ui-primary) 88%, transparent);
    color: var(--boost-ui-primary-contrast);
}

.bgf-touch-control[data-bgf-touch-variant="secondary"] {
    background: color-mix(in srgb, var(--boost-ui-surface) 88%, transparent);
    color: var(--boost-ui-text);
}

.bgf-touch-control[data-bgf-touch-variant="danger"] {
    background: color-mix(in srgb, var(--boost-ui-accent) 88%, transparent);
    color: var(--boost-ui-primary-contrast);
}

.bgf-touch-control[data-bgf-touch-active="true"],
.bgf-touch-control:active {
    transform: translateY(2px) scale(0.97);
    filter: brightness(1.08);
}

.bgf-touch-control[data-bgf-touch-direction="up"] { grid-area: up; }
.bgf-touch-control[data-bgf-touch-direction="down"] { grid-area: down; }
.bgf-touch-control[data-bgf-touch-direction="left"] { grid-area: left; }
.bgf-touch-control[data-bgf-touch-direction="right"] { grid-area: right; }

.bgf-game-funnel[data-bgf-settings-open="true"] .bgf-touch-controls,
.bgf-game-funnel[data-bgf-mode="result"] .bgf-touch-controls,
.bgf-game-funnel[data-bgf-mode="pre-game"] .bgf-touch-controls,
.bgf-game-funnel[data-bgf-decision-open="true"] .bgf-touch-controls {
    display: none;
}

@media (max-width: 560px) {
    .bgf-touch-controls {
        gap: 12px;
    }

    .bgf-touch-controls__dpad {
        grid-template-columns: repeat(3, 44px);
        grid-template-rows: repeat(3, 44px);
    }

    .bgf-touch-control {
        width: 44px;
        height: 44px;
        border-radius: 15px;
        font-size: 1rem;
    }

    .bgf-touch-control[data-bgf-touch-kind="button"] {
        width: 54px;
        height: 54px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .bgf-touch-control {
        transition: none;
    }
}
