:root {
  --bg: #050505;
  --fg: #f4f4f4;
  --accent: #39ff88;
  --accent-dim: #1c7a44;
  --danger: #ff5555;
  --font: "Press Start 2P", monospace;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font);
  min-height: 100%;
}

body {
  display: flex;
  justify-content: center;
  padding: 16px;
}

.crt {
  width: 100%;
  max-width: 860px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.title-bar {
  text-align: center;
}

h1 {
  margin: 0;
  font-size: clamp(20px, 5vw, 34px);
  letter-spacing: 2px;
  text-shadow: 0 0 8px var(--accent);
}

h1 span {
  color: var(--accent);
}

#app {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.screen {
  display: none;
  width: 100%;
  flex-direction: column;
  align-items: center;
  gap: 20px;
}

.screen.active {
  display: flex;
}

.subtitle {
  font-size: 12px;
  color: var(--accent);
  letter-spacing: 1px;
  text-align: center;
}

.hint {
  font-size: 9px;
  color: #888;
  text-align: center;
}

.menu-options {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  justify-content: center;
}

.btn {
  font-family: var(--font);
  background: transparent;
  border: 2px solid var(--fg);
  color: var(--fg);
  padding: 16px 20px;
  font-size: 12px;
  line-height: 1.6;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s, transform 0.1s;
  min-width: 160px;
}

.btn:hover,
.btn:focus-visible {
  background: var(--accent);
  border-color: var(--accent);
  color: #000;
  outline: none;
}

.btn:active {
  transform: scale(0.97);
}

.btn.ghost {
  border-color: #555;
  color: #999;
}

.btn.ghost:hover {
  background: #333;
  border-color: #999;
  color: var(--fg);
}

.btn.small {
  min-width: 90px;
  padding: 10px 8px;
  font-size: 10px;
}

.btn.selected {
  background: var(--accent);
  border-color: var(--accent);
  color: #000;
}

#setup-form {
  width: 100%;
  max-width: 420px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 10px;
}

.field input {
  font-family: var(--font);
  background: #111;
  border: 2px solid #444;
  color: var(--fg);
  padding: 10px;
  font-size: 12px;
}

.field input:focus {
  border-color: var(--accent);
  outline: none;
}

.difficulty-options {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.setup-actions {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

/* HUD + jogo */
.hud {
  width: 100%;
  max-width: 800px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
}

.hud-side {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.hud-side.right {
  flex-direction: row-reverse;
}

.hud-name {
  font-size: 9px;
  color: #aaa;
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.hud-score {
  font-size: 24px;
  color: var(--accent);
  text-shadow: 0 0 6px var(--accent);
}

.hud-level {
  font-size: 9px;
  color: #666;
}

#canvas {
  width: 100%;
  max-width: 800px;
  height: auto;
  aspect-ratio: 8 / 5;
  background: #000;
  border: 2px solid var(--fg);
  image-rendering: pixelated;
}

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  z-index: 10;
}

.overlay.hidden {
  display: none;
}

.overlay p {
  font-size: 20px;
  color: var(--accent);
  text-shadow: 0 0 8px var(--accent);
}

.winner {
  font-size: 14px;
  color: var(--accent);
  text-align: center;
}

.final-score {
  font-size: 28px;
  text-align: center;
}

.footer {
  font-size: 8px;
  color: #555;
  text-align: center;
  padding-top: 8px;
}

/* ---------- Controles de toque (celular e tablet) ---------- */
html, body { overscroll-behavior: none; }
.hud-mid { display: flex; align-items: center; gap: 10px; }
.pause-btn {
  display: none; font-family: var(--font); font-size: 10px; letter-spacing: 2px;
  background: transparent; color: var(--fg); border: 2px solid #555; padding: 8px 10px; cursor: pointer;
}
.pause-btn:active { background: #333; }
.arena { width: 100%; max-width: 800px; display: flex; flex-direction: column; align-items: center; gap: 14px; }
.joy { display: none; }

body.touch .pause-btn { display: inline-block; }
body.touch .arena {
  max-width: none; display: grid; gap: 12px 16px; align-items: center; justify-items: center;
  grid-template-columns: 1fr 1fr; grid-template-areas: "tela tela" "j1 j2";
}
body.touch #canvas { grid-area: tela; }
body.touch .joy {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
  padding: 6px 18px; /* área de toque maior que o desenho */
}
body.touch #joy1 { grid-area: j1; justify-self: start; }
body.touch #joy2 { grid-area: j2; justify-self: end; }
body.touch.mode-cpu #joy2 { display: none; }
body.touch.mode-cpu #joy1 { grid-column: 1 / -1; justify-self: center; }
.joy-track {
  position: relative; width: 68px; height: clamp(150px, 34vh, 270px);
  border: 2px solid #444; background: repeating-linear-gradient(0deg, #0b0b0b 0 6px, #111 6px 12px);
}
.joy-track::before, .joy-track::after {
  content: ""; position: absolute; left: 50%; translate: -50% 0; border: 7px solid transparent; opacity: .55;
}
.joy-track::before { top: 6px; border-bottom-color: var(--accent); border-top-width: 0; }
.joy-track::after { bottom: 6px; border-top-color: var(--accent); border-bottom-width: 0; }
.joy-knob {
  position: absolute; left: 50%; top: 50%; width: 52px; height: 52px; translate: -50% -50%;
  background: var(--accent); box-shadow: 0 0 12px var(--accent), inset 0 -5px 0 rgba(0,0,0,.25);
  transition: transform .12s ease-out;
}
.joy.active .joy-knob { transition: none; }
.joy.active .joy-track { border-color: var(--accent); }
.joy-label { font-size: 8px; color: #888; max-width: 110px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Durante a partida no celular: tela cheia para o jogo */
body.touch.playing { padding: 8px max(8px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left)); }
body.touch.playing .title-bar, body.touch.playing .footer { display: none; }
body.touch.playing #screen-game { gap: 10px; }
body.touch.playing .hint { font-size: 7px; line-height: 1.6; }

/* Celular deitado: joysticks nas laterais, mesa no centro */
@media (orientation: landscape) {
  body.touch .arena { grid-template-columns: auto minmax(0, 1fr) auto; grid-template-areas: "j1 tela j2"; gap: 12px; }
  body.touch #joy1, body.touch #joy2 { justify-self: center; }
  body.touch.mode-cpu #joy1 { grid-column: auto; }
  body.touch.mode-cpu #joy2 { display: flex; visibility: hidden; }
  body.touch.playing #canvas { width: auto; max-width: 100%; height: calc(100dvh - 92px); }
  body.touch .joy-track { height: min(60vh, 220px); }
  body.touch.playing #game-hint { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
  }
}
