/* ===================================
   RESET & BASE STYLES
   =================================== */
* { 
  margin: 0; 
  padding: 0; 
  box-sizing: border-box; 
}

body { 
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  min-height: 100vh;
  padding: 20px;
}

/* ===============================
   Test sticky submit bar (mobile-first)
   - Hiện khi đang làm bài thi
   - Không che nội dung: body sẽ được add class .has-test-sticky để chừa padding
================================= */

body.has-test-sticky {
  /* chừa chỗ cho thanh sticky (đủ cho mobile + safe area) */
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
}

.test-sticky-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 999;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-top: 1px solid rgba(0, 0, 0, 0.06);
  box-shadow: 0 -8px 20px rgba(0, 0, 0, 0.08);
}

.test-sticky-inner {
  max-width: 980px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.test-sticky-meta {
  display: flex;
  align-items: baseline;
  gap: 12px;
  min-width: 0;
}

.test-sticky-timer {
  font-weight: 900;
  letter-spacing: 0.5px;
  color: #667eea;
  font-size: 16px;
}

.test-sticky-progress {
  font-weight: 800;
  color: #444;
  font-size: 13px;
  opacity: 0.9;
  white-space: nowrap;
}

.test-sticky-submit {
  padding: 10px 16px !important;
  font-size: 14px !important;
  font-weight: 900 !important;
  border-radius: 12px !important;
}

@media (max-width: 480px) {
  body.has-test-sticky {
    padding-bottom: calc(80px + env(safe-area-inset-bottom));
  }
  .test-sticky-inner {
    gap: 8px;
  }
  .test-sticky-timer {
    font-size: 15px;
  }
  .test-sticky-progress {
    font-size: 12px;
  }
  .test-sticky-submit {
    padding: 10px 14px !important;
    font-size: 13px !important;
  }
}

/* ===================================
   CONTAINER
   =================================== */
.container { 
  max-width: 1000px; 
  margin: 0 auto; 
  background: white;
  border-radius: 20px;
  padding: 30px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}

h1 { 
  color: #667eea; 
  margin-bottom: 10px;
  font-size: 32px;
  text-align: center;
}

.subtitle {
  text-align: center;
  color: #666;
  margin-bottom: 30px;
  font-size: 16px;
}

/* ===================================
   TABS NAVIGATION
   =================================== */
.tabs {
  display: flex;
  gap: 10px;
  margin-bottom: 30px;
  flex-wrap: wrap;
}

.tab {
  padding: 12px 24px;
  background: #f5f5f5;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  font-size: 16px;
  font-weight: 500;
  transition: all 0.3s;
}

.tab:hover {
  background: #e0e0e0;
  transform: translateY(-2px);
}

.tab.active {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
}

/* ===================================
   TAB CONTENT
   =================================== */
.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
}

/* ===================================
   STATS DASHBOARD
   =================================== */
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 20px;
  margin-bottom: 30px;
}

.stat-card {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  padding: 20px;
  border-radius: 15px;
  text-align: center;
}

.stat-number {
  font-size: 36px;
  font-weight: bold;
  margin-bottom: 5px;
}

.stat-label {
  font-size: 14px;
  opacity: 0.9;
}

/* ===================================
   CATEGORY FILTER
   =================================== */
.filter-section {
  margin-bottom: 30px;
}

.filter-section h3 {
  margin-bottom: 15px;
  color: #333;
}

.category-filter {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 10px;
}

.category-btn {
  padding: 12px;
  background: white;
  border: 2px solid #667eea;
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.3s;
  text-align: left;
  font-size: 14px;
}

.category-btn:hover {
  background: #f0f0ff;
}

.category-btn.active {
  background: #667eea;
  color: white;
}

.category-count {
  float: right;
  font-weight: bold;
}

/* ===================================
   PROGRESS BAR
   =================================== */
.progress-container {
  margin-bottom: 20px;
}

.progress-bar {
  height: 10px;
  background: #e0e0e0;
  border-radius: 5px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #667eea, #764ba2);
  transition: width 0.3s;
}

.progress-text {
  text-align: center;
  margin-top: 10px;
  color: #666;
  font-size: 14px;
}

/* ===================================
   QUESTION CARD
   =================================== */
.question-card {
  background: #f8f9fa;
  padding: 30px;
  border-radius: 15px;
  margin-bottom: 20px;
  border-left: 5px solid #667eea;
}

.question-number {
  color: #667eea;
  font-weight: bold;
  margin-bottom: 10px;
  font-size: 14px;
}

.question-text {
  font-size: 18px;
  font-weight: 500;
  margin-bottom: 20px;
  line-height: 1.6;
  color: #333;
}

.question-category {
  display: inline-block;
  background: #667eea;
  color: white;
  padding: 5px 15px;
  border-radius: 20px;
  font-size: 12px;
  margin-bottom: 15px;
}

/* ===================================
   ANSWERS
   =================================== */
.answers {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.answer {
  padding: 15px 20px;
  background: white;
  border: 2px solid #e0e0e0;
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.3s;
  font-size: 16px;
  line-height: 1.5;
}

.answer:hover {
  border-color: #667eea;
  transform: translateX(5px);
}

.answer.selected {
  border-color: #667eea;
  background: #f0f0ff;
}

.answer.correct {
  background: #4CAF50;
  color: white;
  border-color: #4CAF50;
}

.answer.wrong {
  background: #f44336;
  color: white;
  border-color: #f44336;
}

/* Answer Card (used in new rendering) */
.answer-card {
  padding: 15px 20px;
  background: white;
  border: 2px solid #e0e0e0;
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.3s;
  display: flex;
  align-items: center;
  gap: 15px;
}

.answer-card:hover {
  border-color: #667eea;
  transform: translateX(5px);
  box-shadow: 0 2px 8px rgba(102, 126, 234, 0.2);
}

.answer-card.selected {
  border-color: #667eea;
  background: #f0f0ff;
  box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
}

.answer-card.correct {
  background: #4CAF50;
  color: white;
  border-color: #4CAF50;
}

.answer-card.wrong {
  background: #f44336;
  color: white;
  border-color: #f44336;
}

.answer-letter {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: #667eea;
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
}

.answer-card.correct .answer-letter {
  background: #2e7d32;
}

.answer-card.wrong .answer-letter {
  background: #c62828;
}

.answer-text {
  flex: 1;
  font-size: 16px;
  line-height: 1.5;
}

.answers-grid {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin: 20px 0;
}

/* ===================================
   BUTTONS
   =================================== */
.btn-group {
  display: flex;
  gap: 15px;
  margin-top: 30px;
}

button {
  flex: 1;
  padding: 15px;
  border: none;
  border-radius: 10px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s;
}

.btn-primary {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
}

.btn-secondary {
  background: #f5f5f5;
  color: #333;
}

.btn-secondary:hover {
  background: #e0e0e0;
}

.btn-success {
  background: #4CAF50;
  color: white;
}

.btn-warning {
  background: #FF9800;
  color: white;
}

/* ===================================
   TEST MODE
   =================================== */
.timer {
  text-align: center;
  font-size: 48px;
  font-weight: bold;
  color: #667eea;
  margin: 20px 0;
}

.test-grid {
  display: grid;
  grid-template-columns: repeat(10, 1fr);
  gap: 8px;
  margin: 20px 0;
  max-height: 300px;
  overflow-y: auto;
  padding: 15px;
  background: #f5f5f5;
  border-radius: 10px;
}

.test-grid-item {
  width: 50px;
  height: 50px;
  border-radius: 8px;
  border: 2px solid #e0e0e0;
  background: white;
  cursor: pointer;
  font-weight: bold;
  transition: all 0.3s;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
}

.test-grid-item:hover {
  border-color: #667eea;
  transform: scale(1.05);
  box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
}

.test-grid-item.answered {
  background: #4CAF50;
  color: white;
  border-color: #4CAF50;
}

.test-grid-item.current {
  background: #667eea;
  color: white;
  border-color: #667eea;
  transform: scale(1.1);
}

.test-answer-option {
  display: flex;
  align-items: center;
  padding: 15px;
  background: #f8f9fa;
  border: 2px solid #e0e0e0;
  border-radius: 10px;
  transition: all 0.3s;
}

.test-answer-option:hover {
  background: #e3f2fd;
  border-color: #667eea;
}

.test-answer-option.selected {
  background: #e8f5e9;
  border-color: #4CAF50;
  box-shadow: 0 2px 8px rgba(76, 175, 80, 0.3);
}

.test-answer-option input[type="radio"] {
  accent-color: #667eea;
}

.test-question-block {
  scroll-margin-top: 80px;
}

.question-nav-btn {
  width: 50px;
  height: 50px;
  border-radius: 8px;
  border: 2px solid #e0e0e0;
  background: white;
  cursor: pointer;
  font-weight: bold;
  transition: all 0.3s;
}

.question-nav-btn:hover {
  border-color: #667eea;
}

.question-nav-btn.answered {
  background: #4CAF50;
  color: white;
  border-color: #4CAF50;
}

.question-nav-btn.current {
  background: #667eea;
  color: white;
  border-color: #667eea;
}

/* ===================================
   RESULTS
   =================================== */
.results {
  text-align: center;
  padding: 40px;
}

.score-circle {
  width: 200px;
  height: 200px;
  border-radius: 50%;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  margin: 0 auto 30px;
  box-shadow: 0 10px 30px rgba(102, 126, 234, 0.3);
}

.score-number {
  font-size: 64px;
  font-weight: bold;
}

.score-label {
  font-size: 18px;
  margin-top: 10px;
}

.result-details {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 20px;
  margin: 30px 0;
}

.result-item {
  padding: 20px;
  background: #f8f9fa;
  border-radius: 10px;
}

.result-item-number {
  font-size: 32px;
  font-weight: bold;
  margin-bottom: 5px;
}

.result-item-label {
  color: #666;
}

/* ===================================
   TIPS SECTION
   =================================== */
.tips-container {
  margin: 20px 0;
}

.tip-card {
  background: #f8f9fa;
  padding: 20px;
  border-radius: 15px;
  margin-bottom: 20px;
  border-left: 5px solid #FF9800;
}

.tip-title {
  font-size: 20px;
  font-weight: bold;
  color: #FF9800;
  margin-bottom: 15px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.tip-item {
  background: white;
  padding: 15px;
  border-radius: 10px;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 15px;
}

.tip-emoji {
  font-size: 32px;
}

.tip-content {
  flex: 1;
}

.tip-number {
  font-size: 24px;
  font-weight: bold;
  color: #667eea;
}

.tip-meaning {
  color: #666;
  margin-top: 5px;
}

/* ===================================
   RESPONSIVE
   =================================== */
@media (max-width: 768px) {
  .container { 
    padding: 20px; 
  }
  
  h1 { 
    font-size: 24px; 
  }
  
  .stats { 
    grid-template-columns: 1fr; 
  }
  
  .result-details { 
    grid-template-columns: 1fr; 
  }
  
  .category-filter { 
    grid-template-columns: 1fr; 
  }
  
  .test-grid { 
    grid-template-columns: repeat(5, 1fr); 
  }
  
  .btn-group {
    flex-direction: column;
  }
  
  button {
    width: 100%;
  }
  
  .timer {
    font-size: 36px;
  }
}

/* ===================================
   UTILITY CLASSES
   =================================== */
.text-center {
  text-align: center;
}

.mt-20 {
  margin-top: 20px;
}

.mb-20 {
  margin-bottom: 20px;
}

.hidden {
  display: none;
}

/* ===================================
   APP FONT SCALE (A- / A+)
   - Áp dụng toàn app, lưu localStorage
   - Chỉ scale chữ (không zoom layout)
   =================================== */
:root {
  --app-font-scale: 1;
}

/* Base font (các chỗ dùng em/rem sẽ tự scale) */
body {
  font-size: calc(16px * var(--app-font-scale));
}

/* Scale các phần đang dùng px cứng */
.subtitle {
  font-size: calc(16px * var(--app-font-scale));
}

.tab {
  font-size: calc(16px * var(--app-font-scale));
}

.progress-text {
  font-size: calc(14px * var(--app-font-scale));
}

.question-number {
  font-size: calc(14px * var(--app-font-scale));
}

.question-text {
  font-size: calc(18px * var(--app-font-scale));
  line-height: calc(1.6 * (1 / var(--app-font-scale)) + 0.0);
}

.question-category {
  font-size: calc(12px * var(--app-font-scale));
}

.answer {
  font-size: calc(16px * var(--app-font-scale));
}

.timer {
  font-size: calc(20px * var(--app-font-scale));
}

/* Tips content (nếu tips render bằng thẻ p/li trong #tipsContent) */
#tipsContent,
#tipsContent p,
#tipsContent li {
  font-size: calc(16px * var(--app-font-scale));
}

/* Review/Test results text */
#reviewContent,
#testResults {
  font-size: calc(16px * var(--app-font-scale));
}

/* ===================================
   FONT FAB (A- / A+) - always visible
   =================================== */
.font-fab {
  position: fixed;
  right: 12px;
  bottom: calc(12px + env(safe-area-inset-bottom));
  z-index: 1000;
  display: flex;
  gap: 6px;
  padding: 8px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid rgba(0, 0, 0, 0.08);
  box-shadow: 0 10px 24px rgba(0,0,0,0.12);
}

/* Khi đang thi (có sticky submit bar) thì nhấc font-fab lên để không đè nhau */
body.has-test-sticky .font-fab {
  bottom: calc(86px + env(safe-area-inset-bottom));
}

.font-fab-btn {
  min-width: 38px;
  height: 34px;
  border-radius: 10px;
  border: 1px solid rgba(0, 0, 0, 0.12);
  background: #fff;
  font-weight: 900;
  font-size: 14px;
  cursor: pointer;
}

.font-fab-btn:active {
  background: #f2f2f2;
}

.font-fab-reset {
  opacity: 0.85;
}

@media (max-width: 480px) {
  .font-fab {
    right: 10px;
    padding: 7px;
    border-radius: 16px;
  }
  .font-fab-btn {
    min-width: 40px;
    height: 36px;
    border-radius: 12px;
    font-size: 14px;
  }
}

/* =========================================================
   FONT SIZE (A-/A+) - GLOBAL (mobile-first)
   - Điều chỉnh cỡ chữ toàn app bằng CSS variable
   - Lưu vào localStorage (handled in app.js)
   ========================================================= */
:root {
  --app-font-scale: 1;
}

/* Base font scale (các text không set font-size sẽ tự scale) */
body {
  font-size: calc(16px * var(--app-font-scale));
}

/* Override các chỗ dùng px cứng để cũng scale theo */
.subtitle { font-size: calc(16px * var(--app-font-scale)); }
.tab { font-size: calc(16px * var(--app-font-scale)); }
.progress-text { font-size: calc(14px * var(--app-font-scale)); }

.question-number { font-size: calc(14px * var(--app-font-scale)); }
.question-text { font-size: calc(18px * var(--app-font-scale)); }
.question-category { font-size: calc(12px * var(--app-font-scale)); }
.answer { font-size: calc(16px * var(--app-font-scale)); }

/* Test */
.timer { font-size: calc(18px * var(--app-font-scale)) !important; }
.test-sticky-timer { font-size: calc(16px * var(--app-font-scale)); }
.test-sticky-progress { font-size: calc(13px * var(--app-font-scale)); }

/* Tips + Review thường dùng chữ dài */
#tipsContent, #reviewContent, #testResults {
  font-size: calc(16px * var(--app-font-scale));
}

/* =========================
   Font FAB (A- / A+)
   ========================= */
.font-fab {
  position: fixed;
  right: 12px;
  bottom: calc(12px + env(safe-area-inset-bottom));
  z-index: 1001;
  display: flex;
  gap: 8px;
  padding: 8px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid rgba(0, 0, 0, 0.08);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.12);
}

/* Khi đang có test sticky bar -> đẩy FAB lên, tránh chồng */
body.has-test-sticky .font-fab {
  bottom: calc(88px + env(safe-area-inset-bottom));
}

.font-fab-btn {
  min-width: 38px;
  height: 34px;
  border-radius: 12px;
  border: 1px solid rgba(0, 0, 0, 0.10);
  background: #fff;
  font-weight: 900;
  font-size: 14px;
  cursor: pointer;
  line-height: 1;
}

.font-fab-btn--reset {
  min-width: 34px;
  opacity: 0.85;
}

.font-fab-btn:active {
  transform: translateY(1px);
}

@media (max-width: 480px) {
  .font-fab {
    right: 10px;
    bottom: calc(10px + env(safe-area-inset-bottom));
    padding: 6px;
    gap: 6px;
    border-radius: 14px;
  }
  body.has-test-sticky .font-fab {
    bottom: calc(92px + env(safe-area-inset-bottom));
  }
  .font-fab-btn {
    min-width: 40px;
    height: 36px;
    border-radius: 12px;
    font-size: 15px;
  }
}



/* ============================================================
   COMPACT MODE FOR MOBILE + SCALE SPACING WITH --app-font-scale
   (Patch: giảm chữ + khung đáp án gọn theo)
   ============================================================ */

/* Desktop/base: nhỏ hơn trước một nấc */
.question-text {
  font-size: calc(16px * var(--app-font-scale));
  line-height: 1.45;
  margin-bottom: calc(12px * var(--app-font-scale));
}

.answer-text {
  font-size: calc(14px * var(--app-font-scale));
  line-height: 1.4;
}

/* Khung đáp án gọn theo */
.test-answer-option {
  padding: calc(12px * var(--app-font-scale)) calc(14px * var(--app-font-scale));
  border-radius: calc(10px * var(--app-font-scale));
  margin-bottom: calc(10px * var(--app-font-scale));
}

.answer-card {
  padding: calc(12px * var(--app-font-scale)) calc(14px * var(--app-font-scale));
  border-radius: calc(12px * var(--app-font-scale));
}

/* Badge A/B/C/D gọn theo */
.question-badge {
  width: calc(34px * var(--app-font-scale));
  height: calc(34px * var(--app-font-scale));
  border-radius: calc(17px * var(--app-font-scale));
  font-size: calc(14px * var(--app-font-scale));
}

/* Mobile: nhỏ thêm nữa để bao quát */
@media (max-width: 480px) {
  .question-text {
    font-size: calc(14px * var(--app-font-scale));
    line-height: 1.38;
    margin-bottom: calc(10px * var(--app-font-scale));
  }

  .answer-text {
    font-size: calc(13px * var(--app-font-scale));
    line-height: 1.32;
  }

  .test-answer-option {
    padding: calc(10px * var(--app-font-scale)) calc(12px * var(--app-font-scale));
    border-radius: calc(10px * var(--app-font-scale));
    margin-bottom: calc(8px * var(--app-font-scale));
  }

  .question-badge {
    width: calc(32px * var(--app-font-scale));
    height: calc(32px * var(--app-font-scale));
    border-radius: calc(16px * var(--app-font-scale));
    font-size: calc(13px * var(--app-font-scale));
  }

  /* Nút điều hướng/hiện đáp án gọn hơn */
  .btn-primary, .btn-secondary, .btn-warning, .btn-success {
    padding: calc(10px * var(--app-font-scale)) calc(14px * var(--app-font-scale));
    font-size: calc(14px * var(--app-font-scale));
  }
}
