/* Memory Match — "the toy tray": a warm maple tray on a cream-and-honey table. Teal card backs
   with a cream star; cream faces with a picture that has its own shape and colour. Matched cards
   dim and wear a small dot in the colour of whoever found them. Layout basics from cb-arcade.css. */
.mm-page, .mm-dlg, .mm-end-back {
  --ink: #2a2116; --ink-2: #5a4a33; --ink-3: #6b5a40;
  --cream: #fffaf0; --paper-1: #f6e7c8; --paper-2: #ecd6aa;
  --maple-1: #e9b979; --maple-2: #d39a55; --maple-3: #bf8443;
  --teal-1: #2c8c8a; --teal-2: #1d6766; --teal-3: #154f4e; --teal-4: #0f3b3a;
  --good: #2fae8a; --warn: #f4882a;
}
.mm-page [hidden], .mm-dlg [hidden] { display: none !important; }

/* ---------- mode tabs ---------- */
.mm-tabs { display: flex; gap: 4px; margin: 0 0 10px; padding: 4px; border-radius: 15px; background: rgba(120, 80, 30, .14); }
.mm-tabs button { flex: 1; border: 0; background: transparent; padding: 10px 4px; border-radius: 11px; font: 900 14px var(--cbx-body); color: var(--ink-3); cursor: pointer; min-height: 44px; }
.mm-tabs button[aria-selected="true"] { color: var(--ink); background: var(--cream); box-shadow: 0 2px 0 rgba(120, 80, 30, .25); }

/* ---------- the table ---------- */
.cbx-card.mm-card { --cbx-full-pad: 14px; padding: 16px 14px 18px; color: var(--ink); display: flex; flex-direction: column; gap: 12px;
  background: radial-gradient(110% 55% at 50% -5%, #fff6e2, transparent 65%), linear-gradient(180deg, var(--paper-1), var(--paper-2));
  box-shadow: 0 1px 0 rgba(120, 80, 30, .12), 0 20px 40px -26px rgba(90, 50, 10, .55); }
.cbx-card.mm-card p { color: inherit; margin: 0; }

.mm-sizes { display: flex; gap: 6px; padding: 4px; border-radius: 14px; background: rgba(120, 80, 30, .12); }
.mm-sizes button { flex: 1; min-height: 44px; border: 0; border-radius: 10px; background: transparent; font: 800 14px var(--cbx-body); color: var(--ink-3); cursor: pointer; padding: 0 4px; }
.mm-sizes button[aria-pressed="true"] { background: var(--cream); font-weight: 900; color: var(--ink); box-shadow: 0 2px 0 rgba(120, 80, 30, .25); }
.mm-sizes button:disabled { cursor: default; opacity: .45; }
.mm-sizes button:disabled[aria-pressed="true"] { opacity: 1; }

.mm-challenge { padding: 10px 14px; border-radius: 14px; background: rgba(255, 250, 240, .75); border: 2px dashed rgba(194, 95, 12, .45); font: 800 14px/1.4 var(--cbx-body); text-align: center; }
.mm-challenge b { color: #a8501a; }

/* ---------- players / score chips ---------- */
.mm-players { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px 10px; min-height: 44px; }
.mm-chip { display: inline-flex; align-items: center; gap: 6px; min-width: 0; max-width: calc(50% - 5px); padding: 5px 12px 5px 5px; border-radius: 999px;
  background: rgba(255, 250, 240, .55); border: 2px solid transparent; font: 800 14px var(--cbx-body); color: var(--ink-3); transition: border-color .25s, box-shadow .25s, background .25s; }
.mm-chip .ini { width: 28px; height: 28px; flex: none; border-radius: 50%; color: #fff; display: flex; align-items: center; justify-content: center; font: 900 14px var(--cbx-body); background: var(--c); }
.mm-chip .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.mm-chip .pc { flex: none; white-space: nowrap; }
.mm-chip.turn { background: var(--cream); border-color: var(--c); color: var(--ink); font-weight: 900; box-shadow: 0 6px 16px -6px color-mix(in srgb, var(--c) 80%, transparent); }
.mm-chip.stat { max-width: none; padding: 6px 14px; background: var(--cream); color: var(--ink); font-weight: 900; }
.mm-chip.stat small { font-weight: 800; color: var(--ink-3); font-size: 13px; }

/* ---------- the tray and cards ---------- */
.mm-tray { padding: 12px; border-radius: 26px;
  background: repeating-linear-gradient(92deg, rgba(150, 95, 40, .07) 0 2px, transparent 2px 9px), linear-gradient(180deg, var(--maple-1), var(--maple-2) 60%, var(--maple-3));
  box-shadow: inset 0 2px 0 rgba(255, 240, 210, .7), inset 0 -4px 0 rgba(110, 60, 20, .25), 0 22px 40px -22px rgba(90, 50, 10, .7); }
.mm-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: clamp(6px, 2.4vw, 10px); padding: clamp(6px, 2.4vw, 10px); border-radius: 16px;
  background: rgba(110, 60, 20, .18); box-shadow: inset 0 3px 8px rgba(90, 45, 10, .35); margin: 0 auto; max-width: 440px;
  user-select: none; -webkit-user-select: none; touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
/* the tallest board (10 pairs, 5 rows) gets narrower cards on a short screen so it still fits */
.mm-grid[data-rows="5"] { max-width: min(440px, calc((100svh - 330px) * .64)); min-width: min(100%, 300px); }

.mm-c { position: relative; aspect-ratio: 4 / 5; width: 100%; min-height: 56px; border: 0; padding: 0; background: none; cursor: pointer; perspective: 600px; border-radius: 12px; }
.mm-c:focus-visible { outline: 3px solid #1d6766; outline-offset: 3px; }
.mm-in { position: absolute; inset: 0; transform-style: preserve-3d; transition: transform .32s cubic-bezier(.3, .7, .3, 1); border-radius: 12px; }
.mm-c.up .mm-in, .mm-c.done .mm-in { transform: rotateY(180deg); }
.mm-back, .mm-face { position: absolute; inset: 0; border-radius: 12px; display: flex; align-items: center; justify-content: center; backface-visibility: hidden; -webkit-backface-visibility: hidden; }
.mm-back { background: radial-gradient(circle at 50% 40%, var(--teal-1), var(--teal-2) 70%, var(--teal-3));
  box-shadow: inset 0 0 0 3px rgba(255, 240, 200, .35), inset 0 0 0 6px var(--teal-2), inset 0 0 0 7px rgba(255, 240, 200, .25), 0 4px 0 var(--teal-4), 0 6px 10px rgba(60, 30, 5, .35); }
.mm-back svg { width: 42%; height: auto; }
.mm-face { transform: rotateY(180deg); background: linear-gradient(180deg, #fffdf6, #fbf1dc); box-shadow: 0 4px 0 #c9b48a, 0 6px 10px rgba(60, 30, 5, .3); }
.mm-face svg { width: 62%; height: auto; }
.mm-c.up .mm-in { transform: rotateY(180deg) translateZ(0); }
.mm-c.up { transform: translateY(-4px) scale(1.04); transition: transform .25s; z-index: 1; }
.mm-c.up .mm-face { box-shadow: 0 0 0 3px var(--good), 0 0 18px 2px rgba(47, 174, 138, .55), 0 8px 0 #c9b48a, 0 12px 16px rgba(60, 30, 5, .3); }
.mm-c.up.miss .mm-face { box-shadow: 0 0 0 3px var(--warn), 0 0 16px 2px rgba(244, 136, 42, .5), 0 8px 0 #c9b48a, 0 12px 16px rgba(60, 30, 5, .3); }
.mm-c.done { cursor: default; }
.mm-c.done .mm-face { background: linear-gradient(180deg, #fbf3e2, #f1e3c5); box-shadow: inset 0 2px 4px rgba(120, 80, 30, .25); opacity: .62; }
.mm-c.just .mm-face { animation: mm-pop .5s ease-out; }
@keyframes mm-pop { 0% { transform: rotateY(180deg) scale(1.12); opacity: 1; } 100% { transform: rotateY(180deg) scale(1); } }
.mm-own { position: absolute; right: 6px; top: 6px; width: 10px; height: 10px; border-radius: 50%; background: var(--c); transform: rotateY(180deg); box-shadow: 0 0 0 2px rgba(255, 250, 240, .9); }
.mm-grid.wait .mm-c:not(.up):not(.done) { cursor: pointer; }

/* ---------- banner, foot, actions ---------- */
.mm-banner { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: 16px; background: var(--cream); box-shadow: 0 2px 0 rgba(120, 80, 30, .18); min-height: 64px; }
.mm-banner p { font: 800 15px/1.35 var(--cbx-body); }
.mm-banner b { color: #c25f0c; }
.mm-bicon { width: 40px; height: 40px; flex: none; border-radius: 50%; display: flex; align-items: center; justify-content: center; background: #e7c48c; }
.mm-bicon.good { background: var(--good); }
.mm-bicon.miss { background: var(--warn); }
.mm-bicon.win { background: #ffc93c; }
.mm-foot { display: flex; justify-content: center; align-items: center; flex-wrap: wrap; gap: 2px 6px; font-size: 13px; font-weight: 700; color: var(--ink-3); text-align: center; }
.mm-link { border: 0; background: none; padding: 8px 4px; min-height: 40px; font: 800 13px var(--cbx-body); color: var(--ink-2); text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }
.mm-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; }
.mm-actions .cbx-btn { min-height: 46px; padding: 10px 18px; font-size: 15px; }
.mm-card .cbx-btn:not(.alt) { background: var(--warn); color: #2b1503; box-shadow: 0 4px 0 #a8501a; }

/* ---------- players dialog ---------- */
.mm-dlg { border: 0; padding: 0; background: transparent; max-width: min(420px, calc(100vw - 24px)); width: 100%; }
.mm-dlg::backdrop { background: rgba(42, 33, 22, .55); }
.mm-dlg-card { margin: 0; padding: 22px 20px 18px; border-radius: 24px; background: var(--cream); color: var(--ink); font-family: var(--cbx-body); }
.mm-dlg-card h2 { margin: 0 0 4px; font: 900 24px 'Fraunces', Georgia, serif; }
.mm-dlg-card p { margin: 0 0 12px; font-weight: 700; color: var(--ink-2); }
.mm-field { display: flex; align-items: center; gap: 10px; margin: 0 0 8px; }
.mm-field .ini { width: 30px; height: 30px; flex: none; border-radius: 50%; background: var(--c); }
.mm-field input { flex: 1; min-width: 0; min-height: 46px; padding: 0 12px; border-radius: 12px; border: 2px solid #e2cfa9; background: #fff; font: 800 16px var(--cbx-body); color: var(--ink); }
.mm-field input:focus { outline: none; border-color: var(--warn); }
.mm-field .x { width: 40px; height: 40px; border: 0; border-radius: 50%; background: rgba(120, 80, 30, .1); font: 900 18px var(--cbx-body); color: var(--ink-3); cursor: pointer; }
.mm-dlg-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 12px; }

/* ---------- the result sheet ---------- */
.mm-end-back { position: fixed; inset: 0; z-index: 2147482000; display: flex; align-items: flex-end; justify-content: center; padding: 12px; background: rgba(42, 33, 22, .45); animation: mm-fade .25s ease-out; }
@keyframes mm-fade { from { opacity: 0; } }
.mm-end { box-sizing: border-box; width: 100%; max-width: 440px; max-height: calc(100svh - 24px); overflow: auto; padding: 24px 20px calc(18px + env(safe-area-inset-bottom)); border-radius: 28px; background: var(--cream); color: var(--ink);
  display: flex; flex-direction: column; align-items: center; gap: 12px; text-align: center; font-family: var(--cbx-body); box-shadow: 0 -10px 40px rgba(90, 50, 10, .3); animation: mm-up .35s cubic-bezier(.2, .9, .25, 1); }
@keyframes mm-up { from { transform: translateY(40px); opacity: 0; } }
.mm-fan { display: flex; justify-content: center; gap: 10px; margin: -4px 0 2px; }
.mm-fan span { width: 46px; height: 58px; border-radius: 10px; display: flex; align-items: center; justify-content: center; background: linear-gradient(180deg, #fffdf6, #fbf1dc); box-shadow: 0 4px 0 #c9b48a, 0 8px 12px rgba(60, 30, 5, .25); }
.mm-fan span svg { width: 30px; height: 30px; }
.mm-kick { margin: 0; font-size: 13px; font-weight: 900; letter-spacing: .12em; text-transform: uppercase; color: #8a6a3c; }
.mm-end h2 { margin: 0; font: 900 30px/1.1 'Fraunces', Georgia, serif; color: var(--ink); }
.mm-end-line { margin: 0; font-size: 15px; font-weight: 700; color: var(--ink-2); }
.mm-scores { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; width: 100%; }
.mm-scores.n1 { grid-template-columns: minmax(0, 1fr); max-width: 220px; }
.mm-scores.n3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.mm-scores.n4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.mm-sc { padding: 12px 8px; border-radius: 18px; background: color-mix(in srgb, var(--c) 14%, #fff); border: 3px solid transparent; min-width: 0; }
.mm-sc.top { border-color: var(--c); }
.mm-sc .nm { font-size: 14px; font-weight: 900; color: color-mix(in srgb, var(--c) 70%, #000); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mm-sc .n { font: 900 40px/1.1 'Fraunces', Georgia, serif; }
.mm-sc .sub { font-size: 13px; font-weight: 800; color: var(--ink-2); }
.mm-stars { margin-top: 6px; display: flex; justify-content: center; gap: 2px; }
.mm-more { width: 100%; margin: 0; padding: 0; list-style: none; font-size: 14px; font-weight: 800; color: var(--ink-2); }
.mm-more li { display: flex; justify-content: space-between; padding: 6px 12px; border-radius: 10px; background: #f4ecd9; margin-top: 4px; }
.mm-note { margin: 0; font-size: 13px; font-weight: 800; color: var(--ink-2); }
.mm-name { display: flex; align-items: center; gap: 8px; width: 100%; font-weight: 800; font-size: 14px; color: var(--ink-2); }
.mm-name input { flex: 1; min-width: 0; min-height: 44px; padding: 0 12px; border-radius: 12px; border: 2px solid #e2cfa9; background: #fff; font: 800 16px var(--cbx-body); color: var(--ink); }
.mm-end-btns { display: flex; flex-direction: column; gap: 10px; width: 100%; }
.mm-go { min-height: 54px; border: 0; border-radius: 16px; background: var(--warn); color: #2b1503; font: 900 17px var(--cbx-body); box-shadow: 0 4px 0 #a8501a; cursor: pointer; }
.mm-alt { min-height: 48px; border: 0; border-radius: 16px; background: #efe3c8; color: var(--ink); font: 800 16px var(--cbx-body); cursor: pointer; }
.mm-end-btns a { min-height: 40px; display: flex; align-items: center; justify-content: center; font-weight: 800; color: var(--ink-2); }

@media (prefers-reduced-motion: reduce) {
  .mm-in, .mm-c.up, .mm-chip { transition: none !important; }
  .mm-c.just .mm-face, .mm-end, .mm-end-back { animation: none !important; }
}
