/* Safe Area Inset Handling and Margins */
:root {
    --widget-safe-margin-desktop: 0.5rem;
    --widget-safe-margin-tablet: 0.5rem;
    --widget-safe-margin-mobile: 0.5rem;
    --widget-safe-area-top: max(env(safe-area-inset-top), 0px);
    --widget-safe-area-bottom: max(env(safe-area-inset-bottom), 0px);
    --widget-safe-area-left: max(env(safe-area-inset-left), 0px);
    --widget-safe-area-right: max(env(safe-area-inset-right), 0px);
}

/* Bootstrap Utility Class Support for Environments/Widgets */
.position-fixed {
    position: fixed !important;
}
.position-absolute {
    position: absolute !important;
}
.translate-middle {
    transform: translate(-50%, -50%) !important;
}
.w-100 {
    width: 100% !important;
}
.d-flex {
    display: flex !important;
}
.justify-content-center {
    justify-content: center !important;
}
.align-items-center {
    align-items: center !important;
}

/* Z-Index Stacking (Confirming Layer Order) */
#header-jackpot-strip {
    z-index: 1050; /* Above chat, below toast */
}
#chat-toast-container {
    z-index: 1980;
}
#winning-toast-container {
    z-index: 2000; /* Topmost */
}

/* Startup hidden state for widget restore flow */
#winning-toast-container,
#header-jackpot-strip,
#chat-toast-container {
    display: none;
}

#winning-toast-container.ready,
#header-jackpot-strip.ready,
#chat-toast-container.ready {
    display: block;
}

/* Desktop layout rules (>= 768px) */
@media (min-width: 768px) {
    #header-jackpot-strip {
        position: fixed;
        /* Positioned via JS inline styles */
    }

    #winning-toast-container {
        position: fixed;
        left: 50%;
        top: 50%;
        transform: translate(-50%, -50%);
        /* JS applies translate-middle for consistency */
    }

    #chat-toast-container {
        position: fixed;
        /* Do not give active stack container a centered desktop contract that fights JS/default right-edge anchor */
    }

    /* Allow user-positioned overrides */
    #header-jackpot-strip.user-positioned,
    #winning-toast-container.user-positioned,
    #chat-toast-container.user-positioned {
        position: fixed;
    }
}

/* Mobile layout rules (< 768px) */
@media (max-width: 767.98px) {
    #header-jackpot-strip {
        position: static !important;
        left: auto !important;
        top: auto !important;
        width: 100% !important;
        margin: 0 !important;
    }

    #winning-toast-container {
        position: fixed !important;
        left: 50% !important;
        transform: translateX(-50%) !important;
        top: auto !important;
        bottom: var(--widget-safe-area-bottom, 20px) !important;
        width: auto !important;
        max-height: 50vh;
        overflow-y: auto;
    }

    #chat-toast-container {
        position: fixed !important;
        left: 50% !important;
        transform: translateX(-50%) !important;
        top: auto !important;
        bottom: calc(var(--widget-safe-area-bottom, 20px) + 12px) !important;
        width: auto !important;
        max-height: 50vh;
        overflow-y: auto;
    }
}

/* Out-of-Bounds Visual Feedback (Boundary Clamping) */
#header-jackpot-strip.out-of-bounds,
#winning-toast-container.out-of-bounds,
#chat-toast-container.out-of-bounds {
    box-shadow: 0 0 0 2px rgba(220, 38, 38, 0.7) !important;
    /* Red outline to indicate boundary correction with high visual contrast */
}

