/* ===== RESET ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Nunito', sans-serif;
  background: #1a1a2e;
  background-image: radial-gradient(circle at 30% 70%, #16213e 0%, #1a1a2e 60%);
  height: 100dvh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  color: #fff;
  user-select: none;
}

/* ===== TOP BAR ===== */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 1rem;
  background: rgba(0,0,0,0.3);
  backdrop-filter: blur(4px);
  gap: 0.5rem;
  flex-shrink: 0;
}

.btn-back {
  color: #fff;
  text-decoration: none;
  font-weight: 700;
  font-size: 0.85rem;
  background: rgba(255,255,255,0.15);
  padding: 0.3rem 0.7rem;
  border-radius: 999px;
  transition: background 0.2s;
  white-space: nowrap;
}
.btn-back:hover { background: rgba(255,255,255,0.3); }

.game-title {
  font-size: 1.1rem;
  font-weight: 800;
  letter-spacing: 0.5px;
  white-space: nowrap;
}

.stats {
  display: flex;
  gap: 0.8rem;
  font-size: 0.9rem;
  font-weight: 700;
  opacity: 0.9;
  white-space: nowrap;
}

/* ===== CONTROLS BAR ===== */
.controls-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.8rem;
  padding: 0.5rem 1rem;
  flex-shrink: 0;
}

.controls-bar select {
  font-family: 'Nunito', sans-serif;
  font-size: 0.85rem;
  font-weight: 600;
  padding: 0.35rem 0.7rem;
  border-radius: 999px;
  border: 2px solid rgba(255,255,255,0.2);
  background: rgba(255,255,255,0.1);
  color: #fff;
  cursor: pointer;
  outline: none;
  transition: border-color 0.2s;
}
.controls-bar select:focus { border-color: #ff6b35; }
.controls-bar select option { background: #1a1a2e; color: #fff; }

/* ===== BUTTONS ===== */
.btn {
  padding: 0.6rem 1.8rem;
  border: none;
  border-radius: 999px;
  font-family: 'Nunito', sans-serif;
  font-weight: 700;
  font-size: 1rem;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
}
.btn:active { transform: scale(0.96); }
.btn-orange { background: #ff6b35; color: #fff; }
.btn-orange:hover { opacity: 0.88; }
.btn-sm { padding: 0.35rem 1rem; font-size: 0.85rem; }

/* ===== GAME CONTAINER ===== */
.game-container {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.5rem;
  min-height: 0;
  overflow: auto;
}

/* ===== BOARD ===== */
.board {
  display: grid;
  gap: 8px;
  padding: 8px;
  max-width: 100%;
  max-height: 100%;
}

/* Grid columns set by JS via CSS variable */
.board[data-cols="4"] { grid-template-columns: repeat(4, 1fr); }
.board[data-cols="6"] { grid-template-columns: repeat(6, 1fr); }

/* ===== CARD ===== */
.card {
  aspect-ratio: 1;
  perspective: 600px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.card-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transition: transform 0.5s ease;
  transform-style: preserve-3d;
}

.card.flipped .card-inner {
  transform: rotateY(180deg);
}

.card.matched .card-inner {
  transform: rotateY(180deg);
}

.card-face {
  position: absolute;
  inset: 0;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}

/* Verso da carta */
.card-back {
  background: linear-gradient(135deg, #ff6b35, #f7c59f);
  box-shadow: 0 2px 10px rgba(0,0,0,0.3);
  overflow: hidden;
}

.card-back::before {
  content: '';
  position: absolute;
  inset: 6px;
  border: 2px solid rgba(255,255,255,0.35);
  border-radius: 8px;
}

.card-back::after {
  content: '?';
  font-size: 1.6rem;
  font-weight: 800;
  color: rgba(255,255,255,0.5);
}

/* Face da carta */
.card-front {
  background: #fff;
  box-shadow: 0 2px 10px rgba(0,0,0,0.2);
  transform: rotateY(180deg);
  font-size: 2rem;
}

/* Matched glow */
.card.matched .card-front {
  box-shadow: 0 0 16px rgba(255, 107, 53, 0.5);
  border: 2px solid #ff6b35;
}

.card.matched {
  animation: matchPop 0.4s ease;
}

@keyframes matchPop {
  0%   { transform: scale(1); }
  50%  { transform: scale(1.08); }
  100% { transform: scale(1); }
}

/* ===== VICTORY MODAL ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  backdrop-filter: blur(4px);
}
.modal-overlay.hidden { display: none; }

.modal-content {
  background: #16213e;
  border-radius: 20px;
  padding: 2rem 2.5rem;
  text-align: center;
  animation: popIn 0.3s ease;
  max-width: 340px;
  width: 90%;
  box-shadow: 0 8px 40px rgba(0,0,0,0.5);
}

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

.modal-icon { font-size: 3.5rem; margin-bottom: 0.5rem; }

.modal-content h2 {
  font-size: 1.8rem;
  font-weight: 800;
  color: #ff6b35;
  margin-bottom: 0.3rem;
}

.modal-content p {
  font-size: 0.95rem;
  color: rgba(255,255,255,0.7);
  margin-bottom: 1rem;
}

.modal-stats {
  display: flex;
  justify-content: center;
  gap: 2rem;
  margin-bottom: 1.2rem;
}

.modal-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.modal-stat-label {
  font-size: 0.8rem;
  color: rgba(255,255,255,0.5);
  text-transform: uppercase;
  font-weight: 700;
  letter-spacing: 0.5px;
}

.modal-stat-value {
  font-size: 1.6rem;
  font-weight: 800;
  color: #fff;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 480px) {
  .board { gap: 6px; padding: 4px; }
  .card-front { font-size: 1.5rem; }
  .card-back::after { font-size: 1.2rem; }
  .game-title { font-size: 0.95rem; }
  .controls-bar { padding: 0.3rem 0.5rem; gap: 0.5rem; }
}

@media (max-width: 360px) {
  .board { gap: 4px; padding: 2px; }
  .card-front { font-size: 1.2rem; }
  .card-back::after { font-size: 1rem; }
  .card-face { border-radius: 8px; }
}

@media (max-height: 500px) and (orientation: landscape) {
  .topbar { padding: 0.25rem 0.5rem; }
  .game-title { display: none; }
  .controls-bar { padding: 0.2rem 0.5rem; }
  .board { gap: 4px; padding: 4px; }
  .card-front { font-size: 1.4rem; }
}

/* ===== SEO GAME INFO SECTION ===== */
body:has(.game-info) { overflow-y: auto; height: auto; min-height: 100dvh; }
.game-info {
  max-width: 780px;
  margin: 1rem auto;
  padding: 1rem 1.2rem;
  background: rgba(0,0,0,0.15);
  border-radius: 12px;
  color: rgba(255,255,255,0.85);
  font-size: 0.88rem;
  line-height: 1.6;
}
.game-info h2 { font-size: 1.1rem; font-weight: 800; margin-bottom: 0.5rem; }
.game-info h3 { font-size: 0.95rem; font-weight: 700; margin: 0.8rem 0 0.3rem; }
.game-info ul { padding-left: 1.2rem; }
.game-info li { margin-bottom: 0.2rem; }
