:root {
  --bg: #0f1419;
  --surface: #1a2332;
  --surface2: #243044;
  --border: #2d3a4f;
  --text: #e8edf4;
  --muted: #8b9cb3;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --danger: #ef4444;
  --success: #22c55e;
  --accent: #f59e0b;
  --radius: 12px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.35);
  --sidebar-width: 280px;
}

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

body {
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

a {
  color: var(--primary);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

/* ——— Sidebar ——— */
.sidebar-backdrop {
  display: none;
}

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--sidebar-width);
  background: linear-gradient(180deg, #152038 0%, #0f1419 100%);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 40;
  transition: width 0.25s ease, transform 0.25s ease;
}

.sidebar-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 1rem 0.9rem;
  border-bottom: 1px solid var(--border);
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  background: none;
  border: none;
  color: inherit;
  cursor: pointer;
  text-align: left;
  min-width: 0;
  padding: 0.15rem;
}

.sidebar-brand-mark {
  width: 2.4rem;
  height: 2.4rem;
  border-radius: 10px;
  background: linear-gradient(135deg, #1e3a8a, #3b82f6);
  display: grid;
  place-items: center;
  font-weight: 700;
  flex-shrink: 0;
}

.sidebar-brand-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.sidebar-brand-text strong {
  font-size: 0.95rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-brand-text small {
  color: var(--muted);
  font-size: 0.75rem;
}

.sidebar-top-actions {
  display: flex;
  gap: 0.25rem;
  flex-shrink: 0;
}

.sidebar-icon-btn {
  width: 2.1rem;
  height: 2.1rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  display: grid;
  place-items: center;
  cursor: pointer;
}

.sidebar-icon-btn svg {
  width: 1.05rem;
  height: 1.05rem;
  fill: currentColor;
}

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

.sidebar-close-btn {
  display: none;
}

.sidebar-section {
  padding: 1rem 0.9rem 0.35rem;
}

.sidebar-section-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-bottom: 0.55rem;
  padding-left: 0.35rem;
}

.sidebar-lessons,
.sidebar-links {
  display: grid;
  gap: 0.4rem;
}

.sidebar-lesson {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  width: 100%;
  text-align: left;
  padding: 0.75rem 0.7rem;
  border-radius: 10px;
  border: 1px solid transparent;
  background: transparent;
  color: inherit;
  cursor: pointer;
}

.sidebar-lesson:hover {
  background: var(--surface);
}

.sidebar-lesson.active {
  background: rgba(59, 130, 246, 0.14);
  border-color: rgba(59, 130, 246, 0.35);
}

.sidebar-lesson-num {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--primary);
  background: var(--surface2);
  border-radius: 8px;
  padding: 0.35rem 0.45rem;
  min-width: 2.2rem;
  text-align: center;
}

.sidebar-lesson-body {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.sidebar-lesson-body strong {
  font-size: 0.95rem;
}

.sidebar-lesson-body small {
  color: var(--muted);
  font-size: 0.75rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  width: 100%;
  text-align: left;
  padding: 0.65rem 0.7rem;
  border-radius: 10px;
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.92rem;
  text-decoration: none;
}

.sidebar-link svg {
  width: 1.15rem;
  height: 1.15rem;
  fill: currentColor;
  flex-shrink: 0;
}

.sidebar-link:hover {
  background: var(--surface);
  color: var(--text);
  text-decoration: none;
}

.sidebar-link.active {
  background: rgba(59, 130, 246, 0.16);
  color: var(--primary);
  font-weight: 600;
}

.sidebar-link .badge {
  margin-left: auto;
}

.sidebar-footer {
  margin-top: auto;
  padding: 0.9rem;
  border-top: 1px solid var(--border);
}

.app-shell {
  margin-left: var(--sidebar-width);
  min-height: 100vh;
  transition: margin-left 0.25s ease;
}

/* Sidebar fullscreen */
body.sidebar-fullscreen .sidebar {
  width: 100%;
  border-right: none;
  z-index: 60;
}

body.sidebar-fullscreen .app-shell {
  margin-left: 0;
  visibility: hidden;
  pointer-events: none;
}

body.sidebar-fullscreen .sidebar-close-btn {
  display: grid;
}

body.sidebar-fullscreen .sidebar-section,
body.sidebar-fullscreen .sidebar-footer {
  max-width: 560px;
  margin-left: auto;
  margin-right: auto;
  width: 100%;
}

body.sidebar-fullscreen .sidebar-top {
  max-width: 560px;
  margin: 0 auto;
  width: 100%;
}

body.sidebar-fullscreen .sidebar-lesson,
body.sidebar-fullscreen .sidebar-link {
  padding: 0.9rem 1rem;
  font-size: 1rem;
}

.header {
  background: linear-gradient(135deg, #1e3a8a 0%, #0f1419 100%);
  border-bottom: 1px solid var(--border);
  padding: 1rem 1.5rem;
}

.header-inner {
  max-width: 900px;
  margin: 0 auto;
}

.header-main {
  width: 100%;
}

.header-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.header-titles {
  flex: 1;
  min-width: 0;
}

.header-lesson-tag {
  color: var(--accent);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  margin: 0;
}

.header-title-row h1 {
  margin: 0;
  min-width: 0;
  font-size: 1.25rem;
}

.btn-menu {
  display: none;
  align-items: center;
  justify-content: center;
  width: 2.5rem;
  height: 2.5rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  flex-shrink: 0;
}

.btn-menu svg {
  width: 1.25rem;
  height: 1.25rem;
  fill: currentColor;
}

.btn-settings {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2.5rem;
  height: 2.5rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 1.2rem;
  text-decoration: none;
  transition: background 0.15s, border-color 0.15s;
  flex-shrink: 0;
}

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

.header h1 {
  font-size: 1.25rem;
  font-weight: 700;
}

.subtitle {
  color: var(--muted);
  font-size: 0.875rem;
  margin-top: 0.25rem;
}

.stats {
  display: flex;
  gap: 1rem;
  font-size: 0.875rem;
  color: var(--muted);
  margin-top: 0.75rem;
  flex-wrap: wrap;
}

.stats span {
  background: var(--surface);
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
  border: 1px solid var(--border);
}

.tabs {
  display: flex;
  gap: 0.5rem;
  padding: 1rem 1.5rem 0;
  max-width: 900px;
  margin: 0 auto;
  border-bottom: 1px solid var(--border);
}

.tab {
  background: none;
  border: none;
  color: var(--muted);
  padding: 0.75rem 1rem;
  cursor: pointer;
  font-size: 0.95rem;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  transition: color 0.15s, border-color 0.15s;
  position: relative;
}

.tab-icon {
  display: none;
  width: 1.35rem;
  height: 1.35rem;
  fill: currentColor;
  flex-shrink: 0;
}

.tab-label {
  white-space: nowrap;
}

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

.tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
  font-weight: 600;
}

.badge {
  background: var(--primary);
  color: white;
  font-size: 0.75rem;
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  min-width: 1.25rem;
  text-align: center;
}

.container {
  max-width: 900px;
  margin: 0 auto;
  padding: 1.5rem;
}

.panel {
  display: none;
}

.panel.active {
  display: block;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
  margin-bottom: 1rem;
}

.search {
  flex: 1;
  min-width: 200px;
  padding: 0.65rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font-size: 0.95rem;
}

.search:focus {
  outline: none;
  border-color: var(--primary);
}

.select-all {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.875rem;
  color: var(--muted);
  cursor: pointer;
  white-space: nowrap;
}

.btn {
  padding: 0.6rem 1rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  font-size: 0.875rem;
  transition: background 0.15s, border-color 0.15s;
}

.btn:hover:not(:disabled) {
  background: var(--surface2);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

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

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

.btn-danger {
  background: rgba(239, 68, 68, 0.15);
  border-color: var(--danger);
  color: #fca5a5;
}

.btn-ghost {
  background: transparent;
}

.btn-icon {
  font-size: 1.25rem;
  padding: 0.5rem 0.75rem;
}

.sentence-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.sentence-item {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: border-color 0.15s, background 0.15s;
}

.sentence-item:hover {
  border-color: #5b4a75;
}

.sentence-item.in-study {
  border-left: 3px solid var(--success);
}

.sentence-item input[type="checkbox"] {
  margin-top: 0.35rem;
  width: 1.1rem;
  height: 1.1rem;
  accent-color: var(--primary);
  cursor: pointer;
  flex-shrink: 0;
}

.sentence-body {
  flex: 1;
  min-width: 0;
}

.sentence-chinese {
  font-size: 1.35rem;
  font-weight: 600;
  letter-spacing: 0.05em;
}

.sentence-pinyin {
  color: var(--accent);
  font-size: 0.9rem;
  margin-top: 0.15rem;
}

.sentence-vi .label {
  color: var(--muted);
  font-size: 0.75rem;
  margin-right: 0.25rem;
}

.sentence-booi {
  color: #86efac;
  font-size: 0.875rem;
  margin-top: 0.1rem;
}

.sentence-booi .label {
  color: var(--muted);
  font-size: 0.75rem;
  margin-right: 0.25rem;
}

.sentence-vi {
  color: var(--muted);
  font-size: 0.875rem;
  margin-top: 0.15rem;
}

.sentence-meta {
  font-size: 0.75rem;
  color: #5a6a80;
  margin-top: 0.35rem;
}

.sentence-actions {
  display: flex;
  gap: 0.35rem;
  flex-shrink: 0;
}

.sentence-actions .btn {
  padding: 0.4rem 0.6rem;
}

.study-tag {
  display: inline-block;
  font-size: 0.7rem;
  background: rgba(34, 197, 94, 0.15);
  color: var(--success);
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  margin-left: 0.5rem;
}

.from900-tag {
  display: inline-block;
  font-size: 0.7rem;
  background: rgba(139, 92, 246, 0.15);
  color: #a78bfa;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  margin-left: 0.5rem;
}

.empty {
  text-align: center;
  color: var(--muted);
  padding: 3rem 1rem;
  font-size: 0.95rem;
}

.hidden {
  display: none !important;
}

.practice-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem;
  box-shadow: var(--shadow);
}

.practice-progress {
  margin-bottom: 1.5rem;
}

.practice-progress span {
  font-size: 0.875rem;
  color: var(--muted);
}

.progress-bar {
  height: 4px;
  background: var(--surface2);
  border-radius: 999px;
  margin-top: 0.5rem;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--primary);
  border-radius: 999px;
  transition: width 0.3s;
  width: 0%;
}

.card-content {
  text-align: center;
  padding: 2rem 1rem;
  min-height: 180px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.card-chinese {
  font-size: 2.5rem;
  font-weight: 700;
  letter-spacing: 0.08em;
}

.card-pinyin {
  font-size: 1.25rem;
  color: var(--accent);
  margin-top: 0.75rem;
}

.card-booi {
  font-size: 1.15rem;
  color: #86efac;
  margin-top: 0.75rem;
}

.card-booi::before {
  content: "Bồi: ";
  color: var(--muted);
  font-size: 0.85rem;
}

.card-vietnamese {
  font-size: 1.1rem;
  color: var(--muted);
  margin-top: 0.75rem;
}

.card-actions,
.card-nav {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 1.25rem;
}

.auto-play {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  margin-top: 1rem;
  font-size: 0.875rem;
  color: var(--muted);
  cursor: pointer;
}

.playall-card .card-vietnamese {
  margin-top: 0.75rem;
}

.playall-status {
  margin-top: 1.25rem;
  font-size: 0.9rem;
  color: var(--primary);
}

.playall-controls {
  display: flex;
  justify-content: center;
  gap: 0.75rem;
  margin-top: 0.5rem;
}

.btn-playall,
#btnStopPlayAll {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 1.4rem;
  font-size: 1rem;
}

.btn-playall svg,
#btnStopPlayAll svg {
  width: 1.15rem;
  height: 1.15rem;
  fill: currentColor;
}

.playall-hint {
  text-align: center;
  color: var(--muted);
  font-size: 0.8rem;
  margin-top: 1rem;
}

.grammar-intro {
  margin-bottom: 1.25rem;
}

.grammar-title {
  font-size: 1.15rem;
  margin-bottom: 0.75rem;
}

.grammar-patterns {
  display: grid;
  gap: 0.75rem;
}

.grammar-pattern-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
}

.grammar-formula {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  font-weight: 600;
}

.grammar-q { color: var(--accent); }
.grammar-a { color: var(--success); }
.grammar-arrow { color: var(--muted); }

.grammar-note {
  color: var(--muted);
  font-size: 0.875rem;
  margin-top: 0.35rem;
}

.grammar-sample {
  margin-top: 0.65rem;
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 0.35rem;
  font-size: 0.95rem;
}

.grammar-sample-block {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}

.grammar-sample-block .grammar-py,
.grammar-sample-block .grammar-vi {
  margin-top: 0;
}

.grammar-sep { color: var(--muted); margin: 0 0.25rem; }

.grammar-list {
  display: grid;
  gap: 1rem;
}

.grammar-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  box-shadow: var(--shadow);
}

.grammar-card-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.5rem 0.75rem;
  margin-bottom: 0.85rem;
  padding-bottom: 0.65rem;
  border-bottom: 1px solid var(--border);
}

.grammar-verb {
  font-size: 1.35rem;
  font-weight: 700;
}

.grammar-verb-py { color: var(--accent); }
.grammar-verb-vi { color: var(--muted); font-size: 0.9rem; }

.grammar-pair {
  display: grid;
  gap: 0.55rem;
  margin-bottom: 0.85rem;
}

.grammar-pair:last-child { margin-bottom: 0; }

.grammar-line {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 0.65rem;
  align-items: start;
  background: var(--surface2);
  border-radius: 10px;
  padding: 0.7rem 0.8rem;
}

.grammar-role {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--accent);
  min-width: 2.2rem;
  padding-top: 0.2rem;
}

.grammar-role.answer { color: var(--success); }

.grammar-zh {
  font-size: 1.15rem;
  font-weight: 600;
  letter-spacing: 0.03em;
}

.grammar-py {
  color: var(--accent);
  font-size: 0.9rem;
  margin-top: 0.15rem;
}

.grammar-vi {
  color: var(--muted);
  font-size: 0.85rem;
  margin-top: 0.15rem;
}

.toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface2);
  border: 1px solid var(--border);
  padding: 0.75rem 1.25rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  z-index: 100;
  font-size: 0.875rem;
  animation: fadeIn 0.2s;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateX(-50%) translateY(8px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

@media (max-width: 900px) {
  .sidebar {
    transform: translateX(-105%);
    box-shadow: var(--shadow);
  }

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

  body.sidebar-open .sidebar-backdrop,
  body.sidebar-fullscreen .sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    z-index: 35;
    border: none;
    padding: 0;
  }

  body.sidebar-open .sidebar-close-btn,
  body.sidebar-fullscreen .sidebar-close-btn {
    display: grid;
  }

  .app-shell {
    margin-left: 0;
  }

  .btn-menu {
    display: flex;
  }

  body.sidebar-fullscreen .sidebar-backdrop {
    display: none;
  }
}

@media (max-width: 600px) {
  .card-chinese { font-size: 2rem; }
  .sentence-chinese { font-size: 1.15rem; }
  .toolbar { flex-direction: column; align-items: stretch; }

  .tabs {
    padding: 0.5rem 1rem 0;
    justify-content: space-around;
    gap: 0;
  }

  .tab {
    flex: 1;
    justify-content: center;
    padding: 0.7rem 0.5rem;
    font-size: 0;
  }

  .tab-icon {
    display: block;
  }

  .tab-label {
    display: none;
  }

  .tab .badge {
    position: absolute;
    top: 0.25rem;
    right: calc(50% - 1.4rem);
    font-size: 0.65rem;
    min-width: 1rem;
    padding: 0.05rem 0.3rem;
  }

  .header {
    padding: 0.85rem 1rem;
  }

  .container {
    padding: 1rem;
  }
}
