/* Giao diện Mầm Non Tối Ưu Máy Tính Bảng (iPad / Android Tablet Ngang & Dọc) */
:root {
  --bg-top: #FFF9EB;
  --bg-bottom: #E8F7FF;
  --card-bg: #FFFFFF;
  --text-main: #2B2D42;
  --text-muted: #5C677D;
  --hl-red: #FA5252;
  --radius-xl: 24px;
  --radius-lg: 18px;
  --radius-md: 14px;
  --font-kid: 'Segoe UI', 'Arial Rounded MT Bold', system-ui, -apple-system, sans-serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
}

html, body {
  width: 100%;
  max-width: 100vw;
  height: 100%;
  overflow-x: hidden;
  font-family: var(--font-kid);
  color: var(--text-main);
  background: linear-gradient(180deg, var(--bg-top) 0%, var(--bg-bottom) 100%);
  user-select: none;
  -webkit-user-select: none;
  overscroll-behavior: none;
}

button {
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    radial-gradient(circle at 10% 14%, rgba(255, 212, 59, 0.16) 0, rgba(255, 212, 59, 0.16) 48px, transparent 50px),
    radial-gradient(circle at 90% 12%, rgba(255, 107, 107, 0.12) 0, rgba(255, 107, 107, 0.12) 56px, transparent 58px),
    radial-gradient(circle at 86% 86%, rgba(81, 207, 102, 0.14) 0, rgba(81, 207, 102, 0.14) 52px, transparent 54px);
  z-index: 0;
}

/* ==================== KHUNG APP VỪA KHÍT MÀN HÌNH TABLET (100dvh) ==================== */
.app-shell {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 1440px;
  height: 100vh;
  height: 100dvh;
  max-height: 100dvh;
  margin: 0 auto;
  padding:
    max(8px, env(safe-area-inset-top))
    max(12px, env(safe-area-inset-right))
    max(10px, env(safe-area-inset-bottom))
    max(12px, env(safe-area-inset-left));
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow: hidden;
}

/* ==================== HEADER CẢM ỨNG LỚN GỌN GÀNG ==================== */
.top-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: rgba(255, 255, 255, 0.96);
  border: 3px solid #FFE8A3;
  border-radius: 22px;
  padding: 6px 14px;
  box-shadow: 0 5px 16px rgba(43, 45, 66, 0.07);
  flex-shrink: 0;
  min-width: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  flex: 0 1 auto;
  overflow: hidden;
}

.brand-mascot {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  background: linear-gradient(135deg, #FF6B6B, #FFA94D);
  display: grid;
  place-items: center;
  font-size: 24px;
  box-shadow: 0 3px 0 #D9480F;
  flex-shrink: 0;
}

.brand-text {
  min-width: 0;
  overflow: hidden;
}

.brand-text h1 {
  font-size: clamp(1.05rem, 1.8vw, 1.38rem);
  font-weight: 900;
  color: #D9480F;
  line-height: 1.18;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.brand-sub {
  font-size: 0.76rem;
  font-weight: 700;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.mode-tabs {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

.mode-tab {
  border: none;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.96rem;
  font-weight: 900;
  min-height: 44px;
  padding: 7px 16px;
  border-radius: 999px;
  background: #F1F3F5;
  color: #495057;
  box-shadow: 0 4px 0 #DEE2E6;
  transition: transform 0.1s ease, background 0.15s ease;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  flex-shrink: 0;
}

.mode-tab:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 #CED4DA;
}

.mode-tab.active[data-mode="learn"] {
  background: #FF6B6B;
  color: #FFF;
  box-shadow: 0 4px 0 #C92A2A;
}

.mode-tab.active[data-mode="trace"] {
  background: #845EF7;
  color: #FFF;
  box-shadow: 0 4px 0 #5F3DC4;
}

.mode-tab.active[data-mode="quiz"] {
  background: #40C057;
  color: #FFF;
  box-shadow: 0 4px 0 #2B8A3E;
}

.header-status {
  display: flex;
  align-items: center;
  gap: 7px;
  flex-shrink: 0;
}

.star-pill {
  background: #FFF9DB;
  border: 2.5px solid #FFD43B;
  border-radius: 999px;
  min-height: 42px;
  padding: 5px 13px;
  font-weight: 900;
  font-size: 1rem;
  color: #D9480F;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  box-shadow: 0 3px 0 #FAB005;
  white-space: nowrap;
}

.icon-btn {
  border: 2px solid #DEE2E6;
  background: #FFF;
  border-radius: 14px;
  min-height: 42px;
  padding: 6px 12px;
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 800;
  color: var(--text-main);
  cursor: pointer;
  box-shadow: 0 3px 0 #DEE2E6;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  white-space: nowrap;
  flex-shrink: 0;
}

.icon-btn:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 #DEE2E6;
}

.icon-btn.muted {
  background: #FFF0F0;
  border-color: #FFA8A8;
  color: #C92A2A;
}

/* ==================== PROGRESS BAR ==================== */
.progress-strip {
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(255, 255, 255, 0.9);
  border-radius: 999px;
  padding: 4px 10px 4px 15px;
  border: 2px solid #E7F5FF;
  flex-shrink: 0;
  min-width: 0;
}

.progress-label {
  font-size: 0.86rem;
  font-weight: 800;
  color: #1971C2;
  white-space: nowrap;
}

.progress-track {
  flex: 1;
  height: 11px;
  background: #E9ECEF;
  border-radius: 999px;
  overflow: hidden;
  min-width: 50px;
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #51CF66, #FFD43B, #FF6B6B);
  border-radius: 999px;
  transition: width 0.35s ease;
}

.btn-compact-pill {
  min-height: 32px;
  padding: 3px 11px;
  font-size: 0.8rem;
  border-radius: 999px;
}

/* ==================== MODE VIEWS ==================== */
.mode-view {
  display: none;
  flex: 1;
  min-height: 0;
  min-width: 0;
  overflow: hidden;
}

.mode-view.active {
  display: flex;
  flex-direction: column;
  animation: fadeSlideIn 0.2s ease;
}

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

/* ==================== CHẾ ĐỘ 1: BỐ CỤC CHIA ĐÔI TABLET (NGANG & DỌC) ==================== */
.learn-workspace {
  flex: 1;
  min-height: 0;
  min-width: 0;
  width: 100%;
  display: grid;
  grid-template-columns: minmax(0, 1.06fr) minmax(0, 0.94fr);
  grid-template-rows: minmax(0, 1fr);
  gap: 12px;
  overflow: hidden;
}

/* Khi bật chế độ Phóng to Thẻ học lớn (Cinema Flashcard Mode) */
.learn-workspace.expanded-stage {
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr) 114px;
}

.learn-workspace.expanded-stage .stage-body {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 18px;
  align-items: center;
}

.learn-workspace.expanded-stage .alphabet-dock {
  padding: 8px 12px;
}

.learn-workspace.expanded-stage .filter-bar {
  display: none;
}

.learn-workspace.expanded-stage .alphabet-grid-scroll {
  overflow-x: auto;
  overflow-y: hidden;
  padding: 2px 4px;
}

.learn-workspace.expanded-stage .alphabet-grid {
  display: flex;
  flex-wrap: nowrap;
  gap: 10px;
  width: max-content;
}

.learn-workspace.expanded-stage .alpha-tile {
  width: 96px;
  flex-shrink: 0;
  padding: 6px 6px 8px;
}

.learn-workspace.expanded-stage .tile-mini-illus {
  display: none;
}

/* Thẻ Học Tương Tác Chính */
.learn-stage {
  background: var(--card-bg);
  border-radius: var(--radius-xl);
  border: 4px solid var(--stage-color, #FF6B6B);
  box-shadow: 0 6px 20px rgba(43, 45, 66, 0.08);
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 8px;
  min-height: 0;
  min-width: 0;
  width: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  touch-action: pan-y;
  transition: border-color 0.22s ease;
}

.learn-stage.swipe-left-anim {
  animation: cardSwipeLeft 0.22s ease;
}

.learn-stage.swipe-right-anim {
  animation: cardSwipeRight 0.22s ease;
}

@keyframes cardSwipeLeft {
  0% { transform: translateX(18px); opacity: 0.78; }
  100% { transform: translateX(0); opacity: 1; }
}

@keyframes cardSwipeRight {
  0% { transform: translateX(-18px); opacity: 0.78; }
  100% { transform: translateX(0); opacity: 1; }
}

.stage-top-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
  flex-shrink: 0;
}

.badge-group {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.pill-badge {
  padding: 4px 11px;
  border-radius: 999px;
  font-size: 0.84rem;
  font-weight: 800;
  white-space: nowrap;
}

.pill-order {
  background: #2B2D42;
  color: #FFF;
}

.pill-type.vowel {
  background: #FFF0F6;
  color: #C2255C;
  border: 2px solid #FCC2D7;
}

.pill-type.cons {
  background: #E7F5FF;
  color: #1864AB;
  border: 2px solid #A5D8FF;
}

.pill-phonetic {
  background: #FFF9DB;
  color: #E67700;
  border: 2px solid #FFE066;
}

.autoplay-btn {
  border: none;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.88rem;
  font-weight: 800;
  min-height: 38px;
  padding: 5px 14px;
  border-radius: 999px;
  background: #EDF2FF;
  color: #364FC7;
  box-shadow: 0 3px 0 #BAC8FF;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

.autoplay-btn.playing {
  background: #FA5252;
  color: #FFF;
  box-shadow: 0 3px 0 #C92A2A;
}

.stage-body {
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1;
  justify-content: center;
  min-height: 0;
  min-width: 0;
}

.letters-showcase {
  display: flex;
  flex-direction: column;
  gap: 7px;
  min-width: 0;
}

.letter-boxes {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 9px;
}

.letter-box {
  font-family: inherit;
  background: var(--stage-soft, #FFF0F0);
  border: 3px solid rgba(0, 0, 0, 0.06);
  border-radius: 18px;
  padding: 6px 4px 5px;
  text-align: center;
  cursor: pointer;
  transition: transform 0.12s ease;
  min-width: 0;
}

.letter-box:active {
  transform: scale(0.95);
}

.letter-box-caption {
  display: block;
  font-size: 0.72rem;
  font-weight: 900;
  color: var(--text-muted);
}

.big-glyph {
  font-size: clamp(2.5rem, 4.1vw, 3.85rem);
  font-weight: 900;
  line-height: 1.18;
  color: var(--stage-color, #FF6B6B);
  text-shadow: 0 3px 0 rgba(0, 0, 0, 0.07);
  display: block;
}

.letter-box.oly-grid {
  background-color: #FFFFFF;
  background-image:
    linear-gradient(to bottom, rgba(51, 154, 240, 0.25) 1px, transparent 1px),
    linear-gradient(to right, rgba(51, 154, 240, 0.16) 1px, transparent 1px);
  background-size: 20px 20px;
  border: 3px solid #A5D8FF;
}

.cursive-glyph {
  font-family: 'Segoe Script', 'Comic Sans MS', 'Bradley Hand', cursive, sans-serif;
  font-size: clamp(2.25rem, 3.6vw, 3.35rem);
  font-weight: 700;
  line-height: 1.24;
  color: #1864AB;
  display: block;
}

.stroke-tip-bar {
  background: #F8F9FA;
  border-left: 4px solid var(--stage-color, #FF6B6B);
  border-radius: 10px;
  padding: 6px 10px;
  font-size: 0.84rem;
  font-weight: 700;
  color: #495057;
}

/* Hàng Tranh SVG + Từ Vựng nằm ngang gọn đẹp trên Tablet */
.word-showcase {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  background: var(--stage-soft, #FFF5F5);
  border-radius: 18px;
  padding: 8px 14px;
  border: 2.5px dashed rgba(0, 0, 0, 0.08);
  min-width: 0;
}

.illus-frame {
  width: clamp(108px, 13.5vw, 148px);
  height: clamp(108px, 13.5vw, 148px);
  flex-shrink: 0;
  cursor: pointer;
  filter: drop-shadow(0 6px 12px rgba(0, 0, 0, 0.1));
}

.illus-frame:active {
  transform: scale(0.95);
}

.illus-frame.pop-anim {
  animation: jellyBounce 0.6s ease;
}

.letter-svg {
  width: 100%;
  height: 100%;
  display: block;
}

.letter-svg .illus-actor {
  transform-origin: 110px 110px;
  animation: gentleFloat 3.2s ease-in-out infinite;
}

@keyframes gentleFloat {
  0%, 100% { transform: translateY(0px); }
  50% { transform: translateY(-5px); }
}

@keyframes jellyBounce {
  0%   { transform: scale(1); }
  30%  { transform: scale(1.14) rotate(3deg); }
  55%  { transform: scale(0.94) rotate(-2deg); }
  80%  { transform: scale(1.05) rotate(1deg); }
  100% { transform: scale(1); }
}

.word-info-col {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  text-align: left;
  min-width: 0;
  flex: 1;
}

.main-word-title {
  font-size: clamp(1.5rem, 2.4vw, 2.05rem);
  font-weight: 900;
  color: var(--text-main);
  line-height: 1.22;
  cursor: pointer;
}

.hl-letter {
  color: var(--hl-red);
  text-decoration: underline;
  text-decoration-thickness: 3.5px;
  text-underline-offset: 4px;
  font-weight: 900;
}

.rhyme-line {
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--text-muted);
  margin: 2px 0 7px;
}

.extra-words-row {
  display: flex;
  gap: 7px;
  flex-wrap: wrap;
}

.extra-chip {
  border: 2px solid rgba(0, 0, 0, 0.08);
  background: #FFFFFF;
  border-radius: 999px;
  min-height: 38px;
  padding: 5px 12px;
  font-family: inherit;
  font-size: 0.88rem;
  font-weight: 800;
  color: var(--text-main);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.07);
}

.extra-chip:active {
  transform: translateY(2px);
}

/* Cụm nút bấm cảm ứng lớn dưới chân thẻ */
.stage-footer-controls {
  display: flex;
  flex-direction: column;
  gap: 7px;
  flex-shrink: 0;
}

.action-buttons,
.nav-arrows-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.kid-btn {
  border: none;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.94rem;
  font-weight: 900;
  min-height: 46px;
  padding: 8px 10px;
  border-radius: 15px;
  color: #FFF;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  white-space: nowrap;
  transition: transform 0.1s ease, filter 0.12s ease;
}

.kid-btn:active {
  transform: translateY(3px);
}

.btn-speak-letter {
  background: #FF6B6B;
  box-shadow: 0 4px 0 #C92A2A;
}

.btn-speak-word {
  background: #339AF0;
  box-shadow: 0 4px 0 #1864AB;
}

.btn-speak-card {
  background: #40C057;
  box-shadow: 0 4px 0 #2B8A3E;
}

.btn-nav {
  background: #FFF3BF;
  color: #D9480F;
  border: 2px solid #FFD43B;
  box-shadow: 0 4px 0 #FAB005;
}

.btn-go-trace {
  background: #845EF7;
  box-shadow: 0 4px 0 #5F3DC4;
}

.btn-clear-trace {
  background: #FF922B;
  box-shadow: 0 4px 0 #D9480F;
}

.swipe-hint {
  text-align: center;
  font-size: 0.75rem;
  font-weight: 700;
  color: #868E96;
}

/* ==================== KHUNG BẢNG 29 CHỮ CÁI CUỘN ĐỘC LẬP MƯỢT MÀ ==================== */
.alphabet-dock {
  background: rgba(255, 255, 255, 0.88);
  border: 3px solid #E7F5FF;
  border-radius: var(--radius-xl);
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 0;
  min-width: 0;
  width: 100%;
  max-width: 100%;
  overflow: hidden;
}

.filter-bar {
  display: flex;
  gap: 7px;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 2px 2px 6px;
  flex-shrink: 0;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
}

.filter-pill {
  border: 2px solid #DEE2E6;
  background: #FFF;
  border-radius: 999px;
  min-height: 38px;
  padding: 5px 13px;
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 800;
  color: #495057;
  cursor: pointer;
  white-space: nowrap;
  box-shadow: 0 2px 0 #E9ECEF;
  flex-shrink: 0;
}

.filter-pill.active {
  background: #339AF0;
  border-color: #1C7ED6;
  color: #FFF;
  box-shadow: 0 2px 0 #1864AB;
}

.alphabet-grid-scroll {
  flex: 1;
  min-height: 0;
  min-width: 0;
  width: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 4px 4px 10px;
}

.alphabet-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(104px, 1fr));
  gap: 10px;
  width: 100%;
}

.alpha-tile {
  background: #FFFFFF;
  border: 3px solid var(--tile-color, #FF6B6B);
  border-radius: 18px;
  padding: 7px 6px 9px;
  cursor: pointer;
  text-align: center;
  position: relative;
  box-shadow: 0 5px 0 var(--tile-color, #FF6B6B);
  transition: transform 0.12s ease, box-shadow 0.12s ease;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 0;
  touch-action: manipulation;
}

.alpha-tile:active {
  transform: translateY(3px);
  box-shadow: 0 2px 0 var(--tile-color, #FF6B6B);
}

.alpha-tile.selected {
  background: var(--tile-soft, #FFF5F5);
  outline: 3.5px solid #FFD43B;
}

.tile-num {
  position: absolute;
  top: 5px;
  left: 6px;
  font-size: 0.7rem;
  font-weight: 900;
  color: var(--text-muted);
  background: #F1F3F5;
  border-radius: 999px;
  padding: 1px 6px;
}

.tile-seen {
  position: absolute;
  top: 4px;
  right: 6px;
  font-size: 0.82rem;
}

.tile-letters {
  font-size: 1.65rem;
  font-weight: 900;
  line-height: 1.22;
  color: var(--tile-color, #FF6B6B);
  margin-top: 10px;
}

.tile-mini-illus {
  width: 50px;
  height: 50px;
  margin: 2px auto;
}

.tile-word {
  font-size: 0.84rem;
  font-weight: 800;
  color: var(--text-main);
  line-height: 1.2;
}

/* ==================== CHẾ ĐỘ 2: TẬP TÔ CẢM ỨNG & BÚT STYLUS ==================== */
.trace-panel {
  background: #FFFFFF;
  border-radius: var(--radius-xl);
  border: 4px solid #845EF7;
  box-shadow: 0 6px 20px rgba(132, 94, 247, 0.14);
  padding: 12px 16px;
  flex: 1;
  min-height: 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.trace-layout {
  display: grid;
  grid-template-columns: 272px minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr);
  gap: 16px;
  flex: 1;
  min-height: 0;
  min-width: 0;
}

.trace-sidebar {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 0;
  min-width: 0;
  overflow: hidden;
}

.trace-case-toggle {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.trace-case-toggle .icon-btn {
  flex: 1;
  padding: 6px 8px;
  font-size: 0.85rem;
}

.trace-case-toggle .icon-btn.active-case {
  background: #F3F0FF;
  border-color: #845EF7;
  color: #5F3DC4;
}

.trace-picker {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 6px;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 2px;
  flex: 1;
  min-height: 0;
  min-width: 0;
}

.trace-letter-btn {
  border: 2px solid #E9ECEF;
  background: #F8F9FA;
  border-radius: 13px;
  min-height: 44px;
  font-family: inherit;
  font-size: 1.2rem;
  font-weight: 900;
  cursor: pointer;
  color: var(--text-main);
}

.trace-letter-btn.active {
  background: #845EF7;
  border-color: #5F3DC4;
  color: #FFF;
}

.trace-stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 0;
  min-width: 0;
  overflow: hidden;
}

.trace-header-bar {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  flex-shrink: 0;
}

.trace-header-bar h2 {
  font-size: 1.24rem;
  color: #5F3DC4;
}

.trace-header-bar p {
  font-size: 0.84rem;
  font-weight: 700;
  color: var(--text-muted);
}

.brush-size-group {
  display: inline-flex;
  background: #F1F3F5;
  padding: 4px;
  border-radius: 999px;
  gap: 4px;
  flex-shrink: 0;
}

.brush-btn {
  border: none;
  background: transparent;
  border-radius: 999px;
  padding: 6px 13px;
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 800;
  color: #495057;
  cursor: pointer;
}

.brush-btn.active {
  background: #845EF7;
  color: #FFF;
}

.trace-board-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  flex: 1;
  min-height: 0;
  min-width: 0;
  width: 100%;
}

.trace-controls {
  display: flex;
  flex-direction: column;
  gap: 9px;
  flex-shrink: 0;
}

.crayon-dot {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 3px solid #FFF;
  box-shadow: 0 0 0 2px #CED4DA;
  cursor: pointer;
  transition: transform 0.12s ease;
}

.crayon-dot.active {
  transform: scale(1.18);
  box-shadow: 0 0 0 3.5px #2B2D42;
}

.crayon-rainbow {
  background: conic-gradient(#FF6B6B, #FFD43B, #51CF66, #339AF0, #845EF7, #FF6B6B);
}

.canvas-wrap {
  position: relative;
  width: min(100%, 400px, calc(100dvh - 285px));
  aspect-ratio: 1 / 1;
  border-radius: 22px;
  border: 4px solid #A5D8FF;
  background-color: #FFFFFF;
  background-image:
    linear-gradient(to bottom, rgba(51, 154, 240, 0.24) 1.5px, transparent 1.5px),
    linear-gradient(to right, rgba(51, 154, 240, 0.18) 1.5px, transparent 1.5px);
  background-size: 40px 40px;
  overflow: hidden;
  box-shadow: inset 0 4px 12px rgba(0, 0, 0, 0.04);
  touch-action: none;
  flex-shrink: 0;
}

#traceCanvas {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

.trace-actions-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 175px));
  gap: 10px;
  width: 100%;
  justify-content: center;
  flex-shrink: 0;
}

/* ==================== CHẾ ĐỘ 3: ĐỐ VUI TABLET 2x2 CHẠM HAI TAY ==================== */
.quiz-panel {
  background: #FFFFFF;
  border-radius: var(--radius-xl);
  border: 4px solid #40C057;
  box-shadow: 0 6px 20px rgba(64, 192, 87, 0.14);
  padding: 14px 18px;
  flex: 1;
  min-height: 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow: hidden;
}

.quiz-top-bar {
  display: flex;
  justify-content: center;
  flex-shrink: 0;
}

.quiz-mode-switch {
  display: inline-flex;
  gap: 8px;
  background: #F1F3F5;
  padding: 5px;
  border-radius: 999px;
}

.quiz-sub-btn {
  border: none;
  background: transparent;
  min-height: 42px;
  padding: 7px 18px;
  border-radius: 999px;
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 900;
  cursor: pointer;
  color: #495057;
  white-space: nowrap;
}

.quiz-sub-btn.active {
  background: #40C057;
  color: #FFF;
  box-shadow: 0 3px 0 #2B8A3E;
}

.quiz-tablet-grid {
  flex: 1;
  min-height: 0;
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr);
  grid-template-rows: minmax(0, 1fr);
  gap: 18px;
  align-items: center;
}

.quiz-prompt-card {
  background: #F8F9FA;
  border: 3px dashed #8CE99A;
  border-radius: 22px;
  padding: 16px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 100%;
  max-height: 400px;
  min-height: 0;
  min-width: 0;
}

.quiz-prompt-title {
  font-size: 1.25rem;
  font-weight: 900;
  color: #2B8A3E;
}

.quiz-illus-box {
  width: 136px;
  height: 136px;
  flex-shrink: 0;
}

.quiz-word-mask {
  font-size: 1.95rem;
  font-weight: 900;
  letter-spacing: 1px;
}

.quiz-replay-btn {
  width: 100%;
  max-width: 250px;
}

.quiz-options {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  min-width: 0;
}

.quiz-opt-btn {
  background: #FFFFFF;
  border: 4px solid var(--opt-color, #339AF0);
  border-radius: 22px;
  min-height: 122px;
  padding: 14px 10px;
  font-family: inherit;
  font-size: clamp(2.2rem, 3.8vw, 2.9rem);
  font-weight: 900;
  color: var(--opt-color, #339AF0);
  cursor: pointer;
  box-shadow: 0 6px 0 var(--opt-color, #339AF0);
  transition: transform 0.12s ease;
}

.quiz-opt-btn:active {
  transform: translateY(4px);
  box-shadow: 0 2px 0 var(--opt-color, #339AF0);
}

.quiz-opt-btn.correct {
  background: #D3F9D8;
  border-color: #2B8A3E;
  color: #2B8A3E;
  animation: jellyBounce 0.6s ease;
}

.quiz-opt-btn.wrong {
  background: #FFE3E3;
  opacity: 0.65;
  animation: shakeAnim 0.4s ease;
}

@keyframes shakeAnim {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-8px); }
  75% { transform: translateX(8px); }
}

.quiz-feedback {
  min-height: 24px;
  font-size: 1.02rem;
  font-weight: 900;
  color: #D9480F;
}

/* Chỉ bật hiệu ứng hover trên thiết bị có chuột thật */
@media (hover: hover) and (pointer: fine) {
  .mode-tab:hover { transform: translateY(-2px); }
  .kid-btn:hover { filter: brightness(1.05); transform: translateY(-2px); }
  .alpha-tile:hover { transform: translateY(-3px); box-shadow: 0 8px 0 var(--tile-color, #FF6B6B); }
  .quiz-opt-btn:hover { transform: translateY(-3px); }
  .letter-box:hover { transform: translateY(-2px); }
}

#confettiCanvas {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  pointer-events: none;
  z-index: 999;
}

/* Gọn thanh Header trên Tablet ngang <= 1180px để 100% nằm trên 1 dòng thoáng đãng */
@media (max-width: 1180px) {
  .hide-compact,
  .brand-sub {
    display: none;
  }
}

/* ==================== MÁY TÍNH BẢNG CẦM DỌC (PORTRAIT TABLET: <= 960px) ==================== */
@media (max-width: 960px) {
  .mode-tab {
    padding: 7px 13px;
    font-size: 0.9rem;
  }

  /* Chia đôi Trên (Thẻ học cố định) - Dưới (Bảng 29 chữ cuộn mượt) */
  .learn-workspace {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr);
    gap: 10px;
  }

  .learn-stage {
    padding: 10px 14px;
    gap: 7px;
  }

  .stage-body {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1.05fr);
    gap: 12px;
    align-items: center;
  }

  .big-glyph {
    font-size: 2.5rem;
  }

  .cursive-glyph {
    font-size: 2.25rem;
  }

  .illus-frame {
    width: 104px;
    height: 104px;
  }

  .main-word-title {
    font-size: 1.48rem;
  }

  .swipe-hint {
    display: none;
  }

  /* Tập tô ở chế độ cầm dọc Tablet */
  .trace-layout {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr);
    gap: 10px;
  }

  .trace-picker {
    display: flex;
    flex-wrap: nowrap;
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    padding-bottom: 6px;
  }

  .trace-letter-btn {
    width: 50px;
    flex-shrink: 0;
  }

  .trace-board-row {
    flex-direction: column;
    gap: 10px;
  }

  .trace-controls {
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: center;
  }

  .canvas-wrap {
    width: min(76vw, 410px, calc(100dvh - 380px));
  }

  /* Đố vui ở chế độ cầm dọc Tablet */
  .quiz-tablet-grid {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr);
    gap: 12px;
  }

  .quiz-prompt-card {
    padding: 14px;
    max-height: none;
    height: auto;
  }

  .quiz-illus-box {
    width: 120px;
    height: 120px;
  }

  .quiz-opt-btn {
    min-height: 106px;
  }
}

/* ==================== MÀN HÌNH ĐIỆN THOẠI NHỎ HOẶC XOAY NGANG RẤT THẤP ==================== */
@media (max-width: 640px), (max-height: 580px) {
  .app-shell {
    height: auto;
    max-height: none;
    min-height: 100dvh;
    overflow-y: visible;
  }

  .mode-view,
  .learn-workspace,
  .trace-panel,
  .quiz-panel {
    overflow: visible;
  }

  .top-header {
    justify-content: center;
    flex-wrap: wrap;
  }

  .stage-body,
  .learn-workspace.expanded-stage .stage-body {
    display: flex;
    flex-direction: column;
  }

  .word-showcase {
    flex-direction: column;
    text-align: center;
  }

  .word-info-col {
    align-items: center;
    text-align: center;
  }

  .alphabet-grid-scroll {
    max-height: 420px;
  }

  .canvas-wrap {
    width: min(86vw, 340px);
  }

  .trace-actions-row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
