:root {
  --vh: 100vh;
  --fundo: #0b1a2b;
  --papel: #f4efe6;
  --tinta: #1a1a1a;
  --verde: #009c3b;
  --amarelo: #ffdf00;
  --vermelho: #c0392b;
  --azul: #1f4e8c;
}
@supports (height: 100dvh) { :root { --vh: 100dvh; } }
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--fundo); color: var(--papel); font-family: ui-monospace, Menlo, Consolas, monospace; overflow: hidden; overscroll-behavior: none; }
button { font: inherit; cursor: pointer; }

/* canvas 16:9 centralizado */
#jogo {
  position: fixed; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: min(100vw, calc(var(--vh) * 16 / 9)); height: min(56.25vw, var(--vh));
  background: #000; touch-action: none;
}

/* HUD em HTML (texto nítido) sobre a área do canvas */
#hud {
  position: fixed; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: min(100vw, calc(var(--vh) * 16 / 9)); height: min(56.25vw, var(--vh));
  pointer-events: none; font-size: clamp(11px, 1.8vh, 16px); text-transform: uppercase; letter-spacing: 1px;
  text-shadow: 2px 2px 0 #000;
}
#hud-fase { position: absolute; top: 4%; right: 3%; }
#hud-esp { position: absolute; top: 13%; left: 1.5%; color: var(--amarelo); }
#hud-onda { position: absolute; top: 12%; right: 3%; color: var(--amarelo); }
#hud-chefe { position: absolute; top: 4%; left: 50%; transform: translateX(-50%); color: var(--vermelho); }
#hud-fala { position: absolute; top: 20%; left: 50%; transform: translateX(-50%); width: 80%; text-align: center; text-transform: none; letter-spacing: 0; font-size: clamp(13px, 2.4vh, 18px); background: rgba(0,0,0,.6); padding: .4em .8em; border: 2px solid var(--papel); }
#hud-nomes div { position: absolute; transform: translateX(-50%); font-size: .75em; letter-spacing: 0; text-transform: none; color: #fff; white-space: nowrap; }
#hud-nomes div.chefe { color: var(--amarelo); font-weight: bold; }
#hud-nomes div.balao { background: #fff; color: #000; padding: 2px 6px; border: 2px solid #000; border-radius: 6px; font-weight: bold; font-size: .8em; }
#hud-nomes div.balao::after { content: ''; position: absolute; left: 50%; bottom: -8px; margin-left: -4px; border: 4px solid transparent; border-top-color: #000; }
#hud-aviso { position: absolute; top: 40%; left: 50%; transform: translateX(-50%); font-size: clamp(16px, 4vh, 40px); color: var(--amarelo); text-shadow: 3px 3px 0 #000; }

/* telas HTML por cima do canvas */
section[data-tela] {
  position: fixed; inset: 0; overflow-y: auto; -webkit-overflow-scrolling: touch;
  display: flex; flex-direction: column; align-items: center; justify-content: flex-start; overscroll-behavior: contain;
  padding: 24px 16px; gap: 12px; text-align: center; background: rgba(11, 26, 43, .92);
}
section[data-tela]::before, section[data-tela]::after { content: ""; margin: auto; }
section[data-tela="titulo"] { background: rgba(11, 26, 43, .55); }
[hidden] { display: none !important; }

h1 { font-size: clamp(28px, 7vw, 64px); line-height: 1.05; margin: 0; text-transform: uppercase; color: var(--amarelo); text-shadow: 4px 4px 0 var(--verde), 8px 8px 0 #000; }
h2 { font-size: clamp(20px, 4vw, 36px); margin: 0; text-transform: uppercase; color: var(--amarelo); text-shadow: 3px 3px 0 #000; }
h3 { font-size: clamp(14px, 2.5vw, 20px); margin: 12px 0 0; text-transform: uppercase; color: var(--verde); }
.sub { margin: 0; opacity: .9; }
.acoes { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }
button { min-height: 48px; padding: 12px 22px; border: 3px solid #000; background: var(--amarelo); color: #000; text-transform: uppercase; letter-spacing: 1px; box-shadow: 4px 4px 0 #000; }
button:active { transform: translate(2px, 2px); box-shadow: 2px 2px 0 #000; }
button.sec { background: var(--papel); }
footer { font-size: 11px; opacity: .7; max-width: 60ch; line-height: 1.4; }

/* seleção */
.sel { display: flex; gap: 20px; align-items: flex-start; flex-wrap: wrap; justify-content: center; }
.preview-wrap { background: #223; border: 3px solid #000; padding: 8px; }
#preview { width: 120px; height: 200px; display: block; }
.grupos { display: flex; flex-direction: column; gap: 8px; max-width: 520px; }
.grupo { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; }
.opcao { min-height: 36px; padding: 6px 10px; font-size: 12px; background: var(--papel); box-shadow: 3px 3px 0 #000; }
.opcao.ativa { background: var(--verde); color: #fff; }
.opcao.pele { width: 36px; padding: 0; }
blockquote { margin: 8px 0 0; font-style: italic; max-width: 50ch; color: var(--papel); }
.cite { margin: 0; font-size: 14px; opacity: .9; max-width: 50ch; line-height: 1.4; }
a { color: var(--amarelo); }

.prologo { display: flex; gap: 20px; align-items: center; flex-wrap: wrap; justify-content: center; max-width: 720px; }
#lula { width: 144px; height: 144px; display: block; }
#prologo-frases { max-width: 46ch; text-align: left; }
#prologo-frases blockquote { margin: 0 0 10px; font-size: clamp(13px, 1.6vw, 16px); }
#prologo-frases a { font-size: 12px; font-style: normal; }

#comandos { border-collapse: collapse; font-size: clamp(13px, 1.8vw, 18px); }
#comandos td { padding: 6px 14px; text-align: left; }
#comandos td:first-child { color: var(--amarelo); font-weight: bold; text-align: right; }
.tecla { display: inline-block; min-width: 1.6em; padding: 2px 8px; margin: 0 2px; background: var(--papel); color: #000; border: 2px solid #000; box-shadow: 2px 2px 0 #000; text-align: center; font-weight: bold; }
.piscar { margin-top: 10px; color: var(--amarelo); font-weight: bold; animation: piscar 1s steps(2) infinite; }
@keyframes piscar { 50% { opacity: 0; } }

/* arquivo */
.selo { display: inline-block; padding: 6px 12px; border: 3px solid var(--vermelho); color: var(--vermelho); font-weight: bold; letter-spacing: 1px; background: #fff; transform: rotate(-3deg); }
#arq-fatos, #final-panorama { max-width: 60ch; text-align: left; padding-left: 1.2em; line-height: 1.5; margin: 0; }
#arq-fatos li, #final-panorama li { margin-bottom: 8px; }
.fontes { max-width: 70ch; text-align: left; font-size: 11px; line-height: 1.5; padding-left: 1.2em; margin: 0; word-break: break-all; }
.aviso { max-width: 60ch; font-size: 12px; line-height: 1.5; border: 2px dashed var(--amarelo); padding: 10px; }

/* touch */
#touch { position: fixed; inset: 0; pointer-events: none; touch-action: none; }
#touch, #touch * { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent; }
#dpad { position: absolute; left: 16px; bottom: 16px; width: 140px; height: 140px; border-radius: 50%; background: rgba(255,255,255,.15); border: 3px solid rgba(255,255,255,.4); pointer-events: auto; }
#dpad::before { content: ""; position: absolute; left: 50%; top: 50%; width: 50px; height: 50px; transform: translate(-50%,-50%); border-radius: 50%; background: rgba(255,255,255,.3); }
#touch .botoes { position: absolute; right: 16px; bottom: 24px; display: flex; gap: 12px; align-items: flex-end; pointer-events: auto; }
#touch .botoes button { width: 64px; height: 64px; border-radius: 50%; padding: 0; min-height: 0; font-size: 20px; opacity: .85; touch-action: none; }
#touch .botoes button:nth-child(1) { background: var(--papel); }
#touch .botoes button:nth-child(2) { background: var(--verde); color: #fff; margin-bottom: 30px; }
#touch .botoes button:nth-child(3) { background: var(--amarelo); }

#idiomas { position: fixed; top: 8px; right: 8px; z-index: 6; display: flex; gap: 4px; }
#idiomas button { min-height: 0; padding: 4px 8px; font-size: 12px; background: var(--papel); box-shadow: 2px 2px 0 #000; opacity: .85; }
#idiomas button.ativa { background: var(--amarelo); opacity: 1; }
#retrato { position: fixed; top: 8px; left: 50%; transform: translateX(-50%); background: var(--amarelo); color: #000; padding: 6px 12px; border: 3px solid #000; font-weight: bold; z-index: 5; }
