/* ============================================================================
   LEARNHANZII - HSK 1 MASTER WEB APP STYLES
   ============================================================================ */

:root {
  --bg-main: #faf7f2;
  --bg-card: #ffffff;
  --bg-subtle: #f3ede2;
  --bg-accent-soft: #fff1f0;
  --text-main: #1f2421;
  --text-secondary: #5a626a;
  --text-muted: #8b939c;

  --primary: #d93829;
  --primary-hover: #b8281a;
  --primary-dark: #b8281a;
  --primary-light: #ffe4e1;

  --jade: #0d9488;
  --jade-light: #ccfbf1;

  --gold: #d97706;
  --gold-light: #fef3c7;

  --indigo: #4f46e5;
  --indigo-light: #e0e7ff;

  --border: #e6dfd3;
  --shadow-sm: 0 2px 8px rgba(31, 36, 33, 0.05);
  --shadow-md: 0 8px 24px rgba(31, 36, 33, 0.08);
  --shadow-lg: 0 16px 40px rgba(31, 36, 33, 0.12);

  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-xl: 28px;

  --font-sans: 'Plus Jakarta Sans', 'Segoe UI', system-ui, -apple-system, sans-serif;
  --font-hanzi: 'Noto Serif SC', 'KaiTi', 'STKaiti', 'SimSun', 'Microsoft YaHei', serif;
}

[data-theme="dark"] {
  --bg-main: #121519;
  --bg-card: #1b2026;
  --bg-subtle: #252b33;
  --bg-accent-soft: #2d1a1a;
  --text-main: #f3f4f6;
  --text-secondary: #9ca3af;
  --text-muted: #6b7280;
  --border: #2e3640;
  --primary-dark: #ef4444;
  --primary-light: #3b1919;
  --jade-light: #133330;
  --gold-light: #362812;
  --indigo-light: #1e2142;
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.25);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.5);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-sans);
  background-color: var(--bg-main);
  color: var(--text-main);
  line-height: 1.6;
  min-height: 100vh;
  transition: background-color 0.25s ease, color 0.25s ease;
  background-image: radial-gradient(circle at 10% 10%, rgba(217, 56, 41, 0.04) 0%, transparent 40%),
                    radial-gradient(circle at 90% 80%, rgba(13, 148, 136, 0.04) 0%, transparent 40%);
}

.hanzi-font {
  font-family: var(--font-hanzi);
}

/* ============================================================================
   HEADER & NAVIGATION
   ============================================================================ */
.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(255, 255, 255, 0.88);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  transition: background 0.25s ease;
}

[data-theme="dark"] .app-header {
  background: rgba(27, 32, 38, 0.88);
}

.header-inner {
  max-width: 1320px;
  margin: 0 auto;
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  color: var(--text-main);
}

.brand-seal {
  width: 44px;
  height: 44px;
  background: linear-gradient(135deg, var(--primary), #991b1b);
  color: #fff;
  border-radius: 11px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-hanzi);
  font-size: 24px;
  font-weight: 700;
  box-shadow: 0 4px 12px rgba(217, 56, 41, 0.35);
  border: 2px solid rgba(255, 255, 255, 0.25);
}

.brand-text h1 {
  font-size: 1.2rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.2;
}

.brand-text span {
  font-size: 0.78rem;
  color: var(--text-secondary);
  font-weight: 500;
}

.main-nav {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-subtle);
  padding: 5px;
  border-radius: 14px;
  flex-wrap: wrap;
}

.nav-tab {
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  padding: 8px 15px;
  border-radius: 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 7px;
  transition: all 0.2s ease;
}

.nav-tab:hover {
  color: var(--text-main);
  background: rgba(255, 255, 255, 0.45);
}

.nav-tab.active {
  background: var(--bg-card);
  color: var(--primary);
  box-shadow: var(--shadow-sm);
}

.header-stats {
  display: flex;
  align-items: center;
  gap: 10px;
}

.stat-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-subtle);
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-main);
}

.icon-btn {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-main);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.05rem;
  transition: all 0.2s ease;
}

.icon-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
  transform: translateY(-1px);
}

/* ============================================================================
   MAIN CONTAINER & SECTIONS
   ============================================================================ */
.app-container {
  max-width: 1320px;
  margin: 0 auto;
  padding: 24px;
}

.tab-section {
  display: none;
  animation: fadeIn 0.25s ease;
}

.tab-section.active {
  display: block;
}

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

/* ============================================================================
   HERO / PROGRESS BANNER
   ============================================================================ */
.hero-banner {
  background: linear-gradient(135deg, #b91c1c 0%, #d93829 55%, #ea580c 100%);
  color: #ffffff;
  border-radius: var(--radius-lg);
  padding: 24px 28px;
  margin-bottom: 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  flex-wrap: wrap;
  box-shadow: 0 12px 30px rgba(217, 56, 41, 0.22);
  position: relative;
  overflow: hidden;
}

.hero-banner::after {
  content: '漢';
  position: absolute;
  right: 20px;
  bottom: -35px;
  font-family: var(--font-hanzi);
  font-size: 170px;
  color: rgba(255, 255, 255, 0.08);
  pointer-events: none;
  user-select: none;
}

.hero-info h2 {
  font-size: 1.55rem;
  font-weight: 800;
  margin-bottom: 6px;
}

.hero-info p {
  font-size: 0.95rem;
  opacity: 0.92;
  max-width: 620px;
}

.hero-progress-box {
  background: rgba(255, 255, 255, 0.14);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.24);
  padding: 16px 22px;
  border-radius: var(--radius-md);
  min-width: 280px;
}

.progress-header {
  display: flex;
  justify-content: space-between;
  font-size: 0.88rem;
  font-weight: 700;
  margin-bottom: 8px;
}

.progress-bar-track {
  width: 100%;
  height: 10px;
  background: rgba(0, 0, 0, 0.22);
  border-radius: 99px;
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  background: #fde047;
  border-radius: 99px;
  width: 0%;
  transition: width 0.4s ease;
}

.hero-quick-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
  flex-wrap: wrap;
}

.btn-hero-sm {
  background: rgba(255, 255, 255, 0.92);
  color: #991b1b;
  border: none;
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-hero-sm:hover {
  background: #ffffff;
  transform: translateY(-1px);
}

/* ============================================================================
   VOCABULARY CONTROLS & FILTERS
   ============================================================================ */
.vocab-toolbar {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px 20px;
  margin-bottom: 16px;
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  align-items: center;
  justify-content: space-between;
  box-shadow: var(--shadow-sm);
}

.search-box {
  position: relative;
  flex: 1;
  min-width: 240px;
}

.search-box input {
  width: 100%;
  padding: 11px 16px 11px 40px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg-main);
  color: var(--text-main);
  font-family: inherit;
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.2s;
}

.search-box input:focus {
  border-color: var(--primary);
}

.search-icon {
  position: absolute;
  left: 13px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
}

.toolbar-group {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.select-control {
  padding: 10px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-main);
  color: var(--text-main);
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  outline: none;
}

.view-switcher {
  display: flex;
  background: var(--bg-subtle);
  padding: 4px;
  border-radius: 10px;
  gap: 4px;
}

.view-btn {
  border: none;
  background: transparent;
  color: var(--text-secondary);
  padding: 7px 13px;
  border-radius: 7px;
  font-size: 0.86rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
}

.view-btn.active {
  background: var(--bg-card);
  color: var(--primary);
  box-shadow: var(--shadow-sm);
}

/* Category Chips with Scroll & Arrow Controls */
.category-chips-wrapper {
  position: relative;
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 16px;
  width: 100%;
}

.chips-arrow {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-main);
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.95rem;
  flex-shrink: 0;
  transition: all 0.18s ease;
  user-select: none;
}

.chips-arrow:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--primary-light);
  transform: scale(1.06);
}

.category-chips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 4px 2px 8px;
  flex: 1;
  scroll-behavior: smooth;
  scroll-snap-type: x proximity;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
}

.category-chips::-webkit-scrollbar {
  height: 5px;
}

.category-chips::-webkit-scrollbar-track {
  background: var(--bg-main);
  border-radius: 999px;
}

.category-chips::-webkit-scrollbar-thumb {
  background: rgba(217, 56, 41, 0.3);
  border-radius: 999px;
}

.category-chips::-webkit-scrollbar-thumb:hover {
  background: var(--primary);
}

.cat-chip {
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-secondary);
  padding: 7px 14px;
  border-radius: 999px;
  font-size: 0.84rem;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex: 0 0 auto;
  scroll-snap-align: center;
  transition: all 0.18s ease;
  user-select: none;
}

.cat-chip:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--bg-main);
}

.cat-chip.active {
  background: var(--primary);
  color: #ffffff;
  border-color: var(--primary);
  box-shadow: 0 2px 8px rgba(217, 56, 41, 0.28);
}

/* ============================================================================
   VOCABULARY GRID & CARDS
   ============================================================================ */
.vocab-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(265px, 1fr));
  gap: 16px;
}

.vocab-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 18px;
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  transition: all 0.2s ease;
  box-shadow: var(--shadow-sm);
}

.vocab-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-md);
  border-color: rgba(217, 56, 41, 0.35);
}

.vocab-card.mastered {
  border-left: 4px solid var(--jade);
}

.card-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 8px;
}

.word-index {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-muted);
  background: var(--bg-subtle);
  padding: 2px 8px;
  border-radius: 6px;
}

.hsk-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 3px 9px;
  border-radius: 6px;
  font-size: 0.74rem;
  font-weight: 800;
  letter-spacing: 0.03em;
  white-space: nowrap;
  flex-shrink: 0;
  line-height: 1.2;
}

.hsk-badge-1 {
  background: var(--jade-light);
  color: var(--jade);
}

.hsk-badge-2 {
  background: var(--gold-light);
  color: var(--gold);
}

.hsk-badge-3 {
  background: var(--indigo-light);
  color: var(--indigo);
}

.hsk-level-pills {
  display: inline-flex;
  background: var(--bg-subtle);
  padding: 4px;
  border-radius: 11px;
  gap: 4px;
  flex-wrap: wrap;
}

.hsk-lvl-btn {
  border: none;
  background: transparent;
  color: var(--text-secondary);
  padding: 7px 13px;
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s ease;
}

.hsk-lvl-btn.active {
  background: var(--primary);
  color: #ffffff;
  box-shadow: var(--shadow-sm);
}

.card-actions {
  display: flex;
  gap: 6px;
}

.card-action-btn {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-main);
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.92rem;
  transition: all 0.15s;
}

.card-action-btn:hover {
  background: var(--primary-light);
  color: var(--primary);
  border-color: var(--primary);
}

.card-action-btn.active-star {
  background: var(--gold-light);
  color: var(--gold);
  border-color: var(--gold);
}

.card-action-btn.active-master {
  background: var(--jade-light);
  color: var(--jade);
  border-color: var(--jade);
}

.word-main {
  text-align: center;
  padding: 10px 0 14px;
  cursor: pointer;
}

.word-hanzi {
  font-family: var(--font-hanzi);
  font-size: 2.85rem;
  font-weight: 700;
  color: var(--text-main);
  line-height: 1.15;
  margin-bottom: 4px;
}

.word-pinyin {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 4px;
}

.word-hanviet {
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--jade);
  background: var(--jade-light);
  display: inline-block;
  padding: 2px 9px;
  border-radius: 99px;
  margin-bottom: 8px;
}

.word-meaning {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-main);
}

.word-example {
  border-top: 1px dashed var(--border);
  padding-top: 10px;
  margin-top: 8px;
  font-size: 0.84rem;
}

.ex-hanzi {
  font-family: var(--font-hanzi);
  font-size: 0.96rem;
  font-weight: 600;
  color: var(--text-main);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.ex-pinyin {
  color: var(--text-secondary);
  font-size: 0.8rem;
}

.ex-meaning {
  color: var(--text-muted);
  font-style: italic;
}

/* ============================================================================
   TABLE VIEW FOR VOCABULARY
   ============================================================================ */
.vocab-table-wrap {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow-x: auto;
  box-shadow: var(--shadow-sm);
}

.vocab-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
}

.vocab-table th,
.vocab-table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.vocab-table th:first-child,
.vocab-table td:first-child {
  width: 86px;
  min-width: 86px;
  white-space: nowrap;
  text-align: center;
}

.vocab-table th:last-child,
.vocab-table td:last-child {
  width: 1%;
  min-width: 124px;
  white-space: nowrap;
  text-align: center;
}

.vocab-table th {
  background: var(--bg-subtle);
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-secondary);
}

.vocab-table tr:hover {
  background: var(--bg-main);
}

.table-hanzi {
  font-family: var(--font-hanzi);
  font-size: 1.55rem;
  font-weight: 700;
}

/* ============================================================================
   3D FLASHCARD VIEW
   ============================================================================ */
.flashcard-stage {
  max-width: 680px;
  margin: 12px auto 32px;
  text-align: center;
}

.flashcard-progress {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  font-weight: 700;
  color: var(--text-secondary);
}

.flashcard-3d-wrapper {
  perspective: 1200px;
  height: 390px;
  margin-bottom: 20px;
  cursor: pointer;
}

.flashcard-3d-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transition: transform 0.55s cubic-bezier(0.4, 0, 0.2, 1);
  transform-style: preserve-3d;
}

.flashcard-3d-wrapper.flipped .flashcard-3d-inner {
  transform: rotateY(180deg);
}

.flashcard-face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  background: var(--bg-card);
  border: 2px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 32px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-lg);
}

.flashcard-back {
  transform: rotateY(180deg);
  border-color: var(--primary);
}

.fc-Front-hanzi {
  font-family: var(--font-hanzi);
  font-size: 5.8rem;
  font-weight: 700;
  line-height: 1.1;
  margin-bottom: 14px;
}

.fc-hint {
  font-size: 0.88rem;
  color: var(--text-muted);
  margin-top: 16px;
}

.fc-back-pinyin {
  font-size: 1.85rem;
  font-weight: 800;
  color: var(--primary);
  margin-bottom: 6px;
}

.fc-back-meaning {
  font-size: 1.45rem;
  font-weight: 700;
  margin: 10px 0 18px;
}

.fc-controls {
  display: flex;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
}

/* ============================================================================
   BUTTONS & COMMON UI
   ============================================================================ */
.btn {
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-main);
  padding: 10px 18px;
  border-radius: 11px;
  font-family: inherit;
  font-size: 0.92rem;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: all 0.18s ease;
}

.btn:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}

.btn-primary {
  background: var(--primary);
  color: #ffffff;
  border-color: var(--primary);
}

.btn-primary:hover {
  background: var(--primary-hover);
}

.btn-jade {
  background: var(--jade);
  color: #ffffff;
  border-color: var(--jade);
}

.btn-gold {
  background: var(--gold);
  color: #ffffff;
  border-color: var(--gold);
}

/* ============================================================================
   SECTION 2: GHÉP ĐOẠN VĂN (PASSAGE & SENTENCE BUILDER)
   ============================================================================ */
.passage-layout {
  display: grid;
  grid-template-columns: 310px 1fr;
  gap: 22px;
  align-items: start;
}

@media (max-width: 920px) {
  .passage-layout {
    grid-template-columns: 1fr;
  }
}

.passage-sidebar {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
  box-shadow: var(--shadow-sm);
}

.passage-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 12px;
}

.passage-item-btn {
  width: 100%;
  text-align: left;
  padding: 12px 14px;
  border-radius: 11px;
  border: 1px solid var(--border);
  background: var(--bg-main);
  color: var(--text-main);
  cursor: pointer;
  transition: all 0.18s;
}

.passage-item-btn:hover {
  border-color: var(--primary);
}

.passage-item-btn.active {
  background: var(--primary-light);
  border-color: var(--primary);
}

.passage-item-title {
  font-weight: 700;
  font-size: 0.94rem;
  margin-bottom: 3px;
}

.passage-item-meta {
  font-size: 0.78rem;
  color: var(--text-secondary);
}

.passage-workspace {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow-sm);
}

.passage-mode-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.mode-pill {
  border: 1px solid var(--border);
  background: var(--bg-main);
  color: var(--text-secondary);
  padding: 9px 16px;
  border-radius: 10px;
  font-weight: 700;
  font-size: 0.88rem;
  cursor: pointer;
  transition: all 0.18s;
}

.mode-pill.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.completed-passage-box {
  background: var(--bg-subtle);
  border-radius: var(--radius-md);
  padding: 16px 20px;
  margin-bottom: 20px;
  border-left: 4px solid var(--primary);
}

.sentence-build-area {
  background: var(--bg-main);
  border: 2px dashed var(--border);
  border-radius: var(--radius-md);
  min-height: 76px;
  padding: 14px;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin: 16px 0;
}

.token-pool {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 16px 0;
}

.word-token {
  background: var(--bg-card);
  border: 2px solid var(--border);
  border-radius: 11px;
  padding: 10px 16px;
  font-family: var(--font-hanzi);
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--text-main);
  cursor: pointer;
  user-select: none;
  transition: all 0.15s ease;
  box-shadow: var(--shadow-sm);
  display: inline-flex;
  flex-direction: column;
  align-items: center;
}

.word-token .token-py {
  font-family: var(--font-sans);
  font-size: 0.74rem;
  color: var(--primary);
  font-weight: 600;
}

.word-token:hover {
  border-color: var(--primary);
  transform: translateY(-2px);
}

.word-token.in-slot {
  background: var(--primary-light);
  border-color: var(--primary);
}

.paragraph-order-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 16px 0;
}

.order-sentence-card {
  background: var(--bg-main);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.order-controls {
  display: flex;
  gap: 6px;
}

/* ============================================================================
   SECTION 3: LUYỆN TẬP (ĐIỀN PINYIN, DỊCH VIỆT-TRUNG, DỊCH TRUNG-VIỆT)
   ============================================================================ */
.practice-header-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.practice-type-tabs {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
  margin-bottom: 22px;
}

.practice-mode-card {
  background: var(--bg-card);
  border: 2px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px 18px;
  cursor: pointer;
  transition: all 0.2s ease;
  text-align: left;
}

.practice-mode-card:hover {
  border-color: var(--primary);
  transform: translateY(-2px);
}

.practice-mode-card.active {
  border-color: var(--primary);
  background: var(--bg-accent-soft);
}

.practice-mode-card h3 {
  font-size: 1.05rem;
  margin-bottom: 4px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.practice-mode-card p {
  font-size: 0.83rem;
  color: var(--text-secondary);
}

.quiz-arena {
  max-width: 780px;
  margin: 0 auto;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 28px;
  box-shadow: var(--shadow-md);
}

.quiz-top-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  flex-wrap: wrap;
  gap: 10px;
}

.quiz-prompt-box {
  text-align: center;
  padding: 24px 16px;
  background: var(--bg-main);
  border-radius: var(--radius-md);
  margin-bottom: 20px;
  border: 1px solid var(--border);
}

.quiz-big-hanzi {
  font-family: var(--font-hanzi);
  font-size: 4.2rem;
  font-weight: 700;
  line-height: 1.15;
  margin-bottom: 8px;
}

.quiz-big-viet {
  font-size: 1.75rem;
  font-weight: 800;
  color: var(--text-main);
  margin-bottom: 8px;
}

.quiz-sub-hint {
  font-size: 0.95rem;
  color: var(--text-secondary);
}

/* Tone Keyboard for Pinyin Input */
.tone-keyboard {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
  margin-bottom: 14px;
  background: var(--bg-subtle);
  padding: 10px;
  border-radius: 12px;
}

.tone-key {
  min-width: 34px;
  height: 34px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-main);
  border-radius: 7px;
  font-weight: 700;
  font-size: 0.95rem;
  cursor: pointer;
  transition: all 0.12s;
}

.tone-key:hover {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.quiz-input-row {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
}

.quiz-text-input {
  flex: 1;
  padding: 14px 18px;
  font-size: 1.15rem;
  font-weight: 600;
  border: 2px solid var(--border);
  border-radius: 12px;
  background: var(--bg-main);
  color: var(--text-main);
  outline: none;
  transition: border-color 0.2s;
}

.quiz-text-input:focus {
  border-color: var(--primary);
}

.quiz-options-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-bottom: 18px;
}

@media (max-width: 600px) {
  .quiz-options-grid {
    grid-template-columns: 1fr;
  }
}

.quiz-option-btn {
  padding: 16px;
  border: 2px solid var(--border);
  border-radius: 13px;
  background: var(--bg-main);
  color: var(--text-main);
  font-family: inherit;
  font-size: 1.05rem;
  font-weight: 700;
  cursor: pointer;
  text-align: left;
  display: flex;
  align-items: center;
  gap: 12px;
  transition: all 0.15s;
}

.quiz-option-btn:hover:not(:disabled) {
  border-color: var(--primary);
  background: var(--bg-accent-soft);
}

.quiz-option-btn.correct {
  border-color: var(--jade);
  background: var(--jade-light);
  color: #065f46;
}

.quiz-option-btn.wrong {
  border-color: var(--primary);
  background: var(--primary-light);
  color: #991b1b;
}

.feedback-banner {
  padding: 14px 18px;
  border-radius: 12px;
  margin-top: 12px;
  font-weight: 600;
  display: none;
}

.feedback-banner.correct {
  display: block;
  background: var(--jade-light);
  color: #065f46;
  border: 1px solid var(--jade);
}

.feedback-banner.wrong {
  display: block;
  background: var(--primary-light);
  color: #991b1b;
  border: 1px solid var(--primary);
}

/* ============================================================================
   SECTION 4: MINI GAMES HSK 1
   ============================================================================ */
.games-selector {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.game-card-tab {
  background: var(--bg-card);
  border: 2px solid var(--border);
  border-radius: var(--radius-md);
  padding: 18px;
  cursor: pointer;
  transition: all 0.2s;
}

.game-card-tab.active {
  border-color: var(--primary);
  background: var(--bg-accent-soft);
}

.game-stage-box {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow-md);
}

/* Game 1: Memory / Match Grid */
.match-board {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  max-width: 760px;
  margin: 20px auto;
}

@media (max-width: 600px) {
  .match-board {
    grid-template-columns: repeat(3, 1fr);
  }
}

.match-tile {
  min-height: 92px;
  border: 2px solid var(--border);
  border-radius: 14px;
  background: var(--bg-main);
  padding: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  cursor: pointer;
  font-weight: 700;
  transition: all 0.18s;
  user-select: none;
}

.match-tile.hanzi-tile {
  font-family: var(--font-hanzi);
  font-size: 1.9rem;
}

.match-tile.selected {
  border-color: var(--primary);
  background: var(--primary-light);
  transform: scale(1.03);
}

.match-tile.matched {
  border-color: var(--jade);
  background: var(--jade-light);
  opacity: 0.35;
  pointer-events: none;
  transform: scale(0.95);
}

.match-tile.error-shake {
  animation: shake 0.35s ease;
  border-color: var(--primary);
  background: #fecaca;
}

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

/* Game 2: Falling Hanzi */
.falling-arena {
  position: relative;
  height: 410px;
  background: linear-gradient(180deg, #1e1b4b 0%, #312e81 65%, #4338ca 100%);
  border-radius: var(--radius-md);
  overflow: hidden;
  margin-bottom: 16px;
  border: 2px solid #4f46e5;
}

.falling-lantern {
  position: absolute;
  background: radial-gradient(circle at 30% 30%, #ef4444, #b91c1c);
  color: #fef08a;
  border: 2px solid #facc15;
  border-radius: 20px;
  padding: 10px 18px;
  font-family: var(--font-hanzi);
  font-size: 1.75rem;
  font-weight: 700;
  box-shadow: 0 6px 20px rgba(239, 68, 68, 0.55);
  text-align: center;
  user-select: none;
  transition: transform 0.1s;
}

.falling-ground {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 8px;
  background: #ef4444;
}

/* ============================================================================
   ICON LIBRARY ENHANCEMENTS & LIVELY ANIMATIONS (PHOSPHOR DUOTONE / FILL)
   ============================================================================ */
i[class^="ph-"],
i[class*=" ph-"] {
  font-size: 1.2em;
  line-height: 1;
  vertical-align: middle;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1), color 0.2s ease;
}

.nav-tab i {
  font-size: 1.28rem;
}

.nav-tab:hover i,
.btn:hover i,
.btn-hero-sm:hover i,
.cat-chip:hover i,
.view-btn:hover i {
  transform: scale(1.18) rotate(-5deg);
}

.nav-tab.active i {
  color: var(--primary);
  filter: drop-shadow(0 2px 6px rgba(217, 56, 41, 0.3));
}

.stat-pill i {
  font-size: 1.2rem;
}

.stat-icon-jade {
  color: var(--jade);
}

.stat-icon-gold {
  color: var(--gold);
  animation: gentlePulse 2.4s infinite ease-in-out;
}

.stat-icon-fire {
  color: #ea580c;
  animation: flameFlicker 1.8s infinite alternate ease-in-out;
}

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

@keyframes flameFlicker {
  0% { transform: scale(1) rotate(-3deg); filter: drop-shadow(0 0 4px rgba(234, 88, 12, 0.35)); }
  100% { transform: scale(1.16) rotate(3deg); filter: drop-shadow(0 0 8px rgba(234, 88, 12, 0.65)); }
}

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

/* Vivid Feature Icon Badges for Cards */
.feature-icon-badge {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.45rem;
  flex-shrink: 0;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.06);
  transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.practice-mode-card:hover .feature-icon-badge,
.game-card-tab:hover .feature-icon-badge {
  transform: scale(1.12) rotate(-6deg);
}

.badge-red {
  background: linear-gradient(135deg, #ffe4e1, #fecaca);
  color: #dc2626;
}

.badge-jade {
  background: linear-gradient(135deg, #ccfbf1, #99f6e4);
  color: #0d9488;
}

.badge-gold {
  background: linear-gradient(135deg, #fef3c7, #fde68a);
  color: #d97706;
}

.badge-indigo {
  background: linear-gradient(135deg, #e0e7ff, #c7d2fe);
  color: #4f46e5;
}

[data-theme="dark"] .badge-red {
  background: linear-gradient(135deg, #451a1a, #7f1d1d);
  color: #fca5a5;
}

[data-theme="dark"] .badge-jade {
  background: linear-gradient(135deg, #134e4a, #115e59);
  color: #5eead4;
}

[data-theme="dark"] .badge-gold {
  background: linear-gradient(135deg, #451a03, #78350f);
  color: #fcd34d;
}

[data-theme="dark"] .badge-indigo {
  background: linear-gradient(135deg, #1e1b4b, #312e81);
  color: #a5b4fc;
}

.card-action-btn i {
  font-size: 1.12rem;
}

.card-action-btn:hover i {
  transform: scale(1.22);
}

.card-action-btn.active-star i {
  color: #f59e0b;
  filter: drop-shadow(0 2px 5px rgba(245, 158, 11, 0.4));
}

.card-action-btn.active-master i {
  color: #10b981;
  filter: drop-shadow(0 2px 5px rgba(16, 185, 129, 0.4));
}

.hero-empty-icon {
  width: 68px;
  height: 68px;
  border-radius: 20px;
  margin: 0 auto 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.2rem;
  animation: floatSlow 3s infinite ease-in-out;
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 20px;
}

.modal-backdrop.open {
  display: flex;
}

.modal-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  max-width: 520px;
  width: 100%;
  padding: 28px;
  position: relative;
  box-shadow: var(--shadow-lg);
}



/* ============================================================================
   RESPONSIVE / MOBILE-FIRST OPTIMIZATION
   - Điện thoại: thanh điều hướng cố định dưới đáy (dễ bấm bằng ngón cái)
   - Vùng chạm tối thiểu 44px, chữ nhập 16px (chống iOS tự zoom)
   - Danh sách bài đọc cuộn ngang, flashcard vuốt trái/phải
   ============================================================================ */

/* ---- Nền tảng chung (áp dụng mọi kích thước) ---- */
html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body {
  overflow-x: clip;
}

button,
.btn,
select,
input,
.vocab-card,
.match-tile,
.word-token,
.passage-item-btn,
.cat-chip {
  touch-action: manipulation;
}

img,
svg {
  max-width: 100%;
}

.lbl-short {
  display: none;
}

.passage-item-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
}

.passage-item-count {
  font-size: 0.75rem;
  color: var(--text-secondary);
}

.passage-hsk-pills {
  margin-top: 10px;
}

.btn:active,
.btn-hero-sm:active,
.cat-chip:active,
.quiz-option-btn:active,
.word-token:active,
.match-tile:active,
.card-action-btn:active,
.icon-btn:active {
  transform: scale(0.97);
}

/* Thiết bị cảm ứng: bỏ hiệu ứng hover "nhảy" gây giật khi chạm */
@media (hover: none) {
  .vocab-card:hover,
  .btn:hover,
  .practice-mode-card:hover,
  .word-token:hover,
  .btn-hero-sm:hover,
  .icon-btn:hover {
    transform: none;
    box-shadow: var(--shadow-sm);
  }

  .nav-tab:hover i,
  .btn:hover i,
  .btn-hero-sm:hover i,
  .cat-chip:hover i,
  .view-btn:hover i,
  .card-action-btn:hover i {
    transform: none;
  }
}

/* ---- Máy tính bảng / laptop nhỏ: menu xuống dòng thứ 2, full chiều ngang ---- */
@media (min-width: 769px) and (max-width: 1100px) {
  .header-inner {
    padding: 10px 16px;
  }

  .main-nav {
    order: 3;
    width: 100%;
  }

  .nav-tab {
    flex: 1 1 0;
    justify-content: center;
  }

  .app-container {
    padding: 18px;
  }
}

/* ============================================================================
   ĐIỆN THOẠI (<= 768px)
   ============================================================================ */
@media (max-width: 768px) {
  body {
    /* chừa chỗ cho thanh điều hướng đáy + vùng an toàn (tai thỏ / thanh home) */
    padding-bottom: calc(76px + env(safe-area-inset-bottom, 0px));
    background-image: none;
  }

  /* ---------- Header gọn ---------- */
  .header-inner {
    padding: 8px 12px;
    padding-top: calc(8px + env(safe-area-inset-top, 0px));
    gap: 8px;
    flex-wrap: nowrap;
  }

  .brand {
    gap: 9px;
    min-width: 0;
  }

  .brand-seal {
    width: 38px;
    height: 38px;
    font-size: 20px;
    border-radius: 10px;
    flex-shrink: 0;
  }

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

  .brand-text h1 {
    font-size: 1rem;
    white-space: nowrap;
  }

  .brand-text span {
    display: none;
  }

  .header-stats {
    gap: 6px;
    flex-shrink: 0;
  }

  .stat-pill {
    padding: 5px 9px;
    font-size: 0.78rem;
    gap: 4px;
  }

  .icon-btn {
    width: 40px;
    height: 40px;
  }

  /* ---------- Thanh điều hướng cố định dưới đáy ---------- */
  .main-nav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 150;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 2px;
    padding: 6px 8px calc(6px + env(safe-area-inset-bottom, 0px));
    background: var(--bg-card);
    border-top: 1px solid var(--border);
    border-radius: 0;
    box-shadow: 0 -6px 24px rgba(31, 36, 33, 0.1);
  }

  [data-theme="dark"] .main-nav {
    box-shadow: 0 -6px 24px rgba(0, 0, 0, 0.45);
  }

  .nav-tab {
    flex-direction: column;
    justify-content: center;
    gap: 3px;
    min-height: 54px;
    padding: 6px 2px;
    font-size: 0.7rem;
    font-weight: 700;
    border-radius: 12px;
    line-height: 1.15;
    text-align: center;
  }

  .nav-tab i {
    font-size: 1.5rem;
  }

  .nav-tab.active {
    background: var(--primary-light);
    box-shadow: none;
  }

  .lbl-full {
    display: none;
  }

  .lbl-short {
    display: inline;
  }

  /* Ẩn thanh đáy khi bàn phím ảo đang mở để khỏi chiếm chỗ */
  body:has(input[type="text"]:focus) .main-nav {
    display: none;
  }

  /* ---------- Khung nội dung ---------- */
  .app-container {
    padding: 12px;
  }

  /* Cuộn mượt, không bị "kẹt" dưới thanh sticky */
  .tab-section {
    scroll-margin-top: 70px;
  }

  /* ---------- Banner tiến độ ---------- */
  .hero-banner {
    flex-direction: column;
    align-items: stretch;
    gap: 14px;
    padding: 16px;
    margin-bottom: 14px;
    border-radius: 16px;
  }

  .hero-banner::after {
    font-size: 110px;
    right: 6px;
    bottom: -26px;
  }

  .hero-info h2 {
    font-size: 1.2rem;
  }

  .hero-info p {
    font-size: 0.86rem;
  }

  .hero-progress-box {
    min-width: 0;
    width: 100%;
    padding: 12px 14px;
  }

  .progress-header {
    font-size: 0.8rem;
    gap: 8px;
    flex-wrap: wrap;
  }

  .hero-quick-actions {
    gap: 8px;
  }

  .btn-hero-sm {
    flex: 1 1 auto;
    min-height: 40px;
    padding: 9px 12px;
    font-size: 0.8rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
  }

  /* ---------- Thanh công cụ từ vựng ---------- */
  .vocab-toolbar {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    padding: 12px;
  }

  .search-box {
    min-width: 0;
    width: 100%;
  }

  .search-box input {
    padding: 13px 14px 13px 40px;
    font-size: 16px;
    min-height: 46px;
  }

  .toolbar-group {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }

  .hsk-level-pills {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    width: 100%;
  }

  .hsk-lvl-btn {
    padding: 10px 2px;
    font-size: 0.76rem;
    min-height: 40px;
    text-align: center;
    white-space: nowrap;
  }

  .select-control {
    width: 100%;
    min-height: 44px;
    font-size: 16px;
  }

  .view-switcher {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    width: 100%;
  }

  .view-btn {
    min-height: 42px;
    padding: 8px 4px;
    font-size: 0.78rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
  }

  /* ---------- Chip chủ đề: vuốt ngang ---------- */
  .category-chips {
    margin: 0 -12px 12px;
    padding: 0 12px 8px;
    scroll-snap-type: x proximity;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }

  .category-chips::-webkit-scrollbar {
    display: none;
  }

  .cat-chip {
    min-height: 40px;
    padding: 8px 14px;
    scroll-snap-align: start;
  }

  /* ---------- Thẻ từ vựng ---------- */
  .vocab-grid {
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 270px), 1fr));
    gap: 12px;
  }

  .vocab-card {
    padding: 14px;
  }

  .word-hanzi {
    font-size: 2.6rem;
  }

  .word-main {
    padding: 6px 0 10px;
  }

  .card-action-btn {
    width: 40px;
    height: 40px;
    border-radius: 10px;
  }

  .card-actions {
    gap: 6px;
  }

  /* ---------- Bảng: ẩn bớt cột phụ, cuộn ngang khi cần ---------- */
  .vocab-table-wrap {
    -webkit-overflow-scrolling: touch;
  }

  .vocab-table {
    min-width: 520px;
  }

  .vocab-table th,
  .vocab-table td {
    padding: 10px 10px;
  }

  .vocab-table th:first-child,
  .vocab-table td:first-child {
    width: 76px;
    min-width: 76px;
    white-space: nowrap;
    padding-left: 8px;
    padding-right: 8px;
  }

  .vocab-table th:nth-child(4),
  .vocab-table td:nth-child(4),
  .vocab-table th:nth-child(6),
  .vocab-table td:nth-child(6) {
    display: none;
  }

  .table-hanzi {
    font-size: 1.35rem;
  }

  /* ---------- Flashcard 3D ---------- */
  .flashcard-stage {
    margin: 4px auto 20px;
  }

  .flashcard-3d-wrapper {
    height: clamp(320px, 54vh, 420px);
    margin-bottom: 14px;
    touch-action: pan-y;
  }

  .flashcard-face {
    padding: 18px 16px;
    border-radius: 22px;
    overflow-y: auto;
  }

  .fc-Front-hanzi {
    font-size: clamp(3.6rem, 22vw, 5rem);
  }

  .fc-back-pinyin {
    font-size: 1.55rem;
  }

  .fc-back-meaning {
    font-size: 1.2rem;
    margin: 8px 0 12px;
    text-align: center;
  }

  .fc-hint {
    font-size: 0.8rem;
    text-align: center;
  }

  .fc-controls {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  .fc-controls .btn {
    justify-content: center;
    min-height: 48px;
    padding: 10px 8px;
    font-size: 0.88rem;
  }

  .fc-controls > .btn:first-child {
    order: 1;
  }

  .fc-controls > .btn-primary {
    order: 2;
  }

  #fcStarBtn {
    order: 3;
  }

  .fc-controls > .btn:nth-child(4) {
    order: 4;
  }

  #fcMasterBtn {
    order: 5;
    grid-column: 1 / -1;
  }

  /* ---------- Ghép đoạn văn ---------- */
  .passage-layout {
    gap: 14px;
  }

  .passage-sidebar {
    padding: 12px;
    border-radius: 14px;
  }

  .passage-sidebar-desc {
    display: none;
  }

  .passage-list {
    flex-direction: row;
    overflow-x: auto;
    gap: 10px;
    margin: 10px -4px 0;
    padding: 2px 4px 8px;
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }

  .passage-list::-webkit-scrollbar {
    display: none;
  }

  .passage-item-btn {
    flex: 0 0 min(78%, 250px);
    scroll-snap-align: start;
    padding: 11px 12px;
  }

  .passage-item-title {
    font-size: 0.88rem;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }

  .passage-workspace {
    padding: 14px 12px;
    border-radius: 16px;
  }

  #passageTitle {
    font-size: 1.1rem !important;
  }

  .passage-workspace .btn {
    min-height: 44px;
    justify-content: center;
  }

  .passage-mode-tabs {
    flex-wrap: nowrap;
    overflow-x: auto;
    margin: 0 -12px 14px;
    padding: 0 12px 6px;
    gap: 8px;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }

  .passage-mode-tabs::-webkit-scrollbar {
    display: none;
  }

  .mode-pill {
    flex: 0 0 auto;
    white-space: nowrap;
    min-height: 44px;
    padding: 9px 14px;
    font-size: 0.84rem;
    display: inline-flex;
    align-items: center;
    gap: 6px;
  }

  .completed-passage-box {
    padding: 12px 14px;
  }

  .sentence-build-area {
    min-height: 66px;
    padding: 10px;
    gap: 8px;
  }

  .token-pool {
    gap: 8px;
  }

  .word-token {
    min-height: 46px;
    padding: 9px 12px;
    font-size: 1.15rem;
    border-radius: 10px;
  }

  .order-sentence-card {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    padding: 12px;
  }

  .order-controls {
    justify-content: flex-end;
  }

  .order-controls .icon-btn {
    width: 46px;
    height: 46px;
  }

  /* các nút chọn từ trong điền khuyết */
  #passageInteractiveArea .btn[onclick^="selectClozeOption"] {
    min-height: 44px;
    padding: 8px 14px !important;
  }

  /* ---------- Luyện tập ---------- */
  .practice-type-tabs {
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin-bottom: 14px;
  }

  .practice-mode-card {
    padding: 10px 6px;
    text-align: center;
    border-radius: 12px;
  }

  .practice-mode-card h3 {
    flex-direction: column;
    gap: 6px;
    font-size: 0.74rem;
    line-height: 1.25;
    margin-bottom: 0;
    justify-content: center;
  }

  .practice-mode-card p {
    display: none;
  }

  .practice-mode-card .feature-icon-badge {
    width: 38px;
    height: 38px;
    font-size: 1.25rem;
  }

  .quiz-arena {
    padding: 14px 12px;
    border-radius: 16px;
  }

  .quiz-top-meta {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }

  .quiz-top-meta > div {
    width: 100%;
  }

  .quiz-top-meta > div:first-child select {
    flex: 1 1 100%;
  }

  .quiz-top-meta > div:last-child {
    display: flex;
    justify-content: space-between;
    gap: 8px;
  }

  .quiz-top-meta > div:last-child .stat-pill {
    flex: 1;
    justify-content: center;
  }

  .quiz-prompt-box {
    padding: 16px 10px;
  }

  .quiz-big-hanzi {
    font-size: clamp(2.4rem, 14vw, 3.4rem);
  }

  .quiz-big-viet {
    font-size: 1.35rem;
  }

  .tone-keyboard {
    gap: 5px;
    padding: 8px;
  }

  .tone-key {
    min-width: 40px;
    height: 40px;
    font-size: 1rem;
  }

  .quiz-text-input {
    font-size: 16px;
    padding: 13px 14px;
    min-width: 0;
  }

  .quiz-options-grid {
    gap: 10px;
  }

  .quiz-option-btn {
    min-height: 56px;
    padding: 12px 14px;
    font-size: 1rem;
  }

  .feedback-banner {
    font-size: 0.92rem;
    padding: 12px 14px;
  }

  .quiz-arena > div:last-child {
    flex-direction: column;
    align-items: stretch;
  }

  .quiz-arena > div:last-child > div {
    display: flex;
    gap: 8px;
  }

  .quiz-arena > div:last-child .btn {
    flex: 1;
    justify-content: center;
    min-height: 48px;
  }

  /* ---------- Game ---------- */
  .games-selector {
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin-bottom: 14px;
  }

  .game-card-tab {
    padding: 10px 6px;
    text-align: center;
    border-radius: 12px;
  }

  .game-card-tab h3 {
    flex-direction: column !important;
    gap: 6px !important;
    font-size: 0.72rem;
    line-height: 1.25;
    margin-bottom: 0 !important;
    justify-content: center;
  }

  .game-card-tab p {
    display: none;
  }

  .game-card-tab .feature-icon-badge {
    width: 38px;
    height: 38px;
    font-size: 1.25rem;
  }

  .game-stage-box {
    padding: 14px 12px;
    border-radius: 16px;
  }

  .game-stage-box > div:first-child {
    align-items: stretch !important;
  }

  .game-stage-box > div:first-child > div {
    width: 100%;
  }

  .game-stage-box > div:first-child select {
    flex: 1 1 100%;
  }

  .game-stage-box .btn-primary {
    flex: 1 1 100%;
    justify-content: center;
    min-height: 46px;
  }

  .game-stage-box .stat-pill {
    flex: 1 1 auto;
    justify-content: center;
  }

  /* Game 1 */
  .match-board {
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin: 14px auto;
  }

  .match-tile {
    min-height: 82px;
    padding: 6px;
    font-size: 0.82rem;
    border-radius: 12px;
    word-break: break-word;
    line-height: 1.25;
  }

  .match-tile.hanzi-tile {
    font-size: 1.6rem;
  }

  /* Game 2 */
  .falling-arena {
    height: clamp(260px, 38vh, 340px);
    border-radius: 14px;
  }

  .falling-lantern {
    font-size: 1.4rem;
    padding: 8px 14px;
    border-radius: 16px;
  }

  #fallingChoicesGrid {
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  #fallingChoicesGrid .quiz-option-btn {
    min-height: 54px;
    padding: 8px 10px;
    font-size: 0.86rem;
    line-height: 1.25;
  }

  #fallingOverlayMsg h3 {
    font-size: 1.15rem !important;
  }

  #fallingOverlayMsg p {
    font-size: 0.85rem;
  }

  /* Game 3 */
  #blitzContentArea {
    padding: 6px 0 !important;
  }

  /* ---------- Hộp chi tiết từ: dạng bottom-sheet ---------- */
  .modal-backdrop {
    align-items: flex-end;
    padding: 0;
  }

  .modal-card {
    max-width: none;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    border-radius: 22px 22px 0 0;
    padding: 18px 16px calc(18px + env(safe-area-inset-bottom, 0px));
    animation: sheetUp 0.28s ease;
  }

  .modal-card .word-hanzi {
    font-size: 3.4rem !important;
  }

  .modal-card .btn {
    flex: 1 1 100%;
    justify-content: center;
    min-height: 46px;
  }
}

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

/* ============================================================================
   ĐIỆN THOẠI NHỎ (<= 480px)
   ============================================================================ */
@media (max-width: 480px) {
  .quiz-input-row {
    flex-direction: column;
  }

  .quiz-input-row .btn {
    justify-content: center;
    min-height: 48px;
  }

  .stat-pill .stat-label {
    display: none;
  }

  .hero-quick-actions .btn-hero-sm {
    flex: 1 1 100%;
  }

  .brand-text h1 {
    font-size: 0.92rem;
  }

  .vocab-grid {
    grid-template-columns: 1fr;
  }
}

/* ============================================================================
   MÀN HÌNH RẤT HẸP (<= 360px)
   ============================================================================ */
@media (max-width: 360px) {
  .brand-seal {
    width: 34px;
    height: 34px;
  }

  .nav-tab {
    font-size: 0.64rem;
  }

  .practice-mode-card h3,
  .game-card-tab h3 {
    font-size: 0.66rem;
  }

  .match-tile {
    min-height: 74px;
  }

  .tone-key {
    min-width: 36px;
    height: 38px;
  }
}

/* ============================================================================
   ĐIỆN THOẠI XOAY NGANG (chiều cao thấp)
   ============================================================================ */
@media (max-width: 920px) and (max-height: 480px) and (orientation: landscape) {
  .flashcard-3d-wrapper {
    height: 260px;
  }

  .fc-Front-hanzi {
    font-size: 3.2rem;
  }

  .falling-arena {
    height: 200px;
  }

  .main-nav {
    padding-top: 2px;
    padding-bottom: calc(2px + env(safe-area-inset-bottom, 0px));
  }

  .nav-tab {
    min-height: 42px;
    flex-direction: row;
    gap: 6px;
  }

  body {
    padding-bottom: calc(52px + env(safe-area-inset-bottom, 0px));
  }
}

/* ============================================================================
   TÔN TRỌNG CÀI ĐẶT "GIẢM CHUYỂN ĐỘNG"
   ============================================================================ */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ---- FIX: backdrop-filter trên header tạo "containing block" làm thanh nav
        position:fixed bị kẹt trong header. Trên điện thoại dùng nền đặc. ---- */
@media (max-width: 768px) {
  .app-header,
  [data-theme="dark"] .app-header {
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
    background: var(--bg-card);
  }
}

/* ---- FIX: lưới 1fr bị nội dung cuộn ngang "đẩy" rộng quá màn hình ---- */
.passage-layout > *,
.practice-type-tabs > *,
.games-selector > *,
.quiz-arena,
.game-stage-box,
.passage-workspace,
.passage-sidebar {
  min-width: 0;
}

.brand-hsk {
  font-style: normal;
}

@media (max-width: 920px) {
  .passage-layout {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (max-width: 768px) {
  .brand-text > span {
    display: none;
  }

  .brand-text h1 {
    overflow: hidden;
    text-overflow: ellipsis;
  }

  /* Bàn phím dấu thanh gọn: 8 phím / hàng */
  .tone-keyboard {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 4px;
    padding: 8px;
  }

  .tone-key {
    min-width: 0;
    height: 40px;
    padding: 0;
  }
}

@media (max-width: 480px) {
  .brand-hsk {
    display: none;
  }
}

/* ============================================================================
   VOCABULARY PAGINATION (20 WORDS / PAGE - SHARED FOR GRID & TABLE)
   ============================================================================ */
.vocab-pagination {
  margin-top: 24px;
  padding: 14px 20px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 14px;
}

.pagination-info {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.88rem;
  color: var(--text-secondary);
}

.pagination-info strong {
  color: var(--text-main);
  font-weight: 700;
}

.pagination-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.page-numbers {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.page-btn {
  min-width: 38px;
  height: 38px;
  padding: 0 11px;
  border-radius: 10px;
  border: 1.5px solid var(--border);
  background: var(--bg-card);
  color: var(--text-main) !important;
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  transition: all 0.2s cubic-bezier(0.22, 1, 0.36, 1);
  user-select: none;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.page-btn:hover:not(:disabled):not(.active) {
  border-color: var(--primary);
  color: var(--primary) !important;
  background: var(--primary-light);
  transform: translateY(-1px);
}

.page-btn.active {
  background: #d93829 !important;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%) !important;
  color: #ffffff !important;
  border-color: var(--primary-dark) !important;
  box-shadow: 0 4px 14px rgba(217, 56, 41, 0.35);
  font-weight: 800;
}

.page-btn:disabled {
  opacity: 0.38;
  cursor: not-allowed;
  background: var(--bg-subtle);
  color: var(--text-muted) !important;
  border-color: var(--border);
  box-shadow: none;
}

.page-nav-btn {
  padding: 0 14px;
  font-weight: 700;
  color: var(--text-main) !important;
}

.page-nav-btn:hover:not(:disabled) {
  color: var(--primary) !important;
}

.page-ellipsis {
  padding: 0 6px;
  color: var(--text-main);
  font-weight: 800;
  font-size: 1.05rem;
  user-select: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

[data-theme="dark"] .page-btn {
  background: var(--bg-subtle);
  color: #f3f4f6 !important;
  border-color: #374151;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
}

[data-theme="dark"] .page-btn:hover:not(:disabled):not(.active) {
  background: #3b1919;
  color: #ff8577 !important;
  border-color: var(--primary);
}

[data-theme="dark"] .page-btn.active {
  background: #d93829 !important;
  background: linear-gradient(135deg, #ef4444 0%, #b8281a 100%) !important;
  color: #ffffff !important;
  border-color: #ef4444 !important;
}

[data-theme="dark"] .page-btn:disabled {
  background: rgba(255, 255, 255, 0.04);
  color: #6b7280 !important;
  border-color: #2e3640;
}

[data-theme="dark"] .page-ellipsis {
  color: #cbd5e1;
}

[data-theme="dark"] .page-nav-btn {
  color: #f3f4f6 !important;
}

/* ============================================================================
   APP FOOTER (AUTHOR CREDIT: NGUYỄN NGỌC SÁNG - BẮC NINH, VIỆT NAM)
   ============================================================================ */
.app-footer {
  margin-top: 24px;
  background: var(--bg-card);
  border-top: 1px solid var(--border);
  padding: 14px 18px;
}

.footer-inner {
  max-width: 1320px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}

.footer-brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.footer-seal {
  width: 28px;
  height: 28px;
  font-size: 0.95rem;
  border-radius: 8px;
  flex-shrink: 0;
}

.footer-title {
  font-weight: 700;
  font-size: 0.86rem;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 6px;
}

.footer-desc {
  font-size: 0.74rem;
  color: var(--text-muted);
  margin-top: 1px;
}

.footer-author-card {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 5px 12px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--primary-light) 0%, var(--gold-light) 100%);
  border: 1px solid var(--border);
}

.footer-author-line {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.78rem;
  color: var(--text-main);
}

.footer-author-line strong {
  color: var(--primary);
  font-weight: 700;
  font-size: 0.8rem;
}

.footer-badge-icon {
  width: 20px;
  height: 20px;
  border-radius: 5px;
  background: var(--primary);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.72rem;
  box-shadow: 0 2px 6px rgba(217, 56, 41, 0.25);
}

.footer-author-loc {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.74rem;
  font-weight: 600;
  color: var(--text-secondary);
  padding-left: 10px;
  border-left: 1px solid var(--border);
}

.footer-author-loc i {
  color: var(--primary);
}

@media (max-width: 768px) {
  .vocab-pagination {
    flex-direction: column;
    align-items: stretch;
    padding: 12px 14px;
    gap: 10px;
  }

  .pagination-info {
    justify-content: center;
    text-align: center;
    font-size: 0.82rem;
  }

  .pagination-controls {
    justify-content: center;
  }

  .page-btn {
    min-width: 36px;
    height: 36px;
    padding: 0 9px;
    font-size: 0.82rem;
  }

  .footer-inner {
    flex-direction: column;
    text-align: center;
    justify-content: center;
    gap: 8px;
    padding-bottom: calc(56px + env(safe-area-inset-bottom, 0px));
  }

  .footer-brand {
    flex-direction: column;
    gap: 4px;
  }

  .footer-title {
    justify-content: center;
    font-size: 0.82rem;
  }

  .footer-desc {
    font-size: 0.72rem;
  }

  .footer-author-card {
    flex-direction: column;
    gap: 4px;
    width: 100%;
    justify-content: center;
    padding: 5px 8px;
  }

  .footer-author-loc {
    padding-left: 0;
    border-left: none;
    font-size: 0.72rem;
  }
}

/* ============================================================================
   OPTIMIZED PASSAGE SIDEBAR & SCROLLING (DESKTOP & MOBILE/TABLET)
   ============================================================================ */
.passage-layout {
  grid-template-columns: 340px minmax(0, 1fr);
}

.passage-sidebar {
  position: sticky;
  top: 82px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 16px;
  max-height: calc(100vh - 98px);
}

.passage-sidebar-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.passage-sidebar-title {
  font-size: 1.02rem;
  font-weight: 800;
  display: flex;
  align-items: center;
  gap: 7px;
  margin: 0;
}

.passage-counter-badge {
  background: var(--primary-light);
  color: var(--primary);
  font-size: 0.76rem;
  font-weight: 800;
  padding: 4px 10px;
  border-radius: 999px;
  white-space: nowrap;
  border: 1px solid rgba(217, 56, 41, 0.2);
}

.passage-sidebar-desc {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin: 0;
  line-height: 1.4;
}

.passage-search-box {
  position: relative;
  display: flex;
  align-items: center;
}

.passage-search-box i {
  position: absolute;
  left: 11px;
  color: var(--text-muted);
  font-size: 0.95rem;
  pointer-events: none;
}

.passage-search-box input {
  width: 100%;
  padding: 8px 12px 8px 34px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-main);
  color: var(--text-main);
  font-family: inherit;
  font-size: 0.85rem;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.passage-search-box input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}

.passage-list-wrapper {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

/* Mũi tên nổi hai bên khi ở chế độ cuộn ngang */
.passage-edge-arrow {
  display: none;
  position: absolute;
  top: 45%;
  transform: translateY(-50%);
  z-index: 5;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--primary);
  box-shadow: var(--shadow-md);
  cursor: pointer;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  transition: all 0.18s ease;
}

.passage-edge-arrow:hover {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.passage-edge-arrow.arrow-prev {
  left: -6px;
}

.passage-edge-arrow.arrow-next {
  right: -6px;
}

/* Danh sách cuộn dọc mượt trên Máy tính (> 920px) */
.passage-list {
  margin-top: 2px;
  max-height: calc(100vh - 340px);
  min-height: 280px;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  scroll-behavior: smooth;
  padding-right: 6px;
  scrollbar-width: thin;
  scrollbar-color: rgba(217, 56, 41, 0.45) var(--bg-main);
  cursor: grab;
}

.passage-list.dragging {
  cursor: grabbing;
  scroll-behavior: auto;
  user-select: none;
}

.passage-list::-webkit-scrollbar {
  width: 8px;
  height: 8px;
  display: block;
}

.passage-list::-webkit-scrollbar-track {
  background: var(--bg-main);
  border-radius: 999px;
}

.passage-list::-webkit-scrollbar-thumb {
  background: rgba(217, 56, 41, 0.42);
  border-radius: 999px;
  border: 2px solid var(--bg-main);
}

.passage-list::-webkit-scrollbar-thumb:hover {
  background: var(--primary);
}

.passage-empty-state {
  padding: 24px 12px;
  text-align: center;
  color: var(--text-secondary);
  font-size: 0.85rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.passage-empty-state i {
  font-size: 1.6rem;
  color: var(--primary);
}

/* Tablet & Điện thoại (<= 920px): hỗ trợ cả Cuộn ngang (có nút mũi tên + thanh cuộn rõ)
   VÀ nút chuyển sang Khung cuộn dọc 250px cực kỳ tiện lợi */
@media (max-width: 920px) {
  .passage-layout {
    grid-template-columns: minmax(0, 1fr);
  }

  .passage-sidebar {
    position: static;
    max-height: none;
    padding: 12px 14px;
    gap: 8px;
  }

  .passage-sidebar-desc {
    display: none;
  }

  .passage-search-box input {
    font-size: 16px;
    padding: 9px 12px 9px 34px;
  }

  /* Danh sách bài đọc trên <= 920px: Cuộn ngang mượt mà */
  .passage-list {
    flex-direction: row;
    max-height: none;
    min-height: 0;
    overflow-x: auto;
    overflow-y: hidden;
    gap: 10px;
    margin: 2px 0 0;
    padding: 4px 4px 10px;
    scroll-snap-type: x proximity;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
  }

  .passage-list::-webkit-scrollbar {
    display: block;
    height: 6px;
  }

  .passage-list .passage-item-btn {
    flex: 0 0 min(70%, 225px);
    scroll-snap-align: center;
    padding: 10px 12px;
  }

  .passage-list-wrapper.can-scroll-left .passage-edge-arrow.arrow-prev {
    display: inline-flex;
  }

  .passage-list-wrapper.can-scroll-right .passage-edge-arrow.arrow-next {
    display: inline-flex;
  }
}

/* ============================================================================
   PASSAGE MODE CHECKBOX / RADIO TABS & WORKSPACE ACTIONS (DESKTOP & MOBILE)
   ============================================================================ */
.passage-workspace-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 14px;
}

.passage-workspace-heading {
  flex: 1 1 260px;
  min-width: 0;
}

.passage-workspace-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.passage-mode-tabs {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin: 0 0 18px;
  padding: 0;
}

.mode-pill {
  position: relative;
  border: 1.5px solid var(--border);
  background: var(--bg-main);
  color: var(--text-main);
  padding: 11px 14px;
  border-radius: 13px;
  font-family: inherit;
  font-weight: 700;
  font-size: 0.86rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 10px;
  text-align: left;
  transition: all 0.2s cubic-bezier(0.22, 1, 0.36, 1);
  user-select: none;
}

.mode-pill:hover:not(.active) {
  border-color: var(--primary);
  background: var(--bg-card);
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}

.mode-check-box {
  width: 20px;
  height: 20px;
  border-radius: 6px;
  border: 2px solid var(--border);
  background: var(--bg-card);
  color: transparent;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.72rem;
  flex-shrink: 0;
  transition: all 0.2s ease;
}

.mode-pill-icon {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: var(--primary-light);
  color: var(--primary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.15rem;
  flex-shrink: 0;
  transition: all 0.2s ease;
}

.mode-pill-text {
  line-height: 1.3;
  min-width: 0;
}

.mode-lbl-short {
  display: none;
}

.mode-pill.active {
  background: var(--primary-light);
  color: var(--primary-dark);
  border-color: var(--primary);
  box-shadow: 0 4px 14px rgba(217, 56, 41, 0.16);
}

[data-theme="dark"] .mode-pill.active {
  color: #fff;
}

.mode-pill.active .mode-check-box {
  background: var(--primary);
  border-color: var(--primary);
  color: #ffffff;
  box-shadow: 0 2px 6px rgba(217, 56, 41, 0.35);
}

.mode-pill.active .mode-pill-icon {
  background: var(--primary);
  color: #ffffff;
}

.passage-action-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 14px;
}

/* Điện thoại (<= 768px): Hiển thị đủ cả 3 thẻ chế độ trên cùng 1 hàng lưới 3 cột,
   có ô tích (checkbox) góc trên phải, icon ở giữa và chữ gọn 2 dòng dễ bấm */
@media (max-width: 768px) {
  .passage-workspace-header {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }

  .passage-workspace-heading {
    flex: 1 1 auto;
  }

  .passage-workspace-actions {
    width: 100%;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  .passage-workspace-actions .btn {
    width: 100%;
    padding: 9px 10px;
    font-size: 0.82rem;
  }

  .passage-mode-tabs {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
    margin: 0 0 14px;
    padding: 0;
    overflow: visible;
  }

  .mode-pill {
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 10px 6px 9px;
    min-height: 78px;
    gap: 6px;
    border-radius: 12px;
    white-space: normal;
  }

  .mode-check-box {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 17px;
    height: 17px;
    border-radius: 5px;
    font-size: 0.65rem;
  }

  .mode-pill-icon {
    width: 34px;
    height: 34px;
    border-radius: 10px;
    font-size: 1.18rem;
  }

  .mode-lbl-full {
    display: none;
  }

  .mode-lbl-short {
    display: block;
    font-size: 0.74rem;
    font-weight: 700;
    line-height: 1.25;
  }

  .passage-action-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  .passage-action-row .btn {
    width: 100%;
    justify-content: center;
    padding: 10px 8px;
    font-size: 0.84rem;
  }
}

@media (max-width: 380px) {
  .mode-lbl-short {
    font-size: 0.68rem;
  }

  .passage-action-row {
    grid-template-columns: 1fr;
  }
}

/* ============================================================================
   QUESTION-FIRST UX: THU GỌN COMBOBOX / TAB PHỤ & LÀM NỔI BẬT CÂU HỎI
   + FIX VỠ CHỮ MÀN HÌNH ĐIỆN THOẠI (ĐÈN LỒNG RƠI & ĐẤU TRƯỜNG 60S)
   ============================================================================ */

/* 1. Thu gọn các Tab phụ (Luyện tập, Game, Chế độ Đoạn văn) để không lấn át Câu hỏi */
.practice-type-tabs,
.games-selector {
  gap: 8px;
  margin-bottom: 12px;
}

.practice-mode-card,
.game-card-tab {
  padding: 10px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg-main);
  box-shadow: none;
  opacity: 0.82;
  transition: all 0.18s ease;
}

.practice-mode-card:hover,
.game-card-tab:hover {
  opacity: 1;
  transform: none;
}

.practice-mode-card.active,
.game-card-tab.active {
  opacity: 1;
  background: var(--bg-card);
  border-color: var(--primary);
  box-shadow: 0 3px 10px rgba(217, 56, 41, 0.12);
}

.practice-mode-card h3,
.game-card-tab h3 {
  font-size: 0.9rem;
  margin-bottom: 2px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.practice-mode-card p,
.game-card-tab p {
  font-size: 0.76rem;
  color: var(--text-muted);
  margin: 0;
  line-height: 1.3;
}

.practice-mode-card .feature-icon-badge,
.game-card-tab .feature-icon-badge {
  width: 32px;
  height: 32px;
  font-size: 1.05rem;
  border-radius: 8px;
}

/* 2. Thu gọn Combobox (.select-compact) và thanh công cụ phụ (.quiz-top-meta) */
.quiz-top-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
  padding-bottom: 10px;
  border-bottom: 1px dashed var(--border);
}

.quiz-filters-row {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.quiz-stats-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.select-control.select-compact {
  padding: 5px 24px 5px 10px;
  min-height: 34px;
  height: 34px;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-secondary);
  background-color: var(--bg-main);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: none;
}

.select-control.select-compact:focus {
  border-color: var(--primary);
  color: var(--text-main);
}

.stat-pill.stat-pill-sm {
  padding: 4px 10px;
  min-height: 32px;
  font-size: 0.78rem;
  border-radius: 8px;
  white-space: nowrap;
  flex-shrink: 0;
  background: var(--bg-main);
}

/* Fix Game 1 timer jitter: cố định độ rộng và dùng tabular numbers chống vỡ layout combobox */
.stat-pill.stat-pill-timer {
  flex: 0 0 86px !important;
  width: 86px !important;
  min-width: 86px !important;
  max-width: 86px !important;
  justify-content: center;
  padding: 4px 6px !important;
}

#matchTimerText {
  display: inline-block;
  min-width: 42px;
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum";
  font-family: monospace, var(--font-sans);
}

/* 3. Làm nổi bật Khung Câu Hỏi (.quiz-prompt-box & .question-spotlight-card) */
.quiz-prompt-box,
.question-spotlight-card {
  position: relative;
  background: linear-gradient(180deg, var(--bg-card) 0%, var(--primary-light) 180%);
  border: 2px solid var(--primary);
  border-radius: 18px;
  padding: 20px 18px;
  margin-bottom: 16px;
  box-shadow: 0 10px 26px rgba(217, 56, 41, 0.11);
}

[data-theme="dark"] .quiz-prompt-box,
[data-theme="dark"] .question-spotlight-card {
  background: linear-gradient(180deg, #1f1b18 0%, rgba(217, 56, 41, 0.14) 100%);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.4);
}

.quiz-prompt-top,
.question-spotlight-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

.question-focus-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: var(--primary);
  color: #ffffff;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 4px 10px;
  border-radius: 999px;
  box-shadow: 0 2px 8px rgba(217, 56, 41, 0.3);
}

.btn.btn-listen-sm {
  padding: 5px 11px;
  min-height: 32px;
  font-size: 0.78rem;
  border-radius: 8px;
  white-space: nowrap;
}

.passage-question-box {
  background: var(--bg-card);
  border: 1px solid rgba(217, 56, 41, 0.25);
  border-radius: 14px;
  padding: 14px 16px;
  margin-bottom: 12px;
  text-align: center;
}

.passage-question-label {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.passage-question-meaning {
  font-size: 1.32rem;
  font-weight: 800;
  color: var(--primary);
  line-height: 1.35;
}

.passage-question-pinyin {
  font-size: 0.86rem;
  color: var(--text-secondary);
  margin-top: 6px;
}

/* Thu gọn bàn phím dấu thanh Pinyin nằm dưới ô nhập */
.tone-keyboard {
  margin-top: 8px;
  margin-bottom: 4px;
  padding: 6px 8px;
  background: var(--bg-main);
  border: 1px dashed var(--border);
  border-radius: 10px;
}

.quiz-bottom-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 14px;
  flex-wrap: wrap;
  gap: 10px;
}

.quiz-lenient-label {
  font-size: 0.82rem;
  color: var(--text-secondary);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
}

.quiz-bottom-actions {
  display: flex;
  gap: 8px;
}

/* 4. Header của 3 Game (Ghép Thẻ, Đèn Lồng Rơi, Phản Xạ 60s): Chống vỡ chữ tuyệt đối */
.game-header-bar {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 14px;
  padding-bottom: 12px;
  border-bottom: 1px dashed var(--border);
}

.game-header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
}

.game-stage-title {
  font-size: 1.08rem;
  font-weight: 800;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  margin: 0;
}

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

.btn.btn-sm-game {
  padding: 6px 12px;
  min-height: 34px;
  font-size: 0.8rem;
  border-radius: 9px;
  white-space: nowrap;
  flex-shrink: 0;
  flex: 0 0 auto !important;
  width: auto !important;
}

.game-filters-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  max-width: 460px;
}

.blitz-stage-content {
  text-align: center;
  padding: 12px 4px;
}

.blitz-prompt-box {
  max-width: 640px;
  margin: 0 auto 14px;
  padding: 16px 14px;
}

/* ============================================================================
   TỐI ƯU HIỂN THỊ TRÊN ĐIỆN THOẠI (<= 768px): CÂU HỎI RÕ RÀNG, KHÔNG VỠ CHỮ
   ============================================================================ */
@media (max-width: 768px) {
  /* Thu gọn 3 tab chọn chế độ Luyện tập / Game thành thanh mỏng 46px */
  .practice-type-tabs,
  .games-selector {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
    margin-bottom: 10px;
  }

  .practice-mode-card,
  .game-card-tab {
    padding: 7px 4px;
    border-radius: 10px;
  }

  .practice-mode-card h3,
  .game-card-tab h3 {
    flex-direction: column !important;
    gap: 3px !important;
    font-size: 0.68rem !important;
    line-height: 1.2;
    margin: 0 !important;
  }

  .practice-mode-card .feature-icon-badge,
  .game-card-tab .feature-icon-badge {
    width: 26px;
    height: 26px;
    font-size: 0.95rem;
    border-radius: 7px;
  }

  /* Thu gọn 3 nút chế độ trong Ghép Đoạn Văn trên điện thoại để không che câu hỏi */
  .passage-workspace-header {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 8px;
  }

  .passage-workspace-heading {
    flex: 1 1 auto;
  }

  #passageTitle {
    font-size: 1rem !important;
    line-height: 1.25;
  }

  #passageSummary {
    display: none;
  }

  .passage-workspace-actions {
    width: auto;
    display: inline-flex;
    gap: 6px;
    flex-shrink: 0;
  }

  .passage-workspace-actions .btn {
    width: auto;
    min-height: 34px;
    padding: 5px 9px;
    font-size: 0.74rem;
    border-radius: 8px;
  }

  .passage-mode-tabs {
    gap: 6px;
    margin-bottom: 10px;
  }

  .mode-pill {
    min-height: 54px;
    padding: 6px 4px;
    gap: 4px;
    border-radius: 10px;
  }

  .mode-pill-icon {
    width: 24px;
    height: 24px;
    font-size: 0.95rem;
    border-radius: 7px;
  }

  .mode-check-box {
    width: 14px;
    height: 14px;
    top: 4px;
    right: 4px;
    font-size: 0.55rem;
  }

  .mode-lbl-short {
    font-size: 0.67rem;
    line-height: 1.18;
  }

  /* Thanh combobox trong Luyện tập nằm gọn trên 1 hàng duy nhất (3 cột nhỏ) */
  .quiz-top-meta {
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
    margin-bottom: 10px;
    padding-bottom: 8px;
  }

  .quiz-filters-row {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 5px;
    width: 100%;
  }

  .quiz-filters-row .select-control.select-compact {
    width: 100%;
    min-width: 0;
    padding: 4px 18px 4px 6px;
    height: 32px;
    min-height: 32px;
    font-size: 0.72rem;
    background-position: right 5px center;
  }

  .quiz-stats-row {
    display: flex;
    justify-content: space-between;
    gap: 6px;
    width: 100%;
  }

  .quiz-stats-row .stat-pill.stat-pill-sm {
    flex: 1;
    justify-content: center;
    min-height: 30px;
    padding: 3px 8px;
    font-size: 0.75rem;
  }

  /* Khung Câu hỏi nổi bật, rõ ràng ngay giữa màn hình điện thoại */
  .quiz-prompt-box,
  .question-spotlight-card {
    padding: 14px 12px;
    margin-bottom: 12px;
    border-radius: 15px;
  }

  .passage-question-meaning {
    font-size: 1.12rem;
  }

  /* Fix triệt để lỗi vỡ chữ ở Đèn Lồng Chữ Hán Rơi & Đấu Trường 60 Giây */
  .game-stage-box > div:first-child > div {
    width: auto;
  }

  .game-stage-box .btn-primary:not(.btn-sm-game) {
    flex: 0 0 auto;
    width: auto;
  }

  .game-header-bar {
    gap: 8px;
    margin-bottom: 10px;
    padding-bottom: 10px;
  }

  .game-header-top {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }

  .game-stage-title {
    font-size: 0.98rem;
  }

  .game-stats-group {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: nowrap;
    gap: 6px;
    width: 100%;
  }

  .game-stats-group .stat-pill.stat-pill-sm {
    flex: 1 1 auto;
    justify-content: center;
    padding: 5px 7px;
    font-size: 0.75rem;
    min-height: 34px;
    white-space: nowrap;
  }

  .game-stats-group .stat-pill.stat-pill-timer {
    flex: 0 0 78px !important;
    width: 78px !important;
    min-width: 78px !important;
    max-width: 78px !important;
    padding: 4px 4px !important;
  }

  .game-stats-group .btn.btn-sm-game {
    flex: 0 0 auto !important;
    width: auto !important;
    min-height: 34px;
    padding: 5px 10px;
    font-size: 0.76rem;
    white-space: nowrap;
  }

  .game-filters-row {
    max-width: none;
    width: 100%;
    gap: 6px;
  }

  .game-filters-row .select-control.select-compact {
    width: 100%;
    min-width: 0;
    height: 34px;
    min-height: 34px;
    font-size: 0.75rem;
    padding: 4px 20px 4px 8px;
  }
}
