/* Candy Memory Match — scoped to .g-memory */
.g-memory .mm-hint { text-align: center; font-family: var(--head); font-weight: 600; color: var(--ink-soft); margin: -4px 0 12px; font-size: 1.05rem; transition: opacity .3s; }
.g-memory .mm-hint.is-hidden { opacity: 0; }
.g-memory .mm-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; margin: 0; }
.g-memory .mm-board { width: 100%; padding: 4px 0 10px; }
.g-memory .mm-grid {
  --cw: 110px; --gap: 12px;
  display: flex; flex-wrap: wrap; justify-content: center; gap: var(--gap);
  margin: 0 auto; perspective: 900px;
}

/* ---- card ---- */
.g-memory .mm-card {
  position: relative; width: var(--cw); aspect-ratio: 1 / 1.3; height: auto;
  padding: 0; border: 0; background: none; cursor: pointer; border-radius: 18px;
  -webkit-tap-highlight-color: transparent; touch-action: manipulation; font: inherit; color: inherit;
}
@supports not (aspect-ratio: 1) { .g-memory .mm-card { height: calc(var(--cw) * 1.3); } }
.g-memory .mm-card:focus-visible { outline: 4px solid var(--gold); outline-offset: 3px; }
.g-memory .mm-inner {
  position: absolute; inset: 0; transform-style: preserve-3d;
  transition: transform .5s cubic-bezier(.3, 1.35, .5, 1); border-radius: inherit;
}
.g-memory .mm-card.is-up .mm-inner, .g-memory .mm-card.is-matched .mm-inner { transform: rotateY(180deg); }
.g-memory .mm-card:not(.is-up):not(.is-matched):hover .mm-inner { transform: translateY(-4px) rotate(-1.5deg); }
.g-memory .mm-face {
  position: absolute; inset: 0; border-radius: inherit; backface-visibility: hidden; -webkit-backface-visibility: hidden;
  display: grid; place-items: center; overflow: hidden; box-shadow: 0 6px 0 rgba(60, 30, 35, .14), 0 10px 18px rgba(60, 30, 35, .12);
}

/* back: berry & white candy wrapper with a peppermint swirl and a gold star */
.g-memory .mm-back {
  background:
    linear-gradient(160deg, rgba(255, 255, 255, .45) 0, rgba(255, 255, 255, 0) 38%),
    repeating-linear-gradient(135deg, var(--berry) 0 10px, #ff6f97 10px 13px, #fff 13px 18px, #ff6f97 18px 21px, var(--berry) 21px 31px);
  box-shadow: inset 0 0 0 4px #fff, inset 0 0 0 7px var(--berry-dark), 0 6px 0 var(--berry-dark), 0 10px 18px rgba(60, 30, 35, .16);
}
/* wrapper "twist" ends */
.g-memory .mm-back::before, .g-memory .mm-back::after {
  content: ""; position: absolute; left: 18%; right: 18%; height: 9%;
  background: repeating-linear-gradient(90deg, #fff 0 5px, var(--berry-soft) 5px 10px);
  clip-path: polygon(0 0, 100% 0, 88% 100%, 12% 100%);
}
.g-memory .mm-back::before { top: 7px; }
.g-memory .mm-back::after { bottom: 7px; transform: scaleY(-1); }
.g-memory .mm-mint {
  width: 62%; aspect-ratio: 1; border-radius: 50%;
  background: repeating-conic-gradient(from 10deg, #fff 0 22.5deg, var(--berry) 22.5deg 45deg);
  box-shadow: 0 0 0 4px #fff, 0 0 0 7px var(--berry-dark), 0 6px 12px rgba(0, 0, 0, .2);
  grid-area: 1 / 1;
}
.g-memory .mm-star {
  grid-area: 1 / 1; width: 34%; aspect-ratio: 1; background: var(--gold);
  clip-path: polygon(50% 0, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%);
  filter: drop-shadow(0 2px 0 var(--gold-dark));
}
.g-memory .mm-card:not(.is-up):hover .mm-star { animation: mmTwinkle .8s ease-in-out; }

/* front: friend cut-out on a soft candy color */
.g-memory .mm-front {
  transform: rotateY(180deg);
  background: radial-gradient(circle at 50% 38%, rgba(255, 255, 255, .9) 0 30%, rgba(255, 255, 255, 0) 62%), var(--tint, var(--pink));
  box-shadow: inset 0 0 0 4px #fff, 0 6px 0 rgba(60, 30, 35, .14), 0 10px 18px rgba(60, 30, 35, .12);
  grid-template-rows: 1fr auto; padding: 8% 6% 5%;
}
.g-memory .mm-front img { width: auto; height: 100%; max-height: 100%; max-width: 100%; object-fit: contain; min-height: 0; filter: drop-shadow(0 4px 4px rgba(60, 30, 35, .2)); user-select: none; -webkit-user-drag: none; pointer-events: none; }
.g-memory .mm-label { font-family: var(--head); font-weight: 700; font-size: clamp(.72rem, calc(var(--cw) * .13), 1.05rem); line-height: 1.1; color: var(--ink); background: rgba(255, 255, 255, .85); border-radius: 999px; padding: 2px 8px; margin-top: 3px; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.g-memory .mm-grid.is-tiny .mm-label { padding: 1px 5px; }
.g-memory .mm-card.is-matched { cursor: default; }
.g-memory .mm-card.is-matched .mm-front { box-shadow: inset 0 0 0 4px var(--gold), 0 0 0 3px #fff, 0 0 18px 4px rgba(255, 201, 77, .75); }
.g-memory .mm-card.is-matched::after {
  content: "★"; position: absolute; top: -8px; right: -6px; width: 28px; height: 28px; border-radius: 50%;
  display: grid; place-items: center; background: var(--gold); color: #fff; font-size: 17px; line-height: 1;
  box-shadow: 0 3px 0 var(--gold-dark); z-index: 2; animation: mmPop .45s cubic-bezier(.2, 1.6, .4, 1);
}

/* deal-in, wiggle on match, little shake on a miss */
.g-memory .mm-grid.is-dealt .mm-card { animation: mmDeal .45s cubic-bezier(.2, 1.3, .4, 1) both; animation-delay: var(--d, 0ms); }
.g-memory .mm-card.is-wiggle { animation: mmWiggle .7s ease-in-out .35s both; }
.g-memory .mm-card.is-nope { animation: mmNope .45s ease-in-out .45s; }
@keyframes mmDeal { from { opacity: 0; transform: translateY(18px) scale(.85); } }
@keyframes mmWiggle { 0%, 100% { transform: none; } 20% { transform: rotate(-7deg) scale(1.08); } 40% { transform: rotate(6deg) scale(1.08); } 60% { transform: rotate(-4deg) scale(1.05); } 80% { transform: rotate(2deg); } }
@keyframes mmNope { 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }
@keyframes mmPop { from { transform: scale(0); } }
@keyframes mmTwinkle { 50% { transform: rotate(72deg) scale(1.15); } }

/* speech bubble when a pair is found */
.g-memory .mm-say {
  position: fixed; left: 50%; bottom: 18px; z-index: 120; display: flex; align-items: flex-end; gap: 6px;
  transform: translate(-50%, 140%); opacity: 0; pointer-events: none; transition: transform .45s cubic-bezier(.2, 1.4, .4, 1), opacity .25s;
  max-width: calc(100vw - 24px);
}
.g-memory .mm-say.is-on { transform: translate(-50%, 0); opacity: 1; }
.g-memory .mm-say img { height: 96px; width: auto; flex-shrink: 0; filter: drop-shadow(0 6px 8px rgba(0, 0, 0, .22)); }
.g-memory .mm-say-bubble {
  position: relative; background: #fff; border-radius: 22px; padding: 10px 18px 12px; margin-bottom: 34px;
  box-shadow: 0 10px 28px rgba(60, 30, 35, .22), inset 0 0 0 3px var(--berry-soft); min-width: 0;
}
.g-memory .mm-say-bubble::before { content: ""; position: absolute; left: -10px; bottom: 14px; border: 10px solid transparent; border-right-color: #fff; border-left: 0; }
.g-memory .mm-say-name { display: block; font-family: var(--head); font-size: .85rem; color: var(--berry); text-transform: uppercase; letter-spacing: 1px; }
.g-memory .mm-say-text { display: block; font-family: var(--head); font-weight: 700; font-size: 1.3rem; line-height: 1.2; color: var(--ink); }
@media (max-width: 520px) {
  .g-memory .mm-say img { height: 72px; }
  .g-memory .mm-say-text { font-size: 1.08rem; }
  .g-memory .game-bar { justify-content: center; }
  .g-memory .seg button { padding: 8px 11px; }
}
@media (max-width: 380px) { .g-memory .stat { padding: 7px 11px; font-size: .95rem; } .g-memory .mm-pairs { display: none; } }

/* reduced motion: no 3D spin — the face simply appears */
@media (prefers-reduced-motion: reduce) {
  .g-memory .mm-inner { transform: none !important; }
  .g-memory .mm-front { transform: none; visibility: hidden; }
  .g-memory .mm-card.is-up .mm-front, .g-memory .mm-card.is-matched .mm-front { visibility: visible; }
  .g-memory .mm-card.is-up .mm-back, .g-memory .mm-card.is-matched .mm-back { visibility: hidden; }
  .g-memory .mm-say { transform: translate(-50%, 0); }
}
@media print { .g-memory .mm-say { display: none; } }
