:root {
  --bg: #F1F2F8;
  --card-bg: #FFFFFF;
  --border: #E4E6F0;
  --text: #1F2233;
  --text-muted: #7C8194;
  --purple: #6C5DD3;
  --purple-light: #EFEBFC;
  --red: #FF3B30;
  --red-light: #FEE9E7;
  --blue: #2F80ED;
  --blue-light: #E8F1FE;
  --green: #22C55E;
  --violet: #8B5CF6;
  --pink: #EC4899;
  --orange: #F2994A;
  --teal: #14B8A6;
  --radius-lg: 16px;
  --radius-md: 12px;
  --shadow-card: 0 8px 24px rgba(31, 34, 51, 0.06);
}

* {
  box-sizing: border-box;
}

html, body {
  height: 100%;
}

body {
  margin: 0;
  overflow: hidden;
  font-family: "Inter", -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text);
}

/* Ghim header + cột "Câu hỏi" — #screen-builder chiếm trọn viewport, chỉ
   .content (danh sách câu hỏi) cuộn riêng bên trong, xem .builder-body bên
   dưới. Cùng cách dựng với #ai-chat-screen/#settings-screen (header cố
   định + vùng nội dung overflow-y:auto riêng), áp dụng luôn cho màn chính
   để lướt trang không kéo mất header/cột trái. */
.page {
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.icon {
  width: 18px;
  height: 18px;
  display: block;
}

/* ---------- Top bar ---------- */
.topbar {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 68px;
  padding: 0 32px;
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
}

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

.tab-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 0.9375rem;
  font-weight: 600;
  padding: 8px 18px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, box-shadow 0.15s;
}

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

.tab-btn.is-active {
  background: var(--card-bg);
  color: var(--text);
  box-shadow: 0 1px 3px rgba(31, 34, 51, 0.1);
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 24px;
}

.save-status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-muted);
}

.save-status .icon {
  width: 16px;
  height: 16px;
  color: var(--green);
}

.btn-next {
  display: flex;
  align-items: center;
  gap: 4px;
  border: none;
  background: var(--purple);
  color: #fff;
  font-family: inherit;
  font-size: 0.9375rem;
  font-weight: 600;
  padding: 10px 20px;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}

.btn-next:hover {
  background: #5b4dc4;
}

.btn-next:active {
  transform: scale(0.97);
}

/* ---------- Content ---------- */
.builder-body {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: stretch;
}

.content {
  flex: 1;
  min-width: 0;
  height: 100%;
  overflow-y: auto;
  max-width: 680px;
  margin: 0 auto;
  padding: 40px 20px 80px;
}

/* ---------- Cột "Câu hỏi" (điều hướng nhanh giữa các thẻ câu hỏi) ---------- */
.question-nav[hidden] {
  display: none;
}

.question-nav {
  flex-shrink: 0;
  width: 240px;
  height: 100%;
  overflow-y: auto;
  padding: 40px 16px 40px 20px;
}

.question-nav-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.question-nav-title {
  font-size: 0.9375rem;
  font-weight: 700;
  color: var(--text);
}

.question-nav-count {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
}

.question-nav-count .icon {
  width: 14px;
  height: 14px;
}

.question-nav-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 16px;
}

.question-nav-item {
  display: flex;
  align-items: center;
  gap: 8px;
}

.question-nav-item-number {
  flex-shrink: 0;
  width: 14px;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-muted);
  text-align: right;
}

.question-nav-item-pill {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1.5px solid var(--border);
  background: var(--card-bg);
  border-radius: 10px;
  padding: 9px 12px;
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.question-nav-item-pill:hover {
  border-color: #C7CCDB;
}

.question-nav-item.is-active .question-nav-item-pill {
  border-color: var(--purple);
  box-shadow: 0 0 0 3px var(--purple-light);
}

.question-nav-item-icon {
  flex-shrink: 0;
  display: flex;
}

.question-nav-item-icon .icon {
  width: 15px;
  height: 15px;
}

.question-nav-item-text {
  flex: 1;
  min-width: 0;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: left;
}

.question-nav-shuffle-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  border: 1px solid var(--border);
  background: var(--card-bg);
  border-radius: 10px;
  padding: 10px;
  font-family: inherit;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
}

.question-nav-shuffle-btn:not(:disabled):hover {
  background: var(--bg);
  color: var(--text);
}

.question-nav-shuffle-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.question-nav-shuffle-btn .icon {
  width: 15px;
  height: 15px;
}

.ai-card {
  position: relative;
  background: var(--card-bg);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: 28px 32px 32px;
}

.ai-heading {
  margin: 0 0 24px;
  font-size: 1.0625rem;
  font-weight: 700;
  line-height: 1.5;
  max-width: 460px;
  color: var(--text);
}

.ai-heading .accent {
  color: var(--purple);
}

.mascot {
  position: absolute;
  top: 22px;
  right: 28px;
}

.ai-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 14px;
}

.ai-option {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  text-align: left;
  border: 1px solid var(--border);
  background: var(--card-bg);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  cursor: pointer;
  font-family: inherit;
  transition: border-color 0.15s, box-shadow 0.15s, transform 0.1s;
}

.ai-option:hover {
  border-color: var(--purple);
  box-shadow: 0 4px 14px rgba(108, 93, 211, 0.14);
}

.ai-option:active {
  transform: scale(0.99);
}

.ai-icon {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.ai-icon .icon {
  width: 20px;
  height: 20px;
}

.icon-bg-purple {
  background: var(--purple-light);
  color: var(--purple);
}

.icon-bg-red {
  background: var(--red-light);
  color: var(--red);
}

.icon-bg-blue {
  background: var(--blue-light);
  color: var(--blue);
}

.ai-option-text {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

.ai-option-title-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.ai-option-title {
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--text);
}

.ai-option-sub {
  font-size: 0.8125rem;
  color: var(--text-muted);
  line-height: 1.4;
}

.badge-beta {
  flex-shrink: 0;
  font-size: 0.6875rem;
  font-weight: 700;
  color: #B45309;
  background: #FEF3C7;
  padding: 2px 8px;
  border-radius: 999px;
  line-height: 1.4;
}

/* ---------- Divider ---------- */
.divider {
  display: flex;
  align-items: center;
  gap: 16px;
  margin: 32px 0;
  color: var(--text-muted);
  font-size: 0.875rem;
}

.divider::before,
.divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* ---------- Manual question-type grid ---------- */
.manual-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  row-gap: 20px;
  column-gap: 12px;
}

.manual-btn {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  border: 1px solid var(--border);
  background: var(--card-bg);
  border-radius: 999px;
  padding: 12px 16px;
  cursor: pointer;
  font-family: inherit;
  transition: border-color 0.15s, box-shadow 0.15s, transform 0.1s;
}

.manual-btn:hover {
  border-color: #C7CCDB;
  box-shadow: 0 4px 14px rgba(31, 34, 51, 0.08);
}

.manual-btn:active {
  transform: scale(0.99);
}

.manual-icon {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
}

.manual-icon .icon {
  width: 20px;
  height: 20px;
}

.color-green { color: var(--green); }
.color-blue { color: var(--blue); }
.color-violet { color: var(--violet); }
.color-pink { color: var(--pink); }
.color-orange { color: var(--orange); }
.color-teal { color: var(--teal); }

.manual-label {
  flex: 1;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.manual-plus {
  flex-shrink: 0;
  font-size: 1.125rem;
  font-weight: 400;
  color: var(--text-muted);
  line-height: 1;
}

.new-badge {
  position: absolute;
  top: -1px;
  right: -1px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--card-bg);
  box-shadow: 0 0 0 1px var(--border);
}

.new-badge .icon {
  width: 16px;
  height: 16px;
  color: var(--blue);
}

/* ---------- Question list (populated once a type is chosen) ---------- */
.question-list {
  list-style: none;
  margin: 24px 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.question-list li {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  font-size: 0.875rem;
  color: var(--text);
}

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 32px;
  transform: translateX(-50%) translateY(12px);
  background: #1F2233;
  color: #fff;
  font-size: 0.875rem;
  font-weight: 500;
  padding: 12px 20px;
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 100;
}

.toast.is-visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ---------- Responsive ---------- */
/* ============================================================================
   Màn hình "Hỏi AI" (#ai-chat-screen) — mở bằng animation trượt từ phải khi
   nhấn "Nhập chủ đề" ở màn chính (xem js/script.js openAiChatScreen()).
   Đè toàn màn hình (position:fixed inset:0), nên không cần ẩn/hiện
   #screen-builder bên dưới — nó vẫn nằm nguyên trong layout, chỉ bị che.
   ============================================================================ */
.ai-chat-screen[hidden] {
  display: none;
}

.ai-chat-screen {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  background: var(--bg);
  transform: translateX(100%);
  transition: transform 0.38s cubic-bezier(0.22, 1, 0.36, 1);
}

.ai-chat-screen.is-open {
  transform: translateX(0);
}

.ai-chat-left {
  flex: 1;
  min-width: 0;
  overflow-y: auto;
  padding: 24px 40px 40px;
}

.ai-chat-left-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 24px;
}

.icon-btn-square {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border: none;
  border-radius: 8px;
  background: var(--card-bg);
  color: var(--text-muted);
  cursor: pointer;
  transition: background 0.15s;
}

.icon-btn-square:hover {
  background: #E4E6F0;
}

.ai-chat-left-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
}

.badge-free {
  font-size: 0.6875rem;
  font-weight: 700;
  color: var(--text-muted);
  background: var(--card-bg);
  border: 1px solid var(--border);
  padding: 2px 10px;
  border-radius: 999px;
}

.ai-chat-right {
  width: 460px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: var(--card-bg);
  border-left: 1px solid var(--border);
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  padding: 16px 20px;
}

.icon-btn-round {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--card-bg);
  color: var(--text-muted);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  flex-shrink: 0;
}

.icon-btn-round:hover {
  border-color: #C7CCDB;
  background: var(--bg);
}

.btn-collapse-chat {
  border: 1px solid var(--purple);
  background: var(--card-bg);
  color: var(--purple);
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  padding: 8px 16px;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.15s;
}

.btn-collapse-chat:hover {
  background: var(--purple-light);
}

.chat-messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 4px 20px 20px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.chat-bot-msg {
  position: relative;
  padding-right: 8px;
}

.chat-bot-msg p {
  margin: 0 0 4px;
  font-size: 0.9375rem;
  line-height: 1.6;
  color: var(--text);
}

.chat-bot-msg p:last-of-type {
  margin-bottom: 8px;
}

.chat-msg-copy {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: 6px;
}

.chat-msg-copy:hover {
  background: var(--bg);
  color: var(--text);
}

.chat-msg-copy .icon {
  width: 15px;
  height: 15px;
}

.chat-suggestions {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 10px;
}

.chat-suggestion-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: 340px;
  border: 1px solid var(--border);
  background: var(--card-bg);
  border-radius: 14px;
  padding: 10px 14px;
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text);
  text-align: left;
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.chat-suggestion-chip:hover {
  border-color: var(--purple);
  box-shadow: 0 4px 14px rgba(108, 93, 211, 0.14);
}

.chip-icon {
  flex-shrink: 0;
  width: 18px;
  height: 18px;
}

.chip-chevron {
  flex-shrink: 0;
  width: 16px;
  height: 16px;
  margin-left: auto;
  color: var(--text-muted);
}

.chat-msg-user {
  align-self: flex-end;
  max-width: 340px;
  background: var(--purple-light);
  color: var(--purple);
  font-size: 0.875rem;
  font-weight: 500;
  padding: 10px 14px;
  border-radius: 14px;
}

.chat-msg-assistant p {
  margin: 0 0 4px;
  font-size: 0.9375rem;
  line-height: 1.6;
  color: var(--text);
}

.chat-msg-assistant.is-typing p {
  color: var(--text-muted);
}

.chat-input-area {
  padding: 8px 20px 16px;
}

.chat-input-box {
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 12px 14px 10px;
}

.chat-input {
  width: 100%;
  border: none;
  outline: none;
  resize: none;
  background: transparent;
  font-family: inherit;
  font-size: 0.9375rem;
  color: var(--text);
  min-height: 22px;
  max-height: 120px;
}

.chat-input::placeholder {
  color: #A9AEBD;
}

.chat-input-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 6px;
}

.chat-quota {
  flex: 1;
  text-align: right;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.chat-send-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  flex-shrink: 0;
  border: none;
  border-radius: 50%;
  background: #E4E6F0;
  color: var(--text-muted);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.chat-send-btn:hover {
  background: var(--purple);
  color: #fff;
}

.chat-disclaimer {
  margin: 10px 4px 0;
  font-size: 0.75rem;
  color: var(--text-muted);
  line-height: 1.5;
}

.chat-disclaimer a {
  color: var(--blue);
  text-decoration: none;
  font-weight: 500;
}

.chat-disclaimer a:hover {
  text-decoration: underline;
}

/* ============================================================================
   Thẻ soạn câu hỏi "Trắc nghiệm" (#question-cards, .question-card) — xuất
   hiện với animation trượt+mờ dần khi nhấn nút "Trắc nghiệm" (xem
   insertQuestionCard() trong js/script.js). Container #question-cards được
   DI CHUYỂN (không nhân bản) giữa #screen-builder và #ai-chat-screen tuỳ
   màn nào đang mở, nên chỉ có 1 bộ DOM node duy nhất.
   ============================================================================ */
.question-cards[hidden] {
  display: none;
}

.question-cards {
  display: flex;
  flex-direction: column;
  gap: 24px;
  margin-bottom: 20px;
}

.question-card {
  position: relative;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: 0 2px 8px rgba(31, 34, 51, 0.05);
  padding: 24px 28px 20px;
  opacity: 1;
  transform: translateY(0) scale(1);
  transition: opacity 0.28s ease, transform 0.28s cubic-bezier(0.22, 1, 0.36, 1), max-height 0.22s ease, margin 0.22s ease, padding 0.22s ease;
}

.question-card.is-entering {
  opacity: 0;
  transform: translateY(-14px) scale(0.97);
}

.question-card.is-leaving {
  opacity: 0;
  transform: scale(0.97);
  max-height: 0;
  padding-top: 0;
  padding-bottom: 0;
  margin-bottom: -24px;
  overflow: hidden;
}

/* Nhấp nháy nhẹ khi bấm 1 mục ở cột "Câu hỏi" để cuộn tới đúng thẻ đó */
.question-card.is-flash {
  box-shadow: 0 0 0 3px var(--purple-light);
}

.qc-drag-handle {
  position: absolute;
  top: -11px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 16px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--card-bg);
  color: var(--text-muted);
  cursor: grab;
}

.qc-drag-handle .icon {
  width: 16px;
  height: 16px;
}

.qc-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 18px;
  flex-wrap: wrap;
  row-gap: 8px;
}

.qc-index {
  font-size: 0.9375rem;
  font-weight: 700;
  color: var(--text);
}

.qc-type-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--border);
  background: var(--card-bg);
  border-radius: 999px;
  padding: 6px 12px;
  font-family: inherit;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
}

.qc-type-badge:hover {
  border-color: #C7CCDB;
}

.qc-type-icon {
  display: flex;
  color: var(--green);
}

.qc-type-icon .icon {
  width: 15px;
  height: 15px;
}

.qc-badge-chevron {
  width: 14px;
  height: 14px;
  color: var(--text-muted);
}

.qc-header-spacer {
  flex: 1;
}

.qc-shuffle-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  border: none;
  background: transparent;
  font-family: inherit;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-muted);
  padding: 6px 8px;
  border-radius: 8px;
  cursor: pointer;
}

.qc-shuffle-btn .icon {
  width: 15px;
  height: 15px;
}

.qc-shuffle-btn:hover {
  background: var(--bg);
  color: var(--text);
}

.qc-shuffle-btn.is-active {
  color: var(--purple);
  background: var(--purple-light);
}

.qc-divider {
  width: 1px;
  height: 20px;
  background: var(--border);
  flex-shrink: 0;
}

.qc-icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  flex-shrink: 0;
}

.qc-icon-btn:hover {
  background: var(--bg);
  color: var(--text);
}

.qc-icon-btn .icon {
  width: 17px;
  height: 17px;
}

.qc-delete-btn:hover {
  color: var(--red);
}

.qc-question-input {
  display: block;
  width: 100%;
  border: none;
  border-bottom: 2px solid transparent;
  outline: none;
  background: transparent;
  font-family: inherit;
  font-size: 1rem;
  font-weight: 500;
  color: var(--text);
  padding-bottom: 6px;
  margin-bottom: 14px;
  min-height: 24px;
  cursor: text;
  word-wrap: break-word;
  transition: border-color 0.15s;
}

.qc-question-input:focus {
  border-color: var(--purple);
}

/* .qc-question-input giờ là <div contenteditable> (không còn <textarea>) để
   hỗ trợ định dạng thật (đậm/gạch chân/tô màu/công thức/ảnh) — placeholder
   mô phỏng bằng kỹ thuật :empty:before vì contenteditable không có thuộc
   tính placeholder gốc. */
.qc-question-input:empty:before {
  content: attr(data-placeholder);
  color: #A9AEBD;
  font-weight: 400;
}

.qc-question-input img {
  display: block;
  max-width: 100%;
  max-height: 220px;
  border-radius: 8px;
  margin: 6px 0;
}

.qc-question-input .katex {
  font-size: 1.05em;
}

.qc-editor-toolbar {
  display: flex;
  align-items: center;
  gap: 2px;
  flex-wrap: wrap;
  max-height: 0;
  opacity: 0;
  overflow: hidden;
  margin-bottom: 0;
  transition: max-height 0.22s ease, opacity 0.18s ease, margin-bottom 0.22s ease;
}

.qc-editor-toolbar.is-visible {
  max-height: 60px;
  opacity: 1;
  margin-bottom: 16px;
}

.qc-toolbar-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  border: none;
  background: transparent;
  border-radius: 6px;
  padding: 6px 8px;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 0.8125rem;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
}

.qc-toolbar-btn:hover {
  background: var(--bg);
  color: var(--text);
}

.qc-toolbar-btn .icon {
  width: 16px;
  height: 16px;
}

.qc-toolbar-fx {
  font-style: italic;
  font-weight: 700;
  font-size: 0.8125rem;
}

.qc-toolbar-divider {
  width: 1px;
  height: 18px;
  background: var(--border);
  margin: 0 4px;
  flex-shrink: 0;
}

.qc-toolbar-main,
.qc-toolbar-colors {
  display: flex;
  align-items: center;
  gap: 2px;
  flex-wrap: wrap;
}

.qc-toolbar-main[hidden],
.qc-toolbar-colors[hidden] {
  display: none;
}

.qc-color-back-btn,
.qc-color-none-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: none;
  background: transparent;
  border-radius: 6px;
  color: var(--text-muted);
  cursor: pointer;
  flex-shrink: 0;
}

.qc-color-back-btn:hover,
.qc-color-none-btn:hover {
  background: var(--bg);
  color: var(--text);
}

.qc-color-back-btn .icon,
.qc-color-none-btn .icon {
  width: 16px;
  height: 16px;
}

.qc-color-swatch {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 1px solid rgba(31, 34, 51, 0.08);
  cursor: pointer;
  flex-shrink: 0;
  transition: transform 0.1s;
}

.qc-color-swatch:hover {
  transform: scale(1.15);
}

.qc-options {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 14px;
}

.qc-option {
  display: flex;
  align-items: center;
  gap: 12px;
}

.qc-option-correct {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 2px solid #D5D9E3;
  background: var(--card-bg);
  color: transparent;
  cursor: pointer;
}

.qc-option-correct .icon {
  width: 14px;
  height: 14px;
}

.qc-option-correct.is-correct {
  border-color: var(--green);
  background: var(--green);
  color: #fff;
}

.qc-option-input {
  flex: 1;
  min-width: 0;
  border: none;
  outline: none;
  background: transparent;
  font-family: inherit;
  font-size: 0.9375rem;
  color: var(--text);
  padding: 4px 0;
}

.qc-option-input::placeholder {
  color: #A9AEBD;
}

.qc-option-remove {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border: none;
  border-radius: 50%;
  background: var(--bg);
  color: var(--text-muted);
  cursor: pointer;
}

.qc-option-remove:hover {
  background: #E4E6F0;
  color: var(--text);
}

.qc-option-remove .icon {
  width: 12px;
  height: 12px;
}

.qc-add-option-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  border: 1px dashed var(--border);
  background: transparent;
  border-radius: 10px;
  padding: 10px;
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  margin-bottom: 14px;
}

.qc-add-option-btn .icon {
  width: 16px;
  height: 16px;
}

.qc-add-option-btn:hover {
  border-color: var(--purple);
  color: var(--purple);
  background: var(--purple-light);
}

.qc-add-hint-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--border);
  background: #FEF9E7;
  border-radius: 999px;
  padding: 7px 14px;
  font-family: inherit;
  font-size: 0.8125rem;
  font-weight: 600;
  color: #92730B;
  cursor: pointer;
}

.qc-add-hint-btn .icon:first-child {
  width: 15px;
  height: 15px;
  color: #D4A72C;
}

.qc-add-hint-btn .icon:last-child {
  width: 14px;
  height: 14px;
}

.qc-hint-field[hidden] {
  display: none;
}

.qc-hint-field {
  margin-top: 12px;
}

.qc-hint-input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  padding: 10px 12px;
  font-family: inherit;
  font-size: 0.875rem;
  color: var(--text);
  resize: none;
  outline: none;
}

.chat-context-chips {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.chat-context-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--purple-light);
  color: var(--purple);
  font-size: 0.75rem;
  font-weight: 600;
  padding: 4px 6px 4px 10px;
  border-radius: 999px;
}

.chat-context-chip button {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  border: none;
  background: transparent;
  color: var(--purple);
  font-size: 0.875rem;
  line-height: 1;
  cursor: pointer;
  border-radius: 50%;
}

.chat-context-chip button:hover {
  background: rgba(108, 93, 211, 0.18);
}

/* ============================================================================
   Màn hình "Cài đặt" (#settings-screen) — mở bằng animation trượt từ phải
   khi nhấn "Tiếp" (đã tạo ít nhất 1 câu hỏi) hoặc tab "Cài đặt" (xem
   openSettingsScreen() trong js/script.js). Cùng kỹ thuật overlay
   position:fixed + transform như #ai-chat-screen.
   ============================================================================ */
.settings-screen[hidden] {
  display: none;
}

.settings-screen {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  transform: translateX(100%);
  transition: transform 0.38s cubic-bezier(0.22, 1, 0.36, 1);
}

.settings-screen.is-open {
  transform: translateX(0);
}

.settings-topbar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  height: 68px;
  padding: 0 24px;
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.settings-topbar-left {
  display: flex;
  align-items: center;
  gap: 10px;
  justify-self: start;
}

.settings-tab-group {
  justify-self: center;
}

.settings-content {
  flex: 1;
  overflow-y: auto;
  padding: 40px 20px 80px;
}

.settings-card {
  max-width: 620px;
  margin: 0 auto 20px;
  background: var(--card-bg);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: 24px 28px;
}

.settings-card-title {
  margin: 0 0 18px;
  font-size: 0.8125rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  color: var(--text-muted);
}

.map-picker {
  background: var(--purple-light);
  border-radius: 14px;
  padding: 20px;
  text-align: center;
  margin-bottom: 16px;
}

.map-picker-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--purple);
  margin-bottom: 4px;
}

.map-picker-icon .icon {
  width: 20px;
  height: 20px;
}

.map-picker-label {
  margin: 0 0 16px;
  font-size: 0.9375rem;
  font-weight: 700;
  color: var(--purple);
}

.map-thumbs {
  display: flex;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
}

.map-thumb {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 56px;
  border-radius: 12px;
  border: 2px solid transparent;
  color: #fff;
  cursor: pointer;
  transition: transform 0.15s, border-color 0.15s;
}

.map-thumb:hover {
  transform: translateY(-2px);
}

.map-thumb.is-selected {
  border-color: var(--purple);
}

.map-thumb .icon {
  width: 24px;
  height: 24px;
}

.map-thumb-1 { background: linear-gradient(135deg, #FFB800, #FF8A00); }
.map-thumb-2 { background: linear-gradient(135deg, #2F80ED, #6C5DD3); }
.map-thumb-3 { background: linear-gradient(135deg, #EC4899, #F2994A); }
.map-thumb-4 { background: linear-gradient(135deg, #22C55E, #14B8A6); }
.map-thumb-5 { background: linear-gradient(135deg, #8B5CF6, #2F80ED); }

.settings-input {
  display: block;
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  font-family: inherit;
  font-size: 0.9375rem;
  color: var(--text);
  outline: none;
  margin-bottom: 16px;
}

.settings-input:focus {
  border-color: var(--purple);
}

.settings-input::placeholder {
  color: #A9AEBD;
}

.school-info-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--border);
  background: var(--card-bg);
  border-radius: 999px;
  padding: 8px 16px;
  font-family: inherit;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
}

.school-info-btn:hover {
  border-color: #C7CCDB;
  background: var(--bg);
}

.school-info-btn .icon {
  width: 16px;
  height: 16px;
  color: var(--text-muted);
}

.required-star {
  color: var(--red);
}

.settings-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 0;
  border-top: 1px solid var(--border);
}

.settings-card > .settings-row:first-of-type {
  border-top: none;
  padding-top: 0;
}

.settings-row-main {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  min-width: 0;
}

.settings-row-icon {
  flex-shrink: 0;
  width: 19px;
  height: 19px;
  color: var(--text-muted);
  margin-top: 2px;
}

.settings-row-text {
  min-width: 0;
}

.settings-row-title {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.9375rem;
  font-weight: 700;
  color: var(--text);
}

.settings-row-sub {
  margin: 4px 0 0;
  font-size: 0.8125rem;
  color: var(--text-muted);
  line-height: 1.5;
}

.pro-bolt {
  width: 14px;
  height: 14px;
  color: var(--purple);
}

.custom-select {
  position: relative;
  flex-shrink: 0;
  width: 200px;
}

.custom-select-trigger {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px 12px;
  font-family: inherit;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text);
  background: var(--card-bg);
  cursor: pointer;
}

.custom-select-trigger:hover {
  border-color: #C7CCDB;
}

.custom-select.is-open .custom-select-trigger {
  border-color: var(--purple);
  box-shadow: 0 0 0 3px var(--purple-light);
}

.custom-select-chevron {
  flex-shrink: 0;
  width: 15px;
  height: 15px;
  color: var(--text-muted);
  transition: transform 0.15s;
}

.custom-select.is-open .custom-select-chevron {
  transform: rotate(180deg);
}

.custom-select-panel[hidden] {
  display: none;
}

.custom-select-panel {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  z-index: 5;
  margin: 0;
  padding: 6px;
  list-style: none;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 12px 28px rgba(31, 34, 51, 0.14);
}

.custom-select-option {
  padding: 9px 10px;
  border-radius: 8px;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text);
  cursor: pointer;
}

.custom-select-option:hover {
  background: var(--bg);
}

.custom-select-option.is-selected {
  background: var(--purple-light);
  color: var(--purple);
  font-weight: 700;
}

.toggle-switch {
  position: relative;
  flex-shrink: 0;
  display: inline-block;
  width: 40px;
  height: 24px;
}

.toggle-switch input {
  position: absolute;
  opacity: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  cursor: pointer;
}

.toggle-slider {
  position: absolute;
  inset: 0;
  background: #D5D9E3;
  border-radius: 999px;
  transition: background 0.15s;
}

.toggle-slider::before {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.15s;
  box-shadow: 0 1px 3px rgba(31, 34, 51, 0.2);
}

.toggle-switch input:checked + .toggle-slider {
  background: var(--purple);
}

.toggle-switch input:checked + .toggle-slider::before {
  transform: translateX(16px);
}

/* ============================================================================
   Modal chặn chuyển bước khi còn trường bắt buộc trống (xem
   showValidationModal() trong js/script.js).
   ============================================================================ */
.validation-modal-overlay[hidden] {
  display: none;
}

.validation-modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(31, 34, 51, 0.45);
  padding: 20px;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.validation-modal-overlay.is-visible {
  opacity: 1;
}

.validation-modal {
  width: 100%;
  max-width: 360px;
  background: var(--card-bg);
  border-radius: 16px;
  padding: 28px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.25);
  transform: scale(0.95) translateY(8px);
  transition: transform 0.2s ease;
}

.validation-modal-overlay.is-visible .validation-modal {
  transform: scale(1) translateY(0);
}

.validation-modal-text {
  margin: 0 0 20px;
  font-size: 1.0625rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1.4;
}

.validation-modal-btn {
  display: block;
  width: 100%;
  border: none;
  background: var(--purple);
  color: #fff;
  font-family: inherit;
  font-size: 0.9375rem;
  font-weight: 700;
  padding: 13px;
  border-radius: 12px;
  cursor: pointer;
}

.validation-modal-btn:hover {
  background: #5b4dc4;
}

/* ============================================================================
   Modal "Nhập công thức" (xem openFormulaModal() trong js/script.js) — cùng
   kỹ thuật overlay+animation với .validation-modal-overlay ở trên.
   ============================================================================ */
.formula-modal-overlay[hidden] {
  display: none;
}

.formula-modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(31, 34, 51, 0.45);
  padding: 20px;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.formula-modal-overlay.is-visible {
  opacity: 1;
}

.formula-modal {
  width: 100%;
  max-width: 380px;
  background: var(--card-bg);
  border-radius: 16px;
  padding: 24px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.25);
  transform: scale(0.95) translateY(8px);
  transition: transform 0.2s ease;
}

.formula-modal-overlay.is-visible .formula-modal {
  transform: scale(1) translateY(0);
}

.formula-modal-title {
  margin: 0 0 14px;
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
}

.formula-modal-input {
  display: block;
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  font-family: "Courier New", monospace;
  font-size: 0.9375rem;
  color: var(--text);
  outline: none;
  margin-bottom: 12px;
}

.formula-modal-input:focus {
  border-color: var(--purple);
}

.formula-modal-preview {
  min-height: 48px;
  border: 1px dashed var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow-x: auto;
  color: var(--text-muted);
  font-size: 0.8125rem;
}

.formula-modal-preview .katex-error {
  color: var(--red);
  font-family: inherit;
  font-size: 0.8125rem;
}

.formula-modal-actions {
  display: flex;
  gap: 10px;
}

.formula-modal-cancel-btn {
  flex: 1;
  border: 1px solid var(--border);
  background: var(--card-bg);
  color: var(--text);
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  padding: 11px;
  border-radius: 10px;
  cursor: pointer;
}

.formula-modal-cancel-btn:hover {
  background: var(--bg);
}

.formula-modal-insert-btn {
  flex: 1;
  border: none;
  background: var(--purple);
  color: #fff;
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 700;
  padding: 11px;
  border-radius: 10px;
  cursor: pointer;
}

.formula-modal-insert-btn:hover {
  background: #5b4dc4;
}

.formula-modal-insert-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

@media (max-width: 640px) {
  .topbar {
    padding: 0 16px;
  }

  .topbar-right {
    gap: 12px;
  }

  .save-status-text {
    display: none;
  }

  .content {
    padding: 24px 12px 60px;
  }

  .ai-card {
    padding: 20px 16px 24px;
  }

  .mascot {
    display: none;
  }

  .ai-grid,
  .manual-grid {
    grid-template-columns: 1fr;
  }

  .question-nav {
    display: none;
  }

  .ai-chat-screen {
    flex-direction: column;
  }

  .ai-chat-left {
    display: none;
  }

  .ai-chat-right {
    width: 100%;
    height: 100%;
  }

  .question-card {
    padding: 20px 16px 16px;
  }

  .qc-header {
    gap: 8px;
  }

  .qc-shuffle-label {
    display: none;
  }

  .settings-topbar {
    grid-template-columns: auto 1fr auto;
    padding: 0 12px;
    gap: 8px;
  }

  .settings-tab-group .tab-btn span,
  .settings-tab-group .tab-btn {
    font-size: 0.8125rem;
  }

  .ai-chat-left-title,
  .badge-free {
    display: none;
  }

  .settings-card {
    padding: 20px 16px;
  }

  .map-thumb {
    width: 48px;
    height: 48px;
  }
}
