/* ==================================================
   AI LESSON V2 — Bài Học Cá Nhân Hóa AI
   100% CSS Variables — Dark Mode Safe
   ================================================== */

/* ── HSK Badge Colors ── */
:root {
  --bg-hsk-1: #e3f2fd;
  --text-hsk-1: #1565c0;
  --bg-hsk-2: #e8f5e9;
  --text-hsk-2: #2e7d32;
  --bg-hsk-3: #fff3e0;
  --text-hsk-3: #e65100;
  --bg-hsk-4: #fce4ec;
  --text-hsk-4: #c62828;
  --bg-hsk-5: #ede7f6;
  --text-hsk-5: #6a1b9a;
  --bg-hsk-6: #efebe9;
  --text-hsk-6: #4e342e;
  --bg-hsk-7: #e0f2f1;
  --text-hsk-7: #00695c;
  --bg-hsk-8: #f3e5f5;
  --text-hsk-8: #7b1fa2;
  --bg-hsk-9: #e8eaf6;
  --text-hsk-9: #283593;

  --lesson-text: var(--text-dark);
  --lesson-bg: var(--bg-dark);
  --lesson-card-bg: var(--bg-panel);
  --lesson-border: var(--border-color);
  --lesson-shadow: var(--shadow-card);
  --lesson-accent: var(--primary-red);
  --color-success: #4caf50;
  --color-error: #f44336;
  --color-warning: #ff9800;
}

/* Dark Mode overrides */
body.dark-mode {
  --bg-hsk-1: rgba(21, 101, 192, 0.2);
  --text-hsk-1: #64b5f6;
  --bg-hsk-2: rgba(46, 125, 50, 0.2);
  --text-hsk-2: #81c784;
  --bg-hsk-3: rgba(230, 81, 0, 0.2);
  --text-hsk-3: #ffb74d;
  --bg-hsk-4: rgba(198, 40, 40, 0.2);
  --text-hsk-4: #e57373;
  --bg-hsk-5: rgba(106, 27, 154, 0.2);
  --text-hsk-5: #ce93d8;
  --bg-hsk-6: rgba(78, 52, 46, 0.2);
  --text-hsk-6: #bcaaa4;
  --bg-hsk-7: rgba(0, 105, 92, 0.2);
  --text-hsk-7: #80cbc4;
  --bg-hsk-8: rgba(123, 31, 162, 0.2);
  --text-hsk-8: #ce93d8;
  --bg-hsk-9: rgba(40, 53, 147, 0.2);
  --text-hsk-9: #9fa8da;

  --color-success: #66bb6a;
  --color-error: #ef5350;
  --color-warning: #ffa726;
}

/* ══════════════════════════════════════
   CONTAINER
   ══════════════════════════════════════ */
.ai-lesson-container {
  background: var(--lesson-bg);
  border-radius: 16px;
  border: 1px solid var(--lesson-border);
  box-shadow: var(--lesson-shadow);
  overflow: hidden;
  animation: fadeIn 0.4s ease;
  line-height: 1.6;
  max-width: 800px;
  margin: 0 auto;
  /* V5: Cho phép chọn & copy text trong bài học */
  user-select: text;
  -webkit-user-select: text;
  cursor: text;
}

/* ══════════════════════════════════════
   HEADER
   ══════════════════════════════════════ */
.ai-lesson-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  padding: 16px 20px;
  background: var(--lesson-card-bg);
  border-bottom: 2px solid var(--lesson-border);
}
.ai-lesson-header-left {
  flex: 1; 
  min-width: 200px;
}
.ai-lesson-title {
  color: var(--lesson-accent);
  font-size: 1.2rem;
  font-weight: 700;
  margin: 0;
}
.ai-lesson-title i {
  margin-right: 8px;
}
.ai-lesson-subtitle {
  color: var(--text-light);
  font-size: 0.9rem;
  margin: 2px 0 0;
}
.ai-lesson-header-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
}
.ai-lesson-cost-badge {
  font-size: 0.75rem;
  padding: 3px 10px;
  border-radius: 20px;
  background: rgba(46, 125, 50, 0.1);
  color: var(--dict-noun);
  border: 1px solid rgba(46, 125, 50, 0.3);
  font-weight: 600;
  white-space: nowrap;
}
.ai-lesson-btn-notebook {
  background: var(--primary-gradient);
  color: #fff;
  border: none;
  padding: 7px 14px;
  border-radius: 25px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
  white-space: nowrap;
}
.ai-lesson-btn-notebook:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 15px rgba(211, 47, 47, 0.35);
}
.ai-lesson-btn-header {
  background: white;
  color: var(--primary-red, #d32f2f);
  border: 1px solid var(--primary-red, #d32f2f);
  padding: 5px 10px;
  border-radius: 4px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  transition: all 0.2s;
}
.ai-lesson-btn-header:hover {
  background: rgba(211, 47, 47, 0.05);
}
body.dark-mode .ai-lesson-btn-header {
  background: #2a2a2a;
  color: #ff5252;
  border-color: #ff5252;
}
body.dark-mode .ai-lesson-btn-header:hover {
  background: rgba(255, 82, 82, 0.1);
}

/* ══════════════════════════════════════
   SECTIONS (Chung)
   ══════════════════════════════════════ */
.ai-lesson-section {
  padding: 10px 14px;
  border-bottom: 1px solid var(--lesson-border);
}
.ai-lesson-section:last-child {
  border-bottom: none;
}
.ai-lesson-section-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--lesson-text);
  margin: 0 0 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.ai-lesson-icon {
  font-size: 1.2rem;
  display: inline-flex;
}
.ai-lesson-section-count {
  font-size: 0.78rem;
  color: var(--text-light);
  font-weight: 400;
  margin-left: auto;
}

/* ══════════════════════════════════════
   HSK BADGES
   ══════════════════════════════════════ */
.ai-lesson-hsk-badge {
  display: inline-block;
  font-size: 0.65rem;
  font-weight: 700;
  padding: 1px 7px;
  border-radius: 10px;
  letter-spacing: 0.3px;
  white-space: nowrap;
  flex-shrink: 0;
}
.ai-lesson-hsk-badge[data-hsk="1"] { background: var(--bg-hsk-1); color: var(--text-hsk-1); }
.ai-lesson-hsk-badge[data-hsk="2"] { background: var(--bg-hsk-2); color: var(--text-hsk-2); }
.ai-lesson-hsk-badge[data-hsk="3"] { background: var(--bg-hsk-3); color: var(--text-hsk-3); }
.ai-lesson-hsk-badge[data-hsk="4"] { background: var(--bg-hsk-4); color: var(--text-hsk-4); }
.ai-lesson-hsk-badge[data-hsk="5"] { background: var(--bg-hsk-5); color: var(--text-hsk-5); }
.ai-lesson-hsk-badge[data-hsk="6"] { background: var(--bg-hsk-6); color: var(--text-hsk-6); }
.ai-lesson-hsk-badge[data-hsk="7"] { background: var(--bg-hsk-7); color: var(--text-hsk-7); }
.ai-lesson-hsk-badge[data-hsk="8"] { background: var(--bg-hsk-8); color: var(--text-hsk-8); }
.ai-lesson-hsk-badge[data-hsk="9"] { background: var(--bg-hsk-9); color: var(--text-hsk-9); }

/* ══════════════════════════════════════
   SPEAKER / COPY BUTTONS
   ══════════════════════════════════════ */
.ai-lesson-btn-speak,
.ai-lesson-btn-copy {
  background: none;
  border: 1px solid var(--lesson-border);
  color: var(--text-light);
  width: 28px;
  height: 28px;
  border-radius: 50%;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.78rem;
  transition: all 0.25s ease;
  flex-shrink: 0;
}
.ai-lesson-btn-speak:hover {
  color: var(--dict-verb);
  border-color: var(--dict-verb);
  background: rgba(25, 118, 210, 0.08);
}
.ai-lesson-btn-copy:hover {
  color: var(--dict-noun);
  border-color: var(--dict-noun);
  background: rgba(46, 125, 50, 0.08);
}
.ai-lesson-btn-speak-sm,
.ai-lesson-btn-speak-xs {
  background: none;
  border: none;
  color: var(--text-light);
  cursor: pointer;
  font-size: 0.85rem;
  padding: 4px 6px;
  transition: color 0.2s, transform 0.15s;
  border-radius: 4px;
}
.ai-lesson-btn-speak-sm:hover,
.ai-lesson-btn-speak-xs:hover {
  color: var(--dict-verb);
  transform: scale(1.15);
}

/* Copy button nhỏ (V3.5 - Tiên Khí) */
.ai-lesson-btn-copy-sm {
  background: none;
  border: 1px solid var(--lesson-border);
  color: var(--text-light);
  cursor: pointer;
  font-size: 0.78rem;
  padding: 4px 8px;
  border-radius: 6px;
  transition: all 0.25s ease;
}
.ai-lesson-btn-copy-sm:hover {
  color: var(--dict-noun);
  border-color: var(--dict-noun);
  background: rgba(46, 125, 50, 0.08);
  transform: scale(1.08);
}

/* ══════════════════════════════════════
   VOCABULARY SECTION — LAYOUT NGANG V3
   ══════════════════════════════════════ */
.ai-lesson-vocab-grid {
  display: flex;
  flex-direction: column;
  gap: 0;
}
.ai-lesson-vocab-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--lesson-border);
  transition: background 0.15s;
}
.ai-lesson-vocab-card:last-child {
  border-bottom: none;
}
.ai-lesson-vocab-card:hover {
  background: rgba(0,0,0,0.02);
}
body.dark-mode .ai-lesson-vocab-card:hover {
  background: rgba(255,255,255,0.03);
}
.ai-lesson-vocab-hanzi {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--lesson-text);
  min-width: 50px;
  flex-shrink: 0;
}
.ai-lesson-vocab-pinyin {
  font-size: 0.82rem;
  color: var(--dict-verb);
  font-style: italic;
  min-width: 80px;
  flex-shrink: 0;
}
.ai-lesson-vocab-meaning {
  font-size: 0.88rem;
  color: var(--lesson-text);
  flex: 1;
  min-width: 0;
}
.ai-lesson-vocab-footer {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}
.ai-lesson-vocab-actions {
  display: flex;
  gap: 3px;
  flex-shrink: 0;
}
.ai-lesson-vocab-top {
  display: contents;
}
.ai-lesson-vocab-example {
  display: none;
}

/* ══════════════════════════════════════
   GRAMMAR SECTION
   ══════════════════════════════════════ */
.ai-lesson-grammar-card {
  background: var(--lesson-card-bg);
  border: 1px solid var(--lesson-border);
  border-left: 4px solid var(--dict-grammar);
  border-radius: 10px;
  padding: 12px 14px;
  margin-bottom: 10px;
}
.ai-lesson-grammar-card:last-child {
  margin-bottom: 0;
}
.ai-lesson-grammar-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
  flex-wrap: wrap;
}
.ai-lesson-grammar-num {
  width: 24px;
  height: 24px;
  background: var(--dict-grammar);
  color: #fff;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.78rem;
  font-weight: 700;
  flex-shrink: 0;
}
.ai-lesson-grammar-pattern {
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--lesson-text);
}
.ai-lesson-grammar-meaning {
  color: var(--text-light);
  font-size: 0.85rem;
  margin-bottom: 8px;
  line-height: 1.5;
}
.ai-lesson-grammar-example {
  background: rgba(0, 0, 0, 0.03);
  border-radius: 8px;
  padding: 8px 12px;
  margin-bottom: 6px;
}
body.dark-mode .ai-lesson-grammar-example {
  background: rgba(255, 255, 255, 0.04);
}
.ai-lesson-grammar-ex-zh {
  font-size: 0.95rem;
  color: var(--lesson-text);
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.ai-lesson-grammar-ex-sub {
  font-size: 0.82rem;
  color: var(--dict-verb);
  font-style: italic;
  margin-top: 1px;
}
/* V4: details/summary collapsible */
.ai-lesson-grammar-mistake,
.ai-lesson-grammar-tip {
  border-radius: 8px;
  padding: 0;
  font-size: 0.82rem;
  margin-bottom: 5px;
  overflow: hidden;
}
.ai-lesson-grammar-mistake {
  background: rgba(244, 67, 54, 0.06);
  border: 1px solid rgba(244, 67, 54, 0.2);
  color: var(--color-error);
}
.ai-lesson-grammar-tip {
  background: rgba(255, 152, 0, 0.06);
  border: 1px solid rgba(255, 152, 0, 0.2);
  color: var(--color-warning);
}
.ai-lesson-grammar-mistake summary,
.ai-lesson-grammar-tip summary {
  padding: 6px 10px;
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 5px;
  user-select: none;
}
.ai-lesson-grammar-mistake summary::-webkit-details-marker,
.ai-lesson-grammar-tip summary::-webkit-details-marker {
  display: none;
}
.ai-lesson-grammar-mistake summary::after,
.ai-lesson-grammar-tip summary::after {
  content: '▸';
  margin-left: auto;
  transition: transform 0.2s;
  font-size: 0.75rem;
}
.ai-lesson-grammar-mistake[open] summary::after,
.ai-lesson-grammar-tip[open] summary::after {
  transform: rotate(90deg);
}
.ai-lesson-details-body {
  padding: 4px 10px 8px;
  font-size: 0.82rem;
  line-height: 1.5;
}
.ai-lesson-grammar-mistake i,
.ai-lesson-grammar-tip i,
.ai-lesson-grammar-alt i {
  margin-right: 3px;
}
/* V4.1: Alternatives = collapsible too */
.ai-lesson-grammar-alt {
  background: rgba(25, 118, 210, 0.06);
  border: 1px solid rgba(25, 118, 210, 0.2);
  border-radius: 8px;
  padding: 0;
  font-size: 0.82rem;
  color: var(--dict-verb);
  margin-bottom: 5px;
}
.ai-lesson-grammar-alt summary {
  padding: 6px 10px;
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 5px;
  user-select: none;
}
.ai-lesson-grammar-alt summary::-webkit-details-marker { display: none; }
.ai-lesson-grammar-alt summary::after {
  content: '\25b8';
  margin-left: auto;
  transition: transform 0.2s;
  font-size: 0.75rem;
}
.ai-lesson-grammar-alt[open] summary::after { transform: rotate(90deg); }
/* V4.1: Exercise interactive styling */
.ai-lesson-grammar-ex-exercise {
  background: rgba(156, 39, 176, 0.06);
  border: 1px solid rgba(156, 39, 176, 0.2);
  border-radius: 8px;
  padding: 0;
  font-size: 0.82rem;
  color: #7b1fa2;
  margin-bottom: 5px;
}
.ai-lesson-grammar-ex-exercise summary {
  padding: 6px 10px;
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 5px;
}
.ai-lesson-grammar-ex-exercise summary::-webkit-details-marker { display: none; }
.ai-lesson-grammar-ex-exercise summary::after {
  content: '\25b8'; margin-left: auto; transition: transform 0.2s; font-size: 0.75rem;
}
.ai-lesson-grammar-ex-exercise[open] summary::after { transform: rotate(90deg); }
.ai-lesson-mini-ex-q {
  padding: 8px 10px 4px;
}
.ai-lesson-mini-ex-opts {
  padding: 0 10px 4px;
  font-size: 0.8rem;
  color: var(--text-light);
}
.ai-lesson-ex-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
  align-items: center;
  flex-wrap: wrap;
}
/* VIP BUTTON (V4.3) */
.ai-vip-btn {
  width: fit-content;
  display: flex;
  padding: 0.4em 0.8rem;
  cursor: pointer;
  gap: 0.4rem;
  font-weight: bold;
  border-radius: 30px;
  text-shadow: 2px 2px 3px rgb(136 0 136 / 50%);
  background: linear-gradient(15deg, #880088, #aa2068, #cc3f47, #de6f3d, #f09f33, #de6f3d, #cc3f47, #aa2068, #880088) no-repeat;
  background-size: 300%;
  color: #fff;
  border: none;
  background-position: left center;
  box-shadow: 0 4px 10px -2px rgba(0,0,0,.2);
  transition: background .3s ease;
  font-size: 0.8rem;
  align-items: center;
}
.ai-vip-btn:hover { background-size: 320%; background-position: right center; }
.ai-vip-btn svg { width: 16px; fill: #f09f33; transition: .3s ease; }

/* HINT BUTTON (V4.3) */
.item-hints {
  --purple: #720c8f;
  cursor: pointer;
  display: flex;
  justify-content: flex-start;
  margin-left: 10px;
}
.item-hints .hint {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
}
.item-hints .hint-dot {
  z-index: 3;
  border: 1px solid #ffe4e4;
  border-radius: 50%;
  width: 32px;
  height: 32px;
  transform: translate(-0%, -0%) scale(0.95);
  margin: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  background: var(--primary-gradient);
}
.item-hints .hint-radius {
  background-color: rgba(211, 47, 47, 0.15);
  border-radius: 50%;
  position: absolute;
  top: 50%;
  left: 50%;
  margin: -25px 0 0 -25px;
  opacity: 0;
  visibility: hidden;
  transform: scale(0);
  width: 50px;
  height: 50px;
}
.item-hints .hint:hover .hint-radius {
  opacity: 1;
  visibility: visible;
  animation: pulseHints 1.5s infinite;
}
@keyframes pulseHints {
  0% { transform: scale(0.5); opacity: 0; }
  50% { opacity: 1; }
  100% { transform: scale(1.3); opacity: 0; }
}
.item-hints .hint-content {
  width: 250px;
  position: absolute;
  z-index: 9999;
  padding: 0;
  opacity: 0;
  transition: opacity 0.5s ease, visibility 0.5s ease;
  color: #fff;
  visibility: hidden;
  pointer-events: none;
}
.item-hints .hint:hover .hint-content {
  opacity: 1;
  visibility: visible;
}
.item-hints .hint-content::before {
  width: 0px;
  top: 50%;
  right: 100%;
  content: "";
  background-color: var(--primary-red, #d32f2f);
  height: 2px;
  position: absolute;
  transition: width 0.4s;
}
.item-hints .hint:hover .hint-content::before {
  width: 15px;
}
.item-hints .hint[data-position="4"] .hint-content {
  top: 50%;
  left: 100%;
  transform: translateY(-50%);
  margin-left: 15px;
}
.item-hints .hint-content p {
  background: rgba(0,0,0,0.8);
  padding: 10px;
  border-radius: 8px;
  margin: 0;
  font-size: 0.85rem;
  line-height: 1.4;
  box-shadow: 0 4px 10px rgba(0,0,0,0.3);
}
.ai-lesson-mini-ex-result {
  padding: 0 10px 6px;
}
.ai-lesson-mini-ex-actions {
  display: flex;
  gap: 6px;
  padding: 4px 10px 8px;
  align-items: center;
  flex-wrap: wrap;
}
.ai-lesson-mini-ex-result {
  padding: 0 10px 6px;
}
.ai-lesson-fill-input {
  border: 1px solid #ccc;
  border-radius: 6px;
  padding: 5px 10px;
  font-size: 0.85rem;
  max-width: 140px;
  outline: none;
  transition: border-color 0.2s;
}
.ai-lesson-fill-input:focus {
  border-color: var(--lesson-accent);
}
.ai-lesson-btn-check {
  background: var(--primary-gradient);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 5px 12px;
  font-size: 0.82rem;
  cursor: pointer;
  transition: all 0.2s;
}
.ai-lesson-btn-check:hover {
  transform: scale(1.05);
  box-shadow: 0 2px 8px rgba(211,47,47,0.3);
}
.ai-lesson-correct { color: #2e7d32; font-weight: 600; }
.ai-lesson-wrong { color: #c62828; font-weight: 600; }

/* ══════════════════════════════════════
   PHRASES SECTION
   ══════════════════════════════════════ */
.ai-lesson-phrases-list {
  display: flex;
  flex-direction: column;
  gap: 0;
}
.ai-lesson-phrase-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  border-bottom: 1px solid var(--lesson-border);
  gap: 8px;
}
.ai-lesson-phrase-item:last-child {
  border-bottom: none;
}
.ai-lesson-phrase-left {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 1;
  min-width: 0;
}
.ai-lesson-phrase-zh {
  font-weight: 600;
  color: var(--lesson-text);
  font-size: 0.95rem;
  white-space: nowrap;
}
.ai-lesson-phrase-py {
  color: var(--dict-verb);
  font-size: 0.8rem;
  font-style: italic;
  white-space: nowrap;
}
.ai-lesson-phrase-right {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}
.ai-lesson-phrase-right .ai-lesson-hsk-badge {
  flex-shrink: 0;
  white-space: nowrap;
}
.ai-lesson-phrase-meaning {
  color: var(--text-light);
  font-size: 0.85rem;
}

/* ══════════════════════════════════════
   DIALOGUE SECTION — COMPACT V3
   ══════════════════════════════════════ */
/* Toggle Pinyin Button */
.ai-lesson-toggle-pinyin {
  background: var(--lesson-card-bg);
  border: 1px solid var(--lesson-border);
  color: var(--text-light);
  padding: 4px 12px;
  border-radius: 16px;
  font-size: 0.75rem;
  cursor: pointer;
  transition: all 0.2s;
  margin-left: auto;
}
.ai-lesson-toggle-pinyin:hover {
  color: var(--dict-verb);
  border-color: var(--dict-verb);
}
.ai-lesson-toggle-pinyin.active {
  background: var(--dict-verb);
  color: #fff;
  border-color: var(--dict-verb);
}

/* Hide pinyin when container has hide-pinyin class */
.hide-pinyin .ai-lesson-dialogue-py,
.hide-pinyin .ai-lesson-dialogue-py-wrapper,
.hide-pinyin .ai-pinyin-toggleable {
  opacity: 0 !important;
  pointer-events: none;
  visibility: hidden;
}

/* Hover over the sentence to reveal pinyin when hidden */
.hide-pinyin .ai-lesson-dialogue-bubble:hover .ai-lesson-dialogue-py-wrapper,
.hide-pinyin .ai-lesson-dialogue-bubble:hover .ai-pinyin-toggleable,
.hide-pinyin .ai-lesson-fill-item:hover .ai-pinyin-toggleable,
.hide-pinyin .ai-lesson-reorder-item:hover .ai-pinyin-toggleable {
  opacity: 1 !important;
  visibility: visible;
  transition: opacity 0.2s ease;
}

/* Character intro bar */
.ai-lesson-dialogue-intro {
  display: flex;
  gap: 16px;
  margin-bottom: 10px;
  padding: 8px 12px;
  background: var(--lesson-card-bg);
  border: 1px solid var(--lesson-border);
  border-radius: 10px;
  flex-wrap: wrap;
}
.ai-dlg-char-intro {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 0.85rem;
  color: var(--lesson-text);
}
.ai-dlg-char-avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  object-fit: cover;
  vertical-align: middle;
}
.ai-lesson-dialogue-box {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.ai-lesson-dialogue-line {
  display: flex;
  align-items: flex-start;
  gap: 8px;
}
.ai-lesson-dialogue-line.ai-dlg-right {
  flex-direction: row-reverse;
}
.ai-lesson-dialogue-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  overflow: hidden;
}
.ai-dlg-avatar-img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
}
.ai-dlg-avatar-male {
  background: rgba(25, 118, 210, 0.12);
  border: 1.5px solid var(--dict-verb);
}
.ai-dlg-avatar-female {
  background: rgba(233, 30, 99, 0.12);
  border: 1.5px solid var(--dict-default);
}
/* Character name above text */
.ai-lesson-dialogue-name {
  font-size: 0.7rem;
  font-weight: 700;
  margin-bottom: 1px;
}
.ai-dlg-left .ai-lesson-dialogue-name {
  color: var(--dict-verb);
}
.ai-dlg-right .ai-lesson-dialogue-name {
  color: var(--dict-default);
}
.ai-lesson-dialogue-bubble {
  max-width: 88%;
  padding: 8px 12px;
  border-radius: 12px;
  background: var(--lesson-card-bg);
  border: 1px solid var(--lesson-border);
}
.ai-dlg-left .ai-lesson-dialogue-bubble {
  border-bottom-left-radius: 3px;
}
.ai-dlg-right .ai-lesson-dialogue-bubble {
  border-bottom-right-radius: 3px;
}
.ai-lesson-dialogue-zh {
  font-weight: 600;
  color: var(--lesson-text);
  font-size: 0.9rem;
}
.ai-lesson-dialogue-py {
  font-size: 0.75rem;
  color: var(--dict-verb);
  font-style: italic;
}
.ai-lesson-dialogue-vi {
  font-size: 0.78rem;
  color: var(--text-light);
  margin-top: 1px;
}
/* V4.2: Ẩn Pinyin */
.ai-lesson-dialogue-box.hide-pinyin .ai-pinyin-toggleable {
  display: none !important;
}

/* ══════════════════════════════════════
   EXERCISES SECTION
   ══════════════════════════════════════ */
.ai-lesson-exercise-group {
  margin-bottom: 16px;
}
.ai-lesson-exercise-group:last-child {
  margin-bottom: 0;
}
.ai-lesson-exercise-subtitle {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--lesson-text);
  margin: 0 0 10px;
}
.ai-lesson-exercise-subtitle i {
  color: var(--lesson-accent);
  margin-right: 5px;
}

/* Fill-in-the-blank */
.ai-lesson-fill-item {
  background: var(--lesson-card-bg);
  border: 1px solid var(--lesson-border);
  border-radius: 10px;
  padding: 12px;
  margin-bottom: 8px;
}
.ai-lesson-fill-q {
  font-size: 0.85rem;
  color: var(--text-light);
  margin-bottom: 5px;
}
.ai-lesson-fill-zh {
  font-size: 0.95rem;
  color: var(--lesson-text);
  margin-bottom: 6px;
}
.ai-lesson-fill-input {
  display: inline-block;
  width: 80px;
  padding: 3px 8px;
  border: 2px solid var(--lesson-border);
  border-radius: 6px;
  font-size: 0.95rem;
  text-align: center;
  background: var(--lesson-bg);
  color: var(--lesson-text);
  transition: border-color 0.3s;
  vertical-align: middle;
}
.ai-lesson-fill-input:focus {
  outline: none;
  border-color: var(--lesson-accent);
}
.ai-lesson-fill-hint {
  font-size: 0.78rem;
  color: var(--text-light);
  font-style: italic;
}
.ai-lesson-btn-check {
  background: var(--lesson-accent);
  color: #fff;
  border: none;
  padding: 5px 14px;
  border-radius: 20px;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  margin-top: 5px;
  transition: all 0.2s;
}
.ai-lesson-btn-check:hover {
  opacity: 0.85;
  transform: scale(1.03);
}
.ai-lesson-fill-result,
.ai-lesson-reorder-result {
  margin-top: 6px;
  font-size: 0.85rem;
}
.ai-lesson-correct {
  color: var(--color-success);
  font-weight: 600;
}
.ai-lesson-correct i { margin-right: 4px; }
.ai-lesson-wrong {
  color: var(--color-error);
  font-weight: 500;
}
.ai-lesson-wrong i { margin-right: 4px; }

/* Reorder exercise */
.ai-lesson-reorder-item {
  background: var(--lesson-card-bg);
  border: 1px solid var(--lesson-border);
  border-radius: 10px;
  padding: 12px;
  margin-bottom: 8px;
}
.ai-lesson-reorder-q {
  font-size: 0.85rem;
  color: var(--text-light);
  margin-bottom: 6px;
}
.ai-lesson-reorder-words {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-bottom: 6px;
}
.ai-lesson-word-chip {
  background: var(--lesson-card-bg);
  border: 1.5px solid var(--dict-verb);
  color: var(--lesson-text);
  padding: 4px 10px;
  border-radius: 18px;
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.2s;
  font-weight: 500;
  position: relative; /* For tooltip */
}

/* --- Tooltip cho Word Chip --- */
.ai-lesson-word-chip[data-py]::after,
.ai-lesson-word-chip-selected[data-py]::after {
  content: attr(data-py);
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.85);
  color: #fff;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 0.75rem;
  white-space: nowrap;
  opacity: 0;
  visibility: hidden;
  transition: all 0.2s ease;
  pointer-events: none;
  z-index: 100;
  margin-bottom: 6px;
  font-weight: normal;
  box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.ai-lesson-word-chip[data-py]::before,
.ai-lesson-word-chip-selected[data-py]::before {
  content: '';
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 4px solid transparent;
  border-top-color: rgba(0, 0, 0, 0.85);
  opacity: 0;
  visibility: hidden;
  transition: all 0.2s ease;
  pointer-events: none;
  z-index: 100;
  margin-bottom: -2px;
}

.ai-lesson-word-chip:hover[data-py]::after,
.ai-lesson-word-chip:hover[data-py]::before,
.ai-lesson-word-chip-selected:hover[data-py]::after,
.ai-lesson-word-chip-selected:hover[data-py]::before {
  opacity: 1;
  visibility: visible;
}
/* ---------------------------------- */
.ai-lesson-word-chip:hover {
  background: rgba(25, 118, 210, 0.1);
  transform: scale(1.05);
}
.ai-lesson-word-chip.used {
  opacity: 0.35;
  pointer-events: none;
  text-decoration: line-through;
}
.ai-lesson-reorder-selected {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  min-height: 32px;
  padding: 5px 8px;
  border: 2px dashed var(--lesson-border);
  border-radius: 10px;
  margin-bottom: 6px;
  align-items: center;
}
.ai-lesson-word-chip-selected {
  background: var(--dict-verb);
  color: #fff;
  padding: 3px 9px;
  border-radius: 14px;
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  position: relative;
}
.ai-lesson-word-chip-selected:hover {
  opacity: 0.75;
}

/* Options hint for fill blank */
.ai-lesson-options-hint {
  font-size: 0.82rem;
  color: var(--text-light);
  margin-top: 4px;
}

/* ══════════════════════════════════════
   SHAKE ERROR — Phản hồi xúc giác sai
   ══════════════════════════════════════ */
.shake-error {
  animation: shakeError 0.5s cubic-bezier(0.36, 0.07, 0.19, 0.97) both;
}
@keyframes shakeError {
  10%, 90% { transform: translateX(-1px); }
  20%, 80% { transform: translateX(2px); }
  30%, 50%, 70% { transform: translateX(-4px); }
  40%, 60% { transform: translateX(4px); }
}

/* PULSE CORRECT — Phản hồi đúng nhẹ */
.pulse-correct {
  animation: pulseCorrect 0.4s ease-out;
}
@keyframes pulseCorrect {
  0% { transform: scale(1); }
  50% { transform: scale(1.02); box-shadow: 0 0 0 4px rgba(76, 175, 80, 0.2); }
  100% { transform: scale(1); box-shadow: none; }
}

/* ══════════════════════════════════════
   GRAND FINALE — Nút hoàn thành bài học
   ══════════════════════════════════════ */
.ai-lesson-complete-zone {
  text-align: center;
  padding: 20px 16px;
  margin-top: 16px;
  border-top: 2px dashed var(--lesson-accent, #d32f2f);
  animation: fadeInUp 0.5s ease-out;
}
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}
.btn-complete-ai-lesson {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 14px 32px;
  font-size: 1.05rem;
  font-weight: 700;
  color: #fff;
  background: linear-gradient(135deg, #43a047, #2e7d32);
  border: none;
  border-radius: 30px;
  cursor: pointer;
  box-shadow: 0 6px 20px rgba(46, 125, 50, 0.35);
  transition: all 0.3s ease;
  letter-spacing: 0.3px;
}
.btn-complete-ai-lesson:hover {
  transform: translateY(-3px) scale(1.03);
  box-shadow: 0 10px 30px rgba(46, 125, 50, 0.45);
}
.btn-complete-ai-lesson:active {
  transform: scale(0.97);
}
.ai-lesson-complete-msg {
  margin-top: 10px;
  font-size: 0.85rem;
  color: var(--text-light, #888);
  font-style: italic;
}


/* ══════════════════════════════════════
   RESPONSIVE
   ══════════════════════════════════════ */
@media (max-width: 768px) {
  .ai-lesson-header {
    padding: 12px 14px;
    flex-direction: column;
    align-items: flex-start;
  }
  .ai-lesson-section {
    padding: 12px 14px;
  }
  /* Vocab: rớt dòng gọn trên mobile */
  .ai-lesson-vocab-card {
    flex-wrap: wrap;
    gap: 4px 8px;
    padding: 8px 12px;
  }
  .ai-lesson-vocab-hanzi {
    font-size: 1.1rem;
    min-width: auto;
  }
  .ai-lesson-vocab-pinyin {
    min-width: auto;
  }
  .ai-lesson-vocab-meaning {
    width: 100%;
    font-size: 0.82rem;
  }
  .ai-lesson-title {
    font-size: 1rem;
  }
  .ai-lesson-dialogue-bubble {
    max-width: 85%;
    padding: 6px 10px;
  }
  .ai-lesson-phrase-item {
    flex-direction: column;
    align-items: flex-start;
    gap: 3px;
  }
}

/* ══════════════════════════════════════════════════════
   XIANXIA LESSON CONTENT — Bài Học Tĩnh (Cổ Trang)
   Dùng cho HTML thuần từ popular_lessons.json
   ══════════════════════════════════════════════════════ */
.xianxia-lesson-content {
  padding: 18px 20px;
  line-height: 1.7;
  color: var(--lesson-text, #333);
  font-size: 0.95rem;
}

/* ── Tables ── */
.xianxia-lesson-content table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 2px 12px rgba(139, 0, 0, 0.08);
  margin: 14px 0;
  border: 1px solid rgba(139, 0, 0, 0.12);
}
.xianxia-lesson-content th {
  background: var(--primary-red, #8b0000);
  color: #fff;
  padding: 12px 16px;
  font-weight: 700;
  font-size: 0.88rem;
  text-align: left;
  letter-spacing: 0.3px;
  border-bottom: 2px solid rgba(139, 0, 0, 0.3);
}
.xianxia-lesson-content th:not(:last-child) {
  border-right: 1px solid rgba(255, 255, 255, 0.15);
}
.xianxia-lesson-content td {
  padding: 10px 16px;
  border-bottom: 1px solid rgba(139, 0, 0, 0.08);
  font-size: 0.9rem;
  color: var(--lesson-text, #333);
  transition: background 0.15s;
}
.xianxia-lesson-content td:not(:last-child) {
  border-right: 1px solid rgba(139, 0, 0, 0.06);
}
.xianxia-lesson-content tr:last-child td {
  border-bottom: none;
}
.xianxia-lesson-content tr:hover td {
  background: rgba(139, 0, 0, 0.03);
}
.xianxia-lesson-content tr:nth-child(even) td {
  background: rgba(139, 0, 0, 0.02);
}

/* ── Headings cổ trang ── */
.xianxia-lesson-content h2 {
  font-size: 1.15rem;
  font-weight: 800;
  color: var(--primary-red, #8b0000);
  margin: 22px 0 10px;
  padding-bottom: 8px;
  border-bottom: 2px dashed rgba(139, 0, 0, 0.25);
  display: flex;
  align-items: center;
  gap: 8px;
}
.xianxia-lesson-content h2::before {
  content: '◈';
  font-size: 0.9rem;
  opacity: 0.6;
}
.xianxia-lesson-content h3 {
  font-size: 1.02rem;
  font-weight: 700;
  color: var(--lesson-text, #444);
  margin: 16px 0 8px;
  padding-bottom: 6px;
  border-bottom: 1.5px dashed rgba(139, 0, 0, 0.15);
}
.xianxia-lesson-content h3::before {
  content: '◆ ';
  color: var(--primary-red, #8b0000);
  font-size: 0.7rem;
}

/* ── Inline elements ── */
.xianxia-lesson-content p {
  margin: 8px 0;
}
.xianxia-lesson-content strong, 
.xianxia-lesson-content b {
  color: var(--primary-red, #8b0000);
  font-weight: 700;
}
.xianxia-lesson-content em,
.xianxia-lesson-content i:not(.fas):not(.far):not(.fab) {
  color: var(--dict-verb, #1976d2);
  font-style: italic;
}
.xianxia-lesson-content ul,
.xianxia-lesson-content ol {
  padding-left: 20px;
  margin: 8px 0;
}
.xianxia-lesson-content li {
  margin: 4px 0;
}

/* ── TTS Buttons ── */
.xianxia-tts-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border: none;
  background: rgba(139, 0, 0, 0.08);
  color: var(--primary-red, #8b0000);
  border-radius: 50%;
  cursor: pointer;
  font-size: 0.75rem;
  margin-left: 6px;
  vertical-align: middle;
  transition: all 0.2s ease;
  flex-shrink: 0;
}
.xianxia-tts-btn:hover {
  background: var(--primary-red, #8b0000);
  color: #fff;
  transform: scale(1.12);
  box-shadow: 0 2px 8px rgba(139, 0, 0, 0.25);
}

/* ── DARK MODE ── */
body.dark-mode .xianxia-lesson-content {
  color: var(--lesson-text, #e0e0e0);
}
body.dark-mode .xianxia-lesson-content table {
  border-color: rgba(255, 82, 82, 0.15);
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.3);
}
body.dark-mode .xianxia-lesson-content th {
  background: linear-gradient(135deg, #5c1010, #7b1a1a);
  border-bottom-color: rgba(255, 82, 82, 0.2);
}
body.dark-mode .xianxia-lesson-content th:not(:last-child) {
  border-right-color: rgba(255, 255, 255, 0.08);
}
body.dark-mode .xianxia-lesson-content td {
  color: var(--lesson-text, #ddd);
  border-bottom-color: rgba(255, 82, 82, 0.06);
}
body.dark-mode .xianxia-lesson-content td:not(:last-child) {
  border-right-color: rgba(255, 82, 82, 0.05);
}
body.dark-mode .xianxia-lesson-content tr:hover td {
  background: rgba(255, 82, 82, 0.05);
}
body.dark-mode .xianxia-lesson-content tr:nth-child(even) td {
  background: rgba(255, 255, 255, 0.02);
}
body.dark-mode .xianxia-lesson-content h2 {
  color: #ff5252;
  border-bottom-color: rgba(255, 82, 82, 0.2);
}
body.dark-mode .xianxia-lesson-content h3 {
  color: #e0e0e0;
  border-bottom-color: rgba(255, 82, 82, 0.12);
}
body.dark-mode .xianxia-lesson-content h3::before {
  color: #ff5252;
}
body.dark-mode .xianxia-lesson-content strong,
body.dark-mode .xianxia-lesson-content b {
  color: #ff5252;
}
body.dark-mode .xianxia-lesson-content em,
body.dark-mode .xianxia-lesson-content i:not(.fas):not(.far):not(.fab) {
  color: #64b5f6;
}
body.dark-mode .xianxia-tts-btn {
  background: rgba(255, 82, 82, 0.12);
  color: #ff5252;
}
body.dark-mode .xianxia-tts-btn:hover {
  background: #ff5252;
  color: #fff;
}

/* ── Responsive ── */
@media (max-width: 768px) {
  .xianxia-lesson-content {
    padding: 14px 12px;
    font-size: 0.9rem;
  }
  .xianxia-lesson-content th,
  .xianxia-lesson-content td {
    padding: 8px 10px;
    font-size: 0.82rem;
  }
  .xianxia-lesson-content h2 { font-size: 1.05rem; }
  .xianxia-lesson-content h3 { font-size: 0.95rem; }
}

/* ══════════════════════════════════════
   TTS SPEAKING HIGHLIGHT — V6
   ══════════════════════════════════════ */

/* Highlight dòng hội thoại đang được đọc TTS */
.ai-lesson-dialogue-line.speaking {
  background: rgba(211, 47, 47, 0.08);
  border-left: 3px solid var(--primary-red, #d32f2f);
  border-radius: 8px;
  transition: background 0.3s ease, border-left 0.3s ease;
}
body.dark-mode .ai-lesson-dialogue-line.speaking {
  background: rgba(255, 82, 82, 0.1);
}

/* Nút Auto-play — trạng thái đang phát */
#btn-auto-dialogue.is-playing {
  background: var(--primary-red, #d32f2f) !important;
  color: #fff !important;
  border-color: var(--primary-red, #d32f2f) !important;
}

/* Toggle Pinyin wrapper — ẩn khi container có class hide-pinyin */
.hide-pinyin .ai-pinyin-toggleable {
  display: none !important;
}

/* ═══════════════════════════════════════════════════════
   PINYIN TOGGLE — BÀI TẬP
═══════════════════════════════════════════════════════ */
.ai-lesson-exercises-section.hide-pinyin .ai-pinyin-toggleable {
  display: none !important;
}
.ex-pinyin {
  color: var(--color-muted, #888);
  font-size: 0.82em;
  font-style: italic;
  margin-top: 3px;
  padding-left: 2px;
  letter-spacing: 0.03em;
}
.ai-lesson-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}
/* V5: Buttons trong lesson giữ cursor pointer */
.ai-lesson-container button {
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
}

/* ═══════════════════════════════════════════════════════
   LESSON HISTORY PANEL
═══════════════════════════════════════════════════════ */
.btn-lesson-history {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  background: var(--color-surface-2, #2a2a2a);
  border: 1px solid var(--color-border, #444);
  border-radius: 8px;
  color: var(--color-text, #eee);
  cursor: pointer;
  font-size: 0.9em;
  transition: all 0.2s;
}
body:not(.dark-mode) .btn-lesson-history {
  background: #f5f5f5;
  border-color: #ddd;
  color: #333;
}
.btn-lesson-history:hover {
  border-color: var(--primary-red, #b41e1e);
  color: var(--primary-red, #b41e1e);
}
.lesson-history-badge {
  display: none;
  background: var(--primary-red, #b41e1e);
  color: #fff;
  border-radius: 50%;
  width: 18px;
  height: 18px;
  font-size: 0.7em;
  font-weight: bold;
  text-align: center;
  line-height: 18px;
}
.lesson-history-panel {
  display: none;
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  right: 0;
  min-width: 340px;
  max-width: 560px;
  background: var(--color-surface, #1e1e1e);
  border: 1px solid var(--color-border, #444);
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.4);
  z-index: 200;
  padding: 0;
  overflow: hidden;
}
body:not(.dark-mode) .lesson-history-panel {
  background: #fff;
  border-color: #ddd;
  box-shadow: 0 8px 32px rgba(0,0,0,0.12);
}
.lesson-history-panel.active { display: block; }
.lesson-history-header {
  padding: 16px 20px 12px;
  border-bottom: 1px solid var(--color-border, #333);
  position: relative;
}
.lesson-history-header h4 { margin: 0 0 6px; font-size: 1em; }
.lesson-history-hint {
  display: block;
  color: var(--color-muted, #888);
  font-size: 0.82em;
  line-height: 1.5;
}
.lesson-history-close {
  position: absolute;
  top: 12px; right: 14px;
  background: none; border: none;
  color: var(--color-muted, #888);
  font-size: 1.1em;
  cursor: pointer;
  line-height: 1;
}
.lesson-history-card {
  display: flex;
  align-items: stretch;
  border-bottom: 1px solid var(--color-border, #2a2a2a);
  transition: background 0.15s;
}
body:not(.dark-mode) .lesson-history-card {
  border-bottom-color: #eee;
}
.lesson-history-card:hover { background: var(--color-surface-2, #252525); }
body:not(.dark-mode) .lesson-history-card:hover { background: #f5f5f5; }
.lesson-history-card-body {
  flex: 1;
  padding: 12px 16px;
  cursor: pointer;
}
.lesson-history-topic {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  font-size: 0.95em;
  margin-bottom: 4px;
}
.lesson-history-meta {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  font-size: 0.78em;
  color: var(--color-muted, #888);
}
.lesson-history-delete {
  padding: 0 16px;
  background: none;
  border: none;
  border-left: 1px solid var(--color-border, #2a2a2a);
  cursor: pointer;
  font-size: 1em;
  opacity: 0.4;
  transition: opacity 0.2s, color 0.2s;
}
.lesson-history-delete:hover { opacity: 1; color: #e74c3c; }
.lesson-history-empty {
  text-align: center;
  padding: 32px 20px;
  color: var(--color-muted, #888);
}
.lesson-history-empty p { margin: 12px 0 0; font-size: 0.9em; line-height: 1.6; }

/* ═══════════════════════════════════════════════════════
   BUG REPORT BUTTON ⚠️
═══════════════════════════════════════════════════════ */
.bug-report-btn {
  --primary: #ffb200;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  background: linear-gradient(to bottom, #3a3d44 0%, #212329 100%);
  border: 1px solid #444;
  box-shadow:
    inset 0 2px 2px -1px rgba(255,255,255,0.2),
    inset 0 -5px 5px -2px rgba(0,0,0,0.8),
    0 4px 10px -2px rgba(0,0,0,0.5);
  border-radius: 4px;
  cursor: pointer;
  text-decoration: none;
  flex-shrink: 0;
  transition: transform 0.1s;
  position: relative;
}
.bug-report-btn:hover {
  animation: bug-electric 0.25s linear infinite;
}
.bug-warning-symbol {
  width: 0; height: 0;
  border-left: 6px solid transparent;
  border-right: 6px solid transparent;
  border-bottom: 10px solid var(--primary);
  position: relative;
}
.bug-warning-symbol::after {
  content: "!";
  position: absolute;
  color: #111;
  font-size: 7px;
  font-weight: bold;
  font-family: sans-serif;
  left: 50%;
  top: 3px;
  transform: translateX(-50%);
}
.bug-report-btn:hover .bug-warning-symbol {
  animation: bug-pulse 1s ease-in-out infinite;
}
/* Tooltip */
.bug-report-btn::before {
  content: "Báo lỗi nội dung này";
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%) translateY(4px);
  opacity: 0;
  pointer-events: none;
  background: var(--primary);
  color: #111;
  padding: 4px 10px;
  border-radius: 4px;
  font-family: sans-serif;
  font-size: 11px;
  font-weight: bold;
  white-space: nowrap;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
  transition: transform 0.2s cubic-bezier(0.2,1.5,0.5,1), opacity 0.2s;
  z-index: 100;
}
.bug-report-btn::after {
  content: "";
  position: absolute;
  bottom: 100%;
  left: 50%;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-top: 5px solid var(--primary);
  transform: translateX(-50%) translateY(4px);
  opacity: 0;
  pointer-events: none;
  transition: transform 0.2s cubic-bezier(0.2,1.5,0.5,1), opacity 0.2s;
}
.bug-report-btn:hover::before,
.bug-report-btn:hover::after {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}
@keyframes bug-electric {
  0%   { transform: translate(0,0); }
  20%  { transform: translate(-1px,1px); }
  40%  { transform: translate(-1px,-1px); }
  60%  { transform: translate(1px,1px); }
  80%  { transform: translate(1px,-1px); }
  100% { transform: translate(0,0); }
}
@keyframes bug-pulse {
  0%,100% { filter: drop-shadow(0 0 3px #ffb200); }
  50%      { transform: scale(1.15); filter: drop-shadow(0 0 8px #ffb200); }
}

/* Bug report positioning inside dialogue lines */
.ai-lesson-dialogue-line .bug-report-btn {
  position: absolute;
  bottom: 4px;
  right: 4px;
  opacity: 0;
  transition: opacity 0.2s;
}
.ai-lesson-dialogue-line:hover .bug-report-btn {
  opacity: 1;
}
.ai-lesson-dialogue-line {
  position: relative;
}

/* Bug report positioning inside exercise items */
.ai-lesson-fill-item .bug-report-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  opacity: 0;
  transition: opacity 0.2s;
}
.ai-lesson-fill-item:hover .bug-report-btn {
  opacity: 1;
}
.ai-lesson-fill-item {
  position: relative;
}


/* ================== CUSTOM PINYIN HOVER WRAP ================== */
.ai-pinyin-wrap {
  position: relative;
}
.ai-pinyin-wrap[data-pinyin]::after {
  content: attr(data-pinyin);
  position: absolute;
  bottom: 95%;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.85);
  color: #fff;
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 0.82rem;
  font-style: italic;
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s, bottom 0.2s;
  white-space: nowrap;
  z-index: 100;
  border: 1px solid rgba(255,255,255,0.1);
  box-shadow: 0 4px 10px rgba(0,0,0,0.3);
}

/* Hiển thị ra khi Hover TRỰC TIẾP vào */
.ai-pinyin-wrap[data-pinyin]:hover::after {
  opacity: 1 !important;
  visibility: visible !important;
  bottom: 110%;
}

/* ═══════════════════════════════════════════════════════
   V10: WORD-GROUP HOVER PINYIN — Bài tập Điền từ
   Chữ Hán được gom nhóm theo từ, hover hiện pinyin cả từ
═══════════════════════════════════════════════════════ */
.fill-char-hover {
  display: inline;
  cursor: help;
  transition: color 0.15s ease;
  font-size: inherit;
}
.fill-char-hover:hover {
  color: var(--primary-red, #d32f2f);
}
/* Nâng tooltip position lên chút cho inline text */
.fill-char-hover[data-pinyin]::after {
  white-space: nowrap;
  font-size: 0.8rem;
  bottom: 100%;
  margin-bottom: 4px;
}

/* ── Word Group (multi-char word like 会议, 学生) ── */
.fill-word-group {
  display: inline;
  cursor: help;
  transition: all 0.15s ease;
  font-size: inherit;
  position: relative;
  border-bottom: 1.5px dotted transparent;
}
.fill-word-group:hover {
  color: var(--primary-red, #d32f2f);
  border-bottom-color: var(--primary-red, #d32f2f);
}
.fill-word-group[data-pinyin]::after {
  white-space: nowrap;
  font-size: 0.82rem;
  bottom: 100%;
  margin-bottom: 6px;
}
.fill-char-inner {
  display: inline;
  font-size: inherit;
}

/* ── Fill-blank speaker button touch target ── */
.ai-lesson-fill-zh .ai-lesson-btn-speak-xs {
  min-width: 32px;
  min-height: 32px;
}

/* Touch device: hiện pinyin khi tap & hold (cả per-char và word-group) */
@media (hover: none) {
  .fill-char-hover:active[data-pinyin]::after,
  .fill-word-group:active[data-pinyin]::after {
    opacity: 1 !important;
    visibility: visible !important;
    bottom: 110%;
  }
}
