/* Memory Match – card flip pairs game */
.mm-stats {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 4px;
    text-align: center;
}
.mm-stat .small { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mm-stars { color: #f5a524; letter-spacing: 1px; }
.mm-stars .mm-star-off { color: #c7ccd1; }

.mm-players {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-top: 8px;
}
.mm-player {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 12px;
    border-radius: 10px;
    border: 2px solid transparent;
    background: rgba(0, 0, 0, .04);
    font-weight: 600;
    transition: border-color .2s, background .2s;
}
.mm-player-score { font-size: 1.25rem; }
.mm-p1.is-active { border-color: #2f6fed; background: rgba(47, 111, 237, .12); }
.mm-p2.is-active { border-color: #e8590c; background: rgba(232, 89, 12, .12); }

/* Board */
.mm-board {
    --cols: 4;
    --gap: 8px;
    display: grid;
    grid-template-columns: repeat(var(--cols), minmax(0, 1fr));
    gap: var(--gap);
    width: 100%;
    max-width: 480px;
    margin: 0 auto;
    container-type: inline-size;
    user-select: none;
    -webkit-user-select: none;
    touch-action: manipulation;
}
.mm-board.is-locked .mm-card { cursor: default; }

.mm-card {
    position: relative;
    aspect-ratio: 1 / 1;
    width: 100%;
    padding: 0;
    border: 0;
    background: none;
    perspective: 700px;
    cursor: pointer;
    border-radius: 12px;
    font-size: 1.6rem;
    font-size: calc(100cqw / var(--cols) * .55);
    line-height: 1;
    -webkit-tap-highlight-color: transparent;
}
.mm-card:focus { outline: none; }
.mm-card:focus-visible { outline: 3px solid #f5a524; outline-offset: 2px; }

.mm-inner {
    position: absolute;
    inset: 0;
    transform-style: preserve-3d;
    transition: transform .45s cubic-bezier(.4, .2, .2, 1);
}
.mm-card.is-flipped .mm-inner,
.mm-card.is-matched .mm-inner { transform: rotateY(180deg); }

.mm-face {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 12px;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    box-shadow: 0 2px 6px rgba(0, 0, 0, .15);
}
.mm-back {
    background:
        radial-gradient(circle at 30% 30%, rgba(255, 255, 255, .25) 0 12%, transparent 13%),
        radial-gradient(circle at 70% 70%, rgba(255, 255, 255, .18) 0 10%, transparent 11%),
        linear-gradient(135deg, #3b5bdb, #7048e8);
    color: rgba(255, 255, 255, .9);
    font-weight: 800;
    font-family: system-ui, sans-serif;
}
.mm-back::after { content: "?"; font-size: .8em; }
.mm-card:hover:not(.is-flipped):not(.is-matched) .mm-back { filter: brightness(1.1); }

.mm-front {
    transform: rotateY(180deg);
    background: #fff;
    border: 2px solid #dee2e6;
}
.mm-front svg { width: 72%; height: 72%; }
.mm-num { font-weight: 800; font-family: system-ui, sans-serif; color: #052c65; font-size: .9em; }

.mm-card.is-matched .mm-front { border-color: #2f9e44; background: #ebfbee; }
.mm-card.is-matched.by-p1 .mm-front { border-color: #2f6fed; background: #e7efff; }
.mm-card.is-matched.by-p2 .mm-front { border-color: #e8590c; background: #fff0e6; }
.mm-card.is-matched { cursor: default; }
.mm-card.is-matched .mm-front { animation: mm-pop .35s ease-out; }
.mm-card.is-wrong .mm-front { border-color: #e03131; animation: mm-shake .35s; }

@keyframes mm-pop { 0%, 100% { scale: 1; } 50% { scale: 1.1; } }
@keyframes mm-shake { 0%, 100% { translate: 0; } 25% { translate: -4px; } 75% { translate: 4px; } }

/* Dark mode */
[data-bs-theme="dark"] .mm-front { background: #2b3035; border-color: #495057; }
[data-bs-theme="dark"] .mm-num { color: #9ec5fe; }
[data-bs-theme="dark"] .mm-card.is-matched .mm-front { background: #1b3a24; border-color: #51cf66; }
[data-bs-theme="dark"] .mm-card.is-matched.by-p1 .mm-front { background: #1c2a4a; border-color: #4c8dff; }
[data-bs-theme="dark"] .mm-card.is-matched.by-p2 .mm-front { background: #45260f; border-color: #ff8a3d; }
[data-bs-theme="dark"] .mm-player { background: rgba(255, 255, 255, .06); }
[data-bs-theme="dark"] .mm-stars .mm-star-off { color: #495057; }

@media (max-width: 575.98px) {
    .mm-board { --gap: 6px; }
    .mm-board-body { padding: 10px 6px; }
    .mm-stat .fs-5 { font-size: 1rem !important; }
    .mm-stat .small { font-size: .7rem; }
}

@media (prefers-reduced-motion: reduce) {
    .mm-inner { transition: none; }
    .mm-card.is-matched .mm-front,
    .mm-card.is-wrong .mm-front { animation: none; }
}
