/* Google Fonts - adjust if you use different fonts */
body {
    font-family: 'Inter', sans-serif;
}

/* General Game Container Styling */
.game-container {
    max-width: 800px;
    margin: 30px auto;
    padding: 20px;
    background-color: #f7f7f7;
    border-radius: 10px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
    text-align: center;
    color: #333;
}

.game-container h1 {
    color: #4CAF50; /* A pleasant green */
    margin-bottom: 15px;
    font-size: 2.2em;
}

.game-container p {
    font-size: 1.1em;
    line-height: 1.6;
    margin-bottom: 20px;
}

/* Boxes Container */
.boxes-container {
    display: flex;
    justify-content: center;
    gap: 25px; /* Space between boxes */
    margin-top: 30px;
    flex-wrap: wrap; /* Allow boxes to wrap on smaller screens */
}

/* Individual Prize Box Styling */
.prize-box {
    width: var(--prize-box-size, 180px); /* Use CSS variable, fallback to 180px */
    height: var(--prize-box-size, 180px); /* Use CSS variable, fallback to 180px */
    background-color: #ff9800; /* Default background if no prize image */
    border-radius: 15px;
    position: relative; /* For absolute positioning of inner elements */
    overflow: hidden; /* Hide overflowing content during transitions */
    cursor: pointer;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
    /* Enhanced transition for all properties for smoother effects */
    transition: transform 0.4s ease-out, box-shadow 0.4s ease-out, border 0.4s ease-out, opacity 0.4s ease-out;
    flex-shrink: 0; /* Prevent shrinking on smaller screens */
    border: 3px solid transparent; /* Default transparent border */
}

.prize-box:hover:not(.disabled):not(.selected) { /* Apply hover only if not disabled or selected */
    transform: translateY(-8px) scale(1.02); /* More pronounced lift and slight scale */
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.35);
}

.prize-box.disabled {
    cursor: not-allowed;
    opacity: 0.7;
}

/* Winning box highlight */
.prize-box.winner {
    border: 5px solid #4CAF50; /* Thicker green border for the winner */
    box-shadow: 0 0 30px 10px rgba(76, 175, 80, 0.9); /* Stronger green glow */
    transform: scale(1.08) translateY(-10px); /* More significant scale and lift */
    animation: pulse-winner 1.5s infinite alternate; /* Pulsing animation */
}

@keyframes pulse-winner {
    0% {
        box-shadow: 0 0 30px 10px rgba(76, 175, 80, 0.9);
        transform: scale(1.08) translateY(-10px);
    }
    100% {
        box-shadow: 0 0 40px 15px rgba(76, 175, 80, 1);
        transform: scale(1.1) translateY(-12px);
    }
}


/* Inner elements of the prize box */
.prize-box .box-content,
.prize-box .box-unopened-image,
.prize-box .box-cover {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background-size: cover;
    background-position: center;
    border-radius: 15px; /* Inherit border-radius */
    transition: opacity 0.6s ease-in-out, transform 0.6s ease-in-out; /* Smoother transitions */
}

/* Content (revealed prize) */
.prize-box .box-content {
    z-index: 1; /* Behind unopened image and cover */
    opacity: 1; /* Always visible when covers are gone */
    background-color: #ff9800; /* Fallback for revealed content */
    flex-direction: column; /* For number/image stacking */
}

.prize-box .box-content .box-image {
    max-width: 90%;
    max-height: 90%;
    object-fit: contain;
    border-radius: 10px;
    transition: transform 0.4s ease-out; /* Added transition for image scaling */
}

/* Magnify the winning prize image */
.prize-box.winner .box-content .box-image {
    transform: scale(var(--winning-image-scale, 1.2)); /* Use CSS variable for magnification */
}


.prize-box .box-number {
    font-size: 4em;
    font-weight: bold;
    color: white;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
}

/* Unopened Image (initial visible layer) */
.prize-box .box-unopened-image {
    z-index: 3; /* Above box-content, below box-cover */
    background-color: #007bff; /* Default blue for unopened box */
    opacity: 1;
    transform: rotateY(0deg);
}

.prize-box.revealed .box-unopened-image {
    opacity: 0; /* Hide unopened image on reveal */
    transform: rotateY(180deg) scale(0.8); /* Flip and slightly shrink */
}

/* General Box Cover (topmost layer, hides all) */
.prize-box .box-cover {
    z-index: 4; /* Topmost layer */
    background-color: #4a4a4a; /* Dark grey default cover */
    opacity: 1;
    transform: scale(1);
}

.prize-box.revealed .box-cover {
    opacity: 0; /* Hide general cover on reveal */
    transform: scale(1.2) rotateY(-180deg); /* Zoom out and flip */
}

/* Styling for unselected boxes after one is revealed */
.prize-box.unselected-hidden {
    opacity: 0.3; /* Make them semi-transparent */
    transform: scale(0.9); /* Slightly shrink them */
    pointer-events: none; /* Disable interaction */
}


/* Message Area Styling */
.message-area {
    margin-top: 25px;
    padding: 15px;
    border-radius: 8px;
    background-color: #e9ecef;
    color: #333;
    font-size: 1.1em;
    min-height: 50px; /* Ensure it has some height */
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
}

.message-area p {
    margin: 5px 0;
}

.message-area .error-message {
    color: #dc3545; /* Red for errors */
    font-weight: bold;
}

.message-area .success-message {
    color: #28a745; /* Green for success */
    font-weight: bold;
}

.message-area .info-message {
    color: #007bff; /* Blue for info */
}

.message-area .copy-success-message {
    color: #28a745;
    font-weight: bold;
    animation: fadeOut 3s forwards; /* Fade out after 3 seconds */
}

.message-area .copy-error-message {
    color: #dc3545;
    font-weight: bold;
}

@keyframes fadeOut {
    from { opacity: 1; }
    to { opacity: 0; }
}

/* Spinner for loading states */
.spinner {
    border: 4px solid rgba(0, 0, 0, 0.1);
    border-left-color: #007bff;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    animation: spin 1s linear infinite;
    display: inline-block;
    vertical-align: middle;
    margin-left: 10px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Button Styling */
.button-container {
    margin-top: 20px;
    display: flex;
    justify-content: center;
    flex-wrap: wrap; /* Allow buttons to wrap */
    gap: 15px; /* Space between buttons */
}

.button-container button,
.button-container .view-cart-button {
    background-color: #007bff; /* Blue */
    color: white;
    padding: 12px 25px;
    border: none;
    border-radius: 5px;
    font-size: 1.1em;
    cursor: pointer;
    transition: background-color 0.3s ease, transform 0.2s ease;
    margin: 0 10px;
    display: inline-block; /* Ensure buttons are side-by-side */
}

.button-container button:hover {
    background-color: #0056b3;
    transform: translateY(-2px);
}

.button-container button#copyCouponButton {
    background-color: #6c757d; /* Grey for copy button */
}

.button-container button#copyCouponButton:hover {
    background-color: #5a6268;
}

.button-container .view-cart-button {
    background-color: #ff9800; /* Orange for view cart */
    text-decoration: none; /* Remove underline for links styled as buttons */
    color: white; /* Ensure text is white */
}

.button-container .view-cart-button:hover {
    background-color: #e68900;
}


/* Responsive Adjustments */
@media (max-width: 768px) {
    .boxes-container {
        flex-direction: column;
        align-items: center;
    }
    .prize-box {
        width: var(--prize-box-size, 150px); /* Use CSS variable, fallback to 150px */
        height: var(--prize-box-size, 150px); /* Use CSS variable, fallback to 150px */
    }
    .prize-box .box-number {
        font-size: 3em;
    }
    .box-unopened-image .box-number {
        font-size: 3em;
    }
}
@media (max-width: 480px) {
    .game-container h1 {
        font-size: 1.8em;
    }
    .game-container p {
        font-size: 1em;
    }
    .prize-box {
        width: var(--prize-box-size, 120px); /* Use CSS variable, fallback to 120px */
        height: var(--prize-box-size, 120px); /* Use CSS variable, fallback to 120px */
    }
    .prize-box .box-number {
        font-size: 2.5em;
    }
    .box-unopened-image .box-number {
        font-size: 2.5em;
    }
    .button-container button,
    .button-container .view-cart-button {
        padding: 10px 20px;
        font-size: 1em;
    }
}

/* NEW: Styles for 3-across layout */
.boxes-container.boxes-3-across {
    display: grid;
    /* Use CSS variable for column width, ensuring 3 columns */
    grid-template-columns: repeat(3, minmax(calc(var(--prize-box-size, 220px) - 20px), 1fr)); /* Adjusted for 3 columns, slightly smaller for spacing */
    gap: 20px; /* Slightly reduced gap to help fit */
    justify-items: center; /* Center items within their grid cells */
    max-width: calc(3 * var(--prize-box-size, 220px) + 2 * 20px); /* Calculate max-width based on box size and gap */
    margin-left: auto;
    margin-right: auto;
}

.boxes-container.boxes-3-across .prize-box {
    width: var(--prize-box-size, 220px); /* Use CSS variable for width */
    height: var(--prize-box-size, 220px); /* Use CSS variable for height */
}

/* Adjust for smaller screens when 3-across is active */
@media (max-width: 768px) { /* Adjusted breakpoint for 3 columns */
    .boxes-container.boxes-3-across {
        grid-template-columns: repeat(2, minmax(calc(var(--prize-box-size, 180px) - 15px), 1fr)); /* 2 columns on medium screens */
        gap: 15px;
        max-width: calc(2 * var(--prize-box-size, 180px) + 1 * 15px); /* Adjusted max-width for 2 columns */
    }
    .boxes-container.boxes-3-across .prize-box {
        width: var(--prize-box-size, 180px); /* Adjusted width */
        height: var(--prize-box-size, 180px); /* Adjusted height */
    }
}

@media (max-width: 480px) { /* Adjusted breakpoint for single column on very small screens */
    .boxes-container.boxes-3-across {
        grid-template-columns: 1fr; /* Single column on small screens */
        gap: 15px;
        max-width: var(--prize-box-size, 250px); /* Adjusted max-width for single column */
    }
    .boxes-container.boxes-3-across .prize-box {
        width: var(--prize-box-size, 250px); /* Make boxes take up more width */
        height: var(--prize-box-size, 250px); /* Maintain square aspect ratio */
    }
}


/* Confetti Effect */
.confetti-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none; /* Allows clicks to pass through */
    overflow: hidden; /* Ensures confetti stays within bounds */
    z-index: 9999; /* Ensure confetti is on top */
}

.confetti {
    position: absolute;
    width: 10px;
    height: 10px;
    background-color: #f00; /* Default color, will be randomized by JS */
    opacity: 0;
    animation: confetti-fall 3s forwards;
    border-radius: 2px;
}

@keyframes confetti-fall {
    0% {
        opacity: 0;
        transform: translate(0, 0) rotate(0deg);
    }
    10% {
        opacity: 1;
    }
    100% {
        opacity: 0;
        transform: translate(var(--x), var(--y)) rotate(var(--deg));
    }
}
