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

body {
    background-color: #0a0a0f;
    background-image: 
        radial-gradient(ellipse at center, rgba(20, 20, 40, 1) 0%, rgba(10, 10, 15, 1) 100%);
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    font-family: 'Courier New', monospace;
    overflow: hidden;
}

.game-container {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
}

#gameCanvas {
    border: 3px solid #33ff33;
    box-shadow: 
        0 0 30px rgba(51, 255, 51, 0.4),
        0 0 60px rgba(51, 255, 51, 0.2),
        inset 0 0 30px rgba(0, 0, 0, 0.5);
    border-radius: 4px;
}

#hud {
    position: absolute;
    top: 5px;
    left: 0;
    right: 0;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 3px;
    padding: 0 5px;
    color: #fff;
    font-size: 10px;
    font-weight: bold;
    pointer-events: none;
    z-index: 10;
    text-shadow: 0 0 10px rgba(255, 255, 255, 0.5);
}

#hud > div {
    background: rgba(0, 0, 0, 0.5);
    padding: 3px 6px;
    border-radius: 4px;
    border: 1px solid rgba(51, 255, 51, 0.3);
    white-space: nowrap;
}

#lives-display span {
    color: #ff4444;
    letter-spacing: 3px;
    text-shadow: 0 0 8px rgba(255, 68, 68, 0.8);
}

#ui-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    pointer-events: none;
    background: transparent;
    transition: background 0.3s ease;
}

#ui-overlay.overlay-active {
    background: rgba(0, 0, 0, 0.7);
    pointer-events: auto;
}

.screen {
    background: linear-gradient(180deg, rgba(10, 20, 30, 0.95) 0%, rgba(5, 10, 15, 0.98) 100%);
    border: 2px solid #33ff33;
    padding: 40px 60px;
    text-align: center;
    color: #fff;
    pointer-events: auto;
    border-radius: 8px;
    box-shadow: 
        0 0 40px rgba(51, 255, 51, 0.3),
        0 0 80px rgba(51, 255, 51, 0.1),
        inset 0 1px 0 rgba(255, 255, 255, 0.1);
    z-index: 999999;
}

.screen.hidden {
    display: none;
}

.screen h1 {
    color: #33ff33;
    font-size: 42px;
    margin-bottom: 25px;
    text-shadow: 
        0 0 10px rgba(51, 255, 51, 0.8),
        0 0 20px rgba(51, 255, 51, 0.5),
        0 0 40px rgba(51, 255, 51, 0.3);
    letter-spacing: 6px;
}

.screen p {
    margin: 10px 0;
    font-size: 16px;
}

.instructions {
    color: #aaa;
}

.screen button {
    background: linear-gradient(180deg, rgba(51, 255, 51, 0.1) 0%, rgba(51, 255, 51, 0.05) 100%);
    border: 2px solid #33ff33;
    color: #33ff33;
    padding: 14px 35px;
    font-size: 18px;
    font-family: 'Courier New', monospace;
    cursor: pointer;
    margin-top: 15px;
    transition: all 0.25s ease;
    text-transform: uppercase;
    border-radius: 4px;
    text-shadow: 0 0 8px rgba(51, 255, 51, 0.5);
    letter-spacing: 2px;
}

.screen button:hover {
    background: linear-gradient(180deg, #33ff33 0%, #22dd22 100%);
    color: #000;
    box-shadow: 
        0 0 25px rgba(51, 255, 51, 0.6),
        0 0 50px rgba(51, 255, 51, 0.3);
    transform: scale(1.02);
    text-shadow: none;
}

.screen button:active {
    transform: scale(0.98);
}

.start-buttons {
    display: flex;
    gap: 15px;
    justify-content: center;
    align-items: center;
    margin-top: 15px;
}

.secondary-btn {
    background: rgba(100, 100, 100, 0.2) !important;
    border-color: #888 !important;
    color: #aaa !important;
    padding: 14px 25px !important;
}

.secondary-btn:hover {
    background: rgba(150, 150, 150, 0.3) !important;
    border-color: #aaa !important;
    color: #fff !important;
    box-shadow: 0 0 15px rgba(150, 150, 150, 0.3) !important;
}

.value-cell.damage {
    color: #ff6600 !important;
}

.score-table-title {
    margin-top: 30px !important;
    color: #33ff33;
    font-size: 14px;
}

.score-table {
    margin-top: 15px;
    text-align: left;
}

.score-row {
    margin: 8px 0;
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

.invader-icon {
    display: inline-block;
    width: 24px;
    text-align: center;
}

.invader-icon.mystery { color: #ff0000; }
.invader-icon.top { color: #ff66ff; }
.invader-icon.mid { color: #00ffff; }
.invader-icon.bot { color: #33ff33; }

#final-score, #victory-score {
    font-size: 24px;
    color: #33ff33;
    margin: 20px 0;
}

@keyframes blink {
    0%, 50% { opacity: 1; }
    51%, 100% { opacity: 0; }
}

.blink {
    animation: blink 1s infinite;
}

/* Game Footer - below game area */
#game-footer {
    display: none;
    justify-content: space-between;
    align-items: center;
    padding: 8px 15px;
    background: rgba(10, 15, 20, 0.95);
    border: 2px solid #33ff33;
    border-top: none;
    border-radius: 0 0 4px 4px;
    width: 100%;
    box-sizing: border-box;
}

#game-footer.visible {
    display: flex;
}

#game-footer #mute-btn,
#game-footer #menu-btn {
    background: rgba(20, 30, 40, 0.9);
    border: 2px solid #33ff33;
    color: #33ff33;
    padding: 8px 15px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    font-family: 'Courier New', monospace;
    font-weight: bold;
    transition: all 0.25s ease;
    display: flex;
    align-items: center;
    gap: 5px;
}

#game-footer #menu-btn {
    display: none;
}

#game-footer #menu-btn.visible {
    display: flex;
}

#game-footer #mute-btn:hover,
#game-footer #menu-btn:hover {
    background: rgba(51, 255, 51, 0.25);
    box-shadow: 0 0 15px rgba(51, 255, 51, 0.5);
}

#game-footer #mute-btn:active,
#game-footer #menu-btn:active {
    transform: scale(0.95);
}

#game-footer #mute-btn.muted {
    border-color: #ff4444;
    color: #ff4444;
}

#game-footer #mode-display {
    background: rgba(0, 0, 0, 0.5);
    padding: 8px 15px;
    border-radius: 6px;
    border: 1px solid #ffff00;
    color: #ffff00;
    font-size: 14px;
    font-weight: bold;
}

#game-footer #mode-display.hidden {
    display: none;
}

.menu-options {
    display: flex;
    flex-direction: column;
    gap: 15px;
    margin-top: 20px;
}

.menu-options button {
    margin-top: 0;
}

/* Info Screen */
#info-screen {
    min-width: 380px;
}

.info-content {
    text-align: left;
    max-height: 400px;
    overflow-y: auto;
}

.info-content h2 {
    color: #33ff33;
    font-size: 18px;
    margin: 25px 0 15px 0;
    text-align: center;
    letter-spacing: 2px;
}

.info-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 10px;
}

.info-table tr {
    border-bottom: 1px solid rgba(51, 255, 51, 0.15);
}

.info-table td {
    padding: 10px 8px;
    vertical-align: middle;
}

.icon-cell {
    width: 40px;
    text-align: center;
}

.icon-cell .icon {
    display: inline-flex;
    width: 30px;
    height: 30px;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    font-weight: bold;
    font-size: 16px;
}

.icon.mystery { background: rgba(255, 0, 0, 0.3); color: #ff0000; }
.icon.top { background: rgba(255, 102, 255, 0.3); color: #ff66ff; }
.icon.mid { background: rgba(0, 255, 255, 0.3); color: #00ffff; }
.icon.bot { background: rgba(51, 255, 51, 0.3); color: #33ff33; }
.icon.shield { background: rgba(0, 255, 255, 0.3); color: #00ffff; }
.icon.rapid { background: rgba(255, 255, 0, 0.3); color: #ffff00; }
.icon.multi { background: rgba(255, 102, 255, 0.3); color: #ff66ff; }
.icon.slow { background: rgba(102, 255, 102, 0.3); color: #66ff66; }
.icon.life { background: rgba(255, 51, 51, 0.3); color: #ff3333; }

.name-cell {
    color: #fff;
    font-size: 14px;
    padding-left: 10px;
}

.value-cell {
    text-align: right;
    white-space: nowrap;
}

.value-cell.points {
    color: #ffff00;
    font-weight: bold;
    font-size: 14px;
}

.value-cell.desc {
    color: #aaa;
    font-size: 12px;
}

#info-back-btn {
    margin-top: 25px;
}

/* Touch Controls */
#touch-controls {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 20px;
    z-index: 200;
    pointer-events: none;
    flex-direction: row;
    justify-content: space-between;
    align-items: flex-end;
}

.touch-row {
    display: flex;
    align-items: center;
    pointer-events: auto;
}

.touch-move {
    gap: 15px;
}

.touch-fire-row {
    justify-content: flex-end;
}

.touch-btn {
    background: rgba(51, 255, 51, 0.15);
    border: 3px solid #33ff33;
    color: #33ff33;
    font-family: 'Courier New', monospace;
    font-size: 28px;
    font-weight: bold;
    width: 80px;
    height: 80px;
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.1s;
    display: flex;
    align-items: center;
    justify-content: center;
    user-select: none;
    -webkit-user-select: none;
    touch-action: manipulation;
}

.touch-btn:active {
    background: rgba(51, 255, 51, 0.4);
    transform: scale(0.95);
    box-shadow: 0 0 20px rgba(51, 255, 51, 0.6);
}

.fire-btn {
    width: 120px;
    height: 80px;
    border-radius: 40px;
    font-size: 20px;
    background: rgba(255, 51, 51, 0.15);
    border-color: #ff3333;
    color: #ff3333;
    pointer-events: auto;
}

.fire-btn:active {
    background: rgba(255, 51, 51, 0.4);
    box-shadow: 0 0 20px rgba(255, 51, 51, 0.6);
}

/* Touch panels layout */
.touch-left-panel,
.touch-right-panel {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    pointer-events: auto;
}

.touch-right-panel {
    align-items: flex-end;
}

.touch-info {
    background: rgba(0, 0, 0, 0.7);
    border: 2px solid #33ff33;
    border-radius: 8px;
    padding: 8px 12px;
    text-align: center;
    min-width: 80px;
}

#combo-display {
    border-color: #ffff00;
}

#combo-display.hidden {
    display: none;
}

#combo-display .combo-value {
    display: block;
    font-size: 20px;
    font-weight: bold;
    color: #33ff33;
    text-shadow: 0 0 10px rgba(51, 255, 51, 0.8);
}

#combo-display .combo-mult {
    display: block;
    font-size: 10px;
    color: #ffff00;
}

#weapon-display .weapon-name {
    display: block;
    font-size: 12px;
    font-weight: bold;
    color: #00ffff;
    text-shadow: 0 0 8px rgba(0, 255, 255, 0.8);
}

#weapon-display .weapon-cooldown {
    height: 4px;
    background: #333;
    border-radius: 2px;
    margin-top: 5px;
    overflow: hidden;
}

#weapon-display .weapon-cooldown::after {
    content: '';
    display: block;
    height: 100%;
    width: var(--cooldown, 100%);
    background: #00ffff;
    transition: width 0.1s;
}

.weapon-btn {
    width: auto;
    min-width: 80px;
    height: 45px;
    padding: 0 15px;
    border-radius: 22px;
    font-size: 14px;
    background: rgba(0, 255, 255, 0.15);
    border-color: #00ffff;
    color: #00ffff;
}

.weapon-btn:active {
    background: rgba(0, 255, 255, 0.4);
    box-shadow: 0 0 20px rgba(0, 255, 255, 0.6);
}

/* Mobile Responsive Styles */
@media (max-width: 850px) {
    body {
        align-items: flex-start;
        padding-top: 5px;
    }
    
    #gameCanvas {
        max-width: 100vw;
        height: auto;
    }
    
    #ui-overlay {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        overflow-y: auto;
        z-index: 1000;
    }
    
    .screen {
        padding: 15px 20px;
        margin: 10px auto;
        max-width: 95vw;
        max-height: 90vh;
        overflow-y: auto;
    }
    
    .screen h1 {
        font-size: 28px;
    }
    
    .screen button {
        padding: 12px 30px;
        font-size: 16px;
    }
    
    #hud {
        font-size: 12px;
        padding: 0 5px;
    }
    
    #game-footer {
        padding: 6px 10px;
    }
    
    #game-footer #mute-btn,
    #game-footer #menu-btn {
        padding: 6px 10px;
        font-size: 12px;
    }
    
    #game-footer #mode-display {
        font-size: 12px;
        padding: 6px 10px;
    }
}

@media (pointer: coarse) {
    #touch-controls {
        display: flex;
    }
    
    .game-container {
        padding-bottom: 140px;
    }
}

@media (max-width: 768px) {
    .screen {
        padding: 12px 15px;
        margin: 5px auto;
    }
    
    .screen h1 {
        font-size: 20px;
        letter-spacing: 2px;
        margin-bottom: 10px;
    }
    
    .instructions {
        font-size: 11px;
        margin: 5px 0;
    }
    
    .score-table-title,
    .score-table {
        display: none;
    }
    
    #start-btn {
        padding: 10px 25px;
        font-size: 14px;
        margin-top: 10px;
    }

    #touch-left.touch-btn {
        font-size: 30px;
    }
    
    #touch-right.touch-btn {
        font-size: 30px;
    }
    
    .touch-btn {
        width: 70px;
        height: 70px;
        font-size: 16px;
    }
    
    .fire-btn {
        width: 100px;
        height: 60px;
        font-size: 18px;
    }
    
    /* HUD mobile - 2 lignes */
    #hud {
        flex-wrap: wrap;
        justify-content: center;
        gap: 4px;
        padding: 5px 8px;
        top: 5px;
    }
    
    #hud > div {
        padding: 3px 6px;
        font-size: 10px;
        flex-shrink: 0;
    }
    
    #lives-display span {
        letter-spacing: 1px;
    }
    
    /* Mode buttons mobile */
    .mode-buttons {
        flex-direction: column;
        gap: 8px;
    }
    
    .mode-btn {
        min-width: 100%;
        padding: 8px 12px;
        flex-direction: row;
        justify-content: space-between;
    }
    
    .mode-btn.selected::before {
        top: 50%;
        right: 8px;
        transform: translateY(-50%);
    }
    
    .mode-btn.selected .mode-name::after {
        display: none;
    }
}

/* Mode Selection */
.mode-title {
    color: #ffff00;
    font-size: 16px;
    margin: 20px 0 10px 0;
    text-shadow: 0 0 10px rgba(255, 255, 0, 0.5);
}

.mode-buttons {
    display: flex;
    gap: 10px;
    justify-content: center;
    margin-bottom: 20px;
}

.mode-btn {
    background: rgba(20, 40, 60, 0.8);
    border: 2px solid #444;
    color: #888;
    padding: 12px 16px;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: 110px;
}

.mode-btn:hover {
    border-color: #33ff33;
    color: #fff;
    background: rgba(30, 60, 90, 0.8);
}

.mode-btn.selected {
    border-color: #33ff33;
    color: #33ff33;
    background: rgba(51, 255, 51, 0.15);
    box-shadow: 0 0 15px rgba(51, 255, 51, 0.3);
    position: relative;
}

.mode-btn.selected::before {
    content: '✓';
    position: absolute;
    top: -8px;
    right: -8px;
    background: #33ff33;
    color: #000;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    font-size: 12px;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 0 10px rgba(51, 255, 51, 0.8);
}

.mode-btn.selected .mode-name::after {
    content: ' ◀';
    font-size: 10px;
}

.mode-name {
    font-weight: bold;
    font-size: 14px;
    margin-bottom: 4px;
}

.mode-desc {
    font-size: 10px;
    opacity: 0.7;
}

.mode-result {
    color: #ffff00;
    font-size: 18px;
    margin-bottom: 10px;
}

#timer-display {
    color: #ff6600;
}

#timer-display span {
    color: #ff6600;
    text-shadow: 0 0 10px rgba(255, 102, 0, 0.8);
}

#mode-display {
    color: #ffff00;
}

#mode-display span {
    text-shadow: 0 0 10px rgba(255, 255, 0, 0.5);
}

/* Tab System for Start Screen */
.start-tabs {
    display: flex;
    justify-content: center;
    gap: 5px;
    margin: 20px 0 15px 0;
}

.tab-btn {
    background: rgba(20, 40, 60, 0.8);
    border: 2px solid #444;
    color: #888;
    padding: 10px 20px;
    font-size: 12px;
    font-family: 'Courier New', monospace;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.2s ease;
    border-radius: 4px 4px 0 0;
    margin-top: 0;
}

.tab-btn:hover {
    border-color: #33ff33;
    color: #fff;
    background: rgba(30, 60, 90, 0.8);
}

.tab-btn.active {
    background: rgba(51, 255, 51, 0.15);
    border-color: #33ff33;
    color: #33ff33;
    border-bottom-color: transparent;
}

.tab-content {
    display: none;
    min-height: 150px;
    padding: 10px 0;
}

.tab-content.active {
    display: block;
}

/* Selection Grid for Ships and Levels */
.selection-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    max-height: 250px;
    overflow-y: auto;
    padding: 5px;
}

.selection-item {
    background: rgba(20, 40, 60, 0.8);
    border: 2px solid #444;
    border-radius: 8px;
    padding: 12px 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
    position: relative;
}

.selection-item:hover:not(.locked) {
    border-color: #33ff33;
    background: rgba(30, 60, 90, 0.8);
}

.selection-item.selected {
    border-color: #33ff33;
    background: rgba(51, 255, 51, 0.15);
    box-shadow: 0 0 15px rgba(51, 255, 51, 0.3);
}

.selection-item.selected::after {
    content: '✓';
    position: absolute;
    top: -8px;
    right: -8px;
    background: #33ff33;
    color: #000;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    font-size: 12px;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 0 10px rgba(51, 255, 51, 0.8);
}

.selection-item.locked {
    /* opacity: 0.7; */
    cursor: not-allowed;
}

.selection-item.locked::before {
    content: '🔒';
    position: absolute;
    top: 5px;
    right: 5px;
    font-size: 14px;
}

.selection-preview {
    width: 50px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.selection-preview canvas {
    max-width: 100%;
    max-height: 100%;
}

.selection-name {
    font-size: 11px;
    font-weight: bold;
    color: #fff;
    text-align: center;
}

.selection-desc {
    font-size: 10px;
    color: #fff;
    font-weight: 600;
    text-align: center;
}

.selection-unlock {
    font-size: 10px;
    color: #ff6600;
    text-align: center;
    margin-top: 3px;
}

/* Environment Preview Colors */
.env-preview {
    width: 50px;
    height: 35px;
    border-radius: 4px;
    border: 1px solid rgba(255,255,255,0.2);
}

.env-space { background: linear-gradient(180deg, #000 0%, #111 100%); }
.env-nebula { background: linear-gradient(180deg, #0a0015 0%, #1a0030 100%); }
.env-asteroid { background: linear-gradient(180deg, #0f0a05 0%, #1f1a0a 100%); }
.env-wormhole { background: linear-gradient(180deg, #050510 0%, #101025 100%); }
.env-inferno { background: linear-gradient(180deg, #150500 0%, #2a0a00 100%); }
.env-frozen { background: linear-gradient(180deg, #001020 0%, #002040 100%); }

/* Mobile adjustments for tabs */
@media (max-width: 768px) {
    .start-tabs {
        gap: 3px;
        margin: 10px 0 8px 0;
    }
    
    .tab-btn {
        padding: 6px 10px;
        font-size: 9px !important;
    }
    
    .tab-content {
        min-height: 100px;
        padding: 5px 0;
    }
    
    .mode-title {
        font-size: 12px;
        margin: 8px 0 6px 0;
    }
    
    .mode-buttons {
        gap: 6px;
        margin-bottom: 10px;
    }
    
    .mode-btn {
        padding: 6px 10px;
    }
    
    .mode-name {
        font-size: 12px;
    }
    
    .mode-desc {
        font-size: 9px;
    }
    
    .selection-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 6px;
        max-height: 350px !important;
    }
    
    .selection-item {
        padding: 6px 4px;
    }
    
    .selection-preview {
        width: 40px;
        height: 30px;
    }
    
    .selection-name {
        font-size: 9px;
    }
    
    .selection-desc {
        font-size: 7px;
    }
    
    .selection-unlock {
        font-size: 7px;
    }
    
    .env-preview {
        width: 40px;
        height: 25px;
    }
}

/* Extra small screens */
@media (max-width: 400px) {
    .screen {
        padding: 10px 12px;
    }
    
    .screen h1 {
        font-size: 18px;
        margin-bottom: 8px;
    }
    
    .instructions {
        font-size: 10px;
    }
    
    .start-tabs {
        gap: 2px;
    }
    
    .tab-btn {
        padding: 5px 8px;
        font-size: 9px;
    }
    
    .selection-grid {
        max-height: 120px;
    }
}
