/* Dùng chung cho tất cả các trang: biến màu, reset, header, search box, side-menu, donate modal, toast */
:root {
  --blue: #007AFF;
  --green: #30D158;
  --orange: #FF9500;
  --red: #FF3B30;
  --bg: #F2F2F7;
  --card: #FFFFFF;
  --text: #000000;
  --text-2: #8E8E93;
  --divider: #C6C6C8;
  --radius-card: 12px;
  --radius-btn: 20px;
  --ease-ios: cubic-bezier(0.25, 0.1, 0.25, 1);
}
* { box-sizing: border-box; }
body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  margin: 0;
  color: var(--text);
  font-size: 17px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  letter-spacing: -0.01em;
  padding-bottom: calc(env(safe-area-inset-bottom) + 12px);
}
a { color: inherit; text-decoration: none; }
button { font-family: inherit; }

/* ---------- Header ---------- */
.header {
  position: sticky; top: 0; z-index: 100;
  background: rgba(255, 255, 255, 0.8);
  backdrop-filter: saturate(180%) blur(20px); -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 0.5px solid var(--divider);
  padding-top: env(safe-area-inset-top);
}
/* Máy RAM thấp: bỏ hiệu ứng mờ kính (tốn GPU, dễ giật khi cuộn), dùng nền gần như đặc thay thế */
html.low-mem .header {
  backdrop-filter: none; -webkit-backdrop-filter: none;
  background: rgba(255, 255, 255, 0.97);
}
.header-row { display: flex; align-items: center; gap: 10px; padding: 10px 14px; min-height: 44px; }
.menu-btn, .back-btn {
  width: 44px; height: 44px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  background: none; border: none; cursor: pointer;
  margin-left: -10px; color: var(--text);
}
.back-btn { color: var(--blue); }
.menu-btn:active, .back-btn:active { opacity: 0.5; }
.header-title { font-size: 20px; font-weight: 700; letter-spacing: -0.3px; color: var(--blue); }
.header-title-group { display: flex; flex-direction: column; min-width: 0; }
.header-subtitle { font-size: 13px; font-weight: 600; color: var(--text-2); margin-top: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.search-wrap { padding: 4px 14px 10px; }
.search-box {
  display: flex; align-items: center; gap: 8px;
  background: rgba(118, 118, 128, 0.12);
  border-radius: 10px;
  padding: 0 10px;
  height: 40px;
}
.search-box svg { flex-shrink: 0; color: var(--text-2); width: 18px; height: 18px; }
.search-box input {
  border: none; background: none; outline: none;
  font-size: 16px; font-family: inherit; color: var(--text);
  width: 100%; height: 100%;
}
.search-box input::placeholder { color: var(--text-2); }
.search-clear {
  display: none;
  width: 20px; height: 20px; border-radius: 50%;
  background: var(--text-2); color: #fff;
  align-items: center; justify-content: center;
  border: none; cursor: pointer; flex-shrink: 0; padding: 0;
}
.search-clear.show { display: flex; }

.search-results { max-height: 320px; overflow-y: auto; padding: 0 10px 10px; }
.search-result-item {
  display: flex; align-items: center; gap: 10px; padding: 10px 8px; border-radius: 10px; cursor: pointer;
}
.search-result-item:active { background: var(--bg); }
.search-result-icon {
  width: 32px; height: 32px; border-radius: 9px; background: rgba(0, 122, 255, 0.1); color: var(--blue);
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.search-result-icon.has-video { background: rgba(255, 59, 48, 0.1); color: var(--red); }
.search-result-icon.locked { background: rgba(142, 142, 147, 0.14); color: var(--text-2); }
.search-result-icon svg { width: 15px; height: 15px; }
.search-result-body { flex: 1; min-width: 0; }
.search-result-name { font-size: 15px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.search-result-sub { font-size: 12px; color: var(--text-2); margin-top: 2px; display: flex; flex-wrap: wrap; align-items: center; gap: 4px 6px; min-width: 0; }
.search-result-hoi { min-width: 0; }
.search-empty { padding: 16px; text-align: center; color: var(--text-2); font-size: 13px; }

.part-row {
  display: flex; align-items: center; gap: 12px; background: var(--card);
  border-radius: var(--radius-card); padding: 12px 14px; margin-bottom: 8px; min-height: 44px;
}
.part-icon {
  width: 36px; height: 36px; border-radius: 10px; background: rgba(0, 122, 255, 0.1); color: var(--blue);
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.part-icon svg { width: 17px; height: 17px; }
.part-body { flex: 1; min-width: 0; }
.part-body.clickable { cursor: pointer; }
.part-name { font-size: 15px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.part-note { font-size: 12px; color: var(--text-2); margin-top: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.part-actions { display: flex; gap: 6px; flex-shrink: 0; }
.part-btn {
  width: 38px; height: 38px; border-radius: 10px; border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0, 122, 255, 0.1); color: var(--blue);
}
.part-btn.yt { background: rgba(255, 59, 48, 0.1); color: var(--red); }
.part-btn:active { transform: scale(0.92); }
.part-btn svg { width: 16px; height: 16px; }

.tong-row { display: flex; gap: 10px; }
.big-btn {
  flex: 1; display: flex; align-items: center; justify-content: center; gap: 8px;
  background: var(--card); border: none; border-radius: var(--radius-card);
  padding: 14px; font-size: 15px; font-weight: 700; color: var(--blue); cursor: pointer; min-height: 44px;
}
.big-btn.yt { color: var(--red); }
.big-btn:active { transform: scale(0.97); }
.big-btn svg { width: 19px; height: 19px; }

/* ---------- List / Card (danh sách bài hoặc hội kèn) ---------- */
.list { padding: 0 14px 24px; max-width: 640px; margin: 0 auto; }
.card {
  display: flex; align-items: center; gap: 12px;
  text-decoration: none; color: inherit; /* .card giờ là <a> ở index.html/banken.html để Google lần theo được */
  background: var(--card);
  border-radius: var(--radius-card);
  padding: 12px 14px;
  margin-bottom: 8px;
  cursor: pointer;
  min-height: 44px;
  transition: transform 0.1s var(--ease-ios);
}
.card:active { transform: scale(0.98); }
.card-icon {
  width: 38px; height: 38px;
  border-radius: 10px;
  background: rgba(0, 122, 255, 0.1);
  color: var(--blue);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.card-icon.has-video { background: rgba(255, 59, 48, 0.1); color: var(--red); }
.card-icon.locked { background: rgba(142, 142, 147, 0.14); color: var(--text-2); }
.card-icon svg { width: 19px; height: 19px; }
.card-body { flex: 1; min-width: 0; }
.card-title {
  font-size: 16px; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.card-sub { font-size: 13px; color: var(--text-2); margin-top: 4px; display: flex; flex-wrap: wrap; align-items: flex-start; gap: 4px 6px; min-width: 0; }
.card-hoi { min-width: 0; flex: 1 1 auto; line-height: 1.3; }
.card-parts { font-size: 12px; color: var(--text-2); flex-shrink: 0; white-space: nowrap; }

#ytViewer {
  display: none; position: fixed; inset: 0; background: rgba(0, 0, 0, 0.92); z-index: 999;
  align-items: center; justify-content: center;
  padding-top: env(safe-area-inset-top); padding-bottom: env(safe-area-inset-bottom);
}
.yt-frame-wrap {
  width: min(92vw, 420px); aspect-ratio: 9 / 16; border-radius: 14px; overflow: hidden;
  background: #000; box-shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
}
.yt-frame-wrap iframe { width: 100%; height: 100%; border: none; }

.badge {
  display: flex; align-items: center; gap: 5px;
  font-size: 12px; font-weight: 700;
  padding: 5px 10px;
  border-radius: 100px;
  flex-shrink: 0;
  white-space: nowrap;
}
.badge .dot { width: 7px; height: 7px; border-radius: 50%; }
.card-copy-btn {
  width: 36px; height: 36px; border-radius: 10px; border: none; cursor: pointer; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  background: rgba(118, 118, 128, 0.12); color: var(--text-2);
}
.card-copy-btn:active { transform: scale(0.9); background: rgba(118, 118, 128, 0.2); }
.card-copy-btn svg { width: 16px; height: 16px; }

/* ---------- Side menu ---------- */
.overlay {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0.3);
  z-index: 199; opacity: 0; pointer-events: none;
  transition: opacity 0.25s var(--ease-ios);
}
.overlay.show { opacity: 1; pointer-events: auto; }
.side-menu {
  position: fixed; top: 0; bottom: 0; left: 0;
  width: 78%; max-width: 300px;
  background: var(--card);
  z-index: 200;
  transform: translateX(-100%);
  transition: transform 0.28s var(--ease-ios);
  display: flex; flex-direction: column;
  padding-top: env(safe-area-inset-top);
  box-shadow: 2px 0 20px rgba(0, 0, 0, 0.15);
}
.side-menu.show { transform: translateX(0); }
.side-menu-head {
  padding: 20px 20px 16px;
  font-size: 18px; font-weight: 700;
  border-bottom: 0.5px solid var(--divider);
}
.side-menu-items { padding: 8px 0; overflow-y: auto; flex: 1; }
.menu-item {
  display: flex; align-items: center; gap: 14px;
  padding: 13px 20px;
  font-size: 16px; font-weight: 500;
  cursor: pointer; background: none; border: none; width: 100%;
  text-align: left; color: var(--text);
}
.menu-item:active { background: var(--bg); }
.menu-item svg { width: 20px; height: 20px; color: var(--blue); flex-shrink: 0; }
.menu-item-static { cursor: default; padding-bottom: 6px; }
.menu-item-static:active { background: none; }
.submenu { /* chiều cao tự nhiên, cuộn chung với .side-menu-items - không giới hạn/cuộn riêng */ }
.submenu-item {
  padding: 11px 20px 11px 54px;
  font-size: 14.5px; color: var(--text-2); font-weight: 500;
  cursor: pointer;
}
.submenu-item:active { background: var(--bg); }
.submenu-all-link { display: block; color: var(--blue); font-weight: 700; border-top: 0.5px solid var(--divider); margin-top: 2px; }
.submenu-loading { padding: 10px 20px 10px 54px; font-size: 13px; color: var(--text-2); }

/* ---------- Donate modal ---------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0.45);
  z-index: 299; display: flex; align-items: flex-end;
  opacity: 0; pointer-events: none;
  transition: opacity 0.25s var(--ease-ios);
}
.modal-overlay.show { opacity: 1; pointer-events: auto; }
.modal {
  background: var(--card);
  width: 100%;
  border-radius: 20px 20px 0 0;
  padding: 20px 20px calc(env(safe-area-inset-bottom) + 20px);
  transform: translateY(100%);
  transition: transform 0.28s var(--ease-ios);
  max-width: 480px; margin: 0 auto;
}
.modal-overlay.show .modal { transform: translateY(0); }
.modal-title { font-size: 18px; font-weight: 700; margin-bottom: 14px; text-align: center; }
.modal-qr { width: 180px; height: 180px; object-fit: contain; display: block; margin: 0 auto 16px; border-radius: 12px; background: #fff; }
.modal-info { background: var(--bg); border-radius: 12px; padding: 14px; font-size: 14px; }
.modal-info-row { display: flex; justify-content: space-between; padding: 6px 0; }
.modal-info-row + .modal-info-row { border-top: 0.5px solid var(--divider); }
.modal-info-label { color: var(--text-2); }
.modal-info-value { font-weight: 600; }
.modal-close-btn {
  display: block; width: 100%; margin-top: 16px;
  background: var(--blue); color: #fff; border: none;
  border-radius: var(--radius-btn); padding: 13px; font-size: 16px; font-weight: 700;
  cursor: pointer;
}

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 24px);
  transform: translateX(-50%) translateY(20px);
  background: rgba(28, 28, 30, 0.92); color: #fff;
  padding: 10px 16px; border-radius: 100px;
  font-size: 14px; font-weight: 600;
  display: flex; align-items: center; gap: 10px;
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  opacity: 0; pointer-events: none;
  transition: opacity 0.25s var(--ease-ios), transform 0.25s var(--ease-ios);
  z-index: 1100; max-width: 88%;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); pointer-events: auto; }
.toast-retry {
  background: var(--blue); color: #fff; border: none;
  border-radius: 100px; padding: 5px 12px; font-size: 13px; font-weight: 700; cursor: pointer;
}
