/* Tela de partida: arena em canvas e camadas em DOM posicionadas pelo layout (src/ui/layout.js). */

body.game-page {
  position: fixed;
  inset: 0;
  overflow: hidden;
  /* Sem rolagem, pinça, toque duplo nem seleção de texto durante a partida. */
  touch-action: none;
  overscroll-behavior: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  /* Sem o retângulo de realce do Chrome Android ao tocar; os botões respondem pelo :active. */
  -webkit-tap-highlight-color: transparent;
}

.game {
  position: fixed;
  inset: 0;
  overflow: hidden;
  touch-action: none;
}

/* Fundo decorativo (laterais no desktop): noite violeta com runas tênues. */
.backdrop {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse 60% 45% at 50% 42%, rgba(124, 58, 237, 0.24), transparent 70%),
    radial-gradient(ellipse 70% 40% at 50% 110%, rgba(63, 141, 255, 0.16), transparent 70%),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='96' height='96'%3E%3Cg fill='none' stroke='%239a66ff' stroke-opacity='0.11' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M24 12v24M15 18l9 8 9-8'/%3E%3Cpath d='M72 58l8 12-8 12-8-12z'/%3E%3Cpath d='M66 14l12 12M78 14l-12 12'/%3E%3Cpath d='M18 64v20M18 70l10-6'/%3E%3C/g%3E%3C/svg%3E"),
    linear-gradient(#191c30, #0d0f1a);
}

.arena {
  position: absolute;
  display: block;
  background: #2f6b3a;
  touch-action: none;
}

.game.has-sides .arena {
  border-radius: 10px;
  box-shadow:
    0 0 0 3px #3a3356,
    0 0 0 6px #120e1f,
    0 22px 60px rgba(0, 0, 0, 0.6),
    0 0 90px rgba(124, 58, 237, 0.28);
}

.game.is-armed .arena {
  cursor: crosshair;
}

/* Barra do topo: itens nos cantos, o centro fica livre para o Bastião inimigo. */
.topbar {
  position: absolute;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 0 6px;
  pointer-events: none;
}

.topbar > * {
  pointer-events: auto;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 6px;
  pointer-events: none;
}

.topbar-right > * {
  pointer-events: auto;
}

/* Placar no canto; o selo do modo pendura logo abaixo, sobre as árvores da borda. */
.topbar-left {
  position: relative;
  pointer-events: none;
}

.topbar-left .scoreboard {
  pointer-events: auto;
}

.scoreboard {
  display: flex;
  align-items: center;
  gap: 6px;
  height: 34px;
  padding: 0 10px;
  border: 2px solid var(--outline);
  border-radius: 999px;
  background: rgba(18, 14, 34, 0.78);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.12), 0 2px 0 rgba(0, 0, 0, 0.35);
  font-family: var(--font-display);
  font-size: 20px;
  line-height: 1;
}

.rune-count {
  min-width: 12px;
  text-align: center;
  -webkit-text-stroke: 3px var(--outline);
  paint-order: stroke fill;
}

.rune-sep {
  color: var(--muted);
  font-size: 15px;
}

.rune-gem {
  width: 13px;
  height: 13px;
  border: 2px solid var(--outline);
  border-radius: 3px;
  transform: rotate(45deg);
}

.rune-gem--blue {
  background: linear-gradient(135deg, #b7dcff, var(--blue) 60%);
}

.rune-gem--red {
  background: linear-gradient(135deg, #ffc1c4, var(--red) 60%);
}

.mode-tag {
  position: absolute;
  left: 4px;
  top: calc(100% + 3px);
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(18, 14, 34, 0.7);
  color: #d8c8ff;
  font-family: var(--font-display);
  font-size: 12px;
  letter-spacing: 0.3px;
  white-space: nowrap;
  pointer-events: none;
}

/* Nome de quem você enfrenta, com a gema do lado de cima antes. */
.mode-tag--opponent {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px 3px 8px;
  border: 2px solid var(--red-dark);
  background: rgba(18, 14, 34, 0.82);
  color: #ffe3e5;
  font-size: 13px;
  max-width: 46vw;
  overflow: hidden;
  text-overflow: ellipsis;
}

.mode-tag--opponent::before {
  content: '';
  flex: none;
  width: 8px;
  height: 8px;
  border: 2px solid var(--outline);
  border-radius: 2px;
  transform: rotate(45deg);
  background: linear-gradient(135deg, #ffc1c4, var(--red) 60%);
}

.mode-tag--opponent[hidden] {
  display: none;
}

/* Botões de pedra. */
.icon-btn,
.act-btn,
.tool-btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--outline);
  border-radius: 12px;
  background: linear-gradient(#514a72, #36304f);
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.14), 0 3px 0 #120e1f;
  color: var(--text);
  cursor: pointer;
  touch-action: manipulation;
}

.icon-btn:active,
.act-btn:active,
.tool-btn:active {
  transform: translateY(2px);
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.14), 0 1px 0 #120e1f;
}

.icon-btn:focus-visible,
.act-btn:focus-visible,
.tool-btn:focus-visible {
  outline: 2px solid #c9a8ff;
  outline-offset: 2px;
}

.icon-btn {
  width: 44px;
  height: 44px;
  padding: 0;
}

.icon-pause,
.icon-pause::after {
  display: block;
  width: 6px;
  height: 18px;
  border-radius: 2px;
  background: #f5f3ff;
  box-shadow: 0 0 0 2px var(--outline);
}

.icon-pause {
  position: relative;
  left: -5px;
}

.icon-pause::after {
  content: "";
  position: absolute;
  left: 10px;
  top: 0;
}

.icon-btn[aria-pressed="true"] .icon-pause,
.icon-btn[aria-pressed="true"] .icon-pause::after {
  background: #c9a8ff;
}

/* Faixa de baixo: a mão na partida, os botões da demonstração fora dela. */
.hud {
  position: absolute;
  z-index: 4;
  touch-action: none;
  background: linear-gradient(rgba(16, 12, 32, 0), rgba(16, 12, 32, 0.9) 12px, rgba(12, 10, 26, 0.97));
}

.debug-panel {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 7px;
  min-height: 0;
  width: 100%;
  padding: 8px;
  border: 2px solid var(--outline);
  border-radius: 14px;
  background: rgba(16, 12, 32, 0.94);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.45);
}

.debug-row {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
  touch-action: pan-x;
  /* Folga para a sombra dos botões não ser cortada. */
  padding: 1px 1px 4px;
  margin: -1px -1px -4px;
}

.debug-row::-webkit-scrollbar {
  display: none;
}

.tool-btn {
  flex: 1 0 44px;
  min-width: 44px;
  height: 54px;
  flex-direction: column;
  gap: 0;
  padding: 2px 1px 3px;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: -0.3px;
  line-height: 1.1;
}

.tool-btn span {
  max-width: 100%;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  text-shadow: 0 1px 0 var(--outline);
}

.tool-btn canvas {
  display: block;
  pointer-events: none;
}

.tool-btn[aria-pressed="true"] {
  background: linear-gradient(#8f63f7, #5d34c4);
  box-shadow: 0 0 0 2px #d9c6ff, 0 3px 0 #120e1f, 0 0 16px rgba(154, 102, 255, 0.75);
}

.tool-icon {
  display: block;
  width: 30px;
  height: 30px;
  position: relative;
}

/* Eliminar: um X de pedra; Ferir: uma gota partida ao meio. */
.icon-kill::before,
.icon-kill::after {
  content: "";
  position: absolute;
  left: 12px;
  top: 3px;
  width: 7px;
  height: 24px;
  border-radius: 3px;
  background: #ff8a8f;
  box-shadow: 0 0 0 2px var(--outline);
  transform: rotate(45deg);
}

.icon-kill::after {
  transform: rotate(-45deg);
}

.icon-hurt::before {
  content: "";
  position: absolute;
  left: 7px;
  top: 7px;
  width: 16px;
  height: 16px;
  border: 2px solid var(--outline);
  border-radius: 0 50% 50% 50%;
  background: linear-gradient(90deg, #ff6b74 50%, #4a4466 50%);
  transform: rotate(45deg);
}

.act-btn {
  /* Não encolhe abaixo do texto: se faltar largura, a fileira rola na horizontal. */
  flex: 1 0 auto;
  min-width: 44px;
  height: 44px;
  gap: 5px;
  padding: 0 7px;
  font-family: var(--font-display);
  font-size: 14px;
  letter-spacing: 0.2px;
  white-space: nowrap;
}

.act-btn span {
  -webkit-text-stroke: 2px var(--outline);
  paint-order: stroke fill;
}

.act-btn:disabled {
  opacity: 0.45;
  cursor: default;
  transform: none;
}

.act-btn--toggle[aria-pressed="true"] {
  background: linear-gradient(#8f63f7, #5d34c4);
  box-shadow: 0 0 0 2px #d9c6ff, 0 3px 0 #120e1f;
}

/* Cartas de teste: o botão do grupo abre a fileira e troca o grupo a cada toque. */
.group-btn {
  flex: 0 0 auto;
  height: 54px;
  max-width: 92px;
  padding: 0 8px;
  font-size: 12.5px;
  white-space: normal;
  line-height: 1.05;
  text-align: center;
  background: linear-gradient(#6b5aa0, #463a72);
}

.group-arrow {
  flex: 0 0 auto;
  width: 8px;
  height: 8px;
  border-right: 3px solid #f5f3ff;
  border-bottom: 3px solid #f5f3ff;
  transform: rotate(-45deg);
}

/* Retrato do motor de arte, com a própria moldura. */
.card-btn canvas {
  border-radius: 3px;
  margin-bottom: 1px;
}

.card-btn[hidden] {
  display: none;
}

.act-btn--icon {
  flex: 0 0 44px;
}

.side-btn {
  flex: 0 0 auto;
}

.side-short {
  display: none;
}

/* Rola só quando não cabe; o esmaecido na borda avisa que há mais botões. */
.debug-row.is-scrollable {
  -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 22px), transparent);
  mask-image: linear-gradient(to right, #000 calc(100% - 22px), transparent);
}

@media (max-width: 380px) {
  .debug-row {
    gap: 3px;
  }

  .act-btn {
    padding: 0 5px;
    font-size: 12.5px;
  }

  .side-full {
    display: none;
  }

  .side-short {
    display: inline;
  }
}

.side-btn[data-side="0"] {
  background: linear-gradient(#5aa2ff, #2d6fd6);
}

.side-btn[data-side="1"] {
  background: linear-gradient(#ff707a, #c9323f);
}

.side-dot {
  width: 12px;
  height: 12px;
  border: 2px solid var(--outline);
  border-radius: 3px;
  background: #fff;
  transform: rotate(45deg);
}

.icon-chevron {
  width: 12px;
  height: 12px;
  border-right: 4px solid #f5f3ff;
  border-bottom: 4px solid #f5f3ff;
  transform: translateY(-3px) rotate(45deg);
  filter: drop-shadow(0 0 1px var(--outline));
}

.debug-hint {
  position: absolute;
  left: 50%;
  bottom: calc(100% + 12px);
  margin: 0;
  padding: 7px 12px;
  border: 2px solid var(--outline);
  border-radius: 999px;
  background: rgba(18, 14, 34, 0.9);
  color: #efe6ff;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  transform: translateX(-50%);
  opacity: 0;
  pointer-events: none;
}

.debug-hint.is-visible {
  animation: hint 2.4s ease forwards;
}

@keyframes hint {
  0% { opacity: 0; transform: translate(-50%, 6px); }
  10%, 80% { opacity: 1; transform: translate(-50%, 0); }
  100% { opacity: 0; transform: translate(-50%, 0); }
}

.progress-link {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0 6px;
  color: #c9b6ff;
  font-size: 13px;
  font-weight: 600;
  text-underline-offset: 3px;
}

/* Painel de desempenho. */
.perf {
  position: absolute;
  z-index: 6;
  margin: 0;
  padding: 6px 8px;
  border-radius: 8px;
  background: rgba(8, 6, 18, 0.72);
  color: #d7ffe0;
  font: 10px/1.35 ui-monospace, "Cascadia Mono", Consolas, monospace;
  pointer-events: none;
  white-space: pre-wrap;
}

/* Resultado: da demonstração (some sozinho, sem bloquear o painel) e da partida (Revanche e Voltar). */
.result {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  pointer-events: none;
}

.result.is-interactive {
  pointer-events: auto;
  background: radial-gradient(ellipse at 50% 45%, rgba(9, 7, 20, 0.45), rgba(9, 7, 20, 0.8));
}

.result-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: min(280px, 86%);
  max-width: 340px;
  padding: 14px 18px 12px;
  border: 3px solid var(--outline);
  border-radius: 18px;
  background: linear-gradient(#3a3356, #231e3a);
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.12), 0 6px 0 #0c0a16, 0 0 40px rgba(124, 58, 237, 0.45);
  text-align: center;
  animation: pop-in 0.35s cubic-bezier(0.2, 1.4, 0.4, 1);
}

.result-card p {
  margin: 0;
}

.result-title {
  font-family: var(--font-display);
  font-size: 30px;
  line-height: 1.1;
  -webkit-text-stroke: 4px var(--outline);
  paint-order: stroke fill;
}

.result[data-outcome="0"] .result-title {
  color: #a9d4ff;
}

.result[data-outcome="1"] .result-title,
.result[data-outcome="loss"] .result-title {
  color: #ffb3b8;
}

.result[data-outcome="win"] .result-title {
  color: #ffe08a;
  text-shadow: 0 0 22px rgba(255, 207, 74, 0.7);
}

.result[data-outcome="draw"] .result-title {
  color: #d9c6ff;
}

.result.is-interactive .result-card {
  min-width: min(300px, 92%);
  padding: 20px 20px 18px;
}

.result.is-interactive .result-title {
  font-size: 44px;
}

.result-runes {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
  font-family: var(--font-display);
  font-size: 24px;
  -webkit-text-stroke: 3px var(--outline);
  paint-order: stroke fill;
}

.result-reason {
  margin-top: 6px !important;
  color: #e3d6ff;
  font-size: 15px;
  font-weight: 600;
}

.result-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
  margin-top: 16px;
}

.result-next {
  margin-top: 6px !important;
  color: var(--muted);
  font-size: 13px;
}

/* Sobreposições que bloqueiam a partida (pausa, girar o aparelho). */
.overlay {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(9, 7, 20, 0.66);
  cursor: pointer;
}

/* Acima das telas de menu (escolha do deck e Acervo, z-index 11): o jogo inteiro é em retrato, e o aviso
   não aparece pela metade atrás do fundo translúcido da escolha do deck. */
.overlay--rotate {
  z-index: 20;
  background: rgba(9, 7, 20, 0.94);
  cursor: default;
}

.overlay-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  max-width: 320px;
  padding: 20px 24px 16px;
  border: 3px solid var(--outline);
  border-radius: 20px;
  background: linear-gradient(#3a3356, #231e3a);
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.12), 0 6px 0 #0c0a16, 0 0 50px rgba(124, 58, 237, 0.4);
  text-align: center;
}

.overlay-card p {
  margin: 0;
}

.overlay-title {
  font-family: var(--font-display);
  font-size: 34px;
  line-height: 1.1;
  -webkit-text-stroke: 4px var(--outline);
  paint-order: stroke fill;
}

.overlay-text {
  color: #d8d2f0;
  font-size: 15px;
}

.icon-play {
  width: 0;
  height: 0;
  margin: 4px 0 6px 10px;
  border-top: 22px solid transparent;
  border-bottom: 22px solid transparent;
  border-left: 34px solid #c9a8ff;
  filter: drop-shadow(0 0 10px rgba(154, 102, 255, 0.8));
}

.icon-rotate {
  width: 40px;
  height: 64px;
  margin-bottom: 10px;
  border: 4px solid #c9a8ff;
  border-radius: 8px;
  box-shadow: inset 0 -8px 0 -4px #c9a8ff;
  animation: turn 1.8s ease-in-out infinite;
}

@keyframes turn {
  0%, 30% { transform: rotate(90deg); }
  60%, 100% { transform: rotate(0deg); }
}

@keyframes pop-in {
  from { transform: scale(0.7); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.safe-probe {
  position: fixed;
  top: 0;
  left: 0;
  visibility: hidden;
  pointer-events: none;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.noscript {
  position: absolute;
  inset: 40% 16px auto;
  text-align: center;
}

@media (prefers-reduced-motion: reduce) {
  .icon-rotate,
  .result-card,
  .debug-hint.is-visible,
  .clock.is-urgent .clock-time,
  .rune-count.is-bump,
  .card-detail {
    animation: none;
  }

  .debug-hint.is-visible {
    opacity: 1;
  }

  .card--hand {
    transition: none;
  }
}
