/* =====================================================
   MEMORY MATCH
   ===================================================== */

.mm-hero {
  background: linear-gradient(180deg, #e3f1fb 0%, var(--parchment) 100%);
  padding: 0.9rem 1rem 0.3rem;
  text-align: center;
}
.mm-hero .section-title { font-size: clamp(1.6rem, 6vw, 2.2rem); margin-bottom: 0.2rem; }
.mm-hero .section-subtitle { font-size: 0.9rem; margin-bottom: 0.4rem; }
.mm-hero .crumbs { text-align: left; max-width: 980px; margin: 0 auto 0.25rem; font-weight: 800; font-size: 0.9rem; }
.mm-hero .crumbs a { color: var(--green); }
.mm-hero .crumbs a:hover { text-decoration: underline; }

.mm-app { max-width: 980px; margin: 0 auto; padding: 0.4rem 0.75rem 2rem; position: relative; }

/* ---------- levels ---------- */
.mm-levels { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 0.4rem; }
.mm-level[hidden] { display: none; }
.mm-level {
  position: relative;
  font-family: var(--font-display);
  color: var(--brown);
  background: var(--parchment2);
  border: 2px solid var(--parchment3);
  border-radius: 14px;
  padding: 0.4rem 0.2rem;
  min-height: 52px;
  cursor: pointer;
  line-height: 1.1;
}
.mm-level b { display: block; font-size: 0.95rem; font-weight: normal; }
.mm-level small { display: block; font-family: var(--font-body); font-weight: 800; font-size: 0.68rem; opacity: 0.75; }
.mm-level[aria-pressed="true"] { background: var(--red); border-color: var(--red); color: #fff; }
.mm-level.done .mm-check::after { content: "✅"; position: absolute; top: -7px; right: -4px; font-size: 0.95rem; font-style: normal; }
.mm-secret { background: #3b2a6b; border-color: var(--gold); color: var(--gold); animation: mm-glow 1.6s ease-in-out infinite; }
.mm-secret[aria-pressed="true"] { background: #6a3fc0; color: #fff; }
@keyframes mm-glow { 0%,100% { box-shadow: 0 0 0 rgba(244,200,66,0); } 50% { box-shadow: 0 0 14px rgba(244,200,66,0.9); } }

/* ---------- HUD ---------- */
.mm-hud { display: flex; align-items: center; gap: 0.4rem; margin-top: 0.6rem; }
.mm-stat {
  flex: 1;
  background: #fff;
  border: 2px solid var(--parchment3);
  border-radius: 12px;
  text-align: center;
  padding: 0.2rem 0.2rem;
  line-height: 1.15;
}
.mm-stat span { display: block; font-weight: 800; font-size: 0.65rem; color: var(--brown); opacity: 0.75; text-transform: uppercase; letter-spacing: 0.04em; }
.mm-stat b { font-family: var(--font-display); font-weight: normal; font-size: 1.2rem; color: var(--red); }
.mm-strikes b { letter-spacing: 0.15rem; font-size: 1rem; min-height: 1.4rem; display: inline-block; }
.mm-icon {
  flex: 0 0 auto;
  width: 46px; height: 46px;
  font-size: 1.3rem;
  background: var(--parchment2);
  border: 2px solid var(--parchment3);
  border-radius: 12px;
  cursor: pointer;
}
.mm-icon[aria-pressed="false"] { opacity: 0.55; }
.mm-status { text-align: center; font-weight: 800; color: var(--brown); margin: 0.5rem 0; min-height: 1.4em; font-size: 0.95rem; }

/* ---------- board ---------- */
.mm-board {
  --cols: 4;
  --gap: 8px;
  display: grid;
  grid-template-columns: repeat(var(--cols), 1fr);
  gap: var(--gap);
  margin: 0 auto;
  max-width: calc(var(--cols) * 150px);
  perspective: 900px;
}
.mm-board[data-level="easy"]   { --cols: 4; }
.mm-board[data-level="medium"] { --cols: 4; }
.mm-board[data-level="hard"],
.mm-board[data-level="secret"] { --cols: 6; --gap: 5px; }
@media (min-width: 700px) {
  .mm-board { --gap: 12px; }
  .mm-board[data-level="easy"]   { --cols: 6; }
  .mm-board[data-level="medium"] { --cols: 8; --gap: 10px; }
  .mm-board[data-level="hard"],
  .mm-board[data-level="secret"] { --cols: 8; --gap: 10px; }
  .mm-board { max-width: calc(var(--cols) * 125px); }
}

.mm-card {
  position: relative;
  aspect-ratio: 270 / 400;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  container-type: inline-size;
}
.mm-card:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; border-radius: 12px; }
.mm-inner {
  position: absolute; inset: 0;
  transform-style: preserve-3d;
  transition: transform 0.45s cubic-bezier(.3,1.3,.5,1);
}
.mm-card.flipped .mm-inner, .mm-card.matched .mm-inner { transform: rotateY(180deg); }
.mm-back, .mm-front {
  position: absolute; inset: 0;
  border-radius: 12px;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  overflow: hidden;
  box-shadow: 0 3px 6px rgba(60, 30, 10, 0.28);
}
.mm-back {
  background:
    radial-gradient(circle at 20% 15%, rgba(255,255,255,0.18) 0 8%, transparent 9%),
    radial-gradient(circle at 80% 85%, rgba(255,255,255,0.18) 0 8%, transparent 9%),
    linear-gradient(160deg, #d62f2f 0%, #a31616 100%);
  border: 3px solid #fff;
  display: flex; align-items: center; justify-content: center;
}
.mm-back::before {
  content: "";
  position: absolute; inset: 5%;
  border: 2px dashed rgba(255, 224, 130, 0.85);
  border-radius: 9px;
}
.mm-logo {
  font-family: var(--font-display);
  color: #ffe082;
  font-size: 28cqw;
  line-height: 1;
  letter-spacing: -0.02em;
  text-shadow: 0 2px 0 #6e1010, 0 0 6px rgba(0,0,0,0.25);
  transform: rotate(-6deg);
}
.mm-logo i { font-style: normal; color: #fff; }
.mm-back::after {
  content: "❄";
  position: absolute; bottom: 7%; left: 0; right: 0;
  text-align: center; color: rgba(255,255,255,0.8);
  font-size: 16cqw; line-height: 1;
}
.mm-front {
  transform: rotateY(180deg);
  background: #fff;
  border: 3px solid var(--green);
}
.mm-front img { width: 100%; height: 100%; object-fit: cover; display: block; pointer-events: none; }
.mm-card.matched .mm-front { border-color: var(--gold); box-shadow: 0 0 10px rgba(244,200,66,0.95); }
.mm-card.matched { cursor: default; animation: mm-pop 0.5s ease-out; }
@keyframes mm-pop { 40% { transform: scale(1.08); } }
.mm-card.nope { animation: mm-shake 0.35s; }
@keyframes mm-shake { 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }

/* secret level */
.mm-board[data-level="secret"] .mm-back { background: linear-gradient(160deg, #5b34b0 0%, #2c1766 100%); }
.mm-board[data-level="secret"] .mm-logo { color: #ffd54a; text-shadow: 0 2px 0 #190c40; }
.mm-board.shuffling { animation: mm-board-shake 0.5s; }
@keyframes mm-board-shake { 20% { transform: rotate(-1deg); } 60% { transform: rotate(1deg); } }

/* ---------- result popup ---------- */
.mm-result {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(30, 20, 10, 0.55);
  display: flex; align-items: center; justify-content: center;
  padding: 1rem;
}
.mm-result[hidden] { display: none; }
.mm-result-card {
  background: var(--parchment);
  border: 4px solid var(--gold);
  border-radius: 22px;
  padding: 1.4rem 1.2rem;
  max-width: 360px; width: 100%;
  text-align: center;
  animation: mm-result-pop 0.35s ease-out;
}
@keyframes mm-result-pop { from { transform: scale(0.7); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.mm-stars { font-size: 2.4rem; letter-spacing: 0.2rem; }
.mm-result-card h2 { font-family: var(--font-display); color: var(--red); margin: 0.3rem 0; }
.mm-result-card p { margin: 0 0 1rem; color: var(--brown); font-weight: 700; }
.mm-result-btns { display: flex; gap: 0.5rem; justify-content: center; flex-wrap: wrap; }
.mm-result-btns .btn { padding: 0.55rem 1rem; }

@media (prefers-reduced-motion: reduce) {
  .mm-inner { transition-duration: 0.01s; }
  .mm-card.matched, .mm-card.nope, .mm-board.shuffling, .mm-result-card, .mm-secret { animation: none; }
}
