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

body {
    font-family: 'Courier New', monospace;
    background: #0a0a1a;
    color: #fff;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 0;
    margin: 0;
    image-rendering: pixelated;
    image-rendering: -moz-crisp-edges;
    image-rendering: crisp-edges;
}

/* Start Screen Styles */
.start-screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 20px;
    text-align: center;
}

.game-cover {
    max-width: 600px;
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 30px;
}

.cover-image {
    width: 100%;
    max-width: 500px;
    height: auto;
    border-radius: 15px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    border: 3px solid #ffd700;
    image-rendering: auto;
}

.start-buttons {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
}

.play-button {
    background: linear-gradient(45deg, #ffd700, #ffaa00);
    color: #1a1a2e;
    font-size: 24px;
    font-weight: bold;
    padding: 15px 40px;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    box-shadow: 0 5px 15px rgba(255, 215, 0, 0.3);
    transition: all 0.3s ease;
    font-family: 'Courier New', monospace;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.play-button:hover {
    background: linear-gradient(45deg, #ffaa00, #ffd700);
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(255, 215, 0, 0.4);
}

.play-button:active {
    transform: translateY(0);
    box-shadow: 0 3px 10px rgba(255, 215, 0, 0.3);
}

/* Level Selector Styles */
.level-selector {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
    margin-bottom: 20px;
}

.level-selector h3 {
    color: #ffd700;
    font-size: 20px;
    margin-bottom: 10px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.level-btn {
    background: linear-gradient(45deg, #4CAF50, #45a049);
    color: white;
    font-size: 16px;
    font-weight: bold;
    padding: 12px 30px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(76, 175, 80, 0.3);
    transition: all 0.3s ease;
    font-family: 'Courier New', monospace;
    text-transform: uppercase;
    letter-spacing: 1px;
    min-width: 250px;
}

.level-btn:hover {
    background: linear-gradient(45deg, #45a049, #4CAF50);
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(76, 175, 80, 0.4);
}

.level-btn:active {
    transform: translateY(0);
    box-shadow: 0 2px 8px rgba(76, 175, 80, 0.3);
}

.level-btn:disabled {
    background: linear-gradient(45deg, #666666, #555555);
    color: #cccccc;
    cursor: not-allowed !important;
    box-shadow: 0 2px 6px rgba(102, 102, 102, 0.2);
    transform: none;
}

.level-btn:disabled:hover {
    background: linear-gradient(45deg, #666666, #555555);
    transform: none;
    box-shadow: 0 2px 6px rgba(102, 102, 102, 0.2);
}

.powered-by {
    color: #cccccc;
    font-size: 14px;
    font-style: italic;
    margin-top: 10px;
}

.game-container {
    max-width: 900px;
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
}

.header {
    text-align: center;
    margin-bottom: 10px;
}

.header h1 {
    font-size: 2.5em;
    text-shadow: 3px 3px 0px #000000, 4px 4px 0px #333333;
    margin-bottom: 10px;
    color: #ffff00;
    font-weight: bold;
    letter-spacing: 2px;
}

.header p {
    font-size: 1.1em;
    color: #ccc;
}

.game-ui {
    display: flex;
    justify-content: space-around;
    width: 100%;
    max-width: 600px;
    background: #000000;
    padding: 10px;
    border: 3px solid #ffff00;
    box-shadow: 0 0 0 3px #000000;
}

.ui-item {
    text-align: center;
    font-size: 1.2em;
    font-weight: bold;
    color: #ffff00;
    text-shadow: 2px 2px 0px #000000;
}

#level-display {
    color: #ffd700;
    font-size: 1.4em;
    font-weight: bold;
    text-transform: uppercase;
    letter-spacing: 1px;
    text-shadow: 2px 2px 0px #000000;
    background: linear-gradient(45deg, #1a1a3e, #0a0a1a);
    padding: 5px 10px;
    border-radius: 6px;
    border: 2px solid #ffd700;
}

#gameCanvas {
    border: 4px solid #ffff00;
    background: #000;
    box-shadow: 0 0 0 4px #000000;
    max-width: 100%;
    height: auto;
    image-rendering: pixelated;
    image-rendering: -moz-crisp-edges;
    image-rendering: crisp-edges;
}

.game-messages {
    min-height: 30px;
    text-align: center;
}

.message {
    font-size: 1.3em;
    font-weight: bold;
    text-shadow: 1px 1px 2px rgba(0,0,0,0.7);
    animation: fadeIn 0.3s ease-in;
}

.message.success {
    color: #4CAF50;
}

.message.warning {
    color: #FF9800;
}

.message.danger {
    color: #f44336;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(-10px); }
    to { opacity: 1; transform: translateY(0); }
}

.controls {
    text-align: center;
    color: #ccc;
    font-size: 0.9em;
}

.controls kbd {
    background: #333;
    border: 1px solid #555;
    border-radius: 3px;
    padding: 2px 6px;
    font-family: 'Courier New', monospace;
    font-weight: bold;
    color: #fff;
}

/* Modal styles for leaderboard */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.modal-content {
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    border: 3px solid #ffd700;
    border-radius: 15px;
    padding: 30px;
    max-width: 90%;
    max-height: 90%;
    overflow-y: auto;
    position: relative;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.modal-header h2 {
    color: #ffd700;
    margin: 0;
    font-size: 2em;
}

.close-btn {
    background: none;
    border: none;
    color: #ffd700;
    font-size: 2em;
    cursor: pointer;
    padding: 0;
    line-height: 1;
}

.close-btn:hover {
    color: #fff;
}

.leaderboard-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 20px;
}

.leaderboard-table th,
.leaderboard-table td {
    padding: 12px;
    text-align: left;
    border-bottom: 1px solid #333;
}

.leaderboard-table th {
    background-color: #ffd700;
    color: #000;
    font-weight: bold;
}

.leaderboard-table tr:nth-child(even) {
    background-color: rgba(255, 215, 0, 0.1);
}

.rank-1 { background-color: rgba(255, 215, 0, 0.3) !important; }
.rank-2 { background-color: rgba(192, 192, 192, 0.3) !important; }
.rank-3 { background-color: rgba(205, 127, 50, 0.3) !important; }

.loading-message, .error-message {
    text-align: center;
    padding: 40px;
    font-size: 1.2em;
    color: #ffd700;
}

.error-message {
    color: #ff6b6b;
}

.name-input-container {
    margin: 20px 0;
}

.name-input-container input {
    width: 100%;
    padding: 12px;
    font-size: 1.1em;
    border: 2px solid #ffd700;
    border-radius: 5px;
    background: rgba(0, 0, 0, 0.5);
    color: #fff;
}

.score-summary {
    background: rgba(255, 215, 0, 0.1);
    border: 1px solid #ffd700;
    border-radius: 5px;
    padding: 15px;
    margin: 15px 0;
}

.total-score {
    font-size: 1.3em;
    font-weight: bold;
    color: #ffd700;
    margin-bottom: 10px;
}

.score-breakdown div {
    margin: 5px 0;
    color: #ccc;
}

.modal-actions {
    display: flex;
    gap: 10px;
    justify-content: center;
    margin-top: 20px;
}

.btn-primary, .btn-secondary {
    padding: 12px 24px;
    border: none;
    border-radius: 5px;
    font-size: 1em;
    cursor: pointer;
    transition: all 0.3s ease;
}

.btn-primary {
    background: #4CAF50;
    color: white;
}

.btn-primary:hover {
    background: #45a049;
}

.btn-secondary {
    background: #666;
    color: white;
}

.btn-secondary:hover {
    background: #555;
}

.game-over {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.95);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.game-over-content {
    background: #1a1a3e;
    padding: 40px;
    border: 4px solid #ffff00;
    text-align: center;
    box-shadow: 0 0 0 4px #000000;
    image-rendering: pixelated;
}

.game-over-content h2 {
    font-size: 2.5em;
    margin-bottom: 20px;
    text-shadow: 3px 3px 0px #000000;
    color: #ff4444;
    font-weight: bold;
    letter-spacing: 2px;
}

.game-over-content p {
    font-size: 1.2em;
    margin-bottom: 30px;
    color: #ffffff;
    text-shadow: 2px 2px 0px #000000;
}

/* Game Over Action Buttons */
.game-over-actions {
    display: flex;
    gap: 10px;
    justify-content: center;
    flex-wrap: wrap;
    margin-top: 25px;
}

.game-over-content button {
    font-size: 1.0em;
    padding: 12px 20px;
    border: 3px solid #000000;
    cursor: pointer;
    font-family: 'Courier New', monospace;
    font-weight: bold;
    text-transform: uppercase;
    letter-spacing: 1px;
    text-shadow: none;
    border-radius: 6px;
    transition: all 0.2s ease;
    min-width: 110px;
    margin: 2px;
}

.restart-btn, .leaderboard-btn {
    background: #4CAF50;
    color: #ffffff;
}

.restart-btn:hover, .leaderboard-btn:hover {
    background: #45a049;
    box-shadow: 0 0 0 2px #4CAF50;
}

.menu-btn {
    background: #ffff00;
    color: #000000;
}

.menu-btn:hover {
    background: #ffaa00;
    box-shadow: 0 0 0 2px #ffff00;
}

footer {
    margin-top: 20px;
    text-align: center;
    color: #888;
    font-size: 0.9em;
}

footer a {
    color: #ffd700;
    text-decoration: none;
}

footer a:hover {
    text-decoration: underline;
}

/* Mobile Touch Controls */
.mobile-controls-container {
    display: none;
    flex-direction: row;
    justify-content: center;
    gap: 20px;
    margin: 20px 0;
    padding: 0 20px;
    width: 100%;
    max-width: 500px;
}

.mobile-action-btn, .mobile-pause-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 15px 20px;
    border: 3px solid #ffff00;
    border-radius: 12px;
    background: linear-gradient(45deg, #ffd700, #ffaa00);
    color: #1a1a2e;
    font-family: 'Courier New', monospace;
    font-weight: bold;
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    min-height: 80px;
    min-width: 120px;
    box-shadow: 0 4px 12px rgba(255, 215, 0, 0.3);
    transition: all 0.2s ease;
}

.mobile-action-btn {
    flex: 1;
    max-width: 200px;
}

.mobile-pause-btn {
    background: linear-gradient(45deg, #888888, #666666);
    color: #ffffff;
    border-color: #cccccc;
    max-width: 120px;
}

.mobile-action-btn:active {
    transform: scale(0.95);
    box-shadow: 0 2px 8px rgba(255, 215, 0, 0.5);
    background: linear-gradient(45deg, #ffaa00, #ff8800);
}

.mobile-pause-btn:active {
    transform: scale(0.95);
    background: linear-gradient(45deg, #666666, #444444);
}

.btn-icon {
    font-size: 24px;
    margin-bottom: 5px;
    display: block;
}

.btn-text {
    font-size: 12px;
    font-weight: bold;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.desktop-controls {
    display: inline;
}

.mobile-controls {
    display: none;
}

/* Performance optimizations */
body {
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: none;
}

#gameCanvas {
    touch-action: none;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -khtml-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

/* Responsive design */
@media (max-width: 768px) {
    body {
        padding: 10px 0;
        font-size: 14px;
    }
    
    .start-screen {
        padding: 15px;
    }
    
    .cover-image {
        max-width: 350px;
    }
    
    .play-button {
        font-size: 20px;
        padding: 12px 30px;
    }
    
    .header h1 {
        font-size: 1.8em;
        margin-bottom: 8px;
    }
    
    .header p {
        font-size: 1em;
        padding: 0 15px;
    }
    
    .game-ui {
        flex-direction: row;
        flex-wrap: wrap;
        gap: 8px;
        padding: 8px;
        margin: 0 15px;
    }
    
    .ui-item {
        font-size: 1em;
        flex: 1;
        min-width: 80px;
    }
    
    #gameCanvas {
        width: calc(100vw - 40px);
        max-width: 400px;
        height: auto;
        border-width: 3px;
    }
    
    .controls {
        padding: 0 20px;
        font-size: 0.85em;
    }
    
    .desktop-controls {
        display: none;
    }
    
    .mobile-controls {
        display: inline;
    }
    
    .mobile-controls-container {
        display: flex;
    }
    
    .game-messages {
        padding: 0 20px;
        min-height: 25px;
    }
    
    .message {
        font-size: 1.1em;
    }
    
    .game-over-content {
        margin: 15px;
        padding: 25px 20px;
        border-width: 3px;
    }
    
    .game-over-content h2 {
        font-size: 2em;
        margin-bottom: 15px;
    }
    
    .game-over-content p {
        font-size: 1em;
        margin-bottom: 20px;
    }
    
    .game-over-content button {
        font-size: 1em;
        padding: 12px 25px;
    }
    
    footer {
        margin-top: 15px;
        padding: 0 20px;
        font-size: 0.8em;
    }
}

@media (max-width: 480px) {
    .header h1 {
        font-size: 1.5em;
    }
    
    .game-ui {
        flex-direction: column;
        gap: 5px;
    }
    
    .ui-item {
        font-size: 0.9em;
    }
    
    #gameCanvas {
        width: calc(100vw - 30px);
        max-width: 320px;
    }
    
    .mobile-controls-container {
        gap: 15px;
        margin: 15px 0;
    }
    
    .mobile-action-btn, .mobile-pause-btn {
        min-height: 70px;
        min-width: 100px;
        padding: 12px 15px;
    }
    
    .btn-icon {
        font-size: 20px;
    }
    
    .btn-text {
        font-size: 10px;
    }
    
    .controls {
        font-size: 0.8em;
    }
}

/* Landscape orientation optimizations */
@media (max-height: 500px) and (orientation: landscape) {
    .header h1 {
        font-size: 1.3em;
        margin-bottom: 5px;
    }
    
    .header p {
        font-size: 0.9em;
    }
    
    .game-ui {
        margin: 5px 15px;
        padding: 5px;
    }
    
    .mobile-controls-container {
        margin: 10px 0;
    }
    
    .mobile-action-btn, .mobile-pause-btn {
        min-height: 60px;
        min-width: 90px;
        padding: 10px 12px;
    }
    
    .controls {
        margin: 5px 0;
    }
    
    .game-messages {
        min-height: 20px;
    }
    
    footer {
        margin-top: 10px;
    }
}
