/* ============================================================
   Corrente — estilo "Papel & Tinta"
   Fundo creme, grade fina, pedras lisas e foscas, visual zen.
   ============================================================ */

:root {
  --paper:        #ece1c6;   /* fundo da página */
  --paper-board:  #f7efda;   /* fundo do tabuleiro */
  --paper-edge:   #e4d7b6;   /* moldura */
  --grid:         rgba(74, 61, 42, 0.20);
  --ink:          #3b3325;   /* texto principal */
  --ink-soft:     #7a6e57;   /* texto secundário */

  --vermelho:      #b03a2e;
  --vermelho-dim:  #9a3327;
  --vermelho-soft: rgba(176, 58, 46, 0.16);

  --azul:      #2e5e86;
  --azul-dim:  #244e70;
  --azul-soft: rgba(46, 94, 134, 0.16);

  --shadow: rgba(59, 51, 37, 0.18);
  --radius: 14px;

  --board-size: min(92vw, 70vh, 560px);
  --cell-gap: 1px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background: var(--paper);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

/* textura sutil de papel */
body::before {
  content: "";
  position: fixed; inset: 0;
  pointer-events: none;
  background:
    radial-gradient(circle at 20% 15%, rgba(255,255,255,0.35), transparent 45%),
    radial-gradient(circle at 80% 85%, rgba(120,100,60,0.10), transparent 50%);
  z-index: 0;
}

.app {
  position: relative;
  z-index: 1;
  min-height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: clamp(14px, 3vw, 32px) 16px 40px;
}

/* ---------- topo (igual ao resto do site) ---------- */
.topbar { width: 100%; margin-bottom: clamp(14px, 3vw, 24px); }
.topbar-inner { display: flex; align-items: center; justify-content: space-between; gap: 12px;
  max-width: 920px; margin: 0 auto; width: 100%; }
.brand { display: flex; align-items: center; gap: 9px; }
.logo-mark { display: block; flex: none; filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.15)); }
.logo {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 24px; font-weight: 700; letter-spacing: 0.02em; color: var(--ink);
}
.btn-account {
  font-size: 14px; font-weight: 600; color: var(--ink); text-decoration: none;
  padding: 9px 15px; border-radius: 11px; background: var(--paper-board);
  box-shadow: inset 0 0 0 1.5px rgba(59, 51, 37, 0.2); transition: background 0.15s ease;
  border: none; cursor: pointer;
}
.btn-account:hover { background: var(--paper-edge); }

/* ---------- palco (tabuleiro + painel) ---------- */
.stage {
  display: flex;
  flex-wrap: wrap;
  gap: clamp(18px, 4vw, 40px);
  align-items: flex-start;
  justify-content: center;
}

/* ---------- moldura com rótulos das bordas ---------- */
.board-frame {
  position: relative;
  padding: 26px 14px 14px 26px;
  background: var(--paper-edge);
  border-radius: var(--radius);
  box-shadow: 0 10px 30px var(--shadow), inset 0 0 0 1px rgba(255,255,255,0.4);
}
/* coordenadas (letras em cima, números à esquerda) */
.coords {
  position: absolute;
  display: flex;
  pointer-events: none;
  color: var(--ink-soft);
  font-size: 11px; font-weight: 700; letter-spacing: 0.02em;
}
.coords span { flex: 1; display: flex; align-items: center; justify-content: center; }
.coords-top  { top: 5px;  left: 26px; right: 14px; height: 18px; flex-direction: row; }
.coords-left { left: 5px; top: 26px; bottom: 14px; width: 18px; flex-direction: column; }

/* faixas coloridas nas bordas do tabuleiro */
.board {
  --n: 9;
  position: relative;
  width: var(--board-size);
  height: var(--board-size);
  display: grid;
  grid-template-columns: repeat(var(--n), 1fr);
  grid-template-rows: repeat(var(--n), 1fr);
  gap: var(--cell-gap);
  background: var(--grid);                 /* gap vira a "tinta" da grade */
  border: 3px solid transparent;
  border-left-color: var(--vermelho);
  border-right-color: var(--vermelho);
  border-top-color: var(--azul);
  border-bottom-color: var(--azul);
  border-radius: 4px;
  box-shadow: 0 2px 10px var(--shadow);
  touch-action: manipulation;
}

/* neon só nas DUAS bordas do objetivo (não enche o quadrado), pulsando de leve */
.board.goal-red::before, .board.goal-red::after,
.board.goal-blue::before, .board.goal-blue::after {
  content: ""; position: absolute; pointer-events: none; z-index: 3;
  animation: goalPulse 2.4s ease-in-out infinite;
}
.board.goal-red::before { top: 0; bottom: 0; left: -1px; width: 3px;
  background: var(--vermelho); box-shadow: 0 0 9px 1px var(--vermelho); }
.board.goal-red::after  { top: 0; bottom: 0; right: -1px; width: 3px;
  background: var(--vermelho); box-shadow: 0 0 9px 1px var(--vermelho); }
.board.goal-blue::before { left: 0; right: 0; top: -1px; height: 3px;
  background: var(--azul); box-shadow: 0 0 9px 1px var(--azul); }
.board.goal-blue::after  { left: 0; right: 0; bottom: -1px; height: 3px;
  background: var(--azul); box-shadow: 0 0 9px 1px var(--azul); }
@keyframes goalPulse { 0%, 100% { opacity: 0.35; } 50% { opacity: 0.75; } }

/* ---------- ajudas visuais ---------- */
/* elos: linhas ligando pedras realmente conectadas */
.elos-svg {
  position: absolute; inset: 0; width: 100%; height: 100%;
  pointer-events: none; overflow: visible; z-index: 4;
}
.elo-line { stroke-width: 2.5; stroke-linecap: round; opacity: 0.5; }

/* respiros: realce do grupo + pontinhos nas casas vazias vizinhas */
.cell.group-hi { background: #fff6e0; }
.cell.respiro::after {
  content: ""; position: absolute;
  width: 34%; height: 34%; border-radius: 50%;
  background: var(--respiro-color, var(--azul));
  animation: breath 1.1s ease-in-out infinite;
}
@keyframes breath {
  0%, 100% { opacity: 0.25; transform: scale(0.85); }
  50%      { opacity: 0.7;  transform: scale(1.05); }
}

/* ---------- casas ---------- */
.cell {
  position: relative;
  background: var(--paper-board);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
}
.cell.empty:hover::after {
  content: "";
  position: absolute;
  width: 62%; height: 62%;
  border-radius: 50%;
  background: var(--turn-color, transparent);
  opacity: 0.22;
}
.board.locked .cell { cursor: default; }
.board.locked .cell.empty:hover::after { display: none; }

/* ---------- pedras ---------- */
.stone {
  width: 78%; height: 78%;
  border-radius: 50%;
  transform: scale(0);
  transition: transform 0.18s ease;
  will-change: transform;
}
.stone.red {
  background: radial-gradient(circle at 35% 30%, #c64b3d, var(--vermelho) 60%, var(--vermelho-dim));
  box-shadow: inset -2px -3px 5px rgba(0,0,0,0.22), 0 2px 4px rgba(0,0,0,0.18);
}
.stone.blue {
  background: radial-gradient(circle at 35% 30%, #4a7ba8, var(--azul) 60%, var(--azul-dim));
  box-shadow: inset -2px -3px 5px rgba(0,0,0,0.22), 0 2px 4px rgba(0,0,0,0.18);
}
.stone.red, .stone.blue { transform: scale(1); }

/* colocar pedra: leve "pop" */
.stone.pop { animation: pop 0.26s cubic-bezier(.34,1.56,.64,1); }
@keyframes pop {
  0%   { transform: scale(0); }
  70%  { transform: scale(1.12); }
  100% { transform: scale(1); }
}

/* conversão: vira (flip 3D) para revelar a nova cor */
.stone.flip-out { animation: flipOut 0.18s ease forwards; }
.stone.flip-in  { animation: flipIn 0.18s ease forwards; }
@keyframes flipOut { from { transform: scale(1) rotateY(0); } to { transform: scale(1) rotateY(90deg); } }
@keyframes flipIn  { from { transform: scale(1) rotateY(90deg); } to { transform: scale(1) rotateY(0); } }

/* corrente vencedora pulsando */
.cell.winning .stone {
  animation: glow 1.1s ease-in-out infinite;
  box-shadow: 0 0 0 3px rgba(255,255,255,0.55), 0 0 14px 2px var(--win-glow, #fff);
}
@keyframes glow {
  0%, 100% { filter: brightness(1); }
  50%      { filter: brightness(1.35); }
}

/* ---------- painel ---------- */
.panel {
  width: min(86vw, 280px);
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.turn {
  display: flex; align-items: center; gap: 12px;
  background: var(--paper-board);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: 0 4px 14px var(--shadow);
}
.dot { width: 18px; height: 18px; border-radius: 50%; background: var(--vermelho); flex: none;
       box-shadow: inset -1px -2px 3px rgba(0,0,0,0.25); }
.dot.blue { background: var(--azul); }
.turn-text { display: flex; flex-direction: column; line-height: 1.25; }
.turn-text strong { font-size: 16px; }
.turn-text small { color: var(--ink-soft); font-size: 12px; }

.legend { display: flex; gap: 8px; }
.legend-item {
  flex: 1; text-align: center; font-size: 12px; font-weight: 600;
  padding: 6px 8px; border-radius: 8px; background: var(--paper-board);
}
.legend-item[data-color="vermelho"] { color: var(--vermelho-dim); box-shadow: inset 0 0 0 1px var(--vermelho-soft); }
.legend-item[data-color="azul"]     { color: var(--azul-dim);     box-shadow: inset 0 0 0 1px var(--azul-soft); }

.message { min-height: 18px; font-size: 13px; color: var(--vermelho-dim); font-weight: 600; }

/* botões */
.btn {
  font: inherit; font-weight: 600; font-size: 14px;
  padding: 11px 16px;
  border: none; border-radius: 10px;
  background: var(--ink); color: var(--paper);
  cursor: pointer;
  transition: transform 0.08s ease, opacity 0.15s ease;
}
.btn:hover { opacity: 0.92; }
.btn:active { transform: translateY(1px); }
.btn-ghost { background: transparent; color: var(--ink); box-shadow: inset 0 0 0 2px var(--ink); }
.btn-quiet {
  background: var(--paper-board); color: var(--ink);
  box-shadow: inset 0 0 0 1px rgba(59,51,37,0.18);
  font-size: 13px; padding: 9px 12px;
}

/* ---------- relógios ---------- */
.clocks { display: flex; gap: 10px; }
.clock {
  flex: 1; text-align: center; padding: 8px 6px; border-radius: 10px;
  background: var(--paper-board); box-shadow: inset 0 0 0 1px rgba(59, 51, 37, 0.12);
  opacity: 0.55; transition: opacity 0.15s ease, box-shadow 0.15s ease;
}
.clock .clabel { font-size: 11px; color: var(--ink-soft); }
.clock .ctime { font-family: Georgia, serif; font-size: 22px; line-height: 1.15; font-variant-numeric: tabular-nums; }
.clock[data-color="vermelho"] .ctime { color: var(--vermelho); }
.clock[data-color="azul"] .ctime { color: var(--azul); }
.clock.active { opacity: 1; }
.clock[data-color="vermelho"].active { box-shadow: inset 0 0 0 2px var(--vermelho); }
.clock[data-color="azul"].active { box-shadow: inset 0 0 0 2px var(--azul); }
.clock.low .ctime { animation: lowblink 1s steps(2, start) infinite; }
@keyframes lowblink { 50% { opacity: 0.35; } }

.swap-panel, .win-banner {
  background: var(--paper-board);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: 0 4px 14px var(--shadow);
}
.swap-title { font-family: Georgia, serif; font-size: 17px; margin-bottom: 4px; }
.swap-sub { font-size: 13px; color: var(--ink-soft); margin-bottom: 12px; }
.swap-buttons { display: flex; gap: 10px; }
.swap-buttons .btn { flex: 1; }

/* painel da troca: barra fixa no rodapé, sempre à vista (não corta no celular
   nem exige rolar no PC). O tabuleiro continua visível acima. */
.swap-panel {
  position: fixed; left: 50%; bottom: calc(14px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%); z-index: 60; width: min(92vw, 380px);
  box-shadow: 0 16px 44px rgba(0, 0, 0, 0.4), inset 0 0 0 1px var(--line);
  animation: swapIn 0.18s ease;
}
@keyframes swapIn { from { opacity: 0; transform: translate(-50%, 14px); } to { opacity: 1; transform: translateX(-50%); } }

.win-banner { text-align: center; }
.win-title { font-family: Georgia, serif; font-size: 22px; margin-bottom: 14px; }
.win-banner .btn { display: block; width: 100%; margin-top: 8px; text-decoration: none; box-sizing: border-box; }
.win-banner .btn:first-of-type { margin-top: 0; }

.controls { display: flex; flex-wrap: wrap; gap: 8px; }
.controls .btn { flex: 1; }

.aids { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.aids-label { font-size: 13px; color: var(--ink-soft); }
.chip {
  font: inherit; font-size: 12.5px; font-weight: 600;
  padding: 7px 12px; border: none; border-radius: 999px; cursor: pointer;
  background: var(--paper-board); color: var(--ink-soft);
  box-shadow: inset 0 0 0 1px rgba(59, 51, 37, 0.18);
  transition: background 0.15s ease, color 0.15s ease;
}
.chip.is-on { background: var(--ink); color: var(--paper); box-shadow: none; }

.score { display: flex; gap: 10px; }
.score-item {
  flex: 1; text-align: center; font-size: 13px; color: var(--ink-soft);
  padding: 8px; border-radius: 10px; background: var(--paper-board);
  box-shadow: inset 0 0 0 1px rgba(59,51,37,0.10);
}
.score-item b { display: block; font-size: 20px; color: var(--ink); }
.score-item[data-color="vermelho"] b { color: var(--vermelho); }
.score-item[data-color="azul"] b { color: var(--azul); }

/* ---------- modal ---------- */
.modal {
  position: fixed; inset: 0; z-index: 10;
  background: rgba(40, 33, 20, 0.45);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.modal-card {
  background: var(--paper-board);
  border-radius: var(--radius);
  padding: 24px;
  max-width: 440px; width: 100%;
  box-shadow: 0 20px 50px rgba(0,0,0,0.3);
}
.modal-card h2 { font-family: Georgia, serif; margin-bottom: 14px; }
.modal-card ul { list-style: none; display: flex; flex-direction: column; gap: 9px; margin-bottom: 18px; }
.modal-card li { font-size: 13.5px; line-height: 1.45; color: var(--ink); }
.modal-card li b { color: var(--ink); }

.hidden { display: none !important; }

/* ---------- responsivo ---------- */
@media (max-width: 720px) {
  :root { --board-size: min(86vw, 58vh); }
  .stage { flex-direction: column; align-items: center; }
  .panel { width: var(--board-size); }
  .controls .btn { flex: 1 1 30%; }
}
