/* --- CORE THEME --- */
:root { 
    --neon: #00f2ff; --bg: #020b14; --panel: rgba(5, 20, 35, 0.95); 
    --alert: #ff3333; --gold: #ffd700; --purple: #bf00ff; --dim: #444; 
    --shield: #00ff88; --inactive: #1a1a1a;
}

body { 
    background: var(--bg); color: var(--neon); 
    font-family: 'Share Tech Mono', monospace; margin: 0; overflow: hidden; user-select: none; 
    height: 100dvh; display: flex; flex-direction: column; font-size: 16px; 
}

/* --- UI COMPONENTS --- */
button { 
    background: var(--neon); color: #000; border: none; padding: 10px 15px; 
    cursor: pointer; font-weight: bold; text-transform: uppercase; width: 100%; 
    margin-top: 5px; font-family: 'Share Tech Mono', monospace; letter-spacing: 1px;
    transition: all 0.2s; font-size: 1em;
}
button:hover { background: #fff; box-shadow: 0 0 15px var(--neon); }
button:active { transform: scale(0.98); }
button:disabled, .btn-disabled { 
    background: var(--inactive) !important; color: #555 !important; 
    border: 1px solid #333 !important; cursor: not-allowed; box-shadow: none !important; 
    pointer-events: none; opacity: 0.6;
}

.btn-cancel { background: transparent; border: 1px solid var(--alert); color: var(--alert); }
.btn-cancel:hover { background: var(--alert); color: #fff; box-shadow: 0 0 15px var(--alert); pointer-events: auto; cursor: pointer; }
.btn-purple { background: var(--purple); color: #fff; }
.btn-purple:hover { box-shadow: 0 0 15px var(--purple); }
.btn-attack { background: transparent; border: 1px solid var(--alert); color: var(--alert); }
.btn-attack:hover { background: var(--alert); color: white; box-shadow: 0 0 15px var(--alert); }
.btn-shield { background: transparent; border: 1px solid var(--shield); color: var(--shield); }
.btn-shield:hover { background: var(--shield); color: #000; box-shadow: 0 0 15px var(--shield); }
.btn-mini { padding: 4px 8px; font-size: 0.7em; width: auto; margin: 0; }

.nav-btn { width: auto; background: transparent; border: 1px solid var(--neon); color: var(--neon); padding: 4px 10px; font-size: 0.8em; }
.nav-btn:hover { background: var(--neon); color: black; }

/* --- CHAT SYSTEM --- */
#chat-container {
    position: fixed; bottom: 200px; left: 10px; width: 320px; height: 220px;
    background: rgba(0,0,0,0.9); border: 1px solid var(--neon);
    display: flex; flex-direction: column; z-index: 5000; font-size: 0.9em; pointer-events: auto;
    box-shadow: 0 0 20px rgba(0,0,0,0.5);
}
.chat-header { display: flex; border-bottom: 1px solid #333; }
.chat-tab { 
    flex: 1; text-align: center; padding: 5px; cursor: pointer; background: #111; color: #666; 
    border-right: 1px solid #333; transition: all 0.2s;
}
.chat-tab:hover { color: white; }
.chat-tab.active { background: var(--panel); color: var(--neon); font-weight: bold; }
#chat-messages {
    flex: 1; overflow-y: auto; padding: 10px; display: flex; flex-direction: column; gap: 5px;
    scrollbar-width: thin; scrollbar-color: var(--neon) #111;
}
.chat-msg { word-wrap: break-word; line-height: 1.3; }
.chat-sender { font-weight: bold; cursor: pointer; }
.chat-tag { color: var(--purple); font-size: 0.8em; margin-right: 3px; }
.msg-global .chat-sender { color: var(--gold); }
.msg-alliance .chat-sender { color: var(--shield); }
.msg-region .chat-sender { color: var(--neon); }
#chat-input-area { display: flex; border-top: 1px solid #333; padding: 5px; background: #000; }
#chat-input { background: transparent; border: none; color: white; padding: 5px; width: 100%; font-family: inherit; outline: none; }

/* --- MODALS --- */
#modal-overlay, #confirm-overlay, #alliance-overlay { 
    position: fixed; top: 0; left: 0; width: 100%; height: 100%; 
    background: rgba(0,0,0,0.85); z-index: 10000; display: none; 
    align-items: center; justify-content: center; backdrop-filter: blur(5px); 
}
.modal-box { 
    background: var(--bg); border: 1px solid var(--neon); 
    padding: 25px; width: 450px; max-width: 90%; max-height: 80vh; overflow-y: auto;
    text-align: center; box-shadow: 0 0 30px rgba(0, 0, 0, 0.8); position: relative;
}
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: #000; }
::-webkit-scrollbar-thumb { background: var(--dim); }
::-webkit-scrollbar-thumb:hover { background: var(--neon); }

/* --- TOASTS --- */
#toast-container {
    position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 10px; 
    z-index: 20000; pointer-events: none; 
}
.toast {
    background: rgba(5, 20, 35, 0.95); border-left: 4px solid var(--neon);
    color: white; padding: 12px 20px; min-width: 250px;
    box-shadow: 0 5px 15px rgba(0,0,0,0.5); font-size: 0.9em;
    animation: slideIn 0.3s cubic-bezier(0.18, 0.89, 0.32, 1.28) forwards;
    pointer-events: auto; cursor: default;
}
.toast.levelup { border-left-color: var(--purple); color: var(--purple); }
.toast.error { border-left-color: var(--alert); color: var(--alert); }
.toast.combat { border-left-color: #ff8800; color: #ff8800; }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* --- AUTH --- */
#auth-overlay { 
    position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: #000; 
    z-index: 9999; display: flex; align-items: center; justify-content: center; flex-direction: column; 
    background-image: radial-gradient(circle at center, #111 0%, #000 70%);
}
.auth-box { border: 1px solid var(--neon); padding: 40px; background: rgba(0,0,0,0.8); text-align: center; width: 320px; box-shadow: 0 0 50px rgba(0, 242, 255, 0.1); }
.input-wrapper { position: relative; width: 100%; margin: 10px 0; }
input { 
    background: #080808; border: 1px solid #333; color: white; 
    padding: 12px; font-family: inherit; width: 100%; display: block; 
    box-sizing: border-box; outline: none; transition: border-color 0.3s;
}
input:focus { border-color: var(--neon); }
.toggle-password { position: absolute; right: 10px; top: 50%; transform: translateY(-50%); cursor: pointer; z-index: 10; opacity: 0.5; }

/* --- LAYOUT FIXES --- */
.top-bar { 
    height: 60px; background: var(--panel); border-bottom: 1px solid #333; 
    display: flex; align-items: center; padding: 0 20px; justify-content: space-between; font-size: 1em; flex-shrink: 0;
}
#map { 
    flex-grow: 1; width: 100%; background: #000;
    filter: hue-rotate(180deg) invert(100%) brightness(0.7) contrast(1.3) saturate(0.5); 
    cursor: url('data:image/svg+xml;utf8,<svg width="32" height="32" viewBox="0 0 32 32" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M16 2V10M16 22V30M2 16H10M22 16H30" stroke="%2300f2ff" stroke-width="3" stroke-linecap="square"/><circle cx="16" cy="16" r="2" fill="%2300f2ff"/></svg>') 16 16, crosshair;
    z-index: 1;
}
.footer { 
    height: auto; min-height: 180px; flex-shrink: 0; background: var(--panel); border-top: 1px solid var(--neon); 
    display: grid; grid-template-columns: 1fr 1.5fr 1fr; padding: 10px; gap: 10px; font-size: 0.9em; 
    position: relative; transition: height 0.3s ease;
}
.stat-box { border: 1px solid #222; padding: 10px; display: flex; flex-direction: column; justify-content: space-between; background: rgba(0,0,0,0.4); position: relative; overflow: hidden; }
.upgrade-list { overflow-y: auto; flex: 1; padding-right: 5px; margin-top: 5px; border-top: 1px solid #222; max-height: 110px; }
.upgrade-item { display: flex; justify-content: space-between; align-items: center; margin-bottom: 5px; border-bottom: 1px solid #1a1a1a; padding: 8px 0; }
.upgrade-item.unlocked-tier .upgrade-name { color: var(--gold); text-shadow: 0 0 5px rgba(255,215,0,0.5); font-weight: bold; }
.upgrade-item.disabled { opacity: 0.5; }

.badge-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(40px, 1fr)); gap: 8px; margin-top: 15px; max-height: 200px; overflow-y: auto; }
.badge { border: 1px solid #333; padding: 5px; border-radius: 4px; opacity: 0.1; font-size: 1.2em; position: relative; cursor: help; text-align: center; background: #050505; }
.badge.unlocked { border-color: var(--gold); color: var(--gold); opacity: 1; box-shadow: 0 0 5px rgba(255, 215, 0, 0.1); background: rgba(255, 215, 0, 0.05); }
.badge:hover::after { content: attr(data-tooltip); position: absolute; bottom: 100%; left: 50%; transform: translateX(-50%); background: rgba(0,0,0,0.95); border: 1px solid var(--neon); color: white; padding: 8px; width: 180px; z-index: 99999; font-size: 0.6em; pointer-events: none; margin-bottom: 5px; box-shadow: 0 0 10px #000; white-space: normal; line-height: 1.2; text-align: left; }
.xp-bar-container { width: 100%; height: 8px; background: #222; margin: 10px 0; border-radius: 4px; overflow: hidden; }
.xp-bar-fill { height: 100%; background: var(--purple); width: 0%; transition: width 0.5s; }
.mult-controls { display: flex; gap: 2px; }
.btn-mult { width: auto; padding: 2px 8px; font-size: 0.8em; background: #111; border: 1px solid #333; color: #666; margin: 0; }
.btn-mult.active { border-color: var(--neon); color: var(--neon); background: rgba(0, 242, 255, 0.05); }

/* --- TABS --- */
.tab-header { display: flex; border-bottom: 1px solid #333; margin-bottom: 15px; }
.tab-btn { flex: 1; background: transparent; color: #666; border-bottom: 2px solid transparent; padding: 10px; border-radius: 0; }
.tab-btn.active { color: var(--neon); border-bottom-color: var(--neon); background: rgba(0,242,255,0.05); }
.tab-content { display: none; }
.tab-content.active { display: block; animation: fadeIn 0.3s; }

/* --- CLAN / ALLIANCE STYLES --- */
.clan-list-item { display: flex; justify-content: space-between; align-items: center; background: rgba(255, 255, 255, 0.05); border: 1px solid #333; padding: 10px; margin-bottom: 5px; transition: border-color 0.2s; }
.clan-list-item:hover { border-color: var(--gold); }
.member-list-container { background: #000; border: 1px solid #333; padding: 10px; max-height: 250px; overflow-y: auto; }
.clan-member-row { display: flex; justify-content: space-between; align-items: center; padding: 5px 0; border-bottom: 1px solid #222; font-size: 0.9em; }
#join-clan-name, #create-clan-name, #new-clan-desc { background: #000; border: 1px solid #444; color: white; text-align: center; letter-spacing: 1px; width: 100%; box-sizing: border-box; }
#join-clan-name:focus, #create-clan-name:focus { border-color: var(--neon); }

/* --- FRIEND LIST --- */
.friend-item { display: flex; justify-content: space-between; align-items: center; padding: 8px; background: rgba(255,255,255,0.05); border: 1px solid #333; margin-bottom: 5px; }
.friend-name { font-weight: bold; color: white; font-size: 0.9em; }
.friend-nick { font-size: 0.8em; color: var(--purple); font-style: italic; margin-left: 5px; }
.friend-actions { display: flex; gap: 5px; }
.settings-row { margin-bottom: 10px; text-align: left; }
.settings-row label { display: block; color: #888; font-size: 0.7em; margin-bottom: 2px; }
.settings-row input { background: #111; border: 1px solid #333; padding: 5px; width: 100%; color: white; }

/* --- RANKING TABLE --- */
.rank-row { display: grid; grid-template-columns: 0.5fr 3fr 1fr 1fr; gap: 5px; padding: 8px; border-bottom: 1px solid #222; font-size: 0.85em; text-align: left; }
.rank-row.header { color: #888; font-weight: bold; border-bottom: 1px solid var(--neon); }
.rank-place { color: var(--gold); font-weight: bold; }

.mobile-handle { display: none; width: 40px; height: 4px; background: #333; border-radius: 2px; margin: 0 auto 5px auto; }

@keyframes fadeIn { from { opacity:0; } to { opacity:1; } }

@media (max-width: 700px) {
    .footer { 
        display: flex; flex-direction: column; 
        position: fixed; bottom: 0; left: 0; width: 100%; 
        height: 55vh; z-index: 4000; box-sizing: border-box;
        border-radius: 20px 20px 0 0; border-top: 2px solid var(--neon);
        box-shadow: 0 -5px 20px rgba(0,0,0,0.8);
    }
    .mobile-handle { display: block; }
    .stat-box { border: none; border-bottom: 1px solid #333; padding: 12px; height: auto; }
    #chat-container { width: 90%; left: 5%; bottom: 60vh; height: 150px; }
}

