* {
  box-sizing: border-box;
  /* sem seleção de texto / destaque de toque: toques rápidos no jogo
     não devem acionar o overlay de seleção do navegador */
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  height: 100%;
  /* nada de rolagem/bounce: o jogo é a tela inteira */
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  margin: 0;
  background: #06080f;
  font-family: -apple-system, system-ui, "Segoe UI", Roboto, sans-serif;
  color: #e8ecf6;
  touch-action: manipulation;
  display: flex;
}

/* celular: tela cheia; desktop: coluna retrato centralizada */
.wrap {
  position: relative;
  width: 100%;
  height: 100dvh;
  display: flex;
  flex-direction: column;
}
@media (min-width: 700px) {
  body { align-items: center; justify-content: center; }
  .wrap {
    width: min(430px, 100vw);
    height: min(100dvh, 932px);
    border-radius: 24px;
    overflow: hidden;
    border: 1px solid #232e4a;
    box-shadow: 0 24px 70px rgba(0, 0, 0, 0.6);
  }
}

/* modo thumbnail (?thumb=1): cena de divulgação em paisagem, sem moldura */
body.thumb { align-items: stretch; justify-content: stretch; }
body.thumb .wrap {
  width: 100%;
  height: 100dvh;
  border: none;
  border-radius: 0;
  box-shadow: none;
}
body.thumb .hud,
body.thumb .deck { display: none; }

.stage {
  position: relative;
  flex: 1;
  overflow: hidden;
  touch-action: none;
  cursor: pointer;
  background: #06080f;
}

canvas {
  position: absolute;
  inset: 0;
  width: 100% !important;
  height: 100% !important;
  display: block;
}

.hud {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  /* acima do overlay: pausar/som continuam clicáveis com o jogo pausado */
  z-index: 4;
  display: flex;
  justify-content: space-between;
  padding: calc(12px + env(safe-area-inset-top)) 18px 0;
  font-weight: 700;
  font-size: 17px;
  text-shadow: 0 1px 8px rgba(0, 0, 0, 0.8);
  pointer-events: none;
}
.hud .sub {
  font-size: 12px;
  font-weight: 600;
  opacity: 0.75;
  margin-top: 4px;
}
.hud .record {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  line-height: 1.25;
}
.hud .record-label {
  font-size: 12px;
  font-weight: 600;
  opacity: 0.65;
}

.hud-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.mute {
  pointer-events: auto;
  width: 36px;
  height: 36px;
  font-size: 16px;
  line-height: 1;
  color: #fff;
  background: rgba(13, 18, 32, 0.55);
  border: 1px solid #2a3550;
  border-radius: 999px;
  cursor: pointer;
}
.mute:active { transform: translateY(1px); }

/* ===== console de pilotagem: direcional + turbo + tiro automático =====
   É um painel de verdade, não um overlay: a arena termina no topo dele,
   então nada voa por baixo dos polegares (e o "wrap" do clássico acontece
   numa borda visível). A altura é medida pelo game.js. */
.deck {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 2;
  padding: 12px 18px calc(14px + env(safe-area-inset-bottom));
  background: linear-gradient(180deg, #0c1222 0%, #070a14 100%);
  border-top: 1px solid #232e4a;
  box-shadow: 0 -12px 30px rgba(0, 0, 0, 0.45), inset 0 1px 0 rgba(255, 140, 26, 0.14);
  touch-action: none;
  cursor: default;
}

.controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  /* invisível (mas ocupando espaço) fora da partida: o painel não muda de
     altura entre o menu e o jogo */
  visibility: hidden;
}
.controls.on { visibility: visible; }

/* direcional analógico: arraste para apontar a nave */
.stick {
  position: relative;
  flex: none;
  width: 118px;
  height: 118px;
  border-radius: 50%;
  background:
    radial-gradient(circle at 50% 50%, rgba(95, 227, 192, 0.07) 0 36%, transparent 37%),
    radial-gradient(circle at 50% 40%, rgba(36, 48, 78, 0.92), rgba(12, 17, 30, 0.96));
  border: 1.5px solid #2a3550;
  box-shadow: inset 0 2px 12px rgba(0, 0, 0, 0.55);
  touch-action: none;
  cursor: grab;
}
.stick.held {
  border-color: #5fe3c0;
  box-shadow: inset 0 2px 12px rgba(0, 0, 0, 0.55), 0 0 18px rgba(95, 227, 192, 0.28);
  cursor: grabbing;
}
/* cruz-guia sutil */
.stick::before,
.stick::after {
  content: "";
  position: absolute;
  background: rgba(232, 236, 246, 0.08);
  pointer-events: none;
}
.stick::before { left: 50%; top: 14px; bottom: 14px; width: 1px; }
.stick::after { top: 50%; left: 14px; right: 14px; height: 1px; }

/* para onde a nave aponta agora: setinha laranja na borda do direcional */
.stick-heading {
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.stick-heading::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 3px;
  margin-left: -6px;
  border-left: 6px solid transparent;
  border-right: 6px solid transparent;
  border-bottom: 9px solid #ff8c1a;
  filter: drop-shadow(0 0 4px rgba(255, 140, 26, 0.75));
}

.knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 52px;
  height: 52px;
  margin: -26px 0 0 -26px;
  border-radius: 50%;
  background: radial-gradient(circle at 38% 32%, #b8fbe9, #5fe3c0 45%, #24937a);
  border: 1.5px solid rgba(220, 255, 245, 0.85);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.45), 0 0 14px rgba(95, 227, 192, 0.35);
  pointer-events: none;
  transition: transform 0.12s ease-out;
}
.stick.held .knob { transition: none; }

.buttons {
  display: flex;
  align-items: center;
  gap: 14px;
}

.ctl {
  pointer-events: auto;
  touch-action: none;
  /* botões grandes: mais fáceis de acertar com o polegar no celular */
  width: 78px;
  height: 78px;
  padding: 0;
  font-size: 30px;
  line-height: 1;
  color: #e8ecf6;
  background: rgba(13, 18, 32, 0.6);
  border: 1.5px solid #2a3550;
  border-radius: 999px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* 🚀 turbo: segurar = acelerar na direção para onde a nave aponta */
.ctl.turbo {
  width: 96px;
  height: 96px;
  font-size: 38px;
  background: linear-gradient(180deg, rgba(255, 179, 71, 0.34), rgba(255, 122, 26, 0.34));
  border-color: #ff8c1a;
  box-shadow: 0 6px 24px rgba(255, 122, 26, 0.28);
}
.ctl.turbo.held {
  background: linear-gradient(180deg, rgba(255, 179, 71, 0.62), rgba(255, 122, 26, 0.62));
  box-shadow: 0 0 30px rgba(255, 140, 26, 0.55);
  transform: scale(0.96);
}

/* 🔥 AUTO: liga/desliga o tiro automático (um toque, não precisa segurar) */
.ctl.auto {
  width: 70px;
  height: 70px;
  font-size: 24px;
  flex-direction: column;
  gap: 3px;
}
.ctl-tag {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.08em;
  opacity: 0.7;
}
.ctl-tag::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #3a4666;
}
.ctl.auto:not(.on) .ctl-ico { filter: grayscale(1); opacity: 0.5; }
.ctl.auto.on {
  background: linear-gradient(180deg, rgba(255, 224, 102, 0.3), rgba(255, 160, 40, 0.3));
  border-color: #ffce54;
  box-shadow: 0 0 20px rgba(255, 206, 84, 0.35);
}
.ctl.auto.on .ctl-tag { color: #ffe9a8; opacity: 1; }
.ctl.auto.on .ctl-tag::before {
  background: #ffe066;
  box-shadow: 0 0 6px #ffce54;
}
.ctl.auto:active { transform: scale(0.95); }

/* celulares estreitos: encolhe p/ o direcional e os botões nunca se sobreporem */
@media (max-width: 344px) {
  .deck { padding-left: 12px; padding-right: 12px; }
  .stick { width: 100px; height: 100px; }
  .knob { width: 44px; height: 44px; margin: -22px 0 0 -22px; }
  .buttons { gap: 10px; }
  .ctl.turbo { width: 80px; height: 80px; font-size: 31px; }
  .ctl.auto { width: 60px; height: 60px; font-size: 20px; }
}
/* telas baixas (paisagem): console mais fino p/ não comer a arena */
@media (max-height: 640px) {
  .deck { padding-top: 8px; padding-bottom: calc(10px + env(safe-area-inset-bottom)); }
  .stick { width: 92px; height: 92px; }
  .knob { width: 42px; height: 42px; margin: -21px 0 0 -21px; }
  .ctl.turbo { width: 74px; height: 74px; font-size: 29px; }
  .ctl.auto { width: 58px; height: 58px; font-size: 20px; }
}

/* vinheta cinematográfica por cima do jogo */
.stage::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  background: radial-gradient(ellipse at 50% 42%, transparent 55%, rgba(0, 0, 0, 0.42));
}

.floater {
  position: absolute;
  z-index: 2;
  transform: translate(-50%, -50%);
  color: #ffce54;
  font-weight: 800;
  font-size: 17px;
  text-shadow: 0 1px 8px rgba(255, 140, 0, 0.65);
  pointer-events: none;
  white-space: nowrap;
  animation: floatUp 0.9s ease-out forwards;
}
.floater.gold {
  color: #ffe066;
  font-size: 19px;
  text-shadow: 0 1px 10px rgba(255, 200, 0, 0.8);
}
/* aviso curto (ex.: tiro automático ligado/desligado) */
.floater.hint {
  color: #e8ecf6;
  font-size: 14px;
  font-weight: 700;
  text-shadow: 0 1px 8px rgba(0, 0, 0, 0.9);
  animation-duration: 1.3s;
}
@keyframes floatUp {
  from { opacity: 1; margin-top: 0; }
  to { opacity: 0; margin-top: -52px; }
}

/* faixa de nível / marco: entra, respira e some (uma de cada vez) */
.banner {
  position: absolute;
  z-index: 2;
  left: 50%;
  top: 34%;
  transform: translate(-50%, -50%);
  width: max-content;
  max-width: calc(100% - 28px);
  padding: 12px 26px;
  border-radius: 26px;
  background: rgba(12, 16, 30, 0.82);
  border: 1px solid rgba(255, 140, 26, 0.55);
  box-shadow: 0 8px 40px rgba(255, 122, 26, 0.35);
  color: #ffe1b0;
  font-weight: 800;
  font-size: clamp(17px, 5vw, 22px);
  text-align: center;
  pointer-events: none;
  animation: bannerPop 2.2s ease forwards;
}
@keyframes bannerPop {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.6); }
  12% { opacity: 1; transform: translate(-50%, -50%) scale(1.06); }
  20% { transform: translate(-50%, -50%) scale(1); }
  80% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -56%) scale(0.94); }
}

.overlay {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  text-align: center;
  padding: 24px calc(20px + env(safe-area-inset-left)) calc(24px + env(safe-area-inset-bottom));
  background: rgba(8, 11, 20, 0.74);
  backdrop-filter: blur(4px);
}
.overlay.visible { display: flex; }

.overlay h1 {
  margin: 0 0 4px;
  font-size: clamp(30px, 9vw, 44px);
  letter-spacing: -0.5px;
}
.overlay h1 .accent { color: #ff8c1a; }
.overlay p { margin: 2px 0; line-height: 1.5; }
.overlay .big { font-size: 19px; }
.overlay .small { font-size: 14px; opacity: 0.7; }

.btn {
  margin-top: 10px;
  font-size: 18px;
  font-weight: 700;
  color: #1a0f05;
  background: linear-gradient(180deg, #ffb347, #ff7a1a);
  border: none;
  border-radius: 999px;
  padding: 15px 44px;
  cursor: pointer;
  box-shadow: 0 6px 20px rgba(255, 122, 26, 0.4);
}
.btn:active { transform: translateY(1px); }

a.btn {
  text-decoration: none;
  display: inline-block;
}

.btn-ghost {
  background: transparent;
  color: #e8ecf6;
  box-shadow: none;
  border: 1.5px solid #3a4666;
  font-size: 16px;
  padding: 12px 36px;
  margin-top: 2px;
}

.overlay .cta {
  font-size: 14px;
  opacity: 0.85;
  line-height: 1.5;
  margin-top: 12px;
  max-width: 300px;
}

/* celular deitado: a tela de derrota (com o convite) precisa caber inteira */
@media (max-height: 460px) {
  .overlay { gap: 5px; padding-top: 10px; padding-bottom: calc(10px + env(safe-area-inset-bottom)); }
  .overlay h1 { font-size: 28px; margin: 0; }
  .overlay .big { font-size: 16px; }
  .overlay .cta { font-size: 12.5px; margin-top: 4px; line-height: 1.35; }
  .btn { margin-top: 4px; padding: 10px 34px; font-size: 16px; }
  .btn-ghost { padding: 8px 28px; font-size: 14px; }
}
