:root {
  --laranja: #ff7a00;
  --laranja-claro: #ffb066;
  --fundo: #050308;
  --painel: rgba(12, 6, 14, 0.88);
  --texto: #f3e9dc;
  --vermelho: #ff2a2a;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--fundo);
  color: var(--texto);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}

#cena { display: block; width: 100vw; height: 100vh; }

.oculto { display: none !important; }

/* ---------- Ecrãs (início, pausa, fim) ---------- */
.ecra {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 24px;
  padding: 24px;
  background: radial-gradient(ellipse at center, rgba(20, 5, 10, 0.55), rgba(0, 0, 0, 0.92));
  flex-wrap: wrap;
  overflow-y: auto;
}

.painel {
  background: var(--painel);
  border: 1px solid rgba(255, 122, 0, 0.35);
  border-radius: 14px;
  padding: 28px 32px;
  max-width: 540px;
  width: 100%;
  box-shadow: 0 0 40px rgba(255, 60, 0, 0.15);
}

.painel.ranking { max-width: 420px; }

h1 {
  margin: 0 0 12px;
  color: var(--laranja);
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(34px, 5vw, 56px);
  letter-spacing: 1px;
  text-shadow: 0 0 18px rgba(255, 90, 0, 0.55);
}

h2 { margin: 0 0 12px; color: var(--laranja); }

p { line-height: 1.5; margin: 0 0 14px; }

.subtitulo { font-size: 18px; }

strong { color: var(--laranja-claro); }

.controlos {
  list-style: none;
  padding: 0;
  margin: 0 0 14px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px 16px;
  font-size: 15px;
}

kbd {
  display: inline-block;
  min-width: 24px;
  padding: 1px 6px;
  margin-right: 3px;
  border: 1px solid #6b5a4a;
  border-bottom-width: 3px;
  border-radius: 5px;
  background: #1c1418;
  font: 13px ui-monospace, monospace;
  text-align: center;
}

form { display: flex; flex-direction: column; gap: 10px; margin-top: 8px; }

label { font-size: 15px; }

.opcao { display: flex; align-items: center; gap: 8px; cursor: pointer; }

input[type="text"], input:not([type]) {
  font: inherit;
  font-size: 18px;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid #5a4636;
  background: #140c10;
  color: var(--texto);
}

input:focus { outline: 2px solid var(--laranja); }

button {
  font: inherit;
  font-size: 19px;
  font-weight: 600;
  padding: 12px 24px;
  margin-top: 6px;
  border-radius: 10px;
  border: 2px solid var(--laranja);
  background: var(--laranja);
  color: #120800;
  cursor: pointer;
}

button:hover, button:focus-visible { background: var(--laranja-claro); outline: none; }

button.secundario { background: transparent; color: var(--texto); }

.aviso-saude { font-size: 13px; opacity: 0.7; margin: 14px 0 0; }

/* ---------- Ranking ---------- */
table { width: 100%; border-collapse: collapse; font-size: 15px; }
th { text-align: left; color: var(--laranja); border-bottom: 1px solid #4a3426; padding: 6px 4px; }
td { padding: 6px 4px; border-bottom: 1px solid rgba(255, 255, 255, 0.06); }
tr.destaque td { color: var(--laranja-claro); font-weight: 700; }
.vazio { opacity: 0.6; font-style: italic; }

/* ---------- HUD ---------- */
#hud {
  position: fixed;
  inset: 0;
  pointer-events: none;
  font-weight: 700;
  font-size: 22px;
  text-shadow: 0 0 8px #000, 0 0 2px #000;
}

#contador { position: absolute; top: 16px; left: 20px; }
#relogio { position: absolute; top: 16px; right: 20px; font-variant-numeric: tabular-nums; }
#relogio.urgente { color: var(--vermelho); animation: pulsar 1s infinite; }

#mira {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 6px;
  height: 6px;
  margin: -3px 0 0 -3px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.45);
}

#mira.acerto {
  width: 22px;
  height: 22px;
  margin: -11px 0 0 -11px;
  border-radius: 0;
  background:
    linear-gradient(45deg, transparent 45%, #ff3b3b 45%, #ff3b3b 55%, transparent 55%),
    linear-gradient(-45deg, transparent 45%, #ff3b3b 45%, #ff3b3b 55%, transparent 55%);
  animation: acerto 0.25s ease-out forwards;
}

#confronto {
  position: absolute;
  top: 60px;
  left: 50%;
  transform: translateX(-50%);
  text-align: center;
}
#confronto .titulo { color: var(--vermelho); font-size: 26px; letter-spacing: 3px; animation: pulsar 0.5s infinite; }
#pips { display: flex; gap: 8px; justify-content: center; margin: 8px 0; }
#pips span {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid var(--laranja);
  background: rgba(0, 0, 0, 0.5);
}
#pips span.cheio { background: var(--laranja); box-shadow: 0 0 10px var(--laranja); }
#confronto .barra { width: 260px; height: 10px; border-radius: 5px; background: rgba(0, 0, 0, 0.6); border: 1px solid #5a2a1a; overflow: hidden; }
#barraTempo { height: 100%; width: 100%; background: linear-gradient(90deg, var(--vermelho), var(--laranja)); }

#minimapa {
  position: absolute;
  left: 16px;
  bottom: 16px;
  width: 248px;
  height: 200px;
  border: 1px solid rgba(255, 122, 0, 0.45);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.55);
}

/* ---------- Game over ---------- */
#morte { position: fixed; inset: 0; pointer-events: none; z-index: 5; }
#morte::before {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at center, rgba(150, 0, 0, 0.35), rgba(70, 0, 0, 0.9));
  mix-blend-mode: multiply;
  animation: avermelhar 1.2s ease-out forwards;
}
#sangue { position: absolute; inset: 0; width: 100%; height: 100%; }
#morte .texto {
  position: absolute;
  top: 42%;
  width: 100%;
  text-align: center;
  font: 700 clamp(48px, 10vw, 120px) Georgia, serif;
  color: #ff1a1a;
  text-shadow: 0 0 24px #000, 0 0 6px #000;
  opacity: 0;
  animation: surgirMorte 1s ease-out 1.2s forwards;
}
@keyframes avermelhar { from { opacity: 0; } to { opacity: 1; } }
@keyframes surgirMorte { from { opacity: 0; transform: scale(1.4); } to { opacity: 1; transform: scale(1); } }

#aviso {
  position: fixed;
  top: 22%;
  left: 50%;
  transform: translateX(-50%);
  padding: 12px 26px;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.75);
  border: 1px solid var(--laranja);
  font-size: 24px;
  font-weight: 700;
  pointer-events: none;
  animation: surgir 0.3s ease-out;
}

/* ---------- Susto ---------- */
#susto {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: radial-gradient(ellipse at center, rgba(40, 0, 0, 0.55), rgba(0, 0, 0, 0.95));
  pointer-events: none;
  overflow: hidden;
}

#sustoImg { height: 100vh; max-width: 100vw; width: auto; object-fit: contain; transform-origin: 50% 70%; }

#susto.grito #sustoImg { animation: avancar 0.35s cubic-bezier(.2, 1.6, .4, 1) forwards, tremer 0.09s linear infinite 0.35s; }
#susto.bracos #sustoImg { animation: saltar 0.25s cubic-bezier(.2, 1.8, .4, 1) forwards, tremerForte 0.07s linear infinite 0.25s; }
#susto.ataque { background: radial-gradient(ellipse at center, rgba(90, 0, 0, 0.5), rgba(0, 0, 0, 0.95)); }
#susto.ataque #sustoImg { animation: ataque 0.18s cubic-bezier(.2, 1.8, .4, 1) forwards, tremerForte 0.06s linear infinite 0.18s; }
#susto.suave #sustoImg { animation: aparecer 0.6s ease-out forwards !important; height: 70vh; }

#vinheta {
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  background: radial-gradient(ellipse at center, transparent 30%, rgba(200, 0, 0, 0.85));
  transition: opacity 0.4s;
}
#vinheta.ativa { opacity: 1; transition: none; }

@keyframes avancar { from { transform: scale(0.45); } to { transform: scale(1); } }
@keyframes ataque { from { transform: scale(0.6); } to { transform: scale(1.6); } }
@keyframes saltar { from { transform: scale(1); } to { transform: scale(1.25); } }
@keyframes tremer {
  0% { translate: 0 0; } 25% { translate: -6px 4px; } 50% { translate: 5px -5px; } 75% { translate: -4px -3px; } 100% { translate: 0 0; }
}
@keyframes tremerForte {
  0% { translate: 0 0; } 25% { translate: -12px 8px; } 50% { translate: 10px -10px; } 75% { translate: -8px -6px; } 100% { translate: 0 0; }
}
@keyframes aparecer { from { opacity: 0; transform: scale(0.9); } to { opacity: 1; transform: scale(1); } }
@keyframes surgir { from { opacity: 0; transform: translate(-50%, -10px); } to { opacity: 1; transform: translate(-50%, 0); } }
@keyframes acerto { from { transform: scale(1.6); opacity: 1; } to { transform: scale(1); opacity: 0; } }
@keyframes pulsar { 50% { opacity: 0.5; } }

/* =============================================================
   TELEMÓVEL (body.movel é posto pelo js/toque.js)
   ============================================================= */
#toque, #rodar, .so-movel { display: none; }
body.movel .so-pc { display: none; }
body.movel .so-movel { display: grid; grid-template-columns: 1fr; }

/* Os controlos só aparecem durante o jogo (quando o HUD está visível) */
body.movel #hud:not(.oculto) ~ #toque { display: block; }
#toque { position: fixed; inset: 0; z-index: 3; touch-action: none; user-select: none; -webkit-user-select: none; }
#zonaJoystick { position: absolute; left: 0; top: 0; bottom: 0; width: 45%; }
#zonaOlhar { position: absolute; right: 0; top: 0; bottom: 0; width: 55%; }
#joyBase {
  position: absolute; width: 120px; height: 120px; margin: -60px 0 0 -60px;
  left: 18%; top: 70%;
  border-radius: 50%; border: 2px solid rgba(255, 122, 0, 0.35); background: rgba(0, 0, 0, 0.25);
  opacity: 0.45; transition: opacity 0.2s;
}
#joyBase.ativo { opacity: 1; transition: none; }
#joyPega {
  position: absolute; left: 50%; top: 50%; width: 54px; height: 54px; transform: translate(-50%, -50%);
  border-radius: 50%; background: rgba(255, 122, 0, 0.6); box-shadow: 0 0 12px rgba(255, 122, 0, 0.5);
}
#btnDisparar {
  position: absolute; right: max(20px, env(safe-area-inset-right)); bottom: 28px;
  width: 92px; height: 92px; margin: 0; padding: 0; border-radius: 50%;
  font-size: 38px; background: rgba(255, 122, 0, 0.75); border: 3px solid #ffd2a6;
  touch-action: none;
}
#btnDisparar.premido { transform: scale(0.9); background: #ff3b3b; }
#btnPausa {
  position: absolute; top: 8px; left: 50%; transform: translateX(-50%);
  width: 44px; height: 36px; margin: 0; padding: 0; font-size: 16px;
  background: rgba(0, 0, 0, 0.45); color: var(--texto); border: 1px solid rgba(255, 122, 0, 0.5);
}

/* HUD mais compacto e sem minimapa */
body.movel #minimapa { display: none; }
body.movel #hud { font-size: 16px; }
body.movel #contador { top: 8px; left: max(12px, env(safe-area-inset-left)); }
body.movel #relogio { top: 8px; right: max(12px, env(safe-area-inset-right)); }
body.movel #confronto { top: 34px; }
body.movel #confronto .titulo { font-size: 18px; }
body.movel #confronto .barra { width: 180px; }
body.movel #pips span { width: 14px; height: 14px; }
body.movel #aviso { font-size: 16px; top: 18%; padding: 8px 16px; }

/* Ecrãs (início, pausa, fim) cabem num ecrã pequeno */
body.movel .ecra { align-items: flex-start; gap: 12px; padding: 12px; }
body.movel .painel { padding: 16px 18px; }
body.movel h1 { font-size: clamp(26px, 6vw, 40px); margin-bottom: 6px; }
body.movel p, body.movel .controlos { font-size: 14px; margin-bottom: 8px; }
body.movel button { font-size: 17px; padding: 10px 18px; }

/* Em vertical, pede para rodar o telemóvel */
@media (orientation: portrait) {
  body.movel #rodar {
    display: flex; position: fixed; inset: 0; z-index: 20; align-items: center; justify-content: center;
    background: #050308; text-align: center; font-size: 56px; color: var(--laranja);
  }
  body.movel #rodar p { font-size: 18px; color: var(--texto); }
}

.estadoRanking { font-size: 13px; opacity: 0.7; margin: -6px 0 10px; }
