/* V342 · Botões de toque em pixel art: mesma forma e tamanho para todos, moldura em degrau,
   realce em cima/à esquerda, sombra embaixo e um afundar de 3px no mesmo quadro do toque.
   O botão inteiro continua sendo o alvo de toque; moldura e face são pseudo-elementos. */

/* Moldura e face */
#root #stage #touch button[data-touch-id]{position:relative}
#root #stage #touch button[data-touch-id]:not(.hud-proxy),#root #stage #interact{
 --tb-ink:#0b0f1f;--tb-sink:0px;
 --tb-hi:color-mix(in srgb,var(--tb-c,#34587e) 50%,#fff6d8);
 --tb-lo:color-mix(in srgb,var(--tb-c,#34587e) 58%,#050816);
 --tb-side:color-mix(in srgb,var(--tb-c,#34587e) 40%,#050816);
 --tb-step:polygon(0 2px,2px 2px,2px 0,calc(100% - 2px) 0,calc(100% - 2px) 2px,100% 2px,100% calc(100% - 2px),calc(100% - 2px) calc(100% - 2px),calc(100% - 2px) 100%,2px 100%,2px calc(100% - 2px),0 calc(100% - 2px));
 isolation:isolate;background:none!important;border:0!important;border-radius:0!important;box-shadow:none!important;
 color:#fff6d8;text-shadow:none;filter:none;transition:none;opacity:.9;-webkit-tap-highlight-color:transparent;
 -webkit-user-select:none;user-select:none
}
#root #stage #touch button[data-touch-id]:not(.hud-proxy){display:flex;flex-direction:column;align-items:center;justify-content:center;gap:1px;padding:2px 2px 5px;transform:none;overflow:visible;line-height:1}
#root #stage #touch button[data-touch-id]:not(.hud-proxy)::before,#root #stage #interact::before{
 content:'';position:absolute;inset:0;z-index:-1;pointer-events:none;clip-path:var(--tb-step);
 background:linear-gradient(var(--tb-side),var(--tb-side)) 2px calc(100% - 2px)/calc(100% - 4px) 3px no-repeat,var(--tb-ink)
}
#root #stage #touch button[data-touch-id]:not(.hud-proxy)::after,#root #stage #interact::after{
 content:'';position:absolute;left:2px;right:2px;top:2px;bottom:5px;z-index:-1;pointer-events:none;clip-path:var(--tb-step);
 background:var(--tb-c,#34587e);transform:translateY(var(--tb-sink));
 box-shadow:inset 0 2px var(--tb-hi),inset 2px 0 var(--tb-hi),inset 0 -2px var(--tb-lo),inset -2px 0 var(--tb-lo)
}

/* Cores por função, na paleta do jogo */
#root #stage #touch button:is([data-touch-id=left],[data-touch-id=right]){--tb-c:#34587e}
#root #stage #touch button[data-touch-id=crouch]{--tb-c:#4d6378}
#root #stage #touch button[data-touch-id=jump]{--tb-c:#b5473a}
#root #stage #touch button[data-touch-id=attack]{--tb-c:#2f71a3}
#root #stage #touch button[data-touch-id=special]{--tb-c:#7150a3}
#root #stage #touch button[data-touch-id=special].special-ready{--tb-c:#3b8653}
#root #stage #touch button[data-touch-id=weapon]{--tb-c:#2d6a5c}
#root #stage #touch button[data-touch-id=weapon][aria-pressed=true]{--tb-c:#3a9474}
#root #stage #touch button[data-touch-id=defend]{--tb-c:#1d6985}
#root #stage #touch button[data-touch-id=consumables]{--tb-c:#a8780f;color:#fff6d8}
#root #stage #touch button[data-touch-id=dismount]{--tb-c:#875733}
#root #stage #touch button[data-touch-id=dash]{--tb-c:#227b8a}
#root #stage #interact{--tb-c:#2b7150}

/* Ícone 12×12 em pixels de 2px; o desenho de arma equipada usa a mesma caixa */
#root #stage #touch .touch-icon{position:relative;display:block;flex:none;width:24px;height:24px;pointer-events:none}
#root #stage #touch .touch-icon svg{display:block;width:100%;height:100%;shape-rendering:crispEdges}
#root #stage #touch .touch-icon .px-o{fill:var(--tb-ink)}
#root #stage #touch .touch-icon .px-m{fill:#fff6d8}
#root #stage #touch .touch-icon .px-a{fill:color-mix(in srgb,var(--tb-c,#34587e) 30%,#ffffff)}
#root #stage #touch .touch-icon .px-s{fill:color-mix(in srgb,#fff6d8 66%,var(--tb-c,#34587e))}

/* Rótulo na fonte do jogo, contornado em pixel para ler sobre qualquer cenário */
#root #stage #touch button[data-touch-id] small{display:block;max-width:100%;margin:0;font:12px/1 'VT323',monospace;letter-spacing:0;color:#fff6d8;text-shadow:1px 0 var(--tb-ink),-1px 0 var(--tb-ink),0 1px var(--tb-ink),0 -1px var(--tb-ink);white-space:nowrap;text-align:center;pointer-events:none}
#root #stage #touch button[data-touch-id] small[data-fit=tight]{font-size:11px;letter-spacing:-.4px}
#root #stage #touch button[data-touch-id] small[data-fit=wrap]{font-size:9px;line-height:.85;letter-spacing:-.4px;white-space:normal;overflow-wrap:anywhere}
#root #stage #touch button[data-touch-id]:has(small[data-fit=wrap]) .touch-icon{width:16px;height:16px}

/* Toque: afunda 3px no mesmo quadro (sem transição), o realce troca de lado e solta faíscas em pixel */
#root #stage #touch button[data-touch-id]:not(.hud-proxy):is(.held,:active),#root #stage #interact:is(.held,:active){--tb-sink:3px;opacity:1}
#root #stage #touch button[data-touch-id]:not(.hud-proxy):is(.held,:active)::after,#root #stage #interact:is(.held,:active)::after{
 background:color-mix(in srgb,var(--tb-c,#34587e) 82%,#fff6d8);
 box-shadow:inset 0 2px var(--tb-lo),inset 2px 0 var(--tb-lo),inset 0 -2px var(--tb-hi),inset -2px 0 var(--tb-hi)
}
#root #stage #touch button[data-touch-id]:not(.hud-proxy):is(.held,:active)>*{translate:0 3px}
#root #stage #interact:is(.held,:active){padding-top:10px;padding-bottom:4px}
#root #stage #touch .touch-icon::after{content:'';position:absolute;left:11px;top:11px;width:2px;height:2px;opacity:0;pointer-events:none;background:#fff6d8}
#root #stage #touch button:is(.held,:active) .touch-icon::after{animation:touch-spark .24s linear forwards}
@keyframes touch-spark{
 0%{opacity:1;box-shadow:0 -10px #fff6d8,0 10px #fff6d8,-10px 0 #fff6d8,10px 0 #fff6d8,-8px -8px var(--tb-hi),8px -8px var(--tb-hi),-8px 8px var(--tb-hi),8px 8px var(--tb-hi)}
 33%{opacity:1;box-shadow:0 -14px #fff6d8,0 14px #fff6d8,-14px 0 #fff6d8,14px 0 #fff6d8,-10px -10px var(--tb-hi),10px -10px var(--tb-hi),-10px 10px var(--tb-hi),10px 10px var(--tb-hi)}
 66%{opacity:.7;box-shadow:0 -18px #fff6d8,0 18px #fff6d8,-18px 0 #fff6d8,18px 0 #fff6d8,-12px -12px var(--tb-hi),12px -12px var(--tb-hi),-12px 12px var(--tb-hi),12px 12px var(--tb-hi)}
 100%{opacity:0;box-shadow:0 -18px #fff6d8,0 18px #fff6d8,-18px 0 #fff6d8,18px 0 #fff6d8,-12px -12px var(--tb-hi),12px -12px var(--tb-hi),-12px 12px var(--tb-hi),12px 12px var(--tb-hi)}
}
#root #stage #touch button:is(.held,:active) .touch-icon::after{animation-timing-function:steps(1,end)}

/* Carregando: a face enche de baixo para cima; com equipamento, a moldura pisca em verde */
#root #stage #touch button[data-touch-id].charging::after{background:linear-gradient(to top,#46b08a calc(var(--attack-charge,0) * 100%),var(--tb-c,#34587e) 0)}
#root #stage #touch button[data-touch-id].charging-equipment{--tb-c:#1f6b5c}
#root #stage #touch button[data-touch-id].charging-equipment::before{animation:touch-charge .36s steps(1,end) infinite}
@keyframes touch-charge{0%{background-color:var(--tb-ink)}50%{background-color:#7ce7b7}}
#root #stage #touch button[data-touch-id].parry-active::after{background:color-mix(in srgb,var(--tb-c,#34587e) 60%,#fff5b8)}

@media(prefers-reduced-motion:reduce){
 #root #stage #touch .touch-icon::after{display:none}
 #root #stage #touch button[data-touch-id].charging-equipment::before{animation:none;background-color:#2c8f73}
}

/* Grade: direcional e itens de um lado, ações do outro; a mão escolhida espelha tudo.
   Botões com posição salva no editor ([data-touch-placed]) ficam fora da grade e usam o #touch inteiro. */
@media(pointer:coarse) and (orientation:landscape),(max-width:1000px) and (orientation:landscape){
 #root #stage{--tb-size:clamp(50px,calc(54px * var(--touch-scale,1)),62px)}
 #root #stage #touch,#root #stage[data-mode] #touch{--button-size:var(--tb-size)}
 #root #stage #touch:not(.menu-touch),#root #stage #touch.touch-editing{
  display:grid;grid-template-columns:repeat(2,var(--button-size)) minmax(0,1fr) repeat(3,var(--button-size));
  grid-template-rows:minmax(0,1fr) repeat(2,var(--button-size));gap:6px;align-items:stretch;justify-items:stretch
 }
 #root #stage #touch.touch-editing{display:grid!important}
 #root #stage #touch :is(.dpad,.actions){display:contents}
 #root #stage #touch button[data-touch-id]{width:100%;height:100%;min-width:0;min-height:0;max-width:none;margin:0;justify-self:stretch;align-self:stretch;font-size:inherit}
 #root #stage #touch button[data-touch-id][data-touch-placed]{grid-column:auto;grid-row:auto}
 #root #stage #touch button[data-touch-id=consumables]:not([data-touch-placed]){grid-column:1;grid-row:2}
 #root #stage #touch button:is([data-touch-id=dismount],[data-touch-id=dash]):not([data-touch-placed]){grid-column:2;grid-row:2}
 #root #stage #touch button[data-touch-id=left]:not([data-touch-placed]){grid-column:1;grid-row:3}
 #root #stage #touch button[data-touch-id=right]:not([data-touch-placed]){grid-column:2;grid-row:3}
 #root #stage #touch button[data-touch-id=weapon]:not([data-touch-placed]){grid-column:4;grid-row:2}
 #root #stage #touch button[data-touch-id=defend]:not([data-touch-placed]){grid-column:5;grid-row:2}
 #root #stage #touch button[data-touch-id=crouch]:not([data-touch-placed]){grid-column:6;grid-row:2}
 #root #stage #touch button[data-touch-id=special]:not([data-touch-placed]){grid-column:4;grid-row:3}
 #root #stage #touch button[data-touch-id=attack]:not([data-touch-placed]){grid-column:5;grid-row:3}
 #root #stage #touch button[data-touch-id=jump]:not([data-touch-placed]){grid-column:6;grid-row:3}
 html[data-touch-hand=left] #root #stage #touch:not(.menu-touch),html[data-touch-hand=left] #root #stage #touch.touch-editing{grid-template-columns:repeat(3,var(--button-size)) minmax(0,1fr) repeat(2,var(--button-size))}
 html[data-touch-hand=left] #root #stage #touch button[data-touch-id=jump]:not([data-touch-placed]){grid-column:1;grid-row:3}
 html[data-touch-hand=left] #root #stage #touch button[data-touch-id=attack]:not([data-touch-placed]){grid-column:2;grid-row:3}
 html[data-touch-hand=left] #root #stage #touch button[data-touch-id=special]:not([data-touch-placed]){grid-column:3;grid-row:3}
 html[data-touch-hand=left] #root #stage #touch button[data-touch-id=crouch]:not([data-touch-placed]){grid-column:1;grid-row:2}
 html[data-touch-hand=left] #root #stage #touch button[data-touch-id=defend]:not([data-touch-placed]){grid-column:2;grid-row:2}
 html[data-touch-hand=left] #root #stage #touch button[data-touch-id=weapon]:not([data-touch-placed]){grid-column:3;grid-row:2}
 html[data-touch-hand=left] #root #stage #touch button[data-touch-id=left]:not([data-touch-placed]){grid-column:5;grid-row:3}
 html[data-touch-hand=left] #root #stage #touch button[data-touch-id=right]:not([data-touch-placed]){grid-column:6;grid-row:3}
 html[data-touch-hand=left] #root #stage #touch button:is([data-touch-id=dismount],[data-touch-id=dash]):not([data-touch-placed]){grid-column:5;grid-row:2}
 html[data-touch-hand=left] #root #stage #touch button[data-touch-id=consumables]:not([data-touch-placed]){grid-column:6;grid-row:2}
 /* O botão de interagir fica no meio, sem encostar no bloco maior de botões */
 #root #stage #interact{max-width:calc(100% - 6 * var(--tb-size) - 72px);min-height:44px;padding:7px 10px;color:#fff6d8;font:17px/1.1 VT323,monospace}
}

/* V378 · Estágios da carga do soco (charge-stages.mjs): a face enche na cor do estágio alcançado
   (neutra, âmbar da rajada, azul-tinta da Canetada) e a moldura acende nessa cor. O que falta encher
   antecipa o próximo: azul-tinta com brilho se a Canetada está pronta, cinza riscado se não está. */
#root #stage #touch button[data-touch-id].charging[data-charge-stage]::after{background:linear-gradient(to top,var(--attack-charge-color,#46b08a) calc(var(--attack-charge,0) * 100%),var(--tb-c,#34587e) 0)}
#root #stage #touch button[data-touch-id].charging[data-charge-stage]:not([data-charge-stage=none])::before{background-color:var(--attack-charge-color,var(--tb-ink))}
#root #stage #touch button[data-touch-id].charging[data-charge-next=canetada]:not(.charge-next-off)::after{background:linear-gradient(to top,var(--attack-charge-color,#46b08a) calc(var(--attack-charge,0) * 100%),#1a3474 0)}
#root #stage #touch button[data-touch-id].charging[data-charge-next=canetada]:not(.charge-next-off){filter:drop-shadow(0 0 3px #9cc4ff)}
#root #stage #touch button[data-touch-id].charging.charge-next-off[data-charge-stage]::after{background:linear-gradient(to top,var(--attack-charge-color,#46b08a) calc(var(--attack-charge,0) * 100%),transparent 0),repeating-linear-gradient(135deg,#5d6570 0 3px,#363c45 3px 6px)}
/* V388 · Casulo da Mandioca ativo: botão cor de terra e uma faixa verde que encolhe com o tempo
   restante das raízes (--root-left, em degraus de 5%), embaixo do rótulo RAIZ n. */
#root #stage #touch button[data-touch-id=special].root-shield{--tb-c:#7a5326}
#root #stage #touch button[data-touch-id=special].root-shield small{padding-bottom:3px;background:linear-gradient(#9ccd5e,#9ccd5e) 0 100%/var(--root-left,100%) 2px no-repeat}

/* V980 · Base circular, face e contorno nas cores dos botões pixelados. */
#root #stage #touch button[data-touch-id=joystick]{display:none;position:absolute;left:max(24px,env(safe-area-inset-left));top:auto;bottom:24px;width:calc(112px * var(--touch-scale,1) * var(--ts,1));height:calc(112px * var(--touch-scale,1) * var(--ts,1));border:4px solid #101a2ccc;border-radius:50%;background:#34587e70;box-shadow:inset 0 0 0 4px #92b6c655,4px 4px #080e2255;touch-action:none;overflow:visible;padding:0;z-index:3}
#root #stage #touch button[data-touch-id=joystick]::before,#root #stage #touch button[data-touch-id=joystick]::after{display:none}
#root #stage #touch button[data-touch-id=joystick] .joystick-knob{position:absolute;left:30%;top:30%;width:40%;height:40%;box-sizing:border-box;border:4px solid #101a2c;background:#efe5c2;box-shadow:inset 4px 4px #fff6d8,inset -4px -4px #9a9b8a,3px 3px #080e2266;clip-path:polygon(20% 0,80% 0,80% 10%,100% 10%,100% 90%,80% 90%,80% 100%,20% 100%,20% 90%,0 90%,0 10%,20% 10%);transform:translate(var(--jx,0px),var(--jy,0px));translate:0 0;pointer-events:none}
#root #stage #touch[data-joystick=truck] button[data-touch-id=joystick],#root #stage #touch[data-joystick=cup] button[data-touch-id=joystick],#root #stage #touch[data-joystick=car] button[data-touch-id=joystick],#root #stage #touch[data-joystick=walk] button[data-touch-id=joystick]{display:block}
/* V571: fora das fases 6 e 12 o joystick some mesmo contra a regra genérica dos botões (#touch button[data-touch-id]:not(.hud-proxy){display:flex}). */
#root #stage #touch:not([data-joystick=cup]):not([data-joystick=car]):not([data-joystick=truck]):not([data-joystick=walk]):not(.touch-editing) button[data-touch-id=joystick]:not(.hud-proxy){display:none}
#root #stage #touch[data-joystick=cup]:not(.touch-editing) button:is([data-touch-id=left],[data-touch-id=right],[data-touch-id=forward],[data-touch-id=crouch]),#root #stage #touch[data-joystick=car]:not(.touch-editing) button:is([data-touch-id=left],[data-touch-id=right],[data-touch-id=jump],[data-touch-id=crouch]){display:none!important}
#root #stage.joystick-active canvas{touch-action:none}
/* V765: joystick opcional nas fases normais esconde ◀ ▶ ▼; pulo, ataque e o resto ficam onde estão. */
#root #stage #touch[data-joystick=walk]:not(.touch-editing) button:is([data-touch-id=left],[data-touch-id=right],[data-touch-id=crouch]){display:none!important}
html[data-touch-hand=left] #root #stage #touch button[data-touch-id=joystick]:not([data-touch-placed]):not(.joystick-held){left:auto;right:max(24px,env(safe-area-inset-right))}
#root #stage #touch button[data-touch-id=joystick][data-touch-placed]{left:calc(var(--tx) * 100% - 56px * var(--touch-scale,1) * var(--ts,1));top:calc(var(--ty) * 100% - 56px * var(--touch-scale,1) * var(--ts,1));bottom:auto}

#root #stage #touch button[data-touch-id=joystick] .joystick-knob svg{width:100%;height:100%;max-width:none}

/* V985: invisible drag surface, with feedback only under the active finger. */
#root #stage #touch:not(.touch-editing) button[data-touch-id=joystick]{opacity:0;pointer-events:none;border:0;background:none;box-shadow:none}
#root #stage #touch:not(.touch-editing) button[data-touch-id=joystick].joystick-held{opacity:1}
#root #stage #touch:not(.touch-editing) button[data-touch-id=joystick].joystick-held::before{content:'';display:block;position:absolute;inset:auto;left:50%;top:50%;width:32px;height:32px;border:1px solid #fff3c455;border-radius:50%;background:transparent;clip-path:none;transform:translate(-50%,-50%);z-index:0;box-shadow:none}
#root #stage #touch:not(.touch-editing) button[data-touch-id=joystick] small,#root #stage #touch:not(.touch-editing) button[data-touch-id=joystick] svg{display:none}
#root #stage #touch:not(.touch-editing) button[data-touch-id=joystick] .joystick-knob{left:calc(50% - 4px);top:calc(50% - 4px);width:8px;height:8px;border:0;border-radius:50%;clip-path:none;background:#fff3c499;box-shadow:none}
#root #stage #touch:not(.touch-editing) button[data-touch-id=joystick]::after{content:'';display:block;position:absolute;left:50%;top:calc(50% - 1px);right:auto;bottom:auto;z-index:0;clip-path:none;width:var(--jlength,0px);height:2px;background:#fff3c444;transform-origin:left center;transform:rotate(var(--jangle,0rad));box-shadow:none}
#stage #drag-touch-hint{position:absolute;z-index:30;top:22%;left:50%;transform:translateX(-50%);max-width:80%;padding:6px 10px;border:2px solid #ffe087;background:#141d33f2;color:#fff3c4;font:17px/1.1 VT323,monospace;box-shadow:3px 3px #050c16;pointer-events:none;text-align:center}
#stage #drag-touch-hint[hidden]{display:none}

#root #stage #touch[data-joystick=truck]:not(.touch-editing) button:is([data-touch-id=left],[data-touch-id=right],[data-touch-id=jump],[data-touch-id=crouch]){display:none!important}
