:root {
  --bg: #07090f;
  --panel: rgba(16, 20, 34, 0.92);
  --border: rgba(245, 185, 66, 0.35);
  --gold: #f5b942;
  --crimson: #e04444;
  --blue: #38bdf8;
  --text: #f1f5f9;
  --muted: #94a3b8;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  touch-action: none;
}

/* Tela de Login / Alocacao de Sessao */
#lobbyOverlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at center, #1b223a 0%, #07090f 75%);
  padding: 16px;
}

#lobbyOverlay.hidden { display: none; }

.lobby-card {
  width: 100%;
  max-width: 440px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 26px;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.65);
}

.lobby-title {
  text-align: center;
  color: var(--gold);
  font-size: 1.45rem;
  font-weight: 800;
  margin-bottom: 6px;
}

.lobby-sub {
  text-align: center;
  color: var(--muted);
  font-size: 0.9rem;
  margin-bottom: 20px;
}

.field { margin-bottom: 14px; }
.field label { display: block; font-size: 0.82rem; color: var(--muted); margin-bottom: 5px; font-weight: 600; }
.field input {
  width: 100%;
  padding: 11px 13px;
  border-radius: 9px;
  border: 1px solid rgba(148, 163, 184, 0.28);
  background: #0b0e18;
  color: var(--text);
  font-size: 1rem;
  -webkit-user-select: text;
  user-select: text;
}

.btn-play {
  width: 100%;
  padding: 13px;
  border: none;
  border-radius: 10px;
  background: linear-gradient(135deg, #f5b942, #d97706);
  color: #111;
  font-size: 1rem;
  font-weight: 800;
  cursor: pointer;
}

.btn-play:disabled { opacity: 0.6; cursor: wait; }

#lobbyStatus {
  margin-top: 12px;
  min-height: 22px;
  text-align: center;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--gold);
}

/* Viewport do Jogo (1024x768 preservado fullscreen) */
#gameStage {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000;
}

#viewportBox {
  position: relative;
  width: min(100vw, calc(100vh * 4 / 3));
  height: min(100vh, calc(100vw * 3 / 4));
  background: #000;
  overflow: hidden;
}

#streamFrame, #streamCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
  background: #000;
}

#streamCanvas {
  pointer-events: none;
}

/* Barra superior minimalista + F1-F10 retratil */
#topHud {
  position: fixed;
  top: 6px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 40;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  pointer-events: none;
}

.hud-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(10, 13, 22, 0.72);
  border: 1px solid rgba(255, 255, 255, 0.14);
  backdrop-filter: blur(6px);
  padding: 4px 8px;
  border-radius: 999px;
  pointer-events: auto;
}

.hud-btn {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 8px;
  padding: 5px 10px;
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
}

.hud-btn.active {
  background: rgba(245, 185, 66, 0.25);
  border-color: var(--gold);
  color: var(--gold);
}

.hud-btn.danger {
  background: rgba(224, 68, 68, 0.22);
  border-color: rgba(224, 68, 68, 0.55);
  color: #fecaca;
}

#fKeysDrawer {
  display: flex;
  gap: 4px;
  flex-wrap: nowrap;
  background: rgba(10, 13, 22, 0.82);
  border: 1px solid var(--border);
  padding: 5px 8px;
  border-radius: 12px;
  pointer-events: auto;
  transition: opacity 0.18s ease, transform 0.18s ease;
}

#fKeysDrawer.collapsed {
  opacity: 0;
  transform: translateY(-10px);
  pointer-events: none;
}

.fkey-btn {
  min-width: 34px;
  height: 32px;
  border-radius: 7px;
  border: 1px solid rgba(245, 185, 66, 0.45);
  background: rgba(245, 185, 66, 0.14);
  color: var(--gold);
  font-weight: 800;
  font-size: 0.76rem;
  cursor: pointer;
}

.fkey-btn:active {
  background: var(--gold);
  color: #111;
}

/* Camada de Controles Virtuais Touch */
#touchOverlay {
  position: fixed;
  inset: 0;
  z-index: 30;
  pointer-events: none;
  display: none;
}

#touchOverlay.visible { display: block; }

/* Joystick Analogico Esquerdo */
#joystickZone {
  position: fixed;
  left: max(18px, env(safe-area-inset-left));
  bottom: max(18px, env(safe-area-inset-bottom));
  width: 144px;
  height: 144px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 255, 255, 0.08) 0%, rgba(15, 23, 42, 0.55) 100%);
  border: 2px solid rgba(245, 185, 66, 0.45);
  pointer-events: auto;
  touch-action: none;
}

#joystickKnob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 56px;
  height: 56px;
  margin-left: -28px;
  margin-top: -28px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #fde68a, #d97706);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.55);
  pointer-events: none;
}

/* Botoes de Acao Direita */
#actionCluster {
  position: fixed;
  right: max(18px, env(safe-area-inset-right));
  bottom: max(18px, env(safe-area-inset-bottom));
  width: 196px;
  height: 170px;
  pointer-events: none;
}

.action-btn {
  position: absolute;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.35);
  color: #fff;
  font-weight: 800;
  font-size: 0.78rem;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  pointer-events: auto;
  touch-action: none;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.5);
}

.action-btn:active { transform: scale(0.92); }

#btnAttack {
  right: 0;
  bottom: 0;
  width: 78px;
  height: 78px;
  background: radial-gradient(circle, #ef4444, #991b1b);
  border-color: #fca5a5;
  font-size: 0.85rem;
}

#btnJump {
  right: 88px;
  bottom: 10px;
  width: 68px;
  height: 68px;
  background: radial-gradient(circle, #f59e0b, #b45309);
  border-color: #fde68a;
}

#btnHp {
  right: 8px;
  bottom: 92px;
  width: 56px;
  height: 56px;
  background: radial-gradient(circle, #dc2626, #7f1d1d);
  border-color: #fecaca;
}

#btnMp {
  right: 76px;
  bottom: 92px;
  width: 56px;
  height: 56px;
  background: radial-gradient(circle, #0284c7, #0c4a6e);
  border-color: #bae6fd;
}

/* Modal de Chat / Teclado Virtual Android */
#chatModal {
  position: fixed;
  left: 50%;
  bottom: 14px;
  transform: translateX(-50%);
  z-index: 60;
  width: min(92vw, 520px);
  display: none;
  gap: 8px;
  background: var(--panel);
  border: 1px solid var(--gold);
  border-radius: 12px;
  padding: 8px;
}

#chatModal.open { display: flex; }

#chatInput {
  flex: 1;
  background: #0b0e18;
  border: 1px solid rgba(148, 163, 184, 0.35);
  border-radius: 8px;
  color: #fff;
  padding: 10px 12px;
  font-size: 0.95rem;
  -webkit-user-select: text;
  user-select: text;
}

#chatSend {
  background: var(--gold);
  color: #111;
  border: none;
  border-radius: 8px;
  padding: 0 16px;
  font-weight: 800;
  cursor: pointer;
}
