/* Memory (js/games/memory.js). Card flip ported from the Tiny Hands memory game: each card
 * is a 3D box (perspective, preserve-3d) whose inner turns 180° on Y; back and front hide
 * their reverse side. Sizes come from the layout in JS (--mm-size, the grid). */

.mm-room { position: absolute; inset: 0; overflow: hidden; background: var(--surface-100); touch-action: manipulation; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.mm-board { position: absolute; display: grid; }

.mm-card {
  position: relative; padding: 0; border: 0; background: none; cursor: pointer; opacity: 0;
  perspective: 800px; -webkit-tap-highlight-color: transparent; border-radius: calc(var(--mm-size, 120px) * .1);
}
.mm-card:focus-visible { outline: 3px solid var(--focus-ring); outline-offset: 3px; }
/* dealt in: a short grow and fade, with no 3D in it and nothing held afterwards (a held 3D
   end state left Chrome drawing the cards edge-on on phones) */
.mm-dealt .mm-card { opacity: 1; animation: mm-deal .4s cubic-bezier(.34, 1.4, .64, 1) backwards; }
@keyframes mm-deal { 0% { transform: scale(.6); opacity: .3; } 70% { transform: scale(1.03); opacity: 1; } 100% { transform: scale(1); opacity: 1; } }

.mm-inner {
  position: absolute; inset: 0; display: block; transform-style: preserve-3d;
  transition: transform .42s cubic-bezier(.4, 0, .2, 1); border-radius: inherit;
}
.mm-card.is-up .mm-inner { transform: rotateY(180deg); }

/* the back: graphite with a fine lattice and the Pinwheel in the middle */
.mm-back, .mm-front {
  position: absolute; inset: 0; border-radius: inherit; overflow: hidden;
  backface-visibility: hidden; -webkit-backface-visibility: hidden;
}
.mm-back {
  background:
    url('/favicon.svg') center / 38% no-repeat,
    repeating-linear-gradient(45deg, rgba(255, 255, 255, .045) 0 2px, transparent 2px 9px),
    linear-gradient(160deg, #2A2A33 0%, #1F1F26 100%);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, .1) inset, 0 3px 10px rgba(0, 0, 0, .35);
}
.mm-back::before { content: ''; position: absolute; inset: 6%; border: 2px solid rgba(255, 255, 255, .12); border-radius: calc(var(--mm-size, 120px) * .07); }
:root[data-theme="light"] .mm-back { box-shadow: 0 2px 8px rgba(17, 17, 17, .18); }

/* the front: the picture, cropped square; playing cards whole on white */
.mm-front { transform: rotateY(180deg); background: #fff; box-shadow: 0 0 0 1px rgba(0, 0, 0, .08) inset, 0 3px 10px rgba(0, 0, 0, .25); }
.mm-front img { display: block; width: 100%; height: 100%; object-fit: cover; }
.mm-playing { position: absolute; inset: 5% 14%; display: grid; place-items: center; }
.mm-playing .sc-svg { width: 100%; height: 100%; }
.mm-playing.sc-s0, .mm-playing.sc-s3 { color: #16181D; }
.mm-playing.sc-s1, .mm-playing.sc-s2 { color: #C62828; }

/* 3D emoji on a soft tint of the deck's colour; flags whole, with a thin edge */
.mm-kind-emoji .mm-front { background: #FBF8F1; }
.mm-deck-food .mm-front { background: #FDF3DC; }
.mm-deck-garden .mm-front { background: #E6F6EC; }
.mm-deck-animals .mm-front { background: #FAEAF6; }
.mm-deck-travel .mm-front, .mm-deck-flags .mm-front { background: #EAF1FC; }
.mm-front .mm-emoji { position: absolute; inset: 14%; width: 72%; height: 72%; object-fit: contain; }
.mm-front .mm-flag { position: absolute; left: 10%; top: 50%; width: 80%; height: auto; transform: translateY(-50%); box-shadow: 0 0 0 1px rgba(0, 0, 0, .14); border-radius: 3px; }

/* a found pair: a soft green ring */
.mm-card.is-matched { cursor: default; }
.mm-card.is-matched .mm-front { box-shadow: 0 0 0 3px var(--positive), 0 4px 14px rgba(0, 0, 0, .25); }
.mm-done .mm-card.is-matched .mm-front { animation: mm-glow .9s ease 1; }
@keyframes mm-glow { 50% { box-shadow: 0 0 0 3px var(--positive), 0 0 22px 4px var(--positive); } }

@media (prefers-reduced-motion: reduce) {
  .mm-dealt .mm-card { animation: none; opacity: 1; }
  .mm-inner { transition: none; }
  .mm-done .mm-card.is-matched .mm-front { animation: none; }
}
