/* style.css - Main Stylesheet */
@import url('./token.css');

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* body {
  font-family: system-ui, -apple-system, sans-serif;
  background: var(--bg-gradient);
  color: var(--text-main);
  min-height: 100vh;
  padding: 20px 12px;
} */

body {
  /* Ưu tiên Quicksand -> Nunito -> Font hệ thống bo tròn */
  font-family: 'Quicksand', 'Nunito', system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg-gradient);
  color: var(--text-main);
  min-height: 100vh;
  padding: 20px 12px;
  
  /* Tối ưu hóa render font chữ nét và mịn trên mọi màn hình */
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

.app-container {
  max-width: 800px;
  margin: 0 auto;
}

/* Header */
header {
  text-align: center;
  margin-bottom: 20px;
}

header h2 {
  font-size: 1.8rem;
  font-weight: 800;
  background: linear-gradient(135deg, #a5b4fc 0%, #34d399 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  margin-bottom: 6px;
}

/* Controls Bar & Settings Panel */
.panel {
  background: var(--card-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-md);
  padding: 16px;
  margin-bottom: 16px;
  box-shadow: var(--shadow-main);
}

.controls-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  align-items: center;
}

.control-item {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.control-item label {
  font-size: 0.85rem;
  color: var(--text-muted);
  font-weight: 600;
}

select, input[type="checkbox"] {
  accent-color: var(--secondary);
}

/* select {
  background: rgba(15, 23, 42, 0.8);
  border: 1px solid var(--card-border);
  color: var(--text-main);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  outline: none;
} */

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 0.9rem;
  user-select: none;
  margin-left: 12px;
}
.checkbox-label span {
  color: var(--text-muted);
}

/* Buttons */
.btn-group-main {
  display: flex;
  align-items: center;
  justify-content: space-between; /* Đẩy nhóm nút chức năng ra 2 đầu (trong card) */  
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 12px;
  align-items: center;
}

.action-btns-left, .action-btns-right {
display: flex;
  align-items: center;
  gap: 8px;
}

#btnPlayAll, #btnRandomWorld {
  min-width: 120px;        /* Chiều rộng cố định */
/*  height: 40px;             Chiều cao chuẩn */
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  white-space: nowrap;
  flex-shrink: 0;
}


/* Nút ngôi sao đánh dấu câu yêu thích, nằm bên phải mỗi card */
.btn-star {
  background: transparent;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  padding: 4px 8px;
  line-height: 1;
  transition: transform 0.2s ease, color 0.2s ease;
  color: var(--text-muted);
  margin-left: auto;
}

.btn-star:hover {
  /* transform: scale(1.25); */
  color: var(--text-highlight-yellow);  
}

.btn-star.active-star {
  color: var(--text-highlight-yellow);
  /* filter: drop-shadow(0 0 2px rgba(255, 193, 7, 0.6)); */
}
.btn-star {
  color: var(--text-highlight);
}


.btn {
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  border: none;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all 0.2s;
}

/* Button Styles chuẩn hóa theo Design Tokens */
.btn-primary { 
  background: var(--primary); 
  color: var(--card-bg-secondary); /* Dùng màu nền sáng làm màu chữ trên nút đậm để dễ đọc */
}
.btn-primary:hover { 
  background: var(--primary-hover); 
}

.btn-secondary { 
  background: var(--secondary); 
  color: var(--card-bg-secondary); 
}
.btn-secondary:hover { 
  background: var(--secondary-hover); 
}


/* Kiểu dáng chung cho Nút bấm Icon vuông bo góc */
.btn-icon {
  width: 38px;
  height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.2s ease;
  padding: 0;
}

/* Định dạng kích thước SVG Icon bên trong */
.btn-icon .icon-svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

/* Biến đổi hiệu ứng Hover & Active */
.btn-icon:hover {
  transform: translateY(-1px);
}

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

/* Màu sắc nút Nghe & Nói theo Token */
.btn-listen {
  background: var(--color-success-bg);
  color: var(--color-success-text);
}

.btn-speak {
  background: var(--color-success-bg-secondary); /* rgba(30, 58, 138, 0.12); */
  color: var(--primary);
}

/* Trạng thái Đang thu âm nhấp nháy */
.btn-speak.recording {
  background: var(--color-danger-bg);
  color: var(--color-danger-text);
  border-color: rgba(225, 29, 72, 0.3);
  animation: pulse 1.2s infinite;
}

/* Mặc định: Hiện "Phát âm", Ẩn "Dừng đọc" */
.btn-listen .btn-text-stop {
    display: none;
}

.word-clickable {
  cursor: pointer;
}
.word-clickable:hover {
  color: var(--text-highlight-yellow);
}


/* Container chứa nhóm nút floating */
.floating-btn-group {
  position: fixed;
  bottom: 44px;
  right: 24px;
  display: flex;
  flex-direction: column; /* Xếp dọc 2 nút */
  gap: 10px;
  z-index: 999;
}

/* Kiểu dáng chung cho nút tròn Floating */
.btn-floating {
  width: 42px;
  height: 42px;
  background-color: var(--card-bg);
  color: var(--text-muted);
  border: 1px solid var(--card-border);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  text-decoration: none;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
  transition: all 0.25s ease, opacity 0.3s ease, visibility 0.3s ease;
}

.btn-floating:hover {
  transform: translateY(-2px);
  color: #38bdf8;
  border-color: #38bdf8;
  box-shadow: 0 6px 18px rgba(56, 189, 248, 0.25);
}

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

/* Nút Scroll Top mặc định ẩn */
#btnScrollTop {
  opacity: 0;
  visibility: hidden;
}

/* Class kích hoạt hiện nút Scroll Top */
#btnScrollTop.show {
  opacity: 1;
  visibility: visible;
}



/* KHI CARD ĐANG HOẠT ĐỘNG (.active): 
   Ẩn "Phát âm", Hiện "Dừng đọc" và đổi nút sang màu đỏ */
.card.active .btn-listen {
    background-color: var(--color-danger-text); /* Màu đỏ warning --color-success-text */
    color: var(--text-main);
}

.card.active .btn-listen .btn-text-play {
    display: none;
}

.card.active .btn-listen .btn-text-stop {
    display: inline;
}

@keyframes pulse {
  0% { opacity: 1; }
  50% { opacity: 0.4; }
  100% { opacity: 1; }
}

/* Cards & Sentence Display */
.card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-md);
  padding: 20px;
  margin-bottom: 16px;
  position: relative;
  overflow: hidden;
  transition: all 0.3s ease;
}

.card.active {
  border-color: var(--secondary);
  box-shadow: 0 0 20px rgba(16, 185, 129, 0.3);
  transform: scale(1.01);
}

.en-target {
  display: flex;
  align-items: baseline;
  gap: 10px; /* Tạo khoảng cách rõ ràng giữa số thứ tự và nội dung */
}

.sentence-num {
  font-size: 1em;
  font-weight: 600;
  color:  var(--text-highlight);
  user-select: none; /* Tránh cho người dùng bôi đen nhầm số thứ tự */
}

/* Bấm vào số thứ tự để đọc liên tục bắt đầu từ câu đó */
.sentence-num-clickable {
  cursor: pointer;
  border-radius: 6px;
  padding: 1px 6px;
  transition: background-color 0.2s, color 0.2s;
}

.sentence-num-clickable:hover {
  background-color: var(--text-highlight);
  color: #fff;
}

/* Ô nhập "đọc từ dòng" cạnh nút Đọc tất cả 
.play-all {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-left: 4px;
}

.play-all label {
  font-size: 0.9em;
  color: var(--text-muted);
  white-space: nowrap;
} */

#playFromInput {
  width: 64px;
  padding: 6px 8px;
  border-radius: 6px;
  border: 1px solid var(--card-border);
  text-align: center;
  font-weight: 600;
  background-color: var(--card-bg-third);
  color: var(--text-main);
}

.sentence-text {
  font-size: 1.25em;
  font-weight: 700;
  color: var(--text-main);
}

.vi-target {
  font-size: 0.95rem;
  color: var(--text-muted);
  transition: opacity 0.3s;
  margin-top: 6px;
  /* padding-left: 40px; */
  font-style: italic;
}
/* .vi-target {
  font-size: 0.88rem;
  color: var(--text-muted);
  margin-top: 6px;
  font-style: italic;
  line-height: 1.4;
  opacity: 0.85;
} */

/* Feature: Hide Translation + Hover */
.hide-translations .vi-target {
  opacity: 0;
  filter: blur(4px);
}

/* .hide-translations .vi-target:hover {
  opacity: 1;
  filter: blur(0);
} */
 .hide-translations .vi-target:hover {
  opacity: 1;
  filter: blur(0);
}

/* Feature: Visual Countdown Timer */
.timer-bar {
  position: absolute;
  bottom: 0;
  left: 0;
  height: 4px;
  background-color: var(--secondary);
  width: 0%;
}

/* Evaluation Box */
.result-box {
  background: var(--card-bg-third);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  margin-top: 12px;
}

/* Hộp kết quả thu âm */
.score-result-box, .speech-result-box {
  background-color: var(--card-bg-third);
  color: var(--text-muted);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font-size: 0.95rem;
  margin-top: 12px;
}

.matched { color: var(--secondary); font-weight: bold; }
.unmatched { color: #f87171; text-decoration: line-through; }
.score-badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 4px;
  font-weight: bold;
  margin-top: 8px;
}
.score-good { background: var(--color-success-bg); color: var(--color-success-text); }
.score-bad { background: var(--color-danger-bg); color: var(--color-danger-text); }

/* ============================================================
   SITE HEADER (dùng chung cho mọi page - nạp từ header.html)
   ============================================================ */
.site-header {
  background: var(--card-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--card-border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.site-header-inner {
  max-width: 800px;
  margin: 0 auto;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  position: relative;
}

/*
.logo-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 0.85rem;
  color: #fff;
  flex-shrink: 0;
} */
 .site-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--text-main);
  flex-shrink: 0;
}


.footer-logo {
  display: flex;
  justify-content: center; /* Căn giữa ảnh bên trong link */
  align-items: center;
  text-decoration: none;
  /* color: var(--text-main);  -> Không cần vì ảnh không dùng màu chữ */
  flex-shrink: 0;
  margin-top: 15px;
}

.footer-logo-avatar {
  width: 150px;
  height: 150px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;   /* Chống co giật khung trong flexbox */
}


.logo-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;   /* Chống co giật khung trong flexbox */
}

.logo-text {
  font-weight: 700;
  font-size: 1rem;
  white-space: nowrap;
}

/* Menu - desktop */
.site-nav {
  display: flex;
  /* background: var(--card-bg-secondary); */
}

.nav-list {
  display: flex;
  list-style: none;
  gap: 4px;
}

.nav-item {
  position: relative;
}

.nav-item > a {
  display: block;
  padding: 8px 14px;
  color: var(--text-muted);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.9rem;
  border-radius: var(--radius-sm);
  transition: all 0.2s;
}

.nav-item > a:hover,
.nav-item > a.active {
  color: var(--text-main);
  background: var(--card-bg-third);
}

.nav-item > a.active {
  color: var(--text-highlight-yellow);
}

/* Tooltip mô tả khi hover vào 1 page trong menu */
.nav-tooltip {
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%) translateY(4px);
  background: var(--card-bg-third);
  border: 1px solid var(--card-border);
  color: var(--text-muted);
  font-size: 0.78rem;
  font-weight: 500;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  white-space: nowrap;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s, visibility 0.2s;
  box-shadow: var(--shadow-main);
  z-index: 10;
}

.nav-item:hover .nav-tooltip {
  opacity: 1;
  visibility: visible;
  transform: translateX(-50%) translateY(8px);
}

/* ============================================================
   MENU "THÊM ▾" - gom các trang không đủ chỗ hiển thị thẳng hàng.
   Đây là cách mở rộng menu khi số lượng trang tăng lên: các mục
   vượt quá MAX_PRIMARY_ITEMS (khai báo trong menu-data.js) sẽ tự
   động rơi vào đây, xổ ra theo chiều dọc thay vì dàn ngang.
   ============================================================ */
.submenu-toggle {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 8px 14px;
  background: transparent;
  border: none;
  color: var(--text-muted);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.9rem;
  font-family: inherit;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.2s;
}

.submenu-toggle:hover,
.submenu-toggle.open,
.submenu-toggle.active {
  color: var(--text-main);
  background: var(--card-bg-third);
}

.submenu-toggle.active { color: var(--text-highlight-yellow); }

.submenu-toggle .caret {
  font-size: 0.75rem;
  transition: transform 0.2s;
}

.submenu-toggle.open .caret { transform: rotate(180deg); }

.submenu {
  list-style: none;
  position: absolute;
  top: 100%;
  right: 0;
  min-width: 200px;
  background: var(--card-bg-secondary);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-main);
  padding: 6px;
  margin-top: 6px;
  opacity: 0;
  visibility: hidden;
  transform: translateY(4px);
  transition: opacity 0.2s, transform 0.2s, visibility 0.2s;
  z-index: 20;
}

.submenu.open {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.submenu-item { position: relative; }

.submenu-item > a {
  display: block;
  padding: 8px 10px;
  color: var(--text-highlight);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.9rem; /* Label page in sub menu */
  border-radius: var(--radius-sm);
  transition: all 0.2s;
}

.submenu-item > a:hover,
.submenu-item > a.active {
  color: var(--text-main);
  background: var(--card-bg-third);
}

.submenu-item > a.active { color: var(--text-highlight-yellow); }

/* Mô tả hiện LUÔN dưới mỗi mục trong "Thêm ▾" (không cần hover).
   Selector cố tình dài (4 lớp) để độ ưu tiên CAO HƠN hẳn luật
   ".nav-item:hover .nav-tooltip" ở trên - nếu không, "transform"
   của luật đó vẫn áp lên đây dù đã position:static, gây lệch chữ. */
.nav-item.has-submenu .submenu-item .nav-tooltip {
  position: static;
  transform: none;
  opacity: 1;
  visibility: visible;
  background: transparent;
  border: none;
  box-shadow: none;
  padding: 0 10px 6px;
  white-space: normal;
  font-size: 0.78rem;
  pointer-events: none;
}

/* Nút Hamburger - chỉ hiện trên mobile */
.menu-toggle {
  display: none;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 5px;
  width: 38px;
  height: 38px;
  background: transparent;
  border: 1px solid var(--card-border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  flex-shrink: 0;
}

.menu-toggle span {
  display: block;
  height: 2px;
  width: 20px;
  background: var(--text-main);
  transition: all 0.25s;
}

.menu-toggle.open span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.menu-toggle.open span:nth-child(2) { opacity: 0; }
.menu-toggle.open span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

/* ============================================================
   RESPONSIVE: Menu Mobile kiểu WordPress (bấm nút để xổ danh sách)
   ============================================================ */
@media (max-width: 640px) {
  .menu-toggle { display: flex; }

  .site-nav {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--card-bg-secondary);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--card-border);
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease;
  }

  .site-nav.open {
    /* max-height: 480 640px; */
    max-height: 80vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .nav-list {
    flex-direction: column;
    padding: 8px;
  }

  .nav-item > a {
    padding: 12px 14px;
    color: var(--text-highlight);
  }


  /* Trên mobile mô tả hiển thị luôn dưới tên trang, không cần hover */
  .nav-tooltip {
    position: static;
    transform: none;
    opacity: 1;
    visibility: visible;
    background: transparent;
    border: none;
    box-shadow: none;
    padding: 0 14px 10px;
    white-space: normal;
  }

  .nav-item:hover .nav-tooltip {
    transform: none;
  }

  /* Menu "Thêm ▾" trên mobile: xổ dọc ngay tại chỗ (accordion), không tách lớp nổi */
  .submenu-toggle {
    width: 100%;
    justify-content: space-between;
    padding: 12px 14px;
    color: var(--text-highlight);
  }

  .submenu {
    position: static;
    min-width: 0;
    background: rgba(255, 255, 255, 0.03);
    border: none;
    box-shadow: none;
    margin: 0 0 4px;
    padding: 0 0 0 10px;
    max-height: 0;
    overflow: hidden;
    opacity: 1;
    visibility: visible;
    transform: none;
    transition: max-height 0.3s ease;
  }

  .submenu.open {
    max-height: 600px;
  }
}

/* ============================================================
   ẨN TIẾNG ANH (chỉ nghe âm, không thấy chữ - luyện tai/phản xạ nói)
   ============================================================ */
/* Chỉ làm mờ phần nội dung tiếng Anh khi bật chế độ Ẩn tiếng Anh */
.hide-english .sentence-text {
  opacity: 0;
  filter: blur(4px);
  transition: opacity 0.3s, filter 0.3s;
}

/* Rê chuột vào nội dung tiếng Anh để xem đáp án */
.hide-english .sentence-text:hover {
  opacity: 1;
  filter: blur(0);
}

/* Đảm bảo số thứ tự câu luôn rõ ràng, không bị ảnh hưởng bởi hiệu ứng mờ */
.hide-english .sentence-num {
  opacity: 1 !important;
  filter: none !important;
}



/* ============================================================
   RANDOM BADGE (thông báo đang ở chế độ ôn ngẫu nhiên cả World)
   ============================================================ */
.random-badge {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  background: rgba(99, 102, 241, 0.15);
  border: 1px solid var(--card-border);
  border-left: 4px solid var(--primary);
  border-radius: var(--radius-md);
  padding: 10px 16px;
  margin-bottom: 16px;
  font-size: 0.9rem;
  color: var(--text-main);
  font-weight: 600;
}

.btn-link {
  background: transparent;
  border: none;
  color: var(--text-highlight);
  font-weight: 700;
  cursor: pointer;
  text-decoration: underline;
  font-size: 0.85rem;
  padding: 4px 0;
  white-space: nowrap;
}

/* ============================================================
   GUIDE PANEL (Hướng dẫn học đầu mỗi World - đọc từ data.json)
   ============================================================ */
.guide-panel {
  display: none;
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-left: 4px solid var(--secondary);
  border-radius: var(--radius-md);
  padding: 16px 18px;
  margin-bottom: 16px;
}

.guide-title {
  font-weight: 800;
  font-size: 1rem;
  margin-bottom: 8px;
  color: var(--text-main);
}

.guide-notes {
  padding-left: 20px;
  color: var(--text-muted);
  font-size: 0.9rem;
  line-height: 1.6;
}

.guide-notes li {
  margin-bottom: 4px;
}

.guide-notes a {
  color: var(--text-highlight);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.guide-notes a:hover {
  color: var(--secondary-hover);
}

.guide-notes img {
  display: block;
  max-width: 100%;
  height: auto;
  border-radius: var(--radius-sm);
  border: 1px solid var(--card-border);
  margin-top: 6px;
}

/* ============================================================
   KARAOKE HIGHLIGHT khi đang đọc câu (đọc từng câu hoặc đọc liên tục)
   ============================================================ */
.word {
  transition: color 0.15s, text-decoration-color 0.15s;
}

.word.karaoke-active {
  color: var(--text-highlight-yellow);
  /* text-decoration: underline; */
  text-decoration-thickness: 2px;
  text-underline-offset: 2px;
  font-weight: 800;
}

/* ============================================================
   AD BANNER (dùng chung mọi page - nạp trong footer.html qua ads.json)
   ============================================================ */
.ad-banner {
  max-width: 800px;
  margin: 20px auto 0;
  padding: 0 16px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

.ad-slot {
  display: block;
  position: relative;
  border-radius: var(--radius-md);
  overflow: hidden;
  border: 1px solid var(--card-border);
  background: var(--card-bg);
  aspect-ratio: 16 / 9;
  text-decoration: none;
}

.ad-slot img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 0.25s;
}

.ad-slot:hover img {
  transform: scale(1.04);
}

.ad-slot-video iframe {
  width: 100%;
  height: 100%;
  display: block;
  border: none;
}

.ad-overlay-link {
  position: absolute;
  inset: 0;
  z-index: 2;
}

@media (max-width: 640px) {
  .ad-banner {
    grid-template-columns: 1fr;
  }
}

/* ============================================================
   SITE FOOTER (dùng chung cho mọi page - nạp từ footer.html)
   ============================================================ */
.site-footer {
  max-width: 800px;
  margin: 24px auto 0;
  padding: 16px;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.85rem;
  border-top: 1px solid var(--card-border);
}


Module rieng, dung cho page co du lieu txt
/* ============================================================
   DATA SOURCE CARD (Khung chọn file & thư mục bài học)
   ============================================================ */
.data-source-card {
  background: rgba(15, 23, 42, 0.6);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-sm);
  padding: 16px;
  margin-bottom: 15px;
  transition: all 0.3s ease;
}

.file-input-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  align-items: flex-start;
}

.file-input-item {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* Đường vạch phân cách giữa Chọn file và Chọn thư mục trên màn hình lớn */
.file-input-item--folder {
  border-left: 1px solid var(--card-border);
  padding-left: 16px;
}

.file-label {
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 6px;
}

/* Nút Chọn File/Folder kiểu Glassmorphism */
.custom-file-input {
  font-size: 0.85rem;
  color: var(--text-muted);
  cursor: pointer;
}

.custom-file-input::file-selector-button {
  background: var(--primary);
  color: var(--card-bg-secondary);
  border: 1px solid var(--card-border);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  cursor: pointer;
  margin-right: 10px;
  transition: all 0.2s ease;
}

.custom-file-input::file-selector-button:hover {
  background: var(--primary-hover);
}

/* Khung hiển thị danh sách bài học sau khi nạp */
.file-select-box {
  display: none; /* Mặc định ẩn, sẽ bật bằng JS */
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px dashed var(--card-border);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.file-select-label {
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--text-highlight);
  white-space: nowrap;
}

.custom-select {
  flex: 1;
  width: 280px;
  background: var(--card-bg-secondary);
  border: 1px solid var(--card-border);
  color: var(--text-main);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 600;
  outline: none;
  cursor: pointer;
  transition: border-color 0.2s;
}

.custom-select:focus {
  border-color: var(--secondary);
  box-shadow: 0 0 0 2px rgba(16, 185, 129, 0.2);
}

/* Responsive điều chỉnh viền ranh giới trên Mobile */
@media (max-width: 580px) {
  .file-input-item--folder {
    border-left: none;
    border-top: 1px solid var(--card-border);
    padding-left: 0;
    padding-top: 12px;
  }
}

/* ============================================================
   POPUP / THÔNG BÁO / STICKER QUẢNG CÁO (js/popup.js + js/popup-data.js)
   ============================================================ */
.popup-overlay {
  position: fixed;
  inset: 0;
  background: transparent;       /* không che mờ / không blur nội dung phía sau */
  display: flex;
  align-items: flex-end;         /* neo popup xuống sát đáy màn hình */
  justify-content: center;
  padding: 16px;
  z-index: 1000;
  animation: popupFadeIn 0.2s ease;
}

@keyframes popupFadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.popup-box {
  position: relative;
  width: 100%;
  max-width: 380px;
  max-height: 20vh;              /* chỉ chiếm khoảng 20% chiều cao màn hình */
  overflow-y: auto;
  background: var(--card-bg, rgba(15, 23, 42, 0.98));
  border: 1px solid var(--card-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-main);
  padding: 14px 36px 14px 16px;  /* chừa chỗ bên phải cho nút đóng */
  animation: popupPopIn 0.2s ease;
}

@keyframes popupPopIn {
  from { transform: translateY(12px); opacity: 0; }
  to   { transform: translateY(0); opacity: 1; }
}

.popup-close {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--card-border);
  border-radius: 50%;
  color: var(--text-main);
  font-size: 0.8rem;
  cursor: pointer;
  transition: background 0.2s;
}

.popup-close:hover {
  background: rgba(255, 255, 255, 0.18);
}

.popup-title {
  font-size: 0.95rem;
  font-weight: 800;
  margin-bottom: 4px;
  padding-right: 20px;
  color: var(--text-main);
}

.popup-content {
  font-size: 0.82rem;
  line-height: 1.45;
  color: var(--text-muted);
}

.popup-content p + p {
  margin-top: 6px;
}

.popup-cta {
  display: inline-block;
  margin-top: 8px;
  padding: 6px 14px;
  background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
  color: #fff;
  font-weight: 700;
  font-size: 0.8rem;
  text-decoration: none;
  border-radius: var(--radius-sm);
}

/* Popup dạng ảnh/sticker: ảnh nhỏ gọn, không tràn quá 20% màn hình */
.popup-box.popup-type-image {
  padding: 0;
  overflow: hidden;
  width: auto;
  max-width: 220px;
  max-height: 20vh;
}

.popup-box.popup-type-image .popup-close {
  top: 6px;
  right: 6px;
  background: rgba(2, 6, 23, 0.6);
  border: none;
}

.popup-image,
.popup-image-link {
  display: block;
  width: 100%;
  height: 100%;
}

.popup-image {
  width: 100%;
  height: 100%;
  max-height: 20vh;
  object-fit: cover;
}

/* ============================================================
   LICENSE (js/app.js đọc field "license" từ get_data.php)
   - Banner cảnh báo sắp hết hạn: không có nút tắt, luôn hiện.
   - Overlay khoá cứng khi hết hạn: chặn toàn bộ thao tác, không đóng được.
   ============================================================ */
.license-warning-banner {
  width: 100%;
  background: var(--color-danger-bg, rgba(239, 68, 68, 0.15));
  color: var(--color-danger-text, #f87171);
  border-bottom: 1px solid var(--card-border);
  text-align: center;
  font-size: 0.85rem;
  font-weight: 700;
  padding: 10px 16px;
}

.license-lock-overlay {
  position: fixed;
  inset: 0;
  background: rgba(2, 6, 23, 0.92);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 5000; /* Luôn nổi trên header, popup và mọi nội dung khác */
}

.license-lock-box {
  max-width: 380px;
  width: 100%;
  text-align: center;
  background: var(--card-bg, rgba(15, 23, 42, 0.98));
  border: 1px solid var(--card-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-main);
  padding: 32px 24px;
}

.license-lock-icon {
  font-size: 2.4rem;
  margin-bottom: 10px;
}

.license-lock-title {
  font-size: 1.15rem;
  font-weight: 800;
  color: var(--text-main);
  margin-bottom: 8px;
}

.license-lock-desc {
  font-size: 0.9rem;
  color: var(--text-muted);
  line-height: 1.5;
}

/* Ghi đè toàn bộ Dropdown (Select & Option) bằng Design Tokens & Font kế thừa */
select, 
.form-select,
.dropdown-select {
  font-family: inherit; /* Ép kế thừa font Quicksand/Nunito từ body */
  font-size: 14px;
  font-weight: 600;     /* Giúp chữ trong dropdown nét và rõ hơn */
  background-color: var(--card-bg-third);
  color: var(--text-main);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  outline: none;
  appearance: auto;
}

/* Danh sách các option sổ xuống */
/* Tối ưu chữ bên trong Option */
select option {
  font-family: inherit;
  background-color: var(--card-bg-secondary);
  color: var(--text-main);
  padding: 10px; /* Thêm khoảng trống dòng cho dễ bấm */
  font-size: 14px;
}

/* Trạng thái khi di chuột hoặc chọn option */
select option:hover,
select option:focus,
select option:active,
select option:checked {
  background-color: var(--color-success-bg);
  color: var(--primary);
}
