@import url('../global.css');

/* =============================================================================
   Memory — game-specific styles (frame/controls/score-bar = shared).
   ========================================================================== */

/* --- Square board: N×N grid (number of columns set in JS) --- */
/* `container-type: size` lets us size the icon in `cqmin` (% of the board's
   smallest side), set in JS via --memory-icon according to the grid size
   (4×4 / 6×6 / 8×8) so everything fits. */
.memory-board {
  container-type: size;
  display: grid;
  gap: clamp(2px, 1cqmin, var(--spacing-sm));
  padding: var(--spacing-sm);
  background: var(--memory-board-bg);
}

/* --- Card: square button that flips in 3D --- */
.memory-card {
  aspect-ratio: 1;
  padding: 0;
  border: none;
  background: transparent;
  perspective: 600px;
  cursor: pointer;
}

.memory-card-inner {
  position: relative;
  display: block;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  /* Slightly slower than the shared speed for a more satisfying flip. */
  transition: transform 0.35s ease;
}

/* A flipped card (pair in progress or found) shows its front face. */
.memory-card.is-flipped .memory-card-inner {
  transform: rotateY(180deg);
}

/* --- Card faces --- */
.memory-card-face {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--border-radius-sm);
  backface-visibility: hidden;
  /* Icon size relative to the board (set in JS according to the grid). */
  font-size: var(--memory-icon, 8cqmin);
}

/* Back (visible at rest): solid pattern with a discreet question mark. */
.memory-card-back {
  background: var(--memory-card-back-bg);
  color: var(--memory-card-back-icon);
}

/* Front face (the symbol): pre-rotated to appear on the flip. */
.memory-card-front {
  background: var(--memory-card-front-bg);
  color: var(--memory-card-front-icon);
  transform: rotateY(180deg);
}

/* Matched pair: lock the cursor and signal the success with a glow pulse. */
.memory-card.is-matched {
  cursor: default;
}

.memory-card.is-matched .memory-card-front {
  background: var(--memory-card-matched-bg);
  color: var(--memory-card-matched-icon);
  animation: memoryMatchGlow 1.8s ease-in-out infinite;
}

/* Focus ring for keyboard players (cards are <button>s). */
.memory-card:focus-visible {
  outline: 3px solid var(--primary-color);
  outline-offset: 2px;
  border-radius: var(--border-radius-sm);
}
