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

body {
  min-height: 100vh;
  background: #1a1a2e;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Segoe UI', sans-serif;
  color: #eee;
}

.container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
  padding: 24px;
}

h1 {
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: 3px;
  color: #e94560;
}

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

.stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.label {
  font-size: 0.7rem;
  letter-spacing: 2px;
  color: #888;
}

.stat span:last-child {
  font-size: 1.5rem;
  font-weight: bold;
  color: #fff;
}

.board {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}

.card {
  width: 120px;
  height: 160px;
  perspective: 600px;
  cursor: pointer;
}

.card-inner {
  width: 100%;
  height: 100%;
  position: relative;
  transform-style: preserve-3d;
  transition: transform 0.4s ease;
  border-radius: 12px;
}

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

.card-front,
.card-back {
  position: absolute;
  width: 100%;
  height: 100%;
  border-radius: 12px;
  backface-visibility: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 3rem;
  user-select: none;
}

.card-front {
  background:
    repeating-linear-gradient(
      45deg,
      rgba(255,255,255,0.03) 0px,
      rgba(255,255,255,0.03) 2px,
      transparent 2px,
      transparent 10px
    ),
    #16213e;
  border: 2px solid #e94560;
}

.card-back {
  background: #16213e;
  border: 2px solid #e94560;
  transform: rotateY(180deg);
}

.card.matched .card-back {
  background: #1a3a2a;
  border-color: #2ecc71;
}

.btn {
  padding: 12px 36px;
  background: transparent;
  color: #e94560;
  border: 2px solid #e94560;
  border-radius: 8px;
  font-size: 1rem;
  cursor: pointer;
  letter-spacing: 1px;
  transition: background 0.2s, color 0.2s;
}

.btn:hover {
  background: #e94560;
  color: #fff;
}

/* Win overlay */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
}

.overlay.hidden {
  display: none;
}

.win-box {
  background: #16213e;
  border: 2px solid #e94560;
  border-radius: 20px;
  padding: 40px 52px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  min-width: 320px;
}

.win-box h2 {
  font-size: 2.2rem;
  font-weight: 800;
  color: #e94560;
  letter-spacing: 2px;
}

.win-sub {
  font-size: 1rem;
  color: #aaa;
}

.win-stats {
  display: flex;
  gap: 48px;
  margin: 8px 0;
}

.win-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.win-stat strong {
  font-size: 2rem;
  font-weight: bold;
  color: #fff;
}

#bestMsg {
  color: #f0c040;
  font-size: 1rem;
  font-weight: bold;
}

/* Mobile */
@media (max-width: 480px) {
  body {
    overflow: hidden;
  }

  .container {
    height: 100dvh;
    gap: 8px;
    padding: 12px;
    justify-content: center;
  }

  h1 {
    font-size: 1.3rem;
  }

  .stats {
    gap: 24px;
  }

  .stat span:last-child {
    font-size: 1.1rem;
  }

  .btn {
    padding: 8px 24px;
    font-size: 0.9rem;
  }

  .board {
    gap: 6px;
  }

  .card {
    width: calc((100vw - 24px - 18px) / 4);
    height: calc((100vw - 24px - 18px) / 4 * 1.33);
  }

  .card-front,
  .card-back {
    font-size: 1.6rem;
  }

  .win-box {
    padding: 32px 28px;
    min-width: unset;
    width: 90vw;
  }
}
