/**
 * Layout da página de jogo — tudo visível na viewport.
 * Tabuleiro só ocupa o espaço que sobra; HUD/bandeja/resgate não encolhem.
 */

body:has(.game-page),
#root:has(.game-page) {
  height: 100%;
  max-height: 100dvh;
  max-height: 100svh;
  overflow: hidden;
}

.game-page {
  box-sizing: border-box !important;
  width: 100%;
  height: 100dvh !important;
  height: 100svh !important;
  max-height: 100dvh !important;
  max-height: 100svh !important;
  min-height: 0 !important;
  margin: 0 !important;

  display: grid !important;
  grid-template-columns: minmax(0, 460px);
  /* HUD | tabuleiro (flexível) | bandeja | resgate */
  grid-template-rows: auto minmax(0, 1fr) auto auto;
  justify-content: center;
  justify-items: center;
  align-content: stretch;
  gap: 0;

  padding-top: max(80px, calc(52px + env(safe-area-inset-top, 0px))) !important;
  padding-right: 12px !important;
  padding-bottom: max(14px, calc(8px + env(safe-area-inset-bottom, 0px))) !important;
  padding-left: 12px !important;

  overflow: hidden !important;
  touch-action: none !important;
  -webkit-user-select: none;
  user-select: none;
}

/* filhos fora da coluna central ocupam a largura útil */
.game-page > * {
  max-width: min(460px, 100%);
  width: 100%;
}

/* ── HUD ─────────────────────────────────────────────────────────────────── */
.bb-hud,
.game-hud {
  grid-row: 1;
  position: relative;
  z-index: 5;
  margin: 0 0 2px;
  padding: 0 2px 4px;
}

.bb-hud-score {
  margin: 2px 0 4px !important;
  font-size: clamp(1.2rem, 5vw, 2rem) !important;
  line-height: 1 !important;
}

.bb-hud-corner {
  font-size: clamp(0.9rem, 3.6vw, 1.15rem) !important;
  padding: 1px 7px !important;
}

.bb-hud-icon {
  width: 20px !important;
  height: 20px !important;
}

.bb-hud-progress {
  width: min(180px, 52%) !important;
  height: 7px !important;
  margin-bottom: 0 !important;
}

.bb-demo-badge {
  margin-bottom: 0.2rem;
}

/* ── Tabuleiro (só a área flexível) ──────────────────────────────────────── */
.board-wrap {
  grid-row: 2;
  min-height: 0;
  min-width: 0;
  width: 100%;
  max-width: min(460px, 100%);
  margin: 0 auto;
  position: relative;
  z-index: 1;
  display: grid;
  place-items: center;
  container-type: size;
  touch-action: none;
}

.board-wrap > .board {
  width: min(100cqw, 100cqh);
  height: min(100cqw, 100cqh);
  max-width: 100%;
  max-height: 100%;
  aspect-ratio: 1 / 1;
  touch-action: none;
}

@supports not (width: 1cqw) {
  .board-wrap > .board {
    width: min(100%, 100%);
    height: auto;
    max-height: 100%;
    aspect-ratio: 1 / 1;
    /* limita pela altura disponível do grid row */
    max-width: min(460px, 100%, 100%);
  }
}

.board {
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  align-content: stretch;
  justify-content: stretch;
  min-height: 0;
}

.board > .cell {
  min-width: 0;
  min-height: 0;
  width: 100%;
  height: 100%;
  aspect-ratio: auto;
  align-self: stretch;
  justify-self: stretch;
}

.board-fall-layer {
  position: absolute;
  inset: 0;
  margin: auto;
  width: min(100cqw, 100cqh);
  height: min(100cqw, 100cqh);
  max-width: 100%;
  max-height: 100%;
  pointer-events: none;
}

@supports not (width: 1cqw) {
  .board-fall-layer {
    width: 100%;
    height: 100%;
  }
}

.board-fall-layer > .cell,
.board-fall-layer > .cell-ghost {
  min-width: 0;
  min-height: 0;
  width: 100%;
  height: 100%;
}

.board-locked-msg {
  grid-row: 2;
  align-self: end;
  justify-self: center;
  margin: 0 0 4px !important;
  font-size: clamp(0.9rem, 3.2vw, 1.15rem) !important;
  pointer-events: none;
  z-index: 3;
}

/* ── Bandeja: altura FIXA (não cresce por aspect-ratio) ───────────────────── */
.tray {
  grid-row: 3;
  width: 100%;
  max-width: min(460px, 100%);
  margin: 4px auto 0 !important;
  gap: 8px !important;
  display: grid !important;
  grid-template-columns: repeat(3, 1fr);
  /* altura dos containers controlada aqui — peças mantêm tamanho original */
  grid-auto-rows: 78px;
  align-items: center;
  touch-action: none;
}

.tray-slot {
  width: 100%;
  height: 78px !important;
  min-height: 78px !important;
  max-height: 78px !important;
  aspect-ratio: auto !important;
  place-items: center;
  box-sizing: border-box;
  padding: 4px !important;
  overflow: visible;
}

/* ── Resgatar: sempre na última linha, nunca cortado ─────────────────────── */
.cashout-btn {
  grid-row: 4;
  width: 100%;
  max-width: min(460px, 100%);
  margin: 6px auto 0 !important;
  padding-top: 12px !important;
  padding-bottom: 12px !important;
  font-size: 0.95rem !important;
  z-index: 6;
}

/* Mute fica fixed no CSS original — ok */

/* ── Telas mais baixas: compacta HUD/bandeja, tabuleiro só encolhe o resto ─ */
@media (max-height: 780px) {
  .game-page {
    padding-top: max(72px, calc(44px + env(safe-area-inset-top, 0px))) !important;
    padding-bottom: max(10px, calc(6px + env(safe-area-inset-bottom, 0px))) !important;
  }

  .bb-hud-score {
    font-size: clamp(1.1rem, 4.5vw, 1.75rem) !important;
    margin: 1px 0 3px !important;
  }

  .tray {
    grid-auto-rows: 70px;
    margin-top: 2px !important;
    gap: 6px !important;
  }

  .tray-slot {
    height: 70px !important;
    min-height: 70px !important;
    max-height: 70px !important;
  }

  .cashout-btn {
    margin-top: 4px !important;
    padding-top: 10px !important;
    padding-bottom: 10px !important;
  }
}

@media (max-height: 680px) {
  .game-page {
    padding-top: max(64px, calc(36px + env(safe-area-inset-top, 0px))) !important;
  }

  .bb-hud-corner {
    font-size: clamp(0.82rem, 3.2vw, 1rem) !important;
  }

  .bb-hud-icon {
    width: 17px !important;
    height: 17px !important;
  }

  .bb-hud-progress {
    height: 6px !important;
  }

  .tray {
    grid-auto-rows: 64px;
  }

  .tray-slot {
    height: 64px !important;
    min-height: 64px !important;
    max-height: 64px !important;
    padding: 2px !important;
  }
}

@media (max-height: 580px) {
  .game-page {
    padding-top: max(56px, calc(28px + env(safe-area-inset-top, 0px))) !important;
    padding-bottom: max(8px, env(safe-area-inset-bottom, 0px)) !important;
  }

  .bb-hud-score {
    font-size: clamp(1rem, 4vw, 1.45rem) !important;
  }

  .tray {
    grid-auto-rows: 58px;
  }

  .tray-slot {
    height: 58px !important;
    min-height: 58px !important;
    max-height: 58px !important;
  }

  .cashout-btn {
    margin-top: 3px !important;
    padding-top: 9px !important;
    padding-bottom: 9px !important;
  }
}

@media (max-width: 360px) {
  .game-page {
    padding-left: 8px !important;
    padding-right: 8px !important;
  }
}
