:root {
  --bg: #f3f7ff;
  --surface: #ffffff;
  --text: #1f2937;
  --muted: #4b5563;
  --primary: #0f766e;
  --primary-dark: #0b5f59;
  --border: #dbe4ef;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  background: radial-gradient(circle at top, #deebff 0%, var(--bg) 45%, #eaf6ff 100%);
  color: var(--text);
  min-height: 100vh;
}

.container {
  max-width: 860px;
  margin: 0 auto;
  padding: 20px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.topbar h1 {
  margin: 0;
  font-size: 2rem;
  text-align: center;
}

.back-link {
  color: var(--primary);
  text-decoration: none;
  font-weight: 600;
}

.hud {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  margin-bottom: 16px;
}

.hud p {
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
}

button {
  border: none;
  border-radius: 10px;
  background: var(--primary);
  color: #fff;
  font-weight: 700;
  cursor: pointer;
  padding: 10px 12px;
}

button:hover {
  background: var(--primary-dark);
}

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

.card {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  border: none;
  background: transparent;
  cursor: pointer;
  perspective: 700px;
  padding: 0;
}

.card:focus-visible {
  outline: 3px solid #2563eb;
  outline-offset: 2px;
}

.card-inner {
  position: absolute;
  inset: 0;
  transition: transform 0.25s ease;
  transform-style: preserve-3d;
}

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

.card-face {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  border-radius: 12px;
  backface-visibility: hidden;
  border: 1px solid var(--border);
}

.card-front {
  background: linear-gradient(135deg, #0ea5a5, #0891b2);
  color: #fff;
  font-size: 1.6rem;
}

.card-back {
  background: #fff;
  transform: rotateY(180deg);
  font-size: 2.1rem;
}

.card.matched .card-back {
  box-shadow: inset 0 0 0 2px #16a34a;
}

.message-box {
  margin-top: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
}

.message-box p {
  margin: 0;
  color: var(--muted);
}

@media (max-width: 600px) {
  .topbar h1 {
    font-size: 1.5rem;
  }

  .hud {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
