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

body {
  background: #202124;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  color: #e8eaed;
  user-select: none;
  -webkit-user-select: none;
}

#back-btn {
  position: fixed;
  top: 16px;
  right: 16px;
  color: #fff;
  text-decoration: none;
  font-size: 22px;
  font-weight: 700;
  z-index: 20;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  background: #5f6368;
  transition: background 0.2s;
  line-height: 1;
}

#back-btn:hover {
  background: #80868b;
}

#game-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 20px;
  width: 100%;
  max-width: 700px;
}

/* Toolbar */
#toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 0 4px;
}

.toolbar-icon {
  width: 20px;
  height: 20px;
  vertical-align: middle;
}

#move-counter,
#timer-display {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 18px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  min-width: 80px;
}

#timer-display {
  justify-content: flex-end;
}

#new-game-btn {
  background: #3c4043;
  border: none;
  padding: 10px 20px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  color: #e8eaed;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}

#new-game-btn:hover {
  background: #5f6368;
}

#new-game-btn:active {
  transform: scale(0.95);
}

/* Difficulty */
#difficulty-bar {
  display: flex;
  gap: 6px;
  background: #292a2d;
  padding: 4px;
  border-radius: 12px;
}

.diff-btn {
  padding: 8px 20px;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: #9aa0a6;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.diff-btn:hover {
  color: #e8eaed;
}

.diff-btn.active {
  background: #e07cba;
  color: #fff;
}

#pairs-display {
  font-size: 15px;
  color: #9aa0a6;
  font-weight: 600;
}

#best-display {
  font-size: 14px;
  color: #9aa0a6;
}

/* Board */
#board {
  display: grid;
  gap: 10px;
  padding: 10px;
}

/* Card */
.card {
  position: relative;
  cursor: pointer;
  perspective: 600px;
}

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

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

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

.card-front {
  background: #3c4043;
  border: 2px solid #4a4a4e;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.card:hover .card-front {
  border-color: #e07cba;
  box-shadow: 0 0 12px rgba(224, 124, 186, 0.2);
}

.card-front::after {
  content: "?";
  font-size: 28px;
  font-weight: 800;
  color: #5f6368;
}

.card-back {
  transform: rotateY(180deg);
  background: #292a2d;
  border: 2px solid #4a4a4e;
  font-size: 36px;
  line-height: 1;
}

.card.matched .card-back {
  border-color: #4caf50;
  background: rgba(76, 175, 80, 0.1);
  box-shadow: 0 0 16px rgba(76, 175, 80, 0.15);
}

.card.matched {
  cursor: default;
}

.card.mismatch .card-back {
  border-color: #ef5350;
  background: rgba(239, 83, 80, 0.1);
}

/* Win overlay */
#win-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 30;
}

#win-overlay .win-box {
  background: #303134;
  border-radius: 16px;
  padding: 40px;
  text-align: center;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
}

#win-overlay h2 {
  font-size: 28px;
  margin-bottom: 8px;
  color: #e07cba;
}

#win-overlay p {
  font-size: 16px;
  color: #9aa0a6;
  margin-bottom: 20px;
  line-height: 1.6;
}

#win-overlay button {
  background: #e07cba;
  border: none;
  padding: 12px 32px;
  border-radius: 8px;
  font-size: 16px;
  font-weight: 600;
  color: #fff;
  cursor: pointer;
  transition: background 0.15s;
}

#win-overlay button:hover {
  background: #e896c8;
}

@keyframes matchPop {
  0% { transform: rotateY(180deg) scale(1); }
  50% { transform: rotateY(180deg) scale(1.08); }
  100% { transform: rotateY(180deg) scale(1); }
}

.card.matched .card-inner {
  animation: matchPop 0.35s ease;
}

@media (max-width: 520px) {
  #game-container {
    padding: 12px;
  }

  #board {
    gap: 6px;
    padding: 6px;
  }

  .card-back {
    font-size: 24px;
  }

  .card-front::after {
    font-size: 20px;
  }

  .diff-btn {
    padding: 6px 14px;
    font-size: 12px;
  }
}
