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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #f1efe8;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #2c2c2a;
}

.game-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.25rem;
  padding: 2rem 1rem;
}

h1 {
  font-size: 2rem;
  font-weight: 500;
  color: #2c2c2a;
  letter-spacing: -0.02em;
}

.subtitle {
  font-size: 15px;
  color: #5f5e5a;
  text-align: center;
}

.hud {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  width: 460px;
  max-width: 100%;
}

.hud-box {
  background: #fff;
  border: 0.5px solid #d3d1c7;
  border-radius: 8px;
  padding: 0.5rem 1.5rem;
  text-align: center;
  flex: 1;
}

.hud-label {
  font-size: 12px;
  color: #888780;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.hud-value {
  font-size: 24px;
  font-weight: 500;
  color: #2c2c2a;
  line-height: 1.3;
}

.hud-value.urgent {
  color: #e24b4a;
}

.restart-btn {
  background: #fff;
  border: 0.5px solid #888780;
  border-radius: 8px;
  padding: 0.6rem 1.5rem;
  font-size: 15px;
  font-weight: 500;
  color: #2c2c2a;
  cursor: pointer;
  transition: background 0.15s;
  white-space: nowrap;
}

.restart-btn:hover {
  background: #f1efe8;
}

.restart-btn:active {
  transform: scale(0.98);
}

.board-wrap {
  position: relative;
}

.board {
  display: grid;
  grid-template-columns: repeat(4, 100px);
  grid-template-rows: repeat(4, 100px);
  gap: 12px;
  background: #fff;
  border: 0.5px solid #d3d1c7;
  border-radius: 16px;
  padding: 20px;
}

.card {
  width: 100px;
  height: 100px;
  cursor: pointer;
  perspective: 700px;
}

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

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

.card-front,
.card-back {
  position: absolute;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}

.card-front {
  background: #888780;
  border: 2.5px solid #b4b2a9;
  transition: background 0.15s;
}

.card:hover:not(.flipped):not(.matched) .card-front {
  background: #a0a098;
}

.card-back {
  transform: rotateY(180deg);
  border: 3px solid rgba(255, 255, 255, 0.4);
}

.card.matched .card-back {
  border-color: rgba(255, 255, 255, 0.8);
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.35);
}

.overlay {
  display: none;
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  border-radius: 16px;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  z-index: 10;
}

.overlay.visible {
  display: flex;
}

.overlay-title {
  font-size: 28px;
  font-weight: 500;
  color: #fff;
}

.overlay-score {
  font-size: 18px;
  color: rgba(255, 255, 255, 0.85);
}

.overlay .restart-btn {
  background: rgba(255, 255, 255, 0.15);
  border-color: rgba(255, 255, 255, 0.6);
  color: #fff;
  margin-top: 0.5rem;
}

.overlay .restart-btn:hover {
  background: rgba(255, 255, 255, 0.25);
}

.msg {
  min-height: 22px;
  font-size: 14px;
  color: #5f5e5a;
  text-align: center;
}

@media (max-width: 520px) {
  .board {
    grid-template-columns: repeat(4, 72px);
    grid-template-rows: repeat(4, 72px);
    gap: 8px;
    padding: 14px;
  }
  .card {
    width: 72px;
    height: 72px;
  }
  .hud {
    width: 100%;
  }
}
