/* Mini-game overlay UI (shared with /games page) */
:root, .games-page {
  --card: #fff;
  --surface: #f8fafc;
  --text: #0f172a;
  --muted: #64748b;
  --border: #cbd5e1;
  --accent: #ea580c;
  --accent-soft: #ffedd5;
  --en: #0369a1;
  --thai: #be123c;
  --danger: #dc2626;
  --shadow: 0 10px 32px rgba(15, 23, 42, 0.14);
  --font-thai: "Sarabun", "Segoe UI", sans-serif;
}
html.dark, body.dark, html.dark .games-page, body.dark.games-page {
  --card: #111827;
  --surface: #1e293b;
  --text: #e5eef7;
  --muted: #94a3b8;
  --border: #334155;
  --accent: #fb923c;
  --accent-soft: #431407;
  --en: #38bdf8;
  --thai: #fb7185;
  --danger: #f87171;
  --shadow: 0 8px 28px rgba(0, 0, 0, 0.4);
}
.flashcard-close {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 10px;
  width: 40px;
  height: 40px;
  font-size: 1.1rem;
  cursor: pointer;
  font-family: inherit;
}
.flashcard-progress {
  text-align: center;
  font-weight: 700;
  color: var(--muted);
  margin-bottom: 8px;
  font-size: 0.9rem;
}
.quiz-choice .th { font-family: var(--font-thai); color: var(--thai); }

.quiz-overlay {
    display: none; position: fixed; inset: 0; z-index: 10050; background: rgba(15, 23, 42, 0.55);
    padding: 12px 12px calc(12px + env(safe-area-inset-bottom, 0px)); align-items: center; justify-content: center;
    -webkit-overflow-scrolling: touch;
}
.quiz-overlay.open { display: flex; }
/* Above mobile menu (10020) + dock (9998) so game windows always surface on phones */
#gamesHubOverlay,
#miniGameOverlay,
#dictationOverlay,
#dialogueOverlay,
#matchOverlay,
#quizOverlay { z-index: 10055; }
.quiz-sheet {
    width: min(520px, 100%); background: var(--card); border-radius: 20px; border: 1px solid var(--border);
    box-shadow: var(--shadow); padding: 16px;
    max-height: min(92dvh, calc(100vh - 24px));
    max-height: min(92dvh, calc(100dvh - 24px));
    overflow: auto;
    -webkit-overflow-scrolling: touch;
    margin: auto;
}
body.overlay-open {
    overflow: hidden !important;
    overscroll-behavior: none;
}
body.overlay-open .mobile-dock {
    display: none !important;
}
.quiz-sheet .quiz-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 8px; }
.quiz-prompt { font-size: clamp(1.35rem, 5vw, 1.9rem); font-weight: 800; text-align: center; margin: 18px 0 6px; color: var(--en); }
.quiz-hint { text-align: center; color: var(--muted); margin-bottom: 14px; }
.quiz-choices { display: grid; gap: 8px; }
.quiz-choice {
    min-height: 48px; border: 1px solid var(--border); background: var(--surface); color: var(--text);
    border-radius: 14px; font-weight: 700; font-family: inherit; font-size: 1rem; cursor: pointer; padding: 10px 12px;
}
.quiz-choice.correct { border-color: #16a34a; background: #dcfce7; }
.quiz-feedback { text-align: center; min-height: 1.4em; margin: 10px 0; font-weight: 700; }
.quiz-feedback.ok { color: #16a34a; }
.quiz-feedback.bad { color: var(--danger); }
#quizTypeWrap { display: none; flex-direction: column; gap: 8px; }
#quizInput {
    min-height: 48px; border-radius: 12px; border: 1px solid var(--border); padding: 10px 12px;
    font-size: 1.05rem; font-family: inherit; background: var(--surface); color: var(--text);
}
.quiz-setup { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-bottom: 10px; }
.quiz-setup select {
    min-height: 40px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface);
    color: var(--text); padding: 6px 10px; font-family: inherit; font-weight: 600;
}
.dlg-line {
    display: flex; flex-direction: column; gap: 4px; width: 100%; text-align: left;
    min-height: 52px; margin: 0 0 8px; padding: 10px 12px; border-radius: 12px;
    border: 1px solid var(--border); background: var(--surface); color: var(--text);
    font-family: inherit; cursor: pointer; font-weight: 600;
}
.dlg-line .dlg-en { color: var(--en); font-size: 0.95rem; }
.dlg-line .dlg-th { color: var(--thai); font-family: var(--font-thai); font-size: 1rem; }
.dlg-line-wrap { margin: 0 0 8px; }
.dlg-line-audio { display: flex; gap: 6px; margin-top: 6px; flex-wrap: wrap; }
.dlg-play {
    min-height: 36px; border-radius: 10px; border: 1px solid var(--border);
    background: var(--accent); color: #fff; font-weight: 700; font-family: inherit;
    padding: 4px 10px; cursor: pointer; font-size: 0.8rem;
}
.dlg-play.th { background: var(--thai); }
.dlg-built-item .dlg-line-audio { display: inline-flex; margin-left: 8px; vertical-align: middle; }
.dlg-built-item {
    padding: 8px 10px; margin: 0 0 6px; border-radius: 10px;
    background: var(--accent-soft); border: 1px solid var(--border); font-size: 0.9rem;
}
.dlg-built-item em { display: block; font-style: normal; color: var(--thai); font-family: var(--font-thai); margin-top: 2px; }
#dialogueBuilt, #dialogueBank { margin-top: 10px; }
.match-grid {
    display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 12px;
}
.match-tile {
    display: block; width: 100%; min-height: 52px; margin: 0 0 8px; padding: 10px;
    border-radius: 12px; border: 2px solid var(--border); background: var(--surface);
    color: var(--en); font-weight: 700; font-family: inherit; cursor: pointer; font-size: 0.92rem;
}
.match-tile.th { color: var(--thai); font-family: var(--font-thai); font-size: 1rem; }
.match-tile.phon { color: var(--muted); font-family: 'Segoe UI', Consolas, monospace; font-style: italic; font-weight: 600; }
.match-tile.selected { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(3,105,161,0.2); }
.match-tile.locked { opacity: 0.45; background: #dcfce7; border-color: #16a34a; cursor: default; }
.match-grid.dense .match-tile { min-height: 44px; margin: 0 0 6px; padding: 8px; font-size: 0.85rem; }
.match-grid.dense .match-tile.th { font-size: 0.92rem; }
.game-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 12px; }
.game-actions button {
    min-height: 44px; border-radius: 12px; border: 1px solid var(--border);
    background: var(--accent); color: #fff; font-weight: 700; font-family: inherit;
    padding: 8px 14px; cursor: pointer;
}
.game-actions button.secondary { background: var(--surface); color: var(--text); }
.mg-hub-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 10px;
    margin-top: 12px;
}
.mg-hub-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 14px 10px;
    border-radius: 14px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
    font-family: inherit;
    text-align: center;
    transition: transform 0.12s, border-color 0.15s, background 0.15s;
}
.mg-hub-card:hover { transform: translateY(-2px); border-color: var(--accent); background: var(--accent-soft); }
.mg-hub-card span { font-size: 1.5rem; line-height: 1; }
.mg-hub-card strong { font-size: 0.88rem; }
.mg-hub-card em { font-style: normal; font-size: 0.78rem; color: var(--muted); font-family: var(--font-thai); }
.qcm-exam-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0 0 12px;
    font-size: 0.9rem;
    color: var(--muted);
    cursor: pointer;
}
.qcm-exam-toggle input { width: 18px; height: 18px; accent-color: var(--accent); }
.qcm-dir-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin: 0 0 12px;
}
.qcm-dir-btn {
    min-height: 56px;
    line-height: 1.25;
}
.qcm-dir-btn em {
    display: block;
    font-style: normal;
    font-size: 0.8rem;
    color: var(--muted);
    font-family: var(--font-thai);
    margin-top: 2px;
}
.qcm-pack-list { margin-bottom: 8px; }
.qcm-pack-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    text-align: center;
}
.qcm-pack-btn .qcm-pack-emoji { font-size: 1.4rem; line-height: 1; }
.qcm-pack-btn strong { font-size: 0.95rem; }
.qcm-pack-btn em { font-style: normal; font-size: 0.78rem; color: var(--muted); font-family: var(--font-thai); }
.qcm-exam50 { margin-top: 4px; border-style: dashed; }
.qcm-emoji {
    font-size: 3rem;
    line-height: 1;
    text-align: center;
    margin: 6px 0 4px;
}
.qcm-tip-btn { margin: 6px 0 10px; width: 100%; }
.qcm-tip-preview { color: var(--accent); }
.qcm-review {
    margin: 0 0 12px;
    padding-left: 1.1rem;
    text-align: left;
    font-size: 0.88rem;
    line-height: 1.45;
}
.qcm-review em { color: var(--muted); font-style: normal; }
/* Live translator chat */
#translatorOverlay .quiz-sheet {
    max-width: 520px;
    width: min(96vw, 520px);
    max-height: min(92vh, 720px);
    display: flex;
    flex-direction: column;
}
.tr-dir-row {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 6px;
    margin: 0 0 8px;
}
.tr-dir-btn, #trFlip {
    border: 1px solid var(--border);
    background: var(--surface);
    border-radius: 12px;
    padding: 8px 6px;
    cursor: pointer;
    font: inherit;
    text-align: center;
    color: var(--text);
}
.tr-dir-btn.active, #trFlip {
    border-color: var(--accent);
    background: var(--accent-soft);
}
.tr-dir-btn strong, #trFlip strong { display: block; font-size: 0.85rem; }
.tr-dir-btn em, #trFlip em {
    display: block; font-style: normal; font-size: 0.72rem;
    color: var(--muted); font-family: var(--font-thai); margin-top: 2px;
}
#trFlip { width: 100%; margin-bottom: 8px; }
.tr-chat {
    flex: 1;
    min-height: 220px;
    max-height: min(48vh, 380px);
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 8px 4px 10px;
    margin-bottom: 8px;
    border-radius: 12px;
    background: linear-gradient(180deg, rgba(224,242,254,0.45), transparent);
}
body.dark .tr-chat { background: linear-gradient(180deg, rgba(12,74,110,0.35), transparent); }
.tr-empty {
    margin: auto;
    text-align: center;
    color: var(--muted);
    padding: 20px 12px;
}
.tr-empty strong { display: block; color: var(--text); margin-bottom: 6px; }
.tr-empty p { margin: 0; font-size: 0.88rem; line-height: 1.4; }
.tr-bubble {
    max-width: 92%;
    padding: 8px 12px;
    border-radius: 14px;
    border: 1px solid var(--border);
    background: var(--card, #fff);
}
.tr-bubble.you {
    align-self: flex-end;
    background: var(--accent-soft);
    border-color: #7dd3fc;
}
.tr-bubble.bot { align-self: flex-start; }
.tr-meta { font-size: 0.7rem; font-weight: 700; color: var(--muted); margin-bottom: 3px; }
.tr-text { font-weight: 700; font-size: 1rem; line-height: 1.35; word-break: break-word; }
.tr-text.th { font-family: var(--font-thai); color: var(--thai, #0f766e); font-size: 1.1rem; }
.tr-actions { display: flex; gap: 6px; margin-top: 6px; }
.tr-act {
    border: 1px solid var(--border); background: var(--surface);
    border-radius: 8px; padding: 4px 8px; cursor: pointer; font-size: 0.9rem;
}
.tr-compose {
    display: grid;
    grid-template-columns: 1fr auto auto;
    gap: 6px;
    align-items: end;
}
#trInput {
    width: 100%;
    min-height: 44px;
    max-height: 96px;
    resize: vertical;
    border-radius: 12px;
    border: 1px solid var(--border);
    padding: 10px 12px;
    font: inherit;
    background: var(--surface);
    color: var(--text);
    box-sizing: border-box;
}
#trSendBtn, #trMicBtn {
    min-height: 44px;
    border-radius: 12px;
    border: 1px solid var(--border);
    padding: 8px 12px;
    font-weight: 800;
    cursor: pointer;
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1px;
    min-width: 64px;
}
#trMicBtn {
    background: var(--surface);
    color: var(--text);
    border-color: var(--border);
}
#trMicBtn.listening {
    background: #fecaca;
    border-color: #ef4444;
    color: #991b1b;
    animation: tr-pulse 1s ease-in-out infinite;
}
@keyframes tr-pulse {
    50% { transform: scale(1.04); }
}
.tr-mic-ico { font-size: 1.1rem; line-height: 1; }
.tr-mic-lbl { font-size: 0.65rem; font-weight: 700; }
.tr-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    margin-top: 8px;
    font-size: 0.82rem;
    color: var(--muted);
}
.tr-toolbar label { display: flex; align-items: center; gap: 6px; cursor: pointer; }
.tr-status { min-height: 1.2em; font-size: 0.8rem; font-weight: 700; margin: 4px 0 0; color: var(--muted); }
.tr-status.ok { color: #16a34a; }
.tr-status.bad { color: #dc2626; }
.tr-status.busy { color: var(--accent); }
.mg-speed-bar {
    display: flex;
    justify-content: space-around;
    gap: 8px;
    margin: 8px 0 14px;
    font-weight: 800;
    font-size: 1.05rem;
}
.mg-letter-pad {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 6px;
    margin-top: 12px;
}
.mg-letter {
    min-height: 40px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--card);
    font-weight: 800;
    cursor: pointer;
    font-family: inherit;
}
.mg-letter:hover { background: var(--accent-soft); border-color: var(--accent); }
.mg-spell-out {
    font-size: 1.4rem;
    font-weight: 800;
    letter-spacing: 0.12em;
    text-align: center;
    margin: 10px 0;
    min-height: 2rem;
}
.mg-type-input {
    display: block;
    width: min(100%, 420px);
    margin: 12px auto 0;
    min-height: 52px;
    border-radius: 14px;
    border: 2px solid var(--border);
    background: var(--surface);
    color: var(--text);
    font-size: 1.35rem;
    font-weight: 700;
    text-align: center;
    font-family: var(--font-thai), var(--font-display), sans-serif;
    padding: 10px 14px;
}
.mg-type-input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}
.mg-type-modes { flex-wrap: wrap; }
.mg-draw-wrap {
    display: flex; flex-direction: column; align-items: center; gap: 10px; margin-top: 8px;
}
.mg-draw-canvas {
    width: min(100%, 320px); height: min(100vw, 320px); max-height: 320px;
    border-radius: 16px; border: 2px solid var(--border);
    background: #f8fafc; touch-action: none; cursor: crosshair;
    box-shadow: inset 0 0 0 1px rgba(15,23,42,0.04);
}
[data-theme="dark"] .mg-draw-canvas, body.dark .mg-draw-canvas {
    background: #0f172a; border-color: var(--border);
}
.mg-draw-score {
    font-size: 1.1rem; font-weight: 800; text-align: center; min-height: 1.4em;
}
.mg-mic-btn.listening {
    background: #dc2626 !important;
    color: #fff !important;
    border-color: #dc2626 !important;
    animation: mg-mic-pulse 1.1s ease-in-out infinite;
}
@keyframes mg-mic-pulse {
    0%, 100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(220, 38, 38, 0.35); }
    50% { transform: scale(1.03); box-shadow: 0 0 0 10px rgba(220, 38, 38, 0); }
}
.mg-speak-target {
    text-align: center;
    font-size: 1.35rem;
    font-weight: 800;
    margin: 8px 0 4px;
    font-family: var(--font-thai);
    color: var(--thai, #be123c);
}
.mg-speak-heard {
    text-align: center;
    min-height: 1.4em;
    margin: 6px 0;
    color: var(--muted);
    font-size: 0.95rem;
}
.mg-speak-score {
    text-align: center;
    font-size: 1.4rem;
    font-weight: 800;
    min-height: 1.5em;
}
.mg-speak-score.ok { color: #16a34a; }
.mg-speak-score.bad { color: #dc2626; }
.mg-linkish {
    background: none;
    border: none;
    color: var(--accent);
    font: inherit;
    font-weight: 700;
    cursor: pointer;
    text-decoration: underline;
    padding: 0;
}
.mg-order-built, .mg-order-bank {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
    min-height: 48px;
    margin: 10px 0;
    padding: 10px;
    border-radius: 12px;
    border: 1px dashed var(--border);
    background: var(--surface);
}
.mg-chip {
    border: 1px solid var(--border);
    background: var(--card);
    border-radius: 999px;
    padding: 8px 12px;
    font-weight: 700;
    cursor: pointer;
    font-family: inherit;
}
.mg-chip.bank { background: var(--accent-soft); border-color: var(--accent); }
.mg-tap-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-top: 12px;
}
.mg-tap-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 14px 8px;
    border-radius: 14px;
    border: 1px solid var(--border);
    background: var(--card);
    cursor: pointer;
    font-family: inherit;
    color: var(--text);
}
.mg-tap-card .mg-emoji { font-size: 1.6rem; }
.mg-tap-card .mg-en { font-weight: 700; font-size: 0.9rem; text-align: center; }
.mg-tap-card .th { font-family: var(--font-thai); color: var(--thai, #be123c); font-size: 0.95rem; }
.mg-tap-card.correct, .quiz-choice.correct { border-color: #16a34a !important; background: #dcfce7 !important; }
.mg-tap-card.wrong, .quiz-choice.wrong { border-color: #dc2626 !important; background: #fee2e2 !important; }
.mg-picto-story {
    display: flex; flex-wrap: wrap; align-items: center; justify-content: center;
    gap: 6px; font-size: clamp(2rem, 8vw, 2.8rem); line-height: 1; margin: 10px 0 4px;
    padding: 12px; border-radius: 16px; background: var(--accent-soft);
}
.mg-picto-story .mg-story-arrow {
    font-size: 1.1rem; color: var(--muted); font-weight: 800; margin: 0 2px;
}
.mg-picto-hero {
    font-size: clamp(4rem, 18vw, 6rem);
    line-height: 1;
    text-align: center;
    margin: 8px 0 14px;
    filter: drop-shadow(0 4px 12px rgba(0,0,0,.12));
}
.mg-alpha-hero {
    font-family: var(--font-thai), "Sarabun", "Noto Sans Thai", sans-serif;
    font-size: clamp(4.5rem, 22vw, 7rem);
    line-height: 1.1;
    text-align: center;
    margin: 10px 0 16px;
    color: var(--thai, #be123c);
    font-weight: 700;
}
.mg-alpha-tile {
    font-family: var(--font-thai), "Sarabun", "Noto Sans Thai", sans-serif;
    font-size: 2.2rem;
    font-weight: 700;
    color: var(--thai, #be123c);
    line-height: 1;
}
.mg-picto-modes {
    display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-bottom: 10px;
}
.mg-picto-modes button {
    min-height: 44px; padding: 8px 12px; border-radius: 10px;
    border: 1px solid var(--border); background: var(--surface); color: var(--text);
    font-weight: 700; cursor: pointer; font-family: inherit;
}
.mg-picto-modes button.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.mg-picto-only {
    font-size: 2.4rem; line-height: 1; display: block; margin-bottom: 4px;
}
.mg-mem-picto {
    display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 8px;
}
.mg-mem-picto button {
    min-height: 72px; border-radius: 12px; border: 1px solid var(--border);
    background: var(--surface); cursor: pointer; font-size: 1.8rem;
    display: flex; align-items: center; justify-content: center;
}
.mg-mem-picto button.flipped, .mg-mem-picto button.matched {
    background: var(--accent-soft); border-color: var(--accent);
    font-size: 0.85rem; flex-direction: column; gap: 2px; font-weight: 700;
}
.mg-mem-picto button.matched { opacity: 0.75; }
@media (max-width: 560px) {
    .mg-mem-picto { grid-template-columns: repeat(3, 1fr); }
}
.mg-mark { opacity: 0.7; margin-left: 4px; }
.mg-memory-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    margin-top: 12px;
}
.mg-mem-card {
    min-height: 72px;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: var(--accent-soft);
    color: var(--text);
    cursor: pointer;
    font-family: inherit;
    font-weight: 700;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    padding: 6px;
}
.mg-mem-card.flipped { background: var(--card); }
.mg-mem-card.matched { background: #dcfce7; border-color: #16a34a; opacity: 0.85; }
.mg-mem-back { font-size: 1.4rem; opacity: 0.5; }
.mg-mem-side { font-size: 0.65rem; opacity: 0.65; letter-spacing: 0.04em; }
.mg-blank { color: var(--accent); letter-spacing: 0.08em; }
.mg-hang-face { font-size: 2.6rem; text-align: center; margin: 8px 0; }
.mg-hang-word {
    font-size: clamp(1.2rem, 5vw, 1.8rem);
    font-weight: 800;
    letter-spacing: 0.18em;
    text-align: center;
    margin: 12px 0;
    font-family: ui-monospace, Consolas, monospace;
}
.mg-letter.wrong { opacity: 0.35; text-decoration: line-through; }
.mg-search-grid {
    display: grid;
    gap: 3px;
    margin: 10px auto;
    max-width: 360px;
    user-select: none;
    touch-action: none;
}
.mg-search-cell {
    aspect-ratio: 1;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--card);
    font-weight: 800;
    font-size: 0.85rem;
    cursor: pointer;
    font-family: inherit;
    color: var(--text);
    padding: 0;
}
.mg-search-cell.sel { background: var(--accent); color: #fff; }
.mg-search-cell.found { background: #dcfce7; border-color: #16a34a; color: #166534; }
.mg-search-list {
    list-style: none;
    padding: 0;
    margin: 12px 0 0;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
}
.mg-search-list li {
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 4px 10px;
    font-size: 0.85rem;
    background: var(--surface);
}
.mg-search-list li.found { opacity: 0.45; text-decoration: line-through; }
.mg-cw-grid {
    display: grid;
    gap: 3px;
    max-width: 280px;
    margin: 12px auto;
}
.mg-cw-cell {
    aspect-ratio: 1;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--card);
    font-weight: 800;
    font-size: 1rem;
    cursor: pointer;
    font-family: inherit;
    color: var(--text);
}
.mg-cw-cell.active { outline: 2px solid var(--accent); background: var(--accent-soft); }
.mg-cw-block {
    aspect-ratio: 1;
    border-radius: 6px;
    background: #0f172a;
}
body:not(.dark) .mg-cw-block { background: #334155; }
.mg-cw-clues {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin: 10px 0;
    font-size: 0.92rem;
    text-align: center;
}
@media (max-width: 560px) {
    .mg-memory-grid { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 560px) {
    .mg-letter-pad { grid-template-columns: repeat(6, 1fr); }
    .mg-hub-grid { grid-template-columns: repeat(2, 1fr); }
}

#lexiqueTable tbody tr { content-visibility: auto; contain-intrinsic-size: auto 140px; }
@media (orientation: landscape) and (max-height: 520px) {
    .flashcard-overlay { padding: 8px; }
    .flashcard-sheet { max-height: calc(100dvh - 16px); width: min(720px, 100%); }
    .flashcard-card { min-height: 120px; padding: 12px; flex-direction: row; flex-wrap: wrap; gap: 16px; }
    .flashcard-card .fc-en, .flashcard-card .fc-th { font-size: 1.35rem; }
}
@media (max-width: 700px) { .situation-packs { grid-template-columns: 1fr; } }

/* Mobile cards + mobile UX */
@media (max-width: 768px) {
    body {
        padding: 10px;
        padding-bottom: calc(88px + env(safe-area-inset-bottom, 0px));
    }
    .container > *:not(.hero):not(.install-banner):not(.home-toolboxes):not(.sticky-filters):not(.site-menu) {
        padding-left: 14px;
        padding-right: 14px;
    }
    .home-toolboxes { margin: 10px 14px 0; }
    .sticky-filters {
        padding: 8px 14px 10px;
        margin-left: 0;
        margin-right: 0;
    }
    .category-btn {
        min-height: 44px;
        padding: 10px 14px;
    }
    .controls button {
        min-height: 44px;
        padding: 12px 14px;
    }
    .playback-buttons button {
        min-height: 48px;
        min-width: min(100%, 160px);
    }
    .category-buttons {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 8px;
        justify-content: stretch;
        overflow: visible;
        flex-wrap: unset;
        padding-bottom: 0;
    }
    .category-buttons .category-btn {
        flex-shrink: unset;
        width: 100%;
        min-height: 44px;
        padding: 10px 8px;
        font-size: 0.82rem;
        text-align: center;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        border-radius: 14px;
    }
    .sticky-filters .category-filter .hint { display: none; }

    .floating-bar {
        left: 0;
        right: 0;
        bottom: 0;
        padding: 10px 10px calc(10px + env(safe-area-inset-bottom, 0px));
        background: color-mix(in srgb, var(--card) 96%, transparent);
        backdrop-filter: blur(12px);
        border-top: 1px solid var(--border);
        align-items: stretch;
        border-radius: 0;
        box-shadow: 0 -8px 24px rgba(15, 23, 42, 0.14);
    }
    .floating-bar .row {
        width: 100%;
        justify-content: stretch;
        gap: 6px;
    }
    .floating-bar button, .floating-bar select {
        flex: 1;
        min-width: 0;
        box-shadow: none;
        border-radius: 12px;
        padding: 8px 4px;
        font-size: 11px;
        line-height: 1.2;
        white-space: normal;
    }
    .corner-nav {
        left: 10px;
        bottom: calc(78px + env(safe-area-inset-bottom, 0px));
    }
    .mobile-dock {
        display: grid;
    }
    body.playing-active .mobile-dock { display: none; }
    body.playing-active {
        padding-bottom: calc(96px + env(safe-area-inset-bottom, 0px));
    }

    /* Thai-first mobile header nav */
    .tm-mobi-nav {
        display: block;
        margin: 12px 0 4px;
        padding: 12px 0 4px;
        border-top: 1px solid rgba(255,255,255,0.14);
    }
    .tm-mobi-gold {
        height: 2px;
        width: 72%;
        max-width: 280px;
        margin: 0 auto 12px;
        border-radius: 999px;
        background: linear-gradient(90deg, transparent, #fbbf24, transparent);
    }
    .tm-mobi-title {
        text-align: left;
        margin: 0 2px 10px;
    }
    .tm-mobi-title strong {
        display: block;
        font-family: var(--font-thai);
        font-size: 1.35rem;
        font-weight: 800;
        color: #fff;
        letter-spacing: -0.02em;
    }
    .tm-mobi-title span {
        display: block;
        margin-top: 2px;
        font-size: 0.78rem;
        font-weight: 600;
        color: #cbd5e1;
    }
    .tm-mobi-label {
        margin: 0 2px 8px;
        font-family: var(--font-thai);
        font-size: 0.78rem;
        font-weight: 800;
        color: #fde68a;
    }
    
