@import url('https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;500;600;700&family=Outfit:wght@500;600;700;800&display=swap');

:root {
  color-scheme: light;
  --ink: #292641;
  --muted: #8d8ba3;
  --purple: #7666ed;
  --purple-dark: #6656de;
  --lavender: #f0edff;
  --surface: #ffffff;
}

* { box-sizing: border-box; }

body {
  min-height: 100vh;
  margin: 0;
  padding: 26px 20px 18px;
  display: flex;
  justify-content: center;
  align-items: center;
  color: var(--ink);
  background:
    radial-gradient(ellipse at 8% 15%, rgba(255, 215, 226, .55), transparent 26%),
    radial-gradient(ellipse at 92% 82%, rgba(206, 224, 255, .64), transparent 29%),
    #f7f6fc;
  font-family: 'DM Sans', sans-serif;
}

button { font: inherit; }

.game-shell { width: min(100%, 590px); }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 7px 18px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--ink);
  text-decoration: none;
  font-family: 'Outfit', sans-serif;
  font-size: 19px;
  font-weight: 700;
  letter-spacing: -.7px;
}

.brand-mark { color: var(--purple); font-size: 23px; }
.brand-accent { color: var(--purple); }
.level-pill { color: #77748e; font-size: 10px; font-weight: 700; letter-spacing: 1.2px; }
.level-dot { display: inline-block; width: 7px; height: 7px; margin: 0 5px 1px 0; border-radius: 50%; background: #69c9a4; }

.game-card {
  padding: 34px 38px 23px;
  overflow: hidden;
  border: 1px solid rgba(226, 222, 244, .78);
  border-radius: 26px;
  background: var(--surface);
  box-shadow: 0 20px 65px rgba(54, 45, 104, .10), 0 3px 10px rgba(54, 45, 104, .03);
}

.intro { text-align: center; }
.eyebrow { color: var(--purple); font-size: 10px; font-weight: 700; letter-spacing: 1.6px; }
.eyebrow span { margin-right: 4px; font-size: 13px; }
h1 { margin: 7px 0 4px; font: 700 clamp(30px, 7vw, 38px)/1.2 'Outfit', sans-serif; letter-spacing: -1.4px; }
.intro p { margin: 0; color: var(--muted); font-size: 13px; }

.difficulty-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin: 20px 0 -10px;
}
.difficulty-row label { color: #a09db2; font-size: 9px; font-weight: 700; letter-spacing: 1.2px; }
.difficulty-row select {
  padding: 7px 27px 7px 10px;
  border: 1px solid #e8e5f5;
  border-radius: 9px;
  color: #6c5cdb;
  background: #fff;
  font: 600 11px 'DM Sans', sans-serif;
  cursor: pointer;
}
.difficulty-row select:focus-visible { outline: 3px solid #312878; outline-offset: 2px; }

.scoreboard {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(12px, 3vw, 27px);
  margin: 25px 0 8px;
  padding: 13px 10px;
  border: 1px solid #eeecf7;
  border-radius: 14px;
  background: #fbfaff;
}

.stat { min-width: 51px; text-align: center; }
.stat-label { display: block; margin-bottom: 2px; color: #a09db2; font-size: 9px; font-weight: 700; letter-spacing: 1.2px; }
.stat-value { color: var(--ink); font: 700 20px 'Outfit', sans-serif; }
.stat-total { color: #aaa7bb; font-size: 13px; font-weight: 500; }
.stat-divider { width: 1px; height: 27px; background: #e9e6f3; }
.best-score { margin: 0 0 13px; color: #9996ad; text-align: center; font-size: 10px; }

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

.memory-card {
  position: relative;
  aspect-ratio: 1 / 1;
  padding: 0;
  border: 0;
  border-radius: 15px;
  background: transparent;
  cursor: pointer;
  perspective: 700px;
  -webkit-tap-highlight-color: transparent;
}

.card-inner {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  border-radius: inherit;
  transform-style: preserve-3d;
  transition: transform .42s cubic-bezier(.2, .75, .25, 1);
}

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

.card-face {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  border-radius: inherit;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}

.card-back {
  color: rgba(255, 255, 255, .9);
  background: linear-gradient(145deg, #8f80fa, #7060e9);
  box-shadow: 0 5px 11px rgba(108, 89, 221, .19);
  transition: background .2s, box-shadow .2s, transform .2s;
}

.card-back::before {
  content: '✦';
  font: 24px 'Outfit', sans-serif;
  opacity: .84;
}

.memory-card:hover:not(.is-open):not(.is-matched) .card-back {
  background: linear-gradient(145deg, #9c8eff, #7969f0);
  box-shadow: 0 8px 16px rgba(108, 89, 221, .26);
  transform: translateY(-2px);
}

.card-front {
  border: 1px solid #eeecf7;
  background: #fbfaff;
  font-size: clamp(27px, 7vw, 39px);
  transform: rotateY(180deg);
}

.memory-card.is-matched .card-front {
  border-color: #c9f0df;
  background: #effbf5;
  animation: match-pop .35s ease-out;
}

.memory-card:focus-visible { outline: 3px solid #312878; outline-offset: 3px; }
.memory-card:disabled { cursor: default; }

@keyframes match-pop {
  0% { transform: rotateY(180deg) scale(.9); }
  65% { transform: rotateY(180deg) scale(1.07); }
  100% { transform: rotateY(180deg) scale(1); }
}

.win-message {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 11px;
  margin-top: 17px;
  padding: 12px;
  border: 1px solid #c9f0df;
  border-radius: 13px;
  background: #f2fcf7;
  text-align: left;
  animation: appear .35s ease-out;
}

.win-message[hidden] { display: none; }
.win-icon { font-size: 25px; }
.win-message strong, .win-message small { display: block; }
.win-message strong { color: #26835e; font: 700 14px 'Outfit', sans-serif; }
.win-message small { margin-top: 3px; color: #729184; font-size: 11px; line-height: 1.6; }
.win-message small b { color: #397a60; }
.win-copy { flex: 1; }
.play-again-button { flex-shrink: 0; }
@keyframes appear { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: translateY(0); } }

.game-footer { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 20px; }
.tip { color: #9996ad; font-size: 11px; }
.tip span { margin-right: 4px; }
.restart-button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 13px;
  border: 1px solid #e8e5f5;
  border-radius: 10px;
  color: #6c5cdb;
  background: #fff;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  transition: background .2s, border-color .2s, transform .2s;
}
.restart-button span { font-size: 16px; line-height: 12px; }
.restart-button:hover { transform: translateY(-1px); border-color: #d6d0f7; background: #faf9ff; }
.restart-button:focus-visible { outline: 3px solid #312878; outline-offset: 3px; }
.page-footer { padding-top: 18px; color: #aaa7b9; text-align: center; font-size: 10px; letter-spacing: .25px; }
.page-footer span { color: #ee8eaa; }

@media (max-width: 520px) {
  body { padding: 16px 14px; align-items: center; }
  .topbar { padding: 0 4px 14px; }
  .game-card { padding: 27px 20px 19px; border-radius: 22px; }
  .scoreboard { gap: clamp(8px, 3vw, 16px); margin: 21px 0 8px; }
  .stat { min-width: 42px; }
  .stat-label { font-size: 8px; }
  .stat-value { font-size: 17px; }
  .board { gap: 9px; }
  .memory-card { border-radius: 12px; }
  .card-back::before { font-size: 21px; }
  .game-footer { align-items: flex-start; }
  .tip { padding-top: 8px; font-size: 10px; }
  .win-message { flex-wrap: wrap; }
  .play-again-button { margin-left: 35px; }
}

@media (max-width: 360px) {
  .game-card { padding-right: 15px; padding-left: 15px; }
  .board { gap: 7px; }
  .game-footer { flex-direction: column; align-items: center; }
  .tip { padding-top: 0; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
