/* ===================================================================
   Kids Vocabulary Learning Platform - Stylesheet
   Designed for Children & Teachers:
   Pastel tones, rounded shapes, playful bouncing, full responsive
   =================================================================== */

:root {
  /* Playful Pastel Palette */
  --bg-gradient: linear-gradient(135deg, #F3F7FA 0%, #FFF9F3 50%, #F5F3FF 100%);
  --text-main: #2D3748;
  --text-muted: #718096;
  --text-thai: #4A5568;

  --color-primary: #FF7B90;
  --color-primary-hover: #FF6077;
  --color-primary-light: #FFEBF0;
  
  --color-secondary: #4FB5FF;
  --color-secondary-hover: #32A2F3;
  --color-secondary-light: #EBF6FF;

  --color-accent: #FFB347;
  --color-accent-light: #FFF5E6;

  --color-success: #52C485;
  --color-success-light: #EBF9F1;

  --card-bg: #FFFFFF;
  --frame-bg: #FAFCFF;
  
  --shadow-sm: 0 4px 10px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 8px 24px rgba(60, 90, 130, 0.08);
  --shadow-lg: 0 16px 36px rgba(50, 80, 120, 0.12);
  --shadow-button: 0 6px 0 rgba(0, 0, 0, 0.08);

  --radius-sm: 12px;
  --radius-md: 20px;
  --radius-lg: 28px;
  --radius-pill: 9999px;

  --font-en: 'Fredoka', 'Quicksand', -apple-system, sans-serif;
  --font-th: 'Mali', 'Prompt', 'Kanit', sans-serif;
  --transition-bounce: all 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
  --transition-smooth: all 0.2s ease-in-out;
}

/* Base & Reset */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

[hidden],
.hidden {
  display: none !important;
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: var(--font-en);
  background: var(--bg-gradient);
  color: var(--text-main);
  min-height: 100vh;
  position: relative;
  overflow-x: hidden;
  line-height: 1.5;
}

/* Background floating decorations */
.bg-decorations {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  pointer-events: none;
  z-index: 0;
  overflow: hidden;
}

.decor-bubble {
  position: absolute;
  border-radius: 50%;
  filter: blur(40px);
  opacity: 0.35;
  animation: floatSlow 14s ease-in-out infinite alternate;
}

.bubble-1 {
  width: 320px;
  height: 320px;
  background: #FFD4DB;
  top: -80px;
  left: -60px;
}

.bubble-2 {
  width: 380px;
  height: 380px;
  background: #CDE8FE;
  top: 20%;
  right: -100px;
  animation-duration: 18s;
}

.bubble-3 {
  width: 300px;
  height: 300px;
  background: #D5F5E3;
  bottom: 5%;
  left: 10%;
  animation-duration: 16s;
}

.bubble-4 {
  width: 280px;
  height: 280px;
  background: #FFF3CD;
  bottom: -60px;
  right: 15%;
  animation-duration: 20s;
}

.decor-cloud, .decor-star {
  position: absolute;
  user-select: none;
  opacity: 0.6;
  animation: floatParticle 8s ease-in-out infinite alternate;
}

.cloud-1 { top: 7%; left: 8%; font-size: 2.2rem; }
.cloud-2 { top: 12%; right: 12%; font-size: 2.5rem; animation-delay: 2s; }
.star-1 { top: 22%; left: 22%; font-size: 1.6rem; animation-delay: 1.5s; }
.star-2 { top: 45%; right: 8%; font-size: 1.8rem; animation-delay: 3s; }
.star-3 { bottom: 15%; left: 5%; font-size: 2rem; animation-delay: 2.5s; }

@keyframes floatSlow {
  0% { transform: translateY(0) scale(1); }
  100% { transform: translateY(40px) scale(1.08); }
}

@keyframes floatParticle {
  0% { transform: translateY(0) rotate(0deg); }
  100% { transform: translateY(-20px) rotate(8deg); }
}

/* App Container */
.app-container {
  position: relative;
  z-index: 1;
  max-width: 1280px;
  margin: 0 auto;
  padding: 1.25rem 1.25rem 4rem;
}

/* Page transitions */
.page {
  animation: pageFadeIn 0.35s ease-out forwards;
}

.page.hidden {
  display: none !important;
}

/* View transitions (inside Page 1) */
.view {
  display: none;
  animation: pageFadeIn 0.35s ease-out forwards;
}

.view.active {
  display: block;
}

@keyframes pageFadeIn {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ===================================================================
   MAIN NAVIGATION BAR (Kid & Teacher Friendly)
   =================================================================== */

.main-navbar {
  position: sticky;
  top: 14px;
  z-index: 1000;
  margin-bottom: 2rem;
  transition: var(--transition-smooth);
}

.navbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.85rem;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 2px solid rgba(255, 255, 255, 0.85);
  border-radius: 28px;
  padding: 0.45rem 0.75rem 0.45rem 0.9rem;
  box-shadow: 0 10px 30px rgba(60, 90, 130, 0.08);
}

.main-navbar .nav-right {
  display: flex;
  flex-direction: column-reverse;
  align-items: flex-end;
  justify-content: center;
  gap: 0.28rem;
  margin-left: auto;
  min-width: 0;
  flex: 1 1 auto;
}

/* Brand */
.nav-brand {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  flex-shrink: 0;
  user-select: none;
  text-decoration: none;
  cursor: pointer;
}

.brand-avatar {
  width: 72px;
  height: 72px;
  border-radius: 18px;
  object-fit: contain;
  background: #FFFFFF;
  display: block;
  flex-shrink: 0;
  box-shadow: 0 4px 12px rgba(255, 123, 144, 0.28);
}

.brand-info {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  line-height: 1.1;
}

.brand-title {
  display: block;
  font-family: var(--font-th);
  font-size: 1.7rem;
  font-weight: 800;
  line-height: 1.15;
  white-space: nowrap;
  letter-spacing: -0.2px;
  background: linear-gradient(45deg, #FF4D6D 0%, #FF8A3D 52%, #F6B73C 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  color: transparent;
  filter: drop-shadow(0px 2px 2px rgba(0, 0, 0, 0.1));
}

.brand-accent {
  color: #FF5E7E;
}

.brand-tag {
  font-family: var(--font-en);
  font-size: 0.875rem;
  font-weight: 700;
  line-height: 1.2;
  color: #3b82f6;
  letter-spacing: 0.08em;
  text-align: left;
  white-space: nowrap;
}

/* Landing: scoped to .lp-landing. Logo is 40% above the previous 364px hero (510px). */
body:has(.lp-landing:not([hidden])) {
  overflow: hidden;
}

.lp-landing {
  position: fixed;
  inset: 0;
  z-index: 13000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(24px, env(safe-area-inset-top)) 20px max(24px, env(safe-area-inset-bottom));
  background: #FFF7FB;
  background-image: radial-gradient(circle at 50% 38%, #FFFFFF 0%, #FFE4F0 48%, #D4EFFF 100%);
}

.lp-landing[hidden] {
  display: none !important;
}

.lp-landing .lp-sparkles {
  position: absolute;
  left: 50%;
  top: 46%;
  width: min(680px, 96vw);
  height: min(680px, 78vh);
  transform: translate(-50%, -54%);
  pointer-events: none;
  overflow: visible;
}

.lp-landing .lp-sparkles span {
  position: absolute;
  width: 12px;
  height: 12px;
  opacity: 0;
  background: #FFE28A;
  clip-path: polygon(50% 0%, 62% 36%, 100% 50%, 62% 64%, 50% 100%, 38% 64%, 0% 50%, 38% 36%);
  animation: lp-sparkle 2.8s ease-in-out infinite;
}

.lp-landing .lp-sparkles span:nth-child(1) { top: 8%; left: 16%; animation-delay: 0s; }
.lp-landing .lp-sparkles span:nth-child(2) { top: 4%; left: 72%; width: 9px; height: 9px; background: #FF8FAB; animation-delay: 0.45s; }
.lp-landing .lp-sparkles span:nth-child(3) { top: 28%; left: 92%; background: #7DD3FC; animation-delay: 0.9s; }
.lp-landing .lp-sparkles span:nth-child(4) { top: 70%; left: 88%; width: 8px; height: 8px; background: #C4B5FD; animation-delay: 0.2s; }
.lp-landing .lp-sparkles span:nth-child(5) { top: 84%; left: 58%; background: #86EFAC; animation-delay: 1.2s; }
.lp-landing .lp-sparkles span:nth-child(6) { top: 74%; left: 8%; width: 10px; height: 10px; background: #F9A8D4; animation-delay: 0.7s; }
.lp-landing .lp-sparkles span:nth-child(7) { top: 34%; left: 2%; background: #FDE68A; animation-delay: 1.5s; }
.lp-landing .lp-sparkles span:nth-child(8) { top: 14%; left: 42%; width: 8px; height: 8px; background: #93C5FD; animation-delay: 1.85s; }

.lp-landing .lp-enter {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.1rem;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  border: none;
  background: transparent;
  cursor: pointer;
  font-family: var(--font-th);
}

.lp-landing .lp-logo {
  width: min(510px, 70vh, 92vw);
  height: auto;
  display: block;
  flex-shrink: 0;
  border-radius: 50%;
  filter: drop-shadow(0 18px 28px rgba(255, 123, 144, 0.35));
  animation: lp-logo-float 3.2s ease-in-out infinite;
}

.lp-landing .lp-copy {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.2rem;
  text-align: center;
}

.lp-landing .lp-welcome {
  font-family: var(--font-th);
  font-size: clamp(1.85rem, 4.6vw, 3.05rem);
  font-weight: 800;
  line-height: 1.35;
  letter-spacing: 0.2px;
  background: linear-gradient(90deg, #FF4D6D 0%, #FF8A3D 24%, #F6B73C 46%, #22C55E 68%, #2E9BFF 86%, #A855F7 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  color: transparent;
}

.lp-landing .lp-tag {
  font-family: var(--font-en);
  font-size: clamp(1.2rem, 2.6vw, 1.75rem);
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: #2E9BFF;
}

@keyframes lp-logo-float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-10px); }
}

@keyframes lp-sparkle {
  0%, 100% { opacity: 0; transform: scale(0.35) rotate(0deg); }
  45% { opacity: 0.95; transform: scale(1) rotate(18deg); }
  70% { opacity: 0.2; transform: scale(0.6) rotate(28deg); }
}

@media (prefers-reduced-motion: reduce) {
  .lp-landing .lp-logo,
  .lp-landing .lp-sparkles span {
    animation: none;
  }

  .lp-landing .lp-sparkles span {
    opacity: 0.75;
  }
}

.nav-burger {
  display: none;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 5px;
  width: 46px;
  height: 46px;
  border: 2px solid #FDE68A;
  border-radius: 16px;
  background: #FFFBEB;
  cursor: pointer;
  flex-shrink: 0;
}

.nav-burger-bar {
  display: block;
  width: 18px;
  height: 2px;
  border-radius: 999px;
  background: #B45309;
}

/* Nav Menu Tabs */
.nav-menu {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.35rem;
  flex-wrap: wrap;
  min-width: 0;
  max-width: 100%;
}

.main-navbar .hub-bgm-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 9999px;
  background: #f472b6;
  color: #ffffff;
  cursor: pointer;
  flex-shrink: 0;
  box-shadow: 0 4px 6px -1px rgba(244, 114, 182, 0.45), 0 2px 4px -2px rgba(0, 0, 0, 0.1);
}

.main-navbar .hub-bgm-toggle:hover {
  background: #ec4899;
}

.main-navbar .hub-bgm-toggle[aria-pressed="false"] {
  background: #fbcfe8;
  color: #9d174d;
  box-shadow: 0 3px 0 #f9a8d4;
}

.main-navbar .hub-bgm-icon {
  width: 22px;
  height: 22px;
  display: none;
}

.main-navbar .hub-bgm-toggle[aria-pressed="true"] .hub-bgm-icon-on,
.main-navbar .hub-bgm-toggle[aria-pressed="false"] .hub-bgm-icon-off {
  display: block;
}

.nav-tab {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.42rem 0.85rem;
  border-radius: var(--radius-pill);
  border: 2px solid transparent;
  background: transparent;
  color: #4A5568;
  font-family: var(--font-th);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition-bounce);
  user-select: none;
  outline: none;
  position: relative;
  white-space: nowrap;
}

.nav-tab .tab-icon {
  font-size: 1.25rem;
  transition: transform 0.25s ease;
}

.nav-tab:hover {
  background: #F0F7FF;
  color: #2F97FF;
  transform: translateY(-2px);
}

.nav-tab:hover .tab-icon {
  transform: scale(1.2) rotate(6deg);
}

.nav-tab:active {
  transform: translateY(1px);
}

/* Active Nav Tab */
.nav-tab.active {
  background: linear-gradient(135deg, #FF7B90 0%, #FF5E7E 100%);
  color: #FFFFFF;
  border-color: #FF7B90;
  box-shadow: 0 6px 16px rgba(255, 94, 126, 0.35);
  transform: scale(1.02);
}

.nav-tab.active .tab-icon {
  transform: scale(1.15);
}

.nav-tab.active:hover {
  color: #FFFFFF;
  background: linear-gradient(135deg, #FF6077 0%, #FF4D6D 100%);
}

.tab-pill {
  font-family: var(--font-en);
  font-size: 0.72rem;
  font-weight: 700;
  padding: 0.15rem 0.5rem;
  border-radius: var(--radius-pill);
  background: #EBF8FF;
  color: #0284C7;
  letter-spacing: 0.3px;
  line-height: 1.2;
}

.nav-tab.active .tab-pill {
  background: rgba(255, 255, 255, 0.3);
  color: #FFFFFF;
}

.tab-pill-soon {
  background: #FFF5F5;
  color: #E53E3E;
}

.nav-tab.active .tab-pill-soon {
  background: rgba(255, 255, 255, 0.35);
  color: #FFFFFF;
}

/* ===================================================================
   HOME VIEW STYLES
   =================================================================== */

.home-header {
  text-align: center;
  margin-bottom: 2.5rem;
  padding-top: 0.5rem;
}

.header-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: #FFF;
  color: #FF6B8B;
  font-weight: 600;
  font-size: 0.95rem;
  padding: 0.4rem 1.2rem;
  border-radius: var(--radius-pill);
  box-shadow: 0 4px 14px rgba(255, 107, 139, 0.15);
  margin-bottom: 0.8rem;
  border: 1.5px solid #FFE4EA;
}

.badge-icon {
  font-size: 1.1rem;
}

.app-title {
  font-size: clamp(2.6rem, 7vw, 4.2rem);
  font-weight: 700;
  letter-spacing: -0.5px;
  margin-bottom: 0.6rem;
  line-height: 1.1;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0.4rem 0.8rem;
}

.title-kids {
  color: #FF5E7E;
  text-shadow: 3px 3px 0 #FFE4EA, 5px 5px 0 rgba(255, 94, 126, 0.1);
  display: inline-block;
  transform: rotate(-2deg);
}

.title-vocab {
  color: #2F97FF;
  text-shadow: 3px 3px 0 #DFF0FF, 5px 5px 0 rgba(47, 151, 255, 0.1);
  display: inline-block;
  transform: rotate(2deg);
}

.title-sparkle {
  font-size: clamp(1.8rem, 4vw, 2.6rem);
  display: inline-block;
  animation: pulseRotate 3s infinite ease-in-out;
}

@keyframes pulseRotate {
  0%, 100% { transform: scale(1) rotate(0deg); }
  50% { transform: scale(1.25) rotate(15deg); }
}

.app-subtitle {
  font-family: var(--font-th);
  color: var(--text-thai);
  font-size: clamp(1rem, 2.5vw, 1.25rem);
  font-weight: 500;
  max-width: 680px;
  margin: 0 auto 1.6rem;
}

/* Stats and Search bar */
.search-and-stats {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  max-width: 580px;
  margin: 0 auto;
}

.category-stats-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(8px);
  padding: 0.5rem 1.4rem;
  border-radius: var(--radius-pill);
  box-shadow: var(--shadow-sm);
  font-family: var(--font-th);
  font-weight: 600;
  color: #4A5568;
  font-size: 0.98rem;
  border: 1px solid rgba(255, 255, 255, 0.8);
}

.stat-icon {
  font-size: 1.15rem;
}

.stat-dot {
  color: #CBD5E0;
}

.search-wrapper {
  position: relative;
  width: 100%;
}

.search-icon {
  position: absolute;
  left: 1.1rem;
  top: 50%;
  transform: translateY(-50%);
  font-size: 1.1rem;
  color: #A0AEC0;
  pointer-events: none;
}

#category-search {
  width: 100%;
  padding: 0.85rem 2.8rem 0.85rem 3rem;
  font-family: var(--font-th);
  font-size: 1.05rem;
  border-radius: var(--radius-pill);
  border: 2.5px solid #E2E8F0;
  background: #FFFFFF;
  color: var(--text-main);
  outline: none;
  box-shadow: var(--shadow-sm);
  transition: var(--transition-smooth);
}

#category-search:focus {
  border-color: #4FB5FF;
  box-shadow: 0 0 0 4px rgba(79, 181, 255, 0.2);
}

.search-clear-btn {
  position: absolute;
  right: 0.8rem;
  top: 50%;
  transform: translateY(-50%);
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: none;
  background: #E2E8F0;
  color: #718096;
  font-size: 1.1rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition-smooth);
}

.search-clear-btn:hover {
  background: #CBD5E0;
  color: #2D3748;
}

/* Loading & Error States */
.state-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 4rem 1.5rem;
  text-align: center;
  background: rgba(255, 255, 255, 0.75);
  backdrop-filter: blur(6px);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  max-width: 520px;
  margin: 2rem auto;
}

.bouncing-loader {
  display: flex;
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.bounce-dot {
  font-size: 2.4rem;
  animation: bounceDot 1.4s infinite ease-in-out both;
}

.dot-1 { animation-delay: -0.32s; }
.dot-2 { animation-delay: -0.16s; }
.dot-3 { animation-delay: 0s; }

@keyframes bounceDot {
  0%, 80%, 100% { transform: translateY(0) scale(0.9); }
  40% { transform: translateY(-24px) scale(1.15); }
}

.state-text {
  font-family: var(--font-th);
  font-size: 1.15rem;
  color: var(--text-thai);
  font-weight: 500;
}

.error-state {
  border: 2px dashed #FEB2B2;
  background: #FFF5F5;
}

.error-icon {
  font-size: 3.5rem;
  margin-bottom: 0.5rem;
}

.error-title {
  font-family: var(--font-th);
  color: #E53E3E;
  font-size: 1.4rem;
  margin-bottom: 0.5rem;
}

.empty-search-state {
  text-align: center;
  padding: 3rem 1.5rem;
  font-family: var(--font-th);
  color: var(--text-muted);
  font-size: 1.15rem;
}

.empty-icon {
  font-size: 2.8rem;
  display: block;
  margin-bottom: 0.5rem;
}

/* ===================================================================
   CATEGORY GRID & BUTTONS
   =================================================================== */

.category-section {
  margin-top: 2rem;
}

.category-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(215px, 1fr));
  gap: 1.35rem;
}

/* Category Card Button */
.category-card {
  position: relative;
  background: #FFFFFF;
  border-radius: var(--radius-md);
  padding: 1.4rem 1.2rem;
  border: 3px solid transparent;
  cursor: pointer;
  text-align: left;
  transition: var(--transition-bounce);
  box-shadow: var(--shadow-md);
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  overflow: hidden;
  user-select: none;
  outline: none;
}

.category-card:hover, .category-card:focus-visible {
  transform: translateY(-8px) scale(1.02);
  box-shadow: var(--shadow-lg);
  border-color: var(--cat-accent, #4FB5FF);
}

.category-card:active {
  transform: translateY(2px) scale(0.98);
  box-shadow: var(--shadow-sm);
}

/* Inner decorative accent corner */
.category-card::before {
  content: '';
  position: absolute;
  top: 0;
  right: 0;
  width: 70px;
  height: 70px;
  background: radial-gradient(circle, var(--cat-light, #EBF6FF) 0%, transparent 70%);
  border-top-right-radius: var(--radius-md);
  pointer-events: none;
}

.card-top-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.cat-icon-bubble {
  width: 52px;
  height: 52px;
  border-radius: 16px;
  background: var(--cat-light, #EBF6FF);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.85rem;
  box-shadow: inset 0 2px 4px rgba(255, 255, 255, 0.8), 0 3px 8px rgba(0, 0, 0, 0.05);
  transition: transform 0.3s ease;
}

.category-card:hover .cat-icon-bubble {
  transform: scale(1.15) rotate(6deg);
}

.cat-id-pill {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--cat-accent, #2F97FF);
  background: var(--cat-light, #EBF6FF);
  padding: 0.2rem 0.65rem;
  border-radius: var(--radius-pill);
  letter-spacing: 0.5px;
}

.cat-names {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.cat-name-en {
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--text-main);
  line-height: 1.2;
}

.cat-name-th {
  font-family: var(--font-th);
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--cat-accent, #4FB5FF);
}

.cat-footer {
  margin-top: auto;
  padding-top: 0.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-top: 1px dashed #EDF2F7;
  font-size: 0.85rem;
  gap: 0.4rem;
}

.cat-word-count {
  font-family: var(--font-th);
  color: var(--text-muted);
  font-weight: 500;
}

.cat-has-img-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.76rem;
  font-family: var(--font-th);
  font-weight: 600;
  padding: 0.15rem 0.55rem;
  border-radius: var(--radius-pill);
}

.badge-ready {
  background: #E6FFFA;
  color: #0D9488;
  border: 1px solid #B2F5EA;
}

.badge-waiting {
  background: #FFF5F5;
  color: #E53E3E;
  border: 1px solid #FED7D7;
}

.cat-play-hint {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--cat-light, #EBF6FF);
  color: var(--cat-accent, #2F97FF);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.85rem;
  transition: transform 0.2s ease;
}

.category-card:hover .cat-play-hint {
  transform: translateX(3px);
  background: var(--cat-accent, #2F97FF);
  color: #FFFFFF;
}

/* ===================================================================
   FLASHCARD VIEW STYLES
   =================================================================== */

#flashcard-view {
  max-width: 820px;
  margin: 0 auto;
}

.flashcard-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.75rem 1.4rem;
  font-family: var(--font-en);
  font-size: 1.05rem;
  font-weight: 600;
  border: none;
  border-radius: var(--radius-pill);
  cursor: pointer;
  transition: var(--transition-bounce);
  user-select: none;
  outline: none;
  text-decoration: none;
}

.btn-back {
  background: #FFFFFF;
  color: #4A5568;
  font-family: var(--font-th);
  font-weight: 600;
  font-size: 1rem;
  padding: 0.65rem 1.25rem;
  box-shadow: var(--shadow-sm);
  border: 2px solid #E2E8F0;
}

.btn-back:hover {
  background: #FFF5F7;
  border-color: #FF7B90;
  color: #FF5E7E;
  transform: translateY(-2px);
}

.btn-back:active {
  transform: translateY(1px);
}

.category-badge-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  background: #FFFFFF;
  padding: 0.55rem 1.2rem;
  border-radius: var(--radius-pill);
  box-shadow: var(--shadow-sm);
  font-family: var(--font-th);
  font-size: 1.05rem;
  font-weight: 600;
  border: 2px solid #E2E8F0;
}

.chip-icon {
  font-size: 1.3rem;
}

.chip-text {
  color: var(--text-main);
}

.card-counter-badge {
  background: #FFFFFF;
  padding: 0.55rem 1.1rem;
  border-radius: var(--radius-pill);
  box-shadow: var(--shadow-sm);
  font-family: var(--font-th);
  font-weight: 600;
  font-size: 0.98rem;
  color: #4A5568;
  border: 2px solid #E2E8F0;
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
}

.counter-current {
  font-size: 1.2rem;
  font-weight: 700;
  color: #FF5E7E;
}

.counter-slash {
  color: #A0AEC0;
}

.counter-total {
  color: #718096;
}

/* Progress bar */
.progress-bar-container {
  width: 100%;
  height: 8px;
  background: rgba(226, 232, 240, 0.7);
  border-radius: var(--radius-pill);
  overflow: hidden;
  margin-bottom: 1.75rem;
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.05);
}

.progress-bar {
  height: 100%;
  background: linear-gradient(90deg, #4FB5FF, #FF7B90);
  border-radius: var(--radius-pill);
  transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Flashcard Stage */
.flashcard-stage {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1.25rem;
  position: relative;
  margin-bottom: 1.75rem;
}

/* Side navigation buttons (Desktop) */
.btn-side-nav {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: 2.5px solid #FFFFFF;
  background: rgba(255, 255, 255, 0.95);
  box-shadow: var(--shadow-md);
  font-size: 2.2rem;
  color: #4A5568;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition-bounce);
  line-height: 1;
  flex-shrink: 0;
  user-select: none;
}

.btn-side-nav:hover:not(:disabled) {
  background: #FFFFFF;
  color: #2F97FF;
  transform: scale(1.12);
  box-shadow: var(--shadow-lg);
}

.btn-side-nav:active:not(:disabled) {
  transform: scale(0.95);
}

.btn-side-nav:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  transform: none;
}

/* The Main Flashcard Card */
.flashcard-card {
  width: 100%;
  max-width: 24rem;
  aspect-ratio: 3 / 4;
  height: auto;
  background: var(--card-bg);
  border-radius: var(--radius-lg);
  padding: 1.75rem 1.75rem 4.5rem;
  box-shadow: var(--shadow-lg);
  border: 3.5px solid #EBF3FA;
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
  transition: var(--transition-bounce);
}

.flashcard-card.card-animate-next {
  animation: slideNext 0.35s ease-out;
}

.flashcard-card.card-animate-prev {
  animation: slidePrev 0.35s ease-out;
}

@keyframes slideNext {
  0% { opacity: 0.3; transform: translateX(25px) scale(0.97); }
  100% { opacity: 1; transform: translateX(0) scale(1); }
}

@keyframes slidePrev {
  0% { opacity: 0.3; transform: translateX(-25px) scale(0.97); }
  100% { opacity: 1; transform: translateX(0) scale(1); }
}

.card-meta {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.card-id-badge {
  font-size: 0.9rem;
  font-weight: 700;
  color: #718096;
  background: #EDF2F7;
  padding: 0.25rem 0.75rem;
  border-radius: var(--radius-pill);
  letter-spacing: 0.5px;
}

.btn-icon-sound {
  position: absolute;
  right: 1rem;
  bottom: 1rem;
  z-index: 10;
  background: #FFF0F4;
  border: none;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  font-size: 1.25rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition-bounce);
  box-shadow: 0 2px 6px rgba(255, 123, 144, 0.2);
}

.btn-icon-sound:hover {
  background: #FFD4DB;
  transform: scale(1.15);
}

.btn-icon-sound:active {
  transform: scale(0.92);
}

/* Image Frame: Black and white line art stands out with clarity */
.flashcard-image-frame {
  width: 100%;
  flex: 1 1 auto;
  min-height: 160px;
  height: auto;
  background: var(--frame-bg);
  border-radius: var(--radius-md);
  border: 2.5px solid #E8EEF5;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  position: relative;
  box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.02);
  padding: 1.25rem;
}

.flashcard-image {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
  filter: contrast(105%) brightness(98%);
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  user-select: none;
  -webkit-user-drag: none;
}

.flashcard-image:hover {
  transform: scale(1.04);
}

/* Fallback state when image is not yet available */
.image-fallback {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  text-align: center;
  color: #A0AEC0;
}

.fallback-icon {
  font-size: 4rem;
  animation: gentlePulse 2s infinite ease-in-out;
}

@keyframes gentlePulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.1); }
}

.fallback-text {
  font-family: var(--font-th);
  font-size: 1.05rem;
  font-weight: 600;
  color: #718096;
}

.fallback-path {
  font-family: 'Consolas', monospace;
  font-size: 0.8rem;
  color: #A0AEC0;
  background: #EDF2F7;
  padding: 0.35rem 0.75rem;
  border-radius: var(--radius-pill);
  word-break: break-all;
  max-width: 90%;
}

/* Word Texts */
.flashcard-content {
  width: 100%;
  text-align: center;
  margin-top: 1.5rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
}

.word-en-wrapper {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  cursor: pointer;
  padding: 0.2rem 0.8rem;
  border-radius: var(--radius-md);
  transition: background 0.2s ease;
}

.word-en-wrapper:hover {
  background: #FFF5F7;
}

.word-en {
  font-size: clamp(2.2rem, 5.5vw, 3rem);
  font-weight: 700;
  color: #1A202C;
  letter-spacing: -0.5px;
  line-height: 1.15;
}

.btn-speak-inline {
  background: #FFEBF0;
  border: none;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  font-size: 1.25rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: #FF5E7E;
  transition: var(--transition-bounce);
  box-shadow: 0 3px 8px rgba(255, 94, 126, 0.2);
}

.btn-speak-inline:hover {
  background: #FF5E7E;
  color: #FFFFFF;
  transform: scale(1.18) rotate(-6deg);
}

.btn-speak-inline:active {
  transform: scale(0.92);
}

.word-th {
  font-family: var(--font-th);
  font-size: clamp(1.4rem, 3.5vw, 1.85rem);
  font-weight: 600;
  color: #4A5568;
}

/* ===================================================================
   FLASHCARD CONTROLS & NAV
   =================================================================== */

.flashcard-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  margin-bottom: 1.5rem;
  width: 100%;
}

.btn-control {
  min-height: 58px;
  padding: 0.8rem 1.75rem;
  border-radius: var(--radius-pill);
  box-shadow: var(--shadow-md);
  font-size: 1.1rem;
  letter-spacing: 0.2px;
}

/* Previous button */
.btn-prev {
  background: #FFFFFF;
  color: #4A5568;
  border: 2.5px solid #E2E8F0;
  flex: 1;
  max-width: 180px;
}

.btn-prev:hover:not(:disabled) {
  background: #F7FAFC;
  border-color: #CBD5E0;
  color: #2D3748;
  transform: translateY(-3px);
  box-shadow: var(--shadow-lg);
}

.btn-prev:active:not(:disabled) {
  transform: translateY(1px);
}

.btn-prev:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

/* Pronounce button */
.btn-pronounce {
  background: linear-gradient(135deg, #FFEBF0 0%, #FFF5E6 100%);
  color: #E53E3E;
  border: 2.5px solid #FFD4DB;
  font-family: var(--font-th);
  font-weight: 700;
  font-size: 1.1rem;
  padding: 0.8rem 1.6rem;
}

.btn-pronounce:hover {
  background: linear-gradient(135deg, #FFD4DB 0%, #FFE8CC 100%);
  transform: translateY(-3px) scale(1.03);
  box-shadow: 0 8px 20px rgba(229, 62, 62, 0.2);
}

.btn-pronounce:active {
  transform: translateY(1px);
}

.btn-sound-emoji {
  font-size: 1.3rem;
}

/* Next button */
.btn-next {
  background: linear-gradient(135deg, #4FB5FF 0%, #2F97FF 100%);
  color: #FFFFFF;
  border: 2.5px solid #2F97FF;
  flex: 1;
  max-width: 180px;
  box-shadow: 0 6px 16px rgba(47, 151, 255, 0.35);
}

.btn-next:hover:not(:disabled) {
  background: linear-gradient(135deg, #38A6F5 0%, #1A85ED 100%);
  transform: translateY(-3px);
  box-shadow: 0 10px 22px rgba(47, 151, 255, 0.45);
}

.btn-next:active:not(:disabled) {
  transform: translateY(1px);
}

.btn-next:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.btn-subtext {
  font-family: var(--font-th);
  font-size: 0.85rem;
  font-weight: 500;
  opacity: 0.85;
}

.btn-arrow {
  font-size: 0.9rem;
}

/* Dots slider */
.dots-slider-wrapper {
  width: 100%;
  display: flex;
  justify-content: center;
  margin-bottom: 1rem;
  overflow-x: auto;
  padding: 0.5rem 0.25rem;
  scrollbar-width: thin;
}

.dots-container {
  display: inline-flex;
  gap: 0.45rem;
  background: rgba(255, 255, 255, 0.7);
  padding: 0.45rem 0.8rem;
  border-radius: var(--radius-pill);
  box-shadow: var(--shadow-sm);
}

.nav-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: none;
  background: #CBD5E0;
  cursor: pointer;
  transition: var(--transition-bounce);
  padding: 0;
}

.nav-dot:hover {
  background: #A0AEC0;
  transform: scale(1.25);
}

.nav-dot.active {
  background: #FF5E7E;
  width: 26px;
  border-radius: var(--radius-pill);
  box-shadow: 0 2px 6px rgba(255, 94, 126, 0.35);
}

/* Keyboard guide */
.keyboard-guide {
  text-align: center;
  font-family: var(--font-th);
  font-size: 0.92rem;
  color: var(--text-muted);
}

.keyboard-guide strong {
  color: #4A5568;
}

/* ===================================================================
   PAGE 2: GENERATOR SECTION STYLES (Worksheet Generator)
   =================================================================== */

.page-header {
  text-align: center;
  margin-bottom: 2.75rem;
  padding-top: 0.5rem;
}

.badge-generator {
  background: #FFF9E6;
  color: #D97706;
  border-color: #FDE68A;
  box-shadow: 0 4px 14px rgba(217, 119, 6, 0.12);
}

#page-generator #generator-menu-view .gen-draft-banner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 14px 18px;
  margin: 0.25rem auto 1.5rem;
  max-width: 920px;
  padding: 16px 18px;
  background: linear-gradient(135deg, #FFF8E8 0%, #FFF0F5 100%);
  border: 3px dashed #F6C56B;
  border-radius: 22px;
  box-shadow: 0 8px 0 rgba(246, 197, 107, 0.28);
}

#page-generator #generator-menu-view .gen-draft-banner[hidden] {
  display: none;
}

#page-generator #generator-menu-view .gen-draft-text {
  margin: 0;
  color: #7C4A12;
  font-family: var(--font-th);
  font-size: 1.05rem;
  font-weight: 700;
  line-height: 1.55;
}

#page-generator #generator-menu-view .gen-draft-text strong {
  color: #E07A2F;
}

#page-generator #generator-menu-view .gen-draft-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

#page-generator #generator-menu-view .gen-draft-restore,
#page-generator #generator-menu-view .gen-draft-discard {
  border: none;
  border-radius: 999px;
  padding: 0.7rem 1.15rem;
  font-family: var(--font-th);
  font-size: 0.95rem;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.08);
}

#page-generator #generator-menu-view .gen-draft-restore {
  background: #52C485;
  color: #FFFFFF;
}

#page-generator #generator-menu-view .gen-draft-discard {
  background: #FFFFFF;
  color: #D4536A;
  border: 2px solid #FFC2CE;
}

#page-generator #generator-menu-view .gen-draft-restore:hover,
#page-generator #generator-menu-view .gen-draft-discard:hover {
  transform: translateY(-1px);
}

.page-title {
  font-size: clamp(2.2rem, 5.5vw, 3.4rem);
  font-weight: 700;
  letter-spacing: -0.5px;
  margin-bottom: 0.8rem;
  line-height: 1.2;
}

.page-subtitle {
  font-family: var(--font-th);
  color: var(--text-thai);
  font-size: clamp(1rem, 2.2vw, 1.2rem);
  font-weight: 500;
  max-width: 740px;
  margin: 0 auto;
  line-height: 1.6;
}

/* Generator Cards Grid */
.generator-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(290px, 1fr));
  gap: 1.6rem;
  margin-top: 1rem;
}

@media (min-width: 1280px) {
  #page-generator .generator-grid {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }
}

/* Generator Card */
.generator-card {
  background: #FFFFFF;
  border-radius: var(--radius-lg);
  padding: 1.85rem 1.6rem;
  border: 3.5px solid transparent;
  box-shadow: var(--shadow-md);
  position: relative;
  display: flex;
  flex-direction: column;
  transition: var(--transition-bounce);
  cursor: pointer;
  overflow: hidden;
}

.generator-card:hover {
  transform: translateY(-10px) scale(1.02);
  box-shadow: 0 20px 42px rgba(60, 90, 140, 0.14);
}

.generator-card:active {
  transform: translateY(-2px) scale(0.99);
}

#page-generator .generator-card.is-vip {
  background:
    linear-gradient(165deg, rgba(255, 248, 220, 0.95) 0%, rgba(255, 255, 255, 0.98) 42%, #fffdf8 100%);
  border-color: #f6d98a;
  box-shadow: 0 12px 28px rgba(180, 130, 32, 0.14);
}

#page-generator .generator-card.is-vip::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(115deg, transparent 30%, rgba(255, 228, 150, 0.45) 46%, transparent 62%);
  pointer-events: none;
}

#page-generator .generator-card .free-badge {
  position: absolute;
  top: 14px;
  right: 14px;
  z-index: 2;
  display: inline-flex;
  align-items: center;
  padding: 0.28rem 0.7rem;
  border-radius: var(--radius-pill);
  background: linear-gradient(135deg, #dcfce7 0%, #4ade80 55%, #16a34a 100%);
  color: #14532d;
  font-family: var(--font-th);
  font-size: 0.78rem;
  font-weight: 800;
  box-shadow: 0 4px 0 #15803d, 0 8px 16px rgba(22, 163, 74, 0.24);
}

#page-generator .generator-card .vip-badge {
  position: absolute;
  top: 14px;
  right: 14px;
  z-index: 2;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 0.28rem 0.7rem;
  border-radius: var(--radius-pill);
  background: linear-gradient(135deg, #fff4c2 0%, #f5c451 55%, #e8a317 100%);
  color: #7a4b08;
  font-family: var(--font-en);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.4px;
  box-shadow: 0 4px 0 #c9890d, 0 8px 16px rgba(201, 138, 16, 0.28);
}

#page-generator .gen-vip-modal {
  position: fixed;
  inset: 0;
  z-index: 1200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
}

#page-generator .gen-vip-modal[hidden] {
  display: none;
}

#page-generator .gen-vip-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(48, 32, 8, 0.48);
}

#page-generator .gen-vip-card {
  position: relative;
  z-index: 1;
  width: min(480px, 100%);
  padding: 28px 24px 22px;
  border-radius: 24px;
  background:
    linear-gradient(180deg, #fffaf0 0%, #ffffff 38%);
  border: 2px solid #f6d98a;
  box-shadow: 0 22px 50px rgba(72, 46, 8, 0.22);
  text-align: center;
}

#page-generator .gen-vip-kicker {
  margin: 0 0 8px;
  font-family: var(--font-en);
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.4px;
  color: #b7791f;
}

#page-generator .gen-vip-title {
  margin: 0 0 12px;
  font-family: var(--font-th);
  font-size: 1.45rem;
  line-height: 1.35;
  color: #7a4b08;
}

#page-generator .gen-vip-text {
  margin: 0;
  font-family: var(--font-th);
  font-size: 1.02rem;
  line-height: 1.6;
  color: #57534e;
}

#page-generator .gen-vip-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  margin-top: 20px;
}

#page-generator .gen-vip-contact,
#page-generator .gen-vip-close {
  border: none;
  cursor: pointer;
  font-family: var(--font-th);
  font-size: 0.98rem;
  font-weight: 800;
  text-decoration: none;
  border-radius: var(--radius-pill);
  padding: 0.72rem 1.1rem;
}

#page-generator .gen-vip-contact {
  color: #ffffff;
  background: linear-gradient(135deg, #22c55e 0%, #16a34a 45%, #d97706 100%);
  box-shadow: 0 4px 0 #166534;
}

#page-generator .gen-vip-close {
  color: #57534e;
  background: #f5f5f4;
}

.main-navbar .nav-vip-upgrade {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.4rem 0.85rem;
  border: 0;
  border-radius: var(--radius-pill);
  background: linear-gradient(135deg, #fff4c2 0%, #f5c451 55%, #e8a317 100%);
  color: #7a4b08;
  font-family: var(--font-th);
  font-size: 0.9rem;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 3px 0 #c9890d;
  white-space: nowrap;
  flex-shrink: 0;
}

.main-navbar .nav-vip-upgrade:hover {
  transform: translateY(-1px);
}

.main-navbar .bdd-nav-auth {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.4rem;
  flex-shrink: 0;
  flex-wrap: wrap;
  max-width: 100%;
}

.main-navbar .bdd-nav-share {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  flex-shrink: 0;
  min-height: 40px;
  border: 0;
  border-radius: 9999px;
  padding: 0.4rem 0.9rem;
  background: #f472b6;
  color: #ffffff;
  font-family: var(--font-th);
  font-size: 0.92rem;
  font-weight: 800;
  line-height: 1.2;
  cursor: pointer;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1);
  white-space: nowrap;
}

.main-navbar .bdd-nav-share:hover {
  background: #ec4899;
}

.main-navbar .bdd-nav-share-icon {
  width: 1.05rem;
  height: 1.05rem;
  flex-shrink: 0;
}

.main-navbar .bdd-nav-share-wrap {
  position: relative;
  flex-shrink: 0;
}

.main-navbar .bdd-nav-share-menu {
  position: absolute;
  top: calc(100% + 0.45rem);
  right: 0;
  z-index: 30;
  min-width: 220px;
  padding: 0.45rem;
  border: 2px solid #fbcfe8;
  border-radius: 1rem;
  background: #ffffff;
  box-shadow: 0 12px 28px rgba(244, 114, 182, 0.22);
}

.main-navbar .bdd-nav-share-line,
.main-navbar .bdd-nav-share-more {
  display: flex;
  width: 100%;
  align-items: center;
  gap: 0.5rem;
  border: 0;
  border-radius: 0.75rem;
  padding: 0.55rem 0.75rem;
  font-family: var(--font-th);
  font-size: 0.92rem;
  font-weight: 800;
  line-height: 1.2;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
}

.main-navbar .bdd-nav-share-line {
  color: #ffffff;
  background: #06c755;
}

.main-navbar .bdd-nav-share-line:hover {
  background: #05b34c;
}

.main-navbar .bdd-nav-share-more {
  margin-top: 0.35rem;
  color: #9d174d;
  background: #fce7f3;
}

.main-navbar .bdd-nav-share-more:hover {
  background: #fbcfe8;
}

.main-navbar .bdd-nav-auth:has(.bdd-nav-share-wrap.is-open) {
  overflow: visible;
  position: relative;
  z-index: 5;
}

.main-navbar .bdd-nav-user {
  display: inline-flex;
  align-items: center;
  gap: 0.28rem;
  max-width: min(16rem, 46vw);
  min-width: 0;
  color: #7a4b08;
  font-family: var(--font-th);
  font-size: 0.88rem;
  font-weight: 800;
}

.main-navbar .bdd-nav-user-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.main-navbar .bdd-nav-vip {
  flex: 0 0 auto;
  color: #c8960a;
  font-weight: 800;
  letter-spacing: 0.02em;
  text-shadow: 0 1px 0 #fff4c2;
}

.main-navbar .bdd-nav-user[hidden] {
  display: none !important;
}

.main-navbar .bdd-nav-login,
.main-navbar .bdd-nav-register,
.main-navbar .bdd-nav-logout {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 0.45rem 0.95rem;
  border-radius: var(--radius-pill);
  font-family: var(--font-th);
  font-size: 0.92rem;
  font-weight: 800;
  line-height: 1.2;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
}

.main-navbar .bdd-nav-login,
.main-navbar .bdd-nav-logout {
  border: 0;
  color: #fffaf0;
  background: linear-gradient(180deg, #e0892a 0%, #c2610c 100%);
  box-shadow: 0 3px 0 #9a4d0b;
}

.main-navbar .bdd-nav-login:hover,
.main-navbar .bdd-nav-logout:hover {
  transform: translateY(-1px);
}

.main-navbar .bdd-nav-register {
  border: 2px solid #f0c14b;
  color: #7a4b08;
  background: #fff8e8;
}

.main-navbar .bdd-nav-register:hover {
  background: #fff1c9;
}

.main-navbar .bdd-nav-login[hidden],
.main-navbar .bdd-nav-register[hidden],
.main-navbar .bdd-nav-logout[hidden] {
  display: none !important;
}

@media (max-width: 900px) {
  .main-navbar .navbar-inner {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    align-items: center;
    gap: 0.45rem;
  }

  .main-navbar .nav-burger {
    display: inline-flex;
    grid-column: 1;
    grid-row: 1;
  }

  .main-navbar .nav-brand {
    grid-column: 2;
    grid-row: 1;
    justify-content: flex-start;
    min-width: 0;
  }

  .main-navbar .nav-right {
    display: contents;
  }

  .main-navbar .bdd-nav-auth {
    grid-column: 1 / -1;
    grid-row: 2;
    align-self: center;
    justify-content: flex-start;
    flex-wrap: wrap;
    max-width: 100%;
    overflow-x: auto;
    padding-bottom: 2px;
  }

  .main-navbar .bdd-nav-share-menu {
    left: 0;
    right: auto;
  }

  .main-navbar .nav-menu {
    display: none;
    grid-column: 1 / -1;
    grid-row: 3;
    grid-template-columns: 1fr;
    width: 100%;
    max-width: 100%;
    max-height: min(70vh, 420px);
    overflow: auto;
  }

  .main-navbar .nav-menu.is-open {
    display: grid;
  }

  .main-navbar .nav-tab {
    width: 100%;
    justify-content: flex-start;
    white-space: normal;
  }

  .main-navbar .nav-vip-upgrade {
    width: auto;
    justify-content: center;
  }

  .main-navbar .bdd-nav-login,
  .main-navbar .bdd-nav-register,
  .main-navbar .bdd-nav-logout {
    min-height: 38px;
    padding: 0.38rem 0.7rem;
    font-size: 0.8rem;
  }
}

#page-vocab .bdd-value-banner,
#page-generator .bdd-value-banner,
#vip-upgrade .bdd-value-banner {
  margin: 1rem auto 0;
  max-width: 820px;
  padding: 0.9rem 1rem;
  border-radius: 18px;
  text-align: left;
  background: linear-gradient(180deg, #fff8dc 0%, #ffe8a3 100%);
  border: 2px solid #e8b931;
  box-shadow: 0 8px 20px rgba(180, 130, 32, 0.16);
}

#page-vocab .bdd-value-banner p,
#page-generator .bdd-value-banner p,
#vip-upgrade .bdd-value-banner p {
  margin: 0;
  color: #7a4b08;
  font-family: var(--font-th);
  font-weight: 700;
  line-height: 1.6;
}

#page-vocab .bdd-value-cta {
  margin-top: 0.75rem;
  border: 0;
  border-radius: var(--radius-pill);
  padding: 0.55rem 1rem;
  background: linear-gradient(135deg, #7a4b08 0%, #b7791f 100%);
  color: #fffaf0;
  font-family: var(--font-th);
  font-weight: 800;
  cursor: pointer;
}

#vip-upgrade {
  position: fixed;
  inset: 0;
  z-index: 14000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
}

#vip-upgrade[hidden],
#vip-upgrade .vip-chat-actions[hidden],
#vip-upgrade .vip-login-btn[hidden] {
  display: none;
}

#vip-upgrade .vip-upgrade-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(48, 32, 8, 0.55);
}

#vip-upgrade .vip-upgrade-card {
  position: relative;
  z-index: 1;
  width: min(520px, 100%);
  max-height: min(92vh, 860px);
  overflow: auto;
  padding: 28px 22px 22px;
  border-radius: 28px;
  text-align: center;
  background:
    radial-gradient(circle at 50% 0%, rgba(255, 236, 170, 0.9), transparent 42%),
    linear-gradient(180deg, #fffaf0 0%, #ffffff 46%);
  border: 2px solid #f0c14b;
  box-shadow: 0 24px 60px rgba(72, 46, 8, 0.28);
}

#vip-upgrade .vip-upgrade-x {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 999px;
  background: #fff4d6;
  color: #7a4b08;
  font-weight: 800;
  cursor: pointer;
}

#vip-upgrade .vip-upgrade-kicker {
  margin: 0 0 6px;
  color: #b7791f;
  font-family: var(--font-en);
  font-weight: 700;
  letter-spacing: 0.4px;
}

#vip-upgrade .vip-upgrade-title {
  margin: 0 0 10px;
  color: #7a4b08;
  font-family: var(--font-th);
  font-size: clamp(1.45rem, 3vw, 1.85rem);
  line-height: 1.35;
}

#vip-upgrade .vip-early-bird {
  margin: 14px 0 0;
  padding: 10px 12px;
  border-radius: 14px;
  background: #fff1f2;
  border: 1.5px solid #e11d48;
  color: #be123c;
  font-family: var(--font-th);
  font-weight: 800;
  line-height: 1.55;
}

#vip-upgrade .vip-pay-box {
  margin-top: 16px;
  padding: 18px 12px 16px;
  border-radius: 24px;
  background:
    radial-gradient(circle at 50% 18%, rgba(255, 214, 102, 0.55), transparent 46%),
    linear-gradient(180deg, #fff7e8 0%, #fff 100%);
  border: 1.5px dashed #e8b931;
}

#vip-upgrade .vip-price {
  display: inline-block;
  margin: 0;
  padding: 8px 26px 10px;
  border-radius: 999px;
  color: #fff;
  font-family: 'Fredoka', var(--font-en);
  font-size: clamp(2.7rem, 8vw, 3.5rem);
  font-weight: 700;
  line-height: 1.05;
  letter-spacing: 0.4px;
  background: linear-gradient(180deg, #ffc44d 0%, #ff8a1f 58%, #ff5a7a 130%);
  text-shadow: 0 3px 0 rgba(154, 52, 18, 0.32);
  box-shadow:
    0 7px 0 #e05a12,
    0 14px 22px rgba(255, 122, 24, 0.32);
}

#vip-upgrade .vip-cta {
  margin: 16px 0 0;
  color: #9a3412;
  font-family: var(--font-th);
  font-size: clamp(1.08rem, 2.5vw, 1.28rem);
  font-weight: 800;
  line-height: 1.55;
}

#vip-upgrade .vip-chat-actions {
  display: flex;
  gap: 10px;
  margin-top: 14px;
}

#vip-upgrade .vip-line-btn,
#vip-upgrade .vip-messenger-btn,
#vip-upgrade .vip-login-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  min-height: 54px;
  border: 0;
  border-radius: 16px;
  color: #fff;
  font-family: var(--font-th);
  font-size: 1.02rem;
  font-weight: 800;
  text-decoration: none;
  cursor: pointer;
}

#vip-upgrade .vip-login-btn {
  margin-top: 14px;
}

#vip-upgrade .vip-line-btn {
  background: linear-gradient(180deg, #06c755 0%, #05a344 100%);
  box-shadow: 0 5px 0 #04753a;
}

#vip-upgrade .vip-messenger-btn {
  background: linear-gradient(180deg, #00b2ff 0%, #0084ff 100%);
  box-shadow: 0 5px 0 #0064c8;
}

#vip-upgrade .vip-login-btn {
  background: linear-gradient(180deg, #d97706 0%, #b45309 100%);
  box-shadow: 0 5px 0 #92400e;
}

#vip-upgrade .vip-line-icon {
  width: 26px;
  height: 26px;
  flex-shrink: 0;
}

@media (max-width: 520px) {
  #vip-upgrade .vip-chat-actions {
    flex-direction: column;
  }
}

/* Top Pill Badge in Card */
.gen-badge {
  position: absolute;
  top: 1.2rem;
  right: 1.2rem;
  font-size: 0.78rem;
  font-weight: 700;
  padding: 0.25rem 0.75rem;
  border-radius: var(--radius-pill);
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

/* Card Icon Bubble */
.gen-icon-bubble {
  width: 64px;
  height: 64px;
  border-radius: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.2rem;
  margin-bottom: 1.2rem;
  box-shadow: inset 0 2px 4px rgba(255, 255, 255, 0.8), 0 4px 10px rgba(0, 0, 0, 0.06);
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.generator-card:hover .gen-icon-bubble {
  transform: scale(1.18) rotate(8deg);
}

.gen-number-pill {
  display: inline-block;
  font-size: 0.82rem;
  font-weight: 700;
  padding: 0.15rem 0.65rem;
  border-radius: var(--radius-pill);
  margin-bottom: 0.4rem;
}

.gen-card-body {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.gen-card-title {
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--text-main);
  line-height: 1.2;
}

.gen-card-th {
  font-family: var(--font-th);
  font-size: 1.12rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
}

.gen-card-desc {
  font-family: var(--font-th);
  font-size: 0.96rem;
  color: var(--text-muted);
  line-height: 1.6;
  margin-bottom: 1.25rem;
}

.gen-card-footer {
  margin-top: auto;
  padding-top: 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-top: 1.5px dashed #EDF2F7;
  gap: 0.5rem;
}

.gen-tag {
  font-family: var(--font-th);
  font-size: 0.84rem;
  font-weight: 600;
  color: #718096;
}

.btn-gen-action {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 1.05rem;
  border-radius: var(--radius-pill);
  border: none;
  font-family: var(--font-th);
  font-size: 0.92rem;
  font-weight: 700;
  cursor: pointer;
  transition: var(--transition-bounce);
  color: #FFFFFF;
}

.btn-gen-action .action-arrow {
  transition: transform 0.2s ease;
}

.generator-card:hover .btn-gen-action .action-arrow {
  transform: translateX(4px);
}

/* Card 1: Flashcard Maker (Pink/Coral Theme) */
.card-flashcard {
  --gen-accent: #FF5E7E;
  --gen-light: #FFF0F4;
}
.card-flashcard:hover { border-color: #FF7B90; }
.card-flashcard .gen-badge { background: #FFEBF0; color: #FF5E7E; }
.card-flashcard .gen-icon-bubble { background: #FFEBF0; }
.card-flashcard .gen-number-pill { background: #FFEBF0; color: #FF5E7E; }
.card-flashcard .gen-card-th { color: #FF5E7E; }
.card-flashcard .btn-gen-action { background: linear-gradient(135deg, #FF7B90, #FF5E7E); box-shadow: 0 4px 12px rgba(255, 94, 126, 0.3); }

/* Card 2: Crossword (Purple Theme) */
.card-crossword {
  --gen-accent: #8B5CF6;
  --gen-light: #F3E8FF;
}
.card-crossword:hover { border-color: #A78BFA; }
.card-crossword .gen-badge { background: #F3E8FF; color: #8B5CF6; }
.card-crossword .gen-icon-bubble { background: #F3E8FF; }
.card-crossword .gen-number-pill { background: #F3E8FF; color: #8B5CF6; }
.card-crossword .gen-card-th { color: #8B5CF6; }
.card-crossword .btn-gen-action { background: linear-gradient(135deg, #A78BFA, #8B5CF6); box-shadow: 0 4px 12px rgba(139, 92, 246, 0.3); }

/* Card 3: Word Search (Blue Theme) */
.card-wordsearch {
  --gen-accent: #0EA5E9;
  --gen-light: #E0F2FE;
}
.card-wordsearch:hover { border-color: #38BDF8; }
.card-wordsearch .gen-badge { background: #E0F2FE; color: #0284C7; }
.card-wordsearch .gen-icon-bubble { background: #E0F2FE; }
.card-wordsearch .gen-number-pill { background: #E0F2FE; color: #0284C7; }
.card-wordsearch .gen-card-th { color: #0284C7; }
.card-wordsearch .btn-gen-action { background: linear-gradient(135deg, #38BDF8, #0284C7); box-shadow: 0 4px 12px rgba(2, 132, 199, 0.3); }

/* Card 4: Word Matching (Green Theme) */
.card-matching {
  --gen-accent: #10B981;
  --gen-light: #D1FAE5;
}
.card-matching:hover { border-color: #34D399; }
.card-matching .gen-badge { background: #D1FAE5; color: #059669; }
.card-matching .gen-icon-bubble { background: #D1FAE5; }
.card-matching .gen-number-pill { background: #D1FAE5; color: #059669; }
.card-matching .gen-card-th { color: #059669; }
.card-matching .btn-gen-action { background: linear-gradient(135deg, #34D399, #059669); box-shadow: 0 4px 12px rgba(5, 150, 105, 0.3); }

/* Card 5: Tracing (Orange/Amber Theme) */
.card-tracing {
  --gen-accent: #F59E0B;
  --gen-light: #FEF3C7;
}
.card-tracing:hover { border-color: #FBBF24; }
.card-tracing .gen-badge { background: #FEF3C7; color: #D97706; }
.card-tracing .gen-icon-bubble { background: #FEF3C7; }
.card-tracing .gen-number-pill { background: #FEF3C7; color: #D97706; }
.card-tracing .gen-card-th { color: #D97706; }
.card-tracing .btn-gen-action { background: linear-gradient(135deg, #FBBF24, #D97706); box-shadow: 0 4px 12px rgba(217, 119, 6, 0.3); }

/* Card: Shadow matching worksheet */
.card-shadow-matching {
  --gen-accent: #7C3AED;
  --gen-light: #EDE9FE;
}
.card-shadow-matching:hover { border-color: #A78BFA; }
.card-shadow-matching .gen-badge { background: #EDE9FE; color: #6D28D9; }
.card-shadow-matching .gen-icon-bubble { background: #EDE9FE; }
.card-shadow-matching .gen-number-pill { background: #EDE9FE; color: #6D28D9; }
.card-shadow-matching .gen-card-th { color: #6D28D9; }
.card-shadow-matching .btn-gen-action { background: linear-gradient(135deg, #A78BFA, #6D28D9); box-shadow: 0 4px 12px rgba(109, 40, 217, 0.28); }

/* Card: Handwriting tracing worksheet */
.card-handwriting {
  --gen-accent: #3B82F6;
  --gen-light: #DBEAFE;
}
.card-handwriting:hover { border-color: #60A5FA; }
.card-handwriting .gen-badge { background: #DBEAFE; color: #1D4ED8; }
.card-handwriting .gen-icon-bubble { background: #DBEAFE; }
.card-handwriting .gen-number-pill { background: #DBEAFE; color: #1D4ED8; }
.card-handwriting .gen-card-th { color: #1D4ED8; }
.card-handwriting .btn-gen-action { background: linear-gradient(135deg, #60A5FA, #1D4ED8); box-shadow: 0 4px 12px rgba(29, 78, 216, 0.28); }

/* Card: Missing letters worksheet */
.card-missing-letters {
  --gen-accent: #EA580C;
  --gen-light: #FFEDD5;
}
.card-missing-letters:hover { border-color: #FB923C; }
.card-missing-letters .gen-badge { background: #FFEDD5; color: #C2410C; }
.card-missing-letters .gen-icon-bubble { background: #FFEDD5; }
.card-missing-letters .gen-number-pill { background: #FFEDD5; color: #C2410C; }
.card-missing-letters .gen-card-th { color: #C2410C; }
.card-missing-letters .btn-gen-action { background: linear-gradient(135deg, #FB923C, #EA580C); box-shadow: 0 4px 12px rgba(234, 88, 12, 0.28); }

/* Card: Word labeling worksheet */
.card-word-labeling {
  --gen-accent: #0F766E;
  --gen-light: #CCFBF1;
}
.card-word-labeling:hover { border-color: #2DD4BF; }
.card-word-labeling .gen-badge { background: #CCFBF1; color: #0F766E; }
.card-word-labeling .gen-icon-bubble { background: #CCFBF1; }
.card-word-labeling .gen-number-pill { background: #CCFBF1; color: #0F766E; }
.card-word-labeling .gen-card-th { color: #0F766E; }
.card-word-labeling .btn-gen-action { background: linear-gradient(135deg, #2DD4BF, #0F766E); box-shadow: 0 4px 12px rgba(15, 118, 110, 0.28); }

/* Card: Classroom Bingo */
.card-classroom-bingo {
  --gen-accent: #C2410C;
  --gen-light: #FFEDD5;
}
.card-classroom-bingo:hover { border-color: #FB923C; }
.card-classroom-bingo .gen-badge { background: #FFEDD5; color: #C2410C; }
.card-classroom-bingo .gen-icon-bubble { background: #FFEDD5; }
.card-classroom-bingo .gen-number-pill { background: #FFEDD5; color: #C2410C; }
.card-classroom-bingo .gen-card-th { color: #C2410C; }
.card-classroom-bingo .btn-gen-action { background: linear-gradient(135deg, #FB923C, #EA580C); box-shadow: 0 4px 12px rgba(234, 88, 12, 0.28); }

/* Card: Picture Story Worksheet Generator */
#page-generator .card-picture-story {
  --gen-accent: #0284C7;
  --gen-light: #E0F2FE;
}
#page-generator .card-picture-story:hover { border-color: #38BDF8; }
#page-generator .card-picture-story .gen-badge { background: #E0F2FE; color: #0369A1; }
#page-generator .card-picture-story .gen-icon-bubble { background: #E0F2FE; }
#page-generator .card-picture-story .gen-number-pill { background: #E0F2FE; color: #0369A1; }
#page-generator .card-picture-story .gen-card-th { color: #0284C7; }
#page-generator .card-picture-story .btn-gen-action { background: linear-gradient(135deg, #38BDF8, #0284C7); box-shadow: 0 4px 12px rgba(2, 132, 199, 0.28); }

/* Card: Telling Time Worksheet Generator */
#page-generator .card-telling-time {
  --gen-accent: #7C3AED;
  --gen-light: #F3E8FF;
}
#page-generator .card-telling-time:hover { border-color: #A78BFA; }
#page-generator .card-telling-time .gen-badge { background: #F3E8FF; color: #6D28D9; }
#page-generator .card-telling-time .gen-icon-bubble { background: #F3E8FF; }
#page-generator .card-telling-time .gen-number-pill { background: #F3E8FF; color: #6D28D9; }
#page-generator .card-telling-time .gen-card-th { color: #7C3AED; }
#page-generator .card-telling-time .btn-gen-action { background: linear-gradient(135deg, #8B5CF6, #6D28D9); box-shadow: 0 4px 12px rgba(109, 40, 217, 0.28); }

/* Card: Word Bank Labeling Worksheet Generator */
#page-generator .card-word-bank {
  --gen-accent: #0D9488;
  --gen-light: #CCFBF1;
}
#page-generator .card-word-bank:hover { border-color: #2DD4BF; }
#page-generator .card-word-bank .gen-badge { background: #CCFBF1; color: #0F766E; }
#page-generator .card-word-bank .gen-icon-bubble { background: #CCFBF1; }
#page-generator .card-word-bank .gen-number-pill { background: #CCFBF1; color: #0F766E; }
#page-generator .card-word-bank .gen-card-th { color: #0D9488; }
#page-generator .card-word-bank .btn-gen-action { background: linear-gradient(135deg, #14B8A6, #0F766E); box-shadow: 0 4px 12px rgba(15, 118, 110, 0.28); }

/* Card: Word Unscramble Worksheet Generator */
#page-generator .card-word-unscramble {
  --gen-accent: #4F46E5;
  --gen-light: #E0E7FF;
}
#page-generator .card-word-unscramble:hover { border-color: #818CF8; }
#page-generator .card-word-unscramble .gen-badge { background: #E0E7FF; color: #3730A3; }
#page-generator .card-word-unscramble .gen-icon-bubble { background: #E0E7FF; }
#page-generator .card-word-unscramble .gen-number-pill { background: #E0E7FF; color: #3730A3; }
#page-generator .card-word-unscramble .gen-card-th { color: #4F46E5; }
#page-generator .card-word-unscramble .btn-gen-action { background: linear-gradient(135deg, #6366F1, #4338CA); box-shadow: 0 4px 12px rgba(67, 56, 202, 0.28); }

/* Card: Word Sorting Worksheet Generator */
#page-generator .card-word-sorting {
  --gen-accent: #D97706;
  --gen-light: #FEF3C7;
}
#page-generator .card-word-sorting:hover { border-color: #F59E0B; }
#page-generator .card-word-sorting .gen-badge { background: #FEF3C7; color: #92400E; }
#page-generator .card-word-sorting .gen-icon-bubble { background: #FEF3C7; }
#page-generator .card-word-sorting .gen-number-pill { background: #FEF3C7; color: #92400E; }
#page-generator .card-word-sorting .gen-card-th { color: #D97706; }
#page-generator .card-word-sorting .btn-gen-action { background: linear-gradient(135deg, #F59E0B, #B45309); box-shadow: 0 4px 12px rgba(180, 83, 9, 0.28); }

/* Card: Printable Word Dominoes Generator */
#page-generator .card-word-dominoes {
  --gen-accent: #E11D48;
  --gen-light: #FFE4E6;
}
#page-generator .card-word-dominoes:hover { border-color: #FB7185; }
#page-generator .card-word-dominoes .gen-badge { background: #FFE4E6; color: #9F1239; }
#page-generator .card-word-dominoes .gen-icon-bubble { background: #FFE4E6; }
#page-generator .card-word-dominoes .gen-number-pill { background: #FFE4E6; color: #9F1239; }
#page-generator .card-word-dominoes .gen-card-th { color: #E11D48; }
#page-generator .card-word-dominoes .btn-gen-action { background: linear-gradient(135deg, #F43F5E, #BE123C); box-shadow: 0 4px 12px rgba(190, 18, 60, 0.28); }

/* Card: Coloring Page Worksheet Generator */
#page-generator .card-coloring-page {
  --gen-accent: #EA580C;
  --gen-light: #FFEDD5;
}
#page-generator .card-coloring-page:hover { border-color: #FB923C; }
#page-generator .card-coloring-page .gen-badge { background: #FFEDD5; color: #9A3412; }
#page-generator .card-coloring-page .gen-icon-bubble { background: #FFEDD5; }
#page-generator .card-coloring-page .gen-number-pill { background: #FFEDD5; color: #9A3412; }
#page-generator .card-coloring-page .gen-card-th { color: #EA580C; }
#page-generator .card-coloring-page .btn-gen-action { background: linear-gradient(135deg, #FB923C, #EA580C); box-shadow: 0 4px 12px rgba(234, 88, 12, 0.28); }

/* ===================================================================
   FLASHCARD GENERATOR WORKSPACE (Toolbar 30% & Preview 70%)
   =================================================================== */

.fc-workspace,
.cw-workspace {
  display: flex;
  gap: 1.5rem;
  align-items: flex-start;
  margin-top: 1rem;
  animation: pageFadeIn 0.35s ease-out forwards;
}

/* Left Column: Toolbar (~30%) */
.workspace-toolbar {
  flex: 1 1 320px;
  width: 100%;
  max-width: 320px;
  min-width: 0;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-radius: var(--radius-lg);
  border: 2.5px solid #EBF3FA;
  box-shadow: var(--shadow-lg);
  padding: 1.5rem 1.35rem 1.75rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  position: sticky;
  top: 90px;
  max-height: calc(100vh - 110px);
  overflow-y: auto;
  scrollbar-width: thin;
}

.toolbar-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding-bottom: 0.85rem;
  border-bottom: 2px dashed #EDF2F7;
}

.btn-back-tools {
  background: #FFF5F7;
  color: #FF5E7E;
  border: 1.5px solid #FFD4DB;
  border-radius: var(--radius-pill);
  padding: 0.4rem 0.9rem;
  font-family: var(--font-th);
  font-weight: 700;
  font-size: 0.88rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  transition: var(--transition-bounce);
}

.btn-back-tools:hover {
  background: #FF5E7E;
  color: #FFFFFF;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(255, 94, 126, 0.25);
}

.btn-arrow-icon {
  font-size: 1rem;
  font-weight: 800;
}

.toolbar-badge {
  font-family: var(--font-en);
  font-size: 0.82rem;
  font-weight: 700;
  background: #EBF8FF;
  color: #0284C7;
  padding: 0.25rem 0.65rem;
  border-radius: var(--radius-pill);
}

.toolbar-scrollable {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

/* Tool Sections */
.tool-section {
  background: #FAFCFF;
  border: 1.5px solid #EDF2F7;
  border-radius: var(--radius-md);
  padding: 1rem 0.9rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.tool-section-title {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  font-family: var(--font-th);
  font-size: 1rem;
  font-weight: 700;
  color: #2D3748;
  margin: 0;
}

.section-icon {
  font-size: 1.15rem;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.form-label {
  font-family: var(--font-th);
  font-size: 0.88rem;
  font-weight: 600;
  color: #4A5568;
}

.sub-label {
  font-family: var(--font-th);
  font-size: 0.84rem;
  font-weight: 600;
  color: #718096;
}

.form-select, .form-input {
  width: 100%;
  padding: 0.65rem 0.9rem;
  font-family: var(--font-th);
  font-size: 0.95rem;
  border-radius: var(--radius-sm);
  border: 2px solid #E2E8F0;
  background: #FFFFFF;
  color: #2D3748;
  outline: none;
  transition: var(--transition-smooth);
}

.form-select:focus, .form-input:focus {
  border-color: #4FB5FF;
  box-shadow: 0 0 0 3px rgba(79, 181, 255, 0.18);
}

/* A4 Layout Toggle Buttons */
#fc-workspace .fc-layout-group {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
}

.layout-btn {
  background: #FFFFFF;
  border: 2px solid #E2E8F0;
  border-radius: var(--radius-sm);
  padding: 0.55rem 0.6rem;
  font-family: var(--font-th);
  font-size: 0.88rem;
  font-weight: 700;
  color: #4A5568;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  transition: var(--transition-bounce);
  outline: none;
}

.layout-btn-icon {
  font-size: 1.1rem;
}

.layout-btn:hover {
  border-color: #4FB5FF;
  color: #0284C7;
  transform: translateY(-1px);
}

.layout-btn.active {
  border-color: #2F97FF;
  background: #F0F7FF;
  color: #0284C7;
  box-shadow: 0 4px 10px rgba(47, 151, 255, 0.15);
}

.tool-tip-text {
  font-family: var(--font-th);
  font-size: 0.78rem;
  color: #A0AEC0;
  margin-top: 0.15rem;
}

/* ===================================================================
   KID-FRIENDLY CAPSULE MODE TOGGLE SWITCH (BW vs COLOR)
   =================================================================== */
.capsule-mode-toggle {
  display: inline-flex;
  align-items: center;
  background: #EDF2F7;
  padding: 4px;
  border-radius: var(--radius-pill);
  box-shadow: inset 0 2px 5px rgba(0, 0, 0, 0.06);
  border: 2px solid #E2E8F0;
  gap: 4px;
  position: relative;
  user-select: none;
  transition: var(--transition-smooth);
}

.mode-capsule-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.45rem 1rem;
  border-radius: var(--radius-pill);
  border: 1.5px solid transparent;
  background: transparent;
  font-family: var(--font-th);
  font-size: 0.92rem;
  font-weight: 700;
  color: #718096;
  cursor: pointer;
  outline: none;
  transition: var(--transition-bounce);
  white-space: nowrap;
}

.mode-capsule-btn .capsule-icon {
  font-size: 1.15rem;
  line-height: 1;
  transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
  display: inline-block;
}

.mode-capsule-btn .capsule-label {
  line-height: 1.2;
}

.mode-capsule-btn:hover {
  color: #2D3748;
  transform: translateY(-1px);
}

.mode-capsule-btn:hover .capsule-icon {
  transform: scale(1.18) rotate(-6deg);
}

.mode-capsule-btn:active {
  transform: scale(0.96);
}

/* Active State: BW Mode (Pencil / Line-art theme) */
.mode-capsule-btn[data-mode="bw"].active {
  background: #FFFFFF;
  color: #2D3748;
  border-color: #CBD5E1;
  box-shadow: 0 4px 12px rgba(45, 55, 72, 0.12), 0 2px 4px rgba(0, 0, 0, 0.04);
}

.mode-capsule-btn[data-mode="bw"].active .capsule-icon {
  transform: scale(1.12);
}

/* Active State: Color Mode (Joyful Rainbow / Coral Gradient theme) */
.mode-capsule-btn[data-mode="color"].active {
  background: linear-gradient(135deg, #FF6B8B 0%, #FF8E53 100%);
  color: #FFFFFF;
  border-color: rgba(255, 255, 255, 0.4);
  box-shadow: 0 4px 14px rgba(255, 107, 139, 0.38), 0 2px 4px rgba(0, 0, 0, 0.08);
}

.mode-capsule-btn[data-mode="color"].active .capsule-icon {
  transform: scale(1.18) rotate(6deg);
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.15));
}

/* Home View Mode Bar */
.home-mode-bar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  margin-top: 1.1rem;
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(8px);
  padding: 0.4rem 1rem;
  border-radius: var(--radius-pill);
  box-shadow: var(--shadow-sm);
  border: 1.5px solid rgba(255, 255, 255, 0.85);
}

.mode-bar-label {
  font-family: var(--font-th);
  font-weight: 700;
  color: #4A5568;
  font-size: 0.95rem;
}

/* Workspace Toolbar Specific Layout */
.capsule-mode-toggle-workspace {
  display: flex;
  width: 100%;
  gap: 5px;
  padding: 5px;
  background: #F1F5F9;
  border-radius: var(--radius-sm);
  box-sizing: border-box;
}

.capsule-mode-toggle-workspace .mode-capsule-btn {
  flex: 1;
  text-align: center;
  white-space: normal;
  word-wrap: break-word;
  padding: 10px 5px;
  border-radius: 10px;
  font-size: 0.88rem;
  justify-content: center;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  box-sizing: border-box;
}

/* Image and Box Control Checkboxes & Sliders */
.toggle-checkbox-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-family: var(--font-th);
  font-size: 0.92rem;
  font-weight: 700;
  color: #2D3748;
  cursor: pointer;
  padding: 0.35rem 0.15rem;
  user-select: none;
  transition: color 0.15s ease;
}

.toggle-checkbox-label:hover {
  color: #0284C7;
}

.toggle-checkbox-label input[type="checkbox"] {
  width: 18px;
  height: 18px;
  cursor: pointer;
  accent-color: #2F97FF;
  border-radius: 4px;
}

.scale-control-group {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  margin-top: 0.25rem;
  padding-left: 0.2rem;
}

.scale-label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.1rem;
}

.scale-label-row .sub-label {
  font-family: var(--font-th);
  font-size: 0.82rem;
  font-weight: 600;
  color: #4A5568;
}

/* Image Scale Control Slider */
.image-scale-box {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  background: #FFFFFF;
  padding: 0.55rem 0.8rem;
  border-radius: var(--radius-sm);
  border: 2px solid #E2E8F0;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}

.image-scale-slider {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 8px;
  border-radius: 4px;
  background: #E2E8F0;
  outline: none;
  cursor: pointer;
  transition: background 0.2s;
}

.image-scale-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #2F97FF;
  box-shadow: 0 2px 6px rgba(47, 151, 255, 0.4);
  cursor: pointer;
  transition: transform 0.15s ease, background-color 0.15s ease;
}

.image-scale-slider::-webkit-slider-thumb:hover {
  transform: scale(1.18);
  background: #0284C7;
}

.image-scale-slider::-moz-range-thumb {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #2F97FF;
  border: none;
  box-shadow: 0 2px 6px rgba(47, 151, 255, 0.4);
  cursor: pointer;
}

.image-scale-badge,
#fc-workspace .fc-image-scale-badge {
  font-family: var(--font-en);
  font-weight: 700;
  font-size: 0.88rem;
  color: #0284C7;
  background: #F0F7FF;
  padding: 0.2rem 0.5rem;
  border-radius: 6px;
  min-width: 44px;
  text-align: center;
  border: 1px solid #BAE6FD;
}

/* Flashcard View Header Specific */
.flashcard-mode-toggle-wrap {
  display: flex;
  align-items: center;
}

.capsule-mode-toggle-compact {
  padding: 3px;
  background: #FFFFFF;
  border: 2px solid #E2E8F0;
  box-shadow: var(--shadow-sm);
}

.capsule-mode-toggle-compact .mode-capsule-btn {
  padding: 0.35rem 0.75rem;
  font-size: 0.86rem;
}

/* Logo Upload Box */
.upload-logo-box {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.btn-upload-label {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: #FFFFFF;
  border: 2px dashed #CBD5E0;
  border-radius: var(--radius-pill);
  padding: 0.55rem 1rem;
  font-family: var(--font-th);
  font-size: 0.9rem;
  font-weight: 600;
  color: #4A5568;
  cursor: pointer;
  transition: var(--transition-bounce);
}

.btn-upload-label:hover {
  border-color: #4FB5FF;
  color: #0284C7;
  background: #F0F7FF;
}

.file-input-hidden {
  display: none;
}

.btn-remove-logo,
#fc-workspace .fc-btn-remove-logo {
  background: #FFF5F5;
  border: 1px solid #FED7D7;
  color: #E53E3E;
  font-family: var(--font-th);
  font-size: 0.82rem;
  font-weight: 600;
  padding: 0.45rem 0.75rem;
  border-radius: var(--radius-pill);
  cursor: pointer;
  transition: var(--transition-smooth);
}

.btn-remove-logo:hover,
#fc-workspace .fc-btn-remove-logo:hover {
  background: #FED7D7;
}

.upload-logo-hint {
  font-family: var(--font-th);
  font-size: 0.78rem;
  color: #718096;
  line-height: 1.45;
  margin-top: 0.4rem;
}

/* Color Picker & Pastel Swatches */
.color-picker-box {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.color-picker-custom-label {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  background: #FFFFFF;
  border: 1.5px solid #E2E8F0;
  border-radius: var(--radius-pill);
  padding: 0.35rem 0.85rem;
  cursor: pointer;
  align-self: flex-start;
  transition: var(--transition-smooth);
}

.color-picker-custom-label:hover {
  border-color: #CBD5E0;
}

.native-color-picker {
  width: 26px;
  height: 26px;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  background: transparent;
  padding: 0;
}

.native-color-picker::-webkit-color-swatch-wrapper {
  padding: 0;
}

.native-color-picker::-webkit-color-swatch {
  border: 1.5px solid #CBD5E0;
  border-radius: 50%;
}

.color-picker-btn-text {
  font-family: var(--font-th);
  font-size: 0.86rem;
  font-weight: 600;
  color: #4A5568;
}

#fc-workspace .fc-pastel-swatches {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.swatch-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 2px solid rgba(0, 0, 0, 0.08);
  cursor: pointer;
  transition: var(--transition-bounce);
  box-shadow: var(--shadow-sm);
  outline: none;
}

.swatch-btn:hover {
  transform: scale(1.2);
}

.swatch-btn.active {
  transform: scale(1.15);
  box-shadow: 0 0 0 3px #4FB5FF;
  border-color: #FFFFFF;
}

/* Background Pattern Selector & Category Dropdown */
.bg-pattern-selector {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 0.45rem;
}

#fc-vocab-category,
#bg-category-select {
  width: 100%;
  padding: 0.62rem 0.9rem;
  font-family: var(--font-th);
  font-size: 0.88rem;
  font-weight: 600;
  color: #2D3748;
  background-color: #FFFFFF;
  border: 2px solid #E2E8F0;
  border-radius: 12px;
  outline: none;
  cursor: pointer;
  transition: var(--transition-smooth);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}

#fc-vocab-category:hover,
#bg-category-select:hover {
  border-color: #4FB5FF;
}

#fc-vocab-category:focus,
#bg-category-select:focus {
  border-color: #2F97FF;
  box-shadow: 0 0 0 3px rgba(79, 181, 255, 0.18);
}

/* Background Selector Grid */
.bg-selector-grid,
.pattern-btn-group {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.45rem;
  max-height: 240px;
  overflow-y: auto;
  padding-right: 2px;
}

.bg-selector-grid::-webkit-scrollbar {
  width: 5px;
}

.bg-selector-grid::-webkit-scrollbar-thumb {
  background: #CBD5E0;
  border-radius: 4px;
}

.bg-empty-msg {
  grid-column: 1 / -1;
  text-align: center;
  padding: 1rem 0.5rem;
  font-family: var(--font-th);
  font-size: 0.82rem;
  font-weight: 500;
  color: #A0AEC0;
  background: #F8FAFC;
  border: 1px dashed #E2E8F0;
  border-radius: 10px;
}

.pattern-btn {
  background: #FFFFFF;
  border: 2px solid #E2E8F0;
  border-radius: 12px;
  padding: 0.55rem 0.35rem;
  font-family: var(--font-th);
  font-size: 0.82rem;
  font-weight: 700;
  color: #4A5568;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.2rem;
  transition: var(--transition-bounce);
  outline: none;
}

.pattern-preview-icon {
  font-size: 1.25rem;
}

.pattern-title {
  font-size: 0.78rem;
  line-height: 1.2;
  text-align: center;
  word-break: break-word;
}

.pattern-desc {
  font-size: 0.7rem;
  color: #A0AEC0;
  font-weight: 500;
  line-height: 1.1;
  text-align: center;
}

.pattern-btn:hover {
  border-color: #4FB5FF;
  transform: translateY(-2px);
}

.pattern-btn.active {
  border-color: #2F97FF;
  background: #F0F7FF;
  color: #0284C7;
  box-shadow: 0 4px 10px rgba(47, 151, 255, 0.15);
}

/* ===================================================================
   CHECKLIST ACCORDION SYSTEM (VOCAB SELECTION)
   =================================================================== */
.tool-section-vocab-select {
  padding-bottom: 0.9rem;
}

.vocab-checklist-control-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.4rem;
  margin-bottom: 0.6rem;
  flex-wrap: wrap;
}

.vocab-count-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.3rem 0.65rem;
  background: #EFF6FF;
  border: 1.5px solid #BFDBFE;
  border-radius: var(--radius-pill);
  font-family: var(--font-th);
  font-size: 0.85rem;
  font-weight: 600;
  color: #1E40AF;
}

.vocab-count-chip strong {
  color: #2563EB;
  font-weight: 700;
}

.vocab-global-actions {
  display: flex;
  align-items: center;
  gap: 0.3rem;
}

.btn-vocab-mini {
  padding: 0.28rem 0.55rem;
  border-radius: 6px;
  border: 1.5px solid #CBD5E0;
  background: #FFFFFF;
  font-family: var(--font-th);
  font-size: 0.78rem;
  font-weight: 700;
  color: #4A5568;
  cursor: pointer;
  transition: var(--transition-bounce);
  outline: none;
  white-space: nowrap;
}

.btn-vocab-mini:hover {
  border-color: #3B82F6;
  color: #2563EB;
  background: #EFF6FF;
  transform: translateY(-1px);
}

.btn-vocab-mini.btn-vocab-clear:hover {
  border-color: #F87171;
  color: #DC2626;
  background: #FEF2F2;
}

/* Quick Search Filter for Checklist */
.vocab-search-box {
  position: relative;
  width: 100%;
  margin-bottom: 0.65rem;
}

.vocab-search-icon {
  position: absolute;
  left: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.85rem;
  color: #94A3B8;
  pointer-events: none;
}

.vocab-filter-input,
#fc-workspace .fc-vocab-filter {
  width: 100%;
  padding: 0.45rem 1.8rem 0.45rem 2.2rem !important;
  font-size: 0.85rem !important;
  border-radius: 8px !important;
  border: 1.5px solid #E2E8F0 !important;
  background: #FFFFFF !important;
  outline: none;
  transition: var(--transition-smooth);
}

.vocab-filter-input:focus,
#fc-workspace .fc-vocab-filter:focus {
  border-color: #3B82F6 !important;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15) !important;
}

.vocab-filter-clear-btn {
  position: absolute;
  right: 0.6rem;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  font-size: 1.1rem;
  color: #94A3B8;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
}

.vocab-filter-clear-btn:hover {
  color: #475569;
}

/* Accordion Container */
.vocab-accordion-container {
  max-height: 350px;
  overflow-y: auto;
  padding-right: 3px;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.vocab-accordion-container::-webkit-scrollbar {
  width: 5px;
}

.vocab-accordion-container::-webkit-scrollbar-thumb {
  background: #CBD5E0;
  border-radius: 4px;
}

/* Accordion Item */
.vocab-accordion-item {
  border: 1.5px solid #E2E8F0;
  border-radius: 10px;
  background: #FFFFFF;
  overflow: hidden;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.vocab-accordion-item:hover {
  border-color: #CBD5E0;
}

.vocab-accordion-item.open {
  border-color: #93C5FD;
  box-shadow: 0 2px 8px rgba(59, 130, 246, 0.08);
}

.vocab-accordion-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.45rem 0.65rem;
  background: #F8FAFC;
  cursor: pointer;
  user-select: none;
  transition: background 0.15s ease;
  gap: 0.4rem;
}

.vocab-accordion-header:hover {
  background: #F1F5F9;
}

.vocab-accordion-item.open .vocab-accordion-header {
  background: #EFF6FF;
}

.accordion-header-left {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  min-width: 0;
  flex: 1;
}

.accordion-cat-icon {
  font-size: 1.05rem;
  line-height: 1;
}

.accordion-cat-title {
  font-family: var(--font-th);
  font-size: 0.86rem;
  font-weight: 700;
  color: #334155;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.accordion-header-right {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.accordion-cat-badge {
  font-family: var(--font-en);
  font-size: 0.72rem;
  font-weight: 700;
  padding: 0.1rem 0.45rem;
  border-radius: var(--radius-pill);
  background: #E2E8F0;
  color: #64748B;
  transition: all 0.2s ease;
}

.accordion-cat-badge.has-selected {
  background: #DBEAFE;
  color: #1E40AF;
  border: 1px solid #BFDBFE;
}

.accordion-chevron {
  font-size: 0.7rem;
  color: #94A3B8;
  transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
  display: inline-block;
}

.vocab-accordion-item.open .accordion-chevron {
  transform: rotate(180deg);
  color: #2563EB;
}

.vocab-accordion-body {
  display: none;
  padding: 0.5rem 0.65rem 0.6rem;
  border-top: 1px dashed #E2E8F0;
  background: #FFFFFF;
}

.vocab-accordion-item.open .vocab-accordion-body {
  display: block;
}

.accordion-cat-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.4rem;
  margin-bottom: 0.45rem;
  padding-bottom: 0.35rem;
  border-bottom: 1px solid #F1F5F9;
}

.btn-cat-action {
  font-family: var(--font-th);
  font-size: 0.74rem;
  font-weight: 600;
  padding: 0.15rem 0.45rem;
  border-radius: 4px;
  border: 1px solid #E2E8F0;
  background: #F8FAFC;
  color: #64748B;
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-cat-action:hover {
  background: #EFF6FF;
  color: #2563EB;
  border-color: #BFDBFE;
}

.btn-cat-clear-all:hover {
  background: #FEF2F2 !important;
  color: #DC2626 !important;
  border-color: #FECACA !important;
}

#fc-vocab-list,
.vocab-checkbox-list {
  max-height: 280px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  padding-right: 2px;
}

.vocab-checkbox-list::-webkit-scrollbar {
  width: 4px;
}

.vocab-checkbox-list::-webkit-scrollbar-thumb {
  background: #CBD5E0;
  border-radius: 3px;
}

.vocab-check-item {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.3rem 0.45rem;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s ease;
  user-select: none;
}

.vocab-check-item:hover {
  background: #F1F5F9;
}

.vocab-check-item input[type="checkbox"] {
  width: 15px;
  height: 15px;
  accent-color: #3B82F6;
  cursor: pointer;
  flex-shrink: 0;
}

.vocab-item-en {
  font-family: var(--font-en);
  font-size: 0.88rem;
  font-weight: 700;
  color: #1E293B;
}

.vocab-item-th {
  font-family: var(--font-th);
  font-size: 0.8rem;
  color: #64748B;
}

.vocab-item-id {
  margin-left: auto;
  font-family: var(--font-en);
  font-size: 0.68rem;
  font-weight: 600;
  color: #94A3B8;
  background: #F1F5F9;
  padding: 0.05rem 0.35rem;
  border-radius: 4px;
}

.vocab-category-picker {
  margin-bottom: 0.75rem;
}

.text-style-control {
  margin-top: 0.55rem;
}

.text-style-control .form-label {
  display: block;
  margin-bottom: 0.35rem;
}

#text-color {
  width: 100%;
  height: 42px;
  padding: 4px;
  border: 2px solid #E2E8F0;
  border-radius: 12px;
  background: #FFFFFF;
  cursor: pointer;
}

#text-size {
  width: 100%;
  accent-color: #3B82F6;
  cursor: pointer;
}

/* ===================================================================
   APPLY TO ALL CARDS BUTTON
   =================================================================== */
.apply-all-bg-box {
  width: 100%;
}

.btn-apply-all-bg {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.6rem 0.9rem;
  background: linear-gradient(135deg, #38BDF8 0%, #2563EB 100%);
  color: #FFFFFF;
  font-family: var(--font-th);
  font-weight: 700;
  font-size: 0.88rem;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  box-shadow: 0 3px 8px rgba(37, 99, 235, 0.25);
  transition: var(--transition-bounce);
  outline: none;
}

.btn-apply-all-bg:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 14px rgba(37, 99, 235, 0.35);
  filter: brightness(105%);
}

.btn-apply-all-bg:active {
  transform: translateY(1px);
}

/* ===================================================================
   FLOATING POPOVER: INDEPENDENT CARD BACKGROUND SELECTOR
   =================================================================== */
.card-bg-popover {
  position: fixed;
  z-index: 9999;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 350px;
  max-width: 92vw;
  max-height: 85vh;
  background: #FFFFFF;
  border-radius: 18px;
  box-shadow: 0 20px 48px rgba(15, 23, 42, 0.25), 0 0 0 1px rgba(15, 23, 42, 0.08);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: popoverFadeIn 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes popoverFadeIn {
  from {
    opacity: 0;
    transform: translate(-50%, -46%) scale(0.95);
  }
  to {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
  }
}

.card-bg-popover.hidden {
  display: none !important;
}

.card-bg-popover-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid #E2E8F0;
  background: #F8FAFC;
}

.popover-title-row {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.popover-icon {
  font-size: 1.1rem;
}

.popover-title {
  font-family: var(--font-th);
  font-size: 0.95rem;
  font-weight: 700;
  color: #1E293B;
}

.btn-close-popover {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 1px solid #E2E8F0;
  background: #FFFFFF;
  color: #64748B;
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
}

.btn-close-popover:hover {
  background: #F1F5F9;
  color: #0F172A;
  border-color: #CBD5E0;
}

.card-bg-popover-body {
  padding: 0.85rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  overflow-y: auto;
  max-height: calc(85vh - 60px);
}

.popover-category-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.form-label-sm {
  font-family: var(--font-th);
  font-size: 0.82rem;
  font-weight: 700;
  color: #475569;
  white-space: nowrap;
}

.form-select-sm {
  padding: 0.35rem 0.65rem !important;
  font-size: 0.82rem !important;
  border-radius: 8px !important;
  border: 1.5px solid #E2E8F0 !important;
}

.popover-bg-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.45rem;
  max-height: 280px;
  overflow-y: auto;
  padding-right: 2px;
}

.popover-bg-grid::-webkit-scrollbar {
  width: 5px;
}

.popover-bg-grid::-webkit-scrollbar-thumb {
  background: #CBD5E0;
  border-radius: 4px;
}

.popover-bg-grid .pattern-btn {
  padding: 0.5rem 0.35rem;
}

/* Action Section */
.tool-action-section {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  padding-top: 0.5rem;
}

.btn-print-pdf {
  width: 100%;
  min-height: 54px;
  background: linear-gradient(135deg, #FF5E7E 0%, #FF8E53 100%);
  color: #FFFFFF;
  border: none;
  border-radius: var(--radius-pill);
  font-family: var(--font-th);
  font-size: 1.12rem;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  box-shadow: 0 8px 22px rgba(255, 94, 126, 0.35);
  transition: var(--transition-bounce);
}

.btn-print-pdf:hover {
  background: linear-gradient(135deg, #FA4368 0%, #FF7A38 100%);
  transform: translateY(-3px) scale(1.02);
  box-shadow: 0 12px 28px rgba(255, 94, 126, 0.45);
}

.btn-print-pdf:active {
  transform: translateY(1px);
}

.dl-hint {
  font-family: var(--font-th);
  font-size: 0.78rem;
  color: #718096;
  text-align: center;
}

/* Right Column: Live Preview (~70%) */
.workspace-preview {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.25rem;
}

.preview-stage-header {
  width: 100%;
  max-width: 794px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.preview-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  background: rgba(255, 255, 255, 0.9);
  padding: 0.4rem 1rem;
  border-radius: var(--radius-pill);
  box-shadow: var(--shadow-sm);
  font-family: var(--font-th);
  font-size: 0.92rem;
  font-weight: 700;
  color: #2D3748;
  border: 1.5px solid #E2E8F0;
}

.preview-live-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #EF4444;
  box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.7);
  animation: pulseDotRed 2s infinite;
}

@keyframes pulseDotRed {
  0% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.7); }
  70% { transform: scale(1.15); box-shadow: 0 0 0 7px rgba(239, 68, 68, 0); }
  100% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(239, 68, 68, 0); }
}

.preview-hint-text {
  font-family: var(--font-th);
  font-size: 0.88rem;
  font-weight: 600;
  color: #718096;
}

/* A4 Scroll Wrapper & Paper Simulation */
.a4-scroll-wrapper {
  width: 100%;
  display: flex;
  justify-content: center;
  overflow-x: auto;
  padding: 0.5rem 0 1.5rem;
  -webkit-overflow-scrolling: touch;
}

/* ===================================================================
   A4 PREVIEW CONTAINER & MULTI-PAGE SIMULATION (.fc-page)
   =================================================================== */
#fc-preview-pages {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 32px;
  padding: 0.5rem 0 2rem;
  box-sizing: border-box;
  background: transparent;
  position: relative;
}

#fc-workspace .fc-page {
  width: 210mm;
  min-height: 297mm;
  height: 297mm;
  background-color: #FFFFFF;
  border-radius: 8px;
  box-shadow: 0 16px 44px rgba(45, 75, 115, 0.16), 0 3px 12px rgba(0, 0, 0, 0.06);
  border: 1px solid #E2E8F0;
  padding: 8mm;
  box-sizing: border-box;
  display: grid;
  position: relative;
  page-break-after: always;
  break-after: page;
  overflow: hidden;
  transition: all 0.25s ease;
}

#fc-workspace .fc-page:last-child {
  page-break-after: auto;
  break-after: auto;
}

/* Page indicator label during preview */
#fc-workspace .fc-page-badge {
  position: absolute;
  top: -24px;
  left: 4px;
  font-family: var(--font-th);
  font-size: 0.82rem;
  font-weight: 700;
  color: #4A5568;
  background: rgba(255, 255, 255, 0.95);
  padding: 2px 10px;
  border-radius: 12px;
  border: 1.5px solid #CBD5E1;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.05);
  display: flex;
  align-items: center;
  gap: 5px;
}

/* 8 cards layout: 2 columns, 4 rows */
#fc-workspace .fc-page.grid-8 {
  grid-template-columns: repeat(2, 1fr);
  grid-template-rows: repeat(4, 1fr);
  gap: 5mm;
}

/* 4 cards layout: 2 columns, 2 rows */
#fc-workspace .fc-page.grid-4 {
  grid-template-columns: repeat(2, 1fr);
  grid-template-rows: repeat(2, 1fr);
  gap: 7mm;
}

/* Empty state inside A4 */
#fc-workspace .fc-empty-state {
  width: 210mm;
  min-height: 297mm;
  background-color: #FFFFFF;
  border-radius: 8px;
  box-shadow: 0 16px 44px rgba(45, 75, 115, 0.16), 0 3px 12px rgba(0, 0, 0, 0.06);
  border: 1px solid #E2E8F0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  color: #A0AEC0;
  font-family: var(--font-th);
  font-size: 1.15rem;
}

#fc-workspace .fc-empty-state span {
  font-size: 3.5rem;
}

#page-generator #fc-workspace .gen-empty-placeholder,
#page-generator #cw-workspace .gen-empty-placeholder,
#page-generator #ws-workspace .gen-empty-placeholder,
#page-generator #wm-workspace .gen-empty-placeholder,
#page-generator #tr-workspace .gen-empty-placeholder {
  width: min(210mm, 100%);
  min-height: 297mm;
  margin: 0 auto;
  box-sizing: border-box;
  background: #ffffff;
  border: 1px dashed #cbd5e1;
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 2rem;
}

#page-generator #fc-workspace .gen-empty-placeholder p,
#page-generator #cw-workspace .gen-empty-placeholder p,
#page-generator #ws-workspace .gen-empty-placeholder p,
#page-generator #wm-workspace .gen-empty-placeholder p,
#page-generator #tr-workspace .gen-empty-placeholder p {
  margin: 0.35rem 0 0;
  font-family: var(--font-th);
  font-size: 1.2rem;
  font-weight: 700;
  color: #334155;
}

#page-generator .gen-live-category {
  margin: 0.2rem 0 0;
  font-family: var(--font-th);
  font-size: 0.95rem;
  font-weight: 700;
  color: #1e3a5f;
}

#fc-workspace .fc-sheet-blank {
  width: 210mm;
  min-height: 297mm;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  gap: 8mm;
  padding: 10mm;
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  box-shadow: 0 16px 44px rgba(45, 75, 115, 0.16), 0 3px 12px rgba(0, 0, 0, 0.06);
}

#fc-workspace .fc-shell-header {
  flex: 0 0 auto;
}

#fc-workspace .fc-shell-title {
  margin: 0;
  font-family: var(--font-en);
  font-size: 1.6rem;
  color: #1e3a5f;
}

#fc-workspace .fc-header-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

#fc-workspace .fc-header-row .form-input {
  width: auto;
  flex: 1 1 auto;
  min-width: 0;
}

#fc-workspace .fc-header-color {
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  padding: 3px;
  border: 2px solid #E2E8F0;
  border-radius: 12px;
  background: #FFFFFF;
  cursor: pointer;
}

#fc-workspace .fc-header-color::-webkit-color-swatch-wrapper {
  padding: 0;
}

#fc-workspace .fc-header-color::-webkit-color-swatch {
  border: none;
  border-radius: 8px;
}

#fc-workspace #fc-logo-scale-group {
  margin-top: 0.75rem;
}

#fc-workspace .fc-sheet-blank .fc-empty-state {
  width: 100%;
  min-height: 0;
  flex: 1;
  box-shadow: none;
  border: 1px dashed #cbd5e1;
}

/* ===================================================================
   BATCH FLASHCARD (.fc-card)
   =================================================================== */
#fc-workspace .fc-card {
  position: relative;
  overflow: hidden;
  box-sizing: border-box;
  background-color: #FFFFFF;
  border: 1.5px dashed #CBD5E0; /* Scissors cutting line guide */
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  padding: 4px 5px;
  user-select: none;
  transition: background-color 0.2s ease, border-color 0.2s ease;
}

#fc-workspace .fc-card:hover {
  border-color: #94A3B8;
}

/* Background Pattern Layer */
#fc-workspace .fc-card .card-bg-layer {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 1;
  opacity: 0.75;
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  transition: all 0.25s ease;
}

#fc-workspace .fc-card.pattern-bg1 .card-bg-layer {
  opacity: 0.55;
  background-image: radial-gradient(#FF7B90 12%, transparent 14%), radial-gradient(#4FB5FF 12%, transparent 14%);
  background-size: 24px 24px;
  background-position: 0 0, 12px 12px;
}

#fc-workspace .fc-card.pattern-bg2 .card-bg-layer {
  opacity: 0.55;
  background-image: linear-gradient(rgba(139, 92, 246, 0.1) 1.5px, transparent 1.5px),
                    linear-gradient(90deg, rgba(139, 92, 246, 0.1) 1.5px, transparent 1.5px);
  background-size: 18px 18px;
}

/* Color Category Card Patterns */
#fc-workspace .fc-card.pattern-nature-garden .card-bg-layer {
  opacity: 0.45;
  background-image: radial-gradient(#48BB78 14%, transparent 16%), radial-gradient(#ED8936 12%, transparent 14%);
  background-size: 26px 26px;
  background-position: 0 0, 13px 13px;
}

#fc-workspace .fc-card.pattern-nature-forest .card-bg-layer {
  opacity: 0.45;
  background-image: radial-gradient(#38A169 15%, transparent 16%), radial-gradient(#319795 10%, transparent 12%);
  background-size: 22px 22px;
  background-position: 0 0, 11px 11px;
}

#fc-workspace .fc-card.pattern-school-classroom .card-bg-layer {
  opacity: 0.4;
  background-image: linear-gradient(rgba(66, 153, 225, 0.14) 1.5px, transparent 1.5px),
                    linear-gradient(90deg, rgba(66, 153, 225, 0.14) 1.5px, transparent 1.5px);
  background-size: 18px 18px;
}

#fc-workspace .fc-card.pattern-school-stationery .card-bg-layer {
  opacity: 0.45;
  background-image: radial-gradient(#ECC94B 14%, transparent 16%), radial-gradient(#9F7AEA 14%, transparent 16%);
  background-size: 24px 24px;
  background-position: 0 0, 12px 12px;
}

/* Black & White (BW) Category Card Patterns */
#fc-workspace .fc-card.pattern-nature-garden-bw .card-bg-layer {
  opacity: 0.35;
  background-image: radial-gradient(#718096 10%, transparent 12%), radial-gradient(#A0AEC0 8%, transparent 10%);
  background-size: 20px 20px;
  background-position: 0 0, 10px 10px;
}

#fc-workspace .fc-card.pattern-nature-forest-bw .card-bg-layer {
  opacity: 0.35;
  background-image: repeating-linear-gradient(45deg, rgba(113, 128, 150, 0.12) 0, rgba(113, 128, 150, 0.12) 1.5px, transparent 0, transparent 14px);
}

#fc-workspace .fc-card.pattern-school-classroom-bw .card-bg-layer {
  opacity: 0.35;
  background-image: linear-gradient(rgba(113, 128, 150, 0.15) 1px, transparent 1px),
                    linear-gradient(90deg, rgba(113, 128, 150, 0.15) 1px, transparent 1px);
  background-size: 16px 16px;
}

#fc-workspace .fc-card.pattern-school-stationery-bw .card-bg-layer {
  opacity: 0.35;
  background-image: repeating-linear-gradient(-45deg, rgba(113, 128, 150, 0.12) 0, rgba(113, 128, 150, 0.12) 1px, transparent 0, transparent 12px);
}

#fc-workspace .fc-card.pattern-dots-bw .card-bg-layer {
  opacity: 0.38;
  background-image: radial-gradient(#4A5568 10%, transparent 12%);
  background-size: 16px 16px;
}

#fc-workspace .fc-card.pattern-grid-bw .card-bg-layer {
  opacity: 0.35;
  background-image: linear-gradient(rgba(74, 85, 104, 0.15) 1px, transparent 1px),
                    linear-gradient(90deg, rgba(74, 85, 104, 0.15) 1px, transparent 1px);
  background-size: 14px 14px;
}

/* Card Header Tag (position: absolute top edge) */
#fc-workspace .fc-card .card-header-tag {
  position: absolute;
  top: 4px;
  left: 6px;
  z-index: 8;
  padding: 1px 7px;
  background: rgba(255, 94, 126, 0.12);
  border: 1px solid rgba(255, 94, 126, 0.25);
  border-radius: var(--radius-pill);
  color: #FF5E7E;
  font-family: var(--font-en);
  font-weight: 700;
  letter-spacing: 0.2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: center;
  line-height: 1.2;
  pointer-events: none;
}

/* Card Logo (Top Right, position: absolute) */
#fc-workspace .fc-card .card-logo-layer {
  position: absolute;
  top: 4px;
  right: 28px;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  pointer-events: none;
}

#fc-workspace .fc-card .card-logo-img {
  max-height: 18px;
  max-width: 42px;
  width: auto;
  height: auto;
  object-fit: contain;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.1));
  transform: scale(var(--logo-scale, 1));
  transform-origin: top right;
  transition: transform 0.08s ease-out;
}

/* Card Independent Background Settings Button (⚙️ / 🖼️) */
.card-bg-setting-btn {
  position: absolute;
  top: 4px;
  right: 4px;
  z-index: 15;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(4px);
  border: 1px solid #CBD5E1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.72rem;
  cursor: pointer;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
  transition: all 0.2s ease;
  opacity: 0.85;
  padding: 0;
  line-height: 1;
}

.card-bg-setting-btn:hover {
  opacity: 1;
  transform: scale(1.15);
  background: #FFFFFF;
  border-color: #3B82F6;
  box-shadow: 0 2px 8px rgba(59, 130, 246, 0.28);
}

/* Main Image Frame: 75% height / flex: 3 */
#fc-workspace .fc-card .card-image-wrap {
  position: relative;
  z-index: 5;
  width: 100%;
  height: 75%;
  flex: 3 1 75%;
  min-height: 0;
  background: #FFFFFF;
  border-radius: 8px;
  border: 1px solid #EDF2F7;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: visible;
  box-sizing: border-box;
  padding: 4px;
  margin: 0;
  transform: scale(var(--card-box-scale, 1));
  transform-origin: center center;
  transition: transform 0.08s ease-out, background-color 0.2s ease, border-color 0.2s ease;
}

/* White Box Background Disabled (Toggle White Box OFF) */
#fc-workspace .fc-card .card-image-wrap.no-box-bg,
.hide-white-box .fc-card .card-image-wrap {
  background: transparent !important;
  background-color: transparent !important;
  border: none !important;
  box-shadow: none !important;
}

#fc-workspace .fc-card .card-word-img {
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  filter: contrast(104%) brightness(98%);
  user-select: none;
  -webkit-user-drag: none;
  display: block;
  position: relative;
  left: 0px;
  top: 0px;
  cursor: grab;
  touch-action: none;
  transform: scale(var(--card-net-img-scale, var(--card-img-scale, 1)));
  transform-origin: center center;
  transition: transform 0.08s ease-out, opacity 0.2s ease;
}

#fc-workspace .fc-card .card-word-img:active,
#fc-workspace .fc-card .card-word-img.is-dragging {
  cursor: grabbing !important;
  z-index: 25;
  filter: contrast(104%) brightness(98%) drop-shadow(0 4px 12px rgba(0, 0, 0, 0.22));
}

/* Image Hidden (Toggle Image OFF) */
#fc-workspace .fc-card .card-word-img.image-hidden,
#fc-workspace .fc-card .card-img-fallback.image-hidden,
.hide-card-images .fc-card .card-word-img,
.hide-card-images .fc-card .card-img-fallback {
  display: none !important;
  opacity: 0 !important;
  visibility: hidden !important;
}

#fc-workspace .fc-card .card-img-fallback {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  color: #CBD5E0;
}

/* Vocabulary Texts Group: 25% height / flex: 1 */
#fc-workspace .fc-card .card-word-group {
  position: relative;
  z-index: 5;
  width: 100%;
  height: 25%;
  flex: 1 1 25%;
  min-height: 0;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  box-sizing: border-box;
  padding: 1px 0;
  margin: 0;
}

#fc-workspace .fc-card .card-word-en {
  font-family: var(--font-en);
  font-weight: 800;
  color: var(--vocab-text-color, #333333);
  font-size: var(--vocab-text-size, 32px);
  line-height: 1.1;
  margin: 0;
  letter-spacing: -0.3px;
}

#fc-workspace .fc-card .card-word-th {
  font-family: var(--font-th);
  font-weight: 600;
  color: var(--vocab-text-color, #333333);
  margin: 0;
  line-height: 1.1;
}

/* --- SPECIFIC RULES FOR GRID-8 (8 CARDS / A4 PAGE) --- */
#fc-workspace .grid-8 .fc-card {
  padding: 3px 5px;
}

#fc-workspace .grid-8 .fc-card .card-header-tag {
  font-size: 0.6rem;
  max-width: 95px;
  padding: 1px 5px;
  top: 3px;
  left: 5px;
}

#fc-workspace .grid-8 .fc-card .card-logo-layer {
  top: 3px;
  right: 26px;
}

#fc-workspace .grid-8 .fc-card .card-bg-setting-btn {
  top: 3px;
  right: 3px;
  width: 20px;
  height: 20px;
  font-size: 0.68rem;
}

#fc-workspace .grid-8 .fc-card .card-logo-img {
  max-height: 14px;
  max-width: 34px;
}

#fc-workspace .grid-8 .fc-card .card-image-wrap {
  width: 100%;
  height: 75%;
  flex: 3 1 75%;
  padding: 2px 4px;
  border-radius: 6px;
}

#fc-workspace .grid-8 .fc-card .card-word-group {
  width: 100%;
  height: 25%;
  flex: 1 1 25%;
}

#fc-workspace .grid-8 .fc-card .card-word-en {
  font-size: var(--vocab-text-size, 32px);
  line-height: 1.1;
}

#fc-workspace .grid-8 .fc-card .card-word-th {
  font-size: 0.88rem;
  line-height: 1.1;
}

/* --- SPECIFIC RULES FOR GRID-4 (4 CARDS / A4 PAGE) --- */
#fc-workspace .grid-4 .fc-card {
  padding: 6px 8px;
  border-radius: 14px;
}

#fc-workspace .grid-4 .fc-card .card-header-tag {
  font-size: 0.8rem;
  max-width: 160px;
  padding: 2px 9px;
  top: 6px;
  left: 8px;
}

#fc-workspace .grid-4 .fc-card .card-logo-layer {
  top: 6px;
  right: 34px;
}

#fc-workspace .grid-4 .fc-card .card-bg-setting-btn {
  top: 6px;
  right: 6px;
  width: 25px;
  height: 25px;
  font-size: 0.82rem;
}

#fc-workspace .grid-4 .fc-card .card-logo-img {
  max-height: 24px;
  max-width: 50px;
}

#fc-workspace .grid-4 .fc-card .card-image-wrap {
  width: 100%;
  height: 75%;
  flex: 3 1 75%;
  padding: 8px 12px;
  border-radius: 12px;
}

#fc-workspace .grid-4 .fc-card .card-word-group {
  width: 100%;
  height: 25%;
  flex: 1 1 25%;
}

#fc-workspace .grid-4 .fc-card .card-word-en {
  font-size: var(--vocab-text-size, 32px);
  line-height: 1.15;
}

#fc-workspace .grid-4 .fc-card .card-word-th {
  font-size: 1.35rem;
  line-height: 1.15;
}

.preview-footer-tips {
  max-width: 794px;
  width: 100%;
}

.tip-card {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  background: rgba(255, 255, 255, 0.85);
  border: 1.5px solid #E2E8F0;
  border-radius: var(--radius-md);
  padding: 0.75rem 1rem;
  font-family: var(--font-th);
  font-size: 0.86rem;
  color: #4A5568;
  line-height: 1.5;
  box-shadow: var(--shadow-sm);
}

.tip-icon {
  font-size: 1.25rem;
  flex-shrink: 0;
}

/* ===================================================================
   COMING SOON PLACEHOLDER (Mini Games & Ebook Library)
   =================================================================== */

.placeholder-hero {
  position: relative;
  background: #FFFFFF;
  border-radius: var(--radius-lg);
  border: 3px dashed #CBD5E0;
  padding: 3.5rem 2rem;
  text-align: center;
  max-width: 860px;
  margin: 1.5rem auto 0;
  box-shadow: var(--shadow-md);
  overflow: hidden;
}

.games-hero {
  border-color: #FED7AA;
  background: linear-gradient(180deg, #FFFFFF 0%, #FFFBF5 100%);
}

.library-hero {
  border-color: #DDD6FE;
  background: linear-gradient(180deg, #FFFFFF 0%, #F8F7FF 100%);
}

/* Floating icons in placeholder */
.placeholder-floating-decorations {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.floating-p-icon {
  position: absolute;
  opacity: 0.35;
  user-select: none;
  animation: floatSlow 8s infinite alternate ease-in-out;
}

.icon-g1 { top: 12%; left: 8%; font-size: 2.5rem; }
.icon-g2 { top: 15%; right: 10%; font-size: 2.8rem; animation-delay: 1.5s; }
.icon-g3 { bottom: 12%; left: 10%; font-size: 2.4rem; animation-delay: 2.5s; }
.icon-g4 { bottom: 15%; right: 8%; font-size: 2.2rem; animation-delay: 3.5s; }

.icon-l1 { top: 12%; left: 8%; font-size: 2.5rem; }
.icon-l2 { top: 15%; right: 10%; font-size: 2.8rem; animation-delay: 1.5s; }
.icon-l3 { bottom: 12%; left: 10%; font-size: 2.4rem; animation-delay: 2.5s; }
.icon-l4 { bottom: 15%; right: 8%; font-size: 2.2rem; animation-delay: 3.5s; }

/* Status Badge */
.placeholder-status-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  background: #FFF;
  padding: 0.4rem 1.2rem;
  border-radius: var(--radius-pill);
  box-shadow: var(--shadow-sm);
  font-family: var(--font-th);
  font-size: 0.92rem;
  font-weight: 600;
  color: #4A5568;
  border: 1.5px solid #E2E8F0;
  margin-bottom: 1.25rem;
}

.pulse-status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #10B981;
  box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7);
  animation: pulseDotGreen 2s infinite;
}

@keyframes pulseDotGreen {
  0% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7); }
  70% { transform: scale(1.15); box-shadow: 0 0 0 8px rgba(16, 185, 129, 0); }
  100% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); }
}

.placeholder-hero-icon {
  font-size: 4.8rem;
  margin-bottom: 0.8rem;
  animation: bounceSlow 3s infinite ease-in-out;
}

@keyframes bounceSlow {
  0%, 100% { transform: translateY(0) scale(1); }
  50% { transform: translateY(-16px) scale(1.08); }
}

.placeholder-main-title {
  font-family: var(--font-th);
  font-size: clamp(1.8rem, 4.5vw, 2.6rem);
  font-weight: 700;
  color: #1A202C;
  margin-bottom: 0.6rem;
}

.placeholder-coming-soon-pill {
  display: inline-block;
  background: linear-gradient(135deg, #FFE5EC, #FFF0EB);
  color: #FF5E7E;
  font-family: var(--font-en);
  font-size: 1.15rem;
  font-weight: 700;
  padding: 0.45rem 1.4rem;
  border-radius: var(--radius-pill);
  border: 2px solid #FFD4DB;
  box-shadow: 0 4px 12px rgba(255, 94, 126, 0.15);
  margin-bottom: 1rem;
}

.placeholder-lead-text {
  font-family: var(--font-th);
  font-size: clamp(1rem, 2.2vw, 1.15rem);
  color: var(--text-thai);
  max-width: 620px;
  margin: 0 auto 2.5rem;
  line-height: 1.7;
}

/* Planned Roadmap Cards Grid */
.planned-cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 1.25rem;
  margin-top: 1rem;
  text-align: left;
}

.planned-item-card {
  background: #FFFFFF;
  border-radius: var(--radius-md);
  padding: 1.35rem 1.15rem;
  box-shadow: var(--shadow-sm);
  border: 2px solid #EDF2F7;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  transition: var(--transition-bounce);
}

.planned-item-card:hover {
  transform: translateY(-5px);
  box-shadow: var(--shadow-md);
  border-color: #CBD5E0;
}

.planned-card-icon {
  font-size: 2rem;
  margin-bottom: 0.3rem;
}

/* ===================================================================
   MINI GAMES HUB (scoped to #page-games)
   =================================================================== */

#page-games .mg-hub-container {
  width: 100%;
  margin-top: 0.5rem;
}

#page-games .mg-hub-header {
  text-align: center;
  margin-bottom: 0.25rem;
  padding: 0.5rem 1rem 0;
}

#page-games .mg-hub-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: #FFFFFF;
  color: #0284C7;
  font-family: var(--font-en);
  font-size: 0.92rem;
  font-weight: 700;
  letter-spacing: 0.3px;
  padding: 0.35rem 0.95rem;
  border-radius: var(--radius-pill);
  border: 1.5px solid #BAE6FD;
  box-shadow: var(--shadow-sm);
  margin-bottom: 0.75rem;
}

#page-games .mg-hub-title {
  font-family: var(--font-th);
  font-size: clamp(1.7rem, 4vw, 2.35rem);
  font-weight: 700;
  color: #1A202C;
  margin-bottom: 0.35rem;
}

#page-games .mg-hub-lead {
  font-family: var(--font-th);
  font-size: clamp(0.95rem, 2vw, 1.08rem);
  color: var(--text-thai);
  max-width: 560px;
  margin: 0 auto;
  line-height: 1.65;
}

#page-games .mg-hub-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 20px;
  padding: 20px;
}

#page-games .mg-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  background: #FFFFFF;
  border-radius: 15px;
  box-shadow: 0 6px 16px rgba(60, 90, 130, 0.08);
  padding: 1.35rem 1rem 1.15rem;
  border: 1.5px solid #F1F5F9;
  transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.25s ease;
}

#page-games .mg-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 14px 28px rgba(50, 80, 120, 0.16);
}

#page-games .mg-card-icon {
  font-size: 3.1rem;
  line-height: 1;
  width: 84px;
  height: 84px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 24px;
  background: linear-gradient(160deg, #FFF5F8 0%, #EBF6FF 100%);
  margin-bottom: 0.85rem;
}

#page-games .mg-card:nth-child(2) .mg-card-icon { background: linear-gradient(160deg, #FFF7ED 0%, #FEF3C7 100%); }
#page-games .mg-card:nth-child(3) .mg-card-icon { background: linear-gradient(160deg, #ECFDF5 0%, #D1FAE5 100%); }
#page-games .mg-card:nth-child(4) .mg-card-icon { background: linear-gradient(160deg, #F5F3FF 0%, #EDE9FE 100%); }
#page-games .mg-card:nth-child(5) .mg-card-icon { background: linear-gradient(160deg, #FFF1F2 0%, #FFE4E6 100%); }
#page-games .mg-card:nth-child(6) .mg-card-icon { background: linear-gradient(160deg, #EFF6FF 0%, #DBEAFE 100%); }
#page-games .mg-card:nth-child(7) .mg-card-icon { background: linear-gradient(160deg, #F0FDFA 0%, #CCFBF1 100%); }
#page-games .mg-card:nth-child(8) .mg-card-icon { background: linear-gradient(160deg, #FFFBEB 0%, #FDE68A 100%); }
#page-games .mg-card:nth-child(9) .mg-card-icon { background: linear-gradient(160deg, #FDF2F8 0%, #FBCFE8 100%); }
#page-games .mg-card:nth-child(10) .mg-card-icon { background: linear-gradient(160deg, #F0FDF4 0%, #BBF7D0 100%); }
#page-games .mg-card:nth-child(11) .mg-card-icon { background: linear-gradient(160deg, #FFFBEB 0%, #FDE68A 100%); }
#page-games .mg-card:nth-child(12) .mg-card-icon { background: linear-gradient(160deg, #EEF2FF 0%, #C7D2FE 100%); }
#page-games .mg-card:nth-child(13) .mg-card-icon { background: linear-gradient(160deg, #FCE7F3 0%, #FBCFE8 100%); }

#page-games .mg-card-vip {
  position: relative;
  border-color: #FDE68A;
  background: linear-gradient(180deg, #FFFDF5 0%, #FFFFFF 100%);
}

#page-games .mg-vip-badge {
  position: absolute;
  top: 10px;
  right: 10px;
  padding: 0.22rem 0.6rem;
  border-radius: 999px;
  background: linear-gradient(135deg, #FEF08A 0%, #F59E0B 100%);
  color: #78350F;
  font-family: var(--font-en);
  font-size: 0.72rem;
  font-weight: 800;
  box-shadow: 0 3px 0 #D97706;
}

#page-games .mg-card-title-en {
  font-family: var(--font-en);
  font-size: 1.2rem;
  font-weight: 700;
  color: #1A202C;
  line-height: 1.2;
  margin-bottom: 0.2rem;
}

#page-games .mg-card-title-th {
  font-family: var(--font-th);
  font-size: 0.92rem;
  font-weight: 600;
  color: #64748B;
  line-height: 1.4;
  margin-bottom: 1rem;
}

#page-games .mg-play-btn {
  display: block;
  margin-top: auto;
  width: 100%;
  border: none;
  cursor: pointer;
  font-family: var(--font-th);
  font-size: 0.95rem;
  font-weight: 700;
  color: #FFFFFF;
  text-align: center;
  text-decoration: none;
  background: linear-gradient(135deg, #FF7B90 0%, #FF4D6D 100%);
  border-radius: var(--radius-pill);
  padding: 0.62rem 0.8rem;
  box-shadow: 0 4px 0 #E11D48;
  transition: transform 0.15s ease, box-shadow 0.15s ease, filter 0.15s ease;
}

#page-games a.mg-play-btn:visited {
  color: #FFFFFF;
}

#page-games .mg-play-btn:hover {
  filter: brightness(1.05);
  transform: translateY(-1px);
}

#page-games .mg-play-btn:active {
  transform: translateY(2px);
  box-shadow: 0 2px 0 #E11D48;
}

@media (min-width: 1180px) {
  #page-games .mg-hub-grid {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }
}

@media (max-width: 520px) {
  #page-games .mg-hub-grid {
    grid-template-columns: 1fr;
    gap: 16px;
    padding: 12px 4px 20px;
  }
}

/* ===================================================================
   MINI GAME: FLASHCARD (scoped to #page-games)
   =================================================================== */

#page-games .mg-flashcard-container {
  display: none;
}

#page-games.mg-flashcard-playing .mg-hub-container {
  display: none;
}

#page-games.mg-flashcard-playing .mg-flashcard-container {
  display: block;
}

#page-games .mg-flashcard-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px 16px;
  background: #FFFFFF;
  border-radius: 18px;
  padding: 14px 16px;
  box-shadow: 0 6px 16px rgba(60, 90, 130, 0.08);
  margin-bottom: 18px;
}

#page-games .mg-flashcard-back {
  border: 1.5px solid #FBCFE8;
  background: #FFF1F2;
  color: #BE123C;
  font-family: var(--font-th);
  font-size: 0.95rem;
  font-weight: 700;
  border-radius: var(--radius-pill);
  padding: 0.55rem 0.95rem;
  cursor: pointer;
}

#page-games .mg-flashcard-back:hover {
  background: #FFE4E6;
}

#page-games .mg-flashcard-title {
  font-family: var(--font-en);
  font-size: 1.7rem;
  font-weight: 700;
  color: #1A202C;
  margin-right: auto;
}

#page-games .mg-flashcard-category-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-th);
  font-weight: 700;
  color: #475569;
}

#page-games .mg-flashcard-category {
  font-family: var(--font-th);
  font-size: 0.95rem;
  font-weight: 600;
  color: #1A202C;
  background: #F8FAFC;
  border: 1.5px solid #E2E8F0;
  border-radius: 12px;
  padding: 0.5rem 0.7rem;
  min-width: 180px;
  cursor: pointer;
}

#page-games .mg-flashcard-start {
  border: none;
  cursor: pointer;
  font-family: var(--font-th);
  font-size: 0.95rem;
  font-weight: 700;
  color: #FFFFFF;
  background: linear-gradient(135deg, #FF7B90 0%, #FF4D6D 100%);
  border-radius: var(--radius-pill);
  padding: 0.62rem 1.1rem;
  box-shadow: 0 4px 0 #E11D48;
}

#page-games .mg-flashcard-start:hover {
  filter: brightness(1.05);
}

#page-games .mg-flashcard-start:active {
  transform: translateY(2px);
  box-shadow: 0 2px 0 #E11D48;
}

#page-games .mg-flashcard-board {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 20px;
  padding: 4px 2px 12px;
}

#page-games .mg-card-item {
  height: 320px;
  padding: 0;
  border: none;
  background: transparent;
  cursor: pointer;
  perspective: 1000px;
}

#page-games .mg-flashcard-inner {
  display: block;
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transition: transform 0.65s cubic-bezier(0.4, 0.2, 0.2, 1);
}

#page-games .mg-card-item.flipped .mg-flashcard-inner {
  transform: rotateY(180deg);
}

#page-games .mg-flashcard-face-front,
#page-games .mg-flashcard-face-back {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border-radius: 18px;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  overflow: hidden;
}

#page-games .mg-flashcard-face-front {
  background:
    radial-gradient(circle at 18% 22%, rgba(255, 255, 255, 0.35) 0 18px, transparent 19px),
    radial-gradient(circle at 80% 75%, rgba(255, 255, 255, 0.22) 0 26px, transparent 27px),
    linear-gradient(145deg, #FF8FA3 0%, #FF6B8A 42%, #7DD3FC 100%);
  color: #FFFFFF;
  box-shadow: 0 10px 22px rgba(255, 77, 109, 0.22);
}

#page-games .mg-flashcard-front-logo {
  width: min(58%, 148px);
  height: auto;
  max-height: 46%;
  object-fit: contain;
  filter: drop-shadow(0 8px 14px rgba(190, 24, 70, 0.22));
}

#page-games .mg-flashcard-face-back {
  background: #FFFFFF;
  transform: rotateY(180deg);
  justify-content: flex-start;
  padding: 16px 14px 4.25rem;
  box-shadow: 0 10px 22px rgba(60, 90, 130, 0.12);
  border: 1.5px solid #F1F5F9;
}

#page-games .mg-flashcard-image-wrap {
  flex: 1;
  width: 100%;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(180deg, #F8FAFC 0%, #FFF7FB 100%);
  border-radius: 14px;
  overflow: hidden;
}

#page-games .mg-flashcard-image {
  width: 100%;
  height: 100%;
  object-fit: contain;
  padding: 8px;
}

#page-games .mg-flashcard-image-fallback {
  font-size: 3rem;
}

#page-games .mg-flashcard-word-en {
  font-family: var(--font-en);
  font-size: 1.55rem;
  font-weight: 700;
  color: #1A202C;
  line-height: 1.15;
  margin-top: 10px;
  text-align: center;
}

#page-games .mg-flashcard-word-th {
  font-family: var(--font-th);
  font-size: 0.98rem;
  font-weight: 600;
  color: #64748B;
  text-align: center;
  margin-top: 2px;
}

#page-games .mg-flashcard-speak {
  position: absolute;
  right: 1rem;
  bottom: 1rem;
  z-index: 10;
  margin-top: 0;
  width: 48px;
  height: 48px;
  border: none;
  border-radius: 999px;
  background: #FFF1F4;
  color: #FF4D6D;
  font-size: 1.3rem;
  line-height: 1;
  cursor: pointer;
  flex-shrink: 0;
  box-shadow: 0 3px 0 #FBCFE8;
}

#page-games .mg-flashcard-speak:hover {
  filter: brightness(1.04);
  transform: translateY(-1px);
}

#page-games .mg-flashcard-speak:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 #FBCFE8;
}

#page-games .mg-flashcard-empty {
  grid-column: 1 / -1;
  text-align: center;
  font-family: var(--font-th);
  color: #64748B;
  background: #FFFFFF;
  border-radius: 16px;
  padding: 2rem 1rem;
}

@media (max-width: 860px) {
  #page-games .mg-flashcard-board {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  #page-games .mg-card-item {
    height: 280px;
  }
}

@media (max-width: 560px) {
  #page-games .mg-flashcard-title {
    margin-right: 0;
    width: 100%;
    order: -1;
  }

  #page-games .mg-flashcard-category {
    min-width: 0;
    width: 140px;
  }

  #page-games .mg-flashcard-board {
    grid-template-columns: 1fr;
    justify-items: center;
  }

  #page-games .mg-card-item {
    width: 100%;
    max-width: 24rem;
    height: auto;
    aspect-ratio: 3 / 4;
  }
}

/* ===================================================================
   MINI GAME: CROSSWORD (scoped to #page-games)
   =================================================================== */

#page-games .mg-crossword-container {
  display: none;
  flex-direction: column;
  gap: 14px;
  width: 100%;
}

#page-games.mg-crossword-playing .mg-hub-container {
  display: none;
}

#page-games.mg-crossword-playing .mg-crossword-container {
  display: flex;
}

#page-games .mg-cw-topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px 14px;
  background: #FFFFFF;
  border-radius: 18px;
  padding: 12px 16px;
  box-shadow: 0 6px 16px rgba(60, 90, 130, 0.08);
}

#page-games .mg-crossword-container .mg-game-logo {
  height: 45px;
  width: auto;
  margin-right: 15px;
  border-radius: 12px;
  object-fit: contain;
  background: #FFFFFF;
  box-shadow: 0 3px 10px rgba(60, 90, 130, 0.16);
  flex-shrink: 0;
}

#page-games .mg-cw-back {
  border: 1.5px solid #FDE68A;
  background: #FFFBEB;
  color: #B45309;
  font-family: var(--font-th);
  font-size: 0.95rem;
  font-weight: 700;
  border-radius: var(--radius-pill);
  padding: 0.55rem 0.95rem;
  cursor: pointer;
}

#page-games .mg-cw-back:hover {
  background: #FEF3C7;
}

#page-games .mg-cw-title {
  font-family: var(--font-en);
  font-size: 1.7rem;
  font-weight: 700;
  color: #1A202C;
  margin-right: auto;
}

#page-games .mg-cw-category-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-th);
  font-weight: 700;
  color: #475569;
}

#page-games .mg-cw-category,
#page-games .mg-cw-rounds {
  font-family: var(--font-th);
  font-size: 0.95rem;
  font-weight: 600;
  color: #1A202C;
  background: #F8FAFC;
  border: 1.5px solid #E2E8F0;
  border-radius: 12px;
  padding: 0.5rem 0.7rem;
  min-width: 160px;
  cursor: pointer;
}

#page-games .mg-cw-rounds {
  min-width: 110px;
}

#page-games .mg-cw-timer {
  font-family: var(--font-en);
  font-size: 1.45rem;
  font-weight: 700;
  letter-spacing: 0.5px;
  color: #9A3412;
  background: #FFF7ED;
  border: 1.5px solid #FDBA74;
  border-radius: 12px;
  padding: 0.28rem 0.75rem;
  min-width: 92px;
  text-align: center;
}

#page-games .mg-cw-round-label {
  font-family: var(--font-th);
  font-weight: 700;
  color: #0369A1;
  background: #E0F2FE;
  border-radius: var(--radius-pill);
  padding: 0.4rem 0.75rem;
}

#page-games .mg-cw-btn-bgm {
  width: 48px;
  height: 48px;
  border: none;
  border-radius: 16px;
  background: #ECFEFF;
  font-size: 1.3rem;
  cursor: pointer;
  flex-shrink: 0;
}

#page-games .mg-cw-btn-bgm[aria-pressed="true"] {
  background: #E2E8F0;
}

#page-games .mg-cw-history-btn {
  border: 1.5px solid #BAE6FD;
  background: #F0F9FF;
  color: #0369A1;
  font-family: var(--font-th);
  font-size: 0.92rem;
  font-weight: 700;
  border-radius: var(--radius-pill);
  min-height: 48px;
  padding: 0.55rem 0.9rem;
  cursor: pointer;
}

#page-games .mg-cw-history-btn:hover {
  background: #E0F2FE;
}

#page-games .mg-cw-restart {
  border: none;
  cursor: pointer;
  font-family: var(--font-th);
  font-size: 0.95rem;
  font-weight: 700;
  color: #FFFFFF;
  background: linear-gradient(135deg, #F59E0B 0%, #F97316 100%);
  border-radius: var(--radius-pill);
  padding: 0.62rem 1.1rem;
  box-shadow: 0 4px 0 #C2410C;
}

#page-games .mg-cw-restart:hover {
  filter: brightness(1.05);
}

#page-games .mg-cw-restart:active {
  transform: translateY(2px);
  box-shadow: 0 2px 0 #C2410C;
}

#page-games .mg-cw-stage {
  display: grid;
  grid-template-columns: minmax(300px, 460px) minmax(0, 1fr);
  gap: 16px;
  align-items: stretch;
  min-height: 440px;
}

#page-games .mg-cw-hints {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  align-content: start;
  background: #FFFFFF;
  border-radius: 18px;
  padding: 12px;
  box-shadow: 0 6px 16px rgba(60, 90, 130, 0.08);
}

#page-games .mg-cw-hint-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  background: linear-gradient(180deg, #FFFBEB 0%, #FFFFFF 100%);
  border: 1.5px solid #FDE68A;
  border-radius: 14px;
  padding: 8px;
  min-width: 0;
}

#page-games .mg-cw-hint-figure {
  position: relative;
  width: 100%;
  height: clamp(140px, 18vh, 230px);
  display: flex;
  align-items: center;
  justify-content: center;
  background: #FFFFFF;
  border-radius: 12px;
  overflow: hidden;
}

#page-games .mg-cw-hints img,
#page-games .mg-cw-hint-image {
  width: auto;
  max-width: clamp(150px, 16vw, 240px);
  height: auto;
  max-height: 100%;
  object-fit: contain;
  padding: 6px;
}

#page-games .mg-cw-hint-fallback {
  font-size: 2rem;
}

#page-games .mg-cw-hint-number {
  position: absolute;
  top: 4px;
  left: 4px;
  min-width: 28px;
  height: 22px;
  padding: 0 6px;
  border-radius: 999px;
  background: #F97316;
  color: #FFFFFF;
  font-family: var(--font-en);
  font-size: 0.75rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}

#page-games .mg-cw-hint-btn {
  border: none;
  cursor: pointer;
  font-family: var(--font-en);
  font-size: 0.86rem;
  font-weight: 700;
  color: #9A3412;
  background: #FFEDD5;
  border-radius: var(--radius-pill);
  padding: 0.32rem 0.7rem;
  box-shadow: 0 2px 0 #FDBA74;
}

#page-games .mg-cw-hint-btn:active {
  transform: translateY(1px);
  box-shadow: 0 1px 0 #FDBA74;
}

#page-games .mg-cw-hint-reveal {
  display: none;
  text-align: center;
  line-height: 1.25;
}

#page-games .mg-cw-hint-card.is-open .mg-cw-hint-reveal {
  display: block;
}

#page-games .mg-cw-hint-en {
  display: block;
  font-family: var(--font-en);
  font-size: 0.95rem;
  font-weight: 700;
  color: #1A202C;
}

#page-games .mg-cw-hint-th {
  display: block;
  font-family: var(--font-th);
  font-size: 0.82rem;
  font-weight: 600;
  color: #64748B;
}

#page-games .mg-cw-empty {
  grid-column: 1 / -1;
  text-align: center;
  font-family: var(--font-th);
  color: #64748B;
  padding: 1.5rem 0.5rem;
}

#page-games .mg-cw-board-area {
  position: relative;
  min-height: 0;
  height: auto;
  border-radius: 20px;
  overflow-x: auto;
  overflow-y: auto;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  background-color: #FFF7ED;
  background-size: cover;
  background-position: center;
  box-shadow: 0 8px 20px rgba(60, 90, 130, 0.1);
}

#page-games .mg-cw-board-scrim {
  position: absolute;
  inset: 0;
  background: rgba(255, 255, 255, 0.55);
}

#page-games .mg-cw-grid-fit {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 100%;
  display: flex;
  justify-content: center;
  overflow: visible;
}

#page-games .mg-cw-grid {
  position: relative;
  z-index: 1;
  display: grid;
  gap: 3px;
  padding: 14px;
  margin: 8px auto;
  background: rgba(255, 255, 255, 0.62);
  border-radius: 18px;
  box-shadow: 0 8px 24px rgba(30, 58, 95, 0.08);
}

#page-games .mg-cw-cell {
  width: var(--mg-cw-cell, 40px);
  height: var(--mg-cw-cell, 40px);
  border-radius: 8px;
  position: relative;
}

#page-games .mg-cw-cell-block {
  background: transparent;
}

#page-games .mg-cw-cell-input {
  display: block;
  width: 100%;
  height: 100%;
  box-sizing: border-box;
  margin: 0;
  padding: 10px 0 0;
  background: #FFFFFF;
  border: 2px solid #7DD3FC;
  border-radius: 8px;
  color: #0F172A;
  font-family: var(--font-en);
  font-size: 18px;
  font-weight: 700;
  line-height: 1;
  text-align: center;
  text-transform: uppercase;
  caret-color: transparent;
  cursor: pointer;
  touch-action: manipulation;
}

#page-games .mg-cw-cell-input:hover {
  border-color: #0284C7;
}

#page-games .mg-cw-cell-path {
  background: #E0F2FE;
}

#page-games .mg-cw-cell-active {
  background: #FDE68A;
  border-color: #F59E0B;
  box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.35);
}

#page-games .mg-cw-cell-match {
  color: #047857;
}

#page-games .mg-cw-cell-miss {
  color: #BE123C;
}

#page-games .mg-cw-cell-input.locked,
#page-games .mg-cw-cell-input.locked.mg-cw-cell-active,
#page-games .mg-cw-cell-input.locked.mg-cw-cell-path {
  background: #86EFAC;
  border-color: #15803D;
  color: #14532D;
  box-shadow: none;
  cursor: default;
  pointer-events: none;
}

#page-games .mg-cw-cell-input:focus {
  outline: none;
}

#page-games .mg-cw-num {
  position: absolute;
  z-index: 2;
  pointer-events: none;
  top: 1px;
  left: 3px;
  font-family: var(--font-en);
  font-size: 0.62rem;
  font-weight: 700;
  line-height: 1;
  color: #0369A1;
}

#page-games .mg-cw-letter {
  line-height: 1;
  margin-top: 6px;
}

#page-games .mg-cw-dir-popup {
  position: absolute;
  z-index: 4;
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: #FFFFFF;
  border: 1.5px solid #FDE68A;
  border-radius: 14px;
  padding: 8px;
  box-shadow: 0 10px 24px rgba(30, 41, 59, 0.18);
}

#page-games .mg-cw-dir-popup[hidden] {
  display: none;
}

#page-games .mg-cw-dir-btn {
  border: none;
  cursor: pointer;
  font-family: var(--font-th);
  font-size: 0.92rem;
  font-weight: 700;
  color: #9A3412;
  background: #FFF7ED;
  border-radius: 10px;
  padding: 0.45rem 0.7rem;
  white-space: nowrap;
}

#page-games .mg-cw-dir-btn:hover {
  background: #FFEDD5;
}

#page-games .mg-cw-win {
  position: absolute;
  z-index: 3;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  margin: 0;
  font-family: var(--font-th);
  font-weight: 700;
  color: #047857;
  background: rgba(236, 253, 245, 0.95);
  border-radius: var(--radius-pill);
  padding: 0.4rem 0.85rem;
  white-space: nowrap;
}

#page-games .mg-cw-keyboard {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  background: #FFFFFF;
  border-radius: 18px;
  padding: 12px 10px 14px;
  box-shadow: 0 6px 16px rgba(60, 90, 130, 0.08);
}

#page-games .mg-cw-key-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
}

#page-games .mg-cw-key {
  min-width: clamp(52px, 5vw, 76px);
  height: clamp(56px, 7vh, 78px);
  padding: 0 12px;
  border: none;
  border-radius: 14px;
  background: #F8FAFC;
  color: #0F172A;
  font-family: var(--font-en);
  font-size: clamp(1.25rem, 2vw, 1.75rem);
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 4px 0 #CBD5E1;
}

#page-games .mg-cw-key:hover {
  background: #E0F2FE;
}

#page-games .mg-cw-key:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 #CBD5E1;
}

#page-games .mg-cw-key-back {
  min-width: clamp(88px, 8vw, 120px);
  font-family: var(--font-th);
  font-size: clamp(0.95rem, 1.4vw, 1.15rem);
  background: #FFF1F2;
  color: #BE123C;
  box-shadow: 0 4px 0 #FECDD3;
}

#page-games #mg-cw-celebration-canvas {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  pointer-events: none;
  z-index: 999;
  display: none;
}

#page-games #mg-cw-celebration-canvas.is-on {
  display: block;
}

#page-games .mg-cw-modal {
  position: fixed;
  inset: 0;
  z-index: 1001;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(15, 23, 42, 0.45);
  padding: 18px;
}

#page-games .mg-cw-modal.mg-cw-modal-celebrate {
  animation: mg-cw-modal-fade 0.55s ease;
}

@keyframes mg-cw-modal-fade {
  from { opacity: 0; }
  to { opacity: 1; }
}

#page-games .mg-cw-modal[hidden] {
  display: none;
}

#page-games .mg-cw-modal-card {
  width: min(520px, 100%);
  background: #FFFFFF;
  border-radius: 20px;
  padding: 22px 20px 18px;
  box-shadow: 0 18px 40px rgba(15, 23, 42, 0.2);
}

#page-games .mg-cw-history-card {
  width: min(760px, 100%);
}

#page-games .mg-cw-modal-title {
  font-family: var(--font-th);
  font-size: 1.45rem;
  color: #1A202C;
  margin-bottom: 12px;
}

#page-games .mg-cw-result-line {
  font-family: var(--font-th);
  font-size: 1.05rem;
  color: #334155;
  margin-bottom: 6px;
}

#page-games .mg-cw-name-label {
  display: block;
  margin-top: 12px;
  font-family: var(--font-th);
  font-weight: 700;
  color: #475569;
}

#page-games .mg-cw-player-name {
  width: 100%;
  margin-top: 6px;
  border: 1.5px solid #E2E8F0;
  border-radius: 12px;
  padding: 0.6rem 0.75rem;
  font-family: var(--font-th);
  font-size: 1rem;
}

#page-games .mg-cw-modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 16px;
}

#page-games .mg-cw-save-btn,
#page-games .mg-cw-modal-close {
  border: none;
  cursor: pointer;
  font-family: var(--font-th);
  font-weight: 700;
  border-radius: var(--radius-pill);
  padding: 0.55rem 1rem;
}

#page-games .mg-cw-save-btn {
  color: #FFFFFF;
  background: linear-gradient(135deg, #22C55E 0%, #16A34A 100%);
  box-shadow: 0 3px 0 #166534;
}

#page-games .mg-cw-save-btn:disabled {
  background: #86EFAC;
  box-shadow: none;
  cursor: default;
}

#page-games .mg-cw-modal-close {
  color: #475569;
  background: #F1F5F9;
}

#page-games .mg-cw-history-table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--font-th);
  font-size: 0.92rem;
}

#page-games .mg-cw-history-table th,
#page-games .mg-cw-history-table td {
  text-align: left;
  padding: 0.45rem 0.4rem;
  border-bottom: 1px solid #E2E8F0;
}

#page-games .mg-cw-history-table th {
  color: #0369A1;
}

#page-games .mg-cw-history-note {
  margin: 0 0 0.6rem;
  text-align: center;
  font-family: var(--font-th);
  font-weight: 700;
  color: #64748B;
}

#page-games .mg-cw-history-list {
  max-height: min(52vh, 420px);
  overflow: auto;
}

#page-games .mg-cw-history-empty {
  font-family: var(--font-th);
  color: #64748B;
  text-align: center;
  padding: 1.2rem 0.4rem;
}

@media (max-width: 860px) {
  #page-games .mg-cw-stage {
    grid-template-columns: 1fr;
  }

  #page-games .mg-cw-hints {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  #page-games .mg-cw-title {
    margin-right: 0;
  }
}

@media (max-width: 768px) {
  body:has(#page-games.mg-crossword-playing) {
    height: auto;
    overflow-x: hidden;
    overflow-y: auto;
  }

  #page-games.mg-crossword-playing,
  #page-games .mg-crossword-container,
  #page-games .mg-cw-stage,
  #page-games .mg-cw-board-area {
    overflow-x: auto;
    overflow-y: visible;
    max-width: 100%;
    max-height: none;
    height: auto;
  }

  #page-games .mg-cw-keyboard {
    display: none;
  }

  #page-games .mg-cw-stage,
  #page-games .mg-cw-board-area {
    min-height: 0;
  }

  #page-games .mg-cw-hints {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    min-width: 0;
  }

  #page-games .mg-cw-hint-card,
  #page-games .mg-cw-hint-figure {
    min-width: 0;
    max-width: 100%;
  }

  #page-games .mg-cw-hint-figure {
    height: 76px;
  }

  #page-games .mg-cw-hints img,
  #page-games .mg-cw-hint-image {
    max-width: 100%;
  }

  #page-games .mg-cw-cell-input {
    font-size: 18px;
  }
}

@media (max-width: 560px) {
  #page-games .mg-cw-hints {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  #page-games .mg-cw-category {
    min-width: 0;
    width: 140px;
  }

  #page-games .mg-crossword-container .mg-game-logo {
    margin-right: 0;
  }
}

/* ===================================================================
   MINI GAME: WORD BUBBLE SHOOTER (scoped to #page-games)
   =================================================================== */

#page-games .mg-bs-container {
  display: none;
  flex-direction: column;
  gap: 10px;
  width: 100%;
  max-width: 1180px;
  margin: 0 auto;
}

#page-games.mg-bs-playing .mg-hub-container {
  display: none;
}

#page-games.mg-bs-playing .mg-bs-container {
  display: flex;
}

#page-games .mg-bs-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 14px;
  background: #FFFFFF;
  border-radius: 20px;
  padding: 10px 16px;
  box-shadow: 0 6px 18px rgba(60, 90, 130, 0.1);
  border: 2px solid #FEF08A;
}

#page-games .mg-bs-back {
  border: 1.5px solid #FDE68A;
  background: #FFFBEB;
  color: #B45309;
  font-family: var(--font-th);
  font-size: 0.92rem;
  font-weight: 700;
  border-radius: var(--radius-pill);
  padding: 0.5rem 0.95rem;
  cursor: pointer;
}

#page-games .mg-bs-back:hover {
  background: #FEF3C7;
}

#page-games .mg-bs-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-right: auto;
}

#page-games .mg-bs-vip-pill {
  padding: 0.22rem 0.65rem;
  border-radius: 999px;
  background: linear-gradient(135deg, #FEF08A 0%, #F59E0B 100%);
  color: #78350F;
  font-family: var(--font-en);
  font-size: 0.78rem;
  font-weight: 800;
  box-shadow: 0 2px 0 #D97706;
}

#page-games .mg-bs-title {
  font-family: var(--font-en);
  font-size: 1.35rem;
  font-weight: 700;
  color: #1E293B;
  margin: 0;
}

#page-games .mg-bs-category-label,
#page-games .mg-bs-count-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-th);
  font-weight: 700;
  font-size: 0.9rem;
  color: #475569;
}

#page-games .mg-bs-category,
#page-games .mg-bs-word-count {
  font-family: var(--font-th);
  font-size: 0.9rem;
  font-weight: 700;
  color: #1E293B;
  background: #F8FAFC;
  border: 1.5px solid #CBD5E1;
  border-radius: 12px;
  padding: 0.45rem 0.65rem;
  max-width: 190px;
  cursor: pointer;
}

#page-games .mg-bs-start-btn {
  border: none;
  cursor: pointer;
  font-family: var(--font-th);
  font-size: 0.92rem;
  font-weight: 800;
  color: #FFFFFF;
  background: linear-gradient(135deg, #22C55E 0%, #16A34A 100%);
  border-radius: var(--radius-pill);
  padding: 0.5rem 1.05rem;
  box-shadow: 0 3px 0 #15803D;
  transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.2s ease, opacity 0.2s ease;
  white-space: nowrap;
}

#page-games .mg-bs-start-btn:hover:not(:disabled) {
  background: linear-gradient(135deg, #4ADE80 0%, #22C55E 100%);
}

#page-games .mg-bs-start-btn:active:not(:disabled) {
  transform: translateY(2px);
  box-shadow: 0 1px 0 #15803D;
}

#page-games .mg-bs-start-btn:disabled {
  background: #CBD5E1;
  color: #64748B;
  box-shadow: 0 2px 0 #94A3B8;
  cursor: not-allowed;
  opacity: 0.8;
}

#page-games .mg-bs-stats {
  display: flex;
  align-items: center;
  gap: 8px;
}

#page-games .mg-bs-stat-pill {
  font-family: var(--font-th);
  font-size: 0.95rem;
  font-weight: 700;
  padding: 0.42rem 0.85rem;
  border-radius: 999px;
  white-space: nowrap;
}

#page-games .mg-bs-level-pill {
  background: #F3E8FF;
  color: #6B21A8;
  border: 1.5px solid #D8B4FE;
}

#page-games .mg-bs-score-pill {
  background: #FEF3C7;
  color: #92400E;
  border: 1.5px solid #FDE68A;
  font-size: 1.02rem;
}

#page-games .mg-bs-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

#page-games .mg-bs-btn-bgm {
  width: 42px;
  height: 42px;
  border: none;
  border-radius: 14px;
  background: #ECFEFF;
  font-size: 1.2rem;
  cursor: pointer;
}

#page-games .mg-bs-btn-bgm[aria-pressed="true"] {
  background: #E2E8F0;
}

#page-games .mg-bs-skip-btn,
#page-games .mg-bs-restart-btn {
  border: none;
  cursor: pointer;
  font-family: var(--font-th);
  font-size: 0.9rem;
  font-weight: 700;
  border-radius: var(--radius-pill);
  padding: 0.5rem 0.9rem;
}

#page-games .mg-bs-skip-btn {
  background: #E0F2FE;
  color: #0369A1;
  box-shadow: 0 3px 0 #7DD3FC;
}

#page-games .mg-bs-skip-btn:disabled,
#page-games .mg-bs-swap-btn:disabled {
  background: #E2E8F0;
  color: #94A3B8;
  border-color: #CBD5E1;
  box-shadow: none;
  cursor: not-allowed;
  opacity: 0.75;
}

#page-games .mg-bs-restart-btn {
  background: linear-gradient(135deg, #FF7B90 0%, #FF4D6D 100%);
  color: #FFFFFF;
  box-shadow: 0 3px 0 #E11D48;
}

/* 3-Column Blue Game Stage (No white background circles) */
#page-games .mg-bs-stage {
  display: grid;
  grid-template-columns: 230px minmax(0, 1fr) 190px;
  align-items: stretch;
  gap: 14px;
  padding: 14px;
  width: 100%;
  min-height: clamp(410px, 60vh, 560px);
  border-radius: 24px;
  overflow: hidden;
  background: linear-gradient(180deg, #1E1B4B 0%, #312E81 40%, #4338CA 78%, #6366F1 100%);
  box-shadow:
    inset 0 0 0 4px rgba(255, 255, 255, 0.25),
    0 12px 28px rgba(30, 27, 75, 0.22);
  user-select: none;
}

#page-games .mg-bs-col-left,
#page-games .mg-bs-col-right {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  z-index: 2;
}

#page-games .mg-bs-target-card {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 10px;
  padding: 16px 12px;
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.95);
  border: 3px solid #7DD3FC;
  box-shadow: 0 10px 24px rgba(15, 23, 42, 0.28);
}

#page-games .mg-bs-target-label {
  font-family: var(--font-th);
  font-size: 0.85rem;
  font-weight: 700;
  color: #0369A1;
  background: #E0F2FE;
  padding: 0.22rem 0.75rem;
  border-radius: 999px;
}

#page-games .mg-bs-target-visual {
  width: clamp(135px, 14vw, 168px);
  height: clamp(135px, 14vw, 168px);
  border-radius: 20px;
  background: #FFFFFF;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  border: 2px solid #BAE6FD;
  box-shadow: 0 5px 0 #BAE6FD;
  flex-shrink: 0;
}

#page-games .mg-bs-target-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  padding: 8px;
}

#page-games .mg-bs-target-fallback {
  font-family: var(--font-en);
  font-size: 3.4rem;
  font-weight: 800;
  color: #0284C7;
}

#page-games .mg-bs-target-info {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  width: 100%;
}

#page-games .mg-bs-target-en {
  font-family: var(--font-en);
  font-size: 1.5rem;
  font-weight: 800;
  letter-spacing: 0.5px;
  color: #0F172A;
  line-height: 1.2;
}

#page-games .mg-bs-target-th {
  font-family: var(--font-th);
  font-size: 1.12rem;
  font-weight: 700;
  color: #0369A1;
  line-height: 1.3;
}

#page-games .mg-bs-speak-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  border: none;
  border-radius: 999px;
  padding: 0.5rem 0.85rem;
  background: linear-gradient(180deg, #FEF9C3 0%, #FACC15 100%);
  box-shadow: 0 3px 0 #CA8A04;
  font-family: var(--font-th);
  font-size: 0.92rem;
  font-weight: 700;
  color: #713F12;
  cursor: pointer;
}

#page-games .mg-bs-speak-btn:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 #CA8A04;
}

#page-games .mg-bs-col-center {
  position: relative;
  width: 100%;
  height: clamp(380px, 56vh, 520px);
  border-radius: 20px;
  overflow: hidden;
  background: rgba(15, 23, 42, 0.25);
  border: 2px solid rgba(255, 255, 255, 0.18);
  touch-action: none;
}

#page-games .mg-bs-canvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: crosshair;
}

#page-games .mg-bs-hint-banner {
  position: absolute;
  left: 50%;
  bottom: 8px;
  transform: translateX(-50%);
  background: rgba(15, 23, 42, 0.68);
  color: #F8FAFC;
  font-family: var(--font-th);
  font-size: 0.8rem;
  font-weight: 600;
  padding: 4px 14px;
  border-radius: 999px;
  pointer-events: none;
  white-space: nowrap;
}

/* Right Column: Timer Card */
#page-games .mg-bs-timer-card {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 8px;
  padding: 20px 12px;
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.95);
  border: 3px solid #FDE68A;
  box-shadow: 0 10px 24px rgba(15, 23, 42, 0.28);
}

#page-games .mg-bs-timer-icon {
  width: 58px;
  height: 58px;
  border-radius: 50%;
  background: linear-gradient(135deg, #FEF3C7 0%, #FDE68A 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.9rem;
  box-shadow: 0 4px 0 #F59E0B;
}

#page-games .mg-bs-timer-label {
  font-family: var(--font-th);
  font-size: 0.88rem;
  font-weight: 700;
  color: #92400E;
}

#page-games .mg-bs-timer-value {
  font-family: var(--font-en);
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: 1px;
  color: #B45309;
  background: #FFFBEB;
  border: 2px solid #FCD34D;
  border-radius: 14px;
  padding: 0.35rem 0.85rem;
  width: 100%;
}

#page-games .mg-bs-pause-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  margin-top: 4px;
  border: none;
  border-radius: 999px;
  padding: 0.52rem 0.85rem;
  background: linear-gradient(180deg, #FEF3C7 0%, #F59E0B 100%);
  box-shadow: 0 3px 0 #B45309;
  font-family: var(--font-th);
  font-size: 0.88rem;
  font-weight: 800;
  color: #78350F;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.2s ease;
}

#page-games .mg-bs-pause-btn[aria-pressed="true"] {
  background: linear-gradient(180deg, #BBF7D0 0%, #22C55E 100%);
  box-shadow: 0 3px 0 #15803D;
  color: #064E3B;
}

#page-games .mg-bs-pause-btn:active:not(:disabled) {
  transform: translateY(2px);
  box-shadow: 0 1px 0 #B45309;
}

#page-games .mg-bs-pause-btn:disabled {
  background: #E2E8F0;
  color: #94A3B8;
  box-shadow: 0 2px 0 #CBD5E1;
  cursor: not-allowed;
  opacity: 0.8;
}

/* Victory Overlay inside Center Stage */
#page-games .mg-bs-victory-overlay {
  position: absolute;
  inset: 0;
  z-index: 10;
  background: rgba(15, 23, 42, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

#page-games .mg-bs-victory-overlay[hidden] {
  display: none !important;
}

#page-games .mg-bs-victory-card {
  width: min(380px, 100%);
  background: #FFFFFF;
  border-radius: 24px;
  padding: 24px 20px;
  text-align: center;
  border: 3px solid #FACC15;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.35);
}

#page-games .mg-bs-victory-icon {
  font-size: 3.2rem;
  line-height: 1;
  margin-bottom: 6px;
}

#page-games .mg-bs-victory-title {
  font-family: var(--font-th);
  font-size: 1.55rem;
  font-weight: 800;
  color: #0F172A;
  margin: 0 0 6px;
}

#page-games .mg-bs-victory-desc {
  font-family: var(--font-th);
  font-size: 0.98rem;
  font-weight: 700;
  color: #475569;
  margin: 0 0 14px;
}

#page-games .mg-bs-victory-summary {
  display: flex;
  justify-content: center;
  gap: 14px;
  flex-wrap: wrap;
  font-family: var(--font-th);
  font-size: 0.98rem;
  font-weight: 700;
  color: #1E293B;
  background: #F8FAFC;
  border-radius: 14px;
  padding: 10px 12px;
  margin-bottom: 16px;
}

#page-games .mg-bs-play-again-btn {
  border: none;
  cursor: pointer;
  font-family: var(--font-th);
  font-size: 1rem;
  font-weight: 700;
  color: #FFFFFF;
  background: linear-gradient(135deg, #22C55E 0%, #16A34A 100%);
  border-radius: 999px;
  padding: 0.65rem 1.4rem;
  box-shadow: 0 4px 0 #15803D;
}

#page-games .mg-bs-rack-bar {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  background: #FFFFFF;
  border-radius: 20px;
  padding: 12px 16px 14px;
  box-shadow: 0 6px 18px rgba(60, 90, 130, 0.1);
  border: 2px solid #E0E7FF;
}

#page-games .mg-bs-rack-header {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 12px;
  width: 100%;
}

#page-games .mg-bs-rack-title {
  font-family: var(--font-th);
  font-size: 0.95rem;
  font-weight: 700;
  color: #475569;
}

#page-games .mg-bs-swap-btn {
  border: 1.5px solid #C7D2FE;
  background: #EEF2FF;
  color: #4338CA;
  font-family: var(--font-th);
  font-size: 0.85rem;
  font-weight: 700;
  border-radius: 999px;
  padding: 0.32rem 0.85rem;
  cursor: pointer;
  box-shadow: 0 2px 0 #A5B4FC;
}

#page-games .mg-bs-swap-btn:active {
  transform: translateY(1px);
  box-shadow: 0 1px 0 #A5B4FC;
}

#page-games .mg-bs-word-rack {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  min-height: 58px;
}

#page-games .mg-bs-slot {
  width: clamp(44px, 6vw, 56px);
  height: clamp(50px, 7vw, 62px);
  border-radius: 14px;
  border: 3px dashed #94A3B8;
  background: #F8FAFC;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-en);
  font-size: clamp(1.4rem, 2.5vw, 1.85rem);
  font-weight: 800;
  color: #64748B;
  position: relative;
  transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1), background 0.25s ease, border-color 0.25s ease;
}

#page-games .mg-bs-slot-filled {
  border-style: solid;
  border-color: #10B981;
  background: linear-gradient(180deg, #ECFDF5 0%, #A7F3D0 100%);
  color: #065F46;
  box-shadow: 0 4px 0 #059669;
  animation: mg-bs-slot-pop 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes mg-bs-slot-pop {
  0% { transform: scale(0.6); }
  60% { transform: scale(1.18); }
  100% { transform: scale(1); }
}

@media (max-width: 920px) {
  #page-games .mg-bs-stage {
    grid-template-columns: 1fr 1fr;
  }

  #page-games .mg-bs-col-center {
    grid-column: 1 / -1;
    order: 2;
    height: clamp(340px, 52vh, 450px);
  }

  #page-games .mg-bs-col-left {
    order: 1;
  }

  #page-games .mg-bs-col-right {
    order: 1;
  }

  #page-games .mg-bs-target-visual {
    width: 100px;
    height: 100px;
  }
}

@media (max-width: 560px) {
  #page-games .mg-bs-header {
    padding: 8px 10px;
    gap: 8px;
  }

  #page-games .mg-bs-stage {
    grid-template-columns: 1fr;
    padding: 10px;
    gap: 10px;
  }

  #page-games .mg-bs-hint-banner {
    font-size: 0.72rem;
  }
}

/* ===================================================================
   MINI GAME: SLIDING JIGSAW (scoped to #page-games)
   =================================================================== */

#page-games .mg-sj-container {
  display: none;
  flex-direction: column;
  gap: 10px;
  width: 100%;
  max-width: 1180px;
  margin: 0 auto;
}

#page-games.mg-sj-playing .mg-hub-container {
  display: none;
}

#page-games.mg-sj-playing .mg-sj-container {
  display: flex;
}

#page-games .mg-sj-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 12px;
  background: #FFFFFF;
  border-radius: 20px;
  padding: 10px 16px;
  box-shadow: 0 6px 18px rgba(60, 90, 130, 0.1);
  border: 2px solid #FEF08A;
}

#page-games .mg-sj-back {
  border: 1.5px solid #FDE68A;
  background: #FFFBEB;
  color: #B45309;
  font-family: var(--font-th);
  font-size: 0.92rem;
  font-weight: 700;
  border-radius: var(--radius-pill);
  padding: 0.5rem 0.95rem;
  cursor: pointer;
}

#page-games .mg-sj-back:hover {
  background: #FEF3C7;
}

#page-games .mg-sj-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-right: auto;
}

#page-games .mg-sj-vip-pill {
  padding: 0.22rem 0.65rem;
  border-radius: 999px;
  background: linear-gradient(135deg, #FEF08A 0%, #F59E0B 100%);
  color: #78350F;
  font-family: var(--font-en);
  font-size: 0.78rem;
  font-weight: 800;
  box-shadow: 0 2px 0 #D97706;
}

#page-games .mg-sj-title {
  font-family: var(--font-en);
  font-size: 1.35rem;
  font-weight: 700;
  color: #1E293B;
  margin: 0;
}

#page-games .mg-sj-word-picker {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

#page-games .mg-sj-field-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-th);
  font-weight: 700;
  font-size: 0.92rem;
  color: #475569;
}

#page-games .mg-sj-category,
#page-games .mg-sj-word,
#page-games .mg-sj-difficulty {
  font-family: var(--font-th);
  font-size: 0.92rem;
  font-weight: 700;
  color: #1E293B;
  background: #F8FAFC;
  border: 1.5px solid #CBD5E1;
  border-radius: 12px;
  padding: 0.45rem 0.65rem;
  max-width: 195px;
  cursor: pointer;
}

#page-games .mg-sj-random-btn {
  border: 1.5px solid #C4B5FD;
  background: linear-gradient(135deg, #F3E8FF 0%, #E9D5FF 100%);
  color: #6B21A8;
  font-family: var(--font-th);
  font-size: 0.88rem;
  font-weight: 800;
  border-radius: var(--radius-pill);
  padding: 0.46rem 0.9rem;
  cursor: pointer;
  box-shadow: 0 3px 0 #A855F7;
  transition: transform 0.15s ease, box-shadow 0.15s ease, filter 0.15s ease;
  white-space: nowrap;
}

#page-games .mg-sj-random-btn:hover {
  filter: brightness(1.03);
}

#page-games .mg-sj-random-btn:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 #A855F7;
}

#page-games .mg-sj-start-btn {
  border: none;
  cursor: pointer;
  font-family: var(--font-th);
  font-size: 0.95rem;
  font-weight: 800;
  color: #FFFFFF;
  background: linear-gradient(135deg, #22C55E 0%, #16A34A 100%);
  border-radius: var(--radius-pill);
  padding: 0.52rem 1.1rem;
  box-shadow: 0 3px 0 #15803D;
  transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.2s ease, opacity 0.2s ease;
  white-space: nowrap;
}

#page-games .mg-sj-start-btn:hover:not(:disabled) {
  background: linear-gradient(135deg, #4ADE80 0%, #22C55E 100%);
}

#page-games .mg-sj-start-btn:active:not(:disabled) {
  transform: translateY(2px);
  box-shadow: 0 1px 0 #15803D;
}

#page-games .mg-sj-start-btn:disabled {
  background: #CBD5E1;
  color: #64748B;
  box-shadow: 0 2px 0 #94A3B8;
  cursor: not-allowed;
  opacity: 0.8;
}

#page-games .mg-sj-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

#page-games .mg-sj-btn-bgm {
  width: 42px;
  height: 42px;
  border: none;
  border-radius: 14px;
  background: #ECFEFF;
  font-size: 1.2rem;
  cursor: pointer;
}

#page-games .mg-sj-btn-bgm[aria-pressed="true"] {
  background: #E2E8F0;
}

#page-games .mg-sj-restart-btn {
  border: none;
  cursor: pointer;
  font-family: var(--font-th);
  font-size: 0.9rem;
  font-weight: 700;
  border-radius: var(--radius-pill);
  padding: 0.5rem 0.9rem;
  background: linear-gradient(135deg, #FF7B90 0%, #FF4D6D 100%);
  color: #FFFFFF;
  box-shadow: 0 3px 0 #E11D48;
}

#page-games .mg-sj-restart-btn:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 #E11D48;
}

/* 3-Column Stage matching VIP Bubble Shooter */
#page-games .mg-sj-stage {
  display: grid;
  grid-template-columns: 230px minmax(0, 1fr) 210px;
  align-items: stretch;
  gap: 16px;
  padding: 16px;
  width: 100%;
  min-height: clamp(460px, 64vh, 580px);
  border-radius: 24px;
  overflow: hidden;
  background: linear-gradient(180deg, #1E1B4B 0%, #312E81 42%, #4338CA 80%, #6366F1 100%);
  box-shadow:
    inset 0 0 0 4px rgba(255, 255, 255, 0.25),
    0 12px 28px rgba(30, 27, 75, 0.22);
  user-select: none;
}

#page-games .mg-sj-col-left,
#page-games .mg-sj-col-right {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  z-index: 2;
}

/* Left Column: Target Word & Reference Picture */
#page-games .mg-sj-target-card {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 10px;
  padding: 16px 12px;
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.96);
  border: 3px solid #7DD3FC;
  box-shadow: 0 10px 24px rgba(15, 23, 42, 0.28);
}

#page-games .mg-sj-target-label {
  font-family: var(--font-th);
  font-size: 0.85rem;
  font-weight: 700;
  color: #0369A1;
  background: #E0F2FE;
  padding: 0.24rem 0.75rem;
  border-radius: 999px;
}

#page-games .mg-sj-target-visual {
  width: clamp(140px, 14vw, 174px);
  height: clamp(140px, 14vw, 174px);
  border-radius: 20px;
  background: #FFFFFF;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  border: 2.5px solid #BAE6FD;
  box-shadow: 0 5px 0 #BAE6FD;
  flex-shrink: 0;
}

#page-games .mg-sj-target-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  padding: 8px;
}

#page-games .mg-sj-target-fallback {
  font-family: var(--font-en);
  font-size: 3.4rem;
  font-weight: 800;
  color: #0284C7;
}

#page-games .mg-sj-target-info {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  width: 100%;
}

#page-games .mg-sj-target-en {
  font-family: var(--font-en);
  font-size: 1.55rem;
  font-weight: 800;
  letter-spacing: 0.5px;
  color: #0F172A;
  line-height: 1.2;
}

#page-games .mg-sj-target-th {
  font-family: var(--font-th);
  font-size: 1.15rem;
  font-weight: 700;
  color: #0369A1;
  line-height: 1.3;
}

#page-games .mg-sj-speak-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  border: none;
  border-radius: 999px;
  padding: 0.52rem 0.85rem;
  background: linear-gradient(180deg, #FEF9C3 0%, #FACC15 100%);
  box-shadow: 0 3px 0 #CA8A04;
  font-family: var(--font-th);
  font-size: 0.92rem;
  font-weight: 700;
  color: #713F12;
  cursor: pointer;
}

#page-games .mg-sj-speak-btn:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 #CA8A04;
}

/* Center Column: Jigsaw Puzzle Board */
#page-games .mg-sj-col-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-width: 0;
}

/* Hint System Toolbar (Hold-to-Peek & Show Numbers Switch) */
#page-games .mg-sj-hint-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 12px;
  width: min(100%, 450px);
  padding: 8px 14px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.96);
  border: 2.5px solid #FDE68A;
  box-shadow: 0 8px 20px rgba(15, 23, 42, 0.25);
}

#page-games .mg-sj-peek-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 2px solid #F59E0B;
  border-radius: 999px;
  padding: 0.45rem 1.05rem;
  background: linear-gradient(180deg, #FEF9C3 0%, #FACC15 100%);
  box-shadow: 0 4px 0 #D97706;
  color: #78350F;
  font-family: var(--font-th);
  font-size: 0.94rem;
  font-weight: 800;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  transition: transform 0.12s ease, box-shadow 0.12s ease, filter 0.15s ease;
}

#page-games .mg-sj-peek-btn:hover:not(:disabled) {
  filter: brightness(1.04);
}

#page-games .mg-sj-peek-btn:active:not(:disabled),
#page-games .mg-sj-peek-btn.mg-sj-peek-active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 #D97706;
  background: linear-gradient(180deg, #FDE047 0%, #F59E0B 100%);
  color: #451A03;
}

#page-games .mg-sj-peek-btn:disabled {
  background: #E2E8F0;
  border-color: #CBD5E1;
  color: #94A3B8;
  box-shadow: 0 2px 0 #CBD5E1;
  cursor: not-allowed;
  opacity: 0.78;
}

#page-games .mg-sj-peek-icon {
  font-size: 1.15rem;
  line-height: 1;
}

/* Cute Kid-Friendly Toggle Switch for Show Numbers */
#page-games .mg-sj-num-switch {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  padding: 4px 10px 4px 6px;
  border-radius: 999px;
  background: #F0F9FF;
  border: 2px solid #BAE6FD;
  user-select: none;
  -webkit-user-select: none;
  transition: background 0.2s ease, border-color 0.2s ease;
}

#page-games .mg-sj-num-switch:hover {
  background: #E0F2FE;
}

#page-games .mg-sj-num-checkbox {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
  pointer-events: none;
}

#page-games .mg-sj-num-slider {
  position: relative;
  width: 46px;
  height: 26px;
  border-radius: 999px;
  background: #CBD5E1;
  box-shadow: inset 0 2px 4px rgba(15, 23, 42, 0.18);
  transition: background 0.25s ease;
  flex-shrink: 0;
}

#page-games .mg-sj-num-slider::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #FFFFFF;
  box-shadow: 0 2px 5px rgba(15, 23, 42, 0.28);
  transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}

#page-games .mg-sj-num-checkbox:checked + .mg-sj-num-slider {
  background: linear-gradient(135deg, #38BDF8 0%, #0284C7 100%);
}

#page-games .mg-sj-num-checkbox:checked + .mg-sj-num-slider::after {
  transform: translateX(20px);
}

#page-games .mg-sj-num-checkbox:focus-visible + .mg-sj-num-slider {
  outline: 3px solid #FACC15;
  outline-offset: 2px;
}

#page-games .mg-sj-num-switch-label {
  font-family: var(--font-th);
  font-size: 0.9rem;
  font-weight: 800;
  color: #0369A1;
  white-space: nowrap;
}

#page-games .mg-sj-board-wrap {
  position: relative;
  width: min(100%, 450px);
  aspect-ratio: 1 / 1;
  border-radius: 24px;
  padding: 10px;
  background: linear-gradient(145deg, #FEF08A 0%, #F59E0B 100%);
  box-shadow:
    0 12px 30px rgba(15, 23, 42, 0.4),
    inset 0 2px 0 rgba(255, 255, 255, 0.65);
  overflow: hidden;
  touch-action: none;
}

/* Full Original Image Preview (Before Start Game) */
#page-games .mg-sj-preview-layer {
  position: relative;
  width: 100%;
  height: 100%;
  border-radius: 18px;
  background: radial-gradient(circle at 50% 45%, #FFFFFF 0%, #F0F9FF 72%, #E0F2FE 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

#page-games .mg-sj-preview-layer[hidden],
#page-games .mg-sj-board[hidden],
#page-games .mg-sj-peek-overlay[hidden],
#page-games .mg-sj-countdown-overlay[hidden],
#page-games .mg-sj-pause-overlay[hidden],
#page-games .mg-sj-victory-overlay[hidden] {
  display: none !important;
}

/* Hold-to-Peek Full Image Overlay (Seamless, Hides Jigsaw Grid Lines Temporarily) */
#page-games .mg-sj-peek-overlay {
  position: absolute;
  inset: 10px;
  z-index: 12;
  border-radius: 18px;
  background: radial-gradient(circle at 50% 45%, #FFFFFF 0%, #F0F9FF 72%, #E0F2FE 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  box-shadow: 0 0 0 3px #FACC15;
  animation: mg-sj-peek-fade 0.16s ease-out;
  pointer-events: none;
}

#page-games .mg-sj-peek-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  padding: 4%;
  pointer-events: none;
  user-select: none;
}

#page-games .mg-sj-peek-pill {
  position: absolute;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  padding: 5px 14px;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.82);
  border: 2px solid #FDE047;
  color: #FEF08A;
  font-family: var(--font-th);
  font-size: 0.84rem;
  font-weight: 800;
  white-space: nowrap;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

@keyframes mg-sj-peek-fade {
  from {
    opacity: 0;
    transform: scale(0.98);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

#page-games .mg-sj-preview-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  padding: 4%;
  pointer-events: none;
}

#page-games .mg-sj-preview-badge {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 12px;
  padding: 10px 14px;
  border-radius: 16px;
  background: rgba(15, 23, 42, 0.82);
  border: 2px solid #FDE047;
  color: #FFFFFF;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 2px;
  box-shadow: 0 8px 20px rgba(15, 23, 42, 0.35);
}

#page-games .mg-sj-preview-badge-title {
  font-family: var(--font-th);
  font-size: 1.05rem;
  font-weight: 800;
  color: #FEF08A;
}

#page-games .mg-sj-preview-badge-sub {
  font-family: var(--font-th);
  font-size: 0.84rem;
  font-weight: 600;
  color: #F8FAFC;
}

/* Sliced Sliding Grid Board */
#page-games .mg-sj-board {
  --mg-sj-size: 3;
  position: relative;
  width: 100%;
  height: 100%;
  border-radius: 18px;
  background: #1E293B;
  overflow: hidden;
  box-shadow: inset 0 4px 12px rgba(0, 0, 0, 0.45);
}

#page-games .mg-sj-blank-slot {
  position: absolute;
  top: 0;
  left: 0;
  width: calc(100% / var(--mg-sj-size));
  height: calc(100% / var(--mg-sj-size));
  padding: 4px;
  transform: translate3d(calc(var(--mg-sj-col) * 100%), calc(var(--mg-sj-row) * 100%), 0);
  transition: transform 0.22s cubic-bezier(0.22, 1, 0.36, 1);
  pointer-events: none;
  z-index: 1;
}

#page-games .mg-sj-blank-slot-inner {
  width: 100%;
  height: 100%;
  border-radius: 12px;
  border: 2.5px dashed rgba(148, 163, 184, 0.45);
  background: rgba(15, 23, 42, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  color: rgba(148, 163, 184, 0.5);
  font-family: var(--font-th);
  font-size: 0.78rem;
  font-weight: 700;
}

#page-games .mg-sj-tile {
  position: absolute;
  top: 0;
  left: 0;
  width: calc(100% / var(--mg-sj-size));
  height: calc(100% / var(--mg-sj-size));
  padding: 3px;
  border: none;
  background: transparent;
  cursor: default;
  z-index: 2;
  transform: translate3d(calc(var(--mg-sj-col) * 100%), calc(var(--mg-sj-row) * 100%), 0);
  transition:
    transform 0.22s cubic-bezier(0.22, 1, 0.36, 1),
    padding 0.35s ease;
  touch-action: manipulation;
}

#page-games .mg-sj-tile:focus-visible {
  outline: none;
}

#page-games .mg-sj-tile-inner {
  position: relative;
  width: 100%;
  height: 100%;
  border-radius: 12px;
  overflow: hidden;
  background: radial-gradient(circle at 50% 45%, #FFFFFF 0%, #F0F9FF 72%, #E0F2FE 100%);
  border: 2.5px solid #BAE6FD;
  box-shadow: 0 4px 10px rgba(15, 23, 42, 0.25);
  transition:
    border-color 0.2s ease,
    border-radius 0.35s ease,
    box-shadow 0.2s ease,
    transform 0.16s ease;
}

#page-games .mg-sj-tile-movable {
  cursor: pointer;
}

#page-games .mg-sj-tile-movable .mg-sj-tile-inner {
  border-color: #FACC15;
  box-shadow:
    0 0 0 2px rgba(250, 204, 21, 0.35),
    0 6px 14px rgba(15, 23, 42, 0.3);
}

#page-games .mg-sj-tile-movable:hover .mg-sj-tile-inner {
  transform: scale(0.97);
  border-color: #F59E0B;
}

#page-games .mg-sj-tile-movable:active .mg-sj-tile-inner {
  transform: scale(0.93);
}

#page-games .mg-sj-tile-correct:not(.mg-sj-tile-movable) .mg-sj-tile-inner {
  border-color: #4ADE80;
}

#page-games .mg-sj-tile-img {
  position: absolute;
  top: calc(var(--mg-sj-orig-row) * -100%);
  left: calc(var(--mg-sj-orig-col) * -100%);
  width: calc(var(--mg-sj-size) * 100%);
  height: calc(var(--mg-sj-size) * 100%);
  max-width: none;
  object-fit: contain;
  padding: 4%;
  pointer-events: none;
  user-select: none;
}

#page-games .mg-sj-tile-num {
  position: absolute;
  top: 6px;
  left: 6px;
  min-width: 28px;
  height: 28px;
  padding: 0 7px;
  border-radius: 999px;
  background: linear-gradient(135deg, #1E293B 0%, #0F172A 100%);
  border: 2px solid #FDE047;
  color: #FEF08A;
  font-family: var(--font-en);
  font-size: 0.88rem;
  font-weight: 900;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 3px 6px rgba(0, 0, 0, 0.32);
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

#page-games .mg-sj-board.mg-sj-hide-nums .mg-sj-tile-num,
#page-games .mg-sj-board.mg-sj-board-solved .mg-sj-tile-num {
  opacity: 0;
  transform: scale(0.75);
}

/* Completed Board State: Merge Pieces Together & Reveal Missing Corner */
#page-games .mg-sj-board.mg-sj-board-solved {
  background: radial-gradient(circle at 50% 45%, #FFFFFF 0%, #F0F9FF 72%, #E0F2FE 100%);
}

#page-games .mg-sj-board.mg-sj-board-solved .mg-sj-tile {
  padding: 0;
}

#page-games .mg-sj-board.mg-sj-board-solved .mg-sj-tile-inner {
  border-radius: 0;
  border-width: 0;
  box-shadow: none;
}

#page-games .mg-sj-tile-final-reveal {
  animation: mg-sj-final-piece-pop 0.55s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

@keyframes mg-sj-final-piece-pop {
  0% {
    opacity: 0;
    transform: translate3d(calc(var(--mg-sj-col) * 100%), calc(var(--mg-sj-row) * 100%), 0) scale(0.35);
  }
  70% {
    opacity: 1;
    transform: translate3d(calc(var(--mg-sj-col) * 100%), calc(var(--mg-sj-row) * 100%), 0) scale(1.08);
  }
  100% {
    opacity: 1;
    transform: translate3d(calc(var(--mg-sj-col) * 100%), calc(var(--mg-sj-row) * 100%), 0) scale(1);
  }
}

/* Countdown Overlay (3 -> 2 -> 1 -> GO!) */
#page-games .mg-sj-countdown-overlay {
  position: absolute;
  inset: 0;
  z-index: 15;
  background: rgba(15, 23, 42, 0.52);
  display: flex;
  align-items: center;
  justify-content: center;
}

#page-games .mg-sj-countdown-circle {
  width: 156px;
  height: 156px;
  border-radius: 50%;
  background: rgba(30, 27, 75, 0.92);
  border: 6px solid #FACC15;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 14px 32px rgba(0, 0, 0, 0.45);
  animation: mg-sj-countdown-pop 0.45s cubic-bezier(0.22, 1.4, 0.36, 1);
}

#page-games .mg-sj-countdown-circle.mg-sj-countdown-go {
  width: 176px;
  height: 176px;
  background: rgba(34, 197, 94, 0.94);
  border-color: #BBF7D0;
}

#page-games .mg-sj-countdown-text {
  font-family: var(--font-en);
  font-size: 4.8rem;
  font-weight: 900;
  color: #FFFFFF;
  text-shadow: 0 6px 14px rgba(0, 0, 0, 0.4);
  line-height: 1;
}

#page-games .mg-sj-countdown-circle.mg-sj-countdown-go .mg-sj-countdown-text {
  font-size: 3.9rem;
}

@keyframes mg-sj-countdown-pop {
  0% {
    transform: scale(0.45);
    opacity: 0.2;
  }
  65% {
    transform: scale(1.14);
    opacity: 1;
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

/* Pause Overlay */
#page-games .mg-sj-pause-overlay {
  position: absolute;
  inset: 0;
  z-index: 14;
  background: rgba(15, 23, 42, 0.84);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

#page-games .mg-sj-pause-card {
  width: min(360px, 100%);
  padding: 24px 20px;
  border-radius: 24px;
  background: rgba(30, 27, 75, 0.96);
  border: 4px solid #FACC15;
  text-align: center;
  box-shadow: 0 16px 36px rgba(0, 0, 0, 0.45);
}

#page-games .mg-sj-pause-icon {
  font-size: 2.8rem;
  margin-bottom: 4px;
}

#page-games .mg-sj-pause-title {
  font-family: var(--font-th);
  font-size: 1.5rem;
  font-weight: 800;
  color: #FEF08A;
  margin: 0 0 6px;
}

#page-games .mg-sj-pause-sub {
  font-family: var(--font-th);
  font-size: 0.95rem;
  font-weight: 600;
  color: #E0E7FF;
  margin: 0 0 16px;
}

#page-games .mg-sj-resume-btn {
  border: none;
  cursor: pointer;
  font-family: var(--font-th);
  font-size: 1rem;
  font-weight: 800;
  color: #064E3B;
  background: linear-gradient(180deg, #BBF7D0 0%, #22C55E 100%);
  border-radius: 999px;
  padding: 0.6rem 1.4rem;
  box-shadow: 0 4px 0 #15803D;
}

#page-games .mg-sj-resume-btn:active {
  transform: translateY(2px);
  box-shadow: 0 2px 0 #15803D;
}

/* Victory Overlay */
#page-games .mg-sj-victory-overlay {
  position: absolute;
  inset: 0;
  z-index: 16;
  background: rgba(15, 23, 42, 0.68);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

#page-games .mg-sj-victory-card {
  width: min(390px, 100%);
  background: #FFFFFF;
  border-radius: 24px;
  padding: 22px 18px;
  text-align: center;
  border: 3px solid #FACC15;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.38);
  animation: mg-sj-countdown-pop 0.4s cubic-bezier(0.22, 1.4, 0.36, 1);
}

#page-games .mg-sj-victory-icon {
  font-size: 3rem;
  line-height: 1;
  margin-bottom: 4px;
}

#page-games .mg-sj-victory-title {
  font-family: var(--font-th);
  font-size: 1.45rem;
  font-weight: 800;
  color: #0F172A;
  margin: 0 0 4px;
}

#page-games .mg-sj-victory-word {
  font-family: var(--font-th);
  font-size: 1.08rem;
  font-weight: 800;
  color: #0284C7;
  margin: 0 0 6px;
}

#page-games .mg-sj-victory-stars {
  font-size: 1.85rem;
  letter-spacing: 4px;
  margin-bottom: 10px;
}

#page-games .mg-sj-victory-summary {
  display: flex;
  justify-content: center;
  gap: 10px 14px;
  flex-wrap: wrap;
  font-family: var(--font-th);
  font-size: 0.94rem;
  font-weight: 700;
  color: #1E293B;
  background: #F8FAFC;
  border-radius: 14px;
  padding: 10px 12px;
  margin-bottom: 14px;
  border: 1.5px solid #E2E8F0;
}

#page-games .mg-sj-victory-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}

#page-games .mg-sj-play-again-btn,
#page-games .mg-sj-next-random-btn {
  border: none;
  cursor: pointer;
  font-family: var(--font-th);
  font-size: 0.95rem;
  font-weight: 800;
  border-radius: 999px;
  padding: 0.6rem 1.2rem;
}

#page-games .mg-sj-play-again-btn {
  color: #FFFFFF;
  background: linear-gradient(135deg, #22C55E 0%, #16A34A 100%);
  box-shadow: 0 4px 0 #15803D;
}

#page-games .mg-sj-next-random-btn {
  color: #6B21A8;
  background: linear-gradient(135deg, #F3E8FF 0%, #E9D5FF 100%);
  border: 1.5px solid #C4B5FD;
  box-shadow: 0 4px 0 #A855F7;
}

#page-games .mg-sj-confetti-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 18;
}

#page-games .mg-sj-hint-banner {
  background: rgba(15, 23, 42, 0.72);
  color: #F8FAFC;
  font-family: var(--font-th);
  font-size: 0.86rem;
  font-weight: 600;
  padding: 6px 16px;
  border-radius: 999px;
  text-align: center;
  max-width: 100%;
}

#page-games .mg-sj-hint-banner strong {
  color: #FEF08A;
}

/* Right Column: Timer & Moves Card */
#page-games .mg-sj-timer-card {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 10px;
  padding: 18px 12px;
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.96);
  border: 3px solid #FDE68A;
  box-shadow: 0 10px 24px rgba(15, 23, 42, 0.28);
}

#page-games .mg-sj-timer-icon {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: linear-gradient(135deg, #FEF3C7 0%, #FDE68A 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.85rem;
  box-shadow: 0 4px 0 #F59E0B;
}

#page-games .mg-sj-timer-label {
  font-family: var(--font-th);
  font-size: 0.88rem;
  font-weight: 700;
  color: #92400E;
}

#page-games .mg-sj-timer-value {
  font-family: var(--font-en);
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: 1px;
  color: #B45309;
  background: #FFFBEB;
  border: 2px solid #FCD34D;
  border-radius: 14px;
  padding: 0.32rem 0.85rem;
  width: 100%;
}

#page-games .mg-sj-moves-box {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 8px 10px;
  border-radius: 14px;
  background: #F0F9FF;
  border: 1.5px solid #BAE6FD;
}

#page-games .mg-sj-moves-label {
  font-family: var(--font-th);
  font-size: 0.8rem;
  font-weight: 700;
  color: #0369A1;
}

#page-games .mg-sj-moves-value {
  font-family: var(--font-en);
  font-size: 1.45rem;
  font-weight: 800;
  color: #0284C7;
  line-height: 1.1;
}

#page-games .mg-sj-pause-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  border: none;
  border-radius: 999px;
  padding: 0.55rem 0.85rem;
  background: linear-gradient(180deg, #FEF3C7 0%, #F59E0B 100%);
  box-shadow: 0 3px 0 #B45309;
  font-family: var(--font-th);
  font-size: 0.88rem;
  font-weight: 800;
  color: #78350F;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.2s ease;
}

#page-games .mg-sj-pause-btn[aria-pressed="true"] {
  background: linear-gradient(180deg, #BBF7D0 0%, #22C55E 100%);
  box-shadow: 0 3px 0 #15803D;
  color: #064E3B;
}

#page-games .mg-sj-pause-btn:active:not(:disabled) {
  transform: translateY(2px);
  box-shadow: 0 1px 0 #B45309;
}

#page-games .mg-sj-pause-btn:disabled {
  background: #E2E8F0;
  color: #94A3B8;
  box-shadow: 0 2px 0 #CBD5E1;
  cursor: not-allowed;
  opacity: 0.8;
}

@media (max-width: 960px) {
  #page-games .mg-sj-stage {
    grid-template-columns: 1fr 1fr;
  }

  #page-games .mg-sj-col-center {
    grid-column: 1 / -1;
    order: 2;
  }

  #page-games .mg-sj-col-left {
    order: 1;
  }

  #page-games .mg-sj-col-right {
    order: 1;
  }

  #page-games .mg-sj-target-visual {
    width: 110px;
    height: 110px;
  }
}

@media (max-width: 560px) {
  #page-games .mg-sj-header {
    padding: 8px 10px;
    gap: 8px;
  }

  #page-games .mg-sj-stage {
    grid-template-columns: 1fr;
    padding: 10px;
    gap: 10px;
  }

  #page-games .mg-sj-hint-banner {
    font-size: 0.75rem;
  }
}

/* ===================================================================
   MINI GAME: DRAG & DROP JIGSAW (scoped to #page-games)
   =================================================================== */

#page-games .mg-dj-container {
  display: none;
  flex-direction: column;
  gap: 10px;
  width: 100%;
  max-width: 1220px;
  margin: 0 auto;
}

#page-games.mg-dj-playing .mg-hub-container {
  display: none;
}

#page-games.mg-dj-playing .mg-dj-container {
  display: flex;
}

#page-games .mg-dj-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 12px;
  background: #FFFFFF;
  border-radius: 20px;
  padding: 10px 16px;
  box-shadow: 0 6px 18px rgba(60, 90, 130, 0.1);
  border: 2px solid #FEF08A;
}

#page-games .mg-dj-back {
  border: 1.5px solid #FDE68A;
  background: #FFFBEB;
  color: #B45309;
  font-family: var(--font-th);
  font-size: 0.92rem;
  font-weight: 700;
  border-radius: var(--radius-pill);
  padding: 0.5rem 0.95rem;
  cursor: pointer;
}

#page-games .mg-dj-back:hover {
  background: #FEF3C7;
}

#page-games .mg-dj-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-right: auto;
}

#page-games .mg-dj-vip-pill {
  padding: 0.22rem 0.65rem;
  border-radius: 999px;
  background: linear-gradient(135deg, #FEF08A 0%, #F59E0B 100%);
  color: #78350F;
  font-family: var(--font-en);
  font-size: 0.78rem;
  font-weight: 800;
  box-shadow: 0 2px 0 #D97706;
}

#page-games .mg-dj-title {
  font-family: var(--font-en);
  font-size: 1.35rem;
  font-weight: 700;
  color: #1E293B;
  margin: 0;
}

#page-games .mg-dj-word-picker {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

#page-games .mg-dj-field-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-th);
  font-weight: 700;
  font-size: 0.92rem;
  color: #475569;
}

#page-games .mg-dj-category,
#page-games .mg-dj-word,
#page-games .mg-dj-difficulty {
  font-family: var(--font-th);
  font-size: 0.92rem;
  font-weight: 700;
  color: #1E293B;
  background: #F8FAFC;
  border: 1.5px solid #CBD5E1;
  border-radius: 12px;
  padding: 0.45rem 0.65rem;
  max-width: 210px;
  cursor: pointer;
}

#page-games .mg-dj-random-btn {
  border: 1.5px solid #C4B5FD;
  background: linear-gradient(135deg, #F3E8FF 0%, #E9D5FF 100%);
  color: #6B21A8;
  font-family: var(--font-th);
  font-size: 0.88rem;
  font-weight: 800;
  border-radius: var(--radius-pill);
  padding: 0.46rem 0.9rem;
  cursor: pointer;
  box-shadow: 0 3px 0 #A855F7;
  transition: transform 0.15s ease, box-shadow 0.15s ease, filter 0.15s ease;
  white-space: nowrap;
}

#page-games .mg-dj-random-btn:hover {
  filter: brightness(1.03);
}

#page-games .mg-dj-random-btn:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 #A855F7;
}

#page-games .mg-dj-start-btn {
  border: none;
  cursor: pointer;
  font-family: var(--font-th);
  font-size: 0.95rem;
  font-weight: 800;
  color: #FFFFFF;
  background: linear-gradient(135deg, #22C55E 0%, #16A34A 100%);
  border-radius: var(--radius-pill);
  padding: 0.52rem 1.1rem;
  box-shadow: 0 3px 0 #15803D;
  transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.2s ease, opacity 0.2s ease;
  white-space: nowrap;
}

#page-games .mg-dj-start-btn:hover:not(:disabled) {
  background: linear-gradient(135deg, #4ADE80 0%, #22C55E 100%);
}

#page-games .mg-dj-start-btn:active:not(:disabled) {
  transform: translateY(2px);
  box-shadow: 0 1px 0 #15803D;
}

#page-games .mg-dj-start-btn:disabled {
  background: #CBD5E1;
  color: #64748B;
  box-shadow: 0 2px 0 #94A3B8;
  cursor: not-allowed;
  opacity: 0.8;
}

#page-games .mg-dj-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

#page-games .mg-dj-btn-bgm {
  width: 42px;
  height: 42px;
  border: none;
  border-radius: 14px;
  background: #ECFEFF;
  font-size: 1.2rem;
  cursor: pointer;
}

#page-games .mg-dj-btn-bgm[aria-pressed="true"] {
  background: #E2E8F0;
}

#page-games .mg-dj-restart-btn {
  border: none;
  cursor: pointer;
  font-family: var(--font-th);
  font-size: 0.9rem;
  font-weight: 700;
  border-radius: var(--radius-pill);
  padding: 0.5rem 0.9rem;
  background: linear-gradient(135deg, #FF7B90 0%, #FF4D6D 100%);
  color: #FFFFFF;
  box-shadow: 0 3px 0 #E11D48;
}

#page-games .mg-dj-restart-btn:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 #E11D48;
}

/* 3-Column Standardized Stage matching Sliding Jigsaw */
#page-games .mg-dj-stage {
  display: grid;
  grid-template-columns: 215px minmax(0, 1fr) 205px;
  align-items: stretch;
  gap: 14px;
  padding: 16px;
  width: 100%;
  min-height: clamp(460px, 64vh, 580px);
  border-radius: 24px;
  overflow: hidden;
  background: linear-gradient(180deg, #1E1B4B 0%, #312E81 42%, #4338CA 80%, #6366F1 100%);
  box-shadow:
    inset 0 0 0 4px rgba(255, 255, 255, 0.25),
    0 12px 28px rgba(30, 27, 75, 0.22);
  user-select: none;
}

#page-games .mg-dj-col-left,
#page-games .mg-dj-col-right {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  z-index: 2;
}

/* Left Column: Target Word & Reference Picture */
#page-games .mg-dj-target-card {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 10px;
  padding: 16px 12px;
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.96);
  border: 3px solid #7DD3FC;
  box-shadow: 0 10px 24px rgba(15, 23, 42, 0.28);
}

#page-games .mg-dj-target-label {
  font-family: var(--font-th);
  font-size: 0.85rem;
  font-weight: 700;
  color: #0369A1;
  background: #E0F2FE;
  padding: 0.24rem 0.75rem;
  border-radius: 999px;
}

#page-games .mg-dj-target-visual {
  width: clamp(134px, 13vw, 168px);
  height: clamp(134px, 13vw, 168px);
  border-radius: 20px;
  background: #FFFFFF;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  border: 2.5px solid #BAE6FD;
  box-shadow: 0 5px 0 #BAE6FD;
  flex-shrink: 0;
}

#page-games .mg-dj-target-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  padding: 8px;
}

#page-games .mg-dj-target-fallback {
  font-family: var(--font-en);
  font-size: 3.4rem;
  font-weight: 800;
  color: #0284C7;
}

#page-games .mg-dj-target-info {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  width: 100%;
}

#page-games .mg-dj-target-en {
  font-family: var(--font-en);
  font-size: 1.5rem;
  font-weight: 800;
  letter-spacing: 0.5px;
  color: #0F172A;
  line-height: 1.2;
}

#page-games .mg-dj-target-th {
  font-family: var(--font-th);
  font-size: 1.12rem;
  font-weight: 700;
  color: #0369A1;
  line-height: 1.3;
}

#page-games .mg-dj-speak-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  border: none;
  border-radius: 999px;
  padding: 0.52rem 0.85rem;
  background: linear-gradient(180deg, #FEF9C3 0%, #FACC15 100%);
  box-shadow: 0 3px 0 #CA8A04;
  font-family: var(--font-th);
  font-size: 0.92rem;
  font-weight: 700;
  color: #713F12;
  cursor: pointer;
}

#page-games .mg-dj-speak-btn:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 #CA8A04;
}

/* Center Column: Drag & Drop Game Area */
#page-games .mg-dj-col-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-width: 0;
}

#page-games .mg-dj-hint-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: min(100%, 680px);
  padding: 7px 14px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.96);
  border: 2.5px solid #FDE68A;
  box-shadow: 0 8px 20px rgba(15, 23, 42, 0.25);
}

#page-games .mg-dj-peek-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 2px solid #F59E0B;
  border-radius: 999px;
  padding: 0.4rem 0.95rem;
  background: linear-gradient(180deg, #FEF9C3 0%, #FACC15 100%);
  box-shadow: 0 4px 0 #D97706;
  color: #78350F;
  font-family: var(--font-th);
  font-size: 0.9rem;
  font-weight: 800;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  transition: transform 0.12s ease, box-shadow 0.12s ease, filter 0.15s ease;
}

#page-games .mg-dj-peek-btn:hover:not(:disabled) {
  filter: brightness(1.04);
}

#page-games .mg-dj-peek-btn:active:not(:disabled),
#page-games .mg-dj-peek-btn.mg-dj-peek-active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 #D97706;
  background: linear-gradient(180deg, #FDE047 0%, #F59E0B 100%);
  color: #451A03;
}

#page-games .mg-dj-peek-btn:disabled {
  background: #E2E8F0;
  border-color: #CBD5E1;
  color: #94A3B8;
  box-shadow: 0 2px 0 #CBD5E1;
  cursor: not-allowed;
  opacity: 0.78;
}

#page-games .mg-dj-peek-icon {
  font-size: 1.1rem;
  line-height: 1;
}

#page-games .mg-dj-num-switch {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  padding: 4px 10px 4px 6px;
  border-radius: 999px;
  background: #F0F9FF;
  border: 2px solid #BAE6FD;
  user-select: none;
  -webkit-user-select: none;
  transition: background 0.2s ease, border-color 0.2s ease;
}

#page-games .mg-dj-num-switch:hover {
  background: #E0F2FE;
}

#page-games .mg-dj-num-checkbox {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
  pointer-events: none;
}

#page-games .mg-dj-num-slider {
  position: relative;
  width: 44px;
  height: 24px;
  border-radius: 999px;
  background: #CBD5E1;
  box-shadow: inset 0 2px 4px rgba(15, 23, 42, 0.18);
  transition: background 0.25s ease;
  flex-shrink: 0;
}

#page-games .mg-dj-num-slider::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #FFFFFF;
  box-shadow: 0 2px 5px rgba(15, 23, 42, 0.28);
  transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}

#page-games .mg-dj-num-checkbox:checked + .mg-dj-num-slider {
  background: linear-gradient(135deg, #38BDF8 0%, #0284C7 100%);
}

#page-games .mg-dj-num-checkbox:checked + .mg-dj-num-slider::after {
  transform: translateX(20px);
}

#page-games .mg-dj-num-switch-label {
  font-family: var(--font-th);
  font-size: 0.88rem;
  font-weight: 800;
  color: #0369A1;
  white-space: nowrap;
}

#page-games .mg-dj-rescatter-btn {
  border: 1.5px solid #C4B5FD;
  background: linear-gradient(135deg, #F3E8FF 0%, #E9D5FF 100%);
  color: #6B21A8;
  font-family: var(--font-th);
  font-size: 0.85rem;
  font-weight: 800;
  border-radius: 999px;
  padding: 0.4rem 0.85rem;
  cursor: pointer;
  box-shadow: 0 3px 0 #A855F7;
  white-space: nowrap;
  transition: transform 0.12s ease, box-shadow 0.12s ease, opacity 0.2s ease;
}

#page-games .mg-dj-rescatter-btn:active:not(:disabled) {
  transform: translateY(2px);
  box-shadow: 0 1px 0 #A855F7;
}

#page-games .mg-dj-rescatter-btn:disabled {
  background: #E2E8F0;
  border-color: #CBD5E1;
  color: #94A3B8;
  box-shadow: 0 2px 0 #CBD5E1;
  cursor: not-allowed;
  opacity: 0.75;
}

/* Main Board Wrapper */
#page-games .mg-dj-board-wrap {
  position: relative;
  width: min(100%, 720px);
  min-height: 390px;
  border-radius: 24px;
  padding: 12px;
  background: linear-gradient(145deg, #FEF08A 0%, #F59E0B 100%);
  box-shadow:
    0 12px 30px rgba(15, 23, 42, 0.4),
    inset 0 2px 0 rgba(255, 255, 255, 0.65);
  overflow: hidden;
  display: flex;
  align-items: stretch;
  justify-content: center;
}

#page-games .mg-dj-preview-layer[hidden],
#page-games .mg-dj-arena[hidden],
#page-games .mg-dj-peek-overlay[hidden],
#page-games .mg-dj-countdown-overlay[hidden],
#page-games .mg-dj-pause-overlay[hidden],
#page-games .mg-dj-victory-overlay[hidden] {
  display: none !important;
}

/* Idle Preview Layer */
#page-games .mg-dj-preview-layer {
  position: relative;
  width: 100%;
  min-height: 366px;
  border-radius: 18px;
  background: radial-gradient(circle at 50% 45%, #FFFFFF 0%, #F0F9FF 72%, #E0F2FE 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

#page-games .mg-dj-preview-img {
  width: min(76%, 320px);
  height: min(76%, 320px);
  object-fit: contain;
  pointer-events: none;
}

#page-games .mg-dj-preview-badge {
  position: absolute;
  left: 14px;
  right: 14px;
  bottom: 12px;
  padding: 10px 14px;
  border-radius: 16px;
  background: rgba(15, 23, 42, 0.84);
  border: 2px solid #FDE047;
  color: #FFFFFF;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 2px;
  box-shadow: 0 8px 20px rgba(15, 23, 42, 0.35);
}

#page-games .mg-dj-preview-badge-title {
  font-family: var(--font-th);
  font-size: 1.04rem;
  font-weight: 800;
  color: #FEF08A;
}

#page-games .mg-dj-preview-badge-sub {
  font-family: var(--font-th);
  font-size: 0.84rem;
  font-weight: 600;
  color: #F8FAFC;
}

/* Playing Arena: Drop Zone (Left) + Scattered Area (Right/Bottom) */
#page-games .mg-dj-arena {
  --mg-dj-size: 3;
  position: relative;
  width: 100%;
  min-height: 366px;
  border-radius: 18px;
  background: linear-gradient(135deg, #0F172A 0%, #1E293B 100%);
  padding: 12px;
  display: grid;
  grid-template-columns: minmax(250px, 316px) minmax(200px, 1fr);
  gap: 14px;
  align-items: center;
  overflow: hidden;
  touch-action: none;
  box-shadow: inset 0 4px 12px rgba(0, 0, 0, 0.45);
}

#page-games .mg-dj-drop-panel,
#page-games .mg-dj-scatter-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  height: 100%;
  justify-content: center;
}

#page-games .mg-dj-zone-tag {
  font-family: var(--font-th);
  font-size: 0.8rem;
  font-weight: 800;
  color: #FEF08A;
  background: rgba(15, 23, 42, 0.78);
  border: 1.5px solid rgba(250, 204, 21, 0.55);
  border-radius: 999px;
  padding: 3px 12px;
  white-space: nowrap;
  pointer-events: none;
  z-index: 2;
}

#page-games .mg-dj-zone-tag-scatter {
  color: #BAE6FD;
  border-color: rgba(125, 211, 252, 0.55);
}

/* Drop Zone (Target Board with Ghost Hint Image) */
#page-games .mg-dj-drop-zone {
  position: relative;
  width: min(100%, 306px);
  aspect-ratio: 1 / 1;
  border-radius: 14px;
  background: #FFFFFF;
  border: 3px solid #FACC15;
  box-shadow:
    0 8px 22px rgba(0, 0, 0, 0.38),
    0 0 0 3px rgba(250, 204, 21, 0.22);
  overflow: hidden;
  flex-shrink: 0;
}

#page-games .mg-dj-arena.mg-dj-board-solved .mg-dj-drop-zone {
  border-color: #4ADE80;
  box-shadow:
    0 0 0 4px rgba(74, 222, 128, 0.45),
    0 12px 28px rgba(0, 0, 0, 0.45);
}

/* Faint Background Hint Image (Opacity 0.25 as requested: 0.2 - 0.3) */
#page-games .mg-dj-ghost-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  padding: 0;
  opacity: 0.26;
  pointer-events: none;
  user-select: none;
  z-index: 1;
  transition: opacity 0.35s ease;
}

#page-games .mg-dj-arena.mg-dj-board-solved .mg-dj-ghost-img {
  opacity: 1;
}

/* Grid Cell Guides on Drop Zone */
#page-games .mg-dj-slot-grid {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: repeat(var(--mg-dj-size), 1fr);
  grid-template-rows: repeat(var(--mg-dj-size), 1fr);
  z-index: 2;
  pointer-events: none;
}

#page-games .mg-dj-slot {
  border: 1.5px dashed rgba(14, 165, 233, 0.42);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-en);
  font-size: 0.9rem;
  font-weight: 800;
  color: rgba(15, 23, 42, 0.24);
  transition: background 0.2s ease, border-color 0.2s ease, opacity 0.25s ease;
}

#page-games .mg-dj-slot.mg-dj-slot-highlight {
  background: rgba(74, 222, 128, 0.24);
  border: 2px solid #22C55E;
}

#page-games .mg-dj-arena.mg-dj-hide-nums .mg-dj-slot-num,
#page-games .mg-dj-arena.mg-dj-board-solved .mg-dj-slot {
  opacity: 0;
}

/* Scattered Pieces Area (Side / Bottom Tray) */
#page-games .mg-dj-scatter-zone {
  position: relative;
  width: 100%;
  height: 306px;
  min-height: 250px;
  border-radius: 14px;
  border: 2.5px dashed rgba(125, 211, 252, 0.45);
  background: rgba(15, 23, 42, 0.58);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
  text-align: center;
  overflow: hidden;
}

#page-games .mg-dj-scatter-watermark {
  font-family: var(--font-th);
  font-size: 0.86rem;
  font-weight: 700;
  color: rgba(186, 230, 253, 0.42);
  max-width: 210px;
  pointer-events: none;
  user-select: none;
}

/* Interactive Jigsaw Pieces Layer covering the Arena */
#page-games .mg-dj-pieces-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 6;
}

#page-games .mg-dj-piece {
  position: absolute;
  top: 0;
  left: 0;
  padding: 0;
  border: none;
  background: transparent;
  cursor: grab;
  pointer-events: auto;
  z-index: 8;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  will-change: transform;
  transition:
    transform 0.34s cubic-bezier(0.22, 1, 0.36, 1),
    filter 0.2s ease;
}

#page-games .mg-dj-piece:hover:not(.mg-dj-piece-locked):not(.mg-dj-piece-dragging) {
  filter: brightness(1.05);
  z-index: 12;
}

#page-games .mg-dj-piece.mg-dj-piece-dragging {
  cursor: grabbing;
  z-index: 30 !important;
  transition: none !important;
  filter: drop-shadow(0 14px 20px rgba(0, 0, 0, 0.45));
}

#page-games .mg-dj-piece.mg-dj-piece-locked {
  cursor: default;
  pointer-events: none;
  z-index: 4 !important;
  transition: transform 0.18s cubic-bezier(0.34, 1.56, 0.64, 1);
}

#page-games .mg-dj-piece-inner {
  position: relative;
  width: 100%;
  height: 100%;
  border-radius: 10px;
  overflow: hidden;
  background: #FFFFFF;
  border: 2.5px solid #38BDF8;
  box-shadow: 0 6px 14px rgba(0, 0, 0, 0.34);
  transition:
    border-color 0.2s ease,
    border-radius 0.3s ease,
    box-shadow 0.2s ease,
    transform 0.15s ease;
}

#page-games .mg-dj-piece.mg-dj-piece-dragging .mg-dj-piece-inner {
  transform: scale(1.06);
  border-color: #FACC15;
  box-shadow: 0 0 0 3px rgba(250, 204, 21, 0.45);
}

#page-games .mg-dj-piece.mg-dj-piece-near .mg-dj-piece-inner {
  border-color: #4ADE80;
  box-shadow: 0 0 0 4px rgba(74, 222, 128, 0.55);
}

#page-games .mg-dj-piece.mg-dj-piece-locked .mg-dj-piece-inner {
  border-radius: 2px;
  border: 1px solid rgba(74, 222, 128, 0.65);
  box-shadow: none;
  animation: mg-dj-snap-pop 0.32s cubic-bezier(0.34, 1.56, 0.64, 1);
}

#page-games .mg-dj-arena.mg-dj-board-solved .mg-dj-piece.mg-dj-piece-locked .mg-dj-piece-inner {
  border-width: 0;
  border-radius: 0;
}

@keyframes mg-dj-snap-pop {
  0% {
    transform: scale(1.12);
  }
  65% {
    transform: scale(0.96);
  }
  100% {
    transform: scale(1);
  }
}

/* 1:1 Aligned Image Slice inside Each Piece */
#page-games .mg-dj-piece-img {
  position: absolute;
  top: calc(var(--mg-dj-orig-row) * -100%);
  left: calc(var(--mg-dj-orig-col) * -100%);
  width: calc(var(--mg-dj-size) * 100%);
  height: calc(var(--mg-dj-size) * 100%);
  max-width: none;
  object-fit: contain;
  padding: 0;
  pointer-events: none;
  user-select: none;
}

#page-games .mg-dj-piece-num {
  position: absolute;
  top: 4px;
  left: 4px;
  min-width: 24px;
  height: 24px;
  padding: 0 6px;
  border-radius: 999px;
  background: linear-gradient(135deg, #1E293B 0%, #0F172A 100%);
  border: 1.5px solid #FDE047;
  color: #FEF08A;
  font-family: var(--font-en);
  font-size: 0.78rem;
  font-weight: 900;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.32);
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

#page-games .mg-dj-arena.mg-dj-hide-nums .mg-dj-piece-num,
#page-games .mg-dj-piece.mg-dj-piece-locked .mg-dj-piece-num,
#page-games .mg-dj-arena.mg-dj-board-solved .mg-dj-piece-num {
  opacity: 0;
  transform: scale(0.7);
}

/* Hold-to-Peek Overlay */
#page-games .mg-dj-peek-overlay {
  position: absolute;
  inset: 0;
  z-index: 25;
  border-radius: 18px;
  background: radial-gradient(circle at 50% 45%, #FFFFFF 0%, #F0F9FF 72%, #E0F2FE 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  box-shadow: 0 0 0 3px #FACC15;
  animation: mg-sj-peek-fade 0.16s ease-out;
  pointer-events: none;
}

#page-games .mg-dj-peek-img {
  width: min(76%, 320px);
  height: min(76%, 320px);
  object-fit: contain;
  pointer-events: none;
  user-select: none;
}

#page-games .mg-dj-peek-pill {
  position: absolute;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  padding: 5px 14px;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.84);
  border: 2px solid #FDE047;
  color: #FEF08A;
  font-family: var(--font-th);
  font-size: 0.84rem;
  font-weight: 800;
  white-space: nowrap;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

/* Countdown Overlay (3 -> 2 -> 1 -> GO!) */
#page-games .mg-dj-countdown-overlay {
  position: absolute;
  inset: 0;
  z-index: 35;
  background: rgba(15, 23, 42, 0.56);
  display: flex;
  align-items: center;
  justify-content: center;
}

#page-games .mg-dj-countdown-circle {
  width: 156px;
  height: 156px;
  border-radius: 50%;
  background: rgba(30, 27, 75, 0.92);
  border: 6px solid #FACC15;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 14px 32px rgba(0, 0, 0, 0.45);
  animation: mg-sj-countdown-pop 0.45s cubic-bezier(0.22, 1.4, 0.36, 1);
}

#page-games .mg-dj-countdown-circle.mg-dj-countdown-go {
  width: 176px;
  height: 176px;
  background: rgba(34, 197, 94, 0.94);
  border-color: #BBF7D0;
}

#page-games .mg-dj-countdown-text {
  font-family: var(--font-en);
  font-size: 4.8rem;
  font-weight: 900;
  color: #FFFFFF;
  text-shadow: 0 6px 14px rgba(0, 0, 0, 0.4);
  line-height: 1;
}

#page-games .mg-dj-countdown-circle.mg-dj-countdown-go .mg-dj-countdown-text {
  font-size: 3.9rem;
}

/* Pause Overlay (Locks Pieces) */
#page-games .mg-dj-pause-overlay {
  position: absolute;
  inset: 0;
  z-index: 34;
  background: rgba(15, 23, 42, 0.84);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

#page-games .mg-dj-pause-card {
  width: min(360px, 100%);
  padding: 24px 20px;
  border-radius: 24px;
  background: rgba(30, 27, 75, 0.96);
  border: 4px solid #FACC15;
  text-align: center;
  box-shadow: 0 16px 36px rgba(0, 0, 0, 0.45);
}

#page-games .mg-dj-pause-icon {
  font-size: 2.8rem;
  margin-bottom: 4px;
}

#page-games .mg-dj-pause-title {
  font-family: var(--font-th);
  font-size: 1.5rem;
  font-weight: 800;
  color: #FEF08A;
  margin: 0 0 6px;
}

#page-games .mg-dj-pause-sub {
  font-family: var(--font-th);
  font-size: 0.95rem;
  font-weight: 600;
  color: #E0E7FF;
  margin: 0 0 16px;
}

#page-games .mg-dj-resume-btn {
  border: none;
  cursor: pointer;
  font-family: var(--font-th);
  font-size: 1rem;
  font-weight: 800;
  color: #064E3B;
  background: linear-gradient(180deg, #BBF7D0 0%, #22C55E 100%);
  border-radius: 999px;
  padding: 0.6rem 1.4rem;
  box-shadow: 0 4px 0 #15803D;
}

#page-games .mg-dj-resume-btn:active {
  transform: translateY(2px);
  box-shadow: 0 2px 0 #15803D;
}

/* Victory Overlay */
#page-games .mg-dj-victory-overlay {
  position: absolute;
  inset: 0;
  z-index: 36;
  background: rgba(15, 23, 42, 0.68);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

#page-games .mg-dj-victory-card {
  width: min(390px, 100%);
  background: #FFFFFF;
  border-radius: 24px;
  padding: 22px 18px;
  text-align: center;
  border: 3px solid #FACC15;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.38);
  animation: mg-sj-countdown-pop 0.4s cubic-bezier(0.22, 1.4, 0.36, 1);
}

#page-games .mg-dj-victory-icon {
  font-size: 3rem;
  line-height: 1;
  margin-bottom: 4px;
}

#page-games .mg-dj-victory-title {
  font-family: var(--font-th);
  font-size: 1.45rem;
  font-weight: 800;
  color: #0F172A;
  margin: 0 0 4px;
}

#page-games .mg-dj-victory-word {
  font-family: var(--font-th);
  font-size: 1.08rem;
  font-weight: 800;
  color: #0284C7;
  margin: 0 0 6px;
}

#page-games .mg-dj-victory-stars {
  font-size: 1.85rem;
  letter-spacing: 4px;
  margin-bottom: 10px;
}

#page-games .mg-dj-victory-summary {
  display: flex;
  justify-content: center;
  gap: 10px 14px;
  flex-wrap: wrap;
  font-family: var(--font-th);
  font-size: 0.94rem;
  font-weight: 700;
  color: #1E293B;
  background: #F8FAFC;
  border-radius: 14px;
  padding: 10px 12px;
  margin-bottom: 14px;
  border: 1.5px solid #E2E8F0;
}

#page-games .mg-dj-victory-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}

#page-games .mg-dj-play-again-btn,
#page-games .mg-dj-next-random-btn {
  border: none;
  cursor: pointer;
  font-family: var(--font-th);
  font-size: 0.95rem;
  font-weight: 800;
  border-radius: 999px;
  padding: 0.6rem 1.2rem;
}

#page-games .mg-dj-play-again-btn {
  color: #FFFFFF;
  background: linear-gradient(135deg, #22C55E 0%, #16A34A 100%);
  box-shadow: 0 4px 0 #15803D;
}

#page-games .mg-dj-next-random-btn {
  color: #6B21A8;
  background: linear-gradient(135deg, #F3E8FF 0%, #E9D5FF 100%);
  border: 1.5px solid #C4B5FD;
  box-shadow: 0 4px 0 #A855F7;
}

#page-games .mg-dj-confetti-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 38;
}

#page-games .mg-dj-hint-banner {
  background: rgba(15, 23, 42, 0.72);
  color: #F8FAFC;
  font-family: var(--font-th);
  font-size: 0.86rem;
  font-weight: 600;
  padding: 6px 16px;
  border-radius: 999px;
  text-align: center;
  max-width: 100%;
}

#page-games .mg-dj-hint-banner strong {
  color: #FEF08A;
}

/* Right Column: Timer & Progress Card */
#page-games .mg-dj-timer-card {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 10px;
  padding: 18px 12px;
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.96);
  border: 3px solid #FDE68A;
  box-shadow: 0 10px 24px rgba(15, 23, 42, 0.28);
}

#page-games .mg-dj-timer-icon {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: linear-gradient(135deg, #FEF3C7 0%, #FDE68A 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.85rem;
  box-shadow: 0 4px 0 #F59E0B;
}

#page-games .mg-dj-timer-label {
  font-family: var(--font-th);
  font-size: 0.88rem;
  font-weight: 700;
  color: #92400E;
}

#page-games .mg-dj-timer-value {
  font-family: var(--font-en);
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: 1px;
  color: #B45309;
  background: #FFFBEB;
  border: 2px solid #FCD34D;
  border-radius: 14px;
  padding: 0.32rem 0.85rem;
  width: 100%;
}

#page-games .mg-dj-progress-box {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 8px 10px;
  border-radius: 14px;
  background: #F0FDF4;
  border: 1.5px solid #86EFAC;
}

#page-games .mg-dj-progress-label {
  font-family: var(--font-th);
  font-size: 0.8rem;
  font-weight: 700;
  color: #15803D;
}

#page-games .mg-dj-progress-value {
  font-family: var(--font-en);
  font-size: 1.45rem;
  font-weight: 800;
  color: #16A34A;
  line-height: 1.1;
}

#page-games .mg-dj-pause-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  border: none;
  border-radius: 999px;
  padding: 0.55rem 0.85rem;
  background: linear-gradient(180deg, #FEF3C7 0%, #F59E0B 100%);
  box-shadow: 0 3px 0 #B45309;
  font-family: var(--font-th);
  font-size: 0.88rem;
  font-weight: 800;
  color: #78350F;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.2s ease;
}

#page-games .mg-dj-pause-btn[aria-pressed="true"] {
  background: linear-gradient(180deg, #BBF7D0 0%, #22C55E 100%);
  box-shadow: 0 3px 0 #15803D;
  color: #064E3B;
}

#page-games .mg-dj-pause-btn:active:not(:disabled) {
  transform: translateY(2px);
  box-shadow: 0 1px 0 #B45309;
}

#page-games .mg-dj-pause-btn:disabled {
  background: #E2E8F0;
  color: #94A3B8;
  box-shadow: 0 2px 0 #CBD5E1;
  cursor: not-allowed;
  opacity: 0.8;
}

@media (max-width: 1040px) {
  #page-games .mg-dj-stage {
    grid-template-columns: 1fr 1fr;
  }

  #page-games .mg-dj-col-center {
    grid-column: 1 / -1;
    order: 2;
  }

  #page-games .mg-dj-col-left {
    order: 1;
  }

  #page-games .mg-dj-col-right {
    order: 1;
  }

  #page-games .mg-dj-target-visual {
    width: 110px;
    height: 110px;
  }
}

@media (max-width: 680px) {
  #page-games .mg-dj-header {
    padding: 8px 10px;
    gap: 8px;
  }

  #page-games .mg-dj-stage {
    grid-template-columns: 1fr;
    padding: 10px;
    gap: 10px;
  }

  #page-games .mg-dj-arena {
    grid-template-columns: 1fr;
    min-height: 530px;
  }

  #page-games .mg-dj-drop-zone {
    width: min(100%, 260px);
  }

  #page-games .mg-dj-scatter-zone {
    height: 210px;
    min-height: 190px;
  }

  #page-games .mg-dj-hint-banner {
    font-size: 0.75rem;
  }
}

/* ===================================================================
   VIP MINI-GAME: PIXEL ART COLORING (#page-games .mg-pa-*)
   =================================================================== */

#page-games .mg-pa-container {
  display: none;
  flex-direction: column;
  gap: 10px;
  width: 100%;
  max-width: 1240px;
  margin: 0 auto;
}

#page-games.mg-pa-playing .mg-hub-container {
  display: none;
}

#page-games.mg-pa-playing .mg-pa-container {
  display: flex;
}

#page-games .mg-pa-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 12px;
  background: #FFFFFF;
  border-radius: 20px;
  padding: 10px 16px;
  box-shadow: 0 6px 18px rgba(60, 90, 130, 0.1);
  border: 2px solid #FEF08A;
}

#page-games .mg-pa-back {
  border: 1.5px solid #FDE68A;
  background: #FFFBEB;
  color: #B45309;
  font-family: var(--font-th);
  font-size: 0.92rem;
  font-weight: 700;
  border-radius: var(--radius-pill);
  padding: 0.5rem 0.95rem;
  cursor: pointer;
}

#page-games .mg-pa-back:hover {
  background: #FEF3C7;
}

#page-games .mg-pa-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-right: auto;
}

#page-games .mg-pa-vip-pill {
  padding: 0.22rem 0.65rem;
  border-radius: 999px;
  background: linear-gradient(135deg, #FEF08A 0%, #F59E0B 100%);
  color: #78350F;
  font-family: var(--font-en);
  font-size: 0.78rem;
  font-weight: 800;
  box-shadow: 0 2px 0 #D97706;
}

#page-games .mg-pa-title {
  font-family: var(--font-en);
  font-size: 1.35rem;
  font-weight: 700;
  color: #1E293B;
  margin: 0;
}

#page-games .mg-pa-word-picker {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

#page-games .mg-pa-field-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-th);
  font-weight: 700;
  font-size: 0.92rem;
  color: #475569;
}

#page-games .mg-pa-category,
#page-games .mg-pa-word,
#page-games .mg-pa-difficulty {
  font-family: var(--font-th);
  font-size: 0.92rem;
  font-weight: 700;
  color: #1E293B;
  background: #F8FAFC;
  border: 1.5px solid #CBD5E1;
  border-radius: 12px;
  padding: 0.45rem 0.65rem;
  max-width: 210px;
  cursor: pointer;
}

#page-games .mg-pa-random-btn {
  border: 1.5px solid #C4B5FD;
  background: linear-gradient(135deg, #F3E8FF 0%, #E9D5FF 100%);
  color: #6B21A8;
  font-family: var(--font-th);
  font-size: 0.88rem;
  font-weight: 800;
  border-radius: var(--radius-pill);
  padding: 0.46rem 0.9rem;
  cursor: pointer;
  box-shadow: 0 3px 0 #A855F7;
  transition: transform 0.15s ease, box-shadow 0.15s ease, filter 0.15s ease;
  white-space: nowrap;
}

#page-games .mg-pa-random-btn:hover {
  filter: brightness(1.03);
}

#page-games .mg-pa-random-btn:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 #A855F7;
}

#page-games .mg-pa-start-btn {
  border: none;
  cursor: pointer;
  font-family: var(--font-th);
  font-size: 0.95rem;
  font-weight: 800;
  color: #FFFFFF;
  background: linear-gradient(135deg, #22C55E 0%, #16A34A 100%);
  border-radius: var(--radius-pill);
  padding: 0.52rem 1.1rem;
  box-shadow: 0 3px 0 #15803D;
  transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.2s ease, opacity 0.2s ease;
  white-space: nowrap;
}

#page-games .mg-pa-start-btn:hover:not(:disabled) {
  background: linear-gradient(135deg, #4ADE80 0%, #22C55E 100%);
}

#page-games .mg-pa-start-btn:active:not(:disabled) {
  transform: translateY(2px);
  box-shadow: 0 1px 0 #15803D;
}

#page-games .mg-pa-start-btn:disabled {
  background: #CBD5E1;
  color: #64748B;
  box-shadow: 0 2px 0 #94A3B8;
  cursor: not-allowed;
  opacity: 0.8;
}

#page-games .mg-pa-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

#page-games .mg-pa-btn-bgm {
  width: 42px;
  height: 42px;
  border: none;
  border-radius: 14px;
  background: #ECFEFF;
  font-size: 1.2rem;
  cursor: pointer;
}

#page-games .mg-pa-btn-bgm[aria-pressed="true"] {
  background: #E2E8F0;
}

#page-games .mg-pa-restart-btn {
  border: none;
  cursor: pointer;
  font-family: var(--font-th);
  font-size: 0.9rem;
  font-weight: 700;
  border-radius: var(--radius-pill);
  padding: 0.5rem 0.9rem;
  background: linear-gradient(135deg, #FF7B90 0%, #FF4D6D 100%);
  color: #FFFFFF;
  box-shadow: 0 3px 0 #E11D48;
}

#page-games .mg-pa-restart-btn:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 #E11D48;
}

/* 3-Column Arena: Left (Reference + Word + Timer) | Center (Vertical Palette) | Right (Playable Grid) */
#page-games .mg-pa-arena {
  --mg-pa-size: 8;
  display: grid;
  grid-template-columns: clamp(210px, 21vw, 270px) clamp(104px, 9vw, 124px) minmax(0, 1fr);
  gap: 14px;
  padding: 14px;
  width: 100%;
  height: clamp(500px, calc(100vh - 290px), 920px);
  height: clamp(500px, calc(100dvh - 290px), 920px);
  border-radius: 24px;
  overflow: hidden;
  background: linear-gradient(180deg, #1E1B4B 0%, #312E81 42%, #4338CA 80%, #6366F1 100%);
  box-shadow:
    inset 0 0 0 4px rgba(255, 255, 255, 0.25),
    0 12px 28px rgba(30, 27, 75, 0.22);
  user-select: none;
}

/* Left Column: Pixel Reference, Word Card, Timer Card */
#page-games .mg-pa-col-left {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
  min-height: 0;
  overflow-y: auto;
  scrollbar-width: thin;
  z-index: 2;
}

#page-games .mg-pa-panel {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

#page-games .mg-pa-ref-panel {
  flex-shrink: 0;
  padding: 8px;
  border-radius: 18px;
  background: rgba(15, 23, 42, 0.55);
  border: 1.5px solid rgba(255, 255, 255, 0.18);
  container-type: inline-size;
}

#page-games .mg-pa-zone-tag {
  font-family: var(--font-th);
  font-size: 0.78rem;
  font-weight: 800;
  color: #FEF08A;
  background: rgba(15, 23, 42, 0.82);
  border: 1.5px solid rgba(250, 204, 21, 0.55);
  border-radius: 999px;
  padding: 3px 10px;
  white-space: nowrap;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}

#page-games .mg-pa-target-card {
  flex-shrink: 0;
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.96);
  border: 3px solid #7DD3FC;
  box-shadow: 0 8px 20px rgba(15, 23, 42, 0.28);
}

#page-games .mg-pa-target-visual {
  width: 72px;
  height: 72px;
  border-radius: 14px;
  background: #FFFFFF;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  border: 2.5px solid #BAE6FD;
  box-shadow: 0 4px 0 #BAE6FD;
  flex-shrink: 0;
}

#page-games .mg-pa-target-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  padding: 4px;
}

#page-games .mg-pa-target-fallback {
  font-family: var(--font-en);
  font-size: 2.2rem;
  font-weight: 800;
  color: #0284C7;
}

#page-games .mg-pa-target-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
}

#page-games .mg-pa-target-en {
  font-family: var(--font-en);
  font-size: 1.2rem;
  font-weight: 800;
  letter-spacing: 0.5px;
  color: #0F172A;
  line-height: 1.15;
  overflow-wrap: anywhere;
}

#page-games .mg-pa-target-th {
  font-family: var(--font-th);
  font-size: 0.95rem;
  font-weight: 700;
  color: #0369A1;
  line-height: 1.25;
}

#page-games .mg-pa-speak-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  margin-top: 4px;
  border: none;
  border-radius: 999px;
  padding: 0.3rem 0.75rem;
  background: linear-gradient(180deg, #FEF9C3 0%, #FACC15 100%);
  box-shadow: 0 3px 0 #CA8A04;
  font-family: var(--font-th);
  font-size: 0.8rem;
  font-weight: 700;
  color: #713F12;
  cursor: pointer;
}

#page-games .mg-pa-speak-btn:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 #CA8A04;
}

#page-games .mg-pa-timer-card {
  flex-shrink: 0;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.96);
  border: 3px solid #FDE68A;
  box-shadow: 0 8px 20px rgba(15, 23, 42, 0.28);
}

#page-games .mg-pa-timer-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

#page-games .mg-pa-timer-icon {
  width: 36px;
  height: 36px;
  flex-shrink: 0;
  border-radius: 50%;
  background: linear-gradient(135deg, #FEF3C7 0%, #FDE68A 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  box-shadow: 0 3px 0 #F59E0B;
}

#page-games .mg-pa-timer-label {
  flex: 1;
  min-width: 0;
  font-family: var(--font-th);
  font-size: 0.82rem;
  font-weight: 700;
  color: #92400E;
}

#page-games .mg-pa-timer-value {
  font-family: var(--font-en);
  font-size: 1.5rem;
  font-weight: 800;
  letter-spacing: 1px;
  color: #B45309;
  background: #FFFBEB;
  border: 2px solid #FCD34D;
  border-radius: 10px;
  padding: 0.12rem 0.55rem;
}

#page-games .mg-pa-progress-box {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 7px 9px;
  border-radius: 12px;
  background: #F0FDF4;
  border: 1.5px solid #86EFAC;
}

#page-games .mg-pa-progress-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 6px;
}

#page-games .mg-pa-progress-label {
  font-family: var(--font-th);
  font-size: 0.8rem;
  font-weight: 700;
  color: #15803D;
}

#page-games .mg-pa-progress-value {
  font-family: var(--font-en);
  font-size: 1.2rem;
  font-weight: 800;
  color: #16A34A;
  line-height: 1.1;
}

#page-games .mg-pa-progress-sub {
  align-self: center;
  font-family: var(--font-th);
  font-size: 0.74rem;
  font-weight: 700;
  color: #15803D;
}

#page-games .mg-pa-progress-track {
  width: 100%;
  height: 8px;
  border-radius: 999px;
  background: #DCFCE7;
  overflow: hidden;
}

#page-games .mg-pa-progress-fill {
  width: 0%;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #4ADE80 0%, #16A34A 100%);
  transition: width 0.2s ease;
}

#page-games .mg-pa-pause-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  border: none;
  border-radius: 999px;
  padding: 0.5rem 0.85rem;
  background: linear-gradient(180deg, #FEF3C7 0%, #F59E0B 100%);
  box-shadow: 0 3px 0 #B45309;
  font-family: var(--font-th);
  font-size: 0.86rem;
  font-weight: 800;
  color: #78350F;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.2s ease;
}

#page-games .mg-pa-pause-btn[aria-pressed="true"] {
  background: linear-gradient(180deg, #BBF7D0 0%, #22C55E 100%);
  box-shadow: 0 3px 0 #15803D;
  color: #064E3B;
}

#page-games .mg-pa-pause-btn:active:not(:disabled) {
  transform: translateY(2px);
  box-shadow: 0 1px 0 #B45309;
}

#page-games .mg-pa-pause-btn:disabled {
  background: #E2E8F0;
  color: #94A3B8;
  box-shadow: 0 2px 0 #CBD5E1;
  cursor: not-allowed;
  opacity: 0.8;
}

/* Center Column: Vertical Color Palette + Helper Tools */
#page-games .mg-pa-col-center {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
  min-height: 0;
  z-index: 2;
}

#page-games .mg-pa-palette-bar {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 10px 6px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.96);
  border: 2.5px solid #BAE6FD;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.25);
}

#page-games .mg-pa-palette-header {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

#page-games .mg-pa-palette-title {
  font-family: var(--font-th);
  font-size: 0.88rem;
  font-weight: 800;
  color: #0F172A;
  white-space: nowrap;
}

#page-games .mg-pa-palette-meta {
  font-family: var(--font-th);
  font-size: 0.74rem;
  font-weight: 800;
  color: #0369A1;
  background: #E0F2FE;
  padding: 1px 10px;
  border-radius: 999px;
}

#page-games .mg-pa-palette-list {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 10px 4px;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: thin;
}

/* Circular Palette Swatch Buttons (numbered) */
#page-games .mg-pa-swatch-btn {
  position: relative;
  flex-shrink: 0;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: 3px solid #CBD5E1;
  background: var(--mg-pa-swatch-color, #FFFFFF);
  cursor: pointer;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow:
    0 4px 0 rgba(15, 23, 42, 0.22),
    inset 0 2px 4px rgba(255, 255, 255, 0.45);
  transition: transform 0.16s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.16s ease, border-color 0.16s ease;
}

#page-games .mg-pa-swatch-btn:hover {
  transform: scale(1.06);
}

#page-games .mg-pa-swatch-btn.mg-pa-swatch-active {
  transform: scale(1.1);
  border-color: #0F172A;
  box-shadow:
    0 0 0 4px #FACC15,
    0 6px 14px rgba(15, 23, 42, 0.35),
    inset 0 2px 4px rgba(255, 255, 255, 0.5);
  z-index: 2;
}

#page-games .mg-pa-swatch-num {
  font-family: var(--font-en);
  font-size: 1.3rem;
  font-weight: 900;
  line-height: 1;
  color: #FFFFFF;
  text-shadow:
    0 1px 3px rgba(0, 0, 0, 0.85),
    0 0 2px rgba(0, 0, 0, 0.9);
  pointer-events: none;
}

#page-games .mg-pa-swatch-btn.mg-pa-swatch-light .mg-pa-swatch-num {
  color: #0F172A;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.9);
}

#page-games .mg-pa-swatch-done {
  position: absolute;
  top: -4px;
  right: -4px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #22C55E;
  border: 2px solid #FFFFFF;
  color: #FFFFFF;
  font-size: 0.68rem;
  font-weight: 900;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.25);
  pointer-events: none;
}

#page-games .mg-pa-swatch-done[hidden] {
  display: none !important;
}

#page-games .mg-pa-hint-toolbar {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
  padding: 8px 6px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.96);
  border: 2.5px solid #FDE68A;
  box-shadow: 0 6px 18px rgba(15, 23, 42, 0.25);
}

#page-games .mg-pa-peek-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  border: 2px solid #F59E0B;
  border-radius: 14px;
  padding: 0.35rem 0.25rem;
  background: linear-gradient(180deg, #FEF9C3 0%, #FACC15 100%);
  box-shadow: 0 4px 0 #D97706;
  color: #78350F;
  font-family: var(--font-th);
  font-size: 0.74rem;
  font-weight: 800;
  line-height: 1.2;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  transition: transform 0.12s ease, box-shadow 0.12s ease, filter 0.15s ease;
}

#page-games .mg-pa-peek-btn:hover:not(:disabled) {
  filter: brightness(1.04);
}

#page-games .mg-pa-peek-btn:active:not(:disabled),
#page-games .mg-pa-peek-btn.mg-pa-peek-active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 #D97706;
  background: linear-gradient(180deg, #FDE047 0%, #F59E0B 100%);
  color: #451A03;
}

#page-games .mg-pa-peek-btn:disabled {
  background: #E2E8F0;
  border-color: #CBD5E1;
  color: #94A3B8;
  box-shadow: 0 2px 0 #CBD5E1;
  cursor: not-allowed;
  opacity: 0.78;
}

#page-games .mg-pa-peek-icon {
  font-size: 1.1rem;
  line-height: 1;
}

#page-games .mg-pa-num-switch {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  padding: 6px 4px;
  border-radius: 14px;
  background: #F0F9FF;
  border: 2px solid #BAE6FD;
  user-select: none;
  -webkit-user-select: none;
  transition: background 0.2s ease, border-color 0.2s ease;
}

#page-games .mg-pa-num-switch:hover {
  background: #E0F2FE;
}

#page-games .mg-pa-num-checkbox {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
  pointer-events: none;
}

#page-games .mg-pa-num-slider {
  position: relative;
  width: 44px;
  height: 24px;
  border-radius: 999px;
  background: #CBD5E1;
  box-shadow: inset 0 2px 4px rgba(15, 23, 42, 0.18);
  transition: background 0.25s ease;
  flex-shrink: 0;
}

#page-games .mg-pa-num-slider::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #FFFFFF;
  box-shadow: 0 2px 5px rgba(15, 23, 42, 0.28);
  transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}

#page-games .mg-pa-num-checkbox:checked + .mg-pa-num-slider {
  background: linear-gradient(135deg, #38BDF8 0%, #0284C7 100%);
}

#page-games .mg-pa-num-checkbox:checked + .mg-pa-num-slider::after {
  transform: translateX(20px);
}

#page-games .mg-pa-num-switch-label {
  font-family: var(--font-th);
  font-size: 0.74rem;
  font-weight: 800;
  color: #0369A1;
  white-space: nowrap;
}

#page-games .mg-pa-clear-btn {
  border: 1.5px solid #FECDD3;
  background: linear-gradient(135deg, #FFF1F2 0%, #FFE4E6 100%);
  color: #BE123C;
  font-family: var(--font-th);
  font-size: 0.74rem;
  font-weight: 800;
  line-height: 1.2;
  border-radius: 14px;
  padding: 0.4rem 0.25rem;
  cursor: pointer;
  box-shadow: 0 3px 0 #F43F5E;
  transition: transform 0.12s ease, box-shadow 0.12s ease, opacity 0.2s ease;
}

#page-games .mg-pa-clear-btn:active:not(:disabled) {
  transform: translateY(2px);
  box-shadow: 0 1px 0 #F43F5E;
}

#page-games .mg-pa-clear-btn:disabled {
  background: #E2E8F0;
  border-color: #CBD5E1;
  color: #94A3B8;
  box-shadow: 0 2px 0 #CBD5E1;
  cursor: not-allowed;
  opacity: 0.75;
}

/* Right Column: Largest possible square Playable Grid */
#page-games .mg-pa-col-right {
  min-width: 0;
  min-height: 0;
  container-type: size;
  display: flex;
  align-items: center;
  justify-content: center;
}

#page-games .mg-pa-board-wrap {
  position: relative;
  width: min(100cqw, 100cqh);
  aspect-ratio: 1 / 1;
  border-radius: 22px;
  padding: 10px;
  background: linear-gradient(145deg, #FEF08A 0%, #F59E0B 100%);
  box-shadow:
    0 12px 30px rgba(15, 23, 42, 0.4),
    inset 0 2px 0 rgba(255, 255, 255, 0.65);
  overflow: hidden;
}

#page-games .mg-pa-board-fit {
  width: 100%;
  height: 100%;
}

#page-games .mg-pa-countdown-overlay[hidden],
#page-games .mg-pa-pause-overlay[hidden],
#page-games .mg-pa-victory-overlay[hidden],
#page-games .mg-pa-idle-banner[hidden] {
  display: none !important;
}

#page-games .mg-pa-grid-frame {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: 14px;
  padding: 5px;
  background: #FFFFFF;
  border: 3px solid #38BDF8;
  box-shadow:
    0 8px 22px rgba(0, 0, 0, 0.38),
    0 0 0 3px rgba(56, 189, 248, 0.2);
  overflow: hidden;
}

#page-games .mg-pa-play-frame {
  height: 100%;
  border-color: #FACC15;
  box-shadow: inset 0 0 0 1px rgba(250, 204, 21, 0.35);
}

#page-games .mg-pa-arena.mg-pa-board-solved .mg-pa-play-frame {
  border-color: #4ADE80;
  box-shadow: 0 0 0 4px rgba(74, 222, 128, 0.45);
}

/* Reference & Playable Pixel Grids */
#page-games .mg-pa-ref-grid,
#page-games .mg-pa-play-grid {
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-columns: repeat(var(--mg-pa-size), 1fr);
  grid-template-rows: repeat(var(--mg-pa-size), 1fr);
  border: 1px solid #CBD5E1;
  border-radius: 8px;
  overflow: hidden;
  background: #F8FAFC;
}

#page-games .mg-pa-play-grid {
  touch-action: none;
  cursor: crosshair;
}

#page-games .mg-pa-arena.mg-pa-locked .mg-pa-play-grid {
  pointer-events: none;
  cursor: not-allowed;
}

#page-games .mg-pa-ref-cell,
#page-games .mg-pa-play-cell {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  min-height: 0;
  border-right: 1px solid rgba(148, 163, 184, 0.32);
  border-bottom: 1px solid rgba(148, 163, 184, 0.32);
  padding: 0;
  margin: 0;
  user-select: none;
  -webkit-user-select: none;
  transition: transform 0.08s ease, box-shadow 0.12s ease;
}

#page-games .mg-pa-play-cell {
  background-color: #F1F5F9;
  background-image: radial-gradient(rgba(148, 163, 184, 0.28) 1px, transparent 0);
  background-size: 6px 6px;
}

#page-games .mg-pa-play-cell.mg-pa-cell-painted {
  background-image: none;
}

#page-games .mg-pa-play-cell:hover {
  z-index: 2;
  box-shadow: inset 0 0 0 3px rgba(250, 204, 21, 0.92);
}

#page-games .mg-pa-play-cell.mg-pa-cell-pop {
  animation: mg-pa-cell-pop 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes mg-pa-cell-pop {
  0% {
    transform: scale(0.84);
  }
  60% {
    transform: scale(1.08);
  }
  100% {
    transform: scale(1);
  }
}

/* Cell Color Numbers (scale with each grid's own size) */
#page-games .mg-pa-cell-num {
  font-family: var(--font-en);
  font-weight: 800;
  line-height: 1;
  color: rgba(15, 23, 42, 0.55);
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
}

#page-games .mg-pa-ref-cell .mg-pa-cell-num {
  font-size: max(0.45rem, calc(100cqw / var(--mg-pa-size) * 0.38));
  color: rgba(15, 23, 42, 0.72);
  background: rgba(255, 255, 255, 0.68);
  padding: 1px 3px;
  border-radius: 4px;
}

#page-games .mg-pa-play-cell .mg-pa-cell-num {
  font-size: max(0.6rem, calc(min(100cqw, 100cqh) / var(--mg-pa-size) * 0.42));
}

#page-games .mg-pa-play-cell.mg-pa-cell-correct .mg-pa-cell-num {
  opacity: 0;
  transform: scale(0.6);
}

#page-games .mg-pa-play-cell.mg-pa-cell-wrong .mg-pa-cell-num {
  opacity: 1;
  color: #FFFFFF;
  background: rgba(225, 29, 72, 0.86);
  padding: 0.12em 0.32em;
  border-radius: 999px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
}

/* Highlight matching cells for currently selected color */
#page-games .mg-pa-play-cell.mg-pa-cell-target-match:not(.mg-pa-cell-correct) .mg-pa-cell-num {
  color: #0F172A;
  background: rgba(254, 240, 138, 0.92);
  padding: 0.12em 0.32em;
  border-radius: 6px;
  box-shadow: 0 0 0 1px rgba(202, 138, 4, 0.45);
}

#page-games .mg-pa-arena.mg-pa-hide-nums .mg-pa-cell-num,
#page-games .mg-pa-arena.mg-pa-board-solved .mg-pa-cell-num {
  opacity: 0 !important;
}

#page-games .mg-pa-arena.mg-pa-board-solved .mg-pa-ref-cell,
#page-games .mg-pa-arena.mg-pa-board-solved .mg-pa-play-cell {
  border-color: rgba(148, 163, 184, 0.12);
}

/* Hold-to-Peek Ghost Color Hint on Playable Grid */
#page-games .mg-pa-arena.mg-pa-peeking .mg-pa-play-cell:not(.mg-pa-cell-correct) {
  background-color: var(--mg-pa-target-color, #F1F5F9) !important;
  background-image: none;
  opacity: 0.72;
}

/* Idle Lock Banner on Playable Grid */
#page-games .mg-pa-idle-banner {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 12px;
  z-index: 10;
  padding: 10px 14px;
  border-radius: 14px;
  background: rgba(15, 23, 42, 0.88);
  border: 2px solid #FACC15;
  color: #FFFFFF;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 2px;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.4);
  pointer-events: none;
}

#page-games .mg-pa-idle-banner-title {
  font-family: var(--font-th);
  font-size: 1rem;
  font-weight: 800;
  color: #FEF08A;
}

#page-games .mg-pa-idle-banner-sub {
  font-family: var(--font-th);
  font-size: 0.82rem;
  font-weight: 600;
  color: #F8FAFC;
  line-height: 1.35;
}

/* Countdown, Pause, Victory Overlays */
#page-games .mg-pa-countdown-overlay {
  position: absolute;
  inset: 0;
  z-index: 35;
  background: rgba(15, 23, 42, 0.56);
  display: flex;
  align-items: center;
  justify-content: center;
}

#page-games .mg-pa-countdown-circle {
  width: 156px;
  height: 156px;
  border-radius: 50%;
  background: rgba(30, 27, 75, 0.92);
  border: 6px solid #FACC15;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 14px 32px rgba(0, 0, 0, 0.45);
  animation: mg-sj-countdown-pop 0.45s cubic-bezier(0.22, 1.4, 0.36, 1);
}

#page-games .mg-pa-countdown-circle.mg-pa-countdown-go {
  width: 176px;
  height: 176px;
  background: rgba(34, 197, 94, 0.94);
  border-color: #BBF7D0;
}

#page-games .mg-pa-countdown-text {
  font-family: var(--font-en);
  font-size: 4.8rem;
  font-weight: 900;
  color: #FFFFFF;
  text-shadow: 0 6px 14px rgba(0, 0, 0, 0.4);
  line-height: 1;
}

#page-games .mg-pa-countdown-circle.mg-pa-countdown-go .mg-pa-countdown-text {
  font-size: 3.9rem;
}

#page-games .mg-pa-pause-overlay {
  position: absolute;
  inset: 0;
  z-index: 34;
  background: rgba(15, 23, 42, 0.84);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

#page-games .mg-pa-pause-card {
  width: min(360px, 100%);
  padding: 24px 20px;
  border-radius: 24px;
  background: rgba(30, 27, 75, 0.96);
  border: 4px solid #FACC15;
  text-align: center;
  box-shadow: 0 16px 36px rgba(0, 0, 0, 0.45);
}

#page-games .mg-pa-pause-icon {
  font-size: 2.8rem;
  margin-bottom: 4px;
}

#page-games .mg-pa-pause-title {
  font-family: var(--font-th);
  font-size: 1.5rem;
  font-weight: 800;
  color: #FEF08A;
  margin: 0 0 6px;
}

#page-games .mg-pa-pause-sub {
  font-family: var(--font-th);
  font-size: 0.95rem;
  font-weight: 600;
  color: #E0E7FF;
  margin: 0 0 16px;
}

#page-games .mg-pa-resume-btn {
  border: none;
  cursor: pointer;
  font-family: var(--font-th);
  font-size: 1rem;
  font-weight: 800;
  color: #064E3B;
  background: linear-gradient(180deg, #BBF7D0 0%, #22C55E 100%);
  border-radius: 999px;
  padding: 0.6rem 1.4rem;
  box-shadow: 0 4px 0 #15803D;
}

#page-games .mg-pa-resume-btn:active {
  transform: translateY(2px);
  box-shadow: 0 2px 0 #15803D;
}

#page-games .mg-pa-victory-overlay {
  position: absolute;
  inset: 0;
  z-index: 36;
  background: rgba(15, 23, 42, 0.68);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

#page-games .mg-pa-victory-card {
  width: min(390px, 100%);
  background: #FFFFFF;
  border-radius: 24px;
  padding: 22px 18px;
  text-align: center;
  border: 3px solid #FACC15;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.38);
  animation: mg-sj-countdown-pop 0.4s cubic-bezier(0.22, 1.4, 0.36, 1);
}

#page-games .mg-pa-victory-icon {
  font-size: 3rem;
  line-height: 1;
  margin-bottom: 4px;
}

#page-games .mg-pa-victory-title {
  font-family: var(--font-th);
  font-size: 1.4rem;
  font-weight: 800;
  color: #0F172A;
  margin: 0 0 4px;
}

#page-games .mg-pa-victory-word {
  font-family: var(--font-th);
  font-size: 1.08rem;
  font-weight: 800;
  color: #0284C7;
  margin: 0 0 6px;
}

#page-games .mg-pa-victory-stars {
  font-size: 1.85rem;
  letter-spacing: 4px;
  margin-bottom: 10px;
}

#page-games .mg-pa-victory-summary {
  display: flex;
  justify-content: center;
  gap: 10px 14px;
  flex-wrap: wrap;
  font-family: var(--font-th);
  font-size: 0.94rem;
  font-weight: 700;
  color: #1E293B;
  background: #F8FAFC;
  border-radius: 14px;
  padding: 10px 12px;
  margin-bottom: 14px;
  border: 1.5px solid #E2E8F0;
}

#page-games .mg-pa-victory-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}

#page-games .mg-pa-play-again-btn,
#page-games .mg-pa-next-random-btn {
  border: none;
  cursor: pointer;
  font-family: var(--font-th);
  font-size: 0.95rem;
  font-weight: 800;
  border-radius: 999px;
  padding: 0.6rem 1.2rem;
}

#page-games .mg-pa-play-again-btn {
  color: #FFFFFF;
  background: linear-gradient(135deg, #22C55E 0%, #16A34A 100%);
  box-shadow: 0 4px 0 #15803D;
}

#page-games .mg-pa-next-random-btn {
  color: #6B21A8;
  background: linear-gradient(135deg, #F3E8FF 0%, #E9D5FF 100%);
  border: 1.5px solid #C4B5FD;
  box-shadow: 0 4px 0 #A855F7;
}

#page-games .mg-pa-confetti-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 38;
}

/* Tablet / Mobile: stack columns, palette becomes horizontal */
@media (max-width: 860px) {
  #page-games .mg-pa-arena {
    grid-template-columns: minmax(0, 1fr);
    height: auto;
    padding: 10px;
    gap: 10px;
  }

  #page-games .mg-pa-col-left {
    flex-direction: row;
    flex-wrap: wrap;
    overflow: visible;
  }

  #page-games .mg-pa-ref-panel {
    width: 180px;
  }

  #page-games .mg-pa-target-card,
  #page-games .mg-pa-timer-card {
    flex: 1 1 220px;
    width: auto;
  }

  #page-games .mg-pa-col-center {
    flex-direction: row;
    flex-wrap: wrap;
  }

  #page-games .mg-pa-palette-bar {
    flex: 1 1 260px;
  }

  #page-games .mg-pa-palette-header {
    flex-direction: row;
    justify-content: center;
  }

  #page-games .mg-pa-palette-list {
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: center;
    overflow: visible;
  }

  #page-games .mg-pa-swatch-btn {
    width: 46px;
    height: 46px;
  }

  #page-games .mg-pa-hint-toolbar {
    flex: 1 1 100%;
    flex-direction: row;
    justify-content: center;
  }

  #page-games .mg-pa-col-right {
    container-type: inline-size;
  }

  #page-games .mg-pa-board-wrap {
    width: min(100cqw, 640px);
  }

  #page-games .mg-pa-play-cell .mg-pa-cell-num {
    font-size: max(0.55rem, calc(min(100cqw, 640px) / var(--mg-pa-size) * 0.4));
  }
}

@media (max-width: 680px) {
  #page-games .mg-pa-header {
    padding: 8px 10px;
    gap: 8px;
  }

  #page-games .mg-pa-ref-panel {
    width: 100%;
  }
}

/* ===================================================================
   VIP MINI-GAME: SHEEP CROSSING — POSITIVE HANGMAN (#page-games .mg-hm-*)
   =================================================================== */

#page-games .mg-hm-container {
  display: none;
  flex-direction: column;
  gap: 10px;
  width: 100%;
  max-width: 1240px;
  margin: 0 auto;
  outline: none;
}

#page-games.mg-hm-playing .mg-hub-container {
  display: none;
}

#page-games.mg-hm-playing .mg-hm-container {
  display: flex;
}

#page-games .mg-hm-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 12px;
  background: #FFFFFF;
  border-radius: 20px;
  padding: 10px 16px;
  box-shadow: 0 6px 18px rgba(60, 90, 130, 0.1);
  border: 2px solid #BAE6FD;
}

#page-games .mg-hm-back {
  border: 1.5px solid #BAE6FD;
  background: #F0F9FF;
  color: #0369A1;
  font-family: var(--font-th);
  font-size: 0.92rem;
  font-weight: 700;
  border-radius: var(--radius-pill);
  padding: 0.5rem 0.95rem;
  cursor: pointer;
}

#page-games .mg-hm-back:hover {
  background: #E0F2FE;
}

#page-games .mg-hm-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-right: auto;
}

#page-games .mg-hm-vip-pill {
  padding: 0.22rem 0.65rem;
  border-radius: 999px;
  background: linear-gradient(135deg, #FEF08A 0%, #F59E0B 100%);
  color: #78350F;
  font-family: var(--font-en);
  font-size: 0.78rem;
  font-weight: 800;
  box-shadow: 0 2px 0 #D97706;
}

#page-games .mg-hm-title {
  font-family: var(--font-en);
  font-size: 1.35rem;
  font-weight: 700;
  color: #1E293B;
  margin: 0;
}

#page-games .mg-hm-word-picker {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

#page-games .mg-hm-field-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-th);
  font-weight: 700;
  font-size: 0.92rem;
  color: #475569;
}

#page-games .mg-hm-category,
#page-games .mg-hm-word {
  font-family: var(--font-th);
  font-size: 0.92rem;
  font-weight: 700;
  color: #1E293B;
  background: #F8FAFC;
  border: 1.5px solid #CBD5E1;
  border-radius: 12px;
  padding: 0.45rem 0.65rem;
  max-width: 210px;
  cursor: pointer;
}

#page-games .mg-hm-random-btn {
  border: 1.5px solid #C4B5FD;
  background: linear-gradient(135deg, #F3E8FF 0%, #E9D5FF 100%);
  color: #6B21A8;
  font-family: var(--font-th);
  font-size: 0.88rem;
  font-weight: 800;
  border-radius: var(--radius-pill);
  padding: 0.46rem 0.9rem;
  cursor: pointer;
  box-shadow: 0 3px 0 #A855F7;
  white-space: nowrap;
}

#page-games .mg-hm-random-btn:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 #A855F7;
}

#page-games .mg-hm-start-btn {
  border: none;
  cursor: pointer;
  font-family: var(--font-th);
  font-size: 0.95rem;
  font-weight: 800;
  color: #FFFFFF;
  background: linear-gradient(135deg, #22C55E 0%, #16A34A 100%);
  border-radius: var(--radius-pill);
  padding: 0.52rem 1.1rem;
  box-shadow: 0 3px 0 #15803D;
  white-space: nowrap;
}

#page-games .mg-hm-start-btn:hover:not(:disabled) {
  background: linear-gradient(135deg, #4ADE80 0%, #22C55E 100%);
}

#page-games .mg-hm-start-btn:active:not(:disabled) {
  transform: translateY(2px);
  box-shadow: 0 1px 0 #15803D;
}

#page-games .mg-hm-start-btn:disabled {
  background: #CBD5E1;
  color: #64748B;
  box-shadow: 0 2px 0 #94A3B8;
  cursor: not-allowed;
  opacity: 0.8;
}

#page-games .mg-hm-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

#page-games .mg-hm-btn-bgm {
  width: 42px;
  height: 42px;
  border: none;
  border-radius: 14px;
  background: #ECFEFF;
  font-size: 1.2rem;
  cursor: pointer;
}

#page-games .mg-hm-btn-bgm[aria-pressed="true"] {
  background: #E2E8F0;
}

#page-games .mg-hm-restart-btn {
  border: none;
  cursor: pointer;
  font-family: var(--font-th);
  font-size: 0.9rem;
  font-weight: 700;
  border-radius: var(--radius-pill);
  padding: 0.5rem 0.9rem;
  background: linear-gradient(135deg, #FF7B90 0%, #FF4D6D 100%);
  color: #FFFFFF;
  box-shadow: 0 3px 0 #E11D48;
}

#page-games .mg-hm-restart-btn:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 #E11D48;
}

/* 2-Column Arena: Main Stage (River + Word Slots) | Control Panel (Lives + Keyboard + Timer) */
#page-games .mg-hm-arena {
  --mg-hm-progress: 0;
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) clamp(300px, 30vw, 380px);
  gap: 14px;
  padding: 14px;
  width: 100%;
  height: clamp(540px, calc(100vh - 250px), 860px);
  height: clamp(540px, calc(100dvh - 250px), 860px);
  border-radius: 24px;
  overflow: hidden;
  background: linear-gradient(180deg, #E0F2FE 0%, #BAE6FD 100%);
  box-shadow:
    inset 0 0 0 4px rgba(255, 255, 255, 0.6),
    0 12px 28px rgba(2, 132, 199, 0.18);
  user-select: none;
}

#page-games .mg-hm-arena [hidden] {
  display: none !important;
}

#page-games .mg-hm-col-main {
  position: relative;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  gap: 12px;
  min-width: 0;
  min-height: 0;
}

/* River Scene */
#page-games .mg-hm-river {
  position: relative;
  min-height: 230px;
  border-radius: 20px;
  overflow: hidden;
  background: linear-gradient(180deg, #7DD3FC 0%, #BAE6FD 55%, #E0F2FE 100%);
  border: 3px solid #FFFFFF;
  box-shadow: 0 8px 20px rgba(2, 132, 199, 0.18);
}

#page-games .mg-hm-sun {
  position: absolute;
  top: 10px;
  right: 24%;
  font-size: clamp(2rem, 4vw, 2.8rem);
  line-height: 1;
  animation: mg-hm-sun-glow 4s ease-in-out infinite;
}

#page-games .mg-hm-cloud {
  position: absolute;
  font-size: clamp(1.8rem, 3.6vw, 2.6rem);
  line-height: 1;
  opacity: 0.95;
  animation: mg-hm-cloud-drift 14s ease-in-out infinite alternate;
}

#page-games .mg-hm-cloud-a {
  top: 16px;
  left: 18%;
}

#page-games .mg-hm-cloud-b {
  top: 46px;
  left: 52%;
  font-size: clamp(1.4rem, 2.8vw, 2rem);
  animation-duration: 18s;
  animation-direction: alternate-reverse;
}

#page-games .mg-hm-bank {
  position: absolute;
  bottom: 0;
  height: 58%;
  z-index: 2;
  background: linear-gradient(180deg, #86EFAC 0%, #4ADE80 18%, #A16207 18%, #854D0E 100%);
  box-shadow: inset 0 -6px 0 rgba(0, 0, 0, 0.12);
}

#page-games .mg-hm-bank-start {
  left: 0;
  width: 14%;
  border-top-right-radius: 26px;
}

#page-games .mg-hm-bank-goal {
  right: 0;
  width: 18%;
  border-top-left-radius: 26px;
}

#page-games .mg-hm-bank-deco {
  position: absolute;
  bottom: calc(100% - 0.3em);
  left: 50%;
  margin-left: -0.55em;
  font-size: clamp(1.8rem, 3.6vw, 2.8rem);
  line-height: 1;
}

#page-games .mg-hm-bank-goal .mg-hm-bank-deco {
  left: 30%;
}

#page-games .mg-hm-bank-goal .mg-hm-bank-home {
  left: 72%;
  font-size: clamp(1.4rem, 2.8vw, 2.1rem);
}

#page-games .mg-hm-bank-tag {
  position: absolute;
  left: 50%;
  bottom: 12px;
  transform: translateX(-50%);
  font-family: var(--font-en);
  font-size: 0.72rem;
  font-weight: 900;
  letter-spacing: 0.04em;
  color: #FFFFFF;
  background: rgba(15, 23, 42, 0.35);
  border-radius: 999px;
  padding: 2px 8px;
  white-space: nowrap;
}

#page-games .mg-hm-water {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 44%;
  z-index: 1;
  background: linear-gradient(180deg, #38BDF8 0%, #0EA5E9 45%, #0369A1 100%);
}

#page-games .mg-hm-wave {
  position: absolute;
  left: -40px;
  right: -40px;
  height: 16px;
  background: radial-gradient(circle at 10px 0, transparent 9px, rgba(255, 255, 255, 0.7) 10px, transparent 12px) 0 0 / 40px 16px repeat-x;
  animation: mg-hm-wave-drift 3s linear infinite;
}

#page-games .mg-hm-wave-a {
  top: 6px;
}

#page-games .mg-hm-wave-b {
  top: 46%;
  opacity: 0.45;
  animation-duration: 4.6s;
  animation-direction: reverse;
}

/* Raft position follows --mg-hm-progress (0 → start bank edge, 1 → goal bank edge) */
#page-games .mg-hm-raft {
  --mg-hm-raft-w: clamp(84px, 15%, 128px);
  position: absolute;
  z-index: 3;
  bottom: calc(44% - 18px);
  left: calc(14% + (68% - var(--mg-hm-raft-w)) * var(--mg-hm-progress));
  width: var(--mg-hm-raft-w);
  transition: left 0.7s cubic-bezier(0.34, 1.3, 0.64, 1);
}

#page-games .mg-hm-raft-body {
  position: relative;
  display: block;
  width: 100%;
  animation: mg-hm-bob 2.4s ease-in-out infinite;
}

#page-games .mg-hm-raft-logs {
  display: block;
  height: 22px;
  border-radius: 10px;
  border: 2px solid #713F12;
  background: repeating-linear-gradient(90deg, #CA8A04 0 14px, #A16207 14px 17px);
  box-shadow: 0 4px 0 rgba(15, 23, 42, 0.25);
}

#page-games .mg-hm-raft-mast {
  position: absolute;
  bottom: 16px;
  left: 6%;
  font-size: clamp(1.1rem, 2vw, 1.5rem);
  line-height: 1;
}

#page-games .mg-hm-sheep {
  position: absolute;
  bottom: 14px;
  left: 50%;
  margin-left: -0.55em;
  font-size: clamp(2.3rem, 4.4vw, 3.2rem);
  line-height: 1;
  transform: scaleX(-1);
  transform-origin: center bottom;
}

#page-games .mg-hm-raft.mg-hm-raft-wobble {
  animation: mg-hm-wobble 0.55s ease-in-out;
}

#page-games .mg-hm-raft.mg-hm-raft-bump {
  animation: mg-hm-bump 0.45s ease-out;
}

#page-games .mg-hm-sheep.mg-hm-sheep-hop {
  animation: mg-hm-sheep-hop 0.9s cubic-bezier(0.3, 0.9, 0.4, 1) forwards;
}

#page-games .mg-hm-arena.mg-hm-arrived .mg-hm-raft-body {
  animation: none;
}

#page-games .mg-hm-progress-pill {
  position: absolute;
  top: 10px;
  left: 16px;
  z-index: 4;
  font-family: var(--font-th);
  font-size: 0.85rem;
  font-weight: 800;
  color: #0369A1;
  background: rgba(255, 255, 255, 0.9);
  border: 2px solid #7DD3FC;
  border-radius: 999px;
  padding: 3px 12px;
}

/* Word Slots */
#page-games .mg-hm-word-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 12px 14px 14px;
  border-radius: 20px;
  background: #FFFFFF;
  border: 3px solid #7DD3FC;
  box-shadow: 0 8px 20px rgba(2, 132, 199, 0.16);
  container-type: inline-size;
  width: 100%;
  max-width: 100%;
  min-width: 0;
}

#page-games .mg-hm-target-frame,
#page-games .mg-hm-slots-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  container-type: inline-size;
}

#page-games .mg-hm-target-visual {
  width: min(180px, 100%);
  max-height: 160px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

#page-games .mg-hm-target-img {
  display: block;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 160px;
  object-fit: contain;
}

#page-games .mg-hm-zone-tag {
  font-family: var(--font-th);
  font-size: 0.8rem;
  font-weight: 800;
  color: #0369A1;
  background: #E0F2FE;
  border-radius: 999px;
  padding: 3px 12px;
}

#page-games .mg-hm-slots {
  --mg-hm-len: 6;
  --mg-hm-slot-w: clamp(24px, calc((100cqw - 20px) / var(--mg-hm-len) - 8px), 60px);
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px 26px;
  min-height: calc(var(--mg-hm-slot-w) * 1.2);
}

#page-games .mg-hm-word-group {
  display: inline-flex;
  flex-wrap: nowrap;
  gap: 8px;
}

#page-games .mg-hm-slot {
  width: var(--mg-hm-slot-w);
  height: calc(var(--mg-hm-slot-w) * 1.2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-en);
  font-size: calc(var(--mg-hm-slot-w) * 0.68);
  font-weight: 900;
  color: #1E293B;
  background: #F1F5F9;
  border-bottom: 5px solid #334155;
  border-radius: 10px 10px 4px 4px;
}

#page-games .mg-hm-slot.mg-hm-slot-fixed {
  width: auto;
  min-width: calc(var(--mg-hm-slot-w) * 0.4);
  background: transparent;
  border-bottom-color: transparent;
  color: #64748B;
}

#page-games .mg-hm-slot.mg-hm-slot-revealed {
  color: #15803D;
  background: #DCFCE7;
  border-bottom-color: #22C55E;
}

#page-games .mg-hm-slot.mg-hm-slot-answer {
  color: #EA580C;
  background: #FFEDD5;
  border-bottom-color: #FB923C;
}

#page-games .mg-hm-slot.mg-hm-slot-pop {
  animation: mg-hm-slot-pop 0.45s cubic-bezier(0.22, 1.4, 0.36, 1);
}

#page-games .mg-hm-word-meta {
  font-family: var(--font-th);
  font-size: 0.82rem;
  font-weight: 700;
  color: #64748B;
  text-align: center;
}

/* Control Panel */
#page-games .mg-hm-col-side {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 12px;
  min-width: 0;
  min-height: 0;
}

#page-games .mg-hm-lives-card,
#page-games .mg-hm-keyboard-card,
#page-games .mg-hm-timer-card {
  background: #FFFFFF;
  border-radius: 18px;
  padding: 10px 12px;
  border: 3px solid #E0F2FE;
  box-shadow: 0 6px 16px rgba(2, 132, 199, 0.14);
}

#page-games .mg-hm-card-label {
  font-family: var(--font-th);
  font-size: 0.85rem;
  font-weight: 800;
  color: #475569;
}

#page-games .mg-hm-lives-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

#page-games .mg-hm-hearts {
  display: flex;
  justify-content: center;
  gap: 4px;
  font-size: clamp(1.4rem, 2.4vw, 1.8rem);
  line-height: 1.1;
}

#page-games .mg-hm-heart {
  display: inline-block;
  transition: opacity 0.25s ease, filter 0.25s ease;
}

#page-games .mg-hm-heart.mg-hm-heart-lost {
  opacity: 0.55;
}

#page-games .mg-hm-heart.mg-hm-heart-pop {
  animation: mg-hm-heart-pop 0.55s ease-out;
}

#page-games .mg-hm-keyboard-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 0;
}

#page-games .mg-hm-keyboard-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

#page-games .mg-hm-hint-btn {
  border: none;
  cursor: pointer;
  font-family: var(--font-th);
  font-size: 0.85rem;
  font-weight: 800;
  color: #78350F;
  background: linear-gradient(135deg, #FEF08A 0%, #FACC15 100%);
  border-radius: 999px;
  padding: 0.38rem 0.85rem;
  box-shadow: 0 3px 0 #CA8A04;
  white-space: nowrap;
}

#page-games .mg-hm-hint-btn:active:not(:disabled) {
  transform: translateY(2px);
  box-shadow: 0 1px 0 #CA8A04;
}

#page-games .mg-hm-hint-btn:disabled {
  background: #E2E8F0;
  color: #94A3B8;
  box-shadow: 0 2px 0 #CBD5E1;
  cursor: not-allowed;
}

#page-games .mg-hm-keyboard {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  grid-auto-rows: minmax(36px, 52px);
  gap: 6px;
  align-content: center;
}

#page-games .mg-hm-key {
  border: 2px solid #93C5FD;
  border-radius: 12px;
  background: linear-gradient(180deg, #FFFFFF 0%, #EFF6FF 100%);
  color: #1E3A8A;
  font-family: var(--font-en);
  font-size: clamp(1rem, 1.6vw, 1.3rem);
  font-weight: 900;
  box-shadow: 0 3px 0 #60A5FA;
  cursor: pointer;
  transition: transform 0.12s ease, background 0.2s ease, opacity 0.2s ease;
}

#page-games .mg-hm-key:hover:not(:disabled) {
  transform: translateY(-1px);
  background: #DBEAFE;
}

#page-games .mg-hm-key:active:not(:disabled) {
  transform: translateY(2px);
  box-shadow: 0 1px 0 #60A5FA;
}

#page-games .mg-hm-key:disabled {
  cursor: not-allowed;
}

#page-games .mg-hm-key:disabled:not(.mg-hm-key-correct):not(.mg-hm-key-wrong) {
  opacity: 0.45;
}

#page-games .mg-hm-key.mg-hm-key-correct {
  background: linear-gradient(180deg, #4ADE80 0%, #22C55E 100%);
  border-color: #16A34A;
  color: #FFFFFF;
  box-shadow: 0 3px 0 #15803D;
}

#page-games .mg-hm-key.mg-hm-key-wrong {
  background: #E2E8F0;
  border-color: #FCA5A5;
  color: #DC2626;
  box-shadow: 0 3px 0 #CBD5E1;
  text-decoration: line-through;
  opacity: 0.8;
}

#page-games .mg-hm-timer-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

#page-games .mg-hm-timer-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

#page-games .mg-hm-timer-icon {
  font-size: 1.4rem;
}

#page-games .mg-hm-timer-label {
  font-family: var(--font-th);
  font-size: 0.9rem;
  font-weight: 800;
  color: #475569;
  margin-right: auto;
}

#page-games .mg-hm-timer-value {
  font-family: var(--font-en);
  font-size: 1.7rem;
  font-weight: 900;
  color: #0F172A;
  letter-spacing: 0.04em;
}

#page-games .mg-hm-pause-btn {
  border: none;
  cursor: pointer;
  width: 100%;
  font-family: var(--font-th);
  font-size: 0.92rem;
  font-weight: 800;
  color: #FFFFFF;
  background: linear-gradient(135deg, #38BDF8 0%, #0284C7 100%);
  border-radius: 999px;
  padding: 0.5rem 1rem;
  box-shadow: 0 3px 0 #0369A1;
}

#page-games .mg-hm-pause-btn[aria-pressed="true"] {
  background: linear-gradient(135deg, #4ADE80 0%, #16A34A 100%);
  box-shadow: 0 3px 0 #15803D;
}

#page-games .mg-hm-pause-btn:active:not(:disabled) {
  transform: translateY(2px);
  box-shadow: 0 1px 0 #0369A1;
}

#page-games .mg-hm-pause-btn:disabled {
  background: #CBD5E1;
  color: #64748B;
  box-shadow: 0 2px 0 #94A3B8;
  cursor: not-allowed;
}

/* Idle Banner, Hint Popup, Pause (main stage) */
#page-games .mg-hm-idle-banner {
  position: absolute;
  top: 48px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 6;
  width: min(92%, 440px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  text-align: center;
  padding: 10px 14px;
  border-radius: 16px;
  background: rgba(15, 23, 42, 0.78);
  pointer-events: none;
}

#page-games .mg-hm-idle-banner-title {
  font-family: var(--font-th);
  font-size: 0.98rem;
  font-weight: 800;
  color: #FEF08A;
}

#page-games .mg-hm-idle-banner-sub {
  font-family: var(--font-th);
  font-size: 0.82rem;
  font-weight: 600;
  color: #E0F2FE;
}

#page-games .mg-hm-hint-popup {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  border-radius: 20px;
  background: rgba(15, 23, 42, 0.45);
}

#page-games .mg-hm-hint-card {
  width: min(320px, 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 16px;
  border-radius: 22px;
  background: #FFFFFF;
  border: 4px solid #FACC15;
  box-shadow: 0 14px 32px rgba(0, 0, 0, 0.3);
  animation: mg-hm-pop 0.4s cubic-bezier(0.22, 1.4, 0.36, 1);
}

#page-games .mg-hm-hint-title {
  font-family: var(--font-th);
  font-size: 0.95rem;
  font-weight: 800;
  color: #92400E;
  text-align: center;
}

#page-games .mg-hm-hint-visual {
  width: min(220px, 60vw);
  aspect-ratio: 1 / 1;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 18px;
  background: #FFFBEB;
  overflow: hidden;
}

#page-games .mg-hm-hint-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  padding: 8px;
}

#page-games .mg-hm-hint-fallback {
  font-family: var(--font-th);
  font-size: 2rem;
  font-weight: 800;
  color: #B45309;
  text-align: center;
  padding: 10px;
}

#page-games .mg-hm-hint-bar {
  width: 100%;
  height: 8px;
  border-radius: 999px;
  background: #FEF3C7;
  overflow: hidden;
}

#page-games .mg-hm-hint-bar-fill {
  display: block;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, #FACC15 0%, #F59E0B 100%);
  transform-origin: left center;
}

#page-games .mg-hm-hint-bar-fill.mg-hm-hint-running {
  animation: mg-hm-hint-bar 3s linear forwards;
}

#page-games .mg-hm-pause-overlay {
  position: absolute;
  inset: 0;
  z-index: 31;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  border-radius: 20px;
  background: rgba(15, 23, 42, 0.8);
  backdrop-filter: blur(6px);
}

#page-games .mg-hm-pause-card {
  width: min(360px, 100%);
  padding: 22px 18px;
  border-radius: 24px;
  background: rgba(12, 74, 110, 0.96);
  border: 4px solid #7DD3FC;
  text-align: center;
  box-shadow: 0 16px 36px rgba(0, 0, 0, 0.45);
}

#page-games .mg-hm-pause-icon {
  font-size: 2.6rem;
  margin-bottom: 4px;
}

#page-games .mg-hm-pause-title {
  font-family: var(--font-th);
  font-size: 1.4rem;
  font-weight: 800;
  color: #E0F2FE;
  margin: 0 0 6px;
}

#page-games .mg-hm-pause-sub {
  font-family: var(--font-th);
  font-size: 0.92rem;
  font-weight: 600;
  color: #BAE6FD;
  margin: 0 0 16px;
}

#page-games .mg-hm-resume-btn {
  border: none;
  cursor: pointer;
  font-family: var(--font-th);
  font-size: 1rem;
  font-weight: 800;
  color: #064E3B;
  background: linear-gradient(180deg, #BBF7D0 0%, #22C55E 100%);
  border-radius: 999px;
  padding: 0.6rem 1.4rem;
  box-shadow: 0 4px 0 #15803D;
}

#page-games .mg-hm-resume-btn:active {
  transform: translateY(2px);
  box-shadow: 0 2px 0 #15803D;
}

/* Countdown, Result, Confetti (whole arena) */
#page-games .mg-hm-countdown-overlay {
  position: absolute;
  inset: 0;
  z-index: 35;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(15, 23, 42, 0.5);
}

#page-games .mg-hm-countdown-circle {
  width: 156px;
  height: 156px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(3, 105, 161, 0.94);
  border: 6px solid #FACC15;
  box-shadow: 0 14px 32px rgba(0, 0, 0, 0.45);
  animation: mg-hm-pop 0.45s cubic-bezier(0.22, 1.4, 0.36, 1);
}

#page-games .mg-hm-countdown-circle.mg-hm-countdown-go {
  width: 176px;
  height: 176px;
  background: rgba(34, 197, 94, 0.94);
  border-color: #BBF7D0;
}

#page-games .mg-hm-countdown-text {
  font-family: var(--font-en);
  font-size: 4.8rem;
  font-weight: 900;
  line-height: 1;
  color: #FFFFFF;
  text-shadow: 0 6px 14px rgba(0, 0, 0, 0.4);
}

#page-games .mg-hm-countdown-circle.mg-hm-countdown-go .mg-hm-countdown-text {
  font-size: 3.9rem;
}

#page-games .mg-hm-result-overlay {
  position: absolute;
  inset: 0;
  z-index: 36;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(15, 23, 42, 0.6);
}

#page-games .mg-hm-result-card {
  width: min(420px, 100%);
  max-height: 100%;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 20px 18px;
  text-align: center;
  border-radius: 24px;
  background: #FFFFFF;
  border: 4px solid #FACC15;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.38);
  animation: mg-hm-pop 0.4s cubic-bezier(0.22, 1.4, 0.36, 1);
}

#page-games .mg-hm-result-card.mg-hm-result-lose {
  border-color: #F9A8D4;
}

#page-games .mg-hm-result-icon {
  font-size: 2.8rem;
  line-height: 1;
}

#page-games .mg-hm-result-title {
  font-family: var(--font-th);
  font-size: 1.4rem;
  font-weight: 800;
  color: #0F172A;
  margin: 0;
}

#page-games .mg-hm-result-lose .mg-hm-result-title {
  font-family: var(--font-en);
  font-size: 1.8rem;
  color: #DB2777;
}

#page-games .mg-hm-result-sub {
  font-family: var(--font-th);
  font-size: 0.92rem;
  font-weight: 600;
  color: #475569;
  margin: 0;
}

#page-games .mg-hm-result-visual {
  width: 130px;
  height: 130px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 4px;
  border-radius: 20px;
  background: #F0F9FF;
  border: 3px solid #BAE6FD;
  overflow: hidden;
}

#page-games .mg-hm-result-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  padding: 6px;
}

#page-games .mg-hm-result-fallback {
  font-size: 3.4rem;
}

#page-games .mg-hm-result-word {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
  margin: 2px 0 0;
}

#page-games .mg-hm-result-word strong {
  font-family: var(--font-en);
  font-size: 1.7rem;
  font-weight: 900;
  letter-spacing: 0.06em;
  color: #0284C7;
}

#page-games .mg-hm-result-word span {
  font-family: var(--font-th);
  font-size: 1.05rem;
  font-weight: 700;
  color: #334155;
}

#page-games .mg-hm-speak-btn {
  border: 1.5px solid #7DD3FC;
  cursor: pointer;
  font-family: var(--font-th);
  font-size: 0.85rem;
  font-weight: 800;
  color: #0369A1;
  background: #E0F2FE;
  border-radius: 999px;
  padding: 0.3rem 0.9rem;
}

#page-games .mg-hm-result-stars {
  font-size: 1.7rem;
  letter-spacing: 4px;
}

#page-games .mg-hm-result-summary {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px 14px;
  width: 100%;
  padding: 10px 12px;
  border-radius: 14px;
  background: #F8FAFC;
  border: 1.5px solid #E2E8F0;
  font-family: var(--font-th);
  font-size: 0.9rem;
  font-weight: 700;
  color: #1E293B;
}

#page-games .mg-hm-result-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin-top: 6px;
}

#page-games .mg-hm-play-again-btn,
#page-games .mg-hm-next-random-btn {
  border: none;
  cursor: pointer;
  font-family: var(--font-th);
  font-size: 0.95rem;
  font-weight: 800;
  border-radius: 999px;
  padding: 0.6rem 1.2rem;
}

#page-games .mg-hm-play-again-btn {
  color: #FFFFFF;
  background: linear-gradient(135deg, #22C55E 0%, #16A34A 100%);
  box-shadow: 0 4px 0 #15803D;
}

#page-games .mg-hm-next-random-btn {
  color: #6B21A8;
  background: linear-gradient(135deg, #F3E8FF 0%, #E9D5FF 100%);
  border: 1.5px solid #C4B5FD;
  box-shadow: 0 4px 0 #A855F7;
}

#page-games .mg-hm-confetti-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 38;
}

@keyframes mg-hm-pop {
  0% { transform: scale(0.4); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

@keyframes mg-hm-sun-glow {
  0%, 100% { transform: scale(1) rotate(0deg); }
  50% { transform: scale(1.08) rotate(12deg); }
}

@keyframes mg-hm-cloud-drift {
  from { transform: translateX(-24px); }
  to { transform: translateX(36px); }
}

@keyframes mg-hm-wave-drift {
  from { transform: translateX(0); }
  to { transform: translateX(40px); }
}

@keyframes mg-hm-bob {
  0%, 100% { transform: translateY(0) rotate(-1.5deg); }
  50% { transform: translateY(-5px) rotate(1.5deg); }
}

@keyframes mg-hm-wobble {
  0%, 100% { transform: rotate(0deg); }
  20% { transform: rotate(-7deg); }
  45% { transform: rotate(6deg); }
  70% { transform: rotate(-3deg); }
}

@keyframes mg-hm-bump {
  0%, 100% { transform: translateY(0); }
  40% { transform: translateY(-10px); }
}

@keyframes mg-hm-sheep-hop {
  0% { transform: translate(0, 0) scaleX(-1); }
  45% { transform: translate(1.2em, -1.6em) scaleX(-1); }
  75% { transform: translate(2.2em, -0.7em) scaleX(-1); }
  88% { transform: translate(2.2em, -0.9em) scaleX(-1); }
  100% { transform: translate(2.2em, -0.7em) scaleX(-1); }
}

@keyframes mg-hm-slot-pop {
  0% { transform: scale(0.5); }
  60% { transform: scale(1.18); }
  100% { transform: scale(1); }
}

@keyframes mg-hm-heart-pop {
  0% { transform: scale(1.5) rotate(-12deg); }
  60% { transform: scale(0.85) rotate(8deg); }
  100% { transform: scale(1) rotate(0deg); }
}

@keyframes mg-hm-hint-bar {
  from { transform: scaleX(1); }
  to { transform: scaleX(0); }
}

/* Tablet / Mobile: stack Main Stage above Control Panel */
@media (max-width: 900px) {
  #page-games .mg-hm-arena {
    grid-template-columns: minmax(0, 1fr);
    height: auto;
    padding: 10px;
    gap: 10px;
  }

  #page-games .mg-hm-river {
    height: 250px;
  }

  #page-games .mg-hm-col-side {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    grid-template-rows: auto auto;
    grid-template-areas:
      "lives timer"
      "keys keys";
  }

  #page-games .mg-hm-lives-card {
    grid-area: lives;
    justify-content: center;
  }

  #page-games .mg-hm-timer-card {
    grid-area: timer;
  }

  #page-games .mg-hm-keyboard-card {
    grid-area: keys;
  }

  #page-games .mg-hm-keyboard {
    grid-auto-rows: 46px;
  }
}

@media (max-width: 560px) {
  #page-games .mg-hm-header {
    padding: 8px 10px;
    gap: 8px;
  }

  #page-games .mg-hm-river {
    width: 100%;
    position: relative;
    height: 30vh;
    min-height: 250px;
  }

  #page-games .mg-hm-col-side {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas:
      "lives"
      "keys"
      "timer";
  }

  #page-games .mg-hm-keyboard {
    gap: 5px;
    grid-auto-rows: 42px;
  }

  #page-games .mg-hm-idle-banner {
    top: 42px;
  }
}

.planned-card-title {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--text-main);
}

.planned-card-desc {
  font-family: var(--font-th);
  font-size: 0.9rem;
  color: var(--text-muted);
  line-height: 1.5;
  margin-bottom: 0.5rem;
}

.planned-card-tag {
  margin-top: auto;
  font-family: var(--font-th);
  font-size: 0.78rem;
  font-weight: 600;
  color: #4FB5FF;
  background: #F0F7FF;
  padding: 0.2rem 0.6rem;
  border-radius: var(--radius-pill);
  align-self: flex-start;
}

/* ===================================================================
   TOAST NOTIFICATION
   =================================================================== */

.app-toast.is-share {
  background: #f472b6;
  box-shadow: 0 10px 24px rgba(244, 114, 182, 0.45);
}

.app-toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(0);
  background: #2D3748;
  color: #FFFFFF;
  padding: 0.85rem 1.6rem;
  border-radius: var(--radius-pill);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.25);
  font-family: var(--font-th);
  font-size: 1rem;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 0.65rem;
  z-index: 2000;
  animation: toastSlideUp 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  pointer-events: none;
  max-width: 90%;
  text-align: center;
}

@keyframes toastSlideUp {
  from {
    opacity: 0;
    transform: translateX(-50%) translateY(30px) scale(0.9);
  }
  to {
    opacity: 1;
    transform: translateX(-50%) translateY(0) scale(1);
  }
}

.toast-icon {
  font-size: 1.3rem;
}

/* ===================================================================
   RESPONSIVE DESIGN (Desktop, Tablet, Mobile)
   =================================================================== */

/* Tablet & Smaller Desktops */
@media (max-width: 1024px) {
  .app-container {
    padding: 1rem 1rem 3.5rem;
  }

  .main-navbar {
    top: 8px;
    margin-bottom: 1.6rem;
  }

  .navbar-inner {
    padding: 0.4rem 0.6rem 0.4rem 0.75rem;
    gap: 0.55rem;
  }

  .main-navbar .brand-avatar {
    width: 60px;
    height: 60px;
  }

  .main-navbar .brand-title {
    font-size: 1.35rem;
  }

  .main-navbar .brand-tag {
    font-size: 0.75rem;
  }

  .nav-tab {
    padding: 0.38rem 0.62rem;
    font-size: 0.86rem;
    gap: 0.3rem;
  }

  .main-navbar .tab-pill {
    display: none;
  }

  .generator-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 1.25rem;
  }
}

/* Tablet & Mobile Stacking */
@media (max-width: 820px) {
  .fc-workspace,
  .cw-workspace,
  #ws-workspace.ws-workspace,
  #wm-workspace.wm-workspace,
  #tr-workspace.tr-workspace,
  #ps-workspace.ps-workspace,
  #tt-workspace.tt-workspace,
  #wb-workspace.wb-workspace,
  #wu-workspace.wu-workspace,
  #wst-workspace.wst-workspace,
  #wd-workspace.wd-workspace,
  #cp-workspace.cp-workspace {
    flex-direction: column;
    align-items: center;
    gap: 1.75rem;
  }

  .workspace-toolbar {
    flex: 1 1 auto;
    width: 100%;
    max-width: 580px;
    position: static;
    max-height: none;
  }

  .workspace-preview {
    order: -1;
    width: 100%;
  }
}

/* Mobile & Small Tablets */
@media (max-width: 768px) {
  .app-container {
    padding: 0.75rem 0.75rem 3rem;
  }

  /* Responsive Navbar — hamburger lives in the earlier mobile rule */
  .main-navbar {
    top: 6px;
    margin-bottom: 1.25rem;
  }

  .navbar-inner {
    align-items: stretch;
    border-radius: 22px;
    padding: 0.75rem 0.85rem;
    gap: 0.65rem;
  }

  .nav-brand {
    min-width: 0;
  }

  .nav-menu.is-open {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.45rem;
    width: 100%;
  }

  .nav-tab {
    justify-content: center;
    padding: 0.55rem 0.6rem;
    font-size: 0.88rem;
    border-radius: 14px;
    gap: 0.35rem;
  }

  .main-navbar .brand-avatar {
    width: 52px;
    height: 52px;
  }

  .main-navbar .brand-title {
    font-size: 1.15rem;
  }

  .main-navbar .brand-tag {
    font-size: 0.7rem;
    letter-spacing: 0.04em;
  }

  .main-navbar .nav-vip-upgrade {
    justify-content: center;
    width: auto;
    font-size: 0.8rem;
    padding: 0.32rem 0.65rem;
  }

  .tab-pill {
    display: none;
  }

  .home-header {
    margin-bottom: 1.8rem;
  }

  .category-grid {
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 0.85rem;
  }

  .category-card {
    padding: 1rem 0.85rem;
    border-radius: 16px;
  }

  .cat-icon-bubble {
    width: 44px;
    height: 44px;
    font-size: 1.5rem;
    border-radius: 12px;
  }

  .cat-name-en {
    font-size: 1.15rem;
  }

  .cat-name-th {
    font-size: 0.95rem;
  }

  .btn-side-nav {
    display: none;
  }

  .flashcard-image-frame {
    min-height: 180px;
    padding: 0.85rem;
  }

  .flashcard-card {
    padding: 1.25rem 1rem;
    border-radius: 22px;
  }

  .flashcard-controls {
    gap: 0.6rem;
  }

  .btn-control {
    min-height: 50px;
    padding: 0.65rem 0.9rem;
    font-size: 0.95rem;
  }

  .btn-pronounce {
    padding: 0.65rem 1rem;
    font-size: 0.95rem;
  }

  .btn-subtext {
    display: none;
  }

  .flashcard-header {
    gap: 0.6rem;
    justify-content: space-between;
  }

  .capsule-mode-toggle-compact .mode-capsule-btn {
    padding: 0.3rem 0.65rem;
    font-size: 0.82rem;
  }

  .home-mode-bar {
    width: 100%;
    justify-content: center;
  }

  .btn-back {
    padding: 0.5rem 0.85rem;
    font-size: 0.9rem;
  }

  .category-badge-chip {
    padding: 0.45rem 0.85rem;
    font-size: 0.92rem;
  }

  .generator-grid {
    grid-template-columns: 1fr;
    gap: 1.1rem;
  }

  .generator-card {
    padding: 1.4rem 1.2rem;
    border-radius: 20px;
  }

  .placeholder-hero {
    padding: 2.2rem 1.2rem;
    border-radius: 22px;
  }

  .planned-cards-grid {
    grid-template-columns: 1fr;
  }
}

/* Extra Small Mobile (< 420px) */
@media (max-width: 420px) {
  .category-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 0.65rem;
  }

  .category-card {
    padding: 0.85rem 0.75rem;
  }

  .cat-name-en {
    font-size: 1.05rem;
  }

  .cat-name-th {
    font-size: 0.88rem;
  }

  .flashcard-image-frame {
    min-height: 150px;
  }

  .word-en {
    font-size: 2rem;
  }

  .word-th {
    font-size: 1.35rem;
  }

  .nav-tab .tab-label {
    font-size: 0.82rem;
  }
}

/* ===================================================================
   MAKER MODE TOGGLE + PICTURE CROSSWORD WORKSHEET
   =================================================================== */

.maker-mode-toggle {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.4rem;
  padding: 0.3rem;
  background: #F8FAFC;
  border: 1.5px solid #E2E8F0;
  border-radius: 14px;
}

.maker-mode-btn {
  border: none;
  background: transparent;
  border-radius: 10px;
  padding: 0.55rem 0.4rem;
  font-family: var(--font-th);
  font-size: 0.86rem;
  font-weight: 700;
  color: #64748B;
  cursor: pointer;
}

.maker-mode-btn.active {
  background: #FFFFFF;
  color: #1D4ED8;
  box-shadow: 0 2px 8px rgba(37, 99, 235, 0.15);
}

#cw-workspace .cw-badge {
  background: #F3E8FF;
  color: #7C3AED;
}

#cw-workspace .cw-note-input {
  width: 100%;
  min-height: 84px;
  resize: vertical;
  font-family: var(--font-th);
}

#cw-workspace .cw-style-toggle {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

#cw-workspace .cw-style-option {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.45rem 0.6rem;
  border: 1.5px solid #E2E8F0;
  border-radius: 10px;
  background: #FFFFFF;
  font-family: var(--font-th);
  font-size: 0.86rem;
  font-weight: 600;
  color: #334155;
  cursor: pointer;
}

#cw-workspace .cw-style-option:has(input:checked) {
  border-color: #60A5FA;
  background: #EFF6FF;
  color: #1D4ED8;
}

#cw-workspace .cw-pages {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 28px;
  width: min(794px, 100%);
}

#cw-workspace .cw-sheet {
  width: 100%;
  aspect-ratio: 210 / 297;
  height: auto;
  max-height: min(297mm, 1122px);
  background: #FFFFFF;
  border-radius: 4px;
  box-shadow: 0 12px 40px rgba(15, 23, 42, 0.12);
  padding: 16px 16px 12px;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  gap: 8px;
  color: #111827;
  position: relative;
  overflow: hidden;
}

#cw-workspace .cw-header {
  flex: 0 0 auto;
  flex-shrink: 0;
  min-height: 0;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

#cw-workspace .cw-header-main {
  flex: 1 1 auto;
  min-width: 0;
}

#cw-workspace .cw-logo-slot {
  flex: 0 0 16mm;
  width: 16mm;
  height: 16mm;
}

#cw-workspace .cw-header-logo {
  width: 16mm;
  height: 16mm;
  max-width: 16mm;
  max-height: 16mm;
  object-fit: contain;
  display: block;
}

#cw-workspace .cw-logo-slot[hidden] {
  display: none !important;
  width: 0 !important;
  height: 0 !important;
  margin: 0 !important;
  padding: 0 !important;
}

#cw-workspace .cw-answer-sheet {
  page-break-before: always;
  break-before: page;
  background: #FFFFFF;
}

#cw-workspace .cw-bg-layer {
  position: absolute;
  inset: 0;
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  opacity: 0.22;
  pointer-events: none;
  z-index: 0;
}

#cw-workspace .cw-panel {
  position: relative;
  z-index: 1;
}

#cw-workspace .cw-header h2 {
  margin: 0 0 6px;
  font-family: var(--font-en);
  font-size: 1.45rem;
  font-weight: 700;
  letter-spacing: -0.3px;
  line-height: 1.15;
}

#cw-workspace .cw-answer-kicker {
  margin: 0 0 6px;
  font-family: var(--font-en);
  font-size: 0.95rem;
  font-weight: 700;
  color: #1E3A5F;
}

#cw-workspace .cw-meta {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  font-family: var(--font-en);
  font-size: 0.92rem;
  font-weight: 600;
  min-width: 0;
}

#cw-workspace .cw-meta-custom {
  font-family: var(--font-th);
  font-weight: 600;
  line-height: 1.45;
  white-space: pre-wrap;
}

#cw-workspace .cw-line {
  flex: 1 1 auto;
  border-bottom: 1.5px solid #111827;
  min-width: 28px;
  height: 1.05em;
}

#cw-workspace .cw-line-name {
  flex: 2.4 1 0;
}

#cw-workspace .cw-line-short {
  flex: 0.7 1 0;
  max-width: 18%;
}

#cw-workspace .cw-body {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
  overflow: hidden;
}

#cw-workspace .cw-clues-panel {
  flex: 0 1 40%;
  max-height: 40%;
  min-height: 0;
  min-width: 0;
  overflow: hidden;
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  align-items: center;
  align-content: center;
  justify-content: center;
  gap: 10px 16px;
  margin-top: 0;
  padding-top: 24px;
  box-sizing: border-box;
}

#cw-workspace .cw-clue-col {
  flex: 0 1 auto;
  width: max-content;
  max-width: 100%;
  max-height: 100%;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow: hidden;
}

#cw-workspace .cw-grid-col {
  flex: 1 1 auto;
  width: 100%;
  min-width: 0;
  min-height: 0;
  max-width: 100%;
  max-height: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

#cw-workspace .cw-grid {
  display: grid;
  grid-template-columns: repeat(var(--cw-cols), var(--cw-cell));
  grid-template-rows: repeat(var(--cw-rows), var(--cw-cell));
  gap: 0;
  width: max-content;
  height: max-content;
  max-width: 100%;
  max-height: 100%;
  margin: auto;
  overflow: hidden;
}

#cw-workspace .cw-cell {
  width: var(--cw-cell);
  height: var(--cw-cell);
  box-sizing: border-box;
  background: #FFFFFF;
  border: 1.5px solid #111111;
  position: relative;
  container-type: size;
}

#cw-workspace .cw-cell.is-block {
  background: transparent;
  border-color: transparent;
}

#cw-workspace .cw-num {
  position: absolute;
  top: 0;
  left: 1px;
  font-family: var(--font-en);
  font-size: 8px;
  font-weight: 800;
  line-height: 1;
  color: #111111;
  z-index: 1;
}

#cw-workspace .cw-letter {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-en);
  font-weight: 700;
  font-size: 58cqmin;
  line-height: 1;
  color: #111111;
  text-transform: uppercase;
}

#cw-workspace .cw-clue-col h3 {
  margin: 0 0 4px;
  font-family: var(--font-en);
  font-size: 0.82rem;
  font-weight: 700;
}

#cw-workspace .cw-clue-list {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-content: center;
  align-items: center;
  gap: 6px;
  min-width: 0;
  overflow: hidden;
}

#cw-workspace .cw-clue {
  position: relative;
  flex: 0 1 var(--cw-clue-size, 72px);
  width: var(--cw-clue-size, 72px);
  max-width: 100%;
  max-height: 100%;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: 2px;
  padding: 4px;
  background: #FFFFFF;
  border: 1.5px solid #CBD5E1;
  border-radius: 10px;
  box-shadow: 0 2px 5px rgba(15, 23, 42, 0.06);
}

#cw-workspace .cw-clue-num {
  align-self: flex-start;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  box-sizing: border-box;
  border-radius: 999px;
  background: #FEF3C7;
  border: 1.5px solid #1E3A5F;
  color: #1E3A5F;
  font-family: var(--font-en);
  font-size: 0.72rem;
  font-weight: 800;
  line-height: 1;
  flex-shrink: 0;
  z-index: 1;
}

#cw-workspace .cw-clue img {
  display: block;
  width: 100%;
  max-width: 100%;
  max-height: 100%;
  aspect-ratio: 1;
  height: auto;
  object-fit: contain;
  background: transparent;
  border: none;
  box-shadow: none;
  border-radius: 6px;
}

#cw-workspace .cw-note,
#cw-workspace .cw-empty {
  font-family: var(--font-th);
  font-size: 0.9rem;
  color: #334155;
  margin: 0;
}

#cw-workspace .cw-empty {
  text-align: center;
  padding: 4rem 1rem;
}

/* ===================================================================
   WORD SEARCH MODULE (scoped to #ws-workspace)
   =================================================================== */
#ws-workspace.ws-workspace {
  display: flex;
  gap: 1.5rem;
  align-items: flex-start;
  margin-top: 1rem;
  animation: pageFadeIn 0.35s ease-out forwards;
}

#ws-workspace .ws-badge {
  background: #E0F2FE;
  color: #0369A1;
}

#ws-workspace > .workspace-toolbar {
  overflow: hidden;
}

#ws-workspace > .workspace-toolbar > .toolbar-scrollable {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
}

#ws-workspace .ws-note-input {
  width: 100%;
  min-height: 84px;
  resize: vertical;
  font-family: var(--font-th);
}

#ws-workspace .ws-limit-note {
  margin: 0;
  font-family: var(--font-th);
  font-size: 0.82rem;
  font-weight: 600;
  color: #0369A1;
}

#ws-workspace .ws-mode-toggle {
  display: flex;
  gap: 0.4rem;
  padding: 0.3rem;
  background: #F0F9FF;
  border-radius: 999px;
}

#ws-workspace .ws-mode-btn {
  flex: 1 1 0;
  border: none;
  background: transparent;
  border-radius: 999px;
  padding: 0.45rem 0.6rem;
  font-family: var(--font-th);
  font-weight: 700;
  font-size: 0.84rem;
  color: #0369A1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.3rem;
}

#ws-workspace .ws-mode-btn.active {
  background: #FFFFFF;
  box-shadow: 0 2px 8px rgba(2, 132, 199, 0.18);
}

#ws-workspace .ws-vocab-list {
  max-height: 280px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  padding-right: 2px;
}

#ws-workspace .ws-check-item {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.3rem 0.45rem;
  border-radius: 6px;
  cursor: pointer;
  user-select: none;
}

#ws-workspace .ws-check-item:hover {
  background: #F0F9FF;
}

#ws-workspace .ws-check-item input[type="checkbox"] {
  width: 15px;
  height: 15px;
  accent-color: #0284C7;
  cursor: pointer;
  flex-shrink: 0;
}

#ws-workspace .ws-style-toggle {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

#ws-workspace .ws-style-option {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.45rem 0.6rem;
  border: 1.5px solid #E2E8F0;
  border-radius: 10px;
  background: #FFFFFF;
  font-family: var(--font-th);
  font-size: 0.86rem;
  font-weight: 600;
  color: #334155;
  cursor: pointer;
}

#ws-workspace .ws-style-option:has(input:checked) {
  border-color: #38BDF8;
  background: #F0F9FF;
  color: #0369A1;
}

#ws-workspace .ws-color-row input[type="color"] {
  width: 100%;
  height: 38px;
  border: 1.5px solid #E2E8F0;
  border-radius: 8px;
  background: #FFFFFF;
  cursor: pointer;
}

#ws-workspace .ws-bg-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.4rem;
  max-height: 180px;
  overflow-y: auto;
}

#ws-workspace .ws-bg-thumb {
  padding: 0;
  border: 2px solid transparent;
  border-radius: 8px;
  background: #FFFFFF;
  cursor: pointer;
  overflow: hidden;
}

#ws-workspace .ws-bg-thumb.active {
  border-color: #0284C7;
  box-shadow: 0 0 0 2px rgba(2, 132, 199, 0.25);
}

#ws-workspace .ws-bg-thumb img {
  width: 100%;
  height: 58px;
  object-fit: cover;
  display: block;
  background: #FFFFFF;
}

#ws-workspace .ws-toolbar-actions {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  padding-top: 0.55rem;
  border-top: 2px dashed #EDF2F7;
}

#ws-workspace .ws-action-row {
  display: flex;
  flex-direction: row;
  align-items: stretch;
  gap: 0.35rem;
}

#ws-workspace .ws-action-row > .btn-print-pdf,
#ws-workspace .ws-action-row > .ws-save-btn {
  flex: 1 1 50%;
  width: auto;
  min-width: 0;
  min-height: 36px;
  padding: 0.3rem 0.4rem;
  font-size: 0.72rem;
  line-height: 1.2;
  gap: 0.2rem;
  box-shadow: none;
  white-space: normal;
  text-align: center;
}

#ws-workspace .ws-action-row .dl-icon {
  font-size: 0.85rem;
}

#ws-workspace .ws-save-btn {
  border: none;
  border-radius: var(--radius-pill);
  background: linear-gradient(135deg, #38BDF8, #0284C7);
  color: #FFFFFF;
  font-family: var(--font-th);
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

#ws-workspace .ws-load-btn {
  width: 100%;
  min-height: 32px;
  padding: 0.28rem 0.5rem;
  border: 1.5px solid #7DD3FC;
  border-radius: var(--radius-pill);
  background: #F0F9FF;
  color: #0369A1;
  font-family: var(--font-th);
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
}

#ws-workspace .ws-action-hint {
  font-family: var(--font-th);
  font-size: 0.7rem;
  color: #64748B;
  text-align: center;
  line-height: 1.3;
}

#ws-workspace .ws-preview-scroll {
  max-height: calc(100vh - 210px);
  overflow: auto;
  justify-content: center;
}

#ws-workspace .ws-pages {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 28px;
  width: max-content;
  max-width: 100%;
}

#ws-workspace .ws-sheet {
  width: 210mm;
  height: 297mm;
  max-width: none;
  flex: 0 0 auto;
  box-sizing: border-box;
  background: #FFFFFF;
  border-radius: 4px;
  box-shadow: 0 12px 40px rgba(15, 23, 42, 0.12);
  padding: 8mm 8mm 7mm;
  display: flex;
  flex-direction: column;
  gap: 3mm;
  color: #111827;
  position: relative;
  overflow: hidden;
}

#ws-workspace .ws-answer-sheet {
  background: #FFFFFF !important;
}

#ws-workspace .ws-bg-layer {
  position: absolute;
  inset: 0;
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  opacity: 0.22;
  pointer-events: none;
  z-index: 0;
}

#ws-workspace .ws-header,
#ws-workspace .ws-wordbox,
#ws-workspace .ws-grid-wrap,
#ws-workspace .ws-empty,
#ws-workspace .ws-note {
  position: relative;
  z-index: 1;
}

#ws-workspace .ws-header {
  flex: 0 0 auto;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 4mm;
  min-height: 18mm;
}

#ws-workspace .ws-header-main {
  flex: 1 1 auto;
  min-width: 0;
}

#ws-workspace .ws-title {
  margin: 0 0 1.5mm;
  font-family: var(--font-en);
  font-size: 18pt;
  font-weight: 700;
  line-height: 1.1;
  color: #0F2744;
}

#ws-workspace .ws-answer-kicker {
  margin: 0 0 1.5mm;
  font-family: var(--font-en);
  font-size: 16pt;
  font-weight: 700;
  color: #0F2744;
}

#ws-workspace .ws-meta {
  display: flex;
  align-items: flex-end;
  gap: 2mm;
  font-family: var(--font-en);
  font-size: 11pt;
  font-weight: 600;
  min-width: 0;
}

#ws-workspace .ws-meta-custom {
  display: block;
  font-family: var(--font-th);
  font-weight: 600;
  font-size: 12pt;
  line-height: 1.4;
  white-space: pre-wrap;
  min-height: 8mm;
}

#ws-workspace .ws-line {
  flex: 1 1 auto;
  border-bottom: 1.5px solid #111827;
  min-width: 8mm;
  height: 1.05em;
}

#ws-workspace .ws-line-name {
  flex: 2.4 1 0;
}

#ws-workspace .ws-line-short {
  flex: 0.7 1 0;
  max-width: 18%;
}

#ws-workspace .ws-logo-slot {
  flex: 0 0 16mm;
  width: 16mm;
  height: 16mm;
}

#ws-workspace .ws-logo-img {
  width: 16mm;
  height: 16mm;
  object-fit: contain;
  display: block;
}

#ws-workspace .ws-logo-slot[hidden],
#ws-workspace .ws-logo-empty {
  display: none !important;
  width: 0 !important;
  height: 0 !important;
  border: none !important;
  padding: 0 !important;
  margin: 0 !important;
}

#ws-workspace .ws-wordbox {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(2, 32mm);
  gap: 2mm 3mm;
}

#ws-workspace .ws-word {
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  gap: 0.5mm;
}

#ws-workspace .ws-word-img {
  width: 20mm;
  height: 20mm;
  object-fit: contain;
  display: block;
  background: transparent;
}

#ws-workspace .ws-word-label {
  font-family: var(--font-en);
  font-weight: bold;
  font-size: 14pt;
  letter-spacing: 0.06em;
  line-height: 1.25;
  padding-top: 0.4mm;
  text-align: center;
  text-transform: uppercase;
  color: #111827;
  max-width: 100%;
}

#ws-workspace .ws-grid-wrap {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

#ws-workspace .ws-grid {
  --ws-cell: 13.2mm;
  position: relative;
  display: grid;
  grid-template-columns: repeat(12, var(--ws-cell));
  grid-template-rows: repeat(12, var(--ws-cell));
  width: calc(var(--ws-cell) * 12);
  height: calc(var(--ws-cell) * 12);
  margin: 0 auto;
}

#ws-workspace .ws-cell {
  width: var(--ws-cell);
  height: var(--ws-cell);
  box-sizing: border-box;
  border: 1px solid #111111;
  background: var(--ws-cell-bg, transparent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-en);
  font-weight: bold;
  font-size: 16pt;
  line-height: 1.15;
  padding: 0.4mm;
  color: #111111;
  text-transform: uppercase;
  position: relative;
  z-index: 1;
}

#ws-workspace .ws-answer-sheet .ws-cell {
  background: #FFFFFF;
}

#ws-workspace .ws-pill {
  position: absolute;
  z-index: 2;
  pointer-events: none;
  box-sizing: border-box;
  border: 0.55mm solid var(--ws-pill, #E11D48);
  background: color-mix(in srgb, var(--ws-pill, #F59E0B) 34%, transparent);
  border-radius: 999px;
}

#ws-workspace .ws-pill[data-dir="h"] {
  left: calc(var(--ws-c) * var(--ws-cell) + var(--ws-cell) * 0.05);
  top: calc(var(--ws-r) * var(--ws-cell) + var(--ws-cell) * 0.16);
  width: calc(var(--ws-len) * var(--ws-cell) - var(--ws-cell) * 0.1);
  height: calc(var(--ws-cell) * 0.68);
}

#ws-workspace .ws-pill[data-dir="v"] {
  left: calc(var(--ws-c) * var(--ws-cell) + var(--ws-cell) * 0.16);
  top: calc(var(--ws-r) * var(--ws-cell) + var(--ws-cell) * 0.05);
  width: calc(var(--ws-cell) * 0.68);
  height: calc(var(--ws-len) * var(--ws-cell) - var(--ws-cell) * 0.1);
}

#ws-workspace .ws-pill[data-dir="dd"],
#ws-workspace .ws-pill[data-dir="du"] {
  left: calc((var(--ws-c) + 0.5) * var(--ws-cell));
  top: calc((var(--ws-r) + 0.5) * var(--ws-cell));
  width: calc((var(--ws-len) - 1) * var(--ws-cell) * 1.41421356 + var(--ws-cell) * 0.7);
  height: calc(var(--ws-cell) * 0.58);
}

#ws-workspace .ws-pill[data-dir="dd"] {
  transform: translateY(-50%) rotate(45deg);
  transform-origin: left center;
}

#ws-workspace .ws-pill[data-dir="du"] {
  transform: translateY(-50%) rotate(-45deg);
  transform-origin: left center;
}

#ws-workspace .ws-note,
#ws-workspace .ws-empty {
  margin: 0;
  font-family: var(--font-th);
  font-size: 11pt;
  color: #334155;
}

#ws-workspace .ws-empty {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 2mm;
}

#ws-workspace .ws-modal {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: rgba(15, 23, 42, 0.45);
}

#ws-workspace .ws-modal-card {
  width: min(420px, 100%);
  max-height: min(78vh, 640px);
  overflow: auto;
  background: #FFFFFF;
  border-radius: 16px;
  padding: 1rem 1rem 0.9rem;
  box-shadow: 0 18px 50px rgba(15, 23, 42, 0.25);
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
}

#ws-workspace .ws-modal-title {
  margin: 0;
  font-family: var(--font-th);
  font-size: 1.15rem;
  color: #0F2744;
}

#ws-workspace .ws-project-list {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  max-height: 320px;
  overflow-y: auto;
  margin-top: 0.45rem;
}

#ws-workspace .ws-project-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.45rem 0.5rem;
  border: 1px solid #E2E8F0;
  border-radius: 10px;
  background: #F8FAFC;
}

#ws-workspace .ws-project-name {
  display: block;
  font-family: var(--font-th);
  font-size: 0.92rem;
  color: #0F172A;
}

#ws-workspace .ws-project-meta {
  display: block;
  font-family: var(--font-th);
  font-size: 0.75rem;
  color: #64748B;
}

#ws-workspace .ws-project-item-actions {
  display: flex;
  gap: 0.3rem;
  flex: 0 0 auto;
}

#ws-workspace .ws-project-load,
#ws-workspace .ws-project-delete,
#ws-workspace .ws-modal-cancel,
#ws-workspace .ws-modal-confirm {
  border: none;
  border-radius: 999px;
  padding: 0.35rem 0.7rem;
  font-family: var(--font-th);
  font-size: 0.82rem;
  font-weight: 700;
  cursor: pointer;
}

#ws-workspace .ws-project-load,
#ws-workspace .ws-modal-confirm {
  background: #0284C7;
  color: #FFFFFF;
}

#ws-workspace .ws-project-delete,
#ws-workspace .ws-modal-cancel {
  background: #F1F5F9;
  color: #334155;
}

#ws-workspace .ws-modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.4rem;
}

#ws-workspace .ws-project-empty {
  margin: 0.4rem 0;
  font-family: var(--font-th);
  font-size: 0.88rem;
  color: #64748B;
  text-align: center;
}

#fc-workspace > .workspace-toolbar,
#cw-workspace > .workspace-toolbar {
  overflow: hidden;
}

#fc-workspace > .workspace-toolbar > .toolbar-scrollable,
#cw-workspace > .workspace-toolbar > .toolbar-scrollable {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
}

#fc-workspace .fc-style-toggle {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

#fc-workspace .fc-style-option {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.45rem 0.6rem;
  border: 1.5px solid #E2E8F0;
  border-radius: 10px;
  background: #FFFFFF;
  font-family: var(--font-th);
  font-size: 0.86rem;
  font-weight: 600;
  color: #334155;
  cursor: pointer;
}

#fc-workspace .fc-style-option:has(input:checked) {
  border-color: #60A5FA;
  background: #EFF6FF;
  color: #1D4ED8;
}

#fc-workspace .fc-toolbar-actions,
#cw-workspace .cw-toolbar-actions {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  padding-top: 0.55rem;
  border-top: 2px dashed #EDF2F7;
}

#fc-workspace .fc-action-row,
#cw-workspace .cw-action-row {
  display: flex;
  flex-direction: row;
  align-items: stretch;
  gap: 0.35rem;
}

#fc-workspace .fc-action-row > .btn-print-pdf,
#fc-workspace .fc-action-row > .fc-save-btn,
#cw-workspace .cw-action-row > .btn-print-pdf,
#cw-workspace .cw-action-row > .cw-save-btn {
  flex: 1 1 50%;
  width: auto;
  min-width: 0;
  min-height: 36px;
  padding: 0.3rem 0.4rem;
  font-size: 0.72rem;
  line-height: 1.2;
  gap: 0.2rem;
  box-shadow: none;
  white-space: normal;
  text-align: center;
}

#fc-workspace .fc-action-row .dl-icon,
#cw-workspace .cw-action-row .dl-icon {
  font-size: 0.85rem;
}

#fc-workspace .fc-save-btn,
#cw-workspace .cw-save-btn {
  border: none;
  border-radius: var(--radius-pill);
  background: linear-gradient(135deg, #38BDF8, #0284C7);
  color: #FFFFFF;
  font-family: var(--font-th);
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

#fc-workspace .fc-load-btn,
#cw-workspace .cw-load-btn {
  width: 100%;
  min-height: 32px;
  padding: 0.28rem 0.5rem;
  border: 1.5px solid #7DD3FC;
  border-radius: var(--radius-pill);
  background: #F0F9FF;
  color: #0369A1;
  font-family: var(--font-th);
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
}

#cw-workspace .cw-action-hint {
  font-family: var(--font-th);
  font-size: 0.7rem;
  color: #64748B;
  text-align: center;
  line-height: 1.3;
}

#fc-workspace .fc-modal,
#cw-workspace .cw-modal {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: rgba(15, 23, 42, 0.45);
}

#fc-workspace .fc-modal-card,
#cw-workspace .cw-modal-card {
  width: min(420px, 100%);
  max-height: min(78vh, 640px);
  overflow: auto;
  background: #FFFFFF;
  border-radius: 16px;
  padding: 1rem 1rem 0.9rem;
  box-shadow: 0 18px 50px rgba(15, 23, 42, 0.25);
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
}

#fc-workspace .fc-modal-title,
#cw-workspace .cw-modal-title {
  margin: 0;
  font-family: var(--font-th);
  font-size: 1.15rem;
  color: #0F2744;
}

#fc-workspace .fc-project-list,
#cw-workspace .cw-project-list {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  max-height: 320px;
  overflow-y: auto;
  margin-top: 0.45rem;
}

#fc-workspace .fc-project-item,
#cw-workspace .fc-project-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.45rem 0.5rem;
  border: 1px solid #E2E8F0;
  border-radius: 10px;
  background: #F8FAFC;
}

#fc-workspace .fc-project-name,
#cw-workspace .fc-project-name {
  display: block;
  font-family: var(--font-th);
  font-size: 0.92rem;
  color: #0F172A;
}

#fc-workspace .fc-project-meta,
#cw-workspace .fc-project-meta {
  display: block;
  font-family: var(--font-th);
  font-size: 0.75rem;
  color: #64748B;
}

#fc-workspace .fc-project-item-actions,
#cw-workspace .fc-project-item-actions {
  display: flex;
  gap: 0.3rem;
  flex: 0 0 auto;
}

#fc-workspace .fc-project-load,
#fc-workspace .fc-project-delete,
#fc-workspace .fc-modal-cancel,
#fc-workspace .fc-modal-confirm,
#cw-workspace .cw-project-load,
#cw-workspace .cw-project-delete,
#cw-workspace .cw-modal-cancel,
#cw-workspace .cw-modal-confirm {
  border: none;
  border-radius: 999px;
  padding: 0.35rem 0.7rem;
  font-family: var(--font-th);
  font-size: 0.82rem;
  font-weight: 700;
  cursor: pointer;
}

#fc-workspace .fc-project-load,
#fc-workspace .fc-modal-confirm,
#cw-workspace .cw-project-load,
#cw-workspace .cw-modal-confirm {
  background: #0284C7;
  color: #FFFFFF;
}

#fc-workspace .fc-project-delete,
#fc-workspace .fc-modal-cancel,
#cw-workspace .cw-project-delete,
#cw-workspace .cw-modal-cancel {
  background: #F1F5F9;
  color: #334155;
}

#fc-workspace .fc-modal-actions,
#cw-workspace .cw-modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.4rem;
}

#fc-workspace .fc-project-empty,
#cw-workspace .fc-project-empty {
  margin: 0.4rem 0;
  font-family: var(--font-th);
  font-size: 0.88rem;
  color: #64748B;
  text-align: center;
}

/* ===================================================================
   WORD MATCHING WORKSPACE
   =================================================================== */
#wm-workspace.wm-workspace {
  display: flex;
  gap: 1.5rem;
  align-items: flex-start;
  margin-top: 1rem;
  animation: pageFadeIn 0.35s ease-out forwards;
}

#wm-workspace .wm-badge {
  background: #D1FAE5;
  color: #047857;
}

#wm-workspace > .workspace-toolbar {
  overflow: hidden;
}

#wm-workspace > .workspace-toolbar > .toolbar-scrollable {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
}

#wm-workspace .wm-note-input {
  width: 100%;
  min-height: 84px;
  resize: vertical;
  font-family: var(--font-th);
}

#wm-workspace .wm-limit-note,
#wm-workspace .wm-layout-label {
  margin: 0.35rem 0 0;
  font-family: var(--font-th);
  font-size: 0.82rem;
  font-weight: 600;
  color: #047857;
}

#wm-workspace .wm-layout-label {
  margin-bottom: 0.35rem;
}

#wm-workspace .wm-mode-toggle {
  display: flex;
  gap: 0.4rem;
  padding: 0.3rem;
  background: #ECFDF5;
  border-radius: 999px;
}

#wm-workspace .wm-mode-btn {
  flex: 1 1 0;
  border: none;
  background: transparent;
  border-radius: 999px;
  padding: 0.45rem 0.6rem;
  font-family: var(--font-th);
  font-weight: 700;
  font-size: 0.84rem;
  color: #047857;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.3rem;
}

#wm-workspace .wm-mode-btn.active {
  background: #FFFFFF;
  box-shadow: 0 2px 8px rgba(5, 150, 105, 0.18);
}

#wm-workspace .wm-vocab-list {
  max-height: 240px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  padding-right: 2px;
}

#wm-workspace .wm-check-item {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.3rem 0.45rem;
  border-radius: 6px;
  cursor: pointer;
  user-select: none;
}

#wm-workspace .wm-check-item:hover {
  background: #ECFDF5;
}

#wm-workspace .wm-check-item input[type="checkbox"] {
  width: 15px;
  height: 15px;
  accent-color: #059669;
  cursor: pointer;
  flex-shrink: 0;
}

#wm-workspace .wm-shuffle-btn {
  width: 100%;
  margin-top: 0.55rem;
  min-height: 34px;
  border: 1.5px solid #6EE7B7;
  border-radius: var(--radius-pill);
  background: #ECFDF5;
  color: #047857;
  font-family: var(--font-th);
  font-size: 0.84rem;
  font-weight: 700;
  cursor: pointer;
}

#wm-workspace .wm-style-toggle {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

#wm-workspace .wm-style-option {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.45rem 0.6rem;
  border: 1.5px solid #E2E8F0;
  border-radius: 10px;
  background: #FFFFFF;
  font-family: var(--font-th);
  font-size: 0.86rem;
  font-weight: 600;
  color: #334155;
  cursor: pointer;
}

#wm-workspace .wm-style-option:has(input:checked) {
  border-color: #34D399;
  background: #ECFDF5;
  color: #047857;
}

#wm-workspace .wm-color-row input[type="color"] {
  width: 100%;
  height: 38px;
  border: 1.5px solid #E2E8F0;
  border-radius: 8px;
  background: #FFFFFF;
  cursor: pointer;
}

#wm-workspace .wm-bg-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.4rem;
  max-height: 180px;
  overflow-y: auto;
}

#wm-workspace .wm-bg-thumb {
  padding: 0;
  border: 2px solid transparent;
  border-radius: 8px;
  background: #FFFFFF;
  cursor: pointer;
  overflow: hidden;
}

#wm-workspace .wm-bg-thumb.active {
  border-color: #059669;
  box-shadow: 0 0 0 2px rgba(5, 150, 105, 0.25);
}

#wm-workspace .wm-bg-thumb img {
  width: 100%;
  height: 58px;
  object-fit: cover;
  display: block;
  background: #FFFFFF;
}

#wm-workspace .wm-toolbar-actions {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  padding-top: 0.55rem;
  border-top: 2px dashed #EDF2F7;
}

#wm-workspace .wm-action-row {
  display: flex;
  flex-direction: row;
  align-items: stretch;
  gap: 0.35rem;
}

#wm-workspace .wm-action-row > .btn-print-pdf,
#wm-workspace .wm-action-row > .wm-save-btn {
  flex: 1 1 50%;
  width: auto;
  min-width: 0;
  min-height: 36px;
  padding: 0.3rem 0.4rem;
  font-size: 0.72rem;
  line-height: 1.2;
  gap: 0.2rem;
  box-shadow: none;
  white-space: normal;
  text-align: center;
}

#wm-workspace .wm-action-row .dl-icon {
  font-size: 0.85rem;
}

#wm-workspace .wm-save-btn {
  border: none;
  border-radius: var(--radius-pill);
  background: linear-gradient(135deg, #34D399, #059669);
  color: #FFFFFF;
  font-family: var(--font-th);
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

#wm-workspace .wm-load-btn {
  width: 100%;
  min-height: 32px;
  padding: 0.28rem 0.5rem;
  border: 1.5px solid #6EE7B7;
  border-radius: var(--radius-pill);
  background: #ECFDF5;
  color: #047857;
  font-family: var(--font-th);
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
}

#wm-workspace .wm-action-hint {
  font-family: var(--font-th);
  font-size: 0.7rem;
  color: #64748B;
  text-align: center;
  line-height: 1.3;
}

#wm-workspace .wm-preview-scroll {
  max-height: calc(100vh - 210px);
  overflow: auto;
  justify-content: center;
}

#wm-workspace .wm-pages {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 28px;
  width: max-content;
  max-width: 100%;
}

#wm-workspace .wm-sheet {
  width: 210mm;
  height: 297mm;
  max-width: none;
  flex: 0 0 auto;
  box-sizing: border-box;
  background: #FFFFFF;
  border-radius: 4px;
  box-shadow: 0 12px 40px rgba(15, 23, 42, 0.12);
  padding: 8mm 8mm 7mm;
  display: flex;
  flex-direction: column;
  gap: 3mm;
  color: #111827;
  position: relative;
  overflow: hidden;
}

#wm-workspace .wm-answer-sheet {
  background: #FFFFFF !important;
}

#wm-workspace .wm-bg-layer {
  position: absolute;
  inset: 0;
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  opacity: 0.22;
  pointer-events: none;
  z-index: 0;
}

#wm-workspace .wm-header,
#wm-workspace .wm-board,
#wm-workspace .wm-empty,
#wm-workspace .wm-instruction {
  position: relative;
  z-index: 1;
}

#wm-workspace .wm-header {
  flex: 0 0 auto;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 4mm;
  min-height: 16mm;
}

#wm-workspace .wm-header-main {
  flex: 1 1 auto;
  min-width: 0;
}

#wm-workspace .wm-title {
  margin: 0 0 1.2mm;
  font-family: var(--font-en);
  font-size: 18pt;
  font-weight: 700;
  line-height: 1.1;
  color: #064E3B;
}

#wm-workspace .wm-answer-kicker {
  margin: 0 0 1.2mm;
  font-family: var(--font-en);
  font-size: 16pt;
  font-weight: 700;
  color: #064E3B;
}

#wm-workspace .wm-instruction,
#wm-workspace .wm-answer-note {
  margin: 1.2mm 0 0;
  font-family: var(--font-en);
  font-size: 11pt;
  font-weight: 600;
  color: #111827;
}

#wm-workspace .wm-answer-note {
  font-family: var(--font-th);
}

#wm-workspace .wm-meta {
  display: flex;
  align-items: flex-end;
  gap: 2mm;
  font-family: var(--font-en);
  font-size: 11pt;
  font-weight: 600;
  min-width: 0;
}

#wm-workspace .wm-meta-custom {
  display: block;
  font-family: var(--font-th);
  font-weight: 600;
  font-size: 12pt;
  line-height: 1.4;
  white-space: pre-wrap;
  min-height: 8mm;
}

#wm-workspace .wm-line {
  flex: 1 1 auto;
  border-bottom: 1.5px solid #111827;
  min-width: 8mm;
  height: 1.05em;
}

#wm-workspace .wm-line-name {
  flex: 2.4 1 0;
}

#wm-workspace .wm-line-short {
  flex: 0.7 1 0;
  max-width: 18%;
}

#wm-workspace .wm-logo-slot {
  flex: 0 0 16mm;
  width: 16mm;
  height: 16mm;
}

#wm-workspace .wm-logo-img {
  width: 16mm;
  height: 16mm;
  object-fit: contain;
  display: block;
}

#wm-workspace .wm-logo-slot[hidden] {
  display: none !important;
  width: 0 !important;
  height: 0 !important;
  margin: 0 !important;
  padding: 0 !important;
}

#wm-workspace .wm-board {
  --wm-img-size: 80%;
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  grid-template-rows: repeat(var(--wm-rows), minmax(0, 1fr));
  column-gap: 16mm;
  row-gap: 2.5mm;
  position: relative;
}

#wm-workspace .wm-board.wm-layout-center {
  grid-template-columns: minmax(0, 1fr) minmax(0, 0.92fr) minmax(0, 1fr);
  column-gap: 10mm;
}

#wm-workspace .wm-slot {
  position: relative;
  min-width: 0;
  min-height: 0;
}

#wm-workspace .wm-slot-image {
  height: 100%;
  align-self: stretch;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 1mm;
}

#wm-workspace .wm-slot-word {
  align-self: center;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 12mm;
  padding: 1.5mm 3mm;
  border: 0.45mm solid #111827;
  border-radius: 3mm;
  background: rgba(255, 255, 255, 0.88);
}

#wm-workspace .wm-pic {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  min-width: 0;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

#wm-workspace .wm-img {
  width: var(--wm-img-size);
  height: var(--wm-img-size);
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  display: block;
}

#wm-workspace .wm-label {
  font-family: var(--font-en);
  font-weight: 700;
  font-size: 16pt;
  line-height: 1.15;
  letter-spacing: 0.03em;
  text-align: center;
  text-transform: uppercase;
  color: #111827;
  overflow-wrap: anywhere;
}

#wm-workspace .wm-board[data-wm-count="6"] .wm-label,
#wm-workspace .wm-board[data-wm-count="5"] .wm-label {
  font-size: 13pt;
}

#wm-workspace .wm-blank {
  flex: 0 0 8mm;
  height: 8mm;
  margin: 0 6mm;
  border-bottom: 0.45mm solid #111827;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  overflow: hidden;
}

#wm-workspace .wm-blank-fill {
  font-family: var(--font-en);
  font-weight: 700;
  font-size: 13pt;
  line-height: 1;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #DC2626;
  text-align: center;
  overflow-wrap: anywhere;
  max-width: 100%;
}

#wm-workspace .wm-anchor {
  position: absolute;
  top: 50%;
  width: 3.2mm;
  height: 3.2mm;
  border-radius: 50%;
  border: 0.45mm solid #111827;
  background: #FFFFFF;
  transform: translateY(-50%);
  z-index: 4;
}

#wm-workspace .wm-face-end .wm-anchor {
  right: 0;
}

#wm-workspace .wm-face-start .wm-anchor {
  left: 0;
}

#wm-workspace .wm-lines {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
  pointer-events: none;
  z-index: 3;
}

#wm-workspace .wm-lines line {
  stroke: #DC2626;
  stroke-width: 2.4px;
  stroke-linecap: round;
  vector-effect: non-scaling-stroke;
}

#wm-workspace .wm-empty {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 2mm;
  font-family: var(--font-th);
  font-weight: 600;
}

#wm-workspace .wm-modal {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: rgba(15, 23, 42, 0.45);
}

#wm-workspace .wm-modal-card {
  width: min(420px, 100%);
  max-height: min(78vh, 640px);
  overflow: auto;
  background: #FFFFFF;
  border-radius: 16px;
  padding: 1rem 1rem 0.9rem;
  box-shadow: 0 18px 50px rgba(15, 23, 42, 0.25);
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
}

#wm-workspace .wm-modal-title {
  margin: 0;
  font-family: var(--font-th);
  font-size: 1.15rem;
  color: #064E3B;
}

#wm-workspace .wm-project-list {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  max-height: 320px;
  overflow: auto;
}

#wm-workspace .wm-project-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.45rem 0.5rem;
  border: 1px solid #D1FAE5;
  border-radius: 10px;
}

#wm-workspace .wm-project-name,
#wm-workspace .wm-project-meta,
#wm-workspace .wm-project-empty {
  display: block;
  font-family: var(--font-th);
}

#wm-workspace .wm-project-name {
  font-size: 0.92rem;
  color: #064E3B;
}

#wm-workspace .wm-project-meta,
#wm-workspace .wm-project-empty {
  font-size: 0.78rem;
  color: #64748B;
}

#wm-workspace .wm-project-item-actions,
#wm-workspace .wm-modal-actions {
  display: flex;
  gap: 0.35rem;
  justify-content: flex-end;
}

#wm-workspace .wm-project-load,
#wm-workspace .wm-project-delete,
#wm-workspace .wm-modal-cancel,
#wm-workspace .wm-modal-confirm {
  border: none;
  border-radius: 999px;
  padding: 0.35rem 0.7rem;
  font-family: var(--font-th);
  font-size: 0.82rem;
  font-weight: 700;
  cursor: pointer;
}

#wm-workspace .wm-project-load,
#wm-workspace .wm-modal-confirm {
  background: #059669;
  color: #FFFFFF;
}

#wm-workspace .wm-project-delete,
#wm-workspace .wm-modal-cancel {
  background: #F1F5F9;
  color: #334155;
}

@font-face {
  font-family: "LayijiKutlaimuu";
  src: url("./assets/fonts/Layiji_kutlaimuu.ttf") format("truetype");
  font-weight: normal;
  font-style: normal;
  font-display: swap;
}

/* ===================================================================
   TRACING WORKSPACE
   =================================================================== */
#tr-workspace.tr-workspace {
  --tr-font-print: "Fredoka", sans-serif;
  --tr-ink: #92400e;
  display: flex;
  gap: 1.5rem;
  align-items: flex-start;
  margin-top: 1rem;
  animation: pageFadeIn 0.35s ease-out forwards;
}

#tr-workspace .tr-badge {
  background: #FEF3C7;
  color: #B45309;
}

#tr-workspace > .workspace-toolbar {
  overflow: hidden;
}

#tr-workspace > .workspace-toolbar > .toolbar-scrollable {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
}

#tr-workspace .tr-note-input {
  width: 100%;
  min-height: 84px;
  resize: vertical;
  font-family: var(--font-th);
}

#tr-workspace .tr-helper-text {
  margin: 12px 0 15px;
  font-family: var(--font-th);
  font-size: 0.85em;
  font-weight: 600;
  line-height: 1.45;
  color: #0056b3;
}

#tr-workspace .tr-limit-note,
#tr-workspace .tr-layout-label {
  margin: 0.35rem 0 0;
  font-family: var(--font-th);
  font-size: 0.82rem;
  font-weight: 600;
  color: #B45309;
}

#tr-workspace .tr-layout-label {
  margin-bottom: 0.35rem;
}

#tr-workspace .tr-tabs {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.35rem;
}

#tr-workspace .tr-tab {
  border: 1.5px solid #FDE68A;
  background: #FFFBEB;
  color: #92400E;
  border-radius: 12px;
  padding: 0.45rem 0.3rem;
  font-family: var(--font-th);
  font-size: 0.78rem;
  font-weight: 700;
  line-height: 1.25;
  cursor: pointer;
}

#tr-workspace .tr-tab.active {
  background: linear-gradient(135deg, #FBBF24, #D97706);
  border-color: #D97706;
  color: #FFFFFF;
}

#tr-workspace .tr-panel {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

#tr-workspace .tr-style-toggle {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

#tr-workspace .tr-style-option {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.45rem 0.6rem;
  border: 1.5px solid #FDE68A;
  border-radius: 12px;
  background: #FFFBEB;
  font-family: var(--font-th);
  font-size: 0.84rem;
  font-weight: 700;
  color: #78350F;
  cursor: pointer;
}

#tr-workspace .tr-style-option:has(input:checked) {
  border-color: #D97706;
  background: #FEF3C7;
  box-shadow: inset 0 0 0 1px #D97706;
}

#tr-workspace .tr-style-copy {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
}

#tr-workspace .tr-sample {
  width: 2.5rem;
  height: 0.95rem;
  flex: 0 0 auto;
  border-radius: 3px;
  background-repeat: no-repeat;
}

#tr-workspace .tr-sample-2 {
  background-image: linear-gradient(#92400E, #92400E), linear-gradient(#92400E, #92400E);
  background-size: 100% 2px, 100% 2px;
  background-position: top, bottom;
}

#tr-workspace .tr-sample-3 {
  background-image:
    linear-gradient(#92400E, #92400E),
    repeating-linear-gradient(90deg, #D97706 0 3px, transparent 3px 6px),
    linear-gradient(#92400E, #92400E);
  background-size: 100% 2px, 100% 2px, 100% 2px;
  background-position: top, center, bottom;
}

#tr-workspace .tr-sample-blank {
  border: 1.5px dashed #D6D3D1;
  background: #FFFFFF;
}

#tr-workspace .tr-letter-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 0.3rem;
  margin-top: 0.55rem;
}

#tr-workspace .tr-letter-btn {
  border: 1.5px solid #FDE68A;
  background: #FFFFFF;
  color: #92400E;
  border-radius: 10px;
  min-height: 2rem;
  font-family: var(--tr-font-print);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
}

#tr-workspace .tr-letter-btn.active {
  background: #D97706;
  border-color: #B45309;
  color: #FFFFFF;
}

#tr-workspace .tr-mode-toggle {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.4rem;
}

#tr-workspace .tr-mode-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.3rem;
  border: 1.5px solid #FDE68A;
  background: #FFFBEB;
  color: #92400E;
  border-radius: 999px;
  padding: 0.4rem 0.5rem;
  font-family: var(--font-th);
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
}

#tr-workspace .tr-mode-btn.active {
  background: #D97706;
  border-color: #D97706;
  color: #FFFFFF;
}

#tr-workspace .tr-vocab-list {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  max-height: 220px;
  overflow: auto;
  margin-top: 0.45rem;
}

#tr-workspace .tr-check-item {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.3rem 0.4rem;
  border-radius: 10px;
  font-family: var(--font-en);
  font-weight: 600;
  color: #44403C;
}

#tr-workspace .tr-check-item:hover {
  background: #FFFBEB;
}

#tr-workspace .tr-check-line {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  margin-bottom: 0.55rem;
  font-family: var(--font-th);
  font-weight: 700;
  color: #78350F;
}

#tr-workspace .tr-heading-pair {
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

#tr-workspace .tr-heading-pair .tr-heading-input {
  flex: 1 1 auto;
  min-width: 0;
}

#tr-workspace .tr-heading-color {
  flex: 0 0 2.6rem;
  width: 2.6rem;
  height: 2.4rem;
  padding: 0.15rem;
  border: 1.5px solid #FDE68A;
  border-radius: 10px;
  background: #FFFFFF;
  cursor: pointer;
}

#tr-workspace .tr-title.tr-heading-hidden,
#tr-workspace .tr-instruction.tr-heading-hidden {
  display: none;
}

#tr-workspace .tr-color-row input[type="color"] {
  width: 100%;
  height: 2.2rem;
  border: 1.5px solid #FDE68A;
  border-radius: 10px;
  background: #FFFFFF;
  cursor: pointer;
}

#tr-workspace .tr-bg-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.4rem;
}

#tr-workspace .tr-bg-thumb {
  border: 2px solid transparent;
  border-radius: 10px;
  padding: 0;
  overflow: hidden;
  background: #F5F5F4;
  cursor: pointer;
  aspect-ratio: 1.4;
}

#tr-workspace .tr-bg-thumb.active {
  border-color: #D97706;
}

#tr-workspace .tr-bg-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

#tr-workspace .tr-toolbar-actions {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  padding-top: 0.35rem;
}

#tr-workspace .tr-action-row {
  display: flex;
  gap: 0.4rem;
}

#tr-workspace .tr-action-row > .btn-print-pdf,
#tr-workspace .tr-action-row > .tr-save-btn {
  flex: 1 1 0;
  min-width: 0;
  justify-content: center;
  min-height: 0;
  padding: 0.28rem 0.4rem;
  font-size: 0.72rem;
  gap: 0.25rem;
  box-shadow: none;
}

#tr-workspace .tr-action-row > .btn-print-pdf:hover,
#tr-workspace .tr-action-row > .tr-save-btn:hover {
  transform: none;
}

#tr-workspace .tr-save-btn,
#tr-workspace .tr-load-btn,
#tr-workspace .tr-modal-cancel,
#tr-workspace .tr-modal-confirm,
#tr-workspace .tr-project-load,
#tr-workspace .tr-project-delete {
  border: none;
  border-radius: 999px;
  font-family: var(--font-th);
  font-weight: 700;
  cursor: pointer;
}

#tr-workspace .tr-save-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  background: #FEF3C7;
  color: #92400E;
}

#tr-workspace .tr-load-btn {
  background: #FFFFFF;
  color: #92400E;
  border: 1.5px solid #FDE68A;
  padding: 0.28rem 0.5rem;
  font-size: 0.72rem;
}

#tr-workspace .tr-action-hint {
  font-family: var(--font-th);
  font-size: 0.68rem;
  color: #78716C;
}

#tr-workspace .tr-custom-fields {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

#tr-workspace .tr-custom-field {
  display: grid;
  grid-template-columns: 1.4rem minmax(0, 1fr);
  align-items: center;
  gap: 0.4rem;
  font-family: var(--font-en);
  font-weight: 700;
  color: #B45309;
}

#tr-workspace .tr-preview-scroll {
  width: 100%;
}

#tr-workspace .tr-pages {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 28px;
  width: max-content;
  max-width: 100%;
}

#tr-workspace .tr-sheet {
  --tr-top: 8%;
  --tr-mid: 40%;
  --tr-base: 74%;
  --tr-band: 66%;
  --tr-desc: 18%;
  width: 210mm;
  height: 297mm;
  max-width: none;
  flex: 0 0 auto;
  box-sizing: border-box;
  background: #FFFDF8;
  border-radius: 4px;
  box-shadow: 0 12px 40px rgba(15, 23, 42, 0.12);
  padding: 8mm 9mm 7mm;
  display: flex;
  flex-direction: column;
  gap: 3mm;
  color: #1C1917;
  position: relative;
  overflow: hidden;
}

#tr-workspace .tr-bg-layer {
  position: absolute;
  inset: 0;
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  opacity: 0.2;
  pointer-events: none;
  z-index: 0;
}

#tr-workspace .tr-header,
#tr-workspace .tr-content-area,
#tr-workspace .tr-empty {
  position: relative;
}

#tr-workspace .tr-header {
  flex: 0 0 auto;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 4mm;
  min-height: 16mm;
  z-index: 3;
  background-color: inherit;
  padding-bottom: 1.5mm;
}

#tr-workspace .tr-header-main {
  flex: 1 1 auto;
  min-width: 0;
}

#tr-workspace .tr-title {
  margin: 0;
  font-family: var(--font-en);
  font-size: 16pt;
  font-weight: 700;
  line-height: 1.05;
  color: #92400E;
}

#tr-workspace .tr-instruction {
  margin: 1mm 0 1.4mm;
  font-family: var(--font-th);
  font-size: 11pt;
  font-weight: 600;
  color: #44403C;
}

#tr-workspace .tr-meta {
  display: flex;
  align-items: flex-end;
  gap: 2mm;
  font-family: var(--font-en);
  font-size: 11pt;
  font-weight: 600;
  min-width: 0;
}

#tr-workspace .tr-meta-custom {
  display: block;
  font-family: var(--font-th);
  font-weight: 600;
  font-size: 12pt;
  line-height: 1.35;
  white-space: pre-wrap;
  min-height: 8mm;
}

#tr-workspace .tr-field-line {
  flex: 1 1 auto;
  border-bottom: 1.5px solid #1C1917;
  min-width: 8mm;
  height: 1.05em;
}

#tr-workspace .tr-field-name {
  flex: 2.2 1 0;
}

#tr-workspace .tr-field-short {
  flex: 0.7 1 0;
  max-width: 18%;
}

#tr-workspace .tr-logo-slot {
  flex: 0 0 16mm;
  width: 16mm;
  height: 16mm;
}

#tr-workspace .tr-logo-img {
  width: 16mm;
  height: 16mm;
  object-fit: contain;
  display: block;
}

#tr-workspace .tr-logo-slot[hidden] {
  display: none !important;
  width: 0 !important;
  height: 0 !important;
  margin: 0 !important;
  padding: 0 !important;
}

#tr-workspace .tr-content-area {
  flex: 1 1 auto;
  min-height: 0;
  height: calc(100% - 32mm);
  margin-top: 3mm;
  padding-top: 5mm;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  gap: 0.4mm;
  overflow: hidden;
  z-index: 1;
}

#tr-workspace .tr-row {
  flex: 1 1 0;
  height: auto;
  min-height: 0;
  display: flex;
  align-items: stretch;
  gap: 2.2mm;
  overflow: visible;
}

#tr-workspace .tr-pic-slot {
  position: relative;
  flex: 0 0 16mm;
  width: 16mm;
  align-self: stretch;
}

#tr-workspace .tr-pic {
  position: absolute;
  left: 0;
  right: 0;
  top: var(--tr-top);
  height: var(--tr-band);
  width: 100%;
  object-fit: contain;
  object-position: center bottom;
  display: block;
}

#tr-workspace .tr-write {
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
}

#tr-workspace .tr-rule {
  position: absolute;
  left: 0;
  right: 0;
  border-top: 0.45mm solid #1C1917;
  pointer-events: none;
}

#tr-workspace .tr-rule-top { top: calc(var(--tr-top) - 4px); }
#tr-workspace .tr-rule-mid {
  top: calc((var(--tr-top) + var(--tr-base)) / 2);
  border-top-style: dotted;
  border-top-width: 0.55mm;
  border-top-color: #6B7280;
}
#tr-workspace .tr-rule-base { top: calc(var(--tr-base) + 4px); }

#tr-workspace .tr-sheet[data-tr-guide="2"] .tr-rule-mid,
#tr-workspace .tr-sheet[data-tr-guide="blank"] .tr-rule {
  display: none;
}

#tr-workspace .tr-line-grid {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: repeat(var(--tr-cols, 4), minmax(0, 1fr));
  column-gap: 4.5mm;
  align-items: stretch;
}

#tr-workspace .tr-cell {
  position: relative;
  min-width: 0;
  height: 100%;
  overflow: visible;
}

#tr-workspace .tr-custom-word,
#tr-workspace .tr-thai-glyph,
#tr-workspace .tr-glyph text {
  font-family: "LayijiKutlaimuu", sans-serif;
  font-weight: normal;
  color: #999999;
  fill: #999999;
}

#tr-workspace .tr-thai-glyph,
#tr-workspace .tr-glyph text {
  text-rendering: optimizeLegibility;
  font-feature-settings: "liga" 1, "ccmp" 0;
}

#tr-workspace .tr-glyph {
  position: absolute;
  left: 50%;
  top: var(--tr-top);
  height: calc(var(--tr-band) + var(--tr-desc));
  width: auto;
  transform: translateX(-50%);
  overflow: visible;
  pointer-events: none;
}

#tr-workspace .tr-empty {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 2mm;
  font-family: var(--font-th);
  font-weight: 600;
  color: #78716C;
}

#tr-workspace .tr-modal {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: rgba(15, 23, 42, 0.45);
}

#tr-workspace .tr-modal-card {
  width: min(420px, 100%);
  max-height: min(78vh, 640px);
  overflow: auto;
  background: #FFFFFF;
  border-radius: 16px;
  padding: 1rem 1rem 0.9rem;
  box-shadow: 0 18px 50px rgba(15, 23, 42, 0.25);
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
}

#tr-workspace .tr-modal-title {
  margin: 0;
  font-family: var(--font-th);
  font-size: 1.15rem;
  color: #92400E;
}

#tr-workspace .tr-project-list {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  max-height: 320px;
  overflow: auto;
}

#tr-workspace .tr-project-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.45rem 0.5rem;
  border: 1px solid #FDE68A;
  border-radius: 10px;
}

#tr-workspace .tr-project-name,
#tr-workspace .tr-project-meta,
#tr-workspace .tr-project-empty {
  display: block;
  font-family: var(--font-th);
}

#tr-workspace .tr-project-name {
  font-size: 0.92rem;
  color: #92400E;
}

#tr-workspace .tr-project-meta,
#tr-workspace .tr-project-empty {
  font-size: 0.78rem;
  color: #78716C;
}

#tr-workspace .tr-project-item-actions,
#tr-workspace .tr-modal-actions {
  display: flex;
  gap: 0.35rem;
  justify-content: flex-end;
}

#tr-workspace .tr-project-load,
#tr-workspace .tr-project-delete,
#tr-workspace .tr-modal-cancel,
#tr-workspace .tr-modal-confirm {
  padding: 0.35rem 0.7rem;
  font-size: 0.82rem;
}

#tr-workspace .tr-project-load,
#tr-workspace .tr-modal-confirm {
  background: #D97706;
  color: #FFFFFF;
}

#tr-workspace .tr-project-delete,
#tr-workspace .tr-modal-cancel {
  background: #F5F5F4;
  color: #44403C;
}

/* ===================================================================
   PICTURE STORY WORKSHEET GENERATOR (#ps-workspace)
   =================================================================== */
#ps-workspace.ps-workspace {
  display: flex;
  gap: 1.5rem;
  align-items: flex-start;
  margin-top: 1rem;
  animation: pageFadeIn 0.35s ease-out forwards;
}

#ps-workspace .ps-badge {
  background: #E0F2FE;
  color: #0369A1;
}

#ps-workspace > .workspace-toolbar {
  overflow: hidden;
}

#ps-workspace > .workspace-toolbar > .toolbar-scrollable {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding-right: 0.2rem;
}

#ps-workspace .ps-mode-toggle {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.45rem;
}

#ps-workspace .ps-mode-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  padding: 0.55rem 0.6rem;
  border-radius: 12px;
  border: 2px solid #E2E8F0;
  background: #FFFFFF;
  color: #334155;
  font-family: var(--font-th);
  font-size: 0.86rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.18s ease;
}

#ps-workspace .ps-mode-btn.active {
  border-color: #0284C7;
  background: #E0F2FE;
  color: #0369A1;
}

#ps-workspace .ps-scene-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.45rem;
  max-height: 175px;
  overflow-y: auto;
  padding: 0.25rem;
  background: #FFFFFF;
  border: 1.5px solid #E2E8F0;
  border-radius: 12px;
}

#ps-workspace .ps-scene-thumb {
  position: relative;
  border: 2px solid #E2E8F0;
  border-radius: 9px;
  padding: 0;
  background: #F8FAFC;
  cursor: pointer;
  overflow: hidden;
  aspect-ratio: 16 / 10;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s ease, border-color 0.15s ease;
}

#ps-workspace .ps-scene-thumb:hover {
  transform: translateY(-1px);
  border-color: #38BDF8;
}

#ps-workspace .ps-scene-thumb.active {
  border-color: #0284C7;
  box-shadow: 0 0 0 2px rgba(2, 132, 199, 0.25);
}

#ps-workspace .ps-scene-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

#ps-workspace .ps-scene-thumb-label {
  position: absolute;
  bottom: 2px;
  right: 4px;
  background: rgba(15, 23, 42, 0.72);
  color: #FFFFFF;
  font-family: var(--font-th);
  font-size: 0.65rem;
  font-weight: 700;
  padding: 1px 5px;
  border-radius: 6px;
}

#ps-workspace .ps-scene-blank-note {
  grid-column: 1 / -1;
  padding: 0.85rem;
  text-align: center;
  font-family: var(--font-th);
  font-size: 0.85rem;
  color: #64748B;
}

#ps-workspace .ps-vocab-picker-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.45rem;
  max-height: 230px;
  overflow-y: auto;
  padding: 0.35rem;
  background: #FFFFFF;
  border: 1.5px solid #E2E8F0;
  border-radius: 12px;
}

#ps-workspace .ps-vocab-card-btn {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.15rem;
  padding: 0.45rem 0.35rem;
  border: 1.5px solid #E2E8F0;
  border-radius: 10px;
  background: #FAFCFF;
  cursor: pointer;
  text-align: center;
  transition: all 0.16s ease;
}

#ps-workspace .ps-vocab-card-btn:hover {
  border-color: #0284C7;
  background: #F0F9FF;
  transform: translateY(-1px);
}

#ps-workspace .ps-vocab-card-btn:active {
  transform: scale(0.97);
}

#ps-workspace .ps-vocab-card-thumb {
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
}

#ps-workspace .ps-vocab-thumb-img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  display: block;
}

#ps-workspace .ps-vocab-card-en {
  font-family: var(--font-en);
  font-size: 0.8rem;
  font-weight: 700;
  color: #1E293B;
  line-height: 1.15;
}

#ps-workspace .ps-vocab-card-th {
  font-family: var(--font-th);
  font-size: 0.72rem;
  color: #64748B;
  line-height: 1.15;
}

#ps-workspace .ps-vocab-add-badge {
  font-family: var(--font-th);
  font-size: 0.66rem;
  font-weight: 700;
  color: #0284C7;
  background: #E0F2FE;
  padding: 1px 6px;
  border-radius: 999px;
  margin-top: 2px;
}

#ps-workspace .ps-item-inspector {
  margin-top: 0.45rem;
  padding: 0.65rem;
  border-radius: 12px;
  background: #F0F9FF;
  border: 1.5px solid #BAE6FD;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

#ps-workspace .ps-inspector-title {
  font-family: var(--font-th);
  font-size: 0.84rem;
  color: #0369A1;
}

#ps-workspace .ps-inspector-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.35rem;
}

#ps-workspace .ps-mini-btn {
  padding: 0.38rem 0.3rem;
  border-radius: 8px;
  border: 1px solid #CBD5E1;
  background: #FFFFFF;
  color: #1E293B;
  font-family: var(--font-th);
  font-size: 0.76rem;
  font-weight: 700;
  cursor: pointer;
}

#ps-workspace .ps-mini-btn:hover {
  background: #E2E8F0;
}

#ps-workspace .ps-mini-btn-danger {
  border-color: #FECACA;
  background: #FEF2F2;
  color: #DC2626;
}

#ps-workspace .ps-mini-btn-danger:hover {
  background: #FEE2E2;
}

#ps-workspace .ps-lines-selector {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.45rem;
}

#ps-workspace .ps-line-option {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  padding: 0.5rem 0.4rem;
  border: 2px solid #E2E8F0;
  border-radius: 10px;
  background: #FFFFFF;
  font-family: var(--font-th);
  font-size: 0.85rem;
  font-weight: 700;
  color: #334155;
  cursor: pointer;
}

#ps-workspace .ps-line-option:has(input:checked) {
  border-color: #0284C7;
  background: #E0F2FE;
  color: #0369A1;
}

#ps-workspace .ps-check-line {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  font-family: var(--font-th);
  font-size: 0.85rem;
  font-weight: 600;
  color: #334155;
  cursor: pointer;
}

#ps-workspace .ps-toolbar-actions {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding-top: 0.55rem;
  border-top: 2px dashed #E2E8F0;
}

#ps-workspace .ps-action-row {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: 0.45rem;
}

#ps-workspace .ps-action-row > .btn-print-pdf,
#ps-workspace .ps-action-row > .ps-save-btn {
  width: 100%;
  min-height: 44px;
  padding: 0.55rem 0.65rem;
  font-size: 0.86rem;
  border-radius: 12px;
  justify-content: center;
}

#ps-workspace .ps-save-btn,
#ps-workspace .ps-load-btn,
#ps-workspace .ps-modal-cancel,
#ps-workspace .ps-modal-confirm,
#ps-workspace .ps-project-load,
#ps-workspace .ps-project-delete {
  border: none;
  border-radius: 12px;
  font-family: var(--font-th);
  font-weight: 700;
  cursor: pointer;
}

#ps-workspace .ps-save-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  color: #FFFFFF;
  background: linear-gradient(135deg, #0284C7, #0369A1);
}

#ps-workspace .ps-load-btn {
  width: 100%;
  min-height: 38px;
  padding: 0.45rem 0.65rem;
  font-size: 0.85rem;
  color: #0369A1;
  background: #E0F2FE;
}

#ps-workspace .ps-action-hint {
  font-family: var(--font-th);
  font-size: 0.76rem;
  color: #64748B;
  text-align: center;
}

/* A4 Worksheet Preview Sheet (#ps-workspace .ps-sheet) */
#ps-workspace .ps-preview-scroll {
  overflow-x: auto;
}

#ps-workspace .ps-pages {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
  width: max-content;
  max-width: 100%;
}

#ps-workspace .ps-sheet {
  width: 210mm;
  height: 297mm;
  max-width: none;
  flex: 0 0 auto;
  box-sizing: border-box;
  background: #FFFFFF;
  border-radius: 4px;
  box-shadow: 0 12px 40px rgba(15, 23, 42, 0.12);
  padding: 9mm 11mm 9mm;
  display: flex;
  flex-direction: column;
  gap: 3.5mm;
  color: #1E293B;
  position: relative;
  overflow: hidden;
}

#ps-workspace .ps-header {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  gap: 2.5mm;
  border-bottom: 2px solid #1E293B;
  padding-bottom: 2.5mm;
}

#ps-workspace .ps-header-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 3mm;
}

#ps-workspace .ps-header-main {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.8mm;
}

#ps-workspace .ps-logo-slot {
  flex: 0 0 16mm;
  width: 16mm;
  height: 16mm;
}

#ps-workspace .ps-header-logo {
  width: 16mm;
  height: 16mm;
  max-width: 16mm;
  max-height: 16mm;
  object-fit: contain;
  flex-shrink: 0;
  display: block;
}

#ps-workspace .ps-logo-slot[hidden] {
  display: none !important;
  width: 0 !important;
  height: 0 !important;
  margin: 0 !important;
  padding: 0 !important;
}

#ps-workspace .ps-title-wrap {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

#ps-workspace .ps-title {
  margin: 0;
  font-family: var(--font-en), var(--font-th);
  font-size: 16pt;
  font-weight: 800;
  color: #0F172A;
  line-height: 1.15;
}

#ps-workspace .ps-instruction {
  margin: 0.8mm 0 0;
  font-family: var(--font-en), var(--font-th);
  font-size: 10.5pt;
  font-weight: 600;
  color: #475569;
  line-height: 1.25;
}

#ps-workspace .ps-student-meta {
  display: flex;
  align-items: flex-end;
  gap: 4mm;
  font-family: var(--font-en);
  font-size: 11pt;
  font-weight: 700;
  color: #1E293B;
}

#ps-workspace .ps-meta-field {
  display: flex;
  align-items: flex-end;
  gap: 1.5mm;
  min-width: 0;
}

#ps-workspace .ps-meta-name {
  flex: 2.2 1 0;
}

#ps-workspace .ps-meta-class {
  flex: 1 1 0;
}

#ps-workspace .ps-meta-date,
#ps-workspace .ps-meta-no {
  flex: 0.9 1 0;
}

#ps-workspace .ps-meta-label {
  white-space: nowrap;
}

#ps-workspace .ps-meta-line {
  flex: 1 1 auto;
  border-bottom: 1.5px solid #334155;
  height: 1.05em;
  min-width: 10mm;
}

#ps-workspace .ps-meta-custom {
  font-family: var(--font-th);
  font-size: 11pt;
  font-weight: 600;
  line-height: 1.35;
  white-space: pre-wrap;
  color: #1E293B;
}

#ps-workspace .ps-student-checks {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.35rem 0.75rem;
}

/* Scene Canvas Box */
#ps-workspace .ps-scene-canvas {
  position: relative;
  width: 100%;
  flex: 1 1 auto;
  min-height: 105mm;
  border: 2.2px solid #1E293B;
  border-radius: 4mm;
  background: #F8FAFC;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  touch-action: pan-y;
}

#ps-workspace .ps-scene-bg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  pointer-events: none;
  user-select: none;
  z-index: 1;
}

#ps-workspace .ps-scene-bg.is-bw {
  filter: grayscale(1) contrast(0.72) brightness(1.36);
  opacity: 0.42;
}

#ps-workspace .ps-scene-thumb img.is-bw {
  filter: grayscale(1) contrast(0.8) brightness(1.3);
  opacity: 0.56;
}

#ps-workspace .ps-scene-bg-blank {
  position: absolute;
  inset: 0;
  background: #FFFFFF;
  z-index: 1;
}

#ps-workspace .ps-scene-items-layer {
  position: absolute;
  inset: 0;
  z-index: 2;
}

#ps-workspace .ps-scene-item {
  position: absolute;
  cursor: grab;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid transparent;
  border-radius: 4px;
  box-sizing: border-box;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

#ps-workspace .ps-scene-item.is-selected {
  border-color: #0284C7;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.85);
}

#ps-workspace .ps-scene-item:active {
  cursor: grabbing;
}

#ps-workspace .ps-scene-item-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
  user-select: none;
  display: block;
  filter: drop-shadow(0 2px 4px rgba(15, 23, 42, 0.14));
}

#ps-workspace .ps-item-delete-btn,
#ps-workspace .ps-item-flip-btn,
#ps-workspace .ps-item-handle,
#ps-workspace .ps-item-rotate-handle,
#ps-workspace .ps-item-rotate-stem {
  display: none;
}

#ps-workspace .ps-scene-item.is-selected .ps-item-delete-btn {
  display: inline-flex;
  position: absolute;
  top: -12px;
  right: -12px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid #FFFFFF;
  background: #EF4444;
  color: #FFFFFF;
  font-size: 14px;
  font-weight: 800;
  line-height: 1;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
  z-index: 6;
  touch-action: none;
  padding: 0;
}

#ps-workspace .ps-scene-item.is-selected .ps-item-flip-btn {
  display: inline-flex;
  position: absolute;
  left: -13px;
  top: 50%;
  width: 24px;
  height: 24px;
  margin-top: -12px;
  border-radius: 50%;
  border: 2px solid #FFFFFF;
  background: #0284C7;
  color: #FFFFFF;
  font-size: 13px;
  font-weight: 800;
  line-height: 1;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
  z-index: 6;
  touch-action: none;
  padding: 0;
}

#ps-workspace .ps-scene-item.is-selected .ps-item-handle {
  display: block;
  position: absolute;
  width: 14px;
  height: 14px;
  border-radius: 3px;
  border: 2px solid #FFFFFF;
  background: #0284C7;
  box-shadow: 0 1px 4px rgba(15, 23, 42, 0.28);
  z-index: 6;
  touch-action: none;
}

#ps-workspace .ps-item-handle[data-ps-handle="nw"] {
  top: -8px;
  left: -8px;
  cursor: nwse-resize;
}

#ps-workspace .ps-item-handle[data-ps-handle="sw"] {
  bottom: -8px;
  left: -8px;
  cursor: nesw-resize;
}

#ps-workspace .ps-item-handle[data-ps-handle="se"] {
  bottom: -8px;
  right: -8px;
  cursor: nwse-resize;
}

#ps-workspace .ps-scene-item.is-selected .ps-item-rotate-stem {
  display: block;
  position: absolute;
  top: -28px;
  left: 50%;
  width: 2px;
  height: 18px;
  background: #0284C7;
  transform: translateX(-50%);
  pointer-events: none;
  z-index: 5;
}

#ps-workspace .ps-scene-item.is-selected .ps-item-rotate-handle {
  display: block;
  position: absolute;
  top: -42px;
  left: 50%;
  width: 18px;
  height: 18px;
  margin-left: -9px;
  border-radius: 50%;
  border: 2px solid #FFFFFF;
  background: #0F766E;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
  cursor: grab;
  z-index: 6;
  touch-action: none;
}

#ps-workspace .ps-scene-item.is-selected .ps-item-rotate-handle::after {
  content: "";
  position: absolute;
  inset: 4px;
  border: 2px solid #FFFFFF;
  border-right-color: transparent;
  border-radius: 50%;
}

#ps-workspace .ps-item-rotate-handle:active {
  cursor: grabbing;
}

#ps-workspace .ps-canvas-empty-hint {
  position: absolute;
  left: 50%;
  bottom: 12px;
  transform: translateX(-50%);
  background: rgba(255, 255, 255, 0.88);
  border: 1.5px dashed #0284C7;
  color: #0369A1;
  font-family: var(--font-th);
  font-size: 0.9rem;
  font-weight: 700;
  padding: 6px 14px;
  border-radius: 999px;
  pointer-events: none;
  z-index: 3;
  white-space: nowrap;
}

/* Word Bank Bar */
#ps-workspace .ps-wordbank {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 2mm;
  padding: 2mm 3mm;
  border: 1.5px dashed #475569;
  border-radius: 2.5mm;
  background: #F8FAFC;
}

#ps-workspace .ps-wordbank-label {
  font-family: var(--font-en);
  font-size: 10pt;
  font-weight: 800;
  color: #0F172A;
}

#ps-workspace .ps-wordbank-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 1.8mm;
}

#ps-workspace .ps-wordbank-chip {
  font-family: var(--font-en);
  font-size: 10pt;
  font-weight: 700;
  color: #1E293B;
  background: #FFFFFF;
  border: 1.2px solid #94A3B8;
  border-radius: 999px;
  padding: 0.5mm 3mm;
}

/* Handwriting 3-Line Section */
#ps-workspace .ps-writing-area {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 3.5mm;
  padding-top: 1mm;
}

#ps-workspace .ps-sheet.ps-lines-3 .ps-writing-line {
  height: 15mm;
}

#ps-workspace .ps-sheet.ps-lines-4 .ps-writing-line {
  height: 13.5mm;
}

#ps-workspace .ps-sheet.ps-lines-5 .ps-writing-line {
  height: 12mm;
}

#ps-workspace .ps-writing-line {
  display: block;
  width: 100%;
}

#ps-workspace .ps-line-guides {
  flex: 1 1 auto;
  position: relative;
  height: 100%;
}

#ps-workspace .ps-rule {
  position: absolute;
  left: 0;
  right: 0;
  display: block;
}

#ps-workspace .ps-rule-top {
  top: 0;
  border-top: 1.4px solid #334155;
}

#ps-workspace .ps-rule-mid {
  top: 50%;
  border-top: 1.2px dashed #64748B;
}

#ps-workspace .ps-rule-bottom {
  bottom: 0;
  border-top: 1.6px solid #0F172A;
}

/* Project Save/Load Modal inside #ps-workspace */
#ps-workspace .ps-modal {
  position: fixed;
  inset: 0;
  z-index: 1200;
  background: rgba(15, 23, 42, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

#ps-workspace .ps-modal[hidden] {
  display: none !important;
}

#ps-workspace .ps-modal-card {
  width: min(440px, 100%);
  background: #FFFFFF;
  border-radius: 20px;
  padding: 1.35rem;
  box-shadow: 0 20px 48px rgba(15, 23, 42, 0.22);
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

#ps-workspace .ps-modal-title {
  margin: 0;
  font-family: var(--font-th);
  font-size: 1.2rem;
  color: #0F172A;
}

#ps-workspace .ps-project-list {
  max-height: 240px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

#ps-workspace .ps-project-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.65rem 0.75rem;
  border: 1.5px solid #E2E8F0;
  border-radius: 12px;
  background: #F8FAFC;
}

#ps-workspace .ps-project-name {
  margin: 0;
  font-family: var(--font-th);
  font-size: 0.92rem;
  font-weight: 700;
  color: #1E293B;
}

#ps-workspace .ps-project-meta,
#ps-workspace .ps-project-empty {
  margin: 0;
  font-family: var(--font-th);
  font-size: 0.78rem;
  color: #64748B;
}

#ps-workspace .ps-project-item-actions,
#ps-workspace .ps-modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.45rem;
}

#ps-workspace .ps-project-load,
#ps-workspace .ps-project-delete,
#ps-workspace .ps-modal-cancel,
#ps-workspace .ps-modal-confirm {
  padding: 0.45rem 0.85rem;
  font-size: 0.85rem;
}

#ps-workspace .ps-project-load,
#ps-workspace .ps-modal-confirm {
  color: #FFFFFF;
  background: #0284C7;
}

#ps-workspace .ps-project-delete,
#ps-workspace .ps-modal-cancel {
  color: #475569;
  background: #F1F5F9;
}

/* ===================================================================
   TELLING TIME WORKSHEET GENERATOR (#tt-workspace)
   =================================================================== */
#tt-workspace.tt-workspace {
  display: flex;
  gap: 1.5rem;
  align-items: flex-start;
  margin-top: 1rem;
  animation: pageFadeIn 0.35s ease-out forwards;
}

#tt-workspace .tt-badge {
  background: #F3E8FF;
  color: #6D28D9;
}

#tt-workspace > .workspace-toolbar {
  overflow: hidden;
}

#tt-workspace > .workspace-toolbar > .toolbar-scrollable {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding-right: 0.2rem;
}

#tt-workspace .tt-time-control-row {
  display: flex;
  gap: 0.55rem;
  align-items: stretch;
}

#tt-workspace .tt-time-input {
  flex: 1 1 0;
  min-width: 110px;
  font-family: var(--font-en);
  font-size: 1.15rem;
  font-weight: 700;
  color: #1E293B;
  text-align: center;
  padding: 0.5rem 0.65rem;
  border-radius: 12px;
  border: 2px solid #DDD6FE;
  background: #FAF5FF;
}

#tt-workspace .tt-time-input:focus {
  outline: none;
  border-color: #7C3AED;
  box-shadow: 0 0 0 3px rgba(124, 58, 237, 0.16);
}

#tt-workspace .tt-random-btn {
  flex: 1.15 1 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  border: none;
  border-radius: 12px;
  padding: 0.55rem 0.75rem;
  background: linear-gradient(135deg, #8B5CF6, #6D28D9);
  color: #FFFFFF;
  font-family: var(--font-th);
  font-size: 0.84rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(109, 40, 217, 0.25);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

#tt-workspace .tt-random-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 14px rgba(109, 40, 217, 0.32);
}

#tt-workspace .tt-random-btn:active {
  transform: translateY(0);
}

#tt-workspace .tt-preset-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.4rem;
}

#tt-workspace .tt-preset-btn {
  padding: 0.42rem 0.5rem;
  border-radius: 10px;
  border: 1.5px solid #E2E8F0;
  background: #F8FAFC;
  font-family: var(--font-en);
  font-size: 0.88rem;
  font-weight: 700;
  color: #334155;
  cursor: pointer;
  transition: all 0.15s ease;
}

#tt-workspace .tt-preset-btn:hover {
  border-color: #A78BFA;
  background: #FAF5FF;
  color: #6D28D9;
}

#tt-workspace .tt-preset-btn.active {
  border-color: #7C3AED;
  background: #F3E8FF;
  color: #5B21B6;
}

#tt-workspace .tt-format-group,
#tt-workspace .tt-mode-group {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

#tt-workspace .tt-radio-card,
#tt-workspace .tt-mode-option {
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
  padding: 0.65rem 0.75rem;
  border-radius: 12px;
  border: 1.8px solid #E2E8F0;
  background: #F8FAFC;
  cursor: pointer;
  transition: all 0.16s ease;
}

#tt-workspace .tt-radio-card:hover,
#tt-workspace .tt-mode-option:hover {
  border-color: #C4B5FD;
  background: #FAF5FF;
}

#tt-workspace .tt-radio-card:has(input:checked),
#tt-workspace .tt-mode-option:has(input:checked) {
  border-color: #7C3AED;
  background: #F3E8FF;
  box-shadow: 0 2px 8px rgba(124, 58, 237, 0.12);
}

#tt-workspace .tt-radio-card input,
#tt-workspace .tt-mode-option input {
  margin-top: 0.2rem;
  accent-color: #7C3AED;
}

#tt-workspace .tt-radio-body {
  display: flex;
  flex-direction: column;
  gap: 0.12rem;
  min-width: 0;
}

#tt-workspace .tt-radio-title {
  font-family: var(--font-th);
  font-size: 0.88rem;
  font-weight: 700;
  color: #1E293B;
}

#tt-workspace .tt-radio-example {
  font-family: var(--font-en), var(--font-th);
  font-size: 0.8rem;
  font-weight: 600;
  color: #6D28D9;
}

#tt-workspace .tt-mode-content {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  min-width: 0;
}

#tt-workspace .tt-mode-icon {
  font-size: 1rem;
  line-height: 1.2;
}

#tt-workspace .tt-mode-text {
  display: flex;
  flex-direction: column;
  gap: 0.12rem;
}

#tt-workspace .tt-mode-text strong {
  font-family: var(--font-th);
  font-size: 0.86rem;
  font-weight: 700;
  color: #1E293B;
}

#tt-workspace .tt-mode-text small {
  font-family: var(--font-th);
  font-size: 0.76rem;
  color: #475569;
  line-height: 1.3;
}

#tt-workspace .tt-lines-selector {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.45rem;
}

#tt-workspace .tt-line-option {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  border: 1.5px solid #E2E8F0;
  border-radius: 10px;
  padding: 0.48rem 0.5rem;
  background: #F8FAFC;
  font-family: var(--font-th);
  font-size: 0.82rem;
  font-weight: 700;
  color: #334155;
  cursor: pointer;
}

#tt-workspace .tt-line-option:has(input:checked) {
  border-color: #7C3AED;
  background: #F3E8FF;
  color: #5B21B6;
}

#tt-workspace .tt-student-checks {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.35rem 0.75rem;
}

#tt-workspace .tt-toolbar-actions {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  padding-top: 0.75rem;
  border-top: 1.5px solid #E2E8F0;
}

#tt-workspace .tt-action-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
}

#tt-workspace .tt-action-row > .btn-print-pdf,
#tt-workspace .tt-action-row > .tt-save-btn {
  min-width: 0;
  width: 100%;
  min-height: 44px;
  padding: 0.55rem 0.6rem;
  font-size: 0.84rem;
}

#tt-workspace .tt-save-btn,
#tt-workspace .tt-load-btn,
#tt-workspace .tt-modal-cancel,
#tt-workspace .tt-modal-confirm,
#tt-workspace .tt-project-load,
#tt-workspace .tt-project-delete {
  border: none;
  border-radius: 12px;
  font-family: var(--font-th);
  font-weight: 700;
  cursor: pointer;
}

#tt-workspace .tt-save-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  background: #7C3AED;
  color: #FFFFFF;
}

#tt-workspace .tt-load-btn {
  width: 100%;
  padding: 0.58rem 0.85rem;
  background: #F3E8FF;
  color: #5B21B6;
  font-size: 0.86rem;
}

#tt-workspace .tt-action-hint {
  font-family: var(--font-th);
  font-size: 0.76rem;
  color: #64748B;
  text-align: center;
}

/* A4 Worksheet Preview Sheet (#tt-workspace .tt-sheet) */
#tt-workspace .tt-preview-scroll {
  overflow-x: auto;
}

#tt-workspace .tt-pages {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
  width: max-content;
  max-width: 100%;
}

#tt-workspace .tt-sheet {
  width: 210mm;
  height: 297mm;
  max-width: none;
  flex: 0 0 auto;
  box-sizing: border-box;
  background: #FFFFFF;
  border-radius: 4px;
  box-shadow: 0 12px 40px rgba(15, 23, 42, 0.12);
  padding: 9mm 11mm 9mm;
  display: flex;
  flex-direction: column;
  gap: 3.5mm;
  color: #1E293B;
  position: relative;
  overflow: hidden;
}

#tt-workspace .tt-header {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  gap: 2.5mm;
  border-bottom: 2px solid #1E293B;
  padding-bottom: 2.5mm;
}

#tt-workspace .tt-header-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 3mm;
}

#tt-workspace .tt-header-main {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.8mm;
}

#tt-workspace .tt-logo-slot {
  flex: 0 0 16mm;
  width: 16mm;
  height: 16mm;
}

#tt-workspace .tt-header-logo {
  width: 16mm;
  height: 16mm;
  max-width: 16mm;
  max-height: 16mm;
  object-fit: contain;
  flex-shrink: 0;
  display: block;
}

#tt-workspace .tt-logo-slot[hidden] {
  display: none !important;
  width: 0 !important;
  height: 0 !important;
  margin: 0 !important;
  padding: 0 !important;
}

#tt-workspace .tt-title {
  margin: 0;
  font-family: var(--font-en), var(--font-th);
  font-size: 16pt;
  font-weight: 800;
  color: #0F172A;
  line-height: 1.15;
}

#tt-workspace .tt-instruction {
  margin: 0.8mm 0 0;
  font-family: var(--font-en), var(--font-th);
  font-size: 10.5pt;
  font-weight: 600;
  color: #475569;
  line-height: 1.25;
}

#tt-workspace .tt-student-meta {
  display: flex;
  align-items: flex-end;
  gap: 4mm;
  font-family: var(--font-en);
  font-size: 11pt;
  font-weight: 700;
  color: #1E293B;
}

#tt-workspace .tt-meta-field {
  display: flex;
  align-items: flex-end;
  gap: 1.5mm;
  min-width: 0;
}

#tt-workspace .tt-meta-name {
  flex: 2.2 1 0;
}

#tt-workspace .tt-meta-class {
  flex: 1 1 0;
}

#tt-workspace .tt-meta-date,
#tt-workspace .tt-meta-no {
  flex: 0.9 1 0;
}

#tt-workspace .tt-meta-label {
  white-space: nowrap;
}

#tt-workspace .tt-meta-line {
  flex: 1 1 auto;
  border-bottom: 1.5px solid #334155;
  height: 1.05em;
  min-width: 10mm;
}

#tt-workspace .tt-meta-custom {
  font-family: var(--font-th);
  font-size: 11pt;
  font-weight: 600;
  line-height: 1.35;
  white-space: pre-wrap;
  color: #1E293B;
}

/* Main Clock & Time Reading Stage on A4 */
#tt-workspace .tt-clock-card {
  width: 100%;
  flex: 1 1 auto;
  min-height: 105mm;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3mm;
  border: 2.2px solid #1E293B;
  border-radius: 4mm;
  background: #F8FAFC;
  padding: 5mm 6mm;
  box-sizing: border-box;
}

#tt-workspace .tt-clock-svg-wrap {
  width: 122mm;
  height: 122mm;
  max-width: 100%;
  max-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

#tt-workspace .tt-clock-svg {
  width: 100%;
  height: 100%;
  display: block;
  overflow: visible;
}

#tt-workspace .tt-clock-prompt-pill {
  display: inline-flex;
  align-items: center;
  gap: 2mm;
  padding: 1.5mm 4.5mm;
  border-radius: 999px;
  border: 1.5px dashed #64748B;
  background: #F8FAFC;
  font-family: var(--font-en), var(--font-th);
  font-size: 10.5pt;
  font-weight: 700;
  color: #334155;
}

/* Time Text Display Box below the clock */
#tt-workspace .tt-reading-panel {
  width: 100%;
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.5mm;
  padding: 3.5mm 5mm;
  border: 2px solid #1E293B;
  border-radius: 4mm;
  background: #F8FAFC;
  box-sizing: border-box;
  text-align: center;
}

#tt-workspace .tt-reading-panel.is-hidden-text {
  border-style: dashed;
  border-color: #64748B;
  background: #FFFFFF;
}

#tt-workspace .tt-reading-kicker {
  font-family: var(--font-en);
  font-size: 9.5pt;
  font-weight: 700;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  color: #64748B;
}

#tt-workspace .tt-reading-phrase {
  margin: 0;
  font-family: var(--font-en);
  font-size: 22pt;
  font-weight: 800;
  color: #0F172A;
  line-height: 1.2;
}

#tt-workspace .tt-reading-blank-line {
  width: 82%;
  height: 9mm;
  border-bottom: 2px dashed #475569;
  margin-top: 1mm;
}

/* 3-Line Handwriting Guidelines Section */
#tt-workspace .tt-writing-area {
  width: 100%;
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 4mm;
  padding-top: 1mm;
}

#tt-workspace .tt-writing-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-family: var(--font-en), var(--font-th);
  font-size: 10pt;
  font-weight: 700;
  color: #334155;
}

#tt-workspace .tt-sheet.tt-lines-2 .tt-writing-line {
  height: 16mm;
}

#tt-workspace .tt-sheet.tt-lines-3 .tt-writing-line {
  height: 14.5mm;
}

#tt-workspace .tt-sheet.tt-lines-4 .tt-writing-line {
  height: 13mm;
}

#tt-workspace .tt-writing-line {
  display: block;
  width: 100%;
}

#tt-workspace .tt-line-guides {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
}

#tt-workspace .tt-rule {
  position: absolute;
  left: 0;
  right: 0;
  display: block;
}

#tt-workspace .tt-rule-top {
  top: 0;
  border-top: 1.5px solid #334155;
}

#tt-workspace .tt-rule-mid {
  top: 50%;
  border-top: 1.3px dashed #64748B;
}

#tt-workspace .tt-rule-bottom {
  bottom: 0;
  border-top: 1.7px solid #0F172A;
}

#tt-workspace .tt-line-trace-text {
  position: relative;
  z-index: 1;
  padding-left: 3mm;
  font-family: var(--font-en);
  font-size: 19pt;
  font-weight: 600;
  letter-spacing: 0.8px;
  color: #CBD5E1;
  line-height: 1;
  user-select: none;
}

/* Project Save/Load Modal inside #tt-workspace */
#tt-workspace .tt-modal {
  position: fixed;
  inset: 0;
  z-index: 1200;
  background: rgba(15, 23, 42, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

#tt-workspace .tt-modal[hidden] {
  display: none !important;
}

#tt-workspace .tt-modal-card {
  width: min(460px, 100%);
  background: #FFFFFF;
  border-radius: 20px;
  padding: 1.35rem;
  box-shadow: 0 24px 60px rgba(15, 23, 42, 0.25);
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
}

#tt-workspace .tt-modal-title {
  margin: 0;
  font-family: var(--font-th);
  font-size: 1.15rem;
  color: #0F172A;
}

#tt-workspace .tt-project-list {
  max-height: 260px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

#tt-workspace .tt-project-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.65rem 0.75rem;
  border: 1px solid #E2E8F0;
  border-radius: 12px;
  background: #F8FAFC;
}

#tt-workspace .tt-project-name {
  margin: 0;
  font-family: var(--font-th);
  font-size: 0.9rem;
  font-weight: 700;
  color: #1E293B;
}

#tt-workspace .tt-project-meta,
#tt-workspace .tt-project-empty {
  margin: 0.15rem 0 0;
  font-family: var(--font-th);
  font-size: 0.76rem;
  color: #64748B;
}

#tt-workspace .tt-project-item-actions,
#tt-workspace .tt-modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.45rem;
}

#tt-workspace .tt-project-load,
#tt-workspace .tt-project-delete,
#tt-workspace .tt-modal-cancel,
#tt-workspace .tt-modal-confirm {
  padding: 0.45rem 0.85rem;
  font-size: 0.85rem;
}

#tt-workspace .tt-project-load,
#tt-workspace .tt-modal-confirm {
  color: #FFFFFF;
  background: #7C3AED;
}

#tt-workspace .tt-project-delete,
#tt-workspace .tt-modal-cancel {
  color: #475569;
  background: #F1F5F9;
}

/* ===================================================================
   WORD BANK LABELING WORKSHEET GENERATOR (#wb-workspace)
   =================================================================== */
#wb-workspace.wb-workspace {
  display: flex;
  gap: 1.5rem;
  align-items: flex-start;
  margin-top: 1rem;
  animation: pageFadeIn 0.35s ease-out forwards;
}

#wb-workspace .wb-badge {
  background: #CCFBF1;
  color: #0F766E;
}

#wb-workspace > .workspace-toolbar {
  overflow: hidden;
}

#wb-workspace > .workspace-toolbar > .toolbar-scrollable {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding-right: 0.2rem;
}

#wb-workspace .wb-student-checks {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.35rem 0.75rem;
}

#wb-workspace .wb-count-selector,
#wb-workspace .wb-bank-sort-selector {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.45rem;
}

#wb-workspace .wb-bank-sort-selector {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

#wb-workspace .wb-count-option,
#wb-workspace .wb-sort-option {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  padding: 0.55rem 0.4rem;
  border-radius: 12px;
  border: 2px solid #E2E8F0;
  background: #FFFFFF;
  color: #334155;
  font-family: var(--font-th);
  font-size: 0.84rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.16s ease;
  text-align: center;
}

#wb-workspace .wb-count-option:hover,
#wb-workspace .wb-sort-option:hover {
  border-color: #2DD4BF;
  background: #F0FDFA;
}

#wb-workspace .wb-count-option:has(input:checked),
#wb-workspace .wb-sort-option:has(input:checked) {
  border-color: #0D9488;
  background: #CCFBF1;
  color: #0F766E;
}

#wb-workspace .wb-count-option input,
#wb-workspace .wb-sort-option input {
  accent-color: #0D9488;
}

#wb-workspace .wb-selection-status {
  margin: 0.35rem 0 0.45rem;
  padding: 0.48rem 0.7rem;
  border-radius: 10px;
  font-family: var(--font-th);
  font-size: 0.8rem;
  font-weight: 700;
  line-height: 1.35;
  background: #F0FDFA;
  border: 1.5px solid #99F6E4;
  color: #0F766E;
}

#wb-workspace .wb-selection-status.is-warning {
  background: #FFFBEB;
  border-color: #FDE68A;
  color: #B45309;
}

#wb-workspace .wb-vocab-picker-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.45rem;
  max-height: 240px;
  overflow-y: auto;
  padding: 0.35rem;
  background: #FFFFFF;
  border: 1.5px solid #E2E8F0;
  border-radius: 12px;
}

#wb-workspace .wb-vocab-card-btn {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.15rem;
  padding: 0.45rem 0.35rem;
  border: 1.8px solid #E2E8F0;
  border-radius: 10px;
  background: #FAFCFF;
  cursor: pointer;
  text-align: center;
  transition: all 0.16s ease;
}

#wb-workspace .wb-vocab-card-btn:hover {
  border-color: #14B8A6;
  background: #F0FDFA;
  transform: translateY(-1px);
}

#wb-workspace .wb-vocab-card-btn.is-selected {
  border-color: #0D9488;
  background: #CCFBF1;
  box-shadow: 0 0 0 2px rgba(13, 148, 136, 0.18);
}

#wb-workspace .wb-vocab-card-thumb {
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
}

#wb-workspace .wb-vocab-thumb-img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  display: block;
}

#wb-workspace .wb-vocab-card-en {
  font-family: var(--font-en);
  font-size: 0.8rem;
  font-weight: 700;
  color: #1E293B;
  line-height: 1.15;
}

#wb-workspace .wb-vocab-card-th {
  font-family: var(--font-th);
  font-size: 0.72rem;
  color: #64748B;
  line-height: 1.15;
}

#wb-workspace .wb-vocab-state-badge {
  font-family: var(--font-th);
  font-size: 0.66rem;
  font-weight: 700;
  color: #0F766E;
  background: #E6FFFA;
  padding: 1px 6px;
  border-radius: 999px;
  margin-top: 2px;
}

#wb-workspace .wb-vocab-card-btn.is-selected .wb-vocab-state-badge {
  color: #FFFFFF;
  background: #0D9488;
}

#wb-workspace .wb-order-controls {
  margin-top: 0.65rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

#wb-workspace .wb-shuffle-btn {
  width: 100%;
  padding: 0.58rem 0.75rem;
  border-radius: 12px;
  border: 1.8px solid #14B8A6;
  background: #F0FDFA;
  color: #0F766E;
  font-family: var(--font-th);
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.16s ease;
}

#wb-workspace .wb-shuffle-btn:hover {
  background: #CCFBF1;
  border-color: #0D9488;
}

#wb-workspace .wb-answer-style-group {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

#wb-workspace .wb-style-card {
  display: flex;
  align-items: flex-start;
  gap: 0.55rem;
  padding: 0.65rem 0.75rem;
  border-radius: 12px;
  border: 2px solid #E2E8F0;
  background: #FFFFFF;
  cursor: pointer;
  transition: all 0.16s ease;
}

#wb-workspace .wb-style-card:hover {
  border-color: #2DD4BF;
  background: #F0FDFA;
}

#wb-workspace .wb-style-card:has(input:checked) {
  border-color: #0D9488;
  background: #F0FDFA;
  box-shadow: 0 0 0 2px rgba(13, 148, 136, 0.14);
}

#wb-workspace .wb-style-card input {
  margin-top: 0.2rem;
  accent-color: #0D9488;
}

#wb-workspace .wb-style-content {
  display: flex;
  align-items: flex-start;
  gap: 0.45rem;
  min-width: 0;
}

#wb-workspace .wb-style-icon {
  font-size: 1.1rem;
  line-height: 1.2;
}

#wb-workspace .wb-style-text {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}

#wb-workspace .wb-style-text strong {
  font-family: var(--font-th);
  font-size: 0.88rem;
  color: #0F172A;
}

#wb-workspace .wb-style-text small {
  font-family: var(--font-th);
  font-size: 0.75rem;
  color: #64748B;
}

#wb-workspace .wb-toolbar-actions {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  padding-top: 0.55rem;
  border-top: 1.5px solid #E2E8F0;
}

#wb-workspace .wb-action-row {
  display: flex;
  gap: 0.45rem;
}

#wb-workspace .wb-action-row > .btn-print-pdf,
#wb-workspace .wb-action-row > .wb-save-btn {
  flex: 1 1 0;
  min-width: 0;
  margin: 0;
  padding: 0.65rem 0.6rem;
  font-size: 0.86rem;
}

#wb-workspace .wb-save-btn,
#wb-workspace .wb-load-btn,
#wb-workspace .wb-modal-cancel,
#wb-workspace .wb-modal-confirm,
#wb-workspace .wb-project-load,
#wb-workspace .wb-project-delete {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  border-radius: 12px;
  font-family: var(--font-th);
  font-weight: 700;
  cursor: pointer;
  border: none;
  transition: all 0.18s ease;
}

#wb-workspace .wb-save-btn {
  background: #0D9488;
  color: #FFFFFF;
  box-shadow: 0 4px 12px rgba(13, 148, 136, 0.25);
}

#wb-workspace .wb-load-btn {
  width: 100%;
  padding: 0.55rem 0.75rem;
  font-size: 0.84rem;
  background: #F1F5F9;
  color: #334155;
  border: 1.5px solid #CBD5E1;
}

#wb-workspace .wb-action-hint {
  font-family: var(--font-th);
  font-size: 0.76rem;
  color: #64748B;
  text-align: center;
}

/* A4 Worksheet Preview Sheet (#wb-workspace .wb-sheet) */
#wb-workspace .wb-preview-scroll {
  overflow-x: auto;
}

#wb-workspace .wb-pages {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
  width: max-content;
  max-width: 100%;
}

#wb-workspace .wb-sheet {
  width: 210mm;
  height: 297mm;
  max-width: none;
  flex: 0 0 auto;
  box-sizing: border-box;
  background: #FFFFFF;
  border-radius: 4px;
  box-shadow: 0 12px 40px rgba(15, 23, 42, 0.12);
  padding: 9mm 11mm 9mm;
  display: flex;
  flex-direction: column;
  gap: 3.5mm;
  color: #1E293B;
  position: relative;
  overflow: hidden;
}

#wb-workspace .wb-header {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  gap: 2.5mm;
  border-bottom: 2px solid #1E293B;
  padding-bottom: 2.5mm;
}

#wb-workspace .wb-header-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 3mm;
}

#wb-workspace .wb-header-main {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.8mm;
}

#wb-workspace .wb-logo-slot {
  flex: 0 0 16mm;
  width: 16mm;
  height: 16mm;
}

#wb-workspace .wb-header-logo {
  width: 16mm;
  height: 16mm;
  max-width: 16mm;
  max-height: 16mm;
  object-fit: contain;
  flex-shrink: 0;
  display: block;
}

#wb-workspace .wb-logo-slot[hidden] {
  display: none !important;
  width: 0 !important;
  height: 0 !important;
  margin: 0 !important;
  padding: 0 !important;
}

#wb-workspace .wb-title {
  margin: 0;
  font-family: var(--font-en), var(--font-th);
  font-size: 16pt;
  font-weight: 800;
  color: #0F172A;
  line-height: 1.15;
}

#wb-workspace .wb-instruction {
  margin: 0.8mm 0 0;
  font-family: var(--font-en), var(--font-th);
  font-size: 10.5pt;
  font-weight: 600;
  color: #475569;
  line-height: 1.25;
}

#wb-workspace .wb-student-meta {
  display: flex;
  align-items: flex-end;
  gap: 4mm;
  font-family: var(--font-en);
  font-size: 11pt;
  font-weight: 700;
  color: #1E293B;
}

#wb-workspace .wb-meta-field {
  display: flex;
  align-items: flex-end;
  gap: 1.5mm;
  min-width: 0;
}

#wb-workspace .wb-meta-name {
  flex: 2.2 1 0;
}

#wb-workspace .wb-meta-class {
  flex: 1 1 0;
}

#wb-workspace .wb-meta-date,
#wb-workspace .wb-meta-no {
  flex: 0.9 1 0;
}

#wb-workspace .wb-meta-label {
  white-space: nowrap;
}

#wb-workspace .wb-meta-line {
  flex: 1 1 auto;
  border-bottom: 1.5px solid #334155;
  height: 1.05em;
  min-width: 10mm;
}

#wb-workspace .wb-meta-custom {
  font-family: var(--font-th);
  font-size: 11pt;
  font-weight: 600;
  line-height: 1.35;
  white-space: pre-wrap;
  color: #1E293B;
}

/* Word Bank Area Box */
#wb-workspace .wb-wordbank-box {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  gap: 2mm;
  padding: 2.8mm 4mm 3.2mm;
  border: 2px solid #0F172A;
  border-radius: 3mm;
  background: #F8FAFC;
}

#wb-workspace .wb-wordbank-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 2mm;
}

#wb-workspace .wb-wordbank-title {
  font-family: var(--font-en);
  font-size: 10.5pt;
  font-weight: 800;
  color: #0F172A;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

#wb-workspace .wb-wordbank-chips {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 2.2mm 3.2mm;
}

#wb-workspace .wb-wordbank-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-en);
  font-size: 12pt;
  font-weight: 700;
  color: #0F172A;
  background: #FFFFFF;
  border: 1.5px solid #334155;
  border-radius: 2mm;
  padding: 1mm 4mm;
  min-width: 24mm;
  text-align: center;
}

/* Matching Picture Grid (2x2 for 4, 2x3 for 6, 2x4 for 8) */
#wb-workspace .wb-matching-grid {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 3.5mm 5mm;
  align-content: stretch;
}

#wb-workspace .wb-matching-grid.wb-grid-4 {
  grid-template-rows: repeat(2, minmax(0, 1fr));
  gap: 5mm 6mm;
}

#wb-workspace .wb-matching-grid.wb-grid-6 {
  grid-template-rows: repeat(3, minmax(0, 1fr));
  gap: 3.8mm 5mm;
}

#wb-workspace .wb-matching-grid.wb-grid-8 {
  grid-template-rows: repeat(4, minmax(0, 1fr));
  gap: 2.8mm 4.5mm;
}

#wb-workspace .wb-item-card {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  padding: 2.5mm 3.5mm 3mm;
  border: 1.6px solid #CBD5E1;
  border-radius: 3mm;
  background: #FFFFFF;
  min-height: 0;
  box-sizing: border-box;
  overflow: hidden;
}

#wb-workspace .wb-item-number {
  position: absolute;
  top: 2mm;
  left: 2.5mm;
  width: 6mm;
  height: 6mm;
  border-radius: 999px;
  background: #F1F5F9;
  border: 1.2px solid #475569;
  color: #0F172A;
  font-family: var(--font-en);
  font-size: 9pt;
  font-weight: 800;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

#wb-workspace .wb-item-image-wrap {
  flex: 1 1 auto;
  width: 100%;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1mm 2mm;
  box-sizing: border-box;
}

#wb-workspace .wb-matching-grid.wb-grid-4 .wb-item-image {
  max-height: 56mm;
}

#wb-workspace .wb-matching-grid.wb-grid-6 .wb-item-image {
  max-height: 36mm;
}

#wb-workspace .wb-matching-grid.wb-grid-8 .wb-item-image {
  max-height: 25mm;
}

#wb-workspace .wb-item-image {
  max-width: 88%;
  width: auto;
  height: 100%;
  object-fit: contain;
  display: block;
}

/* Answer Area Under Each Picture */
#wb-workspace .wb-answer-slot {
  flex: 0 0 auto;
  width: 100%;
  margin-top: 1.5mm;
  box-sizing: border-box;
}

/* Style 1: Empty Box */
#wb-workspace .wb-answer-box {
  width: 100%;
  height: 11.5mm;
  border: 1.8px solid #1E293B;
  border-radius: 2mm;
  background: #FFFFFF;
  box-sizing: border-box;
}

#wb-workspace .wb-matching-grid.wb-grid-4 .wb-answer-box {
  height: 13.5mm;
}

#wb-workspace .wb-matching-grid.wb-grid-8 .wb-answer-box {
  height: 10mm;
}

/* Style 2: 3 Primary Handwriting Lines (Solid / Dashed / Solid) */
#wb-workspace .wb-writing-line {
  display: block;
  width: 100%;
  height: 11.5mm;
}

#wb-workspace .wb-matching-grid.wb-grid-4 .wb-writing-line {
  height: 13.5mm;
}

#wb-workspace .wb-matching-grid.wb-grid-8 .wb-writing-line {
  height: 10mm;
}

#wb-workspace .wb-line-guides {
  position: relative;
  width: 100%;
  height: 100%;
}

#wb-workspace .wb-rule {
  position: absolute;
  left: 0;
  right: 0;
  display: block;
}

#wb-workspace .wb-rule-top {
  top: 0;
  border-top: 1.4px solid #334155;
}

#wb-workspace .wb-rule-mid {
  top: 50%;
  border-top: 1.2px dashed #64748B;
}

#wb-workspace .wb-rule-bottom {
  bottom: 0;
  border-top: 1.6px solid #0F172A;
}

/* Project Save/Load Modal inside #wb-workspace */
#wb-workspace .wb-modal {
  position: fixed;
  inset: 0;
  z-index: 1200;
  background: rgba(15, 23, 42, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

#wb-workspace .wb-modal[hidden] {
  display: none !important;
}

#wb-workspace .wb-modal-card {
  width: min(440px, 100%);
  background: #FFFFFF;
  border-radius: 20px;
  padding: 1.35rem;
  box-shadow: 0 20px 48px rgba(15, 23, 42, 0.22);
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

#wb-workspace .wb-modal-title {
  margin: 0;
  font-family: var(--font-th);
  font-size: 1.2rem;
  color: #0F172A;
}

#wb-workspace .wb-project-list {
  max-height: 240px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

#wb-workspace .wb-project-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.65rem 0.75rem;
  border: 1.5px solid #E2E8F0;
  border-radius: 12px;
  background: #F8FAFC;
}

#wb-workspace .wb-project-name {
  margin: 0;
  font-family: var(--font-th);
  font-size: 0.92rem;
  font-weight: 700;
  color: #1E293B;
}

#wb-workspace .wb-project-meta,
#wb-workspace .wb-project-empty {
  margin: 0;
  font-family: var(--font-th);
  font-size: 0.78rem;
  color: #64748B;
}

#wb-workspace .wb-project-item-actions,
#wb-workspace .wb-modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.45rem;
}

#wb-workspace .wb-project-load,
#wb-workspace .wb-project-delete,
#wb-workspace .wb-modal-cancel,
#wb-workspace .wb-modal-confirm {
  padding: 0.45rem 0.85rem;
  font-size: 0.85rem;
}

#wb-workspace .wb-project-load,
#wb-workspace .wb-modal-confirm {
  color: #FFFFFF;
  background: #0D9488;
}

#wb-workspace .wb-project-delete,
#wb-workspace .wb-modal-cancel {
  color: #475569;
  background: #F1F5F9;
}

/* ===================================================================
   WORD UNSCRAMBLE WORKSHEET GENERATOR (#wu-workspace)
   =================================================================== */
#wu-workspace.wu-workspace {
  display: flex;
  gap: 1.5rem;
  align-items: flex-start;
  margin-top: 1rem;
  animation: pageFadeIn 0.35s ease-out forwards;
}

#wu-workspace .wu-badge {
  background: #E0E7FF;
  color: #3730A3;
}

#wu-workspace > .workspace-toolbar {
  overflow: hidden;
}

#wu-workspace > .workspace-toolbar > .toolbar-scrollable {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding-right: 0.2rem;
}

#wu-workspace .wu-student-checks {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.35rem 0.75rem;
}

#wu-workspace .wu-count-selector {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.45rem;
}

#wu-workspace .wu-count-option {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  padding: 0.55rem 0.4rem;
  border-radius: 12px;
  border: 2px solid #E2E8F0;
  background: #FFFFFF;
  color: #334155;
  font-family: var(--font-th);
  font-size: 0.84rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.16s ease;
  text-align: center;
}

#wu-workspace .wu-count-option:hover {
  border-color: #818CF8;
  background: #EEF2FF;
}

#wu-workspace .wu-count-option:has(input:checked) {
  border-color: #4F46E5;
  background: #E0E7FF;
  color: #3730A3;
}

#wu-workspace .wu-count-option input {
  accent-color: #4F46E5;
}

#wu-workspace .wu-selection-status {
  margin: 0.35rem 0 0.45rem;
  padding: 0.48rem 0.7rem;
  border-radius: 10px;
  font-family: var(--font-th);
  font-size: 0.8rem;
  font-weight: 700;
  line-height: 1.35;
  background: #EEF2FF;
  border: 1.5px solid #C7D2FE;
  color: #3730A3;
}

#wu-workspace .wu-selection-status.is-warning {
  background: #FFFBEB;
  border-color: #FDE68A;
  color: #B45309;
}

#wu-workspace .wu-vocab-picker-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.45rem;
  max-height: 240px;
  overflow-y: auto;
  padding: 0.35rem;
  background: #FFFFFF;
  border: 1.5px solid #E2E8F0;
  border-radius: 12px;
}

#wu-workspace .wu-vocab-card-btn {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.15rem;
  padding: 0.45rem 0.35rem;
  border: 1.8px solid #E2E8F0;
  border-radius: 10px;
  background: #FAFCFF;
  cursor: pointer;
  text-align: center;
  transition: all 0.16s ease;
}

#wu-workspace .wu-vocab-card-btn:hover {
  border-color: #6366F1;
  background: #EEF2FF;
  transform: translateY(-1px);
}

#wu-workspace .wu-vocab-card-btn.is-selected {
  border-color: #4F46E5;
  background: #E0E7FF;
  box-shadow: 0 0 0 2px rgba(79, 70, 229, 0.18);
}

#wu-workspace .wu-vocab-card-thumb {
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
}

#wu-workspace .wu-vocab-thumb-img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  display: block;
}

#wu-workspace .wu-vocab-card-en {
  font-family: var(--font-en);
  font-size: 0.8rem;
  font-weight: 700;
  color: #1E293B;
  line-height: 1.15;
}

#wu-workspace .wu-vocab-card-th {
  font-family: var(--font-th);
  font-size: 0.72rem;
  color: #64748B;
  line-height: 1.15;
}

#wu-workspace .wu-vocab-state-badge {
  font-family: var(--font-th);
  font-size: 0.66rem;
  font-weight: 700;
  color: #3730A3;
  background: #EEF2FF;
  padding: 1px 6px;
  border-radius: 999px;
  margin-top: 2px;
}

#wu-workspace .wu-vocab-card-btn.is-selected .wu-vocab-state-badge {
  color: #FFFFFF;
  background: #4F46E5;
}

#wu-workspace .wu-order-controls {
  margin-top: 0.65rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

#wu-workspace .wu-rescramble-btn {
  width: 100%;
  padding: 0.58rem 0.75rem;
  border-radius: 12px;
  border: 1.8px solid #6366F1;
  background: #EEF2FF;
  color: #3730A3;
  font-family: var(--font-th);
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.16s ease;
}

#wu-workspace .wu-rescramble-btn:hover {
  background: #E0E7FF;
  border-color: #4F46E5;
}

#wu-workspace .wu-answer-style-group {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

#wu-workspace .wu-style-card {
  display: flex;
  align-items: flex-start;
  gap: 0.55rem;
  padding: 0.65rem 0.75rem;
  border-radius: 12px;
  border: 2px solid #E2E8F0;
  background: #FFFFFF;
  cursor: pointer;
  transition: all 0.16s ease;
}

#wu-workspace .wu-style-card:hover {
  border-color: #818CF8;
  background: #EEF2FF;
}

#wu-workspace .wu-style-card:has(input:checked) {
  border-color: #4F46E5;
  background: #EEF2FF;
  box-shadow: 0 0 0 2px rgba(79, 70, 229, 0.14);
}

#wu-workspace .wu-style-card input {
  margin-top: 0.2rem;
  accent-color: #4F46E5;
}

#wu-workspace .wu-style-content {
  display: flex;
  align-items: flex-start;
  gap: 0.45rem;
  min-width: 0;
}

#wu-workspace .wu-style-icon {
  font-size: 1.1rem;
  line-height: 1.2;
}

#wu-workspace .wu-style-text {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}

#wu-workspace .wu-style-text strong {
  font-family: var(--font-th);
  font-size: 0.88rem;
  color: #0F172A;
}

#wu-workspace .wu-style-text small {
  font-family: var(--font-th);
  font-size: 0.75rem;
  color: #64748B;
}

#wu-workspace .wu-toolbar-actions {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  padding-top: 0.55rem;
  border-top: 1.5px solid #E2E8F0;
}

#wu-workspace .wu-action-row {
  display: flex;
  gap: 0.45rem;
}

#wu-workspace .wu-action-row > .btn-print-pdf,
#wu-workspace .wu-action-row > .wu-save-btn {
  flex: 1 1 0;
  min-width: 0;
  margin: 0;
  padding: 0.65rem 0.6rem;
  font-size: 0.86rem;
}

#wu-workspace .wu-save-btn,
#wu-workspace .wu-load-btn,
#wu-workspace .wu-modal-cancel,
#wu-workspace .wu-modal-confirm,
#wu-workspace .wu-project-load,
#wu-workspace .wu-project-delete {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  border-radius: 12px;
  font-family: var(--font-th);
  font-weight: 700;
  cursor: pointer;
  border: none;
  transition: all 0.18s ease;
}

#wu-workspace .wu-save-btn {
  background: #4F46E5;
  color: #FFFFFF;
  box-shadow: 0 4px 12px rgba(79, 70, 229, 0.25);
}

#wu-workspace .wu-load-btn {
  width: 100%;
  padding: 0.55rem 0.75rem;
  font-size: 0.84rem;
  background: #F1F5F9;
  color: #334155;
  border: 1.5px solid #CBD5E1;
}

#wu-workspace .wu-action-hint {
  font-family: var(--font-th);
  font-size: 0.76rem;
  color: #64748B;
  text-align: center;
}

/* A4 Worksheet Preview Sheet (#wu-workspace .wu-sheet) */
#wu-workspace .wu-preview-scroll {
  overflow-x: auto;
}

#wu-workspace .wu-pages {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
  width: max-content;
  max-width: 100%;
}

#wu-workspace .wu-sheet {
  width: 210mm;
  height: 297mm;
  max-width: none;
  flex: 0 0 auto;
  box-sizing: border-box;
  background: #FFFFFF;
  border-radius: 4px;
  box-shadow: 0 12px 40px rgba(15, 23, 42, 0.12);
  padding: 9mm 11mm 9mm;
  display: flex;
  flex-direction: column;
  gap: 4mm;
  color: #1E293B;
  position: relative;
  overflow: hidden;
}

#wu-workspace .wu-header {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  gap: 2.5mm;
  border-bottom: 2px solid #1E293B;
  padding-bottom: 2.5mm;
}

#wu-workspace .wu-header-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 3mm;
}

#wu-workspace .wu-header-main {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.8mm;
}

#wu-workspace .wu-logo-slot {
  flex: 0 0 16mm;
  width: 16mm;
  height: 16mm;
}

#wu-workspace .wu-header-logo {
  width: 16mm;
  height: 16mm;
  max-width: 16mm;
  max-height: 16mm;
  object-fit: contain;
  flex-shrink: 0;
  display: block;
}

#wu-workspace .wu-logo-slot[hidden] {
  display: none !important;
  width: 0 !important;
  height: 0 !important;
  margin: 0 !important;
  padding: 0 !important;
}

#wu-workspace .wu-title {
  margin: 0;
  font-family: var(--font-en), var(--font-th);
  font-size: 16pt;
  font-weight: 800;
  color: #0F172A;
  line-height: 1.15;
}

#wu-workspace .wu-instruction {
  margin: 0.8mm 0 0;
  font-family: var(--font-en), var(--font-th);
  font-size: 10.5pt;
  font-weight: 600;
  color: #475569;
  line-height: 1.25;
}

#wu-workspace .wu-student-meta {
  display: flex;
  align-items: flex-end;
  gap: 4mm;
  font-family: var(--font-en);
  font-size: 11pt;
  font-weight: 700;
  color: #1E293B;
}

#wu-workspace .wu-meta-field {
  display: flex;
  align-items: flex-end;
  gap: 1.5mm;
  min-width: 0;
}

#wu-workspace .wu-meta-name {
  flex: 2.2 1 0;
}

#wu-workspace .wu-meta-class {
  flex: 1 1 0;
}

#wu-workspace .wu-meta-date,
#wu-workspace .wu-meta-no {
  flex: 0.9 1 0;
}

#wu-workspace .wu-meta-label {
  white-space: nowrap;
}

#wu-workspace .wu-meta-line {
  flex: 1 1 auto;
  border-bottom: 1.5px solid #334155;
  height: 1.05em;
  min-width: 10mm;
}

#wu-workspace .wu-meta-custom {
  font-family: var(--font-th);
  font-size: 11pt;
  font-weight: 600;
  line-height: 1.35;
  white-space: pre-wrap;
  color: #1E293B;
}

/* Unscramble Rows List (5, 6 or 8 items per A4 page) */
#wu-workspace .wu-list {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: 1fr;
  align-content: stretch;
  gap: 3.5mm;
}

#wu-workspace .wu-list.wu-list-5 {
  grid-template-rows: repeat(5, minmax(0, 1fr));
  gap: 4.5mm;
}

#wu-workspace .wu-list.wu-list-6 {
  grid-template-rows: repeat(6, minmax(0, 1fr));
  gap: 3.6mm;
}

#wu-workspace .wu-list.wu-list-8 {
  grid-template-rows: repeat(8, minmax(0, 1fr));
  gap: 2.5mm;
}

#wu-workspace .wu-row {
  display: grid;
  grid-template-columns: 36mm minmax(46mm, 1fr) minmax(64mm, 1.25fr);
  align-items: center;
  gap: 4mm;
  padding: 2mm 4mm;
  border: 1.6px solid #CBD5E1;
  border-radius: 3mm;
  background: #FFFFFF;
  min-height: 0;
  box-sizing: border-box;
  overflow: hidden;
}

#wu-workspace .wu-list.wu-list-8 .wu-row {
  grid-template-columns: 31mm minmax(44mm, 1fr) minmax(62mm, 1.25fr);
  padding: 1.5mm 3.5mm;
  gap: 3.5mm;
}

/* Left: Item Number + Vocabulary Picture */
#wu-workspace .wu-col-left {
  display: flex;
  align-items: center;
  gap: 2.5mm;
  height: 100%;
  min-height: 0;
}

#wu-workspace .wu-item-number {
  flex: 0 0 6.5mm;
  width: 6.5mm;
  height: 6.5mm;
  border-radius: 999px;
  background: #F1F5F9;
  border: 1.2px solid #475569;
  color: #0F172A;
  font-family: var(--font-en);
  font-size: 9.5pt;
  font-weight: 800;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

#wu-workspace .wu-image-wrap {
  flex: 1 1 auto;
  height: 100%;
  min-width: 0;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

#wu-workspace .wu-item-image {
  max-width: 100%;
  width: auto;
  height: 100%;
  object-fit: contain;
  display: block;
}

#wu-workspace .wu-list.wu-list-5 .wu-item-image {
  max-height: 34mm;
}

#wu-workspace .wu-list.wu-list-6 .wu-item-image {
  max-height: 28mm;
}

#wu-workspace .wu-list.wu-list-8 .wu-item-image {
  max-height: 20mm;
}

/* Middle: Scrambled Word Display */
#wu-workspace .wu-col-middle {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  padding: 1.5mm 3mm;
  background: #F8FAFC;
  border: 1.4px dashed #94A3B8;
  border-radius: 2.5mm;
  box-sizing: border-box;
}

#wu-workspace .wu-scrambled-word {
  font-family: var(--font-en);
  font-size: 16.5pt;
  font-weight: 800;
  letter-spacing: 0.22em;
  padding-left: 0.22em;
  color: #0F172A;
  text-align: center;
  line-height: 1.2;
  word-break: break-word;
}

#wu-workspace .wu-list.wu-list-5 .wu-scrambled-word {
  font-size: 18pt;
  letter-spacing: 0.24em;
  padding-left: 0.24em;
}

#wu-workspace .wu-list.wu-list-8 .wu-scrambled-word {
  font-size: 14.5pt;
  letter-spacing: 0.2em;
  padding-left: 0.2em;
}

/* Right: Answer Writing Space */
#wu-workspace .wu-col-right {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  min-width: 0;
  box-sizing: border-box;
}

/* Style 1: 3 Primary Handwriting Lines (Solid / Dashed / Solid) */
#wu-workspace .wu-primary-lines {
  position: relative;
  width: 100%;
  height: 13mm;
}

#wu-workspace .wu-list.wu-list-5 .wu-primary-lines {
  height: 15mm;
}

#wu-workspace .wu-list.wu-list-8 .wu-primary-lines {
  height: 10.5mm;
}

#wu-workspace .wu-rule {
  position: absolute;
  left: 0;
  right: 0;
  display: block;
}

#wu-workspace .wu-rule-top {
  top: 0;
  border-top: 1.4px solid #334155;
}

#wu-workspace .wu-rule-mid {
  top: 50%;
  border-top: 1.2px dashed #64748B;
}

#wu-workspace .wu-rule-bottom {
  bottom: 0;
  border-top: 1.6px solid #0F172A;
}

/* Style 2: Single Writing Line */
#wu-workspace .wu-single-line-wrap {
  width: 100%;
  height: 12mm;
  display: flex;
  align-items: flex-end;
  padding-bottom: 1.5mm;
  box-sizing: border-box;
}

#wu-workspace .wu-list.wu-list-8 .wu-single-line-wrap {
  height: 9.5mm;
}

#wu-workspace .wu-single-line {
  display: block;
  width: 100%;
  border-bottom: 1.8px solid #0F172A;
}

/* Project Save/Load Modal inside #wu-workspace */
#wu-workspace .wu-modal {
  position: fixed;
  inset: 0;
  z-index: 1200;
  background: rgba(15, 23, 42, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

#wu-workspace .wu-modal[hidden] {
  display: none !important;
}

#wu-workspace .wu-modal-card {
  width: min(440px, 100%);
  background: #FFFFFF;
  border-radius: 20px;
  padding: 1.35rem;
  box-shadow: 0 20px 48px rgba(15, 23, 42, 0.22);
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

#wu-workspace .wu-modal-title {
  margin: 0;
  font-family: var(--font-th);
  font-size: 1.2rem;
  color: #0F172A;
}

#wu-workspace .wu-project-list {
  max-height: 240px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

#wu-workspace .wu-project-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.65rem 0.75rem;
  border: 1.5px solid #E2E8F0;
  border-radius: 12px;
  background: #F8FAFC;
}

#wu-workspace .wu-project-name {
  margin: 0;
  font-family: var(--font-th);
  font-size: 0.92rem;
  font-weight: 700;
  color: #1E293B;
}

#wu-workspace .wu-project-meta,
#wu-workspace .wu-project-empty {
  margin: 0;
  font-family: var(--font-th);
  font-size: 0.78rem;
  color: #64748B;
}

#wu-workspace .wu-project-item-actions,
#wu-workspace .wu-modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.45rem;
}

#wu-workspace .wu-project-load,
#wu-workspace .wu-project-delete,
#wu-workspace .wu-modal-cancel,
#wu-workspace .wu-modal-confirm {
  padding: 0.45rem 0.85rem;
  font-size: 0.85rem;
}

#wu-workspace .wu-project-load,
#wu-workspace .wu-modal-confirm {
  color: #FFFFFF;
  background: #4F46E5;
}

#wu-workspace .wu-project-delete,
#wu-workspace .wu-modal-cancel {
  color: #475569;
  background: #F1F5F9;
}

/* ===================================================================
   WORD SORTING WORKSHEET GENERATOR (#wst-workspace)
   =================================================================== */
#wst-workspace.wst-workspace {
  display: flex;
  gap: 1.5rem;
  align-items: flex-start;
  margin-top: 1rem;
  animation: pageFadeIn 0.35s ease-out forwards;
}

#wst-workspace .wst-badge {
  background: #FEF3C7;
  color: #92400E;
}

#wst-workspace > .workspace-toolbar {
  overflow: hidden;
}

#wst-workspace > .workspace-toolbar > .toolbar-scrollable {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding-right: 0.2rem;
}

#wst-workspace .wst-student-checks {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.35rem 0.75rem;
}

#wst-workspace .wst-cat-count-selector {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.45rem;
}

#wst-workspace .wst-count-selector {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.45rem;
}

#wst-workspace .wst-count-option {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  padding: 0.55rem 0.4rem;
  border-radius: 12px;
  border: 2px solid #E2E8F0;
  background: #FFFFFF;
  color: #334155;
  font-family: var(--font-th);
  font-size: 0.84rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.16s ease;
  text-align: center;
}

#wst-workspace .wst-count-option:hover {
  border-color: #F59E0B;
  background: #FFFBEB;
}

#wst-workspace .wst-count-option:has(input:checked) {
  border-color: #D97706;
  background: #FEF3C7;
  color: #92400E;
}

#wst-workspace .wst-count-option input {
  accent-color: #D97706;
}

#wst-workspace .wst-selection-status {
  margin: 0.35rem 0 0.45rem;
  padding: 0.48rem 0.7rem;
  border-radius: 10px;
  font-family: var(--font-th);
  font-size: 0.8rem;
  font-weight: 700;
  line-height: 1.35;
  background: #ECFDF5;
  border: 1.5px solid #A7F3D0;
  color: #065F46;
}

#wst-workspace .wst-selection-status.is-warning {
  background: #FFFBEB;
  border-color: #FDE68A;
  color: #B45309;
}

#wst-workspace .wst-vocab-picker-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.45rem;
  max-height: 240px;
  overflow-y: auto;
  padding: 0.35rem;
  background: #FFFFFF;
  border: 1.5px solid #E2E8F0;
  border-radius: 12px;
}

#wst-workspace .wst-vocab-card-btn {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.15rem;
  padding: 0.45rem 0.35rem;
  border: 1.8px solid #E2E8F0;
  border-radius: 10px;
  background: #FAFCFF;
  cursor: pointer;
  text-align: center;
  transition: all 0.16s ease;
}

#wst-workspace .wst-vocab-card-btn:hover {
  border-color: #F59E0B;
  background: #FFFBEB;
  transform: translateY(-1px);
}

#wst-workspace .wst-vocab-card-btn.is-selected {
  border-color: #D97706;
  background: #FEF3C7;
  box-shadow: 0 0 0 2px rgba(217, 119, 6, 0.18);
}

#wst-workspace .wst-vocab-card-thumb {
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
}

#wst-workspace .wst-vocab-thumb-img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  display: block;
}

#wst-workspace .wst-vocab-card-en {
  font-family: var(--font-en);
  font-size: 0.8rem;
  font-weight: 700;
  color: #1E293B;
  line-height: 1.15;
}

#wst-workspace .wst-vocab-card-th {
  font-family: var(--font-th);
  font-size: 0.72rem;
  color: #64748B;
  line-height: 1.15;
}

#wst-workspace .wst-vocab-state-badge {
  font-family: var(--font-th);
  font-size: 0.66rem;
  font-weight: 700;
  color: #92400E;
  background: #FFFBEB;
  padding: 1px 6px;
  border-radius: 999px;
  margin-top: 2px;
}

#wst-workspace .wst-vocab-card-btn.is-selected .wst-vocab-state-badge {
  color: #FFFFFF;
  background: #D97706;
}

#wst-workspace .wst-order-controls {
  margin-top: 0.65rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

#wst-workspace .wst-shuffle-btn {
  width: 100%;
  padding: 0.58rem 0.75rem;
  border-radius: 12px;
  border: 1.8px solid #F59E0B;
  background: #FFFBEB;
  color: #92400E;
  font-family: var(--font-th);
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.16s ease;
}

#wst-workspace .wst-shuffle-btn:hover {
  background: #FEF3C7;
  border-color: #D97706;
}

#wst-workspace .wst-activity-style-group {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

#wst-workspace .wst-style-card {
  display: flex;
  align-items: flex-start;
  gap: 0.55rem;
  padding: 0.65rem 0.75rem;
  border-radius: 12px;
  border: 2px solid #E2E8F0;
  background: #FFFFFF;
  cursor: pointer;
  transition: all 0.16s ease;
}

#wst-workspace .wst-style-card:hover {
  border-color: #F59E0B;
  background: #FFFBEB;
}

#wst-workspace .wst-style-card:has(input:checked) {
  border-color: #D97706;
  background: #FFFBEB;
  box-shadow: 0 0 0 2px rgba(217, 119, 6, 0.14);
}

#wst-workspace .wst-style-card input {
  margin-top: 0.2rem;
  accent-color: #D97706;
}

#wst-workspace .wst-style-content {
  display: flex;
  align-items: flex-start;
  gap: 0.45rem;
  min-width: 0;
}

#wst-workspace .wst-style-icon {
  font-size: 1.1rem;
  line-height: 1.2;
}

#wst-workspace .wst-style-text {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}

#wst-workspace .wst-style-text strong {
  font-family: var(--font-th);
  font-size: 0.88rem;
  color: #0F172A;
}

#wst-workspace .wst-style-text small {
  font-family: var(--font-th);
  font-size: 0.75rem;
  color: #64748B;
}

#wst-workspace .wst-toolbar-actions {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  padding-top: 0.55rem;
  border-top: 1.5px solid #E2E8F0;
}

#wst-workspace .wst-action-row {
  display: flex;
  gap: 0.45rem;
}

#wst-workspace .wst-action-row > .btn-print-pdf,
#wst-workspace .wst-action-row > .wst-save-btn {
  flex: 1 1 0;
  min-width: 0;
  margin: 0;
  padding: 0.65rem 0.6rem;
  font-size: 0.86rem;
}

#wst-workspace .wst-save-btn,
#wst-workspace .wst-load-btn,
#wst-workspace .wst-modal-cancel,
#wst-workspace .wst-modal-confirm,
#wst-workspace .wst-project-load,
#wst-workspace .wst-project-delete {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  border-radius: 12px;
  font-family: var(--font-th);
  font-weight: 700;
  cursor: pointer;
  border: none;
  transition: all 0.18s ease;
}

#wst-workspace .wst-save-btn {
  background: #D97706;
  color: #FFFFFF;
  box-shadow: 0 4px 12px rgba(217, 119, 6, 0.25);
}

#wst-workspace .wst-load-btn {
  width: 100%;
  padding: 0.55rem 0.75rem;
  font-size: 0.84rem;
  background: #F1F5F9;
  color: #334155;
  border: 1.5px solid #CBD5E1;
}

#wst-workspace .wst-action-hint {
  font-family: var(--font-th);
  font-size: 0.76rem;
  color: #64748B;
  text-align: center;
}

/* A4 Worksheet Preview Sheet (#wst-workspace .wst-sheet) */
#wst-workspace .wst-preview-scroll {
  overflow-x: auto;
}

#wst-workspace .wst-pages {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
  width: max-content;
  max-width: 100%;
}

#wst-workspace .wst-sheet {
  width: 210mm;
  height: 297mm;
  max-width: none;
  flex: 0 0 auto;
  box-sizing: border-box;
  background: #FFFFFF;
  border-radius: 4px;
  box-shadow: 0 12px 40px rgba(15, 23, 42, 0.12);
  padding: 8mm 10mm 8mm;
  display: flex;
  flex-direction: column;
  gap: 3.5mm;
  color: #1E293B;
  position: relative;
  overflow: hidden;
}

#wst-workspace .wst-header {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  gap: 2.2mm;
  border-bottom: 2px solid #1E293B;
  padding-bottom: 2.2mm;
}

#wst-workspace .wst-header-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 3mm;
}

#wst-workspace .wst-header-main {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.8mm;
}

#wst-workspace .wst-logo-slot {
  flex: 0 0 16mm;
  width: 16mm;
  height: 16mm;
}

#wst-workspace .wst-header-logo {
  width: 16mm;
  height: 16mm;
  max-width: 16mm;
  max-height: 16mm;
  object-fit: contain;
  flex-shrink: 0;
  display: block;
}

#wst-workspace .wst-logo-slot[hidden] {
  display: none !important;
  width: 0 !important;
  height: 0 !important;
  margin: 0 !important;
  padding: 0 !important;
}

#wst-workspace .wst-title {
  margin: 0;
  font-family: var(--font-en), var(--font-th);
  font-size: 16pt;
  font-weight: 800;
  color: #0F172A;
  line-height: 1.15;
}

#wst-workspace .wst-instruction {
  margin: 0.6mm 0 0;
  font-family: var(--font-en), var(--font-th);
  font-size: 10.5pt;
  font-weight: 600;
  color: #475569;
  line-height: 1.25;
}

#wst-workspace .wst-student-meta {
  display: flex;
  align-items: flex-end;
  gap: 4mm;
  font-family: var(--font-en);
  font-size: 11pt;
  font-weight: 700;
  color: #1E293B;
}

#wst-workspace .wst-meta-field {
  display: flex;
  align-items: flex-end;
  gap: 1.5mm;
  min-width: 0;
}

#wst-workspace .wst-meta-name {
  flex: 2.2 1 0;
}

#wst-workspace .wst-meta-class {
  flex: 1 1 0;
}

#wst-workspace .wst-meta-date,
#wst-workspace .wst-meta-no {
  flex: 0.9 1 0;
}

#wst-workspace .wst-meta-label {
  white-space: nowrap;
}

#wst-workspace .wst-meta-line {
  flex: 1 1 auto;
  border-bottom: 1.5px solid #334155;
  height: 1.05em;
  min-width: 10mm;
}

#wst-workspace .wst-meta-custom {
  font-family: var(--font-th);
  font-size: 11pt;
  font-weight: 600;
  line-height: 1.35;
  white-space: pre-wrap;
  color: #1E293B;
}

/* Upper Section: Category Boxes (2 or 3 horizontal columns) */
#wst-workspace .wst-categories-section {
  flex: 1.15 1 0;
  min-height: 0;
  display: grid;
  gap: 4.5mm;
  align-items: stretch;
}

#wst-workspace .wst-categories-section.wst-cats-2 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

#wst-workspace .wst-categories-section.wst-cats-3 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 3.5mm;
}

#wst-workspace .wst-category-box {
  display: flex;
  flex-direction: column;
  border: 2.2px solid #0F172A;
  border-radius: 3.5mm;
  background: #FFFFFF;
  overflow: hidden;
  min-height: 0;
  box-sizing: border-box;
}

#wst-workspace .wst-category-header {
  flex: 0 0 auto;
  padding: 2.5mm 3mm;
  background: #F1F5F9;
  border-bottom: 2px solid #0F172A;
  text-align: center;
}

#wst-workspace .wst-category-title {
  margin: 0;
  font-family: var(--font-en), var(--font-th);
  font-size: 13.5pt;
  font-weight: 800;
  color: #0F172A;
  line-height: 1.2;
  word-break: break-word;
}

#wst-workspace .wst-categories-section.wst-cats-3 .wst-category-title {
  font-size: 12pt;
}

#wst-workspace .wst-category-body {
  flex: 1 1 auto;
  min-height: 0;
  padding: 3.5mm 4.5mm;
  display: flex;
  flex-direction: column;
  justify-content: space-evenly;
  box-sizing: border-box;
  background: #FFFFFF;
}

/* Cut & Paste empty zone inside category box */
#wst-workspace .wst-paste-zone-hint {
  flex: 1 1 auto;
  border: 1.5px dashed #CBD5E1;
  border-radius: 2.5mm;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Write mode lines inside category box */
#wst-workspace .wst-write-lines {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  justify-content: space-around;
  gap: 2mm;
  padding: 1mm 0;
}

#wst-workspace .wst-write-line-row {
  display: flex;
  align-items: flex-end;
  gap: 2mm;
  width: 100%;
}

#wst-workspace .wst-write-line-bullet {
  font-family: var(--font-en);
  font-size: 10pt;
  font-weight: 800;
  color: #475569;
  line-height: 1;
  flex: 0 0 auto;
}

#wst-workspace .wst-write-line {
  flex: 1 1 auto;
  border-bottom: 1.6px solid #334155;
  height: 6.5mm;
}

/* Divider between Category Boxes and Sorting Items */
#wst-workspace .wst-items-divider {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 2.5mm;
  color: #334155;
  font-family: var(--font-en), var(--font-th);
  font-size: 9.5pt;
  font-weight: 800;
  letter-spacing: 0.02em;
}

#wst-workspace .wst-items-divider::before,
#wst-workspace .wst-items-divider::after {
  content: "";
  flex: 1 1 auto;
  border-top: 1.5px dashed #64748B;
}

#wst-workspace .wst-sheet.wst-style-write .wst-items-divider::before,
#wst-workspace .wst-sheet.wst-style-write .wst-items-divider::after {
  border-top: 1.5px solid #94A3B8;
}

/* Lower Section: Sorting Items Grid (6, 8, or 10 items) */
#wst-workspace .wst-items-section {
  flex: 1 1 0;
  min-height: 0;
  display: grid;
  gap: 3.2mm;
  align-content: stretch;
}

#wst-workspace .wst-items-section.wst-items-6 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  grid-template-rows: repeat(2, minmax(0, 1fr));
  gap: 4mm 5mm;
}

#wst-workspace .wst-items-section.wst-items-8 {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  grid-template-rows: repeat(2, minmax(0, 1fr));
  gap: 3.5mm 4mm;
}

#wst-workspace .wst-items-section.wst-items-10 {
  grid-template-columns: repeat(5, minmax(0, 1fr));
  grid-template-rows: repeat(2, minmax(0, 1fr));
  gap: 3mm 3.2mm;
}

#wst-workspace .wst-sort-item {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  padding: 2.2mm 2.2mm 2mm;
  background: #FFFFFF;
  box-sizing: border-box;
  min-height: 0;
  overflow: hidden;
}

/* Style 1: Cut & Paste — Dashed border + Scissors icon */
#wst-workspace .wst-sheet.wst-style-cut-paste .wst-sort-item {
  border: 1.8px dashed #334155;
  border-radius: 2.5mm;
}

#wst-workspace .wst-scissors-badge {
  position: absolute;
  top: 1mm;
  right: 1.5mm;
  font-size: 9.5pt;
  line-height: 1;
  color: #334155;
  pointer-events: none;
  user-select: none;
}

/* Style 2: Write — Clean solid card + Word label */
#wst-workspace .wst-sheet.wst-style-write .wst-sort-item {
  border: 1.5px solid #CBD5E1;
  border-radius: 2.5mm;
}

#wst-workspace .wst-item-image-wrap {
  flex: 1 1 auto;
  width: 100%;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1mm;
  box-sizing: border-box;
}

#wst-workspace .wst-item-image {
  max-width: 90%;
  max-height: 100%;
  width: auto;
  height: 100%;
  object-fit: contain;
  display: block;
}

#wst-workspace .wst-items-section.wst-items-6 .wst-item-image {
  max-height: 32mm;
}

#wst-workspace .wst-items-section.wst-items-8 .wst-item-image {
  max-height: 29mm;
}

#wst-workspace .wst-items-section.wst-items-10 .wst-item-image {
  max-height: 26mm;
}

#wst-workspace .wst-item-label {
  flex: 0 0 auto;
  width: 100%;
  text-align: center;
  font-family: var(--font-en);
  font-size: 10.5pt;
  font-weight: 800;
  color: #0F172A;
  line-height: 1.15;
  margin-top: 1mm;
  padding-top: 1mm;
  border-top: 1px solid #E2E8F0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#wst-workspace .wst-items-section.wst-items-10 .wst-item-label {
  font-size: 9.2pt;
}

#wst-workspace .wst-sheet.wst-style-cut-paste .wst-item-label {
  border-top: none;
  padding-top: 0.4mm;
  font-size: 9.5pt;
}

#wst-workspace .wst-items-section.wst-items-10 .wst-sheet.wst-style-cut-paste .wst-item-label,
#wst-workspace .wst-sheet.wst-style-cut-paste .wst-items-section.wst-items-10 .wst-item-label {
  font-size: 8.6pt;
}

/* Project Save/Load Modal inside #wst-workspace */
#wst-workspace .wst-modal {
  position: fixed;
  inset: 0;
  z-index: 1200;
  background: rgba(15, 23, 42, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

#wst-workspace .wst-modal[hidden] {
  display: none !important;
}

#wst-workspace .wst-modal-card {
  width: min(440px, 100%);
  background: #FFFFFF;
  border-radius: 20px;
  padding: 1.35rem;
  box-shadow: 0 20px 48px rgba(15, 23, 42, 0.22);
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

#wst-workspace .wst-modal-title {
  margin: 0;
  font-family: var(--font-th);
  font-size: 1.2rem;
  color: #0F172A;
}

#wst-workspace .wst-project-list {
  max-height: 240px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

#wst-workspace .wst-project-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.65rem 0.75rem;
  border: 1.5px solid #E2E8F0;
  border-radius: 12px;
  background: #F8FAFC;
}

#wst-workspace .wst-project-name {
  margin: 0;
  font-family: var(--font-th);
  font-size: 0.92rem;
  font-weight: 700;
  color: #1E293B;
}

#wst-workspace .wst-project-meta,
#wst-workspace .wst-project-empty {
  margin: 0;
  font-family: var(--font-th);
  font-size: 0.78rem;
  color: #64748B;
}

#wst-workspace .wst-project-item-actions,
#wst-workspace .wst-modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.45rem;
}

#wst-workspace .wst-project-load,
#wst-workspace .wst-project-delete,
#wst-workspace .wst-modal-cancel,
#wst-workspace .wst-modal-confirm {
  padding: 0.45rem 0.85rem;
  font-size: 0.85rem;
}

#wst-workspace .wst-project-load,
#wst-workspace .wst-modal-confirm {
  color: #FFFFFF;
  background: #D97706;
}

#wst-workspace .wst-project-delete,
#wst-workspace .wst-modal-cancel {
  color: #475569;
  background: #F1F5F9;
}

/* ===================================================================
   PRINTABLE WORD DOMINOES WORKSHEET GENERATOR (#wd-workspace)
   =================================================================== */
#wd-workspace.wd-workspace {
  display: flex;
  gap: 1.5rem;
  align-items: flex-start;
  margin-top: 1rem;
  animation: pageFadeIn 0.35s ease-out forwards;
}

#wd-workspace .wd-badge {
  background: #FFE4E6;
  color: #9F1239;
}

#wd-workspace > .workspace-toolbar {
  max-height: calc(100vh - 88px);
}

#wd-workspace > .workspace-toolbar > .toolbar-scrollable {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding-right: 0.25rem;
}

#wd-workspace .wd-student-checks {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.35rem;
}

#wd-workspace .wd-count-selector {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.4rem;
}

#wd-workspace .wd-cols-selector {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.45rem;
}

#wd-workspace .wd-count-option {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  padding: 0.5rem 0.35rem;
  border: 2px solid #E2E8F0;
  border-radius: 10px;
  background: #FFFFFF;
  cursor: pointer;
  font-family: var(--font-th);
  font-size: 0.84rem;
  font-weight: 700;
  color: #334155;
  text-align: center;
  transition: all 0.18s ease;
}

#wd-workspace .wd-count-option:hover {
  border-color: #FB7185;
  background: #FFF1F2;
}

#wd-workspace .wd-count-option:has(input:checked) {
  border-color: #E11D48;
  background: #FFE4E6;
  color: #9F1239;
}

#wd-workspace .wd-count-option input {
  accent-color: #E11D48;
}

#wd-workspace .wd-selection-status {
  margin: 0.35rem 0 0.5rem;
  padding: 0.45rem 0.65rem;
  border-radius: 10px;
  font-family: var(--font-th);
  font-size: 0.8rem;
  font-weight: 700;
  background: #ECFDF5;
  color: #065F46;
  border: 1.5px solid #A7F3D0;
}

#wd-workspace .wd-selection-status.is-warning {
  background: #FFFBEB;
  color: #B45309;
  border-color: #FDE68A;
}

#wd-workspace .wd-selection-status.is-error {
  background: #FEF2F2;
  color: #B91C1C;
  border-color: #FECACA;
}

#wd-workspace .wd-vocab-picker-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.45rem;
  max-height: 250px;
  overflow-y: auto;
  padding: 0.35rem;
  border: 1.5px solid #E2E8F0;
  border-radius: 12px;
  background: #F8FAFC;
}

#wd-workspace .wd-vocab-card-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.18rem;
  padding: 0.45rem 0.35rem;
  border: 2px solid #E2E8F0;
  border-radius: 10px;
  background: #FFFFFF;
  cursor: pointer;
  transition: all 0.16s ease;
  text-align: center;
}

#wd-workspace .wd-vocab-card-btn:hover {
  border-color: #FB7185;
  transform: translateY(-1px);
}

#wd-workspace .wd-vocab-card-btn.is-selected {
  border-color: #E11D48;
  background: #FFF1F2;
  box-shadow: 0 2px 8px rgba(225, 29, 72, 0.16);
}

#wd-workspace .wd-vocab-card-thumb {
  width: 46px;
  height: 46px;
  display: flex;
  align-items: center;
  justify-content: center;
}

#wd-workspace .wd-vocab-thumb-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

#wd-workspace .wd-vocab-card-en {
  font-family: var(--font-en);
  font-size: 0.84rem;
  font-weight: 700;
  color: #1E293B;
  line-height: 1.15;
}

#wd-workspace .wd-vocab-card-th {
  font-family: var(--font-th);
  font-size: 0.72rem;
  color: #64748B;
  line-height: 1.15;
}

#wd-workspace .wd-vocab-state-badge {
  margin-top: 0.1rem;
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  font-family: var(--font-th);
  font-size: 0.68rem;
  font-weight: 700;
  background: #F1F5F9;
  color: #475569;
}

#wd-workspace .wd-vocab-card-btn.is-selected .wd-vocab-state-badge {
  background: #E11D48;
  color: #FFFFFF;
}

#wd-workspace .wd-order-controls {
  margin-top: 0.65rem;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

#wd-workspace .wd-shuffle-btn {
  width: 100%;
  padding: 0.55rem 0.75rem;
  border-radius: 10px;
  border: 1.5px solid #FB7185;
  background: #FFF1F2;
  color: #9F1239;
  font-family: var(--font-th);
  font-size: 0.82rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.18s ease;
}

#wd-workspace .wd-shuffle-btn:hover {
  background: #FFE4E6;
  border-color: #E11D48;
}

#wd-workspace .wd-shuffle-secondary-btn {
  width: 100%;
  padding: 0.48rem 0.75rem;
  border-radius: 10px;
  border: 1.5px solid #CBD5E1;
  background: #F8FAFC;
  color: #334155;
  font-family: var(--font-th);
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.18s ease;
}

#wd-workspace .wd-shuffle-secondary-btn:hover {
  background: #F1F5F9;
  border-color: #94A3B8;
}

#wd-workspace .wd-chain-guide-box {
  margin-top: 0.55rem;
  padding: 0.55rem 0.7rem;
  border-radius: 10px;
  background: #F8FAFC;
  border: 1.5px dashed #CBD5E1;
}

#wd-workspace .wd-chain-guide-title {
  font-family: var(--font-th);
  font-size: 0.78rem;
  font-weight: 700;
  color: #334155;
  margin-bottom: 0.25rem;
}

#wd-workspace .wd-chain-guide-list {
  font-family: var(--font-en), var(--font-th);
  font-size: 0.78rem;
  font-weight: 600;
  color: #475569;
  line-height: 1.45;
  word-break: break-word;
}

#wd-workspace .wd-toolbar-actions {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  margin-top: 0.65rem;
  padding-top: 0.55rem;
  border-top: 1.5px solid #E2E8F0;
}

#wd-workspace .wd-action-row {
  display: flex;
  gap: 0.45rem;
}

#wd-workspace .wd-action-row > .btn-print-pdf,
#wd-workspace .wd-action-row > .wd-save-btn {
  flex: 1 1 0;
  min-width: 0;
  margin: 0;
  padding: 0.65rem 0.6rem;
  font-size: 0.86rem;
}

#wd-workspace .wd-save-btn,
#wd-workspace .wd-load-btn,
#wd-workspace .wd-modal-cancel,
#wd-workspace .wd-modal-confirm,
#wd-workspace .wd-project-load,
#wd-workspace .wd-project-delete {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  border-radius: 12px;
  font-family: var(--font-th);
  font-weight: 700;
  cursor: pointer;
  border: none;
  transition: all 0.18s ease;
}

#wd-workspace .wd-save-btn {
  background: #E11D48;
  color: #FFFFFF;
  box-shadow: 0 4px 12px rgba(225, 29, 72, 0.25);
}

#wd-workspace .wd-load-btn {
  width: 100%;
  padding: 0.55rem 0.75rem;
  font-size: 0.84rem;
  background: #F1F5F9;
  color: #334155;
  border: 1.5px solid #CBD5E1;
}

#wd-workspace .wd-action-hint {
  font-family: var(--font-th);
  font-size: 0.76rem;
  color: #64748B;
  text-align: center;
}

/* A4 Worksheet Preview Sheet (#wd-workspace .wd-sheet) */
#wd-workspace .wd-preview-scroll {
  overflow-x: auto;
}

#wd-workspace .wd-pages {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
  width: max-content;
  max-width: 100%;
}

#wd-workspace .wd-sheet {
  width: 210mm;
  height: 297mm;
  max-width: none;
  flex: 0 0 auto;
  box-sizing: border-box;
  background: #FFFFFF;
  border-radius: 4px;
  box-shadow: 0 12px 40px rgba(15, 23, 42, 0.12);
  padding: 8mm 10mm 8mm;
  display: flex;
  flex-direction: column;
  gap: 3.5mm;
  color: #1E293B;
  position: relative;
  overflow: hidden;
  page-break-inside: avoid;
  break-inside: avoid;
}

#wd-workspace .wd-page-badge {
  position: absolute;
  top: 2.5mm;
  right: 10mm;
  padding: 0.8mm 2.6mm;
  border-radius: 999px;
  background: #F1F5F9;
  color: #64748B;
  font-family: var(--font-th);
  font-size: 8pt;
  font-weight: 700;
}

#wd-workspace .wd-header {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  gap: 2.2mm;
  border-bottom: 2px solid #1E293B;
  padding-bottom: 2.2mm;
}

#wd-workspace .wd-header-compact {
  padding-bottom: 1.6mm;
  gap: 1mm;
}

#wd-workspace .wd-header-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 3mm;
}

#wd-workspace .wd-header-main {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.8mm;
}

#wd-workspace .wd-logo-slot {
  flex: 0 0 16mm;
  width: 16mm;
  height: 16mm;
}

#wd-workspace .wd-header-logo {
  width: 16mm;
  height: 16mm;
  max-width: 16mm;
  max-height: 16mm;
  object-fit: contain;
  flex-shrink: 0;
  display: block;
}

#wd-workspace .wd-logo-slot[hidden] {
  display: none !important;
  width: 0 !important;
  height: 0 !important;
  margin: 0 !important;
  padding: 0 !important;
}

#wd-workspace .wd-title {
  margin: 0;
  font-family: var(--font-en), var(--font-th);
  font-size: 16pt;
  font-weight: 800;
  color: #0F172A;
  line-height: 1.15;
}

#wd-workspace .wd-header-compact .wd-title {
  font-size: 13pt;
}

#wd-workspace .wd-instruction {
  margin: 0.6mm 0 0;
  font-family: var(--font-en), var(--font-th);
  font-size: 10pt;
  font-weight: 600;
  color: #475569;
  line-height: 1.25;
}

/* Domino Tiles Grid on A4 */
#wd-workspace .wd-domino-grid {
  display: grid;
  width: 100%;
  box-sizing: border-box;
  align-content: start;
}

#wd-workspace .wd-domino-grid.wd-cols-2 {
  grid-template-columns: repeat(2, 1fr);
  gap: 3.5mm 4mm;
}

#wd-workspace .wd-domino-grid.wd-cols-3 {
  grid-template-columns: repeat(3, 1fr);
  gap: 3mm 3mm;
}

/* Individual Horizontal Domino Tile — Solid Black Border & 90-degree Sharp Corners */
#wd-workspace .wd-tile {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 1fr;
  box-sizing: border-box;
  width: 100%;
  height: 38mm;
  background: #FFFFFF;
  border: 2px solid #000000;
  border-radius: 0;
  padding: 0;
  overflow: hidden;
  page-break-inside: avoid;
  break-inside: avoid;
}

#wd-workspace .wd-domino-grid.wd-cols-3 .wd-tile {
  height: 31.5mm;
  padding: 0;
  border-radius: 0;
}

#wd-workspace .wd-tile-inner {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: 1fr 1fr;
  width: 100%;
  height: 100%;
  border: none;
  border-radius: 0;
  background: #FFFFFF;
  overflow: hidden;
  box-sizing: border-box;
}

/* Left & Right Halves with Solid Black Center Divider */
#wd-workspace .wd-tile-half {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2mm 2.2mm;
  box-sizing: border-box;
  min-width: 0;
  min-height: 0;
  text-align: center;
  position: relative;
}

#wd-workspace .wd-tile-left {
  border-right: 2px solid #000000;
  background: #FFFFFF;
}

#wd-workspace .wd-tile-right {
  background: #FFFFFF;
}

/* START & FINISH Badges */
#wd-workspace .wd-terminal-badge {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.8mm;
  width: 90%;
  height: 82%;
  border-radius: 0;
  padding: 1.5mm;
  box-sizing: border-box;
}

#wd-workspace .wd-badge-start {
  background: #ECFDF5;
  border: 2px solid #059669;
  color: #065F46;
}

#wd-workspace .wd-badge-finish {
  background: #FFF1F2;
  border: 2px solid #E11D48;
  color: #9F1239;
}

#wd-workspace .wd-terminal-icon {
  font-size: 13pt;
  line-height: 1;
}

#wd-workspace .wd-domino-grid.wd-cols-3 .wd-terminal-icon {
  font-size: 10.5pt;
}

#wd-workspace .wd-terminal-text {
  font-family: var(--font-en);
  font-size: 13pt;
  font-weight: 900;
  letter-spacing: 0.06em;
  line-height: 1.05;
}

#wd-workspace .wd-domino-grid.wd-cols-3 .wd-terminal-text {
  font-size: 10pt;
}

#wd-workspace .wd-terminal-sub {
  font-family: var(--font-th);
  font-size: 7pt;
  font-weight: 700;
  opacity: 0.85;
  line-height: 1;
}

#wd-workspace .wd-domino-grid.wd-cols-3 .wd-terminal-sub {
  font-size: 6pt;
}

/* Word Text on Left Half */
#wd-workspace .wd-word-text {
  font-family: var(--font-en);
  font-size: 14pt;
  font-weight: 800;
  color: #0F172A;
  line-height: 1.15;
  word-break: break-word;
  overflow-wrap: anywhere;
}

#wd-workspace .wd-word-text.is-long {
  font-size: 11.5pt;
}

#wd-workspace .wd-domino-grid.wd-cols-3 .wd-word-text {
  font-size: 10.8pt;
}

#wd-workspace .wd-domino-grid.wd-cols-3 .wd-word-text.is-long {
  font-size: 9pt;
}

#wd-workspace .wd-word-th {
  margin-top: 0.8mm;
  font-family: var(--font-th);
  font-size: 8pt;
  font-weight: 600;
  color: #475569;
  line-height: 1.15;
}

#wd-workspace .wd-domino-grid.wd-cols-3 .wd-word-th {
  font-size: 6.8pt;
}

/* Image on Right Half */
#wd-workspace .wd-image-wrap {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

#wd-workspace .wd-tile-image {
  max-width: 92%;
  max-height: 30mm;
  width: auto;
  height: auto;
  object-fit: contain;
  display: block;
}

#wd-workspace .wd-domino-grid.wd-cols-3 .wd-tile-image {
  max-height: 24mm;
}

#wd-workspace .wd-tile-placeholder {
  border-color: #94A3B8;
}

#wd-workspace .wd-placeholder-label {
  font-family: var(--font-en), var(--font-th);
  font-size: 9pt;
  font-weight: 700;
  color: #94A3B8;
}

/* Project Save/Load Modal inside #wd-workspace */
#wd-workspace .wd-modal {
  position: fixed;
  inset: 0;
  z-index: 1200;
  background: rgba(15, 23, 42, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

#wd-workspace .wd-modal[hidden] {
  display: none !important;
}

#wd-workspace .wd-modal-card {
  width: 100%;
  max-width: 440px;
  background: #FFFFFF;
  border-radius: 20px;
  padding: 1.35rem;
  box-shadow: 0 20px 50px rgba(15, 23, 42, 0.25);
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
}

#wd-workspace .wd-modal-title {
  margin: 0;
  font-family: var(--font-th);
  font-size: 1.15rem;
  font-weight: 800;
  color: #1E293B;
}

#wd-workspace .wd-project-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-height: 260px;
  overflow-y: auto;
  margin-top: 0.5rem;
}

#wd-workspace .wd-project-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.65rem 0.75rem;
  border: 1.5px solid #E2E8F0;
  border-radius: 12px;
  background: #F8FAFC;
}

#wd-workspace .wd-project-name {
  margin: 0;
  font-family: var(--font-th);
  font-size: 0.92rem;
  font-weight: 700;
  color: #1E293B;
}

#wd-workspace .wd-project-meta,
#wd-workspace .wd-project-empty {
  margin: 0;
  font-family: var(--font-th);
  font-size: 0.78rem;
  color: #64748B;
}

#wd-workspace .wd-project-item-actions,
#wd-workspace .wd-modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.45rem;
}

#wd-workspace .wd-project-load,
#wd-workspace .wd-project-delete,
#wd-workspace .wd-modal-cancel,
#wd-workspace .wd-modal-confirm {
  padding: 0.45rem 0.85rem;
  font-size: 0.85rem;
}

#wd-workspace .wd-project-load,
#wd-workspace .wd-modal-confirm {
  color: #FFFFFF;
  background: #E11D48;
}

#wd-workspace .wd-project-delete,
#wd-workspace .wd-modal-cancel {
  color: #475569;
  background: #F1F5F9;
}

/* ===================================================================
   COLORING PAGE WORKSHEET GENERATOR (#cp-workspace)
   =================================================================== */
#cp-workspace.cp-workspace {
  display: flex;
  gap: 1.5rem;
  align-items: flex-start;
  margin-top: 1rem;
  animation: pageFadeIn 0.35s ease-out forwards;
}

#cp-workspace .cp-badge {
  background: #FFEDD5;
  color: #9A3412;
}

#cp-workspace > .workspace-toolbar {
  overflow: hidden;
}

#cp-workspace > .workspace-toolbar > .toolbar-scrollable {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding-right: 0.2rem;
}

#cp-workspace .cp-note-input {
  resize: vertical;
  min-height: 64px;
}

#cp-workspace .cp-student-checks {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.35rem 0.75rem;
}

#cp-workspace .cp-image-list {
  width: 100%;
  min-height: 220px;
  padding: 0.25rem;
  overflow-y: auto;
  background: #FFFFFF;
  font-family: var(--font-th);
}

#cp-workspace .cp-image-list option {
  padding: 0.4rem 0.55rem;
  border-radius: 8px;
  font-family: var(--font-th);
  font-weight: 700;
  color: #1E293B;
}

#cp-workspace .cp-upload-box {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  align-items: center;
  margin-top: 0.55rem;
}

#cp-workspace .cp-scale-row {
  display: grid;
  grid-template-columns: 36px 1fr 36px auto;
  gap: 0.4rem;
  align-items: center;
}

#cp-workspace .cp-scale-btn {
  width: 36px;
  height: 36px;
  border: 1.5px solid #FDBA74;
  border-radius: 10px;
  background: #FFF7ED;
  color: #9A3412;
  font-size: 1.2rem;
  font-weight: 800;
  cursor: pointer;
}

#cp-workspace .cp-scale-btn:hover {
  background: #FFEDD5;
}

#cp-workspace .cp-scale-value {
  min-width: 3.2rem;
  text-align: right;
  font-family: var(--font-en);
  font-weight: 800;
  color: #9A3412;
}

#cp-workspace .cp-toolbar-actions {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding-top: 0.55rem;
  border-top: 2px dashed #E2E8F0;
}

#cp-workspace .cp-action-row {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: 0.45rem;
}

#cp-workspace .cp-action-row > .btn-print-pdf,
#cp-workspace .cp-action-row > .cp-save-btn {
  width: 100%;
  min-height: 44px;
  padding: 0.55rem 0.65rem;
  font-size: 0.86rem;
  border-radius: 12px;
  justify-content: center;
}

#cp-workspace .cp-save-btn,
#cp-workspace .cp-load-btn,
#cp-workspace .cp-modal-cancel,
#cp-workspace .cp-modal-confirm,
#cp-workspace .cp-project-load,
#cp-workspace .cp-project-delete {
  border: none;
  border-radius: 12px;
  font-family: var(--font-th);
  font-weight: 700;
  cursor: pointer;
}

#cp-workspace .cp-save-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  color: #FFFFFF;
  background: linear-gradient(135deg, #FB923C, #EA580C);
}

#cp-workspace .cp-load-btn {
  width: 100%;
  min-height: 38px;
  padding: 0.45rem 0.65rem;
  font-size: 0.85rem;
  color: #9A3412;
  background: #FFEDD5;
}

#cp-workspace .cp-action-hint {
  font-family: var(--font-th);
  font-size: 0.76rem;
  color: #64748B;
  text-align: center;
}

#cp-workspace .cp-preview-scroll {
  overflow-x: auto;
}

#cp-workspace .cp-pages {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
  width: max-content;
  max-width: 100%;
}

#cp-workspace .cp-sheet {
  width: 210mm;
  height: 297mm;
  max-width: none;
  flex: 0 0 auto;
  box-sizing: border-box;
  background: #FFFFFF;
  border-radius: 4px;
  box-shadow: 0 12px 40px rgba(15, 23, 42, 0.12);
  padding: 9mm 11mm 9mm;
  display: flex;
  flex-direction: column;
  gap: 3.5mm;
  color: #1E293B;
  position: relative;
  overflow: hidden;
}

#cp-workspace .cp-header {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  gap: 2.5mm;
  border-bottom: 2px solid #1E293B;
  padding-bottom: 2.5mm;
}

#cp-workspace .cp-header-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 3mm;
}

#cp-workspace .cp-header-main {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.8mm;
}

#cp-workspace .cp-logo-slot {
  flex: 0 0 16mm;
  width: 16mm;
  height: 16mm;
}

#cp-workspace .cp-header-logo {
  width: 16mm;
  height: 16mm;
  max-width: 16mm;
  max-height: 16mm;
  object-fit: contain;
  display: block;
}

#cp-workspace .cp-logo-slot[hidden] {
  display: none !important;
  width: 0 !important;
  height: 0 !important;
  margin: 0 !important;
  padding: 0 !important;
}

#cp-workspace .cp-title {
  margin: 0;
  font-family: var(--font-en), var(--font-th);
  font-size: 16pt;
  font-weight: 800;
  line-height: 1.15;
}

#cp-workspace .cp-instruction {
  margin: 0.8mm 0 0;
  font-family: var(--font-en), var(--font-th);
  font-size: 10.5pt;
  font-weight: 600;
  line-height: 1.25;
}

#cp-workspace .cp-student-meta {
  display: flex;
  align-items: flex-end;
  gap: 4mm;
  font-family: var(--font-en);
  font-size: 11pt;
  font-weight: 700;
  color: #1E293B;
}

#cp-workspace .cp-meta-field {
  display: flex;
  align-items: flex-end;
  gap: 1.5mm;
  min-width: 0;
}

#cp-workspace .cp-meta-name { flex: 2.2 1 0; }
#cp-workspace .cp-meta-class { flex: 1 1 0; }
#cp-workspace .cp-meta-date,
#cp-workspace .cp-meta-no { flex: 0.9 1 0; }

#cp-workspace .cp-meta-label { white-space: nowrap; }

#cp-workspace .cp-meta-line {
  flex: 1 1 auto;
  border-bottom: 1.5px solid #334155;
  height: 1.05em;
  min-width: 10mm;
}

#cp-workspace .cp-meta-custom {
  font-family: var(--font-th);
  font-size: 11pt;
  font-weight: 600;
  line-height: 1.35;
  white-space: pre-wrap;
  color: #1E293B;
}

#cp-workspace .cp-art-stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  border: 2.2px solid #1E293B;
  border-radius: 4mm;
  background: #FFFFFF;
}

#cp-workspace .cp-art-frame {
  position: absolute;
  left: 50%;
  top: 50%;
  width: var(--cp-scale, 100%);
  height: var(--cp-scale, 100%);
  max-width: 100%;
  max-height: 100%;
  transform: translate(-50%, -50%);
  box-sizing: border-box;
}

#cp-workspace .cp-art-img {
  display: block;
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

#cp-workspace .cp-art-empty {
  font-family: var(--font-th);
  font-size: 12pt;
  font-weight: 700;
  color: #94A3B8;
  text-align: center;
  padding: 8mm;
}

#cp-workspace .cp-modal {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: rgba(15, 23, 42, 0.45);
}

#cp-workspace .cp-modal[hidden] {
  display: none !important;
}

#cp-workspace .cp-modal-card {
  width: min(460px, 100%);
  background: #FFFFFF;
  border-radius: 18px;
  padding: 1.1rem 1.15rem 1rem;
  box-shadow: 0 18px 50px rgba(15, 23, 42, 0.22);
}

#cp-workspace .cp-modal-title {
  margin: 0 0 0.8rem;
  font-family: var(--font-th);
  color: #9A3412;
}

#cp-workspace .cp-project-list {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  max-height: 280px;
  overflow-y: auto;
  margin-top: 0.55rem;
}

#cp-workspace .cp-project-empty {
  margin: 0;
  font-family: var(--font-th);
  color: #64748B;
}

#cp-workspace .cp-project-item {
  display: flex;
  justify-content: space-between;
  gap: 0.6rem;
  align-items: center;
  padding: 0.55rem 0.65rem;
  border-radius: 12px;
  background: #FFF7ED;
}

#cp-workspace .cp-project-name {
  margin: 0;
  font-family: var(--font-th);
  font-weight: 800;
  color: #1E293B;
}

#cp-workspace .cp-project-meta {
  margin: 0.15rem 0 0;
  font-family: var(--font-th);
  font-size: 0.78rem;
  color: #64748B;
}

#cp-workspace .cp-project-item-actions,
#cp-workspace .cp-modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.45rem;
  margin-top: 0.85rem;
}

#cp-workspace .cp-project-load,
#cp-workspace .cp-project-delete,
#cp-workspace .cp-modal-cancel,
#cp-workspace .cp-modal-confirm {
  padding: 0.45rem 0.85rem;
  font-size: 0.85rem;
}

#cp-workspace .cp-project-load,
#cp-workspace .cp-modal-confirm {
  color: #FFFFFF;
  background: #EA580C;
}

#cp-workspace .cp-project-delete,
#cp-workspace .cp-modal-cancel {
  color: #475569;
  background: #F1F5F9;
}

/* ===================================================================
   MINIGAME RESPONSIVE PLAY (portrait stack / landscape side-by-side)
   Bubble Shooter, Sliding Jigsaw, Drag Jigsaw, Pixel Art
   =================================================================== */

#page-games .mg-touch-lock {
  touch-action: none;
  overscroll-behavior: none;
}

#page-games .mg-sl-container {
  display: none;
  flex-direction: column;
  gap: 6px;
  width: 100%;
  max-width: 1180px;
  margin: 0 auto;
}

#page-games.mg-sl-playing .mg-hub-container {
  display: none;
}

#page-games.mg-sl-playing .mg-sl-container {
  display: flex;
}

body:has(#page-games.mg-bs-playing),
body:has(#page-games.mg-sj-playing),
body:has(#page-games.mg-dj-playing),
body:has(#page-games.mg-pa-playing) {
  height: 100dvh;
  overflow: hidden;
}

body:has(#page-games.mg-bs-playing) .app-container,
body:has(#page-games.mg-sj-playing) .app-container,
body:has(#page-games.mg-dj-playing) .app-container,
body:has(#page-games.mg-pa-playing) .app-container {
  height: 100dvh;
  max-height: 100dvh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  padding: 0.35rem 0.5rem 0.4rem;
}

body:has(#page-games.mg-bs-playing) .main-navbar,
body:has(#page-games.mg-sj-playing) .main-navbar,
body:has(#page-games.mg-dj-playing) .main-navbar,
body:has(#page-games.mg-pa-playing) .main-navbar {
  position: relative;
  top: 0;
  flex-shrink: 0;
  margin-bottom: 0.35rem;
}

body:has(#page-games.mg-bs-playing) .brand-avatar,
body:has(#page-games.mg-sj-playing) .brand-avatar,
body:has(#page-games.mg-dj-playing) .brand-avatar,
body:has(#page-games.mg-pa-playing) .brand-avatar {
  width: 36px;
  height: 36px;
}

body:has(#page-games.mg-bs-playing) .brand-title,
body:has(#page-games.mg-sj-playing) .brand-title,
body:has(#page-games.mg-dj-playing) .brand-title,
body:has(#page-games.mg-pa-playing) .brand-title {
  font-size: 1.05rem;
  padding: 0;
  margin: 0;
}

body:has(#page-games.mg-bs-playing) .nav-tab,
body:has(#page-games.mg-sj-playing) .nav-tab,
body:has(#page-games.mg-dj-playing) .nav-tab,
body:has(#page-games.mg-pa-playing) .nav-tab {
  padding: 0.28rem 0.55rem;
  font-size: 0.78rem;
}

#page-games.mg-bs-playing,
#page-games.mg-sj-playing,
#page-games.mg-dj-playing,
#page-games.mg-pa-playing {
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

#page-games.mg-bs-playing .mg-bs-container,
#page-games.mg-sj-playing .mg-sj-container,
#page-games.mg-dj-playing .mg-dj-container,
#page-games.mg-pa-playing .mg-pa-container {
  flex: 1 1 auto;
  min-height: 0;
  max-height: 100%;
  width: 100%;
  overflow: hidden;
}

#page-games.mg-bs-playing .mg-bs-header,
#page-games.mg-sj-playing .mg-sj-header,
#page-games.mg-dj-playing .mg-dj-header,
#page-games.mg-pa-playing .mg-pa-header {
  flex-shrink: 0;
  flex-wrap: wrap;
  align-items: center;
  overflow: visible;
  max-height: none;
  padding: 6px 10px;
  gap: 6px 8px;
}

#page-games.mg-bs-playing .mg-bs-title,
#page-games.mg-sj-playing .mg-sj-title,
#page-games.mg-dj-playing .mg-dj-title,
#page-games.mg-pa-playing .mg-pa-title {
  font-size: 1.05rem;
}

#page-games.mg-bs-playing .mg-bs-stage,
#page-games.mg-sj-playing .mg-sj-stage,
#page-games.mg-dj-playing .mg-dj-stage,
#page-games.mg-pa-playing .mg-pa-arena {
  flex: 1 1 auto;
  min-height: 0;
  max-height: 100%;
  height: auto;
  overflow: hidden;
}

#page-games.mg-bs-playing .mg-bs-rack-bar {
  flex-shrink: 0;
  max-height: 108px;
  padding: 6px 10px 8px;
}

#page-games.mg-bs-playing .mg-bs-word-rack {
  flex-wrap: nowrap;
  justify-content: flex-start;
  overflow-x: auto;
  max-width: 100%;
}

#page-games.mg-bs-playing .mg-bs-slot {
  flex-shrink: 0;
}

#page-games.mg-bs-playing .mg-bs-col-center {
  height: 100%;
  min-height: 0;
  max-height: 100%;
}

#page-games.mg-bs-playing .mg-bs-col-left,
#page-games.mg-bs-playing .mg-bs-col-right,
#page-games.mg-sj-playing .mg-sj-col-left,
#page-games.mg-sj-playing .mg-sj-col-right,
#page-games.mg-dj-playing .mg-dj-col-left,
#page-games.mg-dj-playing .mg-dj-col-right {
  min-height: 0;
  min-width: 0;
  width: 100%;
  gap: 8px;
  justify-content: flex-start;
  overflow: auto;
}

#page-games.mg-sj-playing .mg-sj-col-center,
#page-games.mg-dj-playing .mg-dj-col-center {
  height: 100%;
  min-height: 0;
  min-width: 0;
  justify-content: flex-start;
}

#page-games .mg-sj-board-fit {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  container-type: size;
}

#page-games.mg-sj-playing .mg-sj-board-wrap {
  width: min(100cqw, 100cqh, 560px);
  height: min(100cqw, 100cqh, 560px);
  max-width: 100%;
  max-height: 100%;
  aspect-ratio: 1 / 1;
}

#page-games.mg-sj-playing .mg-sj-hint-toolbar,
#page-games.mg-dj-playing .mg-dj-hint-toolbar {
  width: 100%;
  border-radius: 18px;
  flex-direction: column;
  align-items: stretch;
}

#page-games.mg-sj-playing .mg-sj-num-switch-label,
#page-games.mg-dj-playing .mg-dj-num-switch-label {
  white-space: normal;
}

#page-games.mg-sj-playing .mg-sj-hint-banner,
#page-games.mg-dj-playing .mg-dj-hint-banner {
  flex-shrink: 0;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}

#page-games.mg-dj-playing .mg-dj-board-wrap {
  flex: 1 1 auto;
  width: 100%;
  min-height: 0;
  max-height: 100%;
  height: auto;
  touch-action: none;
}

#page-games.mg-dj-playing .mg-dj-arena {
  width: 100%;
  height: 100%;
  min-height: 0;
  max-height: 100%;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  align-items: stretch;
}

#page-games.mg-dj-playing .mg-dj-drop-panel,
#page-games.mg-dj-playing .mg-dj-scatter-panel {
  min-height: 0;
  height: 100%;
  justify-content: flex-start;
  container-type: size;
}

#page-games.mg-dj-playing .mg-dj-drop-zone {
  width: min(100cqw, calc(100cqh - 34px));
  height: min(100cqw, calc(100cqh - 34px));
  max-width: 100%;
  max-height: calc(100% - 28px);
}

#page-games.mg-dj-playing .mg-dj-scatter-zone {
  width: 100%;
  height: 100%;
  min-height: 0;
  flex: 1 1 auto;
}

#page-games.mg-pa-playing .mg-pa-col-left,
#page-games.mg-pa-playing .mg-pa-col-center,
#page-games.mg-pa-playing .mg-pa-col-right {
  min-height: 0;
  min-width: 0;
  overflow: auto;
}

#page-games.mg-pa-playing .mg-pa-board-wrap {
  touch-action: none;
  width: min(100cqw, 100cqh, 100%);
  max-width: 100%;
  max-height: 100%;
}

@media (max-width: 768px) {
  body:has(#page-games.mg-bs-playing) .navbar-inner,
  body:has(#page-games.mg-sj-playing) .navbar-inner,
  body:has(#page-games.mg-dj-playing) .navbar-inner,
  body:has(#page-games.mg-pa-playing) .navbar-inner {
    flex-direction: row;
    align-items: center;
    padding: 0.28rem 0.45rem;
    gap: 0.35rem;
  }

  body:has(#page-games.mg-bs-playing) .nav-menu,
  body:has(#page-games.mg-sj-playing) .nav-menu,
  body:has(#page-games.mg-dj-playing) .nav-menu,
  body:has(#page-games.mg-pa-playing) .nav-menu {
    display: flex;
    width: auto;
    gap: 0.2rem;
  }

  body:has(#page-games.mg-bs-playing) .tab-label,
  body:has(#page-games.mg-sj-playing) .tab-label,
  body:has(#page-games.mg-dj-playing) .tab-label,
  body:has(#page-games.mg-pa-playing) .tab-label {
    display: none;
  }
}

@media (orientation: landscape) {
  #page-games.mg-bs-playing .mg-bs-stage,
  #page-games.mg-sj-playing .mg-sj-stage,
  #page-games.mg-dj-playing .mg-dj-stage {
    display: grid;
    grid-template-columns: minmax(112px, 210px) minmax(0, 1fr) minmax(128px, 230px);
    align-items: stretch;
  }

  #page-games.mg-bs-playing .mg-bs-col-center,
  #page-games.mg-sj-playing .mg-sj-col-center,
  #page-games.mg-dj-playing .mg-dj-col-center {
    grid-column: auto;
    order: 0;
    width: 100%;
  }

  #page-games.mg-bs-playing .mg-bs-col-left,
  #page-games.mg-bs-playing .mg-bs-col-right,
  #page-games.mg-sj-playing .mg-sj-col-left,
  #page-games.mg-sj-playing .mg-sj-col-right,
  #page-games.mg-dj-playing .mg-dj-col-left,
  #page-games.mg-dj-playing .mg-dj-col-right {
    order: 0;
  }

  #page-games.mg-pa-playing .mg-pa-arena {
    display: grid;
    grid-template-columns: minmax(132px, 220px) minmax(86px, 120px) minmax(0, 1fr);
    align-items: stretch;
  }
}

@media (max-width: 700px) {
  #page-games.mg-bs-playing .mg-bs-title,
  #page-games.mg-sj-playing .mg-sj-title,
  #page-games.mg-dj-playing .mg-dj-title,
  #page-games.mg-pa-playing .mg-pa-title,
  #page-games.mg-bs-playing .mg-bs-vip-pill,
  #page-games.mg-sj-playing .mg-sj-vip-pill,
  #page-games.mg-dj-playing .mg-dj-vip-pill,
  #page-games.mg-pa-playing .mg-pa-vip-pill {
    display: none;
  }

  #page-games.mg-bs-playing .mg-bs-stats {
    order: -1;
  }
}

@media (orientation: portrait) {
  #page-games.mg-bs-playing .mg-bs-stage,
  #page-games.mg-sj-playing .mg-sj-stage,
  #page-games.mg-dj-playing .mg-dj-stage {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
    padding: 8px;
  }

  #page-games.mg-bs-playing .mg-bs-col-left,
  #page-games.mg-sj-playing .mg-sj-col-left,
  #page-games.mg-dj-playing .mg-dj-col-left {
    order: 1;
    flex: 0 0 auto;
    overflow: visible;
  }

  #page-games.mg-bs-playing .mg-bs-col-center,
  #page-games.mg-sj-playing .mg-sj-col-center,
  #page-games.mg-dj-playing .mg-dj-col-center {
    order: 2;
    flex: 1 1 0%;
    width: 100%;
    min-height: 180px;
    height: auto;
  }

  #page-games.mg-bs-playing .mg-bs-col-right,
  #page-games.mg-sj-playing .mg-sj-col-right,
  #page-games.mg-dj-playing .mg-dj-col-right {
    order: 3;
    flex: 0 1 auto;
    max-height: 132px;
    overflow: auto;
  }

  #page-games.mg-bs-playing .mg-bs-target-card,
  #page-games.mg-sj-playing .mg-sj-target-card,
  #page-games.mg-dj-playing .mg-dj-target-card {
    flex-direction: row;
    align-items: center;
    text-align: left;
    padding: 8px 10px;
    gap: 8px;
  }

  #page-games.mg-bs-playing .mg-bs-target-info,
  #page-games.mg-sj-playing .mg-sj-target-info,
  #page-games.mg-dj-playing .mg-dj-target-info {
    align-items: flex-start;
    flex: 1 1 auto;
  }

  #page-games.mg-bs-playing .mg-bs-target-visual,
  #page-games.mg-sj-playing .mg-sj-target-visual,
  #page-games.mg-dj-playing .mg-dj-target-visual {
    width: 68px;
    height: 68px;
  }

  #page-games.mg-bs-playing .mg-bs-speak-btn,
  #page-games.mg-sj-playing .mg-sj-speak-btn,
  #page-games.mg-dj-playing .mg-dj-speak-btn {
    width: auto;
  }

  #page-games.mg-bs-playing .mg-bs-target-label,
  #page-games.mg-sj-playing .mg-sj-target-label,
  #page-games.mg-dj-playing .mg-dj-target-label,
  #page-games.mg-bs-playing .mg-bs-timer-icon,
  #page-games.mg-sj-playing .mg-sj-timer-icon,
  #page-games.mg-dj-playing .mg-dj-timer-icon,
  #page-games.mg-bs-playing .mg-bs-timer-label,
  #page-games.mg-sj-playing .mg-sj-timer-label,
  #page-games.mg-dj-playing .mg-dj-timer-label {
    display: none;
  }

  #page-games.mg-bs-playing .mg-bs-timer-card,
  #page-games.mg-sj-playing .mg-sj-timer-card,
  #page-games.mg-dj-playing .mg-dj-timer-card {
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    padding: 8px;
    gap: 8px;
  }

  #page-games.mg-bs-playing .mg-bs-timer-value,
  #page-games.mg-sj-playing .mg-sj-timer-value,
  #page-games.mg-dj-playing .mg-dj-timer-value {
    width: auto;
    font-size: 1.25rem;
  }

  #page-games.mg-bs-playing .mg-bs-actions,
  #page-games.mg-sj-playing .mg-sj-hint-toolbar,
  #page-games.mg-dj-playing .mg-dj-hint-toolbar {
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: center;
    width: 100%;
  }

  #page-games.mg-dj-playing .mg-dj-arena {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(0, 1.15fr) minmax(0, 0.85fr);
  }

  #page-games.mg-pa-playing .mg-pa-arena {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }

  #page-games.mg-pa-playing .mg-pa-col-left { order: 1; flex: 0 0 auto; }
  #page-games.mg-pa-playing .mg-pa-col-right { order: 2; flex: 1 1 auto; min-height: 0; }
  #page-games.mg-pa-playing .mg-pa-col-center { order: 3; flex: 0 0 auto; }
}

@media (orientation: landscape) and (max-height: 520px) {
  #page-games.mg-bs-playing .mg-bs-header,
  #page-games.mg-sj-playing .mg-sj-header,
  #page-games.mg-dj-playing .mg-dj-header,
  #page-games.mg-pa-playing .mg-pa-header {
    padding: 4px 8px;
  }

  #page-games.mg-bs-playing .mg-bs-rack-bar {
    max-height: 72px;
    padding: 4px 8px;
  }

  #page-games.mg-bs-playing .mg-bs-slot {
    width: 36px;
    height: 42px;
  }

  #page-games.mg-bs-playing .mg-bs-target-visual,
  #page-games.mg-sj-playing .mg-sj-target-visual,
  #page-games.mg-dj-playing .mg-dj-target-visual {
    width: 58px;
    height: 58px;
  }

  #page-games.mg-bs-playing .mg-bs-target-card,
  #page-games.mg-sj-playing .mg-sj-target-card,
  #page-games.mg-dj-playing .mg-dj-target-card,
  #page-games.mg-bs-playing .mg-bs-timer-card,
  #page-games.mg-sj-playing .mg-sj-timer-card,
  #page-games.mg-dj-playing .mg-dj-timer-card {
    padding: 6px;
    gap: 4px;
  }

  #page-games.mg-bs-playing .mg-bs-timer-icon,
  #page-games.mg-sj-playing .mg-sj-timer-icon,
  #page-games.mg-dj-playing .mg-dj-timer-icon,
  #page-games.mg-bs-playing .mg-bs-hint-banner,
  #page-games.mg-sj-playing .mg-sj-hint-banner,
  #page-games.mg-dj-playing .mg-dj-hint-banner {
    display: none;
  }

  #page-games.mg-bs-playing .mg-bs-timer-value,
  #page-games.mg-sj-playing .mg-sj-timer-value,
  #page-games.mg-dj-playing .mg-dj-timer-value {
    font-size: 1.05rem;
    padding: 0.12rem 0.4rem;
  }
}

/* Every in-page minigame fits the viewport, with a short header */
body:has(#page-games:is(.mg-flashcard-playing, .mg-crossword-playing, .mg-bs-playing, .mg-sj-playing, .mg-dj-playing, .mg-pa-playing, .mg-hm-playing, .mg-sl-playing)) {
  height: 100dvh;
  overflow: hidden;
}

body:has(#page-games:is(.mg-flashcard-playing, .mg-crossword-playing, .mg-bs-playing, .mg-sj-playing, .mg-dj-playing, .mg-pa-playing, .mg-hm-playing, .mg-sl-playing)) .app-container {
  height: 100dvh;
  max-height: 100dvh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  padding: 0.35rem 0.5rem 0.4rem;
}

body:has(#page-games:is(.mg-flashcard-playing, .mg-crossword-playing, .mg-bs-playing, .mg-sj-playing, .mg-dj-playing, .mg-pa-playing, .mg-hm-playing, .mg-sl-playing)) .main-navbar {
  position: relative;
  top: 0;
  flex-shrink: 0;
  margin-bottom: 0.35rem;
}

body:has(#page-games:is(.mg-flashcard-playing, .mg-crossword-playing, .mg-bs-playing, .mg-sj-playing, .mg-dj-playing, .mg-pa-playing, .mg-hm-playing, .mg-sl-playing)) .brand-avatar {
  width: 36px;
  height: 36px;
}

body:has(#page-games:is(.mg-flashcard-playing, .mg-crossword-playing, .mg-bs-playing, .mg-sj-playing, .mg-dj-playing, .mg-pa-playing, .mg-hm-playing, .mg-sl-playing)) .brand-title {
  font-size: 1.05rem;
  padding: 0;
  margin: 0;
}

body:has(#page-games:is(.mg-flashcard-playing, .mg-crossword-playing, .mg-bs-playing, .mg-sj-playing, .mg-dj-playing, .mg-pa-playing, .mg-hm-playing, .mg-sl-playing)) .brand-tag {
  display: none;
}

body:has(#page-games:is(.mg-flashcard-playing, .mg-crossword-playing, .mg-bs-playing, .mg-sj-playing, .mg-dj-playing, .mg-pa-playing, .mg-hm-playing, .mg-sl-playing)) .nav-right {
  flex-direction: row;
  align-items: center;
  justify-content: flex-end;
  gap: 0.3rem;
  min-width: 0;
}

body:has(#page-games:is(.mg-flashcard-playing, .mg-crossword-playing, .mg-bs-playing, .mg-sj-playing, .mg-dj-playing, .mg-pa-playing, .mg-hm-playing, .mg-sl-playing)) .nav-tab {
  padding: 0.28rem 0.55rem;
  font-size: 0.78rem;
}

body:has(#page-games:is(.mg-flashcard-playing, .mg-crossword-playing, .mg-bs-playing, .mg-sj-playing, .mg-dj-playing, .mg-pa-playing, .mg-hm-playing, .mg-sl-playing)) .hub-bgm-toggle {
  width: 36px;
  height: 36px;
  border-radius: 12px;
}

body:has(#page-games:is(.mg-flashcard-playing, .mg-crossword-playing, .mg-bs-playing, .mg-sj-playing, .mg-dj-playing, .mg-pa-playing, .mg-hm-playing, .mg-sl-playing)) .hub-bgm-icon {
  width: 20px;
  height: 20px;
}

#page-games:is(.mg-flashcard-playing, .mg-crossword-playing, .mg-hm-playing, .mg-sl-playing) {
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

#page-games.mg-flashcard-playing .mg-flashcard-container,
#page-games.mg-hm-playing .mg-hm-container,
#page-games.mg-sl-playing .mg-sl-container {
  flex: 1 1 auto;
  min-height: 0;
  max-height: 100%;
  width: 100%;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

#page-games.mg-crossword-playing .mg-crossword-container {
  flex: 1 1 auto;
  min-height: 0;
  max-height: 100%;
  width: 100%;
  overflow-x: hidden;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

#page-games.mg-flashcard-playing .mg-flashcard-header,
#page-games.mg-crossword-playing .mg-cw-topbar,
#page-games.mg-hm-playing .mg-hm-header,
#page-games.mg-sl-playing .mg-sl-header {
  flex-shrink: 0;
  flex-wrap: wrap;
  align-items: center;
  overflow: visible;
  max-height: none;
  margin-bottom: 8px;
  padding: 6px 10px;
  gap: 8px;
}

#page-games.mg-flashcard-playing .mg-flashcard-title,
#page-games.mg-crossword-playing .mg-cw-title,
#page-games.mg-hm-playing .mg-hm-title,
#page-games.mg-sl-playing .mg-sl-title {
  font-size: 1.05rem;
  margin: 0;
}

#page-games.mg-flashcard-playing .mg-flashcard-board,
#page-games.mg-crossword-playing .mg-cw-stage,
#page-games.mg-hm-playing .mg-hm-arena,
#page-games.mg-sl-playing .mg-sl-stage {
  flex: 1 1 auto;
  min-height: 0;
  max-height: 100%;
  height: auto;
  overflow: hidden;
}

#page-games.mg-crossword-playing .mg-cw-board-area {
  min-height: 0;
}

#page-games.mg-crossword-playing .mg-cw-keyboard {
  position: sticky;
  bottom: 0;
  z-index: 8;
  flex-shrink: 0;
  margin-top: auto;
  max-height: none;
  overflow: visible;
  background: #FFFFFF;
  padding: 6px;
}

#page-games.mg-crossword-playing .mg-cw-key {
  min-width: 36px;
  height: 40px;
  font-size: 1rem;
  padding: 0 8px;
}

@media (max-height: 800px) {
  #page-games.mg-crossword-playing .mg-cw-topbar {
    padding: 4px 8px;
    gap: 6px;
  }

  #page-games.mg-crossword-playing .mg-crossword-container .mg-game-logo {
    height: 32px;
    margin-right: 8px;
  }

  #page-games.mg-crossword-playing .mg-cw-hint-figure {
    height: clamp(64px, 11vh, 108px);
  }

  #page-games.mg-crossword-playing .mg-cw-hints {
    gap: 6px;
    padding: 8px;
  }

  #page-games.mg-crossword-playing .mg-cw-hint-card {
    gap: 4px;
    padding: 6px;
  }

  #page-games.mg-crossword-playing .mg-cw-keyboard {
    gap: 4px;
    padding: 4px 6px 6px;
  }

  #page-games.mg-crossword-playing .mg-cw-key {
    min-width: clamp(28px, 3vw, 42px);
    height: 34px;
    font-size: 0.95rem;
    border-radius: 10px;
    box-shadow: 0 2px 0 #CBD5E1;
  }

  #page-games.mg-crossword-playing .mg-cw-key-back {
    min-width: 72px;
  }
}

#page-games.mg-flashcard-playing .mg-card-item {
  height: auto;
  min-height: 0;
}

#page-games.mg-sl-playing .mg-sl-col-board,
#page-games.mg-sl-playing .mg-sl-col-panel {
  min-width: 0;
  min-height: 0;
  overflow: auto;
}

#page-games.mg-sl-playing .mg-sl-board-frame {
  width: min(100%, 70dvh);
  max-width: 100%;
  aspect-ratio: 1;
  margin: 0 auto;
}

@media (max-width: 768px) {
  body:has(#page-games:is(.mg-flashcard-playing, .mg-crossword-playing, .mg-bs-playing, .mg-sj-playing, .mg-dj-playing, .mg-pa-playing, .mg-hm-playing, .mg-sl-playing)) .navbar-inner {
    flex-direction: row;
    align-items: center;
    padding: 0.28rem 0.45rem;
  }

  body:has(#page-games:is(.mg-flashcard-playing, .mg-crossword-playing, .mg-bs-playing, .mg-sj-playing, .mg-dj-playing, .mg-pa-playing, .mg-hm-playing, .mg-sl-playing)) .nav-menu {
    display: none;
    width: 100%;
    max-width: 100%;
  }

  body:has(#page-games:is(.mg-flashcard-playing, .mg-crossword-playing, .mg-bs-playing, .mg-sj-playing, .mg-dj-playing, .mg-pa-playing, .mg-hm-playing, .mg-sl-playing)) .nav-menu.is-open {
    display: grid;
    grid-template-columns: 1fr;
  }

  body:has(#page-games:is(.mg-flashcard-playing, .mg-crossword-playing, .mg-bs-playing, .mg-sj-playing, .mg-dj-playing, .mg-pa-playing, .mg-hm-playing, .mg-sl-playing)) .tab-label {
    display: inline;
  }

  #page-games.mg-flashcard-playing .mg-flashcard-title,
  #page-games.mg-crossword-playing .mg-cw-title,
  #page-games.mg-hm-playing .mg-hm-title,
  #page-games.mg-sl-playing .mg-sl-title,
  #page-games.mg-hm-playing .mg-hm-vip-pill,
  #page-games.mg-sl-playing .mg-sl-vip-pill {
    display: none;
  }

  #page-games.mg-flashcard-playing .mg-flashcard-header,
  #page-games.mg-crossword-playing .mg-cw-topbar,
  #page-games.mg-bs-playing .mg-bs-header,
  #page-games.mg-sj-playing .mg-sj-header,
  #page-games.mg-dj-playing .mg-dj-header,
  #page-games.mg-pa-playing .mg-pa-header,
  #page-games.mg-hm-playing .mg-hm-header,
  #page-games.mg-sl-playing .mg-sl-header {
    display: flex;
    flex-direction: column;
    flex-wrap: wrap;
    align-items: stretch;
    justify-content: flex-start;
    gap: 8px;
    overflow: visible;
    max-height: none;
    width: 100%;
    max-width: 100%;
  }

  #page-games.mg-flashcard-playing .mg-flashcard-header > *,
  #page-games.mg-crossword-playing .mg-cw-topbar > *,
  #page-games.mg-bs-playing .mg-bs-header > *,
  #page-games.mg-sj-playing .mg-sj-header > *,
  #page-games.mg-dj-playing .mg-dj-header > *,
  #page-games.mg-pa-playing .mg-pa-header > *,
  #page-games.mg-hm-playing .mg-hm-header > *,
  #page-games.mg-sl-playing .mg-sl-header > *,
  #page-games .mg-cw-category,
  #page-games .mg-cw-rounds,
  #page-games .mg-flashcard-category,
  #page-games .mg-bs-category,
  #page-games .mg-bs-word-count,
  #page-games .mg-sj-category,
  #page-games .mg-sj-word,
  #page-games .mg-sj-difficulty,
  #page-games .mg-dj-category,
  #page-games .mg-dj-word,
  #page-games .mg-dj-difficulty,
  #page-games .mg-pa-category,
  #page-games .mg-pa-word,
  #page-games .mg-pa-difficulty,
  #page-games .mg-hm-category,
  #page-games .mg-hm-word,
  #page-games .mg-sl-category,
  #page-games.mg-crossword-playing .mg-cw-category-label,
  #page-games.mg-hm-playing .mg-hm-field-label,
  #page-games.mg-hm-playing .mg-hm-word-picker,
  #page-games.mg-flashcard-playing select,
  #page-games.mg-crossword-playing select,
  #page-games.mg-bs-playing select,
  #page-games.mg-sj-playing select,
  #page-games.mg-dj-playing select,
  #page-games.mg-pa-playing select,
  #page-games.mg-hm-playing select,
  #page-games.mg-sl-playing select {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    box-sizing: border-box;
  }

  #page-games .mg-flashcard-start,
  #page-games .mg-cw-restart,
  #page-games .mg-bs-start-btn,
  #page-games .mg-sj-start-btn,
  #page-games .mg-dj-start-btn,
  #page-games .mg-pa-start-btn,
  #page-games .mg-hm-start-btn,
  #page-games .mg-hm-random-btn,
  #page-games .mg-hm-restart-btn,
  #page-games .mg-sl-start {
    display: inline-flex;
    visibility: visible;
    width: 100%;
    max-width: 100%;
    justify-content: center;
    white-space: normal;
  }
}

@media (orientation: landscape) {
  #page-games.mg-flashcard-playing .mg-flashcard-board {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    grid-template-rows: repeat(2, minmax(0, 1fr));
  }

  #page-games.mg-crossword-playing .mg-cw-stage {
    display: grid;
    grid-template-columns: minmax(160px, 34%) minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr);
    overflow: hidden;
  }

  #page-games.mg-crossword-playing .mg-cw-board-area,
  #page-games.mg-crossword-playing .mg-cw-hints {
    height: 100%;
    max-height: 100%;
    min-height: 0;
    overflow: auto;
  }

  #page-games.mg-hm-playing .mg-hm-arena {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(180px, 280px);
  }
}

@media (orientation: portrait) {
  #page-games.mg-flashcard-playing .mg-flashcard-board {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-template-rows: repeat(3, minmax(0, 1fr));
    gap: 8px;
    padding: 0;
  }

  #page-games.mg-crossword-playing .mg-cw-stage,
  #page-games.mg-crossword-playing .mg-cw-stage,
  #page-games.mg-hm-playing .mg-hm-arena,
  #page-games.mg-sl-playing .mg-sl-stage {
    display: flex;
    flex-direction: column;
    gap: 8px;
  }

  #page-games.mg-crossword-playing .mg-cw-board-area,
  #page-games.mg-hm-playing .mg-hm-col-main,
  #page-games.mg-sl-playing .mg-sl-col-board {
    flex: 1 1 auto;
    min-height: 0;
    order: 1;
  }

  #page-games.mg-crossword-playing .mg-cw-hints {
    flex: 0 1 auto;
    max-height: 28dvh;
    overflow: auto;
    order: 2;
  }

  #page-games.mg-hm-playing .mg-hm-river {
    height: auto;
    min-height: 0;
  }
}

@media (max-width: 768px) {
  body:has(#page-games.mg-crossword-playing),
  body:has(#page-games.mg-flashcard-playing) {
    height: auto;
    min-height: 100dvh;
    overflow-x: hidden;
    overflow-y: auto;
  }

  body:has(#page-games.mg-crossword-playing) .app-container,
  body:has(#page-games.mg-flashcard-playing) .app-container {
    height: auto;
    max-height: none;
    overflow: visible;
  }

  #page-games.mg-crossword-playing,
  #page-games.mg-flashcard-playing,
  #page-games.mg-flashcard-playing .mg-flashcard-container,
  #page-games.mg-crossword-playing .mg-crossword-container,
  #page-games.mg-flashcard-playing .mg-flashcard-board,
  #page-games.mg-crossword-playing .mg-cw-stage,
  #page-games.mg-crossword-playing .mg-cw-board-area,
  #page-games.mg-crossword-playing .mg-cw-hints {
    overflow: visible;
    max-height: none;
    height: auto;
    flex: none;
  }

  #page-games.mg-flashcard-playing .mg-flashcard-board {
    display: grid;
    grid-template-columns: 1fr;
    grid-template-rows: none;
    justify-items: center;
  }

  #page-games.mg-card-item {
    width: min(100%, 24rem);
    max-width: 24rem;
    height: auto;
    aspect-ratio: 3 / 4;
  }
}

@media (max-width: 768px) {
  #page-games.mg-hm-playing .mg-hm-arena {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    grid-template-rows: max-content max-content max-content;
    grid-template-areas:
      "lives timer"
      "main main"
      "keys keys";
    align-content: start;
    gap: 8px;
    height: auto;
    max-height: 100%;
    overflow-x: hidden;
    overflow-y: auto;
  }

  #page-games.mg-hm-playing .mg-hm-col-side {
    display: contents;
  }

  #page-games.mg-hm-playing .mg-hm-lives-card {
    grid-area: lives;
  }

  #page-games.mg-hm-playing .mg-hm-timer-card {
    grid-area: timer;
  }

  #page-games.mg-hm-playing .mg-hm-col-main {
    grid-area: main;
    display: flex;
    flex-direction: column;
    gap: 8px;
    height: max-content;
    min-height: max-content;
    flex: 0 0 auto;
    align-self: start;
    overflow: visible;
  }

  #page-games.mg-hm-playing .mg-hm-word-panel {
    display: contents;
  }

  #page-games.mg-hm-playing .mg-hm-target-frame {
    order: 1;
    background: #FFFFFF;
    border: 3px solid #7DD3FC;
    border-radius: 16px;
    padding: 8px;
  }

  #page-games.mg-hm-playing .mg-hm-river {
    order: 2;
    position: relative;
    flex: 0 0 auto;
    width: 100%;
    height: 30vh;
    min-height: 250px;
    flex-shrink: 0;
  }

  #page-games.mg-hm-playing .mg-hm-slots-wrap {
    order: 3;
    background: #FFFFFF;
    border: 3px solid #7DD3FC;
    border-radius: 16px;
    padding: 8px;
  }

  #page-games.mg-hm-playing .mg-hm-keyboard-card {
    grid-area: keys;
  }

  #page-games.mg-hm-playing .mg-hm-target-visual,
  #page-games.mg-hm-playing .mg-hm-target-img {
    max-width: 100%;
    max-height: 120px;
    object-fit: contain;
  }

  #page-games.mg-hm-playing .mg-hm-keyboard {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-content: flex-start;
    gap: 4px;
    grid-template-columns: none;
  }

  #page-games.mg-hm-playing .mg-hm-key {
    width: 34px;
    height: 34px;
    min-width: 0;
    padding: 0;
    font-size: 0.95rem;
  }
}

/* Screen Time mode choice — visible on phone, tablet, and desktop */
#st-mode-modal {
  position: fixed;
  inset: 0;
  z-index: 16000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
  background: rgba(15, 23, 42, 0.55);
}

#st-mode-modal[hidden] {
  display: none !important;
}

#st-mode-modal .st-mode-card {
  width: min(440px, 100%);
  max-height: min(92dvh, 720px);
  display: flex;
  flex-direction: column;
  overflow: auto;
  background: #FFFFFF;
  border-radius: 24px;
  border: 3px solid #FDE68A;
  box-shadow: 0 18px 40px rgba(15, 23, 42, 0.28);
  padding: 22px 18px 18px;
}

#st-mode-modal .st-mode-choose,
#st-mode-modal .st-mode-verify {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 12px;
}

#st-mode-modal .st-mode-choose[hidden],
#st-mode-modal .st-mode-verify[hidden] {
  display: none !important;
}

#st-mode-modal .st-mode-title {
  margin: 0;
  text-align: center;
  font-family: var(--font-th);
  font-size: 1.45rem;
  font-weight: 800;
  color: #0F172A;
}

#st-mode-modal .st-mode-lead,
#st-mode-modal .st-mode-current {
  margin: 0;
  text-align: center;
  font-family: var(--font-th);
  font-weight: 700;
  color: #475569;
}

#st-mode-modal .st-mode-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 52px;
  border: none;
  border-radius: 999px;
  padding: 0.7rem 1rem;
  font-family: var(--font-th);
  font-size: 1rem;
  font-weight: 800;
  cursor: pointer;
}

#st-mode-modal .st-mode-btn-adult {
  color: #FFFFFF;
  background: linear-gradient(135deg, #0284C7 0%, #0369A1 100%);
  box-shadow: 0 4px 0 #075985;
}

#st-mode-modal .st-mode-btn-kids {
  color: #78350F;
  background: linear-gradient(180deg, #FEF9C3 0%, #FACC15 100%);
  box-shadow: 0 4px 0 #CA8A04;
}

#st-mode-modal .st-mode-btn-back {
  color: #475569;
  background: #F1F5F9;
  box-shadow: 0 3px 0 #CBD5E1;
}

#st-mode-modal .st-mode-actions {
  display: flex;
  gap: 8px;
}

#st-mode-modal .st-math-question {
  margin: 0;
  text-align: center;
  font-family: var(--font-en);
  font-size: 2rem;
  font-weight: 800;
  color: #0F172A;
}

#st-mode-modal .st-math-label {
  font-family: var(--font-th);
  font-weight: 700;
  color: #334155;
}

#st-mode-modal .st-math-input {
  width: 100%;
  min-height: 48px;
  border-radius: 14px;
  border: 2px solid #CBD5E1;
  padding: 0.55rem 0.8rem;
  font-family: var(--font-en);
  font-size: 1.3rem;
  font-weight: 700;
  text-align: center;
}

#st-mode-modal .st-math-error {
  margin: 0;
  text-align: center;
  font-family: var(--font-th);
  font-weight: 700;
  color: #BE123C;
}

#page-games .mg-hub-header .st-switch-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  margin: 0.95rem auto 0.15rem;
  min-height: 56px;
  border: 3px solid #ffffff;
  border-radius: 999px;
  padding: 0.7rem 1.4rem;
  font-family: var(--font-th);
  font-size: 1.15rem;
  font-weight: 800;
  line-height: 1.2;
  cursor: pointer;
  color: #ffffff;
  background: linear-gradient(135deg, #fb7185 0%, #a78bfa 55%, #38bdf8 100%);
  box-shadow: 0 6px 0 #7c3aed, 0 12px 24px rgba(124, 58, 237, 0.28);
  white-space: nowrap;
}

#page-games .mg-hub-header .st-switch-badge[hidden] {
  display: none !important;
}

#page-games .mg-hub-header .st-switch-badge.st-switch-kids {
  color: #7c2d12;
  background: linear-gradient(135deg, #fde047 0%, #fb923c 100%);
  box-shadow: 0 6px 0 #c2410c, 0 12px 24px rgba(234, 88, 12, 0.35);
  animation: st-mode-glow 1.6s ease-in-out infinite;
}

#page-games .mg-hub-header .st-switch-badge.st-switch-adult {
  color: #ffffff;
  background: linear-gradient(135deg, #22d3ee 0%, #2563eb 100%);
  box-shadow: 0 6px 0 #1d4ed8, 0 12px 24px rgba(37, 99, 235, 0.32);
  animation: none;
}

@keyframes st-mode-glow {
  0%, 100% { transform: translateY(0) scale(1); }
  50% { transform: translateY(-2px) scale(1.03); }
}

@media (prefers-reduced-motion: reduce) {
  #page-games .mg-hub-header .st-switch-badge.st-switch-kids {
    animation: none;
  }
}

#page-games .st-lock-overlay {
  position: fixed;
  inset: 0;
  z-index: 4500;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(15, 23, 42, 0.62);
}

#page-games .st-lock-overlay[hidden] {
  display: none !important;
}

#page-games .st-lock-card {
  width: min(420px, 100%);
  background: #FFFFFF;
  border-radius: 24px;
  border: 3px solid #FDE68A;
  padding: 22px 18px;
  text-align: center;
}

#page-games .st-lock-message,
#page-games .st-lock-remain {
  font-family: var(--font-th);
  font-weight: 800;
  color: #0F172A;
}

#page-games .st-lock-remain {
  margin-top: 8px;
  font-family: var(--font-en);
  font-size: 2rem;
  color: #B45309;
}

#page-games .st-lock-adult {
  margin-top: 16px;
  border: none;
  border-radius: 999px;
  padding: 0.7rem 1.1rem;
  font-family: var(--font-th);
  font-size: 1rem;
  font-weight: 800;
  cursor: pointer;
  color: #FFFFFF;
  background: linear-gradient(135deg, #0EA5E9 0%, #2563EB 100%);
  box-shadow: 0 4px 0 #1D4ED8;
}

@media (min-width: 768px) and (max-width: 1024px) {
  #st-mode-modal:not([hidden]) {
    display: flex !important;
    visibility: visible !important;
    opacity: 1 !important;
  }

  #st-mode-modal .st-mode-card,
  #st-mode-modal .st-mode-choose:not([hidden]),
  #st-mode-modal .st-mode-verify:not([hidden]),
  #st-mode-modal .st-mode-btn {
    display: flex !important;
    visibility: visible !important;
  }

  #st-mode-modal .st-mode-btn {
    display: inline-flex !important;
  }

  #page-games .mg-hub-header .st-switch-badge:not([hidden]) {
    display: inline-flex !important;
    visibility: visible !important;
  }
}

@media (max-width: 767px) {
  #st-mode-modal:not([hidden]) {
    display: flex !important;
    visibility: visible !important;
    opacity: 1 !important;
  }

  #page-games .mg-hub-header .st-switch-badge:not([hidden]) {
    display: inline-flex !important;
    visibility: visible !important;
    min-height: 48px;
    padding: 0.55rem 1rem;
    font-size: 1rem;
    white-space: normal;
  }

  .main-navbar .bdd-nav-share {
    padding: 0.4rem 0.75rem;
    font-size: 0.78rem;
  }

  .main-navbar .bdd-nav-share-menu {
    left: 0;
    right: auto;
  }

  .main-navbar .bdd-nav-share-line,
  .main-navbar .bdd-nav-share-more {
    font-size: 0.84rem;
  }
}

/* ===================================================================
   PRINT STYLES: BATCH A4 FLASHCARD GENERATION
   =================================================================== */
@media print {
  @page {
    size: A4 portrait;
    margin: 10mm;
  }

  html, body {
    background: #FFFFFF !important;
    color: #000000 !important;
    margin: 0 !important;
    padding: 0 !important;
    width: 100% !important;
    height: auto !important;
    overflow: visible !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  #page-generator .gen-live-category {
    display: none !important;
  }

  /* Hide Header, Navigation, Toolbar, Tips, Toast and other pages */
  #main-navbar,
  .main-navbar,
  .workspace-toolbar,
  .preview-stage-header,
  .preview-footer-tips,
  #fc-btn-back,
  #page-vocab,
  #generator-menu-view,
  #page-games,
  #page-library,
  #app-toast,
  .ambient-glow,
  .floating-stars,
  .floating-bubbles,
  .floating-p-icon,
  .footer-copyright,
  .card-bg-setting-btn,
  #card-bg-popover,
  .card-bg-popover,
  .fc-modal,
  .cw-modal,
  .ws-modal,
  .wm-modal,
  .tr-modal,
  .ps-modal,
  .tt-modal,
  .wb-modal,
  .wu-modal,
  .wst-modal,
  .wd-modal,
  .cp-modal {
    display: none !important;
  }

  /* Reset outer layout wrappers */
  .app-container,
  #page-generator,
  #fc-workspace,
  #fc-preview-panel,
  .workspace-preview,
  .a4-scroll-wrapper {
    display: block !important;
    width: 100% !important;
    max-width: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
    border: none !important;
    box-shadow: none !important;
    background: transparent !important;
    overflow: visible !important;
  }

  /* Format #fc-preview-pages and .fc-page for printing onto real A4 paper */
  #fc-preview-pages {
    display: block !important;
    width: 100% !important;
    max-width: 100% !important;
    min-height: auto !important;
    margin: 0 !important;
    padding: 0 !important;
    gap: 0 !important;
    box-shadow: none !important;
    border: none !important;
    border-radius: 0 !important;
    background: transparent !important;
    overflow: visible !important;
  }

  .fc-page {
    width: 100% !important;
    height: 277mm !important;
    min-height: 0 !important;
    max-height: 277mm !important;
    margin: 0 !important;
    padding: 6mm !important;
    box-shadow: none !important;
    border: none !important;
    border-radius: 0 !important;
    background: #FFFFFF !important;
    page-break-after: always !important;
    break-after: page !important;
    page-break-inside: avoid !important;
    break-inside: avoid !important;
    overflow: hidden !important;
    box-sizing: border-box !important;
  }

  .fc-page:last-child {
    page-break-after: auto !important;
    break-after: auto !important;
    margin-bottom: 0 !important;
  }

  .fc-page-badge {
    display: none !important;
  }

  .fc-page.grid-8 {
    display: grid !important;
    grid-template-columns: repeat(2, 1fr) !important;
    grid-template-rows: repeat(4, 1fr) !important;
    gap: 4mm !important;
  }

  .fc-page.grid-4 {
    display: grid !important;
    grid-template-columns: repeat(2, 1fr) !important;
    grid-template-rows: repeat(2, 1fr) !important;
    gap: 6mm !important;
  }

  /* Cards stay intact without breaking awkwardly across sheets */
  .fc-card {
    display: flex !important;
    flex-direction: column !important;
    box-shadow: none !important;
    border: 1px dashed #718096 !important; /* clear scissors cut border */
    border-radius: 8px !important;
    break-inside: avoid !important;
    page-break-inside: avoid !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  .fc-card .card-image-wrap {
    width: 100% !important;
    height: 75% !important;
    flex: 3 1 75% !important;
    min-height: 0 !important;
  }

  .fc-card .card-word-img {
    width: 100% !important;
    height: 100% !important;
    object-fit: contain !important;
  }

  .fc-card .card-word-group {
    width: 100% !important;
    height: 25% !important;
    flex: 1 1 25% !important;
    min-height: 0 !important;
  }

  /* Hide the workspace that is not the active print target */
  #fc-workspace.hidden,
  #cw-workspace.hidden,
  #ws-workspace.hidden,
  #wm-workspace.hidden,
  #tr-workspace.hidden,
  #ps-workspace.hidden,
  #tt-workspace.hidden,
  #wb-workspace.hidden,
  #wu-workspace.hidden,
  #wst-workspace.hidden,
  #wd-workspace.hidden,
  #generator-menu-view.hidden {
    display: none !important;
  }

  body.print-crossword #fc-workspace,
  body.print-crossword #generator-menu-view,
  body.print-crossword #ws-workspace,
  body.print-crossword #wm-workspace,
  body.print-crossword #tr-workspace,
  body.print-crossword #ps-workspace,
  body.print-crossword #tt-workspace,
  body.print-crossword #wb-workspace,
  body.print-crossword #wu-workspace,
  body.print-crossword #wst-workspace,
  body.print-crossword #wd-workspace,
  body.print-flashcard #cw-workspace,
  body.print-flashcard #ws-workspace,
  body.print-flashcard #wm-workspace,
  body.print-flashcard #tr-workspace,
  body.print-flashcard #ps-workspace,
  body.print-flashcard #tt-workspace,
  body.print-flashcard #wb-workspace,
  body.print-flashcard #wu-workspace,
  body.print-flashcard #wst-workspace,
  body.print-flashcard #wd-workspace,
  body.print-wordsearch #fc-workspace,
  body.print-wordsearch #cw-workspace,
  body.print-wordsearch #generator-menu-view,
  body.print-wordsearch #wm-workspace,
  body.print-wordsearch #tr-workspace,
  body.print-wordsearch #ps-workspace,
  body.print-wordsearch #tt-workspace,
  body.print-wordsearch #wb-workspace,
  body.print-wordsearch #wu-workspace,
  body.print-wordsearch #wst-workspace,
  body.print-wordsearch #wd-workspace,
  body.print-matching #fc-workspace,
  body.print-matching #cw-workspace,
  body.print-matching #ws-workspace,
  body.print-matching #generator-menu-view,
  body.print-matching #tr-workspace,
  body.print-matching #ps-workspace,
  body.print-matching #tt-workspace,
  body.print-matching #wb-workspace,
  body.print-matching #wu-workspace,
  body.print-matching #wst-workspace,
  body.print-matching #wd-workspace,
  body.print-tracing #fc-workspace,
  body.print-tracing #cw-workspace,
  body.print-tracing #ws-workspace,
  body.print-tracing #wm-workspace,
  body.print-tracing #ps-workspace,
  body.print-tracing #tt-workspace,
  body.print-tracing #wb-workspace,
  body.print-tracing #wu-workspace,
  body.print-tracing #wst-workspace,
  body.print-tracing #wd-workspace,
  body.print-tracing #generator-menu-view,
  body.print-picture-story #fc-workspace,
  body.print-picture-story #cw-workspace,
  body.print-picture-story #ws-workspace,
  body.print-picture-story #wm-workspace,
  body.print-picture-story #tr-workspace,
  body.print-picture-story #tt-workspace,
  body.print-picture-story #wb-workspace,
  body.print-picture-story #wu-workspace,
  body.print-picture-story #wst-workspace,
  body.print-picture-story #wd-workspace,
  body.print-picture-story #generator-menu-view,
  body.print-telling-time #fc-workspace,
  body.print-telling-time #cw-workspace,
  body.print-telling-time #ws-workspace,
  body.print-telling-time #wm-workspace,
  body.print-telling-time #tr-workspace,
  body.print-telling-time #ps-workspace,
  body.print-telling-time #wb-workspace,
  body.print-telling-time #wu-workspace,
  body.print-telling-time #wst-workspace,
  body.print-telling-time #wd-workspace,
  body.print-telling-time #generator-menu-view,
  body.print-word-bank #fc-workspace,
  body.print-word-bank #cw-workspace,
  body.print-word-bank #ws-workspace,
  body.print-word-bank #wm-workspace,
  body.print-word-bank #tr-workspace,
  body.print-word-bank #ps-workspace,
  body.print-word-bank #tt-workspace,
  body.print-word-bank #wu-workspace,
  body.print-word-bank #wst-workspace,
  body.print-word-bank #wd-workspace,
  body.print-word-bank #generator-menu-view,
  body.print-word-unscramble #fc-workspace,
  body.print-word-unscramble #cw-workspace,
  body.print-word-unscramble #ws-workspace,
  body.print-word-unscramble #wm-workspace,
  body.print-word-unscramble #tr-workspace,
  body.print-word-unscramble #ps-workspace,
  body.print-word-unscramble #tt-workspace,
  body.print-word-unscramble #wb-workspace,
  body.print-word-unscramble #wst-workspace,
  body.print-word-unscramble #wd-workspace,
  body.print-word-unscramble #generator-menu-view,
  body.print-word-sorting #fc-workspace,
  body.print-word-sorting #cw-workspace,
  body.print-word-sorting #ws-workspace,
  body.print-word-sorting #wm-workspace,
  body.print-word-sorting #tr-workspace,
  body.print-word-sorting #ps-workspace,
  body.print-word-sorting #tt-workspace,
  body.print-word-sorting #wb-workspace,
  body.print-word-sorting #wu-workspace,
  body.print-word-sorting #wd-workspace,
  body.print-word-sorting #generator-menu-view,
  body.print-word-dominoes #fc-workspace,
  body.print-word-dominoes #cw-workspace,
  body.print-word-dominoes #ws-workspace,
  body.print-word-dominoes #wm-workspace,
  body.print-word-dominoes #tr-workspace,
  body.print-word-dominoes #ps-workspace,
  body.print-word-dominoes #tt-workspace,
  body.print-word-dominoes #wb-workspace,
  body.print-word-dominoes #wu-workspace,
  body.print-word-dominoes #wst-workspace,
  body.print-word-dominoes #generator-menu-view,
  body.print-flashcard #cp-workspace,
  body.print-crossword #cp-workspace,
  body.print-wordsearch #cp-workspace,
  body.print-matching #cp-workspace,
  body.print-tracing #cp-workspace,
  body.print-picture-story #cp-workspace,
  body.print-telling-time #cp-workspace,
  body.print-word-bank #cp-workspace,
  body.print-word-unscramble #cp-workspace,
  body.print-word-sorting #cp-workspace,
  body.print-word-dominoes #cp-workspace,
  body.print-coloring-page #fc-workspace,
  body.print-coloring-page #cw-workspace,
  body.print-coloring-page #ws-workspace,
  body.print-coloring-page #wm-workspace,
  body.print-coloring-page #tr-workspace,
  body.print-coloring-page #ps-workspace,
  body.print-coloring-page #tt-workspace,
  body.print-coloring-page #wb-workspace,
  body.print-coloring-page #wu-workspace,
  body.print-coloring-page #wst-workspace,
  body.print-coloring-page #wd-workspace,
  body.print-coloring-page #generator-menu-view {
    display: none !important;
  }

  body.print-coloring-page .bg-decorations,
  body.print-coloring-page #cp-workspace .preview-footer-tips,
  body.print-coloring-page #cp-workspace .cp-toolbar-actions,
  body.print-coloring-page #cp-workspace .cp-modal,
  body.print-coloring-page #cp-workspace .cp-art-empty {
    display: none !important;
  }

  body.print-coloring-page .app-container,
  body.print-coloring-page #page-generator,
  body.print-coloring-page #cp-workspace,
  body.print-coloring-page #cp-workspace .workspace-preview,
  body.print-coloring-page #cp-workspace .a4-scroll-wrapper,
  body.print-coloring-page #cp-workspace .cp-pages {
    display: block !important;
    width: 100% !important;
    max-width: 100% !important;
    height: auto !important;
    max-height: none !important;
    margin: 0 !important;
    padding: 0 !important;
    background: transparent !important;
    box-shadow: none !important;
    overflow: visible !important;
    gap: 0 !important;
  }

  body.print-coloring-page #cp-workspace .cp-sheet {
    display: flex !important;
    flex-direction: column !important;
    box-sizing: border-box !important;
    width: 100% !important;
    height: 277mm !important;
    min-height: 0 !important;
    max-height: 277mm !important;
    margin: 0 !important;
    padding: 4mm 5mm !important;
    gap: 3mm !important;
    box-shadow: none !important;
    border-radius: 0 !important;
    overflow: hidden !important;
    page-break-after: auto !important;
    break-after: auto !important;
    page-break-inside: avoid !important;
    break-inside: avoid !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  body.print-coloring-page #cp-workspace .cp-title,
  body.print-coloring-page #cp-workspace .cp-instruction,
  body.print-coloring-page #cp-workspace .cp-header-logo,
  body.print-coloring-page #cp-workspace .cp-art-img {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  body.print-coloring-page #cp-workspace .cp-logo-slot[hidden] {
    display: none !important;
    width: 0 !important;
    height: 0 !important;
  }

  body.print-crossword #cw-workspace,
  body.print-crossword #cw-workspace .workspace-preview,
  body.print-crossword #cw-workspace .a4-scroll-wrapper,
  body.print-crossword #cw-workspace .cw-pages {
    display: block !important;
    width: 100% !important;
    max-width: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
    gap: 0 !important;
    background: transparent !important;
    box-shadow: none !important;
    overflow: visible !important;
  }

  body.print-crossword .cw-sheet,
  body.print-crossword .cw-body,
  body.print-crossword .cw-clues-panel,
  body.print-crossword .cw-grid-col {
    page-break-inside: avoid !important;
    break-inside: avoid !important;
  }

  body.print-crossword .cw-sheet {
    display: flex !important;
    flex-direction: column !important;
    box-sizing: border-box !important;
    width: 100% !important;
    height: 277mm !important;
    min-height: 0 !important;
    max-height: 277mm !important;
    aspect-ratio: auto !important;
    margin: 0 !important;
    padding: 0 !important;
    gap: 3mm !important;
    box-shadow: none !important;
    border-radius: 0 !important;
    overflow: hidden !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  body.print-crossword .cw-answer-sheet {
    page-break-before: always !important;
    break-before: page !important;
    background: #FFFFFF !important;
    background-image: none !important;
  }

  body.print-crossword .cw-header {
    flex: 0 0 auto !important;
    flex-shrink: 0 !important;
    max-height: 20mm !important;
    overflow: hidden !important;
  }

  body.print-crossword #cw-workspace .cw-header-logo {
    max-width: 16mm !important;
    max-height: 16mm !important;
  }

  body.print-crossword #cw-workspace .cw-logo-slot[hidden] {
    display: none !important;
    width: 0 !important;
    height: 0 !important;
  }

  body.print-crossword .cw-body {
    flex: 0 0 auto !important;
    display: flex !important;
    flex-direction: column !important;
    gap: 3mm !important;
    min-height: 0 !important;
    height: auto !important;
    overflow: hidden !important;
  }

  body.print-crossword .cw-clues-panel {
    flex: 0 0 100mm !important;
    height: 100mm !important;
    max-height: 100mm !important;
    min-height: 0 !important;
    width: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow: hidden !important;
    display: flex !important;
    flex-direction: row !important;
    flex-wrap: wrap !important;
    justify-content: center !important;
    align-items: center !important;
    align-content: center !important;
    gap: 4mm !important;
  }

  body.print-crossword .cw-clue-col {
    max-width: 100% !important;
    max-height: 100% !important;
    overflow: hidden !important;
  }

  body.print-crossword .cw-clue-col h3 {
    display: block !important;
    position: static !important;
    width: 100% !important;
    margin: 0 0 2mm !important;
    text-align: center !important;
    line-height: 1.2 !important;
  }

  body.print-crossword .cw-clue-list {
    display: flex !important;
    flex-wrap: wrap !important;
    justify-content: center !important;
    align-items: center !important;
    align-content: center !important;
    gap: 2.5mm !important;
    overflow: hidden !important;
    max-height: 100% !important;
  }

  body.print-crossword .cw-clue {
    position: relative !important;
    flex: 0 0 auto !important;
    width: auto !important;
    height: auto !important;
    max-width: none !important;
    max-height: none !important;
    margin: 0 !important;
    padding: 1.2mm 1.5mm 1.5mm !important;
    box-sizing: border-box !important;
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
    justify-content: flex-start !important;
    gap: 0.8mm !important;
    background: #FFFFFF !important;
    border: 1.2px solid #1E293B !important;
    border-radius: 6px !important;
    box-shadow: none !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  body.print-crossword .cw-clue-num {
    align-self: flex-start !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    min-width: 5mm !important;
    height: 5mm !important;
    padding: 0 1.4mm !important;
    box-sizing: border-box !important;
    border-radius: 999px !important;
    background: #FEF3C7 !important;
    border: 1.2px solid #111827 !important;
    color: #111827 !important;
    font-family: var(--font-en) !important;
    font-size: 9pt !important;
    font-weight: 800 !important;
    line-height: 1 !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  body.print-crossword .cw-clue img {
    display: block !important;
    width: 21mm !important;
    height: 21mm !important;
    max-width: 21mm !important;
    max-height: 21mm !important;
    margin: 0 !important;
    object-fit: contain !important;
    background: transparent !important;
    box-shadow: none !important;
  }

  body.print-crossword .cw-grid-col {
    flex: 0 0 150mm !important;
    height: 150mm !important;
    max-height: 150mm !important;
    min-height: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
    overflow: hidden !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
  }

  body.print-crossword .cw-grid {
    --cw-cell: min(calc(186mm / var(--cw-cols)), calc(146mm / var(--cw-rows))) !important;
    width: calc(var(--cw-cell) * var(--cw-cols)) !important;
    height: calc(var(--cw-cell) * var(--cw-rows)) !important;
    max-width: 100% !important;
    max-height: 100% !important;
    margin: auto !important;
    overflow: hidden !important;
  }

  body.print-crossword .cw-answer-sheet .cw-bg-layer {
    display: none !important;
  }

  body.print-crossword .cw-bg-layer {
    opacity: 0.18 !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  .cw-cell {
    background: #FFFFFF !important;
    border-color: #111111 !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  .cw-cell.is-block {
    background: transparent !important;
    border-color: transparent !important;
  }

  body.print-wordsearch .bg-decorations,
  body.print-wordsearch #ws-workspace .preview-footer-tips,
  body.print-wordsearch #ws-workspace .ws-toolbar-actions,
  body.print-wordsearch #ws-workspace .ws-modal {
    display: none !important;
  }

  body.print-wordsearch .app-container,
  body.print-wordsearch #page-generator,
  body.print-wordsearch #ws-workspace,
  body.print-wordsearch #ws-workspace .workspace-preview,
  body.print-wordsearch #ws-workspace .a4-scroll-wrapper,
  body.print-wordsearch #ws-workspace .ws-pages {
    display: block !important;
    width: 100% !important;
    max-width: 100% !important;
    height: auto !important;
    max-height: none !important;
    margin: 0 !important;
    padding: 0 !important;
    background: transparent !important;
    box-shadow: none !important;
    overflow: visible !important;
    gap: 0 !important;
  }

  body.print-wordsearch #ws-workspace .ws-sheet {
    display: flex !important;
    flex-direction: column !important;
    box-sizing: border-box !important;
    width: 100% !important;
    height: 270mm !important;
    min-height: 0 !important;
    max-height: 270mm !important;
    margin: 0 !important;
    padding: 4mm 5mm !important;
    gap: 2mm !important;
    box-shadow: none !important;
    border-radius: 0 !important;
    overflow: hidden !important;
    page-break-inside: avoid !important;
    break-inside: avoid !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  body.print-wordsearch #ws-workspace .ws-answer-sheet {
    page-break-before: always !important;
    break-before: page !important;
    background: #FFFFFF !important;
    background-image: none !important;
  }

  body.print-wordsearch #ws-workspace .ws-answer-sheet .ws-bg-layer {
    display: none !important;
  }

  body.print-wordsearch #ws-workspace .ws-bg-layer {
    opacity: 0.18 !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  body.print-wordsearch #ws-workspace .ws-grid {
    --ws-cell: 12.2mm !important;
  }

  body.print-wordsearch #ws-workspace .ws-cell,
  body.print-wordsearch #ws-workspace .ws-pill {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  body.print-wordsearch #ws-workspace .ws-answer-sheet .ws-cell {
    background: #FFFFFF !important;
  }

  body.print-matching .bg-decorations,
  body.print-matching #wm-workspace .preview-footer-tips,
  body.print-matching #wm-workspace .wm-toolbar-actions,
  body.print-matching #wm-workspace .wm-modal {
    display: none !important;
  }

  body.print-matching .app-container,
  body.print-matching #page-generator,
  body.print-matching #wm-workspace,
  body.print-matching #wm-workspace .workspace-preview,
  body.print-matching #wm-workspace .a4-scroll-wrapper,
  body.print-matching #wm-workspace .wm-pages {
    display: block !important;
    width: 100% !important;
    max-width: 100% !important;
    height: auto !important;
    max-height: none !important;
    margin: 0 !important;
    padding: 0 !important;
    background: transparent !important;
    box-shadow: none !important;
    overflow: visible !important;
    gap: 0 !important;
  }

  body.print-matching #wm-workspace .wm-sheet {
    display: flex !important;
    flex-direction: column !important;
    box-sizing: border-box !important;
    width: 100% !important;
    height: 270mm !important;
    min-height: 0 !important;
    max-height: 270mm !important;
    margin: 0 !important;
    padding: 4mm 5mm !important;
    gap: 2mm !important;
    box-shadow: none !important;
    border-radius: 0 !important;
    overflow: hidden !important;
    page-break-inside: avoid !important;
    break-inside: avoid !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  body.print-matching #wm-workspace .wm-answer-sheet {
    page-break-before: always !important;
    break-before: page !important;
    background: #FFFFFF !important;
    background-image: none !important;
  }

  body.print-matching #wm-workspace .wm-answer-sheet .wm-bg-layer {
    display: none !important;
  }

  body.print-matching #wm-workspace .wm-bg-layer {
    opacity: 0.18 !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  body.print-matching #wm-workspace .wm-lines line,
  body.print-matching #wm-workspace .wm-blank-fill,
  body.print-matching #wm-workspace .wm-anchor {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  body.print-tracing .bg-decorations,
  body.print-tracing #tr-workspace .preview-footer-tips,
  body.print-tracing #tr-workspace .tr-toolbar-actions,
  body.print-tracing #tr-workspace .tr-modal {
    display: none !important;
  }

  body.print-tracing .app-container,
  body.print-tracing #page-generator,
  body.print-tracing #tr-workspace,
  body.print-tracing #tr-workspace .workspace-preview,
  body.print-tracing #tr-workspace .a4-scroll-wrapper,
  body.print-tracing #tr-workspace .tr-pages {
    display: block !important;
    width: 100% !important;
    max-width: 100% !important;
    height: auto !important;
    max-height: none !important;
    margin: 0 !important;
    padding: 0 !important;
    background: transparent !important;
    box-shadow: none !important;
    overflow: visible !important;
    gap: 0 !important;
  }

  body.print-tracing #tr-workspace .tr-sheet {
    display: flex !important;
    flex-direction: column !important;
    box-sizing: border-box !important;
    width: 100% !important;
    height: 270mm !important;
    min-height: 0 !important;
    max-height: 270mm !important;
    margin: 0 !important;
    padding: 4mm 5mm !important;
    gap: 2mm !important;
    box-shadow: none !important;
    border-radius: 0 !important;
    overflow: hidden !important;
    page-break-after: always !important;
    break-after: page !important;
    page-break-inside: avoid !important;
    break-inside: avoid !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  body.print-tracing #tr-workspace .tr-sheet:last-child {
    page-break-after: auto !important;
    break-after: auto !important;
  }

  body.print-tracing #tr-workspace .tr-title.tr-heading-hidden,
  body.print-tracing #tr-workspace .tr-instruction.tr-heading-hidden {
    display: none !important;
  }

  body.print-tracing #tr-workspace .tr-title {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  body.print-tracing #tr-workspace .tr-bg-layer,
  body.print-tracing #tr-workspace .tr-glyph,
  body.print-tracing #tr-workspace .tr-rule {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  body.print-tracing #tr-workspace .tr-bg-layer {
    opacity: 0.16 !important;
  }

  body.print-picture-story .bg-decorations,
  body.print-picture-story #ps-workspace .preview-footer-tips,
  body.print-picture-story #ps-workspace .ps-toolbar-actions,
  body.print-picture-story #ps-workspace .ps-modal,
  body.print-picture-story #ps-workspace .ps-item-delete-btn,
  body.print-picture-story #ps-workspace .ps-item-flip-btn,
  body.print-picture-story #ps-workspace .ps-item-handle,
  body.print-picture-story #ps-workspace .ps-item-rotate-handle,
  body.print-picture-story #ps-workspace .ps-item-rotate-stem,
  body.print-picture-story #ps-workspace .ps-canvas-empty-hint {
    display: none !important;
  }

  body.print-picture-story .app-container,
  body.print-picture-story #page-generator,
  body.print-picture-story #ps-workspace,
  body.print-picture-story #ps-workspace .workspace-preview,
  body.print-picture-story #ps-workspace .a4-scroll-wrapper,
  body.print-picture-story #ps-workspace .ps-pages {
    display: block !important;
    width: 100% !important;
    max-width: 100% !important;
    height: auto !important;
    max-height: none !important;
    margin: 0 !important;
    padding: 0 !important;
    background: transparent !important;
    box-shadow: none !important;
    overflow: visible !important;
    gap: 0 !important;
  }

  body.print-picture-story #ps-workspace .ps-sheet {
    display: flex !important;
    flex-direction: column !important;
    box-sizing: border-box !important;
    width: 100% !important;
    height: 277mm !important;
    min-height: 0 !important;
    max-height: 277mm !important;
    margin: 0 !important;
    padding: 4mm 5mm !important;
    gap: 3mm !important;
    box-shadow: none !important;
    border-radius: 0 !important;
    overflow: hidden !important;
    page-break-after: auto !important;
    break-after: auto !important;
    page-break-inside: avoid !important;
    break-inside: avoid !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  body.print-picture-story #ps-workspace .ps-scene-item {
    border: none !important;
    background: transparent !important;
    box-shadow: none !important;
  }

  body.print-picture-story #ps-workspace .ps-scene-bg.is-bw {
    filter: grayscale(1) contrast(0.72) brightness(1.36) !important;
    opacity: 0.42 !important;
  }

  body.print-picture-story #ps-workspace .ps-scene-bg,
  body.print-picture-story #ps-workspace .ps-scene-bg.is-bw,
  body.print-picture-story #ps-workspace .ps-scene-item-img,
  body.print-picture-story #ps-workspace .ps-title,
  body.print-picture-story #ps-workspace .ps-instruction,
  body.print-picture-story #ps-workspace .ps-header-logo,
  body.print-picture-story #ps-workspace .ps-rule {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  body.print-telling-time .bg-decorations,
  body.print-telling-time #tt-workspace .preview-footer-tips,
  body.print-telling-time #tt-workspace .tt-toolbar-actions,
  body.print-telling-time #tt-workspace .tt-modal {
    display: none !important;
  }

  body.print-telling-time .app-container,
  body.print-telling-time #page-generator,
  body.print-telling-time #tt-workspace,
  body.print-telling-time #tt-workspace .workspace-preview,
  body.print-telling-time #tt-workspace .a4-scroll-wrapper,
  body.print-telling-time #tt-workspace .tt-pages {
    display: block !important;
    width: 100% !important;
    max-width: 100% !important;
    height: auto !important;
    max-height: none !important;
    margin: 0 !important;
    padding: 0 !important;
    background: transparent !important;
    box-shadow: none !important;
    overflow: visible !important;
    gap: 0 !important;
  }

  body.print-telling-time #tt-workspace .tt-sheet {
    display: flex !important;
    flex-direction: column !important;
    box-sizing: border-box !important;
    width: 100% !important;
    height: 277mm !important;
    min-height: 0 !important;
    max-height: 277mm !important;
    margin: 0 !important;
    padding: 4mm 5mm !important;
    gap: 3mm !important;
    box-shadow: none !important;
    border-radius: 0 !important;
    overflow: hidden !important;
    page-break-after: auto !important;
    break-after: auto !important;
    page-break-inside: avoid !important;
    break-inside: avoid !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  body.print-telling-time #tt-workspace .tt-clock-svg-wrap {
    width: 114mm !important;
    height: 114mm !important;
  }

  body.print-telling-time #tt-workspace .tt-title,
  body.print-telling-time #tt-workspace .tt-instruction,
  body.print-telling-time #tt-workspace .tt-header-logo,
  body.print-telling-time #tt-workspace .tt-clock-svg,
  body.print-telling-time #tt-workspace .tt-reading-panel,
  body.print-telling-time #tt-workspace .tt-rule,
  body.print-telling-time #tt-workspace .tt-line-trace-text {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  body.print-word-bank .bg-decorations,
  body.print-word-bank #wb-workspace .preview-footer-tips,
  body.print-word-bank #wb-workspace .wb-toolbar-actions,
  body.print-word-bank #wb-workspace .wb-modal {
    display: none !important;
  }

  body.print-word-bank .app-container,
  body.print-word-bank #page-generator,
  body.print-word-bank #wb-workspace,
  body.print-word-bank #wb-workspace .workspace-preview,
  body.print-word-bank #wb-workspace .a4-scroll-wrapper,
  body.print-word-bank #wb-workspace .wb-pages {
    display: block !important;
    width: 100% !important;
    max-width: 100% !important;
    height: auto !important;
    max-height: none !important;
    margin: 0 !important;
    padding: 0 !important;
    background: transparent !important;
    box-shadow: none !important;
    overflow: visible !important;
    gap: 0 !important;
  }

  body.print-word-bank #wb-workspace .wb-sheet {
    display: flex !important;
    flex-direction: column !important;
    box-sizing: border-box !important;
    width: 100% !important;
    height: 277mm !important;
    min-height: 0 !important;
    max-height: 277mm !important;
    margin: 0 !important;
    padding: 4mm 5mm !important;
    gap: 3mm !important;
    box-shadow: none !important;
    border-radius: 0 !important;
    overflow: hidden !important;
    page-break-after: auto !important;
    break-after: auto !important;
    page-break-inside: avoid !important;
    break-inside: avoid !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  body.print-word-bank #wb-workspace .wb-title,
  body.print-word-bank #wb-workspace .wb-instruction,
  body.print-word-bank #wb-workspace .wb-header-logo,
  body.print-word-bank #wb-workspace .wb-wordbank-box,
  body.print-word-bank #wb-workspace .wb-wordbank-chip,
  body.print-word-bank #wb-workspace .wb-item-card,
  body.print-word-bank #wb-workspace .wb-item-number,
  body.print-word-bank #wb-workspace .wb-item-image,
  body.print-word-bank #wb-workspace .wb-answer-box,
  body.print-word-bank #wb-workspace .wb-rule {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  body.print-word-unscramble .bg-decorations,
  body.print-word-unscramble #wu-workspace .preview-footer-tips,
  body.print-word-unscramble #wu-workspace .wu-toolbar-actions,
  body.print-word-unscramble #wu-workspace .wu-modal {
    display: none !important;
  }

  body.print-word-unscramble .app-container,
  body.print-word-unscramble #page-generator,
  body.print-word-unscramble #wu-workspace,
  body.print-word-unscramble #wu-workspace .workspace-preview,
  body.print-word-unscramble #wu-workspace .a4-scroll-wrapper,
  body.print-word-unscramble #wu-workspace .wu-pages {
    display: block !important;
    width: 100% !important;
    max-width: 100% !important;
    height: auto !important;
    max-height: none !important;
    margin: 0 !important;
    padding: 0 !important;
    background: transparent !important;
    box-shadow: none !important;
    overflow: visible !important;
    gap: 0 !important;
  }

  body.print-word-unscramble #wu-workspace .wu-sheet {
    display: flex !important;
    flex-direction: column !important;
    box-sizing: border-box !important;
    width: 100% !important;
    height: 277mm !important;
    min-height: 0 !important;
    max-height: 277mm !important;
    margin: 0 !important;
    padding: 4mm 5mm !important;
    gap: 3mm !important;
    box-shadow: none !important;
    border-radius: 0 !important;
    overflow: hidden !important;
    page-break-after: auto !important;
    break-after: auto !important;
    page-break-inside: avoid !important;
    break-inside: avoid !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  body.print-word-unscramble #wu-workspace .wu-title,
  body.print-word-unscramble #wu-workspace .wu-instruction,
  body.print-word-unscramble #wu-workspace .wu-header-logo,
  body.print-word-unscramble #wu-workspace .wu-row,
  body.print-word-unscramble #wu-workspace .wu-item-number,
  body.print-word-unscramble #wu-workspace .wu-item-image,
  body.print-word-unscramble #wu-workspace .wu-col-middle,
  body.print-word-unscramble #wu-workspace .wu-scrambled-word,
  body.print-word-unscramble #wu-workspace .wu-rule,
  body.print-word-unscramble #wu-workspace .wu-single-line {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  body.print-word-sorting .bg-decorations,
  body.print-word-sorting #wst-workspace .preview-footer-tips,
  body.print-word-sorting #wst-workspace .wst-toolbar-actions,
  body.print-word-sorting #wst-workspace .wst-modal {
    display: none !important;
  }

  body.print-word-sorting .app-container,
  body.print-word-sorting #page-generator,
  body.print-word-sorting #wst-workspace,
  body.print-word-sorting #wst-workspace .workspace-preview,
  body.print-word-sorting #wst-workspace .a4-scroll-wrapper,
  body.print-word-sorting #wst-workspace .wst-pages {
    display: block !important;
    width: 100% !important;
    max-width: 100% !important;
    height: auto !important;
    max-height: none !important;
    margin: 0 !important;
    padding: 0 !important;
    background: transparent !important;
    box-shadow: none !important;
    overflow: visible !important;
    gap: 0 !important;
  }

  body.print-word-sorting #wst-workspace .wst-sheet {
    display: flex !important;
    flex-direction: column !important;
    box-sizing: border-box !important;
    width: 100% !important;
    height: 277mm !important;
    min-height: 0 !important;
    max-height: 277mm !important;
    margin: 0 !important;
    padding: 4mm 5mm !important;
    gap: 3mm !important;
    box-shadow: none !important;
    border-radius: 0 !important;
    overflow: hidden !important;
    page-break-after: auto !important;
    break-after: auto !important;
    page-break-inside: avoid !important;
    break-inside: avoid !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  body.print-word-sorting #wst-workspace .wst-title,
  body.print-word-sorting #wst-workspace .wst-instruction,
  body.print-word-sorting #wst-workspace .wst-header-logo,
  body.print-word-sorting #wst-workspace .wst-category-box,
  body.print-word-sorting #wst-workspace .wst-category-header,
  body.print-word-sorting #wst-workspace .wst-category-title,
  body.print-word-sorting #wst-workspace .wst-write-line,
  body.print-word-sorting #wst-workspace .wst-sort-item,
  body.print-word-sorting #wst-workspace .wst-scissors-badge,
  body.print-word-sorting #wst-workspace .wst-item-image,
  body.print-word-sorting #wst-workspace .wst-item-label {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  body.print-word-dominoes .bg-decorations,
  body.print-word-dominoes #wd-workspace .preview-footer-tips,
  body.print-word-dominoes #wd-workspace .wd-toolbar-actions,
  body.print-word-dominoes #wd-workspace .wd-modal,
  body.print-word-dominoes #wd-workspace .wd-page-badge {
    display: none !important;
  }

  body.print-word-dominoes .app-container,
  body.print-word-dominoes #page-generator,
  body.print-word-dominoes #wd-workspace,
  body.print-word-dominoes #wd-workspace .workspace-preview,
  body.print-word-dominoes #wd-workspace .a4-scroll-wrapper,
  body.print-word-dominoes #wd-workspace .wd-pages {
    display: block !important;
    width: 100% !important;
    max-width: 100% !important;
    height: auto !important;
    max-height: none !important;
    margin: 0 !important;
    padding: 0 !important;
    background: transparent !important;
    box-shadow: none !important;
    overflow: visible !important;
    gap: 0 !important;
  }

  body.print-word-dominoes #wd-workspace .wd-sheet {
    display: flex !important;
    flex-direction: column !important;
    box-sizing: border-box !important;
    width: 100% !important;
    height: 277mm !important;
    min-height: 0 !important;
    max-height: 277mm !important;
    margin: 0 !important;
    padding: 4mm 5mm !important;
    gap: 3mm !important;
    box-shadow: none !important;
    border-radius: 0 !important;
    overflow: hidden !important;
    page-break-after: always !important;
    break-after: page !important;
    page-break-inside: avoid !important;
    break-inside: avoid !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  body.print-word-dominoes #wd-workspace .wd-sheet:last-child {
    page-break-after: auto !important;
    break-after: auto !important;
  }

  body.print-word-dominoes #wd-workspace .wd-tile,
  body.print-word-dominoes #wd-workspace .wd-tile-inner,
  body.print-word-dominoes #wd-workspace .wd-tile-half {
    page-break-inside: avoid !important;
    break-inside: avoid !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  body.print-word-dominoes #wd-workspace .wd-title,
  body.print-word-dominoes #wd-workspace .wd-instruction,
  body.print-word-dominoes #wd-workspace .wd-header-logo,
  body.print-word-dominoes #wd-workspace .wd-terminal-badge,
  body.print-word-dominoes #wd-workspace .wd-badge-start,
  body.print-word-dominoes #wd-workspace .wd-badge-finish,
  body.print-word-dominoes #wd-workspace .wd-word-text,
  body.print-word-dominoes #wd-workspace .wd-tile-image {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }
}

/* ===================================================================
   Snakes & Ladders — 5×5 board, tight two-column play layout
   Scoped to #page-games so other pages stay unchanged.
   =================================================================== */

#page-games .mg-sl-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 8px;
  background: #FFFFFF;
  border: 2px solid #FDE68A;
  border-radius: 16px;
  padding: 6px 10px;
  box-shadow: 0 4px 12px rgba(120, 80, 20, 0.08);
}

#page-games .mg-sl-back,
#page-games .mg-sl-start,
#page-games .mg-sl-restart,
#page-games .mg-sl-roll,
#page-games .mg-sl-again,
#page-games .mg-sl-bgm {
  font-family: var(--font-th);
  font-weight: 800;
  cursor: pointer;
  border-radius: var(--radius-pill);
}

#page-games .mg-sl-back {
  border: 1.5px solid #FDE68A;
  background: #FFFBEB;
  color: #92400E;
  font-size: 0.86rem;
  padding: 0.32rem 0.75rem;
}

#page-games .mg-sl-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-right: auto;
  min-width: 0;
}

#page-games .mg-sl-vip-pill {
  padding: 0.16rem 0.55rem;
  border-radius: 999px;
  background: linear-gradient(135deg, #FEF08A 0%, #F59E0B 100%);
  color: #78350F;
  font-family: var(--font-en);
  font-size: 0.72rem;
  font-weight: 800;
}

#page-games .mg-sl-title {
  margin: 0;
  font-family: var(--font-en);
  font-size: 1.15rem;
  font-weight: 700;
  color: #1E293B;
}

#page-games .mg-sl-field-label {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  font-family: var(--font-th);
  font-size: 0.82rem;
  font-weight: 700;
  color: #475569;
}

#page-games .mg-sl-category {
  font-family: var(--font-th);
  font-size: 0.86rem;
  font-weight: 700;
  color: #1E293B;
  background: #F8FAFC;
  border: 1.5px solid #CBD5E1;
  border-radius: 12px;
  padding: 0.32rem 0.5rem;
  max-width: 220px;
}

#page-games .mg-sl-start {
  border: none;
  color: #FFFFFF;
  background: linear-gradient(135deg, #22C55E 0%, #16A34A 100%);
  font-size: 0.88rem;
  padding: 0.36rem 0.9rem;
  box-shadow: 0 3px 0 #15803D;
}

#page-games .mg-sl-timer-card {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  background: #ECFEFF;
  border: 1.5px solid #A5F3FC;
  font-family: var(--font-th);
  font-size: 0.8rem;
  font-weight: 700;
  color: #0F766E;
  white-space: nowrap;
}

#page-games .mg-sl-timer-value {
  font-variant-numeric: tabular-nums;
}

#page-games .mg-sl-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

#page-games .mg-sl-bgm {
  width: 36px;
  height: 36px;
  border: none;
  background: #ECFEFF;
  font-size: 1.05rem;
  padding: 0;
}

#page-games .mg-sl-bgm[aria-pressed="true"] {
  background: #E2E8F0;
}

#page-games .mg-sl-restart {
  border: none;
  color: #FFFFFF;
  background: linear-gradient(135deg, #FF7B90 0%, #FF4D6D 100%);
  font-size: 0.84rem;
  padding: 0.34rem 0.75rem;
  box-shadow: 0 3px 0 #E11D48;
  white-space: nowrap;
}

#page-games.mg-sl-playing .mg-sl-container {
  gap: 6px;
  max-width: 1100px;
}

#page-games.mg-sl-playing .mg-sl-stage {
  display: flex;
  flex-direction: row;
  justify-content: center;
  align-items: stretch;
  gap: 8px;
  width: 100%;
  max-width: 100%;
  height: 100%;
  margin-inline: auto;
  padding: 8px;
  border-radius: 20px;
  background: linear-gradient(180deg, #ECFDF5 0%, #D1FAE5 100%);
  box-shadow: inset 0 0 0 3px rgba(255, 255, 255, 0.7);
  overflow: hidden;
  container-type: size;
}

#page-games.mg-sl-playing .mg-sl-col-board,
#page-games.mg-sl-playing .mg-sl-col-panel {
  overflow: hidden;
}

#page-games.mg-sl-playing .mg-sl-col-board {
  flex: 0 0 auto;
  width: min(calc(100cqh - 40px), calc(100cqw - 284px));
  max-width: 100%;
  min-width: 0;
  min-height: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: flex-start;
  gap: 4px;
}

#page-games .mg-sl-board-head {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-shrink: 0;
  font-family: var(--font-th);
  font-size: 0.82rem;
  font-weight: 700;
  color: #14532D;
}

#page-games .mg-sl-pos strong {
  font-size: 1rem;
}

#page-games.mg-sl-playing .mg-sl-board-frame {
  flex: 0 0 auto;
  align-self: flex-end;
  width: 100%;
  height: auto;
  max-width: 100%;
  max-height: 100%;
  min-height: 0;
  min-width: 0;
  aspect-ratio: 1 / 1;
  margin: 0;
}

#page-games .mg-sl-board {
  position: relative;
  width: 100%;
  height: 100%;
  container-type: size;
}

#page-games .mg-sl-grid {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  grid-template-rows: repeat(5, minmax(0, 1fr));
  grid-auto-flow: row;
  gap: 3px;
  width: 100%;
  height: 100%;
  padding: 4px;
  box-sizing: border-box;
  background: #166534;
  border-radius: 16px;
  box-shadow: 0 8px 18px rgba(20, 83, 45, 0.18);
}

#page-games .mg-sl-cell {
  position: relative;
  min-width: 0;
  min-height: 0;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.72);
}

#page-games .mg-sl-cell-num {
  position: absolute;
  top: 1px;
  left: 4px;
  font-family: var(--font-en);
  font-size: clamp(0.62rem, 18cqmin, 0.9rem);
  font-weight: 800;
  line-height: 1.1;
  color: #1E293B;
}

#page-games .mg-sl-cell-tag {
  position: absolute;
  left: 3px;
  bottom: 2px;
  font-family: var(--font-en);
  font-size: clamp(0.45rem, 11cqmin, 0.62rem);
  font-weight: 800;
  letter-spacing: 0.02em;
  color: #0F172A;
}

#page-games .mg-sl-cell-icon {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -42%);
  font-size: clamp(0.85rem, 28cqmin, 1.35rem);
  line-height: 1;
}

#page-games .mg-sl-cell-arrow {
  position: absolute;
  right: 3px;
  bottom: 1px;
  font-size: clamp(0.55rem, 14cqmin, 0.75rem);
  line-height: 1;
  color: #334155;
}

#page-games .mg-sl-cell-active {
  box-shadow: inset 0 0 0 3px #0284C7;
  z-index: 1;
}

#page-games .mg-sl-links {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 2;
  pointer-events: none;
}

#page-games .mg-sl-token {
  position: absolute;
  z-index: 3;
  left: 0;
  top: 0;
  font-size: clamp(1rem, 7cqmin, 1.7rem);
  line-height: 1;
  transform: translate(-50%, -68%);
  transition: left 0.28s ease, top 0.28s ease;
  pointer-events: none;
  filter: drop-shadow(0 2px 0 rgba(15, 23, 42, 0.18));
}

#page-games .mg-sl-token-hop {
  animation: mg-sl-token-hop 0.7s ease;
}

@keyframes mg-sl-token-hop {
  0%, 100% { transform: translate(-50%, -68%) scale(1); }
  40% { transform: translate(-50%, -130%) scale(1.12); }
}

#page-games.mg-sl-playing .mg-sl-col-panel {
  flex: 1 1 268px;
  width: 100%;
  max-width: 268px;
  min-width: 0;
  min-height: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

#page-games .mg-sl-quiz,
#page-games .mg-sl-dice-card {
  background: #FFFFFF;
  border: 2px solid #BBF7D0;
  border-radius: 16px;
  padding: 8px 10px;
  min-height: 0;
}

#page-games .mg-sl-quiz {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  overflow: hidden;
}

#page-games .mg-sl-dice-card {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

#page-games .mg-sl-panel-title {
  margin: 0;
  font-family: var(--font-th);
  font-size: 0.92rem;
  font-weight: 800;
  color: #14532D;
  text-align: center;
}

#page-games .mg-sl-quiz-visual {
  flex: 0 1 auto;
  height: clamp(64px, 14dvh, 112px);
  max-height: 112px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #F8FAFC;
  border-radius: 12px;
  overflow: hidden;
}

#page-games .mg-sl-quiz-img {
  display: block;
  width: auto;
  height: auto;
  max-width: 88%;
  max-height: 100%;
  object-fit: contain;
}

#page-games .mg-sl-quiz-img[hidden],
#page-games .mg-sl-quiz-fallback[hidden],
#page-games .mg-sl-win[hidden] {
  display: none !important;
}

#page-games .mg-sl-quiz-fallback {
  font-size: 1.6rem;
  line-height: 1;
}

#page-games .mg-sl-quiz-status,
#page-games .mg-sl-roll-result {
  margin: 0;
  font-family: var(--font-th);
  font-size: 0.78rem;
  font-weight: 700;
  line-height: 1.3;
  color: #334155;
  text-align: center;
}

#page-games .mg-sl-choices {
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-height: 0;
}

#page-games .mg-sl-choice {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  min-height: 32px;
  padding: 3px 8px;
  border: 1.5px solid #CBD5E1;
  border-radius: 12px;
  background: #F8FAFC;
  color: #0F172A;
  font-family: var(--font-en);
  font-size: 0.92rem;
  font-weight: 700;
  cursor: pointer;
  text-align: left;
}

#page-games .mg-sl-choice-letter {
  flex: 0 0 auto;
  width: 22px;
  height: 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  background: #DBEAFE;
  color: #1D4ED8;
  font-size: 0.75rem;
}

#page-games .mg-sl-choice-word {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#page-games .mg-sl-choice-correct {
  background: #DCFCE7;
  border-color: #16A34A;
}

#page-games .mg-sl-choice-wrong {
  background: #FEE2E2;
  border-color: #EF4444;
}

#page-games .mg-sl-choice:disabled {
  cursor: default;
}

#page-games .mg-sl-die-scene {
  width: 64px;
  height: 64px;
  perspective: 240px;
  flex-shrink: 0;
}

#page-games .mg-sl-die {
  position: relative;
  width: 56px;
  height: 56px;
  margin: 4px auto;
  transform-style: preserve-3d;
  transition: transform 0.9s cubic-bezier(0.2, 0.75, 0.2, 1);
}

#page-games .mg-sl-die-face {
  position: absolute;
  inset: 0;
  background: #FFFFFF;
  border: 2px solid #E2E8F0;
  border-radius: 8px;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.8);
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}

#page-games .mg-sl-die-f1 { transform: rotateY(0deg) translateZ(28px); }
#page-games .mg-sl-die-f2 { transform: rotateY(90deg) translateZ(28px); }
#page-games .mg-sl-die-f3 { transform: rotateX(90deg) translateZ(28px); }
#page-games .mg-sl-die-f4 { transform: rotateX(-90deg) translateZ(28px); }
#page-games .mg-sl-die-f5 { transform: rotateY(-90deg) translateZ(28px); }
#page-games .mg-sl-die-f6 { transform: rotateY(180deg) translateZ(28px); }

#page-games .mg-sl-pip {
  position: absolute;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #0F172A;
}

#page-games .mg-sl-pip-c { top: 50%; left: 50%; transform: translate(-50%, -50%); }
#page-games .mg-sl-pip-tl { top: 6px; left: 6px; }
#page-games .mg-sl-pip-tr { top: 6px; right: 6px; }
#page-games .mg-sl-pip-bl { bottom: 6px; left: 6px; }
#page-games .mg-sl-pip-br { bottom: 6px; right: 6px; }
#page-games .mg-sl-pip-ml { top: 50%; left: 6px; transform: translateY(-50%); }
#page-games .mg-sl-pip-mr { top: 50%; right: 6px; transform: translateY(-50%); }

#page-games .mg-sl-die {
  transform: none !important;
}

#page-games .mg-sl-die-face {
  display: none;
  transform: none;
  backface-visibility: visible;
  -webkit-backface-visibility: visible;
}

#page-games .mg-sl-die[data-mg-sl-value="1"] .mg-sl-die-f1,
#page-games .mg-sl-die[data-mg-sl-value="2"] .mg-sl-die-f2,
#page-games .mg-sl-die[data-mg-sl-value="3"] .mg-sl-die-f3,
#page-games .mg-sl-die[data-mg-sl-value="4"] .mg-sl-die-f4,
#page-games .mg-sl-die[data-mg-sl-value="5"] .mg-sl-die-f5,
#page-games .mg-sl-die[data-mg-sl-value="6"] .mg-sl-die-f6 {
  display: block;
}

#page-games .mg-sl-roll {
  width: 100%;
  border: none;
  color: #FFFFFF;
  background: #94A3B8;
  font-size: 0.86rem;
  padding: 0.4rem 0.6rem;
  box-shadow: 0 3px 0 #64748B;
}

#page-games .mg-sl-roll-ready {
  background: linear-gradient(135deg, #F59E0B 0%, #D97706 100%);
  box-shadow: 0 3px 0 #B45309;
}

#page-games .mg-sl-roll:disabled {
  cursor: not-allowed;
  opacity: 0.85;
}

#page-games .mg-sl-countdown {
  position: absolute;
  inset: 0;
  z-index: 8;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(15, 23, 42, 0.5);
}

#page-games .mg-sl-countdown[hidden] {
  display: none !important;
}

#page-games .mg-sl-countdown-circle {
  width: 156px;
  height: 156px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(3, 105, 161, 0.94);
  border: 6px solid #FACC15;
  box-shadow: 0 14px 32px rgba(0, 0, 0, 0.45);
  animation: mg-sl-countdown-pop 0.45s cubic-bezier(0.22, 1.4, 0.36, 1);
}

#page-games .mg-sl-countdown-circle.mg-sl-countdown-go {
  width: 176px;
  height: 176px;
  background: rgba(34, 197, 94, 0.94);
  border-color: #BBF7D0;
}

#page-games .mg-sl-countdown-text {
  font-family: var(--font-en);
  font-size: 4.8rem;
  font-weight: 900;
  line-height: 1;
  color: #FFFFFF;
  text-shadow: 0 6px 14px rgba(0, 0, 0, 0.4);
}

#page-games .mg-sl-countdown-circle.mg-sl-countdown-go .mg-sl-countdown-text {
  font-family: var(--font-th);
  font-size: 3.2rem;
}

@keyframes mg-sl-countdown-pop {
  0% { transform: scale(0.4); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

#page-games .mg-sl-win {
  position: absolute;
  inset: 0;
  z-index: 6;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(15, 23, 42, 0.45);
}

#page-games .mg-sl-win-card {
  width: min(360px, calc(100% - 24px));
  background: #FFFFFF;
  border-radius: 20px;
  border: 3px solid #FDE68A;
  padding: 16px;
  text-align: center;
}

#page-games .mg-sl-win-icon {
  font-size: 2rem;
}

#page-games .mg-sl-win-title,
#page-games .mg-sl-win-sub {
  margin: 4px 0;
  font-family: var(--font-th);
}

#page-games .mg-sl-again {
  margin-top: 8px;
  border: none;
  color: #FFFFFF;
  background: linear-gradient(135deg, #22C55E 0%, #16A34A 100%);
  padding: 0.45rem 0.9rem;
}

#page-games .mg-sl-confetti {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 5;
}

#page-games.mg-sl-playing .mg-sl-stage {
  position: relative;
}

@media (max-height: 760px) {
  #page-games.mg-sl-playing .mg-sl-quiz-visual {
    height: 72px;
    max-height: 72px;
  }

  #page-games.mg-sl-playing .mg-sl-die-scene {
    width: 52px;
    height: 52px;
  }

  #page-games.mg-sl-playing .mg-sl-choice {
    min-height: 28px;
    font-size: 0.84rem;
  }
}

@media (max-width: 700px) {
  #page-games.mg-sl-playing .mg-sl-container {
    overflow-x: hidden;
    overflow-y: auto;
  }

  #page-games.mg-sl-playing .mg-sl-stage {
    flex-direction: column;
    align-items: stretch;
    justify-content: flex-start;
    width: 100%;
    height: auto;
    max-height: none;
    flex: 0 0 auto;
    overflow: visible;
    gap: 8px;
    container-type: normal;
  }

  #page-games.mg-sl-playing .mg-sl-col-board {
    order: 0;
    flex: 0 0 auto;
    width: 100%;
    height: auto;
    align-items: center;
    overflow: visible;
  }

  #page-games.mg-sl-playing .mg-sl-board-frame {
    align-self: center;
    width: min(100%, 92vw, 420px);
    max-width: 100%;
    height: auto;
    max-height: none;
    aspect-ratio: 1 / 1;
    flex: 0 0 auto;
  }

  #page-games.mg-sl-playing .mg-sl-col-panel {
    order: 1;
    flex: 0 0 auto;
    width: 100%;
    max-width: none;
    height: auto;
    display: grid;
    grid-template-columns: minmax(0, 1.3fr) minmax(132px, 0.7fr);
    align-items: stretch;
    overflow: visible;
  }

  #page-games.mg-sl-playing .mg-sl-quiz-visual {
    height: 72px;
    max-height: 72px;
  }
}

@media (max-width: 1100px) {
  body:has(#page-games.mg-sl-playing) .navbar-inner {
    flex-direction: row;
    flex-wrap: nowrap;
    align-items: center;
    gap: 0.35rem;
    overflow: hidden;
    padding: 0.28rem 0.5rem;
  }

  body:has(#page-games.mg-sl-playing) .nav-brand {
    min-width: 0;
    flex: 0 1 auto;
  }

  body:has(#page-games.mg-sl-playing) .brand-tag,
  body:has(#page-games.mg-sl-playing) .tab-label,
  body:has(#page-games.mg-sl-playing) .tab-pill,
  #page-games.mg-sl-playing .mg-sl-brand,
  #page-games.mg-sl-playing .mg-sl-field-label > span {
    display: none;
  }

  body:has(#page-games.mg-sl-playing) .nav-menu {
    display: flex;
    flex: 0 0 auto;
    flex-wrap: nowrap;
    justify-content: flex-end;
    width: auto;
    gap: 0.2rem;
    margin-left: auto;
  }

  body:has(#page-games.mg-sl-playing) .nav-tab {
    flex: 0 0 auto;
    justify-content: center;
    min-width: 36px;
    padding: 0.28rem 0.45rem;
    gap: 0;
  }

  #page-games.mg-sl-playing .mg-sl-header {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
  }

  #page-games.mg-sl-playing .mg-sl-header > * {
    width: auto;
    max-width: 100%;
    min-width: 0;
  }

  #page-games.mg-sl-playing .mg-sl-field-label {
    flex: 1 1 180px;
    min-width: 0;
  }

  #page-games.mg-sl-playing .mg-sl-category {
    flex: 1 1 auto;
    width: auto;
    min-width: 0;
    max-width: 100%;
  }
}

@media (max-width: 768px) {
  body:has(#page-games.mg-sl-playing) .navbar-inner {
    flex-wrap: nowrap;
    gap: 0.3rem;
    overflow: hidden;
  }

  body:has(#page-games.mg-sl-playing) .nav-brand {
    min-width: 0;
    flex: 0 1 auto;
  }

  body:has(#page-games.mg-sl-playing) .brand-tag {
    display: none;
  }

  body:has(#page-games.mg-sl-playing) .nav-menu {
    flex: 0 0 auto;
    flex-wrap: nowrap;
    justify-content: flex-end;
    gap: 0.2rem;
    margin-left: auto;
  }

  body:has(#page-games.mg-sl-playing) .nav-tab {
    flex: 0 0 auto;
    justify-content: center;
    min-width: 36px;
    padding: 0.22rem 0.38rem;
    gap: 0;
  }

  body:has(#page-games.mg-sl-playing) .tab-pill {
    display: none;
  }

  #page-games.mg-sl-playing .mg-sl-header {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto auto;
    grid-template-areas:
      "back timer actions"
      "category category category"
      "start start start";
    align-items: center;
    gap: 6px;
    width: 100%;
  }

  #page-games.mg-sl-playing .mg-sl-header > * {
    width: auto;
    max-width: 100%;
    min-width: 0;
  }

  #page-games.mg-sl-playing .mg-sl-back {
    grid-area: back;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  #page-games.mg-sl-playing .mg-sl-brand {
    display: none;
  }

  #page-games.mg-sl-playing .mg-sl-field-label {
    grid-area: category;
    width: 100%;
  }

  #page-games.mg-sl-playing .mg-sl-category {
    flex: 1 1 auto;
    width: 100%;
    max-width: none;
  }

  #page-games.mg-sl-playing .mg-sl-start {
    grid-area: start;
    width: 100%;
  }

  #page-games.mg-sl-playing .mg-sl-timer-card {
    grid-area: timer;
  }

  #page-games.mg-sl-playing .mg-sl-actions {
    grid-area: actions;
  }

  #page-games.mg-sl-playing {
    overflow: hidden;
  }

  #page-games.mg-sl-playing .mg-sl-container {
    overflow-x: hidden;
    overflow-y: auto;
  }
}

@media (max-width: 420px) {
  body:has(#page-games.mg-sl-playing) .brand-title {
    display: none;
  }

  #page-games.mg-sl-playing .mg-sl-col-panel {
    grid-template-columns: minmax(0, 1fr);
  }

  #page-games.mg-sl-playing .mg-sl-restart {
    padding: 0.3rem 0.5rem;
    font-size: 0.78rem;
  }
}

@media (orientation: landscape) and (max-height: 520px) {
  #page-games.mg-sl-playing .mg-sl-stage {
    flex-direction: row;
    overflow: hidden;
  }

  #page-games.mg-sl-playing .mg-sl-col-board {
    flex: 1 1 auto;
    width: auto;
    height: 100%;
    align-items: flex-end;
  }

  #page-games.mg-sl-playing .mg-sl-board-frame {
    width: auto;
    height: 100%;
    max-height: 100%;
    align-self: flex-end;
  }

  #page-games.mg-sl-playing .mg-sl-col-panel {
    display: flex;
    flex-direction: column;
    flex: 0 0 220px;
    width: 220px;
    max-width: 220px;
    height: 100%;
  }

  #page-games.mg-sl-playing .mg-sl-quiz-visual {
    height: 56px;
    max-height: 56px;
  }
}

/* Mobile scroll: Bubble Shooter letter rack and Pixel Art palette */
@media (max-width: 768px) {
  body:has(#page-games.mg-bs-playing),
  body:has(#page-games.mg-pa-playing) {
    height: auto;
    min-height: 100vh;
    min-height: 100dvh;
    max-height: none;
    overflow-x: hidden;
    overflow-y: auto;
  }

  body:has(#page-games.mg-bs-playing) .app-container,
  body:has(#page-games.mg-pa-playing) .app-container {
    height: auto;
    min-height: 0;
    max-height: none;
    overflow: visible;
  }

  #page-games.mg-bs-playing,
  #page-games.mg-pa-playing {
    flex: 0 0 auto;
    height: auto;
    min-height: 100vh;
    min-height: 100dvh;
    overflow-x: hidden;
    overflow-y: visible;
  }

  #page-games.mg-bs-playing .mg-bs-container {
    flex: 0 0 auto;
    min-height: 100vh;
    min-height: 100dvh;
    max-height: none;
    overflow: visible;
    padding-bottom: 5rem;
  }

  #page-games.mg-bs-playing .mg-bs-stage {
    flex: 0 0 auto;
    height: auto;
    max-height: none;
    overflow: visible;
  }

  #page-games.mg-bs-playing .mg-bs-col-center {
    flex: 0 0 auto;
    width: 100%;
    height: 60vh;
    min-height: 60vh;
    max-height: none;
  }

  #page-games.mg-bs-playing .mg-bs-rack-bar {
    flex-shrink: 0;
    max-height: none;
    overflow: visible;
  }

  #page-games.mg-bs-playing .mg-bs-word-rack {
    flex-wrap: wrap;
    justify-content: center;
    overflow: visible;
  }

  #page-games.mg-pa-playing .mg-pa-container {
    flex: 0 0 auto;
    min-height: 100vh;
    min-height: 100dvh;
    max-height: none;
    overflow: visible;
    padding-bottom: 6rem;
  }

  #page-games.mg-pa-playing .mg-pa-arena {
    flex: 0 0 auto;
    height: auto;
    max-height: none;
    overflow: visible;
  }

  #page-games.mg-pa-playing .mg-pa-col-left,
  #page-games.mg-pa-playing .mg-pa-col-center,
  #page-games.mg-pa-playing .mg-pa-col-right {
    flex: 0 0 auto;
    min-height: auto;
    overflow: visible;
  }

  #page-games.mg-pa-playing .mg-pa-palette-bar,
  #page-games.mg-pa-playing .mg-pa-palette-list {
    min-height: auto;
    max-height: none;
    overflow: visible;
  }

  #page-games.mg-pa-playing .mg-pa-board-wrap {
    max-height: none;
  }
}

/* Mobile scroll + size: Drag Jigsaw, Sliding Jigsaw, Sheep Crossing, Snakes */
@media (max-width: 768px) {
  body:has(#page-games.mg-dj-playing),
  body:has(#page-games.mg-sj-playing),
  body:has(#page-games.mg-hm-playing),
  body:has(#page-games.mg-sl-playing) {
    width: 100%;
    height: auto;
    min-height: 100vh;
    min-height: 100dvh;
    max-height: none;
    overflow-x: hidden;
    overflow-y: auto;
  }

  body:has(#page-games.mg-dj-playing) .app-container,
  body:has(#page-games.mg-sj-playing) .app-container,
  body:has(#page-games.mg-hm-playing) .app-container,
  body:has(#page-games.mg-sl-playing) .app-container {
    width: 100%;
    height: auto;
    min-height: 0;
    max-height: none;
    overflow: visible;
  }

  #page-games.mg-dj-playing,
  #page-games.mg-sj-playing,
  #page-games.mg-hm-playing,
  #page-games.mg-sl-playing {
    flex: 0 0 auto;
    width: 100%;
    height: auto;
    min-height: 100vh;
    min-height: 100dvh;
    overflow-x: hidden;
    overflow-y: visible;
  }

  #page-games.mg-dj-playing .mg-dj-container,
  #page-games.mg-sj-playing .mg-sj-container,
  #page-games.mg-hm-playing .mg-hm-container,
  #page-games.mg-sl-playing .mg-sl-container {
    flex: 0 0 auto;
    width: 100%;
    max-height: none;
    overflow: visible;
    padding-bottom: 8rem;
  }

  #page-games.mg-dj-playing .mg-dj-stage,
  #page-games.mg-sj-playing .mg-sj-stage,
  #page-games.mg-hm-playing .mg-hm-arena,
  #page-games.mg-sl-playing .mg-sl-stage {
    flex: 0 0 auto;
    height: auto;
    max-height: none;
    overflow: visible;
  }

  #page-games.mg-dj-playing .mg-dj-col-center,
  #page-games.mg-sj-playing .mg-sj-col-center,
  #page-games.mg-dj-playing .mg-dj-col-right,
  #page-games.mg-sj-playing .mg-sj-col-right {
    flex: 0 0 auto;
    height: auto;
    max-height: none;
    overflow: visible;
  }

  #page-games.mg-dj-playing .mg-dj-board-wrap,
  #page-games.mg-dj-playing .mg-dj-arena {
    width: 100%;
    height: auto;
    min-height: 420px;
    max-height: none;
  }

  #page-games.mg-dj-playing .mg-dj-arena {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto auto;
  }

  #page-games.mg-dj-playing .mg-dj-drop-panel,
  #page-games.mg-dj-playing .mg-dj-scatter-panel {
    height: auto;
    min-height: 0;
  }

  #page-games.mg-dj-playing .mg-dj-drop-zone {
    width: min(100%, 320px);
    height: auto;
    aspect-ratio: 1 / 1;
    max-height: none;
    margin-inline: auto;
  }

  #page-games.mg-dj-playing .mg-dj-scatter-zone {
    width: 100%;
    height: 200px;
    min-height: 180px;
  }

  #page-games .mg-sj-board-wrap,
  #page-games.mg-sj-playing .mg-sj-board-wrap {
    width: 100%;
    max-width: 350px;
    height: auto;
    max-height: none;
    aspect-ratio: 1 / 1;
    margin-inline: auto;
  }

  #page-games.mg-sj-playing .mg-sj-board-fit {
    container-type: normal;
    height: auto;
  }

  #page-games.mg-hm-playing .mg-hm-arena {
    max-height: none;
    overflow: visible;
  }

  #page-games .mg-hm-river,
  #page-games.mg-hm-playing .mg-hm-river {
    position: relative;
    width: 100%;
    height: 30vh;
    min-height: 250px;
    flex: 0 0 auto;
  }
}
