/* Thành phần riêng cho web học từ vựng — dùng chung biến màu của style.css */

.muted { color: var(--muted); }
.center { text-align: center; justify-content: center; }
.warn {
  margin: 8px 0;
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--note-bg);
  border: 1px solid var(--note-bd);
  color: var(--note-fg);
  font-size: 0.85rem;
}

kbd {
  display: inline-block;
  min-width: 1.4em;
  padding: 0 5px;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 5px;
  background: var(--surface-2);
  font: 600 0.72rem/1.5 ui-monospace, Consolas, monospace;
  text-align: center;
  color: var(--muted);
}

.sel,
.num-input {
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-size: 0.82rem;
  max-width: 100%;
}

.sel:disabled { opacity: 0.5; }

.lesson-pick {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.lesson-pick[hidden] { display: none; }

.lesson-pick .sel { max-width: 210px; }

.btn.danger {
  border-color: var(--bad);
  color: var(--bad);
}

/* Thanh chọn cách học */
.mode-bar {
  margin: 0;
}

.mode-bar .chip {
  padding: 7px 12px;
  font-size: 0.82rem;
  font-weight: 600;
}

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

html.dark .mode-bar .chip.active { color: #fff; }

/* Thẻ học */
.vocab-card { min-height: 360px; }

.session-bar {
  height: 4px;
  margin: 0 0 12px;
  background: var(--progress-track);
  border-radius: 99px;
  overflow: hidden;
}

.session-bar > div {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), #22c55e);
  transition: width 0.25s ease;
}

.vocab-prompt {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  margin: 6px 0 18px;
  text-align: center;
}

.vocab-word {
  font-size: clamp(1.7rem, 5vw, 2.4rem);
  font-weight: 800;
  letter-spacing: 0.01em;
  line-height: 1.2;
  word-break: break-word;
}

.vocab-ipa {
  font-family: "Segoe UI", "Lucida Sans Unicode", "Arial Unicode MS", sans-serif;
  font-size: 1.05rem;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 8px;
}

.vocab-meaning-big {
  font-size: clamp(1.1rem, 3.4vw, 1.4rem);
  font-weight: 700;
  line-height: 1.45;
  max-width: 640px;
}

.pos-tag {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--pick);
  border: 1px solid var(--pick-b);
  color: var(--primary);
  font-size: 0.72rem;
  font-weight: 700;
  font-style: italic;
  vertical-align: middle;
}

.wi-pos {
  font-size: 0.85rem;
  color: var(--muted);
}

.speak-btn { font-size: 0.95rem; }
.speak-btn.big {
  font-size: 1.25rem;
  padding: 16px 28px;
  border-radius: 999px;
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}
.speak-btn.big:hover { background: var(--primary-h); }

.listen-prompt {
  flex-direction: row;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 10px;
  display: flex;
  margin: 18px 0 22px;
}

/* Flashcard */
.flash-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  min-height: 220px;
  padding: 24px 16px;
  border: 2px dashed var(--line);
  border-radius: 14px;
  background: var(--surface-2);
  color: inherit;
  cursor: pointer;
  text-align: center;
  transition: border-color 0.15s ease, transform 0.15s ease;
}

div.flash-card:not(.flipped):hover {
  border-color: var(--pick-b);
  transform: translateY(-1px);
}

.flash-card.flipped {
  cursor: default;
  border-style: solid;
  align-items: stretch;
}

.flash-face {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.flash-tip {
  font-size: 0.8rem;
  color: var(--muted);
  font-style: italic;
}

.flash-back {
  border-top: 1px solid var(--line);
  padding-top: 12px;
  text-align: left;
}

.grade-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  width: 100%;
}

.btn.grade {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 8px 6px;
  white-space: normal;
}

.btn.grade small { font-size: 0.7rem; color: var(--muted); }
.btn.grade.g0 { border-color: #f87171; }
.btn.grade.g0 b { color: var(--bad); }
.btn.grade.g1 { border-color: #fbbf24; }
.btn.grade.g1 b { color: #d97706; }
.btn.grade.g2 { border-color: #60a5fa; }
.btn.grade.g2 b { color: var(--primary); }
.btn.grade.g3 { border-color: #34d399; }
.btn.grade.g3 b { color: var(--ok); }

/* Thông tin từ */
.word-info {
  display: flex;
  flex-direction: column;
  gap: 6px;
  color: var(--text);
}

.wi-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.wi-word { font-size: 1.25rem; font-weight: 800; }
.wi-ipa { color: var(--muted); }
.wi-meaning { font-size: 0.98rem; line-height: 1.5; }
.wi-meaning.center { text-align: center; }
.wi-meta { font-size: 0.78rem; color: var(--muted); }

.card-explain .word-info { font-size: 0.9rem; }
.card-explain { max-height: none; }

.dict-links {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 12px;
  font-size: 0.8rem;
}

.dict-links a { color: var(--primary); text-decoration: none; }
.dict-links a:hover { text-decoration: underline; }

.badge {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 700;
  white-space: nowrap;
  border: 1px solid var(--line);
  color: var(--muted);
  background: var(--surface);
}

.badge.st-learning { color: #b45309; border-color: #fcd34d; background: var(--star-bg); }
.badge.st-mastered { color: var(--cell-ok-fg); border-color: #6ee7b7; background: var(--cell-ok-bg); }

/* Đáp án dạng lớn (từ tiếng Anh) */
.opts-big .opt-text { font-size: 1.08rem; font-weight: 600; }
.opts-two {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.opts-two .opt {
  justify-content: center;
  border-color: var(--line);
  padding: 14px 12px;
}

.card-options .opt { border-color: var(--line); }

.fill-sentence {
  font-size: 1.15rem;
  line-height: 1.6;
  max-width: 640px;
}

.blank {
  display: inline-block;
  min-width: 5ch;
  padding: 0 6px;
  border-bottom: 2px solid var(--primary);
  font-weight: 800;
  color: var(--primary);
}

.hint-pattern {
  margin: 0 0 12px;
  text-align: center;
  font: 700 1.2rem/1.4 ui-monospace, Consolas, monospace;
  letter-spacing: 0.08em;
  color: var(--primary);
}

.vocab-card .fill-input { font-size: 1.1rem; }

/* Đúng / Sai */
.tf-prompt { gap: 4px; }
.tf-eq { font-size: 0.85rem; color: var(--muted); font-style: italic; }

.tf-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.btn.tf-btn {
  padding: 14px 10px;
  font-size: 1.05rem;
  font-weight: 700;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
}

.btn.tf-yes { border-color: #34d399; color: var(--ok); }
.btn.tf-no { border-color: #f87171; color: var(--bad); }
.btn.tf-btn.is-answer { box-shadow: 0 0 0 3px var(--pick-b); opacity: 1; }

.combo { text-align: center; margin: 12px 0 0; font-size: 0.85rem; color: var(--muted); }
.combo b { color: var(--primary); font-size: 1.05rem; }

/* Phát âm */
.mic-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.btn.mic-btn {
  padding: 14px 26px;
  border-radius: 999px;
  font-size: 1.05rem;
  font-weight: 700;
  border-color: var(--primary);
  color: var(--primary);
}

.btn.mic-btn.is-on {
  background: var(--bad);
  border-color: var(--bad);
  color: #fff;
  animation: pulse 1.1s ease-in-out infinite;
}

@keyframes pulse {
  50% { box-shadow: 0 0 0 8px rgba(220, 38, 38, 0.15); }
}

.heard { margin: 0; font-size: 0.92rem; }

/* Ghép cặp */
.match-grid {
  display: grid;
  grid-template-columns: minmax(0, 0.8fr) minmax(0, 1.2fr);
  gap: 10px;
}

.match-col {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.match-item {
  min-height: 48px;
  padding: 10px 12px;
  border: 1.5px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: inherit;
  text-align: left;
  font-size: 0.92rem;
  line-height: 1.35;
  cursor: pointer;
  transition: background 0.15s ease, opacity 0.2s ease;
}

.match-col:first-child .match-item { font-weight: 700; }
.match-item:hover:not(:disabled) { border-color: var(--hover-bd); }
.match-item.sel { background: var(--pick); border-color: var(--pick-b); }
.match-item.wrong { background: var(--bad-bg); border-color: #fca5a5; animation: shake 0.3s; }
.match-item.done { background: var(--ok-bg); border-color: #6ee7b7; opacity: 0.55; cursor: default; }

@keyframes shake {
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}

/* Trống / tổng kết */
.empty-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 6px;
}

.empty-card h2 { margin: 4px 0; font-size: 1.25rem; }
.big-emoji { font-size: 2.6rem; }
.summary-line { font-size: 1rem; font-weight: 600; }
.summary-line .ok { color: var(--ok); }
.summary-line .bad { color: var(--bad); }

.wrong-list {
  width: 100%;
  max-width: 620px;
  margin: 8px 0;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.wrong-list > strong {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.wrong-item {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  font-size: 0.9rem;
}

/* Danh sách */
.list-search { margin: 4px 0 12px; }

.vocab-table {
  display: flex;
  flex-direction: column;
}

.vrow {
  display: grid;
  grid-template-columns: 42px 40px minmax(120px, 1fr) minmax(0, 1.6fr) auto 40px;
  align-items: center;
  gap: 8px;
  padding: 8px 4px;
  border-bottom: 1px solid var(--line);
  font-size: 0.9rem;
}

.vrow:hover { background: var(--surface-2); }
.vno { color: var(--muted); font-size: 0.75rem; text-align: right; }
.vword { line-height: 1.4; word-break: break-word; }
.vmean { line-height: 1.45; }
.star-btn.starred,
#btnStar.starred {
  color: var(--star-fg);
  border-color: var(--star-bd);
  background: var(--star-bg);
}

/* Thống kê */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 10px;
  margin: 6px 0 16px;
}

.stat-tile {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface-2);
}

.stat-tile b { font-size: 1.45rem; }
.stat-tile span { font-size: 0.78rem; color: var(--muted); }
.stat-tile.ok b { color: var(--ok); }
.stat-tile.bad b { color: var(--bad); }

.stat-h {
  margin: 16px 0 8px;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.bars {
  display: grid;
  grid-template-columns: repeat(14, minmax(0, 1fr));
  gap: 4px;
  align-items: end;
  height: 130px;
}

.bar {
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
  height: 100%;
  gap: 3px;
}

.bar-fill {
  width: 100%;
  min-height: 2px;
  border-radius: 4px 4px 0 0;
  background: linear-gradient(180deg, #60a5fa, var(--primary));
}

.bar small { font-size: 0.6rem; color: var(--muted); }

.box-rows { display: flex; flex-direction: column; gap: 6px; }

.box-row {
  display: grid;
  grid-template-columns: 170px 1fr 40px;
  align-items: center;
  gap: 8px;
  font-size: 0.8rem;
}

.box-row b { text-align: right; }

.box-track {
  height: 8px;
  border-radius: 99px;
  background: var(--progress-track);
  overflow: hidden;
}

.box-track > span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, #f59e0b, #22c55e);
}

/* Bản đồ bài */
.map-legend .dot.lv1 { background: #fde68a; border-color: #f59e0b; }
.lesson-cell.lv1 { background: var(--star-bg); border-color: #fcd34d; color: #b45309; }
.lesson-cell.lv2 { background: #fef3c7; border-color: #f59e0b; color: #92400e; }
html.dark .lesson-cell.lv2 { background: #713f12; color: #fde68a; }
.lesson-cell.is-ok.is-current,
.lesson-cell.lv1.is-current,
.lesson-cell.lv2.is-current {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

/* Modal */
.modal-wide { max-width: 640px; }
.help-body { font-size: 0.9rem; line-height: 1.55; }
.help-body p { margin: 0 0 10px; }
.help-body h3 { font-size: 0.85rem; margin: 14px 0 6px; }
.kbd-list { margin: 0; padding-left: 18px; display: flex; flex-direction: column; gap: 4px; }
.modal .sel,
.modal .num-input { width: 100%; padding: 8px 10px; }
.modal input[type="range"] { width: 100%; }

.foot {
  margin: 18px 0 4px;
  font-size: 0.75rem;
  color: var(--muted);
  text-align: center;
  line-height: 1.5;
}

@media (max-width: 640px) {
  .mode-bar {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .mode-bar::-webkit-scrollbar { display: none; }
  .mode-bar .source-label { display: none; }
  .mode-bar .chip { flex: 0 0 auto; }
  .vrow {
    grid-template-columns: 36px minmax(0, 1fr) 40px;
    grid-template-areas: "spk word star" "mean mean mean" "badge badge badge";
  }
  .vrow .vno { display: none; }
  .vrow > .btn:first-of-type { grid-area: spk; }
  .vrow .vword { grid-area: word; }
  .vrow .vmean { grid-area: mean; }
  .vrow .badge { grid-area: badge; justify-self: start; }
  .vrow .star-btn { grid-area: star; }
  .grade-row { gap: 5px; }
  .btn.grade kbd { display: none; }
  .match-grid { grid-template-columns: 1fr 1.3fr; gap: 6px; }
  .match-item { font-size: 0.82rem; padding: 8px; }
  .box-row { grid-template-columns: 120px 1fr 32px; }
  .bars small { display: none; }
}

/* ===================== Bản 2: nhóm từ, FSRS, ghi chú ===================== */
.badge.st-young { color: var(--primary); border-color: var(--pick-b); background: var(--pick); }
.badge.st-leech { color: var(--bad); border-color: #fca5a5; background: var(--bad-bg); }

.chip-sm {
  padding: 2px 8px;
  font-size: 0.74rem;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.chip-sm i { font-style: normal; color: var(--muted); font-size: 0.68rem; }
.chip-static { cursor: default; }
.chip-link { color: var(--primary); border-color: var(--pick-b); }
.chip-on { background: var(--pick); border-color: var(--pick-b); color: var(--text); cursor: default; }
.chip-on .x {
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  padding: 0 0 0 2px;
  font-size: 0.75rem;
}
.chip-on .x:hover { color: var(--bad); }

.wi-tags, .wi-family, .wi-lists {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 5px;
}
.wi-family { font-size: 0.8rem; }
.wi-note {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--muted);
}
.wi-note textarea {
  width: 100%;
  min-height: 2.6rem;
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 400;
  font-size: 0.86rem;
  resize: vertical;
}
.wi-note textarea:focus { outline: none; border-color: var(--pick-b); }
.sel-sm { padding: 3px 6px; font-size: 0.75rem; border-radius: 999px; }
.vnote { font-size: 0.78rem; color: var(--note-fg); }

.mix-tag {
  font-size: 0.7rem;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--pick);
  color: var(--primary);
  font-weight: 700;
}

.wf-base { font-size: 0.95rem; }

/* Nhóm từ */
.gtabs { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0 10px; }
.gtabs .chip { padding: 7px 12px; font-weight: 600; }
.gtabs .chip.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.gintro { font-size: 0.84rem; margin: 0 0 12px; line-height: 1.5; }
.ggrid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 10px;
}
.gcard {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface-2);
}
.gcard-head { display: flex; justify-content: space-between; align-items: baseline; gap: 6px; font-size: 0.92rem; }
.gcard-head .muted { font-size: 0.75rem; white-space: nowrap; }
.gcard-sub { font-size: 0.76rem; color: var(--muted); }
.gcard-meta { font-size: 0.74rem; color: var(--muted); }
.gcard-meta .bad { color: var(--bad); font-weight: 600; }
.gcard-actions { display: flex; flex-wrap: wrap; gap: 5px; }

.gbar {
  position: relative;
  height: 6px;
  border-radius: 99px;
  background: var(--line);
  overflow: hidden;
}
.gbar span { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 99px; }
.gbar-seen { background: #fcd34d; }
.gbar-master { background: #22c55e; }

.gtools { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 10px; }
.gtools .search-input-wrap { flex: 1 1 200px; margin: 0; }
.fam-list { display: flex; flex-direction: column; gap: 8px; }
.fam-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 90px auto;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface-2);
}
.fam-words { display: flex; flex-wrap: wrap; gap: 4px; }
.fam-w {
  padding: 2px 8px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: var(--surface);
  font-size: 0.84rem;
  font-weight: 600;
}
.fam-w i { font-style: normal; font-weight: 400; color: var(--muted); font-size: 0.7rem; }
.fam-w.st-learning, .fam-w.st-young { border-color: #fcd34d; }
.fam-w.st-mastered { border-color: #6ee7b7; background: var(--cell-ok-bg); }

/* Bản đồ bên phải: Bài / Chủ đề */
.map-toggle { display: flex; gap: 4px; margin-bottom: 8px; }
.map-toggle .chip { flex: 1; text-align: center; padding: 5px 6px; font-weight: 600; }
.map-toggle .chip.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.map-legend[hidden] { display: none; }
.topic-map {
  display: flex;
  flex-direction: column;
  gap: 5px;
  overflow-y: auto;
  flex: 1 1 auto;
  min-height: 180px;
}
.topic-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 2px 6px;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: inherit;
  text-align: left;
  cursor: pointer;
  font-size: 0.74rem;
}
.topic-row:hover { border-color: var(--hover-bd); }
.topic-row.is-current { border-color: var(--primary); box-shadow: inset 0 0 0 1px var(--primary); }
.topic-row .tr-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 600; }
.topic-row .tr-count { color: var(--muted); font-size: 0.68rem; }
.topic-row .gbar { grid-column: 1 / -1; height: 4px; }

/* Thống kê bản 2 */
.bars-30 { grid-template-columns: repeat(30, minmax(0, 1fr)); gap: 2px; height: 110px; }
.bar-fill.alt { background: linear-gradient(180deg, #fbbf24, #f59e0b); }
.heatmap {
  display: grid;
  grid-template-rows: repeat(7, 12px);
  grid-auto-flow: column;
  grid-auto-columns: 12px;
  gap: 3px;
  overflow-x: auto;
  padding-bottom: 4px;
}
.hm { display: inline-block; width: 12px; height: 12px; border-radius: 3px; background: var(--progress-track); }
.hm.lv1 { background: #bbf7d0; }
.hm.lv2 { background: #4ade80; }
.hm.lv3 { background: #16a34a; }
.hm.lv4 { background: #166534; }
html.dark .hm.lv1 { background: #14532d; }
html.dark .hm.lv2 { background: #15803d; }
html.dark .hm.lv3 { background: #22c55e; }
html.dark .hm.lv4 { background: #86efac; }
.hm-legend { display: flex; align-items: center; gap: 3px; font-size: 0.72rem; color: var(--muted); margin-top: 6px; }
.mode-table { display: flex; flex-direction: column; gap: 4px; }
.mode-row {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) repeat(3, minmax(0, 1fr));
  gap: 8px;
  padding: 6px 8px;
  border-radius: 8px;
  background: var(--surface-2);
  font-size: 0.82rem;
}

/* Cài đặt */
.set-h { margin: 14px 0 6px; font-size: 0.8rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.03em; }
.set-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.modal { max-width: 460px; }

/* Thông báo nhỏ */
.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translate(-50%, 20px);
  max-width: min(92vw, 520px);
  padding: 10px 16px;
  border-radius: 10px;
  background: #0f172a;
  color: #f8fafc;
  font-size: 0.88rem;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 80;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
html.dark .toast { background: #e2e8f0; color: #0f172a; }

@media (max-width: 640px) {
  .fam-row { grid-template-columns: 1fr; }
  .set-row { grid-template-columns: 1fr; }
  .mode-row { grid-template-columns: 1fr 1fr; }
  .topic-map { max-height: 260px; }
}

/* ===================== Điện thoại / màn hình cảm ứng ===================== */
button.fam-w { cursor: pointer; color: inherit; font-family: inherit; }

/* Thiết bị cảm ứng: ẩn gợi ý phím tắt, nút đủ lớn để chạm */
@media (hover: none) and (pointer: coarse) {
  .kb, kbd { display: none !important; }
  .btn.small,
  .speak-btn.small,
  .chip-sm,
  .sel-sm,
  .fam-w { min-height: 36px; }
  .chip-sm, .fam-w { padding: 6px 10px; }
  .sel-sm { padding: 6px 10px; }
  .chip-on .x { padding: 4px 6px; font-size: 0.9rem; }
  .q-cell { min-height: 36px; height: 36px; }
  .topic-row { padding: 9px 10px; }
  .dict-links a { padding: 6px 0; }
}

@media (max-width: 640px) {
  /* iOS Safari tự phóng to khi ô nhập có chữ < 16px */
  input[type="text"],
  input[type="search"],
  input[type="number"],
  select,
  textarea,
  .fill-input,
  .sel,
  .num-input,
  .sel-sm,
  .wi-note textarea { font-size: 16px; }

  .toolbar-right { width: 100%; }
  .toolbar-right .sel { flex: 1 1 140px; }
  .lesson-pick { flex: 1 1 100%; }
  .lesson-pick .sel { flex: 1; max-width: none; }

  /* Thanh chế độ cuộn ngang: mờ dần ở mép phải để biết còn nút */
  .mode-bar {
    -webkit-mask-image: linear-gradient(to right, #000 85%, transparent);
    mask-image: linear-gradient(to right, #000 85%, transparent);
    padding-right: 28px;
  }

  .exam-card { padding: 16px 14px 18px; }
  .card-header { font-size: 0.72rem; }
  .vocab-card { min-height: 0; }
  .gcard-actions .btn { flex: 1 1 auto; }
  .gtools > * { flex: 1 1 100%; }
  .toast { bottom: 84px; }
}

/* Nút cài app (PWA) */
.install-btn[hidden] { display: none; }
.btn.install-btn {
  border-color: var(--pick-b);
  color: var(--primary);
  font-weight: 700;
}

/* Câu ví dụ & giọng người thật (Free Dictionary API) */
.wi-dict { display: flex; flex-direction: column; gap: 6px; }
.wi-dict:empty { display: none; }
.dict-audio { display: flex; flex-wrap: wrap; gap: 6px; }
.dict-ex { margin: 0; padding-left: 18px; display: flex; flex-direction: column; gap: 4px; font-size: 0.88rem; line-height: 1.45; }
.dict-ex .pos-tag { font-size: 0.66rem; margin-right: 2px; }
.dict-ex mark { background: var(--star-bg); color: inherit; border-radius: 3px; padding: 0 2px; font-weight: 700; }
.dict-src { margin: 0; font-size: 0.68rem; color: var(--muted); }
.dict-loading { margin: 0; font-size: 0.8rem; }

/* Điền từ vào câu */
.cloze-sentence {
  font-size: clamp(1.05rem, 3.2vw, 1.25rem);
  line-height: 1.7;
  max-width: 640px;
  font-style: italic;
}
.cloze-sentence .blank { font-style: normal; }

/* Thẻ câu hỏi nhận focus bằng script (không cần viền) */
.exam-card:focus { outline: none; }
.exam-card:focus-visible { box-shadow: 0 0 0 2px var(--pick-b); }

/* Ô chọn trong thanh công cụ được phép co lại (tránh tràn ngang trên màn hình rất hẹp) */
.toolbar-right { min-width: 0; max-width: 100%; }
.toolbar-right .sel { min-width: 0; max-width: 100%; text-overflow: ellipsis; }
.lesson-pick { min-width: 0; max-width: 100%; }
.lesson-pick .sel { min-width: 0; flex: 1 1 auto; }
@media (max-width: 640px) {
  .lesson-pick { display: flex; width: 100%; }
}

/* Hướng dẫn lần đầu */
.welcome {
  margin-bottom: 10px;
  padding: 14px 16px;
  border: 1px solid var(--pick-b);
  border-radius: var(--radius);
  background: var(--pick);
}
.welcome h2 { margin: 0 0 8px; font-size: 1.05rem; }
.welcome ol { margin: 0 0 10px; padding-left: 20px; display: flex; flex-direction: column; gap: 4px; font-size: 0.9rem; line-height: 1.5; }
.welcome .sync-actions { margin: 0; }

/* Từ đã ẩn */
.badge.st-skip {
  cursor: pointer;
  font-family: inherit;
  color: var(--muted);
  border-style: dashed;
}
.badge.st-skip:hover { color: var(--text); border-color: var(--hover-bd); }
