:root {
  --bg: #fff3f7;
  --ink: #2b2233;
  --pink: #d6336c;
  --pink-dark: #a61e4d;
  --purple: #5f3dc4;
  --card-back: #f06595;
  --card-face: #fff;
  --fb: #1877f2;
  --gap: 8px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg) radial-gradient(circle at 20% 0%, #ffdeeb 0, transparent 55%);
  color: var(--ink);
  font-family: "Arial Rounded MT Bold", "Nunito", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}
button, a { font: inherit; }

.app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100%;
  padding: 12px 12px calc(16px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.top { text-align: center; }
h1 {
  margin: 4px 0 0;
  font-size: clamp(26px, 8vw, 36px);
  color: var(--pink);
  letter-spacing: .3px;
}
.sub { margin: 2px 0 8px; font-size: 15px; color: var(--purple); }
.stats {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  background: #fff; border-radius: 14px; padding: 8px 12px;
  box-shadow: 0 2px 8px rgba(214, 51, 108, .12);
  font-size: 16px;
}
.stats b { font-variant-numeric: tabular-nums; }

.board {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--gap);
  width: 100%;
  /* keep the 4x4 grid inside short viewports too */
  max-width: min(100%, calc(100svh - 250px));
  margin: 0 auto;
}
.card {
  position: relative;
  aspect-ratio: 1;
  border: 0; padding: 0; background: none;
  perspective: 600px;
  cursor: pointer;
  touch-action: manipulation;
}
.card .inner {
  position: absolute; inset: 0;
  transition: transform .35s ease;
  transform-style: preserve-3d;
  -webkit-transform-style: preserve-3d;
}
.card.flipped .inner, .card.matched .inner { transform: rotateY(180deg); }
.card .face {
  position: absolute; inset: 0;
  border-radius: 12px;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  display: grid; place-items: center;
  overflow: hidden;
}
.card .back {
  background: var(--card-back) repeating-radial-gradient(circle at 50% 50%, rgba(255,255,255,.25) 0 3px, transparent 3px 14px);
  color: #fff; font-size: clamp(26px, 9vw, 40px); font-weight: 700;
  box-shadow: 0 3px 0 var(--pink-dark);
}
.card .front {
  background: var(--card-face);
  transform: rotateY(180deg);
  box-shadow: 0 3px 0 #e9c6d6;
}
.card .front img { width: 100%; height: 100%; object-fit: contain; display: block; }
.card.matched .front { box-shadow: inset 0 0 0 3px #51cf66, 0 3px 0 #2b8a3e; }
.card:focus-visible { outline: 3px solid var(--purple); outline-offset: 2px; border-radius: 12px; }

.hint { text-align: center; margin: 0; font-size: 14px; color: #6b5a6e; }
.foot { margin-top: auto; text-align: center; }

.follow {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  background: var(--fb); color: #fff; text-decoration: none;
  border-radius: 999px; font-weight: 700;
}
.follow::before { content: "f"; font-family: Arial, sans-serif; font-weight: 900; background: #fff; color: var(--fb); border-radius: 50%; width: 1.3em; height: 1.3em; display: inline-grid; place-items: center; font-size: .9em; }
.follow.small { padding: 10px 18px; font-size: 15px; }
.follow.big { padding: 16px 24px; font-size: 20px; width: 100%; min-height: 56px; box-shadow: 0 4px 0 #0e5ac4; }

button.ghost {
  background: #ffe4ee; color: var(--pink-dark); border: 0; border-radius: 999px;
  padding: 8px 14px; min-height: 40px; font-weight: 700;
}
button.secondary {
  flex: 1; min-height: 50px; border-radius: 14px; border: 2px solid var(--pink);
  background: #fff; color: var(--pink); font-weight: 700; font-size: 17px;
}

.overlay {
  position: fixed; inset: 0; z-index: 10;
  background: rgba(43, 34, 51, .55);
  display: grid; place-items: center; padding: 16px;
  animation: fade .25s ease;
}
.overlay[hidden] { display: none; }
.panel {
  width: 100%; max-width: 380px; background: #fff; border-radius: 22px;
  padding: 20px 18px 18px; text-align: center;
  display: flex; flex-direction: column; gap: 12px;
  animation: pop .35s cubic-bezier(.2, 1.4, .4, 1);
}
.win-bear { width: 120px; height: 120px; margin: -70px auto 0; }
.panel h2 { margin: 0; font-size: 34px; color: var(--pink); }
.result { margin: 0; font-size: 17px; }
.row { display: flex; gap: 10px; }
.toast { margin: 0; font-size: 14px; color: var(--purple); }

@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { transform: scale(.85); opacity: 0; } }
@media (prefers-reduced-motion: reduce) {
  .card .inner { transition: none; }
  .overlay, .panel { animation: none; }
}
