/* Khepri: interface pixelada nas cores do besouro (casco azul, contorno quase preto) e da bola (palha dourada, esterco).
   Bordas em "degrau" feitas com box-shadow (cantos recortados), nada de cantos arredondados nem faixa colorida lateral. */
@font-face { font-family: Pixelify; src: url(fonts/pixelify.woff2) format('woff2'); font-display: block; }
@font-face { font-family: Jersey; src: url(fonts/jersey20.woff2) format('woff2'); font-display: block; }
:root {
  --ink: #1e2238; --shell: #2f3d73; --shell2: #4a5a9a; --gold: #d9b45a; --gold2: #8a6a3a; --dung: #7a4f2a; --cream: #fff3d6; --pink: #ff8fa8;
  --b: 4px;
  --notch: 0 calc(-1 * var(--b)) 0 0 var(--ink), 0 var(--b) 0 0 var(--ink), calc(-1 * var(--b)) 0 0 0 var(--ink), var(--b) 0 0 0 var(--ink);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--ink); color: var(--cream); }
body {
  font: 16px/1.25 Pixelify, monospace; -webkit-font-smoothing: none; font-smooth: never; text-rendering: optimizeSpeed;
  touch-action: none; user-select: none; -webkit-user-select: none; -webkit-tap-highlight-color: transparent; overscroll-behavior: none;
}
canvas#c { position: fixed; inset: 0; width: 100vw; height: 100vh; height: 100dvh; display: block; }
svg.px { display: inline-block; vertical-align: middle; image-rendering: pixelated; }
button { font: inherit; color: inherit; border: 0; background: none; padding: 0; cursor: pointer; }

/* ---------- toque ---------- */
#touch { position: fixed; inset: 0; z-index: 1; }
#jbase { position: fixed; left: 0; top: 0; width: 96px; height: 96px; margin: -48px 0 0 -48px; z-index: 2; pointer-events: none; opacity: 0; }
#jbase.on { opacity: 1; }
#jbase::before { content: ''; position: absolute; inset: 0; background: #1e223866;
  clip-path: polygon(30% 0, 70% 0, 70% 8%, 85% 8%, 85% 15%, 92% 15%, 92% 30%, 100% 30%, 100% 70%, 92% 70%, 92% 85%, 85% 85%, 85% 92%, 70% 92%, 70% 100%, 30% 100%, 30% 92%, 15% 92%, 15% 85%, 8% 85%, 8% 70%, 0 70%, 0 30%, 8% 30%, 8% 15%, 15% 15%, 15% 8%, 30% 8%); }
#knob { position: absolute; left: 28px; top: 28px; width: 40px; height: 40px; background: var(--gold); box-shadow: var(--notch), inset 0 -4px 0 var(--gold2), inset 4px 4px 0 #f3d98a; }

/* ---------- HUD ---------- */
#hud { position: fixed; left: 0; right: 0; top: 0; z-index: 3; display: none; align-items: flex-start; gap: 12px; pointer-events: none;
  padding: calc(env(safe-area-inset-top) + 12px) calc(env(safe-area-inset-right) + 12px) 0 calc(env(safe-area-inset-left) + 12px); }
#hud.on { display: flex; }
.box { background: var(--shell); box-shadow: var(--notch), inset 0 -4px 0 #232f5c, inset 0 4px 0 var(--shell2); }
#sizebox { display: grid; grid-template-columns: auto 1fr; column-gap: 10px; row-gap: 6px; padding: 8px 12px 10px; min-width: 168px; }
#ballico { grid-row: 1; display: flex; align-items: center; }
.sz { display: flex; flex-direction: column; justify-content: center; }
#size { font: 28px/0.9 Jersey, monospace; color: #fff; letter-spacing: 0.5px; white-space: nowrap; }
#tier { font-size: 13px; color: var(--gold); text-transform: lowercase; }
#bar { grid-column: 1 / 3; display: flex; gap: 3px; }
#bar i { flex: 1; height: 8px; background: var(--ink); }
#bar i.f { background: var(--gold); box-shadow: inset 0 -2px 0 var(--gold2); }
#countbox { margin-left: auto; padding: 8px 12px; text-align: right; display: flex; flex-direction: column; }
#count { font: 28px/0.9 Jersey, monospace; color: #fff; }
#countbox small { font-size: 12px; color: #c9d0f0; }
#pbtn { pointer-events: auto; width: 52px; height: 52px; display: flex; align-items: center; justify-content: center; }
#pbtn:active { transform: translateY(2px); }

/* ---------- seta do marco ---------- */
#arrow { position: fixed; left: 0; top: 0; z-index: 3; display: none; pointer-events: none; width: 0; height: 0; }
#arrow.on { display: block; }
#arrow svg { position: absolute; left: -12px; top: -12px; filter: drop-shadow(2px 2px 0 var(--ink)); animation: blink 0.8s steps(2) infinite; }
#arrow span { position: absolute; left: 0; top: 18px; white-space: nowrap; font-size: 13px; padding: 2px 8px; background: var(--ink); color: var(--gold); }
@keyframes blink { 50% { opacity: 0.55; } }

/* ---------- faixa de nova escala ---------- */
#banner { position: fixed; left: 50%; top: 24%; z-index: 4; transform: translateX(-50%); text-align: center; pointer-events: none; display: none; padding: 10px 22px 12px;
  background: var(--ink); box-shadow: 0 -4px 0 0 var(--ink), 0 4px 0 0 var(--ink), -4px 0 0 0 var(--ink), 4px 0 0 0 var(--ink), 0 8px 0 0 #0006; }
#banner.on { display: block; animation: pop 2.8s steps(1) forwards; }
#banner small { display: block; font-size: 12px; color: #9aa4d8; letter-spacing: 2px; text-transform: uppercase; }
#banner b { display: block; font: 46px/1 Jersey, monospace; color: var(--gold); text-shadow: 3px 3px 0 var(--dung); white-space: nowrap; }
#banner span { display: block; font-size: 14px; color: var(--cream); }
@keyframes pop {
  0% { transform: translateX(-50%) scale(0.6); opacity: 0; } 4% { transform: translateX(-50%) scale(1.15); opacity: 1; } 8% { transform: translateX(-50%) scale(1); }
  88% { opacity: 1; transform: translateX(-50%) scale(1); } 94% { opacity: 0.5; } 100% { opacity: 0; }
}

/* ---------- avisos ---------- */
#toasts { position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 22px); z-index: 4; transform: translateX(-50%); display: flex; flex-direction: column-reverse; align-items: center; gap: 8px; pointer-events: none; width: 90vw; }
.toast { font-size: 15px; padding: 4px 10px; background: #1e2238dd; color: #fff; white-space: nowrap; animation: tin 0.24s steps(3) both; }
.toast.big { background: var(--gold); color: var(--ink); font-size: 17px; box-shadow: var(--notch); }
.toast.warn { color: var(--pink); }
.toast.out { animation: tout 0.3s steps(3) forwards; }
@keyframes tin { from { transform: translateY(12px); opacity: 0; } }
@keyframes tout { to { transform: translateY(-8px); opacity: 0; } }

#hint { position: fixed; left: 50%; bottom: 26%; z-index: 3; transform: translateX(-50%); display: none; pointer-events: none; font-size: 18px; color: #fff; text-shadow: 2px 2px 0 var(--ink); animation: blink 1s steps(2) infinite; white-space: nowrap; }
#hint.on { display: block; }

/* ---------- telas (título, pausa, fim) ---------- */
#scr { position: fixed; inset: 0; z-index: 10; display: none; align-items: center; justify-content: center; padding: 20px; background: #10142acc; overflow: auto; }
#scr.on { display: flex; }
#scr.dim0 { background: linear-gradient(#10142a00 30%, #10142a99); }
#scr.gold { background: #3a2410cc; }
.panel { position: relative; width: min(360px, 100%); padding: 22px 24px 20px; text-align: center; background: var(--shell);
  box-shadow: var(--notch), inset 0 4px 0 var(--shell2), inset 0 -6px 0 #232f5c, 0 12px 0 0 #0005; animation: tin 0.3s steps(3) both; }
.panel.title { background: #2f3d73f2; }
.panel.end { background: var(--dung); box-shadow: var(--notch), inset 0 4px 0 #9a6a3e, inset 0 -6px 0 #5c3b1f, 0 12px 0 0 #0005; }
.logo { display: flex; flex-direction: column; align-items: center; gap: 6px; margin: 0 0 4px; }
.logo svg { animation: bob 1.2s steps(2) infinite; }
@keyframes bob { 50% { transform: translateY(-4px); } }
h1 { margin: 0; font: 68px/0.9 Jersey, monospace; color: var(--gold); letter-spacing: 3px; text-shadow: 4px 4px 0 var(--dung), 0 8px 0 var(--ink); }
h2 { margin: 0 0 8px; font: 40px/1 Jersey, monospace; color: var(--gold); text-shadow: 3px 3px 0 var(--ink); }
.sub { margin: 4px 0 18px; color: var(--cream); font-size: 15px; }
.col { display: flex; flex-direction: column; gap: 14px; margin: 0 6px 16px; }
.row { display: flex; gap: 10px; justify-content: center; margin-bottom: 14px; }
.btn { display: flex; align-items: center; justify-content: center; gap: 10px; min-height: 52px; padding: 6px 16px 10px; font: 26px/1 Jersey, monospace; letter-spacing: 1px;
  background: var(--gold); color: var(--ink); box-shadow: var(--notch), inset 0 -6px 0 var(--gold2), inset 0 4px 0 #f3d98a; }
.btn svg rect { fill: var(--ink); }
.btn small { font: 15px Pixelify, monospace; opacity: 0.8; }
.btn:active { transform: translateY(3px); box-shadow: var(--notch), inset 0 -2px 0 var(--gold2), inset 0 4px 0 #b8963e; }
.btn:focus-visible { outline: 4px dashed #fff; outline-offset: 6px; }
.btn.main { min-height: 62px; font-size: 32px; }
.btn.small { min-height: 40px; padding: 4px 12px 7px; font: 15px/1 Pixelify, monospace; background: var(--shell2); color: #fff; box-shadow: var(--notch), inset 0 -4px 0 #343f75, inset 0 3px 0 #6a7ac0; }
.btn.small svg rect { fill: #fff; }
.btn.small.off { background: var(--ink); color: #8f97c2; box-shadow: var(--notch), inset 0 -4px 0 #151829; }
.btn.small.off svg rect { fill: #8f97c2; }
.btn.quit { min-height: 40px; font: 15px Pixelify, monospace; background: none; color: #c9d0f0; box-shadow: none; text-decoration: underline; text-underline-offset: 4px; }
.how { margin: 0; font-size: 13px; color: #c9d0f0; line-height: 1.45; }
.cyc { margin: 12px 0 0; font-size: 14px; color: var(--gold); }
.stat { margin: 0 0 16px; font-size: 15px; }
.stat b { font: 24px Jersey, monospace; color: #fff; }
.end h2 { color: #ffe9a8; text-shadow: 3px 3px 0 #5c3b1f; }
.end .logo svg { animation: spin 3s steps(8) infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-height: 460px) {
  .panel { padding: 14px 18px; } h1 { font-size: 48px; } .logo svg { width: 64px; height: 48px; } .sub { margin-bottom: 10px; }
  .col { gap: 10px; margin-bottom: 10px; } .btn.main { min-height: 50px; font-size: 28px; } .how { display: none; }
  #banner { top: 16%; } #banner b { font-size: 36px; }
}
@media (max-width: 380px) { #size { font-size: 24px; } #size.long { font-size: 18px; } }
#sizebox { flex: 0 1 auto; min-width: 0; }
#size.long { font-size: 21px; }
#countbox { flex: none; white-space: nowrap; }
.toast.warn { white-space: normal; text-align: center; max-width: min(90vw, 420px); }
