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

:root {
    --bg-color: #0d0e15;
    --text-color: #f4f4f4;
    --primary-color: #ff003c;
    --secondary-color: #00f0ff;
    --health-color: #ff2a2a;
    --armor-color: #2a7aff;
    --hud-bg: rgba(0, 0, 0, 0.7);
}

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

body {
    background-color: #000;
    color: var(--text-color);
    font-family: 'Press Start 2P', monospace;
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    width: 100vw;
}

#game-container {
    position: relative;
    width: 100vw;
    height: 100vh;
    overflow: hidden;
    background-color: var(--bg-color);
}

/* Crisp pixel rendering */
canvas {
    display: block;
    width: 100vw;
    height: 100vh;
    cursor: none;
    image-rendering: -moz-crisp-edges;
    image-rendering: -webkit-crisp-edges;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
    object-fit: contain; /* keep aspect ratio */
}

/* --- UI Layers --- */
#ui-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none; /* Let clicks pass through to canvas when playing */
    display: flex;
    flex-direction: column;
}

.hidden {
    display: none !important;
}

.screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    background: rgba(0, 0, 0, 0.85);
    pointer-events: auto;
    z-index: 10;
}

/* --- HUD --- */
#hud {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    width: 100%;
    height: 100%;
    padding: 20px;
    z-index: 5;
}

.hud-top, .hud-bottom {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
}

.hud-top {
    align-items: flex-start;
}

.bars-container {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.health-bar, .armor-bar {
    width: 200px;
    height: 20px;
    background: #333;
    border: 2px solid #fff;
    position: relative;
    box-shadow: 2px 2px 0 #000;
}

.bar-label {
    position: absolute;
    left: 5px;
    top: 4px;
    font-size: 10px;
    color: #fff;
    z-index: 2;
    text-shadow: 1px 1px 0px #000;
}

#health-fill {
    width: 100%;
    height: 100%;
    background: var(--health-color);
    transition: width 0.1s linear;
}

#armor-fill {
    width: 100%;
    height: 100%;
    background: var(--armor-color);
    transition: width 0.1s linear;
}

.stats span, .fps-counter {
    background: var(--hud-bg);
    padding: 10px;
    border: 2px solid var(--secondary-color);
    margin-left: 10px;
    font-size: 14px;
    text-shadow: 2px 2px 0px #000;
}

.stats {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 10px;
}

.wave-text {
    background: var(--hud-bg) !important;
    padding: 10px 20px !important;
    border: 3px solid var(--primary-color) !important;
    font-size: 20px !important;
    font-weight: bold;
    color: var(--primary-color);
    text-shadow: 2px 2px 0px #000;
}

.hud-bottom {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
}

.weapon-inventory {
    display: flex;
    gap: 5px;
    margin-right: auto;
}

.weapon-slot {
    width: 48px;
    height: 48px;
    background: #111;
    border: 2px solid #444;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    position: relative;
    opacity: 0.5;
    transition: all 0.2s;
}

.weapon-slot.owned {
    opacity: 1;
    border-color: var(--primary-color);
}

.weapon-slot.active {
    background: #331122;
    border-color: #ff3366;
    box-shadow: 0 0 10px #ff3366;
    transform: translateY(-5px);
}

.weapon-slot img {
    width: 32px;
    height: 32px;
    image-rendering: pixelated;
}

.weapon-slot-num {
    position: absolute;
    top: -10px;
    left: -5px;
    background: var(--secondary-color);
    color: #fff;
    font-size: 10px;
    padding: 2px 5px;
    border: 1px solid #fff;
}

.center-hud {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 10px;
    align-items: center;
    z-index: 10;
}

.weapon-info {
    display: flex;
    gap: 10px;
    align-items: center;
    background: var(--hud-bg);
    border: 2px solid var(--secondary-color);
    padding: 5px 15px;
}
.weapon-info span {
    font-size: 16px;
    text-shadow: 2px 2px 0px #000;
}

.pause-btn {
    display: none;
    background: var(--hud-bg);
    border: 2px solid var(--secondary-color);
    color: #fff;
    font-size: 14px;
    padding: 5px 10px;
    cursor: pointer;
    font-family: inherit;
    pointer-events: auto;
    z-index: 10;
}
.pause-btn:active {
    background: var(--secondary-color);
    color: #000;
}

/* --- Buttons --- */
.pixel-btn {
    background: transparent;
    color: var(--secondary-color);
    border: 4px solid var(--secondary-color);
    font-family: inherit;
    font-size: 20px;
    padding: 15px 30px;
    margin: 10px;
    cursor: pointer;
    text-transform: uppercase;
    transition: all 0.1s;
    pointer-events: auto;
    box-shadow: 4px 4px 0px var(--primary-color);
}

.pixel-btn:hover {
    background: var(--secondary-color);
    color: #000;
    box-shadow: 0px 0px 0px var(--primary-color);
    transform: translate(4px, 4px);
}

.pixel-btn:active {
    background: var(--primary-color);
    border-color: var(--primary-color);
    color: #fff;
}

input[type="text"], input[type="password"] {
    background: #111;
    border: 2px solid var(--primary-color);
    color: #fff;
    font-family: 'Courier New', Courier, monospace;
    font-size: 16px;
    padding: 10px;
    margin: 10px 0 20px 0;
    text-align: center;
    width: 250px;
}
input[type="text"]:focus, input[type="password"]:focus {
    outline: none;
    background: #222;
    border-color: #ff3366;
}

/* --- Menus --- */
#main-menu {
    background: transparent;
}

h1, h2 {
    color: #fff;
    margin-bottom: 30px;
    text-shadow: 4px 4px 0px var(--primary-color);
    font-size: 40px;
    text-align: center;
}

.game-logo {
    width: 96px;
    height: 96px;
    image-rendering: -moz-crisp-edges;
    image-rendering: -webkit-crisp-edges;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
    margin-bottom: 15px;
    filter: drop-shadow(4px 4px 0px var(--primary-color));
}

.setting-item {
    margin: 15px 0;
    display: flex;
    justify-content: space-between;
    width: 400px;
    align-items: center;
    color: #fff;
}

.drops-info {
    display: flex;
    gap: 20px;
    margin: 20px 0 40px 0;
}

.drop-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    color: #fff;
    font-size: 10px;
}

.drop-item img {
    width: 32px;
    height: 32px;
    image-rendering: -moz-crisp-edges;
    image-rendering: -webkit-crisp-edges;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
    margin-bottom: 10px;
    filter: drop-shadow(2px 2px 0px #000);
}

/* --- Visual Effects --- */
.crt-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: radial-gradient(circle, rgba(0,0,0,0) 60%, rgba(0,0,0,0.6) 100%);
    pointer-events: none;
    z-index: 50;
    mix-blend-mode: overlay;
}

.scanlines {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(
        to bottom,
        rgba(255,255,255,0),
        rgba(255,255,255,0) 50%,
        rgba(0,0,0,0.2) 50%,
        rgba(0,0,0,0.2)
    );
    background-size: 100% 4px; /* Scaled scanline size */
    pointer-events: none;
    z-index: 51;
}

/* Glitch Animation for Title */
.glitch {
    position: relative;
}
.glitch::before, .glitch::after {
    content: attr(data-text);
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.85);
}
.glitch::before {
    left: 2px;
    text-shadow: -2px 0 red;
    clip: rect(24px, 550px, 90px, 0);
    animation: glitch-anim-2 3s infinite linear alternate-reverse;
}
.glitch::after {
    left: -2px;
    text-shadow: -2px 0 blue;
    clip: rect(85px, 550px, 140px, 0);
    animation: glitch-anim 2.5s infinite linear alternate-reverse;
}

@keyframes glitch-anim {
    0% { clip: rect(20px, 9999px, 85px, 0); }
    20% { clip: rect(92px, 9999px, 11px, 0); }
    40% { clip: rect(43px, 9999px, 65px, 0); }
    60% { clip: rect(78px, 9999px, 90px, 0); }
    80% { clip: rect(12px, 9999px, 32px, 0); }
    100% { clip: rect(54px, 9999px, 78px, 0); }
}
@keyframes glitch-anim-2 {
    0% { clip: rect(12px, 9999px, 54px, 0); }
    20% { clip: rect(85px, 9999px, 98px, 0); }
    40% { clip: rect(23px, 9999px, 34px, 0); }
    60% { clip: rect(65px, 9999px, 12px, 0); }
    80% { clip: rect(99px, 9999px, 45px, 0); }
    100% { clip: rect(32px, 9999px, 21px, 0); }
}

.blood-text {
    color: var(--health-color);
    text-shadow: 4px 4px 0px #550000;
}

/* Mobile Controls */
#mobile-controls {
    position: absolute;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    pointer-events: none;
    z-index: 1000;
}

#mobile-controls:not(.hidden) {
    display: block;
}

#mobile-controls.hidden {
    display: none;
}

.joystick-base {
    position: absolute;
    width: 120px;
    height: 120px;
    background: rgba(0, 0, 0, 0.5);
    border: 4px solid var(--primary-color);
    pointer-events: auto;
    touch-action: none;
    box-shadow: inset 0px 0px 10px rgba(0, 255, 255, 0.2);
}

.joystick-knob {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 50px;
    height: 50px;
    background: var(--secondary-color);
    border: 4px solid #fff;
    transform: translate(-50%, -50%);
    pointer-events: none;
    box-shadow: 4px 4px 0px #000;
}

#joystick-left {
    bottom: 40px;
    left: 40px;
}

#joystick-right {
    bottom: 40px;
    right: 40px;
}

#mobile-buttons {
    position: absolute;
    bottom: 180px;
    right: 40px;
    display: flex;
    flex-direction: column;
    gap: 15px;
    pointer-events: auto;
}

.mobile-btn {
    background: rgba(0, 0, 0, 0.5);
    border: 4px solid var(--secondary-color);
    color: var(--secondary-color);
    font-family: inherit;
    font-size: 10px;
    font-weight: bold;
    width: 60px;
    height: 60px;
    padding: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    text-align: center;
    pointer-events: auto;
    touch-action: none;
    box-shadow: 4px 4px 0px var(--primary-color);
    text-transform: uppercase;
    transition: all 0.1s;
}

.mobile-btn:active {
    background: var(--secondary-color);
    color: #000;
    box-shadow: 0px 0px 0px var(--primary-color);
    transform: translate(4px, 4px);
}

/* Responsive UI Tweaks */
@media (max-width: 1024px) {
    #menu-ui {
        width: 100vw;
        height: 100vh;
    }
    
    .menu {
        padding: 10px;
        overflow-y: hidden;
        justify-content: center;
    }
    
    h1, h2 {
        font-size: 16px;
        margin-bottom: 5px;
    }
    
    .game-logo {
        width: 32px;
        height: 32px;
        margin-bottom: 5px;
    }

    .settings-list {
        grid-template-columns: 1fr !important;
        max-height: 50vh;
        overflow-y: auto;
    }
    
    .pixel-btn {
        padding: 8px 12px !important;
        font-size: 10px !important;
        margin-bottom: 5px !important;
    }
    h3#current-username {
        margin-bottom: 10px !important;
        font-size: 14px !important;
    }
    /* HUD mobile tweaks */
    #hud {
        padding: 10px;
    }
    .stats span, .fps-counter {
        padding: 5px;
        font-size: 10px;
        margin-left: 5px;
    }
    .health-bar, .armor-bar {
        width: 120px;
        height: 12px;
    }
    .bar-label {
        font-size: 8px;
        top: 1px;
    }
    .wave-text {
        padding: 5px 10px !important;
        font-size: 14px !important;
    }
    .weapon-slot {
        width: 32px;
        height: 32px;
    }
    .hud-bottom {
        width: 100%;
        justify-content: center;
        align-items: center;
        flex-direction: column;
        z-index: 10;
    }
    .center-hud {
        top: 10px;
        bottom: auto;
    }

    .weapon-inventory {
        margin-right: 0;
    }
    .fps-counter {
        display: none !important;
    }
    .joystick-base {
        width: 100px;
        height: 100px;
    }
    #mobile-buttons {
        bottom: 150px;
        right: 40px;
        flex-direction: row;
        gap: 15px;
    }
    .mobile-btn {
        font-size: 8px;
    }
    .weapon-info {
        padding: 5px 10px;
        gap: 5px;
    }
    .weapon-info span {
        font-size: 12px;
    }
    .pause-btn {
        display: block !important;
        padding: 5px !important;
        font-size: 14px;
        background: var(--hud-bg) !important;
        border: 2px solid var(--secondary-color) !important;
        color: var(--secondary-color);
    }
    #joystick-left { left: 40px; bottom: 40px; }
    #joystick-right { right: 40px; bottom: 40px; }
}
