:root {
  --primary: #4f46e5;
  --primary-dark: #3730a3;
  --primary-light: #e0e7ff;
  --secondary: #ec4899;
  --secondary-light: #fce7f3;
  --math-color: #2563eb;
  --math-bg: #eff6ff;
  --tv-color: #db2777;
  --tv-bg: #fdf2f8;
  --success: #16a34a;
  --success-bg: #dcfce7;
  --warning: #d97706;
  --warning-bg: #fef3c7;
  --danger: #dc2626;
  --danger-bg: #fee2e2;
  --bg: #f4f6fb;
  --surface: #ffffff;
  --text: #0f172a;
  --text-muted: #475569;
  --border: #e2e8f0;
  --radius-lg: 18px;
  --radius-md: 12px;
  --radius-sm: 8px;
  --shadow-sm: 0 2px 8px rgba(15, 23, 42, 0.05);
  --shadow-md: 0 8px 24px rgba(15, 23, 42, 0.08);
  --bottom-nav-h: 68px;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  padding: 0;
  background-color: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.55;
  overflow-x: hidden;
}

body {
  padding-bottom: calc(var(--bottom-nav-h) + env(safe-area-inset-bottom, 16px) + 20px);
}

/* Top App Header */
.app-header {
  position: sticky;
  top: 0;
  z-index: 40;
  background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 60%, #db2777 100%);
  color: #ffffff;
  padding: calc(env(safe-area-inset-top, 0px) + 12px) 16px 12px;
  box-shadow: 0 4px 16px rgba(79, 70, 229, 0.22);
}

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

.student-badge {
  display: flex;
  align-items: center;
  gap: 10px;
}

.avatar-circle {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: #fbbf24;
  color: #1e1b4b;
  font-weight: 900;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2.5px solid #ffffff;
  box-shadow: 0 2px 6px rgba(0,0,0,0.15);
  flex-shrink: 0;
}

.student-info h1 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 800;
  letter-spacing: -0.01em;
}

.student-info p {
  margin: 0;
  font-size: 0.78rem;
  opacity: 0.92;
}

.header-stats {
  display: flex;
  align-items: center;
  gap: 8px;
}

.stat-pill {
  background: rgba(255, 255, 255, 0.2);
  backdrop-filter: blur(6px);
  padding: 5px 10px;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 4px;
  border: 1px solid rgba(255,255,255,0.28);
}

/* Main Container */
.main-container {
  max-width: 900px;
  margin: 0 auto;
  padding: 14px 14px 28px;
}

/* Hero Banner */
.hero-card {
  background: linear-gradient(135deg, #ffffff 0%, #eef2ff 100%);
  border-radius: var(--radius-lg);
  padding: 16px;
  margin-bottom: 16px;
  border: 1px solid #c7d2fe;
  box-shadow: var(--shadow-sm);
}

.hero-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  flex-wrap: wrap;
}

.hero-title {
  margin: 0 0 4px;
  font-size: 1.15rem;
  font-weight: 800;
  color: #1e1b4b;
}

.hero-sub {
  margin: 0;
  font-size: 0.88rem;
  color: var(--text-muted);
}

.progress-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-top: 14px;
}

.prog-box {
  background: #ffffff;
  border-radius: var(--radius-md);
  padding: 10px 12px;
  border: 1px solid var(--border);
}

.prog-box-header {
  display: flex;
  justify-content: space-between;
  font-size: 0.82rem;
  font-weight: 700;
  margin-bottom: 6px;
}

.prog-bar-bg {
  height: 8px;
  background: #e2e8f0;
  border-radius: 999px;
  overflow: hidden;
}

.prog-bar-fill {
  height: 100%;
  border-radius: 999px;
  transition: width 0.4s ease;
}

.prog-bar-fill.math {
  background: linear-gradient(90deg, #2563eb, #60a5fa);
}

.prog-bar-fill.tv {
  background: linear-gradient(90deg, #db2777, #f472b6);
}

/* Filter Tabs */
.subject-filter {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
  margin-bottom: 14px;
  scrollbar-width: none;
}
.subject-filter::-webkit-scrollbar {
  display: none;
}

.filter-chip {
  border: 1.5px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 0.88rem;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.18s ease;
}

.filter-chip.active {
  background: var(--primary);
  color: #ffffff;
  border-color: var(--primary);
  box-shadow: 0 3px 10px rgba(79, 70, 229, 0.25);
}

/* Exam Cards Grid */
.exam-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

@media (min-width: 680px) {
  .exam-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

.exam-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 16px;
  border: 1.5px solid var(--border);
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 12px;
  transition: transform 0.16s ease, box-shadow 0.16s ease;
}

.exam-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.exam-card.math-card {
  border-left: 5px solid var(--math-color);
}

.exam-card.tv-card {
  border-left: 5px solid var(--tv-color);
}

.exam-badges {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  flex-wrap: wrap;
}

.subject-tag {
  font-size: 0.74rem;
  font-weight: 800;
  padding: 3px 9px;
  border-radius: 999px;
  text-transform: uppercase;
}

.subject-tag.math {
  background: var(--math-bg);
  color: var(--math-color);
}

.subject-tag.vietnamese {
  background: var(--tv-bg);
  color: var(--tv-color);
}

.source-badge {
  font-size: 0.74rem;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 999px;
  background: #fef3c7;
  color: #b45309;
}

.exam-card h3 {
  margin: 6px 0 4px;
  font-size: 1.02rem;
  font-weight: 800;
  color: var(--text);
}

.exam-card p {
  margin: 0;
  font-size: 0.84rem;
  color: var(--text-muted);
}

.exam-meta {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 600;
}

.best-score-badge {
  background: var(--success-bg);
  color: var(--success);
  padding: 2px 8px;
  border-radius: 6px;
  font-weight: 800;
}

.exam-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.btn {
  border: none;
  border-radius: var(--radius-md);
  padding: 10px 14px;
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: all 0.15s ease;
  min-height: 44px;
}

.btn:active {
  transform: scale(0.98);
}

.btn-primary {
  background: var(--primary);
  color: #ffffff;
  flex: 1;
}

.btn-primary:hover {
  background: var(--primary-dark);
}

.btn-secondary {
  background: var(--primary-light);
  color: var(--primary-dark);
}

.btn-outline {
  background: #ffffff;
  color: var(--text);
  border: 1.5px solid var(--border);
}

.btn-success {
  background: var(--success);
  color: #ffffff;
}

.btn-warning {
  background: #f59e0b;
  color: #ffffff;
}

/* Active Exam Workspace */
.exam-topbar {
  position: sticky;
  top: 64px;
  z-index: 30;
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(8px);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  margin-bottom: 14px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.timer-box {
  background: #fef3c7;
  color: #b45309;
  padding: 5px 11px;
  border-radius: 999px;
  font-weight: 800;
  font-size: 0.88rem;
  display: flex;
  align-items: center;
  gap: 5px;
}

.reading-box {
  background: #fffbeb;
  border: 2px solid #fde68a;
  border-radius: var(--radius-lg);
  padding: 16px;
  margin-bottom: 16px;
  box-shadow: var(--shadow-sm);
}

.reading-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

.reading-title {
  margin: 0;
  font-size: 1.12rem;
  font-weight: 900;
  color: #92400e;
}

.reading-content p {
  margin: 0 0 10px;
  text-indent: 1.4em;
  font-size: 1rem;
  line-height: 1.68;
  color: #1e293b;
}

.reading-author {
  text-align: right;
  font-style: italic;
  font-weight: 700;
  color: #78350f;
  margin-top: 6px;
}

/* Section Divider */
.section-banner {
  background: linear-gradient(90deg, #1e1b4b, #4338ca);
  color: #ffffff;
  padding: 9px 14px;
  border-radius: var(--radius-md);
  font-weight: 800;
  font-size: 0.9rem;
  margin: 18px 0 12px;
  letter-spacing: 0.01em;
}

/* Question Card */
.question-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 16px;
  margin-bottom: 14px;
  border: 1.5px solid var(--border);
  box-shadow: var(--shadow-sm);
}

.question-card.mistake-highlight {
  border-color: #f59e0b;
  background: linear-gradient(180deg, #fffbeb 0%, #ffffff 42%);
}

.q-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}

.q-number {
  background: var(--primary-light);
  color: var(--primary-dark);
  padding: 4px 10px;
  border-radius: 8px;
  font-weight: 800;
  font-size: 0.84rem;
}

.q-number.warn {
  background: #fef3c7;
  color: #b45309;
}

.q-points {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--text-muted);
}

.q-prompt {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 12px;
}

.geo-svg {
  display: block;
  width: 100%;
  max-width: 340px;
  height: auto;
  margin: 10px auto 14px;
  background: #ffffff;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  padding: 6px;
}

/* MCQ Options */
.options-list {
  display: grid;
  grid-template-columns: 1fr;
  gap: 9px;
}

@media (min-width: 560px) {
  .options-list {
    grid-template-columns: repeat(2, 1fr);
  }
}

.option-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  background: #f8fafc;
  border: 2px solid var(--border);
  border-radius: var(--radius-md);
  padding: 11px 12px;
  font-size: 0.96rem;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  transition: all 0.14s ease;
  min-height: 50px;
}

.option-btn:hover {
  border-color: #94a3b8;
  background: #f1f5f9;
}

.option-btn.selected {
  border-color: var(--primary);
  background: var(--primary-light);
  color: var(--primary-dark);
}

.option-btn.correct {
  border-color: var(--success);
  background: var(--success-bg);
  color: #14532d;
}

.option-btn.wrong {
  border-color: var(--danger);
  background: var(--danger-bg);
  color: #7f1d1d;
}

.opt-letter {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: #ffffff;
  border: 1.5px solid #cbd5e1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 0.84rem;
  flex-shrink: 0;
}

.option-btn.selected .opt-letter {
  background: var(--primary);
  color: #ffffff;
  border-color: var(--primary);
}

.option-btn.correct .opt-letter {
  background: var(--success);
  color: #ffffff;
  border-color: var(--success);
}

.option-btn.wrong .opt-letter {
  background: var(--danger);
  color: #ffffff;
  border-color: var(--danger);
}

/* True/False Group */
.tf-item {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px 12px;
  background: #f8fafc;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  margin-bottom: 8px;
}

@media (min-width: 540px) {
  .tf-item {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
  }
}

.tf-buttons {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

.tf-btn {
  min-width: 54px;
  min-height: 40px;
  padding: 6px 12px;
  border-radius: 8px;
  border: 2px solid #cbd5e1;
  background: #ffffff;
  font-weight: 800;
  font-size: 0.9rem;
  cursor: pointer;
}

.tf-btn.selected {
  background: var(--primary);
  color: #ffffff;
  border-color: var(--primary);
}

.tf-btn.correct {
  background: var(--success);
  color: #ffffff;
  border-color: var(--success);
}

.tf-btn.wrong {
  background: var(--danger);
  color: #ffffff;
  border-color: var(--danger);
}

/* Fill in the blanks */
.fill-list {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.fill-row {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.fill-input {
  border: 2px solid #cbd5e1;
  border-radius: 8px;
  padding: 8px 11px;
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
  width: 140px;
  max-width: 100%;
  background: #ffffff;
}

.fill-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.15);
}

.fill-input.correct {
  border-color: var(--success);
  background: var(--success-bg);
}

.fill-input.wrong {
  border-color: var(--danger);
  background: var(--danger-bg);
}

.comp-picker {
  display: inline-flex;
  gap: 6px;
}

.comp-btn {
  width: 44px;
  height: 40px;
  border-radius: 8px;
  border: 2px solid #cbd5e1;
  background: #ffffff;
  font-size: 1.1rem;
  font-weight: 900;
  cursor: pointer;
}

.comp-btn.selected {
  background: var(--primary);
  color: #ffffff;
  border-color: var(--primary);
}

/* Essay & Word Problem */
.essay-textarea {
  width: 100%;
  min-height: 110px;
  border: 2px solid #cbd5e1;
  border-radius: var(--radius-md);
  padding: 12px;
  font-family: inherit;
  font-size: 0.96rem;
  line-height: 1.5;
  resize: vertical;
}

.essay-textarea:focus {
  outline: none;
  border-color: var(--primary);
}

/* Feedback & Explanation Box */
.q-actions-row {
  margin-top: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.explanation-box {
  margin-top: 12px;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  background: #eff6ff;
  border-left: 4px solid var(--math-color);
  font-size: 0.92rem;
  color: #1e293b;
}

.explanation-box.correct-box {
  background: #f0fdf4;
  border-left-color: var(--success);
}

.explanation-box.wrong-box {
  background: #fef2f2;
  border-left-color: var(--danger);
}

/* Mistake Cards & Study Cards */
.mistake-card, .guide-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 16px;
  margin-bottom: 14px;
  border: 1.5px solid var(--border);
  box-shadow: var(--shadow-sm);
}

.mistake-card {
  border-left: 5px solid #f59e0b;
}

.compare-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 10px;
  font-size: 0.88rem;
}

.compare-table th, .compare-table td {
  border: 1px solid var(--border);
  padding: 8px 10px;
  text-align: left;
}

.compare-table th {
  background: #f8fafc;
}

/* Bottom Navigation Bar (Mobile PWA) */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 50;
  background: rgba(255, 255, 255, 0.98);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--border);
  padding: 6px 8px calc(env(safe-area-inset-bottom, 6px) + 4px);
  box-shadow: 0 -4px 16px rgba(15, 23, 42, 0.06);
}

.bottom-nav-inner {
  max-width: 680px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 4px;
}

.nav-item {
  border: none;
  background: transparent;
  color: var(--text-muted);
  padding: 6px 4px;
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-size: 0.72rem;
  font-weight: 700;
  cursor: pointer;
}

.nav-item .nav-icon {
  font-size: 1.22rem;
  line-height: 1;
}

.nav-item.active {
  color: var(--primary);
  background: var(--primary-light);
}

/* Modal for Original Teacher Handout Images */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(15, 23, 42, 0.78);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px;
}

.modal-content {
  background: var(--surface);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 760px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 16px;
  box-shadow: var(--shadow-md);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
  position: sticky;
  top: 0;
  background: var(--surface);
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.handout-img {
  width: 100%;
  height: auto;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  margin-bottom: 12px;
}

/* Score Result Card */
.result-banner {
  background: linear-gradient(135deg, #4f46e5 0%, #db2777 100%);
  color: #ffffff;
  border-radius: var(--radius-lg);
  padding: 20px;
  text-align: center;
  margin-bottom: 16px;
  box-shadow: var(--shadow-md);
}

.score-circle {
  width: 96px;
  height: 96px;
  border-radius: 50%;
  background: #ffffff;
  color: #4f46e5;
  font-size: 1.9rem;
  font-weight: 900;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  margin: 0 auto 10px;
  border: 4px solid #fbbf24;
}

.score-circle span {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 700;
}

.fraction-inline {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  vertical-align: middle;
  font-size: 0.92em;
  line-height: 1.1;
  margin: 0 3px;
}
.fraction-inline .num {
  border-bottom: 1.5px solid currentColor;
  padding: 0 3px;
}
.fraction-inline .den {
  padding: 0 3px;
}
