@charset "UTF-8";

/* Cấu hình biến màu sắc cho Light/Dark Mode */
:root {
   --writer-bg: #fffdf2;
   --writer-border: #e0e0e0;
   --card-bg: #ffffff;
   --card-shadow: 0 4px 10px rgba(0, 0, 0, 0.06);
   --card-hover-shadow: 0 10px 20px rgba(0, 0, 0, 0.12);
   --card-border: 1px solid rgba(0, 0, 0, 0.05);
   --chat-left-bg: #ffffff;
   --chat-right-bg: #f0f7ff;
}
[data-bs-theme="dark"] {
   --writer-bg: #1e2125;
   --writer-border: #495057;
   --card-bg: #2b3035; /* Sáng hơn màu nền body (#212529) để thẻ nổi lên */
   --card-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
   --card-hover-shadow: 0 10px 20px rgba(0, 0, 0, 0.5);
   --card-border: 1px solid rgba(255, 255, 255, 0.08);
   --chat-left-bg: #2b3035;
   --chat-right-bg: #1c2b39; /* Xanh đen nhẹ, tránh trùng màu đỏ của chữ */
}

html {
   overflow-x: clip; /* Sửa lỗi để position: sticky có thể hoạt động */
   scroll-behavior: smooth;
}

/* Mobile-First CSS */
body {
   background-color: var(--bs-body-bg);
   color: var(--bs-body-color);
   transition: background-color 0.3s, color 0.3s;
   line-height: 1.4;
   overflow-x: clip; /* Đổi hidden thành clip để sửa lỗi thanh cuộn dính */
   width: 100%;
   position: relative;
   padding-top: 60px; /* Bù không gian cho thanh Navbar cố định (fixed-top) */
}

/* Tùy chỉnh thanh cuộn (Scrollbar) hiện đại */
::-webkit-scrollbar {
   width: 6px;
   height: 6px;
}
::-webkit-scrollbar-track {
   background: transparent;
}
::-webkit-scrollbar-thumb {
   background: rgba(0, 0, 0, 0.2);
   border-radius: 10px;
}
::-webkit-scrollbar-thumb:hover {
   background: rgba(0, 0, 0, 0.4);
}
[data-bs-theme="dark"] ::-webkit-scrollbar-thumb {
   background: rgba(255, 255, 255, 0.2);
}

/* Hiệu ứng thanh Navbar Glassmorphism & Điều Hướng */
.navbar {
   backdrop-filter: blur(12px);
   -webkit-backdrop-filter: blur(12px);
   background-color: rgba(255, 255, 255, 0.85) !important;
   transition: all 0.3s ease;
   border-bottom: 1px solid rgba(0,0,0,0.05);
}
[data-bs-theme="dark"] .navbar {
   background-color: rgba(33, 37, 41, 0.85) !important;
   border-bottom: 1px solid rgba(255,255,255,0.05);
}
.navbar.shadow-sm {
   box-shadow: 0 4px 20px rgba(0, 0, 0, 0.05) !important;
}

.radical-card {
   border: var(--card-border) !important;
   border-radius: 10px;
   box-shadow: var(--card-shadow) !important;
   transition: transform 0.2s, box-shadow 0.2s, background-color 0.3s, border-color 0.3s;
   background-color: var(--card-bg) !important;
   cursor: pointer;
}

.radical-card:hover, .module-card:hover {
   transform: translateY(-5px);
   box-shadow: var(--card-hover-shadow) !important;
}

.topic-card {
   background-color: var(--card-bg) !important;
   border: var(--card-border) !important;
   box-shadow: var(--card-shadow) !important;
}
.topic-card:hover {
   transform: translateY(-4px);
   box-shadow: var(--card-hover-shadow) !important;
}

.module-card {
   background-color: var(--card-bg) !important;
   border: var(--card-border) !important;
   box-shadow: var(--card-shadow) !important;
}

/* Hiệu ứng chọn Thẻ từ vựng trong Bài Khóa */
.vocab-item-card {
   cursor: pointer;
   transition: all 0.2s ease-in-out;
   border: 2px solid transparent !important;
}

/* Lớp CSS dùng chung cho tất cả các chữ tiếng Trung */
.zh-text {
   font-family: 'KaiTi', 'STKaiti', serif !important;
}

.character-display {
   font-size: 2.2rem;
   font-weight: bold;
   color: #d32f2f;
   font-family: 'KaiTi', 'STKaiti', serif;
}

.hanzi-writer-box {
   display: flex;
   justify-content: center;
   background: var(--writer-bg);
   border: 2px dashed var(--writer-border);
   border-radius: 10px;
   padding: 10px;
   margin-bottom: 15px;
}

/* Hiệu ứng 3D Flashcard */
.flip-card {
   background-color: transparent;
   width: 100%;
   max-width: 350px;
   height: 350px;
   perspective: 1000px;
   margin: 0 auto;
   cursor: pointer;
   user-select: none; /* Ngăn bôi đen văn bản khi vuốt bằng chuột trên máy tính */
   touch-action: pan-y; /* Ngăn trình duyệt tự động cuộn ngang hoặc chuyển trang khi vuốt */
}
@media (max-width: 767.98px) {
   .flip-card {
      height: 300px; /* Thu gọn chiều cao thẻ trên di động để vừa màn hình hơn */
   }
}
.flip-card-inner {
   position: relative;
   width: 100%;
   height: 100%;
   text-align: center;
   transition: transform 0.6s;
   transform-style: preserve-3d;
   will-change: transform; /* Giữ thẻ luôn xử lý bằng GPU để không bị mờ chữ sau khi lật */
}
.flip-card.flipped .flip-card-inner {
   transform: rotateY(180deg);
}
.flip-card-front, .flip-card-back {
   position: absolute;
   width: 100%;
   height: 100%;
   -webkit-backface-visibility: hidden;
   backface-visibility: hidden;
   border-radius: 20px;
   box-shadow: 0 10px 20px rgba(0,0,0,0.1);
   display: flex;
   flex-direction: column;
   justify-content: center;
   align-items: center;
   padding: 20px;
   -webkit-font-smoothing: antialiased;
   -moz-osx-font-smoothing: grayscale;
}
.flip-card-front {
   background-color: var(--card-bg);
   transform: rotateY(0deg);
}
.flip-card-back {
   background-color: var(--writer-bg);
   transform: rotateY(180deg);
   border: 2px dashed var(--writer-border);
}

/* =========================================
   CHAT BUBBLES (MODULE GIAO TIẾP)
   ========================================= */
.chat-container { display: flex; flex-direction: column; gap: 10px; margin-bottom: 30px; }
@media (max-width: 767.98px) {
   .chat-container { gap: 8px; margin-bottom: 15px; }
}
.chat-message { display: flex; max-width: 90%; }
.chat-left { align-self: flex-start; }
.chat-right { align-self: flex-end; flex-direction: row-reverse; }
.chat-bubble {
   padding: 6px 7px; border-radius: 15px; box-shadow: 0 2px 5px rgba(0,0,0,0.05);
   position: relative; width: 100%; border: 1px solid var(--writer-border);
}
.chat-left .chat-bubble {
   border-bottom-left-radius: 3px; background-color: var(--chat-left-bg);
}
.chat-right .chat-bubble {
   background-color: var(--chat-right-bg); border-bottom-right-radius: 5px;
}
/* Dictionary Clickable Chars in Chat */
.chat-bubble .zh-text span { cursor: pointer; transition: color 0.15s ease, transform 0.15s ease; display: inline-block; }
.chat-bubble .zh-text span:hover { color: #0d6efd; transform: scale(1.15); }

/* Hiệu ứng Highlight khi đang Auto Play */
.chat-message.playing-highlight .chat-bubble {
   box-shadow: 0 0 0 3px rgba(211, 47, 47, 0.5) !important;
   transition: all 0.3s ease;
}
.module-card.playing-highlight, .radical-card.playing-highlight, .new-word-card.playing-highlight {
   box-shadow: 0 0 0 3px rgba(211, 47, 47, 0.5) !important;
   transition: all 0.3s ease;
}
.speaker-avatar {
   width: 30px; height: 30px; border-radius: 50%; background-color: #d32f2f; color: white;
   display: flex; align-items: center; justify-content: center; font-weight: bold; margin: 5px; flex-shrink: 0;
}

/* Hiệu ứng rung lắc khi trả lời sai (Trắc nghiệm) */
@keyframes shakeError {
   0%, 100% { transform: translateX(0); }
   20%, 60% { transform: translateX(-5px); }
   40%, 80% { transform: translateX(5px); }
}
.shake-error {
   animation: shakeError 0.4s ease-in-out;
   background-color: #ffeaea !important;
   border-color: #d32f2f !important;
}

/* Hiệu ứng Floating EXP */
@keyframes floatUpExp {
   0% { opacity: 1; transform: translateY(0) scale(1); }
   100% { opacity: 0; transform: translateY(-60px) scale(1.3); }
}
.floating-exp {
   position: absolute;
   color: #ffc107;
   font-weight: bold;
   font-size: 1.5rem;
   pointer-events: none;
   animation: floatUpExp 1s ease-out forwards;
   z-index: 9999;
   text-shadow: 1px 1px 3px rgba(0,0,0,0.3);
}

/* Hiệu ứng trượt (Swipe) cho Flashcards */
@keyframes slideOutLeft {
   0% { transform: translateX(0) rotate(0); opacity: 1; }
   100% { transform: translateX(-100%) rotate(-10deg); opacity: 0; }
}
@keyframes slideInRight {
   0% { transform: translateX(100%) rotate(10deg); opacity: 0; }
   100% { transform: translateX(0) rotate(0); opacity: 1; }
}
@keyframes slideOutRight {
   0% { transform: translateX(0) rotate(0); opacity: 1; }
   100% { transform: translateX(100%) rotate(10deg); opacity: 0; }
}
@keyframes slideInLeft {
   0% { transform: translateX(-100%) rotate(-10deg); opacity: 0; }
   100% { transform: translateX(0) rotate(0); opacity: 1; }
}
.slide-out-left { animation: slideOutLeft 0.3s forwards ease-in; }
.slide-in-right { animation: slideInRight 0.3s forwards ease-out; }
.slide-out-right { animation: slideOutRight 0.3s forwards ease-in; }
.slide-in-left { animation: slideInLeft 0.3s forwards ease-out; }

/* =========================================
   MOBILE BOTTOM NAVIGATION
   ========================================= */
.mobile-bottom-nav {
   display: none;
   position: fixed;
   bottom: 0; left: 0; right: 0;
   background-color: var(--bs-body-bg);
   box-shadow: 0 -2px 10px rgba(0,0,0,0.1);
   z-index: 1030;
   border-top: 1px solid var(--writer-border);
}
@media (max-width: 767.98px) {
   .mobile-bottom-nav { 
      display: flex; 
      overflow-x: auto;
      -webkit-overflow-scrolling: touch;
   }
   .mobile-bottom-nav::-webkit-scrollbar { display: none; }
   body { padding-bottom: 75px; } /* Tránh nội dung bị che bởi bottom nav */
}
.nav-item-bottom {
   flex: 1; min-width: 50px; text-align: center; padding: 8px 0;
   color: var(--bs-secondary-color); text-decoration: none; font-size: 0.7rem;
   position: relative;
   overflow: hidden;
   -webkit-tap-highlight-color: transparent; /* Ẩn viền xanh/xám mặc định khi chạm trên điện thoại */
}
/* Hiệu ứng Ripple bằng CSS thuần */
.nav-item-bottom::after {
   content: "";
   position: absolute;
   top: 50%; left: 50%;
   width: 120px; height: 120px;
   background-color: rgba(211, 47, 47, 0.15); /* Màu đỏ nhẹ */
   border-radius: 50%;
   transform: translate(-50%, -50%) scale(1);
   opacity: 0;
   transition: transform 0.5s ease-out, opacity 0.5s ease-out;
}
.nav-item-bottom:active::after {
   transform: translate(-50%, -50%) scale(0);
   opacity: 1;
   transition: 0s; /* Ngay khi chạm vào: hiện chấm tròn ở giữa lập tức */
}
.nav-item-bottom.active { color: #d32f2f; font-weight: bold; }
.nav-item-bottom i { display: block; font-size: 1.1rem; margin-bottom: 2px; }

/* =========================================
   FLOATING AUTO PLAY BUTTON
   ========================================= */
.floating-play-btn {
   position: fixed;
   bottom: 80px;
   left: 20px;
   height: 50px;
   width: 50px;
   border-radius: 50px !important;
   z-index: 1040;
   display: flex;
   align-items: center;
   padding: 0;
   transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
   overflow: hidden;
   white-space: nowrap;
}
.floating-play-icon {
   width: 50px;
   display: flex;
   justify-content: center;
   align-items: center;
   flex-shrink: 0;
}
.floating-play-text {
   opacity: 0;
   transition: opacity 0.2s ease;
   margin-left: 2px;
}
.floating-play-btn:hover,
.floating-play-btn:focus,
.floating-play-btn:active {
   width: 145px;
}
.floating-play-btn:hover .floating-play-text,
.floating-play-btn:focus .floating-play-text,
.floating-play-btn:active .floating-play-text {
   opacity: 1;
}

/* =========================================
   GLOBAL SETTINGS (FONT SIZE & PINYIN)
   ========================================= */
html.font-size-sm { font-size: 14px !important; }
html.font-size-md { font-size: 16px !important; }
html.font-size-lg { font-size: 18px !important; }
html.font-size-xl { font-size: 20px !important; }

body.hide-pinyin .pinyin-text {
   filter: blur(4px);
   opacity: 0.4;
   transition: all 0.3s ease;
}
body.hide-pinyin .pinyin-text:hover,
body.hide-pinyin .pinyin-text:active {
   filter: blur(0);
   opacity: 1;
}

/* =========================================
   LESSONS TABS (MOBILE SCROLL)
   ========================================= */
.lesson-tabs::-webkit-scrollbar {
   display: none;
}

/* Sửa lỗi thanh header che mất phần Quay lại và Danh sách trên Mobile */
@media (max-width: 767.98px) {
   body {
      padding-top: 80px; /* Tăng khoảng trống cho body để Navbar không lẹm xuống dưới */
   }
   #lessonDetailView {
      padding-top: 15px; /* Đẩy khối bài học (chứa nút Quay lại/Danh sách) xuống vùng an toàn */
   }
   .sticky-top {
      top: 70px !important; /* Đồng bộ lại vị trí bám dính nếu thanh công cụ dùng class sticky-top */
   }
}

[data-bs-toggle="collapse"][aria-expanded="true"] .collapse-indicator {
   transform: rotate(180deg);
}
.transition-transform {
   transition: transform 0.3s ease;
}

/* Chế độ ẩn Pinyin và Tiếng Việt trong phần Giao Tiếp và Bài Khóa (Blind-Test) */
#chatView.hide-pinyin .pinyin-text,
#chatView.hide-vn .vn-text,
#chatView.hide-cn .zh-text,
#lessonDetailView.hide-pinyin .pinyin-text,
#lessonDetailView.hide-vn .vn-text,
#playerView.hide-pinyin .pinyin-text,
#playerView.hide-vn #plVietnamese,
#playerView.hide-cn #plChinese {
   filter: blur(4.5px);
   opacity: 0.3;
   transition: all 0.3s ease;
   cursor: pointer;
}
#chatView.hide-pinyin .pinyin-text:hover,
#chatView.hide-pinyin .pinyin-text:active,
#chatView.hide-vn .vn-text:hover,
#chatView.hide-vn .vn-text:active,
#chatView.hide-cn .zh-text:hover,
#chatView.hide-cn .zh-text:active,
#lessonDetailView.hide-pinyin .pinyin-text:hover,
#lessonDetailView.hide-vn .vn-text:hover,
#playerView.hide-pinyin .pinyin-text:hover,
#playerView.hide-pinyin .pinyin-text:active,
#playerView.hide-vn #plVietnamese:hover,
#playerView.hide-vn #plVietnamese:active,
#playerView.hide-cn #plChinese:hover,
#playerView.hide-cn #plChinese:active {
   filter: blur(0);
   opacity: 1;
}

/* Các class tiện ích bổ sung cho trang chủ */
.hover-scale {
   transition: transform 0.3s ease;
}

.hover-scale:hover {
   transform: scale(1.15);
}

/* Hiệu ứng Fade In Up dùng cho danh sách thẻ */
@keyframes fadeInUp {
   from { opacity: 0; transform: translateY(15px); }
   to { opacity: 1; transform: translateY(0); }
}