/* Fontes (Press Start 2P e Rubik) carregadas por <link> no index.html. */

:root {
  --bg-0: #0a0612;
  --bg-1: #120a20;
  --bg-2: #1b0f2e;
  --purple-900: #2e1065;
  --purple-700: #6d28d9;
  --purple-600: #7c3aed;
  --purple-500: #a855f7;
  --purple-300: #d8b4fe;
  --purple-100: #f3e8ff;
  --cyan: #22d3ee;
  --gold: #fbbf24;
  --white: #f8fafc;
  --danger: #f87171;
  --success: #4ade80;
  --font-display: 'Press Start 2P', 'Courier New', monospace;
  --font-body: 'Rubik', system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: radial-gradient(circle at 50% 0%, var(--bg-2), var(--bg-0) 70%);
  color: var(--white);
  font-family: var(--font-body);
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}

body {
  background-image:
    linear-gradient(rgba(168,85,247,0.06) 1px, transparent 1px),
    linear-gradient(90deg, rgba(168,85,247,0.06) 1px, transparent 1px);
  background-size: 28px 28px;
}

#app {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding: env(safe-area-inset-top, 12px) 12px calc(env(safe-area-inset-bottom, 12px) + 12px);
}

.screen { display: none; width: 100%; max-width: 720px; }
.screen.active { display: flex; flex-direction: column; align-items: center; }

/* ---- Logo ---- */
.logo, .hud-logo { display: flex; align-items: center; }
.logo { margin-top: 18px; }
.logo-badge {
  height: 42px;
  display: block;
  image-rendering: pixelated;
  filter: drop-shadow(0 0 8px rgba(168,85,247,0.5));
}
.hud-badge { height: 26px; filter: drop-shadow(0 0 5px rgba(168,85,247,0.5)); }

/* ---- Panels (start / end) ---- */
.panel {
  width: 100%;
  max-width: 420px;
  background: linear-gradient(160deg, var(--bg-2), var(--bg-1));
  border: 2px solid var(--purple-700);
  border-radius: 18px;
  box-shadow: 0 0 40px rgba(124,58,237,0.25), inset 0 0 30px rgba(0,0,0,0.4);
  padding: 22px 20px 26px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.panel h1 {
  font-family: var(--font-display);
  font-size: 16px;
  line-height: 1.6;
  margin: 8px 0 2px;
  color: var(--purple-100);
}

/* ---- Start screen hero art ---- */
.start-panel { max-width: 620px; padding: 14px 14px 22px; gap: 14px; }

.title-art-btn {
  width: 100%;
  padding: 0;
  border: none;
  background: none;
  cursor: pointer;
  border-radius: 14px;
  overflow: hidden;
  line-height: 0;
  touch-action: manipulation;
}
.title-art {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 14px;
  border: 2px solid var(--purple-700);
  box-shadow: 0 0 30px rgba(168,85,247,0.35);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.title-art-btn picture { display: block; }
.title-art-btn:hover .title-art { transform: scale(1.015); box-shadow: 0 0 40px rgba(168,85,247,0.5); }
.title-art-btn:active .title-art { transform: scale(0.99); }

.subtitle {
  font-size: 14px;
  color: #c9c3d9;
  margin: 0 0 6px;
  line-height: 1.5;
}

.mascot-box {
  width: 120px;
  height: 120px;
  margin: 6px auto;
  filter: drop-shadow(0 0 16px rgba(168,85,247,0.45));
  transition: transform 0.25s ease;
}
.mascot-box.small { width: 64px; height: 64px; flex: none; }
.mascot-box svg, .mascot-box img { width: 100%; height: 100%; display: block; object-fit: contain; image-rendering: pixelated; }
.mascot-box.bounce { animation: bounce 0.5s ease; }
.mascot-box.shake { animation: shake 0.4s ease; }

@keyframes bounce {
  0% { transform: scale(1) translateY(0); }
  30% { transform: scale(1.12) translateY(-8px); }
  60% { transform: scale(0.96) translateY(2px); }
  100% { transform: scale(1) translateY(0); }
}
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-6px) rotate(-3deg); }
  75% { transform: translateX(6px) rotate(3deg); }
}

.name-row {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
}
.study-art {
  width: 72px;
  height: 72px;
  flex: none;
  object-fit: contain;
  image-rendering: pixelated;
  filter: drop-shadow(0 0 8px rgba(168,85,247,0.35));
}
/* Empilha os dois campos (nome e RA) ao lado da arte do Byte. */
.name-fields {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.name-field {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  text-align: left;
  font-size: 12px;
  color: var(--purple-300);
}
.field-req { color: var(--danger); font-style: normal; font-size: 10px; }
.field-opt { color: #8b8398; font-style: normal; font-size: 10px; }
/* Campo obrigatório vazio após tentativa de avançar. */
.name-field input.invalid { border-color: var(--danger); }
.start-error {
  width: 100%;
  margin-top: -4px;
  color: var(--danger);
  font-size: 12px;
  text-align: left;
}
.name-field input {
  width: 100%;
  background: var(--bg-1);
  border: 2px solid var(--purple-700);
  border-radius: 10px;
  padding: 12px 14px;
  color: var(--white);
  font-size: 15px;
  font-family: var(--font-body);
}
.name-field input:focus { outline: none; border-color: var(--purple-500); }

.rules {
  list-style: none;
  padding: 0;
  margin: 8px 0;
  text-align: left;
  width: 100%;
  font-size: 13px;
  color: #d9d3e8;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.rules li { display: flex; align-items: center; gap: 8px; }
.dot { width: 12px; height: 12px; border-radius: 50%; flex: none; box-shadow: 0 0 8px currentColor; }
.dot.common { background: var(--purple-500); color: var(--purple-500); }
.dot.rare { background: var(--purple-300); color: var(--purple-300); }
.dot.junk { background: var(--danger); color: var(--danger); }
.rule-icon { height: 24px; width: auto; max-width: 34px; flex: none; image-rendering: pixelated; }

.btn {
  font-family: var(--font-display);
  font-size: 13px;
  border: none;
  border-radius: 12px;
  padding: 16px 22px;
  cursor: pointer;
  touch-action: manipulation;
  width: 100%;
  margin-top: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}
.btn-primary {
  background: linear-gradient(135deg, var(--purple-500), var(--purple-700));
  color: var(--white);
  box-shadow: 0 6px 0 var(--purple-900), 0 8px 18px rgba(124,58,237,0.4);
}
.btn-primary:active { transform: translateY(4px); box-shadow: 0 2px 0 var(--purple-900); }

.btn-secondary {
  background: var(--bg-1);
  border: 2px solid var(--purple-700);
  color: var(--purple-100);
}
.btn-secondary:active { transform: translateY(2px); }

.btn-ghost {
  background: none;
  border: none;
  color: #a9a2bd;
  font-size: 11px;
  text-decoration: underline;
  padding: 8px;
  box-shadow: none;
}
.btn-ghost:active { opacity: 0.7; }

.best-score { font-size: 12px; color: #a9a2bd; margin-top: 4px; }

/* ---- Tela de seleção de fases ---- */
.levels-panel { max-width: 640px; }
#btn-levels-home { margin-top: 16px; }
.levels-grid {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 12px;
  margin-top: 6px;
}
.level-card {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  background: var(--bg-1);
  border: 2px solid var(--purple-700);
  border-radius: 12px;
  padding: 14px 10px;
  cursor: pointer;
  touch-action: manipulation;
  filter: hue-rotate(var(--level-hue, 0deg));
}
.level-card:active { transform: scale(0.96); }
/* Cartão apontado pelo teclado (setas) ou pelo mouse. O outline não
   desloca o layout do grid como uma borda mais grossa faria. */
.level-card.selected {
  border-color: var(--purple-500);
  outline: 3px solid var(--purple-300);
  outline-offset: 2px;
  background: var(--bg-2);
}
.level-card:focus { outline: none; }
.level-card:focus-visible { outline: 3px solid var(--purple-300); outline-offset: 2px; }

/* Itens navegáveis da tela inicial (arte do título, campo de nome e
   botão). Mesma linguagem visual do grid de fases. */
.title-art-btn.selected .title-art,
#player-name-input.selected,
#btn-start.selected {
  outline: 3px solid var(--purple-300);
  outline-offset: 3px;
}
.title-art-btn:focus, #btn-start:focus { outline: none; }
.title-art-btn:focus-visible .title-art,
#btn-start:focus-visible { outline: 3px solid var(--purple-300); outline-offset: 3px; }
.level-card-num {
  font-family: var(--font-display);
  font-size: 20px;
  color: var(--purple-300);
  text-shadow: 0 0 10px var(--purple-500);
}
.level-card-name { font-size: 12px; color: var(--white); text-align: center; }
.level-card-score { font-size: 10px; color: var(--success); }
.level-card-score.level-card-new { color: #8b8398; }

/* ---- HUD ---- */
.hud { width: 100%; max-width: 720px; margin-top: 6px; }
.hud-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.hud-score { font-family: var(--font-display); font-size: 13px; color: var(--purple-100); }
.hud-actions { display: flex; align-items: center; gap: 8px; }
.icon-btn {
  background: var(--bg-2);
  border: 1px solid var(--purple-700);
  border-radius: 10px;
  width: 38px; height: 38px;
  font-size: 16px;
  color: var(--white);
  cursor: pointer;
  flex: none;
  touch-action: manipulation;
}
.icon-btn:hover { border-color: var(--purple-500); }
.icon-btn.selected { outline: 3px solid var(--purple-300); outline-offset: 2px; }

/* ---- Modal de pausa (reaproveita o fundo escurecido do quiz) ---- */
.pause-card { max-width: 380px; text-align: center; }
.pause-title {
  font-family: var(--font-display);
  font-size: 16px;
  color: var(--purple-100);
  margin: 0 0 6px;
}
.pause-subtitle { font-size: 12px; color: #8b8398; margin-bottom: 18px; }
.pause-actions { display: flex; flex-direction: column; gap: 10px; }
.pause-actions .btn { width: 100%; }

.timer-track {
  margin-top: 10px;
  width: 100%;
  height: 14px;
  background: var(--bg-2);
  border: 1px solid var(--purple-900);
  border-radius: 8px;
  overflow: hidden;
}
.timer-fill {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, var(--purple-500), var(--cyan));
  /* Encolhe por transform (scaleX), não por width: a transição de width
     recalculava o layout e repintava a barra a cada quadro durante a fase
     inteira; transform fica só na composição. O gradiente encolhe junto do
     mesmo jeito, então o visual não muda. */
  transform-origin: left center;
  transition: transform 1s linear, background 0.4s ease;
}
.timer-fill.warn { background: linear-gradient(90deg, var(--gold), var(--purple-500)); }
.timer-fill.danger { background: var(--danger); animation: pulse 0.6s infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.5; } }

.hud-level-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-top: 6px;
}
.hud-level-name {
  font-size: 11px;
  color: var(--purple-300);
  letter-spacing: 0.5px;
}
.hud-repeticoes { font-size: 11px; color: #b7b0c9; white-space: nowrap; }

.hud-sub {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 11px;
  color: #b7b0c9;
  margin-top: 6px;
}
.combo-label { color: var(--purple-300); font-weight: 600; }
.combo-label.hot { color: var(--gold); text-shadow: 0 0 8px var(--gold); }

/* Corações de vida: a arte tem 7x6 "pixels", desenhados a 3px cada — um
   múltiplo inteiro, para a pixel art não borrar. */
.hud-vidas { display: flex; align-items: center; gap: 4px; }
.coracao { display: block; width: 21px; height: 18px; }
.coracao svg { display: block; width: 100%; height: 100%; }
.coracao.perdendo { animation: coracaoPerdido 0.55s ease-out; }
@keyframes coracaoPerdido {
  0% { transform: scale(1); }
  35% { transform: scale(1.6) rotate(-8deg); }
  100% { transform: scale(1); }
}

/* ---- Mascot row ---- */
.mascot-row {
  width: 100%;
  max-width: 720px;
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 10px 0;
}
.speech-bubble {
  flex: 1;
  background: var(--bg-2);
  border: 1px solid var(--purple-700);
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 13px;
  min-height: 18px;
  position: relative;
}
.speech-bubble::before {
  content: '';
  position: absolute;
  left: -8px; top: 18px;
  border: 6px solid transparent;
  border-right-color: var(--purple-700);
}

/* ---- Game viewport / side-scroll camera ---- */
.game-viewport {
  position: relative;
  width: 100%;
  max-width: 900px;
  height: min(52vh, 460px);
  min-height: 260px;
  overflow: hidden;
  border-radius: 14px;
  border: 2px solid var(--purple-700);
  box-shadow: 0 0 30px rgba(124,58,237,0.3), inset 0 0 40px rgba(0,0,0,0.6);
  background: linear-gradient(180deg, #150a24 0%, #0d0817 70%, #050308 100%);
  touch-action: none;
}

/* Cenário de fundo da fase (parallax lento, atrás de tudo). Fica vazio
   nas fases sem arte própria, deixando aparecer o gradiente do viewport.
   O `filter` é definido pelo JS para cancelar o hue-rotate do tema — sem
   isso a arte do fundo sairia com as cores giradas junto com a fase. */
.game-bg {
  position: absolute;
  top: 0; bottom: 0; left: 0;
  /* Mais largo que o viewport de propósito: essa folga é o quanto o fundo
     pode deslizar no parallax sem nunca expor borda vazia. */
  width: 135%;
  z-index: 0;
  background-repeat: no-repeat;
  background-position: center bottom;
  background-size: cover;
  pointer-events: none;
  will-change: transform;
}
/* Escurece o fundo para o cenário e o personagem continuarem legíveis
   por cima da arte. */
.game-bg::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(5,3,8,0.45) 0%, rgba(5,3,8,0.25) 45%, rgba(5,3,8,0.7) 100%);
}

.game-world {
  position: absolute;
  top: 0; left: 0;
  z-index: 1;
  will-change: transform;
  /* Em telas baixas a câmera escala o mundo (updateCamera). O mundo tem a
     largura da fase inteira, então a origem padrão (centro) ficaria no
     meio dela e o cenário deslizaria para o lado — a escala parte do canto. */
  transform-origin: 0 0;
}

.ground {
  /* top vem do JS (= GROUND_Y), alinhado com a física — não usar bottom:0
     aqui, senão a posição vertical depende da altura do container em vez
     da superfície real onde o personagem pisa. */
  position: absolute;
  background: linear-gradient(180deg, #2e1065 0%, #1b0f2e 12%, #150a24 100%);
  border-top: 3px solid var(--purple-500);
  box-shadow: 0 -6px 16px rgba(168,85,247,0.25) inset;
}
.ground::before {
  content: '';
  position: absolute;
  top: 3px; left: 0; right: 0; height: 6px;
  background-image: repeating-linear-gradient(90deg, rgba(103,232,249,0.5) 0 10px, transparent 10px 34px);
}

.pit-hazard {
  /* top vem do JS (= GROUND_Y), mesma lógica do .ground acima. */
  position: absolute;
  height: 10px;
  background: repeating-linear-gradient(135deg, var(--danger) 0 8px, #2e0a0a 8px 16px);
  opacity: 0.75;
}

.platform {
  position: absolute;
  filter: drop-shadow(0 6px 10px rgba(0,0,0,0.5));
}
.platform svg { width: 100%; height: 100%; display: block; }
/* Plataforma móvel: mesma arte, mas com um brilho pulsante para avisar que
   ela desliza — sem isso o jogador só percebe o movimento tarde demais. */
.platform-moving { animation: platformMovingGlow 1.4s ease-in-out infinite; }
@keyframes platformMovingGlow {
  0%, 100% { filter: drop-shadow(0 6px 10px rgba(0,0,0,0.5)) drop-shadow(0 0 4px rgba(103,232,249,0.5)); }
  50% { filter: drop-shadow(0 6px 10px rgba(0,0,0,0.5)) drop-shadow(0 0 12px rgba(103,232,249,0.95)); }
}

.finish-flag {
  position: absolute;
  width: 46px;
  height: 200px;
  filter: drop-shadow(0 0 12px rgba(168,85,247,0.6));
}
.finish-flag svg { width: 100%; height: 100%; display: block; }

.obstacle {
  position: absolute;
  filter: drop-shadow(0 4px 6px rgba(0,0,0,0.5));
}
.obstacle svg { width: 100%; height: 100%; display: block; }

.chest {
  position: absolute;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  filter: drop-shadow(0 0 6px rgba(168,85,247,0.5));
  animation: chestIdle 1.8s ease-in-out infinite;
}
.chest svg { width: 100%; height: 100%; }
@keyframes chestIdle { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-4px); } }

.chest.opening svg { animation: openPop 0.35s ease; }
@keyframes openPop {
  0% { transform: scale(1) rotate(0); }
  40% { transform: scale(1.3) rotate(-5deg); }
  100% { transform: scale(1) rotate(0); }
}

.chest.opened { animation: none; opacity: 0.55; filter: grayscale(0.4) drop-shadow(0 0 4px rgba(168,85,247,0.3)); }
.chest.opened.correct { filter: drop-shadow(0 0 10px var(--success)); opacity: 0.85; }
.chest.opened.wrong { filter: drop-shadow(0 0 10px var(--danger)); opacity: 0.85; }

/* Three nested layers so nothing fights over the `transform` property:
   .player (outer) — position, set every frame via JS, never animated by CSS.
   .player-flip (middle) — static left/right mirror, never animated.
   .player-anim (inner) — celebrate keyframe animation only. The walk/jump
   motion itself now comes from swapping the sprite-sheet frame in JS
   (updateSpriteFrame), not from a CSS bob — real animation frames read as
   more fluid than a single image bouncing on a timer. */
.player {
  position: absolute;
  width: 110px;
  height: 110px;
  will-change: transform;
}
.player-flip, .player-anim { width: 100%; height: 100%; }
.player-anim { position: relative; }
/* Todo o sprite sheet olha para a DIREITA nativamente — espelha o
   personagem inteiro só quando ele está indo para a esquerda. */
.player.facing-left .player-flip { transform: scaleX(-1); }
/* Todos os quadros ficam empilhados e já decodificados; só o `.active`
   aparece. Alternar visibilidade não repinta a imagem (ao contrário de
   trocar o `src`), então a animação não pisca entre um quadro e outro.
   `visibility` em vez de `display:none` mantém as camadas renderizadas
   pela GPU, sem custo de layout a cada troca. */
.player .char-frame {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  visibility: hidden;
  image-rendering: pixelated;
  filter: drop-shadow(0 3px 4px rgba(0,0,0,0.5));
  backface-visibility: hidden;
}
.player .char-frame.active { visibility: visible; }
/* Piscada de "reapareceu depois de cair", como em plataformas retro —
   fica na camada externa (.player) porque essa é a única que nunca tem
   `transform` mexido por CSS, então a animação de opacidade não briga com
   a posição (JS) nem com o espelhamento (.player-flip). */
.player.blinking { animation: respawnBlink 0.12s steps(1, end) infinite; }
@keyframes respawnBlink {
  0%, 49% { opacity: 1; }
  50%, 100% { opacity: 0.15; }
}
.player-anim.celebrate { animation: celebrate 0.5s ease; }
@keyframes celebrate {
  0% { transform: scale(1); }
  40% { transform: scale(1.25) translateY(-6px); }
  100% { transform: scale(1); }
}

/* Moeda que sobe girando ao acertar uma pergunta (spawnCoinEffect) */
.coin-pop {
  width: 40px;
  height: 40px;
  pointer-events: none;
  filter: drop-shadow(0 0 10px rgba(251,191,36,0.8));
  animation: coinPop 0.9s ease-out forwards;
}
.coin-pop svg { width: 100%; height: 100%; display: block; }
@keyframes coinPop {
  0% { opacity: 0; transform: translateY(0) scale(0.4) rotateY(0deg); }
  15% { opacity: 1; transform: translateY(-10px) scale(1.1) rotateY(90deg); }
  60% { opacity: 1; transform: translateY(-46px) scale(1) rotateY(360deg); }
  100% { opacity: 0; transform: translateY(-66px) scale(0.9) rotateY(430deg); }
}

/* ---- Movement controls (mobile touch + desktop click) ---- */
.controls {
  width: 100%;
  max-width: 900px;
  margin: 14px auto 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  user-select: none;
}
.move-pad { display: flex; gap: 28px; }
.ctrl-btn {
  background: var(--bg-2);
  border: 1px solid var(--purple-700);
  border-radius: 12px;
  color: var(--purple-300);
  font-size: 20px;
  cursor: pointer;
  touch-action: none;
  width: 62px;
  height: 62px;
}
.ctrl-btn:active, .ctrl-btn.active { background: var(--purple-700); color: var(--white); }
.ctrl-jump {
  width: 110px;
  height: 62px;
  font-family: var(--font-display);
  font-size: 12px;
  border-color: var(--cyan);
  color: var(--cyan);
}
.ctrl-jump:active, .ctrl-jump.active { background: var(--cyan); color: var(--bg-0); }

.hidden { display: none !important; }

/* ---- Aviso de vidas esgotadas (por cima do cenário, antes do recomeço) ---- */
.vidas-esgotadas {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 16px;
  text-align: center;
  background: rgba(5, 3, 8, 0.72);
  animation: vidasEsgotadasIn 0.25s ease-out;
}
.vidas-esgotadas-titulo {
  font-family: var(--font-display);
  font-size: 16px;
  color: var(--danger);
  text-shadow: 0 0 12px rgba(248, 113, 113, 0.6);
}
.vidas-esgotadas-sub { font-size: 12px; color: var(--purple-100); }
@keyframes vidasEsgotadasIn { from { opacity: 0; } to { opacity: 1; } }

/* ---- Quiz modal ---- */
.quiz-modal {
  position: fixed;
  inset: 0;
  background: rgba(5, 3, 8, 0.82);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 16px;
}
.quiz-card {
  position: relative;
  width: 100%;
  max-width: 480px;
  max-height: 92vh;
  overflow-y: auto;
  overflow-x: hidden;
  background: linear-gradient(160deg, var(--bg-2), var(--bg-1));
  border: 2px solid var(--purple-700);
  border-radius: 16px;
  box-shadow: 0 0 40px rgba(124,58,237,0.4);
  padding: 18px;
}
.quiz-coin-layer {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 64px;
  display: flex;
  justify-content: center;
  pointer-events: none;
  z-index: 5;
}
.quiz-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
}
.quiz-byte-icon {
  width: 36px;
  height: 36px;
  object-fit: cover;
  border-radius: 50%;
  border: 2px solid var(--purple-500);
  background: var(--bg-1);
  image-rendering: pixelated;
  flex: none;
  margin-right: auto;
}
.quiz-progress {
  font-family: var(--font-display);
  font-size: 11px;
  color: var(--purple-300);
}
.quiz-context {
  margin-bottom: 14px;
  background: var(--bg-1);
  border: 1px solid var(--purple-900);
  border-radius: 10px;
  padding: 12px 14px;
  max-height: 48vh;
  overflow-y: auto;
  overflow-x: hidden;
}
.quiz-context-label {
  font-family: var(--font-display);
  font-size: 11px;
  color: var(--purple-300);
  margin-bottom: 8px;
  letter-spacing: 0.5px;
}
.quiz-context-body {
  font-size: 14px;
  line-height: 1.6;
  color: var(--white);
  white-space: pre-line;
  overflow-wrap: anywhere;
  word-break: break-word;
}
.quiz-question {
  font-size: 16px;
  font-weight: 600;
  line-height: 1.4;
  margin-bottom: 14px;
  overflow-wrap: anywhere;
  word-break: break-word;
}
.quiz-pager {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  margin-top: 4px;
  margin-bottom: 10px;
}
.quiz-page-btn {
  width: auto;
  flex: 1 1 120px;
  min-width: 0;
  max-width: 100%;
  padding: 8px 12px;
  font-size: 12px;
  margin-top: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.quiz-page-dots {
  font-family: var(--font-display);
  font-size: 10px;
  color: var(--purple-300);
  flex: 1 0 100%;
  order: 3;
  text-align: center;
}
.quiz-choices {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.quiz-choice {
  text-align: left;
  background: var(--bg-1);
  border: 2px solid var(--purple-900);
  border-radius: 10px;
  padding: 12px 14px;
  color: var(--white);
  font-size: 14px;
  font-family: var(--font-body);
  cursor: pointer;
  touch-action: manipulation;
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
}
.quiz-choice > span:last-child {
  min-width: 0;
  overflow-wrap: anywhere;
  word-break: break-word;
}
.quiz-choice:hover:not(:disabled) { border-color: var(--purple-500); }
/* Alternativa apontada pelo teclado (▲▼) ou pelo mouse. O outline extra
   deixa o destaque legível mesmo quando a borda já está colorida, e o
   `outline` não desloca o layout como uma borda mais grossa faria. */
.quiz-choice.selected:not(:disabled) {
  border-color: var(--purple-500);
  outline: 2px solid var(--purple-300);
  outline-offset: 2px;
  background: var(--bg-2);
}
/* O foco nativo já é comunicado pela classe .selected acima. */
.quiz-choice:focus { outline: none; }
.quiz-choice:focus-visible { outline: 2px solid var(--purple-300); outline-offset: 2px; }
.quiz-choice .choice-letter {
  font-family: var(--font-display);
  font-size: 11px;
  color: var(--purple-300);
  flex: none;
}
.quiz-choice.choice-selected-correct { background: rgba(74,222,128,0.15); border-color: var(--success); }
.quiz-choice.choice-selected-wrong { background: rgba(248,113,113,0.15); border-color: var(--danger); }
.quiz-choice:disabled { cursor: default; opacity: 0.85; }

.quiz-feedback {
  margin-top: 12px;
  font-size: 13px;
  min-height: 18px;
  color: var(--purple-100);
}
.quiz-continue { margin-top: 6px; }

/* ---- End screen ---- */
.end-player-name { font-size: 12px; color: #a9a2bd; margin-top: -4px; }
.end-player-ra { font-size: 11px; color: #8b8398; letter-spacing: 0.5px; }
/* Botão apontado pelo teclado na tela de resultados. */
.btn.selected { outline: 3px solid var(--purple-300); outline-offset: 3px; }
.btn:focus { outline: none; }
.btn:focus-visible { outline: 3px solid var(--purple-300); outline-offset: 3px; }
.end-levelup-banner {
  width: 190px;
  image-rendering: pixelated;
  filter: drop-shadow(0 0 14px rgba(168,85,247,0.6));
  animation: levelUpPop 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes levelUpPop {
  0% { opacity: 0; transform: scale(0.5) rotate(-8deg); }
  100% { opacity: 1; transform: scale(1) rotate(0deg); }
}
.end-score { margin: 8px 0; }
.end-score-value {
  font-family: var(--font-display);
  font-size: 40px;
  color: var(--purple-300);
  text-shadow: 0 0 16px var(--purple-500);
}
.end-score-label { font-size: 12px; color: #b7b0c9; letter-spacing: 2px; }
.new-record {
  font-family: var(--font-display);
  font-size: 12px;
  color: var(--gold);
  text-shadow: 0 0 10px var(--gold);
}
.end-tier {
  font-family: var(--font-display);
  font-size: 15px;
  line-height: 1.5;
}
.end-tier.tier-retry { color: var(--danger); text-shadow: 0 0 10px rgba(248,113,113,0.5); }
.end-tier.tier-okay { color: var(--gold); text-shadow: 0 0 10px rgba(251,191,36,0.5); }
.end-tier.tier-great { color: var(--success); text-shadow: 0 0 10px rgba(74,222,128,0.5); }
.end-tier-msg { font-size: 13px; color: #d9d3e8; margin-top: -4px; }

.end-stats {
  width: 100%;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  font-size: 12px;
  color: #d9d3e8;
  background: var(--bg-1);
  border-radius: 10px;
  padding: 10px;
  margin: 6px 0;
}
.end-stats div { display: flex; justify-content: space-between; }
/* Colunas do resultado: só viram colunas em paisagem (ver o fim do arquivo). */
.end-col { display: contents; }

/* ---- Responsive ---- */
@media (min-width: 720px) {
  .game-viewport { height: min(58vh, 520px); }
}
@media (max-width: 380px) {
  .panel h1 { font-size: 14px; }
  .ctrl-btn { width: 52px; height: 52px; font-size: 17px; }
  .ctrl-jump { width: 92px; height: 52px; font-size: 11px; }
  .quiz-question { font-size: 15px; }
  .quiz-context-body { font-size: 13px; }
  .quiz-page-dots { font-size: 9px; }
  .coracao { width: 14px; height: 12px; } /* 2px por pixel da arte */
}

/* ---- Celular deitado (paisagem) ----
   Com 320–430px de altura, a pilha vertical do retrato (HUD, mascote,
   cenário e controles) passava de 500px: a página rolava e os controles
   ficavam abaixo da tela. Aqui a tela do jogo vira uma grade que ocupa
   exatamente a altura disponível — HUD em duas linhas, fala numa linha
   só e controles nas laterais do cenário, que fica com toda a altura que
   sobra (e o updateCamera escala o mundo se ela for menor que a faixa de
   jogo). O `max-height` separa celular de tablet e desktop, que continuam
   no layout normal mesmo com a tela mais larga que alta. */
@media (orientation: landscape) and (max-height: 500px) {
  #app {
    padding:
      max(6px, env(safe-area-inset-top))
      max(10px, env(safe-area-inset-right))
      max(6px, env(safe-area-inset-bottom))
      max(10px, env(safe-area-inset-left));
  }
  .screen { max-width: 960px; }

  /* -- Tela do jogo -- */
  #screen-game.active {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    grid-template-rows: auto auto minmax(0, 1fr);
    grid-template-areas:
      "hud  hud  hud"
      "fala fala fala"
      "esq  jogo dir";
    column-gap: 10px;
    row-gap: 6px;
    align-items: stretch; /* o .screen.active centraliza; o cenário precisa esticar */
    max-width: none;
    /* Altura exata da tela menos o respiro do #app, para nada rolar. O `vh`
       é o fallback para navegadores sem `dvh` (que desconta a barra do
       navegador). */
    height: calc(100vh - max(6px, env(safe-area-inset-top)) - max(6px, env(safe-area-inset-bottom)));
    height: calc(100dvh - max(6px, env(safe-area-inset-top)) - max(6px, env(safe-area-inset-bottom)));
  }

  /* HUD em duas linhas: as divs de agrupamento somem (display: contents)
     e cada item vai direto para a sua célula da grade. */
  .hud {
    grid-area: hud;
    max-width: none;
    margin-top: 0;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto auto auto;
    grid-template-areas:
      "logo  nome  rep   pontos acoes"
      "combo tempo vidas perg   perg";
    align-items: center;
    column-gap: 12px;
    row-gap: 4px;
  }
  .hud-top, .hud-level-row, .hud-sub { display: contents; }
  .hud-logo { grid-area: logo; }
  .hud-badge { height: 22px; }
  .hud-level-name {
    grid-area: nome;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .hud-repeticoes { grid-area: rep; justify-self: center; }
  .hud-score { grid-area: pontos; justify-self: end; font-size: 11px; }
  .hud-actions { grid-area: acoes; }
  .icon-btn { width: 32px; height: 32px; font-size: 14px; }
  .combo-label { grid-area: combo; white-space: nowrap; }
  .timer-track { grid-area: tempo; margin-top: 0; height: 10px; }
  .hud-vidas { grid-area: vidas; justify-self: center; }
  #chests-left-label { grid-area: perg; justify-self: end; white-space: nowrap; }
  .coracao { width: 14px; height: 12px; } /* 2px por pixel da arte */

  /* Fala do mascote numa linha só */
  .mascot-row { grid-area: fala; max-width: none; margin: 0; gap: 8px; }
  .mascot-box.small { width: 28px; height: 28px; margin: 0; }
  .speech-bubble {
    padding: 4px 10px;
    font-size: 12px;
    min-height: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .speech-bubble::before { display: none; } /* a seta ficaria cortada pelo overflow */

  .game-viewport { grid-area: jogo; height: auto; min-height: 0; max-width: none; }

  /* Controles nas laterais do cenário, na altura dos polegares — assim
     não tampam o chão nem os buracos que vêm pela frente. */
  .controls { display: contents; }
  .move-pad { grid-area: esq; align-self: end; gap: 10px; }
  #btn-jump { grid-area: dir; align-self: end; }
  .ctrl-btn { width: 56px; height: 56px; font-size: 18px; }
  .ctrl-jump { width: 88px; height: 72px; font-size: 11px; }

  /* -- Tela inicial: arte e regras à esquerda, cadastro e botão à direita.
     Assim o "Escolher Fase" fica no alto da coluna da direita, visível sem
     rolar mesmo nos celulares mais baixos; no pior caso só o fim das
     regras pede rolagem. -- */
  .start-panel {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    column-gap: 18px;
    row-gap: 8px;
    align-items: start;
    max-width: 900px;
    padding: 10px 16px 12px;
  }
  #btn-start-art { grid-column: 1; grid-row: 1; }
  .rules { grid-column: 1; grid-row: 2 / span 4; margin: 0; font-size: 11px; gap: 3px; }
  .name-row, #start-error, #btn-start, .best-score { grid-column: 2; }
  .study-art { width: 48px; height: 48px; }
  .name-fields { gap: 6px; }
  .name-field input { padding: 8px 12px; }
  .start-panel .btn { margin-top: 0; padding: 12px 16px; }

  /* -- Seleção de fases: as 10 fases em duas linhas de cinco -- */
  .levels-panel { max-width: 900px; padding: 8px 16px 10px; gap: 4px; }
  .logo { margin-top: 0; }
  .levels-panel .logo-badge { height: 24px; }
  .levels-panel h1 { margin: 0; font-size: 14px; }
  .levels-panel .subtitle { display: none; }
  .levels-grid { grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 6px; margin-top: 0; }
  .level-card { padding: 6px 4px; gap: 2px; }
  .level-card-num { font-size: 16px; }
  .level-card-name { font-size: 11px; }
  .levels-panel .btn { margin-top: 2px; padding: 8px 16px; }
  #btn-levels-home { margin-top: 0; padding: 4px; }

  /* -- Resultado: resumo à esquerda, avaliação e botões à direita -- */
  .end-panel {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    column-gap: 20px;
    align-items: center;
    max-width: 900px;
    padding: 8px 18px;
  }
  .end-col { display: flex; flex-direction: column; align-items: center; gap: 6px; min-width: 0; }
  .end-panel h1 { margin: 0; font-size: 14px; }
  .end-levelup-banner { width: 88px; }
  #mascot-end { width: 72px; height: 72px; margin: 0; }
  .end-score { margin: 0; }
  .end-score-value { font-size: 28px; }
  .end-panel .btn { margin-top: 2px; padding: 11px 16px; }

  /* -- Pergunta e pausa: cartão mais largo, preso à altura da tela -- */
  .quiz-modal {
    padding:
      8px
      max(8px, env(safe-area-inset-right))
      8px
      max(8px, env(safe-area-inset-left));
  }
  .quiz-card {
    max-width: 760px;
    max-height: calc(100vh - 16px);
    max-height: calc(100dvh - 16px);
    padding: 12px 16px;
  }
  /* O cartão já rola; um texto de apoio com rolagem própria dentro dele
     criaria duas áreas de rolagem aninhadas numa tela de 360px. */
  .quiz-context { max-height: none; overflow: visible; margin-bottom: 10px; }
  .quiz-question { font-size: 15px; margin-bottom: 10px; }
  .quiz-choices { gap: 6px; }
  .quiz-choice { padding: 8px 12px; font-size: 13px; }
  .quiz-feedback { margin-top: 8px; }

  .pause-card { max-width: 520px; }
  .pause-subtitle { margin-bottom: 10px; }
  .pause-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
  .pause-actions .btn { margin-top: 0; padding: 12px; }
}
