:root {
    --color-bg: #050510;
    --color-primary: #00f0ff;
    --color-secondary: #ff0055;
    --color-ui-bg: rgba(0, 20, 40, 0.85);
    --font-heading: 'Orbitron', sans-serif;
    --font-body: 'Rajdhani', sans-serif;
}

body,
html {
    margin: 0;
    padding: 0;
    overflow: hidden;
    background-color: var(--color-bg);
}

:focus {
    outline: none;
}

/* Scoped to avoid leaking to other apps */
#cosmic-root {
    width: 100vw;
    height: 100vh;
    background-color: var(--color-bg);
    color: white;
    font-family: var(--font-body);
    overflow: hidden;
    position: relative;
    user-select: none;
}

#btn-start-now {
    margin-top: 3rem;
}

#cosmic-root * {
    box-sizing: border-box;
}

#game-canvas {
    display: block;
    position: absolute;
    top: 0;
    left: 0;
    z-index: 1;
    transition: filter 1s ease;
}

.canvas-bg-mode {
    filter: blur(8px) brightness(0.6);
}

/* UI Overlay Layer */
.screen,
#hud {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 10;
    pointer-events: none;
    /* Let clicks pass through to canvas when playing */
}

/* HUD */
#hud {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    display: flex;
    justify-content: space-between;
    padding: 20px;
    box-sizing: border-box;
}

.hud-left {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 15px;
    /* Space between Scoreboard and Lives */
}

.hud-right {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    /* Right align right HUD */
    margin-top: 60px;
    /* Space for Global Audio Controls */
}

/* Audio Controls (Global Fixed) */
.audio-controls {
    position: absolute;
    top: 20px;
    right: 20px;
    display: flex;
    gap: 8px;
    pointer-events: auto;
    z-index: 2000;
    /* Above everything */
}

.audio-btn {
    background: rgba(0, 0, 0, 0.6);
    border: 1px solid #00f0ff;
    color: #00f0ff;
    font-family: 'Orbitron', sans-serif;
    /* Theme font */
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 1.2rem;
    border-radius: 4px;
    transition: all 0.2s;
}

.audio-btn:hover {
    background: rgba(0, 240, 255, 0.2);
    box-shadow: 0 0 10px #00f0ff;
}

.audio-btn.muted {
    border-color: #555;
    color: #555;
    text-decoration: none;
    /* Icon dimming handled by JS opacity */
}

.pixel-icon {
    width: 20px;
    height: 20px;
    fill: #00f0ff;
    shape-rendering: crispEdges;
    /* 8-bit look */
    filter: drop-shadow(0 0 2px #00f0ff);
    transition: all 0.2s;
}

.audio-btn:hover .pixel-icon {
    filter: drop-shadow(0 0 5px #00f0ff);
}

.audio-btn.muted .pixel-icon {
    fill: #555;
    filter: none;
}

/* Enable pointer events on interactive UI elements */
.screen {
    pointer-events: auto;
    background: radial-gradient(circle at center, rgba(10, 20, 60, 0.3), rgba(0, 0, 0, 0.6));
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    backdrop-filter: blur(5px);
    z-index: 100;
    /* Ensure it is above HUD/Canvas */
}

.hidden {
    display: none !important;
}

/* Typography */
h1.logo {
    font-family: var(--font-heading);
    font-size: 4rem;
    color: var(--color-primary);
    text-shadow: 0 0 20px var(--color-primary), 0 0 40px var(--color-primary);
    margin-bottom: 2rem;
    letter-spacing: 4px;
}

h2.sub-logo {
    font-family: var(--font-heading);
    font-size: 2.5rem;
    color: var(--color-primary);
    margin-bottom: 2rem;
    text-shadow: 0 0 10px var(--color-primary);
}

.blink {
    animation: blinker 1.5s linear infinite;
}

@keyframes hit-flash {
    0% {
        opacity: 0.8;
    }

    100% {
        opacity: 0;
    }
}

.hit-flash-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: white;
    pointer-events: none;
    z-index: 1000;
    animation: hit-flash 0.15s ease-out forwards;
}

@keyframes blinker {
    50% {
        opacity: 0;
    }
}

/* Controls */
.menu-options {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    align-items: center;
}

.btn {
    background: transparent;
    border: 2px solid var(--color-primary);
    color: var(--color-primary);
    padding: 1rem 2rem;
    font-family: var(--font-heading);
    font-size: 1.2rem;
    cursor: pointer;
    transition: all 0.2s;
    text-transform: uppercase;
    min-width: 200px;
    clip-path: polygon(10px 0, 100% 0, 100% calc(100% - 10px), calc(100% - 10px) 100%, 0 100%, 0 10px);
}

.btn:hover {
    background: var(--color-primary);
    color: black;
    box-shadow: 0 0 20px var(--color-primary);
}

.btn.secondary {
    border-color: var(--color-secondary);
    color: var(--color-secondary);
}

.btn.secondary:hover {
    background: var(--color-secondary);
    color: white;
    box-shadow: 0 0 20px var(--color-secondary);
}

.join-container {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    align-items: center;
    margin-top: 1rem;
    padding: 1.5rem;
    border: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(0, 0, 0, 0.5);
}

input {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid #444;
    padding: 0.8rem;
    color: white;
    font-family: var(--font-body);
    font-size: 1.2rem;
    text-align: center;
    width: 250px;
}

input:focus {
    outline: none;
    border-color: var(--color-primary);
}

/* HUD */
#hud {
    display: flex;
    justify-content: space-between;
    display: flex;
    justify-content: space-between;
    padding: 2rem;
    /* Increased padding for spacing */
    pointer-events: none;
    /* Pass through clicks to game */
}

/* Re-enable interactions for HUD controls */
#hud button,
#hud input {
    pointer-events: auto;
}

.hud-left,
.hud-right {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    width: 250px;
}

.score-box,
.lives-box {
    text-align: left;
}

.label {
    font-family: var(--font-heading);
    font-size: 0.8rem;
    color: #888;
    margin-bottom: 0.2rem;
}

.value {
    font-family: var(--font-heading);
    font-size: 1.5rem;
    color: white;
}

#lives {
    color: var(--color-secondary);
    letter-spacing: 5px;
}

#wave-display {
    font-family: var(--font-heading);
    font-size: 2rem;
    color: rgba(255, 255, 255, 0.3);
    margin-top: 2rem;
}

#chat-feed {
    height: 150px;
    background: linear-gradient(180deg, rgba(0, 0, 0, 0) 0%, rgba(0, 20, 40, 0.6) 100%);
    border-left: 2px solid var(--color-primary);
    padding: 0.5rem;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    font-size: 0.9rem;
    overflow: hidden;
}

.chat-msg {
    margin-bottom: 4px;
    text-shadow: 1px 1px 0 #000;
}

.chat-sys {
    color: #fe0;
}

.chat-p1 {
    color: #0ff;
}

.chat-p2 {
    color: #f0f;
}

.emote-bar {
    display: flex;
    gap: 0.5rem;
    justify-content: flex-end;
}

.emote-btn {
    background: rgba(255, 255, 255, 0.1);
    border: none;
    font-size: 1.2rem;
    padding: 0.5rem;
    border-radius: 4px;
    cursor: pointer;
    transition: transform 0.1s;
}

.emote-btn:hover {
    transform: scale(1.2);
    background: rgba(255, 255, 255, 0.2);
}


/* Lobby Specifics */
.lobby-code-banner {
    font-family: 'Orbitron', sans-serif;
    font-size: 2rem;
    color: #ff00ff;
    border: 2px solid #ff00ff;
    padding: 10px 20px;
    margin-bottom: 20px;
    background: rgba(255, 0, 255, 0.1);
    box-shadow: 0 0 10px #ff00ff;
    text-shadow: 0 0 5px #ff00ff;
}

.color-picker-row {
    display: flex;
    justify-content: center;
    gap: 15px;
    margin-top: 10px;
}

.color-btn {
    width: 30px;
    height: 30px;
    border: 2px solid #ccc;
    cursor: pointer;
    transition: transform 0.2s;
}

.color-btn:hover {
    transform: scale(1.1);
}

.color-btn.selected {
    border: 2px solid #fff;
    transform: scale(1.2);
}

#live-scoreboard {
    background: rgba(0, 0, 0, 0.6);
    padding: 10px;
    border: 1px solid #00f0ff;
    border-radius: 5px;
    min-width: 180px;
    text-align: left;
    /* Left align */
    margin-top: 5px;
}

.score-entry {
    font-family: 'Rajdhani', sans-serif;
    font-size: 1.2rem;
    color: #fff;
    margin-bottom: 2px;
}

.score-entry.local {
    color: #00f0ff;
    font-weight: bold;
}

.lives-box {
    margin-top: 10px;
    text-align: left;
}

/* Game Over Screen */
#game-over-screen {
    text-align: center;
    z-index: 50;
    font-family: 'Orbitron', sans-serif;
    /* Ensure headings use theme */
}

#game-over-screen h1 {
    font-size: 4rem;
    color: #ff0055;
    text-shadow: 0 0 20px #ff0055;
    margin-bottom: 0.5rem;
}

#game-over-screen h3 {
    color: #00f0ff;
    font-size: 1.5rem;
    margin-top: 20px;
    text-transform: uppercase;
    letter-spacing: 2px;
}

#final-leaderboard {
    margin-bottom: 30px;
    width: 60%;
    margin-left: auto;
    margin-right: auto;
    border: 2px solid #444;
    padding: 20px;
    background: rgba(0, 0, 0, 0.8);
}

.lb-entry {
    display: flex;
    justify-content: space-between;
    padding: 5px 0;
    border-bottom: 1px dashed #333;
    font-family: 'Rajdhani', sans-serif;
    font-size: 1.5rem;
    color: #00f0ff;
}

.lb-entry.winner {
    color: #ffd700;
    font-weight: bold;
}

/* Lobby Styling */
.lobby-name-section {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 2rem;
}

.lobby-name-section label {
    font-family: var(--font-heading);
    color: var(--color-primary);
    letter-spacing: 2px;
}

.lobby-info {
    display: flex;
    gap: 3rem;
    margin-bottom: 5rem;
}

/* Tutorial Overlay */
#tutorial-overlay {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0, 0, 0, 0.85);
    border: 2px solid var(--color-primary);
    padding: 30px 50px;
    text-align: center;
    z-index: 2000;
    box-shadow: 0 0 20px rgba(0, 240, 255, 0.3);
    border-radius: 10px;
}

#tutorial-overlay h2 {
    font-family: var(--font-heading);
    color: var(--color-primary);
    margin: 0 0 20px 0;
    font-size: 2rem;
}

#tutorial-overlay p {
    font-family: var(--font-heading);
    color: white;
    font-size: 1.2rem;
    margin: 10px 0;
}

#tutorial-overlay b {
    color: var(--color-secondary);
}

/* Scoreboard Styles */
.score-entry {
    border: 1px solid var(--color-primary);
    background: rgba(0, 0, 0, 0.5);
    padding: 0.5rem;
    margin-bottom: 0.5rem;
    font-size: 1rem;
    font-family: var(--font-heading);
    box-shadow: 0 0 5px var(--color-primary);
    width: 220px;
    display: flex;
    justify-content: space-between;
}

.score-rank {
    color: #888;
    margin-right: 0.5rem;
}

.score-name {
    color: white;
}

.score-val {
    color: var(--color-secondary);
}

.players-box {
    min-width: 300px;
    background: rgba(0, 0, 0, 0.6);
    border: 1px solid #444;
    padding: 1rem;
    border-radius: 8px;
}

.players-box h3 {
    border-bottom: 1px solid #444;
    padding-bottom: 0.5rem;
    margin-bottom: 1rem;
    color: var(--color-secondary);
}

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

#player-list li {
    padding: 0.5rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    font-size: 1.2rem;
}

/* Powerup Banner */
@keyframes banner-pop {
    0% {
        transform: translate(-50%, -50%) scale(0.5);
        opacity: 0;
    }

    20% {
        transform: translate(-50%, -50%) scale(1.2);
        opacity: 1;
    }

    80% {
        transform: translate(-50%, -50%) scale(1.0);
        opacity: 1;
    }

    100% {
        transform: translate(-50%, -50%) scale(1.5);
        opacity: 0;
    }
}

.powerup-banner {
    position: absolute;
    top: 30%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-family: 'Orbitron', 'Rajdhani', sans-serif;
    font-size: 3rem;
    font-weight: bold;
    color: #fff;
    text-shadow: 0 0 10px #00f0ff, 0 0 20px #00f0ff, 0 0 30px #00f0ff;
    z-index: 3000;
    pointer-events: none;
    white-space: nowrap;
    animation: banner-pop 2s ease-out forwards;
}

#btn-copy-link {
    margin-top: -1rem;
    margin-bottom: 2rem;
    font-size: 0.9rem;
    padding: 0.5rem 1rem;
}

@media (max-width: 600px) {
    .lobby-code-banner {
        font-size: 1.2rem;
        padding: 8px 15px;
        width: 90%;
        text-align: center;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        margin: 0 auto 20px auto;
    }

    h2.sub-logo {
        font-size: 1.5rem;
        text-align: center;
        width: 100%;
    }

    .lobby-info {
        flex-direction: column;
        gap: 1.5rem;
        margin-bottom: 2rem;
    }

    .players-box {
        min-width: 90%;
        width: 90%;
        margin: 0 auto;
    }

    /* Adjust HUD for mobile */
    #hud {
        padding: 0.5rem;
        align-items: flex-start;
    }

    .hud-left {
        transform: scale(0.8);
        transform-origin: top left;
    }

    .hud-right {
        transform: scale(0.8);
        transform-origin: top right;
        margin-top: 50px;
        /* Clear audio controls */
    }

    .audio-controls {
        top: 10px;
        right: 10px;
    }

    h1.logo {
        font-size: 2rem;
        margin-bottom: 1rem;
    }
}

/* Footer & Coffee Button */
#footer-credits {
    position: absolute;
    bottom: 20px;
    width: 100%;
    text-align: center;
    pointer-events: auto;
}

.pixel-coffee-btn {
    font-family: 'Rajdhani', sans-serif;
    text-decoration: none;
    color: #ffcc00;
    /* Coffee/Gold color */
    border: 2px dashed #ffcc00;
    padding: 8px 16px;
    font-size: 1rem;
    font-weight: bold;
    background: rgba(0, 0, 0, 0.6);
    transition: all 0.2s;
    letter-spacing: 2px;
}

.pixel-coffee-btn:hover {
    background: #ffcc00;
    color: black;
    box-shadow: 0 0 15px #ffcc00;
    border-style: solid;
    transform: translateY(-2px);
}