.memory-game {
  max-width: 1100px;
  margin: 0 auto;
  padding: 12px;
  text-align: center;
}

.memory-game h2 {
  font-size: 1.7rem;
  color: #ff69a6;
}

.memory-stats {
  display: flex;
  justify-content: center;
  gap: 20px;
  margin: 18px 0;
  font-size: 1.1rem;
}

.memory-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  width: 100%;
}

.memory-card {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  padding: 0;
  border: 3px solid #fff;
  border-radius: 14px;
  overflow: hidden;
  background: #fff;
  cursor: pointer;
  box-shadow: 0 3px 10px #0002;
  transition: transform 0.2s;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.memory-card:active {
  transform: scale(0.96);
}

.memory-card img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  transition: opacity 0.25s;
}

.memory-card-back {
  opacity: 1;
}

.memory-card-front {
  opacity: 0;
}

.memory-card.flipped .memory-card-back,
.memory-card.matched .memory-card-back {
  opacity: 0;
}

.memory-card.flipped .memory-card-front,
.memory-card.matched .memory-card-front {
  opacity: 1;
}

.memory-card.matched {
  border-color: #78dba4;
  box-shadow: 0 0 12px #78dba488;
}

.memory-victory[hidden] {
  display: none;
}

@media (min-width: 600px) {
  .memory-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 12px;
  }
}

@media (min-width: 1000px) {
  .memory-grid {
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 14px;
  }
}

.memory-restart {
  margin: 22px auto;
  padding: 14px 24px;
  border: none;
  border-radius: 20px;
  background: #ff83b5;
  color: white;
  font-size: 1.1rem;
  font-weight: bold;
  cursor: pointer;
}

.memory-victory {
  margin-top: 20px;
  padding: 20px;
  border-radius: 20px;
  background: #d9ffe8;
  font-size: 1.3rem;
  font-weight: bold;
}

/* Écran indépendant du Memory */
#memoryScreen.hidden {
  display: none !important;
}

#memoryScreen {
  position: fixed;
  inset: 0;
  z-index: 1000;
  overflow-y: auto;
  background: #fff3fa;
  padding: 20px 12px;
  box-sizing: border-box;
}

.memory-page {
  max-width: 1000px;
  margin: 0 auto;
  padding: 20px;
  border-radius: 28px;
  background: white;
  box-sizing: border-box;
}

.memory-back {
  display: block;
  margin-bottom: 20px;
  padding: 12px 18px;
  border: none;
  border-radius: 14px;
  background: #ffe3f0;
  color: #674866;
  font-size: 16px;
  cursor: pointer;
}

/* Petite invitation à retourner la première carte */
@keyframes memoryHop {
  0%, 100% { transform: translateY(0); }
  40% { transform: translateY(-9px); }
  60% { transform: translateY(-9px); }
}

.memory-card.memory-hint {
  animation: memoryHop 0.8s ease-in-out infinite;
  box-shadow: 0 5px 16px #ff83b566;
}

@media (prefers-reduced-motion: reduce) {
  .memory-card.memory-hint {
    animation: none;
  }
}

/* Révision du vocabulaire après la victoire */
.memory-game.memory-complete .memory-card-front {
  filter: grayscale(100%);
  opacity: 0.35;
}

.memory-korean-label {
  display: none;
}

.memory-game.memory-complete .memory-korean-label {
  display: flex;
  position: absolute;
  inset: 0;
  z-index: 5;
  align-items: center;
  justify-content: center;
  padding: 4px;
  color: #222;
  font-size: clamp(24px, 4vw, 46px);
  font-weight: 900;
  text-shadow: 0 1px 3px white;
  pointer-events: none;
}

.memory-game.memory-complete .memory-card {
  border-color: #bbb;
  box-shadow: none;
}

/* Mot coréen et haut-parleur de révision */
.memory-game.memory-complete .memory-korean-label {
  flex-direction: column;
  gap: 6px;
}

.memory-korean-word {
  display: block;
  line-height: 1.15;
  text-align: center;
}

.memory-speaker {
  display: block;
  font-size: 25px;
  line-height: 1;
  opacity: 0.9;
}

.memory-game.memory-complete .memory-card {
  cursor: pointer;
}

@keyframes memorySpeakerPulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.15); }
}

.memory-game.memory-complete .memory-speaker {
  animation: memorySpeakerPulse 1.5s ease-in-out infinite;
}

@media (prefers-reduced-motion: reduce) {
  .memory-game.memory-complete .memory-speaker {
    animation: none;
  }
}

/* Haut-parleur flashy pour la révision */
.memory-game.memory-complete .memory-speaker {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  margin: 3px auto 0;
  border-radius: 50%;
  background: linear-gradient(135deg, #ffea00, #ff48bc 65%, #a600ff);
  border: 2px solid #fff;
  box-shadow:
    0 0 0 3px #ff48bc,
    0 0 14px #ff00b8,
    0 0 25px #ffd900,
    inset 0 3px 6px rgba(255,255,255,.8);
  font-size: 23px;
  text-shadow: 0 1px 2px #fff;
  animation: memorySpeakerPulse 1.5s ease-in-out infinite;
}

@media (max-width: 480px) {
  .memory-game.memory-complete .memory-speaker {
    width: 32px;
    height: 32px;
    font-size: 19px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .memory-game.memory-complete .memory-speaker {
    animation: none;
  }
}


/* Invitation à réécouter après la victoire */
.memory-replay-hint {
  margin: 14px auto 8px;
  padding: 12px 16px;
  max-width: 420px;
  border-radius: 16px;
  background: linear-gradient(135deg, #fff0fa, #fff8d8);
  border: 2px solid #ff79c8;
  color: #a40076;
  font-size: clamp(15px, 3vw, 19px);
  font-weight: 800;
  line-height: 1.5;
  text-align: center;
  box-shadow: 0 4px 12px rgba(255, 72, 188, .18);
}


/* Bouton réservé aux tests */
.memory-debug {
  display: block;
  margin: 18px auto;
  padding: 12px 20px;
  border: 2px dashed #a855f7;
  border-radius: 14px;
  background: #f3e8ff;
  color: #6b21a8;
  font-size: 15px;
  font-weight: 800;
  cursor: pointer;
}

.memory-debug:hover {
  background: #e9d5ff;
}

/* Bouton lecture blanc */
.memory-game.memory-complete .memory-speaker {
  color: #ffffff;
  font-family: Arial, sans-serif;
  font-size: 25px;
  text-shadow: 0 2px 4px rgba(0,0,0,.35);
  padding-left: 3px;
}


/* Bouton lecture : rond bleu clair uni */
.memory-game.memory-complete .memory-speaker {
  width: 36px;
  height: 36px;
  background: #55BDEB;
  border: none;
  border-radius: 50%;
  box-shadow: none;
  color: white;
  font-size: 22px;
  text-shadow: none;
  padding-left: 3px;
  animation: memorySpeakerPulse 1.5s ease-in-out infinite;
}

@media (prefers-reduced-motion: reduce) {
  .memory-game.memory-complete .memory-speaker {
    animation: none;
  }
}

