/* ========== Reset & Base ========== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-tap-highlight-color: transparent; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: linear-gradient(145deg, #0a0a1a 0%, #1a1a2e 50%, #0f0f23 100%);
  color: #e0e0e0;
  min-height: 100vh;
  overflow-x: hidden;
  line-height: 1.5;
}
body::before {
  content: '';
  position: fixed; top: 0; left: 0; right: 0; bottom: 0;
  background: radial-gradient(circle at 20% 20%, rgba(108,92,231,0.08) 0%, transparent 50%),
              radial-gradient(circle at 80% 80%, rgba(0,206,201,0.06) 0%, transparent 50%);
  pointer-events: none; z-index: 0;
}

/* ========== App Container ========== */
.app-container {
  max-width: 520px; margin: 0 auto; min-height: 100vh;
  position: relative; z-index: 1; padding: 0 16px 24px;
}

/* ========== Loading ========== */
.loading-screen {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-height: 60vh; gap: 16px; color: rgba(255,255,255,0.5);
}
.loading-spinner {
  width: 40px; height: 40px; border: 3px solid rgba(108,92,231,0.2);
  border-top-color: #6C5CE7; border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ========== Nav Bar ========== */
.nav-bar {
  position: sticky; top: 0; z-index: 100;
  display: flex; align-items: center; height: 56px;
  background: rgba(10,10,26,0.85); backdrop-filter: blur(20px);
  margin: 0 -16px; padding: 0 16px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}
.nav-bar.hidden { display: none; }
.back-btn {
  background: none; border: none; color: #6C5CE7; font-size: 1.5rem;
  cursor: pointer; padding: 8px; margin-left: -8px; margin-right: 4px;
  display: flex; align-items: center; transition: transform 0.2s;
}
.back-btn:active { transform: scale(0.9); }
.nav-title {
  flex: 1; font-size: 1.1rem; font-weight: 600; color: #fff;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.nav-right { display: flex; gap: 8px; align-items: center; }
.nav-right button {
  background: none; border: none; color: rgba(255,255,255,0.7);
  font-size: 1.2rem; cursor: pointer; padding: 6px;
}

/* ========== Glass Card Mixin ========== */
.glass {
  background: rgba(255,255,255,0.05);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 16px;
}

/* ========== Home ========== */
.home-header {
  text-align: center; padding: 32px 0 20px;
}
.home-header h1 {
  font-size: 1.6rem; color: #fff; margin-bottom: 4px;
  background: linear-gradient(135deg, #6C5CE7, #00CEC9);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
  background-clip: text;
}
.home-header p { color: rgba(255,255,255,0.45); font-size: 0.85rem; }

.stats-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 24px;
}
.stat-card {
  padding: 16px; text-align: center;
  background: rgba(255,255,255,0.04); border-radius: 14px;
  border: 1px solid rgba(255,255,255,0.06);
}
.stat-icon { font-size: 1.4rem; margin-bottom: 4px; }
.stat-number { font-size: 1.5rem; font-weight: 700; color: #fff; }
.stat-number.purple { color: #6C5CE7; }
.stat-number.teal { color: #00CEC9; }
.stat-number.pink { color: #FD79A8; }
.stat-number.green { color: #00b894; }
.stat-label { font-size: 0.75rem; color: rgba(255,255,255,0.4); margin-top: 2px; }

.mode-cards { display: flex; flex-direction: column; gap: 12px; }
.mode-card {
  display: flex; align-items: center; gap: 16px;
  padding: 18px 20px; cursor: pointer;
  background: rgba(255,255,255,0.04); border-radius: 16px;
  border: 1px solid rgba(255,255,255,0.07);
  transition: all 0.3s ease;
}
.mode-card:active { transform: scale(0.97); }
.mode-icon { font-size: 2.2rem; flex-shrink: 0; }
.mode-info h3 { font-size: 1rem; color: #fff; font-weight: 600; margin-bottom: 2px; }
.mode-info p { font-size: 0.8rem; color: rgba(255,255,255,0.4); }
.mode-card.study { border-left: 3px solid #6C5CE7; }
.mode-card.practice { border-left: 3px solid #00CEC9; }
.mode-card.exam { border-left: 3px solid #FD79A8; }
.mode-card.wrong { border-left: 3px solid #e17055; }
.mode-arrow {
  margin-left: auto; color: rgba(255,255,255,0.2); font-size: 1.2rem;
}

/* ========== Filter Bar ========== */
.filter-bar {
  display: flex; gap: 8px; padding: 12px 0; overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.filter-bar::-webkit-scrollbar { display: none; }
.filter-chip {
  padding: 6px 16px; border-radius: 20px; font-size: 0.8rem;
  border: 1px solid rgba(255,255,255,0.15); background: transparent;
  color: rgba(255,255,255,0.6); cursor: pointer; white-space: nowrap;
  transition: all 0.25s;
}
.filter-chip.active {
  background: #6C5CE7; border-color: #6C5CE7; color: #fff;
}

/* ========== Question Card ========== */
.question-card {
  background: rgba(255,255,255,0.04); border-radius: 16px;
  border: 1px solid rgba(255,255,255,0.07);
  padding: 20px; margin-bottom: 16px;
  animation: fadeIn 0.3s ease;
}
.question-header {
  display: flex; align-items: center; gap: 8px; margin-bottom: 14px;
  flex-wrap: wrap;
}
.question-number { font-size: 0.8rem; color: rgba(255,255,255,0.4); }
.badge {
  display: inline-block; padding: 2px 10px; border-radius: 10px;
  font-size: 0.7rem; font-weight: 600;
}
.badge.single { background: rgba(108,92,231,0.25); color: #a29bfe; }
.badge.multi { background: rgba(253,121,168,0.25); color: #fd79a8; }
.chapter-tag {
  padding: 2px 8px; border-radius: 8px; font-size: 0.65rem;
  border: 1px solid rgba(0,206,201,0.3); color: #00CEC9;
}
.question-text {
  font-size: 1rem; line-height: 1.7; color: rgba(255,255,255,0.9);
  margin-bottom: 20px; word-break: break-word;
}

/* ========== Options ========== */
.options-list { display: flex; flex-direction: column; gap: 10px; }
.option-item {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 16px; border-radius: 12px; cursor: pointer;
  background: rgba(255,255,255,0.03);
  border: 2px solid rgba(255,255,255,0.06);
  transition: all 0.25s ease; user-select: none;
}
.option-item:active:not(.disabled) { transform: scale(0.98); }
.option-item.selected { border-color: #6C5CE7; background: rgba(108,92,231,0.1); }
.option-item.correct {
  border-color: #00b894; background: rgba(0,184,148,0.12);
}
.option-item.wrong {
  border-color: #e17055; background: rgba(225,112,85,0.12);
  animation: shake 0.4s ease;
}
.option-item.correct-highlight {
  border-color: #00b894; background: rgba(0,184,148,0.1);
}
.option-item.disabled { pointer-events: none; opacity: 0.85; }

.option-label {
  width: 32px; height: 32px; border-radius: 50%; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.85rem; font-weight: 600;
  border: 2px solid rgba(255,255,255,0.15);
  color: rgba(255,255,255,0.7); transition: all 0.25s;
}
.option-item.selected .option-label {
  border-color: #6C5CE7; background: #6C5CE7; color: #fff;
}
.option-item.correct .option-label,
.option-item.correct-highlight .option-label {
  border-color: #00b894; background: #00b894; color: #fff;
}
.option-item.wrong .option-label {
  border-color: #e17055; background: #e17055; color: #fff;
}
.option-text { flex: 1; font-size: 0.9rem; line-height: 1.5; color: rgba(255,255,255,0.8); }

/* ========== Answer Display (Study Mode) ========== */
.answer-display {
  margin-top: 16px; padding: 12px 16px; border-radius: 10px;
  background: rgba(0,184,148,0.08); border: 1px solid rgba(0,184,148,0.2);
  font-size: 0.85rem; color: #00b894;
}

/* ========== Buttons ========== */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 12px 24px; border-radius: 12px; font-size: 0.9rem;
  font-weight: 600; border: none; cursor: pointer;
  transition: all 0.25s; gap: 6px;
}
.btn:active { transform: scale(0.96); }
.btn-primary { background: #6C5CE7; color: #fff; }
.btn-secondary {
  background: rgba(255,255,255,0.08); color: rgba(255,255,255,0.8);
  border: 1px solid rgba(255,255,255,0.1);
}
.btn-danger { background: rgba(225,112,85,0.2); color: #e17055; }
.btn-success { background: #00b894; color: #fff; }
.btn-block { width: 100%; }
.btn-sm { padding: 8px 16px; font-size: 0.8rem; border-radius: 8px; }

.nav-buttons {
  display: flex; gap: 12px; padding: 16px 0;
  position: sticky; bottom: 0;
  background: linear-gradient(to top, rgba(10,10,26,0.95) 60%, transparent);
  padding-bottom: 20px;
}
.nav-buttons .btn { flex: 1; }
.btn-submit-answer {
  width: 100%; margin-top: 16px; padding: 14px;
  background: #6C5CE7; color: #fff; border: none;
  border-radius: 12px; font-size: 0.95rem; font-weight: 600;
  cursor: pointer; transition: all 0.25s;
}
.btn-submit-answer:active { transform: scale(0.97); }
.btn-submit-answer:disabled {
  opacity: 0.4; cursor: not-allowed; transform: none;
}

/* ========== Progress Bar ========== */
.progress-container {
  height: 3px; background: rgba(255,255,255,0.06);
  border-radius: 2px; margin: 8px 0;
}
.progress-fill {
  height: 100%; border-radius: 2px;
  background: linear-gradient(90deg, #6C5CE7, #00CEC9);
  transition: width 0.4s ease;
}

/* ========== Practice Toolbar ========== */
.practice-toolbar {
  display: flex; gap: 12px; align-items: center; padding: 8px 0;
  flex-wrap: wrap;
}
.toggle-group {
  display: flex; align-items: center; gap: 6px; font-size: 0.8rem;
  color: rgba(255,255,255,0.5);
}
.toggle-switch {
  width: 40px; height: 22px; border-radius: 11px;
  background: rgba(255,255,255,0.1); border: none;
  position: relative; cursor: pointer; transition: background 0.3s;
  flex-shrink: 0;
}
.toggle-switch::after {
  content: ''; position: absolute; top: 2px; left: 2px;
  width: 18px; height: 18px; border-radius: 50%;
  background: #fff; transition: transform 0.3s;
}
.toggle-switch.active { background: #6C5CE7; }
.toggle-switch.active::after { transform: translateX(18px); }

.running-score {
  margin-left: auto; font-size: 0.85rem; color: #00b894; font-weight: 600;
}

/* ========== Answer Feedback ========== */
.answer-feedback {
  padding: 12px 16px; border-radius: 10px; margin-top: 12px;
  font-size: 0.85rem; font-weight: 500;
  animation: fadeIn 0.3s ease;
}
.answer-feedback.correct-feedback {
  background: rgba(0,184,148,0.1); border: 1px solid rgba(0,184,148,0.2);
  color: #00b894;
}
.answer-feedback.wrong-feedback {
  background: rgba(225,112,85,0.1); border: 1px solid rgba(225,112,85,0.2);
  color: #e17055;
}

/* ========== Exam Timer ========== */
.exam-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 0; margin-bottom: 8px;
}
.timer-display {
  font-family: 'SF Mono', 'Menlo', monospace; font-size: 1.1rem;
  font-weight: 700; color: #00CEC9; letter-spacing: 1px;
}
.timer-display.warning { color: #fdcb6e; }
.timer-display.danger { color: #e17055; animation: pulse 1s infinite; }
.exam-progress-text { font-size: 0.8rem; color: rgba(255,255,255,0.4); }
.flag-btn {
  background: none; border: 1px solid rgba(255,255,255,0.1);
  border-radius: 8px; padding: 6px 10px; font-size: 0.9rem;
  cursor: pointer; color: rgba(255,255,255,0.5); transition: all 0.2s;
}
.flag-btn.flagged { color: #fdcb6e; border-color: rgba(253,203,110,0.3); }

/* ========== Question Nav Dots ========== */
.question-nav-dots {
  display: flex; flex-wrap: wrap; gap: 6px; padding: 12px 0;
  justify-content: center;
}
.dot {
  width: 30px; height: 30px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.65rem; font-weight: 600; cursor: pointer;
  background: rgba(255,255,255,0.05); color: rgba(255,255,255,0.4);
  border: 1.5px solid rgba(255,255,255,0.08); transition: all 0.2s;
}
.dot:active { transform: scale(0.9); }
.dot.answered { background: rgba(108,92,231,0.2); border-color: rgba(108,92,231,0.3); color: #a29bfe; }
.dot.current { border-color: #6C5CE7; color: #fff; box-shadow: 0 0 0 2px rgba(108,92,231,0.3); }
.dot.correct { background: rgba(0,184,148,0.25); border-color: rgba(0,184,148,0.4); color: #00b894; }
.dot.wrong { background: rgba(225,112,85,0.25); border-color: rgba(225,112,85,0.4); color: #e17055; }
.dot.flagged { position: relative; }
.dot.flagged::after {
  content: '🚩'; position: absolute; top: -4px; right: -4px;
  font-size: 0.5rem;
}

/* ========== Score Display ========== */
.score-display {
  text-align: center; padding: 40px 0 24px;
  animation: scaleIn 0.5s ease;
}
.score-circle {
  width: 140px; height: 140px; border-radius: 50%; margin: 0 auto 20px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  border: 4px solid;
  position: relative;
}
.score-circle.pass { border-color: #00b894; box-shadow: 0 0 30px rgba(0,184,148,0.2); }
.score-circle.fail { border-color: #e17055; box-shadow: 0 0 30px rgba(225,112,85,0.2); }
.score-number { font-size: 2.5rem; font-weight: 800; color: #fff; }
.score-unit { font-size: 0.8rem; color: rgba(255,255,255,0.5); }
.score-label {
  font-size: 1.2rem; font-weight: 700; margin-top: 8px;
}
.score-label.pass { color: #00b894; }
.score-label.fail { color: #e17055; }

.result-stats {
  display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px;
  margin: 24px 0;
}
.result-stat {
  text-align: center; padding: 14px 8px;
  background: rgba(255,255,255,0.04); border-radius: 12px;
}
.result-stat-num { font-size: 1.3rem; font-weight: 700; color: #fff; }
.result-stat-label { font-size: 0.7rem; color: rgba(255,255,255,0.4); margin-top: 2px; }

/* ========== Wrong Questions List ========== */
.wrong-list { display: flex; flex-direction: column; gap: 10px; }
.wrong-item {
  padding: 14px 16px; border-radius: 12px;
  background: rgba(255,255,255,0.04); border: 1px solid rgba(255,255,255,0.06);
  cursor: pointer; transition: all 0.2s;
}
.wrong-item:active { transform: scale(0.98); }
.wrong-item-header {
  display: flex; align-items: center; gap: 8px; margin-bottom: 6px;
}
.wrong-item-q {
  font-size: 0.88rem; color: rgba(255,255,255,0.8);
  line-height: 1.5; display: -webkit-box;
  -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.wrong-item-answer {
  display: flex; gap: 12px; margin-top: 8px; font-size: 0.78rem;
}
.your-answer { color: #e17055; }
.correct-answer { color: #00b894; }
.wrong-actions {
  display: flex; gap: 10px; margin-top: 16px;
}

/* ========== Empty State ========== */
.empty-state {
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; padding: 60px 20px; text-align: center;
}
.empty-icon { font-size: 3rem; margin-bottom: 12px; }
.empty-text { color: rgba(255,255,255,0.4); font-size: 0.9rem; }

/* ========== Toast ========== */
.toast {
  position: fixed; bottom: 80px; left: 50%; transform: translateX(-50%);
  padding: 12px 24px; border-radius: 12px; font-size: 0.85rem;
  background: rgba(30,30,50,0.95); backdrop-filter: blur(10px);
  border: 1px solid rgba(255,255,255,0.1); color: #fff;
  z-index: 1000; animation: slideUp 0.3s ease;
  max-width: 90%;
}
.toast.success { border-left: 3px solid #00b894; }
.toast.error { border-left: 3px solid #e17055; }

/* ========== Modal ========== */
.modal-overlay {
  position: fixed; top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.6); backdrop-filter: blur(4px);
  z-index: 500; display: flex; align-items: center; justify-content: center;
  padding: 20px; animation: fadeIn 0.2s ease;
}
.modal {
  background: #1e1e32; border-radius: 20px; padding: 24px;
  max-width: 360px; width: 100%;
  border: 1px solid rgba(255,255,255,0.08);
  animation: scaleIn 0.3s ease;
}
.modal-title { font-size: 1.1rem; font-weight: 700; color: #fff; margin-bottom: 12px; }
.modal-body { font-size: 0.9rem; color: rgba(255,255,255,0.6); margin-bottom: 20px; line-height: 1.6; }
.modal-actions { display: flex; gap: 10px; }
.modal-actions .btn { flex: 1; }

/* ========== Section Title ========== */
.section-title {
  font-size: 0.8rem; color: rgba(255,255,255,0.35); font-weight: 600;
  text-transform: uppercase; letter-spacing: 1px;
  margin: 20px 0 10px; padding-left: 4px;
}

/* ========== Exam Review List ========== */
.review-list { display: flex; flex-direction: column; gap: 12px; margin-top: 16px; }
.review-item {
  padding: 14px; border-radius: 12px;
  background: rgba(255,255,255,0.03); border: 1px solid rgba(255,255,255,0.06);
}
.review-item .question-text { font-size: 0.88rem; margin-bottom: 8px; }

/* ========== Animations ========== */
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { opacity: 0; transform: translateY(16px) translateX(-50%); } to { opacity: 1; transform: translateY(0) translateX(-50%); } }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.6; } }
@keyframes shake { 0%,100% { transform: translateX(0); } 20% { transform: translateX(-6px); } 40% { transform: translateX(6px); } 60% { transform: translateX(-4px); } 80% { transform: translateX(4px); } }
@keyframes scaleIn { from { opacity: 0; transform: scale(0.85); } to { opacity: 1; transform: scale(1); } }
.animate-fade { animation: fadeIn 0.3s ease; }
.animate-slide { animation: slideUp 0.3s ease; }

/* ========== Scrollbar ========== */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 2px; }

/* ========== Exam History ========== */
.history-list { display: flex; flex-direction: column; gap: 10px; margin-top: 12px; }
.history-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; border-radius: 12px;
  background: rgba(255,255,255,0.04); border: 1px solid rgba(255,255,255,0.06);
}
.history-date { font-size: 0.8rem; color: rgba(255,255,255,0.4); }
.history-score { font-size: 1.1rem; font-weight: 700; }
.history-score.pass { color: #00b894; }
.history-score.fail { color: #e17055; }

/* ========== Font Scaling ========== */
.font-sm .question-text { font-size: 0.88rem; }
.font-sm .option-text { font-size: 0.8rem; }
.font-sm .option-label { width: 28px; height: 28px; font-size: 0.8rem; }

.font-md .question-text { font-size: 1rem; }
.font-md .option-text { font-size: 0.9rem; }
.font-md .option-label { width: 32px; height: 32px; font-size: 0.85rem; }

.font-lg .question-text { font-size: 1.15rem; }
.font-lg .option-text { font-size: 1.02rem; }
.font-lg .option-label { width: 36px; height: 36px; font-size: 0.9rem; }

.font-xl .question-text { font-size: 1.3rem; }
.font-xl .option-text { font-size: 1.15rem; }
.font-xl .option-label { width: 40px; height: 40px; font-size: 1rem; }

