/* ============================================
   SPACE INVADERS ULTIMATE - Style Sheet
   Rob & Ollie's Arcade at robyward.com
   ============================================ */

/* Reset & Base */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: #000;
    font-family: 'Press Start 2P', monospace;
    color: #fff;
    touch-action: none;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}

/* Game Wrapper */
#game-wrapper {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
}

/* CRT Scanline Effect */
#crt-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1000;
    opacity: 0;
    transition: opacity 0.3s;
}

#crt-overlay.crt-active {
    opacity: 1;
    background: repeating-linear-gradient(
        0deg,
        rgba(0, 0, 0, 0.15) 0px,
        rgba(0, 0, 0, 0.15) 1px,
        transparent 1px,
        transparent 3px
    );
}

#crt-overlay.crt-active::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: radial-gradient(ellipse at center, transparent 60%, rgba(0,0,0,0.4) 100%);
}

/* Canvas Container - all overlays live inside this */
#canvas-container {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    overflow: hidden;
}

#gameCanvas {
    display: block;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
    background: #000;
    border: 2px solid #1a1a2e;
    box-shadow: 0 0 30px rgba(0, 120, 255, 0.15), inset 0 0 30px rgba(0,0,0,0.5);
}

/* HUD */
#hud {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    padding: 10px 20px;
    z-index: 50;
    pointer-events: none;
    font-size: 10px;
    text-shadow: 0 0 10px rgba(0, 200, 255, 0.5);
}

#hud-left, #hud-center, #hud-right {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

#hud-center { align-items: center; }
#hud-right { align-items: flex-end; }

#hud-score { color: #00ff88; font-size: 12px; }
#hud-wave { color: #88aaff; }
#hud-lives { color: #ff6666; }

#hud-combo {
    color: #ffcc00;
    font-size: 14px;
    animation: combo-pulse 0.5s ease-in-out infinite alternate;
}

#hud-powerup {
    margin-top: 4px;
}

#powerup-name {
    font-size: 8px;
    color: #ff66ff;
}

#powerup-timer-bar {
    width: 100px;
    height: 4px;
    background: #333;
    border-radius: 2px;
    overflow: hidden;
    margin-top: 2px;
}

#powerup-timer-fill {
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, #ff66ff, #66ffff);
    transition: width 0.1s linear;
}

/* Boss Health Bar - minimal, tucked under HUD */
#boss-health-container {
    position: absolute;
    top: 28px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 50;
    text-align: center;
    pointer-events: none;
    opacity: 0.7;
}

#boss-health-label {
    font-size: 6px;
    color: #ff4444;
    margin-bottom: 2px;
    text-shadow: 0 0 5px rgba(255, 0, 0, 0.4);
}

#boss-health-bar {
    width: 150px;
    height: 4px;
    background: #1a0000;
    border: 1px solid rgba(255, 68, 68, 0.5);
    border-radius: 2px;
    overflow: hidden;
}

#boss-health-fill {
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, #ff0000, #ff6600, #ff0000);
    transition: width 0.3s ease-out;
}

/* Overlays */
.overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.95);
    z-index: 100;
    transition: opacity 0.4s ease;
}

.overlay.hidden {
    display: none;
}

.overlay-content {
    text-align: center;
    padding: 20px;
    max-height: 90vh;
    overflow-y: auto;
}

/* Start Screen */
.game-title {
    font-size: 36px;
    color: #00ff88;
    text-shadow: 0 0 20px rgba(0, 255, 136, 0.5), 0 0 40px rgba(0, 255, 136, 0.3);
    line-height: 1.4;
    margin-bottom: 5px;
    letter-spacing: 4px;
}

.game-subtitle {
    font-size: 18px;
    color: #ffcc00;
    text-shadow: 0 0 15px rgba(255, 204, 0, 0.5);
    margin-bottom: 15px;
    letter-spacing: 8px;
}

.credits {
    font-size: 10px;
    color: #8888aa;
    margin-bottom: 20px;
}

.instructions {
    font-size: 8px;
    color: #6688aa;
    line-height: 2.2;
    margin-bottom: 15px;
}

/* Buttons */
.game-btn {
    font-family: 'Press Start 2P', monospace;
    font-size: 12px;
    color: #fff;
    background: linear-gradient(180deg, #2a4a7f, #1a2a4f);
    border: 2px solid #4488cc;
    padding: 12px 30px;
    cursor: pointer;
    margin: 10px;
    transition: all 0.2s;
    text-shadow: 0 0 5px rgba(68, 136, 204, 0.5);
}

.game-btn:hover, .game-btn:active {
    background: linear-gradient(180deg, #3a6aaf, #2a4a7f);
    border-color: #66aaee;
    transform: scale(1.05);
    box-shadow: 0 0 20px rgba(68, 136, 204, 0.4);
}

.pulse-btn {
    animation: btn-pulse 2s ease-in-out infinite;
}

@keyframes btn-pulse {
    0%, 100% { box-shadow: 0 0 5px rgba(68, 136, 204, 0.3); }
    50% { box-shadow: 0 0 25px rgba(68, 136, 204, 0.6); }
}

/* Wave Intro */
.wave-text {
    font-size: 40px;
    color: #00ccff;
    text-shadow: 0 0 30px rgba(0, 204, 255, 0.6);
    animation: wave-zoom 2s ease-in-out;
}

.wave-sub {
    font-size: 12px;
    color: #88aacc;
    margin-top: 10px;
}

@keyframes wave-zoom {
    0% { transform: scale(0.5); opacity: 0; }
    20% { transform: scale(1.2); opacity: 1; }
    80% { transform: scale(1); opacity: 1; }
    100% { transform: scale(1.5); opacity: 0; }
}

/* Boss Warning */
.boss-warning {
    font-size: 24px;
    color: #ff0000;
    animation: boss-flash 0.3s ease-in-out infinite alternate;
    margin-bottom: 15px;
}

.boss-approaching {
    font-size: 18px;
    color: #ff4444;
    text-shadow: 0 0 20px rgba(255, 0, 0, 0.8);
    animation: boss-pulse 0.5s ease-in-out infinite alternate;
}

@keyframes boss-flash {
    0% { opacity: 0.3; color: #ff0000; }
    100% { opacity: 1; color: #ff6600; }
}

@keyframes boss-pulse {
    0% { transform: scale(1); }
    100% { transform: scale(1.1); text-shadow: 0 0 40px rgba(255, 0, 0, 1); }
}

/* Pause Screen */
.pause-options {
    margin-top: 20px;
    font-size: 8px;
    color: #888;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
}

.pause-options label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
}

.pause-options input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: #00ff88;
}

.volume-control {
    display: flex;
    align-items: center;
    gap: 10px;
}

.volume-control input[type="range"] {
    width: 120px;
    accent-color: #00ff88;
}

/* Game Over */
.gameover-title {
    font-size: 30px;
    color: #ff4444;
    text-shadow: 0 0 20px rgba(255, 0, 0, 0.5);
    margin-bottom: 15px;
}

.stats-panel {
    font-size: 8px;
    line-height: 2.5;
    color: #aaccee;
    margin-bottom: 15px;
    text-align: left;
    display: inline-block;
}

.stats-panel .stat-row {
    display: flex;
    justify-content: space-between;
    gap: 20px;
}

.stats-panel .stat-label { color: #6688aa; }
.stats-panel .stat-value { color: #00ff88; }

/* High Scores */
.high-scores-panel {
    font-size: 7px;
    margin: 10px 0;
    color: #aaa;
    line-height: 2.2;
}

.high-scores-panel .hs-title {
    color: #ffcc00;
    font-size: 9px;
    margin-bottom: 5px;
}

.high-scores-panel .hs-row {
    display: flex;
    justify-content: space-between;
    gap: 10px;
}

.high-scores-panel .hs-rank { color: #666; width: 30px; }
.high-scores-panel .hs-name { color: #88ccff; flex: 1; text-align: left; }
.high-scores-panel .hs-score { color: #00ff88; width: 80px; text-align: right; }
.high-scores-panel .hs-wave { color: #888; width: 50px; text-align: right; }

/* Name Entry */
#name-entry {
    margin: 10px 0;
}

#name-entry p {
    font-size: 12px;
    color: #ffcc00;
    margin-bottom: 10px;
    animation: combo-pulse 0.5s ease-in-out infinite alternate;
}

#name-input {
    font-family: 'Press Start 2P', monospace;
    font-size: 14px;
    background: #111;
    border: 2px solid #4488cc;
    color: #00ff88;
    padding: 8px 12px;
    text-align: center;
    text-transform: uppercase;
    width: 150px;
    outline: none;
}

#name-input:focus {
    border-color: #66aaee;
    box-shadow: 0 0 15px rgba(68, 136, 204, 0.4);
}

/* Combo Float */
#combo-float {
    position: absolute;
    z-index: 60;
    font-size: 20px;
    color: #ffcc00;
    text-shadow: 0 0 15px rgba(255, 204, 0, 0.8);
    pointer-events: none;
    transition: all 0.3s;
}

@keyframes combo-pulse {
    0% { transform: scale(1); }
    100% { transform: scale(1.15); }
}

/* Touch Controls - joystick + fire */
#touch-controls {
    width: 100%;
    padding: 6px 10px;
    flex-shrink: 0;
}

.touch-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    max-width: 500px;
    margin: 0 auto;
    gap: 12px;
}

/* Joystick */
.joystick-zone {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    height: 70px;
    touch-action: none;
    -webkit-tap-highlight-color: transparent;
}

.joystick-base {
    position: relative;
    width: 200px;
    height: 60px;
    background: rgba(255, 255, 255, 0.06);
    border: 2px solid rgba(255, 255, 255, 0.15);
    border-radius: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.joystick-thumb {
    position: absolute;
    width: 50px;
    height: 50px;
    background: rgba(255, 255, 255, 0.2);
    border: 2px solid rgba(255, 255, 255, 0.4);
    border-radius: 50%;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    transition: left 0.05s ease-out;
}

.joystick-base.active {
    border-color: rgba(0, 120, 212, 0.5);
    background: rgba(0, 120, 212, 0.08);
}

.joystick-base.active .joystick-thumb {
    background: rgba(0, 120, 212, 0.3);
    border-color: rgba(0, 120, 212, 0.6);
}

/* Fire button */
.touch-btn {
    font-family: 'Press Start 2P', monospace;
    font-size: 14px;
    color: #fff;
    background: rgba(255, 255, 255, 0.08);
    border: 2px solid rgba(255, 255, 255, 0.2);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    transition: background 0.1s;
    touch-action: none;
}

.touch-btn:active {
    background: rgba(255, 255, 255, 0.2);
    border-color: rgba(255, 255, 255, 0.4);
}

.touch-fire {
    width: 90px;
    height: 56px;
    background: rgba(255, 50, 50, 0.15);
    border-color: rgba(255, 50, 50, 0.4);
    color: #ff6666;
    flex-shrink: 0;
}

.touch-fire:active {
    background: rgba(255, 50, 50, 0.35);
}

/* Orientation Warning */
#orientation-warning {
    position: fixed;
    bottom: 10px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 7px;
    color: #886600;
    background: rgba(255, 200, 0, 0.1);
    border: 1px solid rgba(255, 200, 0, 0.3);
    padding: 6px 12px;
    border-radius: 4px;
    z-index: 200;
    white-space: nowrap;
}

/* Hidden utility */
.hidden { display: none !important; }

/* Desktop: hide touch controls, show keyboard instructions */
.mobile-only { display: none; }
.desktop-only { display: block; }

/* Mobile media queries */
@media (max-width: 860px), (max-height: 650px) {
    .mobile-only { display: block; }
    .desktop-only { display: none; }

    #hud {
        padding: 6px 10px;
        font-size: 7px;
    }

    #hud-score { font-size: 9px; }
    #hud-combo { font-size: 10px; }

    .game-title { font-size: 24px; }
    .game-subtitle { font-size: 12px; }

    .overlay-content {
        padding: 10px;
        font-size: 8px;
    }

    .wave-text { font-size: 28px; }
    .boss-warning { font-size: 18px; }
    .boss-approaching { font-size: 14px; }
    .gameover-title { font-size: 22px; }

    #boss-health-bar { width: 120px; height: 3px; }

    .game-btn {
        font-size: 10px;
        padding: 10px 20px;
    }
}

/* Very small screens */
@media (max-width: 400px) {
    .game-title { font-size: 18px; }
    .game-subtitle { font-size: 10px; }
    .touch-btn { width: 65px; height: 50px; font-size: 16px; }
    .touch-fire { font-size: 11px; }
    #hud { font-size: 6px; }
}

/* Landscape mobile */
@media (max-height: 450px) and (orientation: landscape) {
    #touch-controls { padding: 5px 15px; }
    .touch-btn { height: 55px; }
    .overlay-content { max-height: 85vh; }
    .game-title { font-size: 20px; }
}
