/* 记忆翻牌 */
* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: system-ui, -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: linear-gradient(180deg, #e1bee7, #ba68c8);
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
}

#stage { position: relative; width: 500px; transform-origin: center; }

#topbar {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 4px;
  color: #4a148c;
}
#topbar a, #topbar button {
  font-size: 20px;
  width: 40px; height: 40px;
  border: none; border-radius: 12px;
  background: rgba(255, 255, 255, .75);
  cursor: pointer; text-decoration: none;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 3px 6px rgba(74, 20, 140, .25);
}
#topbar button:hover, #topbar a:hover { background: #fff; }

#statMoves, #statPairs, #statTime {
  display: flex; align-items: center; gap: 8px;
  background: rgba(255, 255, 255, .75);
  padding: 6px 14px; border-radius: 12px;
  font-size: 14px; font-weight: 700;
  box-shadow: 0 3px 6px rgba(74, 20, 140, .25);
}
#statMoves b, #statPairs b, #statTime b { font-size: 20px; color: #6a1b9a; }
#ctrlBtns { margin-left: auto; display: flex; gap: 8px; }

#grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  perspective: 900px;
}

.card {
  aspect-ratio: 1;
  background: none; border: none; padding: 0;
  cursor: pointer;
  position: relative;
}
.card .inner {
  position: absolute; inset: 0;
  transform-style: preserve-3d;
  transition: transform .3s ease;
}
.card.open .inner { transform: rotateY(180deg); }

.face {
  position: absolute; inset: 0;
  border-radius: 14px;
  display: flex; align-items: center; justify-content: center;
  font-size: clamp(28px, 9vw, 44px);
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}
.face.back {
  background: linear-gradient(150deg, #8e24aa, #4a148c);
  box-shadow: 0 6px 12px rgba(74, 20, 140, .35), inset 0 2px 0 rgba(255, 255, 255, .3);
  color: rgba(255, 255, 255, .7);
  font-size: 26px;
}
.face.front {
  background: #fff;
  transform: rotateY(180deg);
  box-shadow: 0 6px 12px rgba(74, 20, 140, .25);
}
.card.matched .face.front {
  background: #f3e5f5;
  box-shadow: 0 0 0 3px #ce93d8 inset;
}
.card.matched { animation: bounce .4s ease; }
@keyframes bounce {
  30% { transform: scale(1.12); }
  60% { transform: scale(.94); }
}

#overlay {
  position: absolute; inset: 44px 0 0 0;
  display: flex; align-items: center; justify-content: center;
  background: rgba(50, 10, 70, .45);
  border-radius: 16px;
  z-index: 2;
}
#overlay.hidden { display: none; }

.screen {
  background: #fff;
  border-radius: 20px;
  padding: 26px 34px;
  text-align: center;
  color: #4a148c;
  box-shadow: 0 14px 30px rgba(0, 0, 0, .3);
  animation: pop .22s ease;
}
@keyframes pop { from { transform: scale(.8); opacity: 0; } }
.screen h2 { font-size: 26px; margin-bottom: 10px; }
.screen p { font-size: 14px; color: #6a1b9a; margin-bottom: 16px; line-height: 1.8; }
.screen button {
  display: block; width: 200px; margin: 8px auto 0;
  padding: 10px 0;
  font-size: 16px; font-weight: 700;
  border: none; border-radius: 12px;
  background: #f3e5f5; color: #4a148c;
  cursor: pointer;
}
.screen button:hover { background: #e1bee7; }
.screen button.big { background: #ab47bc; color: #fff; font-size: 18px; padding: 12px 0; }
.screen button.big:hover { background: #8e24aa; }
