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

body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: linear-gradient(160deg, #1e1b4b, #312e81);
  color: #e0e7ff;
}

.jogo { width: 100%; max-width: 420px; text-align: center; }

h1 {
  font-size: 1.75rem;
  margin-bottom: 1rem;
  letter-spacing: -0.02em;
}

.placar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  margin-bottom: 1.25rem;
  font-size: 0.95rem;
}

.placar strong { color: #fbbf24; }

#reiniciar {
  padding: 0.4rem 0.9rem;
  border: 1px solid #6366f1;
  border-radius: 999px;
  background: transparent;
  color: #c7d2fe;
  font: inherit;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}

#reiniciar:hover { background: #6366f1; color: #fff; }

.tabuleiro {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.75rem;
}

/* A carta é o contexto 3D; .interna gira dentro dela. */
.carta {
  aspect-ratio: 3 / 4;
  border: none;
  padding: 0;
  background: none;
  perspective: 800px;
  cursor: pointer;
}

.carta:disabled { cursor: default; }

/* display:block é obrigatório: <span> é inline, e transform/width/height
   não se aplicam a elementos inline não-substituídos — a virada não acontece. */
.interna {
  display: block;
  position: relative;
  width: 100%;
  height: 100%;
  transition: transform 0.4s;
  transform-style: preserve-3d;
}

.carta.virada .interna { transform: rotateY(180deg); }

.frente,
.verso {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  border-radius: 12px;
  backface-visibility: hidden;
}

/* Frente = costas da carta, o que aparece fechado. */
.frente {
  background: linear-gradient(135deg, #4f46e5, #7c3aed);
  font-size: 1.5rem;
  color: #ede9fe;
}

.verso {
  background: #f8fafc;
  transform: rotateY(180deg);
}

.verso img {
  width: 68%;
  height: 68%;
  object-fit: contain;
}

.carta.encontrada .verso {
  background: #dcfce7;
  box-shadow: inset 0 0 0 3px #22c55e;
}

.carta.encontrada { animation: pulso 0.4s ease; }

@keyframes pulso {
  50% { transform: scale(1.08); }
}

.vitoria {
  margin-top: 1.25rem;
  font-size: 1.05rem;
  color: #86efac;
}

.jogador {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  margin-bottom: 0.9rem;
  font-size: 0.95rem;
}

#nome {
  width: 11rem;
  padding: 0.35rem 0.7rem;
  border: 1px solid #4f46e5;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.07);
  color: #e0e7ff;
  font: inherit;
}

#nome::placeholder { color: #a5b4fc; opacity: 0.6; }
#nome:focus { outline: 2px solid #a5b4fc; outline-offset: 1px; }

.ranking { margin-top: 1.75rem; }

.ranking h2 {
  font-size: 1.05rem;
  margin-bottom: 0.6rem;
  color: #c7d2fe;
}

.ranking table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.ranking th,
.ranking td {
  padding: 0.35rem 0.5rem;
  text-align: left;
  border-bottom: 1px solid rgba(199, 210, 254, 0.15);
}

.ranking th { color: #a5b4fc; font-weight: 600; }

/* Nome pode ser longo; corta em vez de esticar a tabela. */
.ranking td:nth-child(2) {
  max-width: 9rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ranking th:first-child,
.ranking td:first-child { width: 2rem; color: #a5b4fc; }

.ranking tr.lider td { color: #fbbf24; font-weight: 600; }

.vazio { padding: 0.6rem 0; color: #a5b4fc; font-size: 0.88rem; }

.limpar {
  margin-top: 0.75rem;
  padding: 0.3rem 0.75rem;
  border: 1px solid rgba(248, 113, 113, 0.5);
  border-radius: 999px;
  background: transparent;
  color: #fca5a5;
  font: inherit;
  font-size: 0.85rem;
  cursor: pointer;
}

.limpar:hover { background: rgba(248, 113, 113, 0.15); }

@media (prefers-reduced-motion: reduce) {
  .interna { transition: none; }
  .carta.encontrada { animation: none; }
}
