/* Space Invaders Retro Styling - Mobile First */

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

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

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
}

body {
    background-color: #000;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    min-height: 100dvh;
    font-family: 'Press Start 2P', monospace;
    padding: 10px;
}

#game-container {
    position: relative;
    width: 100%;
    max-width: 800px;
    aspect-ratio: 4 / 3;
    max-height: calc(100vh - 20px);
    max-height: calc(100dvh - 20px);
    border: 2px solid #33ff33;
    box-shadow: 0 0 20px #33ff33, inset 0 0 20px rgba(51, 255, 51, 0.1);
    overflow: hidden;
}

#gameCanvas {
    display: block;
    width: 100%;
    height: 100%;
    background-color: #000;
}

/* Screens */
.screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: safe center;
    align-items: center;
    background-color: rgba(0, 0, 0, 0.95);
    color: #33ff33;
    text-align: center;
    z-index: 10;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 3% 5%;
    gap: 1.5%;
}

.screen.hidden {
    display: none;
}

.screen h1 {
    font-size: clamp(16px, 5vw, 32px);
    text-shadow: 0 0 10px #33ff33;
    animation: pulse 2s ease-in-out infinite;
    flex-shrink: 0;
}

.screen h2 {
    font-size: clamp(14px, 4vw, 24px);
    text-shadow: 0 0 10px #33ff33;
    flex-shrink: 0;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

.subtitle {
    font-size: clamp(8px, 2vw, 12px);
    color: #33ff33;
    letter-spacing: 2px;
    flex-shrink: 0;
}

.invader-demo {
    flex-shrink: 1;
    min-height: 0;
}

#demoCanvas {
    border: 1px solid #33ff3366;
    border-radius: 4px;
    background-color: transparent;
    width: min(200px, 60vw);
    height: auto;
}

.controls {
    font-size: clamp(8px, 1.8vw, 11px);
    line-height: 1.8;
    color: #aaffaa;
    flex-shrink: 0;
}

.tagline {
    font-size: clamp(10px, 2.5vw, 14px);
    color: #ffff33;
    animation: pulse 2s ease-in-out infinite;
    letter-spacing: 3px;
    flex-shrink: 0;
}

.menu-buttons {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: center;
}

.game-btn {
    font-family: 'Press Start 2P', monospace;
    font-size: clamp(9px, 2vw, 12px);
    padding: clamp(8px, 2vw, 12px) clamp(12px, 3vw, 25px);
    background-color: transparent;
    color: #33ff33;
    border: 2px solid #33ff33;
    cursor: pointer;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.game-btn:hover {
    background-color: #33ff33;
    color: #000;
    box-shadow: 0 0 15px #33ff33;
}

.game-btn:active {
    transform: scale(0.95);
}

/* Game Over Screen */
#final-score {
    font-size: clamp(12px, 3vw, 20px);
}

#new-highscore {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}

#new-highscore p {
    color: #ffff33;
    font-size: clamp(10px, 2.5vw, 16px);
    animation: blink 0.5s ease-in-out infinite;
}

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

#player-name {
    font-family: 'Press Start 2P', monospace;
    font-size: clamp(10px, 2vw, 14px);
    padding: 10px;
    background-color: #000;
    color: #33ff33;
    border: 2px solid #33ff33;
    text-align: center;
    text-transform: uppercase;
    width: min(200px, 80%);
}

#player-name:focus {
    outline: none;
    box-shadow: 0 0 10px #33ff33;
}

/* High Score Screen */
#highscore-list {
    list-style: none;
    font-size: clamp(9px, 1.8vw, 12px);
    text-align: left;
    width: min(300px, 90%);
}

#highscore-list li {
    padding: 8px 0;
    border-bottom: 1px solid #33ff3344;
    display: flex;
    justify-content: space-between;
}

#highscore-list li span.rank {
    color: #ffff33;
    width: 30px;
}

#highscore-list li span.name {
    flex: 1;
    text-align: left;
    padding-left: 10px;
}

#highscore-list li span.score {
    width: 80px;
    text-align: right;
}

/* HUD */
#hud {
    position: absolute;
    top: 2%;
    left: 2%;
    right: 2%;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    flex-wrap: wrap;
    gap: 5px;
    color: #33ff33;
    font-size: clamp(8px, 1.5vw, 12px);
    z-index: 5;
    pointer-events: none;
}

#hud.hidden {
    display: none;
}

#lives-icons {
    color: #33ff33;
    letter-spacing: 3px;
}

/* Music Toggle - now inline in menu */
.music-btn {
    font-size: clamp(7px, 1.5vw, 10px) !important;
    padding: clamp(6px, 1.5vw, 10px) clamp(10px, 2vw, 15px) !important;
    opacity: 0.8;
}

.music-btn:hover {
    opacity: 1;
}

/* Touch Controls */
#touch-controls {
    display: none;
    position: fixed;
    bottom: 10px;
    left: 50%;
    transform: translateX(-50%);
    width: calc(100% - 20px);
    max-width: 400px;
    justify-content: space-between;
    align-items: center;
    z-index: 100;
    pointer-events: none;
}

.touch-btn {
    font-family: 'Press Start 2P', monospace;
    font-size: clamp(12px, 3vw, 16px);
    width: clamp(60px, 18vw, 80px);
    height: clamp(45px, 12vw, 60px);
    background-color: rgba(51, 255, 51, 0.2);
    color: #33ff33;
    border: 2px solid #33ff33;
    border-radius: 10px;
    cursor: pointer;
    pointer-events: auto;
    user-select: none;
    -webkit-user-select: none;
    touch-action: manipulation;
}

.touch-btn:active {
    background-color: rgba(51, 255, 51, 0.5);
    box-shadow: 0 0 15px #33ff33;
}

.touch-fire {
    width: clamp(70px, 22vw, 100px);
    font-size: clamp(9px, 2vw, 12px);
    background-color: rgba(255, 51, 51, 0.2);
    border-color: #ff3333;
    color: #ff3333;
}

.touch-fire:active {
    background-color: rgba(255, 51, 51, 0.5);
    box-shadow: 0 0 15px #ff3333;
}

/* Show touch controls on touch devices */
@media (hover: none) and (pointer: coarse) {
    #touch-controls {
        display: flex;
    }

    body {
        padding-bottom: 80px;
    }

    #game-container {
        max-height: calc(100vh - 100px);
        max-height: calc(100dvh - 100px);
    }
}

/* Portrait mobile - allow taller container */
@media (max-width: 500px) and (orientation: portrait) {
    #game-container {
        aspect-ratio: 3 / 4;
        max-height: calc(100dvh - 100px);
    }

    .screen {
        padding: 5% 3%;
        gap: 3%;
    }

    .screen h1 {
        font-size: clamp(14px, 6vw, 24px);
    }

    .subtitle {
        font-size: clamp(7px, 2.5vw, 10px);
    }

    #demoCanvas {
        max-height: 20vh;
    }

    .tagline {
        font-size: clamp(8px, 3vw, 12px);
    }

    .menu-buttons {
        flex-direction: column;
        gap: 8px;
    }

    .game-btn {
        width: 100%;
        max-width: 200px;
    }
}

/* CRT Effect */
#game-container::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: repeating-linear-gradient(
        0deg,
        rgba(0, 0, 0, 0.1),
        rgba(0, 0, 0, 0.1) 1px,
        transparent 1px,
        transparent 3px
    );
    pointer-events: none;
    z-index: 20;
}

/* Landscape phone optimization */
@media (max-height: 500px) and (orientation: landscape) {
    body {
        padding: 5px;
    }

    #game-container {
        max-height: calc(100vh - 10px);
        max-height: calc(100dvh - 10px);
    }

    .screen {
        padding: 2%;
        gap: 1%;
    }

    .screen h1 {
        font-size: clamp(12px, 4vh, 24px);
    }

    .controls {
        display: none;
    }

    #touch-controls {
        bottom: 5px;
    }

    .touch-btn {
        height: 40px;
    }
}

/* Very small screens */
@media (max-width: 400px) {
    .screen h1 {
        font-size: clamp(12px, 5vw, 20px);
    }

    #demoCanvas {
        width: min(150px, 50vw);
    }

    .game-btn {
        font-size: clamp(8px, 2.5vw, 11px);
        padding: clamp(6px, 2vw, 10px) clamp(10px, 2.5vw, 20px);
    }
}
