:root {
  --bg: #f0f4f8;
  --card: #ffffff;
  --text: #1a202c;
  --text-muted: #64748b;
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-soft: #e0e7ff;
  --accent: #06b6d4;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --border: #e2e8f0;
  --shadow: 0 4px 6px -1px rgba(0,0,0,0.07), 0 2px 4px -2px rgba(0,0,0,0.05);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.08), 0 4px 6px -4px rgba(0,0,0,0.05);
  --radius: 14px;
  --sidebar-w: 270px;
  --gradient: linear-gradient(135deg, #4f46e5 0%, #06b6d4 100%);
}

[data-theme="dark"] {
  --bg: #0f172a;
  --card: #1e293b;
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --primary: #818cf8;
  --primary-hover: #a5b4fc;
  --primary-soft: #312e81;
  --accent: #22d3ee;
  --border: #334155;
  --shadow: 0 4px 6px -1px rgba(0,0,0,0.3);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.4);
  --gradient: linear-gradient(135deg, #6366f1 0%, #22d3ee 100%);
}

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

body {
  font-family: 'Inter', 'Noto Sans', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  min-height: 100vh;
}

.app {
  display: flex;
  min-height: 100vh;
}

/* Sidebar */
.sidebar {
  width: var(--sidebar-w);
  background: var(--card);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  z-index: 100;
  transition: transform 0.3s ease;
  box-shadow: var(--shadow);
}

.logo {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 22px 18px;
  font-weight: 700;
  font-size: 1.2rem;
  border-bottom: 1px solid var(--border);
  background: var(--gradient);
  color: white;
  -webkit-background-clip: text;
  background-clip: text;
}

.logo-icon {
  font-size: 1.7rem;
  filter: none;
  -webkit-text-fill-color: initial;
}

.logo-text {
  background: var(--gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.nav-list {
  list-style: none;
  padding: 14px 10px;
  flex: 1;
  overflow-y: auto;
}

.nav-btn {
  width: 100%;
  text-align: left;
  padding: 12px 14px;
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 0.95rem;
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.2s;
  margin-bottom: 3px;
  font-weight: 500;
}

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

.nav-btn.active {
  background: var(--gradient);
  color: white;
  font-weight: 600;
  box-shadow: 0 4px 12px rgba(79, 70, 229, 0.35);
}

.theme-toggle {
  padding: 16px;
  border-top: 1px solid var(--border);
}

#themeBtn {
  width: 100%;
  padding: 11px;
  border: 1px solid var(--border);
  background: var(--bg);
  border-radius: 10px;
  cursor: pointer;
  font-size: 1.25rem;
  transition: all 0.2s;
}

#themeBtn:hover {
  border-color: var(--primary);
}

/* Main */
.main {
  flex: 1;
  margin-left: var(--sidebar-w);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px 28px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: var(--shadow);
}

.menu-toggle {
  display: none;
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--text);
}

#pageTitle {
  font-size: 1.3rem;
  font-weight: 700;
  flex: 1;
  background: var(--gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.user-progress {
  font-size: 0.9rem;
  color: var(--text-muted);
  background: var(--primary-soft);
  padding: 6px 12px;
  border-radius: 20px;
  font-weight: 500;
}

.content {
  padding: 28px;
  max-width: 980px;
  width: 100%;
  margin: 0 auto;
}

/* Cards */
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px;
  margin-bottom: 18px;
  border: 1px solid var(--border);
  transition: box-shadow 0.2s;
}

.card:hover {
  box-shadow: var(--shadow-lg);
}

.card h2 {
  font-size: 1.25rem;
  margin-bottom: 12px;
  font-weight: 700;
}

.card h3 {
  font-size: 1.08rem;
  margin-bottom: 8px;
  color: var(--primary);
  font-weight: 600;
}

.grid {
  display: grid;
  gap: 16px;
}

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

.grid-3 {
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 11px 20px;
  border: none;
  border-radius: 10px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-primary {
  background: var(--gradient);
  color: white;
  box-shadow: 0 4px 12px rgba(79, 70, 229, 0.3);
}

.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(79, 70, 229, 0.4);
}

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

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

.btn-success {
  background: var(--success);
  color: white;
}

.btn-sm {
  padding: 7px 14px;
  font-size: 0.85rem;
}

/* Alphabet */
.letter-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(72px, 1fr));
  gap: 10px;
}

.letter-card {
  background: var(--bg);
  border: 1.5px solid var(--border);
  border-radius: 12px;
  padding: 14px 8px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
}

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

.letter-card .char {
  font-size: 1.65rem;
  font-weight: 700;
  display: block;
}

.letter-card .name {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 4px;
}

/* Vocab */
.vocab-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 13px 16px;
  background: var(--bg);
  border-radius: 10px;
  margin-bottom: 8px;
  border: 1px solid var(--border);
  transition: all 0.15s;
}

.vocab-item:hover {
  border-color: var(--primary);
  background: var(--primary-soft);
}

.vocab-de {
  font-weight: 600;
  font-size: 1.05rem;
}

.vocab-article {
  color: var(--primary);
  font-weight: 700;
  margin-right: 4px;
}

.vocab-vi {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-top: 2px;
}

.speak-btn {
  background: var(--primary-soft);
  border: none;
  font-size: 1.15rem;
  cursor: pointer;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.speak-btn:hover {
  background: var(--primary);
  transform: scale(1.08);
}

/* Category tabs */
.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 18px;
}

.tab {
  padding: 8px 16px;
  border: 1.5px solid var(--border);
  background: var(--card);
  border-radius: 22px;
  cursor: pointer;
  font-size: 0.88rem;
  font-weight: 500;
  transition: all 0.2s;
}

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

.tab.active {
  background: var(--gradient);
  color: white;
  border-color: transparent;
  box-shadow: 0 3px 10px rgba(79, 70, 229, 0.3);
}

/* Flashcard */
.flashcard-container {
  perspective: 1000px;
  max-width: 420px;
  margin: 0 auto 20px;
}

.flashcard {
  width: 100%;
  height: 250px;
  position: relative;
  transform-style: preserve-3d;
  transition: transform 0.5s;
  cursor: pointer;
}

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

.flashcard-face {
  position: absolute;
  width: 100%;
  height: 100%;
  backface-visibility: hidden;
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border);
}

.flashcard-front {
  background: var(--card);
}

.flashcard-back {
  background: var(--gradient);
  color: white;
  transform: rotateY(180deg);
}

.flashcard .word {
  font-size: 1.9rem;
  font-weight: 700;
  margin-bottom: 8px;
  text-align: center;
}

.flashcard .hint {
  font-size: 0.9rem;
  opacity: 0.75;
}

.flash-controls {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 14px;
  margin-top: 16px;
}

/* Quiz */
.quiz-question {
  font-size: 1.2rem;
  font-weight: 600;
  margin-bottom: 18px;
}

.quiz-options {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.quiz-option {
  padding: 14px 18px;
  border: 2px solid var(--border);
  border-radius: 12px;
  background: var(--card);
  cursor: pointer;
  text-align: left;
  font-size: 1rem;
  transition: all 0.2s;
  font-weight: 500;
}

.quiz-option:hover {
  border-color: var(--primary);
  background: var(--primary-soft);
}

.quiz-option.correct {
  border-color: var(--success);
  background: rgba(16, 185, 129, 0.12);
}

.quiz-option.wrong {
  border-color: var(--danger);
  background: rgba(239, 68, 68, 0.1);
}

.quiz-option:disabled {
  cursor: default;
}

.score-box {
  text-align: center;
  padding: 32px;
}

.score-box .big {
  font-size: 2.8rem;
  font-weight: 800;
  background: var(--gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

/* Progress */
.progress-bar {
  height: 12px;
  background: var(--border);
  border-radius: 6px;
  overflow: hidden;
  margin: 10px 0 18px;
}

.progress-fill {
  height: 100%;
  background: var(--gradient);
  border-radius: 6px;
  transition: width 0.5s ease;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 14px;
}

.stat-card {
  background: var(--bg);
  border-radius: 12px;
  padding: 18px;
  text-align: center;
  border: 1px solid var(--border);
}

.stat-card .num {
  font-size: 1.7rem;
  font-weight: 800;
  background: var(--gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.stat-card .label {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-top: 4px;
}

/* Grammar */
.grammar-box {
  background: var(--primary-soft);
  border-left: 4px solid var(--primary);
  padding: 14px 16px;
  border-radius: 0 10px 10px 0;
  margin: 12px 0;
  font-size: 0.98rem;
}

.example {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  margin: 8px 0;
  font-family: 'Inter', monospace;
  font-size: 0.95rem;
}

/* Listening */
.listen-card {
  text-align: center;
  padding: 28px 20px;
}

.listen-sentence {
  font-size: 1.5rem;
  font-weight: 700;
  margin: 20px 0;
  min-height: 40px;
  color: var(--primary);
}

.listen-controls {
  display: flex;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
  margin: 20px 0;
}

.listen-answer-box {
  max-width: 400px;
  margin: 0 auto;
}

.listen-answer-box input {
  width: 100%;
  padding: 12px 16px;
  border: 2px solid var(--border);
  border-radius: 10px;
  font-size: 1rem;
  background: var(--bg);
  color: var(--text);
  margin-bottom: 12px;
}

.listen-answer-box input:focus {
  outline: none;
  border-color: var(--primary);
}

.listen-feedback {
  margin-top: 12px;
  font-weight: 600;
  min-height: 24px;
}

.listen-feedback.correct { color: var(--success); }
.listen-feedback.wrong { color: var(--danger); }

.level-badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: 600;
  background: var(--primary-soft);
  color: var(--primary);
  margin-bottom: 8px;
}

/* Home */
.hero {
  text-align: center;
  padding: 24px 0 32px;
}

.hero h2 {
  font-size: 1.75rem;
  margin-bottom: 10px;
  font-weight: 800;
}

.hero p {
  color: var(--text-muted);
  max-width: 520px;
  margin: 0 auto 24px;
  font-size: 1.02rem;
}

.feature-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 14px;
  margin-top: 20px;
}

.feature-item {
  background: var(--card);
  border-radius: 14px;
  padding: 20px 16px;
  border: 1px solid var(--border);
  text-align: center;
  box-shadow: var(--shadow);
  transition: all 0.2s;
}

.feature-item:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-lg);
  border-color: var(--primary);
}

.feature-item .icon {
  font-size: 2rem;
  margin-bottom: 10px;
}

/* Responsive */
@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
  }
  .sidebar.open {
    transform: translateX(0);
  }
  .main {
    margin-left: 0;
  }
  .menu-toggle {
    display: block;
  }
  .content {
    padding: 16px;
  }
  .hero h2 {
    font-size: 1.4rem;
  }
}

/* Utility */
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mb-2 { margin-bottom: 16px; }
.text-center { text-align: center; }
.text-muted { color: var(--text-muted); }
.flex { display: flex; }
.gap-2 { gap: 12px; }
.justify-center { justify-content: center; }
.hidden { display: none !important; }

/* ===== Bổ sung: ghi âm, từ vựng cá nhân, trạng thái cloud ===== */
.row-actions { display: flex; gap: 8px; align-items: center; }

.mic-btn {
  background: var(--primary-soft);
  border: none;
  font-size: 1.1rem;
  cursor: pointer;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}
.mic-btn:hover { background: var(--accent); transform: scale(1.08); }

.del-btn {
  background: none;
  border: none;
  font-size: 1.05rem;
  cursor: pointer;
  color: var(--danger);
  width: 34px;
  height: 34px;
  border-radius: 8px;
}
.del-btn:hover { background: rgba(239,68,68,0.12); }

.box-badge {
  display: inline-block;
  font-size: 11px;
  background: var(--primary-soft);
  color: var(--primary);
  padding: 2px 8px;
  border-radius: 10px;
  margin-top: 4px;
}

.cloud-status {
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 12px;
  background: var(--border);
  color: var(--text-muted);
  margin-right: 10px;
}
.cloud-status.ok { background: rgba(16,185,129,0.15); color: var(--success); }
.cloud-status.bad { background: rgba(239,68,68,0.15); color: var(--danger); }

/* Bottom sheet luyện phát âm */
.pron-panel {
  position: fixed;
  left: 0; right: 0; bottom: -500px;
  z-index: 999;
  transition: bottom 0.28s ease;
  display: flex;
  justify-content: center;
  pointer-events: none;
}
.pron-panel.open { bottom: 0; pointer-events: auto; }
.pron-panel-inner {
  background: var(--card);
  box-shadow: var(--shadow-lg);
  border-top-left-radius: 20px;
  border-top-right-radius: 20px;
  border: 1px solid var(--border);
  padding: 20px 22px 26px;
  width: 100%;
  max-width: 480px;
  text-align: center;
  position: relative;
}
.pron-close {
  position: absolute; top: 10px; right: 14px;
  background: none; border: none; font-size: 1.1rem; cursor: pointer; color: var(--text-muted);
}
.pron-word { font-size: 1.4rem; font-weight: 700; margin-bottom: 14px; }
.pron-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
#pronRecordBtn.recording { background: var(--danger); }
.pron-panel-inner audio { width: 100%; margin-top: 12px; }
