:root {
  --ink: #1a1a2e; --night: #1f2d52; --night2: #2f4374; --paper: #fff8e7; --sand: #f2e3c2;
  --gold: #f2b53a; --blue: #2f6fb5; --green: #3f8f4a; --red: #c2463a; --muted: #5a5470; --slate: #3b3b4f;
  --pixel: 'Press Start 2P', ui-monospace, monospace;
  --ui: 'Pixelify Sans', system-ui, sans-serif;
  --text: 'Nunito', system-ui, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--ink); color: var(--paper); font-family: var(--ui); overscroll-behavior: none; }
body { -webkit-tap-highlight-color: transparent; }
button, input, select { font: inherit; }
button { cursor: pointer; }
a { color: var(--gold); }
:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
[hidden] { display: none !important; }

#app { position: fixed; inset: 0; display: flex; flex-direction: column; overflow: hidden; }
#game { position: relative; flex: 1; min-height: 0; }
#world { position: absolute; inset: 0; display: block; image-rendering: pixelated; touch-action: none; }

/* ---------- HUD ---------- */
#hud { position: absolute; left: 0; right: 0; top: 0; padding: max(8px, env(safe-area-inset-top)) 10px 0; display: flex; flex-direction: column; gap: 6px; pointer-events: none; }
#hud > * { pointer-events: auto; }
.hud-top { display: flex; align-items: center; gap: 8px; background: rgba(26,26,46,.88); border: 3px solid var(--paper); padding: 5px 6px; max-width: 520px; }
.hud-av { width: 40px; height: 40px; flex-shrink: 0; background: var(--night2); border: 2px solid var(--paper); image-rendering: pixelated; }
.hud-info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.hud-line { display: flex; justify-content: space-between; align-items: baseline; gap: 6px; }
.hud-nick { font-size: 16px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hud-lv { font-family: var(--pixel); font-size: 9px; color: var(--gold); white-space: nowrap; }
.bar { height: 10px; background: var(--slate); border: 2px solid var(--paper); position: relative; }
.bar > i { position: absolute; left: 0; top: 0; bottom: 0; background: var(--gold); transition: width .4s; }
.icon-btn { width: 44px; height: 44px; flex-shrink: 0; background: transparent; border: 3px solid var(--paper); color: var(--paper); display: grid; place-items: center; font-size: 18px; padding: 0; }
.icon-btn:hover { background: var(--night2); }
.mission-pill { max-width: 520px; text-align: left; background: var(--paper); color: var(--ink); border: 3px solid var(--gold); padding: 4px 10px; display: flex; flex-direction: column; gap: 2px; }
.mission-pill small { font-family: var(--pixel); font-size: 7px; color: #8a4a1a; letter-spacing: .5px; }
.mission-pill span { font-size: 15px; font-weight: 600; }
#area { position: absolute; left: 10px; bottom: 10px; background: var(--ink); border: 2px solid var(--paper); padding: 3px 8px; font-size: 14px; pointer-events: none; transition: opacity .4s; }

/* ---------- controles de toque ---------- */
#controls { flex-shrink: 0; display: flex; justify-content: space-between; align-items: center; padding: 10px 14px max(12px, env(safe-area-inset-bottom)); background: var(--ink); border-top: 3px solid var(--slate); user-select: none; -webkit-user-select: none; touch-action: none; }
.dpad { display: grid; grid-template-columns: repeat(3, 54px); grid-template-rows: repeat(3, 50px); gap: 2px; }
.dpad button { background: var(--slate); border: 3px solid var(--paper); color: var(--paper); font-size: 16px; padding: 0; touch-action: none; }
.dpad button.on, .dpad button:active { background: var(--gold); color: var(--ink); }
.dpad .mid { background: var(--slate); }
.ab { display: flex; flex-direction: column; align-items: flex-end; gap: 8px; }
.ab-row { display: flex; align-items: center; gap: 14px; }
.btn-a, .btn-b { border-radius: 50%; border: 3px solid var(--ink); font-family: var(--pixel); touch-action: manipulation; }
.btn-a { width: 72px; height: 72px; background: var(--gold); color: var(--ink); box-shadow: 0 0 0 3px var(--paper); font-size: 18px; }
.btn-b { width: 56px; height: 56px; background: var(--paper); color: var(--ink); box-shadow: 0 0 0 3px var(--paper); font-size: 14px; }
.btn-a:active, .btn-b:active { transform: translateY(2px); }
.ab-hint { font-size: 13px; color: #c9c2d9; }
#keys-hint { flex-shrink: 0; text-align: center; font-size: 13px; color: #c9c2d9; padding: 6px; background: var(--ink); border-top: 2px solid var(--slate); }

/* ---------- diálogo ---------- */
#dialog { position: absolute; left: 8px; right: 8px; bottom: 8px; max-width: 760px; margin: 0 auto; background: var(--paper); color: var(--ink); border: 4px solid var(--ink); box-shadow: 0 0 0 3px var(--paper), 6px 6px 0 3px rgba(0,0,0,.35); padding: 12px 14px 10px; display: flex; flex-direction: column; gap: 8px; }
.dlg-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.dlg-face { width: 40px; height: 40px; background: var(--sand); border: 2px solid var(--ink); image-rendering: pixelated; }
.dlg-name { font-size: 18px; font-weight: 700; }
.tag { font-family: var(--pixel); font-size: 7px; padding: 4px 6px; border: 2px solid var(--ink); letter-spacing: .5px; line-height: 1.3; }
.tag.drama { background: #f6d7a8; color: #7a3a12; }
.tag.resumo { background: #cfe3f5; color: #1f3f6a; }
.tag.narr { background: var(--ink); color: var(--paper); }
.dlg-text { font-family: var(--text); font-size: 17px; line-height: 1.45; min-height: 50px; font-weight: 600; }
.dlg-actions { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }
.dlg-choices { display: flex; flex-direction: column; gap: 6px; width: 100%; }

/* ---------- botões ---------- */
.btn { min-height: 44px; padding: 8px 16px; border: 3px solid var(--ink); background: var(--gold); color: var(--ink); font-weight: 700; font-size: 17px; box-shadow: 4px 4px 0 var(--ink); display: inline-flex; align-items: center; justify-content: center; gap: 8px; text-decoration: none; }
.btn:active { transform: translate(2px, 2px); box-shadow: 2px 2px 0 var(--ink); }
.btn.light { background: var(--paper); }
.btn.dark { background: var(--ink); color: var(--paper); border-color: var(--paper); box-shadow: 4px 4px 0 var(--slate); }
.btn.ghost { background: transparent; color: inherit; border-color: currentColor; box-shadow: none; }
.btn.small { min-height: 36px; padding: 4px 10px; font-size: 15px; box-shadow: 3px 3px 0 var(--ink); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.block { width: 100%; }
.link { background: none; border: 0; color: var(--gold); text-decoration: underline; padding: 6px; font-size: 15px; }

/* ---------- telas sobrepostas ---------- */
#screen { position: absolute; inset: 0; z-index: 20; overflow-y: auto; background: var(--ink); -webkit-overflow-scrolling: touch; }
#screen.over { background: rgba(10,10,24,.82); }
.panel { max-width: 560px; margin: 0 auto; min-height: 100%; padding: max(16px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 14px; }
.panel.paper { background: var(--paper); color: var(--ink); }
.panel h1, .panel h2, .panel h3 { margin: 0; }
.panel h1 { font-size: 26px; }
.panel h2 { font-size: 21px; }
.panel p { margin: 0; }
.kicker { font-family: var(--pixel); font-size: 9px; color: #8a4a1a; letter-spacing: 1px; line-height: 1.6; }
.dark .kicker, .story .kicker, .kicker.gold { color: var(--gold); }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.close { width: 44px; height: 44px; border: 3px solid currentColor; background: transparent; color: inherit; font-size: 20px; flex-shrink: 0; }
.card { border: 3px solid var(--ink); background: #fffdf5; padding: 12px; box-shadow: 4px 4px 0 var(--ink); }
.dark .card, .story .card { background: var(--night); border-color: var(--paper); box-shadow: 4px 4px 0 #000; }
.longtext { font-family: var(--text); font-size: 16px; line-height: 1.55; }
.muted { color: var(--muted); }
.dark .muted, .story .muted { color: #c9c2d9; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.grow { flex: 1; }

/* abertura */
.title-screen { position: relative; min-height: 100%; display: flex; flex-direction: column; align-items: center; overflow: hidden; background: linear-gradient(#1f2d52 0 38%, #2f4374 38% 50%, #44568f 50% 58%, #6a6fa6 58% 63%, #3f8f4a 63%); }
.title-screen canvas.scene { position: absolute; inset: 0; width: 100%; height: 100%; image-rendering: pixelated; }
.title-inner { position: relative; z-index: 1; display: flex; flex-direction: column; align-items: center; gap: 14px; padding: 12vh 20px 30px; width: 100%; max-width: 420px; min-height: 100%; }
.presents { font-family: var(--pixel); font-size: 10px; letter-spacing: 2px; color: var(--gold); }
.logo { display: flex; align-items: baseline; gap: 14px; font-family: var(--pixel); }
.logo .the { font-size: clamp(28px, 9vw, 40px); color: var(--paper); text-shadow: 4px 4px 0 var(--ink); }
.logo .way { font-size: clamp(42px, 14vw, 58px); color: var(--gold); text-shadow: 4px 4px 0 var(--ink), -2px -2px 0 var(--ink); }
.subtitle { background: var(--ink); border: 3px solid var(--gold); padding: 8px 16px; font-size: 22px; font-weight: 600; }
.title-actions { margin-top: auto; width: 100%; display: flex; flex-direction: column; gap: 12px; }
.title-foot { font-size: 13px; color: var(--paper); text-align: center; text-shadow: 1px 1px 0 var(--ink); }

/* formulários */
.field { display: flex; flex-direction: column; gap: 4px; }
.field label { font-weight: 700; font-size: 15px; }
.field input { min-height: 46px; border: 3px solid var(--ink); padding: 8px 10px; font-family: var(--text); font-size: 17px; background: #fffdf5; color: var(--ink); }
.field small { font-family: var(--text); font-size: 13px; color: var(--muted); }
.check { display: flex; gap: 10px; align-items: flex-start; font-family: var(--text); font-size: 15px; line-height: 1.4; }
.check input { width: 24px; height: 24px; flex-shrink: 0; accent-color: var(--green); margin-top: 1px; }
.avatars { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.avatars button { aspect-ratio: 1; border: 3px solid var(--ink); background: var(--sand); padding: 6px; }
.avatars button img { width: 100%; height: 100%; image-rendering: pixelated; }
.avatars button[aria-pressed="true"] { background: var(--gold); box-shadow: 0 0 0 3px var(--gold); }
.err { background: #fbe0dc; border: 3px solid var(--red); color: #7a1f16; padding: 8px 10px; font-family: var(--text); font-weight: 700; }
.notice { background: #fff1c9; border: 3px dashed #b27a12; padding: 8px 10px; font-family: var(--text); font-size: 14px; }

/* jornada */
.journey { display: flex; flex-direction: column; gap: 12px; }
.stage-card { display: flex; gap: 12px; align-items: center; padding: 10px; border: 3px solid var(--paper); background: var(--night); text-align: left; color: var(--paper); width: 100%; }
.stage-card .num { width: 48px; height: 48px; flex-shrink: 0; display: grid; place-items: center; font-family: var(--pixel); font-size: 14px; background: var(--gold); color: var(--ink); border: 3px solid var(--ink); }
.stage-card.locked { opacity: .65; }
.stage-card.locked .num { background: var(--slate); color: var(--paper); }
.stage-card.done .num { background: var(--green); color: var(--paper); }
.stage-card .meta { font-size: 14px; color: #c9c2d9; }
.stage-card .ttl { font-size: 18px; font-weight: 700; }
.stage-card .st { font-family: var(--pixel); font-size: 8px; margin-top: 4px; color: var(--gold); line-height: 1.5; }

/* missão */
.obj { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 2px dashed #d9cba8; }
.obj:last-child { border-bottom: 0; }
.obj .ck { width: 26px; height: 26px; flex-shrink: 0; border: 3px solid var(--ink); display: grid; place-items: center; font-weight: 900; }
.obj.ok .ck { background: var(--green); color: var(--paper); }
.obj .txt { flex: 1; font-family: var(--text); font-size: 15px; font-weight: 700; }
.obj .txt small { display: block; font-weight: 600; color: var(--muted); }

/* leitura */
.tabs { display: flex; gap: 6px; }
.tabs button { flex: 1; min-height: 44px; border: 3px solid var(--ink); background: var(--sand); font-weight: 700; font-size: 16px; color: var(--ink); }
.tabs button[aria-selected="true"] { background: var(--gold); }
.sec { border-left: 4px solid var(--gold); padding: 2px 0 2px 10px; }
.sec .ref { font-family: var(--pixel); font-size: 8px; color: #1f3f6a; }
.sec p { font-family: var(--text); font-size: 16px; line-height: 1.5; margin-top: 4px; }
.keyidea { background: var(--ink); color: var(--paper); padding: 10px 12px; font-family: var(--text); font-weight: 700; line-height: 1.45; }

/* perguntas */
.qprog { display: flex; gap: 4px; }
.qprog i { flex: 1; height: 8px; background: #d9cba8; border: 2px solid var(--ink); }
.qprog i.ok { background: var(--green); }
.qprog i.cur { background: var(--gold); }
/* Cronômetro dos desafios: a barra esvazia; nos últimos 5 s fica vermelha. */
.qtimer { display: flex; align-items: center; gap: 10px; }
.qtimer-bar { flex: 1; height: 14px; background: #d9cba8; border: 2px solid var(--ink); overflow: hidden; }
.qtimer-bar i { display: block; height: 100%; width: 100%; background: var(--green); transition: width .1s linear; }
.qtimer.low .qtimer-bar i { background: var(--red); }
.qtimer.still .qtimer-bar i { transition: none; }
.qtimer.done .qtimer-bar i { background: var(--muted, #5a5470); }
.qtimer-num { font-family: var(--pixel); font-size: 14px; min-width: 3ch; text-align: right; color: var(--ink); }
.qtimer.low .qtimer-num { color: var(--red); }
.opt:disabled { cursor: default; }
.qprompt { font-family: var(--text); font-size: 19px; font-weight: 800; line-height: 1.35; }
.opts { display: flex; flex-direction: column; gap: 10px; }
.opt { min-height: 52px; text-align: left; padding: 10px 12px; border: 3px solid var(--ink); background: #fffdf5; color: var(--ink); font-family: var(--text); font-size: 17px; font-weight: 700; display: flex; gap: 10px; align-items: center; box-shadow: 3px 3px 0 var(--ink); }
.opt b { font-family: var(--pixel); font-size: 11px; width: 26px; height: 26px; display: grid; place-items: center; background: var(--sand); border: 2px solid var(--ink); flex-shrink: 0; }
.opt.right { background: #d8f0d4; } .opt.right b { background: var(--green); color: var(--paper); }
.opt.wrong { background: #fbe0dc; } .opt.wrong b { background: var(--red); color: var(--paper); }
.feedback { border: 3px solid var(--ink); padding: 10px 12px; font-family: var(--text); font-size: 16px; line-height: 1.45; }
.feedback.ok { background: #d8f0d4; } .feedback.no { background: #fff1c9; }
.feedback strong { display: block; font-family: var(--ui); font-size: 19px; margin-bottom: 2px; }

/* ranking / perfil */
.rank-row { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border: 3px solid var(--ink); background: #fffdf5; }
.rank-row.me { background: #fff1c9; border-color: #b27a12; }
.rank-row .pos { width: 34px; font-family: var(--pixel); font-size: 11px; text-align: center; }
.rank-row img { width: 36px; height: 36px; image-rendering: pixelated; background: var(--sand); border: 2px solid var(--ink); }
.rank-row .nk { flex: 1; font-weight: 700; font-size: 17px; }
.rank-row .xp { font-family: var(--pixel); font-size: 9px; text-align: right; line-height: 1.6; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stat { border: 3px solid var(--ink); background: #fffdf5; padding: 8px; text-align: center; }
.stat b { display: block; font-family: var(--pixel); font-size: 14px; margin-bottom: 4px; }
.stat span { font-size: 13px; }
.ach { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.ach > div { border: 3px solid var(--ink); padding: 8px; background: #fffdf5; }
.ach > div.off { opacity: .45; filter: grayscale(1); }
.ach b { display: block; font-size: 16px; }
.ach span { font-family: var(--text); font-size: 13px; }
.menu-list { display: flex; flex-direction: column; gap: 10px; }
.slider { display: flex; align-items: center; gap: 10px; font-family: var(--text); font-weight: 700; }
.slider input { flex: 1; accent-color: var(--gold); height: 30px; }

/* toasts */
#toasts { position: absolute; top: max(70px, calc(env(safe-area-inset-top) + 64px)); left: 50%; transform: translateX(-50%); z-index: 40; display: flex; flex-direction: column; align-items: center; gap: 6px; pointer-events: none; width: min(92vw, 420px); }
.toast { background: var(--gold); color: var(--ink); border: 3px solid var(--ink); padding: 6px 12px; font-weight: 700; font-size: 16px; box-shadow: 3px 3px 0 var(--ink); animation: pop .25s ease-out; text-align: center; }
.toast.ach { background: var(--paper); border-color: var(--gold); }
.toast.lvl { background: var(--green); color: var(--paper); font-size: 18px; }
.toast.err { background: #fbe0dc; color: #7a1f16; border-color: var(--red); }
.toast.out { opacity: 0; transition: opacity .4s; }
@keyframes pop { from { transform: scale(.8); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.reduce-motion *, .reduce-motion *::before { animation: none !important; transition: none !important; }

/* intro / resumo */
.story { background: var(--ink); color: var(--paper); }
.story .longtext { font-size: 18px; }
.big-xp { font-family: var(--pixel); font-size: 22px; color: var(--gold); text-align: center; padding: 10px 0; }
.learned li { font-family: var(--text); font-size: 16px; line-height: 1.45; margin-bottom: 6px; }
.spinner { margin: 30vh auto 0; font-family: var(--pixel); font-size: 12px; color: var(--gold); text-align: center; }

@media (min-width: 700px) {
  .panel { padding-top: 28px; }
  #dialog { bottom: 16px; }
}

/* ---------- texto bíblico ---------- */
.trpick { display: flex; gap: 6px; }
.trpick button { flex: 1; min-height: 44px; border: 3px solid var(--ink); background: var(--paper); font-family: var(--ui); font-weight: 700; font-size: 16px; color: var(--ink); cursor: pointer; }
.trpick button[aria-checked="true"] { background: var(--ink); color: var(--gold); }
.bible { background: #fffdf6; border: 3px solid var(--ink); padding: 14px 14px 12px; display: flex; flex-direction: column; gap: 8px; }
.bible p { font-family: var(--text); font-size: 17px; line-height: 1.7; color: var(--ink); }
.bible sup { font-family: var(--text); font-size: 11px; font-weight: 800; color: #1f3f6a; margin: 0 2px 0 4px; vertical-align: super; line-height: 0; }
.bible .rights { font-family: var(--text); font-size: 12px; color: var(--muted); line-height: 1.4; border-top: 1px solid #e6dcc4; padding-top: 8px; }
.summary { border: 3px dashed var(--ink); padding: 10px 12px; background: var(--sand); }
.summary > summary { font-family: var(--ui); font-weight: 700; font-size: 16px; cursor: pointer; min-height: 32px; display: flex; align-items: center; }
.summary[open] { display: flex; flex-direction: column; gap: 10px; }

/* ---------- celular: aviso para girar ---------- */
#rotate { display: none; }
@media (orientation: portrait) {
  html.mobile.playing #rotate { display: flex; position: fixed; inset: 0; z-index: 100; flex-direction: column; align-items: center; justify-content: center; gap: 14px; padding: 24px; background: var(--ink); color: var(--paper); text-align: center; }
}
#rotate strong { font-family: var(--pixel); font-size: 14px; color: var(--gold); line-height: 1.5; }
#rotate span { font-size: 18px; max-width: 280px; }
.rotate-phone { width: 54px; height: 92px; border: 5px solid var(--paper); border-radius: 8px; position: relative; animation: girar 2.4s ease-in-out infinite; }
.rotate-phone::after { content: ''; position: absolute; left: 50%; bottom: 5px; width: 10px; height: 4px; margin-left: -5px; background: var(--paper); }
@keyframes girar { 0%, 25% { transform: rotate(0); } 55%, 85% { transform: rotate(-90deg); } 100% { transform: rotate(0); } }
@media (prefers-reduced-motion: reduce) { .rotate-phone { animation: none; transform: rotate(-90deg); } }

/* ---------- celular deitado: controles por cima do mapa ---------- */
@media (orientation: landscape) and (max-height: 540px) {
  html.mobile #controls { position: absolute; left: 0; right: 0; bottom: 0; z-index: 15; background: transparent; border: 0; pointer-events: none;
    padding: 0 max(14px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left)); align-items: flex-end; }
  html.mobile #controls .dpad, html.mobile #controls .ab-row { pointer-events: auto; }
  html.mobile .dpad { grid-template-columns: repeat(3, 46px); grid-template-rows: repeat(3, 44px); opacity: .82; }
  html.mobile .dpad span:not(.mid) { visibility: hidden; }
  html.mobile .btn-a { width: 66px; height: 66px; opacity: .9; }
  html.mobile .btn-b { width: 50px; height: 50px; opacity: .9; }
  html.mobile .ab-hint { display: none; }
  html.mobile #hud { padding-top: max(6px, env(safe-area-inset-top)); padding-left: max(10px, env(safe-area-inset-left)); gap: 4px; }
  html.mobile .hud-top { max-width: 360px; padding: 3px 5px; }
  html.mobile .hud-av { width: 32px; height: 32px; }
  html.mobile .icon-btn { width: 38px; height: 38px; }
  html.mobile .mission-pill { max-width: 360px; padding: 2px 8px; }
  html.mobile .mission-pill span { font-size: 13px; }
  html.mobile #area { left: auto; right: max(10px, env(safe-area-inset-right)); top: max(8px, env(safe-area-inset-top)); bottom: auto; }
  html.mobile #dialog { left: 170px; right: 150px; bottom: 6px; max-height: calc(100% - 12px); overflow-y: auto; padding: 8px 10px; gap: 6px; }
  html.mobile .dlg-text { font-size: 15px; min-height: 0; }
  html.mobile #toasts { top: max(10px, env(safe-area-inset-top)); }
  html.mobile .panel { padding-left: max(14px, env(safe-area-inset-left)); padding-right: max(14px, env(safe-area-inset-right)); }
}
