/* ============================================
   TIENGTRUNGBOI.COM - Stylesheet v3.1
   FIX: Force ẩn menu desktop trên mobile
   ============================================ */

/* ⚠️ CRITICAL RULES - đặt đầu file để ưu tiên cao,
   không thể bị override bởi rules sau */
@media only screen and (max-width: 768px) {
  header.site-header nav.desktop-nav,
  .site-header .desktop-nav,
  nav.desktop-nav,
  .desktop-nav {
    display: none !important;
    visibility: hidden !important;
    width: 0 !important;
    height: 0 !important;
    overflow: hidden !important;
    position: absolute !important;
    left: -9999px !important;
  }
  .mobile-header-right {
    display: flex !important;
    align-items: center;
    gap: 6px;
  }
  nav.bottom-tabs,
  .bottom-tabs {
    display: flex !important;
    position: fixed !important;
    bottom: 0 !important;
    left: 0 !important;
    right: 0 !important;
    z-index: 9999 !important;
    background: #fff !important;
  }
  .site-footer { display: none !important; }
  body { padding-bottom: 70px !important; }
}

/* Dự phòng: Nếu CSS bị lỗi và menu desktop bị hiện,
   chữ menu LUÔN màu TRẮNG rõ ràng trên nền đỏ */
.site-header .desktop-nav a {
  color: #ffffff !important;
}
.site-header .desktop-nav a:hover,
.site-header .desktop-nav a.active {
  background: #FFD700 !important;
  color: #8B0000 !important;
}

:root {
  --red: #C8102E;
  --red-dark: #8B0000;
  --red-light: #FF6B6B;
  --yellow: #FFD700;
  --yellow-dark: #F5B800;
  --yellow-light: #FFF4B8;
  --cream: #FFF9E6;
  --ink: #1a1a1a;
  --gray: #6b7280;
  --gray-light: #f3f4f6;
  --shadow: 0 4px 12px rgba(200,16,46,.12);
  --shadow-lg: 0 8px 30px rgba(200,16,46,.18);
  --shadow-up: 0 -2px 12px rgba(0,0,0,.08);
  --radius: 12px;
  --tab-height: 64px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

body {
  font-family: 'Be Vietnam Pro', -apple-system, sans-serif;
  background: linear-gradient(180deg, #FFFBF0 0%, #fff 100%);
  color: var(--ink);
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
}

.container { max-width: 1200px; margin: 0 auto; padding: 0 16px; }
a { color: var(--red); text-decoration: none; }
a:hover { color: var(--red-dark); }

/* =============== HEADER =============== */
.site-header {
  background: linear-gradient(135deg, var(--red) 0%, var(--red-dark) 100%);
  color: #fff;
  box-shadow: var(--shadow-lg);
  position: sticky;
  top: 0;
  z-index: 100;
}
.nav-wrap {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
}
.logo { display: flex; align-items: center; gap: 10px; color: #fff; font-weight: 800; font-size: 19px; }
.logo-icon {
  background: var(--yellow);
  color: var(--red);
  width: 38px; height: 38px;
  display: grid; place-items: center;
  border-radius: 50%;
  font-size: 20px;
  font-weight: 900;
  box-shadow: 0 2px 8px rgba(0,0,0,.2);
}
.logo-text span { color: var(--yellow); }

/* Desktop nav */
.desktop-nav { display: flex; gap: 4px; align-items: center; flex-wrap: wrap; }
.desktop-nav a {
  color: #fff;
  padding: 8px 14px;
  border-radius: 8px;
  font-weight: 500;
  font-size: 14px;
  transition: all .2s;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.desktop-nav a:hover, .desktop-nav a.active {
  background: var(--yellow);
  color: var(--red-dark);
}
.btn-login, .btn-logout {
  border: 2px solid var(--yellow);
}
.user-btn {
  background: rgba(255,215,0,.15);
}
.badge-points {
  background: var(--yellow);
  color: var(--red-dark);
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
}

/* Mobile header right */
.mobile-header-right { display: none; }
.mobile-points {
  background: var(--yellow);
  color: var(--red-dark);
  padding: 6px 12px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 13px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.mobile-logout {
  color: #fff;
  font-size: 18px;
  padding: 6px 10px;
  border: 1.5px solid rgba(255,255,255,.4);
  border-radius: 8px;
  margin-left: 6px;
}

/* =============== BOTTOM TAB BAR =============== */
.bottom-tabs {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: #fff;
  box-shadow: var(--shadow-up);
  z-index: 100;
  padding-bottom: var(--safe-bottom);
  border-top: 1px solid #f0f0f0;
}
.bottom-tabs .tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 10px 4px 8px;
  height: var(--tab-height);
  color: #9ca3af;
  font-size: 11px;
  font-weight: 600;
  text-decoration: none;
  position: relative;
  transition: all .2s;
  letter-spacing: 0.3px;
}
.bottom-tabs .tab:hover { color: var(--red); }
.bottom-tabs .tab.active {
  color: var(--red);
  font-weight: 700;
}
.tab-icon {
  font-size: 22px;
  margin-bottom: 3px;
  transition: transform .2s;
  line-height: 1;
}
.bottom-tabs .tab.active .tab-icon {
  transform: scale(1.15);
}
.tab-label {
  font-size: 10px;
  line-height: 1.2;
  text-align: center;
  text-transform: uppercase;
}

/* =============== MAIN =============== */
.site-main { flex: 1; padding: 20px 0; }

/* =============== HERO =============== */
.hero {
  background: linear-gradient(135deg, var(--red) 0%, var(--red-dark) 100%);
  color: #fff;
  padding: 44px 16px;
  text-align: center;
  position: relative;
  overflow: hidden;
  border-radius: 0 0 30px 30px;
  margin: -20px 0 28px;
}
.hero::before {
  content: '中';
  position: absolute;
  font-size: 400px;
  font-weight: 900;
  opacity: .08;
  top: -100px;
  right: -50px;
  font-family: 'Noto Sans SC', serif;
}
.hero h1 { font-size: clamp(24px, 5vw, 44px); margin-bottom: 12px; line-height: 1.2; position: relative; }
.hero h1 span { color: var(--yellow); }
.hero p { font-size: clamp(14px, 2vw, 17px); opacity: .95; max-width: 700px; margin: 0 auto 18px; position: relative; }
.hero-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; position: relative; }

/* =============== BUTTONS =============== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 12px 22px;
  border-radius: 999px;
  font-weight: 600;
  border: none;
  cursor: pointer;
  font-size: 14px;
  transition: transform .15s, box-shadow .2s;
  text-decoration: none;
}
.btn:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.btn-primary { background: var(--yellow); color: var(--red-dark); }
.btn-secondary { background: #fff; color: var(--red); border: 2px solid var(--red); }
.btn-red { background: var(--red); color: #fff; }
.btn-block { display: flex; width: 100%; justify-content: center; }
.btn-sm { padding: 8px 14px; font-size: 13px; }

/* =============== SECTION TITLE =============== */
.section-title {
  text-align: center;
  font-size: clamp(19px, 3vw, 26px);
  margin-bottom: 18px;
  color: var(--red-dark);
  font-weight: 800;
}
.section-title::after {
  content: '';
  display: block;
  width: 60px;
  height: 4px;
  background: var(--yellow);
  margin: 8px auto 0;
  border-radius: 2px;
}

/* =============== CATEGORIES GRID =============== */
.cat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
  margin: 18px 0;
}
.cat-card {
  background: #fff;
  border: 2px solid var(--yellow-light);
  border-radius: var(--radius);
  padding: 16px 12px;
  text-align: center;
  transition: all .25s;
  position: relative;
  overflow: hidden;
}
.cat-card:hover { border-color: var(--red); transform: translateY(-3px); box-shadow: var(--shadow-lg); }
.cat-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 4px;
  background: linear-gradient(90deg, var(--red), var(--yellow));
}
.cat-icon { font-size: 34px; margin-bottom: 6px; display: block; }
.cat-card h3 { font-size: 14px; color: var(--red-dark); margin-bottom: 2px; }
.cat-card p { font-size: 12px; color: var(--gray); line-height: 1.4; }
.cat-card .count {
  display: inline-block;
  background: var(--yellow-light);
  color: var(--red-dark);
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  margin-top: 6px;
  font-weight: 600;
}

/* =============== PHRASE CARD =============== */
.phrase-list { display: flex; flex-direction: column; gap: 14px; max-width: 800px; margin: 0 auto; }
.phrase-card {
  background: #fff;
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
  border-left: 4px solid var(--red);
  position: relative;
}
.phrase-card.mastered { border-left-color: var(--yellow-dark); background: linear-gradient(90deg, var(--yellow-light) 0%, #fff 30%); }
.phrase-card .num {
  position: absolute;
  top: -8px; right: 14px;
  background: var(--red);
  color: #fff;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
}
.phrase-vi {
  font-size: 17px;
  font-weight: 600;
  color: var(--ink);
  margin-bottom: 10px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}
.btn-speak {
  background: var(--yellow);
  color: var(--red-dark);
  border: none;
  width: 38px; height: 38px;
  border-radius: 50%;
  font-size: 17px;
  cursor: pointer;
  flex-shrink: 0;
  transition: all .2s;
  box-shadow: 0 2px 6px rgba(245,184,0,.4);
}
.btn-speak:hover { background: var(--red); color: #fff; transform: scale(1.1); }
.btn-speak.playing { animation: pulse 1s infinite; }
@keyframes pulse { 0%,100% { transform: scale(1);} 50% { transform: scale(1.15); } }

.phrase-zh {
  font-family: 'Noto Sans SC', serif;
  font-size: 22px;
  color: var(--red-dark);
  margin: 6px 0;
  font-weight: 500;
}
.phrase-boi {
  background: var(--yellow-light);
  display: inline-block;
  padding: 4px 12px;
  border-radius: 6px;
  font-style: italic;
  color: var(--red-dark);
  font-weight: 500;
  margin: 6px 0;
}
.phrase-pinyin { color: var(--gray); font-size: 13px; }
.phrase-meta { display: flex; gap: 6px; margin-top: 10px; font-size: 11px; color: var(--gray); flex-wrap: wrap; }
.tag {
  background: var(--gray-light);
  padding: 2px 8px;
  border-radius: 4px;
}
.tag.mastered-tag { background: var(--yellow); color: var(--red-dark); font-weight: 600; }

/* =============== PRACTICE PAGE =============== */
.practice-box {
  max-width: 700px;
  margin: 0 auto;
  background: #fff;
  border-radius: 20px;
  padding: 24px 18px;
  box-shadow: var(--shadow-lg);
  text-align: center;
}
.practice-box .phrase-vi { justify-content: center; font-size: 20px; }
.practice-box .phrase-zh { font-size: 28px; }

.mic-btn {
  width: 110px; height: 110px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--red), var(--red-dark));
  color: #fff;
  border: 6px solid var(--yellow);
  font-size: 44px;
  cursor: pointer;
  margin: 18px auto;
  display: grid;
  place-items: center;
  box-shadow: 0 8px 30px rgba(200,16,46,.4);
  transition: all .2s;
}
.mic-btn:hover { transform: scale(1.05); }
.mic-btn.recording {
  animation: recording 1.5s infinite;
  background: linear-gradient(135deg, #ff4757, var(--red));
}
@keyframes recording {
  0%, 100% { box-shadow: 0 0 0 0 rgba(200,16,46,.6); }
  50% { box-shadow: 0 0 0 20px rgba(200,16,46,0); }
}

.score-display { font-size: 50px; font-weight: 800; margin: 16px 0 8px; }
.score-display.good { color: #16a34a; }
.score-display.bad { color: var(--red); }

.progress-bar {
  width: 100%;
  height: 10px;
  background: var(--gray-light);
  border-radius: 999px;
  overflow: hidden;
  margin: 12px 0;
}
.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--red), var(--yellow));
  width: 0%;
  transition: width .5s ease;
}

.heard-text {
  background: var(--yellow-light);
  padding: 12px;
  border-radius: 8px;
  margin: 10px 0;
  color: var(--red-dark);
  font-family: 'Noto Sans SC', serif;
  font-size: 16px;
  min-height: 44px;
}

.practice-controls {
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
  margin-top: 16px;
}

/* =============== DIALOGUES =============== */
.dialogue-list { display: grid; gap: 16px; max-width: 900px; margin: 0 auto; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.dialogue-card {
  background: #fff;
  border: 2px solid var(--yellow-light);
  border-radius: var(--radius);
  padding: 18px;
  transition: all .25s;
}
.dialogue-card:hover { border-color: var(--red); transform: translateY(-4px); }
.dialogue-card h3 { color: var(--red-dark); margin-bottom: 8px; font-size: 16px; }
.dialogue-card .scenario { color: var(--gray); font-size: 13px; margin-bottom: 10px; }

.dialogue-detail {
  max-width: 750px;
  margin: 0 auto;
  background: #fff;
  padding: 20px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.dialogue-line {
  padding: 14px;
  border-radius: 12px;
  margin-bottom: 10px;
  position: relative;
}
.dialogue-line.A { background: var(--yellow-light); margin-right: 20px; }
.dialogue-line.B { background: #ffe4e6; margin-left: 20px; }
.speaker-tag {
  position: absolute;
  top: -8px;
  background: var(--red);
  color: #fff;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
}
.dialogue-line.A .speaker-tag { left: 12px; background: var(--yellow-dark); color: var(--red-dark); }
.dialogue-line.B .speaker-tag { right: 12px; }

/* =============== AUTH FORM =============== */
.auth-box {
  max-width: 420px;
  margin: 30px auto;
  background: #fff;
  padding: 26px;
  border-radius: 20px;
  box-shadow: var(--shadow-lg);
  border-top: 6px solid var(--red);
}
.auth-box h2 { color: var(--red-dark); text-align: center; margin-bottom: 20px; }
.form-group { margin-bottom: 14px; }
.form-group label { display: block; margin-bottom: 6px; font-weight: 600; color: var(--ink); font-size: 14px; }
.form-group input {
  width: 100%;
  padding: 12px;
  border: 2px solid var(--gray-light);
  border-radius: 8px;
  font-size: 15px;
  font-family: inherit;
  transition: border-color .2s;
}
.form-group input:focus { outline: none; border-color: var(--red); }
.alert {
  padding: 12px;
  border-radius: 8px;
  margin-bottom: 14px;
  font-size: 14px;
}
.alert-error { background: #fee2e2; color: #991b1b; border: 1px solid #fca5a5; }
.alert-success { background: #d1fae5; color: #065f46; border: 1px solid #6ee7b7; }
.auth-link { text-align: center; margin-top: 14px; font-size: 14px; }

/* =============== PROFILE =============== */
.profile-header {
  background: linear-gradient(135deg, var(--red), var(--red-dark));
  color: #fff;
  padding: 28px 20px;
  border-radius: var(--radius);
  text-align: center;
  margin-bottom: 18px;
  position: relative;
  overflow: hidden;
}
.profile-header::before {
  content: '⭐';
  position: absolute;
  font-size: 180px;
  opacity: .1;
  right: -20px;
  top: -40px;
}
.profile-avatar {
  width: 76px; height: 76px;
  border-radius: 50%;
  background: var(--yellow);
  color: var(--red-dark);
  font-size: 34px;
  font-weight: 900;
  display: grid;
  place-items: center;
  margin: 0 auto 8px;
  border: 4px solid var(--yellow-light);
}
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 12px;
  margin: 18px 0;
}
.stat-card {
  background: #fff;
  padding: 18px 12px;
  border-radius: var(--radius);
  text-align: center;
  box-shadow: var(--shadow);
  border-top: 4px solid var(--yellow);
}
.stat-num { font-size: 28px; font-weight: 800; color: var(--red); }
.stat-label { color: var(--gray); font-size: 12px; margin-top: 4px; }

/* =============== CONNECT =============== */
.service-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 16px;
}
.service-card {
  background: #fff;
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  border-bottom: 4px solid var(--yellow);
  transition: all .25s;
}
.service-card:hover { transform: translateY(-4px); box-shadow: var(--shadow-lg); border-bottom-color: var(--red); }
.service-icon {
  font-size: 40px;
  background: var(--yellow-light);
  width: 68px; height: 68px;
  border-radius: 18px;
  display: grid;
  place-items: center;
  margin-bottom: 10px;
}
.service-card h3 { color: var(--red-dark); margin-bottom: 6px; font-size: 17px; }
.service-card p { color: var(--gray); font-size: 13px; margin-bottom: 10px; }
.service-card .contact {
  background: var(--cream);
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 13px;
  color: var(--red-dark);
  font-weight: 500;
  display: inline-block;
}

/* =============== RANKING PAGE =============== */
.rank-list { max-width: 700px; margin: 0 auto; }
.rank-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px;
  background: #fff;
  border-radius: var(--radius);
  margin-bottom: 8px;
  box-shadow: var(--shadow);
  transition: all .2s;
}
.rank-item:hover { transform: translateX(4px); }
.rank-item.me { background: linear-gradient(90deg, var(--yellow-light), #fff); border: 2px solid var(--yellow); }
.rank-pos {
  width: 40px; height: 40px;
  border-radius: 50%;
  background: var(--gray-light);
  color: var(--gray);
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 17px;
  flex-shrink: 0;
}
.rank-pos.gold { background: linear-gradient(135deg, #FFD700, #F5B800); color: #fff; box-shadow: 0 2px 8px rgba(245,184,0,.5); }
.rank-pos.silver { background: linear-gradient(135deg, #C0C0C0, #999); color: #fff; }
.rank-pos.bronze { background: linear-gradient(135deg, #CD7F32, #8B4513); color: #fff; }
.rank-name { flex: 1; }
.rank-name strong { display: block; color: var(--red-dark); font-size: 15px; }
.rank-name small { color: var(--gray); font-size: 12px; }
.rank-score {
  background: var(--red);
  color: #fff;
  padding: 6px 14px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 14px;
}

/* =============== FILTER BAR =============== */
.filter-bar {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 16px;
  justify-content: center;
  overflow-x: auto;
}
.filter-bar a {
  padding: 6px 12px;
  border-radius: 999px;
  background: #fff;
  color: var(--red-dark);
  border: 2px solid var(--yellow);
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
}
.filter-bar a.active, .filter-bar a:hover {
  background: var(--red);
  color: #fff;
  border-color: var(--red);
}

/* =============== FOOTER (Desktop only) =============== */
.site-footer {
  background: var(--red-dark);
  color: #fff;
  padding: 36px 0 0;
  margin-top: 50px;
}
.footer-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 20px;
  padding-bottom: 20px;
}
.site-footer h4 { color: var(--yellow); margin-bottom: 10px; font-size: 15px; }
.site-footer a { color: #fff; display: block; margin-bottom: 6px; opacity: .85; font-size: 13px; }
.site-footer a:hover { color: var(--yellow); opacity: 1; }
.site-footer p { font-size: 13px; opacity: .85; margin-bottom: 6px; }
.footer-bottom {
  border-top: 1px solid rgba(255,255,255,.15);
  padding: 14px;
  text-align: center;
  font-size: 12px;
  opacity: .8;
}

/* =============== BROWSER WARNING =============== */
.browser-warning {
  background: #fef3c7;
  border: 2px solid var(--yellow-dark);
  color: #78350f;
  padding: 10px 14px;
  margin: 12px 16px;
  border-radius: 8px;
  text-align: center;
  font-size: 13px;
}

/* =============== UTILITIES =============== */
.text-center { text-align: center; }
.mb-2 { margin-bottom: 14px; }
.mt-2 { margin-top: 14px; }
.hidden { display: none !important; }

/* ============================================================
   MOBILE - ẨN DESKTOP NAV + HIỂN BOTTOM TAB BAR
   Dùng !important để chắc chắn ưu tiên
   ============================================================ */
@media (max-width: 768px) {
  .desktop-nav { display: none !important; }
  .mobile-header-right { display: flex !important; align-items: center; gap: 6px; }
  .bottom-tabs { display: flex !important; }
  .site-footer { display: none !important; }

  /* Body padding để không bị tab che */
  body { padding-bottom: calc(var(--tab-height) + var(--safe-bottom)) !important; }

  .nav-wrap { padding: 10px 12px; }
  .logo-text { font-size: 16px; }
  .logo-icon { width: 34px; height: 34px; font-size: 17px; }
  .hero { padding: 32px 16px; border-radius: 0 0 24px 24px; margin: -20px 0 24px; }
  .practice-box .phrase-zh { font-size: 22px; }
  .mic-btn { width: 90px; height: 90px; font-size: 36px; }
  .stat-num { font-size: 24px; }
  .dialogue-line.A { margin-right: 12px; }
  .dialogue-line.B { margin-left: 12px; }
  .cat-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .cat-card { padding: 12px 8px; }
  .cat-icon { font-size: 28px; }
  .container { padding: 0 12px; }
}

/* ============================================================
   DESKTOP - ẨN BOTTOM TAB BAR
   ============================================================ */
@media (min-width: 769px) {
  .bottom-tabs { display: none !important; }
  .mobile-header-right { display: none !important; }
}
