:root{
  --verde:#79C92F; --verde-esc:#4F8C1E; --laranja:#F46A1D; --amarelo:#FFD84A;
  --agua:#39B9F6; --vermelho:#E23B2E; --madeira:#C98A38; --escuro:#241C1C;
  --painel:#2A2320; --painel2:#3A2E2E; --osso:#FDF6E3;
  --ouro:#E0A92E; --marrom:#5a3a1c; --marrom-esc:#3a2410;
}
*{box-sizing:border-box;-webkit-tap-highlight-color:transparent}
html,body{margin:0;height:100%}
body{
  background:#0b0f08;color:var(--osso);
  font-family:"Trebuchet MS","Segoe UI",system-ui,sans-serif;
  display:flex;align-items:center;justify-content:center;
  min-height:100%;overflow:hidden;user-select:none;
}
.sr-only{position:absolute!important;width:1px;height:1px;padding:0;margin:-1px;
  overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap;border:0}

/* ===== Palco 16:9, scale-to-fit com letterbox ===== */
#stage{
  position:relative;aspect-ratio:16/9;
  width:min(100vw, calc(100vh * 16 / 9));
  max-height:100vh;margin:auto;overflow:hidden;background:#0b0f08;
  container-type:size;            /* habilita unidades cqw/cqh nos filhos */
  box-shadow:0 0 40px #000a;
  touch-action:none;             /* toque de jogo não rola/zooma a página (mobile) */
}

/* Aviso de orientação: discreto, não-bloqueante, some ao girar p/ paisagem */
#rotate{position:fixed;top:0;left:0;right:0;z-index:100;pointer-events:none;
  display:none;align-items:center;justify-content:center;gap:6px;
  padding:8px 12px;background:#000b;color:var(--amarelo);
  font-weight:bold;font-size:13px;text-align:center;
  padding-top:calc(8px + env(safe-area-inset-top,0px))}
@media (orientation:portrait){ #rotate{display:flex} }
#board{position:absolute;inset:0;width:100%;height:100%;display:block;
  image-rendering:pixelated;image-rendering:crisp-edges;touch-action:none}

/* Camada de UI: transparente a cliques; filhos reativam */
#ui{position:absolute;inset:0;pointer-events:none}
#ui > *{pointer-events:auto}

/* ===== HUD topo-esquerdo: coração + barras ===== */
#hud{position:absolute;top:2cqh;left:1.4cqw;display:flex;align-items:center;gap:1cqw}
.heart-frame{width:5.8cqw;height:5.8cqw;flex:none;image-rendering:pixelated;
  background:center/contain no-repeat url('assets/sprites/hud_heart.png')}
#bars{display:flex;flex-direction:column;gap:0.7cqh}
/* Barra de vida da torre = sprite pixel (barra_vida.png). O sprite já traz moldura + verde. */
#treebar{position:relative;width:16cqw;height:4.9cqh;overflow:hidden;
  background:center/100% 100% no-repeat url('assets/sprites/barra_vida.png');
  image-rendering:pixelated}
/* #treefill agora é a máscara de dano: cobre da direita a parte de vida perdida */
#treefill{position:absolute;top:0;right:0;height:100%;width:0%;
  background:rgba(18,11,4,.72);transition:width .2s}
.barlbl{position:absolute;inset:0;display:flex;align-items:center;justify-content:center;
  font-size:1.5cqh;font-weight:bold;color:#fff;text-shadow:1px 1px 0 #000,0 0 3px #000}

/* ===== Topo-direito: engrenagem + pause ===== */
#topright{position:absolute;top:2cqh;right:1.4cqw;display:flex;gap:0.8cqw}
.iconbtn{width:5cqw;height:5cqw;font-size:2.6cqw;line-height:1;cursor:pointer;color:var(--osso);
  background:var(--painel);border:0.4cqw solid var(--ouro);border-radius:0.8cqw;
  box-shadow:inset 0 0 0 0.2cqw var(--marrom-esc);display:flex;align-items:center;justify-content:center;padding:0}
.iconbtn:active{transform:translateY(0.3cqh)}
/* botões com arte real (já trazem a própria moldura) */
.iconbtn.art{background:center/contain no-repeat;border:none;box-shadow:none;image-rendering:pixelated}
.iconbtn.art-gear{background-image:url('assets/sprites/btn_gear.png')}
.iconbtn.art-pause{background-image:url('assets/sprites/btn_pause.png')}
.iconbtn.art-mute{background-image:url('assets/sprites/btn_sound.png');position:relative}
/* estado mudo: escurece o alto-falante e cruza com uma barra vermelha */
.iconbtn.art-mute.muted{filter:grayscale(.55) brightness(.72)}
.iconbtn.art-mute.muted::after{content:"";position:absolute;left:16%;right:16%;top:47%;height:0.5cqw;
  background:var(--vermelho);border-radius:0.3cqw;transform:rotate(-45deg);
  box-shadow:0 0 0 0.14cqw #000}

/* ===== Deck + moedas (faixa inferior) ===== */
#deckbar{position:absolute;left:1.4cqw;right:1.4cqw;bottom:1.6cqh;height:19cqh;
  display:flex;align-items:stretch;gap:1cqw}
/* Contador de moedas: a MOLDURA DE ARTE (coin_frame.png) É a caixa/painel de interface;
   a moeda dourada + o número aparecem DENTRO dela. */
#coinbox{flex:none;align-self:center;height:9cqh;display:flex;flex-direction:row;align-items:center;justify-content:center;
  gap:0.6cqw;padding:0 1.6cqw 0 1.2cqw;font-weight:bold;font-size:3cqh;
  color:var(--amarelo);text-shadow:1px 1px 0 #000;
  background:rgba(20,14,10,.32);
  border:1.7cqh solid transparent;
  border-image:url('assets/sprites/coin_frame.png') 8 fill stretch;
  image-rendering:pixelated}
/* a moeda dourada, dentro da caixa (sem moldura própria) */
.coin{flex:none;width:2.8cqh;height:2.8cqh;border-radius:50%;
  background:radial-gradient(circle at 36% 30%, #fff4c2 0%, var(--amarelo) 52%, var(--ouro) 100%);
  box-shadow:inset -0.18cqw -0.18cqw 0 #b8841f, inset 0.14cqw 0.14cqw 0 #fff6cf, 0 0.12cqw 0 #0007}
#deck{flex:1;display:flex;align-items:stretch;justify-content:center;gap:0.8cqw}
.card{position:relative;height:100%;aspect-ratio:37/49;padding:1cqh 0.5cqw;cursor:pointer;overflow:hidden;
  display:flex;flex-direction:column;align-items:center;justify-content:flex-start;gap:0.5cqh;border:none;
  touch-action:none;user-select:none;
  background:center/100% 100% no-repeat url('assets/sprites/cartinha.png');
  image-rendering:pixelated;transition:transform .08s,filter .1s}
.card:not(.locked):not(.cant):not(.empty):hover{transform:translateY(-0.6cqh)}
.card.empty{opacity:.5;cursor:default;filter:saturate(.5)}
/* HIERARQUIA: ilustração dominante no topo → nome → custo. Textos em placa escura p/ legibilidade. */
.card .cchip{width:100%;flex:1 1 auto;min-height:6cqh;order:0;
  background-size:contain;background-repeat:no-repeat;background-position:center bottom;
  filter:drop-shadow(0 0.4cqh 0 rgba(0,0,0,.22))}
.card .cname{order:1;width:100%;min-height:4.4cqh;font-size:1.6cqh;font-weight:800;line-height:1.05;color:#fff;
  display:flex;align-items:center;justify-content:center;text-align:center;
  background:rgba(36,28,28,.80);border-radius:0.6cqw;padding:0.4cqh 0.2cqw;
  overflow:hidden;overflow-wrap:break-word;word-break:break-word;
  box-shadow:0 0 0 0.12cqw rgba(0,0,0,.55)}
.card .ccost{order:2;font-size:1.9cqh;font-weight:900;color:#FFE066;line-height:1;
  background:#241c1c;border:0.14cqw solid var(--ouro);border-radius:1cqw;
  padding:0.3cqh 0.7cqw;text-shadow:0 1px 0 #000}
.card.selected{outline:0.4cqw solid var(--agua);outline-offset:-0.3cqw;border-radius:1cqw}
.card.cant,.card.locked{background-image:url('assets/sprites/cartinha_vermelha.png')}
.card.cant .ccost,.card.locked .ccost{color:#fff}
.card.cant,.card.locked{cursor:not-allowed}
.card .lock{position:absolute;inset:0;display:flex;align-items:center;justify-content:center;
  flex-direction:column;font-size:1.6cqh;color:#fff;background:#0007;gap:0.3cqh;border-radius:0.8cqw}
.card .cd{position:absolute;left:0;bottom:0;width:100%;background:var(--agua);opacity:.4}

/* Foco visível (acessibilidade por teclado) */
.card:focus-visible,#board:focus-visible,.btn:focus-visible,.iconbtn:focus-visible{
  outline:0.4cqw solid var(--agua);outline-offset:0.2cqw}

/* ===== Overlays (start/end) ===== */
.overlay{position:absolute;inset:0;display:flex;flex-direction:column;align-items:center;
  justify-content:center;gap:2.2cqh;background:#0b0f08d0;text-align:center;padding:4cqh;z-index:10}
.overlay h2{margin:0;font-size:5cqh;color:var(--amarelo);text-shadow:2px 2px 0 var(--escuro)}
.overlay p{margin:0;max-width:60cqw;font-size:2.4cqh;line-height:1.4;opacity:.92}
.btn{background:var(--laranja);color:#fff;border:none;border-radius:1cqw;padding:2cqh 5cqw;
  font-size:3cqh;font-weight:bold;cursor:pointer;box-shadow:0 0.6cqh 0 #a3441a}
.btn:active{transform:translateY(0.3cqh);box-shadow:0 0.3cqh 0 #a3441a}
.hidden{display:none!important}

#banner{position:absolute;top:14cqh;left:50%;transform:translateX(-50%);
  background:#000b;border:0.3cqw solid var(--amarelo);border-radius:1cqw;padding:1.4cqh 3cqw;
  font-weight:bold;font-size:2.6cqh;z-index:8;pointer-events:none;transition:opacity .3s;text-align:center}
