* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --accent: #ffce47;
  --accent-2: #ff7b54;
  --panel: rgba(40, 22, 12, 0.78);
  --panel-border: rgba(255, 210, 150, 0.18);
  --field-w: 800px;
  --field-h: 600px;
}

html, body {
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
}

body {
  height: 100dvh;
  overflow: hidden;
  font-family: "Segoe UI", system-ui, sans-serif;
  background:
    radial-gradient(circle at 20% 15%, #6b3410 0%, transparent 45%),
    radial-gradient(circle at 80% 25%, #7a2d1a 0%, transparent 50%),
    linear-gradient(160deg, #2a160c 0%, #3d2113 55%, #140a05 100%);
  color: #fff3e0;
  touch-action: manipulation;
}

/* Layout em tela cheia: HUD no topo, campo preenchendo o resto. */
.game-wrapper {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
  height: 100dvh;
  padding: 10px;
}

/* ===================== HUD ===================== */
.hud {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 14px;
  padding: 12px 16px;
  backdrop-filter: blur(6px);
}

.hud-item { display: flex; flex-direction: column; gap: 2px; }

.hud-label {
  font-size: 11px;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: #d8a87a;
}

.hud-value {
  font-size: 24px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--accent);
}

/* O combo ganha destaque quando está alto (classe .hot via JS) */
.hud-combo .hud-value { color: #ffd27a; transition: color 0.2s, transform 0.1s; }
.hud-combo.hot .hud-value { color: #ff6a3d; }

#difficulty {
  background: #3a2114;
  color: #fff;
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  padding: 6px 8px;
  font-size: 14px;
  cursor: pointer;
}

.sound-btn {
  background: #3a2114;
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  font-size: 20px;
  width: 44px;
  height: 44px;
  cursor: pointer;
  transition: transform 0.1s ease, background 0.2s;
}
.sound-btn:hover { background: #4d2c1a; transform: scale(1.05); }
.sound-btn.off { opacity: 0.55; font-size: 14px; }
#musicToggle { margin-left: auto; }
.hud-home { display: inline-flex; align-items: center; justify-content: center; text-decoration: none; }

/* ===================== CAMPO ===================== */
/* O frame ocupa a célula do grid; o campo (800x600) é escalado por GSAP via
   fitBoard() para PREENCHER a tela disponível (campo grande no celular). */
.field-frame {
  flex: 1 1 auto;
  width: 100%;
  min-height: 0;
  position: relative;
  overflow: hidden;
  touch-action: none;
}
.field {
  position: relative;
  width: var(--field-w);
  height: var(--field-h);
  border-radius: 18px;
  overflow: hidden;
  cursor: crosshair;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.55);
  border: 1px solid var(--panel-border);
  background: linear-gradient(180deg, #ffb14e 0%, #ff8a3d 38%, #d9632a 60%, #8a4a2a 100%);
  user-select: none;
  touch-action: none;
}

/* Cenário do faroeste (pôr do sol no deserto) */
.sky {
  position: absolute;
  inset: 0 0 38% 0;
  background:
    radial-gradient(120% 90% at 50% 100%, rgba(255, 240, 180, 0.5), transparent 60%),
    linear-gradient(180deg, #ffcf6b 0%, #ff9a4a 60%, #ff7a3a 100%);
}
.sun {
  position: absolute;
  top: 16%;
  left: 50%;
  transform: translateX(-50%);
  width: 150px;
  height: 150px;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 45%, #fff4c2, #ffd25e 55%, #ffb02e 100%);
  box-shadow: 0 0 90px 24px rgba(255, 200, 90, 0.55);
}
.mesas {
  position: absolute;
  left: 0; right: 0; bottom: 30%;
  height: 150px;
  background: rgba(120, 56, 28, 0.85);
  clip-path: polygon(
    0 100%, 0 70%, 8% 70%, 8% 45%, 20% 45%, 20% 72%, 34% 72%,
    34% 38%, 50% 38%, 50% 72%, 64% 72%, 64% 52%, 78% 52%, 78% 30%,
    92% 30%, 92% 66%, 100% 66%, 100% 100%
  );
  filter: drop-shadow(0 -3px 0 rgba(255, 180, 110, 0.25));
}
.cactus {
  position: absolute;
  bottom: 28%;
  font-size: 64px;
  line-height: 1;
  filter: drop-shadow(0 4px 4px rgba(0, 0, 0, 0.3)) saturate(0.85) brightness(0.9);
  pointer-events: none;
  user-select: none;
}
.cactus-1 { left: 6%; bottom: 26%; transform: scaleX(-1); }
.cactus-2 { right: 8%; bottom: 27%; font-size: 52px; }
.ground {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 30%;
  background:
    repeating-linear-gradient(90deg, rgba(0,0,0,0.05) 0 40px, rgba(255,255,255,0.04) 40px 80px),
    linear-gradient(180deg, #c97a3c 0%, #9a531f 55%, #6e3b16 100%);
  border-top: 3px solid rgba(255, 220, 160, 0.35);
}
.fence {
  position: absolute;
  left: 0; right: 0; bottom: calc(30% - 4px);
  height: 46px;
  background:
    linear-gradient(180deg, transparent 0 8px, #5a3416 8px 14px, transparent 14px 26px, #5a3416 26px 32px, transparent 32px),
    repeating-linear-gradient(90deg, transparent 0 90px, #6b3f1b 90px 104px);
  opacity: 0.8;
  pointer-events: none;
}

/* ===================== ALVOS ===================== */
.targets-layer { position: absolute; inset: 0; z-index: 5; }
.target {
  position: absolute;
  left: 0; top: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  cursor: pointer;
  user-select: none;
  will-change: transform;
  line-height: 1;
  filter: drop-shadow(0 5px 6px rgba(0, 0, 0, 0.45));
}
/* tamanho-base definido pelo JS (--d = diâmetro); a fonte acompanha */
.target .face { font-size: 0.7em; pointer-events: none; }
.target.bandit  { background: radial-gradient(circle at 38% 30%, rgba(120,60,30,0.55), rgba(70,30,12,0.35)); }
.target.fast    { background: radial-gradient(circle at 38% 30%, rgba(150,40,40,0.55), rgba(80,20,20,0.35)); }
.target.gold    { background: radial-gradient(circle at 38% 30%, rgba(255,215,90,0.7), rgba(180,130,20,0.4)); box-shadow: 0 0 22px rgba(255, 200, 70, 0.6); }
.target.innocent{ background: radial-gradient(circle at 38% 30%, rgba(90,170,255,0.5), rgba(30,80,160,0.35)); }
/* anel de aviso no inocente (NÃO atire) */
.target.innocent::after {
  content: "🚫";
  position: absolute;
  top: -10px; right: -8px;
  font-size: 0.34em;
  filter: none;
}

/* ===================== EFEITOS ===================== */
.fx-layer { position: absolute; inset: 0; pointer-events: none; z-index: 8; }
.particle {
  position: absolute;
  border-radius: 50%;
  will-change: transform, opacity;
}
.bullet-hole {
  position: absolute;
  width: 16px; height: 16px;
  margin: -8px 0 0 -8px;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 50%, #2a1a0e 0%, #4a2d18 55%, transparent 72%);
  box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.25);
}
.muzzle {
  position: absolute;
  width: 60px; height: 60px;
  margin: -30px 0 0 -30px;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 50%, #fff7c2 0%, #ffcf4a 35%, rgba(255,120,40,0.4) 60%, transparent 72%);
}
.float-text {
  position: absolute;
  font-weight: 800;
  font-size: 28px;
  color: #ffe14d;
  text-shadow: 0 0 6px rgba(0,0,0,0.75);
  transform: translate(-50%, -50%);
  white-space: nowrap;
}
.float-text.neg { color: #ff5a5a; }
.float-text.gold { color: #fff0a0; }
.float-text.combo { color: #ff9a3d; }

/* Mira (crosshair) que segue o mouse — só no desktop */
.reticle {
  position: absolute;
  width: 46px; height: 46px;
  margin: -23px 0 0 -23px;
  border: 2px solid rgba(255, 60, 40, 0.85);
  border-radius: 50%;
  z-index: 9;
  pointer-events: none;
  opacity: 0;
}
.reticle::before, .reticle::after {
  content: ""; position: absolute; background: rgba(255, 60, 40, 0.85);
}
.reticle::before { left: 50%; top: -8px; width: 2px; height: 14px; margin-left: -1px; }
.reticle::after  { top: 50%; left: -8px; height: 2px; width: 14px; margin-top: -1px; }

/* Flash vermelho de penalidade (cobre o campo por um instante) */
.field.hurt::before {
  content: "";
  position: absolute; inset: 0;
  background: radial-gradient(circle at 50% 50%, transparent 40%, rgba(255, 0, 0, 0.35) 100%);
  z-index: 7;
  pointer-events: none;
  animation: hurtFlash 0.4s ease-out;
}
@keyframes hurtFlash { from { opacity: 1; } to { opacity: 0; } }

/* ===================== DUELO ===================== */
.duel {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 12;
  pointer-events: none;
  text-align: center;
}
.duel.hidden { display: none; }
.duel span {
  font-size: 64px;
  font-weight: 900;
  letter-spacing: 2px;
  color: #fff;
  text-shadow: 0 4px 18px rgba(0,0,0,0.7);
}
.duel.draw span { color: #ff3b2f; }

/* ===================== OVERLAYS ===================== */
.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  text-align: center;
  padding: 24px;
  background: rgba(20, 10, 5, 0.72);
  backdrop-filter: blur(4px);
  z-index: 10;
}
.overlay.hidden { display: none; }
#startOverlay { pointer-events: none; }

.overlay h1 {
  font-size: 46px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-shadow: 0 4px 24px rgba(255, 123, 84, 0.25);
}
.overlay p { font-size: 17px; line-height: 1.5; color: #ffe6cc; }
.overlay .hint { font-size: 14px; color: #d8a87a; }
.overlay .big-hint { font-size: 16px; color: #ffce47; margin-top: 4px; }

/* ===================== TELA DE GAME OVER (fora do campo) ===================== */
.screen-over {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(20, 10, 5, 0.85);
  backdrop-filter: blur(5px);
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: calc(env(safe-area-inset-top, 0px) + 14px) 16px 16px;
  overflow-y: auto;
}
.screen-over.hidden { display: none; }
.over-card {
  width: 100%;
  max-width: 420px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  text-align: center;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 16px;
  padding: 20px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
}
.over-card h1 {
  font-size: 34px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.over-card p { font-size: 16px; color: #ffe6cc; }
/* Trava os botões por um instante (evita cliques de "martelada" no game over) */
.screen-over.lock .name-row,
.screen-over.lock .play-again,
.screen-over.lock .ovl-home { pointer-events: none; opacity: 0.55; }

.name-row { display: flex; gap: 10px; margin-top: 6px; }
#playerName {
  padding: 14px 18px;
  border-radius: 10px;
  border: 1px solid var(--panel-border);
  background: #2a160c;
  color: #fff;
  font-size: 18px;
  outline: none;
  text-transform: uppercase;
}
#playerName:focus { border-color: var(--accent); }

.over-card button {
  cursor: pointer;
  border: none;
  border-radius: 10px;
  padding: 14px 22px;
  font-size: 18px;
  font-weight: 700;
  color: #2a1300;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transition: transform 0.1s ease, filter 0.2s;
}
.over-card button:hover { transform: translateY(-2px); filter: brightness(1.08); }
.play-again { width: 100%; padding: 12px; font-size: 16px; margin-top: 6px; }
#saveScore { white-space: nowrap; }
.ovl-home { display: inline-block; margin-top: 8px; color: #d8a87a; font-size: 14px; text-decoration: none; }
.ovl-home:hover { color: #fff; }

/* ===================== RANKING ===================== */
.ranking {
  position: fixed;
  top: 76px;
  right: 16px;
  width: 260px;
  max-height: calc(100dvh - 96px);
  z-index: 30;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 14px;
  padding: 16px;
  backdrop-filter: blur(6px);
  display: flex;
  flex-direction: column;
}
.ranking h2 { font-size: 18px; margin-bottom: 12px; }

#rankList { list-style: none; counter-reset: rank; flex: 1; overflow-y: auto; }
#rankList li {
  counter-increment: rank;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 9px 10px;
  border-radius: 9px;
  margin-bottom: 6px;
  background: rgba(255, 255, 255, 0.04);
  font-size: 14px;
}
#rankList li::before {
  content: counter(rank);
  font-weight: 700;
  color: var(--accent);
  min-width: 18px;
}
#rankList li .rk-name { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#rankList li .rk-score { font-variant-numeric: tabular-nums; color: #ffce47; font-weight: 700; }
#rankList li .rk-time { font-variant-numeric: tabular-nums; color: #d8a87a; font-size: 12px; }
#rankList li:nth-child(1)::before { color: #ffd84d; }
#rankList li:nth-child(2)::before { color: #e8d8c0; }
#rankList li:nth-child(3)::before { color: #e09b5a; }
#rankList li.empty { justify-content: center; color: #a87a5a; font-style: italic; }
#rankList li.empty::before { content: ""; min-width: 0; }

.back-link {
  margin-top: 10px;
  display: block;
  text-align: center;
  background: transparent;
  border: 1px solid var(--panel-border);
  color: #d8a87a;
  border-radius: 9px;
  padding: 10px;
  cursor: pointer;
  font-size: 13px;
  text-decoration: none;
  transition: background 0.2s, color 0.2s;
}
.back-link:hover { background: rgba(255, 255, 255, 0.06); color: #fff; }
.rank-total { font-size: 11px; color: #a87a5a; text-align: center; margin-top: 6px; }

/* Controles na tela inicial (o #startOverlay tem pointer-events:none) */
.start-controls {
  display: flex;
  gap: 16px;
  justify-content: center;
  flex-wrap: wrap;
  margin: 4px 0 2px;
  pointer-events: auto;
}
.start-controls label {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  letter-spacing: 0.5px;
  color: #d8a87a;
}
.start-controls select { font-size: 15px; padding: 8px 10px; pointer-events: auto; }

/* Ranking aparece SOMENTE antes de iniciar (estado "ready") */
body[data-state="playing"] .ranking,
body[data-state="over"] .ranking { display: none !important; }

/* ===================== MOBILE ===================== */
@media (max-width: 820px) {
  .game-wrapper {
    gap: 4px;
    padding: calc(env(safe-area-inset-top, 0px) + 4px) 4px 4px;
  }

  .hud {
    flex: 0 0 auto;
    gap: 8px;
    padding: 6px 10px;
    border-radius: 10px;
    flex-wrap: nowrap;
    overflow-x: auto;
  }
  .hud-label { display: none; }
  .hud-value { font-size: 18px; }
  #difficulty { font-size: 12px; padding: 4px 6px; }
  .sound-btn { width: 38px; height: 38px; font-size: 16px; }

  /* Campo preenche todo o espaço entre a HUD e a base (vertical no celular) */
  .field-frame {
    flex: 1 1 auto;
    width: 100%;
    min-height: 0;
  }

  /* Mira não aparece no celular (joga por toque) */
  .reticle { display: none !important; }

  /* Ranking: selo discreto no canto superior direito */
  .ranking {
    position: fixed;
    top: calc(env(safe-area-inset-top, 0px) + 54px);
    right: 8px;
    z-index: 40;
    width: auto;
    min-width: 96px;
    max-width: 46vw;
    padding: 5px 8px;
    border-radius: 10px;
    background: rgba(20, 10, 5, 0.62);
    backdrop-filter: blur(4px);
  }
  .ranking h2 { font-size: 10px; letter-spacing: 0.5px; margin-bottom: 3px; opacity: 0.8; }
  #rankList { overflow: visible; }
  #rankList li {
    padding: 1px 3px;
    margin-bottom: 1px;
    font-size: 11px;
    background: transparent;
    gap: 5px;
  }
  #rankList li::before { min-width: 12px; }
  .back-link { display: none; }
  .rank-total { font-size: 10px; }

  /* Duelo: texto menor para caber no retrato */
  .duel span { font-size: 44px; }

  /* Game over: card largo, campos e botões BEM grandes */
  .over-card { max-width: none; gap: 14px; padding: 18px; }
  .over-card h1 { font-size: 30px; }
  .name-row { width: 100%; flex-direction: column; gap: 12px; }
  #playerName { width: 100%; min-width: 0; font-size: 22px; padding: 18px; text-align: center; }
  #saveScore { width: 100%; font-size: 20px; padding: 18px; }
  .play-again { width: 100%; font-size: 20px; padding: 18px; }
  .ovl-home { font-size: 16px; padding: 6px; }
}
