:root {
  --roxo: #5a3fa0;
  --amarelo: #ffd43b;
  --ouro: #f5b82e;
  --contorno: #2b2118;
  --papel: #fff8e7;
  --verde: #8fd0a8;
  --vermelho: #f05454;
}

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

html, body {
  height: 100%;
  overflow: hidden;
  background: linear-gradient(180deg, #a9dcbb 0%, #6fbf93 100%);
  font-family: "Baloo 2", system-ui, sans-serif;
  color: var(--contorno);
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  overscroll-behavior: none;
}

#game {
  position: fixed;
  inset: 0;
  touch-action: none;
}

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

.hidden { display: none !important; }

/* HUD */
#hud {
  position: absolute;
  top: max(12px, env(safe-area-inset-top));
  left: 16px;
  right: 72px;
  display: flex;
  align-items: baseline;
  gap: 16px;
  pointer-events: none;
}
#hud .score {
  font-family: "Anton", Impact, sans-serif;
  font-size: clamp(28px, 6vmin, 44px);
  color: #fff;
  -webkit-text-stroke: 2px var(--contorno);
  paint-order: stroke fill;
  letter-spacing: 1px;
  line-height: 1;
}
#hud .score span { display: inline-block; }
#hud .score span.pulse { animation: pulse 0.35s ease-out; }
@keyframes pulse {
  0% { transform: scale(1); color: #fff; }
  40% { transform: scale(1.25); color: var(--amarelo); }
  100% { transform: scale(1); color: #fff; }
}
#hud .best {
  font-weight: 800;
  font-size: clamp(14px, 3vmin, 18px);
  background: var(--contorno);
  color: var(--amarelo);
  border-radius: 999px;
  padding: 2px 12px;
  white-space: nowrap;
}

.icon-btn {
  position: absolute;
  top: max(10px, env(safe-area-inset-top));
  right: 16px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 3px solid var(--contorno);
  background: var(--papel);
  font-size: 20px;
  cursor: pointer;
  z-index: 5;
}

/* Telas */
.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 16px;
  text-align: center;
  background: rgba(43, 33, 24, 0.25);
}

/* Em pé: telas ocupam a parte de cima; embaixo fica a pista e a torcida */
@media (orientation: portrait) {
  .screen { justify-content: flex-start; padding-top: max(12vh, 64px); }
  .screen .hero { display: none; }
}

/* Celular deitado (tela baixa): tudo mais compacto */
@media (max-height: 430px) {
  .screen { gap: 6px; }
  .hero { width: 56px; }
  h1 { font-size: 40px; }
  h2 { font-size: 36px; }
  .results strong { font-size: 26px; }
}

.logo {
  width: min(78vw, 300px);
  height: auto;
  filter: drop-shadow(0 2px 0 var(--contorno));
}

h1, h2 {
  font-family: "Anton", Impact, sans-serif;
  font-weight: 400;
  text-transform: uppercase;
  color: #fff;
  -webkit-text-stroke: 3px var(--contorno);
  paint-order: stroke fill;
  line-height: 1;
  letter-spacing: 1px;
}
h1 { font-size: clamp(40px, 11vmin, 76px); }
h1 span { color: var(--amarelo); }
h2 { font-size: clamp(36px, 9vmin, 60px); }

.hero {
  width: clamp(72px, 20vmin, 120px);
  height: auto;
  animation: bob 0.9s ease-in-out infinite;
}
@keyframes bob {
  0%, 100% { transform: translateY(0) rotate(-4deg); }
  50% { transform: translateY(-10px) rotate(4deg); }
}

.btn {
  font-family: "Anton", Impact, sans-serif;
  font-size: clamp(22px, 5vmin, 30px);
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--contorno);
  background: var(--amarelo);
  border: 3px solid var(--contorno);
  border-radius: 999px;
  padding: 8px 36px;
  box-shadow: 0 5px 0 var(--contorno);
  cursor: pointer;
  transition: transform 0.08s;
}
.btn:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--contorno); }

.hint {
  font-weight: 800;
  color: #fff;
  text-shadow: 0 2px 0 var(--contorno);
  font-size: clamp(14px, 3.2vmin, 18px);
}

.results {
  display: flex;
  gap: 12px;
}
.results div {
  background: var(--papel);
  border: 3px solid var(--contorno);
  border-radius: 16px;
  padding: 6px 18px;
  min-width: 110px;
}
.results small { display: block; font-weight: 800; font-size: 13px; text-transform: uppercase; }
.results strong { font-family: "Anton", Impact, sans-serif; font-weight: 400; font-size: 32px; color: var(--roxo); }

.badge {
  font-family: "Anton", Impact, sans-serif;
  text-transform: uppercase;
  background: var(--roxo);
  color: var(--amarelo);
  border: 3px solid var(--contorno);
  border-radius: 999px;
  padding: 2px 16px;
  font-size: 20px;
  animation: pop 0.6s ease-out infinite alternate;
}
@keyframes pop { from { transform: scale(1) rotate(-3deg); } to { transform: scale(1.1) rotate(3deg); } }

/* Fim de jogo: a lição da vila (o cartão inteiro é o link para o episódio) e os botões */
.lesson {
  display: flex;
  flex-direction: column;
  gap: 2px;
  width: min(92vw, 520px);
  background: var(--papel);
  border: 3px solid var(--contorno);
  border-radius: 16px;
  box-shadow: 0 4px 0 var(--contorno);
  padding: 10px 16px;
  text-align: left;
  text-decoration: none;
  color: var(--contorno);
  transition: transform 0.08s;
}
.lesson:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--contorno); }
.lesson strong {
  font-family: "Anton", Impact, sans-serif;
  font-weight: 400;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--vermelho);
  font-size: clamp(18px, 3.4vmin, 26px);
  line-height: 1.1;
}
.lesson span { font-weight: 600; font-size: clamp(14px, 2.4vmin, 18px); line-height: 1.3; }
.lesson em { font-style: normal; font-weight: 800; font-size: clamp(14px, 2.2vmin, 17px); color: var(--roxo); text-decoration: underline; text-underline-offset: 2px; }
.actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px 12px; }
.btn-alt { background: var(--papel); font-size: clamp(18px, 4vmin, 24px); }

@media (max-height: 430px) {
  .lesson { padding: 6px 14px; width: min(80vw, 560px); }
  .lesson strong { font-size: 16px; }
  .lesson span, .lesson em { font-size: 13px; }
  #screen-over .hint { display: none; }
  .btn { padding: 6px 26px; }
}

/* Desafio entre amigos */
.challenge {
  font-weight: 800;
  font-size: clamp(15px, 3vmin, 20px);
  background: var(--roxo);
  color: #fff;
  border: 3px solid var(--contorno);
  border-radius: 999px;
  padding: 4px 18px;
  max-width: min(92vw, 560px);
}
#hud .goal { background: var(--roxo); color: #fff; }
.name-form { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.name-form label { font-weight: 800; color: #fff; text-shadow: 0 2px 0 var(--contorno); font-size: 14px; }
.name-form div { display: flex; gap: 8px; }
.name-form input {
  font: 800 18px "Baloo 2", system-ui, sans-serif;
  width: 170px;
  padding: 6px 14px;
  border: 3px solid var(--contorno);
  border-radius: 999px;
  background: var(--papel);
  color: var(--contorno);
  -webkit-user-select: text;
  user-select: text;
}
.btn-small { font-size: 18px; padding: 4px 20px; box-shadow: 0 3px 0 var(--contorno); }
.link-btn {
  background: none;
  border: 0;
  font: 800 13px "Baloo 2", system-ui, sans-serif;
  color: #fff;
  text-shadow: 0 1px 0 var(--contorno);
  text-decoration: underline;
  cursor: pointer;
}
@media (max-height: 430px) {
  .challenge { font-size: 14px; padding: 2px 14px; }
  .name-form label { display: none; }
  #screen-over { justify-content: flex-start; padding-top: 50px; }
  #screen-over h2 { font-size: 30px; }
  #screen-over.asking .lesson { display: none; }
}
@media (max-width: 420px) {
  #hud { gap: 8px; }
  #hud .best { padding: 2px 9px; }
}

/* Etapa alcançada, no fim de jogo */
.stage-line { font-weight: 800; color: #fff; text-shadow: 0 2px 0 var(--contorno); font-size: clamp(14px, 3vmin, 18px); }
@media (max-height: 430px) { .stage-line { font-size: 13px; } }
