/* Game: Flip & Match */
.arcade-memory { --mm-ink: #1C1433; --mm-face: #fff; --mm-ok: #16B989; --mm-bad: #FF4D6D; --mm-gap: 12px; }
.arcade[data-theme="noir"] .arcade-memory { --mm-face: #FBF3DE; }
.arcade-memory .mm-wrap { width: min(100%, 640px); display: flex; flex-direction: column; align-items: center; }
.arcade-memory .mm-wrap[data-rows="3"] { width: min(100%, 540px); }
.arcade-memory .mm-wrap[data-rows="4"] { width: min(100%, 480px); }
.arcade-memory .mm-title { margin: 0 0 14px; color: var(--a-fg); font-size: clamp(1.6rem, 4vw, 2.3rem); text-align: center; overflow-wrap: anywhere; }

/* HUD */
.arcade-memory .mm-hud { display: flex; justify-content: center; gap: 8px; width: 100%; margin-bottom: 12px; }
.arcade-memory .mm-chip { flex: 1 1 0; max-width: 150px; display: flex; flex-direction: column; align-items: center; padding: 6px 10px 5px; border: 2px solid color-mix(in srgb, var(--a-fg) 22%, transparent); border-radius: 16px; background: color-mix(in srgb, var(--a-fg) 9%, transparent); line-height: 1.1; }
.arcade-memory .mm-chip-k { font-size: .74rem; font-weight: 700; opacity: .82; line-height: 1.25; text-align: center; overflow-wrap: anywhere; }
.arcade-memory .mm-chip-v { font-family: var(--a-font-display); font-weight: 800; font-size: 1.45rem; line-height: 1.15; font-variant-numeric: tabular-nums; }
.arcade-memory .mm-c-pairs .mm-chip-v { color: var(--a-accent); }
.arcade[data-theme="blush"] .arcade-memory .mm-chip { background: rgba(255,255,255,.7); }
.arcade-memory.mm-low .mm-c-time { border-color: var(--mm-bad); background: color-mix(in srgb, var(--mm-bad) 22%, transparent); }
.arcade-memory.mm-low .mm-c-time .mm-chip-v { animation: mm-beat 1s ease-in-out infinite; }

.arcade-memory .mm-timer { width: 100%; height: 12px; margin-bottom: 16px; padding: 2px; border: 2px solid var(--mm-ink); border-radius: 999px; background: color-mix(in srgb, var(--a-fg) 14%, var(--a-bg)); overflow: hidden; }
.arcade-memory .mm-timer-fill { display: block; height: 100%; border-radius: 999px; background: var(--a-accent); transform-origin: left center; transition: transform .2s linear, background-color .3s; }
.arcade-memory.mm-low .mm-timer-fill { background: var(--mm-bad); }

/* Card board */
.arcade-memory .mm-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--mm-gap); width: 100%; padding-bottom: 4px; }
.arcade-memory .mm-card { position: relative; display: block; width: 100%; aspect-ratio: 4 / 5; padding: 0; border: 0; border-radius: 16px; background: none; color: var(--mm-ink); font: inherit; cursor: pointer; perspective: 800px; touch-action: manipulation; -webkit-tap-highlight-color: transparent; container-type: inline-size; transition: transform .15s ease; }
.arcade-memory .mm-card:hover:not(.is-open) { transform: translateY(-3px); }
.arcade-memory .mm-card:active:not(.is-open) { transform: translateY(1px); }
.arcade-memory .mm-card:focus-visible { outline: 3px solid var(--a-accent); outline-offset: 3px; }
.arcade[data-theme="festive"] .arcade-memory .mm-card:focus-visible, .arcade[data-theme="noir"] .arcade-memory .mm-card:focus-visible { outline-color: #fff; }
.arcade-memory .mm-inner { position: absolute; inset: 0; display: block; transform-style: preserve-3d; transition: transform .5s cubic-bezier(.3,1.35,.5,1); }
.arcade-memory .mm-card.is-open .mm-inner { transform: rotateY(180deg); }
.arcade-memory .mm-back, .arcade-memory .mm-face { position: absolute; inset: 0; display: flex; border: 2px solid var(--mm-ink); border-radius: 16px; box-shadow: 0 4px 0 var(--mm-ink); -webkit-backface-visibility: hidden; backface-visibility: hidden; overflow: hidden; }

/* Card back: accent colour, dots and stitched frame */
.arcade-memory .mm-back { align-items: center; justify-content: center; background-color: var(--a-accent);
	background-image: radial-gradient(color-mix(in srgb, var(--a-accent-ink) 16%, transparent) 1.5px, transparent 2px), linear-gradient(135deg, rgba(255,255,255,.28), rgba(255,255,255,0) 55%);
	background-size: 11px 11px, 100% 100%; }
.arcade-memory .mm-back::before { content: ""; position: absolute; inset: 6px; border: 2px dashed color-mix(in srgb, var(--a-accent-ink) 30%, transparent); border-radius: 10px; }
.arcade-memory .mm-mark { position: relative; display: grid; place-items: center; width: 46%; aspect-ratio: 1; border: 2px solid var(--mm-ink); border-radius: 50%; background: var(--a-bg); color: var(--a-accent); box-shadow: 0 3px 0 var(--mm-ink); font-family: var(--a-font-display); font-weight: 800; font-size: 30px; font-size: clamp(18px, 26cqi, 40px); line-height: 1; padding-top: .08em; }
.arcade[data-theme="blush"] .arcade-memory .mm-mark { background: #fff; }

/* Card face: product picture and name */
.arcade-memory .mm-face { flex-direction: column; align-items: center; justify-content: center; gap: 4%; padding: 8% 6% 9%; background: var(--mm-face); transform: rotateY(180deg); }
.arcade-memory .mm-art { position: relative; display: grid; place-items: center; width: 74%; aspect-ratio: 1; border-radius: 50%; }
.arcade-memory .mm-t1 .mm-art { background: color-mix(in srgb, var(--a-c1) 24%, var(--mm-face)); }
.arcade-memory .mm-t3 .mm-art { background: color-mix(in srgb, var(--a-accent) 26%, var(--mm-face)); }
.arcade-memory .mm-t4 .mm-art { background: color-mix(in srgb, var(--a-c4) 30%, var(--mm-face)); }
.arcade[data-theme="noir"] .arcade-memory .mm-t4 .mm-art, .arcade[data-theme="leaf"] .arcade-memory .mm-t4 .mm-art { background: color-mix(in srgb, var(--a-c1) 20%, var(--mm-face)); }
.arcade-memory .mm-ic { display: block; width: 86%; height: auto; overflow: visible; }
.arcade-memory .mm-ic .a { fill: var(--a-accent); }
.arcade-memory .mm-ic .p { fill: var(--a-c1); }
.arcade-memory .mm-ic .s { fill: var(--a-c3); }
.arcade-memory .mm-ic .m { fill: var(--a-c4); }
.arcade-memory .mm-ic .w { fill: #fff; }
.arcade-memory .mm-ic .k { fill: #1C1433; }
.arcade-memory .mm-ic .hl { stroke: #fff; stroke-width: 2.5; }
.arcade-memory .mm-ic .sa { stroke: var(--a-accent); }
.arcade-memory .mm-label { max-width: 100%; color: var(--mm-ink); font-weight: 700; font-size: 12px; font-size: clamp(10.5px, 12.5cqi, 16px); line-height: 1.15; text-align: center; overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.arcade-memory .mm-check { position: absolute; top: 5px; right: 5px; display: grid; place-items: center; width: 24px; height: 24px; border: 2px solid var(--mm-ink); border-radius: 50%; background: var(--mm-ok); transform: scale(0); transition: transform .3s cubic-bezier(.2,1.6,.4,1) .15s; }
.arcade-memory .mm-check svg { width: 16px; height: 16px; }

/* States */
.arcade-memory .mm-card.is-open, .arcade-memory .mm-card[aria-disabled="true"] { cursor: default; }
.arcade-memory .mm-card.is-matched .mm-face { border-color: var(--mm-ink); box-shadow: 0 4px 0 var(--mm-ink), 0 0 0 4px var(--mm-ok), 0 0 22px 6px color-mix(in srgb, var(--mm-ok) 45%, transparent); }
.arcade-memory .mm-card.is-matched .mm-check { transform: scale(1); }
.arcade-memory .mm-card.is-matched .mm-inner { animation: mm-pop .5s ease .35s; }
.arcade-memory .mm-card.is-wrong .mm-face { box-shadow: 0 4px 0 var(--mm-ink), 0 0 0 4px var(--mm-bad); }
.arcade-memory .mm-card.is-wrong .mm-inner { animation: mm-shake .42s ease .4s; }
.arcade-memory .mm-card.is-reveal .mm-face { opacity: .62; filter: saturate(.55); }
.arcade-memory.mm-won .mm-card.is-matched .mm-face { box-shadow: 0 4px 0 var(--mm-ink), 0 0 0 4px var(--a-accent), 0 0 26px 6px color-mix(in srgb, var(--a-accent) 55%, transparent); }
.arcade-memory.mm-over .mm-card { transform: none; }

.arcade-memory .mm-status { min-height: 2.9em; max-width: 46ch; margin: 14px 0 0; font-weight: 600; text-align: center; opacity: .92; line-height: 1.4; }
.arcade-memory .mm-again { margin-top: 6px; min-width: 180px; background: var(--a-accent); color: var(--a-accent-ink); border-color: var(--mm-ink); box-shadow: 0 5px 0 var(--mm-ink); }
.arcade-memory .mm-again:hover { color: var(--a-accent-ink); }
.arcade-memory .mm-again[hidden] { display: none; }

@keyframes mm-pop { 0%, 100% { transform: rotateY(180deg) scale(1); } 45% { transform: rotateY(180deg) scale(1.08); } }
@keyframes mm-shake { 0%, 100% { transform: rotateY(180deg) translateX(0); } 20%, 60% { transform: rotateY(180deg) translateX(-5px); } 40%, 80% { transform: rotateY(180deg) translateX(5px); } }
@keyframes mm-beat { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.12); } }

@media (max-width: 640px) {
	.arcade-memory { --mm-gap: 8px; }
	.arcade-memory .mm-title { margin-bottom: 10px; }
	.arcade-memory .mm-hud { gap: 6px; margin-bottom: 10px; }
	.arcade-memory .mm-chip { padding: 5px 6px 4px; border-radius: 14px; }
	.arcade-memory .mm-chip-k { font-size: .68rem; }
	.arcade-memory .mm-chip-v { font-size: 1.2rem; }
	.arcade-memory .mm-timer { margin-bottom: 12px; }
	.arcade-memory .mm-card, .arcade-memory .mm-back, .arcade-memory .mm-face { border-radius: 12px; }
	.arcade-memory .mm-back::before { inset: 4px; border-radius: 8px; }
	.arcade-memory .mm-face { padding: 7% 4% 8%; }
	.arcade-memory .mm-art { width: 68%; }
	.arcade-memory .mm-check { top: 3px; right: 3px; width: 20px; height: 20px; }
	.arcade-memory .mm-check svg { width: 13px; height: 13px; }
	.arcade-memory .mm-status { font-size: .92rem; margin-top: 12px; }
}

/* Reduced motion */
.arcade-memory.mm-reduced .mm-inner, .arcade-memory.mm-reduced .mm-card, .arcade-memory.mm-reduced .mm-check, .arcade-memory.mm-reduced .mm-timer-fill { transition: none; }
.arcade-memory.mm-reduced .mm-card .mm-inner, .arcade-memory.mm-reduced .mm-chip-v { animation: none !important; }
@media (prefers-reduced-motion: reduce) {
	.arcade-memory .mm-inner, .arcade-memory .mm-card, .arcade-memory .mm-check, .arcade-memory .mm-timer-fill { transition: none; }
	.arcade-memory .mm-card .mm-inner, .arcade-memory .mm-chip-v { animation: none !important; }
}
