/* Paartjes (Memory): home tile, menu extras, the cards and the players. The menu is built from the
   shell's option cards; shared look lives in css/style.css. */

/* ---------- home tile ---------- */
#tile-memory .tile-art { display: flex; align-items: center; justify-content: center; }
#tile-memory .tile-art svg { width: 100%; height: 100%; display: block; }

/* ---------- menu: the shell's option cards (css/style.css) ---------- */
.memory-opt .option-art .msize { width: 56px; height: 56px; }
.memory-sample { width: 52px; height: 52px; display: flex; align-items: center; justify-content: center; border-radius: 12px; background: #fff; box-shadow: 0 0 0 3px var(--bz-brand-tint); }
.memory-sample svg { width: 44px; height: 44px; display: block; }
.memory-opt .option-art .token, .memory-opt .option-art .robot { width: 56px; height: 56px; }
.memory-stars, .memory-wins { display: inline-flex; align-items: center; gap: 2px; margin-top: 2px; font-weight: 900; color: var(--bz-ink); }
.memory-stars svg { width: 16px; height: 16px; fill: none; stroke: var(--bz-star-empty); stroke-width: 2; stroke-linejoin: round; }
.memory-stars svg.on { fill: var(--bz-star); stroke: var(--bz-star-edge); stroke-width: 1.2; }
.memory-wins svg { width: 18px; height: 18px; }

/* ---------- HUD ---------- */
.memory-hud .bar-spacer { width: 60px; flex: none; }

/* ---------- the cards ---------- */
#memory-stage {
  flex: 1;
  min-height: 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 4px 12px 14px;
}
#memory-stage.side { flex-direction: row; }
.memory-board {
  --cols: 3;
  --rows: 2;
  --cell: 80px;
  flex: none;
  display: grid;
  grid-template-columns: repeat(var(--cols), var(--cell));
  grid-auto-rows: var(--cell);
  gap: calc(var(--cell) * 0.12);
  perspective: 900px;
}
.mcard {
  position: relative;
  margin: 0;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.mcard:focus-visible { outline: 4px solid var(--bz-focus); outline-offset: 3px; border-radius: 14px; }
.mcard-in {
  position: absolute;
  inset: 0;
  transform-style: preserve-3d;
  transition: transform 0.38s cubic-bezier(0.3, 0.7, 0.4, 1.25);
}
.mcard.up .mcard-in { transform: rotateY(180deg); }
.mcard-face {
  position: absolute;
  inset: 0;
  border-radius: calc(var(--cell) * 0.16);
  overflow: hidden;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  box-shadow: 0 calc(var(--cell) * 0.05) 0 #c9c1ff, 0 6px 14px rgba(59, 47, 168, 0.18);
}
.mcard-back svg { width: 100%; height: 100%; display: block; }
.mcard-front {
  transform: rotateY(180deg);
  background: #fffdf7;
  border: 3px solid #e4defc;
  display: flex;
  align-items: center;
  justify-content: center;
}
.mcard-front svg { width: 82%; height: 82%; display: block; }
.mcard:active:not(.up) .mcard-in { transform: scale(0.95); }
.mcard.wiggle .mcard-in { animation: memory-wiggle 0.4s ease; }

/* a pair found: a gold ring, a hop, and with two players the finder's colour */
.mcard.found .mcard-front { border-color: var(--gold); background: #fff8dc; }
.mcard.found.p0 .mcard-front { border-color: #d99a3b; background: #fff1d6; }
.mcard.found.p1 .mcard-front { border-color: #5a8fd6; background: #e3efff; }
.mcard.found { cursor: default; }
.mcard.hop { animation: memory-hop 0.6s ease 0.25s 2; }
.mcard.hop::after {
  content: "";
  position: absolute;
  inset: -8%;
  border-radius: calc(var(--cell) * 0.2);
  border: 4px solid var(--gold);
  opacity: 0;
  animation: memory-ring 0.9s ease 0.2s 1;
  pointer-events: none;
}

/* ---------- the players ---------- */
.memory-side { display: flex; flex-direction: column; align-items: center; gap: 8px; }
#memory-stage.side .memory-side { width: 200px; }
#memory-stage.side .memory-turn { flex-direction: column; }
.memory-chip .token, .memory-chip .robot { width: 44px; height: 44px; flex: none; }
.memory-chip .score { white-space: normal; min-width: 1.6em; padding: 2px 8px; border-radius: 999px; background: #f1edff; color: var(--primary-dark); text-align: center; }
.memory-chip.solo { opacity: 1; background: #fff; }
.memory-chip.solo .name { display: none; }
.memory-chip.solo .score { background: none; padding: 0; }
.memory-status { max-width: 320px; }

/* the end card */
.memory-ov-stars { display: inline-flex; gap: 6px; }
.memory-ov-stars svg { width: 64px; height: 64px; fill: none; stroke: var(--bz-star-empty); stroke-width: 1.6; stroke-linejoin: round; }
.memory-ov-stars svg.on { fill: var(--bz-star); stroke: var(--bz-star-edge); animation: memory-hop 0.6s ease 0.1s 2; }

/* short sideways phones: the HUD becomes a column on the left */
@media (orientation: landscape) and (max-height: 520px) {
  #screen-memory { flex-direction: row; }
  .memory-hud { flex-direction: column; justify-content: space-between; padding: 10px 6px 10px 12px; }
  .memory-hud .hud-mid { flex: 0; }
  .memory-hud .btn.icon { width: 54px; height: 54px; }
  .memory-hud .bar-spacer { display: none; }
  .memory-hud { width: 108px; flex: none; }
  .memory-hud .hud-mid { max-width: 100px; text-align: center; }
  .memory-hud .dogu-title { white-space: normal; font-size: 1rem; }
  .memory-hud .hud-level { font-size: 0.8rem; }
  #memory-stage.side .memory-side { width: 150px; }
  #memory-stage.side .memory-chip { width: 100%; box-sizing: border-box; font-size: 0.9rem; gap: 6px; padding: 4px 8px 4px 4px; }
  #memory-stage.side .memory-chip.on, #memory-stage.side .memory-chip.winner { transform: none; }
  .memory-chip .token, .memory-chip .robot { width: 34px; height: 34px; }
  .memory-status { font-size: 0.9rem; }
}
@media (max-width: 360px) {
  .memory-chip { gap: 6px; padding: 4px 10px 4px 4px; font-size: 0.92rem; }
  .memory-chip .token, .memory-chip .robot { width: 36px; height: 36px; }
  .memory-chip.on, .memory-chip.winner { transform: none; }
}
@media (max-height: 600px) {
  .memory-ov-stars svg { width: 44px; height: 44px; }
}

@keyframes memory-hop { 0%, 100% { transform: translateY(0) scale(1); } 40% { transform: translateY(-12%) scale(1.05); } 70% { transform: translateY(2%) scale(0.98, 1.02); } }
@keyframes memory-ring { 0% { opacity: 0.9; transform: scale(0.9); } 100% { opacity: 0; transform: scale(1.12); } }
@keyframes memory-wiggle { 0%, 100% { transform: translateX(0); } 25% { transform: translateX(-5px); } 75% { transform: translateX(5px); } }

@media (prefers-reduced-motion: reduce) {
  .mcard-in { transition: none; }
  .mcard.hop, .mcard.hop::after, .mcard.wiggle .mcard-in, .memory-ov-stars svg.on { animation: none !important; }
}
