/* Core Fonts & Reset */
@import url('https://fonts.googleapis.com/css2?family=Turret+Road:wght@500;700;800&family=Poppins:wght@300;400;500;600;700;800&display=swap');

/* App Loading State */
.app-loader {
    position: fixed;
    inset: 0;
    z-index: 99999;
    background: #0a0a0f;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.4s ease;
}

body:not(.app-loading) .app-loader {
    opacity: 0;
    pointer-events: none;
}

.app-loader-spinner {
    width: 44px;
    height: 44px;
    border: 3px solid rgba(255,255,255,0.1);
    border-top-color: #ff4081;
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

html * {
    font-family: Poppins, sans-serif !important;
}

body {
    margin: 0;
    padding: 0;
    padding-top: 90px;
    /* Space for fixed logo header */
    padding-bottom: 160px;
    /* Space for fixed bottom helper */
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    align-items: center;
    overflow-x: hidden;
    position: relative;
}

/* Lock scrolling on desktop/Windows viewports so the page can't be scrolled */
@media (min-width: 993px) {

    html,
    body {
        height: 100vh;
        overflow: hidden;
    }
}

/* Background image - Admin uploadable */
.background-fixed {
    background-color: #0d0b18;
    background-position: center center;
    background-repeat: no-repeat;
    background-size: cover;
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: -1;
}

/* Logo fixed header bar */
.logo-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 900;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 8px 16px;
    background: transparent;
    pointer-events: none;
}

.logo {
    height: 70px;
    width: auto;
    max-width: 240px;
    display: block;
    filter: drop-shadow(0 4px 12px rgba(0, 0, 0, 0.6));
    pointer-events: auto;
}

/* Override Bootstrap's default container max-width cap, but keep it
   tight enough that the 4 boxes stay close together instead of spreading
   across the full width with big empty gaps. */
#gameContainer {
    max-width: 1920px !important;
}

.game-wrapper {
    width: 100%;
}

/* Large Box Grid Container */
.box-container {
    margin: 40px auto 1rem !important;
    width: max-content !important;
    max-width: 100% !important;
    display: grid !important;
    /* Grid cells (350px) force centers together at a massive scale */
    grid-template-columns: repeat(4, 350px) !important;
    justify-items: center !important;
    align-items: center !important;
    justify-content: center !important;
    gap: 0px !important;
    padding: 10px !important;
    overflow: visible !important;
}

/* Individual Box Item - massively enlarged size (520px) overflows the 350px cell, keeping them close */
.pixelated-box {
    position: relative;
    width: 520px !important;
    height: 520px !important;
    cursor: default;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 0.5rem;
    min-height: 100px;
    /* Smooth transform transitions for JS swapping */
    transition: transform 0.4s ease-in-out, border-color 0.3s, background 0.3s, opacity 0.3s;
    border-radius: 16px;
    will-change: transform;
    transform-style: preserve-3d;
    backface-visibility: hidden;
    z-index: 1;
}

@media (max-width: 992px) {
    /* Override Bootstrap .container padding on mobile */
    #gameContainer,
    #gameContainer.container {
        padding-left: 0 !important;
        padding-right: 0 !important;
        width: 100% !important;
        max-width: 100% !important;
    }

    .box-container {
        grid-template-columns: repeat(2, 1fr) !important;
        width: calc(100% - 16px) !important;
        max-width: 480px !important;
        margin: 16px auto 0 !important;
        row-gap: 8px !important;
        column-gap: 8px !important;
        padding: 0 !important;
    }

    .pixelated-box {
        width: 100% !important;
        height: auto !important;
        aspect-ratio: 1 / 1 !important;
        padding: 0 !important;
        min-height: unset !important;
    }

    .pixelated-box img.planet {
        width: 100% !important;
        height: 100% !important;
        object-fit: contain !important;
    }
}

.pixelated-box.interactive {
    cursor: pointer;
}

.pixelated-box.interactive:hover {
    transform: scale(1.08) !important;
    /* Keep hover scale distinct */
}

.pixelated-box img.planet {
    width: 95%;
    height: 95%;
    object-fit: contain;
    pointer-events: none;
    transition: opacity 0.2s, transform 0.2s;
}

.pixelated-box .box-open-img {
    position: absolute;
    opacity: 0;
    transform: scale(0.8);
}

/* Opened Box State */
.pixelated-box.opened .box-closed-img {
    opacity: 0;
    transform: scale(0.8);
}

.pixelated-box.opened .box-open-img {
    opacity: 1;
    transform: scale(1);
}

.pixelated-box.dimmed {
    opacity: 0.3;
    filter: grayscale(80%);
    pointer-events: none;
    transform: scale(0.92) !important;
}

/* Winning box highlight - stands out among the other opened boxes */
.pixelated-box.winner {
    z-index: 5;
    filter: drop-shadow(0 0 22px rgba(255, 215, 0, 0.75));
}

.pixelated-box.winner .overlay-text.bg-winner {
    background: linear-gradient(90deg, #ffd700, #ff9f1c);
    color: #241246;
    border-color: transparent;
    font-weight: 800;
}

/* Large Prize Label Overlay - Photo 1 style */
.overlay-text {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0);
    z-index: 10;
    pointer-events: none;
    opacity: 0;
    font-family: 'Turret Road', sans-serif !important;
    transition: transform 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.4) 0.3s, opacity 0.3s 0.3s;
}

/* Photo 1: Opened boxes show a semi-transparent black rectangle label over them */
.pixelated-box.opened .overlay-text {
    transform: translate(-50%, -10%) scale(1);
    opacity: 1;
}

.overlay-text.bg-winner {
    background: rgba(0, 0, 0, 0.7);
    border: 2px solid rgba(255, 255, 255, 0.15);
    font-size: 20px;
    font-weight: 800;
    color: #fff;
    padding: 14px 20px;
    border-radius: 12px;
    width: auto;
    max-width: 80%;
    /* Bigger badge, still boxy rather than a long bar */
    text-align: center;
    white-space: normal;
    line-height: 1.3;
    text-transform: uppercase;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.5);
    font-family: 'Turret Road', sans-serif !important;
}

@media (max-width: 576px) {
    .overlay-text.bg-winner {
        font-size: 12px;
        padding: 6px 8px;
        max-width: 85%;
    }
}

/* Shaking micro-animation - kept for backwards compatibility, no longer
   auto-applied during shuffle since it conflicts with the FLIP transform. */
.js-shaking {
    animation: shakeBox 0.15s ease-in-out infinite alternate;
}

@keyframes shakeBox {
    0% {
        transform: translate(1px, 1px) rotate(0deg);
    }

    100% {
        transform: translate(-1px, -1px) rotate(-1deg);
    }
}

/* Blinking text */
.blinking-text {
    animation: 1s infinite blink;
}

@keyframes blink {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.3;
    }
}

/* Floating Animation */
.floating-animation {
    animation: 3s ease-in-out infinite float;
}

@keyframes float {

    0%,
    100% {
        transform: translateY(0);
    }

    50% {
        transform: translateY(-8px);
    }
}

/* Bottom Actions Panel (#helper) */
#helper {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 1000;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    padding: 1.2rem;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
}

.bottom-center {
    position: fixed;
    bottom: 150px;
    left: 50%;
    transform: translateX(-50%);
    padding: 8px 16px;
    border-radius: 8px;
    background-color: rgba(0, 0, 0, 0.7);
    z-index: 999;
    border: 1px solid rgba(255, 255, 255, 0.1);
}


.mute-btn {
    position: fixed;
    top: 25px;
    right: 25px;
    width: 44px;
    height: 44px;
    background: rgba(0, 0, 0, 0.25);
    border: 1.5px solid rgba(255, 255, 255, 0.25);
    border-radius: 50%;
    color: rgba(255, 255, 255, 0.75);
    font-size: 20px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
    z-index: 1000;
    transition: all 0.25s ease;
}

.mute-btn:hover {
    background: rgba(255, 255, 255, 0.15);
    border-color: rgba(255, 255, 255, 0.5);
    color: #fff;
    transform: scale(1.08);
}

@media (max-width: 576px) {
    .mute-btn {
        top: 15px;
        right: 15px;
        width: 36px;
        height: 36px;
        font-size: 16px;
    }
}

/* Welcome Overlay Style - Photo 3 */
.welcome-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
    z-index: 1500;
    display: flex;
    justify-content: center;
    align-items: center;
}

.welcome-content {
    text-align: center;
    padding: 35px;
    width: 90%;
    max-width: 650px; /* Much larger box on desktop */
}

.welcome-title {
    font-family: 'Turret Road', sans-serif !important;
    font-weight: 800;
    font-size: 2.2rem;
    color: white;
    line-height: 1.3;
    text-shadow: 0 4px 15px rgba(0, 0, 0, 0.9);
    margin-bottom: 20px;
}

.welcome-buttons {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.welcome-buttons button {
    font-size: 18px !important;
    padding: 12px 22px !important;
    width: 100%;
}

@media (max-width: 768px) {
    .welcome-content {
        max-width: 360px;
        padding: 16px;
    }
    .welcome-title {
        font-size: 1.6rem;
    }
    .welcome-buttons button {
        font-size: 15px !important;
        padding: 10px 16px !important;
    }
}

/* Retro Game Button Style */
.game-button {
    position: relative;
    top: 0;
    cursor: pointer;
    text-decoration: none !important;
    outline: 0 !important;
    font-size: 16px;
    font-family: 'Turret Road', sans-serif !important;
    text-shadow: 2px 2px 1px #0066a2, -2px 2px 1px #0066a2, 2px -2px 1px #0066a2, -2px -2px 1px #0066a2, 0 2px 1px #0066a2, 0 -2px 1px #0066a2;
    border: none;
    background: repeating-linear-gradient(45deg, #3ebbf7, #3ebbf7 5px, #45b1f4 5px, #45b1f4 10px);
    border-bottom: 3px solid rgba(16, 91, 146, .5);
    border-top: 3px solid rgba(255, 255, 255, .3);
    color: #fff !important;
    border-radius: 8px;
    padding: 10px 16px;
    box-shadow: 0 5px 0 #266b91, 0 6px 1px 1px rgba(0, 0, 0, .2), 0 8px 0 3px #12517d, 0 10px 1px rgba(0, 0, 0, 0.3);
    transition: top 0.1s, box-shadow 0.1s;
}

.game-button:hover {
    top: 2px;
    box-shadow: 0 3px 0 #266b91, 0 4px 1px 1px rgba(0, 0, 0, .2), 0 6px 0 3px #12517d, 0 8px 1px rgba(0, 0, 0, 0.3);
}

.game-button::after,
.game-button::before {
    content: '';
    height: 10%;
    position: absolute;
    background: #fff;
    top: -3%;
    border-radius: 99px
}

.game-button::before {
    width: 30%;
    right: 12%
}

.game-button::after {
    width: 5%;
    right: 4%
}

.game-button.red {
    background: repeating-linear-gradient(45deg, #ff4f4c, #ff4f4c 5px, #ff4643 5px, #ff4643 10px);
    box-shadow: 0 5px 0 #ae2725, 0 6px 1px 1px rgba(0, 0, 0, .2), 0 8px 0 3px #831614, 0 10px 1px rgba(0, 0, 0, 0.3);
    border-bottom: 3px solid rgba(16, 91, 146, .5);
    text-shadow: 2px 2px 1px #d72d21, -2px 2px 1px #d72d21, 2px -2px 1px #d72d21, -2px -2px 1px #d72d21, 0 2px 1px #d72d21, 0 -2px 1px #d72d21;
}

.game-button.red:hover {
    top: 2px;
    box-shadow: 0 3px 0 #ae2725, 0 4px 1px 1px rgba(0, 0, 0, .2), 0 6px 0 3px #831614, 0 8px 1px rgba(0, 0, 0, 0.3);
}

.game-button.orange {
    background: repeating-linear-gradient(45deg, #ffc800, #ffc800 5px, #ffc200 5px, #ffc200 10px);
    box-shadow: 0 5px 0 #b76113, 0 6px 1px 1px rgba(0, 0, 0, .2), 0 8px 0 3px #75421f, 0 10px 1px rgba(0, 0, 0, 0.3);
    border-bottom: 3px solid rgba(205, 102, 0, .5);
    text-shadow: 2px 2px 1px #e78700, -2px 2px 1px #e78700, 2px -2px 1px #e78700, -2px -2px 1px #e78700, 0 2px 1px #e78700, 0 -2px 1px #e78700;
}

.game-button.orange:hover {
    top: 2px;
    box-shadow: 0 3px 0 #b76113, 0 4px 1px 1px rgba(0, 0, 0, .2), 0 6px 0 3px #75421f, 0 8px 1px rgba(0, 0, 0, 0.3);
}

.game-button.green {
    background: repeating-linear-gradient(45deg, #25d366, #25d366 5px, #128c7e 5px, #128c7e 10px);
    box-shadow: 0 5px 0 #075e54, 0 6px 1px 1px rgba(0, 0, 0, .2), 0 8px 0 3px #053b35, 0 10px 1px rgba(0, 0, 0, 0.3);
    border-bottom: 3px solid rgba(7, 94, 84, .5);
    text-shadow: 2px 2px 1px #075e54, -2px 2px 1px #075e54, 2px -2px 1px #075e54, -2px -2px 1px #075e54, 0 2px 1px #075e54, 0 -2px 1px #075e54;
}

.game-button.green:hover {
    top: 2px;
    box-shadow: 0 3px 0 #075e54, 0 4px 1px 1px rgba(0, 0, 0, .2), 0 6px 0 3px #053b35, 0 8px 1px rgba(0, 0, 0, 0.3);
}

/* Game Input Box Style */
.game-input {
    width: 100%;
    outline: 0;
    border-radius: 8px;
    min-height: 54px;
    border: 4px solid #5455a1;
    background-color: #1f1b40;
    font-family: 'Turret Road', sans-serif !important;
    font-size: 20px;
    text-shadow: 2px 2px 1px #6f74dc, -2px 2px 1px #5455a1, 2px -2px 1px #6f74dc, -2px -2px 1px #5455a1;
    color: #fff;
    caret-color: #6f74dc;
    padding: 6px 12px;
    text-align: center;
}

.game-input::placeholder {
    font-family: 'Turret Road', sans-serif !important;
    font-size: 16px;
    color: #999;
    opacity: .8;
    text-shadow: none;
}