/**
 * Memory Match — Games Lab styling (aligned with Slider Puzzle).
 */

.memory-match-page {
  --lo-blue: #6fd3f2;
  --lo-deep-blue: #17345f;
  --lo-navy: #0d2142;
  --lo-yellow: #ffd84d;
  --lo-cream: #fffaf0;
  --lo-green: #8fd36c;
  --lo-text: #16304f;
  --lo-white: #ffffff;
  --lo-btn-primary-bg: linear-gradient(180deg, #ffe57a 0%, var(--lo-yellow) 55%, #f5c83a 100%);
  --lo-btn-primary-border: 2.5px solid rgba(13, 33, 66, 0.18);
  --lo-btn-primary-color: var(--lo-navy);
  --lo-btn-primary-shadow: 0 5px 0 rgba(196, 140, 20, 0.45), 0 8px 16px rgba(17, 52, 89, 0.12);
  --lo-btn-primary-shadow-hover: 0 7px 0 rgba(196, 140, 20, 0.45), 0 12px 22px rgba(17, 52, 89, 0.16);
  --labs-stage-aspect: unset;
  --labs-game-card-min-h: auto;
}

.memory-match-page .labs-game-card {
  min-height: auto;
  gap: 0.65rem;
}

.memory-match-page .labs-game-head {
  margin-bottom: 0;
}

.memory-match-page .memory-match__lead {
  white-space: nowrap;
  max-width: none;
  font-size: clamp(0.72rem, 2.1vw, 0.92rem);
  line-height: 1.2;
  margin-top: 0.35rem;
}

.memory-match-page .labs-game-card__stage-grow {
  flex: 0 0 auto;
}

.memory-match-page *,
.memory-match-page *::before,
.memory-match-page *::after {
  -webkit-tap-highlight-color: transparent;
}

.memory-match__shell {
  width: min(540px, 100%);
}

.memory-match__board {
  width: 100%;
  flex: 0 0 auto;
  display: block;
}

.memory-match__board-wrap {
  width: 100%;
  height: auto;
  min-height: 0;
  max-height: none;
  padding: 0.45rem;
  box-sizing: border-box;
  overflow: visible;
  contain: none;
}

.memory-match-page .memory-match__board-wrap.labs-game-stage {
  aspect-ratio: unset;
  display: block;
}

.memory-match__toolbar {
  display: grid;
  grid-template-columns: 1fr;
  justify-items: center;
  align-items: center;
  gap: 0.4rem;
  min-height: calc(38px + 0.4rem + 38px);
}

.memory-match__difficulty {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  flex: 0 1 auto;
}

.memory-match__difficulty label {
  font-family: var(--lo-font-display);
  font-weight: 700;
  font-size: 0.82rem;
  color: var(--lo-deep-blue);
  white-space: nowrap;
}

.memory-match__select {
  min-height: 38px;
  padding: 0.3rem 0.65rem;
  border-radius: 12px;
  border: 2px solid rgba(13, 33, 66, 0.22);
  background: rgba(255, 255, 255, 0.96);
  color: var(--lo-text);
  font-family: var(--lo-font-body);
  font-size: 0.82rem;
  font-weight: 700;
  cursor: pointer;
  max-width: 9.5rem;
}

.memory-match__select:focus-visible {
  outline: 2px solid var(--lo-deep-blue);
  outline-offset: 2px;
}

.memory-match__stats {
  display: inline-flex;
  flex-wrap: nowrap;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  width: 100%;
  max-width: 100%;
}

.memory-match__stat {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  min-width: 5.65rem;
  padding: 0.3rem 0.55rem;
  font-variant-numeric: tabular-nums;
  border-radius: 999px;
  font-family: var(--lo-font-display);
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--lo-navy);
  background: linear-gradient(180deg, #ffe57a 0%, var(--lo-yellow) 55%, #f5c83a 100%);
  border: 2px solid rgba(13, 33, 66, 0.12);
  box-shadow: 0 3px 0 rgba(196, 140, 20, 0.35);
  white-space: nowrap;
}

.memory-match__grid {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(var(--mm-cols, 3), minmax(0, 1fr));
  grid-auto-rows: auto;
  gap: 0.32rem;
  align-content: start;
}

.memory-match__card {
  position: relative;
  display: block;
  width: 100%;
  min-width: 0;
  border: none;
  padding: 0;
  border-radius: 14px;
  cursor: pointer;
  background: transparent;
  perspective: 800px;
  touch-action: manipulation;
  overflow: hidden;
}

.memory-match__card::before {
  content: "";
  display: block;
  padding-top: 100%;
}

.memory-match__card:focus-visible {
  outline: 3px solid var(--lo-deep-blue);
  outline-offset: 3px;
}

.memory-match__card:disabled {
  cursor: default;
}

.memory-match__card-inner {
  position: absolute;
  inset: 0;
  transform-style: preserve-3d;
  transition: transform 0.42s cubic-bezier(0.34, 1.2, 0.64, 1);
  border-radius: 14px;
}

.memory-match__card.is-flipped .memory-match__card-inner,
.memory-match__card.is-matched .memory-match__card-inner {
  transform: rotateY(180deg);
}

.memory-match__face {
  position: absolute;
  inset: 0;
  border-radius: 14px;
  backface-visibility: hidden;
  overflow: hidden;
  border: 2.5px solid rgba(255, 255, 255, 0.95);
  box-shadow: 0 4px 0 rgba(17, 52, 89, 0.14);
}

.memory-match__face--back {
  display: flex;
  align-items: center;
  justify-content: center;
  background: #0d2142;
}

.memory-match__face--back img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.memory-match__face--front {
  transform: rotateY(180deg);
  background: #fff;
}

.memory-match__face--front img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.memory-match__card.is-matched .memory-match__face {
  border-color: rgba(143, 211, 108, 0.95);
  box-shadow: 0 0 0 2px rgba(143, 211, 108, 0.55), 0 4px 0 rgba(70, 130, 45, 0.25);
}

.memory-match__hint {
  margin: 0;
  min-height: 2.5em;
  text-align: center;
  font-family: var(--lo-font-body);
  font-size: 0.78rem;
  font-weight: 700;
  line-height: 1.25;
  color: rgba(22, 48, 79, 0.72);
}

.memory-match__actions {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  margin-top: 0.15rem;
}

.memory-match__actions-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.55rem;
}

.memory-match__actions .home-btn {
  width: 100%;
  text-align: center;
  justify-content: center;
}

.memory-match-btn {
  border: 2.5px solid rgba(13, 33, 66, 0.16);
  font-family: var(--lo-font-display);
  font-weight: 700;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.memory-match-btn:hover,
.memory-match-btn:focus-visible {
  transform: translateY(-3px) scale(1.02);
  outline: 2px solid var(--lo-deep-blue);
  outline-offset: 3px;
}

.memory-match-btn--yellow {
  background: var(--lo-btn-primary-bg);
  color: var(--lo-btn-primary-color);
  box-shadow: var(--lo-btn-primary-shadow);
}

.memory-match-btn--yellow:hover,
.memory-match-btn--yellow:focus-visible {
  box-shadow:
    var(--lo-btn-primary-shadow-hover),
    0 0 0 4px rgba(255, 216, 77, 0.35);
}

.memory-match-btn--blue {
  background: linear-gradient(160deg, #7ec8ff 0%, #4aa8e8 55%, #3d92d4 100%);
  color: #fff;
  box-shadow: 0 5px 0 rgba(35, 105, 160, 0.45), 0 8px 16px rgba(17, 52, 89, 0.12);
}

.memory-match-btn--purple {
  background:
    linear-gradient(135deg, rgba(90, 70, 170, 0.35) 0%, transparent 55%),
    linear-gradient(160deg, #6b5bd6 0%, #4a7fd4 48%, #3d92d4 100%);
  color: #fff;
  box-shadow: 0 5px 0 rgba(55, 45, 130, 0.45), 0 8px 16px rgba(17, 52, 89, 0.12);
}

.memory-match-btn--green {
  background: linear-gradient(160deg, #b8eb98 0%, var(--lo-green) 55%, #6fbf52 100%);
  color: var(--lo-navy);
  box-shadow: 0 5px 0 rgba(70, 130, 45, 0.4), 0 8px 16px rgba(17, 52, 89, 0.12);
}

.memory-match__actions .labs-back-to-hub--block {
  margin-top: 0.35rem;
  padding-top: 0.85rem;
  border-top: 1px solid rgba(23, 52, 95, 0.1);
}

@media (max-width: 480px) {
  .memory-match__actions-row {
    grid-template-columns: 1fr;
  }

  .memory-match__stat {
    font-size: 0.76rem;
    padding-inline: 0.55rem;
  }

  .memory-match-page .memory-match__lead {
    font-size: 0.7rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .memory-match__card-inner {
    transition: none;
  }

  .leaderboard-card,
  .leaderboard-popup-row {
    animation: none;
    opacity: 1;
    transform: none;
  }
}
