*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg:          #0a0a0f;
  --surface:     #13131a;
  --card-back:   #1e1e2e;
  --card-border: #2a2a3d;
  --accent:      #7c3aed;
  --accent2:     #06b6d4;
  --text:        #e2e8f0;
  --muted:       #64748b;
  --match:       #10b981;
  --wrong:       #ef4444;
  --radius:      14px;
}

body {
  font-family: 'Space Mono', monospace;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 32px 16px;
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  background-image:
    linear-gradient(rgba(124, 58, 237, 0.04) 1px, transparent 1px),
    linear-gradient(90deg, rgba(124, 58, 237, 0.04) 1px, transparent 1px);
  background-size: 40px 40px;
  pointer-events: none;
  z-index: 0;
}

body > * {
  position: relative;
  z-index: 1;
}

#gameHeader {
  text-align: center;
  margin-bottom: 28px;
  width: 100%;
  max-width: 520px;
}

#gameHeader h2 {
  font-family: 'Syne', sans-serif;
  font-size: clamp(1.8rem, 5vw, 2.6rem);
  font-weight: 800;
  background: linear-gradient(135deg, var(--accent2), var(--accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: -1px;
  margin-bottom: 20px;
}

#statsBar {
  display: flex;
  gap: 12px;
  justify-content: center;
  margin-bottom: 20px;
}

.stat-box {
  background: var(--surface);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  padding: 10px 24px;
  text-align: center;
  min-width: 110px;
}

.stat-label {
  font-size: 0.6rem;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 2px;
}

.stat-value {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--accent2);
}

#newGameBtn {
  font-family: 'Space Mono', monospace;
  font-size: 0.75rem;
  letter-spacing: 2px;
  text-transform: uppercase;
  padding: 10px 28px;
  border-radius: var(--radius);
  border: 1px solid var(--card-border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  transition: border-color 0.2s, color 0.2s;
}

#newGameBtn:hover {
  border-color: var(--accent2);
  color: var(--accent2);
}

#gameBoard {
  display: grid;
  grid-template-columns: repeat(4, 80px);
  gap: 10px;
  justify-content: center;
  margin-bottom: 28px;
}

.card {
  width: 80px;
  height: 80px;
  perspective: 600px;
  cursor: pointer;
}

.card-inner {
  width: 100%;
  height: 100%;
  position: relative;
  transform-style: preserve-3d;
  transition: transform 0.45s cubic-bezier(0.4, 0, 0.2, 1);
}

.card.flipped .card-inner,
.card.matched .card-inner {
  transform: rotateY(180deg);
}

.card-face {
  position: absolute;
  inset: 0;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}

.card-back {
  background: var(--card-back);
  border: 1px solid var(--card-border);
  font-family: 'Syne', sans-serif;
  font-size: 1.8rem;
  font-weight: 800;
  color: var(--card-border);
}

.card-back::after {
  content: '?';
}

.card:not(.flipped):not(.matched):hover .card-back {
  border-color: var(--accent);
  box-shadow: 0 0 18px rgba(124, 58, 237, 0.25);
}

.card-front {
  background: var(--surface);
  border: 1px solid var(--accent);
  transform: rotateY(180deg);
  font-size: 2.2rem;
}

.card.matched .card-front {
  border-color: var(--match);
  background: rgba(16, 185, 129, 0.08);
  box-shadow: 0 0 20px rgba(16, 185, 129, 0.2);
  animation: matchPop 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes matchPop {
  0%   { transform: rotateY(180deg) scale(1); }
  50%  { transform: rotateY(180deg) scale(1.15); }
  100% { transform: rotateY(180deg) scale(1); }
}

.card.wrong .card-front {
  border-color: var(--wrong);
  animation: shake 0.4s ease;
}

@keyframes shake {
  0%, 100% { transform: rotateY(180deg) translateX(0); }
  20%       { transform: rotateY(180deg) translateX(-5px); }
  60%       { transform: rotateY(180deg) translateX(5px); }
  80%       { transform: rotateY(180deg) translateX(-3px); }
}

#winMessage {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  z-index: 100;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(8px);
}

#winMessage.show {
  display: flex;
}

.win-card {
  background: var(--surface);
  border: 1px solid var(--accent);
  border-radius: 24px;
  padding: 48px 56px;
  text-align: center;
  max-width: 380px;
  box-shadow: 0 0 60px rgba(124, 58, 237, 0.3);
  animation: winSlide 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes winSlide {
  from { transform: scale(0.7) translateY(40px); opacity: 0; }
  to   { transform: scale(1) translateY(0);      opacity: 1; }
}

.win-emoji {
  font-size: 4rem;
  display: block;
  margin-bottom: 12px;
  animation: bounce 1s infinite;
}

@keyframes bounce {
  0%, 100% { transform: translateY(0); }
  50%       { transform: translateY(-12px); }
}

.win-card h2 {
  font-family: 'Syne', sans-serif;
  font-size: 2.2rem;
  font-weight: 800;
  background: linear-gradient(135deg, #f59e0b, var(--accent2));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 8px;
}

.win-stats {
  display: flex;
  gap: 32px;
  justify-content: center;
  margin: 20px 0 28px;
}

.win-stat-val {
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--accent2);
}

.win-stat-lbl {
  font-size: 0.65rem;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--muted);
}

.win-btn {
  font-family: 'Space Mono', monospace;
  font-size: 0.8rem;
  letter-spacing: 2px;
  text-transform: uppercase;
  padding: 14px 32px;
  border-radius: var(--radius);
  border: none;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  color: #fff;
  cursor: pointer;
  font-weight: 700;
  transition: transform 0.2s, box-shadow 0.2s;
}

.win-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(124, 58, 237, 0.4);
}