/* =========================================================
   RESPONSIVE.CSS — YẾU TIẾNG TRUNG
   Hệ thống responsive hoàn chỉnh: Mobile → Tablet → Laptop → Desktop
   Nguyên tắc: Mobile-first adjustments, override từng cấp lên trên
   ========================================================= */

/* =========================================================
   BREAKPOINTS CHUẨN:
   xs: < 480px   (điện thoại nhỏ: iPhone SE, Android 5")
   sm: 480–767px (điện thoại lớn: iPhone Pro Max, Android 6-7")
   md: 768–991px (tablet: iPad, Android tablet)
   lg: 992–1199px (laptop nhỏ: 13-14")
   xl: 1200px+   (desktop / laptop lớn) — style mặc định
   ========================================================= */

/* =========================================================
   1. XL — DESKTOP (1200px+)
   Đây là style "mặc định" đã có trong các file khác.
   Chỉ cần bổ sung những gì cần thiết.
   ========================================================= */
@media (min-width: 1200px) {
  .mobile-bottom-nav {
    display: none !important;
  }
  .menu-toggle {
    display: none !important;
  }
}

/* =========================================================
   2. LG — LAPTOP NHỎ (992px – 1199px)
   ========================================================= */
@media (max-width: 1199px) {
  .mobile-bottom-nav {
    display: none !important;
  }

  /* Thu nhỏ gap navbar cho vừa màn */
  .nav-links {
    gap: 18px;
  }
  .nav-links a {
    font-size: 0.88rem;
  }

  /* Hero text nhỏ lại một chút */
  .cultivation-bible-glow {
    font-size: 2rem;
  }
  .cultivation-spirit-desc {
    font-size: 1rem;
  }

  /* Footer */
  .footer-col {
    min-width: 200px;
  }
}

/* =========================================================
   3. MD — TABLET (768px – 991px)
   ========================================================= */
@media (min-width: 768px) and (max-width: 991px) {
  .mobile-bottom-nav {
    display: none !important;
  }

  /* Navbar — Cùng thứ tự icon như mobile */
  .logo { order: 1; flex: 1; min-width: 0; }
  #user-account { order: 2; display: flex !important; align-items: center; gap: 8px; }
  .menu-toggle {
    order: 3;
    display: block;
    margin-left: 10px;
  }
  .nav-links {
    position: fixed;
    top: 0;
    right: -100%;
    width: 60%;
    height: 100vh;
    background: white;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    transition: 0.4s cubic-bezier(0.77, 0, 0.175, 1);
    z-index: var(--z-nav);
    box-shadow: -5px 0 30px rgba(0, 0, 0, 0.15);
    padding: 40px 20px;
    gap: 5px;
  }
  .nav-links.active {
    right: 0;
  }
  .nav-links li {
    width: 100%;
    height: auto;
    text-align: center;
    margin: 0;
  }
  .nav-links a {
    color: var(--text-dark) !important;
    font-size: 1.1rem;
    height: auto;
    padding: 12px 0;
    display: block;
    border-bottom: 1px solid #f0f0f0;
    width: 100%;
    justify-content: center;
  }
  .nav-links a::after {
    display: none;
  }
  .nav-links .btn {
    margin-top: 15px;
    height: auto !important;
    display: inline-block !important;
    width: auto !important;
  }

  /* Dropdown trên tablet */
  .dropdown-menu {
    position: static;
    box-shadow: none;
    border-top: none;
    background: rgba(0, 0, 0, 0.03);
    display: none;
    padding-left: 20px;
    min-width: unset;
    width: 100%;
    animation: none;
  }
  .dropdown-menu::before {
    display: none;
  }
  .dropdown-item:hover .dropdown-menu {
    display: block;
  }
  .navbar .dropdown-item {
    flex-direction: column;
    height: auto;
    width: 100%;
  }

  /* Hero */
  .cultivation-bible-glow {
    font-size: 1.8rem;
  }
  .cultivation-spirit-desc {
    font-size: 0.95rem;
  }
  .hero-action-buttons {
    gap: 15px;
  }
  .btn-tu-tien {
    padding: 10px 25px;
    font-size: 0.95rem;
  }

  /* Layout chung */
  .stats-row {
    flex-wrap: wrap;
    gap: 20px;
    justify-content: center;
  }
  .gate-container {
    grid-template-columns: 1fr;
  }

  /* Footer */
  .footer-content {
    flex-wrap: wrap;
    gap: 25px;
  }
  .footer-col {
    flex: 1 1 calc(50% - 15px);
    min-width: 200px;
  }

  /* Modal */
  .auth-box {
    width: 90%;
    padding: 30px 25px;
  }
  .profile-container {
    flex-direction: column;
  }


}

/* =========================================================
   4. SM + XS — MOBILE (< 768px)
   Đây là màn hình chính cần được ưu tiên tối đa.
   ========================================================= */
@media (max-width: 767px) {
  /* ----- 4.1 GLOBAL ----- */
  body {
    padding-bottom: 70px; /* Tránh bị mobile bottom nav che */
    overflow-x: hidden;
  }

  /* [ĐÃ VÁ LỖI CHẶN CUỘN NGANG]: Chỉ giới hạn các khối media/bảng để chống tràn, thả tự do cho các thanh cuộn ngang Tu Tiên */
  img,
  video,
  iframe,
  table,
  canvas {
    max-width: 100%;
    height: auto;
  }

  /* ----- 4.2 NAVBAR — SẮP XẾP ICON CHUẨN YOUTUBE/FACEBOOK ----- */
  /* 
     Thứ tự mong muốn trên mobile:
     [Logo] ---- [🔔 Chuông] [👤 Avatar] [☰ Menu]
     Dùng CSS order để xếp lại mà KHÔNG động vào HTML.
  */
  .navbar {
    padding: 0 12px !important;
    height: 60px !important;
  }

  .logo {
    order: 1;
    flex: 1; /* Logo chiếm toàn bộ khoảng trống → đẩy các icon sang phải */
    min-width: 0;
  }
  .logo span {
    font-size: 24px !important;
  }
  .nav-logo-img {
    width: 32px !important;
    height: 32px !important;
    margin-right: 8px !important;
  }

  #user-account {
    order: 2; /* Chuông + Avatar đứng giữa */
    display: flex !important;
    align-items: center;
    gap: 6px;
    margin-right: 0 !important;
  }
  /* Thu nhỏ chuông trên mobile */
  #user-account .notif-btn {
    width: 36px !important;
    height: 36px !important;
  }
  #user-account .notif-btn .bell {
    width: 15px !important;
  }
  /* Thu nhỏ icon Inbox trên mobile — đồng bộ với chuông */
  #user-account .inbox-btn {
    width: 36px !important;
    height: 36px !important;
  }
  #user-account .inbox-btn i {
    font-size: 14px !important;
  }
  /* Thu nhỏ avatar trên mobile */
  #user-account .user-avatar-container {
    width: 36px !important;
    height: 36px !important;
  }
  /* Bỏ margin-right thừa của wrapper chuông */
  #user-account > div:first-child {
    margin-right: 0 !important;
  }

  .menu-toggle {
    order: 3; /* Hamburger sát mép phải */
    display: flex;
    align-items: center;
    margin-left: 8px;
  }
  .menu-toggle i {
    font-size: 22px !important;
  }

  /* Ẩn nav-links, thay bằng drawer từ phải — COMPACT */
  .nav-links {
    position: fixed;
    top: 0;
    right: -100%;
    width: 70%;
    max-width: 280px;
    height: 100vh;
    background: white;
    flex-direction: column;
    justify-content: flex-start;
    align-items: center;
    padding-top: 60px;
    padding-bottom: 20px;
    overflow-y: auto;
    transition: right 0.35s cubic-bezier(0.77, 0, 0.175, 1);
    z-index: 9998;
    box-shadow: -5px 0 30px rgba(0, 0, 0, 0.2);
    gap: 0;
  }
  .nav-links.active {
    right: 0;
  }
  .nav-links li {
    width: 100%;
    height: auto;
    margin: 0;
    border-bottom: 1px solid #f0f0f0;
  }
  .nav-links li:last-child {
    border-bottom: none;
  }
  .nav-links a {
    color: var(--text-dark) !important;
    font-size: 0.95rem;
    height: auto;
    padding: 12px 20px;
    display: block;
    width: 100%;
    text-align: right;
  }
  .nav-links a::after {
    display: none !important;
  }
  .nav-links .btn {
    height: auto !important;
    width: calc(100% - 40px) !important;
    display: block !important;
    margin: 12px 20px !important;
    text-align: center;
    font-size: 0.9rem !important;
    padding: 10px !important;
  }

  /* --- BẢN VÁ LỖI DARK MODE CHO MOBILE MENU --- */
  body.dark-mode .nav-links {
    background-color: var(--bg-dark, #1a1a22) !important;
    border-color: var(--border-color, #333) !important;
    box-shadow: -5px 0 30px rgba(0, 0, 0, 0.5) !important;
  }
  body.dark-mode .nav-links li {
    border-bottom: 1px solid #333 !important;
  }
  body.dark-mode .nav-links a,
  body.dark-mode .nav-links span {
    color: var(--text-dark, #eee) !important;
  }
  body.dark-mode .nav-links a:hover {
    background-color: rgba(255, 255, 255, 0.05) !important;
  }

  /* Dropdown trên mobile — trigger bằng click (JS) */
  .dropdown-menu {
    position: static !important;
    box-shadow: none !important;
    border-top: none !important;
    background: #fafafa !important;
    display: none;
    padding: 0 0 0 20px !important;
    min-width: unset !important;
    width: 100% !important;
    animation: none !important;
    border-radius: 0 !important;
  }
  .dropdown-menu::before {
    display: none !important;
  }

  /* [ĐÃ VÁ LỖI LIỆT MENU]: Khớp nối chính xác với logic click của main.js */
  .dropdown-item:hover .dropdown-menu {
    display: none; /* Tắt hover, bật click qua JS */
  }
  .dropdown-menu.mobile-active {
    display: block !important;
  }

  .navbar .dropdown-item {
    flex-direction: column;
    height: auto;
    width: 100%;
    align-items: flex-start;
  }
  .dropdown-menu a {
    font-size: 0.9rem !important;
    padding: 12px 16px !important;
  }

  /* ----- 4.3 HERO SECTION ----- */
  .cultivation-bible-glow {
    font-size: 1.4rem;
    letter-spacing: 0.5px;
  }
  .cultivation-spirit-desc {
    font-size: 0.85rem;
    letter-spacing: 0.5px;
  }
  .cultivation-bible-content {
    width: 94%;
    padding: 0 10px;
  }
  .hero-action-buttons {
    flex-direction: column;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 0 20px;
    box-sizing: border-box; /* [v7.56] tránh padding đẩy buttons ra ngoài viewport */
  }
  .btn-tu-tien {
    width: 100%;
    max-width: 280px;
    padding: 13px 20px;
    font-size: 0.95rem;
  }

  /* ----- 4.4 SECTIONS CHUNG ----- */
  section,
  .section {
    padding-left: 16px !important;
    padding-right: 16px !important;
  }

  .stats-row {
    flex-direction: column;
    gap: 20px;
    align-items: center;
  }

  /* Grid 2 cột → 1 cột */
  [class*="grid-"] {
    grid-template-columns: 1fr !important;
  }

  /* Card min-width gây tràn */
  .news-card {
    min-width: calc(100vw - 40px);
    max-width: calc(100vw - 40px);
  }
  /* Slider arrows: hiện trên mobile với style nhỏ gọn */
  .slider-btn {
    display: flex !important;
    width: 36px !important;
    height: 36px !important;
    font-size: 0.85rem !important;
    opacity: 0.8;
    background: rgba(255,255,255,0.9) !important;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15) !important;
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    z-index: 10;
    border-radius: 50% !important;
    border: none !important;
    cursor: pointer;
  }
  .slider-btn.prev-btn {
    left: 5px;
  }
  .slider-btn.next-btn {
    right: 5px;
  }
  .news-slider-wrapper {
    position: relative;
  }

  /* Nút 'Xem Tất Cả Bài Viết': kéo lên gần bài báo */
  #news > div[style*="margin-top: 50px"] {
    margin-top: 20px !important;
  }

  /* Ẩn widget thông báo cuộn */
  #khung-thong-bao {
    display: none;
  }

  /* Gate (đăng nhập / đăng ký song song) */
  .gate-container {
    grid-template-columns: 1fr;
    gap: 15px;
  }

  /* ----- 4.5 MODALS ----- */
  .modal-overlay,
  .all-news-overlay,
  .news-popup-overlay {
    padding: 10px;
    align-items: flex-start;
    overflow-y: auto;
  }

  .auth-box {
    width: 100% !important;
    max-width: 100% !important;
    padding: 24px 18px !important;
    border-radius: 16px !important;
    margin: 10px 0;
  }

  /* Modal Shop & Rank — full screen trên mobile */
  .shop-box,
  .rank-box {
    min-height: auto !important;
    max-height: 90vh;
    overflow-y: auto;
  }
  .shop-tabs {
    gap: 6px !important;
  }
  .shop-tab-btn {
    font-size: 0.8rem;
    padding: 6px 10px;
  }

  /* Profile Modal */
  .profile-container {
    flex-direction: column !important;
  }
  .profile-left {
    padding: 20px 15px 10px !important;
  }
  .profile-right {
    padding: 15px !important;
  }

  /* Close button dễ bấm hơn */
  .close-modal {
    font-size: 28px;
    top: 10px;
    right: 15px;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  /* ----- 4.6 QUIZ ----- */
  .q-options {
    grid-template-columns: 1fr;
  }
  .quiz-timer-box span {
    display: none;
  }
  #quizModal .auth-box {
    padding: 20px 15px !important;
  }

  /* ----- 4.7 FOOTER ----- */
  footer {
    clip-path: none !important;
    margin-top: 0 !important;
    padding-top: 30px !important;
    padding-bottom: 90px !important; /* Tránh bottom nav */
    height: auto !important;
    overflow: visible !important;
  }
  .footer-content {
    flex-direction: column;
    gap: 20px;
    padding: 0 16px;
  }
  .footer-col {
    width: 100%;
    min-width: unset;
    margin-bottom: 0;
  }
  .footer-col:first-child {
    display: block !important; /* Đảm bảo cột thương hiệu luôn hiện */
  }
  .footer-col:first-child .footer-desc {
    font-size: 0.85rem;
    line-height: 1.5;
  }
  .footer-desc {
    height: auto !important;
    -webkit-line-clamp: unset;
    text-align: left;
  }
  .footer-col h3 {
    font-size: 1rem;
    margin-bottom: 12px;
  }
  .contact-row {
    margin-bottom: 10px !important;
    font-size: 0.9rem;
  }
  .social-links {
    gap: 10px !important;
  }
  .copyright {
    padding: 15px 16px !important;
    font-size: 0.78rem;
  }
  .copyright > div {
    flex-direction: column !important;
    align-items: center !important;
    text-align: center;
    gap: 5px !important;
  }

  /* ----- 4.8 FLOATING BUTTONS ----- */
  .zalo-chat-btn {
    display: none;
  }
  .fb-chat-btn {
    bottom: 80px;
    right: 15px;
    width: 48px;
    height: 48px;
  }
  .hotline-phone-ring-wrap {
    bottom: 75px;
    right: 10px;
  }

  /* ----- 4.9 MOBILE BOTTOM NAV ----- */
  .mobile-bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    background: white;
    box-shadow: 0 -3px 15px rgba(0, 0, 0, 0.1);
    display: flex !important;
    z-index: 9998;
    justify-content: space-around;
    padding: 8px 5px;
    border-top: 1px solid #eee;
    /* Safe area cho iOS */
    padding-bottom: max(8px, env(safe-area-inset-bottom));
  }
  .mb-item {
    text-align: center;
    color: #555;
    font-size: 11px;
    text-decoration: none;
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
  }
  .mb-item i {
    font-size: 19px;
    color: #555;
  }
  .mb-item.special {
    background: var(--primary-red);
    color: white;
    border-radius: 8px;
    margin: -12px 4px 4px;
    padding: 8px 4px 4px;
    box-shadow: 0 4px 12px rgba(211, 47, 47, 0.4);
  }
  .mb-item.special i {
    color: white;
  }

  /* ----- 4.10 COMMENT / GAMIFICATION UI ----- */
  .cmt-user-info > div:first-child {
    transform: scale(0.75);
    transform-origin: top left;
    margin-right: -12px;
  }
  .tu-tien-phap-tuong {
    height: 55px !important;
    width: auto !important;
  }
  .xianxia-equip-icon {
    width: 20px !important;
    height: 20px !important;
  }
  .faq-button {
    transform: scale(0.65) !important;
    top: -5px !important;
    right: -5px !important;
  }
  .cmt-meta {
    padding: 10px !important;
  }
  .cmt-actions,
  .reply-box {
    margin-left: 50px !important;
  }


}

/* =========================================================
   5. XS — ĐIỆN THOẠI NHỎ (< 480px)
   Tinh chỉnh thêm cho màn hình ≤ 4.7 inch
   ========================================================= */
@media (max-width: 479px) {
  /* Hero chữ nhỏ hơn nữa */
  .cultivation-bible-glow {
    font-size: 1.15rem;
  }
  .cultivation-spirit-desc {
    font-size: 0.78rem;
  }
  .btn-tu-tien {
    font-size: 0.85rem;
    padding: 11px 16px;
  }

  /* Logo navbar nhỏ lại */
  .logo {
    font-size: 22px !important;
  }
  .logo span {
    font-size: 26px !important;
  }

  /* Form đăng ký nhỏ */
  .auth-box {
    padding: 20px 14px !important;
  }
  .form-control {
    padding: 12px;
    font-size: 15px;
  }

  /* Shop tabs wrap gọn */
  .shop-tabs {
    gap: 4px !important;
  }
  .shop-tab-btn {
    font-size: 0.72rem;
    padding: 5px 8px;
  }

  /* Bottom nav chữ còn nhỏ hơn */
  .mb-item {
    font-size: 10px;
  }
  .mb-item i {
    font-size: 17px;
  }
}

/* =========================================================
   6. LANDSCAPE MOBILE (xoay ngang)
   Màn hình ngắn khi xoay ngang điện thoại
   ========================================================= */
@media (max-height: 500px) and (orientation: landscape) {
  .nav-links {
    padding-top: 60px;
    overflow-y: auto;
  }
  .nav-links a {
    padding: 10px 24px;
    font-size: 0.95rem;
  }
  .mobile-bottom-nav {
    display: none !important; /* Ẩn bottom nav khi landscape để tiết kiệm chiều cao */
  }
  body {
    padding-bottom: 0;
  }
  footer {
    padding-bottom: 30px !important;
  }
}

/* =========================================================
   7. SAFE AREA — iPhone notch / Dynamic Island / Android cutout
   ========================================================= */
@supports (padding: max(0px)) {
  .navbar {
    padding-left: max(5%, env(safe-area-inset-left));
    padding-right: max(5%, env(safe-area-inset-right));
  }
  .mobile-bottom-nav {
    padding-bottom: max(8px, env(safe-area-inset-bottom));
  }
}

/* =========================================================
   8. HIGH DPI / RETINA — Ảnh sắc nét hơn
   ========================================================= */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
  /* Tăng border radius nhỏ để bo mềm hơn trên retina */
  .btn,
  .form-control,
  .auth-box {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
  }
}
