/**
 * Memory Math Grid Pro — touch-first, high-contrast, smart-panel friendly
 */
.mmg-pro {
  --mmg-bg: #0f172a;
  --mmg-panel: #1e293b;
  --mmg-text: #f8fafc;
  --mmg-muted: #94a3b8;
  --mmg-card-back: linear-gradient(145deg, #2563eb, #1d4ed8);
  --mmg-card-front: #ffffff;
  --mmg-ink: #0f172a;
  --mmg-match: #22c55e;
  --mmg-wrong: #ef4444;
  --mmg-radius: 1rem;
  font-family: "Poppins", system-ui, sans-serif;
  background: var(--mmg-bg);
  color: var(--mmg-text);
  border-radius: var(--mmg-radius);
  overflow: hidden;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.mmg-pro * {
  box-sizing: border-box;
}

.mmg-pro button,
.mmg-pro select,
.mmg-pro input {
  font: inherit;
  touch-action: manipulation;
}

.mmg-pro__bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.75rem;
  padding: 0.75rem 1rem;
  background: var(--mmg-panel);
  border-bottom: 2px solid #334155;
}

.mmg-pro__title {
  font-weight: 700;
  font-size: clamp(1rem, 2.5vw, 1.25rem);
  margin-right: auto;
  letter-spacing: 0.02em;
}

.mmg-pro__pill {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.45rem 0.85rem;
  border-radius: 9999px;
  font-weight: 600;
  font-size: clamp(0.8rem, 1.8vw, 0.95rem);
  border: 2px solid transparent;
  min-height: 44px;
}

.mmg-pro__pill--timer {
  background: #0ea5e9;
  color: #fff;
}

.mmg-pro__pill--muted {
  background: #334155;
  color: var(--mmg-muted);
}

.mmg-pro__btn {
  min-height: 48px;
  min-width: 48px;
  padding: 0.5rem 1rem;
  border-radius: 9999px;
  border: 2px solid #475569;
  background: #334155;
  color: var(--mmg-text);
  font-weight: 600;
  cursor: pointer;
}

.mmg-pro__btn:active {
  transform: scale(0.97);
}

.mmg-pro__btn--primary {
  background: #22c55e;
  border-color: #16a34a;
  color: #052e16;
}

.mmg-pro__btn--accent {
  background: #f59e0b;
  border-color: #d97706;
  color: #1c1917;
}

.mmg-pro__controls {
  padding: 0.75rem 1rem 1rem;
  background: #0c1222;
  display: grid;
  gap: 0.75rem;
}

.mmg-pro__row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.75rem;
}

.mmg-pro__label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--mmg-muted);
  width: 100%;
}

.mmg-pro__select {
  min-height: 48px;
  padding: 0 1rem;
  border-radius: 0.75rem;
  border: 2px solid #475569;
  background: var(--mmg-panel);
  color: var(--mmg-text);
  font-weight: 600;
}

.mmg-pro__players {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding: 0.5rem 1rem 0.75rem;
  background: #0c1222;
}

.mmg-pro__player {
  flex: 1 1 140px;
  min-height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 0.85rem;
  border-radius: 0.75rem;
  border: 3px solid transparent;
  font-weight: 700;
  font-size: clamp(0.9rem, 2vw, 1.1rem);
  color: #fff;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
}

.mmg-pro__player--active {
  box-shadow: 0 0 0 3px #fbbf24, 0 0 24px rgba(251, 191, 36, 0.45);
  transform: scale(1.02);
}

.mmg-pro__player-score {
  font-size: 1.5rem;
  font-variant-numeric: tabular-nums;
}

.mmg-pro__hint {
  padding: 0.35rem 1rem 0.75rem;
  text-align: center;
  font-size: clamp(0.85rem, 2vw, 1rem);
  color: var(--mmg-muted);
  min-height: 2.5rem;
}

.mmg-pro__grid-wrap {
  padding: 0.75rem 1rem 1.25rem;
  max-width: 1600px;
  margin: 0 auto;
}

.mmg-pro__grid {
  display: grid;
  gap: clamp(0.5rem, 1.2vw, 1rem);
  width: 100%;
  justify-content: center;
}

.mmg-pro__grid-empty {
  grid-column: 1 / -1;
  text-align: center;
  padding: 2rem;
  color: #fcd34d;
  font-weight: 600;
  max-width: 36rem;
  margin: 0 auto;
}

.mmg-pro__card {
  width: 100%;
  min-width: 120px;
  min-height: 120px;
  aspect-ratio: 1;
  perspective: 1000px;
  border: none;
  padding: 0;
  background: transparent;
  cursor: pointer;
  border-radius: var(--mmg-radius);
}

.mmg-pro__card:focus-visible {
  outline: 4px solid #fbbf24;
  outline-offset: 4px;
}

.mmg-pro__card-inner {
  position: relative;
  width: 100%;
  height: 100%;
  border-radius: var(--mmg-radius);
  transform-style: preserve-3d;
  transition: transform 0.42s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}

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

.mmg-pro__face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  border-radius: var(--mmg-radius);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.35rem;
  text-align: center;
  font-weight: 700;
  font-size: clamp(1.1rem, 3.2vw, 2rem);
  line-height: 1.15;
  word-break: break-word;
}

.mmg-pro__face--back {
  background: var(--mmg-card-back);
  color: #fff;
  border: 3px solid #60a5fa;
}

.mmg-pro__face--front {
  background: var(--mmg-card-front);
  color: var(--mmg-ink);
  border: 3px solid #cbd5e1;
  transform: rotateY(180deg);
}

.mmg-pro__card.is-matched .mmg-pro__face--front {
  background: #dcfce7;
  border-color: var(--mmg-match);
  color: #14532d;
  box-shadow: 0 0 28px rgba(34, 197, 94, 0.65), inset 0 0 20px rgba(34, 197, 94, 0.2);
}

.mmg-pro__card.is-wrong .mmg-pro__face--front,
.mmg-pro__card.is-wrong .mmg-pro__face--back {
  animation: mmg-shake 0.55s ease;
  border-color: var(--mmg-wrong) !important;
  box-shadow: 0 0 20px rgba(239, 68, 68, 0.55);
}

@keyframes mmg-shake {
  0%,
  100% {
    transform: rotateY(var(--ry, 0deg)) translateX(0);
  }
  20% {
    transform: rotateY(var(--ry, 0deg)) translateX(-6px);
  }
  40% {
    transform: rotateY(var(--ry, 0deg)) translateX(6px);
  }
  60% {
    transform: rotateY(var(--ry, 0deg)) translateX(-4px);
  }
  80% {
    transform: rotateY(var(--ry, 0deg)) translateX(4px);
  }
}

.mmg-pro__card.is-flipped .mmg-pro__face--front {
  --ry: 180deg;
}

.mmg-pro__card.is-matched .mmg-pro__card-inner {
  animation: mmg-pop 0.45s ease;
}

@keyframes mmg-pop {
  0% {
    transform: rotateY(180deg) scale(1);
  }
  40% {
    transform: rotateY(180deg) scale(1.06);
  }
  100% {
    transform: rotateY(180deg) scale(1);
  }
}

.mmg-pro__backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.82);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.mmg-pro__modal {
  background: var(--mmg-panel);
  color: var(--mmg-text);
  max-width: 520px;
  width: 100%;
  border-radius: 1.25rem;
  padding: 1.5rem;
  border: 3px solid #475569;
  max-height: 90vh;
  overflow: auto;
}

.mmg-pro__modal h2 {
  margin: 0 0 0.75rem;
  font-size: 1.5rem;
}

.mmg-pro__modal p {
  margin: 0.35rem 0;
  color: var(--mmg-muted);
}

.mmg-pro__modal strong {
  color: var(--mmg-text);
}

.mmg-pro__textarea {
  width: 100%;
  min-height: 120px;
  margin-top: 0.5rem;
  padding: 0.75rem;
  border-radius: 0.75rem;
  border: 2px solid #475569;
  background: #0f172a;
  color: var(--mmg-text);
  font-family: ui-monospace, monospace;
  font-size: 0.9rem;
}

.mmg-pro__table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
  margin-top: 0.75rem;
}

.mmg-pro__table th,
.mmg-pro__table td {
  border: 1px solid #475569;
  padding: 0.35rem 0.5rem;
  text-align: left;
}

.mmg-pro__hidden {
  display: none !important;
}

.mmg-pro__fatal {
  padding: 2rem;
  text-align: center;
  background: #0f172a;
  color: #fecaca;
  border-radius: 1rem;
  border: 2px solid #7f1d1d;
}
.mmg-pro__fatal-title {
  font-weight: 700;
  font-size: 1.125rem;
  margin-bottom: 0.5rem;
}
.mmg-pro__fatal-msg {
  font-size: 0.875rem;
  opacity: 0.95;
  word-break: break-word;
}

@media (min-width: 1024px) {
  .mmg-pro__grid .mmg-pro__card {
    min-width: 128px;
    min-height: 128px;
  }
}
