* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; height: 100%; overflow: hidden;
  overscroll-behavior: none;
  background: #1b1f3a;
  color: #fff;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-user-select: none; user-select: none;
  -webkit-touch-callout: none;
}

#app {
  --cell: 56px;
  height: 100vh; height: 100dvh;
  display: flex; flex-direction: column; align-items: center;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  background: radial-gradient(120% 80% at 50% 0%, #2c3270 0%, #1b1f3a 60%, #12142a 100%);
}

/* ---------- HUD ---------- */
#hud {
  width: 100%; max-width: 520px;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 10px 12px 6px;
}
.stat { display: flex; flex-direction: column; min-width: 0; }
.stat .label { font-size: 11px; letter-spacing: .08em; text-transform: uppercase; opacity: .65; }
.stat .value { font-size: 24px; font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1.1; }
.stat .value.bump { animation: bump .25s ease-out; }
#best { color: #ffd54a; }
.stat.next { align-items: center; }
#nextBox { position: relative; width: 38px; height: 38px; margin-top: 2px; }
.btns { display: flex; gap: 8px; }
.btns button {
  width: 42px; height: 42px; border-radius: 50%; border: 0; cursor: pointer;
  background: rgba(255,255,255,.12); color: #fff; font-size: 20px; line-height: 1;
}
.btns button:active { background: rgba(255,255,255,.25); }

/* ---------- Palco e grade ---------- */
#stage {
  position: relative; width: 100%; flex: 1 1 auto;
  display: flex; flex-direction: column; align-items: center;
  padding-top: calc(var(--cell) * 1.12);
  touch-action: none; cursor: pointer;
}
#board {
  position: relative;
  width: calc(var(--cell) * var(--cols, 5)); height: calc(var(--cell) * var(--rows, 7));
  border-radius: 14px;
  background:
    linear-gradient(rgba(255,255,255,.06) 1px, transparent 1px) 0 0 / 100% var(--cell),
    linear-gradient(90deg, rgba(255,255,255,.06) 1px, transparent 1px) 0 0 / var(--cell) 100%,
    rgba(8, 10, 30, .55);
  box-shadow: 0 0 0 3px rgba(255,255,255,.12), 0 12px 30px rgba(0,0,0,.45);
}
#hint { margin: 10px 0 0; font-size: 13px; opacity: .55; text-align: center; transition: opacity .4s; }
#hint.hide { opacity: 0; }

/* ---------- Blocos ---------- */
.block {
  position: absolute; left: 0; top: 0;
  width: var(--cell); height: var(--cell);
  padding: 3px; z-index: 2;
  will-change: transform; pointer-events: none;
}
.block .face {
  width: 100%; height: 100%;
  display: flex; align-items: center; justify-content: center;
  border-radius: 22%;
  box-shadow: inset 0 3px 0 rgba(255,255,255,.35), 0 3px 0 rgba(0,0,0,.28);
}
.block .num {
  font-weight: 900; color: #fff; letter-spacing: -.02em;
  text-shadow: 0 2px 0 rgba(0,0,0,.35), 0 0 6px rgba(0,0,0,.25);
}
.block .face.pop { animation: pop var(--pop, 280ms) cubic-bezier(.2,.9,.3,1.4); }
.block .face.spawn { animation: spawn .22s ease-out; }
.block .face.land { animation: land .16s ease-out; }
.block .face.dead { animation: dead var(--dead, 260ms) ease-in forwards; }
.block.blocked { opacity: .55; }

@keyframes pop { 0% { transform: scale(1); } 40% { transform: scale(1.38); } 100% { transform: scale(1); } }
@keyframes spawn { 0% { transform: scale(.4); opacity: 0; } 100% { transform: scale(1); opacity: 1; } }
@keyframes land { 0% { transform: scale(1.1, .8); } 100% { transform: scale(1); } }
@keyframes dead { to { transform: scale(0) rotate(40deg); opacity: 0; } }
@keyframes bump { 0% { transform: scale(1); } 40% { transform: scale(1.18); } 100% { transform: scale(1); } }

/* ---------- Sombra de onde vai cair ---------- */
#shadowCol {
  position: absolute; top: 0; left: 0; height: 100%; width: var(--cell);
  background: linear-gradient(180deg, rgba(255,255,255,0), rgba(255,255,255,.13));
  border-radius: 10px; pointer-events: none; z-index: 1;
  transition: transform 70ms ease-out; opacity: 0;
}
#shadowCol.bad { background: linear-gradient(180deg, rgba(255,60,60,0), rgba(255,60,60,.22)); }
#ghost {
  position: absolute; left: 0; top: 0; width: var(--cell); height: var(--cell);
  padding: 3px; pointer-events: none; z-index: 1; opacity: 0;
  transition: transform 70ms ease-out;
}
#ghost i {
  display: block; width: 100%; height: 100%; border-radius: 22%;
  border: 3px dashed rgba(255,255,255,.75); background: rgba(255,255,255,.12);
}
#ghost.merge i { animation: ghostPulse .7s ease-in-out infinite; border-style: solid; }
@keyframes ghostPulse { 50% { background: rgba(255,255,255,.3); } }

/* ---------- Combo e pontos flutuantes ---------- */
#board .comboPop, .comboPop {
  position: absolute; left: 0; right: 0; top: 8%; text-align: center; z-index: 6;
  font-weight: 900; font-style: italic; pointer-events: none; opacity: 0;
  font-size: calc(var(--cell) * .75);
  color: #ffe45e; -webkit-text-stroke: 2px #7a2a00; paint-order: stroke fill;
  text-shadow: 0 4px 0 #7a2a00, 0 0 24px rgba(255,170,0,.8);
}
.comboPop.show { animation: comboIn .35s cubic-bezier(.2,.9,.3,1.5) forwards; }
.comboPop.out { animation: comboOut .4s ease-in forwards; }
@keyframes comboIn { 0% { opacity: 0; transform: scale(.4) rotate(-8deg); } 100% { opacity: 1; transform: scale(1) rotate(-3deg); } }
@keyframes comboOut { from { opacity: 1; transform: scale(1) rotate(-3deg); } to { opacity: 0; transform: translateY(-20px) scale(1.1) rotate(-3deg); } }

.float {
  position: absolute; z-index: 5; pointer-events: none; white-space: nowrap;
  font-weight: 900; font-size: calc(var(--cell) * .36);
  transform: translate(-50%, -50%);
  color: #fff; text-shadow: 0 2px 0 rgba(0,0,0,.5), 0 0 8px rgba(0,0,0,.4);
  animation: floatUp .9s ease-out forwards;
}
@keyframes floatUp { from { opacity: 1; margin-top: 0; } to { opacity: 0; margin-top: calc(var(--cell) * -1.1); } }
.spark { position: absolute; z-index: 4; border-radius: 3px; pointer-events: none; }

/* ---------- Tela por cima (fim de jogo / confirmação) ---------- */
#overlay {
  position: fixed; inset: 0; z-index: 20;
  display: flex; align-items: center; justify-content: center;
  background: rgba(8,10,30,.72); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px);
}
#overlay[hidden] { display: none; }
.card {
  width: min(86vw, 340px); padding: 24px 20px; text-align: center;
  background: linear-gradient(180deg, #343b86, #232859);
  border-radius: 20px; box-shadow: 0 20px 50px rgba(0,0,0,.6), 0 0 0 2px rgba(255,255,255,.15);
  animation: spawn .25s ease-out;
}
.card h2 { margin: 0 0 12px; font-size: 26px; }
#ovBody { font-size: 16px; line-height: 1.6; opacity: .95; margin-bottom: 16px; }
#ovBody b { color: #ffd54a; }
#ovButtons { display: flex; flex-direction: column; gap: 10px; }
#ovButtons button {
  border: 0; border-radius: 14px; padding: 14px; font-size: 17px; font-weight: 800; cursor: pointer;
  background: #ffd54a; color: #3b2a00; box-shadow: 0 4px 0 #b8901a;
}
#ovButtons button.secondary { background: rgba(255,255,255,.14); color: #fff; box-shadow: none; }
#ovButtons button:active { transform: translateY(2px); }

/* ---------- Menu ---------- */
#overlay.solid { background: radial-gradient(120% 80% at 50% 0%, #2c3270 0%, #1b1f3a 70%); backdrop-filter: none; -webkit-backdrop-filter: none; }
#overlay.solid .card { background: none; box-shadow: none; }
#overlay.solid .card h2 { font-size: 32px; }

#fatal { position: fixed; inset: 0; z-index: 15; pointer-events: none; background: rgba(0,0,0,0); transition: background .6s; }
#fatal.show { background: rgba(0,0,0,.8); }
#fatalText {
  position: fixed; left: 0; right: 0; top: 36%; z-index: 17; text-align: center; pointer-events: none;
  font-size: min(13vw, 20vh, 96px); font-weight: 900; font-style: italic; opacity: 0;
  color: #ffe45e; -webkit-text-stroke: 3px #7a0a00; paint-order: stroke fill;
  text-shadow: 0 6px 0 #7a0a00, 0 0 40px rgba(255,60,0,.9);
}
#fatalText.show { animation: fatalIn .55s cubic-bezier(.2,.9,.3,1.3) forwards; }
@keyframes fatalIn { 0% { opacity: 0; transform: scale(3.2) rotate(-6deg); } 100% { opacity: 1; transform: scale(1) rotate(-4deg); } }

/* ==========================================================================
   BATALHA — celular deitado
   ========================================================================== */
#app.battle #hud { position: absolute; left: 50%; top: 4px; transform: translateX(-50%); width: auto; padding: 0; z-index: 30; }
#app.battle #hud .stat { display: none; }
#app.battle .btns button { width: 30px; height: 30px; font-size: 14px; }
#app.battle #stage { position: static; padding-top: 0; flex: none; width: auto; }
#app.battle #hint { display: none; }

#arena {
  position: relative; flex: 1 1 auto; width: 100%; min-height: 0;
  display: flex; justify-content: space-between; align-items: flex-start;
  padding: 8px 14px 6px;
}
#arena[hidden] { display: none; }
#colL, #colR { flex: none; display: flex; flex-direction: column; }
.names { height: 30px; display: flex; justify-content: space-between; align-items: baseline; gap: 10px; padding: 0 2px 4px; }
.names span { font-size: 13px; font-weight: 700; white-space: nowrap; }
.names b { font-size: 18px; font-weight: 800; font-variant-numeric: tabular-nums; }
#scoreMe { color: #ffcf5a; }
#scoreOpp { color: #c9cdf0; }

#oppBoard {
  position: relative;
  width: calc(var(--cell) * var(--cols, 5)); height: calc(var(--cell) * var(--rows, 7));
  border-radius: 14px; background: rgba(10,12,30,.55);
  box-shadow: 0 0 0 3px rgba(255,255,255,.12), 0 12px 30px rgba(0,0,0,.4);
  background-image:
    linear-gradient(rgba(255,255,255,.06) 1px, transparent 1px), linear-gradient(90deg, rgba(255,255,255,.06) 1px, transparent 1px);
  background-size: 100% var(--cell), var(--cell) 100%;
}
#oppBoard .block { z-index: 2; }

/* Sufoco: borda piscando em vermelho + brilho no topo */
#board.danger, #oppBoard.danger { animation: dangerPulse 1s ease-in-out infinite; }
#board.danger::after, #oppBoard.danger::after {
  content: ""; position: absolute; left: 0; top: 0; width: 100%; height: calc(var(--cell) * 1.3);
  border-radius: 14px 14px 0 0; pointer-events: none; z-index: 6;
  background: linear-gradient(180deg, rgba(255,60,60,.4), rgba(255,60,60,0));
}
@keyframes dangerPulse {
  0%,100% { box-shadow: 0 0 0 2px #ff5a5a, 0 0 18px rgba(255,70,70,.35); }
  50% { box-shadow: 0 0 0 4px #ff5a5a, 0 0 36px rgba(255,70,70,.85); }
}

/* Blocos de ataque: caem com rastro vermelho */
.block.atk { z-index: 4; }
.block.atk .face { outline: 2px solid #ff6b6b; outline-offset: -2px; }
.block .trail {
  position: absolute; left: 3px; right: 3px; bottom: 100%; height: 100%; border-radius: 8px;
  background: linear-gradient(180deg, rgba(255,90,90,0), rgba(255,90,90,.55)); pointer-events: none;
}
.block.oppfall { animation: oppFall var(--fall-ms, 380ms) cubic-bezier(.5,0,.9,.55) backwards; animation-delay: var(--delay, 0ms); }
@keyframes oppFall { from { margin-top: calc(var(--cell) * var(--rows-from, -3)); opacity: .3; } to { margin-top: 0; opacity: 1; } }

/* Combo grande (batalha) */
#app.battle .comboPop {
  top: 10%; left: 50%; right: auto; transform: translateX(-50%); width: max-content; text-align: center;
  padding: 4px 14px; border-radius: 14px; background: #ffcf5a; color: #2b2140; -webkit-text-stroke: 0;
  text-shadow: none; font-style: normal; letter-spacing: .5px;
  font-size: calc(var(--cell) * .8); box-shadow: 0 6px 18px rgba(255,207,90,.5);
}
#app.battle .comboPop.show { animation: comboBattle .5s cubic-bezier(.2,.9,.3,1.4) forwards; }
#app.battle .comboPop.out { animation: comboBattleOut .4s ease-in forwards; }
@keyframes comboBattle { 0% { opacity: 0; transform: translateX(-50%) scale(.3); } 60% { transform: translateX(-50%) scale(1.15) rotate(-4deg); } 100% { opacity: 1; transform: translateX(-50%) scale(1) rotate(-4deg); } }
@keyframes comboBattleOut { from { opacity: 1; transform: translateX(-50%) rotate(-4deg); } to { opacity: 0; transform: translateX(-50%) translateY(-24px) scale(1.1) rotate(-4deg); } }

/* ---------- Faixa central ---------- */
#strip { flex: 1 1 auto; min-width: 0; align-self: stretch; display: flex; flex-direction: column; align-items: center; padding: 0 8px; gap: 4px; }
#curNext { display: flex; gap: 12px; align-items: flex-end; margin-top: 26px; }
.cn { display: flex; flex-direction: column; align-items: center; gap: 3px; }
.cn small { font-size: 10px; color: #c9cdf0; letter-spacing: 1px; }
.cn.nx { opacity: .8; }
#stripCur, #stripNext { position: relative; }
#stripCur .block, #stripNext .block { position: relative; left: auto; top: auto; transform: none; }
#banners { display: flex; gap: 8px; min-height: 28px; align-items: center; justify-content: center; }
.banner {
  position: relative; overflow: hidden; padding: 4px 12px; border-radius: 999px; white-space: nowrap;
  background: #ff5a5a; color: #fff; font-weight: 900; font-size: 14px; box-shadow: 0 4px 14px rgba(255,90,90,.5);
  animation: chipPulse .6s ease-in-out infinite alternate;
}
.banner[hidden] { display: none; }
.banner i { position: absolute; left: 0; bottom: 0; height: 3px; background: rgba(255,255,255,.9); }
#chars { position: relative; flex: 1 1 auto; min-height: 0; width: 100%; display: flex; justify-content: center; align-items: flex-end; gap: 4px; }
.char { position: relative; flex: 0 1 46%; height: 100%; min-width: 0; --fwd: 1; }
.char.flip { --fwd: -1; }
.char .flipbox { width: 100%; height: 100%; }
.char.flip .flipbox { transform: scaleX(-1); }
.char svg { width: 100%; height: 100%; display: block; overflow: visible; }
#vs {
  position: absolute; left: 50%; top: 14%; transform: translateX(-50%);
  font-size: 22px; font-weight: 900; color: #ffcf5a; text-shadow: 0 2px 0 #2b2140; z-index: 3;
}
.help {
  position: absolute; top: 2%; left: 50%; transform: translateX(-50%); padding: 3px 9px; border-radius: 10px;
  background: #fff; color: #2b2140; font-size: 12px; font-weight: 800; white-space: nowrap; display: none; z-index: 4;
}
.help::after { content: ""; position: absolute; left: 50%; bottom: -5px; width: 9px; height: 9px; background: #fff; transform: translateX(-50%) rotate(45deg); }
.char.danger .help { display: block; }
#powers { display: flex; gap: 10px; padding-top: 2px; }
#powers button {
  width: 40px; height: 40px; border-radius: 13px; border: 0; background: rgba(255,255,255,.14);
  display: flex; align-items: center; justify-content: center; opacity: .45;
}

/* Reações dos personagens (só CSS) */
.bob { animation: bob 2.4s ease-in-out infinite; transform-origin: 50% 100%; }
@keyframes bob { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-4px) scaleY(1.01); } }
.char.danger { animation: charDanger .35s linear infinite; }
@keyframes charDanger { 0%,100% { transform: translateX(0); } 25% { transform: translateX(-3px); } 75% { transform: translateX(3px); } }
.char.attack { animation: charAttack .55s ease-out; }
@keyframes charAttack {
  0% { transform: translate(0,0); } 35% { transform: translate(calc(var(--fwd) * 26px), -18px) scale(1.08); }
  70% { transform: translate(calc(var(--fwd) * 14px), 0); } 100% { transform: translate(0,0); }
}
.char.hurt { animation: charHurt .6s linear; }
@keyframes charHurt {
  0%,100% { transform: translateX(0); filter: none; } 10% { transform: translateX(-6px); filter: brightness(2.2) saturate(.5); }
  20% { transform: translateX(6px); filter: none; } 30% { transform: translateX(-6px); filter: brightness(2.2); }
  40% { transform: translateX(6px); filter: none; } 50% { transform: translateX(-4px); filter: brightness(2); }
  60% { transform: translateX(4px); filter: none; } 80% { transform: translateX(-2px); }
}
.char.win { animation: charWin .6s ease-in-out infinite; }
@keyframes charWin { 0%,100% { transform: translateY(0); } 40% { transform: translateY(-22%) rotate(calc(var(--fwd) * 4deg)); } }
.char.lose { animation: charLose .9s ease-in forwards; transform-origin: 50% 100%; }
@keyframes charLose { to { transform: translateY(8%) rotate(calc(var(--fwd) * -82deg)); filter: grayscale(.6); } }

/* ---------- Gire o celular ---------- */
#rotate {
  position: fixed; inset: 0; z-index: 40; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
  background: radial-gradient(120% 80% at 50% 0%, #2c3270 0%, #12142a 80%); text-align: center;
}
#rotate[hidden] { display: none; }
.rotIcon { font-size: 72px; animation: rotPhone 1.8s ease-in-out infinite; }
@keyframes rotPhone { 0%,20% { transform: rotate(0); } 60%,100% { transform: rotate(-90deg); } }
.rotText { font-size: 28px; font-weight: 900; }
#rotate small { opacity: .7; font-size: 14px; }

/* ---------- Menu com a Guerreira ---------- */
#ovHead { display: flex; align-items: center; justify-content: center; gap: 10px; margin-bottom: 12px; }
#ovHead h2 { margin: 0; }
#ovArt { width: 78px; flex: none; }
#ovArt:empty { display: none; }
#ovArt svg { width: 100%; height: auto; display: block; }
@keyframes chipPulse { to { transform: scale(1.07); } }
.spot { position: relative; z-index: 16; }

/* ---------- Instalar como app ---------- */
#btnInstall { margin-top: 14px; width: 100%; border: 2px solid rgba(255,255,255,.35); background: transparent;
  color: #fff; font-size: 15px; font-weight: 700; padding: 11px 14px; border-radius: 14px; cursor: pointer; }
#btnInstall[hidden] { display: none; }
#installHelp { position: fixed; inset: 0; z-index: 9999; background: rgba(10,12,30,.8); display: flex;
  align-items: center; justify-content: center; padding: 20px; }
#installHelp[hidden] { display: none; }
#installHelp .ihCard { background: #262b55; color: #fff; border-radius: 20px; padding: 20px 22px; max-width: 360px;
  box-shadow: 0 12px 40px rgba(0,0,0,.5); }
#installHelp h3 { margin: 0 0 10px; font-size: 19px; }
#installHelp ol { margin: 0 0 10px; padding-left: 20px; line-height: 1.5; }
#installHelp p { margin: 0 0 14px; color: #c9cdf0; font-size: 14px; }
#installHelp .ihIcon { display: inline-block; padding: 0 5px; border: 1px solid #c9cdf0; border-radius: 5px; font-size: 12px; }
#installHelp button { width: 100%; border: 0; border-radius: 12px; padding: 11px; font-size: 15px; font-weight: 800;
  background: #ffcf5a; color: #2b2140; cursor: pointer; }
