/* Word Train mini-game. Every rule is scoped to #mg-wt-app. */

#mg-wt-app,
#mg-wt-app * {
  box-sizing: border-box;
}

#mg-wt-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-wt-app .mg-wt-container {
  width: min(1100px, calc(100% - 24px));
  margin: 0 auto;
  padding: 16px 0 32px;
}

#mg-wt-app .mg-wt-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-wt-app .mg-wt-back,
#mg-wt-app .mg-wt-modal-home {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 52px;
  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-wt-app .mg-wt-back:hover,
#mg-wt-app .mg-wt-modal-home:hover {
  background: #fef3c7;
}

#mg-wt-app .mg-wt-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-wt-app .mg-wt-brand {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
  margin-right: auto;
}

#mg-wt-app .mg-wt-brand-th {
  font-weight: 700;
  color: #e11d48;
}

#mg-wt-app .mg-wt-brand-en {
  font-family: 'Fredoka', 'Nunito', sans-serif;
  font-size: 1.35rem;
  font-weight: 700;
  color: #1e293b;
}

#mg-wt-app .mg-wt-category-label {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  font-weight: 700;
  color: #475569;
}

#mg-wt-app .mg-wt-category-label span {
  white-space: nowrap;
}

#mg-wt-app .mg-wt-category {
  flex: 1 1 140px;
  min-height: 52px;
  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-wt-app .mg-wt-pill {
  min-height: 52px;
  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-wt-app .mg-wt-timer {
  background: #fdf2f8;
  color: #be185d;
}

#mg-wt-app .mg-wt-btn-bgm,
#mg-wt-app .mg-wt-restart,
#mg-wt-app .mg-wt-play-again,
#mg-wt-app .mg-wt-btn-hint,
#mg-wt-app .mg-wt-btn-history,
#mg-wt-app .mg-wt-carriage,
#mg-wt-app .mg-wt-history-close,
#mg-wt-app .mg-wt-history-clear {
  font: inherit;
  cursor: pointer;
}

#mg-wt-app .mg-wt-btn-bgm {
  width: 52px;
  height: 52px;
  border: none;
  border-radius: 16px;
  background: #ecfeff;
  font-size: 1.3rem;
}

#mg-wt-app .mg-wt-btn-bgm[aria-pressed="true"],
#mg-wt-app .mg-wt-btn-bgm-off {
  background: #e2e8f0;
}

#mg-wt-app .mg-wt-restart,
#mg-wt-app .mg-wt-play-again {
  min-height: 52px;
  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-wt-app .mg-wt-restart:active,
#mg-wt-app .mg-wt-play-again:active {
  transform: translateY(2px);
  box-shadow: 0 2px 0 #e11d48;
}

#mg-wt-app .mg-wt-btn-history {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 52px;
  padding: 0 14px;
  border: 1.5px solid #bae6fd;
  border-radius: 999px;
  background: #f0f9ff;
  color: #0369a1;
  font-size: 0.95rem;
  font-weight: 700;
}

#mg-wt-app .mg-wt-btn-history:hover {
  background: #e0f2fe;
}

#mg-wt-app .mg-wt-lead {
  margin: 14px 4px 8px;
  text-align: center;
  font-weight: 700;
  color: #64748b;
}

#mg-wt-app .mg-wt-toolbar {
  display: flex;
  justify-content: center;
  margin-bottom: 12px;
}

#mg-wt-app .mg-wt-btn-hint {
  min-height: 52px;
  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-wt-app .mg-wt-btn-hint:active {
  transform: translateY(2px);
  box-shadow: 0 2px 0 #e0a100;
}

#mg-wt-app .mg-wt-btn-hint:disabled {
  cursor: default;
  opacity: 0.55;
  transform: none;
  box-shadow: none;
}

#mg-wt-app .mg-wt-stage {
  padding: 16px 14px 18px;
  background: rgba(255, 255, 255, 0.9);
  border-radius: 28px;
  box-shadow: 0 10px 24px rgba(80, 110, 150, 0.1);
}

#mg-wt-app .mg-wt-prompt {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  min-height: 132px;
  padding: 8px;
}

#mg-wt-app .mg-wt-picture-wrap {
  width: 128px;
  height: 128px;
  display: grid;
  place-items: center;
  border-radius: 28px;
  background: linear-gradient(180deg, #fff7ed 0%, #f0f9ff 100%);
  box-shadow: inset 0 0 0 3px #fff, 0 8px 18px rgba(80, 110, 150, 0.12);
  overflow: hidden;
}

#mg-wt-app .mg-wt-picture {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

#mg-wt-app .mg-wt-picture-fallback {
  font-size: 3rem;
}

#mg-wt-app .mg-wt-clue {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

#mg-wt-app .mg-wt-clue-label {
  font-size: 0.95rem;
  font-weight: 700;
  color: #64748b;
}

#mg-wt-app .mg-wt-thai {
  margin: 0;
  font-size: clamp(1.6rem, 4vw, 2.3rem);
  font-weight: 700;
  color: #be185d;
  line-height: 1.2;
}

#mg-wt-app .mg-wt-empty {
  margin: 0;
  font-weight: 700;
  color: #64748b;
  text-align: center;
}

#mg-wt-app .mg-wt-track {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 10px 12px;
  margin: 4px 0 10px;
}

#mg-wt-app .mg-wt-track-label {
  margin: 0;
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  padding: 0 12px;
  border-radius: 999px;
  background: #fff7ed;
  color: #c2410c;
  font-weight: 700;
}

#mg-wt-app .mg-wt-stations {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
}

#mg-wt-app .mg-wt-station {
  width: 28px;
  height: 28px;
  display: inline-grid;
  place-items: center;
  border-radius: 50%;
  background: #e2e8f0;
  color: #64748b;
  font-family: 'Fredoka', 'Nunito', sans-serif;
  font-size: 0.85rem;
  font-weight: 700;
}

#mg-wt-app .mg-wt-station-done {
  background: #86efac;
  color: #14532d;
}

#mg-wt-app .mg-wt-station-now {
  background: #fb7185;
  color: #ffffff;
  box-shadow: 0 0 0 3px #fecdd3;
}

#mg-wt-app .mg-wt-rail {
  position: relative;
  min-height: 0;
  overflow: visible;
  border-radius: 24px;
  touch-action: pan-y;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  background: linear-gradient(180deg, #e0f6ff 0%, #dff6ea 62%, #d6b48a 62%, #c4a574 100%);
}

#mg-wt-app .mg-wt-viewport {
  position: relative;
  z-index: 1;
  overflow-x: auto;
  overflow-y: visible;
  min-height: 0;
  max-width: 100%;
  touch-action: pan-x pan-y;
  scrollbar-width: none;
}

#mg-wt-app .mg-wt-viewport::-webkit-scrollbar {
  display: none;
}

#mg-wt-app .mg-wt-rail-bed {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 18px;
  height: 10px;
  background:
    linear-gradient(#94a3b8, #94a3b8) center / 100% 4px no-repeat,
    repeating-linear-gradient(90deg, transparent 0 18px, #a16207 18px 28px, transparent 28px 46px);
  pointer-events: none;
}

#mg-wt-app .mg-wt-train {
  position: relative;
  z-index: 1;
  min-height: 168px;
  touch-action: none;
}

#mg-wt-app .mg-wt-train-body {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: center;
  gap: 10px;
  width: 100%;
  max-width: 100%;
  padding: 16px 18px 36px;
  touch-action: manipulation;
  transform-origin: left bottom;
}

#mg-wt-app .mg-wt-arrive {
  animation: mg-wt-train-arrive 0.72s cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

#mg-wt-app .mg-wt-depart {
  animation: mg-wt-train-depart 0.86s ease-in forwards;
}

#mg-wt-app .mg-wt-engine {
  position: relative;
  width: 108px;
  height: 96px;
  flex: 0 0 108px;
}

#mg-wt-app .mg-wt-smoke {
  position: absolute;
  top: 0;
  left: 62px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.92);
  animation: mg-wt-smoke 1.5s ease-out infinite;
}

#mg-wt-app .mg-wt-smoke-2 {
  animation-delay: 0.45s;
}

#mg-wt-app .mg-wt-smoke-3 {
  animation-delay: 0.9s;
}

#mg-wt-app .mg-wt-chimney {
  position: absolute;
  top: 18px;
  left: 58px;
  width: 16px;
  height: 22px;
  border-radius: 4px 4px 0 0;
  background: #475569;
}

#mg-wt-app .mg-wt-boiler {
  position: absolute;
  left: 28px;
  bottom: 16px;
  width: 78px;
  height: 42px;
  border-radius: 22px 8px 8px 22px;
  background: linear-gradient(180deg, #fb7185 0%, #e11d48 100%);
  box-shadow: inset 0 4px 0 rgba(255, 255, 255, 0.28);
}

#mg-wt-app .mg-wt-cab {
  position: absolute;
  left: 0;
  bottom: 22px;
  width: 46px;
  height: 52px;
  border-radius: 12px 12px 6px 6px;
  background: linear-gradient(180deg, #38bdf8 0%, #0284c7 100%);
}

#mg-wt-app .mg-wt-window {
  position: absolute;
  top: 8px;
  left: 8px;
  width: 30px;
  height: 22px;
  border-radius: 8px;
  background: #fff7ed;
  color: #0f172a;
  font-size: 0.72rem;
  display: grid;
  place-items: center;
}

#mg-wt-app .mg-wt-engine-wheel {
  position: absolute;
  bottom: 2px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background:
    radial-gradient(circle at center, #f8fafc 0 4px, transparent 5px),
    #1e293b;
  border: 3px solid #cbd5e1;
}

#mg-wt-app .mg-wt-engine-wheel-front {
  left: 8px;
}

#mg-wt-app .mg-wt-engine-wheel-back {
  left: 62px;
}

#mg-wt-app .mg-wt-carriages {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: center;
  gap: 8px;
  min-width: 0;
  max-width: 100%;
  flex: 1 1 auto;
  touch-action: manipulation;
}

#mg-wt-app .mg-wt-carriage {
  position: relative;
  display: grid;
  place-items: center;
  width: clamp(32px, 12vw, 82px);
  max-width: 82px;
  height: auto;
  aspect-ratio: 3 / 4;
  min-width: 32px;
  flex: 1 1 clamp(32px, 12vw, 72px);
  padding: 0 0 8px;
  border: 3px solid rgba(255, 255, 255, 0.85);
  border-radius: 18px 18px 12px 12px;
  background: var(--mg-wt-paint, #ffe08a);
  color: #1e3a5f;
  font-family: 'Fredoka', 'Nunito', sans-serif;
  font-size: clamp(1rem, 4.4vw, 2.35rem);
  font-weight: 700;
  letter-spacing: 0.02em;
  box-shadow: 0 6px 0 rgba(30, 58, 95, 0.12);
  touch-action: manipulation;
}

#mg-wt-app .mg-wt-letter {
  position: relative;
  z-index: 1;
  line-height: 1;
}

#mg-wt-app .mg-wt-carriage:disabled {
  cursor: default;
}

#mg-wt-app .mg-wt-wheel {
  position: absolute;
  bottom: -12px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background:
    radial-gradient(circle at center, #f8fafc 0 3px, transparent 4px),
    #1e293b;
  border: 3px solid #e2e8f0;
  pointer-events: none;
}

#mg-wt-app .mg-wt-wheel-left {
  left: 8px;
}

#mg-wt-app .mg-wt-wheel-right {
  right: 8px;
}

#mg-wt-app .mg-wt-carriage-active {
  transform: translateY(-8px);
  box-shadow:
    0 0 0 4px #7dd3fc,
    0 0 18px rgba(56, 189, 248, 0.85),
    0 10px 0 rgba(30, 58, 95, 0.08);
}

#mg-wt-app .mg-wt-drop {
  outline: 3px dashed #0284c7;
  outline-offset: 3px;
}

#mg-wt-app .mg-wt-dragging {
  z-index: 5;
  pointer-events: none;
  filter: drop-shadow(0 12px 8px rgba(30, 58, 95, 0.28));
}

#mg-wt-app .mg-wt-carriage-hint {
  z-index: 2;
  animation: mg-wt-sparkle 0.7s ease-in-out infinite;
}

#mg-wt-app .mg-wt-carriage-hint::before,
#mg-wt-app .mg-wt-carriage-hint::after {
  content: '✦';
  position: absolute;
  color: #f59e0b;
  font-size: 1.1rem;
  text-shadow: 0 0 8px #fde68a;
  animation: mg-wt-twinkle 0.45s ease-in-out infinite;
  pointer-events: none;
}

#mg-wt-app .mg-wt-carriage-hint::before {
  top: -10px;
  right: 4px;
}

#mg-wt-app .mg-wt-carriage-hint::after {
  top: 6px;
  left: -6px;
  animation-delay: 0.2s;
}

#mg-wt-app .mg-wt-solved .mg-wt-carriage,
#mg-wt-app .mg-wt-carriage-correct {
  background: #b7f5cc;
  color: #14532d;
  animation: mg-wt-bounce 0.62s cubic-bezier(0.34, 1.4, 0.64, 1);
}

#mg-wt-app .mg-wt-live {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

#mg-wt-app .mg-wt-modal,
#mg-wt-app .mg-wt-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-wt-app .mg-wt-history-modal {
  z-index: 40;
}

#mg-wt-app .mg-wt-modal[hidden],
#mg-wt-app .mg-wt-history-modal[hidden] {
  display: none;
}

#mg-wt-app .mg-wt-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-wt-app .mg-wt-modal-emoji {
  font-size: 3rem;
}

#mg-wt-app .mg-wt-modal-title {
  margin: 4px 0 0;
  font-family: 'Fredoka', 'Nunito', sans-serif;
  font-size: 2rem;
  color: #e11d48;
}

#mg-wt-app .mg-wt-modal-lead,
#mg-wt-app .mg-wt-result-line {
  margin: 6px 0;
  font-weight: 700;
  color: #475569;
}

#mg-wt-app .mg-wt-result-line strong {
  color: #0f172a;
  font-family: 'Fredoka', 'Nunito', sans-serif;
  font-size: 1.25rem;
}

#mg-wt-app .mg-wt-stars {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin: 10px 0 14px;
  font-size: 2.2rem;
}

#mg-wt-app .mg-wt-star {
  opacity: 0.28;
  filter: grayscale(1);
}

#mg-wt-app .mg-wt-star-on {
  opacity: 1;
  filter: none;
  animation: mg-wt-pop 0.45s cubic-bezier(0.34, 1.56, 0.64, 1);
}

#mg-wt-app .mg-wt-modal-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  margin-top: 16px;
}

#mg-wt-app .mg-wt-confetti {
  position: fixed;
  inset: 0;
  z-index: 25;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

#mg-wt-app .mg-wt-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-wt-app .mg-wt-history-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 52px;
  height: 52px;
  border: none;
  border-radius: 16px;
  background: #fff1f2;
  color: #e11d48;
  font-size: 1.3rem;
  font-weight: 700;
}

#mg-wt-app .mg-wt-history-title {
  margin: 0 52px 4px 0;
  font-family: 'Fredoka', 'Nunito', sans-serif;
  font-size: 1.7rem;
  color: #e11d48;
}

#mg-wt-app .mg-wt-history-note {
  margin: 0 0 12px;
  font-weight: 700;
  color: #64748b;
}

#mg-wt-app .mg-wt-history-list {
  overflow: auto;
  border-radius: 16px;
  background: #fffdf8;
}

#mg-wt-app .mg-wt-history-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
}

#mg-wt-app .mg-wt-history-table th,
#mg-wt-app .mg-wt-history-table td {
  padding: 10px 8px;
  text-align: left;
  border-bottom: 1px solid #fde68a;
}

#mg-wt-app .mg-wt-history-table th {
  position: sticky;
  top: 0;
  background: #fff7ed;
  color: #b45309;
}

#mg-wt-app .mg-wt-history-row:nth-child(even) {
  background: #fffbeb;
}

#mg-wt-app .mg-wt-history-empty {
  margin: 18px 8px;
  text-align: center;
  font-weight: 700;
  color: #64748b;
}

#mg-wt-app .mg-wt-history-clear {
  align-self: center;
  min-height: 52px;
  margin-top: 14px;
  padding: 0 16px;
  border: none;
  border-radius: 999px;
  background: #fee2e2;
  color: #b91c1c;
  font-weight: 700;
}

@keyframes mg-wt-train-depart {
  from { transform: translateX(0); }
  to { transform: translateX(120%); }
}

@keyframes mg-wt-train-arrive {
  from { transform: translateX(-115%); }
  to { transform: translateX(0); }
}

@keyframes mg-wt-smoke {
  0% { transform: translate(0, 8px) scale(0.5); opacity: 0; }
  25% { opacity: 0.9; }
  100% { transform: translate(-6px, -28px) scale(1.35); opacity: 0; }
}

@keyframes mg-wt-bounce {
  0%, 100% { transform: translateY(0); }
  40% { transform: translateY(-18px); }
  70% { transform: translateY(-6px); }
}

@keyframes mg-wt-sparkle {
  0%, 100% {
    box-shadow:
      0 0 0 4px rgba(253, 224, 71, 0.95),
      0 0 18px 4px rgba(245, 158, 11, 0.85);
  }
  50% {
    box-shadow:
      0 0 0 7px rgba(254, 240, 138, 0.7),
      0 0 26px 8px rgba(251, 191, 36, 0.95);
  }
}

@keyframes mg-wt-twinkle {
  0%, 100% { opacity: 0.25; transform: scale(0.8); }
  50% { opacity: 1; transform: scale(1.2); }
}

@keyframes mg-wt-pop {
  0% { transform: scale(1); }
  45% { transform: scale(1.08); }
  100% { transform: scale(1); }
}

@media (max-width: 720px) {
  #mg-wt-app .mg-wt-container {
    width: 100%;
    padding-left: 8px;
    padding-right: 8px;
  }

  #mg-wt-app .mg-wt-brand {
    margin-right: 0;
  }

  #mg-wt-app .mg-wt-prompt {
    flex-direction: column;
    text-align: center;
  }

  #mg-wt-app .mg-wt-engine {
    width: 78px;
    flex-basis: 78px;
    transform: scale(0.72);
    transform-origin: left bottom;
  }

  #mg-wt-app .mg-wt-train-body {
    gap: 6px;
    padding-left: 10px;
    padding-right: 10px;
    flex-wrap: wrap;
    width: 100%;
    max-width: 100%;
  }

  #mg-wt-app .mg-wt-carriages {
    flex-wrap: wrap;
    max-width: 100%;
    justify-content: center;
  }

  #mg-wt-app .mg-wt-carriage {
    width: clamp(28px, 14vw, 52px);
    max-width: 52px;
    flex-basis: clamp(28px, 14vw, 52px);
    font-size: clamp(0.95rem, 4vw, 1.4rem);
  }
}

@media (prefers-reduced-motion: reduce) {
  #mg-wt-app .mg-wt-arrive,
  #mg-wt-app .mg-wt-depart,
  #mg-wt-app .mg-wt-smoke,
  #mg-wt-app .mg-wt-carriage-hint,
  #mg-wt-app .mg-wt-carriage-hint::before,
  #mg-wt-app .mg-wt-carriage-hint::after,
  #mg-wt-app .mg-wt-solved .mg-wt-carriage,
  #mg-wt-app .mg-wt-carriage-correct,
  #mg-wt-app .mg-wt-star-on {
    animation: none;
  }
}
