/* Word Matching mini-game. Every rule is scoped to #mg-wm-app. */

#mg-wm-app,
#mg-wm-app * {
  box-sizing: border-box;
}

#mg-wm-app {
  margin: 0;
  min-height: 100vh;
  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-wm-app .mg-wm-container {
  width: min(1100px, calc(100% - 24px));
  margin: 0 auto;
  padding: 16px 0 32px;
}

#mg-wm-app .mg-wm-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 12px;
  padding: 10px 14px;
  background: rgba(255, 255, 255, 0.92);
  border-radius: 24px;
  box-shadow: 0 8px 22px rgba(80, 110, 150, 0.12);
}

#mg-wm-app .mg-wm-back,
#mg-wm-app .mg-wm-modal-home {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 0 16px;
  border-radius: 999px;
  border: 1.5px solid #fde68a;
  background: #fffbeb;
  color: #b45309;
  font-weight: 700;
  font-size: 1rem;
  text-decoration: none;
}

#mg-wm-app .mg-wm-back:hover,
#mg-wm-app .mg-wm-modal-home:hover {
  background: #fef3c7;
}

#mg-wm-app .mg-wm-logo {
  width: 52px;
  height: 52px;
  object-fit: contain;
  border-radius: 14px;
  background: #ffffff;
  box-shadow: 0 3px 10px rgba(60, 90, 130, 0.16);
}

#mg-wm-app .mg-wm-brand {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
  margin-right: auto;
}

#mg-wm-app .mg-wm-brand-th {
  font-weight: 700;
  color: #e11d48;
}

#mg-wm-app .mg-wm-brand-en {
  font-family: 'Fredoka', 'Nunito', sans-serif;
  font-size: 1.35rem;
  font-weight: 700;
  color: #1e293b;
}

#mg-wm-app .mg-wm-category-label {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  font-weight: 700;
  color: #475569;
}

#mg-wm-app .mg-wm-category-label span {
  white-space: nowrap;
}

#mg-wm-app .mg-wm-category {
  flex: 1 1 140px;
  min-height: 48px;
  min-width: 0;
  width: 100%;
  max-width: 280px;
  padding: 0 12px;
  border: 2px solid #e2e8f0;
  border-radius: 14px;
  background: #ffffff;
  color: #1e293b;
  font: inherit;
  font-weight: 700;
}

#mg-wm-app .mg-wm-pill {
  min-height: 48px;
  display: inline-flex;
  align-items: center;
  padding: 0 14px;
  border-radius: 999px;
  background: #eff6ff;
  color: #1d4ed8;
  font-family: 'Fredoka', 'Nunito', sans-serif;
  font-weight: 700;
  font-size: 1.15rem;
}

#mg-wm-app .mg-wm-timer {
  background: #fdf2f8;
  color: #be185d;
}

#mg-wm-app .mg-wm-btn-bgm,
#mg-wm-app .mg-wm-restart,
#mg-wm-app .mg-wm-play-again,
#mg-wm-app .mg-wm-btn-hint,
#mg-wm-app .mg-wm-btn-history,
#mg-wm-app .mg-wm-card {
  font: inherit;
  cursor: pointer;
}

#mg-wm-app .mg-wm-btn-bgm {
  width: 48px;
  height: 48px;
  border: none;
  border-radius: 16px;
  background: #ecfeff;
  font-size: 1.3rem;
}

#mg-wm-app .mg-wm-btn-bgm[aria-pressed="true"],
#mg-wm-app .mg-wm-btn-bgm-off {
  background: #e2e8f0;
}

#mg-wm-app .mg-wm-restart,
#mg-wm-app .mg-wm-play-again {
  min-height: 48px;
  padding: 0 16px;
  border: none;
  border-radius: 999px;
  color: #ffffff;
  font-weight: 700;
  background: linear-gradient(135deg, #ff7b90 0%, #ff4d6d 100%);
  box-shadow: 0 4px 0 #e11d48;
}

#mg-wm-app .mg-wm-restart:active,
#mg-wm-app .mg-wm-play-again:active {
  transform: translateY(2px);
  box-shadow: 0 2px 0 #e11d48;
}

#mg-wm-app .mg-wm-btn-history {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 0 14px;
  border: 1.5px solid #bae6fd;
  border-radius: 999px;
  background: #f0f9ff;
  color: #0369a1;
  font-size: 0.95rem;
  font-weight: 700;
}

#mg-wm-app .mg-wm-btn-history:hover {
  background: #e0f2fe;
}

#mg-wm-app .mg-wm-lead {
  margin: 14px 4px 8px;
  text-align: center;
  font-weight: 700;
  color: #64748b;
}

#mg-wm-app .mg-wm-toolbar {
  display: flex;
  justify-content: center;
  margin-bottom: 12px;
}

#mg-wm-app .mg-wm-btn-hint {
  min-height: 48px;
  padding: 0 18px;
  border: none;
  border-radius: 999px;
  background: linear-gradient(135deg, #ffe082 0%, #ffc107 100%);
  color: #7c4a03;
  font-weight: 700;
  font-size: 1.05rem;
  box-shadow: 0 4px 0 #e0a100;
}

#mg-wm-app .mg-wm-btn-hint:active {
  transform: translateY(2px);
  box-shadow: 0 2px 0 #e0a100;
}

#mg-wm-app .mg-wm-btn-hint:disabled {
  cursor: default;
  opacity: 0.55;
  transform: none;
  box-shadow: none;
}

#mg-wm-app .mg-wm-board {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  column-gap: clamp(64px, 9vw, 96px);
  align-items: start;
  padding: 16px 12px 18px;
  background: rgba(255, 255, 255, 0.88);
  border-radius: 28px;
  box-shadow: 0 10px 24px rgba(80, 110, 150, 0.1);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

#mg-wm-app .mg-wm-svg-layer {
  position: absolute;
  inset: 0;
  z-index: 4;
  width: 100%;
  height: 100%;
  overflow: visible;
  pointer-events: none;
}

#mg-wm-app .mg-wm-col {
  position: relative;
  z-index: 2;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
}

#mg-wm-app .mg-wm-card {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  width: 100%;
  min-height: 92px;
  margin: 0;
  padding: 10px 18px;
  border: 3px solid transparent;
  border-radius: 22px;
  appearance: none;
  -webkit-appearance: none;
  background: #ffffff;
  box-shadow: 0 6px 0 rgba(148, 163, 184, 0.28);
  touch-action: none;
}

#mg-wm-app .mg-wm-card-picture {
  padding-right: 30px;
  background: linear-gradient(180deg, #ffffff 0%, #f8fbff 100%);
}

#mg-wm-app .mg-wm-card-word {
  padding-left: 30px;
  background: linear-gradient(180deg, #ffffff 0%, #fffafc 100%);
}

#mg-wm-app .mg-wm-card:focus-visible,
#mg-wm-app .mg-wm-btn-bgm:focus-visible,
#mg-wm-app .mg-wm-btn-hint:focus-visible,
#mg-wm-app .mg-wm-btn-history:focus-visible,
#mg-wm-app .mg-wm-restart:focus-visible,
#mg-wm-app .mg-wm-play-again:focus-visible,
#mg-wm-app .mg-wm-back:focus-visible,
#mg-wm-app .mg-wm-modal-home:focus-visible {
  outline: 3px solid #38bdf8;
  outline-offset: 2px;
}

#mg-wm-app .mg-wm-image {
  width: 76px;
  height: 76px;
  object-fit: contain;
  pointer-events: none;
}

#mg-wm-app .mg-wm-fallback {
  display: grid;
  place-items: center;
  width: 76px;
  height: 76px;
  border-radius: 18px;
  background: #fff4d6;
  font-size: 2rem;
}

#mg-wm-app .mg-wm-fallback[hidden],
#mg-wm-app .mg-wm-image[hidden] {
  display: none;
}

#mg-wm-app .mg-wm-en {
  font-family: 'Fredoka', 'Nunito', sans-serif;
  font-size: clamp(1.15rem, 2.6vw, 1.7rem);
  font-weight: 700;
  line-height: 1.15;
  color: #1e293b;
  overflow-wrap: anywhere;
}

#mg-wm-app .mg-wm-th {
  font-size: 0.95rem;
  font-weight: 700;
  color: #64748b;
  overflow-wrap: anywhere;
}

#mg-wm-app .mg-wm-dot {
  position: absolute;
  top: 50%;
  z-index: 3;
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  margin: 0;
  padding: 0;
  border-radius: 50%;
}

#mg-wm-app .mg-wm-dot-right {
  right: 0;
  transform: translate(50%, -50%);
}

#mg-wm-app .mg-wm-dot-left {
  left: 0;
  transform: translate(-50%, -50%);
}

#mg-wm-app .mg-wm-dot-core {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #ffffff;
  border: 4px solid #7dd3fc;
  box-shadow: 0 2px 0 rgba(14, 116, 144, 0.18);
}

#mg-wm-app .mg-wm-active {
  border-color: #facc15;
  box-shadow:
    0 0 0 4px rgba(250, 204, 21, 0.45),
    0 8px 18px rgba(250, 204, 21, 0.28);
}

#mg-wm-app .mg-wm-target {
  border-color: #7dd3fc;
  box-shadow: 0 0 0 4px rgba(125, 211, 252, 0.45);
}

#mg-wm-app .mg-wm-matched {
  border-color: var(--mg-wm-pair, #5dcaa5);
  box-shadow:
    0 6px 0 rgba(148, 163, 184, 0.18),
    0 0 0 4px color-mix(in srgb, var(--mg-wm-pair, #5dcaa5) 42%, white);
}

#mg-wm-app .mg-wm-matched .mg-wm-dot-core {
  border-color: var(--mg-wm-pair, #5dcaa5);
  background: color-mix(in srgb, var(--mg-wm-pair, #5dcaa5) 35%, white);
}

#mg-wm-app .mg-wm-card:disabled {
  cursor: default;
  opacity: 1;
}

#mg-wm-app .mg-wm-pop {
  animation: mg-wm-pop 0.48s cubic-bezier(0.34, 1.56, 0.64, 1);
}

#mg-wm-app .mg-wm-nudge {
  animation: mg-wm-shake 0.35s ease;
}

#mg-wm-app .mg-wm-line-locked {
  stroke-linecap: round;
  stroke-width: 8;
  filter: drop-shadow(0 1px 0 #ffffff) drop-shadow(0 2px 2px rgba(15, 23, 42, 0.12));
}

#mg-wm-app .mg-wm-line-rubber {
  stroke: #7dd3fc;
  stroke-linecap: round;
  stroke-width: 7;
  stroke-dasharray: 10 8;
}

#mg-wm-app .mg-wm-line-bad {
  stroke-linecap: round;
  stroke-width: 8;
  animation: mg-wm-shake 0.4s ease, mg-wm-fade 0.35s ease 0.32s forwards;
}

#mg-wm-app .mg-wm-line-hint {
  stroke: #f6c445;
  stroke-linecap: round;
  stroke-width: 8;
  stroke-dasharray: 8 12;
  filter: drop-shadow(0 0 6px rgba(255, 214, 74, 0.95));
  animation: mg-wm-dash 0.55s linear infinite;
}

#mg-wm-app .mg-wm-spark {
  fill: #fff4b0;
  stroke: #f59e0b;
  stroke-width: 1;
  animation: mg-wm-twinkle 0.45s ease-in-out infinite;
}

#mg-wm-app .mg-wm-hint-fade {
  animation: mg-wm-fade 0.4s ease forwards;
}

#mg-wm-app .mg-wm-live {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

#mg-wm-app .mg-wm-modal,
#mg-wm-app .mg-wm-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-wm-app .mg-wm-history-modal {
  z-index: 40;
}

#mg-wm-app .mg-wm-modal[hidden],
#mg-wm-app .mg-wm-history-modal[hidden] {
  display: none;
}

#mg-wm-app .mg-wm-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-wm-app .mg-wm-modal-emoji {
  font-size: 3rem;
}

#mg-wm-app .mg-wm-modal-title {
  margin: 4px 0 0;
  font-family: 'Fredoka', 'Nunito', sans-serif;
  font-size: 2rem;
  color: #e11d48;
}

#mg-wm-app .mg-wm-modal-lead,
#mg-wm-app .mg-wm-result-line {
  margin: 6px 0;
  font-weight: 700;
  color: #475569;
}

#mg-wm-app .mg-wm-result-line strong {
  color: #0f172a;
  font-family: 'Fredoka', 'Nunito', sans-serif;
  font-size: 1.25rem;
}

#mg-wm-app .mg-wm-stars {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin: 10px 0 14px;
  font-size: 2.2rem;
}

#mg-wm-app .mg-wm-star {
  opacity: 0.28;
  filter: grayscale(1);
}

#mg-wm-app .mg-wm-star-on {
  opacity: 1;
  filter: none;
  animation: mg-wm-pop 0.45s cubic-bezier(0.34, 1.56, 0.64, 1);
}

#mg-wm-app .mg-wm-modal-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  margin-top: 16px;
}

#mg-wm-app .mg-wm-confetti {
  position: fixed;
  inset: 0;
  z-index: 25;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

#mg-wm-app .mg-wm-history-card {
  position: relative;
  width: min(680px, 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-wm-app .mg-wm-history-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 48px;
  height: 48px;
  border: none;
  border-radius: 16px;
  background: #fff1f2;
  color: #e11d48;
  font-size: 1.3rem;
  font-weight: 700;
  cursor: pointer;
}

#mg-wm-app .mg-wm-history-title {
  margin: 0 48px 4px 0;
  font-family: 'Fredoka', 'Nunito', sans-serif;
  font-size: 1.7rem;
  color: #e11d48;
}

#mg-wm-app .mg-wm-history-note {
  margin: 0 0 12px;
  font-weight: 700;
  color: #64748b;
}

#mg-wm-app .mg-wm-history-list {
  overflow: auto;
  border-radius: 16px;
  background: #fffdf8;
}

#mg-wm-app .mg-wm-history-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
}

#mg-wm-app .mg-wm-history-table th,
#mg-wm-app .mg-wm-history-table td {
  padding: 10px 8px;
  text-align: left;
  border-bottom: 1px solid #fde68a;
}

#mg-wm-app .mg-wm-history-table th {
  position: sticky;
  top: 0;
  background: #fff7ed;
  color: #b45309;
}

#mg-wm-app .mg-wm-history-row:nth-child(even) {
  background: #fffbeb;
}

#mg-wm-app .mg-wm-history-empty {
  margin: 18px 8px;
  text-align: center;
  font-weight: 700;
  color: #64748b;
}

#mg-wm-app .mg-wm-history-clear {
  align-self: center;
  min-height: 48px;
  margin-top: 14px;
  padding: 0 16px;
  border: none;
  border-radius: 999px;
  background: #fee2e2;
  color: #b91c1c;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

@keyframes mg-wm-pop {
  0% { transform: scale(1); }
  45% { transform: scale(1.08); }
  100% { transform: scale(1); }
}

@keyframes mg-wm-shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-7px); }
  75% { transform: translateX(7px); }
}

@keyframes mg-wm-fade {
  to { opacity: 0; }
}

@keyframes mg-wm-dash {
  to { stroke-dashoffset: -40; }
}

@keyframes mg-wm-twinkle {
  0%, 100% { opacity: 0.2; }
  50% { opacity: 1; }
}

@media (max-width: 720px) {
  #mg-wm-app .mg-wm-container {
    width: 100%;
    padding-left: 8px;
    padding-right: 8px;
  }

  #mg-wm-app .mg-wm-brand {
    margin-right: 0;
  }

  #mg-wm-app .mg-wm-board {
    column-gap: 60px;
    padding: 12px 6px 14px;
  }

  #mg-wm-app .mg-wm-col {
    gap: 8px;
  }

  #mg-wm-app .mg-wm-card {
    min-height: 76px;
    padding: 8px 16px;
  }

  #mg-wm-app .mg-wm-card-picture {
    padding-right: 26px;
  }

  #mg-wm-app .mg-wm-card-word {
    padding-left: 26px;
  }

  #mg-wm-app .mg-wm-image,
  #mg-wm-app .mg-wm-fallback {
    width: 56px;
    height: 56px;
  }
}

@media (prefers-reduced-motion: reduce) {
  #mg-wm-app .mg-wm-pop,
  #mg-wm-app .mg-wm-nudge,
  #mg-wm-app .mg-wm-star-on,
  #mg-wm-app .mg-wm-line-bad,
  #mg-wm-app .mg-wm-line-hint,
  #mg-wm-app .mg-wm-spark {
    animation: none;
  }
}
