/* ==========================================================================
   TAIXU — Tabuleiro / Jogo
   ========================================================================== */

:root {
  /* Tamanho da célula: escala com a viewport, com teto no desktop.
     clamp() garante que 12 células + espaçamentos caibam em telas estreitas. */
  --cell-size: clamp(20px, 7vw, 30px);
}

body {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 10px;
  gap: 10px;
  overflow-x: hidden;
}

.topbar {
  width: 100%;
  max-width: 950px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.btn-lobby {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--accent-p1);
  text-decoration: none;
  font-weight: bold;
  font-size: 0.9rem;
  padding: 8px 12px;
  border: 1px solid rgba(0, 240, 255, 0.3);
  border-radius: 20px;
  transition: transform 0.2s ease, background 0.2s ease;
}

.btn-lobby:hover,
.btn-lobby:focus-visible {
  background: rgba(0, 240, 255, 0.1);
  transform: translateX(-3px);
}

.game-title {
  font-size: clamp(1.3rem, 5vw, 2.2rem);
  flex: 1;
  text-align: center;
}

.mode-tag {
  font-size: 0.75rem;
  font-weight: bold;
  letter-spacing: 1px;
  text-transform: uppercase;
  padding: 6px 12px;
  border-radius: 20px;
  background: rgba(157, 0, 255, 0.15);
  border: 1px solid rgba(157, 0, 255, 0.5);
  color: #d9a8ff;
  white-space: nowrap;
}

/* Interface principal */
.game-container {
  display: flex;
  flex-direction: row;
  gap: 20px;
  background: var(--panel-bg);
  border: 1px solid rgba(0, 240, 255, 0.2);
  border-radius: 12px;
  padding: 15px;
  box-shadow: 0 0 40px rgba(0, 0, 0, 0.8), inset 0 0 15px rgba(0, 240, 255, 0.1);
  backdrop-filter: blur(10px);
  max-width: 950px;
  width: 100%;
  align-items: center;
}

/* Painel lateral */
.sidebar {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
  min-width: 0;
}

.status-card {
  background: rgba(10, 15, 30, 0.6);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--radius-md);
  padding: 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.player-turn {
  font-size: 1.1rem;
  font-weight: bold;
  display: flex;
  align-items: center;
  gap: 8px;
}

.player-indicator {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}

.p1-turn { color: var(--accent-p1); }
.p1-bg { background-color: var(--accent-p1); box-shadow: 0 0 10px var(--accent-p1); }
.p2-turn { color: var(--accent-p2); }
.p2-bg { background-color: var(--accent-p2); box-shadow: 0 0 10px var(--accent-p2); }

.pc-meter {
  font-size: 1rem;
  color: var(--gold);
  text-shadow: 0 0 8px rgba(255, 215, 0, 0.4);
}

.round-meter {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.round-meter strong { color: var(--text-color); }

/* Relógio de partida opcional, estilo xadrez: tempo total por jogador,
   só corre no turno dele e nunca reseta. */
.turn-timer {
  font-size: 0.85rem;
  font-weight: bold;
  padding: 3px 10px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.15);
  display: flex;
  align-items: center;
  gap: 6px;
}

.turn-timer .clock-p1 { color: var(--accent-p1); }
.turn-timer .clock-p2 { color: var(--accent-p2); }
.turn-timer .clock-sep { color: var(--text-muted); }

.turn-timer .clock-p1.urgent,
.turn-timer .clock-p2.urgent {
  animation: timer-pulse 0.8s ease-in-out infinite;
}

@keyframes timer-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

.reserves {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.reserves span strong { color: var(--text-color); }

.actions-menu {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.action-btn {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: #fff;
  padding: 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-family: inherit;
  font-weight: 600;
  font-size: 0.85rem;
  transition: background 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
  min-height: 46px;
  text-align: left;
}

.action-btn:hover:not(:disabled),
.action-btn:focus-visible:not(:disabled) {
  background: rgba(0, 240, 255, 0.15);
  border-color: var(--accent-p1);
}

.action-btn.active {
  background: rgba(0, 240, 255, 0.3);
  border-color: var(--accent-p1);
  box-shadow: 0 0 10px rgba(0, 240, 255, 0.4);
}

.action-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.cost-badge {
  background: rgba(0, 0, 0, 0.5);
  border: 1px solid var(--gold);
  color: var(--gold);
  font-size: 0.75rem;
  padding: 2px 5px;
  border-radius: 10px;
  white-space: nowrap;
  flex-shrink: 0;
}

.end-turn-btn {
  background: linear-gradient(45deg, #441166, #220044);
  border: 1px solid var(--accent-purple);
  color: #fff;
  padding: 14px;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-weight: bold;
  font-size: 0.95rem;
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 1px;
  transition: background 0.2s ease, box-shadow 0.2s ease;
  min-height: 50px;
}

.end-turn-btn:hover:not(:disabled),
.end-turn-btn:focus-visible:not(:disabled) {
  background: linear-gradient(45deg, #661199, #440066);
  box-shadow: 0 0 15px rgba(157, 0, 255, 0.5);
}

.end-turn-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Trava a orientação do tabuleiro no PvP local, evitando o giro automático
   a cada troca de turno (só aparece nesse modo). Ícone discreto flutuando
   sobre o canto superior direito do tabuleiro. */
.board-lock-btn {
  position: absolute;
  top: -6px;
  right: -6px;
  z-index: 5;
  width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 50%;
  color: var(--text-muted);
  font-size: 0.85rem;
  line-height: 1;
  cursor: pointer;
  opacity: 0.45;
  transition: opacity 0.2s ease, background 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

.board-lock-btn:hover,
.board-lock-btn:focus-visible {
  opacity: 1;
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
}

.board-lock-btn.active {
  opacity: 0.85;
  background: rgba(0, 240, 255, 0.15);
  border-color: var(--accent-p1);
  color: var(--accent-p1);
}

.log-box {
  height: 90px;
  background: rgba(0, 0, 0, 0.5);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--radius-sm);
  padding: 8px;
  font-size: 0.8rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column-reverse;
  font-family: 'Consolas', 'Courier New', monospace;
  -webkit-user-select: text;
  user-select: text;
  overscroll-behavior: contain;
}

.log-entry {
  margin-bottom: 4px;
  padding-bottom: 4px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

/* Tabuleiro */
.board-container {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  /* No desktop (linha) ocupa apenas o espaço natural do tabuleiro; no celular
     (coluna) passa a 100% via media query, ficando centralizado. */
  flex: 0 0 auto;
}

.board {
  display: grid;
  /* grid-template-columns/rows definidos via JS (createBoardUI), pois o
     tamanho do tabuleiro (BOARD_SIZE) é controlado em game.js. */
  gap: 4px;
  background: rgba(0, 0, 0, 0.4);
  padding: 8px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: inset 0 0 20px rgba(0, 0, 0, 0.8);
  touch-action: manipulation;
  transition: transform 0.4s ease;
}

/* Perspectiva do tabuleiro: gira 180° pra colocar a borda do jogador que
   está vendo a tela sempre embaixo. As peças giram de volta (contra-rotação)
   pra manter o número de Carga legível. */
.board.flipped {
  transform: rotate(180deg);
}

.board.flipped .piece {
  transform: rotate(180deg);
}

.board.flipped .piece.selected {
  transform: rotate(180deg) scale(1.15);
}

.cell {
  width: var(--cell-size);
  height: var(--cell-size);
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius-sm);
  display: flex;
  justify-content: center;
  align-items: center;
  position: relative;
  cursor: pointer;
  transition: background 0.2s ease;
}

.cell:hover {
  background: rgba(255, 255, 255, 0.08);
}

.cell.core {
  background: rgba(157, 0, 255, 0.12);
  border-color: rgba(157, 0, 255, 0.4);
  box-shadow: inset 0 0 10px var(--core-glow);
}

/* Zona de Energia (regra 2): +1 Carga extra a quem chega ali por Deslocar. */
.cell.energy-zone {
  background: rgba(255, 215, 0, 0.1);
  border-color: rgba(255, 215, 0, 0.35);
  box-shadow: inset 0 0 10px rgba(255, 215, 0, 0.25);
}

/* Anomalia Temporal (regra 6): casa com efeito especial, muda a cada
   ANOMALY_ROUND_INTERVAL rodadas. Cor varia por tipo; o ícone flutua no
   canto pra ficar visível mesmo com uma peça em cima. */
.cell.anomaly {
  animation: anomaly-pulse 2s ease-in-out infinite;
}

.cell.anomaly-overcharge { border-color: #ff9900; box-shadow: inset 0 0 10px rgba(255, 153, 0, 0.3); }
.cell.anomaly-echo { border-color: #00e0c0; box-shadow: inset 0 0 10px rgba(0, 224, 192, 0.3); }
.cell.anomaly-rift { border-color: #9d00ff; box-shadow: inset 0 0 10px rgba(157, 0, 255, 0.3); }
.cell.anomaly-drain { border-color: #00b0ff; box-shadow: inset 0 0 10px rgba(0, 176, 255, 0.3); }
.cell.anomaly-freeswap { border-color: #ff00ff; box-shadow: inset 0 0 10px rgba(255, 0, 255, 0.3); }

@keyframes anomaly-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

.anomaly-icon {
  position: absolute;
  top: 1px;
  left: 2px;
  font-size: calc(var(--cell-size) * 0.28);
  line-height: 1;
  pointer-events: none;
  z-index: 1;
  filter: drop-shadow(0 0 3px rgba(0, 0, 0, 0.9));
}

.cell.highlight-spawn {
  background: rgba(0, 255, 100, 0.25);
  border-color: #00ff64;
}
.cell.highlight-move {
  background: rgba(0, 240, 255, 0.3);
  border-color: var(--accent-p1);
}
.cell.highlight-attack {
  background: rgba(255, 0, 85, 0.3);
  border-color: var(--accent-p2);
}
.cell.highlight-reset {
  background: rgba(255, 165, 0, 0.4);
  border-color: #ffa500;
}
.cell.highlight-swap {
  background: rgba(255, 0, 255, 0.3);
  border-color: #ff00ff;
}

/* Peças */
.piece {
  width: calc(var(--cell-size) * 0.75);
  height: calc(var(--cell-size) * 0.75);
  border-radius: 50%;
  display: flex;
  justify-content: center;
  align-items: center;
  font-weight: bold;
  font-size: calc(var(--cell-size) * 0.35);
  position: relative;
  transition: transform 0.25s ease, box-shadow 0.25s ease;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
}

.piece.selected {
  transform: scale(1.15);
  box-shadow: 0 0 15px #fff;
  z-index: 10;
}

.piece.p1 {
  background: radial-gradient(circle at 30% 30%, #a0f8ff, var(--accent-p1) 60%, #007799);
  color: #002233;
  border: 2px solid #a0f8ff;
}

/* Peça em Carga 4: estável, mas a um passo do Colapso Crítico (Carga 5) —
   pulso de aviso pra chamar atenção sem usar `transform` (evita conflito
   com a rotação de perspectiva do tabuleiro). */
.piece.at-risk {
  animation: at-risk-pulse 1s ease-in-out infinite;
}

@keyframes at-risk-pulse {
  0%, 100% { box-shadow: 0 2px 8px rgba(0, 0, 0, 0.5), 0 0 6px rgba(255, 165, 0, 0.4); }
  50% { box-shadow: 0 2px 8px rgba(0, 0, 0, 0.5), 0 0 18px 4px rgba(255, 60, 0, 0.85); }
}

.piece.p2 {
  background: radial-gradient(circle at 30% 30%, #ffa0c0, var(--accent-p2) 60%, #880022);
  color: #330011;
  border: 2px solid #ffa0c0;
}

.charge-dots {
  position: absolute;
  bottom: -3px;
  display: flex;
  gap: 2px;
}

.dot {
  width: calc(var(--cell-size) * 0.1);
  height: calc(var(--cell-size) * 0.1);
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 0 4px #fff;
}

@keyframes shockwave {
  0% { transform: scale(0.5); opacity: 1; }
  100% { transform: scale(2.2); opacity: 0; }
}

.shockwave-effect {
  position: absolute;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  border: 3px solid var(--accent-p2);
  background: rgba(255, 0, 85, 0.4);
  animation: shockwave 0.5s ease-out forwards;
  pointer-events: none;
}

@keyframes shock-ring {
  0% { transform: scale(0.3); opacity: 0.9; }
  100% { transform: scale(1.7); opacity: 0; }
}

/* Anel da onda de choque — toca nas 8 casas ao redor da explosão, com ou
   sem peça, para mostrar o raio afetado. */
.shock-ring-effect {
  position: absolute;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  border: 2px solid var(--accent-p2);
  background: rgba(255, 0, 85, 0.22);
  animation: shock-ring 0.45s ease-out forwards;
  pointer-events: none;
}

@keyframes capture-burst {
  0% { transform: scale(0.4) rotate(0deg); opacity: 1; }
  100% { transform: scale(1.8) rotate(25deg); opacity: 0; }
}

/* Estilhaços da peça capturada (destruída sem explosão, por vetor de
   colisão) — visualmente distinto da explosão de Colapso Crítico. */
.capture-effect {
  position: absolute;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  border: 3px dashed var(--gold);
  background: transparent;
  animation: capture-burst 0.4s ease-out forwards;
  pointer-events: none;
}

@keyframes flash-invalid {
  0%, 100% { box-shadow: inset 0 0 20px rgba(0, 0, 0, 0.8); background: rgba(0, 0, 0, 0.4); }
  50% {
    box-shadow: inset 0 0 40px rgba(255, 0, 85, 0.9), 0 0 25px rgba(255, 0, 85, 0.6);
    background: rgba(255, 0, 85, 0.25);
  }
}

/* Pisca em vermelho quando uma ação é bloqueada (ex.: atacar com Carga menor). */
.board.flash-invalid {
  animation: flash-invalid 0.4s ease;
}

/* ---------- Modal de fim de partida ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(3, 4, 10, 0.85);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 150;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.25s ease, visibility 0.25s ease;
}

.modal-overlay.open {
  opacity: 1;
  visibility: visible;
}

.modal {
  background: var(--panel-bg);
  border: 1px solid rgba(0, 240, 255, 0.35);
  border-radius: var(--radius-lg);
  box-shadow: 0 0 50px rgba(0, 0, 0, 0.9), inset 0 0 20px rgba(0, 240, 255, 0.1);
  backdrop-filter: blur(12px);
  width: 100%;
  max-width: 420px;
  padding: 30px 25px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 18px;
  transform: translateY(12px) scale(0.98);
  transition: transform 0.25s ease;
}

.modal-overlay.open .modal {
  transform: translateY(0) scale(1);
}

.win-trophy {
  font-size: 3.5rem;
  animation: trophy-pop 0.5s ease-out;
  filter: drop-shadow(0 0 15px var(--gold));
}

@keyframes trophy-pop {
  0% { transform: scale(0.3) rotate(-15deg); opacity: 0; }
  60% { transform: scale(1.15) rotate(5deg); opacity: 1; }
  100% { transform: scale(1) rotate(0); }
}

.win-title {
  font-size: 1.5rem;
  letter-spacing: 2px;
}

.win-reason {
  color: var(--text-muted);
  font-size: 0.95rem;
  line-height: 1.5;
}

.win-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 8px;
}

/* Estatísticas da partida, exibidas no modal de fim de jogo. */
.win-stats {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 4px 12px;
  font-size: 0.82rem;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  text-align: left;
}

.win-stats .stats-header {
  font-weight: bold;
  color: var(--text-muted);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding-bottom: 4px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.win-stats .stats-label {
  color: var(--text-color);
}

.win-stats .stats-p1 { color: var(--accent-p1); text-align: center; font-weight: bold; }
.win-stats .stats-p2 { color: var(--accent-p2); text-align: center; font-weight: bold; }

.win-lobby-link {
  justify-content: center;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: rgba(255, 255, 255, 0.05);
  min-height: 44px;
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--accent-p1);
  text-decoration: none;
  font-weight: bold;
}

.win-lobby-link:hover {
  transform: none;
  background: rgba(0, 240, 255, 0.1);
  border-color: var(--accent-p1);
}

.hidden {
  display: none !important;
}

/* ---------- Modais de modo Online (nome / espera / erro) ---------- */
.online-field {
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.online-field label {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.online-field input {
  padding: 12px 16px;
  border-radius: var(--radius-md);
  border: 1px solid rgba(0, 240, 255, 0.3);
  background: rgba(10, 15, 30, 0.8);
  color: #fff;
  font-family: inherit;
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.3s ease, box-shadow 0.3s ease;
}

.online-field input:focus {
  border-color: var(--accent-p1);
  box-shadow: 0 0 15px rgba(0, 240, 255, 0.4);
}

.online-error {
  color: var(--accent-p2);
  font-size: 0.85rem;
}

.spinner {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 3px solid rgba(0, 240, 255, 0.2);
  border-top-color: var(--accent-p1);
  animation: spin 0.8s linear infinite;
  align-self: center;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.online-room-code {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.online-room-code p {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.room-code {
  font-size: 2rem;
  font-weight: bold;
  letter-spacing: 6px;
  color: var(--gold);
  text-shadow: 0 0 15px rgba(255, 215, 0, 0.5);
  background: rgba(0, 0, 0, 0.4);
  border: 1px dashed rgba(255, 215, 0, 0.4);
  border-radius: var(--radius-md);
  padding: 10px 20px;
}

/* ---------- Responsivo ---------- */
@media (max-width: 768px) {
  .game-container {
    flex-direction: column-reverse;
    padding: 12px;
    gap: 15px;
  }

  .sidebar,
  .board-container {
    width: 100%;
  }
}

/* Tabuleiro maior e mais protagonista em telas de computador */
@media (min-width: 769px) {
  :root {
    --cell-size: 38px;
  }

  .game-container {
    gap: 25px;
    padding: 20px;
  }

  .sidebar {
    flex: 1 1 0;
    max-width: 360px;
  }
}

/* Empilha rótulo + custo em telas muito estreitas para não truncar */
@media (max-width: 360px) {
  .action-btn {
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
    font-size: 0.8rem;
  }
}

/* No desktop as ações ficam em coluna única, mais legíveis */
@media (min-width: 769px) {
  .actions-menu {
    display: flex;
    flex-direction: column;
  }
}
