
    /* ================= TỐI ƯU CỐT LÕI (CORE FIXES) ================= */
    * {
        box-sizing: border-box;
        -webkit-tap-highlight-color: transparent;
        touch-action: manipulation;
    }

   body { 
  font-family: 'Roboto', 'Noto Sans JP', sans-serif; 
  margin: 0; 
  background: #f6f9fc; 
  color: #0f172a; 
  height: 100vh; 
  height: 100dvh; 
  overflow: hidden; 
  -webkit-user-select: none; 
  user-select: none;
  display: flex;     
  flex-direction: column;
  }
    /* === FIX LỖI CHỌN ĐÁP ÁN === */
    .radio-option { 
      display: flex; 
      align-items: flex-start; 
      background: white; 
      border: 1px solid #e2e8f0; 
      border-radius: 12px; 
      padding: 16px; 
      margin-bottom: 12px; 
      cursor: pointer; 
      transition: all 0.15s ease-out; 
      position: relative; 
      pointer-events: auto !important;
      z-index: 10;
    }
    .radio-option * {
        pointer-events: none !important;
    }

    .radio-option:active {
        transform: scale(0.98);
        background-color: #f8fafc;
    }

    .radio-option.selected { 
        border-color: #3b82f6; 
        background: #e0edff; 
        box-shadow: 0 0 0 1px #3b82f6;
    }
    
    /* Màu sắc trạng thái đúng sai khi review */
    .radio-option.correct-ans { background-color: #dcfce7; border-color: #22c55e; color: #166534; }
    .radio-option.wrong-ans { background-color: #fee2e2; border-color: #ef4444; color: #991b1b; }

    .radio-circle { 
        width: 22px; height: 22px; 
        border: 2px solid #cbd5e1; 
        border-radius: 50%; 
        margin-right: 15px; 
        margin-top: 2px; 
        flex-shrink: 0; 
        position: relative; 
        transition: border-color 0.2s;
    }

    .radio-option.selected .radio-circle { 
        border-color: #3b82f6; 
        border-width: 6px; /* Hiệu ứng chấm tròn */
    }

    /* ================= CÁC CLASS GIAO DIỆN KHÁC ================= */
    :root {
      --primary-color: #3b82f6;
      --success-color: #22c55e;
      --danger-color: #ef4444;
      --warning-color: #f59e0b;
      --header-height: 60px;
      --sidebar-width: 280px;
    }

    .watermark {
      position: fixed; top: 0; left: 0; width: 100%; height: 100%; pointer-events: none; z-index: 0; 
      background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='600' height='600'><text x='50%' y='50%' fill='rgba(0,0,0,0.04)' font-size='150' font-family='Montserrat' font-weight='900' text-anchor='middle' transform='rotate(-45 300 300)'>NK</text></svg>");
    }

    #loading-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: white; z-index: 10000; display: flex; align-items: center; justify-content: center; flex-direction: column; }
      
    
    .screen { display: none; height: 100%; position: relative; z-index: 1; }
    .screen.active { display: block; }

    .center-container { display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100%; padding: 20px; overflow-y: auto;}
    .card { background: white; padding: 25px; border-radius: 16px; box-shadow: 0 10px 25px rgba(0,0,0,0.05); width: 100%; max-width: 450px; position: relative; }

    input, select { width: 100%; padding: 14px; margin: 10px 0; border: 1px solid #e2e8f0; border-radius: 10px; font-size: 16px; outline: none; transition: 0.2s; background: white; }
    input:focus { border-color: var(--primary-color); }
    
    .btn { padding: 14px 20px; border: none; border-radius: 10px; cursor: pointer; font-weight: 600; transition: 0.2s; font-size: 15px; width: 100%; display: block; text-align: center; margin-top: 10px;}
    .btn-primary { background: var(--primary-color); color: white; box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3); }
    .btn-secondary { background: #64748b; color: white; }
    .btn-link { background: none; border: none; color: #94a3b8; text-decoration: underline; margin-top: 15px; font-size: 0.9rem; }
    .btn:disabled { opacity: 0.7; cursor: not-allowed; }

    /* Layout Exam */
    .exam-layout { display: flex; height: 100%; width: 100%; }
    .main-content { flex: 1; display: flex; flex-direction: column; background: #f6f9fc; position: relative; z-index: 2;}
    .top-bar { height: var(--header-height); background: white; border-bottom: 1px solid #e2e8f0; display: flex; justify-content: space-between; align-items: center; padding: 0 15px; z-index: 20; position: relative; }
    .timer-display { font-size: 1.1rem; font-weight: bold; color: var(--danger-color); background: #fef2f2; padding: 6px 14px; border-radius: 20px; border: 1px solid #fee2e2; }
    
    .exam-scroll-area { 
  flex: 1; 
  overflow-y: auto; 
  padding: 20px; 
  display: flex; 
  justify-content: center; 
  -webkit-overflow-scrolling: touch; 
  
  /* Quan trọng: Padding đáy mặc định cho Desktop */
  padding-bottom: 40px; 
  }
    .question-wrapper { width: 100%; max-width: 800px; }
    .question-card { background: white; padding: 20px; border-radius: 16px; box-shadow: 0 4px 15px rgba(0,0,0,0.03); margin-bottom: 20px; animation: slideIn 0.3s ease-out; }
    .question-text { font-size: 1.15rem; line-height: 1.6; font-weight: 500; margin-bottom: 20px; color: #1e293b; }
    /* ================= FIX MÀU CHỮ RUBY (FURIGANA) ================= */
    ruby rt, 
    ruby rt *,
    .question-card rt,
    .question-card rt * {
        color: #94a3b8 !important; /* Đổi thành xám nhạt (Slate 400) */
        font-weight: 500 !important; /* Giảm độ đậm để nhìn thanh thoát hơn */
        font-size: 0.5em !important; /* Chỉnh lại kích thước cho cân đối */
        letter-spacing: 0px !important;
    }

    /* Đổi màu chữ phiên âm cho các mục từ vựng, flashcard (Phòng khi bạn gọi nhầm tên thẻ) */
    .vocab-reading, 
    .flashcard-reading {
        color: #94a3b8 !important;
    }
    /* Sidebar */
    .sidebar { width: var(--sidebar-width); background: white; border-right: 1px solid #e2e8f0; display: flex; flex-direction: column; z-index: 50; transition: 0.3s; height: 100%; }
    .question-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; padding: 15px; align-content: start; }
    .q-btn { aspect-ratio: 1; display: flex; align-items: center; justify-content: center; border: 1px solid #e2e8f0; border-radius: 8px; font-weight: 500; cursor: pointer; font-size: 0.9rem; }
    .q-btn.active { background: var(--primary-color); color: white; border-color: var(--primary-color); }
    .q-btn.answered { background: #e0edff; color: var(--primary-color); border-color: #bfdbfe; }

    /* Bottom Nav (Mobile) */
  .bottom-nav { 
  position: fixed; 
  bottom: 0; 
  left: 0; 
  width: 100%; 
  background: white; 
  border-top: 1px solid #e2e8f0; 
  display: none; 
  
  /* GIẢM PADDING: Từ 12px xuống 8px */
  padding: 6px 10px; 
  gap: 8px; 
  
  z-index: 9999; 
  box-shadow: 0 -4px 20px rgba(0,0,0,0.05);
  
  /* Giữ an toàn cho iPhone nhưng giảm khoảng cách thừa */
  padding-bottom: calc(8px + env(safe-area-inset-bottom)); 
}
    .bottom-nav .btn {
    /* Reset style mặc định của nút to */
    margin: 0 !important;
    width: auto !important;
    
    /* Giảm kích thước nút */
    padding: 0 !important; /* Xóa padding dày cũ */
    height: 40px;          /* Cố định chiều cao chuẩn (đủ bấm nhưng gọn) */
    font-size: 0.9rem;     /* Chữ nhỏ lại một chút */
    line-height: 40px;     /* Canh giữa chữ theo chiều dọc */
    
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;    /* Bo góc nhẹ hơn cho gọn */
}

/* ========================================================
       THANH TIẾN ĐỘ GEN Z (BẢN TINH CHỈNH: GỌN GÀNG & ĐỒNG BỘ MÀU)
       ======================================================== */
    /* 1. Rãnh chứa (Thu hẹp chiều cao từ 20px -> 14px) */
    .genz-progress-track {
        width: 100%;
        height: 14px; 
        background: #e2e8f0;
        border-radius: 14px; /* Bo góc tương ứng chiều cao */
        position: relative;
        box-shadow: inset 0 2px 4px rgba(0,0,0,0.08);
    }
    body.dark-mode .genz-progress-track { background: #1e293b; box-shadow: inset 0 2px 5px rgba(0,0,0,0.3); }

    /* Lõi màu chạy (Dải màu Xanh dương chủ đạo) */
    .genz-progress-fill {
        height: 100%;
        border-radius: 14px;
        /* Dùng các sắc thái của Xanh dương (Primary Color) */
        background: linear-gradient(90deg, #60a5fa, var(--primary-color), #2563eb, var(--primary-color));
        background-size: 200% 100%;
        animation: genzGradientMove 3s ease infinite;
        
        transition: width 1.2s cubic-bezier(0.34, 1.56, 0.64, 1), background 0.5s ease;
        /* Bóng đổ màu Xanh dương */
        box-shadow: 0 4px 12px rgba(59, 130, 246, 0.4); 
        position: relative;
    }
    
    /* 2. Bong bóng bay trên đầu (Tối giản, chứa số bài) */
    .genz-progress-bubble {
        position: absolute;
        right: -20px; 
        top: -34px; 
        background: var(--primary-color); /* Nền Xanh dương chủ đạo */
        color: white;
        font-weight: 800;
        font-size: 0.8rem; 
        padding: 4px 10px;   
        border-radius: 10px; 
        /* Bóng đổ màu Xanh dương */
        box-shadow: 0 4px 10px rgba(59, 130, 246, 0.4);
        display: flex;
        align-items: center;
        justify-content: center;
        white-space: nowrap; 
        
        transition: width 0.3s ease, background 0.3s ease;
        /* Hiệu ứng nảy lơ lửng */
        animation: bubbleFloat 2s ease-in-out infinite; 
        z-index: 10;
    }
    
    /* Đuôi tam giác của bong bóng */
    .genz-progress-bubble::after {
        content: '';
        position: absolute;
        bottom: -4px; 
        left: 50%;
        transform: translateX(-50%);
        border-width: 5px 5px 0;
        border-style: solid;
        /* Màu tam giác đồng bộ với nền Xanh dương */
        border-color: var(--primary-color) transparent transparent transparent;
    }

    /* 🌟 KHI HOÀN THÀNH 100% (Đổi sang tông Success Green) */
    .genz-progress-fill.is-done {
        background: linear-gradient(90deg, #34d399, var(--success-color), #16a34a, var(--success-color));
        box-shadow: 0 4px 12px rgba(34, 197, 94, 0.4);
    }
    .genz-progress-fill.is-done .genz-progress-bubble {
        background: var(--success-color);
        /* Nảy mạnh hơn khi hoàn thành */
        animation: bubbleTriumph 1.5s ease-in-out infinite;
        box-shadow: 0 4px 10px rgba(34, 197, 94, 0.4);
    }
    .genz-progress-fill.is-done .genz-progress-bubble::after {
        border-color: var(--success-color) transparent transparent transparent;
    }

    /* 🌙 CÂN BẰNG CHO DARK MODE */
    body.dark-mode .genz-progress-bubble { 
        background: #60a5fa; /* Xanh lơ sáng hơn cho dễ đọc */
        color: #0f172a; 
    }
    body.dark-mode .genz-progress-bubble::after { border-color: #60a5fa transparent transparent transparent; }
    
    body.dark-mode .genz-progress-fill.is-done .genz-progress-bubble { 
        background: #4ade80; /* Xanh lá sáng hơn cho Dark Mode */
        color: #0f172a; 
    }
    body.dark-mode .genz-progress-fill.is-done .genz-progress-bubble::after { border-color: #4ade80 transparent transparent transparent; }

    /* ================= KEYFRAMES ================= */
    @keyframes genzGradientMove {
        0% { background-position: 0% 50%; }
        50% { background-position: 100% 50%; }
        100% { background-position: 0% 50%; }
    }
    
    /* 3. Hiệu ứng nảy lơ lửng nhẹ nhàng cho bong bóng */
    @keyframes bubbleFloat {
        0%, 100% { transform: translateY(0); }
        50% { transform: translateY(-4px); } /* Nhấc lên 4px rồi hạ xuống */
    }

    /* Hiệu ứng nảy ăn mừng khi đạt 100% */
    @keyframes bubbleTriumph {
        0%, 100% { transform: translateY(0) scale(1.05); }
        50% { transform: translateY(-6px) scale(1.1); } 
    }

    /* ================= KEYFRAMES ================= */
    @keyframes genzGradientMove {
        0% { background-position: 0% 50%; }
        50% { background-position: 100% 50%; }
        100% { background-position: 0% 50%; }
    }
    
    /* 3. Hiệu ứng nảy lơ lửng nhẹ nhàng cho bong bóng */
    @keyframes bubbleFloat {
        0%, 100% { transform: translateY(0); }
        50% { transform: translateY(-4px); } /* Nhấc lên 4px rồi hạ xuống */
    }

    /* Hiệu ứng nảy ăn mừng khi đạt 100% (to hơn một chút) */
    @keyframes bubbleTriumph {
        0%, 100% { transform: translateY(0) scale(1.05); }
        50% { transform: translateY(-6px) scale(1.1); } 
    }
    /* ========================================================
       CẤU HÌNH TOAST NOTIFICATION (PHIÊN BẢN HIỆN ĐẠI 2024)
       ======================================================== */
 /* Khung chứa Toast */
    #toast-notification {
        display: none; 
        position: fixed;
        top: 30%; 
        left: 50%;
        transform: translate(-50%, -20px) scale(0.9); /* Thu nhỏ và nhấc lên xíu lúc ẩn */
        
        background: rgba(255, 255, 255, 0.95);
        -webkit-backdrop-filter: blur(12px);
        backdrop-filter: blur(12px);
        
        color: #1f2937; 
        padding: 14px 24px;
        border-radius: 16px;
        border: 1px solid rgba(255, 255, 255, 0.5);
        box-shadow: 0 15px 40px rgba(0, 0, 0, 0.15);
        z-index: 10000; 
        min-width: 300px;
        max-width: 85%;
        width: auto;
        
        align-items: center;
        gap: 12px;
        
        /* Ẩn phần thanh tiến độ bị tràn ra ngoài góc bo tròn */
        overflow: hidden;
        opacity: 0;
    }

    /* 🌟 HIỆU ỨNG NẢY LÚC XUẤT HIỆN (BOUNCE IN) */
    @keyframes toastBounceIn {
        0% { opacity: 0; transform: translate(-50%, -30px) scale(0.85); }
        60% { opacity: 1; transform: translate(-50%, 5px) scale(1.02); }
        100% { opacity: 1; transform: translate(-50%, 0) scale(1); }
    }

    /* 🌟 HIỆU ỨNG TRƯỢT LÚC TẮT (FADE OUT UP) */
    @keyframes toastFadeOut {
        0% { opacity: 1; transform: translate(-50%, 0) scale(1); }
        100% { opacity: 0; transform: translate(-50%, -20px) scale(0.95); }
    }

    #toast-notification.toast-visible {
        display: flex; 
        animation: toastBounceIn 0.5s cubic-bezier(0.25, 1, 0.5, 1) forwards;
    }

    #toast-notification.toast-hiding {
        animation: toastFadeOut 0.3s ease-in forwards;
    }

    /* 🌟 HIỆU ỨNG ICON BUNG RA (POP-UP) */
    @keyframes iconPopEffect {
        0% { transform: scale(0); opacity: 0; }
        70% { transform: scale(1.3); }
        100% { transform: scale(1); opacity: 1; }
    }
    #toast-notification.toast-visible .toast-icon svg {
        animation: iconPopEffect 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
    }

    /* 🌟 THANH ĐẾM NGƯỢC THỜI GIAN Ở ĐÁY */
    .toast-progress {
        position: absolute;
        bottom: 0;
        left: 0;
        height: 4px;
        width: 100%;
        opacity: 0.8;
        /* Chuyển động width sẽ được JS điều khiển */
    }

   /* ========================================================
       CẤU HÌNH ICON BADGE (NỀN TRÒN CÓ MÀU, ICON MÀU TRẮNG)
       ======================================================== */
    /* Định dạng lại khung chứa Icon thành hình tròn */
    .toast-icon { 
        flex-shrink: 0; 
        width: 32px; /* Tăng nhẹ để viền tròn rộng rãi và cân đối hơn */
        height: 32px; 
        display: flex; 
        align-items: center; 
        justify-content: center;
        border-radius: 50%; 
        color: #ffffff !important; 
        padding: 0; /* Xóa padding để Flexbox tự căn giữa 100% */
    }

    /* Ép kích thước và chặn lỗi lệch baseline của thẻ SVG */
    .toast-icon svg {
        width: 18px;
        height: 18px;
        display: block; /* RẤT QUAN TRỌNG: Khử khoảng trắng thừa phía dưới của thẻ inline */
    }

    .toast-content { flex: 1; font-size: 14.5px; line-height: 1.5; font-weight: 600; }

    /* 1. Success (Lá cây) */
    .toast-success { border-color: rgba(34, 197, 94, 0.4) !important; }
    .toast-success .toast-icon { background-color: #22c55e; box-shadow: 0 4px 10px rgba(34, 197, 94, 0.3); }
    .toast-success .toast-progress { background-color: #22c55e; }

    /* 2. Danger/Error (Đỏ) */
    .toast-danger { border-color: rgba(239, 68, 68, 0.4) !important; }
    .toast-danger .toast-icon { background-color: #ef4444; box-shadow: 0 4px 10px rgba(239, 68, 68, 0.3); }
    .toast-danger .toast-progress { background-color: #ef4444; }

    /* 3. Info/Đang lưu (Xanh hệ thống) - PRIMARY COLOR */
    .toast-info { border-color: rgba(59, 130, 246, 0.4) !important; }
    .toast-info .toast-icon { background-color: var(--primary-color, #3b82f6); box-shadow: 0 4px 10px rgba(59, 130, 246, 0.3); }
    .toast-info .toast-progress { background-color: var(--primary-color, #3b82f6); }

    /* 4. Warning (Cam) */
    .toast-warning { border-color: rgba(245, 158, 11, 0.4) !important; }
    .toast-warning .toast-icon { background-color: #f59e0b; box-shadow: 0 4px 10px rgba(245, 158, 11, 0.3); }
    .toast-warning .toast-progress { background-color: #f59e0b; }

    /* Hỗ trợ Dark Mode */
    body.dark-mode #toast-notification {
        background: rgba(31, 41, 55, 0.95);
        color: #f3f4f6; 
        border: 1px solid rgba(255, 255, 255, 0.15);
        box-shadow: 0 15px 40px rgba(0, 0, 0, 0.5);
    }
    /* ================= FIX LỖI CUỘN TRANG REVIEW ================= */

/* 1. Biến màn hình review thành Flexbox dọc để chia vùng header và nội dung */
#screen-review.active {
    display: flex !important; /* Ghi đè display: block mặc định */
    flex-direction: column !important;
    height: 100% !important;
    overflow: hidden !important; /* Chặn cuộn ở body, chỉ cuộn ở con */
}

/* 2. Đảm bảo thanh tiêu đề không bị co lại */
#screen-review .top-bar {
    flex-shrink: 0;
    z-index: 100;
    width: 100%;
}

/* 3. Vùng cuộn chiếm toàn bộ không gian còn lại */
#screen-review .exam-scroll-area {
    flex: 1;
    overflow-y: auto !important;
    height: auto !important;
    display: block !important; /* Đảm bảo hành vi cuộn chuẩn */
    padding: 20px;
    padding-bottom: 80px; /* Khoảng trống dưới cùng để không bị sát mép */
    -webkit-overflow-scrolling: touch; /* Cuộn mượt trên iOS */
}

/* 4. Fix lỗi hiển thị nội dung bên trong vùng cuộn */
#review-container {
    width: 100%;
    max-width: 800px;
    margin: 0 auto;
    display: block; /* Tránh bị ảnh hưởng bởi flex cha */
}

/* Tinh chỉnh thẻ câu hỏi trong phần review cho gọn */
#review-container .question-card {
    margin-bottom: 15px;
    border: 1px solid #e2e8f0;
}
/* --- BỐ CỤC DASHBOARD HIỆN ĐẠI (TỶ LỆ 70 - 30) --- */
.dashboard-layout {
  display: flex;
  gap: 12px;
  justify-content: center;
  align-items: stretch; 
  max-width: 1100px; /* Nới rộng một chút để có không gian cho tỷ lệ 7/3 */
  margin: 0 auto;
  padding: 20px;
  min-height: 500px; 
}

/* Thẻ Chính (Bên trái) - Chiếm 65% - 70% không gian */
.main-card {
  flex: 2; /* Trọng số gấp đôi thẻ bên phải */
  background: white;
  padding: 30px; 
  border-radius: 20px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.04); /* Bóng đổ mềm và sang hơn */
  width: 100%; 
  display: flex;
  flex-direction: column;
}

/* Thẻ Phụ / Widget (Bên phải) - Chiếm 30% - 35% không gian */
.vocab-card {
  flex: 1.1; 
  background: #f8fafc; /* Màu xám nhạt để giảm cạnh tranh thị giác */
  padding: 25px 20px;
  border-radius: 20px;
  border: 1px solid #e2e8f0; /* Viền mỏng tinh tế thay vì bóng đổ nặng */
  box-shadow: none; 
  width: 100%;
  display: flex;
  flex-direction: column; 
  overflow: hidden; 
}

/* List từ vựng */
.vocab-list {
  /* MẤU CHỐT: flex: 1 giúp list chiếm toàn bộ khoảng trống còn lại trong thẻ */
  flex: 1; 
  overflow-y: auto; /* Chỉ cuộn khu vực danh sách, header giữ nguyên */
  padding-right: 5px;
  /* Tùy chỉnh thanh cuộn cho đẹp */
  scrollbar-width: thin;
  scrollbar-color: #cbd5e1 #f1f5f9;
}

/* Style thanh cuộn Webkit (Chrome/Safari) */
.vocab-list::-webkit-scrollbar { width: 6px; }
.vocab-list::-webkit-scrollbar-track { background: #f1f5f9; }
.vocab-list::-webkit-scrollbar-thumb { background-color: #cbd5e1; border-radius: 10px; }

/* Các item bên trong */
.vocab-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px dashed #e2e8f0;
}
.vocab-item:last-child { border-bottom: none; }

.vocab-jp { font-weight: bold; color: #1e293b; font-size: 1.1rem; }
.vocab-reading { font-size: 0.8rem; color: #64748b; display: block; margin-top: 2px;}
.vocab-vi { color: var(--primary-color); font-weight: 600; font-size: 0.95rem; text-align: right; max-width: 50%; line-height: 1.4; }

/* --- MOBILE RESPONSIVE FIX (CẬP NHẬT) --- */
@media (max-width: 768px) {
  /* --- 1. SIDEBAR & NAV --- */
  .sidebar { 
    position: fixed; left: -100%; height: 100%; 
    box-shadow: 5px 0 15px rgba(0,0,0,0.1); 
  }
  .sidebar.open { left: 0; }
  .bottom-nav, .bottom-nav.modern-nav { display: flex !important; }
  
  /* Ẩn các nút điều hướng của Desktop */
  .nav-actions-desktop { display: none !important; }
  
  /* --- 2. GIAO DIỆN LÀM BÀI (EXAM UI) --- */
  .radio-option { padding: 18px; }
  .radio-circle { width: 24px; height: 24px; }

  /* [QUAN TRỌNG] Tăng khoảng đệm đáy để không bị nút che mất nội dung */
  .exam-scroll-area {
      margin-bottom: 0 !important;
      padding-bottom: calc(48px + env(safe-area-inset-bottom)) !important;
      -webkit-overflow-scrolling: touch; 
  }

  /* [QUAN TRỌNG] Hỗ trợ vuốt ngang nếu bảng/ảnh quá to */
  .question-wrapper {
      width: 100%;
      overflow-x: auto; 
  }

  .question-card {
      /* Kéo dài thẻ trắng xuống để giao diện đẹp hơn */
      min-height: 60vh; 
      overflow-x: auto; 
  }

  /* --- 3. GIAO DIỆN DASHBOARD (MÀN HÌNH CHÍNH) --- */
  /* Mở khóa cuộn cho Dashboard */
  #screen-dashboard {
    overflow-y: auto !important; 
    -webkit-overflow-scrolling: touch; 
    height: 100% !important;
  }

  #screen-dashboard .dashboard-layout {
    height: auto !important; 
    min-height: 100%; 
    padding-bottom: 90px !important; /* Khoảng trống đáy để vuốt hết */
  }

  .center-container {
    display: block !important; 
    height: 100%;
    overflow-y: auto !important; 
    -webkit-overflow-scrolling: touch; 
    padding: 15px;
  }

  .dashboard-layout {
    display: flex;
    flex-direction: column; /* Xếp chồng dọc trên mobile */
    height: auto !important; 
    min-height: auto;
    padding-bottom: 20px !important;
    gap: 6px; /* Giảm khoảng cách giữa 2 thẻ trên mobile cho liền mạch */
  }

 /* 1. Thẻ chính: Ép mỏng padding bên dưới để giảm khoảng trắng */
  .main-card {
    width: 100%;
    max-width: 100%;
    margin-bottom: 0; 
    flex: none; 
    padding: 15px 15px 18px 15px; /* Trên-Phải-Dưới-Trái */
    border-radius: 16px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.05);
  }

  /* 2. Thẻ phụ: Xóa giới hạn chiều cao để danh sách từ vựng hiện ra */
  .vocab-card {
    width: 100%;
    max-width: 100%;
    margin-bottom: 0;
    flex: none; 
    background: white; 
    border: none;
    box-shadow: 0 4px 20px rgba(0,0,0,0.05);
    border-radius: 16px;
    height: auto !important; /* Quan trọng: Cho phép thẻ tự động dãn dài ra */
    overflow: visible !important; /* Quan trọng: Hiển thị lại các phần bị cắt giấu */
    display: flex;
    flex-direction: column;
    padding: 15px; /* Giảm nhẹ lớp đệm cho vừa vặn mobile */
  }
  #history-content {
    margin-bottom: 0 !important;
    padding-bottom: 0 !important;
  }
  .vocab-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0; /* Quan trọng: Giúp Flexbox con cuộn được */
    overflow: hidden;
  }
  #vocab-container.vocab-list {
    flex: 1;
    overflow-y: auto !important;
    padding-bottom: 10px;
  }
  .vocab-list {
    flex: 1;
    overflow-y: auto;
  }
  /* --- THU GỌN LỊCH SỬ LÀM BÀI TRÊN MOBILE --- */
    #history-content {
      max-height: 220px; /* Chiều cao tối đa (hiển thị khoảng 3-4 dòng lịch sử) */
      overflow-y: auto;  /* Bật tính năng kéo/vuốt lên xuống */
      overflow-x: hidden; 
      padding-right: 8px; /* Lùi vào một chút để không lẹm vào thanh cuộn */
      margin-bottom: 5px;
    }

    /* Làm đẹp thanh cuộn dọc cho gọn gàng */
    #history-content::-webkit-scrollbar {
      width: 5px;
    }
    #history-content::-webkit-scrollbar-track {
      background: #f1f5f9; 
      border-radius: 10px;
    }
    #history-content::-webkit-scrollbar-thumb {
      background: #cbd5e1; 
      border-radius: 10px;
    }
    #history-content > div:nth-child(n+4) {
      display: none !important; 
    }
}

/* 2. Nội dung danh sách lịch sử */
#history-content {
  /* Tự động dãn full chiều cao của cha (.history-section) */
  flex: 1; 
  /* Nếu danh sách dài hơn chiều cao thẻ -> Hiện thanh cuộn */
  overflow-y: auto; 
  
  /* Xóa bỏ max-height cũ (quan trọng) */
  max-height: none !important; 
  
  /* Thêm style cho đẹp */
  padding-right: 5px;
  scrollbar-width: thin;
  scrollbar-color: #cbd5e1 #f1f5f9;
}

/* Style thanh cuộn riêng cho lịch sử (giống bên từ vựng) */
#history-content::-webkit-scrollbar { width: 6px; }
#history-content::-webkit-scrollbar-track { background: #f1f5f9; }
#history-content::-webkit-scrollbar-thumb { background-color: #cbd5e1; border-radius: 10px; }
/* ================= FIX LỖI CUỘN DASHBOARD MOBILE ================= */

/* 1. Mở khóa cuộn cho riêng màn hình Dashboard */
#screen-dashboard {
    /* Quan trọng: Cho phép nội dung tràn ra được cuộn dọc */
    overflow-y: auto !important; 
    
    /* Giúp cuộn mượt mà trên iPhone/iPad */
    -webkit-overflow-scrolling: touch; 
    
    /* Đảm bảo nó chiếm toàn bộ không gian để tạo vùng cuộn */
    height: 100% !important;
    
}

/* 2. Đảm bảo bố cục bên trong được dãn ra tự nhiên */
#screen-dashboard .dashboard-layout {
    height: auto !important; /* Bỏ giới hạn chiều cao */
    min-height: 100%; 
    
    /* Thêm khoảng trống lớn ở đáy để vuốt được hết nội dung cuối cùng */
    padding-bottom: 65px !important; 
}

/* 3. (Tùy chọn) Ẩn thanh cuộn bên phải cho đẹp như App */
#screen-dashboard::-webkit-scrollbar {
    width: 0px;
    background: transparent;
}
/* ================= DARK MODE TOGGLE (ĐÃ SỬA) ================= */
    /* Thay vì @media, ta dùng class để JS điều khiển được */
    body.dark-mode {
      background: #0f172a !important;
      color: #f1f5f9 !important;
    }

    /* Áp dụng cho các thành phần con khi body có class dark-mode */
    body.dark-mode :root {
      --primary-color: #60a5fa;
      --success-color: #4ade80;
      --danger-color: #fb7185;
      --warning-color: #fbbf24;
    }

    body.dark-mode .card, 
    body.dark-mode .question-card, 
    body.dark-mode .sidebar, 
    body.dark-mode .top-bar, 
    body.dark-mode .bottom-nav, 
    body.dark-mode .main-card, 
    body.dark-mode .vocab-card {
      background: #1e293b !important;
      border-color: #334155 !important;
      color: #f1f5f9 !important;
      box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.5) !important;
    }

    body.dark-mode .question-text { color: #f8fafc !important; }
    body.dark-mode .question-card > div:first-child { color: #94a3b8 !important; }

    body.dark-mode .radio-option {
      background: #1e293b !important;
      border-color: #475569 !important;
      color: #cbd5e1 !important;
    }
    
    body.dark-mode .radio-option:active { background: #334155 !important; }
    
    body.dark-mode .radio-option.selected {
      background: #172554 !important;
      border-color: #60a5fa !important;
      color: #ffffff !important;
    }
    
    body.dark-mode .radio-option.selected .radio-circle { border-color: #60a5fa !important; }

    body.dark-mode .radio-option.correct-ans { 
      background-color: #064e3b !important; border-color: #059669 !important; color: #6ee7b7 !important; 
    }
    body.dark-mode .radio-option.wrong-ans { 
      background-color: #7f1d1d !important; border-color: #b91c1c !important; color: #fca5a5 !important; 
    }
    body.dark-mode .question-card > div[style*="background:#f0fdf4"] {
      background: #064e3b !important; border-color: #065f46 !important; color: #d1fae5 !important;
    }

    body.dark-mode input, body.dark-mode select {
      background: #0f172a !important; color: #ffffff !important; border-color: #475569 !important;
    }
    
    body.dark-mode .q-btn { background: #0f172a; border-color: #334155; color: #cbd5e1; }
    body.dark-mode .q-btn.active { background: #2563eb; color: white; border-color: #3b82f6; }
    body.dark-mode .q-btn.answered { background: #1e3a8a; color: #93c5fd; border-color: #1e40af; }
    body.dark-mode .progress-container { background: #334155 !important; }
    body.dark-mode .watermark { opacity: 0.15; filter: invert(1); }
    body.dark-mode .timer-display { background: #334155 !important; border-color: #475569 !important; color: #f1f5f9; }
    /* --- [FIX] HIỂN THỊ TỪ VỰNG TRONG DARK MODE --- */
    body.dark-mode .vocab-jp { color: #ffffff !important; }
    body.dark-mode .vocab-reading { color: #94a3b8 !important; }
    body.dark-mode .vocab-item { border-bottom-color: #334155 !important; }
    /* CSS CHO NÚT BẬT TẮT */
    .theme-toggle-btn {
      background: none; border: none; font-size: 1.2rem; cursor: pointer; padding: 5px; transition: transform 0.3s;
    }
    .theme-toggle-btn:active { transform: scale(0.9); }
  /* Tương thích Furigana trong Dark Mode */
    body.dark-mode ruby rt,
    body.dark-mode ruby rt *,
    body.dark-mode .question-card rt,
    body.dark-mode .question-card rt * {
        color: #64748b !important; /* Xám đậm hơn một chút để không bị chói lóa trên nền đen */
    }   
/* 1. Nút bấm Primary với hiệu ứng Nổi bật */
.btn-primary { 
    background: linear-gradient(135deg, #3b82f6 0%, #1d4ed8 100%); 
    box-shadow: 0 4px 15px rgba(59, 130, 246, 0.4); 
    border: none;
    transition: all 0.3s ease;
    animation: pulse-blue 2s infinite; /* Thêm hiệu ứng nhịp thở */
}

@keyframes pulse-blue {
    0% { box-shadow: 0 0 0 0 rgba(59, 130, 246, 0.7); }
    70% { box-shadow: 0 0 0 10px rgba(59, 130, 246, 0); }
    100% { box-shadow: 0 0 0 0 rgba(59, 130, 246, 0); }
}

.btn-primary:active { transform: scale(0.95); }

/* 2. Hiệu ứng mờ (Glassmorphism) cho Top Bar */
.top-bar { 
    background: rgba(255, 255, 255, 0.85); 
    backdrop-filter: blur(12px); /* Mờ nền đằng sau */
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid rgba(226, 232, 240, 0.6);
}
body.dark-mode .top-bar { background: rgba(30, 41, 59, 0.85); border-bottom-color: rgba(51, 65, 85, 0.6); }

/* 3. Vòng tròn điểm số (Animated Gradient) */
.score-circle-modern {
    width: 140px; height: 140px;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 2.2rem; font-weight: 900;
    margin: 0 auto 20px;
    position: relative;
    background: conic-gradient(var(--score-color) var(--score-percent), #f1f5f9 0deg);
    transition: background 1s ease-out;
}
/* Lớp phủ bên trong để tạo thành vòng tròn rỗng */
.score-circle-modern::before {
    content: ""; position: absolute;
    width: 115px; height: 115px;
    background: white; border-radius: 50%;
    z-index: 1;
}
body.dark-mode .score-circle-modern::before { background: #1e293b; }
.score-text-inner { position: relative; z-index: 2; }
    /* --- LEADERBOARD STYLES --- */
.leaderboard-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.lb-item {
  display: flex;
  align-items: center;
  padding: 8px;
  background: #f8fafc;
  border-radius: 8px;
  font-size: 0.9rem;
  transition: transform 0.2s;
}

/* Hiệu ứng màu sắc cho Top 1, 2, 3 */
.lb-item.rank-1 { background: linear-gradient(90deg, #fffbeb, #fff); border: 1px solid #fcd34d; }
.lb-item.rank-2 { background: linear-gradient(90deg, #f8fafc, #fff); border: 1px solid #cbd5e1; }
.lb-item.rank-3 { background: linear-gradient(90deg, #fff1f2, #fff); border: 1px solid #fda4af; }
.lb-item.rank-4 { 
    background: linear-gradient(90deg, #eff6ff, #fff); /* Xanh nhạt */
    border: 1px solid #93c5fd; /* Viền xanh */
}

/* Rank 5: Tông Xanh Lá (Hy vọng) */
.lb-item.rank-5 { 
    background: linear-gradient(90deg, #f0fdf4, #fff); /* Lá nhạt */
    border: 1px solid #86efac; /* Viền lá */
}

/* --- Dark Mode Support cho Rank 4 & 5 --- */
body.dark-mode .lb-item.rank-4 { background: #172554; border-color: #1e3a8a; }
body.dark-mode .lb-item.rank-5 { background: #064e3b; border-color: #065f46; }
.lb-medal {
  font-size: 1.2rem;
  margin-right: 10px;
  width: 25px;
  text-align: center;
}

.lb-name {
  font-weight: 600;
  color: #334155;
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.lb-score {
  font-weight: bold;
  color: var(--primary-color);
  font-size: 0.85rem;
  background: #e0edff;
  padding: 2px 8px;
  border-radius: 10px;
}

/* Dark mode support */
body.dark-mode .lb-item { background: #1e293b; border-color: #334155; }
body.dark-mode .lb-name { color: #f1f5f9; }
body.dark-mode .lb-item.rank-1 { background: #422006; border-color: #a16207; }
body.dark-mode .lb-item.rank-2 { background: #1e293b; border-color: #475569; }
body.dark-mode .lb-item.rank-3 { background: #4c0519; border-color: #9f1239; }
/* Style cho Top 4, 5 */
.lb-item.rank-other { 
    background: white; 
    border: 1px solid #e2e8f0; 
}
body.dark-mode .lb-item.rank-other {
    background: #1e293b;
    border-color: #334155;
}
/* ============================================================ */
/* SỬ DỤNG WATERMARK HỆ THỐNG ĐỂ PHỦ KÍN MÀN HÌNH               */
/* ============================================================ */

.main-content {
    position: relative;
    z-index: 0;
    background-color: #f6f9fc;
    overflow: hidden; /* Đảm bảo pattern không tràn khỏi vùng làm việc */
}

/* Tạo lớp lưới Watermark dựa trên SVG gốc của bạn */
.main-content::before {
    content: "";
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    
    /* Sử dụng đúng SVG logo NK của bạn nhưng thu nhỏ để làm pattern */
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='200' height='200'><text x='50%' y='50%' fill='rgba(0,0,0,1)' font-size='60' font-family='Montserrat' font-weight='900' text-anchor='middle' transform='rotate(-45 100 100)'>NK</text></svg>");
    
    /* Lặp lại vô tận */
    background-repeat: repeat;
    background-size: 200px 200px; /* Khoảng cách giữa các logo */
    
    /* Độ mờ siêu nhạt để không gây khó chịu khi nhìn lâu */
    opacity: 0.04; 
    
    pointer-events: none;
    z-index: -1;
}

/* Tương thích Dark Mode: Đảo màu logo NK thành trắng */
body.dark-mode .main-content::before {
    filter: invert(1);
    opacity: 0.04;
}

/* Đảm bảo khung câu hỏi nổi bật trên nền lưới */
.question-card {
    position: relative;
    z-index: 2;
    background: white;
    box-shadow: 0 4px 15px rgba(0,0,0,0.05);
}

/* Đảm bảo thanh điều hướng dưới không bị mờ */
.bottom-nav {
    z-index: 9999;
}
/* ================= CSS CHO KHUNG BẢN DỊCH ================= */
    .translation-box {
        display: none; /* Ẩn mặc định */
        background-color: #f1f5f9;
        border-left: 4px solid var(--primary-color);
        padding: 15px;
        margin-top: 15px;
        border-radius: 0 12px 12px 0;
        font-size: 0.95rem;
        color: #334155;
        animation: slideDown 0.3s ease-out;
    }
    .translation-box.show {
        display: block;
    }
    .translation-box p { margin: 0 0 10px 0; line-height: 1.6; }
    .translation-box ul { margin: 0; padding-left: 20px; line-height: 1.6; list-style-type: disc;}
    .translation-box li { margin-bottom: 6px; }

    /* Hỗ trợ Dark Mode */
    body.dark-mode .translation-box {
        background-color: #1e293b;
        color: #cbd5e1;
        border-left-color: #60a5fa;
    }
    
    @keyframes slideDown {
        from { opacity: 0; transform: translateY(-10px); }
        to { opacity: 1; transform: translateY(0); }
    }
/* ========================================================
   MÀN HÌNH TẢI DỮ LIỆU (LOADING) - MẮT CHỚP HIỆN ĐẠI
   ======================================================== */
#loading-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  
  /* Nền kính mờ (Glassmorphism) cực kỳ sang trọng */
  background: rgba(248, 250, 252, 0.85); 
  backdrop-filter: blur(16px); 
  -webkit-backdrop-filter: blur(16px);
  
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  z-index: 99999;
}

/* --- HIỆU ỨNG ĐÔI MẮT (GIỮ NGUYÊN CHUYỂN ĐỘNG, LÀM ĐẸP GIAO DIỆN) --- */
.loader {
    position: relative;
    width: 108px;
    height: 48px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30px; /* Tăng khoảng cách với chữ */
}

.loader::after, .loader::before {
    content: '';
    display: inline-block;
    width: 48px;
    height: 48px;
    background-color: #ffffff;
    
    /* Tròng mắt màu hệ thống */
    background-image: radial-gradient(circle 14px, var(--primary-color) 100%, transparent 0);
    background-repeat: no-repeat;
    border-radius: 50%;
    
    /* Nâng cấp viền và thêm Hào quang bóng đổ (Glow) */
    border: 3px solid #e2e8f0;
    box-shadow: 0 10px 25px rgba(59, 130, 246, 0.18); /* Ánh sáng xanh mờ dưới mắt */
    
    animation: eyeMove 3s infinite, blink 3s infinite;
}

/* Tối ưu viền mắt khi bật Dark Mode */
body.dark-mode .loader::after, 
body.dark-mode .loader::before {
    border-color: #334155; 
    background-color: #cbd5e1; /* Xám nhạt để bớt chói */
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5);
}

@keyframes eyeMove {
    0%, 10%   { background-position: 0px 0px; }
    13%, 40%  { background-position: -15px 0px; } /* Liếc trái */
    43%, 70%  { background-position: 15px 0px; }  /* Liếc phải */
    73%, 90%  { background-position: 0px 15px; }  /* Nhìn xuống */
    93%, 100% { background-position: 0px 0px; }   /* Nhìn thẳng */
}

@keyframes blink {
    0%, 85%, 89%, 93%, 100% { height: 48px; }
    87%, 91% { height: 8px; }
}

/* --- CHỮ VÀ HIỆU ỨNG HIỆN ĐẠI (HÀI HÒA VỚI ĐÔI MẮT) --- */
#loading-overlay .brand-text {
    font-size: 1.8rem; 
    font-weight: 900; 
    letter-spacing: 1.5px;
    margin-bottom: 8px;
    
    /* Hiệu ứng Ánh sáng lướt qua chữ (Shimmering Text) */
    background: linear-gradient(90deg, var(--primary-color) 0%, #93c5fd 40%, #ffffff 50%, #93c5fd 60%, var(--primary-color) 100%);
    background-size: 200% auto;
    color: transparent;
    -webkit-background-clip: text;
    background-clip: text;
    animation: shimmer-text 2.5s linear infinite;
    
    /* Đổ bóng chữ phát sáng nhẹ nhàng */
    filter: drop-shadow(0 2px 6px rgba(59, 130, 246, 0.3));
}

#loading-overlay .loading-text {
    font-size: 0.8rem;
    font-weight: 600;
    color: #64748b;
    letter-spacing: 0.5px;
    margin: 0;
    
    /* Hiệu ứng nhịp thở lơ lửng cho dòng chữ tải */
    animation: soft-breathe 2s ease-in-out infinite;
}

/* Dấu ba chấm gõ tự động */
#loading-overlay .dots::after {
    content: '';
    animation: typing-dots 1.5s infinite steps(4, end);
}

/* --- KEYFRAMES MỚI --- */
@keyframes shimmer-text {
    to { background-position: 200% center; }
}

@keyframes soft-breathe {
    0%, 100% { opacity: 0.5; transform: translateY(0); }
    50% { opacity: 1; transform: translateY(-3px); } /* Nảy nhẹ lên 3px */
}

@keyframes typing-dots {
    0%, 20% { content: ''; }
    40% { content: '.'; }
    60% { content: '..'; }
    80%, 100% { content: '...'; }
}

/* Hỗ trợ Dark Mode cho Chữ */
body.dark-mode #loading-overlay .brand-text {
    background: linear-gradient(90deg, #60a5fa 0%, #bfdbfe 40%, #ffffff 50%, #bfdbfe 60%, #60a5fa 100%);
    background-size: 200% auto;
    -webkit-background-clip: text;
    filter: drop-shadow(0 2px 10px rgba(96, 165, 250, 0.5));
}
body.dark-mode #loading-overlay .loading-text {
    color: #94a3b8;
}
/* ================= CSS CHO KHUNG GIẢI THÍCH (THAY THẾ BẢN DỊCH) ================= */
    .explanation-detail-box {
        display: none; /* Ẩn mặc định, chỉ hiện khi bấm nút */
        background-color: #fff7ed; /* Nền cam nhạt */
        border-left: 4px solid #ea580c; /* Viền cam đậm */
        padding: 15px;
        margin-top: 15px;
        border-radius: 0 12px 12px 0;
        font-size: 0.95rem;
        color: #334155;
        animation: slideDown 0.3s ease-out;
    }
    .explanation-detail-box.show { display: block; }
    .explanation-detail-box p { margin: 0; line-height: 1.6; }

    /* Hỗ trợ Dark Mode */
    body.dark-mode .explanation-detail-box {
        background-color: #431407;
        color: #fed7aa;
        border-left-color: #ea580c;
    }
    /* ================= CSS CHO FLASHCARD (QUẸT THẺ) ================= */
.flashcard-container {
    perspective: 1000px;
    width: 100%;
    height: 350px;
    margin: 20px 0;
    cursor: pointer;
}
.flashcard-inner {
    position: relative;
    width: 100%;
    height: 100%;
    text-align: center;
    transition: transform 0.6s cubic-bezier(0.4, 0.2, 0.2, 1);
    transform-style: preserve-3d;
}
.flashcard-container.flipped .flashcard-inner {
    transform: rotateY(180deg);
}
.flashcard-front, .flashcard-back {
    position: absolute;
    width: 100%;
    height: 100%;
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: white;
    border: 2px solid #e2e8f0;
    border-radius: 20px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.05);
    padding: 20px;
}
.flashcard-back {
    transform: rotateY(180deg);
    background: #f8fafc;
    border-color: var(--primary-color);
}
.flashcard-word { font-size: 2.5rem; font-weight: 900; color: var(--primary-color); }
.flashcard-reading { font-size: 1.2rem; color: #64748b; margin-top: 10px; }
.flashcard-meaning { font-size: 1.8rem; font-weight: bold; color: #0f172a; }
.flashcard-hint { font-size: 0.85rem; color: #94a3b8; position: absolute; bottom: 20px; }

/* Nút hành động Flashcard */
.flashcard-actions { display: flex; gap: 15px; margin-top: 20px; }
.btn-fc { flex: 1; padding: 15px; border-radius: 15px; font-weight: bold; font-size: 1.1rem; border: none; cursor: pointer; transition: 0.2s; }
.btn-fc-wrong { background: #fee2e2; color: #ef4444; }
.btn-fc-wrong:active { background: #fca5a5; }
.btn-fc-right { background: #dcfce7; color: #22c55e; }
.btn-fc-right:active { background: #86efac; }

/* ================= CSS CHO NỐI TỪ (MATCH-UP) ================= */
.matchup-container { display: flex; justify-content: space-between; gap: 10px; margin-top: 20px; }
.matchup-col { display: flex; flex-direction: column; gap: 12px; width: 48%; }
.match-btn {
    padding: 16px 10px;
    background: white;
    border: 2px solid #e2e8f0;
    border-radius: 12px;
    font-weight: 600;
    font-size: 0.95rem;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
    user-select: none;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 70px;
}
.match-btn.selected { border-color: var(--primary-color); background: #e0edff; transform: scale(0.98); }
.match-btn.matched { visibility: hidden; opacity: 0; transition: visibility 0s 0.3s, opacity 0.3s; }
.match-btn.error { animation: shake-red 0.4s ease-out; background: #fee2e2; border-color: #ef4444; color: #991b1b; }

/* Hỗ trợ Dark Mode cho Game */
body.dark-mode .flashcard-front, body.dark-mode .flashcard-back { background: #1e293b; border-color: #334155; }
body.dark-mode .flashcard-meaning { color: #f8fafc; }
body.dark-mode .btn-fc-wrong { background: #450a0a; color: #fca5a5; }
body.dark-mode .btn-fc-right { background: #064e3b; color: #6ee7b7; }
body.dark-mode .match-btn { background: #1e293b; border-color: #334155; color: #cbd5e1; }
body.dark-mode .match-btn.selected { background: #172554; border-color: #3b82f6; color: white;}
/* --- CSS CHO RANK SIÊU NHỎ GỌN --- */
    .compact-rank-box {
        display: none; /* JS sẽ bật lên */
        background: #f8fafc;
        border: 1px dashed #cbd5e1;
        border-radius: 10px;
        padding: 10px 14px;
        margin-top: 15px;
    }
    
    .cr-top {
        display: flex;
        justify-content: space-between;
        align-items: center;
        font-size: 0.95rem;
        color: #475569;
        margin-bottom: 4px;
    }
    
    .cr-rank {
        font-size: 1.15rem;
        font-weight: 800;
        color: var(--primary-color);
    }
    
    .cr-score {
        font-weight: 700;
        color: #64748b;
        font-size: 0.9rem;
    }
    
    .cr-bottom {
        font-size: 0.8rem;
        color: #ea580c;
        font-weight: 500;
        display: flex;
        align-items: center;
        gap: 5px;
    }

    /* Dark Mode */
    body.dark-mode .compact-rank-box { background: #1e293b; border-color: #475569; }
    body.dark-mode .cr-top { color: #cbd5e1; }
    body.dark-mode .cr-score { color: #94a3b8; }
    body.dark-mode .cr-bottom { color: #fb923c; }
   /* ================= CSS CHO LƯỚI CHẾ ĐỘ THI (SIÊU GỌN) ================= */
    .exam-mode-grid {
        display: grid;
        grid-template-columns: repeat(2, 1fr); /* Giữ 2 cột */
        gap: 8px; /* Thu hẹp khoảng cách giữa các nút */
        margin-bottom: 12px;
    }
    
    .mode-card {
        background: #f8fafc;
        border: 1px solid #e2e8f0; /* Viền mỏng hơn */
        border-radius: 10px; /* Bo góc nhỏ lại */
        padding: 8px 10px; /* Ép mỏng chiều cao thẻ */
        cursor: pointer;
        transition: all 0.15s;
        display: flex;
        align-items: center; /* CĂN NGANG: Icon nằm cạnh chữ */
        gap: 10px;
        user-select: none;
        -webkit-tap-highlight-color: transparent;
    }

    .mode-card:active { transform: scale(0.96); }

    /* Trạng thái được chọn */
    .mode-card.selected { background: #eff6ff; border-color: var(--primary-color); box-shadow: 0 2px 8px rgba(59, 130, 246, 0.15); }
    .mode-card.special-red.selected { background: #fef2f2; border-color: #ef4444; }
    .mode-card.special-purple.selected { background: #fdf4ff; border-color: #d946ef; }

    /* Bố cục bên trong */
    .mode-icon { font-size: 1.3rem; line-height: 1; } /* Icon thu nhỏ lại */
    .mode-info { display: flex; flex-direction: column; text-align: left; }
    
    /* Chữ được làm sắc nét, gọn gàng */
    .mode-title { font-weight: 800; font-size: 0.75rem; color: #334155; line-height: 1.2; }
    .mode-desc { font-size: 0.65rem; color: #64748b; font-weight: 500; margin-top: 2px; }

    /* Đổi màu chữ khi chọn */
    .mode-card.selected .mode-title { color: var(--primary-color); }
    .mode-card.special-red.selected .mode-title { color: #ef4444; }
    .mode-card.special-purple.selected .mode-title { color: #d946ef; }

    /* --- Dark Mode --- */
    body.dark-mode .mode-card { background: #1e293b; border-color: #334155; }
    body.dark-mode .mode-title { color: #cbd5e1; }
    body.dark-mode .mode-desc { color: #64748b; }
    body.dark-mode .mode-card.selected { background: #172554; border-color: #3b82f6; }
    body.dark-mode .mode-card.selected .mode-title { color: #60a5fa; }
    body.dark-mode .mode-card.special-red.selected { background: #450a0a; border-color: #ef4444; }
    body.dark-mode .mode-card.special-red.selected .mode-title { color: #f87171; }
    body.dark-mode .mode-card.special-purple.selected { background: #4a044e; border-color: #d946ef; }
    body.dark-mode .mode-card.special-purple.selected .mode-title { color: #e879f9; }
    /* ================= CSS CHO NÚT TRỢ GIÚP 50/50 ================= */
    .btn-5050 {
        background: linear-gradient(135deg, #a855f7 0%, #7e22ce 100%);
        color: white;
        border: none;
        padding: 8px 16px;
        border-radius: 20px;
        font-size: 0.85rem;
        font-weight: bold;
        cursor: pointer;
        display: inline-flex;
        align-items: center;
        gap: 6px;
        box-shadow: 0 4px 10px rgba(168, 85, 247, 0.3);
        transition: transform 0.2s, filter 0.2s;
    }
    .btn-5050:active { transform: scale(0.95); }
    .btn-5050:disabled { 
        background: #cbd5e1; 
        box-shadow: none; 
        cursor: not-allowed; 
        color: #64748b;
    }
    body.dark-mode .btn-5050 { box-shadow: 0 4px 10px rgba(168, 85, 247, 0.1); }
    body.dark-mode .btn-5050:disabled { background: #334155; color: #94a3b8; }

    /* Hiệu ứng làm mờ và khóa click cho đáp án bị loại */
    .radio-option.eliminated {
        opacity: 0.35;
        pointer-events: none !important;
        filter: grayscale(100%);
        transform: scale(0.98);
        border-color: #e2e8f0;
        background: #f8fafc;
    }
    body.dark-mode .radio-option.eliminated {
        border-color: #334155;
        background: #0f172a;
    }
    /* ================= CSS CHO GAMIFICATION & GAME MỚI ================= */
    /* Thanh Sinh Mệnh (Hearts) & Combo */
    .game-stats-bar { display: flex; justify-content: space-between; align-items: center; padding: 10px 15px; background: white; border-bottom: 1px solid #e2e8f0; }
    .hearts { font-size: 1.3rem; letter-spacing: 2px; }
    .combo-text { font-weight: 900; color: #f59e0b; font-size: 1.1rem; opacity: 0; transition: 0.2s; transform: scale(0.8); }
    .combo-text.show { opacity: 1; transform: scale(1.2); animation: pop 0.3s ease-out forwards; }
    @keyframes pop { 50% { transform: scale(1.4); } 100% { transform: scale(1.2); } }

    /* Thanh đếm ngược Tốc độ */
    .speed-timer-container { width: 100%; height: 6px; background: #e2e8f0; }
    .speed-timer-bar { height: 100%; background: #ef4444; width: 100%; }

    /* Lưới Audio & Speed Options */
    .game-options-grid { display: grid; grid-template-columns: 1fr; gap: 12px; margin-top: 20px; padding: 0 15px; }
    .game-option-btn { padding: 16px; background: white; border: 2px solid #e2e8f0; border-radius: 12px; font-size: 1.05rem; font-weight: 600; color: #334155; transition: 0.2s; }
    .game-option-btn:active { transform: scale(0.97); }
    .game-option-btn.correct { background: #dcfce7; border-color: #22c55e; color: #166534; }
    .game-option-btn.wrong { background: #fee2e2; border-color: #ef4444; color: #991b1b; animation: shake-red 0.4s; }

    /* Nút nghe Audio to */
    .btn-audio-play { width: 80px; height: 80px; border-radius: 50%; background: var(--primary-color); color: white; font-size: 2rem; border: none; box-shadow: 0 10px 20px rgba(59, 130, 246, 0.3); margin: 20px auto; display: flex; align-items: center; justify-content: center; cursor: pointer; transition: 0.2s; }
    .btn-audio-play:active { transform: scale(0.9); }
    .btn-audio-play.playing { animation: pulse-green 1s infinite; background: #2dd4bf; box-shadow: 0 10px 20px rgba(45, 212, 191, 0.4); }

    /* Lưới 4 nút Dashboard mới */
    .vocab-game-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 10px; }
    .btn-v-game { padding: 12px 5px; font-size: 0.85rem; border-radius: 10px; font-weight: bold; border: 1px solid transparent; box-shadow: none; transition: 0.2s; cursor: pointer; }
    .btn-v-game:active { transform: scale(0.95); }

    body.dark-mode .game-stats-bar { background: #1e293b; border-color: #334155; }
    body.dark-mode .game-option-btn { background: #1e293b; border-color: #334155; color: #cbd5e1; }
    /* ================= CSS CHO NÚT AUDIO QUIZ (ĐÃ LÀM GỌN) ================= */
    .btn-audio-quiz {
        background: #e0f2fe; border: 1px solid #bae6fd; color: #0284c7;
        border-radius: 50%; width: 28px; height: 28px; font-size: 0.85rem;
        cursor: pointer; display: inline-flex; align-items: center; justify-content: center;
        transition: transform 0.2s, background 0.2s; box-shadow: 0 2px 5px rgba(2,132,199,0.15);
        margin: 0; padding: 0; line-height: 1;
    }
    .btn-audio-quiz:active { transform: scale(0.9); }
    .btn-audio-quiz.playing { animation: pulse-green 1s infinite; background: #2dd4bf; color: white; border-color: #14b8a6; }
    body.dark-mode .btn-audio-quiz { background: #1e3a8a; border-color: #1e40af; color: #93c5fd; }
    /* ================= FIX LỖI CUỘN DANH SÁCH TỪ SAI ================= */
    #screen-vocab-weak-list.active {
        display: flex !important;
        flex-direction: column !important;
        height: 100% !important;
        overflow: hidden !important; 
    }
    #screen-vocab-weak-list .top-bar {
        flex-shrink: 0;
        width: 100%;
    }
    #screen-vocab-weak-list .exam-scroll-area {
        flex: 1;
        overflow-y: auto !important;
        height: auto !important;
        display: block !important;
        padding: 20px;
        padding-bottom: 80px; /* Đẩy đáy lên để không bị khuất */
        -webkit-overflow-scrolling: touch;
    }
    /* ================= CSS CHO KHUNG CHỌN NGÔN NGỮ ================= */
    .lang-switcher {
        appearance: none;
        -webkit-appearance: none;
        background-color: #f1f5f9;
        border: 1px solid #e2e8f0;
        color: #3b82f6;
        padding: 6px 30px 6px 12px;
        border-radius: 20px;
        font-family: 'Roboto', 'Noto Sans JP', sans-serif;
        font-size: 0.85rem;
        font-weight: 700;
        cursor: pointer;
        outline: none;
        transition: all 0.2s ease;
        /* Custom mũi tên sổ xuống cho đẹp */
        background-image: url('data:image/svg+xml;utf8,<svg fill="%233b82f6" height="20" viewBox="0 0 24 24" width="20" xmlns="http://www.w3.org/2000/svg"><path d="M7 10l5 5 5-5z"/></svg>');
        background-repeat: no-repeat;
        background-position: right 6px center;
        box-shadow: 0 2px 5px rgba(0,0,0,0.02);
    }
    .lang-switcher:hover { background-color: #e2e8f0; }

    /* Chế độ ban đêm cho Dropdown */
    body.dark-mode .lang-switcher {
        background-color: #1e293b;
        border-color: #334155;
        color: #60a5fa;
        background-image: url('data:image/svg+xml;utf8,<svg fill="%2360a5fa" height="20" viewBox="0 0 24 24" width="20" xmlns="http://www.w3.org/2000/svg"><path d="M7 10l5 5 5-5z"/></svg>');
    }
    .theme-box {
              background: #f8fafc; border: 1px solid #e2e8f0; padding: 4px 12px; 
              border-radius: 20px; display: flex; align-items: center; justify-content: center; margin: 0;
          }
    body.dark-mode .theme-box { background: #1e293b; border-color: #334155; }
    
    .id-badge {
        font-size: 0.85rem; color: #1d4ed8; font-weight: 800; 
        background: linear-gradient(135deg, #dbeafe 0%, #eff6ff 100%); 
        border: 1px solid #bfdbfe; display: inline-flex; align-items: center; gap: 5px; 
        padding: 4px 10px; border-radius: 8px; box-shadow: 0 2px 6px rgba(59, 130, 246, 0.15);
    }
    body.dark-mode .id-badge {
        background: linear-gradient(135deg, #1e3a8a 0%, #172554 100%);
        border-color: #1e40af; color: #93c5fd;
    }
    
    .student-name-highlight {
        font-size: 1.45rem; font-weight: 900; line-height: 1.2; 
        color: var(--primary-color); text-transform: uppercase; 
        letter-spacing: 0.5px;
    }

    /* ========================================================= */
    /* --- BỔ SUNG CSS ANIMATION CHO NGỌN LỬA VÀ BÀN TAY --- */
    /* ========================================================= */
    
    /* 1. HIỆU ỨNG CHÁY CỦA LỬA (Pulsing & Bực sáng) */
    .animate-flame {
        display: inline-block;
        animation: flamePulsing 1.8s infinite ease-in-out;
        filter: drop-shadow(0 0 2px #f97316); /* Tạo quầng sáng mờ màu cam */
    }
    @keyframes flamePulsing {
        0%, 100% { transform: scale(1); filter: drop-shadow(0 0 2px #f97316) brightness(1); }
        50% { transform: scale(1.15) translateY(-1px); filter: drop-shadow(0 0 6px #ea580c) brightness(1.2); }
    }
    
    /* 2. HIỆU ỨNG BÀN TAY VẪY (Lắc) */
    .animate-hand {
        display: inline-block;
        transform-origin: 70% 70%; /* Đặt tâm xoay ở cổ tay */
        animation: handWaving 2.5s infinite;
    }
    @keyframes handWaving {
          0% { transform: rotate( 0.0deg); }
        10% { transform: rotate(14.0deg); } /* Vẫy sang phải nhanh */
        20% { transform: rotate(-8.0deg); } /* Trả về trái nhẹ */
        30% { transform: rotate(14.0deg); }
        40% { transform: rotate(-4.0deg); }
        50% { transform: rotate(10.0deg); }
        60% { transform: rotate( 0.0deg); } /* Về vị trí cũ và nghỉ */
        100% { transform: rotate( 0.0deg); }
    }
    /* ========================================================= */
    /* --- CSS CHO LỊCH SỬ ACCORDION & CHỈ DẪN TRÊN MOBILE --- */
    /* ========================================================= */
    .history-section { margin-top: 15px; }
    .mobile-only-icon {
        display: none;
        transition: transform 0.3s ease;
    }
    .mobile-scroll-cue {
        display: none; 
    }

    @media (max-width: 768px) {
        .history-section { margin-top: 5px; }
        
        /* 1. NÚT LỊCH SỬ SIÊU GỌN */
       .history-header {
           display: flex; justify-content: flex-start; align-items: center; gap: 8px;
            background: transparent; /* Xóa nền trắng */
            padding: 8px 4px; /* Giãn padding một chút cho dễ bấm */
            border: none; /* Xóa viền */
            box-shadow: none; /* Xóa bóng đổ */
            cursor: pointer; 
            margin-bottom: 0px;
        }
        .history-header label {
            font-size: 0.85rem !important; 
            font-weight: 700 !important;
            color: #64748b !important; 
            margin: 0;
            display: flex; align-items: center; gap: 8px;
            text-transform: uppercase; letter-spacing: 0.5px;
        }
        .mobile-only-icon { 
            display: block; font-size: 0.75rem; color: #94a3b8; 
        }
        .history-mobile-hidden { display: none; }
        .history-mobile-hidden.show {
            display: block; animation: fadeIn 0.3s ease; margin-bottom: 15px;
        }

        /* 2. KHUNG CHỈ DẪN DÙNG MÀU XANH HỆ THỐNG (PRIMARY COLOR) */
        .mobile-scroll-cue {
            display: flex; flex-direction: row; align-items: center; justify-content: center;
            gap: 6px; 
            margin-top: 0px; /* Đẩy sát lên trên */
            margin-bottom: 0px;
            padding: 6px 16px;
            background: #eff6ff; /* Màu nền xanh nhạt của hệ thống */
            border: 1px solid #bfdbfe; /* Viền xanh nhạt đồng bộ */
            border-radius: 20px; 
            box-shadow: 0 2px 8px rgba(59, 130, 246, 0.1); /* Bóng đổ xanh nhẹ */
            width: fit-content;
            margin-left: auto; margin-right: auto;
            animation: floatingCue 1.5s infinite ease-in-out;
        }
        .mobile-scroll-cue .cue-text {
            font-size: 0.75rem; color: #2563eb; /* Màu chữ xanh đậm (đẹp và dễ đọc) */
            font-weight: 700;
        }
        .css-chevron-down {
            width: 6px; height: 6px;
            border-right: 2px solid #2563eb;
            border-bottom: 2px solid #2563eb;
            transform: rotate(45deg);
            margin-bottom: 2px;
        }
        @keyframes floatingCue {
            0%, 100% { transform: translateY(0); }
            50% { transform: translateY(4px); }
        }
    }

    /* --- CSS THỨ HẠNG CÁ NHÂN: HÀI HÒA VỚI HỆ THỐNG --- */
    .my-rank-highlight {
        /* Nền xanh cực nhẹ tạo cảm giác sạch sẽ */
        background: linear-gradient(135deg, #f0f7ff 0%, #e0efff 100%) !important;
        /* Viền xanh Primary đồng bộ với nút bấm */
        border: 1px solid #bfdbfe !important;
        border-left: 5px solid var(--primary-color) !important; 
        box-shadow: 0 4px 12px rgba(59, 130, 246, 0.08) !important;
        transform: scale(1);
        margin-bottom: 8px; /* Giảm khoảng cách để thanh tiến độ trồi lên */
        margin-top: 5px;    /* Đảm bảo có khoảng hở nhỏ với lời chào */
        border-radius: 12px !important;
    }
    
    /* Chữ bên trong dùng màu xanh đậm chuyên nghiệp */
    .my-rank-highlight .cr-rank {
        color: var(--primary-color) !important;
        font-size: 1.2rem;
    }
    
    .my-rank-highlight .cr-score {
        color: #1e40af !important; /* Xanh đậm */
    }

    .my-rank-highlight .cr-bottom {
        color: #1d4ed8 !important;
        background: rgba(255, 255, 255, 0.5);
        padding: 4px 8px;
        border-radius: 6px;
        display: inline-flex;
    }

    /* --- Tương thích Dark Mode --- */
    body.dark-mode .my-rank-highlight {
        background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%) !important;
        border-color: #334155 !important;
        border-left-color: var(--primary-color) !important;
    }
    body.dark-mode .my-rank-highlight .cr-score,
    body.dark-mode .my-rank-highlight div {
        color: #f1f5f9 !important;
    }
    /* --- STYLE DÒNG FOOTER TỐI GIẢN --- */
.footer-brand-simple {
    text-align: center;
    font-size: 0.65rem;      /* Kích thước siêu nhỏ */
    font-weight: 700;
    color: #cbd5e1;          /* Màu xám nhạt ở chế độ sáng */
    letter-spacing: 2px;     /* Giãn chữ cho sang trọng */
    text-transform: uppercase;
    margin-top: 15px;        /* Khoảng cách với nội dung trên */
    padding-bottom: 5px;
    transition: color 0.3s ease;
}

/* Đổi màu chữ khi ở Dark Mode */
body.dark-mode .footer-brand-simple {
    color: #475569;          /* Màu xám đậm hơn một chút để chìm vào nền tối */
}
/* ========================================================
       CẤU HÌNH MODAL BẬT LÊN (CONFIRM / PROMPT)
  ======================================================== */
    /* Lớp phủ nền tối mờ */
    .custom-overlay {
        display: none; 
        position: fixed; 
        top: 0; left: 0; width: 100%; height: 100%;
        background: rgba(15, 23, 42, 0.4); /* Màu xanh đen nhạt */
        backdrop-filter: blur(4px);
        -webkit-backdrop-filter: blur(4px);
        z-index: 10001; 
        align-items: center; 
        justify-content: center;
        opacity: 0;
        transition: opacity 0.3s ease;
    }

    /* Khung Modal chính */
    .custom-modal {
        background: white; 
        padding: 26px 22px; 
        border-radius: 24px; 
        width: 85%; 
        max-width: 360px; 
        text-align: center; 
        box-shadow: 0 20px 50px rgba(0,0,0,0.15);
        /* Chuẩn bị cho hiệu ứng trượt từ dưới lên và phóng to */
        transform: scale(0.9) translateY(20px);
        opacity: 0;
        transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    }

    /* Class kích hoạt khi Modal hiện lên */
    .custom-overlay.modal-active {
        display: flex;
        opacity: 1;
    }
    .custom-overlay.modal-active .custom-modal {
        transform: scale(1) translateY(0);
        opacity: 1;
    }

    /* Định dạng Text bên trong */
    .modal-title { margin: 0 0 10px 0; color: var(--primary-color); font-size: 1.25rem; font-weight: 800; }
    .modal-desc { margin: 0 0 20px 0; color: #64748b; font-size: 0.95rem; line-height: 1.5; white-space: pre-wrap; }
    
    /* Vùng chứa nút bấm */
    .modal-actions { display: flex; gap: 12px; justify-content: center; }
    .modal-actions .btn { flex: 1; margin: 0; padding: 14px 0; border-radius: 14px; font-size: 0.95rem; }
    
    /* Nút màu đỏ (Nguy hiểm / Báo lỗi) */
    .btn-danger { background: var(--danger-color); color: white; box-shadow: 0 4px 12px rgba(239, 68, 68, 0.3); border: none;}
    .btn-danger:active { transform: scale(0.95); }

    /* Ô nhập Text báo lỗi */
    .modal-textarea {
        width: 100%; padding: 14px; border: 1px solid #e2e8f0; border-radius: 14px; 
        outline: none; font-size: 0.95rem; resize: none; margin-bottom: 20px; 
        color: #1e293b; background: #f8fafc; transition: all 0.2s;
        font-family: inherit;
    }
    .modal-textarea:focus { border-color: var(--primary-color); background: white; box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15); }

    /* --- Hỗ trợ Dark Mode --- */
    body.dark-mode .custom-modal { background: #1e293b; border: 1px solid #334155; box-shadow: 0 20px 50px rgba(0,0,0,0.5); }
    body.dark-mode .modal-desc { color: #cbd5e1; }
    body.dark-mode .modal-textarea { background: #0f172a; border-color: #334155; color: #f1f5f9; }
    body.dark-mode .modal-textarea:focus { border-color: var(--primary-color); }
   /* ========================================================
       HIỆU ỨNG MÀN HÌNH KẾT QUẢ (PREMIUM RESULT SCREEN)
       ======================================================== */
    
    /* ================= 1. HIỆU ỨNG CHUNG & THI ĐỖ (GIỮ NGUYÊN) ================= */
    /* Hiệu ứng nảy cho Vòng tròn điểm */
    @keyframes scorePopIn {
        0% { opacity: 0; transform: scale(0.5) translateY(20px); }
        60% { opacity: 1; transform: scale(1.05) translateY(-5px); }
        100% { opacity: 1; transform: scale(1) translateY(0); }
    }

    /* Hiệu ứng trượt lên mượt mà cho Text và Nút */
    @keyframes slideUpFade {
        0% { opacity: 0; transform: translateY(20px); }
        100% { opacity: 1; transform: translateY(0); }
    }

    /* Trạng thái Đậu: Vòng tròn tỏa hào quang */
    .score-circle-modern.is-pass {
        box-shadow: 0 0 30px rgba(34, 197, 94, 0.3);
    }

    /* Gắn Animation chung vào các Element khi màn hình Active */
    #screen-result.active .score-circle-modern {
        animation: scorePopIn 0.6s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
    }
    
    #screen-result.active #resultText {
        animation: slideUpFade 0.5s ease forwards;
        animation-delay: 0.2s; /* Trễ một chút so với vòng tròn */
        opacity: 0; 
    }
    
    #screen-result.active #percentageText {
        animation: slideUpFade 0.5s ease forwards;
        animation-delay: 0.3s;
        opacity: 0;
    }
    
    #screen-result.active .btn-primary {
        animation: slideUpFade 0.5s ease forwards;
        animation-delay: 0.4s;
        opacity: 0;
    }

    #screen-result.active .btn-secondary {
        animation: slideUpFade 0.5s ease forwards;
        animation-delay: 0.5s;
        opacity: 0;
    }

 /* ========================================================
       2. HIỆU ỨNG THI TRƯỢT (MƯA PHÙN U ÁM - CINEMATIC)
       ======================================================== */
    /* Làm nền xung quanh mờ đi và xám lại (Sương mù) */
    #screen-result.gloomy-rain-bg {
        /* 👉 ĐÃ SỬA: Giảm độ đen của nền, tăng độ sáng (brightness) lên 75% thay vì 50% */
        background-color: rgba(30, 41, 59, 0.6) !important; 
        backdrop-filter: blur(5px) grayscale(60%) brightness(75%);
        -webkit-backdrop-filter: blur(5px) grayscale(60%) brightness(75%);
        transition: all 1.5s ease-in-out;
    }

    /* ÉP THẺ KẾT QUẢ SANG TÔNG TỐI MỜ */
    #screen-result.gloomy-rain-bg .card {
        /* 👉 ĐÃ SỬA: Dùng màu xám tối nhẹ nhàng (#2a364a) thay vì xanh đen đậm */
        background-color: #2a364a !important; 
        border: 1px solid #475569;
        box-shadow: 0 15px 40px rgba(0, 0, 0, 0.3) !important; 
        transition: all 1.5s ease-in-out;
    }

    /* Làm tối phần bên trong vòng tròn điểm số */
    #screen-result.gloomy-rain-bg .score-circle-modern::before {
        background-color: #1e293b !important; 
        transition: all 1.5s ease-in-out;
    }

    /* Đổi màu chữ điểm số thành trắng sáng */
    #screen-result.gloomy-rain-bg .score-text-inner {
        color: #f8fafc !important;
        transition: color 1.5s ease-in-out;
    }

    /* Đổi màu chữ tỷ lệ phần trăm */
    #screen-result.gloomy-rain-bg #percentageText {
        color: #94a3b8 !important;
    }

    /* Đổi màu chữ kết quả (TOANG NHẸ) cho nổi bật trên nền tối */
    #screen-result.gloomy-rain-bg #resultText {
        color: #fb7185 !important; /* Màu hồng nhạt */
    }

    /* Dùng pseudo-element ::after để tạo một lớp sương mờ phủ lên trên toàn màn hình */
    #screen-result.gloomy-rain-bg::after {
        content: "";
        position: absolute;
        top: -20%; left: -20%; right: -20%; bottom: -20%; 
        pointer-events: none; 
        z-index: 100; 
        
        /* 👉 ĐÃ SỬA: Giảm độ đen của lớp phủ (0.4 thay vì 0.65), sương mù xám nhạt hơn */
        background: 
            rgba(15, 23, 42, 0.4), 
            radial-gradient(circle at 30% 50%, rgba(100, 116, 139, 0.5) 0%, transparent 50%),
            radial-gradient(circle at 70% 80%, rgba(71, 85, 105, 0.5) 0%, transparent 60%),
            radial-gradient(circle at 60% 20%, rgba(51, 65, 85, 0.4) 0%, transparent 50%);
            
        filter: blur(25px); 
        opacity: 0;
        animation: 
            mistFadeIn 2s ease-out forwards,
            driftingMist 15s infinite alternate ease-in-out;
    }

    /* Hiển thị sương từ từ để không bị sốc */
    @keyframes mistFadeIn {
        from { opacity: 0; }
        to { opacity: 1; }
    }

    /* Sương mù trôi lững lờ theo đường chéo và hơi phình ra thu vào */
    @keyframes driftingMist {
        0% { transform: translate(-5%, -5%) scale(1); }
        50% { transform: translate(5%, 2%) scale(1.05); }
        100% { transform: translate(-2%, 5%) scale(1.1); }
    }

    /* Hiệu ứng thở dài (Deflate): Phồng nhẹ -> Xẹp xuống */
    @keyframes failSigh {
        0% { transform: scale(1); opacity: 1; }
        30% { transform: scale(1.05); } 
        100% { transform: scale(0.95); opacity: 0.85; } 
    }

    /* Hiệu ứng phai màu chữ */
    @keyframes textFadeDim {
        0% { opacity: 1; filter: saturate(100%); }
        100% { opacity: 0.8; filter: saturate(60%); }
    }

    /* Trạng thái Trượt của Vòng tròn điểm */
    .score-circle-modern.is-fail {
        animation: failSigh 0.8s ease-out forwards !important;
        box-shadow: 0 0 15px rgba(100, 116, 139, 0.2), 0 0 40px rgba(71, 85, 105, 0.3);
        border-color: #475569 !important; 
        filter: saturate(40%) brightness(0.9); 
    }
    
    .is-fail-text {
        animation: textFadeDim 0.8s ease-out forwards !important; 
    }
/* ========================================================
   THANH ĐIỀU HƯỚNG DƯỚI (BOTTOM NAV) - HIỆN ĐẠI & NHỎ GỌN
   ======================================================== */
.bottom-nav.modern-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  width: 100%;
  
  /* Hiệu ứng kính mờ */
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid #e2e8f0;
  
  display: none;
  justify-content: space-between;
  align-items: center;
  gap: 8px; /* Giảm gap để gọn hơn */
  
  /* ÉP MỎNG THANH NAV: Giảm padding trên/dưới xuống còn 6px */
  padding: 6px 10px calc(6px + env(safe-area-inset-bottom));
  box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.05);
  z-index: 9999;
}

.modern-nav .nav-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: none;
  border-radius: 10px; /* Bo góc nhỏ lại một chút cho cân đối */
  font-family: inherit;
  font-weight: 700;
  cursor: pointer;
  /* ÉP MỎNG NÚT: Giảm chiều cao từ 50px xuống 42px */
  height: 36px; 
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  margin: 0 !important;
}

.modern-nav .nav-btn:active {
  transform: scale(0.92);
}

/* Nút Lùi/Tiến (Hành động phụ) */
.modern-nav .nav-icon-btn {
  flex: 0 0 40px; /* Thu nhỏ bề ngang nút icon */
  background: #f1f5f9;
  color: #64748b;
}

.modern-nav .nav-icon-btn svg {
  width: 18px; /* Thu nhỏ icon */
  height: 18px;
}

/* Nút Nộp bài (Hành động chính) */
.modern-nav .nav-submit-btn {
  flex: 1;
  /* Sử dụng màu xanh dương hệ thống (giống btn-primary) */
  background: linear-gradient(135deg, #3b82f6 0%, #1d4ed8 100%);
  color: white;
  font-size: 0.95rem; /* Chữ nhỏ lại một chút cho thanh lịch */
  letter-spacing: 0.5px;
  
  /* ÁP DỤNG HIỆU ỨNG NHỊP THỞ (PULSE) ĐÃ CÓ SẴN TRONG FILE GỐC */
  animation: pulse-blue 2s infinite; 
}

/* ========================================================
   HỖ TRỢ DARK MODE
   ======================================================== */
body.dark-mode .bottom-nav.modern-nav {
  background: rgba(30, 41, 59, 0.92); 
  border-top-color: #334155;
}

body.dark-mode .modern-nav .nav-icon-btn {
  background: #334155;
  color: #cbd5e1;
}

/* ================= BONG BÓNG CHỈ DẪN OPE 100 ================= */
    .ope-guide-bubble {
        position: absolute;
        bottom: calc(100% + 10px); 
        left: 50%;
        transform: translateX(-50%);
        background: linear-gradient(135deg, #a855f7 0%, #7e22ce 100%);
        color: white;
        padding: 8px 11px;
        border-radius: 12px;
        font-size: 0.8rem;
        font-weight: 700;
        width: max-content;
        max-width: 250px; 
        text-align: center; 
        line-height: 1.4; 
        z-index: 100;
        box-shadow: 0 4px 15px rgba(168, 85, 247, 0.5);
        pointer-events: none;
        opacity: 1;
        transition: opacity 0.5s ease-out;
        animation: ope-guide-bob 1s ease-in-out infinite;
    }

    @keyframes ope-guide-bob {
        0%, 100% { transform: translateX(-50%) translateY(0); }
        50% { transform: translateX(-50%) translateY(-6px); }
    }

    .ope-guide-bubble.hide-bubble { opacity: 0; }
    
    .ope-guide-bubble::after {
        content: '';
        position: absolute;
        bottom: -5px;
        left: 50%;
        transform: translateX(-50%);
        border-width: 5px 5px 0;
        border-style: solid;
        border-color: #7e22ce transparent transparent transparent;
    }

    /* ================= GIAO DIỆN MODAL CHỌN Phần OPE 100 ================= */
    .ope-modal {
        max-width: 420px !important;
        padding: 0 !important; 
        overflow: hidden;
        display: flex;
        flex-direction: column;
    }
    
    .ope-modal-header {
        background: #f8fafc;
        padding: 20px 24px;
        border-bottom: 1px solid #e2e8f0;
        display: flex;
        justify-content: space-between;
        align-items: center;
        text-align: left;
    }
    .ope-modal-header h3 { margin: 0; font-size: 1.15rem; font-weight: 800; color: #1e293b; }
    .ope-modal-header p { margin: 4px 0 0 0; font-size: 0.8rem; color: #64748b; font-weight: 500; }
    
    .close-modal-btn {
        background: #e2e8f0; border: none; width: 34px; height: 34px; border-radius: 50%;
        font-size: 1.4rem; display: flex; align-items: center; justify-content: center;
        color: #64748b; cursor: pointer; transition: 0.2s; padding-bottom: 3px;
    }
    .close-modal-btn:active { transform: scale(0.9); background: #cbd5e1; }

    /* Lưới chứa các nút - Responsive tự động xếp cột */
    .ope-chunks-grid {
        display: grid;
        grid-template-columns: repeat(auto-fill, minmax(80px, 1fr)); 
        gap: 12px;
        padding: 20px 24px 30px 24px;
        overflow-y: auto;
        max-height: 55vh;
        scrollbar-width: thin; 
        scrollbar-color: #cbd5e1 transparent;
    }
    
    .ope-chunks-grid::-webkit-scrollbar { width: 6px; }
    .ope-chunks-grid::-webkit-scrollbar-track { background: transparent; }
    .ope-chunks-grid::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 10px; }

    /* Thiết kế Nút Chọn Phần Hiện Đại */
    .chunk-btn {
        background: white; color: #475569; border: 2px solid #e2e8f0;
        border-radius: 12px; padding: 12px 5px; font-size: 0.95rem; font-weight: 700;
        cursor: pointer; transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
        display: flex; align-items: center; justify-content: center;
        box-shadow: 0 2px 5px rgba(0,0,0,0.02);
        user-select: none; -webkit-tap-highlight-color: transparent;
        position: relative;
    }
    
    /* Hiệu ứng Hover mượt mà (Chỉ trên PC) */
    @media (hover: hover) {
        .chunk-btn:hover {
            border-color: #93c5fd; background: #f0f9ff; color: #2563eb;
            transform: translateY(-2px);
            box-shadow: 0 4px 10px rgba(59, 130, 246, 0.15);
        }
    }

    .chunk-btn:active { transform: scale(0.92); }

    /* Nút khi được bấm (Active Gradient) */
    .chunk-btn.active {
        background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
        color: white; border-color: transparent;
        box-shadow: 0 4px 15px rgba(37, 99, 235, 0.35);
    }

    /* 👉 NÚT ĐÃ HOÀN THÀNH: Đánh dấu viền màu hệ thống & Icon V */
    .chunk-btn.is-completed {
        border-color: var(--primary-color);
        background: #f0f9ff; /* Nền xanh siêu nhạt */
        color: var(--primary-color);
    }
    /* Thêm dấu tick xanh nho nhỏ ở góc */
    .chunk-btn.is-completed::after {
        content: '✓';
        position: absolute;
        top: -6px;
        right: -6px;
        background: var(--primary-color);
        color: white;
        font-size: 0.6rem;
        width: 16px;
        height: 16px;
        display: flex;
        align-items: center;
        justify-content: center;
        border-radius: 50%;
        box-shadow: 0 2px 4px rgba(59, 130, 246, 0.4);
    }

    /* 🌙 Cân bằng màu cho chế độ tối (Dark Mode) */
    body.dark-mode .ope-modal-header { background: #0f172a; border-color: #334155; }
    body.dark-mode .ope-modal-header h3 { color: #f1f5f9; }
    body.dark-mode .ope-modal-header p { color: #94a3b8; }
    body.dark-mode .close-modal-btn { background: #334155; color: #cbd5e1; }
    body.dark-mode .close-modal-btn:active { background: #475569; }
    body.dark-mode .chunk-btn { background: #1e293b; color: #cbd5e1; border-color: #334155; box-shadow: none;}
    @media (hover: hover) { body.dark-mode .chunk-btn:hover { border-color: #60a5fa; background: #172554; color: #93c5fd; } }
    body.dark-mode .chunk-btn.active { background: linear-gradient(135deg, #3b82f6 0%, #1d4ed8 100%); box-shadow: 0 4px 15px rgba(59, 130, 246, 0.4); }
    body.dark-mode .chunk-btn.is-completed { border-color: #60a5fa; background: #172554; color: #93c5fd; }
    /* ================= THANH FOOTER & NÚT BẮT ĐẦU OPE ================= */
    .ope-modal-footer {
        padding: 16px 24px 24px 24px;
        background: #f8fafc;
        border-top: 1px solid #e2e8f0;
        box-shadow: 0 -4px 10px rgba(0,0,0,0.02);
    }
    
    /* Trạng thái nút SẴN SÀNG (Sử dụng màu hệ thống) */
    #btn-start-ope {
        background: var(--primary-color) !important; /* Dùng biến màu hệ thống */
        background-image: linear-gradient(135deg, var(--primary-color) 0%, #2563eb 100%) !important; /* Gradient sang trọng */
        color: white !important;
        border: none;
        box-shadow: 0 4px 15px rgba(59, 130, 246, 0.4) !important;
        transition: all 0.3s ease;
    }

    #btn-start-ope:active {
        transform: scale(0.95);
    }

    /* Trạng thái nút BỊ KHÓA (Khi chưa chọn Phần nào) */
    #btn-start-ope:disabled {
        background: #cbd5e1 !important;
        background-image: none !important; /* Tắt gradient khi khóa */
        color: #f1f5f9 !important;
        box-shadow: none !important;
        cursor: not-allowed;
        transform: scale(1) !important;
        animation: none !important;
    }

    /* 🌙 Cân bằng màu cho Dark Mode */
    body.dark-mode .ope-modal-footer {
        background: #0f172a;
        border-top-color: #334155;
    }
    body.dark-mode #btn-start-ope:disabled {
        background: #334155 !important;
        color: #64748b !important;
    }
  

    /* ================= SETUP SCREEN STYLES ================= */
    .setup-group { margin-bottom: 20px; }
    .setup-label {
        display: block;
        font-size: 0.85rem;
        font-weight: 800;
        color: #64748b;
        margin-bottom: 10px;
        letter-spacing: 0.5px;
    }
    
    .setup-modes-grid {
        display: grid;
        grid-template-columns: repeat(3, 1fr);
        gap: 10px;
        margin-bottom: 15px;
    }
    
    .s-mode-card {
        background: white;
        border: 1px solid #e2e8f0;
        border-radius: 12px;
        padding: 12px 5px;
        text-align: center;
        cursor: pointer;
        transition: all 0.2s;
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 5px;
    }
    
    .s-mode-card.selected {
        border-color: var(--primary-color);
        background: #eff6ff;
        transform: translateY(-2px);
        box-shadow: 0 4px 12px rgba(59, 130, 246, 0.15);
    }
    
    .s-mode-card .sm-icon { font-size: 1.5rem; }
    .s-mode-card .sm-text { font-size: 0.75rem; font-weight: 700; color: #475569; }
    .s-mode-card.selected .sm-text { color: var(--primary-color); }
    
    .setup-input {
        width: 100%;
        padding: 12px;
        border: 2px solid #e2e8f0;
        border-radius: 10px;
        text-align: center;
        font-size: 1.1rem;
        font-weight: bold;
        color: var(--primary-color);
    }
    
    .setup-input:focus { border-color: var(--primary-color); }

    /* Slider styling */
    input[type=range] {
        -webkit-appearance: none;
        width: 100%;
        height: 6px;
        background: #e2e8f0;
        border-radius: 5px;
        outline: none;
    }
    
    input[type=range]::-webkit-slider-thumb {
        -webkit-appearance: none;
        width: 20px;
        height: 20px;
        background: var(--primary-color);
        border-radius: 50%;
        cursor: pointer;
        box-shadow: 0 0 10px rgba(59, 130, 246, 0.3);
    }

    body.dark-mode .s-mode-card {
        background: #1e293b;
        border-color: #334155;
    }
    body.dark-mode .s-mode-card.selected {
        background: #172554;
        border-color: #60a5fa;
    }
    body.dark-mode .s-mode-card .sm-text { color: #94a3b8; }
    body.dark-mode .s-mode-card.selected .sm-text { color: #60a5fa; }
    body.dark-mode .setup-input { background: #0f172a; border-color: #334155; }
    body.dark-mode #setup-timeline-preview { color: #94a3b8 !important; }
