:root {
  --bg: #0d1117;
  --panel: #161b22;
  --border: #30363d;
  --ink: #e6edf3;
  --muted: #8b949e;
  --accent: #58a6ff;
  --back: #1f6feb;
  --match: #238636;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  line-height: 1.5;
}

.game {
  width: min(100%, 520px);
  margin: 0 auto;
  padding: 24px 16px 40px;
}

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

h1 {
  margin: 0;
  font-size: 1.9rem;
}

button {
  font: inherit;
  color: var(--ink);
  cursor: pointer;
}

#new-game {
  font-weight: 600;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 14px;
}

#new-game:hover {
  border-color: var(--accent);
}

button:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 3px;
}

.stats {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 24px;
  margin: 12px 0 0;
}

.stats div {
  display: flex;
  gap: 6px;
}

.stats dt {
  color: var(--muted);
}

.stats dd {
  margin: 0;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.help {
  color: var(--muted);
  margin: 12px 0 16px;
  font-size: 0.95rem;
}

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

.card {
  aspect-ratio: 3 / 4;
  border: 0;
  border-radius: 10px;
  background: none;
  padding: 0;
  perspective: 700px;
}

.card-inner {
  position: relative;
  display: block;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transition: transform 320ms ease;
}

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

.side {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: 10px;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}

.back {
  background:
    repeating-linear-gradient(45deg, rgba(255, 255, 255, 0.08) 0 6px, transparent 6px 12px),
    var(--back);
}

.front {
  transform: rotateY(180deg);
  background: var(--panel);
  font-size: clamp(1.6rem, 9vw, 2.6rem);
  line-height: 1;
}

.card.is-matched {
  cursor: default;
}

.card.is-matched .front {
  background: var(--match);
  border-color: var(--match);
}

.status {
  min-height: 1.5em;
  margin: 16px 0 0;
  text-align: center;
}

@media (max-width: 400px) {
  .game {
    padding: 16px 12px 32px;
  }

  h1 {
    font-size: 1.6rem;
  }

  .grid {
    gap: 8px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .card-inner {
    transition: none;
  }
}
