/* ==========================================================================
   CSS Stylesheet: Web Tĩnh Học Tiếng Trung Cơ Bản
   Giao diện tiếng Việt, Responsive, Light/Dark Mode
   ========================================================================== */

:root {
  --font-base: "Be Vietnam Pro", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-hanzi: "Noto Sans SC", "PingFang SC", "Microsoft YaHei", "Hiragino Sans GB", sans-serif;

  /* Light Theme Colors */
  --bg-app: #f8fafc;
  --bg-card: #ffffff;
  --bg-elevated: #f1f5f9;
  --border-color: #e2e8f0;
  --border-highlight: #cbd5e1;

  --text-main: #0f172a;
  --text-sub: #4b5563;
  --text-muted: #4b5563;

  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-light: #eff6ff;

  --success: #10b981;
  --success-light: #ecfdf5;
  --warning: #f59e0b;
  --warning-light: #fffbeb;
  --danger: #ef4444;
  --danger-light: #fef2f2;

  --tone-1: #3b82f6;
  --tone-2: #10b981;
  --tone-3: #f59e0b;
  --tone-4: #ef4444;
  --tone-5: #8b5cf6;

  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --space-7: 48px;

  /* 2-level soft shadows */
  --shadow-sm: 0 1px 3px 0 rgba(0, 0, 0, 0.05), 0 1px 2px -1px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 4px 16px -2px rgba(0, 0, 0, 0.08), 0 2px 6px -2px rgba(0, 0, 0, 0.04);
  --shadow-lg: 0 12px 24px -4px rgba(0, 0, 0, 0.12);

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-full: 9999px;
}

[data-theme="dark"] {
  --bg-app: #090d16;
  --bg-card: #131b2e;
  --bg-elevated: #1e293b;
  --border-color: #1e293b;
  --border-highlight: #334155;

  --text-main: #f8fafc;
  --text-sub: #a1a1aa;
  --text-muted: #a1a1aa;

  --primary: #3b82f6;
  --primary-hover: #60a5fa;
  --primary-light: #172554;

  --success: #10b981;
  --success-light: #064e3b;
  --warning: #f59e0b;
  --warning-light: #451a03;
  --danger: #ef4444;
  --danger-light: #450a0a;

  --shadow-sm: 0 1px 3px 0 rgba(0, 0, 0, 0.4);
  --shadow-md: 0 4px 16px -2px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 12px 24px -4px rgba(0, 0, 0, 0.45);
}

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

body {
  font-family: var(--font-base);
  background-color: var(--bg-app);
  color: var(--text-main);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

/* Layout */
.app-layout {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background-color: var(--bg-card);
  border-bottom: 1px solid var(--border-color);
  backdrop-filter: blur(8px);
}

.header-container {
  width: 100%;
  max-width: 100%;
  margin: 0 auto;
  padding: 0.5rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  box-sizing: border-box;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-shrink: 0;
}

.mobile-menu-btn {
  display: none;
  background: var(--bg-elevated);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 0.35rem 0.6rem;
  border-radius: var(--radius-md);
  cursor: pointer;
  font-size: 1.1rem;
  line-height: 1;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0;
  text-decoration: none;
  color: var(--text-main);
  line-height: 1;
  flex-shrink: 0;
}

.brand-logo {
  height: 32px;
  width: auto;
  display: block;
  object-fit: contain;
  transition: transform 0.15s ease;
}

.brand-logo:hover {
  transform: scale(1.02);
}

.brand-logo-mark {
  display: none;
  height: 28px;
  width: 28px;
  object-fit: contain;
  transition: transform 0.15s ease;
}

.brand-logo-mark:hover {
  transform: scale(1.05);
}

:root:not([data-theme="dark"]) .brand-logo-dark {
  display: none !important;
}

[data-theme="dark"] .brand-logo-light {
  display: none !important;
}

/* Menu Ngang: Language Selector */
.lang-nav-bar {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex: 1 1 auto;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: none;
  padding: 0.2rem 0;
}

.lang-nav-bar::-webkit-scrollbar {
  display: none;
}

.lang-nav-tab {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.35rem 0.65rem;
  border-radius: var(--radius-full);
  border: 1px solid var(--border-color);
  background: var(--bg-card);
  color: var(--text-sub);
  font-size: 0.82rem;
  font-weight: 500;
  text-decoration: none;
  transition: all 0.15s ease;
  white-space: nowrap;
  flex-shrink: 0;
}

@media (max-width: 1200px) {
  .header-container {
    gap: 0.5rem;
    padding: 0.5rem 0.85rem;
  }
  .header-left {
    gap: 0.5rem;
  }
  .brand-title {
    font-size: 1.02rem;
  }
  .lang-nav-bar {
    gap: 0.3rem;
  }
  .lang-nav-tab {
    padding: 0.25rem 0.42rem;
    font-size: 0.75rem;
    gap: 0.2rem;
  }
  .lang-tab-flag {
    font-size: 0.95rem;
  }
  .header-right-actions {
    gap: 0.4rem;
  }
  .btn-header-farm {
    padding: 0.4rem 0.6rem;
    font-size: 0.82rem;
  }
  .header-wallet-chip .economy-widget-chip {
    padding: 4px 9px !important;
    gap: 6px !important;
    font-size: 11.5px !important;
  }
}

.lang-nav-tab:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--primary-light);
}

.lang-nav-tab.active {
  background: var(--primary);
  color: #ffffff;
  border-color: var(--primary);
  font-weight: 600;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.15);
}

.lang-tab-flag {
  font-size: 1.15rem;
  line-height: 1;
}

/* Header Right Actions & Compact Mobile Language Picker */
.header-right-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
  margin-left: auto;
}

.lang-picker-wrap {
  display: none;
  position: relative;
}

.btn-lang-picker {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.3rem 0.65rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-full);
  color: var(--text-main);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  height: 34px;
}

.btn-lang-picker:hover {
  border-color: var(--primary);
}

.lang-picker-flag {
  font-size: 1.15rem;
  line-height: 1;
}

.lang-picker-arrow {
  color: var(--text-muted);
  transition: transform 0.2s ease;
}

.btn-lang-picker[aria-expanded="true"] .lang-picker-arrow {
  transform: rotate(180deg);
}

.lang-picker-dropdown {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 175px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  padding: 6px;
  display: none;
  flex-direction: column;
  gap: 3px;
  z-index: 1005;
}

.lang-picker-dropdown.open {
  display: flex;
}

.lang-dropdown-item {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.5rem 0.65rem;
  border-radius: var(--radius-sm);
  text-decoration: none;
  color: var(--text-main);
  font-size: 0.84rem;
  font-weight: 500;
  transition: background 0.15s ease;
}

.lang-dropdown-item:hover {
  background: var(--bg-elevated);
}

.lang-dropdown-item.active {
  background: var(--primary-light);
  color: var(--primary);
  font-weight: 600;
}

.dropdown-item-flag {
  font-size: 1.15rem;
  line-height: 1;
}

.dropdown-item-name {
  flex: 1;
}

.dropdown-item-badge {
  font-size: 0.65rem;
  color: var(--text-muted);
  background: var(--bg-elevated);
  border: 1px solid var(--border-color);
  padding: 0.1rem 0.4rem;
  border-radius: var(--radius-full);
}

.dropdown-item-badge.badge-ready {
  color: var(--success);
  background: var(--success-light);
  border-color: rgba(16, 185, 129, 0.3);
}

.lang-tab-name {
  line-height: 1;
}

.lang-tab-badge {
  font-size: 0.65rem;
  padding: 0.1rem 0.4rem;
  border-radius: 999px;
  background: var(--bg-elevated);
  color: var(--text-muted);
  font-weight: 500;
}

.lang-nav-tab.active .lang-tab-badge {
  background: rgba(255, 255, 255, 0.25);
  color: #ffffff;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

/* App Body Layout */
.app-body {
  display: flex;
  min-height: calc(100vh - 61px);
  width: 100%;
  position: relative;
}

/* Menu Dọc: Sidebar */
.app-sidebar {
  width: 248px;
  min-width: 248px;
  max-width: 248px;
  flex-shrink: 0;
  background: var(--bg-card);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 61px;
  height: calc(100vh - 61px);
  overflow-y: auto;
  z-index: 40;
}

.sidebar-header {
  padding: 1rem 1.1rem;
  border-bottom: 1px solid var(--border-color);
}

.sidebar-lang-card {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.sidebar-lang-flag {
  font-size: 1.8rem;
  line-height: 1;
}

.sidebar-lang-text {
  display: flex;
  flex-direction: column;
}

.sidebar-lang-name {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-main);
  line-height: 1.2;
}

.sidebar-lang-native {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  padding: 0.6rem 0.5rem;
  gap: 0.2rem;
  flex: 1;
}

.sidebar-nav-item {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.6rem 0.75rem;
  border-radius: var(--radius-md);
  color: var(--text-sub);
  text-decoration: none;
  font-size: 0.88rem;
  font-weight: 500;
  transition: all 0.15s ease;
}

.sidebar-nav-item:hover {
  background: var(--bg-elevated);
  color: var(--text-main);
}

.sidebar-nav-item.active {
  background: var(--primary-light);
  color: var(--primary);
  font-weight: 600;
}

.sidebar-nav-item.dimmed {
  opacity: 0.8;
}

.sidebar-icon {
  font-size: 1.1rem;
  line-height: 1;
}

.sidebar-label {
  flex: 1;
}

.sidebar-badge {
  font-size: 0.65rem;
  background: var(--bg-elevated);
  padding: 0.1rem 0.4rem;
  border-radius: 999px;
  color: var(--text-muted);
}

.sidebar-footer {
  border-top: 1px solid var(--border-color);
  padding: 0.85rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  background: var(--bg-card);
}

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

.setting-label {
  font-size: 0.8rem;
  color: var(--text-sub);
}

.btn-speed {
  background: var(--bg-elevated);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 0.3rem 0.65rem;
  border-radius: var(--radius-md);
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 500;
  font-family: inherit;
  transition: all 0.15s ease;
}

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

.sidebar-progress-box {
  background: var(--bg-elevated);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.65rem 0.75rem;
}

.prog-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.4rem;
  font-size: 0.78rem;
  font-weight: 600;
}

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

.prog-fraction {
  color: var(--primary);
}

.prog-track {
  height: 6px;
  background: var(--border-color);
  border-radius: 999px;
  overflow: hidden;
  margin-bottom: 0.4rem;
}

.prog-bar {
  height: 100%;
  background: var(--primary);
  border-radius: 999px;
  transition: width 0.3s ease;
}

.prog-streak {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.prog-streak strong {
  color: #f59e0b;
}

/* Main Area */
.app-main {
  flex: 1;
  min-width: 0;
  max-width: 1120px;
  margin: 0 auto;
  padding: 1.5rem 1.75rem 3rem 1.75rem;
  width: 100%;
}

/* Portal Mode: ẩn sidebar và mở rộng toàn trang */
.portal-mode .app-sidebar {
  display: none !important;
}

.portal-mode .mobile-menu-btn {
  display: none !important;
}

.portal-mode .app-main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 2.5rem 1.5rem 3.5rem 1.5rem;
}

/* Chinese Text Font Assignment */
.hanzi-text,
.tone-hanzi,
.pinyin-char,
.drill-hanzi,
.vocab-hanzi,
.card-hanzi,
.writer-preview,
.dia-zh,
.wrong-item .item-zh,
.stroke-char,
.radical-char,
.quiz-char-target,
.char-display {
  font-family: var(--font-hanzi) !important;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  font-size: 0.9rem;
  font-weight: 500;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.2s ease;
  text-decoration: none;
  font-family: inherit;
}

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

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

.btn-outline {
  background-color: transparent;
  border-color: var(--border-color);
  color: var(--text-main);
}

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

.btn-icon {
  background: var(--bg-elevated);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 0.45rem 0.75rem;
  border-radius: var(--radius-md);
  cursor: pointer;
  font-size: 0.9rem;
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  transition: background-color 0.2s;
}

.btn-icon:hover {
  border-color: var(--border-highlight);
}

.btn-sm {
  padding: 0.3rem 0.6rem;
  font-size: 0.8rem;
}

.btn-lg {
  padding: 0.75rem 1.5rem;
  font-size: 1rem;
}

/* Tab panes */
.tab-pane {
  display: none;
  animation: fadeIn 0.25s ease-in-out;
}

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

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

/* Common UI */
.info-alert {
  background: var(--primary-light);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 0.75rem 1rem;
  border-radius: var(--radius-md);
  margin-bottom: 1.25rem;
  font-size: 0.9rem;
}

.hidden {
  display: none !important;
}

/* Sub-nav in tabs */
.tab-subnav {
  display: flex;
  gap: 0.5rem;
  overflow-x: auto;
  padding-bottom: 0.75rem;
  margin-bottom: 1.25rem;
  border-bottom: 1px solid var(--border-color);
}

.subnav-btn {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  padding: 0.5rem 0.9rem;
  border-radius: var(--radius-md);
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-sub);
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.2s;
}

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

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

.subtab-content {
  display: none;
}

.subtab-content.active {
  display: block;
}

/* ==========================================================================
   1. HOME TAB
   ========================================================================== */
.pane-hero {
  background: var(--bg-card);
  color: var(--text-main);
  border: 1px solid var(--border-color);
  border-left: 4px solid var(--primary);
  border-radius: var(--radius-lg);
  padding: 1.75rem 2rem;
  margin-bottom: 1.5rem;
  box-shadow: var(--shadow-sm);
  position: relative;
  overflow: hidden;
}

.pane-hero h2 {
  font-size: 1.6rem;
  font-weight: 700;
  margin-bottom: 0.4rem;
  color: var(--text-main);
}

.pane-hero p {
  color: var(--text-sub);
  font-size: 0.95rem;
  max-width: 680px;
  line-height: 1.6;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
  margin-bottom: 2rem;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  box-shadow: var(--shadow-sm);
}

.stat-icon {
  font-size: 2rem;
  width: 50px;
  height: 50px;
  background: var(--bg-elevated);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
}

.stat-info {
  display: flex;
  flex-direction: column;
}

.stat-value {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--primary);
}

.stat-label {
  font-size: 0.82rem;
  color: var(--text-muted);
}

.stat-target-wrap {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.stat-target-wrap input {
  width: 60px;
  padding: 0.2rem 0.4rem;
  font-size: 1.2rem;
  font-weight: 700;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  color: var(--text-main);
  text-align: center;
}

.stat-unit {
  font-size: 0.85rem;
  color: var(--text-sub);
}

.section-block {
  margin-bottom: 2rem;
}

.section-title {
  font-size: 1.2rem;
  font-weight: 700;
  margin-bottom: 1rem;
}

.roadmap-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 1rem;
}

.roadmap-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  text-decoration: none;
  color: var(--text-main);
  display: flex;
  flex-direction: column;
  transition: all 0.2s ease;
  position: relative;
}

.roadmap-card:hover {
  transform: translateY(-3px);
  border-color: var(--primary);
  box-shadow: var(--shadow-md);
}

.step-badge {
  display: inline-block;
  align-self: flex-start;
  background: var(--primary-light);
  color: var(--primary);
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.2rem 0.5rem;
  border-radius: var(--radius-sm);
  margin-bottom: 0.75rem;
}

.roadmap-card h4 {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
}

.roadmap-card p {
  font-size: 0.85rem;
  color: var(--text-sub);
  margin-bottom: 1rem;
  flex: 1;
}

.card-link {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--primary);
}

.quick-actions-bar {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
}

/* ==========================================================================
   2. PINYIN TAB
   ========================================================================== */
.pinyin-cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 0.75rem;
}

.pinyin-cell-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.85rem;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.pinyin-cell-card:hover {
  border-color: var(--primary);
  transform: translateY(-2px);
  box-shadow: var(--shadow-sm);
  background: var(--primary-light);
}

.pinyin-cell-symbol {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--primary);
}

.pinyin-cell-ex {
  font-size: 0.9rem;
  font-family: var(--font-hanzi);
  color: var(--text-sub);
}

.pinyin-cell-vi {
  font-size: 0.75rem;
  color: var(--text-muted);
  line-height: 1.2;
}

/* Tones Grid & SVG pitch curves */
.tones-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
}

.tone-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s ease;
}

.tone-card:hover {
  border-color: var(--primary);
  box-shadow: var(--shadow-sm);
}

.tone-card-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.tone-mark {
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--primary);
}

.tone-title {
  font-size: 1rem;
  font-weight: 600;
}

.tone-svg-wrap {
  width: 140px;
  height: 90px;
  margin: 0.5rem 0;
  background: var(--bg-elevated);
  border-radius: var(--radius-sm);
  padding: 0.35rem;
}

.tone-svg {
  width: 100%;
  height: 100%;
}

.tone-desc {
  font-size: 0.8rem;
  color: var(--text-sub);
  margin-top: 0.5rem;
}

.tone-play-btn {
  margin-top: 0.75rem;
  font-size: 0.8rem;
  color: var(--primary);
  font-weight: 600;
}

/* Tone Rules */
.rules-container {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.rule-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.25rem;
}

.rule-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
}

.rule-badge {
  background: var(--warning-light);
  color: var(--warning);
  font-size: 0.75rem;
  font-weight: 700;
  padding: 0.2rem 0.5rem;
  border-radius: var(--radius-sm);
}

.rule-desc {
  font-size: 0.9rem;
  color: var(--text-sub);
  margin-bottom: 1rem;
}

.rule-examples {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 0.75rem;
}

.rule-ex-item {
  background: var(--bg-elevated);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  cursor: pointer;
  transition: all 0.15s ease;
}

.rule-ex-item:hover {
  border-color: var(--primary);
}

.rule-ex-item .zh {
  font-size: 1.2rem;
  font-weight: 600;
  font-family: var(--font-hanzi);
}

.rule-ex-item .py {
  font-size: 0.85rem;
  color: var(--primary);
}

.rule-ex-item .vi {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.rule-ex-item .ex-audio {
  font-size: 0.75rem;
  color: var(--primary);
  font-weight: 500;
  margin-top: 0.25rem;
}

/* Tone Drill */
.drill-wrapper {
  max-width: 600px;
  margin: 0 auto;
}

.drill-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 2rem;
  box-shadow: var(--shadow-md);
  text-align: center;
}

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

.drill-score {
  font-weight: 700;
  color: var(--primary);
}

.drill-instruction {
  font-size: 0.9rem;
  color: var(--text-sub);
  margin-bottom: 1.5rem;
}

.drill-play-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.btn-play-large {
  padding: 0.9rem 1.8rem;
  font-size: 1.1rem;
  border-radius: var(--radius-full);
}

.drill-hanzi {
  font-size: 2.5rem;
  font-family: var(--font-hanzi);
  font-weight: 700;
  min-height: 3.5rem;
  color: var(--text-main);
}

.drill-options-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}

.drill-opt {
  padding: 0.85rem;
  font-size: 0.95rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}

.drill-opt .tone-sym {
  font-size: 1.4rem;
  font-weight: 700;
}

.drill-opt.correct {
  background-color: var(--success-light);
  border-color: var(--success);
  color: var(--success);
}

.drill-opt.wrong {
  background-color: var(--danger-light);
  border-color: var(--danger);
  color: var(--danger);
}

.drill-feedback {
  padding: 0.75rem;
  border-radius: var(--radius-md);
  margin-bottom: 1.25rem;
  font-size: 0.9rem;
  font-weight: 500;
}

.drill-feedback.is-correct {
  background: var(--success-light);
  color: var(--success);
  border: 1px solid var(--success);
}

.drill-feedback.is-wrong {
  background: var(--danger-light);
  color: var(--danger);
  border: 1px solid var(--danger);
}

/* ==========================================================================
   3. VOCABULARY TAB
   ========================================================================== */
.toolbar {
  display: flex;
  gap: 1rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.search-wrap {
  flex: 1;
  min-width: 250px;
}

.search-wrap input,
.filter-wrap select,
.form-select {
  width: 100%;
  padding: 0.65rem 0.9rem;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  background: var(--bg-card);
  color: var(--text-main);
  font-size: 0.9rem;
  font-family: inherit;
  outline: none;
}

.search-wrap input:focus,
.filter-wrap select:focus,
.form-select:focus {
  border-color: var(--primary);
}

.vocab-count-indicator {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 1rem;
}

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

.vocab-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.15rem;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  box-shadow: var(--shadow-sm);
  transition: border-color 0.2s, transform 0.2s, box-shadow 0.2s;
}

.vocab-card:hover {
  border-color: var(--primary);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.vocab-card-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.5rem;
}

.vocab-hanzi {
  font-size: 2.1rem;
  font-weight: 700;
  font-family: var(--font-hanzi);
  color: var(--text-main);
  line-height: 1.1;
  cursor: pointer;
  transition: color 0.15s ease;
}

.vocab-hanzi:hover {
  color: var(--primary);
}

.vocab-card-actions {
  display: flex;
  gap: 0.35rem;
}

.vocab-pinyin {
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--primary);
}

.vocab-vi {
  font-size: 0.95rem;
  color: var(--text-main);
  line-height: 1.4;
}

.vocab-meta {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.badge {
  font-size: 0.72rem;
  padding: 0.15rem 0.45rem;
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  color: var(--text-muted);
  border: 1px solid var(--border-color);
  font-weight: 500;
}

.vocab-ex-box {
  background: var(--bg-elevated);
  border-radius: var(--radius-sm);
  padding: 0.55rem 0.7rem;
  font-size: 0.82rem;
  margin-top: 0.25rem;
  border-left: 3px solid var(--primary);
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

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

.vocab-ex-py {
  color: var(--primary);
  font-size: 0.78rem;
}

.vocab-ex-vi {
  color: var(--text-sub);
}

.vocab-footer {
  margin-top: auto;
  padding-top: 0.65rem;
  border-top: 1px solid var(--border-color);
  display: flex;
  gap: 0.5rem;
  align-items: center;
  justify-content: space-between;
}

.vocab-footer .btn {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  padding: 0.42rem 0.5rem;
  font-size: 0.82rem;
  white-space: nowrap;
}

.vocab-speaker-svg,
.vocab-ex-audio svg {
  color: var(--primary) !important;
  stroke: var(--primary) !important;
}

/* ==========================================================================
   4. FLASHCARDS TAB (SM-2)
   ========================================================================== */
.flashcard-controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
  gap: 12px;
}

.fc-filter-group {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.fc-filter-group label {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-sub);
}

.fc-counter {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--primary);
  background: var(--primary-light);
  border: 1px solid var(--border-color);
  padding: 0.35rem 0.85rem;
  border-radius: var(--radius-full);
  white-space: nowrap;
  margin-left: auto;
}

/* 3D Flip Card */
.flashcard-scene {
  max-width: 520px;
  height: 340px;
  margin: 0 auto 1.5rem auto;
  perspective: 1000px;
  cursor: pointer;
}

.flashcard-card {
  width: 100%;
  height: 100%;
  position: relative;
  transform-style: preserve-3d;
  transition: transform 0.45s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: var(--shadow-lg);
  border-radius: var(--radius-lg);
}

.flashcard-card.flipped {
  transform: rotateY(180deg);
}

.fc-face {
  position: absolute;
  width: 100%;
  height: 100%;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  border-radius: var(--radius-lg);
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.fc-front {
  text-align: center;
  align-items: center;
}

.fc-badge {
  background: var(--primary-light);
  color: var(--primary);
  font-size: 0.78rem;
  font-weight: 600;
  padding: 0.25rem 0.65rem;
  border-radius: var(--radius-full);
}

.fc-hanzi {
  font-size: 4rem;
  font-weight: 700;
  font-family: var(--font-hanzi);
  color: var(--text-main);
  margin: auto 0;
}

.fc-hint {
  font-size: 0.82rem;
  color: var(--text-muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  margin-top: 1rem;
}

.fc-hint kbd {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  font-size: 0.72rem;
  font-weight: 700;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  color: var(--text-main);
  background: var(--bg-elevated);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  box-shadow: 0 1px 0 1px var(--border-color);
  line-height: 1.2;
}

.fc-back {
  transform: rotateY(180deg);
  text-align: center;
}

.fc-back-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.fc-hanzi-sm {
  font-size: 2.2rem;
  font-weight: 700;
  font-family: var(--font-hanzi);
  color: var(--text-main);
}

.fc-pinyin {
  font-size: 1.3rem;
  font-weight: 600;
  color: var(--primary);
}

.fc-vi {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text-main);
  margin-bottom: 0.5rem;
}

.fc-example-box {
  background: var(--bg-elevated);
  border-radius: var(--radius-md);
  padding: 0.75rem;
  font-size: 0.85rem;
  text-align: left;
}

.fc-example-box .ex-zh {
  font-family: var(--font-hanzi);
  font-weight: 600;
  color: var(--text-main);
}

.fc-example-box .ex-py {
  color: var(--primary);
  font-size: 0.8rem;
}

.fc-example-box .ex-vi {
  color: var(--text-sub);
  margin-bottom: 0.35rem;
}

/* Rating Bar */
.fc-rating-actions {
  max-width: 520px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  padding: 0 4px;
}

.btn-rate {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 0.65rem 0.4rem;
  border-radius: 10px !important;
  cursor: pointer;
  border: none !important;
  font-family: inherit;
  transition: transform 0.15s ease, filter 0.15s ease, box-shadow 0.15s ease;
  color: #ffffff !important;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
}

.btn-rate .rate-name {
  font-size: 0.95rem;
  font-weight: 700;
  line-height: 1.2;
}

.btn-rate .rate-key {
  font-size: 0.72rem;
  opacity: 0.75;
  margin-top: 3px;
  font-weight: 500;
  letter-spacing: 0.02em;
}

/* Quên: Chu sa #A23B2A */
.rate-again {
  background-color: #A23B2A !important;
  border: none !important;
}

/* Khó: Đất nung #9A5522 */
.rate-hard {
  background-color: #9A5522 !important;
  border: none !important;
}

/* Nhớ: Lục bảo sẫm #2F6B4F */
.rate-good {
  background-color: #2F6B4F !important;
  border: none !important;
}

/* Dễ: Chàm #2E4A7D */
.rate-easy {
  background-color: #2E4A7D !important;
  border: none !important;
}

.btn-rate:hover {
  transform: translateY(-2px);
  filter: brightness(1.15);
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
}

/* Completed box */
.completed-box {
  max-width: 500px;
  margin: 2rem auto;
  text-align: center;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 2.5rem 1.5rem;
  box-shadow: var(--shadow-md);
}

.completed-icon {
  font-size: 3rem;
  margin-bottom: 0.5rem;
}

.completed-box h3 {
  font-size: 1.3rem;
  margin-bottom: 0.5rem;
}

.completed-box p {
  color: var(--text-sub);
  font-size: 0.9rem;
  margin-bottom: 1.5rem;
}

.completed-actions {
  display: flex;
  justify-content: center;
  gap: 1rem;
  flex-wrap: wrap;
}

/* ==========================================================================
   5. WRITING TAB
   ========================================================================== */
.writing-layout {
  display: grid;
  grid-template-columns: 360px 1fr;
  gap: 1.5rem;
}

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

.writing-canvas-col {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.writer-topbar {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}

.writer-char-picker,
.writer-custom-input {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  width: 100%;
}

.writer-custom-input input {
  flex: 1;
  padding: 0.5rem;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  background: var(--bg-card);
  color: var(--text-main);
  text-align: center;
  font-size: 1rem;
}

.canvas-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: 1.25rem;
}

.writer-box {
  width: 260px;
  height: 260px;
  background: var(--bg-elevated);
  border: 2px solid var(--border-highlight);
  border-radius: var(--radius-md);
  position: relative;
  box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.05);
  display: flex;
  align-items: center;
  justify-content: center;
}

/* 米字格 Mi Zi Ge guidelines */
.writer-box::before,
.writer-box::after {
  content: '';
  position: absolute;
  pointer-events: none;
}

.writer-status {
  margin-top: 0.5rem;
  font-size: 0.85rem;
  color: var(--text-sub);
  min-height: 1.2rem;
}

.writer-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: center;
  width: 100%;
}

/* Radicals Explorer */
.radicals-col {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
}

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

.radicals-header h3 {
  font-size: 1.1rem;
}

.radicals-header input {
  padding: 0.4rem 0.75rem;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  background: var(--bg-elevated);
  color: var(--text-main);
  font-size: 0.85rem;
}

.radicals-table-wrap {
  overflow-y: auto;
  max-height: 480px;
}

.radicals-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.radicals-table th,
.radicals-table td {
  padding: 0.6rem 0.75rem;
  text-align: left;
  border-bottom: 1px solid var(--border-color);
}

.radicals-table th {
  background: var(--bg-elevated);
  position: sticky;
  top: 0;
  z-index: 2;
  font-weight: 600;
  font-size: 0.82rem;
  color: var(--text-sub);
}

.radicals-table td.rad-char {
  font-size: 1.4rem;
  font-family: var(--font-hanzi);
  font-weight: 700;
  color: var(--primary);
}

.radicals-table td.rad-alt {
  font-size: 1.2rem;
  font-family: var(--font-hanzi);
  color: var(--text-sub);
}

.radicals-table td.rad-ex {
  font-family: var(--font-hanzi);
  font-size: 1rem;
}

.btn-practice-rad {
  padding: 0.2rem 0.5rem;
  font-size: 0.75rem;
  border-radius: var(--radius-sm);
  background: var(--primary-light);
  color: var(--primary);
  border: 1px solid var(--primary);
  cursor: pointer;
}

.btn-practice-rad:hover {
  background: var(--primary);
  color: #fff;
}

/* ==========================================================================
   6. QUIZ TAB
   ========================================================================== */
.quiz-container {
  max-width: 650px;
  margin: 0 auto;
}

.quiz-card-box {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 2rem;
  box-shadow: var(--shadow-md);
  text-align: center;
}

.quiz-meta-info {
  display: flex;
  justify-content: center;
  gap: 1.25rem;
  margin: 1.5rem 0 2rem 0;
  font-size: 0.85rem;
  color: var(--text-sub);
  flex-wrap: wrap;
}

.quiz-progress-bar {
  width: 100%;
  height: 6px;
  background: var(--bg-elevated);
  border-radius: var(--radius-full);
  margin-bottom: 1.25rem;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--primary);
  width: 10%;
  transition: width 0.3s ease;
}

.quiz-top-info {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
  font-size: 0.9rem;
  color: var(--text-sub);
}

.quiz-question-display {
  margin-bottom: 1.75rem;
  min-height: 80px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.quiz-prompt {
  font-size: 2.5rem;
  font-weight: 700;
  font-family: var(--font-hanzi);
  color: var(--text-main);
}

.quiz-prompt.vi-text {
  font-size: 1.5rem;
  font-family: var(--font-base);
}

.quiz-options-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.85rem;
  margin-bottom: 1.5rem;
}

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

.quiz-opt-btn {
  padding: 1rem 0.85rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  background: var(--bg-elevated);
  color: var(--text-main);
  font-size: 1.05rem;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.15s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.quiz-opt-btn:hover:not(:disabled) {
  border-color: var(--primary);
  background: var(--primary-light);
}

.quiz-opt-btn.correct {
  background: var(--success-light) !important;
  border-color: var(--success) !important;
  color: var(--success) !important;
  font-weight: 600;
}

.quiz-opt-btn.wrong {
  background: var(--danger-light) !important;
  border-color: var(--danger) !important;
  color: var(--danger) !important;
}

.quiz-feedback {
  padding: 0.75rem;
  border-radius: var(--radius-md);
  font-size: 0.9rem;
  margin-bottom: 1.25rem;
}

.quiz-feedback.correct {
  background: var(--success-light);
  color: var(--success);
}

.quiz-feedback.wrong {
  background: var(--danger-light);
  color: var(--danger);
}

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

.result-score {
  font-size: 2rem;
  font-weight: 700;
  color: var(--primary);
  margin: 1rem 0;
}

.wrong-section {
  text-align: left;
  margin: 1.5rem 0;
  border-top: 1px solid var(--border-color);
  padding-top: 1.25rem;
}

.wrong-section h3 {
  font-size: 1rem;
  margin-bottom: 0.75rem;
}

.wrong-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-height: 200px;
  overflow-y: auto;
  margin-bottom: 1rem;
}

.wrong-item {
  background: var(--bg-elevated);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.75rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.85rem;
}

.wrong-item .item-zh {
  font-family: var(--font-hanzi);
  font-weight: 700;
  font-size: 1.1rem;
}

.wrong-actions {
  display: flex;
  justify-content: center;
}

.result-actions {
  display: flex;
  justify-content: center;
  gap: 1rem;
  margin-top: 1.5rem;
  flex-wrap: wrap;
}

/* ==========================================================================
   7. DIALOGUES TAB
   ========================================================================== */
.dialogue-layout {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 1.5rem;
}

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

.dialogue-sidebar {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1rem;
  height: fit-content;
}

.dialogue-sidebar-header h3 {
  font-size: 1rem;
  margin-bottom: 0.75rem;
  color: var(--text-sub);
}

.dialogue-nav-list {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.dia-nav-item {
  padding: 0.6rem 0.75rem;
  border-radius: var(--radius-md);
  font-size: 0.88rem;
  font-weight: 500;
  cursor: pointer;
  color: var(--text-main);
  background: transparent;
  border: none;
  text-align: left;
  transition: all 0.15s ease;
}

.dia-nav-item:hover {
  background: var(--bg-elevated);
  color: var(--primary);
}

.dia-nav-item.active {
  background: var(--primary-light);
  color: var(--primary);
  font-weight: 600;
}

.dialogue-content-area {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
}

.dialogue-header-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border-color);
  flex-wrap: wrap;
  gap: 1rem;
}

.dialogue-controls {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.toggle-control {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.85rem;
  color: var(--text-sub);
  cursor: pointer;
}

.dialogue-lines-list {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.dia-line-row {
  display: flex;
  gap: 0.75rem;
  padding: 0.85rem;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  transition: all 0.2s ease;
}

.dia-line-row:hover {
  background: var(--bg-elevated);
}

.dia-line-row.playing {
  background: var(--primary-light);
  border-color: var(--primary);
}

.dia-speaker-tag {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-full);
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.85rem;
  flex-shrink: 0;
}

.dia-speaker-tag.speaker-B {
  background: var(--success);
}

.dia-line-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.dia-zh {
  font-size: 1.25rem;
  font-weight: 600;
  font-family: var(--font-hanzi);
  color: var(--text-main);
}

.dia-py {
  font-size: 0.88rem;
  color: var(--primary);
}

.dia-vi {
  font-size: 0.85rem;
  color: var(--text-sub);
}

.dia-py.hidden,
.dia-vi.hidden {
  display: none;
}

.dia-audio-btn {
  background: transparent;
  border: none;
  cursor: pointer;
  font-size: 1.1rem;
  padding: 0.35rem;
  color: var(--text-muted);
  align-self: flex-start;
  transition: color 0.15s;
}

.dia-audio-btn:hover {
  color: var(--primary);
}

/* ==========================================================================
   Toast Notifications
   ========================================================================== */
.toast-container {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  pointer-events: none;
}

.toast {
  background: var(--text-main);
  color: var(--bg-card);
  padding: 0.75rem 1rem;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  font-size: 0.88rem;
  max-width: 350px;
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  animation: slideUp 0.25s ease-out;
}

.toast.toast-warning {
  background: #d97706;
  color: #ffffff;
}

.toast.toast-success {
  background: #059669;
  color: #ffffff;
}

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

/* Không cho tab Luyện viết tràn ngang trên điện thoại */
.writing-layout > * { min-width: 0; }
.writer-custom-input input, .writer-char-picker select { min-width: 0; flex: 1 1 auto; max-width: 100%; }

/* (Old portal styles removed - see portal.css) */

/* ==========================================================================
   COMING SOON VIEW (Ngôn ngữ chưa có)
   ========================================================================== */
.coming-soon-wrapper {
  max-width: 660px;
  margin: 1.5rem auto;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 2.75rem 2rem;
  text-align: center;
  box-shadow: var(--shadow-sm);
}

.coming-soon-badge-top {
  display: inline-block;
  background: var(--warning-light);
  color: var(--warning);
  font-size: 0.78rem;
  font-weight: 600;
  padding: 0.25rem 0.75rem;
  border-radius: 999px;
  margin-bottom: 1.25rem;
  border: 1px solid rgba(245, 158, 11, 0.2);
}

.coming-soon-flag {
  font-size: 4.5rem;
  line-height: 1;
  margin-bottom: 1rem;
}

.coming-soon-title {
  font-size: 1.65rem;
  font-weight: 700;
  color: var(--text-main);
  margin-bottom: 0.4rem;
  line-height: 1.3;
}

.coming-soon-native {
  font-size: 0.95rem;
  color: var(--text-muted);
  margin-bottom: 1.25rem;
  font-weight: 500;
}

.coming-soon-desc {
  font-size: 0.95rem;
  color: var(--text-sub);
  line-height: 1.6;
  margin-bottom: 1.75rem;
  max-width: 540px;
  margin-left: auto;
  margin-right: auto;
}

.coming-soon-preview-box {
  background: var(--bg-elevated);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  margin-bottom: 2rem;
  text-align: left;
}

.coming-soon-preview-box h3 {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-main);
  margin-bottom: 0.75rem;
}

.cs-preview-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.cs-preview-tag {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  padding: 0.4rem 0.75rem;
  border-radius: var(--radius-md);
  font-size: 0.82rem;
  color: var(--text-sub);
}

.cs-preview-tag .cs-icon {
  font-size: 1rem;
  line-height: 1;
}

.coming-soon-actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
}

.coming-soon-actions p {
  font-size: 0.88rem;
  color: var(--text-muted);
}

.cs-btn-group {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  justify-content: center;
}

/* ==========================================================================
   RESPONSIVE DESIGN (Điện thoại & Tablet < 860px)
   ========================================================================== */
.sidebar-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  backdrop-filter: blur(2px);
  z-index: 998;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

@media (max-width: 860px) {
  .app-header {
    height: 56px !important;
    max-height: 56px !important;
  }

  .header-container {
    height: 56px !important;
    padding: 0 0.75rem !important;
    gap: 0.5rem !important;
  }

  .mobile-menu-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .brand-sub {
    display: none !important;
  }

  .brand-title {
    font-size: 0.95rem !important;
  }

  /* Bỏ dải tab ngôn ngữ cuộn ngang trên điện thoại */
  .lang-nav-bar {
    display: none !important;
  }

  /* Thay bằng 1 nút chọn ngôn ngữ gọn mở dropdown */
  .lang-picker-wrap {
    display: inline-flex !important;
  }

  .header-right-actions {
    display: flex !important;
    align-items: center !important;
    gap: 0.4rem !important;
    margin-left: auto !important;
  }

  .app-body {
    display: block;
    position: relative;
  }

  .app-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 270px;
    max-width: 82vw;
    height: 100vh;
    z-index: 1000;
    transform: translateX(-100%);
    transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: var(--shadow-lg);
  }

  .sidebar-open .app-sidebar {
    transform: translateX(0);
  }

  .sidebar-open .sidebar-overlay {
    opacity: 1;
    pointer-events: auto;
  }

  .app-main {
    padding: 1rem 0.75rem 2.5rem 0.75rem;
    max-width: 100%;
  }

  .portal-mode .app-main {
    padding: 1.5rem 0.75rem 3rem 0.75rem;
  }

  .coming-soon-wrapper {
    padding: 2rem 1.25rem;
  }

  .coming-soon-title {
    font-size: 1.35rem;
  }

  /* Thống kê trang tổng quan zh trên điện thoại: lưới 2 cột, số 22px, nhãn 12px, không cắt */
  .stats-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 0.65rem !important;
    margin-bottom: 1.5rem !important;
  }

  .stat-card {
    padding: 0.75rem 0.65rem !important;
    gap: 0.5rem !important;
    min-width: 0 !important;
  }

  .stat-icon {
    width: 38px !important;
    height: 38px !important;
    font-size: 1.1rem !important;
    flex-shrink: 0 !important;
    border-radius: 8px !important;
  }

  .stat-icon svg {
    width: 18px !important;
    height: 18px !important;
  }

  .stat-info {
    min-width: 0 !important;
    flex: 1 !important;
  }

  .stat-value {
    font-size: 22px !important;
    line-height: 1.2 !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
  }

  .stat-label {
    font-size: 12px !important;
    line-height: 1.3 !important;
    white-space: normal !important;
    word-break: break-word !important;
  }

  .stat-target-wrap {
    display: flex !important;
    align-items: center !important;
    gap: 0.25rem !important;
  }

  .stat-target-wrap input {
    width: 44px !important;
    padding: 0.1rem 0.2rem !important;
    font-size: 16px !important;
    height: 28px !important;
  }

  .stat-unit {
    font-size: 11px !important;
  }

  /* Flashcard 4 nút trên điện thoại: chữ 13px vừa khít, grid 4 cột gap 6px */
  .fc-rating-actions {
    grid-template-columns: repeat(4, 1fr) !important;
    gap: 6px !important;
  }

  .btn-rate {
    padding: 0.5rem 0.2rem !important;
  }

  .btn-rate .rate-name {
    font-size: 13px !important;
    letter-spacing: -0.01em;
  }

  .btn-rate .rate-key {
    font-size: 10px !important;
    margin-top: 2px !important;
  }
}

/* Bảo đảm không tràn ngang ở 375px */
html, body {
  overflow-x: hidden;
  max-width: 100%;
}

@media (max-width: 480px) {
  .header-actions .btn-icon {
    padding: 0.35rem 0.5rem;
  }

  .brand-icon {
    font-size: 1.5rem;
  }

  .lang-tab-name {
    display: inline-block;
  }

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

/* Nút ☰ chỉ dùng trên điện thoại; máy tính đã có sidebar cố định */
@media (min-width: 861px) {
  .mobile-menu-btn { display: none !important; }
}

/* ==========================================================================
   Header Wallet Chip & Farm Nav Button
   ========================================================================== */
.header-wallet-chip {
  display: inline-flex;
  align-items: center;
}

.btn-header-farm {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.45rem 0.75rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-main);
  text-decoration: none;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  background: var(--bg-card);
  transition: all 0.2s ease;
  white-space: nowrap;
}

.btn-header-farm:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.btn-header-farm.active {
  background: var(--primary) !important;
  color: #ffffff !important;
  border-color: var(--primary) !important;
}

/* Featured item in sidebar (Lộ trình) */
.sidebar-nav-item.featured-nav-item {
  font-weight: 600;
}
.sidebar-badge.badge-featured {
  background: var(--primary-light, rgba(179, 38, 30, 0.12));
  color: var(--primary, #b3261e);
  font-weight: 700;
  font-size: 0.65rem;
  padding: 0.12rem 0.45rem;
}

/* Home Learn CTA Banner */
.home-learn-cta {
  background: linear-gradient(135deg, var(--bg-card), var(--bg-elevated));
  border: 1px solid var(--border-color);
  border-left: 5px solid var(--primary);
  border-radius: var(--radius-lg);
  padding: 1.25rem 1.5rem;
  margin-bottom: 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.25rem;
  box-shadow: var(--shadow-sm);
  flex-wrap: wrap;
}

.home-learn-cta-badge {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--primary);
  margin-bottom: 0.25rem;
}

.home-learn-cta-title {
  font-size: 1.2rem;
  font-weight: 700;
  margin-bottom: 0.25rem;
  color: var(--text-main);
}

.home-learn-cta-desc {
  color: var(--text-sub);
  font-size: 0.9rem;
  margin: 0;
  max-width: 620px;
}

.home-cta-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  white-space: nowrap;
}

@media (max-width: 768px) {
  .home-learn-cta {
    flex-direction: column;
    align-items: flex-start;
  }
  .home-cta-btn {
    width: 100%;
    justify-content: center;
  }
}

/* Economy widget chip & wallet rules */
.header-wallet-chip .economy-widget-chip {
  display: inline-flex !important;
  align-items: center !important;
  gap: 8px !important;
  padding: 5px 11px !important;
  font-size: 12px !important;
  white-space: nowrap !important;
  box-sizing: border-box !important;
  line-height: 1 !important;
}

/* Nhãn "Cấp" chỉ hiện khi đủ chỗ (>=1366px) */
.eco-chip-level,
.eco-sep-level {
  display: none !important;
}

@media (min-width: 1366px) {
  .eco-chip-level {
    display: inline-flex !important;
  }
  .eco-sep-level {
    display: inline !important;
  }
}

/* Header trên <=768px */
@media (max-width: 768px) {
  .lang-nav-bar {
    display: none !important;
  }
  .lang-picker-wrap {
    display: inline-flex !important;
  }
  .btn-lang-picker {
    padding: 0.25rem 0.5rem !important;
    font-size: 0.78rem !important;
    height: 32px !important;
  }

  /* Chip ví trên <=768px */
  .eco-chip-level,
  .eco-sep-level {
    display: none !important;
  }
  .header-wallet-chip .economy-widget-chip {
    padding: 4px 8px !important;
    gap: 6px !important;
    font-size: 11.5px !important;
  }

  /* Nút Nông trại chỉ còn biểu tượng */
  .btn-header-farm .farm-label {
    display: none !important;
  }
  .btn-header-farm {
    padding: 0.35rem 0.5rem !important;
    gap: 0 !important;
    min-width: 36px !important;
    height: 36px !important;
    justify-content: center !important;
  }
  .btn-icon {
    min-width: 36px !important;
    height: 36px !important;
    padding: 0.35rem !important;
  }
  .header-right-actions {
    gap: 0.4rem !important;
    flex-shrink: 0 !important;
  }
}

/* 3. HEADER ĐIỆN THOẠI CHẬT (<=480px & <=360px)
   Chỉ giữ logo thu gọn, chip ví gộp (xu + chuỗi ngày),
   nút chọn ngôn ngữ dạng biểu tượng cờ/địa cầu 40px,
   nút nông trại và sáng/tối dạng biểu tượng; khoảng cách đều, không tràn ở 360px */
@media (max-width: 480px) {
  .header-container {
    padding: 0 0.65rem !important;
    gap: 0.5rem !important;
    height: 56px !important;
    overflow: visible !important;
  }

  .header-left {
    min-width: 0 !important;
    flex-shrink: 0 !important;
    gap: 0.35rem !important;
  }

  /* Logo thương hiệu Polylingo trên điện thoại (<=480px) */
  .brand {
    gap: 0 !important;
    min-width: 0 !important;
  }
  .brand-logo {
    height: 28px !important;
    width: auto !important;
  }

  .header-right-actions {
    gap: 0.45rem !important;
    flex-shrink: 0 !important;
    align-items: center !important;
  }

  /* Chip ví gộp: xu + chuỗi ngày */
  .header-wallet-chip .economy-widget-chip {
    padding: 4px 8px !important;
    gap: 6px !important;
    font-size: 11.5px !important;
    border-radius: 9999px !important;
    height: 40px !important;
    box-sizing: border-box !important;
  }
  .eco-chip-coins {
    display: inline-flex !important;
  }
  .eco-sep-water,
  .eco-chip-water,
  .eco-sep-level,
  .eco-chip-level {
    display: none !important;
  }
  .eco-sep-streak {
    display: inline !important;
    opacity: 0.35 !important;
  }
  .eco-chip-streak {
    display: inline-flex !important;
  }

  /* Nút chọn ngôn ngữ dạng biểu tượng cờ/quả địa cầu 40px */
  .btn-lang-picker {
    width: 40px !important;
    min-width: 40px !important;
    height: 40px !important;
    padding: 0 !important;
    border-radius: 50% !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    gap: 0 !important;
    box-sizing: border-box !important;
  }
  .btn-lang-picker .lang-picker-name,
  .btn-lang-picker .lang-picker-arrow {
    display: none !important;
  }
  .lang-picker-flag {
    font-size: 1.25rem !important;
    line-height: 1 !important;
    margin: 0 !important;
  }

  /* Nút nông trại và sáng/tối dạng biểu tượng 40px */
  .btn-header-farm {
    width: 40px !important;
    min-width: 40px !important;
    height: 40px !important;
    padding: 0 !important;
    border-radius: 50% !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    gap: 0 !important;
    box-sizing: border-box !important;
  }
  .btn-header-farm .farm-label {
    display: none !important;
  }
  .btn-header-farm .farm-icon {
    font-size: 1.2rem !important;
    line-height: 1 !important;
  }

  #btn-theme-toggle {
    width: 40px !important;
    min-width: 40px !important;
    height: 40px !important;
    padding: 0 !important;
    border-radius: 50% !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    box-sizing: border-box !important;
    font-size: 1.15rem !important;
  }
}

/* Đảm bảo không tràn ở 360px */
@media (max-width: 360px) {
  .header-container {
    padding: 0 0.35rem !important;
    gap: 0.35rem !important;
  }
  /* Màn hình siêu nhỏ <=360px: dùng logo mark 28px để header thông thoáng */
  .brand-logo {
    display: none !important;
  }
  .brand-logo-mark {
    display: block !important;
    height: 28px !important;
    width: 28px !important;
  }
  .header-right-actions {
    gap: 0.3rem !important;
  }
  .header-wallet-chip .economy-widget-chip {
    padding: 3px 6px !important;
    gap: 4px !important;
    font-size: 11px !important;
    height: 36px !important;
  }
  .btn-lang-picker,
  .btn-header-farm,
  #btn-theme-toggle {
    width: 36px !important;
    min-width: 36px !important;
    height: 36px !important;
  }
  .lang-picker-flag,
  .btn-header-farm .farm-icon {
    font-size: 1.1rem !important;
  }
}

