:root {
    --primary: #4CAF50;
    --primary-hover: #45a049;
    --secondary: #2196F3;
    --secondary-hover: #1976D2;
    --danger: #f44336;
    --danger-hover: #d32f2f;
    --bg-dark: #0f172a;
    --glass-bg: rgba(30, 41, 59, 0.7);
    --glass-border: rgba(255, 255, 255, 0.1);
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Outfit', sans-serif;
}

body {
    background-color: var(--bg-dark);
    color: var(--text-main);
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    overflow: hidden;
}

#app {
    width: 100%;
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
}

.screen {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    position: relative;
}

.hidden {
    display: none !important;
}

/* Background Animations */
.background-animation {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    z-index: -1;
    overflow: hidden;
    background: linear-gradient(135deg, #0f172a 0%, #1e1b4b 100%);
}

.shape {
    position: absolute;
    filter: blur(80px);
    opacity: 0.6;
    animation: float 20s infinite alternate;
}

.shape-1 {
    top: -10%; left: -10%;
    width: 50vw; height: 50vw;
    background: #3b82f6;
}

.shape-2 {
    bottom: -10%; right: -10%;
    width: 60vw; height: 60vw;
    background: #8b5cf6;
    animation-delay: -5s;
}

.shape-3 {
    top: 40%; left: 40%;
    width: 40vw; height: 40vw;
    background: #ec4899;
    animation-delay: -10s;
}

@keyframes float {
    0% { transform: translate(0, 0) rotate(0deg); }
    100% { transform: translate(100px, 100px) rotate(45deg); }
}

/* Glassmorphism Cards */
.glass-card {
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    padding: 2rem;
}

/* Typography */
.logo-container {
    text-align: center;
    margin-bottom: 3rem;
    z-index: 10;
}

.glitch {
    font-size: 4rem;
    font-weight: 800;
    text-transform: uppercase;
    position: relative;
    text-shadow: 0.05em 0 0 #00fffc, -0.03em -0.04em 0 #fc00ff,
                 0.025em 0.04em 0 #fffc00;
    animation: glitch 3s infinite;
}

@keyframes glitch {
    0% { text-shadow: 0.05em 0 0 #00fffc, -0.03em -0.04em 0 #fc00ff, 0.025em 0.04em 0 #fffc00; }
    15% { text-shadow: 0.05em 0 0 #00fffc, -0.03em -0.04em 0 #fc00ff, 0.025em 0.04em 0 #fffc00; }
    16% { text-shadow: -0.05em -0.025em 0 #00fffc, 0.025em 0.035em 0 #fc00ff, -0.05em -0.05em 0 #fffc00; }
    49% { text-shadow: -0.05em -0.025em 0 #00fffc, 0.025em 0.035em 0 #fc00ff, -0.05em -0.05em 0 #fffc00; }
    50% { text-shadow: 0.05em 0.035em 0 #00fffc, 0.03em 0 0 #fc00ff, 0 -0.04em 0 #fffc00; }
    99% { text-shadow: 0.05em 0.035em 0 #00fffc, 0.03em 0 0 #fc00ff, 0 -0.04em 0 #fffc00; }
    100% { text-shadow: -0.05em 0 0 #00fffc, -0.025em -0.04em 0 #fc00ff, -0.04em -0.025em 0 #fffc00; }
}

.subtitle {
    font-size: 1.2rem;
    color: var(--text-muted);
    letter-spacing: 2px;
}

/* Layouts */
.cards-wrapper {
    display: flex;
    flex-direction: column;
    gap: 2rem;
    align-items: center;
    width: 100%;
    max-width: 900px;
    z-index: 10;
}

@media (min-width: 768px) {
    .cards-wrapper {
        flex-direction: row;
        justify-content: center;
        align-items: stretch;
    }
}

.panel {
    flex: 1;
    width: 100%;
    max-width: 400px;
}

.panel h2 {
    margin-bottom: 1.5rem;
    font-size: 1.8rem;
    text-align: center;
    background: -webkit-linear-gradient(#fff, #94a3b8);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.divider {
    display: flex;
    align-items: center;
    color: var(--text-muted);
    font-weight: 600;
}
@media (min-width: 768px) {
    .divider {
        flex-direction: column;
    }
    .divider::before, .divider::after {
        content: "";
        width: 1px;
        height: 50px;
        background: var(--glass-border);
        margin: 10px 0;
    }
}

/* Forms */
.form-group {
    margin-bottom: 1.2rem;
    display: flex;
    flex-direction: column;
}

.form-group label {
    margin-bottom: 0.5rem;
    font-size: 0.95rem;
    color: var(--text-muted);
    font-weight: 600;
}

input[type="text"], select {
    padding: 0.8rem 1rem;
    border: 1px solid var(--glass-border);
    background: rgba(0, 0, 0, 0.2);
    color: #fff;
    border-radius: 8px;
    font-size: 1rem;
    outline: none;
    transition: all 0.3s ease;
}

input[type="text"]:focus, select:focus {
    border-color: var(--secondary);
    box-shadow: 0 0 0 3px rgba(33, 150, 243, 0.2);
}

.color-picker-wrapper {
    height: 45px;
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid var(--glass-border);
}

input[type="color"] {
    width: 150%;
    height: 150%;
    margin: -25%;
    cursor: pointer;
    border: none;
}

/* Buttons */
button {
    width: 100%;
    padding: 1rem;
    border: none;
    border-radius: 8px;
    font-size: 1.1rem;
    font-weight: 800;
    cursor: pointer;
    text-transform: uppercase;
    letter-spacing: 1px;
    transition: all 0.2s ease;
    margin-top: 1rem;
}

.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-hover); transform: translateY(-2px); box-shadow: 0 10px 20px -10px var(--primary); }
.btn-secondary { background: var(--secondary); color: white; }
.btn-secondary:hover { background: var(--secondary-hover); transform: translateY(-2px); box-shadow: 0 10px 20px -10px var(--secondary); }
.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { background: var(--danger-hover); transform: translateY(-2px); }

.btn-large { padding: 1.2rem; font-size: 1.2rem; }

/* Toasts */
#toast-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.toast {
    background: rgba(244, 67, 54, 0.9);
    color: white;
    padding: 1rem 1.5rem;
    border-radius: 8px;
    font-weight: 600;
    box-shadow: 0 10px 25px -5px rgba(0,0,0,0.5);
    animation: slideIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    display: flex;
    align-items: center;
    gap: 10px;
}

.toast::before {
    content: "!";
    background: white;
    color: var(--danger);
    width: 20px; height: 20px;
    border-radius: 50%;
    display: flex; justify-content: center; align-items: center;
    font-weight: 800;
}

.toast.fade-out {
    animation: fadeOut 0.3s forwards;
}

@keyframes slideIn {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}
@keyframes fadeOut {
    to { opacity: 0; transform: translateY(10px); }
}

/* Lobby */
.lobby-card {
    width: 100%;
    max-width: 600px;
    text-align: center;
    z-index: 10;
}

.lobby-info {
    display: flex;
    justify-content: center;
    gap: 1rem;
    margin-bottom: 2rem;
}

.info-badge {
    background: rgba(0,0,0,0.3);
    padding: 0.5rem 1rem;
    border-radius: 20px;
    font-size: 0.9rem;
    color: var(--text-muted);
}

.highlight {
    color: var(--primary);
    font-weight: 800;
    letter-spacing: 1px;
}

.players-list-container {
    text-align: left;
    background: rgba(0,0,0,0.2);
    padding: 1.5rem;
    border-radius: 12px;
    margin-bottom: 2rem;
}

.players-list-container h3 {
    margin-bottom: 1rem;
    color: var(--text-muted);
    font-size: 1rem;
    text-transform: uppercase;
}

.lobby-actions {
    display: flex;
    flex-direction: column;
    gap: 15px;
    margin-bottom: 1.5rem;
}

.bot-controls-row {
    display: flex;
    gap: 10px;
    margin-bottom: 12px;
    flex-wrap: wrap;
}

.bot-controls-row button {
    flex: 1;
    min-width: 90px;
    font-size: 0.88rem;
    padding: 0.65rem 0.6rem;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.15);
    color: var(--text-main);
    cursor: pointer;
    transition: all 0.2s ease;
}

.bot-controls-row button:hover {
    background: rgba(33, 150, 243, 0.25);
    border-color: var(--secondary);
    transform: translateY(-1px);
}

.bot-badge {
    background: rgba(156, 39, 176, 0.25);
    color: #ce93d8;
    border: 1px solid rgba(156, 39, 176, 0.5);
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 600;
    margin-left: 8px;
}

#players-list {
    list-style: none;
}

#players-list li {
    padding: 1rem;
    background: rgba(255,255,255,0.05);
    margin-bottom: 0.5rem;
    border-radius: 8px;
    display: flex;
    align-items: center;
    transition: transform 0.2s;
}

#players-list li:hover {
    transform: translateX(5px);
    background: rgba(255,255,255,0.1);
}

.player-color-box {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    margin-right: 15px;
    border: 2px solid white;
    box-shadow: 0 0 10px rgba(255,255,255,0.2);
}

.ready-badge {
    margin-left: auto;
    font-size: 0.8rem;
    padding: 3px 8px;
    border-radius: 12px;
    background: #ffaa00;
    color: #fff;
    font-weight: 600;
}
.ready-badge.is-ready {
    background: var(--primary);
}

.pulsate {
    animation: pulsate 2s infinite;
    color: var(--secondary);
    font-weight: 600;
}

@keyframes pulsate {
    0% { opacity: 0.5; }
    50% { opacity: 1; }
    100% { opacity: 0.5; }
}

/* Game Area */
#game-screen {
    background: #000;
}

#game-arena {
    width: 800px;
    height: 600px;
    position: relative;
    overflow: hidden;
    border: 4px solid #1e293b;
    box-shadow: 0 0 40px rgba(0,0,0,0.9), inset 0 0 50px rgba(0,0,0,0.8);
    border-radius: 12px;
    z-index: 1; /* Isolates internal tank and obstacle layers */
}

/* Default map background if none matches perfectly */
#game-arena {
    /* Removed default background-image here so .map-snow etc can take effect */
    background-color: #2c3e50;
}
#game-arena.map-desert { 
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='150' height='150' viewBox='0 0 150 150'%3E%3Crect width='150' height='150' fill='%23edc9af'/%3E%3Cpath d='M0 50 Q37.5 25 75 50 T150 50 M0 125 Q37.5 100 75 125 T150 125' fill='none' stroke='%23d6a273' stroke-width='4' opacity='0.5'/%3E%3Ccircle cx='40' cy='30' r='2' fill='%23c28c5a'/%3E%3Ccircle cx='110' cy='90' r='1.5' fill='%23c28c5a'/%3E%3Ccircle cx='75' cy='140' r='2.5' fill='%23c28c5a'/%3E%3C/svg%3E");
    background-size: 150px 150px; 
    background-repeat: repeat;
}
#game-arena.map-mountain { 
    background-image: url('assets/bg_grass.jpg'); 
    background-size: 200px 200px; 
    background-repeat: repeat;
    filter: brightness(0.6) contrast(1.1) grayscale(0.2);
}
#game-arena.map-volcano { 
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200' viewBox='0 0 200 200'%3E%3Crect width='200' height='200' fill='%232b1a1a'/%3E%3Cpath d='M-20 40 Q50 -20 120 40 T220 40' fill='none' stroke='%23ff3300' stroke-width='6' opacity='0.8'/%3E%3Cpath d='M50 0 L60 40 L40 80' fill='none' stroke='%23ff9900' stroke-width='4' opacity='0.9'/%3E%3Cpath d='M100 200 L120 150 L110 110 L160 80' fill='none' stroke='%23ff4400' stroke-width='5' opacity='0.7'/%3E%3Ccircle cx='40' cy='120' r='15' fill='%231a0a0a'/%3E%3Ccircle cx='150' cy='160' r='25' fill='%231f0f0f'/%3E%3Ccircle cx='80' cy='180' r='8' fill='%23110505'/%3E%3C/svg%3E");
    background-size: 200px 200px; 
    background-repeat: repeat;
}
#game-arena.map-snow { 
    background-image: url('assets/bg_snow.jpg'); 
    background-size: 200px 200px; 
    background-repeat: repeat;
}

#ui-layer {
    position: absolute;
    top: 15px;
    left: 20px;
    right: 20px;
    display: flex;
    justify-content: space-between;
    align-items: flex-start; /* CRITICAL: Prevents timer from stretching to scoreboard height */
    z-index: 100;
    pointer-events: none;
}

#score-board {
    background: var(--glass-bg);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    padding: 10px 14px;
    border-radius: 8px;
    border: 1px solid var(--glass-border);
    line-height: 1.4;
    font-size: 0.85rem;
    max-width: 280px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}

#timer-display {
    background: var(--glass-bg);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    padding: 6px 18px;
    font-size: 1.6rem;
    font-weight: 800;
    border-radius: 8px;
    font-family: 'JetBrains Mono', monospace;
    border: 1px solid var(--glass-border);
    color: var(--primary);
    text-shadow: 0 0 10px var(--primary);
    align-self: flex-start;
    height: auto; /* Fixes tall dark rectangular overhang */
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}

#ingame-map-mode {
    background: var(--glass-bg);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    padding: 6px 12px;
    border-radius: 6px;
    border: 1px solid var(--glass-border);
    align-self: flex-start;
}

#fps-counter {
    position: absolute;
    top: 5px;
    right: 5px;
    color: #00ff00;
    font-family: 'JetBrains Mono', monospace;
    font-size: 14px;
    z-index: 2000;
    background: rgba(0,0,0,0.5);
    padding: 2px 5px;
    border-radius: 3px;
    pointer-events: none;
}

#ingame-menu {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    width: 360px;
    z-index: 9999; /* Always on top of arena, tanks, and obstacles */
    background: rgba(15, 23, 42, 0.95);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 2px solid rgba(255, 255, 255, 0.2);
    border-radius: 16px;
    padding: 2.5rem 2rem;
    box-shadow: 0 0 0 100vmax rgba(0, 0, 0, 0.65), 0 25px 60px rgba(0, 0, 0, 0.9);
}

#ingame-menu h2 {
    font-size: 2rem;
    margin-bottom: 0.5rem;
    color: #fff;
    text-transform: uppercase;
    letter-spacing: 2px;
}

#ingame-menu p {
    color: var(--text-muted);
    margin-bottom: 1.5rem;
    font-size: 1rem;
}

#endgame-screen {
    z-index: 9999 !important;
    box-shadow: 0 0 0 100vmax rgba(0, 0, 0, 0.65), 0 25px 60px rgba(0, 0, 0, 0.9);
}

.menu-buttons {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* Obstacles */
.obstacle {
    position: absolute;
    background-color: #555;
    background-image: repeating-linear-gradient(45deg, rgba(255,255,255,0.1), rgba(255,255,255,0.1) 15px, rgba(0,0,0,0.1) 15px, rgba(0,0,0,0.1) 30px);
    border: 3px solid #333;
    border-radius: 8px;
    z-index: 8;
    box-shadow: inset 0 0 10px rgba(0,0,0,0.5), 0 15px 25px rgba(0,0,0,0.6);
}
.map-snow .obstacle { 
    background-color: #b2ebf2; 
    border-color: #80deea; 
    box-shadow: inset 0 0 15px rgba(255,255,255,0.8), 0 10px 20px rgba(0,0,0,0.3);
}
.map-desert .obstacle { 
    background-color: #d6a273; 
    border-color: #c28c5a; 
    box-shadow: inset 0 0 10px rgba(0,0,0,0.2), 0 15px 25px rgba(0,0,0,0.6);
}
.map-mountain .obstacle { 
    background-color: #5d4037; 
    border-color: #3e2723; 
}
.map-volcano .obstacle { 
    background-color: #2b1a1a; 
    border-color: #ff3300; 
    box-shadow: 0 0 15px #ff3300, inset 0 0 20px #ff5500, 0 15px 25px rgba(0,0,0,0.8);
}

/* Tank & Game Entities */
.bullet {
    position: absolute;
    width: 6px;
    height: 6px;
    background: #ffff00;
    border-radius: 50%;
    z-index: 5;
    box-shadow: 0 0 10px #ff0, 0 0 20px #ff0;
    transform-origin: center;
}

.powerup {
    position: absolute;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    z-index: 4;
    transform-origin: center;
    border: 2px solid rgba(255, 255, 255, 0.4);
    box-shadow: 0 0 20px rgba(255,255,255,0.6), inset 0 0 10px rgba(255,255,255,0.8);
    text-align: center;
    line-height: 28px;
    font-size: 18px;
    animation: hoverPU 2s infinite ease-in-out, pulsePU 1.5s infinite alternate;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
}

@keyframes pulsePU {
    0% { transform: scale(0.95); }
    100% { transform: scale(1.05); }
}

@keyframes hoverPU {
    0%, 100% { margin-top: 0; }
    50% { margin-top: -5px; }
}

.pu-speed { background: rgba(0, 255, 255, 0.4); border-color: #00ffff; box-shadow: 0 0 20px #00ffff, inset 0 0 10px #00ffff; }
.pu-shield { background: rgba(68, 68, 255, 0.4); border-color: #4444ff; box-shadow: 0 0 20px #4444ff, inset 0 0 10px #4444ff; }
.pu-rapidfire { background: rgba(255, 170, 0, 0.4); border-color: #ffaa00; box-shadow: 0 0 20px #ffaa00, inset 0 0 10px #ffaa00; }
.pu-spread { background: rgba(255, 0, 255, 0.4); border-color: #ff00ff; box-shadow: 0 0 20px #ff00ff, inset 0 0 10px #ff00ff; }
.pu-timebomb { 
    background: rgba(255, 0, 0, 0.4); 
    border-color: #ff0000;
    box-shadow: 0 0 20px #ff0000, inset 0 0 10px #ff0000;
    border-radius: 50%;
    animation: blink 0.3s infinite alternate, hoverPU 2s infinite ease-in-out;
}

.tank {
    position: absolute;
    width: 48px;
    height: 48px;
    z-index: 10;
    transform-origin: center center;
    transition: transform 0.05s linear;
    filter: drop-shadow(0 5px 10px rgba(0,0,0,0.5));
}

.tank-graphic {
    width: 100%;
    height: 100%;
    transform: rotate(0deg); /* Adjust if needed based on movement angle */
}

.tank.dead {
    opacity: 0.3;
    filter: grayscale(100%) sepia(100%) hue-rotate(0deg) saturate(5);
}

.hp-container {
    position: absolute;
    top: -30px;
    left: -15px;
    width: 70px;
    height: 8px;
    background: rgba(0,0,0,0.8);
    border: 1px solid #000;
    border-radius: 4px;
    overflow: hidden;
    transform-origin: center calc(100% + 50px);
}

.hp-bar {
    height: 100%;
    background: linear-gradient(90deg, #f44336, #4CAF50);
    transition: width 0.2s ease-out;
}

.tank-name {
    position: absolute;
    top: -55px;
    left: -30px;
    width: 100px;
    text-align: center;
    font-size: 12px;
    font-weight: 800;
    color: white;
    text-shadow: 1px 1px 3px black, -1px -1px 3px black;
    transform-origin: center calc(100% + 75px);
}

.tank-shield {
    position: absolute;
    top: -8px;
    left: -8px;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    border: 3px solid #00ffff;
    box-shadow: 0 0 15px #00ffff, inset 0 0 15px #00ffff;
    pointer-events: none;
    z-index: 15;
    animation: shieldPulse 1s infinite alternate;
}

@keyframes shieldPulse {
    from { opacity: 0.6; transform: scale(0.95); }
    to { opacity: 1; transform: scale(1.05); }
}
