@import url('https://fonts.googleapis.com/css2?family=Press+Start+2P&display=swap');

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -khtml-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    height: 100%;
    overflow: hidden;
    touch-action: manipulation;
}

body {
    font-family: 'Press Start 2P', monospace;
    background: linear-gradient(135deg, #1a4d00, #2d5016);
    color: white;
    user-select: none;
    position: fixed;
    width: 100%;
    height: 100%;
}

body.mobile {
    -webkit-overflow-scrolling: touch;
}

#game-container {
    position: relative;
    width: 100vw;
    height: 100vh;
    height: 100svh; /* Safe area viewport height */
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
}

.screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    background: linear-gradient(135deg, #1a4d00, #2d5016);
    z-index: 10;
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.screen.hidden {
    display: none;
}

/* Loading Screen */
#loading-screen .loading-content {
    text-align: center;
}

.loading-spinner {
    width: 50px;
    height: 50px;
    border: 4px solid #ff6b00;
    border-top: 4px solid transparent;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 2rem auto;
}

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

#loading-text {
    font-size: 0.8rem;
    color: #ffaa00;
    margin-top: 1rem;
}

/* Game Title */
.game-title {
    font-size: 3rem;
    color: #ff6b00;
    text-shadow: 4px 4px 0px #cc4400, 8px 8px 0px rgba(0,0,0,0.3);
    margin-bottom: 2rem;
    animation: pulse 2s infinite;
}

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

/* Menu Buttons */
.menu-buttons {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    align-items: center;
}

.menu-btn {
    font-family: 'Press Start 2P', monospace;
    font-size: 1rem;
    padding: 1rem 2rem;
    margin: 0.5rem;
    background: linear-gradient(45deg, #ff6b00, #ff8c00);
    border: 3px solid #cc4400;
    color: white;
    cursor: pointer;
    text-shadow: 2px 2px 0px rgba(0,0,0,0.5);
    box-shadow: 0 4px 0 #aa3300, 0 8px 15px rgba(0,0,0,0.3);
    transition: all 0.1s;
    min-width: 240px;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.menu-btn:hover, .menu-btn:focus {
    background: linear-gradient(45deg, #ff8c00, #ffaa00);
    transform: translateY(-2px);
    box-shadow: 0 6px 0 #aa3300, 0 10px 20px rgba(0,0,0,0.4);
    outline: none;
}

.menu-btn:active {
    transform: translateY(2px);
    box-shadow: 0 2px 0 #aa3300, 0 4px 8px rgba(0,0,0,0.3);
}

/* Game Screen */
#game-screen {
    background: transparent;
    justify-content: flex-start;
    align-items: center;
    padding: 0;
}

/* HUD */
#hud {
    position: absolute;
    top: env(safe-area-inset-top);
    left: 0;
    right: 0;
    height: 60px;
    background: linear-gradient(to bottom, rgba(0,0,0,0.9), rgba(0,0,0,0.7));
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 1rem;
    z-index: 15;
    border-bottom: 2px solid #ff6b00;
}

.hud-left, .hud-center, .hud-right {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.hud-label {
    font-size: 0.6rem;
    color: #ffaa00;
}

#score, #level, #timer, #lives {
    font-size: 0.7rem;
    color: white;
    text-shadow: 1px 1px 0px rgba(0,0,0,0.8);
}

/* Canvas Container */
#canvas-container {
    position: absolute;
    top: 60px;
    left: 0;
    right: 0;
    bottom: 80px;
    display: flex;
    justify-content: center;
    align-items: center;
    background: #1a4d00;
}

#canvas {
    border: 2px solid #ff6b00;
    box-shadow: 0 0 20px rgba(255,107,0,0.3);
    background: #2d5016;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
    image-rendering: -moz-crisp-edges;
    image-rendering: -webkit-crisp-edges;
    max-width: 100%;
    max-height: 100%;
}

/* Power-ups Display */
#powerups-display {
    position: absolute;
    bottom: env(safe-area-inset-bottom, 0px);
    left: 50%;
    transform: translateX(-50%);
    height: 80px;
    background: linear-gradient(to top, rgba(0,0,0,0.9), rgba(0,0,0,0.7));
    display: flex;
    gap: 1rem;
    align-items: center;
    padding: 0 2rem;
    border-top: 2px solid #ff6b00;
    border-radius: 20px 20px 0 0;
    z-index: 15;
}

.powerup-item {
    font-size: 1rem;
    color: white;
    text-shadow: 1px 1px 0px rgba(0,0,0,0.8);
}

/* Touch Controls */
.touch-controls {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 180px;
    pointer-events: none;
    z-index: 20;
    padding: 0 env(safe-area-inset-right, 20px) env(safe-area-inset-bottom, 20px) env(safe-area-inset-left, 20px);
}

/* D-Pad */
.dpad {
    position: absolute;
    bottom: 20px;
    left: 20px;
    width: 140px;
    height: 140px;
    pointer-events: auto;
    opacity: 0.7;
}

.dpad-btn {
    position: absolute;
    background: rgba(255, 255, 255, 0.2);
    border: 2px solid rgba(255, 255, 255, 0.4);
    color: rgba(255, 255, 255, 0.8);
    font-size: 18px;
    font-weight: bold;
    border-radius: 8px;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    transition: all 0.1s;
}

.dpad-btn:active, .dpad-btn.active {
    background: rgba(255, 107, 0, 0.6);
    border-color: #ff6b00;
    color: white;
    transform: scale(0.95);
}

.dpad-up {
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 40px;
    height: 40px;
}

.dpad-down {
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 40px;
    height: 40px;
}

.dpad-left {
    top: 50%;
    left: 0;
    transform: translateY(-50%);
    width: 40px;
    height: 40px;
}

.dpad-right {
    top: 50%;
    right: 0;
    transform: translateY(-50%);
    width: 40px;
    height: 40px;
}

.dpad-center {
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 30px;
    height: 30px;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 50%;
    pointer-events: none;
}

/* Action Buttons */
.action-buttons {
    position: absolute;
    bottom: 20px;
    right: 20px;
    display: flex;
    flex-direction: column;
    gap: 15px;
    pointer-events: auto;
    opacity: 0.7;
}

.action-btn {
    width: 70px;
    height: 70px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    border: 3px solid rgba(255, 255, 255, 0.4);
    color: rgba(255, 255, 255, 0.9);
    font-size: 24px;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    transition: all 0.1s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.action-btn:active, .action-btn.active {
    background: rgba(255, 107, 0, 0.6);
    border-color: #ff6b00;
    transform: scale(0.9);
}

.bomb-btn {
    background: rgba(255, 0, 0, 0.3);
    border-color: rgba(255, 0, 0, 0.5);
}

.pause-btn {
    background: rgba(0, 0, 255, 0.3);
    border-color: rgba(0, 0, 255, 0.5);
    width: 50px;
    height: 50px;
    font-size: 18px;
}

/* Instructions Content */
.instructions-content {
    text-align: left;
    font-size: 0.7rem;
    line-height: 1.8;
    color: #cccccc;
    max-width: 600px;
    margin-bottom: 2rem;
    padding: 0 1rem;
}

.control-section {
    margin-bottom: 1.5rem;
}

.instructions-content p {
    margin-bottom: 0.5rem;
}

.instructions-content strong {
    color: #ff6b00;
}

/* Settings Screen */
.settings-content {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    max-width: 400px;
    margin-bottom: 2rem;
}

.setting-group {
    display: flex;
    align-items: center;
    gap: 1rem;
    font-size: 0.7rem;
}

.setting-group label {
    min-width: 120px;
    color: #ffaa00;
}

.setting-group input[type="range"] {
    flex: 1;
    height: 6px;
    background: #333;
    border-radius: 3px;
    outline: none;
}

.setting-group input[type="range"]::-webkit-slider-thumb {
    appearance: none;
    width: 16px;
    height: 16px;
    background: #ff6b00;
    border-radius: 50%;
    cursor: pointer;
}

.setting-group input[type="checkbox"] {
    width: 20px;
    height: 20px;
    accent-color: #ff6b00;
}

.setting-group select {
    background: #333;
    color: white;
    border: 1px solid #666;
    border-radius: 4px;
    padding: 0.5rem;
    font-size: 0.7rem;
}

.setting-group span {
    min-width: 50px;
    color: white;
}

/* Overlays */
.overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 25;
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.overlay.hidden {
    display: none;
}

.pause-content, .game-over-content {
    background: linear-gradient(135deg, #2d5016, #1a4d00);
    padding: 2rem;
    border: 3px solid #ff6b00;
    border-radius: 15px;
    text-align: center;
    box-shadow: 0 0 30px rgba(255,107,0,0.6);
    max-width: 90%;
}

.pause-content h2, #game-over-title {
    font-size: 1.8rem;
    color: #ff6b00;
    margin-bottom: 1.5rem;
    text-shadow: 2px 2px 0px rgba(0,0,0,0.5);
}

.game-over-buttons {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-top: 1rem;
}

#final-score, #final-level {
    color: #ffaa00;
    font-weight: bold;
}

#new-record {
    color: #00ff00;
    font-size: 0.8rem;
    margin-top: 1rem;
    animation: celebrate 0.5s infinite alternate;
}

@keyframes celebrate {
    0% { transform: scale(1); }
    100% { transform: scale(1.1); }
}

/* Achievement Toast */
.achievement-toast {
    position: fixed;
    top: 80px;
    left: 50%;
    transform: translateX(-50%);
    background: linear-gradient(45deg, #gold, #ffaa00);
    color: black;
    padding: 1rem 2rem;
    border-radius: 10px;
    border: 2px solid #ff6b00;
    z-index: 30;
    animation: slide-down 0.5s ease-out;
    max-width: 90%;
    text-align: center;
    box-shadow: 0 4px 15px rgba(255, 107, 0, 0.5);
}

.achievement-toast.hidden {
    display: none;
}

@keyframes slide-down {
    from {
        transform: translateX(-50%) translateY(-100%);
        opacity: 0;
    }
    to {
        transform: translateX(-50%) translateY(0);
        opacity: 1;
    }
}

#achievement-text {
    font-size: 0.7rem;
    font-weight: bold;
}

/* Mobile-specific adjustments */
@media (max-width: 768px), (max-height: 768px) {
    .game-title {
        font-size: 2rem;
        margin-bottom: 1rem;
    }
    
    .menu-btn {
        font-size: 0.8rem;
        padding: 0.8rem 1.5rem;
        min-width: 200px;
    }
    
    .hud-label {
        font-size: 0.5rem;
    }
    
    #score, #level, #timer, #lives {
        font-size: 0.6rem;
    }
    
    .powerup-item {
        font-size: 0.8rem;
    }
    
    .instructions-content {
        font-size: 0.6rem;
    }
    
    .setting-group {
        font-size: 0.6rem;
    }
    
    #achievement-text {
        font-size: 0.6rem;
    }
}

/* Portrait mode adjustments */
@media (orientation: portrait) {
    .game-title {
        font-size: 2.5rem;
    }
    
    #canvas-container {
        bottom: 160px;
    }
    
    .touch-controls {
        height: 160px;
    }
    
    .dpad {
        width: 120px;
        height: 120px;
        bottom: 10px;
        left: 10px;
    }
    
    .action-buttons {
        bottom: 10px;
        right: 10px;
    }
    
    .action-btn {
        width: 60px;
        height: 60px;
        font-size: 20px;
    }
    
    .pause-btn {
        width: 45px;
        height: 45px;
        font-size: 16px;
    }
}

/* Landscape mode adjustments */
@media (orientation: landscape) and (max-height: 500px) {
    .game-title {
        font-size: 1.8rem;
        margin-bottom: 1rem;
    }
    
    .menu-btn {
        font-size: 0.7rem;
        padding: 0.6rem 1.2rem;
        margin: 0.3rem;
        min-width: 180px;
    }
    
    #hud {
        height: 50px;
    }
    
    #canvas-container {
        top: 50px;
        bottom: 120px;
    }
    
    #powerups-display {
        height: 60px;
    }
    
    .touch-controls {
        height: 120px;
    }
    
    .dpad {
        width: 100px;
        height: 100px;
    }
    
    .action-btn {
        width: 50px;
        height: 50px;
        font-size: 18px;
    }
}

/* Very small screens */
@media (max-width: 480px) {
    .game-title {
        font-size: 1.5rem;
    }
    
    .menu-btn {
        font-size: 0.6rem;
        padding: 0.6rem 1rem;
        min-width: 160px;
    }
    
    .instructions-content {
        font-size: 0.5rem;
        max-width: 95%;
    }
    
    .setting-group {
        font-size: 0.5rem;
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }
    
    .setting-group label {
        min-width: auto;
    }
}

/* Disable pull-to-refresh on mobile */
html {
    overscroll-behavior: none;
}

body {
    overscroll-behavior: none;
}

/* Hide scrollbars */
::-webkit-scrollbar {
    display: none;
}

html {
    -ms-overflow-style: none;
    scrollbar-width: none;
}