/* ── Memory Game ── */

.memory-container {
  background: linear-gradient(145deg, #1a1a2e, #16213e 50%, #1a1a2e);
  border-radius: var(--radius-lg, 16px);
  padding: 20px;
  box-shadow:
    inset 0 2px 20px rgba(0, 0, 0, 0.3),
    0 4px 24px rgba(0, 0, 0, 0.2);
  border: 3px solid #2a2a4a;
}

/* ── Controls Bar ── */
.mem-controls {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.mem-btn {
  padding: 6px 16px;
  border: none;
  border-radius: 6px;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.18);
  transition: background 0.15s ease;
}

.mem-btn:hover { background: rgba(255, 255, 255, 0.22); }

.mem-btn-new {
  background: #ffd700;
  color: #1a1a2e;
  border-color: #e6c200;
}
.mem-btn-new:hover { background: #ffed4a; }

/* Difficulty toggle */
.mem-difficulty {
  display: flex;
  gap: 0;
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.18);
}

.mem-diff-opt {
  padding: 6px 12px;
  border: none;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  background: rgba(255, 255, 255, 0.08);
  color: rgba(255, 255, 255, 0.5);
  transition: background 0.15s ease, color 0.15s ease;
}

.mem-diff-opt.active {
  background: rgba(255, 255, 255, 0.22);
  color: #fff;
}

/* Theme toggle */
.mem-theme-toggle {
  display: flex;
  gap: 0;
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.18);
}

.mem-theme-opt {
  padding: 6px 10px;
  border: none;
  font-size: 0.82rem;
  cursor: pointer;
  background: rgba(255, 255, 255, 0.08);
  transition: background 0.15s ease;
}

.mem-theme-opt.active {
  background: rgba(255, 255, 255, 0.22);
}

.mem-stats {
  margin-left: auto;
  display: flex;
  gap: 16px;
  color: rgba(255, 255, 255, 0.6);
  font-size: 0.82rem;
}

.mem-stats span {
  font-weight: 600;
  color: #fff;
}

/* ── Game Board ── */
.mem-board {
  display: grid;
  gap: 8px;
  justify-content: center;
  padding: 8px 0;
}

.mem-board.grid-4x3 { grid-template-columns: repeat(4, 1fr); max-width: 380px; margin: 0 auto; }
.mem-board.grid-4x4 { grid-template-columns: repeat(4, 1fr); max-width: 380px; margin: 0 auto; }
.mem-board.grid-6x4 { grid-template-columns: repeat(6, 1fr); max-width: 560px; margin: 0 auto; }
.mem-board.grid-6x5 { grid-template-columns: repeat(6, 1fr); max-width: 560px; margin: 0 auto; }
.mem-board.grid-8x4 { grid-template-columns: repeat(8, 1fr); max-width: 720px; margin: 0 auto; }

/* ── Card Tile ── */
.mem-card {
  aspect-ratio: 1;
  perspective: 600px;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
}

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

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

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

.mem-card.matched {
  cursor: default;
}

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

/* Back face (what you see before flipping) */
.mem-card-back {
  background: linear-gradient(135deg, #3b5bdb, #5b7ff5);
  border: 2px solid rgba(255, 255, 255, 0.15);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.mem-card-back::after {
  content: '?';
  font-size: 1.5rem;
  font-weight: 700;
  color: rgba(255, 255, 255, 0.3);
}

/* Front face (revealed content) */
.mem-card-front {
  background: #fff;
  border: 2px solid #e0e0e0;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  transform: rotateY(180deg);
  font-size: clamp(1.4rem, 4vw, 2.4rem);
}

/* Matched state */
.mem-card.matched .mem-card-front {
  background: #e8f5e9;
  border-color: #66bb6a;
}

.mem-card.matched .mem-card-front::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 8px;
  background: rgba(102, 187, 106, 0.1);
}

/* Wrong match shake */
@keyframes mem-shake {
  0%, 100% { transform: rotateY(180deg) translateX(0); }
  20% { transform: rotateY(180deg) translateX(-4px); }
  40% { transform: rotateY(180deg) translateX(4px); }
  60% { transform: rotateY(180deg) translateX(-3px); }
  80% { transform: rotateY(180deg) translateX(2px); }
}

.mem-card.wrong .mem-card-inner {
  animation: mem-shake 0.4s ease;
}

.mem-card.wrong .mem-card-front {
  border-color: #e74c3c;
  background: #fde8e8;
}

/* ── Win Banner ── */
.mem-win {
  text-align: center;
  padding: 24px;
  display: none;
}

.mem-win.visible {
  display: block;
}

.mem-win-text {
  font-size: 1.6rem;
  font-weight: 700;
  color: #ffd700;
  margin-bottom: 6px;
}

.mem-win-stats {
  color: rgba(255, 255, 255, 0.7);
  font-size: 0.95rem;
  margin-bottom: 16px;
}

.mem-win-btn {
  padding: 10px 28px;
  border: none;
  border-radius: 8px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  background: #ffd700;
  color: #1a1a2e;
  transition: background 0.15s ease;
}

.mem-win-btn:hover { background: #ffed4a; }

/* ── Best Stats ── */
.mem-best {
  display: flex;
  gap: 20px;
  justify-content: center;
  color: rgba(255, 255, 255, 0.4);
  font-size: 0.72rem;
  padding-top: 8px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  margin-top: 12px;
}

.mem-best span {
  color: rgba(255, 255, 255, 0.7);
  font-weight: 600;
}

/* ── Responsive ── */
@media (max-width: 768px) {
  .memory-container { padding: 12px 8px; }
  .mem-controls { gap: 6px; margin-bottom: 10px; padding-bottom: 8px; }
  .mem-btn { padding: 5px 10px; font-size: 0.75rem; }
  .mem-diff-opt { padding: 5px 8px; font-size: 0.72rem; }
  .mem-theme-opt { padding: 5px 8px; font-size: 0.75rem; }
  .mem-stats { gap: 10px; font-size: 0.75rem; }
  .mem-board { gap: 6px; }
  .mem-card-back::after { font-size: 1.2rem; }
}

@media (max-width: 480px) {
  .memory-container { padding: 8px 4px; border-radius: 12px; }
  .mem-controls { justify-content: center; }
  .mem-stats { margin-left: 0; width: 100%; justify-content: center; }
  .mem-board { gap: 4px; }
  .mem-card-front { font-size: clamp(1rem, 5vw, 1.6rem); }
  .mem-card-back::after { font-size: 1rem; }
  .mem-win-text { font-size: 1.3rem; }
}
