* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --primary: #6c5ce7;
  --primary-dark: #5a4bd1;
  --accent: #ff7675;
  --bg-start: #2b1055;
  --bg-end: #7597de;
  --text: #2d3436;
  --card-back: linear-gradient(145deg, #6c5ce7, #a29bfe);
}

body {
  min-height: 100vh;
  background: linear-gradient(135deg, var(--bg-start), var(--bg-end));
  font-family: "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
  color: #fff;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 20px;
}

.app {
  width: 100%;
  max-width: 860px;
}

.header {
  text-align: center;
  margin-bottom: 18px;
}

.header h1 {
  font-size: 2.2rem;
  letter-spacing: 4px;
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.35);
}

.subtitle {
  margin-top: 6px;
  font-size: 0.95rem;
  opacity: 0.85;
}

.control-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: rgba(255, 255, 255, 0.12);
  backdrop-filter: blur(6px);
  border-radius: 14px;
  padding: 12px 16px;
  margin-bottom: 20px;
}

.difficulty {
  display: flex;
  align-items: center;
  gap: 6px;
}

.label {
  font-size: 0.9rem;
  opacity: 0.85;
  margin-right: 4px;
}

.diff-btn {
  border: none;
  cursor: pointer;
  padding: 7px 14px;
  border-radius: 8px;
  font-size: 0.9rem;
  background: rgba(255, 255, 255, 0.18);
  color: #fff;
  transition: all 0.2s;
}

.diff-btn:hover {
  background: rgba(255, 255, 255, 0.32);
}

.diff-btn.active {
  background: var(--accent);
  font-weight: 600;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.25);
}

.stats {
  display: flex;
  gap: 20px;
}

.stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 56px;
}

.stat-value {
  font-size: 1.35rem;
  font-weight: 700;
}

.stat-label {
  font-size: 0.75rem;
  opacity: 0.75;
}

.restart-btn {
  border: none;
  cursor: pointer;
  padding: 9px 18px;
  border-radius: 8px;
  font-size: 0.95rem;
  font-weight: 600;
  background: var(--accent);
  color: #fff;
  transition: all 0.2s;
}

.restart-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 14px rgba(255, 118, 117, 0.5);
}

.board-wrap {
  display: flex;
  justify-content: center;
}

.board {
  display: grid;
  gap: 12px;
  width: 100%;
  max-width: 720px;
  perspective: 1000px;
}

.card {
  position: relative;
  aspect-ratio: 1;
  cursor: pointer;
  transform-style: preserve-3d;
  transition: transform 0.45s ease, opacity 0.4s ease;
  user-select: none;
}

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

.card.eliminated {
  opacity: 0;
  transform: rotateY(180deg) scale(0.5);
  pointer-events: none;
}

.card .face {
  position: absolute;
  inset: 0;
  border-radius: 14px;
  backface-visibility: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
}

.card .back {
  background: var(--card-back);
  border: 3px solid rgba(255, 255, 255, 0.35);
}

.card .back::after {
  content: "";
  width: 40%;
  height: 40%;
  border-radius: 50%;
  border: 3px dashed rgba(255, 255, 255, 0.5);
}

.card .front {
  background: #fff;
  transform: rotateY(180deg);
  font-size: clamp(1.6rem, 5vw, 3rem);
  border: 3px solid rgba(0, 0, 0, 0.06);
}

.card:hover:not(.flipped):not(.eliminated) .back {
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.6), 0 4px 14px rgba(0, 0, 0, 0.25);
}

.card.matched-glow .front {
  background: #dfffd6;
  border-color: #2ecc71;
}

.footer {
  text-align: center;
  margin-top: 20px;
  font-size: 0.85rem;
  opacity: 0.7;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  backdrop-filter: blur(4px);
}

.modal.hidden {
  display: none;
}

.modal-content {
  background: #fff;
  color: var(--text);
  border-radius: 20px;
  padding: 36px 48px;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
  animation: pop-in 0.4s ease;
}

.modal-content h2 {
  font-size: 1.8rem;
  color: var(--primary);
  margin-bottom: 6px;
}

.modal-subtitle {
  color: #636e72;
  margin-bottom: 24px;
}

.modal-stats {
  display: flex;
  justify-content: center;
  gap: 32px;
  margin-bottom: 26px;
}

.modal-stats .stat-value {
  color: var(--primary);
}

.modal-stats #rating {
  font-size: 2.4rem;
  color: var(--accent);
}

.play-again-btn {
  border: none;
  cursor: pointer;
  padding: 12px 32px;
  border-radius: 10px;
  font-size: 1.05rem;
  font-weight: 600;
  background: var(--primary);
  color: #fff;
  transition: all 0.2s;
}

.play-again-btn:hover {
  background: var(--primary-dark);
  transform: translateY(-2px);
}

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

@media (max-width: 640px) {
  .control-bar {
    flex-direction: column;
    align-items: stretch;
  }

  .difficulty,
  .stats {
    justify-content: center;
  }

  .header h1 {
    font-size: 1.7rem;
  }
}
