:root {
  --ok: #2FBF84;
  --bad: #F2564B;
  --warn: #E5A019;
}

* { box-sizing: border-box; }
html { overscroll-behavior: none; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--fundo, #F3F1EC);
  background-attachment: fixed;
  color: var(--texto, #1A1A1A);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

/* Ecrã de jogo: número e barras em cima, tabuleiro a ocupar o meio, botões em baixo. Nada mexe entre toques. */
.app {
  max-width: 720px;
  margin: 0 auto;
  height: calc(100dvh - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
  display: flex;
  flex-direction: column;
  padding-block: 10px;
  padding-left: max(14px, env(safe-area-inset-left, 0px));
  padding-right: max(14px, env(safe-area-inset-right, 0px));
}
body:not(.lab) .so-lab { display: none !important; }
body.nativo .app { height: 100dvh; padding-top: calc(10px + env(safe-area-inset-top, 0px)); padding-bottom: calc(6px + env(safe-area-inset-bottom, 0px)); }
body.lab .app { height: auto; padding-bottom: 48px; }

.play-head { display: flex; align-items: center; gap: 12px; flex: none; }
#lv-num { font: var(--peso) 46px/1 var(--fonte); font-variant-numeric: lining-nums; min-width: 1.1em; }
#lv-num.bump { animation: bump .5s ease; }
@keyframes bump { 40% { transform: scale(1.2); } }
.level-info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.stage-line { display: flex; justify-content: space-between; gap: 10px; font-size: 12px; min-height: 14px; font-variant-numeric: tabular-nums; }
.streak { display: inline-flex; align-items: center; gap: 2px; color: var(--acento); }
.streak .ico { width: 13px; height: 13px; }
.bar { height: 9px; background: var(--tubo); border-radius: 5px; overflow: hidden; box-shadow: inset 0 1px 2px var(--tubo-sombra, transparent); }
#pts-bar { height: 100%; width: 0; background: var(--acento); border-radius: 5px; transition: width .5s ease; }

/* Barra de hipóteses: verde quando quase todas as arrumações possíveis ainda têm solução, vermelha quando nenhuma. */
.chance { display: flex; align-items: center; gap: 6px; font-size: 10px; }
.chance-track { flex: 1; min-width: 0; height: 5px; border-radius: 3px; background: var(--tubo); overflow: hidden; }
.chance-fill { height: 100%; width: 100%; border-radius: 3px; background-color: hsl(120, 72%, 46%); transition: width .5s ease, background-color .5s ease, opacity .2s; }
.chance.calc .chance-fill { opacity: .45; transition: width .5s ease, background-color .5s ease, opacity .3s .5s; }
.chance-pct { min-width: 3.2em; text-align: right; font-variant-numeric: tabular-nums; }

.note { font-size: 13px; margin: 6px 0 0; line-height: 1.4; }
/* Desafio extra e relógio: linha própria por cima do tabuleiro. */
.note.objective, .note.relogio { flex: none; display: flex; align-items: center; justify-content: center; gap: 5px; align-self: center; text-align: center; font-size: 12.5px; line-height: 1.3; margin: 5px 0 0; padding: 3px 12px; border: 1.5px solid var(--acento); border-radius: 14px; font-variant-numeric: tabular-nums lining-nums; }
.note.relogio.fim { opacity: .5; border-color: var(--linha); }
.objective .miniatura { font-size: 18px; vertical-align: -4px; margin: 0 1px; }
.relogio .ico { width: 16px; height: 16px; color: var(--acento); }
/* Faixa de avisos: lugar reservado, para o aviso nunca tapar nada nem empurrar o tabuleiro. */
.aviso { flex: none; height: 32px; margin-top: 3px; display: flex; align-items: center; justify-content: center; gap: 8px; text-align: center; font-size: 12.5px; line-height: 1.2; font-variant-numeric: lining-nums; opacity: 0; transition: opacity .2s; overflow: hidden; }
.aviso.on { opacity: 1; }
.aviso .ico { width: 16px; height: 16px; }
.aviso .pilula .ico { width: 16px; height: 16px; }
.stage { position: relative; flex: 1; min-height: 0; display: flex; align-items: center; }
/* Quadro mais largo do que o ecrã: desliza de lado dentro do seu espaço. */
.stage.desliza { overflow-x: auto; overflow-y: hidden; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
.stage.desliza::-webkit-scrollbar { display: none; }
.stage.desliza .board { flex: none; touch-action: pan-x; }
body.zen .bar, body.zen .chance { visibility: hidden; }
.board { position: relative; width: 100%; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; touch-action: manipulation; }
/* Quando o quadro cabe no ecrã, tocar nele nunca faz deslizar a página. */
.board.fits { touch-action: none; }

.tube { position: absolute; transition: opacity .15s, outline-color .15s; outline: 2px solid transparent; outline-offset: 1px; }
.tube.ok { outline-color: var(--ok); }
.tube.no { opacity: 0.45; }
.tube.closed { outline-color: color-mix(in srgb, var(--ok) 55%, transparent); }
.tube.hint { animation: pulse 0.9s ease-in-out 4; }
@keyframes pulse { 50% { outline-color: var(--acento); outline-offset: 5px; } }
.board.gold .tube { outline-color: rgba(246, 181, 42, .55); }
.board.flash .tube { animation: flash .7s ease; }
@keyframes flash { 50% { outline-color: var(--acento); } }
.tube.side { opacity: .92; }
.tube.no.side { opacity: .4; }

.hit { position: absolute; cursor: pointer; z-index: 6; }
.col-label { position: absolute; font-size: 12px; text-align: center; color: var(--texto); }
body:not(.lab) .col-label { display: none; }
/* O que cada coluna tem: miniaturas das próprias peças, com a quantidade ao lado. */
.counts { position: absolute; display: grid; grid-template-columns: repeat(2, auto); justify-content: center; align-content: start; gap: 2px; font-size: 10px; font-variant-numeric: tabular-nums lining-nums; color: var(--texto); }
.cnt { display: inline-flex; align-items: center; gap: 1px; }
.cnt b { font-weight: 600; min-width: 6px; }
.miniatura { position: relative; display: inline-flex; align-items: center; justify-content: center; flex: none; width: 1em; height: 1em; font-size: clamp(11px, calc(var(--s) * .3), 16px); }
.miniatura.azulejo { box-shadow: inset 0 0 0 .06em var(--a); }
.miniatura.azulejo svg { width: 76%; height: 76%; }
.miniatura svg, .miniatura svg.tema { width: 76%; height: 76%; }
.miniatura::after { display: none; }

.hand-slot { position: absolute; border: 1.5px dashed var(--linha); border-radius: 50%; }
.hand-label { display: none; }

.blk { position: absolute; left: 0; top: 0; perspective: 500px; pointer-events: none; z-index: 2; will-change: transform; font-size: var(--s, 48px); }
.blk.moving { z-index: 5; }
.blk .inner { position: relative; width: 100%; height: 100%; transform-style: preserve-3d; transform: rotateY(180deg); transition: transform .32s ease; }
.blk.up .inner { transform: rotateY(0deg); }
.face { position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden; display: flex; align-items: center; justify-content: center; }
.face.verso { transform: rotateY(180deg); }
.face svg.eye { position: absolute; left: 7%; top: 7%; width: 30%; height: 30%; fill: var(--g, #fff); }
.face.verso svg.eye.big { position: static; width: 55%; height: 55%; fill: var(--texto); opacity: .7; }

.acoes { flex: none; display: flex; justify-content: center; gap: 10px; padding-top: 8px; }
/* Os seis botões cabem sempre numa linha, mesmo no telefone mais estreito. */
.acoes .r { width: clamp(38px, calc((100vw - 78px) / 6), 48px); height: clamp(38px, calc((100vw - 78px) / 6), 48px); }
/* Os botões têm sempre o nome por baixo. */
body:not(.lab) .acoes { padding-bottom: 15px; }
body:not(.lab) .acoes .r::before { content: attr(data-rot); position: absolute; left: 50%; top: 100%; transform: translateX(-50%); margin-top: 4px; font-size: 10px; line-height: 1; white-space: nowrap; color: var(--texto); }

.overlay { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; padding: 16px; background: var(--veu, rgba(0, 0, 0, .4)); z-index: 30; }
.overlay.cheio { background: var(--fundo); background-attachment: fixed; }
.overlay.cheio .card { background: none; box-shadow: none; border: none; }
.overlay.com-roda .card { overflow: hidden; }
.card { background: var(--cartao); color: var(--texto); border: 1px solid var(--linha); border-radius: 20px; padding: 18px 20px; width: 100%; max-width: 360px; max-height: 100%; overflow: auto; text-align: center; }
.ov-title { font: var(--peso) 24px/1.2 var(--fonte); margin: 0 0 6px; }
.ov-title:empty, .ov-text:empty { display: none; }
.ov-text { margin: 0 0 14px; line-height: 1.5; opacity: .8; }
.ov-actions { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.ov-actions:empty { display: none; }
.ov-actions button, .controls button, .controls select { font: inherit; font-size: 14px; color: var(--texto); background: none; border: 1px solid var(--linha); border-radius: 22px; padding: 9px 16px; }
.ov-actions button.primary { background: var(--acento); border-color: var(--acento); color: #fff; }
.ov-actions button .ico { width: 24px; height: 24px; display: block; }
#ov-body .ganho, #ov-body > .contas { justify-content: center; }
#ov-body > .contas { margin-bottom: 8px; }
html[data-aspeto="noite"] .ov-actions button.primary { color: #1A1206; }

/* Painel entre níveis */
.painel { display: flex; flex-direction: column; align-items: center; gap: 30px; }
.ganho { display: flex; align-items: center; gap: 8px; font: var(--peso) 27px var(--fonte); font-variant-numeric: lining-nums; }
.ganho .ico { width: 24px; height: 24px; }
.ganho .sobe { color: var(--acento); }
.jogar .ico { width: 46%; height: 46%; }
.nota-painel { margin: -14px 0 0; display: flex; flex-direction: column; gap: 6px; align-items: center; font-size: 14px; }
.fim-painel { display: flex; gap: 16px; align-items: center; }
.painel .ganho .ico { width: 26px; height: 26px; }

/* Fim do nível: frase, número, tabela de pontos e símbolos do tema a cair. */
.titulo-painel { margin: 0; font: var(--peso) 28px/1.15 var(--fonte); text-align: center; }
.painel.com-tabela { gap: 12px; }
.painel.com-tabela .disco { width: 104px; height: 104px; font-size: 50px; }
.painel.com-tabela .disco::after { left: 18px; top: 12px; width: 26px; height: 13px; }
html[data-aspeto="abaco"] .painel.com-tabela .disco { width: auto; height: auto; font-size: 92px; }
/* Progresso no estádio: barra com a frase por baixo. */
.progresso-estadio { width: 100%; max-width: 300px; display: flex; flex-direction: column; gap: 4px; text-align: center; font-size: 12.5px; font-variant-numeric: lining-nums; }
.bar > div:not(#pts-bar) { height: 100%; background: var(--acento); border-radius: 5px; }
/* Recibo dos pontos: cartão com uma linha por parcela, multiplicadores numa só linha e total em destaque. */
.recibo { width: 100%; max-width: 300px; box-sizing: border-box; padding: 8px 12px 10px; border-radius: 18px; background: color-mix(in srgb, var(--cartao) 80%, transparent); box-shadow: 0 6px 16px var(--sombra), inset 0 0 0 1px var(--linha); }
.linha-pontos { display: flex; align-items: center; gap: 8px; padding: 3px 0; font-size: 14px; font-variant-numeric: tabular-nums lining-nums; animation: entra .3s ease backwards; }
.linha-pontos .ico { width: 18px; height: 18px; flex: none; opacity: .75; }
.linha-pontos span { flex: 1; min-width: 0; text-align: left; }
.linha-pontos b { font: var(--peso) 16px var(--fonte); font-variant-numeric: lining-nums; }
.linha-pontos.menos, .linha-pontos.menos b { color: var(--bad); }
.multiplicadores { display: flex; flex-wrap: wrap; gap: 5px; justify-content: center; padding: 5px 0 2px; animation: entra .3s ease backwards; }
.multiplicadores span { padding: 2px 9px; border-radius: 999px; background: var(--acento); color: #fff; font-size: 12px; font-variant-numeric: lining-nums; }
html[data-aspeto="noite"] .multiplicadores span { color: #1A1206; }
.total-recibo { display: flex; align-items: baseline; justify-content: space-between; margin-top: 6px; padding-top: 6px; border-top: 1.5px solid var(--linha); font-weight: 600; animation: entra .3s ease backwards; }
.total-recibo b { font: var(--peso) 30px/1 var(--fonte); font-variant-numeric: lining-nums; color: var(--acento); }
@keyframes entra { from { opacity: 0; transform: translateY(6px); } }
.festa { position: fixed; inset: 0; overflow: hidden; pointer-events: none; z-index: 0; }
.queda { position: absolute; top: -30px; animation: cai 2s ease-in 1 both; }
.queda .miniatura { font-size: 24px; }
@keyframes cai { to { transform: translateY(110vh) rotate(300deg); } }
.overlay.cheio .painel { position: relative; z-index: 1; }
.enfeites { display: flex; justify-content: center; gap: 8px; }
.enfeites .miniatura { font-size: 34px; }
.enfeites .miniatura:nth-child(even) { transform: translateY(8px) rotate(-10deg); }

/* Ícone com número: avisos, prémios e notas */
.pilula { display: inline-flex; align-items: center; gap: 3px; font-variant-numeric: lining-nums; }
.pilula .ico { width: 20px; height: 20px; }
.pilula b { font-weight: 600; }
.medalha { display: inline-flex; width: 26px; height: 26px; }
.medalha .ico { width: 100%; height: 100%; stroke-width: 2.2; }
.medalha.grande { width: 96px; height: 96px; }
.topo-painel { display: flex; gap: 14px; justify-content: center; align-items: center; margin: 0 0 12px; font-variant-numeric: tabular-nums; }
.note .ico { width: 18px; height: 18px; }

/* Missões */
.missao { display: flex; align-items: center; gap: 12px; margin: 0 0 14px; font-size: 14px; text-align: left; font-variant-numeric: tabular-nums; }
.missao > .ico { width: 26px; height: 26px; flex: none; }
.missao-meio { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 5px; }
.missao .bar div { height: 100%; background: var(--acento); border-radius: 5px; }
.missao .fim { width: 38px; display: inline-flex; justify-content: flex-end; flex: none; }
.missao .fim .ico { width: 20px; height: 20px; color: var(--ok); }

/* Roda da sorte: as peças do jogo pousadas num prato com aro. As cores do prato e do aro vêm de cada aspeto. */
.roda-caixa { position: relative; width: min(290px, 74vw); aspect-ratio: 1; margin: 26px auto 20px; }
.aro { position: absolute; inset: -13px; border-radius: 50%; box-shadow: 0 14px 28px var(--sombra); background: var(--roda-aro); }
.roda { position: absolute; inset: 0; border-radius: 50%; overflow: hidden; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .12); }
.brilho { position: absolute; inset: 0; border-radius: 50%; pointer-events: none; z-index: 1; background: radial-gradient(70% 45% at 50% 14%, rgba(255, 255, 255, .34), transparent 70%), radial-gradient(circle at 50% 50%, transparent 72%, rgba(0, 0, 0, .13) 100%); }
.raio { position: absolute; left: 50%; top: 0; width: 1px; height: 50%; margin-left: -.5px; transform-origin: 50% 100%; background: rgba(0, 0, 0, .1); }
.pino { position: absolute; left: 50%; top: 50%; width: 9px; height: 9px; margin: -4.5px; border-radius: 50%; background: radial-gradient(circle at 35% 30%, #fff, #E2DBD2 70%, #B9AFA3); box-shadow: 0 1px 2px rgba(0, 0, 0, .35); }
.fatia { position: absolute; left: 50%; top: 50%; width: 0; height: 0; }
.rotulo { position: absolute; left: -.5em; top: -.5em; width: 1em; height: 1em; font-size: min(60px, 16vw); display: flex; align-items: center; justify-content: center; color: var(--g); }
.rotulo .pilula { flex-direction: column; gap: 0; font: var(--peso) 13px/1 var(--fonte); font-variant-numeric: lining-nums; position: relative; }
.rotulo.peca svg.ico { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; filter: none; }
.rotulo b { font-weight: inherit; }
.rotulo > b { font: var(--peso) 21px var(--fonte); position: relative; }
.rotulo.peca.esmalte::after, .rotulo.peca.noite::after { z-index: 0; }
.fatia.ganhou .rotulo { box-shadow: 0 0 0 3px var(--acento), 0 0 0 7px color-mix(in srgb, var(--acento) 30%, transparent); }
.miolo { position: absolute; inset: 39%; border-radius: 50%; z-index: 2; display: flex; align-items: center; justify-content: center; color: #fff; background: var(--roda-aro); box-shadow: 0 3px 8px rgba(0, 0, 0, .3), inset 0 0 0 2px rgba(255, 255, 255, .5); }
.miolo .ico { width: 54%; height: 54%; }
.ponteiro { position: absolute; left: 50%; top: -26px; z-index: 3; width: 34px; height: 34px; margin-left: -17px; border-radius: 50% 50% 50% 4px; transform: rotate(-45deg); background: var(--roda-aro); box-shadow: -2px 3px 6px rgba(0, 0, 0, .35), inset 0 0 0 2px rgba(255, 255, 255, .55); }
.roda-fim { min-height: 28px; margin-bottom: 10px; text-align: center; font-size: 16px; line-height: 1.3; }
.overlay.com-roda .ov-title { margin-bottom: 0; }

/* Escolha do aspeto */
.grelha-aspetos { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 8px 0 14px; }
.cartao-aspeto { padding: 0; border: 2px solid var(--linha); border-radius: 16px; background: none; overflow: hidden; color: var(--texto); font: inherit; }
.cartao-aspeto.on { border-color: var(--acento); box-shadow: 0 0 0 2px var(--acento); }
.cartao-aspeto .vista { display: flex; justify-content: center; gap: 4px; padding: 16px 6px; font-size: 34px; }
.cartao-aspeto .nome { display: block; padding: 7px; font-size: 14px; }
.chip-simbolo { display: inline-flex; align-items: center; gap: 6px; padding: 5px 12px 5px 6px; border: 2px solid var(--linha); border-radius: 22px; background: none; color: var(--texto); font-family: inherit; font-size: 22px; }
.chip-simbolo span:last-child { font-size: 13px; }
.chip-simbolo.on { border-color: var(--acento); box-shadow: 0 0 0 1px var(--acento); }
.linha-simbolos { display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; margin-bottom: 14px; }
.menu-titulo { margin: 0; font-size: 13px; opacity: .75; }
.abas { display: flex; width: 100%; margin-bottom: 10px; }
.abas button { flex: 1; min-width: 0; padding: 6px 2px; font-size: 11px; }
.ganho.grande { font-size: 40px; margin: 18px 0; }

/* Convites */
.qr-caixa { background: #fff; border-radius: 14px; padding: 6px; width: min(230px, 62vw); margin: 4px auto 10px; }
.qr { display: block; width: 100%; height: auto; }
.conv-url { width: 100%; margin: 0 0 10px; padding: 7px 10px; border: 1px solid var(--linha); border-radius: 10px; background: none; color: var(--texto); font-size: 12px; text-align: center; }
.regras-convite { text-align: left; margin: 0 0 12px; padding-left: 18px; font-size: 13px; line-height: 1.45; }

/* Novidade: aponta no tabuleiro o que é novo */
.tube.foco { outline-color: var(--acento); animation: pulse .9s ease-in-out infinite; }
.blk.foco::before { content: ''; position: absolute; inset: -5px; border-radius: 50%; border: 3px solid var(--acento); animation: anel 1s ease-in-out infinite; }
@keyframes anel { 50% { transform: scale(1.14); opacity: .5; } }

/* Menu */
.card.menu { display: flex; flex-direction: column; gap: 10px; align-items: stretch; }
.menu-lista { display: flex; flex-direction: column; }
.linha-menu { display: flex; align-items: center; gap: 12px; width: 100%; padding: 10px 4px; border: none; border-bottom: 1px solid var(--linha); background: none; color: var(--texto); font: inherit; font-size: 15px; text-align: left; box-sizing: border-box; }
.linha-menu .ico { width: 24px; height: 24px; flex: none; }
.linha-menu span { flex: 1; min-width: 0; }
.linha-menu b { font-weight: 600; font-variant-numeric: tabular-nums; font-size: 14px; }
.menu-fim { display: flex; gap: 12px; justify-content: center; margin-top: 4px; }
.check-inline { display: flex; align-items: center; justify-content: center; gap: 6px; font-size: 13px; }

.modes { display: inline-flex; border: 1px solid var(--linha); border-radius: 12px; padding: 3px; gap: 3px; margin-bottom: 10px; }
.modes button { border: none; background: transparent; color: var(--texto); padding: 6px 14px; border-radius: 9px; font: inherit; font-size: 14px; opacity: .6; }
.modes button.on { background: var(--tubo); opacity: 1; }
.modes.small { margin: 0; align-self: center; }
.modes.small button { min-width: 44px; font-size: 13px; padding: 6px 10px; }

.shake { animation: shake .25s; }
@keyframes shake { 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }

.wheel { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 5px; margin: 4px 0 12px; }
.prize { border: 1px solid var(--linha); border-radius: 10px; padding: 6px; font-size: 12px; line-height: 1.3; }
.prize.hl { border-color: var(--acento); background: color-mix(in srgb, var(--acento) 18%, transparent); }
.prize.neg { color: var(--bad); }

.rank-wrap { max-height: 260px; overflow: auto; margin: 0 0 12px; }
.rank { width: 100%; border-collapse: collapse; font-size: 14px; text-align: left; }
.rank td { padding: 5px 6px; border-bottom: 1px solid var(--linha); }
.rank td.num { text-align: right; font-variant-numeric: tabular-nums; }
.rank tr.me td { color: var(--acento); font-weight: 600; }
.rank tr.up td:first-child { color: var(--ok); }
.rank tr.down td:first-child { color: var(--bad); }
.missions { text-align: left; margin: 0 0 14px; padding-left: 18px; line-height: 1.7; font-size: 14px; }
.missions li.done { color: var(--ok); }

/* Laboratório */
.top h1 { font-size: 16px; font-weight: 600; margin: 12px 0 0; }
.controls, .custom, .status { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 10px; }
.custom { background: var(--cartao); border: 1px solid var(--linha); border-radius: 10px; padding: 10px; }
.custom label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; }
.custom input { width: 90px; padding: 5px 8px; }
.custom label.check { flex-direction: row; align-items: center; gap: 6px; font-size: 13px; }
.custom label.check input { width: auto; padding: 0; }
.status { font-size: 13px; gap: 14px; margin-top: 10px; }
.warn-toggle { display: flex; gap: 6px; align-items: center; }
.msg { height: 2.7em; line-height: 1.35; overflow: hidden; font-size: 14px; margin: 6px 0; }
.msg.bad { color: var(--bad); }
.msg.warn { color: var(--warn); }
.msg.ok { color: var(--ok); }
.msg.tip { color: var(--acento); }
