/* Run Ape - Mobile Optimizations */

/* General mobile improvements */
html, body {
    overscroll-behavior: none; /* Prevent pull-to-refresh */
    touch-action: manipulation; /* Disable double-tap to zoom */
    -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
    -webkit-user-select: none; /* Prevent selection on iOS */
    user-select: none; /* Prevent selection */
    -webkit-touch-callout: none; /* Prevent callout on iOS */
    overflow: hidden !important;
    -webkit-overflow-scrolling: auto;
    scrollbar-width: none; /* Firefox */
    -ms-overflow-style: none; /* Internet Explorer and Edge */
}

#gameContainer {
    touch-action: manipulation;
    -webkit-user-select: none;
    user-select: none;
}

#gameCanvas {
    touch-action: none; /* Prevent browser handling of touch events */
    image-rendering: pixelated; /* Keep pixel art crisp when scaled */
    image-rendering: -webkit-optimize-contrast; /* For Safari */
}

/* Better touch targets */
.arcade-button {
    min-height: 44px;
    min-width: 44px;
    padding: 12px 20px;
}

/* Add touch controls hint */
.control-text {
    background-color: rgba(0, 0, 0, 0.6);
    border: 1px solid #4444dd;
    border-radius: 5px;
    padding: 8px;
    font-size: 12px;
    text-align: center;
    margin-top: 10px;
    box-shadow: 0 0 8px rgba(255, 0, 0, 0.3);
}

/* Touch indicator styling */
.touch-indicator {
    position: absolute;
    display: none;
    color: rgba(255, 255, 255, 0.3);
    font-family: 'Press Start 2P', monospace;
    font-size: 1.5rem;
    text-align: center;
    pointer-events: none;
    z-index: 100;
}

#topTouchIndicator {
    top: 25%;
    left: 0;
    width: 100%;
}

#bottomTouchIndicator {
    bottom: 25%;
    left: 0;
    width: 100%;
}

.top-active #topTouchIndicator {
    display: block;
    color: rgba(255, 255, 255, 0.6);
}

.bottom-active #bottomTouchIndicator {
    display: block;
    color: rgba(255, 255, 255, 0.6);
}



/* Remove scroll bars from body and html */
html::-webkit-scrollbar, 
body::-webkit-scrollbar,
*::-webkit-scrollbar {
    display: none;
    width: 0;
    height: 0;
}

/* Base mobile styles */
@media (max-width: 768px) {
    html, body {
        overflow: hidden !important;
        scrollbar-width: none;
        -ms-overflow-style: none;
    }
    
    html::-webkit-scrollbar, 
    body::-webkit-scrollbar {
        display: none;
    }
    
    #gameContainer {
        position: relative;
        width: 100%;
        height: 100vh;
        margin: 0;
        padding: 0;
        overflow: hidden;
    }
    
    .overlay-content {
        padding: 1rem;
        overflow: hidden;
    }
    
    .arcade-title {
        font-size: 2rem;
    }
    
    .arcade-subtitle {
        font-size: 1rem;
    }
    
    .buttons {
        display: flex;
        flex-direction: column;
        width: 100%;
        align-items: center;
    }
    
    .arcade-button {
        margin: 0.5rem;
        padding: 0.75rem 1rem;
        font-size: 0.8rem;
        min-height: 44px; /* Minimum touch target size */
    }

    /* Hide unnecessary elements on mobile */
    .credits {
        display: none;
    }
    
    /* Improved leaderboard modal for mobile */
    #leaderboardModal {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        width: 100vw !important;
        height: 100vh !important;
        z-index: 3000 !important;
        display: flex !important;
        justify-content: center !important;
        align-items: center !important;
        background-color: rgba(0, 0, 0, 0.8) !important;
        overflow: hidden !important;
    }
    
    .modal-content {
        width: 95vw !important;
        max-width: none !important;
        height: auto !important;
        max-height: 85vh !important;
        margin: 0 auto !important;
        padding: 15px !important;
        box-sizing: border-box !important;
        overflow: hidden !important;
        position: relative !important;
        border-radius: 10px !important;
        background-color: #000 !important;
        border: 2px solid #ff0000 !important;
        box-shadow: 0 0 20px rgba(255, 0, 0, 0.5) !important;
        display: flex !important;
        flex-direction: column !important;
    }
    
    .modal-header {
        padding-bottom: 10px !important;
        margin-bottom: 10px !important;
        border-bottom: 1px solid rgba(255, 0, 0, 0.3) !important;
        text-align: center !important;
        flex-shrink: 0 !important;
    }
    
    .modal-header h2 {
        font-size: clamp(1rem, 4vw, 1.4rem) !important;
        margin: 0 !important;
        color: #ff0000 !important;
        text-align: center !important;
    }
    
    .close {
        position: absolute !important;
        top: 10px !important;
        right: 15px !important;
        font-size: clamp(24px, 6vw, 32px) !important;
        line-height: 1 !important;
        color: #ff0000 !important;
        cursor: pointer !important;
        z-index: 1 !important;
    }
    
    #leaderboardContent {
        max-height: 70vh !important;
        overflow-y: auto !important;
        overflow-x: hidden !important;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: thin;
        scrollbar-color: #ff0000 rgba(255, 0, 0, 0.1);
        padding: 0 !important;
        margin: 0 !important;
        flex: 1 !important;
    }
    
    #leaderboardContent::-webkit-scrollbar {
        width: 6px !important;
    }
    
    #leaderboardContent::-webkit-scrollbar-track {
        background: rgba(255, 0, 0, 0.1) !important;
        border-radius: 3px !important;
    }
    
    #leaderboardContent::-webkit-scrollbar-thumb {
        background: #ff0000 !important;
        border-radius: 3px !important;
    }
    
    #leaderboardContent table {
        width: 100% !important;
        font-size: clamp(0.6rem, 2.5vw, 0.75rem) !important;
        table-layout: fixed !important;
        margin: 0 !important;
        border-collapse: collapse !important;
    }
    
    #leaderboardContent th,
    #leaderboardContent td {
        padding: clamp(0.3rem, 1.5vw, 0.5rem) clamp(0.2rem, 1vw, 0.3rem) !important;
        text-align: center !important;
        white-space: nowrap !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
        border-bottom: 1px solid rgba(255, 0, 0, 0.2) !important;
        line-height: 1.2 !important;
    }
    
    #leaderboardContent th {
        background-color: rgba(255, 0, 0, 0.1) !important;
        color: #ff0000 !important;
        font-weight: bold !important;
        font-size: clamp(0.55rem, 2.2vw, 0.7rem) !important;
    }
    
    #leaderboardContent td:nth-child(3) {
        text-align: left !important;
    }
    
    /* Responsive column widths for different screen sizes */
    #leaderboardContent th:nth-child(1), 
    #leaderboardContent td:nth-child(1) {
        width: 10% !important; /* Rank column - smaller */
    }
    
    #leaderboardContent th:nth-child(2),
    #leaderboardContent td:nth-child(2) {
        width: 12% !important; /* Ape column - smaller */
    }
    
    #leaderboardContent th:nth-child(3),
    #leaderboardContent td:nth-child(3) {
        width: 53% !important; /* User column - larger */
    }
    
    #leaderboardContent th:nth-child(4),
    #leaderboardContent td:nth-child(4) {
        width: 25% !important; /* Score column */
    }

    /* Extra small screens adjustments */
    @media (max-width: 350px) and (orientation: portrait) {
        .modal-content {
            width: 98vw !important;
            padding: 10px !important;
        }
        
        #leaderboardContent table {
            font-size: 0.55rem !important;
        }
        
        #leaderboardContent th {
            font-size: 0.5rem !important;
        }
        
        #leaderboardContent th,
        #leaderboardContent td {
            padding: 0.25rem 0.15rem !important;
        }
        
        /* Adjust column widths for very small screens */
        #leaderboardContent th:nth-child(1), 
        #leaderboardContent td:nth-child(1) {
            width: 8% !important;
        }
        
        #leaderboardContent th:nth-child(2),
        #leaderboardContent td:nth-child(2) {
            width: 10% !important;
        }
        
        #leaderboardContent th:nth-child(3),
        #leaderboardContent td:nth-child(3) {
            width: 57% !important;
        }
        
        #leaderboardContent th:nth-child(4),
        #leaderboardContent td:nth-child(4) {
            width: 25% !important;
        }
    }
    
    /* Canvas touch zones with visual indicators */
    #gameContainer::before {
        content: '';
        position: absolute;
        width: 100%;
        height: 50%;
        top: 0;
        left: 0;
        background: radial-gradient(ellipse at center 80%, rgba(0, 255, 255, 0.1) 0%, transparent 70%);
        opacity: 0;
        transition: opacity 0.2s;
        pointer-events: none;
        z-index: 4;
    }
    
    #gameContainer::after {
        content: '';
        position: absolute;
        width: 100%;
        height: 50%;
        bottom: 0;
        left: 0;
        background: radial-gradient(ellipse at center 20%, rgba(255, 0, 0, 0.1) 0%, transparent 70%);
        opacity: 0;
        transition: opacity 0.2s;
        pointer-events: none;
        z-index: 4;
    }
    
    #gameContainer.top-active::before {
        opacity: 0.7;
    }
    
    #gameContainer.bottom-active::after {
        opacity: 0.7;
    }
}

/* Portrait Mode - Full screen canvas */
@media (max-width: 768px) and (orientation: portrait) {
    html, body {
        overflow: hidden !important;
        width: 100%;
        height: 100%;
        margin: 0;
        padding: 0;
        position: fixed;
        scrollbar-width: none;
        -ms-overflow-style: none;
    }
    
    html::-webkit-scrollbar, 
    body::-webkit-scrollbar {
        display: none !important;
    }
    
    #gameContainer {
        position: fixed;
        top: 0;
        left: 0;
        width: 100vw;
        height: 100vh;
        overflow: hidden;
        margin: 0;
        padding: 0;
        box-sizing: border-box;
    }

    #gameCanvas {
        position: fixed;
        top: 0;
        left: 0;
        width: 100vh;
        height: 100vw;
        transform: rotate(-90deg);
        transform-origin: center center;
        margin: calc((100vh - 100vw) / 2) calc((100vw - 100vh) / 2);
        object-fit: none !important;
        max-width: none !important;
        max-height: none !important;
        background-image: none !important;
    }

    /* Keep overlays and menus in portrait orientation */
    .overlay {
        position: fixed;
        top: 0;
        left: 0;
        width: 100vw;
        height: 100vh;
        z-index: 1000;
        display: flex;
        justify-content: center;
        align-items: center;
        overflow: hidden;
    }

    .overlay-content {
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        max-width: 90vw;
        max-height: 90vh;
        padding: 1rem;
        overflow: hidden;
        box-sizing: border-box;
    }
    
    .title-section {
        text-align: center;
        margin-bottom: 1rem;
    }
    
    .buttons-section {
        display: flex;
        flex-direction: column;
        align-items: center;
        width: 100%;
    }
    
    .arcade-title {
        font-size: 1.8rem;
        margin-bottom: 0.5rem;
    }
    
    .arcade-subtitle {
        font-size: 0.9rem;
        margin-bottom: 1rem;
    }
    
    .menu-character {
        width: 60px;
        height: 60px;
        margin: 0.5rem auto;
    }
    
    .insert-coin {
        font-size: 0.8rem;
        margin-top: 0.5rem;
    }
    
    .buttons {
        display: flex;
        flex-direction: column;
        align-items: center;
        width: 100%;
        gap: 0.5rem;
    }
    
    .arcade-button {
        padding: 0.8rem 1.5rem;
        font-size: 0.8rem;
        margin: 0.25rem;
        width: 80%;
        max-width: 250px;
    }
    
    .overlay-content p {
        font-size: 0.7rem;
        margin: 0.3rem 0;
        text-align: center;
    }
    
    /* Mobile controls positioned for portrait screen - viewport coordinates (not rotated) */
    .mobile-controls {
        position: fixed;
        width: 100vw;
        height: 100vh;
        top: 0;
        left: 0;
        z-index: 2000;
        pointer-events: none;
    }

    .thumbstick-container {
        position: absolute !important;
        bottom: 20px !important;    /* User's bottom of phone screen */
        right: 20px !important;     /* User's right of phone screen */
        left: auto !important;      /* Override any left positioning */
        top: auto !important;       /* Override any top positioning */
        width: 120px !important;
        height: 120px !important;
        pointer-events: auto;
    }

    .thumbstick-base {
        width: 100% !important;
        height: 100% !important;
        background: radial-gradient(circle, rgba(34, 139, 34, 0.3), rgba(34, 139, 34, 0.1)) !important;
        border: 3px solid rgba(34, 139, 34, 0.6) !important;
        border-radius: 50% !important;
        position: relative !important;
        box-shadow: 0 0 20px rgba(255, 255, 255, 0.2) !important;
    }

    .thumbstick-knob {
        width: 40px !important;
        height: 40px !important;
        background: radial-gradient(circle, #32CD32, #228B22) !important;
        border: 2px solid #FFD700 !important;
        border-radius: 50% !important;
        position: absolute !important;
        top: 50% !important;
        left: 50% !important;
        transform: translate(-50%, -50%) !important;
        transition: all 0.1s ease !important;
        box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3) !important;
    }

    .thumbstick-knob.active {
        background: radial-gradient(circle, #90EE90, #32CD32) !important;
        border-color: #FFA500 !important;
        box-shadow: 0 0 15px rgba(255, 215, 0, 0.6) !important;
    }

    .fire-button {
        position: absolute !important;
        top: 20px !important;       /* User's top of phone screen */
        right: 20px !important;     /* User's right of phone screen */
        left: auto !important;      /* Override any left positioning */
        bottom: auto !important;    /* Override any bottom positioning */
        width: 80px !important;
        height: 80px !important;
        pointer-events: auto;
    }

    .fire-button-inner {
        width: 100% !important;
        height: 100% !important;
        background: radial-gradient(circle, #ff4444 0%, #cc0000 100%) !important;
        border: 3px solid #ffffff !important;
        border-radius: 50% !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        font-size: 24px !important;
        color: white !important;
        text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.8) !important;
        box-shadow: 0 4px 15px rgba(255, 68, 68, 0.4) !important;
        transition: all 0.1s ease !important;
        user-select: none !important;
    }

    .fire-button-inner:active,
    .fire-button-inner.active {
        transform: scale(0.9) !important;
        background: radial-gradient(circle, #ff6666 0%, #ff0000 100%) !important;
        box-shadow: 0 0 20px rgba(255, 0, 0, 0.8) !important;
    }

    /* Perfect leaderboard modal centering for portrait */
    #leaderboardModal {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        width: 100vw !important;
        height: 100vh !important;
        z-index: 5000 !important;
        display: flex !important;
        justify-content: center !important;
        align-items: center !important;
        background-color: rgba(0, 0, 0, 0.9) !important;
        overflow: hidden !important;
        padding: 10px !important;
        margin: 0 !important;
        box-sizing: border-box !important;
    }

    .modal-content {
        width: 95vw !important;
        max-width: none !important;
        height: auto !important;
        max-height: 85vh !important;
        margin: 0 auto !important;
        padding: 15px !important;
        box-sizing: border-box !important;
        overflow: hidden !important;
        position: relative !important;
        border-radius: 10px !important;
        background-color: #000 !important;
        border: 2px solid #ff0000 !important;
        box-shadow: 0 0 20px rgba(255, 0, 0, 0.5) !important;
        display: flex !important;
        flex-direction: column !important;
    }

    .modal-header {
        padding-bottom: 10px !important;
        margin-bottom: 10px !important;
        border-bottom: 1px solid rgba(255, 0, 0, 0.3) !important;
        text-align: center !important;
        flex-shrink: 0 !important;
    }

    .modal-header h2 {
        font-size: clamp(1rem, 4vw, 1.4rem) !important;
        margin: 0 !important;
        color: #ff0000 !important;
        text-align: center !important;
    }

    .close {
        position: absolute !important;
        top: 10px !important;
        right: 15px !important;
        font-size: clamp(24px, 6vw, 32px) !important;
        line-height: 1 !important;
        color: #ff0000 !important;
        cursor: pointer !important;
        z-index: 1 !important;
    }

    #leaderboardContent {
        max-height: 70vh !important;
        overflow-y: auto !important;
        overflow-x: hidden !important;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: thin;
        scrollbar-color: #ff0000 rgba(255, 0, 0, 0.1);
        padding: 0 !important;
        margin: 0 !important;
        flex: 1 !important;
    }

    #leaderboardContent::-webkit-scrollbar {
        width: 6px !important;
    }

    #leaderboardContent::-webkit-scrollbar-track {
        background: rgba(255, 0, 0, 0.1) !important;
        border-radius: 3px !important;
    }

    #leaderboardContent::-webkit-scrollbar-thumb {
        background: #ff0000 !important;
        border-radius: 3px !important;
    }

    #leaderboardContent table {
        width: 100% !important;
        font-size: clamp(0.6rem, 2.5vw, 0.75rem) !important;
        table-layout: fixed !important;
        margin: 0 !important;
        border-collapse: collapse !important;
    }

    #leaderboardContent th,
    #leaderboardContent td {
        padding: clamp(0.3rem, 1.5vw, 0.5rem) clamp(0.2rem, 1vw, 0.3rem) !important;
        text-align: center !important;
        white-space: nowrap !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
        border-bottom: 1px solid rgba(255, 0, 0, 0.2) !important;
        line-height: 1.2 !important;
    }

    #leaderboardContent th {
        background-color: rgba(255, 0, 0, 0.1) !important;
        color: #ff0000 !important;
        font-weight: bold !important;
        font-size: clamp(0.55rem, 2.2vw, 0.7rem) !important;
    }

    #leaderboardContent td:nth-child(3) {
        text-align: left !important;
    }

    /* Responsive column widths for different screen sizes */
    #leaderboardContent th:nth-child(1), 
    #leaderboardContent td:nth-child(1) {
        width: 10% !important; /* Rank column - smaller */
    }
    
    #leaderboardContent th:nth-child(2),
    #leaderboardContent td:nth-child(2) {
        width: 12% !important; /* Ape column - smaller */
    }
    
    #leaderboardContent th:nth-child(3),
    #leaderboardContent td:nth-child(3) {
        width: 53% !important; /* User column - larger */
    }
    
    #leaderboardContent th:nth-child(4),
    #leaderboardContent td:nth-child(4) {
        width: 25% !important; /* Score column */
    }

    /* Extra small screens adjustments */
    @media (max-width: 350px) and (orientation: portrait) {
        .modal-content {
            width: 98vw !important;
            padding: 10px !important;
        }
        
        #leaderboardContent table {
            font-size: 0.55rem !important;
        }
        
        #leaderboardContent th {
            font-size: 0.5rem !important;
        }
        
        #leaderboardContent th,
        #leaderboardContent td {
            padding: 0.25rem 0.15rem !important;
        }
        
        /* Adjust column widths for very small screens */
        #leaderboardContent th:nth-child(1), 
        #leaderboardContent td:nth-child(1) {
            width: 8% !important;
        }
        
        #leaderboardContent th:nth-child(2),
        #leaderboardContent td:nth-child(2) {
            width: 10% !important;
        }
        
        #leaderboardContent th:nth-child(3),
        #leaderboardContent td:nth-child(3) {
            width: 57% !important;
        }
        
        #leaderboardContent th:nth-child(4),
        #leaderboardContent td:nth-child(4) {
            width: 25% !important;
        }
    }

    /* Game over screen elements */
    .game-over-title {
        font-size: 1.3rem;
        margin-bottom: 0.5rem;
    }

    #finalScore {
        font-size: 1rem;
        margin: 0.5rem 0;
    }

    .continue-text, .countdown {
        font-size: 0.8rem;
        margin: 0.3rem 0;
    }
}

/* Base landscape mode layout */
@media (max-width: 768px) and (orientation: landscape) {
    html, body {
        overflow: hidden !important;
        width: 100%;
        height: 100%;
        margin: 0;
        padding: 0;
        scrollbar-width: none;
        -ms-overflow-style: none;
    }
    
    html::-webkit-scrollbar, 
    body::-webkit-scrollbar {
        display: none !important;
    }
    

    
    #gameContainer {
        width: 100%;
        height: 100vh;
        max-width: 100vw;
        max-height: 100vh;
        overflow: hidden;
        margin: 0;
        padding: 0;
        box-sizing: border-box;
    }
    
    #gameCanvas {
        width: 100%;
        height: 100%;
        max-width: 100vw;
        max-height: 100vh;
        object-fit: contain;
        box-sizing: border-box;
    }
    
    /* Improved landscape layout for menus */
    .overlay {
        display: flex;
        justify-content: center;
        align-items: center;
        overflow: hidden;
    }
    
    .overlay-content {
        display: flex;
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
        max-width: 95%;
        max-height: 95vh;
        padding: 1rem;
        overflow: hidden;
    }
    
    .title-section {
        width: 60%;
        text-align: center;
    }
    
    .buttons-section {
        width: 40%;
        display: flex;
        flex-direction: column;
        justify-content: center;
    }
    
    .arcade-title {
        font-size: 1.8rem;
        margin-bottom: 0.5rem;
    }
    
    .title-letter {
        font-size: 1.8rem;
    }
    
    .arcade-subtitle {
        font-size: 0.8rem;
        margin-bottom: 0.5rem;
    }
    
    .overlay-content p {
        font-size: 0.7rem;
        margin: 0.5rem 0;
    }
    
    .buttons {
        flex-direction: column;
        gap: 0.5rem;
    }
    
    .arcade-button {
        padding: 0.6rem 1rem;
        font-size: 0.7rem;
        margin: 0.3rem;
        width: 100%;
    }
    
    .menu-character {
        width: 80px;
        height: 80px;
        margin: 0.5rem auto;
    }
    
    .insert-coin {
        font-size: 0.8rem;
        margin-top: 0.5rem;
    }
    
    /* Leaderboard modal for landscape mode */
    #leaderboardModal {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        width: 100vw !important;
        height: 100vh !important;
        z-index: 5000 !important;
        display: flex !important;
        justify-content: center !important;
        align-items: center !important;
        background-color: rgba(0, 0, 0, 0.9) !important;
        overflow: hidden !important;
    }
    
    .modal-content {
        width: 70vw !important;
        max-width: 500px !important;
        height: auto !important;
        max-height: 80vh !important;
        margin: 0 !important;
        padding: 20px !important;
        box-sizing: border-box !important;
        overflow: hidden !important;
        position: relative !important;
        border-radius: 8px !important;
    }
    
    #leaderboardContent {
        max-height: 50vh !important;
        overflow-y: auto !important;
        overflow-x: hidden !important;
        -webkit-overflow-scrolling: touch;
    }
}

/* Special layout for larger phones (like iPhone 14 Pro Max) in landscape orientation */
@media (max-width: 1000px) and (max-height: 600px) and (orientation: landscape) {
    html, body {
        overflow: hidden !important;
        width: 100%;
        height: 100%;
        margin: 0;
        padding: 0;
    }
    
    #gameContainer {
        width: 100%;
        height: 100vh;
        max-width: 100vw;
        max-height: 100vh;
        overflow: hidden;
        margin: 0;
        padding: 0;
        box-sizing: border-box;
    }
    
    /* Force landscape mode for the menu on larger phones */
    .overlay-content {
        display: flex;
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
        max-width: 95%;
        max-height: 90vh;
        padding: 0.5rem;
        margin: 0 auto;
        box-sizing: border-box;
        overflow: hidden;
    }
    
    .title-section {
        width: 60%;
        text-align: center;
    }
    
    .buttons-section {
        width: 40%;
        display: flex;
        flex-direction: column;
        justify-content: center;
    }
    
    .arcade-title {
        font-size: 2rem;
        margin-bottom: 0.5rem;
    }
    
    .arcade-subtitle {
        font-size: 1rem;
        margin-bottom: 0.5rem;
    }
    
    .buttons {
        flex-direction: column;
        gap: 0.8rem;
    }
    
    .arcade-button {
        padding: 0.8rem 1.2rem;
        font-size: 0.9rem;
        margin: 0.3rem;
        width: 100%;
    }
    

    
    /* Fix for overlapping screens - only display the active screen */
    #gameContainer {
        display: block !important;
    }
    
    /* Set proper stacking order for overlays */
    .overlay {
        z-index: 10;
    }
    
    #startScreen {
        z-index: 11; /* Higher than game over screen */
    }
    
    #gameOverScreen {
        z-index: 10;
        display: none !important; /* Hidden by default */
    }
    
    /* Override when game is over */
    body.game-over #startScreen {
        display: none !important;
    }
    
    body.game-over #gameOverScreen {
        display: flex !important;
    }
    
    /* Leaderboard modal should be on top of everything */
    #leaderboardModal {
        z-index: 200 !important; /* Much higher than other screens */
    }
    
    /* Ensure leaderboard content is scrollable and sized correctly in landscape */
    .modal-content {
        max-height: 85vh;
        max-width: 90vw;
        width: 80%;
        overflow-y: auto;
        overflow-x: hidden;
        margin: 0 auto;
        box-sizing: border-box;
        position: relative;
    }
    
    /* Ensure table is readable in landscape mode */
    #leaderboardContent table {
        width: 100%;
        min-width: 280px;
        font-size: 0.8rem;
        table-layout: fixed;
    }
    
    #leaderboardContent th,
    #leaderboardContent td {
        padding: 0.5rem;
        text-align: center;
    }
    
    #leaderboardContent td:nth-child(3) {
        text-align: left; /* Align usernames to the left */
    }
    
    .menu-character {
        width: 100px;
        height: 100px;
        margin: 0.8rem auto;
    }
    
    .game-over-title {
        font-size: 2rem;
    }
    
    #finalScore {
        font-size: 1.2rem;
        margin: 0.8rem 0;
    }
    
    .continue-text, .countdown {
        font-size: 1.2rem;
    }
}

/* Ensure modals are visible even when game over is active */
body.game-over #leaderboardModal {
    display: block !important;
    z-index: 200 !important; /* Higher than game over screen */
}

/* iPhone X, 11, 12, 13 notch support */
@supports (padding: max(0px)) {
    .modal-content, 
    .overlay-content,
    #gameContainer,
    #scoreContainer,
    #difficultyBar {
        padding-left: max(1rem, env(safe-area-inset-left));
        padding-right: max(1rem, env(safe-area-inset-right));
        padding-top: max(1rem, env(safe-area-inset-top));
        padding-bottom: max(1rem, env(safe-area-inset-bottom));
    }
}

/* iPhone X, 11, 12, 13 landscape orientation */
@media (max-width: 1000px) and (orientation: landscape) {
    html, body {
        overflow: hidden !important;
    }
    
    #gameContainer {
        width: 100%;
        height: 100vh;
        max-width: 100vw;
        max-height: 100vh;
        overflow: hidden;
        margin: 0;
        padding: 0;
        box-sizing: border-box;
    }
    
    @supports (padding: max(0px)) {
        #gameCanvas {
            padding-left: min(env(safe-area-inset-left), 10px);
            padding-right: min(env(safe-area-inset-right), 10px);
            box-sizing: border-box;
            max-width: 100vw;
            max-height: 100vh;
        }
        
        .overlay-content {
            padding-left: max(0.5rem, env(safe-area-inset-left));
            padding-right: max(0.5rem, env(safe-area-inset-right));
            box-sizing: border-box;
        }
    }
}
