@import url('https://fonts.googleapis.com/css2?family=Nunito:wght@400;600;700;800;900&display=swap');

:root {
  font-family: 'Nunito', 'Trebuchet MS', sans-serif;
  color: #26304a;
  background: #f5f7ff;
  font-synthesis: none;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 8% 10%, #e5eaff 0, transparent 28rem),
    radial-gradient(circle at 92% 80%, #ffe9dc 0, transparent 25rem),
    #f5f7ff;
}
button, select { font: inherit; }
button { cursor: pointer; }
.game-shell { width: min(900px, calc(100% - 32px)); margin: 0 auto; padding: 34px 0 22px; }
.hero { text-align: center; margin-bottom: 24px; }
.eyebrow { color: #6878b3; font-size: .76rem; font-weight: 900; letter-spacing: .16em; }
h1 { margin: 8px 0 4px; color: #26345d; font-size: clamp(2rem, 5vw, 3.25rem); line-height: 1.1; font-weight: 900; }
h1 span { color: #7968df; }
.hero p { color: #77809c; margin: 10px 0 0; font-size: 1rem; }
.game-panel {
  background: rgba(255,255,255,.94); border: 1px solid #e7eafd; border-radius: 25px;
  padding: 22px; box-shadow: 0 18px 55px rgba(66,76,140,.10);
}
.toolbar { display: flex; align-items: end; justify-content: space-between; gap: 12px; margin-bottom: 18px; }
.level-picker { display: grid; gap: 5px; color: #7a829c; font-size: .78rem; font-weight: 800; }
select { background: #f5f6ff; color: #384366; border: 1px solid #e2e6fa; border-radius: 11px; padding: 9px 12px; outline-color: #8d7ceb; font-weight: 800; }
.restart-button, .sound-button { border: 0; border-radius: 11px; padding: 10px 14px; background: #eeeaff; color: #6654cc; font-weight: 900; }
.restart-button:hover, .sound-button:hover { background: #e4defe; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stat { display: flex; align-items: center; justify-content: center; gap: 9px; padding: 12px 8px; background: #f7f8ff; border: 1px solid #edf0ff; border-radius: 14px; }
.stat-icon { font-size: 1.35rem; }
.stat strong, .stat small { display: block; }
.stat strong { color: #35416d; font-size: 1.12rem; line-height: 1.1; }
.stat small { color: #8990a9; font-size: .7rem; font-weight: 800; margin-top: 3px; }
.message { min-height: 42px; display: grid; place-items: center; text-align: center; padding: 10px 4px; color: #7165c7; font-weight: 800; }
.game-board { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 11px; }
.card { position: relative; width: 84%; justify-self: center; aspect-ratio: 1 / .92; min-width: 0; border: 0; border-radius: 15px; background: transparent; perspective: 700px; padding: 0; }
.card-inner { position: absolute; inset: 0; display: grid; transition: transform .42s cubic-bezier(.2,.7,.2,1); 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: 15px; backface-visibility: hidden; }
.card-back { color: #fff; font-size: clamp(1.4rem, 4vw, 2.2rem); font-weight: 900; background: linear-gradient(145deg, #9184ec, #7163d4); box-shadow: 0 5px 0 #5f53bd; overflow: hidden; }
.card-back::after { content: "✦"; position: absolute; right: 9px; bottom: 5px; color: rgba(255,255,255,.25); font-size: 1rem; }
.card-front { transform: rotateY(180deg); background: #fff8e9; border: 2px solid #ffe7b5; font-size: clamp(1.8rem, 5vw, 3rem); box-shadow: 0 4px 0 #f4dfb8; }
.card.matched .card-front { background: #e9faef; border-color: #b8e8c8; box-shadow: 0 4px 0 #a3dcb7; }
.card:focus-visible { outline: 3px solid #ffad4d; outline-offset: 3px; }
.card:disabled { cursor: default; }
.bottom-row { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 10px; margin-top: 18px; color: #9299ae; font-size: .78rem; font-weight: 700; }
.sound-button { padding: 7px 10px; font-size: .75rem; }
footer { text-align: center; color: #a0a6bb; font-size: .8rem; padding: 20px 0 0; font-weight: 700; }
.dialog-backdrop { position: fixed; inset: 0; z-index: 5; display: grid; place-items: center; padding: 20px; background: rgba(36,43,79,.48); backdrop-filter: blur(5px); }
.dialog-backdrop[hidden] { display: none; }
.win-card { width: min(390px, 100%); text-align: center; padding: 30px; border-radius: 25px; background: white; box-shadow: 0 25px 80px rgba(18,24,55,.25); animation: pop .35s ease-out; }
.win-emoji { font-size: 3.4rem; }
.win-card h2 { margin: 8px 0 4px; color: #6455c5; font-size: 2rem; }
.win-card p { color: #8189a2; margin: 0 0 20px; }
.win-results { display: flex; justify-content: center; gap: 45px; margin-bottom: 22px; }
.win-results strong, .win-results small { display: block; }
.win-results strong { font-size: 1.5rem; color: #33406a; }
.win-results small { color: #9299ae; font-size: .75rem; }
.primary-button { width: 100%; padding: 13px; border: 0; border-radius: 13px; color: white; background: linear-gradient(100deg, #8675e8, #6d5bd1); font-weight: 900; box-shadow: 0 5px 0 #5949b7; }
.primary-button:active { transform: translateY(2px); box-shadow: 0 3px 0 #5949b7; }
@keyframes pop { from { opacity: 0; transform: scale(.85); } to { opacity: 1; transform: scale(1); } }

@media (max-width: 600px) {
  .game-shell { width: min(100% - 18px, 500px); padding-top: 22px; }
  .game-panel { padding: 13px; border-radius: 19px; }
  .game-board { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
  .card { aspect-ratio: 1 / .94; }
  .card-face { border-radius: 12px; }
  .toolbar { align-items: center; }
  .stat { gap: 5px; padding: 9px 4px; }
  .stat-icon { font-size: 1.1rem; }
  .stat strong { font-size: 1rem; }
  .hero p { font-size: .88rem; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}