/* ============================================================
   CAT Prep App — Main Stylesheet
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&family=JetBrains+Mono:wght@400;500&display=swap');

/* ---------- CSS Variables ---------- */
:root {
  --navy: #0f172a;
  --navy-800: #1e293b;
  --navy-700: #334155;
  --blue: #1d4ed8;
  --blue-light: #3b82f6;
  --blue-50: #eff6ff;
  --blue-100: #dbeafe;
  --orange: #ea580c;
  --orange-light: #fb923c;
  --orange-50: #fff7ed;
  --green: #15803d;
  --green-light: #22c55e;
  --green-50: #f0fdf4;
  --red: #b91c1c;
  --red-light: #ef4444;
  --red-50: #fef2f2;
  --yellow: #b45309;
  --yellow-light: #f59e0b;
  --yellow-50: #fffbeb;
  --purple: #6d28d9;
  --purple-light: #8b5cf6;
  --purple-50: #f5f3ff;

  --bg: #f1f5f9;
  --card: #ffffff;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;

  --text: #0f172a;
  --text-muted: #64748b;
  --text-light: #94a3b8;

  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -1px rgba(0,0,0,0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -2px rgba(0,0,0,0.05);
  --shadow-xl: 0 20px 25px -5px rgba(0,0,0,0.1), 0 10px 10px -5px rgba(0,0,0,0.04);

  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 16px;
  --radius-xl: 24px;

  --transition: 150ms ease;
  --transition-slow: 300ms ease;
}

/* ---------- Reset & Base ---------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 16px; scroll-behavior: smooth; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }

img { max-width: 100%; height: auto; display: block; }

/* ---------- Utilities ---------- */
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); }

.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: 0.5rem; }
.gap-3 { gap: 0.75rem; }
.gap-4 { gap: 1rem; }

.text-center { text-align: center; }
.text-muted { color: var(--text-muted); }
.text-sm { font-size: 0.875rem; }
.text-xs { font-size: 0.75rem; }
.fw-600 { font-weight: 600; }
.fw-700 { font-weight: 700; }

/* ---------- Navigation ---------- */
#nav {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--navy);
  color: white;
  padding: 0 1.5rem;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: var(--shadow-md);
}

.nav-brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 1.2rem;
  font-weight: 700;
  color: white;
  cursor: pointer;
  letter-spacing: -0.02em;
}
.nav-brand:hover { opacity: 0.9; }
.brand-icon { font-size: 1.4rem; }
.brand-accent { color: var(--orange-light); }

.nav-links { display: flex; align-items: center; gap: 0.25rem; }

.nav-link {
  color: rgba(255,255,255,0.75);
  padding: 0.5rem 1rem;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 500;
  transition: all var(--transition);
  cursor: pointer;
  border: none;
  background: none;
  text-decoration: none;
  display: inline-block;
}
.nav-link:hover { color: white; background: rgba(255,255,255,0.1); text-decoration: none; }
.nav-link.active { color: white; background: rgba(255,255,255,0.15); }

/* ---------- Views ---------- */
.view { min-height: calc(100vh - 60px); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.6rem 1.25rem;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all var(--transition);
  white-space: nowrap;
  line-height: 1;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary {
  background: var(--blue);
  color: white;
  box-shadow: var(--shadow-sm);
}
.btn-primary:hover:not(:disabled) { background: #1a42b3; box-shadow: var(--shadow); }

.btn-orange {
  background: var(--orange);
  color: white;
  box-shadow: var(--shadow-sm);
}
.btn-orange:hover:not(:disabled) { background: #c94d0a; box-shadow: var(--shadow); }

.btn-secondary {
  background: var(--card);
  color: var(--text);
  border: 1.5px solid var(--border-strong);
}
.btn-secondary:hover:not(:disabled) { background: var(--bg); border-color: var(--text-muted); }

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border: 1.5px solid var(--border);
}
.btn-ghost:hover:not(:disabled) { background: var(--bg); color: var(--text); }

.btn-danger {
  background: var(--red);
  color: white;
}
.btn-danger:hover:not(:disabled) { background: #9b1515; }

.btn-sm { padding: 0.4rem 0.9rem; font-size: 0.8rem; }
.btn-lg { padding: 0.8rem 1.75rem; font-size: 1rem; }
.btn-xl { padding: 1rem 2.25rem; font-size: 1.1rem; border-radius: var(--radius); }
.btn-icon { padding: 0.6rem; aspect-ratio: 1; }

/* ---------- Cards ---------- */
.card {
  background: var(--card);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}

.card-padded { padding: 1.5rem; }

/* ---------- Badges ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.2rem 0.65rem;
  border-radius: 99px;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}
.badge-blue   { background: var(--blue-100); color: var(--blue); }
.badge-orange { background: var(--orange-50); color: var(--orange); border: 1px solid #fed7aa; }
.badge-green  { background: var(--green-50); color: var(--green); border: 1px solid #bbf7d0; }
.badge-purple { background: var(--purple-50); color: var(--purple); border: 1px solid #ddd6fe; }
.badge-yellow { background: var(--yellow-50); color: var(--yellow); border: 1px solid #fde68a; }

/* ============================================================
   HOME VIEW
   ============================================================ */
#view-home {
  max-width: 1100px;
  margin: 0 auto;
  padding: 2rem 1.5rem 4rem;
}

.home-hero {
  background: linear-gradient(135deg, var(--navy) 0%, #1e3a8a 60%, #1d4ed8 100%);
  border-radius: var(--radius-xl);
  padding: 3rem 2.5rem;
  color: white;
  margin-bottom: 2rem;
  position: relative;
  overflow: hidden;
}
.home-hero::before {
  content: '';
  position: absolute;
  top: -40px; right: -40px;
  width: 200px; height: 200px;
  background: rgba(255,255,255,0.05);
  border-radius: 50%;
}
.home-hero::after {
  content: '';
  position: absolute;
  bottom: -60px; right: 80px;
  width: 300px; height: 300px;
  background: rgba(255,255,255,0.03);
  border-radius: 50%;
}
.hero-content { position: relative; z-index: 1; }
.hero-title {
  font-size: 2.2rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1.2;
  margin-bottom: 0.75rem;
}
.hero-subtitle {
  font-size: 1.05rem;
  color: rgba(255,255,255,0.75);
  margin-bottom: 2rem;
  max-width: 480px;
}
.hero-actions { display: flex; gap: 1rem; flex-wrap: wrap; }
.hero-stats {
  display: flex;
  gap: 2rem;
  margin-top: 2rem;
  padding-top: 2rem;
  border-top: 1px solid rgba(255,255,255,0.15);
}
.hero-stat { text-align: center; }
.hero-stat-num {
  font-size: 1.8rem;
  font-weight: 800;
  line-height: 1;
  color: var(--orange-light);
}
.hero-stat-label { font-size: 0.8rem; color: rgba(255,255,255,0.6); margin-top: 0.2rem; }

.home-section-title {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.quick-start-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 1rem;
  margin-bottom: 2.5rem;
}
.quick-card {
  background: var(--card);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  cursor: pointer;
  transition: all var(--transition-slow);
  text-align: center;
}
.quick-card:hover {
  border-color: var(--blue-light);
  box-shadow: var(--shadow-lg);
  transform: translateY(-2px);
}
.quick-card-icon { font-size: 2.5rem; margin-bottom: 0.75rem; }
.quick-card-title { font-size: 1rem; font-weight: 700; margin-bottom: 0.3rem; }
.quick-card-desc { font-size: 0.82rem; color: var(--text-muted); }

.popular-topics-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
}
.topic-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.45rem 0.9rem;
  background: var(--card);
  border: 1.5px solid var(--border);
  border-radius: 99px;
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  color: var(--text);
}
.topic-pill:hover {
  border-color: var(--blue-light);
  color: var(--blue);
  background: var(--blue-50);
  transform: translateY(-1px);
}
.topic-pill .pill-count {
  font-size: 0.72rem;
  background: var(--bg);
  padding: 0.1rem 0.4rem;
  border-radius: 99px;
  color: var(--text-muted);
  font-weight: 600;
}

/* ============================================================
   BROWSE VIEW
   ============================================================ */
#view-browse {
  max-width: 1200px;
  margin: 0 auto;
  padding: 2rem 1.5rem 4rem;
}

.browse-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}
.browse-title { font-size: 1.5rem; font-weight: 800; letter-spacing: -0.02em; }

.search-box {
  position: relative;
  flex: 1;
  min-width: 240px;
  max-width: 400px;
}
.search-box input {
  width: 100%;
  padding: 0.65rem 1rem 0.65rem 2.75rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 0.9rem;
  background: var(--card);
  color: var(--text);
  outline: none;
  transition: border-color var(--transition);
}
.search-box input:focus { border-color: var(--blue-light); box-shadow: 0 0 0 3px rgba(59,130,246,0.1); }
.search-icon {
  position: absolute;
  left: 0.85rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-light);
  font-size: 1rem;
  pointer-events: none;
}

.filter-tabs {
  display: flex;
  gap: 0.4rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}
.filter-tab {
  padding: 0.45rem 1.1rem;
  border-radius: 99px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  border: 1.5px solid var(--border);
  background: var(--card);
  color: var(--text-muted);
  transition: all var(--transition);
}
.filter-tab:hover { border-color: var(--blue-light); color: var(--blue); }
.filter-tab.active { background: var(--blue); border-color: var(--blue); color: white; }

.section-group { margin-bottom: 2.5rem; }
.section-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
  padding-bottom: 0.75rem;
  border-bottom: 2px solid var(--border);
}
.section-label {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text);
}
.section-count {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 500;
}

.topics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 1rem;
}

.topic-card {
  background: var(--card);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.25rem 1.25rem 1rem;
  cursor: pointer;
  transition: all var(--transition-slow);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  position: relative;
  overflow: hidden;
}
.topic-card:hover {
  box-shadow: var(--shadow-lg);
  transform: translateY(-2px);
}
.topic-card.selected {
  border-color: var(--blue-light);
  background: var(--blue-50);
}
.topic-card-top { display: flex; align-items: flex-start; justify-content: space-between; }
.topic-card-name { font-size: 0.95rem; font-weight: 700; line-height: 1.3; flex: 1; }
.topic-card-select {
  width: 20px; height: 20px;
  border: 2px solid var(--border-strong);
  border-radius: 4px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: all var(--transition);
  margin-left: 0.5rem;
  font-size: 0.75rem;
}
.topic-card.selected .topic-card-select {
  background: var(--blue);
  border-color: var(--blue);
  color: white;
}
.topic-card-meta {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.78rem;
  color: var(--text-muted);
}
.topic-card-count {
  font-size: 1.35rem;
  font-weight: 800;
  color: var(--blue);
  line-height: 1;
}
.topic-card-actions { display: flex; gap: 0.5rem; margin-top: 0.25rem; }

/* Accent lines per section */
.topic-card[data-section="Quant"]  { border-top: 3px solid var(--blue); }
.topic-card[data-section="VARC"]   { border-top: 3px solid var(--purple); }
.topic-card[data-section="DILR"]   { border-top: 3px solid var(--orange); }

.topic-card[data-section="Quant"]  .topic-card-count { color: var(--blue); }
.topic-card[data-section="VARC"]   .topic-card-count { color: var(--purple); }
.topic-card[data-section="DILR"]   .topic-card-count { color: var(--orange); }

.selection-bar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: var(--navy);
  color: white;
  padding: 0.9rem 2rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: 0 -4px 20px rgba(0,0,0,0.2);
  z-index: 50;
  transform: translateY(100%);
  transition: transform var(--transition-slow);
}
.selection-bar.visible { transform: translateY(0); }
.selection-bar-info { font-size: 0.9rem; font-weight: 500; }
.selection-bar-info strong { color: var(--orange-light); }

/* ============================================================
   TEST SETUP VIEW
   ============================================================ */
#view-setup {
  max-width: 700px;
  margin: 0 auto;
  padding: 2rem 1.5rem;
}

.setup-title { font-size: 1.5rem; font-weight: 800; margin-bottom: 0.5rem; }
.setup-subtitle { color: var(--text-muted); margin-bottom: 2rem; }

.setup-form-group { margin-bottom: 1.5rem; }
.form-label {
  display: block;
  font-size: 0.9rem;
  font-weight: 600;
  margin-bottom: 0.6rem;
  color: var(--text);
}
.form-sublabel { font-size: 0.8rem; font-weight: 400; color: var(--text-muted); margin-left: 0.4rem; }

.selected-topics-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding: 0.75rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  min-height: 52px;
}
.selected-topic-tag {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.3rem 0.75rem;
  background: var(--blue-100);
  color: var(--blue);
  border-radius: 99px;
  font-size: 0.8rem;
  font-weight: 600;
}
.selected-topic-tag button {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--blue);
  padding: 0;
  font-size: 1rem;
  line-height: 1;
  display: flex;
  align-items: center;
}
.selected-topic-tag button:hover { color: var(--red); }

.options-row { display: flex; gap: 1rem; flex-wrap: wrap; }
.option-group { flex: 1; min-width: 140px; }

.nice-select {
  width: 100%;
  padding: 0.65rem 1rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.9rem;
  background: var(--card);
  color: var(--text);
  cursor: pointer;
  outline: none;
  transition: border-color var(--transition);
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%2364748b' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.9rem center;
  padding-right: 2.5rem;
}
.nice-select:focus { border-color: var(--blue-light); box-shadow: 0 0 0 3px rgba(59,130,246,0.1); }

.test-info-box {
  background: var(--blue-50);
  border: 1px solid var(--blue-100);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  margin-bottom: 1.5rem;
  font-size: 0.85rem;
  color: var(--navy-700);
  line-height: 1.6;
}
.test-info-box strong { color: var(--blue); }

.setup-actions { display: flex; gap: 1rem; }

/* ============================================================
   TEST VIEW
   ============================================================ */
#view-test {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 60px);
  height: calc(100dvh - 60px); /* dynamic viewport on mobile */
  overflow: hidden;
}

.test-header {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 0.75rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-shrink: 0;
}

.test-progress-info {
  display: flex;
  align-items: center;
  gap: 1.5rem;
}
.test-q-counter { font-size: 0.9rem; color: var(--text-muted); }
.test-q-counter strong { color: var(--text); font-weight: 700; }

.test-timer {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-family: 'JetBrains Mono', monospace;
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--blue);
  background: var(--blue-50);
  padding: 0.35rem 0.9rem;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--blue-100);
}
.test-timer.warning { color: var(--yellow); background: var(--yellow-50); border-color: #fde68a; }
.test-timer.danger  { color: var(--red);    background: var(--red-50);    border-color: #fca5a5; animation: pulse 1s infinite; }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

.test-progress-bar {
  height: 3px;
  background: var(--border);
  flex-shrink: 0;
}
.test-progress-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--blue) 0%, var(--blue-light) 100%);
  transition: width 0.5s ease;
}

.test-body {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* Question navigation sidebar */
.test-nav {
  width: 200px;
  flex-shrink: 0;
  background: var(--card);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 1rem;
}
.test-nav-title {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
}
.q-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.3rem;
}
.q-dot {
  aspect-ratio: 1;
  border-radius: 5px;
  font-size: 0.72rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border: 2px solid transparent;
  transition: all var(--transition);
  background: var(--bg);
  color: var(--text-muted);
}
.q-dot:hover { border-color: var(--blue-light); }
.q-dot.current { border-color: var(--blue); background: var(--blue-50); color: var(--blue); }
.q-dot.answered { background: var(--blue); color: white; }
.q-dot.flagged { background: var(--yellow-50); border-color: var(--yellow-light); color: var(--yellow); }
.q-dot.answered.flagged { background: var(--yellow-light); border-color: var(--yellow); color: white; }

.test-nav-legend { margin-top: 1rem; display: flex; flex-direction: column; gap: 0.4rem; }
.legend-item { display: flex; align-items: center; gap: 0.5rem; font-size: 0.72rem; color: var(--text-muted); }
.legend-dot { width: 12px; height: 12px; border-radius: 3px; flex-shrink: 0; }
.legend-dot.unanswered { background: var(--bg); border: 1.5px solid var(--border-strong); }
.legend-dot.answered   { background: var(--blue); }
.legend-dot.flagged    { background: var(--yellow-light); }
.legend-dot.current-l  { background: var(--blue-50); border: 2px solid var(--blue); }

/* Main question area */
.test-main {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem 2rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.question-source {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.context-block {
  background: #fffbeb;
  border: 1px solid #fde68a;
  border-left: 4px solid var(--yellow-light);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  font-size: 0.9rem;
  line-height: 1.7;
  color: var(--navy-800);
  max-height: 250px;
  overflow-y: auto;
}
.context-block img { max-width: 100%; height: auto; border-radius: var(--radius-sm); margin: 0.5rem 0; }
.context-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--yellow);
  cursor: pointer;
  margin-bottom: 0.5rem;
  background: none;
  border: none;
  padding: 0;
}

.question-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
}
.question-number {
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
}
.question-text {
  font-size: 1rem;
  line-height: 1.8;
  color: var(--text);
}
.question-text p { margin: 0; }
.question-text img { max-width: 100%; border-radius: var(--radius-sm); margin: 0.75rem 0; }

.options-list {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}
.option-item {
  display: flex;
  align-items: flex-start;
  gap: 1rem;
  padding: 0.85rem 1.1rem;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: all var(--transition);
  background: var(--card);
}
.option-item:hover {
  border-color: var(--blue-light);
  background: var(--blue-50);
}
.option-item.selected {
  border-color: var(--blue);
  background: var(--blue-50);
}
.option-letter {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid var(--border-strong);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.78rem;
  font-weight: 700;
  flex-shrink: 0;
  transition: all var(--transition);
  color: var(--text-muted);
}
.option-item:hover .option-letter { border-color: var(--blue-light); color: var(--blue); }
.option-item.selected .option-letter { background: var(--blue); border-color: var(--blue); color: white; }
.option-text {
  flex: 1;
  font-size: 0.9rem;
  line-height: 1.6;
  padding-top: 0.2rem;
}

/* Review mode styles */
.option-item.correct {
  border-color: var(--green);
  background: var(--green-50);
}
.option-item.correct .option-letter { background: var(--green); border-color: var(--green); color: white; }
.option-item.wrong {
  border-color: var(--red);
  background: var(--red-50);
}
.option-item.wrong .option-letter { background: var(--red); border-color: var(--red); color: white; }

.tita-input-wrap { display: flex; align-items: center; gap: 1rem; }
.tita-input {
  padding: 0.75rem 1rem;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  font-family: 'JetBrains Mono', monospace;
  font-size: 1.1rem;
  font-weight: 600;
  width: 200px;
  outline: none;
  transition: border-color var(--transition);
  background: var(--card);
  color: var(--text);
}
.tita-input:focus { border-color: var(--blue-light); box-shadow: 0 0 0 3px rgba(59,130,246,0.1); }
.tita-hint { font-size: 0.8rem; color: var(--text-muted); }

.question-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}
.q-footer-left  { display: flex; gap: 0.5rem; }
.q-footer-right { display: flex; gap: 0.5rem; }

.btn-flag {
  padding: 0.55rem 1rem;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  border: 1.5px solid var(--border);
  background: var(--card);
  color: var(--text-muted);
  transition: all var(--transition);
  display: flex;
  align-items: center;
  gap: 0.35rem;
}
.btn-flag:hover { border-color: var(--yellow-light); color: var(--yellow); }
.btn-flag.flagged { border-color: var(--yellow-light); color: var(--yellow); background: var(--yellow-50); }

/* ============================================================
   RESULTS VIEW
   ============================================================ */
#view-results {
  max-width: 1000px;
  margin: 0 auto;
  padding: 2rem 1.5rem 4rem;
}

.results-hero {
  background: linear-gradient(135deg, var(--navy) 0%, #1e3a8a 100%);
  border-radius: var(--radius-xl);
  padding: 2.5rem;
  color: white;
  margin-bottom: 2rem;
  text-align: center;
}
.results-emoji { font-size: 3.5rem; margin-bottom: 0.5rem; }
.results-title { font-size: 1.6rem; font-weight: 800; margin-bottom: 0.25rem; }
.results-subtitle { color: rgba(255,255,255,0.65); margin-bottom: 2rem; }

.score-display {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  background: rgba(255,255,255,0.1);
  border-radius: var(--radius-lg);
  padding: 1.5rem 3rem;
  margin-bottom: 1.5rem;
}
.score-num {
  font-size: 3.5rem;
  font-weight: 800;
  line-height: 1;
  font-family: 'JetBrains Mono', monospace;
}
.score-label { font-size: 0.85rem; color: rgba(255,255,255,0.6); margin-top: 0.25rem; }

.score-breakdown {
  display: flex;
  justify-content: center;
  gap: 1.5rem;
  flex-wrap: wrap;
}
.score-item { text-align: center; }
.score-item-num { font-size: 1.5rem; font-weight: 700; }
.score-item-label { font-size: 0.75rem; color: rgba(255,255,255,0.6); }
.score-item.correct   .score-item-num { color: #4ade80; }
.score-item.wrong     .score-item-num { color: #f87171; }
.score-item.skipped   .score-item-num { color: rgba(255,255,255,0.5); }

.results-section-title {
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 1rem;
  margin-bottom: 2rem;
}
.stat-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  text-align: center;
}
.stat-card-num { font-size: 2rem; font-weight: 800; line-height: 1; margin-bottom: 0.25rem; }
.stat-card-label { font-size: 0.8rem; color: var(--text-muted); font-weight: 500; }
.stat-card.correct .stat-card-num { color: var(--green); }
.stat-card.wrong   .stat-card-num { color: var(--red); }
.stat-card.skipped .stat-card-num { color: var(--text-muted); }

.topic-results-table {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  margin-bottom: 2rem;
}
.table-head {
  display: grid;
  grid-template-columns: 1fr 80px 80px 80px 90px;
  gap: 0.5rem;
  padding: 0.75rem 1.25rem;
  background: var(--bg);
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
}
.table-row {
  display: grid;
  grid-template-columns: 1fr 80px 80px 80px 90px;
  gap: 0.5rem;
  padding: 0.85rem 1.25rem;
  font-size: 0.88rem;
  border-bottom: 1px solid var(--border);
  align-items: center;
  transition: background var(--transition);
}
.table-row:last-child { border-bottom: none; }
.table-row:hover { background: var(--bg); }
.table-row .correct-cell { color: var(--green); font-weight: 600; }
.table-row .wrong-cell   { color: var(--red);   font-weight: 600; }
.table-row .score-cell   { font-weight: 700; }

.accuracy-bar {
  height: 6px;
  background: var(--border);
  border-radius: 99px;
  overflow: hidden;
  margin-top: 3px;
}
.accuracy-fill {
  height: 100%;
  border-radius: 99px;
  transition: width 0.8s ease;
}

.review-question-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  margin-bottom: 1rem;
  overflow: hidden;
}
.review-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.85rem 1.25rem;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background var(--transition);
}
.review-card-header:hover { background: var(--border); }
.review-status-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}
.review-status-dot.correct  { background: var(--green-light); }
.review-status-dot.wrong    { background: var(--red-light); }
.review-status-dot.unattempted { background: var(--text-light); }
.review-card-body { padding: 1.25rem; }

.results-actions { display: flex; gap: 1rem; flex-wrap: wrap; }

/* ============================================================
   MODAL
   ============================================================ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  backdrop-filter: blur(2px);
}
.modal {
  background: var(--card);
  border-radius: var(--radius-lg);
  padding: 2rem;
  max-width: 420px;
  width: 100%;
  box-shadow: var(--shadow-xl);
}
.modal h3 { font-size: 1.15rem; font-weight: 700; margin-bottom: 0.5rem; }
.modal p  { color: var(--text-muted); font-size: 0.9rem; margin-bottom: 1.5rem; }
.modal-actions { display: flex; gap: 0.75rem; justify-content: flex-end; }

/* ============================================================
   LOADING STATES
   ============================================================ */
.loading-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: calc(100vh - 60px);
  gap: 1rem;
  color: var(--text-muted);
}
.spinner {
  width: 40px; height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.empty-state {
  text-align: center;
  padding: 4rem 2rem;
  color: var(--text-muted);
}
.empty-icon { font-size: 3rem; margin-bottom: 1rem; }
.empty-title { font-size: 1.1rem; font-weight: 600; color: var(--text); margin-bottom: 0.5rem; }

/* ============================================================
   MOBILE QUESTION STRIP (shown only on phones)
   ============================================================ */
.mobile-q-strip {
  display: none;  /* hidden on desktop */
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: var(--card);
  border-top: 1px solid var(--border);
  padding: 0.6rem 0.75rem;
  padding-bottom: calc(0.6rem + env(safe-area-inset-bottom));
  overflow-x: auto;
  overflow-y: hidden;
  white-space: nowrap;
  z-index: 40;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.mobile-q-strip::-webkit-scrollbar { display: none; }
.mobile-q-strip .q-dot {
  display: inline-flex;
  width: 30px; height: 30px;
  margin: 0 2px;
  flex-shrink: 0;
}

@media (max-width: 768px) {
  .mobile-q-strip { display: block; }
  /* Pad test-main so content isn't hidden behind the strip */
  .test-main { padding-bottom: 4.5rem !important; }
}

/* ============================================================
   MATH / LATEX
   ============================================================ */
mjx-container { display: inline; }
.question-text mjx-container[display="true"] { display: block; margin: 0.75rem 0; }

/* ============================================================
   RESPONSIVE — Tablet & Mobile
   ============================================================ */

/* ── Tablet (≤ 768px) ─────────────────────────────────────── */
@media (max-width: 768px) {
  /* Nav */
  #nav { padding: 0 1rem; }
  .nav-brand { font-size: 1.1rem; }
  .nav-link  { padding: 0.4rem 0.75rem; font-size: 0.85rem; }

  /* Home */
  #view-home > div { padding: 1.25rem 1rem 3rem; }
  .home-hero { padding: 2rem 1.5rem; border-radius: var(--radius-lg); }
  .hero-title { font-size: 1.7rem; }
  .hero-stats { flex-wrap: wrap; gap: 1rem; }
  .quick-start-grid { grid-template-columns: 1fr 1fr; gap: 0.75rem; }

  /* Browse */
  #view-browse > div { padding: 1.25rem 1rem 3rem; }
  .browse-header { flex-direction: column; align-items: stretch; }
  .search-box { max-width: 100%; }
  .topics-grid { grid-template-columns: 1fr 1fr; }

  /* Setup */
  #view-setup > div { padding: 1.25rem 1rem; }

  /* Test — hide sidebar, use full width */
  .test-nav { display: none; }
  .test-main { padding: 1rem; gap: 1rem; }
  .test-header {
    padding: 0.6rem 1rem;
    flex-wrap: nowrap;
    gap: 0.5rem;
  }
  .test-q-counter { font-size: 0.8rem; }
  .test-timer { font-size: 1.1rem; padding: 0.3rem 0.65rem; }
  #test-ans-count { display: none; }

  /* Results */
  #view-results > div { padding: 1.25rem 1rem 3rem; }
  .results-hero { padding: 1.75rem 1.25rem; }
  .score-display { padding: 1.25rem 2rem; }
  .score-num { font-size: 2.8rem; }
  .score-breakdown { gap: 1rem; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .table-head,
  .table-row { grid-template-columns: 1fr 60px 60px 70px; }
  .table-head > *:nth-child(3),
  .table-row  > *:nth-child(3) { display: none; }

  /* Selection bar */
  .selection-bar { padding: 0.75rem 1rem; flex-wrap: wrap; gap: 0.5rem; }
}

/* ── Phone (≤ 480px) ──────────────────────────────────────── */
@media (max-width: 480px) {
  /* Nav — compact */
  #nav { height: 52px; }
  .brand-icon { font-size: 1.1rem; }
  .nav-link { padding: 0.35rem 0.6rem; font-size: 0.78rem; }

  /* Home */
  .home-hero { padding: 1.5rem 1.1rem; }
  .hero-title { font-size: 1.4rem; }
  .hero-subtitle { font-size: 0.9rem; }
  .hero-actions { flex-direction: column; }
  .hero-actions .btn-xl { width: 100%; justify-content: center; }
  .hero-stats { gap: 0.75rem; }
  .hero-stat-num { font-size: 1.4rem; }
  .quick-start-grid { grid-template-columns: 1fr; }
  .quick-card { padding: 1.1rem; text-align: left; display: flex; align-items: center; gap: 1rem; }
  .quick-card-icon { font-size: 1.8rem; margin: 0; }

  /* Browse */
  .topics-grid { grid-template-columns: 1fr; }
  .filter-tabs { gap: 0.3rem; }
  .filter-tab { padding: 0.35rem 0.75rem; font-size: 0.8rem; }

  /* Setup */
  .options-row { flex-direction: column; }
  .setup-actions { flex-direction: column; }
  .setup-actions .btn { width: 100%; justify-content: center; }

  /* Test header — ultra compact */
  .test-header { padding: 0.5rem 0.75rem; gap: 0.4rem; }
  .test-timer { font-size: 1rem; padding: 0.25rem 0.55rem; border-radius: 6px; }
  .test-q-counter { font-size: 0.75rem; }
  .btn.btn-danger.btn-sm { padding: 0.35rem 0.65rem; font-size: 0.75rem; }

  /* Test question area */
  .test-main { padding: 0.75rem; gap: 0.75rem; }
  .question-card { padding: 1.1rem; }
  .question-text { font-size: 0.95rem; line-height: 1.75; }
  .question-number { font-size: 0.7rem; }

  /* Options — large tap targets */
  .option-item { padding: 0.9rem; gap: 0.75rem; }
  .option-letter { width: 32px; height: 32px; font-size: 0.82rem; flex-shrink: 0; }
  .option-text { font-size: 0.88rem; }

  /* TITA input */
  .tita-input { width: 160px; font-size: 1rem; }
  .tita-input-wrap { flex-wrap: wrap; gap: 0.5rem; }
  .tita-hint { font-size: 0.75rem; }

  /* Question footer */
  .question-footer { flex-direction: column; gap: 0.5rem; }
  .q-footer-left  { justify-content: flex-start; flex-wrap: wrap; }
  .q-footer-right { justify-content: flex-end; }
  .btn-flag { font-size: 0.78rem; padding: 0.45rem 0.8rem; }

  /* Context block */
  .context-block { font-size: 0.85rem; max-height: 200px; }

  /* Results */
  .results-hero { padding: 1.5rem 1rem; border-radius: var(--radius-lg); }
  .results-emoji { font-size: 2.5rem; }
  .results-title { font-size: 1.3rem; }
  .score-num { font-size: 2.4rem; }
  .score-breakdown { gap: 0.75rem; }
  .score-item-num { font-size: 1.2rem; }
  .stats-grid { grid-template-columns: 1fr 1fr; gap: 0.65rem; }
  .stat-card { padding: 1rem; }
  .stat-card-num { font-size: 1.6rem; }
  .table-head,
  .table-row { grid-template-columns: 1fr 50px 70px; font-size: 0.8rem; }
  .table-head > *:nth-child(2), .table-row > *:nth-child(2),
  .table-head > *:nth-child(3), .table-row > *:nth-child(3) { display: none; }
  .table-head, .table-row { padding: 0.7rem 0.85rem; }

  /* Review cards */
  .review-card-header { padding: 0.75rem 1rem; }

  /* Selection bar */
  .selection-bar { flex-wrap: wrap; gap: 0.4rem; }

  /* Modals */
  .modal { padding: 1.5rem; }
  .modal-actions { gap: 0.5rem; }
  .modal-actions .btn { flex: 1; justify-content: center; }
}

/* ── Very small phones (≤ 360px) ─────────────────────────── */
@media (max-width: 360px) {
  .nav-link { display: none; }
  .nav-link#nav-home { display: inline-block; }  /* keep Home only */
  .hero-title { font-size: 1.25rem; }
  .score-num { font-size: 2rem; }
}
