/* Game Fullscreen Styles */
.game-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background-color: #242424;
    border-top: 1px solid rgba(16, 185, 129, 0.2);
    padding: 0.75rem 1rem;
    border-radius: 0 0 0.75rem 0.75rem;
}

/* Animation for fullscreen button suggestion */
@keyframes pulse {
    0% { opacity: 0.7; }
    50% { opacity: 1; }
    100% { opacity: 0.7; }
}

.animate-pulse {
    animation: pulse 2s infinite ease-in-out;
}


.fullscreen-exit-btn {
    position: fixed;
    top: 20px;
    left: 0;
    transform: translateX(-70%); /* Only define transform once */
    z-index: 9999;
    background-color: rgba(16, 185, 129, 0.9);
    color: white;
    width: 2.5rem;
    height: 5rem;
    border-radius: 0 2.5rem 2.5rem 0;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
    opacity: 0.7;
    transition: all 0.3s ease;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-left: none;
    transform-origin: left center;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.fullscreen-exit-btn i {
    font-size: 1.2rem;
    margin-left: 0.5rem;
}

.fullscreen-exit-btn:hover {
    opacity: 1;
    transform: translateX(0);
}

/* Initially hide the exit button */
.fullscreen-exit-btn {
    display: none;
    pointer-events: auto;
}

/* Styles for fullscreen mode */
#gameContainer:fullscreen {
    background-color: #1A1A1A;
    padding: 0;
}

#gameContainer:-webkit-full-screen {
    background-color: #1A1A1A;
    padding: 0;
}

#gameContainer:-moz-full-screen {
    background-color: #1A1A1A;
    padding: 0;
}

/* Make sure the iframe takes up the full space in fullscreen mode */
#gameContainer:fullscreen #gameEmbed,
#gameContainer:-webkit-full-screen #gameEmbed,
#gameContainer:-moz-full-screen #gameEmbed {
    width: 100%;
    height: 100%;
}

/* Show the exit button in fullscreen mode */
#gameContainer:fullscreen .fullscreen-exit-btn,
#gameContainer:-webkit-full-screen .fullscreen-exit-btn,
#gameContainer:-moz-full-screen .fullscreen-exit-btn {
    display: flex;
}

/* Active state for the exit button */
.fullscreen-exit-btn.active {
    transform: translateX(0);
}

/* When not hovered, slide back to hidden position */
.fullscreen-exit-btn.active:not(:hover) {
    transform: translateX(-70%);
}

/* Expanded state for mobile (when clicked once) */
.fullscreen-exit-btn.expanded {
    transform: translateX(0);
    opacity: 1;
}

/* iOS Fullscreen Mode */
.ios-fullscreen-mode {
    overflow: hidden;
    position: fixed;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
    z-index: 9999;
    background-color: #1A1A1A;
}

.ios-fullscreen {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: 100% !important;
    height: 100% !important;
    z-index: 10000 !important;
    background-color: #1A1A1A !important;
    padding: 0 !important;
    margin: 0 !important;
    border-radius: 0 !important;
}

.ios-fullscreen #gameEmbed {
    width: 100% !important;
    height: 100% !important;
}

.ios-fullscreen-message {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background-color: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 10px 20px;
    border-radius: 8px;
    z-index: 10001;
    text-align: center;
    max-width: 90%;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
    transition: opacity 0.5s ease;
}

.ios-fullscreen-message p {
    margin-bottom: 8px;
    font-size: 14px;
}

.ios-fullscreen-message button {
    background-color: rgba(16, 185, 129, 0.9);
    border: none;
    color: white;
    padding: 5px 15px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
}

/* Landscape orientation styles */
@media (orientation: landscape) {
    /* Make sure the fullscreen button is more visible in landscape mode */
    #fullscreenBtn {
        background-color: rgba(16, 185, 129, 0.9);
        color: white;
    }

    /* Ensure the exit button is properly positioned in landscape mode */
    .fullscreen-exit-btn {
        top: 10px;
        height: 4rem;
        opacity: 0.9;
    }

    /* Make sure the exit button is more visible in landscape mode */
    .fullscreen-exit-btn.active {
        transform: translateX(-50%);
    }
}

/* Mobile-specific styles */
@media (max-width: 768px) {
    .fullscreen-exit-btn {
        width: 2.5rem;
        height: 5rem;
        transform: translateX(-70%);
        top: 10px; /* Slightly closer to the top on mobile */
        transition: transform 0.3s ease, opacity 0.3s ease; /* Specify exact properties */
        -webkit-tap-highlight-color: transparent; /* Remove tap highlight on mobile */
        touch-action: manipulation; /* Improve touch handling */
        will-change: transform, opacity; /* Optimize for animations */
        pointer-events: auto; /* Ensure touch events are captured */
    }

    .fullscreen-exit-btn i {
        margin-left: 0.5rem;
    }

    /* Ensure the button is always visible on the left edge */
    .fullscreen-exit-btn.active {
        transform: translateX(-70%);
        opacity: 0.9; /* Make it more visible */
    }

    /* When expanded (after first click) */
    .fullscreen-exit-btn.expanded {
        transform: translateX(0) !important; /* Force this to override any inline styles */
        opacity: 1 !important;
        box-shadow: 0 0 15px rgba(0, 0, 0, 0.5); /* Add shadow for better visibility */
    }

    /* Ensure smooth transition when collapsing back */
    .fullscreen-exit-btn.expanded.collapsing {
        transform: translateX(-70%) !important;
        opacity: 0.8;
        transition: transform 0.3s ease, opacity 0.3s ease;
    }

    /* Ensure the button properly resets when exiting fullscreen */
    .fullscreen-exit-btn:not(.expanded):not(.active) {
        transform: translateX(-70%);
        opacity: 0.7;
    }

    /* Improve visibility of the exit button on mobile */
    .ios-fullscreen .fullscreen-exit-btn {
        top: 10px;
        width: 2.5rem;
        height: 4rem;
        opacity: 0.9;
    }

    /* Make sure the button is more visible when active on iOS */
    .ios-fullscreen .fullscreen-exit-btn.active {
        transform: translateX(-50%);
    }

    /* When expanded on iOS */
    .ios-fullscreen .fullscreen-exit-btn.expanded {
        transform: translateX(0) !important;
        opacity: 1 !important;
    }

    /* Ensure iOS transitions work properly */
    .ios-fullscreen .fullscreen-exit-btn.expanded.collapsing {
        transform: translateX(-50%) !important;
        opacity: 0.8;
        transition: transform 0.3s ease, opacity 0.3s ease;
    }

    /* Ensure the button properly resets when exiting fullscreen on iOS */
    .ios-fullscreen .fullscreen-exit-btn:not(.expanded):not(.active) {
        transform: translateX(-50%);
        opacity: 0.7;
    }
}
