* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    height: 100%;
    /* Prevent iOS bounce effect and scrolling */
    overflow: hidden;
    -webkit-overflow-scrolling: touch;
    position: fixed;
    width: 100%;
    height: 100%;
}

body {
    font-family: 'Courier New', monospace;
    background: #1a1a2e;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    color: #eee;
    margin: 0;
    padding: 10px;
    box-sizing: border-box;
    /* Prevent unwanted touch behaviors */
    touch-action: manipulation;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -khtml-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    /* Prevent scrolling */
    overflow: hidden;
    position: fixed;
    width: 100%;
    height: 100%;
}

/* Mobile Detection */
@media (max-width: 768px) {
    body {
        padding: 5px;
        min-height: 100vh;
    }
}

.game-container {
    text-align: center;
    background: rgba(0, 0, 0, 0.6);
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
    max-width: 100%;
    width: 100%;
}

@media (max-width: 768px) {
    .game-container {
        padding: 10px;
        border-radius: 4px;
        width: 100vw;
        max-width: 100vw;
        margin: 0;
    }
}

.header {
    margin-bottom: 20px;
}

h1 {
    font-size: 2.5em;
    color: #4ecca3;
    margin-bottom: 10px;
}

.score-container {
    display: flex;
    justify-content: space-around;
    font-size: 1.2em;
    margin-bottom: 10px;
    gap: 20px;
}

.score-container > span {
    color: #eeeeee;
    background: rgba(78, 204, 163, 0.2);
    padding: 8px 20px;
    border-radius: 20px;
    border: 2px solid rgba(78, 204, 163, 0.4);
    box-shadow: 0 2px 8px rgba(78, 204, 163, 0.15);
    transition: all 0.3s ease;
}

.score-container > span:hover {
    background: rgba(78, 204, 163, 0.3);
    border-color: rgba(78, 204, 163, 0.6);
    box-shadow: 0 4px 12px rgba(78, 204, 163, 0.25);
}

.score-container #score,
.score-container #lives {
    color: #4ecca3;
    font-weight: bold;
}

#gameCanvas {
    border: 2px solid #4ecca3;
    background: #000;
    display: block;
    margin: 0 auto;
    max-width: 100%;
    height: auto;
    /* Prevent unwanted touch behaviors on canvas */
    touch-action: none;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
    /* iOS specific fixes */
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    /* Smooth touch handling */
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
    will-change: transform;
}

@media (max-width: 768px) {
    #gameCanvas {
        width: 100%;
        max-width: 100vw;
        height: auto;
        border: 1px solid #4ecca3;
    }
}

.controls {
    margin-top: 20px;
}

.controls p {
    margin-bottom: 10px;
    color: #ccc;
}

button {
    background: #4ecca3;
    color: #1a1a2e;
    border: none;
    padding: 10px 30px;
    font-size: 1.1em;
    font-family: 'Courier New', monospace;
    cursor: pointer;
    border-radius: 5px;
    margin: 5px;
    transition: 0.2s;
}

button:hover {
    background: #5fddb4;
    transform: scale(1.05);
}

button:active {
    transform: scale(0.95);
}

.modeButton {
    background: #4ecca3;
    color: #1a1a2e;
    border: none;
    padding: 15px 25px;
    font-size: 1.2em;
    font-family: 'Courier New', monospace;
    cursor: pointer;
    border-radius: 8px;
    margin: 10px;
    transition: 0.3s;
    min-width: 200px;
}

.modeButton:hover {
    background: #5fddb4;
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(78, 204, 163, 0.3);
}

.modeButton:active {
    transform: scale(0.95);
}

#modeSelection {
    margin: 20px 0;
}

#modeSelection h3 {
    color: #4ecca3;
    margin-bottom: 15px;
    font-size: 1.3em;
}

#levelSelection h3 {
    color: #4ecca3;
    margin-bottom: 20px;
    font-size: 1.3em;
}

.level-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 10px;
    margin-bottom: 20px;
    max-width: 600px;
    margin-left: auto;
    margin-right: auto;
}

.levelButton {
    background: #4ecca3;
    color: #1a1a2e;
    border: none;
    padding: 12px 8px;
    font-size: 0.9em;
    font-family: 'Courier New', monospace;
    cursor: pointer;
    border-radius: 5px;
    transition: 0.3s;
    min-height: 50px;
}

.levelButton:hover {
    background: #5fddb4;
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(78, 204, 163, 0.3);
}

.levelButton:active {
    transform: scale(0.95);
}

.boss-level {
    background: #ff6b35 !important;
    color: #fff !important;
    font-weight: bold;
}

.boss-level:hover {
    background: #ff8c42 !important;
    box-shadow: 0 4px 12px rgba(255, 107, 53, 0.4);
}

.final-boss {
    background: #ff0000 !important;
    color: #fff !important;
    font-weight: bold;
    animation: pulse 2s infinite;
}

.final-boss:hover {
    background: #ff3333 !important;
    box-shadow: 0 4px 12px rgba(255, 0, 0, 0.5);
}

@keyframes pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.05); }
    100% { transform: scale(1); }
}

.backButton {
    background: #666;
    color: #fff;
    border: none;
    padding: 10px 20px;
    font-size: 1em;
    font-family: 'Courier New', monospace;
    cursor: pointer;
    border-radius: 5px;
    transition: 0.3s;
}

.backButton:hover {
    background: #777;
    transform: scale(1.05);
}

/* Mobile Touch Controls */
.mobile-controls {
    display: none;
    margin-top: 20px;
    padding: 10px;
}

.touch-area {
    background: rgba(78, 204, 163, 0.1);
    border: 2px dashed #4ecca3;
    border-radius: 15px;
    padding: 30px;
    margin: 0 auto;
    max-width: 90%;
    min-height: 120px;
    display: flex;
    align-items: center;
    justify-content: center;
    touch-action: manipulation;
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    position: relative;
    overflow: hidden;
}

.touch-area:active {
    background: rgba(78, 204, 163, 0.2);
    border-color: #5fddb4;
}

.touch-instructions {
    text-align: center;
    color: #4ecca3;
    font-size: 1.1em;
    font-weight: bold;
    pointer-events: none;
}

.touch-instructions p {
    margin: 5px 0;
    font-family: 'Courier New', monospace;
}

.touch-instructions p:first-child {
    font-size: 1.2em;
}

.touch-instructions p:last-child {
    font-size: 0.9em;
    color: #87CEEB;
}

/* Show/hide controls based on screen size */
@media (max-width: 768px) {
    .mobile-controls {
        display: block;
    }
    
    .desktop-text {
        display: none;
    }
    
    .mobile-text {
        display: block;
    }
    
    /* Make mode buttons side by side on mobile */
    #modeSelection {
        display: flex;
        flex-direction: row;
        justify-content: center;
        align-items: center;
        gap: 10px;
        flex-wrap: wrap;
    }
    
    #modeSelection h3 {
        width: 100%;
        margin-bottom: 15px;
    }
    
    .modeButton {
        flex: 1;
        min-width: 140px;
        max-width: 180px;
        margin: 5px;
    }
}

@media (min-width: 769px) {
    .mobile-controls {
        display: none;
    }
    
    .desktop-text {
        display: block;
    }
    
    .mobile-text {
        display: none;
    }
}

/* Mobile-specific button sizing */
@media (max-width: 480px) {
    .modeButton, .levelButton {
        padding: 12px 15px;
        font-size: 1em;
        min-width: 120px;
        max-width: 160px;
    }
    
    .level-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 8px;
    }
    
    /* Ensure mode buttons stay side by side on very small screens */
    #modeSelection {
        gap: 8px;
    }
    
    .modeButton {
        margin: 3px;
    }
    
    .touch-area {
        min-height: 100px;
        padding: 20px;
    }
    
    .touch-instructions {
        font-size: 1em;
    }
}

/* Menu Page Styles */
.menu-container {
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    align-items: center;
    min-height: 100vh;
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
    padding: 60px 20px 100px 20px;
    text-align: center;
    position: relative;
}

.user-info {
    position: absolute;
    top: 15px;
    right: 20px;
    display: flex;
    align-items: center;
    gap: 15px;
    background: rgba(0, 0, 0, 0.5);
    padding: 10px 20px;
    border-radius: 8px;
    border: 1px solid rgba(78, 204, 163, 0.3);
    z-index: 100;
}

.user-info span {
    color: #4ecca3;
    font-size: 0.9em;
    font-family: 'Courier New', monospace;
}

.logout-btn {
    background: linear-gradient(180deg, #ff4444, #cc0000);
    border: 2px solid #ff4444;
    border-radius: 5px;
    color: white;
    cursor: pointer;
    font-size: 0.85em;
    font-weight: bold;
    padding: 6px 15px;
    text-decoration: none;
    transition: all 0.3s ease;
    font-family: 'Courier New', monospace;
}

.logout-btn:hover {
    background: linear-gradient(180deg, #ff6666, #ff0000);
    box-shadow: 0 0 15px rgba(255, 68, 68, 0.5);
    transform: scale(1.05);
}

@media (max-width: 768px) {
    .user-info {
        position: relative;
        top: auto;
        right: auto;
        margin-bottom: 20px;
        width: 100%;
        max-width: 350px;
        justify-content: space-between;
    }

    .user-info span {
        font-size: 0.8em;
    }

    .logout-btn {
        font-size: 0.75em;
        padding: 5px 12px;
    }
}

.menu-header {
    margin-bottom: 40px;
}

.menu-title {
    font-size: 4em;
    color: #4ecca3;
    margin-bottom: 10px;
    text-shadow: 0 0 20px rgba(78, 204, 163, 0.5);
    font-family: 'Courier New', monospace;
    letter-spacing: 3px;
}

.menu-subtitle {
    font-size: 1.5em;
    color: #87CEEB;
    font-family: 'Courier New', monospace;
    letter-spacing: 1px;
}

.menu-content {
    width: 100%;
    max-width: 800px;
}

.game-mode-selection h2 {
    color: #4ecca3;
    font-size: 2em;
    margin-bottom: 30px;
    font-family: 'Courier New', monospace;
}

.mode-buttons {
    display: flex;
    gap: 30px;
    justify-content: center;
    flex-wrap: wrap;
}

.menu-mode-button {
    background: linear-gradient(145deg, #4ecca3, #3db39a);
    color: #1a1a2e;
    border: none;
    padding: 30px;
    border-radius: 15px;
    cursor: pointer;
    transition: all 0.3s ease;
    min-width: 250px;
    box-shadow: 0 8px 20px rgba(78, 204, 163, 0.3);
    font-family: 'Courier New', monospace;
}

.menu-mode-button:hover {
    transform: translateY(-5px);
    box-shadow: 0 12px 30px rgba(78, 204, 163, 0.5);
    background: linear-gradient(145deg, #5fddb4, #4ecca3);
}

.menu-mode-button:active {
    transform: translateY(-2px);
}

.mode-icon {
    font-size: 3em;
    margin-bottom: 15px;
}

.mode-title {
    font-size: 1.5em;
    font-weight: bold;
    margin-bottom: 10px;
}

.mode-description {
    font-size: 1em;
    opacity: 0.8;
}

.level-selection h2 {
    color: #4ecca3;
    font-size: 2em;
    margin-bottom: 30px;
    font-family: 'Courier New', monospace;
}

.menu-footer {
    margin-top: 40px;
}

.controls-info p {
    color: #87CEEB;
    font-size: 1.1em;
    margin: 10px 0;
    font-family: 'Courier New', monospace;
}

/* Mobile Menu Styles */
@media (max-width: 768px) {
    .menu-title {
        font-size: 2.5em;
        letter-spacing: 2px;
    }
    
    .menu-subtitle {
        font-size: 1.2em;
    }
    
    .mode-buttons {
        flex-direction: column;
        align-items: center;
        gap: 20px;
    }
    
    .menu-mode-button {
        min-width: 200px;
        padding: 25px;
    }
    
    .mode-icon {
        font-size: 2.5em;
    }
    
    .mode-title {
        font-size: 1.3em;
    }
    
    .mode-description {
        font-size: 0.9em;
    }
}

#gameOver {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(200, 50, 50, 0.95);
    padding: 40px;
    border-radius: 8px;
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.5);
}

#gameOver h2 {
    font-size: 3em;
    margin-bottom: 20px;
    color: #fff;
}

#gameOver p {
    font-size: 1.5em;
}
