/* Economia de Fichas (scripts/features/utilities/token-economy.js). */
.tokens-page {
  display: grid;
  gap: 20px;
}

/* Quadros e prêmio: os tamanhos (--slot, --prize, --gap, --columns) vêm do JS, para caber na tela. */
.tokens-board {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--gap, 20px);
  height: var(--board-height, auto);
}

.tokens-board.is-landscape {
  flex-direction: row;
  gap: calc(var(--gap, 20px) * 2);
}

.tokens-grid {
  display: grid;
  grid-template-columns: repeat(var(--columns, 3), var(--slot, 140px));
  gap: var(--gap, 20px);
  justify-content: center;
}

.tokens-slot,
.tokens-prize {
  position: relative;
  display: grid;
  place-items: center;
  height: auto;
  min-height: 0;
  padding: 10%;
  border: max(4px, calc(var(--slot, 140px) * 0.035)) solid #1f2a3a;
  border-radius: 18%;
  background: #ffffff;
  box-shadow: 0 6px 0 rgba(31, 42, 58, 0.14);
  cursor: pointer;
  box-sizing: border-box;
  transition: transform 120ms ease;
}

.tokens-slot {
  width: var(--slot, 140px);
  aspect-ratio: 1;
}

.tokens-slot:active,
.tokens-prize.is-won:active {
  transform: scale(0.96);
}

.tokens-slot img,
.tokens-prize img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
}

.tokens-slot.is-new img {
  animation: tokens-pop 420ms cubic-bezier(0.2, 1.6, 0.4, 1);
}

@keyframes tokens-pop {
  from { opacity: 0; transform: scale(0.2) rotate(-25deg); }
}

.tokens-prize-area {
  display: grid;
  justify-items: center;
  gap: 8px;
}

.tokens-prize-label {
  color: #1f2a3a;
  font-size: clamp(1.2rem, calc(var(--prize, 200px) * 0.11), 2rem);
  font-weight: 900;
  letter-spacing: 0.04em;
  line-height: 1.2;
}

.tokens-prize {
  width: var(--prize, 200px);
  aspect-ratio: 1;
  border-width: max(5px, calc(var(--prize, 200px) * 0.035));
  cursor: default;
}

/* Prêmio ainda não ganho: aparece apagado, para a criança saber o que vem. */
.tokens-prize:not(.is-won) img {
  opacity: 0.22;
  filter: grayscale(1);
}

.tokens-prize.is-won {
  border-color: #f0a20b;
  background: #fff8e1;
  cursor: pointer;
  animation: tokens-win 1.6s ease-in-out infinite;
}

.tokens-prize.is-new img {
  animation: tokens-pop 520ms cubic-bezier(0.2, 1.6, 0.4, 1);
}

@keyframes tokens-win {
  0%, 100% { box-shadow: 0 0 0 0 rgba(240, 162, 11, 0.55), 0 6px 0 rgba(31, 42, 58, 0.14); transform: scale(1); }
  50% { box-shadow: 0 0 0 calc(var(--prize, 200px) * 0.08) rgba(240, 162, 11, 0), 0 6px 0 rgba(31, 42, 58, 0.14); transform: scale(1.04); }
}

/* ---------- Escolha da ficha e do prêmio (barra lateral) ---------- */
.tokens-choices {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 6px;
  border: 1px solid #dce8f1;
  border-radius: 14px;
  background: #ffffff;
  box-shadow: 0 5px 14px rgba(53, 91, 122, 0.11);
}

.tokens-choice {
  position: relative;
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
  min-height: 0;
  padding: 6px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--app-blue-dark, #0f78b5);
  font: inherit;
  cursor: pointer;
}

.tokens-choice img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.tokens-choice.is-other {
  grid-template-rows: 1fr auto;
  padding: 4px 4px 2px;
}

.tokens-choice.is-other b {
  font-size: 1.4rem;
  line-height: 1;
}

.tokens-choice.is-other img {
  width: 30px;
  height: 30px;
}

.tokens-choice small {
  font-size: 0.68rem;
  font-weight: 900;
}

.tokens-choice.is-selected {
  background: #e9f6ff;
  box-shadow: inset 0 0 0 2px var(--app-blue, #1ca7f2);
}

/* Fundo escuro: os quadros continuam brancos. */
body.utility-dark .tokens-prize-label {
  color: #f1f5f9;
}

body.utility-dark .tokens-slot,
body.utility-dark .tokens-prize {
  box-shadow: 0 6px 0 rgba(0, 0, 0, 0.35);
}

@media (prefers-reduced-motion: reduce) {
  .tokens-prize.is-won,
  .tokens-slot.is-new img,
  .tokens-prize.is-new img { animation: none; }
}

/* Tela cheia: espaço no alto para os botões de tela cheia e cadeado não cobrirem os quadros. */
body:is(.utility-focus, .utility-locked) .tokens-page {
  padding-top: 52px;
}

/* ---------- Ficha automática ---------- */
.us-button.is-auto-off,
.us-button.is-auto-on {
  border: 0;
  border-radius: 8px;
  color: #ffffff;
}

.us-button.is-auto-off {
  background: #22b35e;
  box-shadow: 0 5px 0 #15803d, 0 9px 18px rgba(21, 128, 61, 0.2);
}

.us-button.is-auto-on {
  background: #8b5cf6;
  box-shadow: 0 5px 0 #6d28d9, 0 9px 18px rgba(109, 40, 217, 0.22);
}

/* Janela flutuante: aparece no meio da tela, por cima de qualquer módulo. */
.tokens-popup {
  position: fixed;
  inset: 0;
  z-index: 360;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(15, 23, 42, 0.45);
  animation: tokens-popup-fade 0.25s ease;
}

.tokens-popup-card {
  position: relative;
  display: grid;
  justify-items: center;
  gap: 14px;
  width: min(820px, 100%);
  max-height: calc(100dvh - 32px);
  overflow: auto;
  padding: 22px 24px 26px;
  border-radius: 26px;
  background: #ffffff;
  box-shadow: 0 24px 60px rgba(15, 23, 42, 0.35);
  box-sizing: border-box;
  animation: tokens-popup-in 0.4s cubic-bezier(0.2, 1.4, 0.4, 1);
}

.tokens-popup-card.is-dark {
  background: #1f2a3a;
}

.tokens-popup-card h3 {
  margin: 0;
  color: #1f2a3a;
  font-size: clamp(1.3rem, 3vw, 1.9rem);
  font-weight: 900;
}

.tokens-popup-card.is-dark h3,
.tokens-popup-card.is-dark .tokens-prize-label {
  color: #ffffff;
}

.tokens-popup .tokens-board {
  height: auto;
}

.tokens-popup .tokens-slot,
.tokens-popup .tokens-prize {
  cursor: default;
}

.tokens-popup .tokens-prize.is-won {
  cursor: pointer;
}

.tokens-popup-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: #eef2f7;
  color: #1f2a3a;
  font: inherit;
  font-size: 2rem;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
}

.tokens-popup-card.is-dark .tokens-popup-close {
  background: rgba(255, 255, 255, 0.15);
  color: #ffffff;
}

/* A ficha nova da janela entra mais devagar, para dar tempo de ver. */
.tokens-popup .tokens-slot.is-new img {
  animation: tokens-pop 900ms cubic-bezier(0.2, 1.6, 0.4, 1) 350ms both;
}

@keyframes tokens-popup-fade {
  from { opacity: 0; }
}

@keyframes tokens-popup-in {
  from { transform: scale(0.6); opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .tokens-popup,
  .tokens-popup-card,
  .tokens-popup .tokens-slot.is-new img { animation: none; }
}

/* Figura do prêmio e das fichas sempre dentro do cartão: qualquer formato (foto alta, larga...) fica inteira,
   centralizada e com a mesma margem, sem esticar o cartão. */
.tokens-slot img,
.tokens-prize img {
  position: absolute;
  inset: 10%;
  width: 80%;
  height: 80%;
  object-fit: contain;
  object-position: center;
}

.tokens-choice {
  overflow: hidden;
}

.tokens-choice img {
  min-width: 0;
  min-height: 0;
  max-height: 100%;
}
