* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; user-select: none; }
html, body { width: 100%; height: 100%; overflow: hidden; background: #0a0a14; font-family: system-ui, -apple-system, sans-serif; color: #fff; touch-action: none; }
#game { display: block; width: 100%; height: 100%; }

.overlay { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; z-index: 10; background: rgba(0,0,0,0.85); padding: 20px; overflow-y: auto; }
.overlay.hidden { display: none; }
.panel { background: #1a1a2e; border: 2px solid #4a4a6a; border-radius: 12px; padding: 24px; max-width: 460px; width: 100%; text-align: center; max-height: 95vh; overflow-y: auto; }
.panel h1 { font-size: 28px; margin-bottom: 8px; color: #ff5577; }
.panel h2 { font-size: 17px; margin-bottom: 16px; color: #aaa; font-weight: normal; }
.panel button { display: block; width: 100%; padding: 14px; margin: 8px 0; background: #ff5577; color: #fff; border: none; border-radius: 8px; font-size: 16px; font-weight: bold; cursor: pointer; }
.panel button.secondary { background: #4a4a6a; }
.panel button:active { transform: scale(0.98); }
.panel button:disabled { opacity: 0.5; cursor: not-allowed; }
.panel input, .panel select { width: 100%; padding: 12px; margin: 8px 0; background: #0d0d1a; color: #fff; border: 2px solid #4a4a6a; border-radius: 8px; font-size: 16px; text-align: center; }
.panel input { text-transform: uppercase; letter-spacing: 2px; }
.panel .label { text-align: left; font-size: 13px; color: #aaa; margin-top: 12px; margin-bottom: 4px; }
.panel .info { font-size: 13px; color: #888; margin-top: 12px; line-height: 1.5; }
.panel .code { font-size: 24px; font-weight: bold; color: #ffcc44; padding: 12px; background: #0d0d1a; border-radius: 8px; margin: 12px 0; letter-spacing: 4px; }
.panel .status { font-size: 14px; color: #88ccff; margin: 8px 0; }

.radio-row { display: flex; gap: 16px; justify-content: center; padding: 4px 0; }
.radio-row label { font-size: 14px; cursor: pointer; }

.roster { background: #0d0d1a; border-radius: 8px; padding: 8px; margin: 8px 0; min-height: 60px; max-height: 180px; overflow-y: auto; }
.roster .item { display: flex; align-items: center; gap: 8px; padding: 4px; font-size: 14px; }
.roster .dot { width: 12px; height: 12px; border-radius: 50%; }

.charsel { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; padding: 4px; background: #0d0d1a; border-radius: 8px; }
.charsel .char { padding: 8px 4px; text-align: center; cursor: pointer; border: 2px solid transparent; border-radius: 6px; font-size: 11px; transition: all 0.15s; }
.charsel .char .av { width: 32px; height: 32px; border-radius: 50%; margin: 0 auto 4px; border: 2px solid #fff; }
.charsel .char .wname { color: #aaa; font-size: 9px; margin-top: 2px; line-height: 1.1; }
.charsel .char.sel { border-color: #ffcc44; background: rgba(255,204,68,0.1); }
.charsel .char.taken { opacity: 0.3; cursor: not-allowed; }

#hud { position: fixed; top: 0; left: 0; right: 0; padding: 8px 12px; pointer-events: none; z-index: 5; font-size: 13px; }
#hud .row { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }
#hud .stat { background: rgba(0,0,0,0.6); padding: 4px 10px; border-radius: 6px; }
#hud .stat b { color: #ffcc44; }
#hp-bar { height: 6px; background: rgba(0,0,0,0.6); border-radius: 3px; overflow: hidden; margin-top: 4px; }
#hp-fill { height: 100%; background: linear-gradient(90deg, #ff3344, #ff7788); transition: width 0.2s; }
#xp-bar { height: 4px; background: rgba(0,0,0,0.6); border-radius: 2px; overflow: hidden; margin-top: 2px; }
#xp-fill { height: 100%; background: #44aaff; transition: width 0.2s; }

#stage-progress { position: fixed; top: 0; left: 50%; transform: translateX(-50%); width: 50%; max-width: 420px; padding: 6px 0; z-index: 4; pointer-events: none; }
#stage-progress .label { text-align: center; font-size: 11px; color: #aaa; margin-bottom: 3px; text-shadow: 0 0 4px #000; }
#stage-progress .bar { height: 8px; background: rgba(0,0,0,0.6); border: 1px solid rgba(255,255,255,0.2); border-radius: 4px; overflow: hidden; }
#stage-progress .fill { height: 100%; background: linear-gradient(90deg, #ffcc44, #ff8844); transition: width 0.3s; width: 0%; }
#stage-progress.boss .fill { background: linear-gradient(90deg, #ff3344, #aa0022); }

/* Players list moved BELOW minimap */
#players-list { position: fixed; top: 220px; right: 8px; font-size: 12px; background: rgba(0,0,0,0.6); padding: 6px 10px; border-radius: 6px; z-index: 5; max-width: 200px; }
#players-list .row { margin-bottom: 4px; }
#players-list .weapons { font-size: 10px; color: #ccc; padding-left: 16px; }
.death { color: #ff5577; font-weight: bold; }

/* Mini upgrade popup at corner */
#upgrade-mini { position: fixed; top: 12px; left: 50%; transform: translateX(-50%); z-index: 6; pointer-events: auto; background: rgba(20,10,40,0.92); border: 2px solid #ffcc44; border-radius: 10px; padding: 10px; max-width: 480px; box-shadow: 0 0 20px rgba(255,204,68,0.4); }
#upgrade-mini .hint { text-align: center; font-size: 12px; color: #ffcc44; margin-bottom: 6px; font-weight: bold; }
#upgrade-mini-cards { display: flex; gap: 6px; }
.upgrade-mini-card { background: #2a2a44; border: 2px solid #5a5a8a; border-radius: 8px; padding: 8px; cursor: pointer; flex: 1; min-width: 130px; transition: all 0.15s; }
.upgrade-mini-card:hover, .upgrade-mini-card:active { background: #3a3a5a; border-color: #ffcc44; transform: scale(1.04); }
.upgrade-mini-card .num { color: #ffcc44; font-weight: bold; font-size: 12px; }
.upgrade-mini-card .name { font-size: 13px; font-weight: bold; color: #fff; margin-top: 2px; }
.upgrade-mini-card .lvl { color: #88ccff; font-size: 10px; }
.upgrade-mini-card .desc { color: #ccc; font-size: 10px; margin-top: 2px; line-height: 1.2; }
.upgrade-mini-card .preview { width: 100%; height: 36px; background: rgba(0,0,0,0.4); border-radius: 4px; margin: 4px 0; }
.upgrade-mini-card.new .name::before { content: '✨ '; }
.upgrade-mini-card.evo { border-color: #ff66cc; }
.upgrade-mini-card.evo .name::before { content: '⚡ '; color: #ff66cc; }

#joystick { position: fixed; bottom: 30px; left: 30px; width: 140px; height: 140px; border-radius: 50%; background: rgba(255,255,255,0.08); border: 2px solid rgba(255,255,255,0.2); display: none; z-index: 5; touch-action: none; }
#joystick.visible { display: block; }
#joystick.editing { background: rgba(255,204,68,0.15); border-color: #ffcc44; }
#knob { position: absolute; top: 50%; left: 50%; width: 60px; height: 60px; margin: -30px 0 0 -30px; border-radius: 50%; background: rgba(255,255,255,0.3); border: 2px solid rgba(255,255,255,0.5); }

#toggles { position: fixed; bottom: 12px; right: 12px; display: flex; gap: 6px; z-index: 5; }
#toggles button { background: rgba(0,0,0,0.6); border: 1px solid #555; color: #fff; padding: 6px 10px; border-radius: 6px; font-size: 12px; cursor: pointer; }

#banner { position: fixed; top: 28%; left: 0; right: 0; text-align: center; z-index: 6; pointer-events: none; opacity: 0; transition: opacity 0.5s; }
#banner.show { opacity: 1; }
#banner .big { font-size: 48px; font-weight: bold; text-shadow: 0 0 20px currentColor, 0 0 40px #000; }
#banner .sub { font-size: 18px; color: #ccc; margin-top: 8px; }

/* Codex */
.codex-tabs { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 12px; }
.codex-tab { flex: 1; min-width: 80px; padding: 8px 4px; background: #2a2a44; border: 1px solid #5a5a8a; border-radius: 6px; color: #aaa; font-size: 12px; cursor: pointer; }
.codex-tab.active { background: #ff5577; color: #fff; }
.codex-content { background: #0d0d1a; padding: 12px; border-radius: 8px; max-height: 60vh; overflow-y: auto; text-align: left; font-size: 13px; }
.codex-content .entry { padding: 8px 0; border-bottom: 1px solid #2a2a44; }
.codex-content .entry:last-child { border-bottom: none; }
.codex-content .name { font-weight: bold; color: #ffcc44; }
.codex-content .desc { color: #ccc; font-size: 12px; margin-top: 2px; }
.codex-content .meta { color: #88ccff; font-size: 11px; margin-top: 2px; }

/* Leaderboard */
.lb-content { background: #0d0d1a; padding: 12px; border-radius: 8px; text-align: left; }
.lb-row { display: flex; justify-content: space-between; padding: 8px 4px; border-bottom: 1px solid #2a2a44; }
.lb-row:last-child { border-bottom: none; }
.lb-rank { color: #ffcc44; font-weight: bold; }
.lb-name { color: #fff; }
.lb-stats { color: #88ccff; font-size: 12px; }

/* Help */
.help-grid { display: grid; grid-template-columns: 110px 1fr; gap: 6px; text-align: left; padding: 12px; background: #0d0d1a; border-radius: 8px; font-size: 13px; }
.help-grid b { color: #ffcc44; }

/* ============ CHAT ============ */
/* Caixa de input do chat: aparece em cima do toggles, abre o teclado no mobile via autofocus */
#chat-input-wrap {
  position: fixed; bottom: 60px; right: 12px; z-index: 12;
  display: flex; gap: 4px; background: rgba(20,10,40,0.92);
  border: 2px solid #ff5577; border-radius: 8px; padding: 6px;
  box-shadow: 0 0 12px rgba(255,85,119,0.4);
  max-width: calc(100vw - 24px); width: 360px;
}
#chat-input {
  flex: 1; padding: 8px 10px; background: #0d0d1a; color: #fff;
  border: 1px solid #4a4a6a; border-radius: 6px; font-size: 14px;
  text-transform: none; letter-spacing: 0; min-width: 0;
}
#chat-send-btn, #chat-close-btn {
  background: #ff5577; color: #fff; border: none; border-radius: 6px;
  padding: 0 12px; font-weight: bold; cursor: pointer; flex: 0 0 auto;
}
#chat-close-btn { background: #4a4a6a; }
/* Mensagens flutuantes — aparecem na parte inferior central, fade out lento */
#chat-messages {
  position: fixed; bottom: 60px; left: 12px; right: 12px;
  pointer-events: none; z-index: 5; display: flex; flex-direction: column;
  gap: 3px; max-width: 460px; max-height: 30vh; overflow: hidden;
}
.chat-msg {
  background: rgba(0,0,0,0.65); padding: 4px 10px; border-radius: 6px;
  font-size: 13px; line-height: 1.3; color: #fff;
  border-left: 3px solid #ff5577; opacity: 1;
  transition: opacity 0.6s ease-out; word-wrap: break-word;
  text-shadow: 0 1px 2px #000;
}
.chat-msg .from { font-weight: bold; margin-right: 6px; }
.chat-msg.fading { opacity: 0; }

/* ============ CODEX STAGE PREVIEW ============ */
.stage-preview-canvas {
  display: block; width: 100%; height: 60px;
  border-radius: 4px; margin-top: 4px;
  border: 1px solid rgba(255,255,255,0.1);
}
