/* Word Search mini-game. Every rule is scoped to #mg-ws-app. */

#mg-ws-app,
#mg-ws-app * {
  box-sizing: border-box;
}

#mg-ws-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-ws-app .mg-ws-container {
  width: min(1180px, calc(100% - 24px));
  margin: 0 auto;
  padding: 16px 0 28px;
}

#mg-ws-app .mg-ws-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-ws-app .mg-ws-back,
#mg-ws-app .mg-ws-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-ws-app .mg-ws-back:hover,
#mg-ws-app .mg-ws-modal-home:hover {
  background: #fef3c7;
}

#mg-ws-app .mg-ws-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-ws-app .mg-ws-brand {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
  margin-right: auto;
}

#mg-ws-app .mg-ws-brand-th {
  font-weight: 700;
  color: #e11d48;
}

#mg-ws-app .mg-ws-brand-en {
  font-family: 'Fredoka', 'Nunito', sans-serif;
  font-size: 1.35rem;
  font-weight: 700;
  color: #1e293b;
}

#mg-ws-app .mg-ws-category-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  color: #475569;
}

#mg-ws-app .mg-ws-category {
  min-height: 44px;
  min-width: 160px;
  padding: 0 12px;
  border: 2px solid #e2e8f0;
  border-radius: 14px;
  background: #ffffff;
  color: #1e293b;
  font: inherit;
  font-weight: 700;
}

#mg-ws-app .mg-ws-pill {
  min-height: 44px;
  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-ws-app .mg-ws-timer {
  background: #fdf2f8;
  color: #be185d;
}

#mg-ws-app .mg-ws-icon-btn,
#mg-ws-app .mg-ws-restart,
#mg-ws-app .mg-ws-play-again,
#mg-ws-app .mg-ws-word-speak {
  font: inherit;
  cursor: pointer;
}

#mg-ws-app .mg-ws-icon-btn {
  width: 48px;
  height: 48px;
  border: none;
  border-radius: 16px;
  background: #ecfeff;
  font-size: 1.3rem;
}

#mg-ws-app .mg-ws-icon-btn[aria-pressed="true"] {
  background: #e2e8f0;
}

#mg-ws-app .mg-ws-restart,
#mg-ws-app .mg-ws-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-ws-app .mg-ws-restart:active,
#mg-ws-app .mg-ws-play-again:active {
  transform: translateY(2px);
  box-shadow: 0 2px 0 #e11d48;
}

#mg-ws-app .mg-ws-hint {
  margin: 14px 4px 12px;
  text-align: center;
  font-weight: 700;
  color: #64748b;
}

#mg-ws-app .mg-ws-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(250px, 340px);
  gap: 16px;
  align-items: start;
}

#mg-ws-app .mg-ws-board-wrap {
  display: flex;
  justify-content: center;
  overflow-x: auto;
  padding: 14px;
  background: rgba(255, 255, 255, 0.88);
  border-radius: 28px;
  box-shadow: 0 10px 24px rgba(80, 110, 150, 0.1);
}

#mg-ws-app .mg-ws-grid {
  position: relative;
  display: grid;
  grid-template-columns: repeat(var(--mg-ws-size, 8), clamp(46px, 6vw, 58px));
  gap: 4px;
  width: max-content;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

#mg-ws-app .mg-ws-line-layer {
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
}

#mg-ws-app .mg-ws-line {
  position: absolute;
  border-radius: 999px;
  opacity: 0.72;
}

#mg-ws-app .mg-ws-line-live {
  background: rgba(125, 211, 252, 0.95);
  opacity: 0.8;
  z-index: 3;
}

#mg-ws-app .mg-ws-line-bad {
  background: #fda4af;
  animation: mg-ws-shake 0.34s ease, mg-ws-fade 0.22s ease 0.34s forwards;
}

#mg-ws-app .mg-ws-cell {
  position: relative;
  z-index: 1;
  width: clamp(46px, 6vw, 58px);
  height: clamp(46px, 6vw, 58px);
  border: none;
  border-radius: 14px;
  background: #ffffff;
  box-shadow: inset 0 0 0 2px #e8eef6;
  color: #1e293b;
  font-family: 'Fredoka', 'Nunito', sans-serif;
  font-size: 1.35rem;
  font-weight: 700;
  line-height: 1;
  touch-action: none;
}

#mg-ws-app .mg-ws-cell-active {
  background: #e0f2fe;
  box-shadow: inset 0 0 0 2px #7dd3fc;
}

#mg-ws-app .mg-ws-cell-pop {
  animation: mg-ws-pop 0.42s cubic-bezier(0.34, 1.56, 0.64, 1);
}

#mg-ws-app .mg-ws-cell-hint {
  background: #fff3b0;
  box-shadow: 0 0 0 3px #facc15, 0 0 16px 4px rgba(250, 204, 21, 0.9);
  animation: mg-ws-hint-glow 0.7s ease-in-out infinite;
}

#mg-ws-app .mg-ws-line-hint {
  z-index: 4;
  opacity: 0.9;
  overflow: visible;
  background: linear-gradient(90deg, rgba(255, 196, 48, 0.25), rgba(255, 248, 190, 0.98) 50%, rgba(255, 196, 48, 0.25));
  box-shadow: 0 0 14px 5px rgba(250, 204, 21, 0.85);
  animation: mg-ws-hint-shimmer 0.55s linear infinite, mg-ws-hint-fade 0.45s ease 1.6s forwards;
}

#mg-ws-app .mg-ws-sparkle {
  position: absolute;
  top: 50%;
  font-size: 0.95rem;
  color: #fff7c2;
  text-shadow: 0 0 8px #f59e0b;
  animation: mg-ws-twinkle 0.7s ease-in-out infinite;
  pointer-events: none;
}

#mg-ws-app .mg-ws-cell:focus-visible,
#mg-ws-app .mg-ws-restart:focus-visible,
#mg-ws-app .mg-ws-play-again:focus-visible,
#mg-ws-app .mg-ws-back:focus-visible,
#mg-ws-app .mg-ws-icon-btn:focus-visible {
  outline: 3px solid #38bdf8;
  outline-offset: 2px;
}

#mg-ws-app .mg-ws-bank {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: min(78vh, 760px);
  overflow: auto;
  padding: 12px;
  background: rgba(255, 255, 255, 0.9);
  border-radius: 28px;
  box-shadow: 0 10px 24px rgba(80, 110, 150, 0.1);
}

#mg-ws-app .mg-ws-bank-title {
  margin: 4px 6px 2px;
  font-family: 'Fredoka', 'Nunito', sans-serif;
  font-size: 1.25rem;
  color: #0f172a;
}

#mg-ws-app .mg-ws-bank-note {
  margin: 0 6px 4px;
  color: #64748b;
  font-weight: 700;
  font-size: 0.92rem;
}

#mg-ws-app .mg-ws-word-card {
  display: grid;
  grid-template-columns: 64px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 8px;
  border-radius: 18px;
  background: #fffdfb;
  box-shadow: inset 0 0 0 2px #f1f5f9;
}

#mg-ws-app .mg-ws-word-card.mg-ws-found {
  background: #f8fafc;
}

#mg-ws-app .mg-ws-word-figure {
  width: 64px;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 16px;
  background: #fff7ed;
  overflow: hidden;
}

#mg-ws-app .mg-ws-word-image {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

#mg-ws-app .mg-ws-word-fallback {
  font-size: 1.8rem;
}

#mg-ws-app .mg-ws-word-copy {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

#mg-ws-app .mg-ws-word-title {
  display: flex;
  align-items: center;
  gap: 6px;
}

#mg-ws-app .mg-ws-word-en {
  font-family: 'Fredoka', 'Nunito', sans-serif;
  font-size: 1.15rem;
  font-weight: 700;
  color: #0f172a;
}

#mg-ws-app .mg-ws-word-th {
  color: #64748b;
  font-weight: 700;
}

#mg-ws-app .mg-ws-word-card.mg-ws-found .mg-ws-word-en {
  color: #94a3b8;
  text-decoration: line-through;
}

#mg-ws-app .mg-ws-word-check {
  font-size: 1.35rem;
}

#mg-ws-app .mg-ws-word-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

#mg-ws-app .mg-ws-hint-btn,
#mg-ws-app .mg-ws-word-speak {
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 14px;
  font-size: 1.15rem;
  cursor: pointer;
}

#mg-ws-app .mg-ws-hint-btn {
  background: linear-gradient(180deg, #fff6cc 0%, #ffd56a 100%);
  box-shadow: 0 3px 0 #f59e0b;
}

#mg-ws-app .mg-ws-hint-btn:disabled {
  opacity: 0.4;
  cursor: default;
  box-shadow: none;
}

#mg-ws-app .mg-ws-word-card.mg-ws-found .mg-ws-hint-btn {
  display: none;
}

#mg-ws-app .mg-ws-word-speak {
  background: #eff6ff;
}

#mg-ws-app .mg-ws-btn-bgm-off {
  background: #e2e8f0;
}

#mg-ws-app .mg-ws-empty {
  margin: 12px;
  font-weight: 700;
  color: #64748b;
}

#mg-ws-app .mg-ws-live {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

#mg-ws-app .mg-ws-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-ws-app .mg-ws-modal[hidden] {
  display: none;
}

#mg-ws-app .mg-ws-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-ws-app .mg-ws-modal-emoji {
  font-size: 3rem;
}

#mg-ws-app .mg-ws-modal-title {
  margin: 4px 0 0;
  font-family: 'Fredoka', 'Nunito', sans-serif;
  font-size: 2rem;
  color: #e11d48;
}

#mg-ws-app .mg-ws-modal-lead,
#mg-ws-app .mg-ws-result-line {
  margin: 6px 0;
  font-weight: 700;
  color: #475569;
}

#mg-ws-app .mg-ws-result-line strong {
  color: #0f172a;
  font-family: 'Fredoka', 'Nunito', sans-serif;
  font-size: 1.25rem;
}

#mg-ws-app .mg-ws-stars {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin: 10px 0 14px;
  font-size: 2.2rem;
}

#mg-ws-app .mg-ws-star {
  opacity: 0.28;
  filter: grayscale(1);
}

#mg-ws-app .mg-ws-star-on {
  opacity: 1;
  filter: none;
  animation: mg-ws-pop 0.45s cubic-bezier(0.34, 1.56, 0.64, 1);
}

#mg-ws-app .mg-ws-modal-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  margin-top: 16px;
}

#mg-ws-app .mg-ws-confetti {
  position: fixed;
  inset: 0;
  z-index: 25;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

@keyframes mg-ws-pop {
  0% { transform: scale(1); }
  45% { transform: scale(1.18); }
  100% { transform: scale(1); }
}

@keyframes mg-ws-shake {
  0%, 100% { margin-left: 0; }
  25% { margin-left: -8px; }
  75% { margin-left: 8px; }
}

@keyframes mg-ws-fade {
  to { opacity: 0; }
}

@keyframes mg-ws-hint-glow {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.08); }
}

@keyframes mg-ws-hint-shimmer {
  0% { filter: brightness(0.9); }
  50% { filter: brightness(1.45); }
  100% { filter: brightness(0.9); }
}

@keyframes mg-ws-hint-fade {
  to { opacity: 0; }
}

@keyframes mg-ws-twinkle {
  0%, 100% { opacity: 0.2; transform: translate(-50%, -50%) scale(0.6); }
  50% { opacity: 1; transform: translate(-50%, -50%) scale(1.3); }
}

@media (max-width: 520px) {
  #mg-ws-app .mg-ws-container {
    width: 100%;
    padding-left: 6px;
    padding-right: 6px;
  }

  #mg-ws-app .mg-ws-board-wrap {
    padding: 6px;
  }

  #mg-ws-app .mg-ws-grid {
    grid-template-columns: repeat(var(--mg-ws-size, 8), 44px);
    gap: 2px;
  }

  #mg-ws-app .mg-ws-cell {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    font-size: 1.15rem;
  }
}

@media (max-width: 860px) {
  #mg-ws-app .mg-ws-layout {
    grid-template-columns: 1fr;
  }

  #mg-ws-app .mg-ws-bank {
    max-height: none;
  }

  #mg-ws-app .mg-ws-brand {
    margin-right: 0;
  }
}

#mg-ws-app .mg-ws-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: inherit;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
}

#mg-ws-app .mg-ws-btn-history:hover {
  background: #e0f2fe;
}

#mg-ws-app .mg-ws-history-modal {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background: rgba(15, 23, 42, 0.35);
}

#mg-ws-app .mg-ws-history-modal[hidden] {
  display: none;
}

#mg-ws-app .mg-ws-history-card {
  position: relative;
  width: min(640px, 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-ws-app .mg-ws-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-ws-app .mg-ws-history-title {
  margin: 0 48px 4px 0;
  font-family: 'Fredoka', 'Nunito', sans-serif;
  font-size: 1.7rem;
  color: #e11d48;
}

#mg-ws-app .mg-ws-history-note {
  margin: 0 0 12px;
  font-weight: 700;
  color: #64748b;
}

#mg-ws-app .mg-ws-history-list {
  overflow: auto;
  border-radius: 16px;
  background: #fffdf8;
}

#mg-ws-app .mg-ws-history-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
}

#mg-ws-app .mg-ws-history-table th,
#mg-ws-app .mg-ws-history-table td {
  padding: 10px 8px;
  text-align: left;
  border-bottom: 1px solid #fde68a;
}

#mg-ws-app .mg-ws-history-table th {
  position: sticky;
  top: 0;
  background: #fff7ed;
  color: #b45309;
}

#mg-ws-app .mg-ws-history-row:nth-child(even) {
  background: #fffbeb;
}

#mg-ws-app .mg-ws-history-empty {
  margin: 18px 8px;
  text-align: center;
  font-weight: 700;
  color: #64748b;
}

#mg-ws-app .mg-ws-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;
}

@media (prefers-reduced-motion: reduce) {
  #mg-ws-app .mg-ws-cell-pop,
  #mg-ws-app .mg-ws-star-on,
  #mg-ws-app .mg-ws-line-bad,
  #mg-ws-app .mg-ws-cell-hint,
  #mg-ws-app .mg-ws-line-hint,
  #mg-ws-app .mg-ws-sparkle {
    animation: none;
  }
}
