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

body {
  margin: 0;
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  color: #e5e5e5;
  background: #121212;
  min-height: 100vh;
  padding: 0.5rem;
  -webkit-tap-highlight-color: transparent;
}

.header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem 1rem;
  margin-bottom: 1rem;
}

.back-link {
  font-size: 0.95rem;
  color: #a0a0a0;
  text-decoration: none;
}

.back-link:hover,
.back-link:focus {
  color: #f5f5f5;
  text-decoration: underline;
}

.header h1 {
  margin: 0;
  font-size: 1.75rem;
  color: #f5f5f5;
}

.header-right {
  margin-left: auto;
}

#new-game {
  min-height: 44px;
  padding: 0.5rem 0.75rem;
  font-size: 0.95rem;
  font-weight: 500;
  border: 1px solid #505050;
  border-radius: 8px;
  background: #252525;
  color: #e5e5e5;
  cursor: pointer;
}

#new-game:hover,
#new-game:focus {
  background: #333;
  border-color: #666;
}

.main {
  max-width: 420px;
  margin: 0 auto;
}

#win-message {
  text-align: center;
  margin-bottom: 1rem;
  font-size: 1.25rem;
  font-weight: 600;
  color: #86efac;
}

#win-message[hidden] {
  display: none;
}

.memory-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(4, 1fr);
  gap: 8px;
  aspect-ratio: 1;
  max-width: min(92vmin, 320px);
  margin: 0 auto 1rem;
  padding: 8px;
  background: #252525;
  border: 2px solid #333;
  border-radius: 12px;
}

.memory-card {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(20px, 5vmin, 32px);
  font-weight: 700;
  border: none;
  border-radius: 8px;
  background: #3d3d2e;
  color: #252525;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.memory-card:hover:not(.flipped):not(.matched) {
  background: #4a4a35;
  color: #e5e5e5;
}

.memory-card.flipped,
.memory-card.matched {
  background: #6b6b44;
  color: #f5f5f5;
  cursor: default;
}

.memory-card.matched {
  background: #2d5a3d;
  color: #e5e5e5;
}

.hint {
  margin: 0;
  font-size: 0.85rem;
  color: #707070;
  text-align: center;
}
