/* ═══════════════════════════════════════════════════════════
   MLBB Arena — v2 with Hero Selection
   ═══════════════════════════════════════════════════════════ */

:root {
  --blue-team: #00b4ff;
  --blue-team-dark: #0066aa;
  --blue-glow: rgba(0, 180, 255, 0.4);
  --red-team: #ff3355;
  --red-team-dark: #aa1133;
  --red-glow: rgba(255, 51, 85, 0.4);
  --gold: #ffd700;
  --gold-glow: rgba(255, 215, 0, 0.3);
  --bg-dark: #0a0e1a;
  --bg-card: rgba(15, 20, 40, 0.85);
  --glass: rgba(255, 255, 255, 0.05);
  --glass-border: rgba(255, 255, 255, 0.1);
  --text-primary: #e8eaf0;
  --text-secondary: #8892a8;
  --hp-green: #00e676;
  --mana-blue: #448aff;
  --font-main: 'Rajdhani', sans-serif;
  --font-display: 'Orbitron', sans-serif;
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; -webkit-touch-callout: none; user-select: none; }
html, body { width: 100%; height: 100%; overflow: hidden; background: var(--bg-dark); font-family: var(--font-main); color: var(--text-primary); touch-action: none; position: fixed; }

/* ── Loading Screen ──────────────────────────────────────── */
#loading-screen {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  background: var(--bg-dark); z-index: 1000; transition: opacity 0.5s ease;
}
#loading-screen.hidden { opacity: 0; pointer-events: none; }
.loading-content { text-align: center; }
.game-title { font-family: var(--font-display); font-size: 2.2rem; font-weight: 900; letter-spacing: 0.12em; color: var(--text-primary); text-shadow: 0 0 40px var(--blue-glow); margin-bottom: 1.5rem; }
.game-title .accent { color: var(--gold); text-shadow: 0 0 40px var(--gold-glow); }
.loading-bar-container { width: 300px; height: 4px; background: rgba(255,255,255,0.1); border-radius: 2px; margin: 0 auto 1rem; overflow: hidden; }
.loading-bar { height: 100%; width: 0%; background: linear-gradient(90deg, var(--blue-team), var(--gold)); border-radius: 2px; transition: width 0.3s ease; }
.loading-text { font-size: 0.9rem; color: var(--text-secondary); animation: pulse 1.5s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { opacity: 0.5; } 50% { opacity: 1; } }

/* ═══════════════════════════════════════════════════════════
   HERO SELECT SCREEN
   ═══════════════════════════════════════════════════════════ */
#hero-select {
  position: fixed; inset: 0; z-index: 900;
  display: flex; flex-direction: column;
}
.hero-select-bg {
  position: absolute; inset: 0;
  background:
    radial-gradient(ellipse at 20% 30%, rgba(0, 100, 200, 0.12) 0%, transparent 50%),
    radial-gradient(ellipse at 80% 70%, rgba(200, 50, 100, 0.08) 0%, transparent 50%),
    linear-gradient(135deg, #080c18 0%, #0d1225 50%, #0a0f1f 100%);
}
.hero-select-content {
  position: relative; z-index: 1;
  display: flex; flex-direction: column;
  height: 100%; padding: 12px 20px;
  overflow: hidden;
}
.hero-select-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 10px; flex-shrink: 0;
}
.hero-select-header .game-title { font-size: 1.3rem; margin-bottom: 0; }
.hero-select-meta { display: flex; align-items: center; gap: 12px; }
.select-timer { position: absolute; top: 12px; left: 50%; transform: translateX(-50%); z-index: 10;
  font-family: var(--font-display); font-size: 1.4rem; color: var(--gold); }
.team-badge { display: inline-block; padding: 0.3rem 1rem; border-radius: 4px; font-family: var(--font-display);
  font-size: 0.7rem; font-weight: 700; letter-spacing: 0.2em; border: 1px solid; }
.team-badge.blue { color: var(--blue-team); border-color: var(--blue-team); background: rgba(0,180,255,0.1); }
.team-badge.red { color: var(--red-team); border-color: var(--red-team); background: rgba(255,51,85,0.1); }

/* ── Hero Grid ────────────────────────────────────────────── */
.hero-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  flex-shrink: 0;
  margin-bottom: 10px;
}
.hero-card {
  position: relative; border-radius: 8px; overflow: hidden;
  border: 2px solid rgba(255,255,255,0.08);
  cursor: pointer; transition: all 0.25s ease;
  background: rgba(10, 15, 30, 0.8);
  aspect-ratio: 1/1.1;
}
.hero-card:hover { border-color: rgba(255,255,255,0.25); transform: translateY(-2px); }
.hero-card.selected { border-color: var(--gold); box-shadow: 0 0 20px var(--gold-glow); transform: translateY(-3px); }
.hero-card-img {
  width: 100%; height: 70%; object-fit: cover; object-position: top;
  filter: brightness(0.8); transition: filter 0.2s;
}
.hero-card:hover .hero-card-img, .hero-card.selected .hero-card-img { filter: brightness(1.1); }
.hero-card-info { padding: 4px 6px; text-align: center; }
.hero-card-name { font-family: var(--font-display); font-size: 0.6rem; font-weight: 700; letter-spacing: 0.05em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hero-card-role { font-size: 0.5rem; color: var(--text-secondary); letter-spacing: 0.1em; text-transform: uppercase; }

/* Role colors */
.hero-card[data-role="Mage"] .hero-card-role { color: #aa88ff; }
.hero-card[data-role="Assassin"] .hero-card-role { color: #ff66aa; }
.hero-card[data-role="Tank"] .hero-card-role { color: #ffaa33; }
.hero-card[data-role="Marksman"] .hero-card-role { color: #33ff66; }
.hero-card[data-role="Fighter"] .hero-card-role { color: #ff6633; }
.hero-card[data-role="Support"] .hero-card-role { color: #cc88ff; }

/* ── Hero Detail Panel ─────────────────────────────────────── */
.hero-detail {
  display: flex; gap: 16px; align-items: center;
  padding: 10px 16px; flex: 1; min-height: 0;
  background: rgba(10, 15, 35, 0.7);
  border: 1px solid var(--glass-border);
  border-radius: 10px;
  backdrop-filter: blur(8px);
}
.hero-detail-portrait {
  width: 120px; height: 120px; border-radius: 10px;
  overflow: hidden; border: 2px solid var(--glass-border);
  flex-shrink: 0;
}
.hero-detail-portrait img { width: 100%; height: 100%; object-fit: cover; }
.hero-detail-info { flex: 1; min-width: 0; overflow: hidden; }
.hero-detail-name { font-family: var(--font-display); font-size: 1.1rem; font-weight: 900; letter-spacing: 0.1em; margin-bottom: 2px; }
.hero-detail-title { font-size: 0.75rem; color: var(--text-secondary); margin-bottom: 4px; }
.hero-role-badge {
  display: inline-block; padding: 2px 10px; border-radius: 3px;
  font-size: 0.6rem; font-weight: 700; letter-spacing: 0.15em;
  text-transform: uppercase; margin-bottom: 6px;
  border: 1px solid rgba(255,255,255,0.15);
  background: rgba(255,255,255,0.05);
}

.hero-stats {
  display: flex; gap: 12px; margin-bottom: 6px; flex-wrap: wrap;
}
.hero-stat {
  font-size: 0.65rem; color: var(--text-secondary);
}
.hero-stat span { color: var(--text-primary); font-weight: 700; }

.hero-abilities {
  display: flex; gap: 6px; flex-wrap: wrap;
}
.ability-preview {
  display: flex; align-items: center; gap: 4px;
  padding: 3px 8px; background: rgba(255,255,255,0.04);
  border-radius: 4px; border: 1px solid rgba(255,255,255,0.06);
  font-size: 0.6rem;
}
.ability-preview-key {
  font-family: var(--font-display); font-weight: 700; font-size: 0.65rem;
  width: 18px; height: 18px; display: flex; align-items: center; justify-content: center;
  background: rgba(255,255,255,0.08); border-radius: 3px;
}
.ability-preview-name { color: var(--text-secondary); }
.ability-preview-dmg { color: #ff6644; font-weight: 600; }

.btn-lock-in {
  position: relative; padding: 12px 30px; flex-shrink: 0;
  font-family: var(--font-display); font-size: 0.9rem; font-weight: 700;
  letter-spacing: 0.15em; color: var(--bg-dark);
  background: linear-gradient(135deg, var(--gold), #ffaa00);
  border: none; border-radius: 8px; cursor: pointer;
  overflow: hidden; transition: all 0.2s;
  box-shadow: 0 4px 25px var(--gold-glow);
  align-self: center;
}
.btn-lock-in:disabled { opacity: 0.3; cursor: not-allowed; filter: grayscale(0.5); }
.btn-lock-in:not(:disabled):hover { transform: scale(1.05); box-shadow: 0 6px 35px var(--gold-glow); }
.btn-glow { position: absolute; top: -50%; left: -50%; width: 200%; height: 200%;
  background: radial-gradient(circle, rgba(255,255,255,0.3), transparent 60%);
  animation: rotateGlow 3s linear infinite; }
@keyframes rotateGlow { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }
.btn-text { position: relative; z-index: 1; }

/* ── Game Canvas ─────────────────────────────────────────── */
#gameCanvas { position: fixed; top: 0; left: 0; width: 100%; height: 100%; display: block; background: #111827; }

/* ── HUD ─────────────────────────────────────────────────── */
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 100; }
#hud > * { pointer-events: auto; }

.hud-top {
  position: absolute; top: 0; left: 50%; transform: translateX(-50%);
  display: flex; align-items: center; gap: 1rem;
  padding: 0.4rem 1.2rem; background: var(--bg-card);
  backdrop-filter: blur(12px); border-radius: 0 0 10px 10px;
  border: 1px solid var(--glass-border); border-top: none;
  pointer-events: none;
}
.team-score { display: flex; align-items: center; gap: 0.4rem; font-family: var(--font-display); }
.team-label { font-size: 0.6rem; font-weight: 700; letter-spacing: 0.15em; opacity: 0.7; }
.score-val { font-size: 1.3rem; font-weight: 900; }
.blue-score .score-val, .blue-score .team-label { color: var(--blue-team); }
.red-score .score-val, .red-score .team-label { color: var(--red-team); }
.game-timer { font-family: var(--font-display); font-size: 0.9rem; font-weight: 500; color: var(--text-secondary); min-width: 55px; text-align: center; }

/* ── Player Stats with Hero Portrait ─────────────────────── */
.player-stats {
  position: absolute; left: 16px; bottom: 135px;
  display: flex; gap: 8px; align-items: flex-end;
}
.hero-hud-portrait {
  position: relative; width: 48px; height: 48px;
  border-radius: 50%; overflow: hidden;
  border: 2px solid var(--gold);
  box-shadow: 0 0 12px var(--gold-glow);
  flex-shrink: 0;
}
.hero-hud-portrait img { width: 100%; height: 100%; object-fit: cover; }
.hero-level {
  position: absolute; bottom: -2px; right: -2px;
  width: 18px; height: 18px; border-radius: 50%;
  background: var(--gold); color: var(--bg-dark);
  font-family: var(--font-display); font-size: 0.55rem; font-weight: 900;
  display: flex; align-items: center; justify-content: center;
}
.stat-bars-container { width: 150px; }
.stat-bar { position: relative; height: 12px; background: rgba(0,0,0,0.6); border-radius: 6px; margin-bottom: 3px; overflow: hidden; border: 1px solid rgba(255,255,255,0.06); }
.stat-bar-fill { height: 100%; border-radius: 6px; transition: width 0.15s ease; position: absolute; top: 0; left: 0; }
.stat-bar-shield { height: 100%; border-radius: 6px; transition: width 0.15s ease; position: absolute; top: 0; left: 0;
  background: rgba(255, 255, 255, 0.3); }
.hp-bar .stat-bar-fill { background: linear-gradient(90deg, #00e676, #66ff99); box-shadow: 0 0 6px rgba(0,230,118,0.3); }
.mana-bar .stat-bar-fill { background: linear-gradient(90deg, #448aff, #82b1ff); box-shadow: 0 0 6px rgba(68,138,255,0.3); }
.stat-bar-text { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-size: 0.5rem; font-weight: 700; text-shadow: 0 1px 2px rgba(0,0,0,0.8); letter-spacing: 0.04em; z-index: 2; }
.kda { font-family: var(--font-display); font-size: 0.65rem; color: var(--text-secondary); text-align: center; letter-spacing: 0.1em; }

/* ── Status Effects ───────────────────────────────────────── */
.status-effects { position: absolute; left: 220px; bottom: 160px; display: flex; gap: 4px; }
.status-icon {
  width: 24px; height: 24px; border-radius: 4px;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.7rem; border: 1px solid rgba(255,255,255,0.1);
  animation: statusPulse 1s ease-in-out infinite;
}
.status-icon.stunned { background: rgba(255,200,0,0.3); border-color: rgba(255,200,0,0.5); }
.status-icon.slowed { background: rgba(0,200,255,0.3); border-color: rgba(0,200,255,0.5); }
.status-icon.poisoned { background: rgba(0,200,0,0.3); border-color: rgba(0,200,0,0.5); }
.status-icon.shielded { background: rgba(255,255,255,0.2); border-color: rgba(255,255,255,0.4); }
.status-icon.buffed { background: rgba(255,100,0,0.3); border-color: rgba(255,100,0,0.5); }
@keyframes statusPulse { 0%, 100% { opacity: 0.7; } 50% { opacity: 1; } }

/* ── Joystick ─────────────────────────────────────────────── */
#joystick-zone { position: absolute; left: 0; bottom: 0; width: 45%; height: 55%; pointer-events: auto; }

/* ── Minimap ──────────────────────────────────────────────── */
#minimap-container {
  position: absolute; left: 14px; top: 46px; width: 140px; height: 140px;
  border-radius: 6px; overflow: hidden; border: 1px solid var(--glass-border);
  background: rgba(0,0,0,0.6); backdrop-filter: blur(4px);
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
}
#minimap { width: 100%; height: 100%; }

/* ── Ability Buttons ──────────────────────────────────────── */
#ability-buttons { position: absolute; right: 16px; bottom: 16px; display: flex; flex-direction: column; align-items: center; gap: 6px; }
.ability-row { display: flex; gap: 6px; }
.ability-btn {
  position: relative; width: 56px; height: 56px; border-radius: 50%;
  border: 2px solid var(--glass-border); background: var(--bg-card);
  backdrop-filter: blur(8px); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  overflow: hidden; transition: transform 0.1s, border-color 0.2s;
  box-shadow: 0 3px 12px rgba(0,0,0,0.4), inset 0 1px 0 rgba(255,255,255,0.04);
}
.ability-btn:active { transform: scale(0.88); }
.ability-btn .ability-icon { font-family: var(--font-display); font-size: 1.1rem; font-weight: 700; color: var(--text-primary); z-index: 2; position: relative; }
.ability-name-label {
  position: absolute; bottom: -14px; left: 50%; transform: translateX(-50%);
  font-size: 0.4rem; font-weight: 600; color: var(--text-secondary);
  white-space: nowrap; z-index: 3; letter-spacing: 0.05em;
}

#btn-q { border-color: #ff6b35; }
#btn-q .ability-icon { color: #ff6b35; }
#btn-w { border-color: #4ecdc4; }
#btn-w .ability-icon { color: #4ecdc4; }
#btn-e { border-color: #ffe66d; }
#btn-e .ability-icon { color: #ffe66d; }

.ult-btn { width: 64px; height: 64px; border-color: var(--gold); box-shadow: 0 0 16px var(--gold-glow), 0 3px 12px rgba(0,0,0,0.4); }
.ult-btn .ability-icon { color: var(--gold); font-size: 1.3rem; }

.basic-attack { width: 68px; height: 68px; border-color: var(--red-team); box-shadow: 0 0 12px var(--red-glow), 0 3px 12px rgba(0,0,0,0.4); }
.basic-attack .ability-icon { font-size: 1.6rem; color: var(--red-team); }

.cooldown-overlay { position: absolute; inset: 0; background: rgba(0,0,0,0.7); border-radius: 50%;
  clip-path: polygon(50% 50%, 50% 0%, 50% 0%); transition: clip-path 0.1s linear; z-index: 1; }
.ability-btn.on-cooldown { border-color: rgba(255,255,255,0.12) !important; opacity: 0.55; }
.ability-cd-text { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-family: var(--font-display); font-size: 0.85rem; font-weight: 700; color: white;
  text-shadow: 0 1px 4px rgba(0,0,0,0.9); z-index: 3; opacity: 0; }
.ability-btn.on-cooldown .ability-cd-text { opacity: 1; }
.ability-btn.on-cooldown .ability-icon { opacity: 0.25; }

/* ── Death Screen ────────────────────────────────────────── */
#death-screen { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  background: rgba(100,0,0,0.3); z-index: 500; animation: deathFadeIn 0.5s ease; }
@keyframes deathFadeIn { from { opacity: 0; } to { opacity: 1; } }
.death-content { text-align: center; }
.death-title { font-family: var(--font-display); font-size: 1.8rem; font-weight: 900; color: var(--red-team);
  text-shadow: 0 0 30px var(--red-glow); letter-spacing: 0.15em; animation: deathPulse 1.5s ease-in-out infinite; }
@keyframes deathPulse { 0%, 100% { text-shadow: 0 0 30px var(--red-glow); } 50% { text-shadow: 0 0 60px var(--red-glow); } }
.respawn-timer { font-family: var(--font-display); font-size: 0.9rem; color: var(--text-secondary); margin-top: 0.8rem; letter-spacing: 0.1em; }

/* ── Kill Feed ────────────────────────────────────────────── */
#kill-feed { position: fixed; top: 55px; right: 16px; z-index: 200; display: flex; flex-direction: column; gap: 3px; pointer-events: none; }
.kill-entry { padding: 0.25rem 0.6rem; background: var(--bg-card); backdrop-filter: blur(8px); border-radius: 4px;
  font-size: 0.65rem; font-weight: 500; border-left: 3px solid;
  animation: killSlideIn 0.3s ease, killFadeOut 0.5s ease 3s forwards; white-space: nowrap; }
.kill-entry.blue { border-color: var(--blue-team); color: var(--blue-team); }
.kill-entry.red { border-color: var(--red-team); color: var(--red-team); }
@keyframes killSlideIn { from { transform: translateX(50px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
@keyframes killFadeOut { to { opacity: 0; transform: translateY(-10px); } }

/* ── In-Game Chat ────────────────────────────────────────── */
#chat-container {
  position: fixed; bottom: 12px; left: 50%; transform: translateX(-50%);
  z-index: 300; display: flex; flex-direction: column; align-items: center;
  transition: all 0.3s ease;
}
#chat-toggle {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--bg-card); backdrop-filter: blur(10px);
  border: 1px solid var(--glass-border);
  display: flex; align-items: center; justify-content: center;
  font-size: 1rem; cursor: pointer; pointer-events: auto;
  box-shadow: 0 2px 10px rgba(0,0,0,0.4);
  transition: all 0.2s;
}
#chat-toggle:hover { background: rgba(30, 40, 70, 0.9); transform: scale(1.1); }
#chat-panel {
  width: 340px; max-width: 90vw;
  background: rgba(10, 15, 30, 0.88);
  backdrop-filter: blur(12px);
  border: 1px solid var(--glass-border);
  border-radius: 8px; overflow: hidden;
  margin-bottom: 6px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.5);
  transition: all 0.3s ease;
}
.chat-hidden #chat-panel {
  opacity: 0; transform: translateY(10px) scale(0.95);
  pointer-events: none; max-height: 0; margin: 0;
}
.chat-visible #chat-panel {
  opacity: 1; transform: translateY(0) scale(1);
  pointer-events: auto; max-height: 250px;
}
#chat-messages {
  height: 150px; overflow-y: auto; padding: 8px 10px;
  display: flex; flex-direction: column; gap: 3px;
  scrollbar-width: thin; scrollbar-color: rgba(255,255,255,0.15) transparent;
}
#chat-messages::-webkit-scrollbar { width: 4px; }
#chat-messages::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.15); border-radius: 2px; }
.chat-msg {
  font-size: 0.7rem; line-height: 1.3;
  animation: chatMsgIn 0.2s ease;
}
.chat-msg .chat-sender {
  font-family: var(--font-display); font-weight: 700; font-size: 0.6rem;
  letter-spacing: 0.05em; margin-right: 4px;
}
.chat-msg .chat-sender.blue { color: var(--blue-team); }
.chat-msg .chat-sender.red { color: var(--red-team); }
.chat-msg .chat-text { color: var(--text-primary); }
@keyframes chatMsgIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }
#chat-input-row {
  display: flex; border-top: 1px solid var(--glass-border);
}
#chat-input {
  flex: 1; border: none; outline: none;
  background: rgba(0,0,0,0.3); color: var(--text-primary);
  font-family: var(--font-main); font-size: 0.75rem;
  padding: 8px 10px; pointer-events: auto;
}
#chat-input::placeholder { color: var(--text-secondary); opacity: 0.5; }
#chat-send {
  background: none; border: none; border-left: 1px solid var(--glass-border);
  color: var(--gold); font-size: 1rem; padding: 6px 12px;
  cursor: pointer; pointer-events: auto; transition: background 0.2s;
}
#chat-send:hover { background: rgba(255,215,0,0.1); }

/* ── Responsive ───────────────────────────────────────────── */
@media (max-height: 420px) {
  .hero-grid { grid-template-columns: repeat(5, 1fr); gap: 5px; }
  .hero-card { aspect-ratio: 1/1; }
  .hero-card-info { padding: 2px 4px; }
  .hero-card-name { font-size: 0.5rem; }
  .hero-detail { padding: 6px 10px; gap: 10px; }
  .hero-detail-portrait { width: 80px; height: 80px; }
  .hero-detail-name { font-size: 0.85rem; }
  .player-stats { bottom: 105px; }
  .ability-btn { width: 48px; height: 48px; }
  .ult-btn { width: 55px; height: 55px; }
  .basic-attack { width: 58px; height: 58px; }
  #minimap-container { width: 110px; height: 110px; }
}

@media (max-width: 700px) {
  .hero-grid { grid-template-columns: repeat(5, 1fr); gap: 4px; }
  .hero-detail-portrait { width: 70px; height: 70px; }
  .ability-btn { width: 44px; height: 44px; }
  .ult-btn { width: 52px; height: 52px; }
  .basic-attack { width: 55px; height: 55px; }
}

/* Hero grid 2 rows for landscape */
@media (min-width: 700px) {
  .hero-grid { grid-template-columns: repeat(5, 1fr); grid-template-rows: repeat(2, 1fr); }
}
