:root {
  --caixa: #f8f8f0;
  --borda: #3a4038;
  --tinta: #22261f;
  --apagado: #7a7f72;
  --vermelho: #d84040;
  --laranja: #f8a030;
  --verde: #58b858;
  --amarelo: #f8e858;
}

html, body {
  margin: 0;
  height: 100%;
  background: #0c120c;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-family: "Avenir Next", system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--tinta);
}

#stage {
  position: relative;
  width: min(96vw, 152vh);
  aspect-ratio: 16 / 10;
  border: 4px solid #26362a;
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 0 60px rgba(0, 0, 0, 0.85);
}

#tela3d { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#ui { position: absolute; inset: 0; pointer-events: none; }
#ui > * { pointer-events: auto; }
.oculto { display: none !important; }

/* micro-transições: painéis entram com fade curto em vez de corte seco */
@keyframes painel-entra {
  from { opacity: 0; transform: translateY(5px); }
}
#menu:not(.oculto), #msg:not(.oculto), #painel-acao:not(.oculto) {
  animation: painel-entra 0.13s ease-out;
}
.msg-lista li { transition: background 0.18s ease, color 0.18s ease; }
.scroll { overflow-y: auto; }

.controles {
  color: #5e7a5e;
  font-size: 13px;
  margin-top: 10px;
  text-align: center;
}

/* ---------- HUD ---------- */
.hud {
  position: absolute;
  top: 1.2%;
  width: 27%;
  min-width: 190px;
  background: var(--caixa);
  border: 3px solid var(--borda);
  border-radius: 10px;
  padding: 8px 10px;
  box-shadow: 2px 3px 0 rgba(0, 0, 0, 0.35);
  display: flex; align-items: center; gap: 9px;
}
.hud-avatar {
  width: 46px; height: 46px; flex: none;
  border-radius: 50%; border: 2px solid var(--borda);
  object-fit: cover; background: #dce4f0;
}
.hud-info { flex: 1; min-width: 0; }
.hud-estilo {
  font-size: 10px; font-weight: 800; letter-spacing: 0.06em;
  color: var(--apagado);
}
#hud-p1 { left: 1.2%; }
#hud-p2 { right: 1.2%; }
.hud-nome { font-weight: 800; letter-spacing: 0.04em; font-size: clamp(13px, 1.9vh, 17px); }
.hud-pontos { font-size: clamp(12px, 1.8vh, 16px); margin: 2px 0 4px; }
.hud-folego { display: flex; align-items: center; gap: 8px; font-size: 11px; font-weight: 700; color: var(--apagado); }
.barra { flex: 1; height: 9px; background: #d8d8cc; border-radius: 5px; overflow: hidden; border: 1px solid #b8b8aa; }
.barra i { display: block; height: 100%; border-radius: 4px; transition: width 0.25s; }
.barra i.ok { background: var(--verde); }
.barra i.medio { background: var(--laranja); }
.barra i.critico { background: var(--vermelho); animation: pisca 0.6s infinite; }
@keyframes pisca { 50% { opacity: 0.35; } }

#turno {
  position: absolute; top: 1.6%; left: 50%; transform: translateX(-50%);
  color: #e8f0dc; font-weight: 700; font-size: clamp(12px, 1.8vh, 15px);
  text-shadow: 0 2px 4px rgba(0,0,0,.6); letter-spacing: 0.06em;
}
#rotulo-posicao {
  position: absolute; bottom: 29%; left: 50%; transform: translateX(-50%);
  background: rgba(10, 20, 10, 0.65); color: #f4f8ea;
  padding: 4px 14px; border-radius: 14px;
  font-weight: 800; font-size: clamp(13px, 2vh, 17px); letter-spacing: 0.05em;
}

#toast-pontos {
  position: absolute; top: 16%; left: 50%; transform: translateX(-50%) scale(0.8);
  background: var(--amarelo); color: #3a3208; border: 3px solid #8a7a10;
  padding: 6px 18px; border-radius: 12px;
  font-weight: 800; font-size: clamp(15px, 2.6vh, 22px);
  opacity: 0; transition: opacity 0.25s, transform 0.25s; pointer-events: none !important;
}
#toast-pontos.ativo { opacity: 1; transform: translateX(-50%) scale(1); }

#flash {
  position: absolute; inset: 0; opacity: 0; pointer-events: none !important;
  transition: opacity 0.12s;
}
#flash.ativo { opacity: 0.45; }

/* ---------- caixa inferior ---------- */
#caixa {
  position: absolute; left: 1%; right: 1%; bottom: 1.2%; height: 26.5%;
}
#menu, #msg, #painel-acao {
  position: absolute; inset: 0;
  background: var(--caixa);
  border: 3px solid var(--borda);
  border-radius: 12px;
  padding: 10px 16px;
  box-shadow: 2px 3px 0 rgba(0, 0, 0, 0.35);
  font-size: clamp(14px, 2.2vh, 18px);
}

.menu-recap {
  color: var(--apagado); font-weight: 700; font-size: 0.75em;
  border-bottom: 2px solid #d8d8cc; margin-bottom: 5px; padding-bottom: 3px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* menu 2x2 estilo Pokémon: duas opções em cima, duas embaixo */
.menu-grade {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px 18px;
}

.menu-item {
  display: flex; align-items: center; gap: 8px;
  padding: 4px 8px; border-radius: 8px; cursor: pointer;
  font-weight: 700; line-height: 1.3;
}
.menu-item .cursor { visibility: hidden; font-size: 0.8em; }
.menu-item.sel { background: #e4e8d2; }
.menu-item.sel .cursor { visibility: visible; }
.menu-item.sem-folego { color: #b0b0a2; }
.menu-item .custo { margin-left: auto; font-weight: 600; color: var(--apagado); font-size: 0.85em; }
.menu-item.sem-folego .custo { color: var(--vermelho); }
.menu-dica { margin-top: 4px; color: var(--apagado); font-size: 0.78em; font-weight: 600; }
.menu-dica .alerta { color: var(--vermelho); }

.msg-titulo { font-weight: 800; margin-bottom: 4px; }
.msg-passos { line-height: 1.45; }
.msg-lista { margin: 4px 0 4px 22px; padding: 0; line-height: 1.4; }
.msg-lista li { margin: 2px 0; padding: 1px 6px; border-radius: 6px; }
.msg-lista li.ativo {
  background: var(--amarelo);
  font-weight: 700;
  box-shadow: 0 0 0 2px #8a7a10 inset;
}
.acao-extra { color: var(--vermelho); font-weight: 700; font-size: 0.9em; }
.acao-resultado { font-weight: 700; margin: 6px 0 2px; line-height: 1.4; }
.acao-passos summary {
  cursor: pointer; color: var(--apagado); font-weight: 600; font-size: 0.8em;
}
.chip-pontos {
  display: inline-block; margin-top: 6px; padding: 2px 12px;
  background: var(--amarelo); border: 2px solid #8a7a10; border-radius: 10px;
  font-weight: 800; font-size: 0.9em;
}
.msg-avancar { margin-top: 6px; color: var(--apagado); font-size: 0.75em; animation: pisca 1.2s infinite; }

.passo-rotulo {
  display: inline-block; margin: 2px 0;
  font-size: 0.68em; font-weight: 800; letter-spacing: 0.08em;
  color: #8a7a10;
}
.passo-rotulo:empty { display: none; }

/* ficha estruturada do resultado: técnica · posição · chance · fôlego · pontos */
.ficha {
  display: grid; grid-template-columns: auto 1fr; gap: 1px 12px;
  margin: 8px 0 2px; padding: 8px 12px;
  background: #eef0e2; border: 2px solid #d8d8cc; border-radius: 10px;
  font-size: 0.72em; line-height: 1.5;
}
.ficha-k { font-weight: 800; letter-spacing: 0.06em; color: var(--apagado); }
.ficha-v { font-weight: 600; }

.replay-ops { display: flex; gap: 14px; margin-top: 8px; }
.replay-ops button {
  font: inherit; font-weight: 800; cursor: pointer;
  background: #fff; color: var(--tinta);
  border: 3px solid var(--borda); border-radius: 10px; padding: 8px 18px;
}
.replay-ops button.sel { background: #e4e8d2; box-shadow: 0 0 0 3px var(--amarelo); }
.replay-ops small { font-weight: 600; color: var(--apagado); }

/* ---------- overlay INFO ---------- */
.painel {
  position: absolute; left: 12%; right: 12%; top: 10%; bottom: 32%;
  background: var(--caixa); border: 3px solid var(--borda); border-radius: 14px;
  padding: 16px 22px; box-shadow: 4px 6px 0 rgba(0, 0, 0, 0.4);
  font-size: clamp(14px, 2.1vh, 18px);
}
.painel h2 { margin: 0 0 8px; font-size: 1.3em; }
.info-meta { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.tag {
  background: #e4e8d2; border: 2px solid var(--borda); border-radius: 10px;
  padding: 1px 10px; font-weight: 700; font-size: 0.75em;
}
.tag.pontos { background: var(--amarelo); }
.tag.finaliza { background: #f0c8c8; }
.info-fonte { font-size: 0.85em; color: #444a3e; line-height: 1.5; margin-bottom: 10px; word-break: break-all; }
.info-passos { line-height: 1.5; }
.info-fechar { margin-top: 12px; color: var(--apagado); font-size: 0.75em; font-weight: 600; }

/* ---------- telas ---------- */
.tela {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: rgba(8, 14, 8, 0.55);
}
.titulo-bloco, .selecao-bloco, .fim-bloco {
  background: var(--caixa); border: 4px solid var(--borda); border-radius: 16px;
  padding: 26px 40px; text-align: center; max-width: 72%;
  box-shadow: 6px 8px 0 rgba(0, 0, 0, 0.45);
}
.titulo-bloco h1 { margin: 0; font-size: clamp(30px, 6vh, 52px); letter-spacing: 0.1em; }
.titulo-mascotes { display: flex; align-items: center; justify-content: center; gap: 18px; }
.mascote { width: clamp(64px, 13vh, 110px); height: auto; }
.mascote-aluno { border-radius: 50%; border: 3px solid var(--borda); width: clamp(56px, 11.5vh, 96px); aspect-ratio: 1; object-fit: cover; }
.tela .sub { color: var(--apagado); font-weight: 700; margin: 4px 0 14px; }
.piscar { font-weight: 800; animation: pisca 1.1s infinite; }
.rodape { color: var(--apagado); font-size: 0.8em; }

.selecao-bloco h2 { margin: 0 0 12px; }
.card-arq {
  display: flex; align-items: center; gap: 12px;
  border: 3px solid var(--borda); border-radius: 12px;
  padding: 8px 14px; margin: 8px 0; cursor: pointer; text-align: left;
}
.card-arq.sel { background: #e4e8d2; box-shadow: 0 0 0 3px var(--amarelo); }
.card-arq .swatch {
  width: 30px; height: 30px; border-radius: 8px; border: 2px solid var(--borda);
  flex: none;
}
.card-main b { font-size: 1.05em; letter-spacing: 0.04em; }
.card-main small { display: block; color: var(--apagado); font-weight: 600; }
.selecao-bloco .desc { min-height: 2.4em; margin: 10px 0 4px; }

.sumula { margin: 0 auto 14px; border-collapse: collapse; }
.sumula th, .sumula td { padding: 4px 18px; border-bottom: 2px solid #d8d8cc; }
.sumula th { font-size: 0.8em; letter-spacing: 0.08em; color: var(--apagado); }
.sumula td:first-child { text-align: left; font-weight: 700; }

/* ---------- celular / toque ---------- */

/* botões de toque (C = aula, X = voltar): só aparecem em tela de toque */
#botoes-touch { display: none; }

@media (hover: none) and (pointer: coarse) {
  .controles { display: none; } /* dicas de teclado não fazem sentido no toque */
  #botoes-touch {
    display: flex; flex-direction: column; gap: 8px;
    position: absolute; right: 1.5%; top: 13%;
  }
  #botoes-touch button {
    font: inherit; font-weight: 800; font-size: 13px;
    background: rgba(248, 248, 240, 0.92); color: var(--tinta);
    border: 2px solid var(--borda); border-radius: 10px;
    padding: 8px 10px; min-width: 44px; min-height: 40px;
    box-shadow: 2px 2px 0 rgba(0, 0, 0, 0.3);
  }
  .menu-item { min-height: 44px; } /* alvo de toque confortável */
  .replay-ops button { min-height: 44px; }
  .card-arq { min-height: 48px; }
}

/* retrato estreito: o palco vira tela cheia e a UI se reorganiza */
@media (orientation: portrait) and (max-width: 760px) {
  html, body { overflow: hidden; }
  body {
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
  }
  #stage {
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    aspect-ratio: auto;
    border: none; border-radius: 0; box-shadow: none;
  }
  .hud { width: 42%; min-width: 0; padding: 4px 6px; border-width: 2px; gap: 6px; }
  .hud-avatar { width: 34px; height: 34px; }
  .hud-estilo { font-size: 8px; }
  .hud-nome { font-size: 11px; }
  .hud-pontos { font-size: 11px; }
  .hud-folego { font-size: 9px; gap: 5px; }
  #turno { top: 8.5%; font-size: 11px; } /* abaixo dos HUDs, não por cima */
  #caixa { height: 31%; left: 1.5%; right: 1.5%; bottom: 1%; }
  #menu, #msg, #painel-acao { padding: 8px 10px; font-size: 14px; }
  .menu-grade { gap: 2px 8px; }
  #rotulo-posicao { bottom: 33.5%; font-size: 12px; padding: 3px 10px; }
  #toast-pontos { top: 11%; font-size: 15px; }
  .painel { left: 3%; right: 3%; top: 7%; bottom: 34%; padding: 12px 14px; font-size: 14px; }
  .titulo-bloco, .selecao-bloco, .fim-bloco { max-width: 92%; padding: 18px 16px; }
  .titulo-bloco h1 { font-size: 32px; }
  .sumula th, .sumula td { padding: 4px 8px; }
  .replay-ops { gap: 8px; flex-wrap: wrap; }
  .replay-ops button { padding: 8px 12px; }
}
