/* Word Quiz. Every rule stays under #mg-wq-app. */

html:has(#mg-wq-app) {
  height: auto;
  min-height: 100%;
  overflow-x: hidden;
  overflow-y: auto;
}

#mg-wq-app,
#mg-wq-app * {
  box-sizing: border-box;
}

#mg-wq-app {
  margin: 0;
  height: auto;
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
  overflow-y: auto;
  padding-bottom: 5rem;
  color: #24324a;
  font-family: 'Mali', 'Nunito', 'Sarabun', sans-serif;
  background:
    radial-gradient(circle at 8% 12%, rgba(253, 224, 71, 0.45), transparent 26%),
    radial-gradient(circle at 92% 8%, rgba(244, 114, 182, 0.35), transparent 24%),
    radial-gradient(circle at 80% 92%, rgba(125, 211, 252, 0.45), transparent 28%),
    linear-gradient(180deg, #fff8ef 0%, #f4fbff 48%, #f7fff4 100%);
}

#mg-wq-app .mg-wq-container {
  width: min(1100px, calc(100% - 12px));
  height: auto;
  min-height: 100%;
  margin: 0 auto;
  padding: 8px 0 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 0;
}

#mg-wq-app .mg-wq-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.94);
  border-radius: 22px;
  box-shadow: 0 8px 22px rgba(120, 90, 60, 0.1);
}

#mg-wq-app .mg-wq-back,
#mg-wq-app .mg-wq-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-wq-app .mg-wq-back:hover,
#mg-wq-app .mg-wq-modal-home:hover {
  background: #fef3c7;
}

#mg-wq-app .mg-wq-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-wq-app .mg-wq-brand {
  display: flex;
  flex-direction: column;
  line-height: 1.1;
  margin-right: auto;
}

#mg-wq-app .mg-wq-brand-th {
  font-weight: 700;
  color: #e11d48;
}

#mg-wq-app .mg-wq-brand-en {
  font-family: 'Fredoka', 'Nunito', sans-serif;
  font-size: 1.15rem;
  font-weight: 700;
  color: #0f172a;
}

#mg-wq-app .mg-wq-category-label {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  font-weight: 700;
  color: #475569;
}

#mg-wq-app .mg-wq-category-label span {
  white-space: nowrap;
}

#mg-wq-app .mg-wq-category {
  flex: 1 1 140px;
  min-height: 44px;
  min-width: 0;
  width: 100%;
  max-width: 260px;
  padding: 0 10px;
  border: 2px solid #e2e8f0;
  border-radius: 14px;
  background: #ffffff;
  color: #1e293b;
  font: inherit;
  font-weight: 700;
}

#mg-wq-app .mg-wq-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.02rem;
  white-space: nowrap;
}

#mg-wq-app .mg-wq-score-pill {
  background: #ecfdf5;
  color: #047857;
}

#mg-wq-app .mg-wq-timer {
  background: #fdf2f8;
  color: #be185d;
}

#mg-wq-app .mg-wq-btn-bgm,
#mg-wq-app .mg-wq-restart,
#mg-wq-app .mg-wq-play-again,
#mg-wq-app .mg-wq-btn-hint,
#mg-wq-app .mg-wq-btn-history,
#mg-wq-app .mg-wq-speaker-btn,
#mg-wq-app .mg-wq-choice-btn,
#mg-wq-app .mg-wq-history-close,
#mg-wq-app .mg-wq-history-clear {
  font: inherit;
  cursor: pointer;
}

#mg-wq-app .mg-wq-btn-bgm {
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 18px;
  background: #ecfeff;
  font-size: 1.25rem;
}

#mg-wq-app .mg-wq-btn-bgm[aria-pressed="true"],
#mg-wq-app .mg-wq-btn-bgm-off {
  background: #e2e8f0;
}

#mg-wq-app .mg-wq-restart,
#mg-wq-app .mg-wq-play-again {
  min-height: 44px;
  padding: 0 14px;
  border: none;
  border-radius: 999px;
  color: #ffffff;
  font-weight: 700;
  background: linear-gradient(135deg, #7dd3fc 0%, #0284c7 100%);
  box-shadow: 0 4px 0 #0369a1;
}

#mg-wq-app .mg-wq-restart:active,
#mg-wq-app .mg-wq-play-again:active {
  transform: translateY(2px);
  box-shadow: 0 2px 0 #0369a1;
}

#mg-wq-app .mg-wq-btn-history {
  min-height: 44px;
  padding: 0 12px;
  border: 1.5px solid #ddd6fe;
  border-radius: 999px;
  background: #f5f3ff;
  color: #6d28d9;
  font-weight: 700;
}

#mg-wq-app .mg-wq-btn-hint {
  min-height: 44px;
  padding: 0 14px;
  border: none;
  border-radius: 999px;
  color: #7c2d12;
  font-weight: 700;
  background: linear-gradient(135deg, #fef3c7 0%, #fbbf24 100%);
  box-shadow: 0 4px 0 #d97706;
}

#mg-wq-app .mg-wq-btn-hint:disabled {
  opacity: 0.45;
  cursor: default;
  box-shadow: none;
}

#mg-wq-app .mg-wq-stage {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

#mg-wq-app .mg-wq-progress-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 0 0 auto;
  padding: 0 4px;
}

#mg-wq-app .mg-wq-progress-label {
  margin: 0;
  min-width: 92px;
  font-family: 'Fredoka', 'Nunito', sans-serif;
  font-weight: 700;
  font-size: 1.05rem;
  color: #0f172a;
}

#mg-wq-app .mg-wq-progress-track {
  flex: 1 1 auto;
  height: 16px;
  border-radius: 999px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.85);
  box-shadow: inset 0 2px 4px rgba(15, 23, 42, 0.08);
}

#mg-wq-app .mg-wq-progress-fill {
  display: block;
  width: 10%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #f9a8d4 0%, #fde68a 28%, #86efac 58%, #7dd3fc 78%, #c4b5fd 100%);
  transition: width 0.35s ease;
}

#mg-wq-app .mg-wq-question-card {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 8px 12px 6px;
  border-radius: 28px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow:
    0 12px 0 rgba(255, 255, 255, 0.45),
    0 16px 30px rgba(80, 100, 140, 0.12);
}

#mg-wq-app .mg-wq-visual {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: min(100%, 420px);
  min-height: 0;
}

#mg-wq-app .mg-wq-image {
  position: relative;
  z-index: 1;
  width: clamp(160px, 24vh, 220px);
  height: clamp(160px, 24vh, 220px);
  object-fit: contain;
  filter: drop-shadow(0 14px 12px rgba(15, 23, 42, 0.16));
  user-select: none;
  pointer-events: none;
}

#mg-wq-app .mg-wq-fallback {
  position: absolute;
  inset: 0;
  z-index: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: auto;
  height: auto;
  margin: 0;
  border-radius: 0;
  background: none;
  font-family: 'Fredoka', 'Nunito', sans-serif;
  font-size: 3rem;
  font-weight: 700;
  line-height: 1;
  color: #0369a1;
  opacity: 0.3;
  pointer-events: none;
}

#mg-wq-app .mg-wq-fallback-solo {
  position: relative;
  inset: auto;
  z-index: 1;
  width: clamp(160px, 24vh, 220px);
  height: clamp(160px, 24vh, 220px);
  border-radius: 28px;
  background: linear-gradient(160deg, #e0f2fe, #fce7f3);
  font-size: 4rem;
  opacity: 1;
}

@media (min-width: 768px) {
  #mg-wq-app .mg-wq-fallback {
    font-size: 8rem;
  }

  #mg-wq-app .mg-wq-fallback-solo {
    font-size: 4rem;
  }
}

#mg-wq-app .mg-wq-speaker-btn {
  position: absolute;
  z-index: 2;
  right: 0;
  bottom: 0;
  width: 72px;
  height: 72px;
  border: none;
  border-radius: 24px;
  background: linear-gradient(160deg, #fef08a 0%, #f59e0b 100%);
  box-shadow: 0 6px 0 #d97706, 0 10px 18px rgba(217, 119, 6, 0.28);
  font-size: 2rem;
  line-height: 1;
}

#mg-wq-app .mg-wq-speaker-btn:active {
  transform: translateY(3px);
  box-shadow: 0 3px 0 #d97706;
}

#mg-wq-app .mg-wq-speaker-pulse {
  animation: mg-wq-speaker 0.45s ease;
}

#mg-wq-app .mg-wq-thai {
  margin: 0;
  min-height: 1.4em;
  font-size: clamp(1.15rem, 2.4vh, 1.7rem);
  font-weight: 700;
  color: #9f1239;
  text-align: center;
}

#mg-wq-app .mg-wq-choices-grid {
  flex: 0 1 auto;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  min-height: 0;
}

#mg-wq-app .mg-wq-choice-btn {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: clamp(52px, 9vh, 78px);
  padding: 8px 16px;
  border: 3px solid #ffffff;
  border-radius: 22px;
  background: linear-gradient(180deg, #ffffff 0%, #f8fafc 100%);
  box-shadow: 0 6px 0 #cbd5e1, 0 10px 18px rgba(15, 23, 42, 0.08);
  color: #0f172a;
  font-family: 'Fredoka', 'Nunito', sans-serif;
  font-size: clamp(1.05rem, 2.2vh, 1.55rem);
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

#mg-wq-app .mg-wq-choice-btn:active:not(:disabled) {
  transform: translateY(3px);
  box-shadow: 0 3px 0 #cbd5e1;
}

#mg-wq-app .mg-wq-choice-btn:disabled {
  cursor: default;
}

#mg-wq-app .mg-wq-choice-mark {
  font-size: 1.3rem;
  line-height: 1;
}

#mg-wq-app .mg-wq-choice-right {
  color: #14532d;
  background: linear-gradient(180deg, #dcfce7 0%, #86efac 100%);
  border-color: #4ade80;
  box-shadow: 0 6px 0 #16a34a;
  animation: mg-wq-bounce 0.55s cubic-bezier(0.2, 1.4, 0.4, 1);
}

#mg-wq-app .mg-wq-choice-wrong {
  color: #9a3412;
  background: linear-gradient(180deg, #ffedd5 0%, #fdba74 100%);
  border-color: #fb923c;
  box-shadow: 0 6px 0 #ea580c;
  animation: mg-wq-wobble 0.5s ease;
}

#mg-wq-app .mg-wq-choice-gone {
  opacity: 0.12;
  pointer-events: none;
  transform: scale(0.92);
  filter: grayscale(1);
  transition: opacity 0.25s ease, transform 0.25s ease;
}

#mg-wq-app .mg-wq-live {
  position: fixed;
  top: 0;
  left: 0;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

#mg-wq-app .mg-wq-modal,
#mg-wq-app .mg-wq-history-modal {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(15, 23, 42, 0.45);
}

#mg-wq-app .mg-wq-modal[hidden],
#mg-wq-app .mg-wq-history-modal[hidden] {
  display: none !important;
}

#mg-wq-app .mg-wq-modal-card,
#mg-wq-app .mg-wq-history-card {
  width: min(460px, 100%);
  max-height: min(86dvh, 640px);
  padding: 22px 20px 18px;
  border-radius: 28px;
  background: #ffffff;
  box-shadow: 0 18px 50px rgba(15, 23, 42, 0.22);
  text-align: center;
  overflow: auto;
}

#mg-wq-app .mg-wq-modal-emoji {
  font-size: 3rem;
  line-height: 1;
}

#mg-wq-app .mg-wq-modal-title {
  margin: 4px 0 0;
  font-family: 'Fredoka', 'Nunito', sans-serif;
  font-size: 1.8rem;
  color: #0f172a;
}

#mg-wq-app .mg-wq-modal-lead,
#mg-wq-app .mg-wq-result-line {
  margin: 6px 0;
  font-weight: 700;
  color: #475569;
}

#mg-wq-app .mg-wq-stars {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin: 8px 0;
  font-size: 2rem;
}

#mg-wq-app .mg-wq-star {
  filter: grayscale(1);
  opacity: 0.4;
}

#mg-wq-app .mg-wq-star-on {
  filter: none;
  opacity: 1;
  animation: mg-wq-twinkle 0.6s ease-in-out infinite alternate;
}

#mg-wq-app .mg-wq-modal-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  margin-top: 12px;
}

#mg-wq-app .mg-wq-history-card {
  position: relative;
  text-align: left;
}

#mg-wq-app .mg-wq-history-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 50%;
  background: #f1f5f9;
  color: #334155;
  font-weight: 700;
}

#mg-wq-app .mg-wq-history-title {
  margin: 0 32px 0 0;
  font-family: 'Fredoka', 'Nunito', sans-serif;
  color: #0f172a;
}

#mg-wq-app .mg-wq-history-note {
  margin: 4px 0 10px;
  color: #64748b;
  font-weight: 700;
}

#mg-wq-app .mg-wq-history-list {
  overflow: auto;
  max-height: 46dvh;
}

#mg-wq-app .mg-wq-history-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}

#mg-wq-app .mg-wq-history-table th,
#mg-wq-app .mg-wq-history-table td {
  padding: 8px 6px;
  text-align: left;
  border-bottom: 1px solid #e2e8f0;
}

#mg-wq-app .mg-wq-history-table th {
  color: #0369a1;
}

#mg-wq-app .mg-wq-history-row:nth-child(even) {
  background: #f8fafc;
}

#mg-wq-app .mg-wq-history-empty {
  margin: 12px 0;
  font-weight: 700;
  color: #64748b;
}

#mg-wq-app .mg-wq-history-clear {
  margin-top: 12px;
  min-height: 40px;
  padding: 0 14px;
  border: 1.5px solid #fecaca;
  border-radius: 999px;
  background: #fff1f2;
  color: #be123c;
  font-weight: 700;
}

#mg-wq-app .mg-wq-confetti {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 85;
}

@keyframes mg-wq-bounce {
  0% { transform: translateY(0) scale(1); }
  35% { transform: translateY(-12px) scale(1.05); }
  60% { transform: translateY(2px) scale(0.98); }
  100% { transform: translateY(0) scale(1); }
}

@keyframes mg-wq-wobble {
  0%,
  100% { transform: translateX(0) rotate(0); }
  20% { transform: translateX(-8px) rotate(-3deg); }
  40% { transform: translateX(8px) rotate(3deg); }
  60% { transform: translateX(-6px) rotate(-2deg); }
  80% { transform: translateX(6px) rotate(2deg); }
}

@keyframes mg-wq-speaker {
  0% { transform: scale(1); }
  40% { transform: scale(1.1); }
  100% { transform: scale(1); }
}

@keyframes mg-wq-twinkle {
  from { transform: scale(0.85); }
  to { transform: scale(1.15); }
}

@media (max-width: 900px) {
  #mg-wq-app .mg-wq-header {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto auto;
    align-items: center;
    gap: 6px;
    padding: 8px;
  }

  #mg-wq-app .mg-wq-back,
  #mg-wq-app .mg-wq-category-label,
  #mg-wq-app .mg-ctrl-actions {
    grid-column: 1 / -1;
  }

  #mg-wq-app .mg-wq-back {
    justify-self: start;
    min-height: 40px;
  }

  #mg-wq-app .mg-wq-logo {
    width: 40px;
    height: 40px;
  }

  #mg-wq-app .mg-wq-brand {
    margin-right: 0;
  }

  #mg-wq-app .mg-wq-brand-en {
    font-size: 1rem;
  }

  #mg-wq-app .mg-wq-category {
    max-width: none;
  }

  #mg-wq-app .mg-wq-speaker-btn {
    width: 64px;
    height: 64px;
    font-size: 1.7rem;
  }
}

@media (max-width: 520px) {
  #mg-wq-app .mg-wq-choices-grid {
    grid-template-columns: 1fr;
    gap: 6px;
  }

  #mg-wq-app .mg-wq-choice-btn {
    min-height: 46px;
    border-radius: 16px;
  }

  #mg-wq-app .mg-wq-image,
  #mg-wq-app .mg-wq-fallback-solo {
    width: clamp(120px, 18vh, 160px);
    height: clamp(120px, 18vh, 160px);
  }

  #mg-wq-app .mg-ctrl-pause-title {
    max-width: 28vw;
    font-size: 0.78rem;
  }

  #mg-wq-app .mg-ctrl-pause-resume,
  #mg-wq-app .mg-ctrl-pause-home {
    min-height: 36px;
    padding: 0 10px;
    font-size: 0.82rem;
  }
}

@media (max-height: 760px) {
  #mg-wq-app .mg-wq-header {
    gap: 4px 8px;
    padding: 6px 8px;
  }

  #mg-wq-app .mg-wq-back,
  #mg-wq-app .mg-wq-category,
  #mg-wq-app .mg-wq-pill,
  #mg-wq-app .mg-wq-btn-history,
  #mg-wq-app .mg-wq-restart,
  #mg-wq-app .mg-wq-btn-hint,
  #mg-wq-app .mg-ctrl-btn-state {
    min-height: 36px;
  }

  #mg-wq-app .mg-wq-logo {
    width: 34px;
    height: 34px;
  }

  #mg-wq-app .mg-wq-image,
  #mg-wq-app .mg-wq-fallback-solo {
    width: clamp(140px, 20vh, 180px);
    height: clamp(140px, 20vh, 180px);
  }

  #mg-wq-app .mg-wq-speaker-btn {
    width: 56px;
    height: 56px;
    font-size: 1.5rem;
    border-radius: 18px;
  }

  #mg-wq-app .mg-wq-question-card {
    padding: 4px 8px;
    border-radius: 20px;
  }

  #mg-wq-app .mg-wq-thai {
    font-size: 1.05rem;
  }
}

@media (max-height: 640px) and (max-width: 520px) {
  #mg-wq-app .mg-wq-brand-th,
  #mg-wq-app .mg-wq-category-label span {
    display: none;
  }

  #mg-wq-app .mg-wq-image,
  #mg-wq-app .mg-wq-fallback-solo {
    width: 112px;
    height: 112px;
  }

  #mg-wq-app .mg-wq-choice-btn {
    min-height: 40px;
    font-size: 0.95rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  #mg-wq-app .mg-wq-choice-right,
  #mg-wq-app .mg-wq-choice-wrong,
  #mg-wq-app .mg-wq-speaker-pulse,
  #mg-wq-app .mg-wq-star-on,
  #mg-wq-app .mg-wq-progress-fill {
    animation: none;
    transition: none;
  }
}

@media (max-width: 768px) {
  #mg-wq-app .mg-wq-header {
    display: flex;
    flex-direction: column;
    flex-wrap: wrap;
    align-items: stretch;
    gap: 8px;
    width: 100%;
    max-width: 100%;
  }

  #mg-wq-app .mg-wq-category,
  #mg-wq-app .mg-wq-restart,
  #mg-wq-app select {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    box-sizing: border-box;
  }

  #mg-wq-app .mg-wq-restart {
    display: inline-flex;
    visibility: visible;
    justify-content: center;
  }
}
