/* ==========================================================================
   GIAO DIỆN: THẺ TỪ VỰNG BAY TRÊN MẶT BÀN XANH MỰC
   - Nền xanh mực: #1f3a93 (có gradient nhẹ + hình khối mờ trôi chậm)
   - Thẻ giấy: #fffdf6 bo góc 20px, đổ bóng mềm
   - Điểm nhấn vàng: #ffd23f | Đúng: #1a9b5c | Sai: #d64045
   - Tự động hỗ trợ chế độ tối theo cài đặt máy (prefers-color-scheme: dark)
   - Tất cả hoạt ảnh đều gom ở PHẦN CUỐI FILE để thầy/cô dễ chỉnh tốc độ.
   ========================================================================== */

:root {
  --desk-bg: #1f3a93;
  --desk-bg-light: #2b4ec0;
  --desk-bg-deep: #15296e;
  --card-bg: #fffdf6;
  --card-surface: #f7f3e6;
  --card-border: #e5dec9;
  --text-main: #1d263b;
  --text-muted: #55607a;
  --accent-yellow: #ffd23f;
  --accent-yellow-hover: #f5c324;
  --accent-yellow-border: #d9ac16;
  --accent-yellow-text: #1b2234;
  --ink-primary: #1f3a93;
  --ink-primary-hover: #182e78;
  --ink-primary-text: #ffffff;
  --correct: #1a9b5c;
  --correct-bg: #e7f8ef;
  --correct-border: #1a9b5c;
  --wrong: #d64045;
  --wrong-bg: #fdecec;
  --wrong-border: #d64045;
  --streak-bg: #fff1cc;
  --streak-border: #f59e0b;
  --streak-text: #b45309;
  --star-empty: #dfd7be;
  --focus-ring: #ffd23f;
  --shadow-card: 0 20px 44px rgba(10, 20, 58, 0.34), 0 4px 12px rgba(10, 20, 58, 0.16);
  --shadow-btn: 0 3px 0 rgba(18, 32, 74, 0.16);
  --radius-card: 20px;
  --radius-md: 14px;
  --radius-pill: 12px;
  --font-heading: "Baloo 2", "Segoe UI", system-ui, -apple-system, sans-serif;
  --font-body: "Be Vietnam Pro", "Segoe UI", system-ui, -apple-system, sans-serif;
}

/* Chế độ tối tự động theo cài đặt máy */
@media (prefers-color-scheme: dark) {
  :root {
    --desk-bg: #122154;
    --desk-bg-light: #1c347d;
    --desk-bg-deep: #0a1436;
    --card-bg: #1a2338;
    --card-surface: #232e47;
    --card-border: #334162;
    --text-main: #f3f6fc;
    --text-muted: #b4c0d9;
    --accent-yellow: #ffd23f;
    --accent-yellow-hover: #ffdc66;
    --accent-yellow-border: #e5b822;
    --accent-yellow-text: #141a2b;
    --ink-primary: #3b63db;
    --ink-primary-hover: #4d73e6;
    --ink-primary-text: #ffffff;
    --correct: #25b870;
    --correct-bg: rgba(37, 184, 112, 0.18);
    --correct-border: #25b870;
    --wrong: #ef5b60;
    --wrong-bg: rgba(239, 91, 96, 0.18);
    --wrong-border: #ef5b60;
    --streak-bg: rgba(255, 210, 63, 0.18);
    --streak-border: #ffd23f;
    --streak-text: #ffd23f;
    --star-empty: #37466b;
    --focus-ring: #ffd23f;
    --shadow-card: 0 22px 48px rgba(0, 0, 0, 0.52);
    --shadow-btn: 0 3px 0 rgba(0, 0, 0, 0.28);
  }
}

/* Đặt lại cơ bản */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.55;
  color: var(--text-main);
  background: linear-gradient(155deg, var(--desk-bg-light) 0%, var(--desk-bg) 48%, var(--desk-bg-deep) 100%);
  background-attachment: fixed;
  overflow-x: hidden;
}

/* Viền focus rõ ràng khi dùng bàn phím */
:focus-visible {
  outline: 3px solid var(--focus-ring);
  outline-offset: 3px;
}

.hidden {
  display: none !important;
}

/* ==========================================================================
   LỚP NỀN HÌNH KHỐI MỜ TRÔI CHẬM & CANVAS PHÁO GIẤY
   ========================================================================== */
.bg-float-layer {
  position: fixed;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  z-index: 0;
}

.float-shape {
  position: absolute;
  user-select: none;
  color: rgba(255, 253, 246, 0.08);
  font-family: var(--font-heading);
  font-weight: 800;
  will-change: transform, opacity;
}

.float-letter {
  font-size: clamp(3.6rem, 9vw, 6.2rem);
  line-height: 1;
}

.float-star {
  font-size: clamp(2rem, 5vw, 3.2rem);
  color: rgba(255, 210, 63, 0.14);
}

.float-bubble {
  border-radius: 50%;
  background: rgba(255, 253, 246, 0.06);
  border: 2px solid rgba(255, 253, 246, 0.09);
}

.shape-1 { top: 8%; left: 6%; }
.shape-2 { top: 58%; right: 5%; }
.shape-3 { bottom: 10%; left: 10%; }
.shape-4 { top: 18%; right: 14%; }
.shape-5 { bottom: 26%; right: 18%; }
.shape-6 { width: 84px; height: 84px; top: 34%; left: 3%; }
.shape-7 { width: 54px; height: 54px; top: 12%; left: 46%; }
.shape-8 { width: 110px; height: 110px; bottom: 8%; right: 32%; }

.confetti-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 999;
}

/* ==========================================================================
   KHUNG CHÍNH TRÊN MẶT BÀN
   ========================================================================== */
.desk-wrapper {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 780px;
  margin: 0 auto;
  padding: 20px 16px 32px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Tiêu đề ứng dụng & nút âm thanh */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: #ffffff;
  padding: 4px 2px 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.brand-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 50px;
  height: 50px;
  border-radius: 14px;
  background: var(--accent-yellow);
  color: var(--accent-yellow-text);
  font-family: var(--font-heading);
  font-size: 1.25rem;
  font-weight: 800;
  letter-spacing: 0.02em;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.22);
  flex-shrink: 0;
}

.brand-title {
  margin: 0;
  font-family: var(--font-heading);
  font-size: clamp(1.38rem, 4vw, 1.88rem);
  font-weight: 800;
  line-height: 1.15;
  color: #ffffff;
}

.brand-subtitle {
  margin: 2px 0 0;
  font-size: 0.9rem;
  color: rgba(255, 255, 255, 0.85);
}

/* Nút bật/tắt âm thanh hiệu ứng */
.sound-toggle-btn {
  min-height: 44px;
  padding: 8px 14px;
  border-radius: 999px;
  border: 2px solid rgba(255, 253, 246, 0.34);
  background: rgba(255, 253, 246, 0.14);
  color: #ffffff;
  font-family: var(--font-body);
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.sound-toggle-btn[aria-pressed="false"] {
  opacity: 0.72;
  background: rgba(0, 0, 0, 0.2);
}

@media (max-width: 480px) {
  .sound-toggle-label {
    display: none;
  }
  .sound-toggle-btn {
    min-width: 44px;
    padding: 8px 12px;
    justify-content: center;
  }
}

/* Thanh thông báo trạng thái dữ liệu */
.status-banner {
  padding: 12px 16px;
  border-radius: var(--radius-md);
  font-size: 0.94rem;
  line-height: 1.45;
  font-weight: 500;
}

.status-banner.is-info {
  background: rgba(255, 253, 246, 0.14);
  color: #fffdf6;
  border: 1px solid rgba(255, 253, 246, 0.28);
}

.status-banner.is-error {
  background: #fff2f2;
  color: #8f1d22;
  border: 2px solid var(--wrong);
}

@media (prefers-color-scheme: dark) {
  .status-banner.is-error {
    background: #3a1a1d;
    color: #ffd5d6;
  }
}

/* Thẻ giấy chính bo góc 20px, đổ bóng mềm */
.paper-card {
  position: relative;
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-card);
  padding: clamp(20px, 4vw, 32px);
  box-shadow: var(--shadow-card);
  overflow: hidden;
}

.screen-stage {
  position: relative;
}

.screen {
  width: 100%;
  will-change: transform, opacity;
}

/* Màn hình đang tải */
.screen-loading {
  text-align: center;
  padding: 48px 16px;
}

.spinner {
  width: 42px;
  height: 42px;
  margin: 0 auto 14px;
  border: 4px solid var(--card-border);
  border-top-color: var(--ink-primary);
  border-radius: 50%;
}

.loading-text {
  margin: 0;
  color: var(--text-muted);
  font-weight: 500;
}

/* ==========================================================================
   MÀN 1: CHỌN BÀI
   ========================================================================== */
.screen-head {
  margin-bottom: 22px;
}

.section-heading {
  margin: 0;
  font-family: var(--font-heading);
  font-size: clamp(1.4rem, 3.5vw, 1.75rem);
  font-weight: 800;
  color: var(--text-main);
  line-height: 1.2;
}

.section-hint {
  margin: 4px 0 0;
  color: var(--text-muted);
  font-size: 0.95rem;
}

.form-group {
  margin-bottom: 22px;
}

.field-label {
  display: block;
  margin-bottom: 10px;
  font-weight: 700;
  font-size: 1rem;
  color: var(--text-main);
}

.label-optional {
  font-weight: 400;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.field-label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

.field-label-row .field-label {
  margin-bottom: 0;
}

.text-input {
  width: 100%;
  min-height: 48px;
  padding: 11px 16px;
  font-family: var(--font-body);
  font-size: 1rem;
  color: var(--text-main);
  background: var(--card-surface);
  border: 2px solid var(--card-border);
  border-radius: var(--radius-pill);
}

.text-input::placeholder {
  color: var(--text-muted);
  opacity: 0.85;
}

.text-input:focus {
  border-color: var(--ink-primary);
  background: var(--card-bg);
}

/* Nút dạng thẻ chọn (Lớp, Kiểu câu hỏi, Số câu) */
.choice-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.pill-btn,
.unit-btn {
  min-height: 46px;
  padding: 10px 16px;
  font-family: var(--font-body);
  font-size: 0.96rem;
  font-weight: 600;
  color: var(--text-main);
  background: var(--card-surface);
  border: 2px solid var(--card-border);
  border-radius: var(--radius-pill);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  text-align: center;
  will-change: transform, opacity;
}

.pill-btn.is-selected,
.unit-btn.is-selected {
  background: var(--accent-yellow);
  border-color: var(--accent-yellow-border);
  color: var(--accent-yellow-text);
  box-shadow: var(--shadow-btn);
}

/* Lưới chọn nhiều Unit */
.unit-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(138px, 1fr));
  gap: 10px;
}

.unit-btn {
  width: 100%;
  justify-content: space-between;
  padding: 10px 14px;
}

.unit-name {
  font-weight: 700;
  text-align: left;
  word-break: break-word;
}

.unit-count {
  font-size: 0.86rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(29, 38, 59, 0.08);
  flex-shrink: 0;
}

@media (prefers-color-scheme: dark) {
  .unit-count {
    background: rgba(255, 255, 255, 0.1);
  }
}

.unit-btn.is-selected .unit-count {
  background: rgba(27, 34, 52, 0.14);
  color: var(--accent-yellow-text);
}

.link-btn {
  min-height: 44px;
  padding: 6px 12px;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: var(--ink-primary);
  font-family: var(--font-body);
  font-size: 0.94rem;
  font-weight: 700;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
}

@media (prefers-color-scheme: dark) {
  .link-btn {
    color: var(--accent-yellow);
  }
}

.link-btn:hover {
  background: var(--card-surface);
}

/* Chân Màn 1 */
.setup-footer {
  margin-top: 26px;
  padding-top: 20px;
  border-top: 2px dashed var(--card-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.selected-summary {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.selected-count-badge {
  font-family: var(--font-heading);
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-main);
}

.start-hint {
  font-size: 0.88rem;
  color: var(--text-muted);
}

/* Các nút bấm chính / phụ */
.primary-btn,
.accent-btn,
.ghost-btn {
  min-height: 48px;
  padding: 12px 24px;
  font-family: var(--font-heading);
  font-size: 1.12rem;
  font-weight: 700;
  border-radius: var(--radius-md);
  cursor: pointer;
  border: 2px solid transparent;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.primary-btn {
  background: var(--ink-primary);
  color: var(--ink-primary-text);
  box-shadow: 0 4px 0 rgba(16, 30, 82, 0.28);
}

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

.primary-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  box-shadow: none;
}

.accent-btn {
  background: var(--accent-yellow);
  color: var(--accent-yellow-text);
  border-color: var(--accent-yellow-border);
  box-shadow: 0 4px 0 rgba(155, 118, 0, 0.24);
}

.accent-btn:hover {
  background: var(--accent-yellow-hover);
}

.ghost-btn {
  min-height: 44px;
  padding: 8px 16px;
  font-family: var(--font-body);
  font-size: 0.94rem;
  font-weight: 600;
  background: var(--card-surface);
  color: var(--text-main);
  border-color: var(--card-border);
}

.ghost-btn:hover {
  border-color: var(--wrong);
  color: var(--wrong);
}

/* ==========================================================================
   MÀN 2: LÀM BÀI
   ========================================================================== */
.quiz-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.quiz-stats {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.stat-pill {
  display: inline-flex;
  align-items: center;
  padding: 6px 14px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 0.94rem;
}

.stat-progress {
  background: var(--card-surface);
  color: var(--text-main);
  border: 1px solid var(--card-border);
}

.stat-correct-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
}

.stat-correct {
  background: var(--correct-bg);
  color: var(--correct);
  border: 1px solid var(--correct-border);
  will-change: transform;
}

/* Số +1 nhảy lên khi trả lời đúng */
.score-plus-one {
  position: absolute;
  top: -8px;
  right: -6px;
  font-family: var(--font-heading);
  font-size: 1rem;
  font-weight: 800;
  color: var(--correct);
  pointer-events: none;
  opacity: 0;
  will-change: transform, opacity;
}

/* Huy hiệu chuỗi đúng liên tiếp 🔥 x3, 🔥 x4... */
.streak-badge {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 5px 12px;
  border-radius: 999px;
  background: var(--streak-bg);
  border: 2px solid var(--streak-border);
  color: var(--streak-text);
  font-family: var(--font-heading);
  font-size: 0.98rem;
  font-weight: 800;
  line-height: 1.2;
  will-change: transform, opacity;
}

/* Thanh tiến độ: dùng scaleX (chỉ transform) + vệt sáng lướt qua */
.progress-track {
  position: relative;
  width: 100%;
  height: 13px;
  border-radius: 999px;
  background: var(--card-surface);
  border: 1px solid var(--card-border);
  overflow: hidden;
  margin-bottom: 22px;
}

.progress-fill {
  position: relative;
  width: 100%;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--ink-primary) 0%, #3d6cf2 100%);
  transform-origin: left center;
  transform: scaleX(0);
  overflow: hidden;
  will-change: transform;
}

.progress-fill::after {
  content: "";
  position: absolute;
  inset: 0;
  width: 42%;
  background: linear-gradient(
    90deg,
    rgba(255, 255, 255, 0) 0%,
    rgba(255, 255, 255, 0.45) 50%,
    rgba(255, 255, 255, 0) 100%
  );
  will-change: transform, opacity;
}

/* Khung thẻ câu hỏi có chiều sâu 3D để lật bài */
.question-card-stage {
  perspective: 1000px;
  margin-bottom: 20px;
}

.question-box {
  background: var(--card-surface);
  border: 2px solid var(--card-border);
  border-radius: 18px;
  padding: clamp(18px, 4vw, 28px);
  text-align: center;
  backface-visibility: hidden;
  will-change: transform, opacity;
}

.question-meta {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.direction-tag {
  font-size: 0.84rem;
  font-weight: 700;
  padding: 4px 12px;
  border-radius: 999px;
  background: var(--accent-yellow);
  color: var(--accent-yellow-text);
}

.pos-tag {
  font-size: 0.86rem;
  font-weight: 700;
  padding: 4px 12px;
  border-radius: 999px;
  background: var(--card-bg);
  color: var(--text-muted);
  border: 1px solid var(--card-border);
}

.prompt-area {
  margin-bottom: 8px;
}

.question-prompt {
  margin: 0;
  font-family: var(--font-heading);
  font-size: clamp(1.9rem, 6vw, 2.85rem);
  font-weight: 800;
  line-height: 1.2;
  color: var(--text-main);
  word-break: break-word;
}

.question-prompt.is-meaning {
  font-size: clamp(1.45rem, 4.5vw, 2.05rem);
  line-height: 1.35;
}

.question-phonetic {
  margin: 6px 0 0;
  font-size: 1.08rem;
  color: var(--text-muted);
  font-weight: 500;
}

.audio-row {
  margin-top: 16px;
  display: flex;
  justify-content: center;
}

.speak-btn {
  min-height: 46px;
  padding: 8px 20px;
  border-radius: 999px;
  border: 2px solid var(--ink-primary);
  background: var(--card-bg);
  color: var(--ink-primary);
  font-family: var(--font-body);
  font-size: 0.96rem;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

@media (prefers-color-scheme: dark) {
  .speak-btn {
    border-color: var(--accent-yellow);
    color: var(--accent-yellow);
  }
}

.speak-btn:hover,
.speak-btn.is-speaking {
  background: var(--accent-yellow);
  border-color: var(--accent-yellow-border);
  color: var(--accent-yellow-text);
}

/* Lưới 4 phương án A-D: 1 cột trên điện thoại, 2 cột trên máy tính */
.options-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

@media (min-width: 640px) {
  .options-grid {
    grid-template-columns: 1fr 1fr;
    gap: 14px;
  }
}

.option-btn {
  position: relative;
  min-height: 60px;
  width: 100%;
  padding: 14px 16px;
  text-align: left;
  font-family: var(--font-body);
  font-size: 1.04rem;
  font-weight: 600;
  line-height: 1.4;
  color: var(--text-main);
  background: var(--card-bg);
  border: 2px solid var(--card-border);
  border-radius: var(--radius-md);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 12px;
  word-break: break-word;
  will-change: transform, opacity;
}

/* Lớp viền xanh phát sáng (chỉ animate opacity & transform) */
.option-btn::after {
  content: "";
  position: absolute;
  inset: -4px;
  border-radius: calc(var(--radius-md) + 3px);
  border: 3px solid var(--correct);
  box-shadow: 0 0 18px rgba(26, 155, 92, 0.52);
  opacity: 0;
  pointer-events: none;
  will-change: transform, opacity;
}

.option-btn:hover:not(:disabled) {
  border-color: var(--ink-primary);
  background: var(--card-surface);
}

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

.option-letter {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: var(--card-surface);
  border: 1px solid var(--card-border);
  color: var(--text-main);
  font-family: var(--font-heading);
  font-size: 1.05rem;
  font-weight: 800;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.option-text {
  flex: 1;
}

/* Trạng thái Đúng / Sai sau khi chọn */
.option-btn.is-correct {
  background: var(--correct-bg);
  border-color: var(--correct-border);
  color: var(--text-main);
}

.option-btn.is-correct .option-letter {
  background: var(--correct);
  border-color: var(--correct);
  color: #ffffff;
}

.option-btn.is-wrong {
  background: var(--wrong-bg);
  border-color: var(--wrong-border);
  color: var(--text-main);
}

.option-btn.is-wrong .option-letter {
  background: var(--wrong);
  border-color: var(--wrong);
  color: #ffffff;
}

.option-btn.is-dimmed {
  opacity: 0.56;
}

/* Thanh phản hồi & nút Câu tiếp */
.feedback-bar {
  margin-top: 20px;
  padding: 16px 18px;
  border-radius: var(--radius-md);
  border: 2px solid var(--card-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
}

.feedback-bar.is-correct {
  background: var(--correct-bg);
  border-color: var(--correct-border);
}

.feedback-bar.is-wrong {
  background: var(--wrong-bg);
  border-color: var(--wrong-border);
}

.feedback-content {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  flex: 1;
  min-width: 200px;
}

.feedback-message {
  font-size: 1.02rem;
  font-weight: 700;
  color: var(--text-main);
}

.mini-speak-btn {
  min-height: 44px;
  padding: 6px 12px;
  border-radius: 10px;
  border: 1px solid var(--card-border);
  background: var(--card-bg);
  color: var(--text-main);
  font-family: var(--font-body);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
}

.mini-speak-btn:hover {
  border-color: var(--ink-primary);
}

.next-btn {
  min-width: 150px;
}

.keyboard-hint {
  margin: 16px 0 0;
  text-align: center;
  font-size: 0.85rem;
  color: var(--text-muted);
}

@media (max-width: 639px) {
  .keyboard-hint {
    display: none;
  }

  .setup-footer .primary-btn,
  .feedback-bar .next-btn,
  .result-actions .primary-btn,
  .result-actions .accent-btn {
    width: 100%;
  }
}

/* ==========================================================================
   MÀN 3: KẾT QUẢ
   ========================================================================== */
.result-hero {
  text-align: center;
  padding: 22px 16px 26px;
  background: var(--card-surface);
  border: 2px solid var(--card-border);
  border-radius: 18px;
  margin-bottom: 20px;
}

/* 3 ngôi sao thành tích */
.result-stars {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-bottom: 8px;
}

.result-star {
  font-size: clamp(2.1rem, 6vw, 2.8rem);
  line-height: 1;
  color: var(--star-empty);
  display: inline-block;
  will-change: transform, opacity;
}

.result-star.is-earned {
  color: var(--accent-yellow);
  text-shadow: 0 3px 0 #d99b00;
}

.result-praise {
  margin: 0 0 12px;
  font-family: var(--font-heading);
  font-size: clamp(1.7rem, 5vw, 2.3rem);
  font-weight: 800;
  color: var(--ink-primary);
}

@media (prefers-color-scheme: dark) {
  .result-praise {
    color: var(--accent-yellow);
  }
}

.score-badge {
  display: inline-flex;
  align-items: baseline;
  justify-content: center;
  gap: 6px;
  padding: 10px 24px;
  border-radius: 999px;
  background: var(--accent-yellow);
  color: var(--accent-yellow-text);
  margin-bottom: 10px;
}

.score-number {
  font-family: var(--font-heading);
  font-size: clamp(2.1rem, 6vw, 2.8rem);
  font-weight: 800;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.score-scale {
  font-weight: 700;
  font-size: 1rem;
}

.result-correct-line {
  margin: 0;
  font-size: 1.08rem;
  font-weight: 700;
  color: var(--text-main);
}

/* Thông tin học sinh, lớp, unit */
.result-meta {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px;
  margin: 0 0 22px;
}

.meta-item {
  background: var(--card-surface);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-pill);
  padding: 10px 14px;
}

.meta-item dt {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-bottom: 2px;
}

.meta-item dd {
  margin: 0;
  font-weight: 700;
  color: var(--text-main);
  word-break: break-word;
}

/* Bảng các từ cần ôn lại */
.wrong-section {
  margin-bottom: 24px;
}

.wrong-heading {
  margin: 0 0 12px;
  font-family: var(--font-heading);
  font-size: 1.3rem;
  font-weight: 800;
  color: var(--text-main);
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
  border: 2px solid var(--card-border);
  border-radius: var(--radius-md);
}

.wrong-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.96rem;
}

.wrong-table th,
.wrong-table td {
  padding: 12px 14px;
  text-align: left;
  border-bottom: 1px solid var(--card-border);
  vertical-align: top;
}

.wrong-table thead th {
  background: var(--card-surface);
  font-weight: 700;
  color: var(--text-main);
  white-space: nowrap;
}

.wrong-table tbody tr:last-child td {
  border-bottom: none;
}

@media (max-width: 480px) {
  .wrong-table {
    font-size: 0.9rem;
  }

  .wrong-table th,
  .wrong-table td {
    padding: 10px 8px;
  }

  .wrong-table thead th {
    white-space: normal;
  }
}

.wrong-word-cell {
  display: flex;
  align-items: flex-start;
  gap: 8px;
}

.table-speak-btn {
  min-width: 36px;
  min-height: 36px;
  padding: 0;
  border-radius: 10px;
  border: 1px solid var(--card-border);
  background: var(--card-surface);
  cursor: pointer;
  font-size: 1rem;
  flex-shrink: 0;
}

.table-speak-btn:hover {
  background: var(--accent-yellow);
  border-color: var(--accent-yellow-border);
}

.wrong-word-main {
  font-weight: 700;
  color: var(--text-main);
}

.wrong-word-phonetic {
  display: block;
  font-size: 0.86rem;
  color: var(--text-muted);
}

.wrong-chosen {
  color: var(--wrong);
  font-weight: 600;
}

.perfect-box {
  padding: 18px;
  margin-bottom: 24px;
  border-radius: var(--radius-md);
  background: var(--correct-bg);
  border: 2px solid var(--correct-border);
  color: var(--text-main);
  text-align: center;
  font-weight: 700;
}

.perfect-box p {
  margin: 0;
}

.result-actions {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
}

.result-save-status {
  margin: 14px 0 0;
  text-align: center;
  font-size: 0.86rem;
  font-weight: 600;
  color: var(--text-muted);
}

.result-save-status.is-saved {
  color: var(--correct);
}

/* Chân trang */
.app-footer {
  text-align: center;
  color: rgba(255, 255, 255, 0.78);
  font-size: 0.85rem;
}

.app-footer p {
  margin: 0;
}

/* ==========================================================================
   KHU VỰC HOẠT ẢNH (GOM CHUNG 1 CHỖ ĐỂ DỄ CHỈNH TỐC ĐỘ)
   Mọi hiệu ứng bên dưới CHỈ dùng transform và opacity để chạy mượt 60fps.
   ========================================================================== */

:root {
  /* Thầy/cô có thể chỉnh nhanh tốc độ từng hiệu ứng tại đây */
  --dur-screen: 300ms;          /* Chuyển giữa các màn */
  --dur-setup-stagger: 40ms;    /* Độ trễ lần lượt từng nút lớp/unit */
  --dur-btn-bounce: 260ms;      /* Nút nảy khi bấm chọn */
  --dur-card-flip: 400ms;       /* Thẻ câu hỏi lật vào */
  --dur-option-stagger: 60ms;   /* Độ trễ lần lượt 4 đáp án bay lên */
  --dur-option-enter: 300ms;    /* Thời gian mỗi đáp án bay lên */
  --dur-correct-pop: 360ms;     /* Đáp án đúng phóng to và nảy */
  --dur-wrong-shake: 400ms;     /* Đáp án sai rung lắc trái phải */
  --dur-correct-blink: 620ms;   /* Đáp án đúng nhấp nháy xanh 2 lần khi chọn sai */
  --dur-progress: 400ms;        /* Thanh tiến độ chạy mượt */
  --dur-star-pop: 440ms;        /* Ngôi sao bật ra ở màn kết quả */
}

/* --- 0. Nền hình khối mờ (A, B, C, ngôi sao, bong bóng) trôi chậm --- */
@keyframes bgFloatSlow {
  0%, 100% {
    transform: translate3d(0, 0, 0) rotate(0deg);
    opacity: 0.85;
  }
  50% {
    transform: translate3d(12px, -22px, 0) rotate(8deg);
    opacity: 1;
  }
}

@keyframes bgFloatAlt {
  0%, 100% {
    transform: translate3d(0, 0, 0) rotate(0deg);
    opacity: 0.75;
  }
  50% {
    transform: translate3d(-14px, 18px, 0) rotate(-10deg);
    opacity: 1;
  }
}

.shape-1 { animation: bgFloatSlow 15s ease-in-out infinite; }
.shape-2 { animation: bgFloatAlt 18s ease-in-out infinite; }
.shape-3 { animation: bgFloatSlow 21s ease-in-out infinite -4s; }
.shape-4 { animation: bgFloatAlt 14s ease-in-out infinite -2s; }
.shape-5 { animation: bgFloatSlow 17s ease-in-out infinite -6s; }
.shape-6 { animation: bgFloatAlt 22s ease-in-out infinite -3s; }
.shape-7 { animation: bgFloatSlow 19s ease-in-out infinite -8s; }
.shape-8 { animation: bgFloatAlt 24s ease-in-out infinite -5s; }

/* Vòng xoay đang tải */
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.spinner {
  animation: spin 0.8s linear infinite;
}

/* --- 1. Chuyển màn: màn cũ trượt ra, màn mới trượt vào và hiện dần (300ms) --- */
@keyframes screenSlideOut {
  from {
    opacity: 1;
    transform: translate3d(0, 0, 0);
  }
  to {
    opacity: 0;
    transform: translate3d(-28px, 0, 0);
  }
}

@keyframes screenSlideIn {
  from {
    opacity: 0;
    transform: translate3d(28px, 0, 0);
  }
  to {
    opacity: 1;
    transform: translate3d(0, 0, 0);
  }
}

.screen.is-leaving {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  pointer-events: none;
  animation: screenSlideOut var(--dur-screen) ease-in forwards;
}

.screen.is-entering {
  animation: screenSlideIn var(--dur-screen) cubic-bezier(0.22, 1, 0.36, 1) both;
}

/* --- 2. Màn chọn bài: nút lớp & unit hiện lần lượt (40ms/nút) + bấm vào là nảy --- */
@keyframes setupItemEnter {
  from {
    opacity: 0;
    transform: translate3d(0, 12px, 0) scale(0.96);
  }
  to {
    opacity: 1;
    transform: translate3d(0, 0, 0) scale(1);
  }
}

.anim-setup-item {
  animation: setupItemEnter 260ms cubic-bezier(0.22, 1, 0.36, 1) both;
  animation-delay: calc(var(--i, 0) * var(--dur-setup-stagger));
}

@keyframes selectBounce {
  0% {
    transform: scale(0.95);
  }
  55% {
    transform: scale(1.05);
  }
  100% {
    transform: scale(1);
  }
}

.anim-select-bounce {
  animation: selectBounce var(--dur-btn-bounce) cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* --- 3. Câu hỏi mới: thẻ câu hỏi lật bài (rotateY 400ms) + 4 đáp án bay lên (stagger 60ms) --- */
@keyframes cardFlipIn {
  0% {
    opacity: 0;
    transform: rotateY(-78deg) scale(0.95);
  }
  65% {
    opacity: 1;
    transform: rotateY(6deg) scale(1.01);
  }
  100% {
    opacity: 1;
    transform: rotateY(0deg) scale(1);
  }
}

.question-box.anim-card-flip {
  animation: cardFlipIn var(--dur-card-flip) cubic-bezier(0.22, 1, 0.36, 1) both;
}

@keyframes optionFlyUp {
  from {
    opacity: 0;
    transform: translate3d(0, 22px, 0);
  }
  to {
    opacity: 1;
    transform: translate3d(0, 0, 0);
  }
}

.option-btn.anim-option-enter {
  animation: optionFlyUp var(--dur-option-enter) cubic-bezier(0.22, 1, 0.36, 1) both;
  animation-delay: calc(110ms + var(--i, 0) * var(--dur-option-stagger));
}

/* --- 4. Trả lời ĐÚNG: đáp án nảy + viền xanh phát sáng + điểm nhảy +1 --- */
@keyframes answerCorrectPop {
  0% {
    transform: scale(1);
  }
  45% {
    transform: scale(1.05);
  }
  75% {
    transform: scale(0.98);
  }
  100% {
    transform: scale(1);
  }
}

@keyframes correctGlowPulse {
  0% {
    opacity: 0;
    transform: scale(0.98);
  }
  45% {
    opacity: 1;
    transform: scale(1.01);
  }
  100% {
    opacity: 0.7;
    transform: scale(1);
  }
}

.option-btn.anim-correct-pop {
  animation: answerCorrectPop var(--dur-correct-pop) cubic-bezier(0.34, 1.56, 0.64, 1);
}

.option-btn.anim-correct-pop::after {
  animation: correctGlowPulse 520ms ease-out forwards;
}

@keyframes scorePlusOneFloat {
  0% {
    opacity: 0;
    transform: translate3d(0, 4px, 0) scale(0.75);
  }
  25% {
    opacity: 1;
    transform: translate3d(0, -10px, 0) scale(1.15);
  }
  100% {
    opacity: 0;
    transform: translate3d(0, -28px, 0) scale(1);
  }
}

.score-plus-one.anim-plus-one {
  animation: scorePlusOneFloat 680ms cubic-bezier(0.22, 1, 0.36, 1) forwards;
}

.stat-correct.anim-stat-pop {
  animation: selectBounce 280ms cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* --- 5. Trả lời SAI: đáp án chọn rung lắc (400ms) + đáp án đúng nhấp nháy xanh 2 lần --- */
@keyframes answerWrongShake {
  0%, 100% {
    transform: translate3d(0, 0, 0);
  }
  16% {
    transform: translate3d(-8px, 0, 0);
  }
  34% {
    transform: translate3d(8px, 0, 0);
  }
  52% {
    transform: translate3d(-6px, 0, 0);
  }
  70% {
    transform: translate3d(6px, 0, 0);
  }
  86% {
    transform: translate3d(-3px, 0, 0);
  }
}

.option-btn.anim-wrong-shake {
  animation: answerWrongShake var(--dur-wrong-shake) ease-in-out;
}

@keyframes correctDoubleBlink {
  0%, 100% {
    transform: scale(1);
    opacity: 1;
  }
  25%, 75% {
    transform: scale(1.035);
    opacity: 0.72;
  }
  50% {
    transform: scale(1);
    opacity: 1;
  }
}

@keyframes correctBlinkHalo {
  0%, 100% {
    opacity: 0.2;
  }
  25%, 75% {
    opacity: 1;
  }
  50% {
    opacity: 0.15;
  }
}

.option-btn.anim-correct-blink {
  animation: correctDoubleBlink var(--dur-correct-blink) ease-in-out;
}

.option-btn.anim-correct-blink::after {
  animation: correctBlinkHalo var(--dur-correct-blink) ease-in-out forwards;
}

/* --- 6. Huy hiệu chuỗi đúng liên tiếp 🔥 x3, 🔥 x4... --- */
@keyframes streakBounce {
  0% {
    opacity: 0.6;
    transform: scale(0.72) translate3d(0, 4px, 0);
  }
  55% {
    opacity: 1;
    transform: scale(1.14) translate3d(0, -3px, 0);
  }
  100% {
    opacity: 1;
    transform: scale(1) translate3d(0, 0, 0);
  }
}

@keyframes streakFadeOut {
  from {
    opacity: 1;
    transform: scale(1) translate3d(0, 0, 0);
  }
  to {
    opacity: 0;
    transform: scale(0.8) translate3d(0, -6px, 0);
  }
}

.streak-badge.anim-streak-pop {
  animation: streakBounce 360ms cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

.streak-badge.anim-streak-out {
  animation: streakFadeOut 280ms ease-out forwards;
}

/* --- 7. Thanh tiến độ chạy mượt (400ms) + vệt sáng lướt qua --- */
.progress-fill {
  transition: transform var(--dur-progress) cubic-bezier(0.22, 1, 0.36, 1);
}

@keyframes progressShimmer {
  0% {
    transform: translate3d(-130%, 0, 0);
    opacity: 0;
  }
  20% {
    opacity: 1;
  }
  80% {
    opacity: 1;
  }
  100% {
    transform: translate3d(260%, 0, 0);
    opacity: 0;
  }
}

.progress-fill::after {
  animation: progressShimmer 2.4s ease-in-out infinite;
}

/* Thanh phản hồi hiện nhẹ lên */
@keyframes feedbackReveal {
  from {
    opacity: 0;
    transform: translate3d(0, 10px, 0);
  }
  to {
    opacity: 1;
    transform: translate3d(0, 0, 0);
  }
}

.feedback-bar.anim-feedback-in {
  animation: feedbackReveal 220ms ease-out both;
}

/* --- 8. Màn kết quả: 1–3 ngôi sao bật ra lần lượt --- */
@keyframes starPopIn {
  0% {
    opacity: 0;
    transform: scale(0.3) rotate(-32deg);
  }
  60% {
    opacity: 1;
    transform: scale(1.24) rotate(8deg);
  }
  100% {
    opacity: 1;
    transform: scale(1) rotate(0deg);
  }
}

.result-star.anim-star-pop {
  animation: starPopIn var(--dur-star-pop) cubic-bezier(0.34, 1.56, 0.64, 1) both;
  animation-delay: calc(var(--star-i, 0) * 180ms);
}

/* --- 9. Mọi nút bấm: hover nổi lên nhẹ, bấm lún xuống (scale 0.96) --- */
button {
  transition: transform 140ms cubic-bezier(0.22, 1, 0.36, 1), opacity 140ms ease;
}

@media (hover: hover) {
  button:hover:not(:disabled) {
    transform: translate3d(0, -2px, 0);
  }
}

button:active:not(:disabled) {
  transform: scale(0.96);
}

/* --- Tôn trọng cài đặt giảm chuyển động của máy (prefers-reduced-motion) --- */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }

  .float-shape,
  .progress-fill::after {
    animation: none !important;
  }

  button:hover:not(:disabled),
  button:active:not(:disabled) {
    transform: none !important;
  }
}
