/* Master Memory mini-game. Every rule is scoped to #mg-mm-app. */

#mg-mm-app,
#mg-mm-app * {
  box-sizing: border-box;
}

#mg-mm-app {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  height: auto;
  overflow-x: hidden;
  overflow-y: auto;
  color: #24324a;
  font-family: 'Mali', 'Nunito', 'Sarabun', sans-serif;
  background:
    radial-gradient(circle at 8% 12%, rgba(255, 183, 197, 0.45), transparent 28%),
    radial-gradient(circle at 92% 8%, rgba(166, 224, 255, 0.5), transparent 26%),
    radial-gradient(circle at 80% 90%, rgba(186, 242, 206, 0.55), transparent 28%),
    linear-gradient(180deg, #fff8fb 0%, #f3f9ff 48%, #f4fff7 100%);
}

#mg-mm-app .mg-mm-container {
  width: min(1180px, calc(100% - 16px));
  max-width: 1180px;
  min-height: 100%;
  height: auto;
  margin: 0 auto;
  padding: 8px 0 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 0;
}

#mg-mm-app .mg-mm-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 10px;
  padding: 8px 12px;
  flex: 0 0 auto;
  background: rgba(255, 255, 255, 0.92);
  border-radius: 22px;
  box-shadow: 0 8px 22px rgba(80, 110, 150, 0.12);
}

#mg-mm-app .mg-mm-back,
#mg-mm-app .mg-mm-modal-home {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0 14px;
  border-radius: 999px;
  border: 1.5px solid #fde68a;
  background: #fffbeb;
  color: #b45309;
  font-weight: 700;
  font-size: 0.95rem;
  text-decoration: none;
}

#mg-mm-app .mg-mm-back:hover,
#mg-mm-app .mg-mm-modal-home:hover {
  background: #fef3c7;
}

#mg-mm-app .mg-mm-logo {
  width: 46px;
  height: 46px;
  object-fit: contain;
  border-radius: 14px;
  background: #ffffff;
  box-shadow: 0 3px 10px rgba(60, 90, 130, 0.16);
}

#mg-mm-app .mg-mm-brand {
  display: flex;
  flex-direction: column;
  line-height: 1.1;
  margin-right: auto;
}

#mg-mm-app .mg-mm-brand-th {
  font-weight: 700;
  color: #e11d48;
}

#mg-mm-app .mg-mm-brand-en {
  font-family: 'Fredoka', 'Nunito', sans-serif;
  font-size: 1.2rem;
  font-weight: 700;
  color: #1e293b;
}

#mg-mm-app .mg-mm-category-label {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  font-weight: 700;
  color: #475569;
}

#mg-mm-app .mg-mm-category-label span {
  white-space: nowrap;
}

#mg-mm-app .mg-mm-category {
  flex: 1 1 120px;
  min-height: 44px;
  min-width: 0;
  width: 100%;
  max-width: 220px;
  padding: 0 10px;
  border: 2px solid #e2e8f0;
  border-radius: 14px;
  background: #ffffff;
  color: #1e293b;
  font: inherit;
  font-weight: 700;
}

#mg-mm-app .mg-mm-pill {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  padding: 0 12px;
  border-radius: 999px;
  background: #eff6ff;
  color: #1d4ed8;
  font-family: 'Fredoka', 'Nunito', sans-serif;
  font-weight: 700;
  font-size: 1.05rem;
}

#mg-mm-app .mg-mm-moves {
  background: #f5f3ff;
  color: #6d28d9;
}

#mg-mm-app .mg-mm-timer {
  background: #fdf2f8;
  color: #be185d;
}

#mg-mm-app .mg-mm-btn-bgm,
#mg-mm-app .mg-mm-restart,
#mg-mm-app .mg-mm-play-again,
#mg-mm-app .mg-mm-btn-hint,
#mg-mm-app .mg-mm-btn-history,
#mg-mm-app .mg-mm-card,
#mg-mm-app .mg-mm-history-close,
#mg-mm-app .mg-mm-history-clear {
  font: inherit;
  cursor: pointer;
}

#mg-mm-app .mg-mm-btn-bgm {
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 18px;
  background: #ecfeff;
  font-size: 1.25rem;
}

#mg-mm-app .mg-mm-btn-bgm[aria-pressed="true"],
#mg-mm-app .mg-mm-btn-bgm-off {
  background: #e2e8f0;
}

#mg-mm-app .mg-mm-restart,
#mg-mm-app .mg-mm-play-again {
  min-height: 44px;
  padding: 0 14px;
  border: none;
  border-radius: 999px;
  color: #ffffff;
  font-weight: 700;
  background: linear-gradient(135deg, #c4b5fd 0%, #8b5cf6 100%);
  box-shadow: 0 4px 0 #6d28d9;
}

#mg-mm-app .mg-mm-restart:active,
#mg-mm-app .mg-mm-play-again:active {
  transform: translateY(2px);
  box-shadow: 0 2px 0 #6d28d9;
}

#mg-mm-app .mg-mm-btn-history {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0 12px;
  border: 1.5px solid #bae6fd;
  border-radius: 999px;
  background: #f0f9ff;
  color: #0369a1;
  font-size: 0.92rem;
  font-weight: 700;
}

#mg-mm-app .mg-mm-btn-history:hover {
  background: #e0f2fe;
}

#mg-mm-app .mg-mm-lead {
  margin: 0;
  flex: 0 0 auto;
  text-align: center;
  font-weight: 700;
  color: #64748b;
}

#mg-mm-app .mg-mm-toolbar {
  display: flex;
  justify-content: center;
  flex: 0 0 auto;
}

#mg-mm-app .mg-mm-btn-hint {
  min-height: 42px;
  padding: 0 16px;
  border: none;
  border-radius: 999px;
  color: #92400e;
  font-weight: 700;
  background: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%);
  box-shadow: 0 3px 0 #f59e0b;
}

#mg-mm-app .mg-mm-btn-hint:disabled {
  cursor: default;
  color: #94a3b8;
  background: #e2e8f0;
  box-shadow: none;
}

#mg-mm-app .mg-mm-btn-hint:not(:disabled):active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 #f59e0b;
}

#mg-mm-app .mg-mm-stage {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  overflow: visible;
}

#mg-mm-app .mg-mm-grid {
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  grid-auto-rows: auto;
  align-content: start;
  gap: clamp(8px, 1.4vh, 16px);
  padding: clamp(8px, 1.2vh, 14px);
  border-radius: 22px;
  background: rgba(255, 255, 255, 0.38);
}

#mg-mm-app .mg-mm-grid.mg-mm-lock {
  pointer-events: none;
}

#mg-mm-app .mg-mm-card {
  position: relative;
  width: 100%;
  height: auto;
  min-height: 148px;
  aspect-ratio: 3 / 4;
  padding: 0;
  border: none;
  border-radius: 18px;
  background: transparent;
  perspective: 900px;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

#mg-mm-app .mg-mm-card:disabled {
  cursor: default;
  opacity: 1;
}

#mg-mm-app .mg-mm-card-inner {
  position: relative;
  display: block;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  -webkit-transform-style: preserve-3d;
  transition: transform 0.48s cubic-bezier(0.4, 0.15, 0.2, 1);
}

#mg-mm-app .mg-mm-flipped .mg-mm-card-inner {
  transform: rotateY(180deg);
}

#mg-mm-app .mg-mm-card-face {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 18px;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  overflow: hidden;
}

#mg-mm-app .mg-mm-card-back {
  background:
    radial-gradient(circle at 50% 42%, #ffffff 0%, #fff7fb 58%, #fce7f3 100%);
  border: 3px solid #ffffff;
  box-shadow: 0 5px 0 rgba(244, 114, 182, 0.28), inset 0 0 0 2px #fbcfe8;
}

#mg-mm-app .mg-mm-card-logo {
  width: 68%;
  height: 68%;
  object-fit: contain;
  filter: drop-shadow(0 4px 8px rgba(190, 24, 93, 0.16));
}

#mg-mm-app .mg-mm-card-front {
  transform: rotateY(180deg);
  flex-direction: column;
  align-items: stretch;
  justify-content: stretch;
  gap: 0;
  padding: 4px 8px 2px;
  background: #ffffff;
  border: 3px solid #ffffff;
  box-shadow: inset 0 0 0 2px #ddd6fe;
}

#mg-mm-app .mg-mm-picture-wrap {
  flex: 7.4 1 0;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

#mg-mm-app .mg-mm-picture {
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
}

#mg-mm-app .mg-mm-picture-fallback,
#mg-mm-app .mg-mm-empty {
  font-size: clamp(1.6rem, 5vh, 2.8rem);
}

#mg-mm-app .mg-mm-word {
  flex: 2.6 0 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0;
  width: 100%;
  min-height: 0;
  padding: 0 4px;
  text-align: center;
}

#mg-mm-app .mg-mm-en {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 1;
  overflow: hidden;
  font-family: 'Fredoka', 'Nunito', sans-serif;
  font-weight: 700;
  letter-spacing: 0.02em;
  line-height: 1.05;
  color: #1e293b;
  font-size: clamp(0.95rem, 2.8vh, 1.7rem);
}

#mg-mm-app .mg-mm-th {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 1;
  overflow: hidden;
  font-weight: 700;
  line-height: 1.15;
  color: #c2410c;
  font-size: clamp(0.72rem, 2vh, 1.05rem);
}

#mg-mm-app .mg-mm-pop {
  z-index: 2;
  animation: mg-mm-pop 0.46s cubic-bezier(0.34, 1.5, 0.64, 1);
}

#mg-mm-app .mg-mm-matched .mg-mm-card-front {
  border-color: #86efac;
  box-shadow: 0 0 0 3px #86efac, 0 0 16px rgba(74, 222, 128, 0.9);
}

#mg-mm-app .mg-mm-card-hint {
  z-index: 2;
  animation: mg-mm-sparkle 0.7s ease-in-out infinite;
}

#mg-mm-app .mg-mm-card-hint::before,
#mg-mm-app .mg-mm-card-hint::after {
  position: absolute;
  z-index: 3;
  color: #f59e0b;
  font-size: clamp(0.85rem, 2vh, 1.2rem);
  line-height: 1;
  pointer-events: none;
  animation: mg-mm-twinkle 0.7s ease-in-out infinite;
}

#mg-mm-app .mg-mm-card-hint::before {
  content: "✦";
  top: 4px;
  right: 6px;
}

#mg-mm-app .mg-mm-card-hint::after {
  content: "✧";
  bottom: 4px;
  left: 6px;
}

#mg-mm-app .mg-mm-live {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

#mg-mm-app .mg-mm-modal,
#mg-mm-app .mg-mm-history-modal {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background: rgba(15, 23, 42, 0.35);
}

#mg-mm-app .mg-mm-history-modal {
  z-index: 40;
}

#mg-mm-app .mg-mm-modal[hidden],
#mg-mm-app .mg-mm-history-modal[hidden] {
  display: none;
}

#mg-mm-app .mg-mm-modal-card {
  width: min(440px, 100%);
  padding: 26px 22px 22px;
  text-align: center;
  background: #ffffff;
  border-radius: 28px;
  box-shadow: 0 18px 50px rgba(15, 23, 42, 0.2);
}

#mg-mm-app .mg-mm-modal-emoji {
  font-size: 3rem;
}

#mg-mm-app .mg-mm-modal-title {
  margin: 4px 0 0;
  font-family: 'Fredoka', 'Nunito', sans-serif;
  font-size: 2rem;
  color: #e11d48;
}

#mg-mm-app .mg-mm-modal-lead,
#mg-mm-app .mg-mm-result-line {
  margin: 6px 0;
  font-weight: 700;
  color: #475569;
}

#mg-mm-app .mg-mm-result-line strong {
  color: #0f172a;
  font-family: 'Fredoka', 'Nunito', sans-serif;
  font-size: 1.25rem;
}

#mg-mm-app .mg-mm-stars {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin: 10px 0 14px;
  font-size: 2.2rem;
}

#mg-mm-app .mg-mm-star {
  opacity: 0.28;
  filter: grayscale(1);
}

#mg-mm-app .mg-mm-star-on {
  opacity: 1;
  filter: none;
  animation: mg-mm-pop 0.45s cubic-bezier(0.34, 1.56, 0.64, 1);
}

#mg-mm-app .mg-mm-modal-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  margin-top: 16px;
}

#mg-mm-app .mg-mm-confetti {
  position: fixed;
  inset: 0;
  z-index: 25;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

#mg-mm-app .mg-mm-history-card {
  position: relative;
  width: min(720px, 100%);
  max-height: min(86vh, 720px);
  display: flex;
  flex-direction: column;
  padding: 22px 18px 16px;
  background: #ffffff;
  border-radius: 28px;
  box-shadow: 0 18px 50px rgba(15, 23, 42, 0.2);
}

#mg-mm-app .mg-mm-history-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 18px;
  background: #fff1f2;
  color: #e11d48;
  font-size: 1.2rem;
  font-weight: 700;
}

#mg-mm-app .mg-mm-history-title {
  margin: 0 48px 4px 0;
  font-family: 'Fredoka', 'Nunito', sans-serif;
  font-size: 1.7rem;
  color: #e11d48;
}

#mg-mm-app .mg-mm-history-note {
  margin: 0 0 12px;
  font-weight: 700;
  color: #64748b;
}

#mg-mm-app .mg-mm-history-list {
  overflow: auto;
  border-radius: 18px;
  background: #fffdf8;
}

#mg-mm-app .mg-mm-history-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
}

#mg-mm-app .mg-mm-history-table th,
#mg-mm-app .mg-mm-history-table td {
  padding: 10px 8px;
  text-align: left;
  border-bottom: 1px solid #fde68a;
}

#mg-mm-app .mg-mm-history-table th {
  position: sticky;
  top: 0;
  background: #fff7ed;
  color: #b45309;
}

#mg-mm-app .mg-mm-history-row:nth-child(even) {
  background: #fffbeb;
}

#mg-mm-app .mg-mm-history-empty {
  margin: 0;
  padding: 28px 12px;
  text-align: center;
  font-weight: 700;
  color: #64748b;
}

#mg-mm-app .mg-mm-history-clear {
  align-self: center;
  margin-top: 14px;
  min-height: 44px;
  padding: 0 16px;
  border: 1.5px solid #fecdd3;
  border-radius: 999px;
  background: #fff1f2;
  color: #e11d48;
  font-weight: 700;
}

@keyframes mg-mm-pop {
  0% { transform: scale(1); }
  45% { transform: scale(1.08); }
  100% { transform: scale(1); }
}

@keyframes mg-mm-sparkle {
  0%,
  100% { box-shadow: 0 0 0 3px #fde68a, 0 0 12px rgba(250, 204, 21, 0.85); }
  50% { box-shadow: 0 0 0 5px #fef3c7, 0 0 20px rgba(245, 158, 11, 0.95); }
}

@keyframes mg-mm-twinkle {
  0%,
  100% { transform: scale(0.8); opacity: 0.55; }
  50% { transform: scale(1.2); opacity: 1; }
}

@media (min-width: 640px) {
  #mg-mm-app .mg-mm-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (min-width: 768px) {
  #mg-mm-app .mg-mm-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

@media (max-width: 900px) {
  #mg-mm-app .mg-mm-lead {
    display: none;
  }

  #mg-mm-app .mg-mm-header {
    display: grid;
    grid-template-columns: auto auto minmax(0, 1fr);
    align-items: center;
    gap: 6px;
    padding: 8px;
  }

  #mg-mm-app .mg-mm-back {
    grid-column: 1 / -1;
    justify-self: start;
    min-height: 40px;
    padding: 0 12px;
  }

  #mg-mm-app .mg-mm-logo {
    width: 40px;
    height: 40px;
  }

  #mg-mm-app .mg-mm-brand {
    grid-column: 2 / -1;
    margin-right: 0;
  }

  #mg-mm-app .mg-mm-brand-en {
    font-size: 1.05rem;
  }

  #mg-mm-app .mg-mm-category-label {
    grid-column: 1 / -1;
  }

  #mg-mm-app .mg-mm-category {
    max-width: none;
    min-height: 40px;
  }

  #mg-mm-app .mg-mm-pill,
  #mg-mm-app .mg-mm-btn-history,
  #mg-mm-app .mg-mm-restart,
  #mg-mm-app .mg-mm-btn-bgm {
    min-height: 40px;
  }

  #mg-mm-app .mg-mm-pill {
    justify-self: start;
    width: auto;
  }

  #mg-mm-app .mg-mm-btn-bgm {
    width: 40px;
    height: 40px;
  }

  #mg-mm-app .mg-ctrl-actions {
    grid-column: 1 / -1;
  }
}

@media (max-height: 640px) {
  #mg-mm-app .mg-mm-lead {
    display: none;
  }

  #mg-mm-app .mg-mm-header {
    padding: 6px 8px;
    gap: 6px;
  }
}

@media (max-width: 768px) {
  #mg-mm-app .mg-mm-header {
    display: flex;
    flex-direction: column;
    flex-wrap: wrap;
    align-items: stretch;
    gap: 8px;
  }

  #mg-mm-app .mg-mm-category-label,
  #mg-mm-app .mg-mm-category,
  #mg-mm-app .mg-mm-restart,
  #mg-mm-app .mg-mm-play-again {
    width: 100%;
    max-width: 100%;
    min-width: 0;
  }

  #mg-mm-app .mg-mm-restart,
  #mg-mm-app .mg-mm-play-again {
    display: inline-flex;
    visibility: visible;
    justify-content: center;
  }

  #mg-mm-app .mg-mm-en,
  #mg-mm-app .mg-mm-th {
    overflow-wrap: anywhere;
    word-break: break-word;
    -webkit-line-clamp: 2;
    line-clamp: 2;
  }

  #mg-mm-app .mg-mm-en {
    font-size: clamp(0.62rem, 2.8vw, 0.9rem);
  }

  #mg-mm-app .mg-mm-th {
    font-size: clamp(0.55rem, 2.4vw, 0.75rem);
  }
}

@media (prefers-reduced-motion: reduce) {
  #mg-mm-app .mg-mm-card-inner,
  #mg-mm-app .mg-mm-pop,
  #mg-mm-app .mg-mm-card-hint,
  #mg-mm-app .mg-mm-card-hint::before,
  #mg-mm-app .mg-mm-card-hint::after,
  #mg-mm-app .mg-mm-star-on {
    animation: none;
    transition: none;
  }
}
