body {
  font-family: Inter, sans-serif;
}

.tool-card {
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 0.75rem;
  padding: 1rem;
  box-shadow: 0 3px 12px rgba(0, 0, 0, 0.04);
}

/* Score pills */
.score-pill {
  background: #1f2937;
  border-radius: 8px;
  padding: 5px 10px;
  text-align: center;
  min-width: 52px;
}
.score-pill .label {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: #9ca3af;
  text-transform: uppercase;
}
.score-pill .value {
  font-size: 18px;
  font-weight: 800;
  color: #fff;
  line-height: 1.2;
}

/* Difficulty tabs */
.diff-btn {
  border: 1px solid #e5e7eb;
  border-radius: 99px;
  padding: 4px 12px;
  font-size: 12px;
  font-weight: 600;
  color: #6b7280;
  background: #fff;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}
.diff-btn:hover {
  border-color: #6ee7b7;
  color: #065f46;
  background: #f0fdf4;
}
.diff-btn.active {
  border-color: #059669;
  color: #065f46;
  background: #ecfdf5;
}

/* Card Grid */
#card-grid {
  display: grid;
  gap: 8px;
  width: 100%;
  max-width: 340px;
}
#card-grid.grid-4x4 {
  grid-template-columns: repeat(4, 1fr);
}
#card-grid.grid-4x5 {
  grid-template-columns: repeat(4, 1fr);
}
#card-grid.grid-5x6 {
  grid-template-columns: repeat(5, 1fr);
  max-width: 380px;
}

/* Card — uses JS-based show/hide instead of 3D flip to avoid backface blur */
.card {
  aspect-ratio: 1;
  position: relative;
  cursor: pointer;
  border-radius: 10px;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
}

/* Back face (default visible) */
.card-back {
  position: absolute;
  inset: 0;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #059669 0%, #047857 100%);
  border: 2px solid #34d399;
  font-size: 22px;
  font-weight: 800;
  color: rgba(255, 255, 255, 0.55);
  transition: opacity 0.2s;
}

/* Front face — NO scale() to avoid emoji blur on mobile */
.card-front {
  position: absolute;
  inset: 0;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #fff;
  border: 2px solid #e5e7eb;
  font-size: 32px;
  line-height: 1;
  opacity: 0;
  transition: opacity 0.2s;
}

/* Flipped: opacity only, no scale transform */
.card.flipped .card-back,
.card.matched .card-back {
  opacity: 0;
}
.card.flipped .card-front,
.card.matched .card-front {
  opacity: 1;
}
.card.matched .card-front {
  background: #ecfdf5;
  border-color: #6ee7b7;
}
.card.matched {
  cursor: default;
}

/* Pop on match — uses card wrapper scale, emoji inside stays at native size */
@keyframes matchPop {
  0% {
    transform: scale(1);
  }
  40% {
    transform: scale(1.08);
  }
  100% {
    transform: scale(1);
  }
}
.card.matched {
  animation: matchPop 0.25s ease-out;
}
/* Ensure emoji inside matched card never gets sub-pixel scaled */
.card.matched .card-front {
  will-change: auto;
}

/* Shake on mismatch */
@keyframes mismatch {
  0%,
  100% {
    transform: translateX(0);
  }
  25% {
    transform: translateX(-5px);
  }
  75% {
    transform: translateX(5px);
  }
}
.card.wrong {
  animation: mismatch 0.3s ease-in-out;
}

/* Toast */
#toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(0);
  background: #1f2937;
  color: #fff;
  padding: 10px 20px;
  border-radius: 99px;
  font-size: 13px;
  font-weight: 600;
  pointer-events: none;
  opacity: 0;
  transition:
    opacity 0.3s,
    transform 0.3s;
  z-index: 999;
  white-space: nowrap;
}
#toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(-8px);
}

/* Win overlay */
#win-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
}
#win-overlay.show {
  opacity: 1;
  pointer-events: all;
}
.win-card {
  background: #fff;
  border-radius: 1.25rem;
  padding: 1.75rem 2rem;
  text-align: center;
  max-width: 300px;
  width: 90%;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
  animation: winSlide 0.4s cubic-bezier(0.4, 0, 0.2, 1) both;
}
@keyframes winSlide {
  from {
    transform: translateY(30px) scale(0.95);
    opacity: 0;
  }
  to {
    transform: translateY(0) scale(1);
    opacity: 1;
  }
}
.win-stat {
  background: #f9fafb;
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  padding: 8px 12px;
  text-align: center;
}
.win-stat .wlabel {
  font-size: 9px;
  font-weight: 700;
  color: #9ca3af;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.win-stat .wvalue {
  font-size: 20px;
  font-weight: 800;
  color: #111827;
}

/* Related games */
.related-game-card {
  display: flex;
  align-items: center;
  gap: 10px;
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  padding: 10px 12px;
  text-decoration: none;
  color: inherit;
  transition:
    border-color 0.15s,
    box-shadow 0.15s,
    transform 0.15s;
}
.related-game-card:hover {
  border-color: #6ee7b7;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.07);
  transform: translateY(-1px);
}
.related-icon {
  width: 40px;
  height: 40px;
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
}

@keyframes timerPulse {
  0%,
  100% {
    color: #ef4444;
  }
  50% {
    color: #fca5a5;
  }
}
.timer-warn {
  animation: timerPulse 0.8s ease-in-out infinite;
}
