:root {
    --bg-color: #0a0a10;
    --panel-bg: #14141e;
    --text-primary: #e0e0e0;
    --text-secondary: #a0a0b0;
    --accent-color: #00f0ff;
    --accent-glow: rgba(0, 240, 255, 0.3);
    --danger-color: #ff2a6d;
    --font-heading: 'Orbitron', sans-serif;
    --font-body: 'Inter', sans-serif;
}

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

body {
    /* ... existing body styles ... */

    color: var(--text-primary);
    font-family: var(--font-body);
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}



@media (max-width: 800px) and (orientation: landscape) {

    /* Compact Landscape Login */
    body {
        height: 100vh;
        overflow: hidden;
    }

    .container {
        justify-content: center !important;
        padding-top: 0 !important;
    }

    h1 {
        font-size: 1.5rem !important;
        margin: 5px 0 !important;
    }

    .server-status-bar {
        position: fixed;
        padding: 2px 10px;
        font-size: 0.6rem;
    }

    .menu-box {
        padding: 1rem;
        max-width: 500px;
        /* Wider for landscape */
        display: flex;
        flex-direction: row;
        /* Horizontal layout? No, inputs still stacked usually better, maybe 2 cols */
        gap: 1rem;
        align-items: center;
        justify-content: center;
    }

    .menu-box form {
        flex: 1;
        width: 100%;
    }

    .menu-box hr {
        display: none;
        /* Hide separator, maybe use border-left? */
    }

    /* If we keep stacked, just reduce vertical */
    .menu-box {
        flex-direction: column;
        padding: 0.8rem;
        max-width: 350px;
    }

    .menu-box input {
        padding: 5px;
        margin-bottom: 5px;
        font-size: 0.8rem;
    }

    .menu-box button {
        padding: 5px;
        font-size: 0.9rem;
    }

    .menu-box hr {
        margin: 0.5rem 0;
        display: block;
    }
}

@media (max-width: 600px) and (orientation: portrait) {

    /* Tight Portrait Login */
    .container {
        justify-content: center;
        padding-top: 2rem;
    }

    h1 {
        font-size: 1.8rem;
        margin: 1rem 0;
    }

    .server-status-bar {
        padding: 5px;
    }

    .menu-box {
        width: 90%;
        padding: 1.5rem;
    }
}

.app-container {
    display: flex;
    flex-direction: column;
    height: 100%;
    align-items: center;
    padding: 1rem;
}

header {
    margin-bottom: 1rem;
    text-align: center;
}

h1 {
    font-family: var(--font-heading);
    font-size: 2rem;
    letter-spacing: 2px;
    color: var(--text-primary);
}

.accent {
    color: var(--accent-color);
    text-shadow: 0 0 10px var(--accent-glow);
}

main {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    max-width: 1200px;
}

.game-wrapper {
    position: relative;
    border: 2px solid var(--panel-bg);
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.5);
    border-radius: 4px;
    background-color: #0f0f16;
}

canvas {
    display: block;
    background-color: #0f0f16;
}

.overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(10, 10, 16, 0.95);
    display: flex;
    justify-content: center;
    align-items: center;
    backdrop-filter: blur(8px);
    transition: opacity 0.3s ease;
    z-index: 200;
    /* High Z to cover everything */
    pointer-events: auto;
}

.overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

/* Garage Styles */
.garage-panel {
    background: var(--panel-bg);
    padding: 1rem;
    border: 1px solid var(--accent-color);
    border-radius: 8px;
    box-shadow: 0 0 30px var(--accent-glow);
    width: 95%;
    max-width: 1000px;
    max-height: 90vh;
    /* Better for mobile */
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
    z-index: 300;
    /* Ensure above everything */
    position: relative;
}

@media (max-width: 800px) {
    .garage-panel {
        width: 100%;
        height: 100%;
        max-height: 100%;
        border: none;
        border-radius: 0;
    }
}

.garage-panel h2 {
    font-family: var(--font-heading);
    color: var(--accent-color);
    text-align: center;
    border-bottom: 1px solid var(--accent-color);
    padding-bottom: 0.5rem;
    margin-bottom: 0.2rem;
}

.config-section label {
    display: block;
    font-family: var(--font-heading);
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-bottom: 0.2rem;
    letter-spacing: 1px;
    margin-bottom: 0.2rem;
    letter-spacing: 1px;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    background: rgba(255, 255, 255, 0.05);
    padding: 10px;
    border-radius: 4px;
    border: 1px solid #3a3a45;
    color: var(--text-primary) !important;
    /* Override label color */
}

.checkbox-label:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: var(--text-secondary);
}

.checkbox-label input {
    cursor: pointer;
    width: 20px;
    height: 20px;
}

.options {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
    gap: 0.5rem;
}

.option-btn {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid #3a3a45;
    padding: 0.8rem;
    border-radius: 4px;
    cursor: pointer;
    text-align: left;
    transition: all 0.2s;
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}

.option-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: var(--text-secondary);
}

.option-btn.active {
    background: rgba(0, 240, 255, 0.1);
    border-color: var(--accent-color);
    box-shadow: 0 0 10px rgba(0, 240, 255, 0.1);
}

.death-btn.terminate {
    background: rgba(255, 77, 77, 0.2);
    border-color: #ff4d4d;
    color: #ff4d4d;
}

.death-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    transform: translateY(-2px);
    box-shadow: 0 0 15px rgba(0, 240, 255, 0.5);
}

.death-btn.disabled {
    opacity: 0.5;
    cursor: not-allowed;
    filter: grayscale(100%);
    pointer-events: none;
}

#death-timer {
    font-size: 1.5rem;
    color: #00f0ff;
    margin: 10px 0;
    text-shadow: 0 0 10px #00f0ff;
    font-family: 'Share Tech Mono', monospace;
}

.opt-name {
    color: var(--text-primary);
    font-weight: bold;
    font-size: 0.9rem;
}

.opt-desc {
    color: var(--text-secondary);
    font-size: 0.75rem;
}

#btn-deploy {
    margin-top: 1rem;
    background: var(--accent-color);
    color: var(--bg-color);
    border: none;
    padding: 1rem;
    font-family: var(--font-heading);
    font-weight: bold;
    font-size: 1.2rem;
    cursor: pointer;
    text-transform: uppercase;
    letter-spacing: 2px;
    transition: all 0.2s;
    align-self: center;
    width: 100%;
    max-width: 300px;
}

#btn-deploy:hover {
    box-shadow: 0 0 20px var(--accent-glow);
    transform: scale(1.02);
}

footer {
    width: 100%;
    margin-top: 1rem;
    border-top: 1px solid var(--panel-bg);
    padding-top: 0.5rem;
}

.status-bar {
    display: flex;
    justify-content: space-between;
    font-family: monospace;
    font-size: 0.8rem;
    color: var(--text-secondary);
    max-width: 800px;
    margin: 0 auto;
}

.online {
    color: #4ade80;
}

/* HUD Styles */
.hud-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    padding: 1.5rem;
    z-index: 10;
}

.hud-top-bar {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    width: 100%;
}

.hud-group {
    flex: 1;
    display: flex;
}

/* Left: HP */
.hud-left {
    justify-content: flex-start;
    align-items: center;
    gap: 15px;
}

.helmet-icon {
    width: 50px;
    height: 50px;
    background: rgba(0, 0, 0, 0.5);
    border: 1px solid var(--accent-color);
    border-radius: 5px;
    padding: 2px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.helmet-icon img {
    width: 100%;
    height: 100%;
}

.hp-container {
    display: flex;
    flex-direction: column;
}

.hp-text {
    font-family: var(--font-heading);
    font-size: 1.2rem;
    color: var(--accent-color);
    text-shadow: 0 0 5px var(--accent-glow);
}

.hp-bar-bg {
    width: 200px;
    height: 10px;
    background: #2a2a35;
    border: 1px solid #3a3a45;
    margin-top: 5px;
}

.hp-bar-fill {
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, #ff2a6d 0%, #4ade80 100%);
    transition: width 0.2s ease-out;
}

/* Center: Reload */
.hud-center {
    justify-content: center;
    padding-top: 5px;
    /* Slight offset align with HP bar visually */
}

.reload-indicator {
    width: 40px;
    /* Smaller */
    height: 40px;
}

.reload-svg {
    width: 100%;
    height: 100%;
    transform: rotate(-90deg);
    /* Start from top */
    overflow: visible;
}

.reload-bg {
    fill: rgba(0, 0, 0, 0.5);
    stroke: #2a2a35;
    stroke-width: 2;
}

.reload-fill {
    fill: none;
    stroke-width: 16;
    /* Half radius = full thick pie */
    transition: stroke-dasharray 0.05s linear, stroke 0.2s;
}

/* Right: Score */
.hud-right {
    justify-content: flex-end;
    align-items: center;
}

/* Game UI Bars (Header/Footer) */
.game-ui-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    max-width: 800px;
    /* Match Canvas Width */
    background: rgba(20, 20, 30, 0.9);
    border: 1px solid #333;
    padding: 0.5rem 1rem;
    margin: 5px 0;
    pointer-events: auto;
}

#game-header {
    border-bottom: none;
    border-radius: 4px 4px 0 0;
    margin-bottom: 0;
}

#game-footer {
    border-top: none;
    border-radius: 0 0 4px 4px;
    margin-top: 0;
}

/* Remove old HUD layer styles that might conflict */
/* Reusing hud-group, hud-left, etc within the new bar */

.score-box {
    font-family: var(--font-heading);
    font-size: 1.5rem;
    color: var(--text-primary);
    background: rgba(0, 0, 0, 0.5);
    padding: 0.5rem 2rem;
    /* Wider padding */
    border-radius: 4px;
    border: 1px solid #3a3a45;
    min-width: 150px;
    /* Prevent wrapping */
    text-align: center;
}

.room-info {
    font-family: var(--font-heading);
    font-size: 1rem;
    color: var(--text-secondary);
}

.hud-exit-btn {
    pointer-events: auto;
    background: rgba(255, 42, 109, 0.2);
    border: 1px solid var(--danger-color);
    color: var(--danger-color);
    padding: 0.5rem 1.5rem;
    font-family: var(--font-heading);
    font-weight: bold;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s;
    text-transform: uppercase;
    border-radius: 4px;
}

.hud-exit-btn:hover {
    background: rgba(255, 42, 109, 0.4);
    box-shadow: 0 0 10px rgba(255, 42, 109, 0.3);
}

/* =========================================
   LOBBY & UI POLISH
   ========================================= */

/* Grid Background Animation */
body::before {
    content: "";
    position: absolute;
    width: 200%;
    height: 200%;
    top: -50%;
    left: -50%;
    background-image:
        linear-gradient(rgba(0, 240, 255, 0.1) 1px, transparent 1px),
        linear-gradient(90deg, rgba(0, 240, 255, 0.1) 1px, transparent 1px);
    background-size: 50px 50px;
    transform: perspective(500px) rotateX(45deg);
    animation: gridMove 20s linear infinite;
    z-index: -1;
    pointer-events: none;
}

@keyframes gridMove {
    0% {
        transform: perspective(500px) rotateX(45deg) translateY(0);
    }

    100% {
        transform: perspective(500px) rotateX(45deg) translateY(50px);
    }
}

/* Server Status Bar */
.server-status-bar {
    position: absolute;
    top: 0;
    width: 100%;
    background: rgba(10, 10, 16, 0.8);
    border-bottom: 1px solid #333;
    padding: 5px 10px;
    font-size: 0.7rem;
    color: var(--text-secondary);
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 10px;
    z-index: 400;
}

.status-icon {
    color: #4ade80;
    text-shadow: 0 0 5px #4ade80;
    animation: blink 2s infinite;
}

@keyframes blink {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.5;
    }
}

/* Menu Box (Landing & Lobby) */

.menu-box {
    background: rgba(20, 20, 30, 0.9);
    border: 1px solid var(--accent-color);
    box-shadow: 0 0 30px rgba(0, 240, 255, 0.15);
    padding: 2rem;
    border-radius: 8px;
    text-align: center;
    backdrop-filter: blur(10px);
    width: 100%;
    max-width: 600px;
}

/* Landing Layout */
.landing-container {
    display: flex;
    justify-content: center;
    align-items: flex-start;
    gap: 20px;
    width: 100%;
    max-width: 1400px;
    padding: 20px;
    flex-wrap: wrap;
}

.admin-panel {
    display: none;
    /* Hidden by default */
    background: rgba(20, 20, 30, 0.95);
    border: 1px solid #ff4444;
    box-shadow: 0 0 30px rgba(255, 68, 68, 0.15);
    padding: 2rem;
    border-radius: 8px;
    width: 100%;
    max-width: 600px;
    flex: 1;
    min-width: 300px;
}

.admin-panel.active {
    display: block;
}

.admin-panel h2 {
    color: #ff4444;
    margin-bottom: 1rem;
    font-family: var(--font-heading);
    text-shadow: 0 0 10px rgba(255, 68, 68, 0.3);
}


.menu-box input {
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid #333;
    color: #fff;
    padding: 10px;
    width: 100%;
    margin-bottom: 10px;
    font-family: var(--font-heading);
    letter-spacing: 1px;
    transition: all 0.2s;
}

.menu-box input:focus {
    border-color: var(--accent-color);
    outline: none;
    box-shadow: 0 0 10px rgba(0, 240, 255, 0.2);
}

.menu-box button {
    background: var(--accent-color);
    color: #000;
    border: none;
    padding: 10px 20px;
    font-weight: bold;
    width: 100%;
    cursor: pointer;
    font-family: var(--font-heading);
    text-transform: uppercase;
    transition: all 0.2s;
}

.menu-box button:hover {
    background: #fff;
    box-shadow: 0 0 15px var(--accent-color);
}

.menu-box hr {
    border: 0;
    height: 1px;
    background: #333;
    margin: 1.5rem 0;
}

/* Lobby Player List */
#player-list {
    margin: 1rem 0;
    text-align: left;
    max-height: 200px;
    overflow-y: auto;
    border: 1px solid #333;
    background: rgba(0, 0, 0, 0.2);
    padding: 0.5rem;
}

#players {
    list-style: none;
    padding: 0;
}

#players li {
    padding: 8px;
    border-bottom: 1px solid #222;
    color: var(--text-secondary);
    display: flex;
    justify-content: space-between;
}

#players li:last-child {
    border-bottom: none;
}

/* Death Screen */
.death-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 50;
    /* Above HUD */
    display: flex;
    justify-content: center;
    align-items: center;
    animation: fadeIn 0.5s ease;
}

.death-overlay.hidden {
    display: none !important;
}

.death-content {
    text-align: center;
    width: 600px;
}

.signal-lost {
    color: #ff2a6d;
    font-family: 'Courier New', monospace;
    font-size: 3rem;
    margin-bottom: 2rem;
    text-shadow: 0 0 10px #ff2a6d;
    animation: pulseText 2s infinite;
}

.ekg-monitor {
    width: 100%;
    height: 100px;
    background: #000;
    border: 1px solid #333;
    margin-bottom: 2rem;
    position: relative;
    overflow: hidden;
}

.ekg-svg {
    width: 100%;
    height: 100%;
}

.ekg-line {
    fill: none;
    stroke: #ff2a6d;
    stroke-width: 3;
    stroke-linecap: round;
    stroke-linejoin: round;
    /* Simulate flatline animation */
    /* We'll use JS or complex CSS keyframes to switch from Pulse to Flat */
    animation: ekgFlatline 4s forwards;
}

/* Keyframe for EKG: Normal pulse then flat */
@keyframes ekgFlatline {
    0% {
        stroke-dasharray: 500;
        stroke-dashoffset: 500;
        opacity: 0;
    }

    10% {
        opacity: 1;
        stroke-dashoffset: 0;
        /* Draw line */
    }

    40% {
        /* Pulse phase */
        transform: scaleY(1);
    }

    50% {
        /* Flatline start - animate points via SVG SMIL or just clear transforms? 
           CSS cannot modify points. We rely on the SVG path shape being static "flatline" visually
           OR we use a clip-path reveal.
           Let's stick to a simple reveal of the static jagged line for now, 
           or use a pre-baked GIF/Video if we wanted perfection. 
           Actually, let's keep it simple: Just draw the line.
        */
        opacity: 1;
    }

    100% {
        opacity: 0.5;
    }
}

.death-controls {
    display: flex;
    justify-content: center;
    gap: 2rem;
}

.death-btn {
    border: 2px solid;
    background: transparent;
    padding: 1rem 2rem;
    font-family: var(--font-heading);
    font-size: 1.2rem;
    cursor: pointer;
    transition: all 0.3s;
    text-transform: uppercase;
}

.death-btn.redeploy {
    border-color: #4ade80;
    color: #4ade80;
}

.death-btn.redeploy:hover {
    background: #4ade80;
    color: #000;
    box-shadow: 0 0 20px #4ade80;
}

.death-btn.terminate {
    border-color: #ff2a6d;
    color: #ff2a6d;
}

.death-btn.terminate:hover {
    background: #ff2a6d;
    color: #000;
    box-shadow: 0 0 20px #ff2a6d;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

@keyframes pulseText {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.5;
    }
}

/* Mobile Controls */
#mobile-controls {
    display: none;
    /* Hidden by default, shown via JS if touch detected or CSS media query */
    position: fixed;
    bottom: 40px;
    left: 0;
    width: 100%;
    height: 150px;
    pointer-events: none;
    /* Let clicks pass through empty space */
    z-index: 100;
    justify-content: space-between;
    padding: 0 40px;
}

.joystick-area {
    width: 120px;
    height: 120px;
    background: rgba(255, 255, 255, 0.1);
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    position: relative;
    pointer-events: auto;
    /* Capture touch */
    touch-action: none;
}

#joystick-right {
    background: rgba(255, 42, 109, 0.1);
    border-color: rgba(255, 42, 109, 0.3);
}

.stick {
    width: 50px;
    height: 50px;
    background: rgba(0, 240, 255, 0.5);
    border-radius: 50%;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    box-shadow: 0 0 10px var(--accent-color);
}

#joystick-right .stick {
    background: rgba(255, 42, 109, 0.5);
    box-shadow: 0 0 10px var(--danger-color);
}

/* Show on Mobile */
@media (max-width: 800px),
(hover: none) {
    #mobile-controls {
        display: flex;
    }

    .game-ui-bar {
        font-size: 0.7rem;
        padding: 0.2rem;
        max-width: 100%;
    }

    .score-box {
        min-width: 80px;
        padding: 0.2rem 0.5rem;
        font-size: 1rem;
    }

    /* Hide redundant "LEAVE" or make small */
    #btn-leave {
        padding: 0.2rem 0.5rem;
        font-size: 0.7rem;
    }
}