:root {
    --primary: #EF4444;    /* Crimson */
    --secondary: #F87171;  /* Light Red */
    --accent: #22C55E;     /* Green */
    --bg-dark: #1A0A0A;    /* Very Dark Red/Black */
    --text-light: #FFFFFF;
    --text-muted: #9CA3AF;
    --overlay-bg: rgba(26, 10, 10, 0.85);
    
    --font-retro: 'Press Start 2P', monospace;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    user-select: none;
    -webkit-user-select: none;
}

body, html {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background-color: #000;
    font-family: var(--font-retro);
    color: var(--text-light);
    touch-action: none;
}

#game-container {
    position: relative;
    width: 100%;
    height: 100%;
    max-width: 800px;
    margin: 0 auto;
    background-color: var(--bg-dark);
    box-shadow: 0 0 20px rgba(239, 68, 68, 0.2);
    overflow: hidden;
}

#gameCanvas {
    display: block;
    width: 100%;
    height: 100%;
    image-rendering: pixelated; /* Retro feel */
}

/* ---------- HUD ---------- */
#hud {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 15px;
    z-index: 10;
}

.hud-top {
    display: flex;
    justify-content: space-between;
    font-size: 14px;
    text-shadow: 2px 2px 0 var(--bg-dark), -1px -1px 0 var(--primary);
}

.hud-bottom {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    font-size: 16px;
    text-shadow: 2px 2px 0 var(--bg-dark), -1px -1px 0 var(--accent);
}

.combo-display {
    color: var(--secondary);
    font-size: 18px;
    transition: transform 0.1s;
}

.combo-display.pop {
    transform: scale(1.5);
    color: #fff;
}

.hitbox-indicator {
    position: absolute;
    top: 40px;
    right: 15px;
    font-size: 10px;
    color: var(--text-muted);
    opacity: 0;
    transition: opacity 0.3s;
}

.hitbox-indicator.active {
    opacity: 1;
    color: var(--accent);
}

/* Floating text container overlaid on canvas */
.floating-text {
    position: absolute;
    pointer-events: none;
    font-family: var(--font-retro);
    font-size: 12px;
    color: var(--secondary);
    text-shadow: 1px 1px 0 #000;
    animation: floatUp 1s ease-out forwards;
    z-index: 5;
}

@keyframes floatUp {
    0% { transform: translateY(0) scale(1); opacity: 1; }
    100% { transform: translateY(-30px) scale(1.2); opacity: 0; }
}

/* ---------- Overlays ---------- */
.overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--overlay-bg);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 20;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
    backdrop-filter: blur(4px);
}

.overlay.active {
    opacity: 1;
    pointer-events: all;
}

.panel {
    background: linear-gradient(135deg, rgba(26,10,10,0.9), rgba(40,10,10,0.9));
    border: 2px solid var(--primary);
    box-shadow: 0 0 15px rgba(239, 68, 68, 0.4), inset 0 0 10px rgba(239, 68, 68, 0.2);
    padding: 30px;
    text-align: center;
    max-width: 90%;
    width: 500px;
    border-radius: 4px; /* Slight rounding but keep mostly square for retro */
}

h1 {
    font-size: 24px;
    color: var(--primary);
    margin-bottom: 20px;
    text-shadow: 3px 3px 0 var(--bg-dark), 0 0 10px var(--primary);
    line-height: 1.4;
}

h2 {
    font-size: 20px;
    color: var(--text-light);
    margin-bottom: 20px;
}

h3 {
    font-size: 14px;
    color: var(--secondary);
    margin-bottom: 15px;
}

p {
    font-size: 10px;
    line-height: 1.6;
    color: var(--text-muted);
    margin-bottom: 10px;
}

/* ---------- UI Elements ---------- */
button {
    font-family: var(--font-retro);
    background: transparent;
    border: 2px solid var(--text-muted);
    color: var(--text-muted);
    padding: 12px 20px;
    margin: 10px 5px;
    cursor: pointer;
    text-transform: uppercase;
    font-size: 12px;
    transition: all 0.2s;
}

button:hover {
    border-color: var(--primary);
    color: var(--text-light);
    box-shadow: 0 0 10px rgba(239, 68, 68, 0.3);
}

.primary-btn {
    border-color: var(--primary);
    color: var(--primary);
    font-size: 16px;
    padding: 15px 30px;
    box-shadow: inset 0 0 5px rgba(239, 68, 68, 0.2);
}

.primary-btn:hover {
    background: var(--primary);
    color: var(--bg-dark);
    box-shadow: 0 0 15px var(--primary);
}

.danger-btn {
    border-color: #EF4444;
    color: #EF4444;
}

.danger-btn:hover {
    background: #EF4444;
    color: white;
}

/* Ship Selection */
.ship-selection {
    margin-bottom: 20px;
    padding-bottom: 20px;
    border-bottom: 1px dashed rgba(239, 68, 68, 0.3);
}

.ship-options, .filter-controls {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px;
}

.ship-btn, .mode-btn, .tab-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 10px;
    width: calc(33% - 10px);
    min-width: 120px;
}

.mode-btn {
    min-width: calc(50% - 10px);
}

.ship-btn small {
    font-size: 8px;
    margin-top: 5px;
    color: var(--text-muted);
}

button.active {
    border-color: var(--accent);
    color: var(--text-light);
    box-shadow: 0 0 10px rgba(34, 197, 94, 0.3);
}

button.active small {
    color: var(--accent);
}

/* Game Over Stats */
.stats {
    margin: 20px 0;
    text-align: left;
    display: inline-block;
}

.stats p {
    font-size: 14px;
    color: var(--text-light);
    margin-bottom: 15px;
}

.stats span {
    color: var(--secondary);
    float: right;
    margin-left: 20px;
}

#new-high-score-form {
    margin: 20px 0;
    padding: 15px;
    background: rgba(34, 197, 94, 0.1);
    border: 1px solid var(--accent);
}

#new-high-score-form h3 {
    color: var(--accent);
    animation: flash 1s infinite;
}

@keyframes flash {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

#player-name {
    font-family: var(--font-retro);
    background: transparent;
    border: none;
    border-bottom: 2px solid var(--text-light);
    color: var(--accent);
    font-size: 24px;
    text-align: center;
    width: 80px;
    padding: 5px;
    text-transform: uppercase;
    outline: none;
}

/* Leaderboard */
.leaderboard-list-container {
    height: 250px;
    overflow-y: auto;
    margin-bottom: 20px;
    text-align: left;
    padding: 10px;
    background: rgba(0,0,0,0.5);
    border: 1px inset rgba(239, 68, 68, 0.2);
}

/* Custom Scrollbar for Retro feel */
::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-track { background: var(--bg-dark); }
::-webkit-scrollbar-thumb { background: var(--primary); }

#leaderboard-list {
    list-style-type: decimal;
    padding-left: 30px;
    color: var(--text-muted);
    font-size: 12px;
}

#leaderboard-list li {
    margin-bottom: 10px;
    padding-bottom: 5px;
    border-bottom: 1px dashed rgba(255,255,255,0.1);
}

.lb-entry {
    display: flex;
    justify-content: space-between;
}

.lb-name { color: var(--text-light); }
.lb-score { color: var(--secondary); }

/* ---------- Touch Controls ---------- */
#touch-controls {
    display: none;
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 40%; /* Bottom 40% of screen */
    z-index: 15;
    pointer-events: none;
}

/* Touch available indicator */
@media (hover: none) and (pointer: coarse) {
    #touch-controls {
        display: flex;
        justify-content: space-between;
    }
}

#joystick-zone {
    width: 50%;
    height: 100%;
    position: relative;
    pointer-events: all;
}

#joystick-base {
    position: absolute;
    bottom: 30px;
    left: 30px;
    width: 100px;
    height: 100px;
    border-radius: 50%;
    background: rgba(239, 68, 68, 0.1);
    border: 2px solid rgba(239, 68, 68, 0.3);
    display: none; /* Shown on touch start */
    transform: translate(-50%, -50%);
}

#joystick-knob {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(239, 68, 68, 0.6);
    transform: translate(-50%, -50%);
}

#action-zone {
    width: 50%;
    height: 100%;
    pointer-events: all;
    position: relative;
}

#touch-bomb-btn {
    position: absolute;
    bottom: 30px;
    right: 30px;
    width: 70px;
    height: 70px;
    border-radius: 50%;
    background: rgba(248, 113, 113, 0.2);
    border: 2px solid var(--secondary);
    color: var(--secondary);
    padding: 0;
    font-size: 10px;
}

#touch-hitbox-btn {
    position: absolute;
    bottom: 120px;
    right: 30px;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: rgba(34, 197, 94, 0.2);
    border: 2px solid var(--accent);
    color: var(--accent);
    padding: 0;
    font-size: 8px;
}

.controls-info p {
    margin: 5px 0;
}

/* Screen shake */
.shake {
    animation: shakeAnim 0.3s cubic-bezier(.36,.07,.19,.97) both;
}

@keyframes shakeAnim {
    10%, 90% { transform: translate3d(-1px, 0, 0); }
    20%, 80% { transform: translate3d(2px, 0, 0); }
    30%, 50%, 70% { transform: translate3d(-4px, 0, 0); }
    40%, 60% { transform: translate3d(4px, 0, 0); }
}

.hidden {
    display: none !important;
}
