/* ── Reset & Base ────────────────────────────────────────────────── */

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

:root {
  --color-primary: #4F46E5;
  --color-primary-light: #818CF8;
  --color-primary-bg: #EEF2FF;
  --color-success: #10B981;
  --color-success-bg: #D1FAE5;
  --color-error: #EF4444;
  --color-error-bg: #FEE2E2;
  --color-warning: #F59E0B;
  --color-warning-bg: #FEF3C7;
  --color-text: #1E293B;
  --color-text-light: #64748B;
  --color-bg: #F8FAFC;
  --color-white: #FFFFFF;
  --color-border: #E2E8F0;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.07), 0 2px 4px rgba(0,0,0,0.06);
  --shadow-lg: 0 10px 15px rgba(0,0,0,0.08), 0 4px 6px rgba(0,0,0,0.05);
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-serif: 'Source Serif 4', Georgia, serif;
}

body {
  font-family: var(--font-sans);
  color: var(--color-text);
  background: var(--color-bg);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* ── Typography ──────────────────────────────────────────────────── */

h1 { font-size: 1.75rem; font-weight: 700; line-height: 1.2; }
h2 { font-size: 1.35rem; font-weight: 600; line-height: 1.3; margin-bottom: 0.75rem; }
h3 { font-size: 1.1rem; font-weight: 600; line-height: 1.3; }

.subtitle {
  color: var(--color-text-light);
  font-size: 1.05rem;
  margin-top: 0.25rem;
}

/* ── Navigation ──────────────────────────────────────────────────── */

.top-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1.5rem;
  background: var(--color-white);
  border-bottom: 1px solid var(--color-border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.nav-brand {
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--color-primary);
  text-decoration: none;
}

.nav-right {
  display: flex;
  align-items: center;
  gap: 1rem;
  font-size: 0.9rem;
}

.nav-best-streak {
  background: #FEF3C7;
  color: #D97706;
  padding: 0.25rem 0.75rem;
  border-radius: 999px;
  font-weight: 700;
  font-size: 0.85rem;
}

.nav-points {
  background: var(--color-primary-bg);
  color: var(--color-primary);
  padding: 0.25rem 0.75rem;
  border-radius: 999px;
  font-weight: 600;
  font-size: 0.85rem;
}

.nav-name { color: var(--color-text-light); }

.nav-link {
  color: var(--color-text-light);
  text-decoration: none;
  font-size: 0.85rem;
}
.nav-link:hover { color: var(--color-primary); }

/* Challenge sub-nav (stats bar below main nav) */
.challenge-sub-nav {
  display: flex;
  justify-content: center;
  gap: 1.5rem;
  padding: 0.35rem 1rem;
  background: var(--color-bg);
  border-bottom: 1px solid var(--color-border);
  font-size: 0.8rem;
  color: var(--color-text-light);
  position: sticky;
  top: 49px; /* below the main nav */
  z-index: 99;
}

.sub-stat {
  font-weight: 500;
}

.sub-stat span {
  font-weight: 700;
  color: var(--color-text);
}

/* ── Container ───────────────────────────────────────────────────── */

.container {
  max-width: 800px;
  margin: 0 auto;
  padding: 2rem 1.5rem 4rem;
}

/* ── Cards ────────────────────────────────────────────────────────── */

.card {
  background: var(--color-white);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 1.5rem;
  margin-bottom: 1.5rem;
  box-shadow: var(--shadow);
}

/* ── Buttons ─────────────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.5rem 1.25rem;
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-weight: 500;
  text-decoration: none;
  border: none;
  cursor: pointer;
  transition: all 0.15s ease;
  font-family: var(--font-sans);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--color-primary);
  color: white;
}
.btn-primary:hover:not(:disabled) {
  background: #4338CA;
  box-shadow: var(--shadow-md);
}

.btn-secondary {
  background: var(--color-white);
  color: var(--color-text);
  border: 1px solid var(--color-border);
}
.btn-secondary:hover:not(:disabled) {
  background: var(--color-bg);
}

.btn-lg {
  padding: 0.75rem 2rem;
  font-size: 1.05rem;
}

/* ── Back link ───────────────────────────────────────────────────── */

.back-link {
  display: inline-block;
  color: var(--color-text-light);
  text-decoration: none;
  font-size: 0.9rem;
  margin-bottom: 1.5rem;
}
.back-link:hover { color: var(--color-primary); }

/* ── Page header ─────────────────────────────────────────────────── */

.page-header {
  display: flex;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 2rem;
}

.page-header h1 { flex: 1; }

/* ── Stats bar ───────────────────────────────────────────────────── */

.stats-bar {
  display: flex;
  gap: 2rem;
  margin-bottom: 2.5rem;
  padding: 1.25rem 1.5rem;
  background: var(--color-white);
  border-radius: var(--radius);
  border: 1px solid var(--color-border);
  box-shadow: var(--shadow);
}

.stat { text-align: center; flex: 1; }
.stat-value {
  display: block;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--color-primary);
}
.stat-label {
  font-size: 0.8rem;
  color: var(--color-text-light);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* ── Progress bars ───────────────────────────────────────────────── */

.progress-bar {
  height: 8px;
  background: var(--color-border);
  border-radius: 999px;
  overflow: hidden;
  width: 100%;
}

.progress-bar-lg { height: 12px; }

.progress-fill {
  height: 100%;
  background: var(--color-primary);
  border-radius: 999px;
  transition: width 0.5s ease;
  min-width: 0;
}

.progress-text {
  font-size: 0.8rem;
  color: var(--color-text-light);
  margin-top: 0.35rem;
  display: block;
}

.progress-summary {
  margin-bottom: 2rem;
}

/* ── Module grid (dashboard) ─────────────────────────────────────── */

.module-grid {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.module-card {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1.25rem;
  background: var(--color-white);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  text-decoration: none;
  color: var(--color-text);
  box-shadow: var(--shadow);
  transition: all 0.15s ease;
  position: relative;
  overflow: hidden;
}

.module-card:hover:not(.locked) {
  box-shadow: var(--shadow-md);
  border-color: var(--color-primary-light);
  transform: translateY(-1px);
}

.module-card.locked {
  opacity: 0.55;
  cursor: default;
}

.module-card.completed {
  border-left: 4px solid var(--color-success);
}

.module-card-icon {
  width: 52px;
  height: 52px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  color: white;
  font-weight: 700;
  flex-shrink: 0;
}

.module-card-body {
  flex: 1;
  min-width: 0;
}

.module-card-body h3 { margin-bottom: 0.2rem; }
.module-card-body p {
  font-size: 0.9rem;
  color: var(--color-text-light);
  margin-bottom: 0.5rem;
}

.lock-overlay {
  color: var(--color-text-light);
}

/* ── Module header icon ──────────────────────────────────────────── */

.module-header-icon {
  width: 56px;
  height: 56px;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.75rem;
  color: white;
  font-weight: 700;
  flex-shrink: 0;
}

/* ── Lesson list ─────────────────────────────────────────────────── */

.lesson-list h2 { margin-bottom: 1rem; }

.lesson-row {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1rem 1.25rem;
  background: var(--color-white);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  margin-bottom: 0.5rem;
  text-decoration: none;
  color: var(--color-text);
  transition: all 0.15s ease;
}

.lesson-row:hover:not(.locked) {
  border-color: var(--color-primary-light);
  box-shadow: var(--shadow);
}

.lesson-row.locked {
  opacity: 0.5;
  cursor: default;
}

.lesson-row.mastered {
  border-left: 3px solid var(--color-success);
}

.lesson-number {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--color-primary-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--color-primary);
  flex-shrink: 0;
}

.lesson-info {
  flex: 1;
  min-width: 0;
}

.lesson-info h3 { font-size: 1rem; margin-bottom: 0.1rem; }
.lesson-info p { font-size: 0.85rem; color: var(--color-text-light); }

.lesson-meta { flex-shrink: 0; }

/* ── Badges ──────────────────────────────────────────────────────── */

.badge {
  display: inline-block;
  padding: 0.2rem 0.65rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
}

.badge-success {
  background: var(--color-success-bg);
  color: #065F46;
}

.badge-progress {
  background: var(--color-warning-bg);
  color: #92400E;
}

.badge-ready {
  background: var(--color-primary-bg);
  color: var(--color-primary);
}

.badge-fluent {
  background: #FEF3C7;
  color: #92400E;
}

.lock-icon { color: var(--color-text-light); }


/* ── Challenge stage bar ────────────────────────────────────────── */

.challenge-stage-bar {
  display: flex;
  align-items: center;
  gap: 0;
  margin: 0.5rem 0 0;
}

.stage-step {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  flex-shrink: 0;
}

.stage-step-pip {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.stage-step-pip.stage-pip-gray {
  border: 2px solid #CBD5E1;
  background: #F1F5F9;
}

.stage-step-pip.stage-pip-yellow {
  border: 2px solid #F59E0B;
  background: var(--color-warning-bg);
}

.stage-step-pip.stage-pip-green {
  border: 2px solid #10B981;
  background: var(--color-success-bg);
}

.stage-step-pip.stage-pip-done {
  background: #10B981;
  border: 2px solid #10B981;
}

.stage-step-label {
  font-size: 0.75rem;
  font-weight: 600;
  color: #94A3B8;
}

.stage-step.stage-yellow .stage-step-label {
  color: #92400E;
}

.stage-step.stage-green .stage-step-label {
  color: #065F46;
}

.stage-step-connector {
  flex: 1;
  height: 3px;
  background: #E2E8F0;
  border-radius: 2px;
  margin: 0 0.4rem;
  min-width: 16px;
  overflow: hidden;
}

.stage-step-connector-fill {
  height: 100%;
  border-radius: 2px;
  transition: width 0.3s ease;
}

.stage-fill-yellow { background: #F59E0B; }
.stage-fill-green { background: #10B981; }
.stage-fill-done { background: #10B981; }

.challenge-count {
  font-size: 1rem;
  font-weight: 700;
  color: var(--color-primary);
  background: var(--color-primary-bg);
  padding: 0.2rem 0.6rem;
  border-radius: 6px;
  white-space: nowrap;
}

.challenge-count.points-flash {
  animation: countFlash 0.6s ease;
}

@keyframes countFlash {
  0% { background: var(--color-primary-bg); }
  30% { background: #D1FAE5; color: #065F46; }
  100% { background: var(--color-primary-bg); color: var(--color-primary); }
}

/* ── Lesson page ─────────────────────────────────────────────────── */

.lesson-container { max-width: 720px; }

.lesson-header {
  margin-bottom: 2rem;
}

.lesson-header h1 { margin-bottom: 0.75rem; }

.lesson-progress-bar {
  max-width: 300px;
}

/* ── Concept & Learn sections ────────────────────────────────────── */

.concept-section,
.learn-section {
  margin-bottom: 1.5rem;
}

.concept-content,
.learn-content {
  font-family: var(--font-serif);
  font-size: 1.05rem;
  line-height: 1.7;
}

.concept-content p,
.learn-content p {
  margin-bottom: 0.75rem;
}

.concept-content strong,
.learn-content strong {
  color: var(--color-primary);
}

.visual-fraction {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  margin: 0 0.25rem;
  vertical-align: middle;
}

.visual-fraction .numerator,
.visual-fraction .denominator {
  font-weight: 600;
  line-height: 1.2;
}

.visual-fraction .frac-line {
  width: 100%;
  height: 2px;
  background: var(--color-text);
}

.fraction-visual-grid {
  display: flex;
  gap: 1.5rem;
  align-items: center;
  justify-content: center;
  margin: 1.5rem 0;
  flex-wrap: wrap;
}

.pie-chart {
  width: 100px;
  height: 100px;
  border-radius: 50%;
  position: relative;
  flex-shrink: 0;
}

.pie-label {
  text-align: center;
  font-weight: 600;
  font-size: 0.95rem;
  margin-top: 0.4rem;
}

.bar-fraction {
  display: flex;
  height: 40px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 2px solid var(--color-border);
  width: 200px;
}

.bar-fraction .filled {
  background: var(--color-primary);
}

.bar-fraction .empty {
  background: var(--color-bg);
}

.callout {
  background: var(--color-primary-bg);
  border-left: 4px solid var(--color-primary);
  padding: 1rem 1.25rem;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  margin: 1rem 0;
  font-family: var(--font-sans);
  font-size: 0.95rem;
}

.example-box {
  background: #FAFAFA;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 1rem 1.25rem;
  margin: 1rem 0;
  font-family: var(--font-sans);
}

.math-big {
  font-size: 1.5rem;
  font-weight: 600;
  text-align: center;
  padding: 0.75rem;
  font-family: var(--font-serif);
}

/* ── Problems ────────────────────────────────────────────────────── */

.problems-section {
  margin-top: 2rem;
}

.problems-section h2 { margin-bottom: 1rem; }

.problem-card {
  margin-bottom: 1.5rem;
  transition: opacity 0.3s ease;
}

.problem-card.answered {
  opacity: 0.7;
}

.problem-number {
  font-size: 0.8rem;
  color: var(--color-text-light);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.75rem;
}

.problem-prompt {
  font-size: 1.1rem;
  font-family: var(--font-serif);
  margin-bottom: 1rem;
  line-height: 1.6;
}

.problem-visual {
  margin: 1rem 0;
  display: flex;
  justify-content: center;
}

.problem-input {
  margin: 1rem 0;
}

/* ── Answer form ─────────────────────────────────────────────────── */

.answer-form {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.answer-input {
  flex: 1;
  padding: 0.6rem 1rem;
  border: 2px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-size: 1.05rem;
  font-family: var(--font-sans);
  outline: none;
  transition: border-color 0.15s;
  max-width: 300px;
}

.answer-input:focus {
  border-color: var(--color-primary);
}

/* ── Multiple choice ─────────────────────────────────────────────── */

.choices {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.choice-btn {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  background: var(--color-white);
  border: 2px solid var(--color-border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 1rem;
  font-family: var(--font-sans);
  text-align: left;
  transition: all 0.15s ease;
}

.choice-btn:hover:not(:disabled) {
  border-color: var(--color-primary-light);
  background: var(--color-primary-bg);
}

.choice-btn.correct {
  border-color: var(--color-success);
  background: var(--color-success-bg);
}

.choice-btn.incorrect {
  border-color: var(--color-error);
  background: var(--color-error-bg);
}

.choice-letter {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--color-primary-bg);
  color: var(--color-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 0.85rem;
  flex-shrink: 0;
}

/* ── Hints ────────────────────────────────────────────────────────── */

.hint-container {
  margin-top: 0.75rem;
}

.hint-toggle {
  background: none;
  border: none;
  color: var(--color-primary);
  cursor: pointer;
  font-size: 0.9rem;
  font-family: var(--font-sans);
  padding: 0;
}

.hint-toggle:hover { text-decoration: underline; }

.hint-text {
  display: none;
  background: var(--color-warning-bg);
  border-radius: var(--radius-sm);
  padding: 0.75rem 1rem;
  margin-top: 0.5rem;
  font-size: 0.9rem;
}

.hint-text.show { display: block; }

/* ── Feedback ────────────────────────────────────────────────────── */

.feedback-area {
  margin-top: 0.75rem;
}

.feedback {
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  animation: fadeIn 0.3s ease;
}

.feedback.correct {
  background: var(--color-success-bg);
  color: #065F46;
}

.feedback.incorrect {
  background: var(--color-error-bg);
  color: #991B1B;
}

.feedback-explanation {
  font-weight: 400;
}

/* ── Mastery banner ──────────────────────────────────────────────── */

.mastery-banner {
  text-align: center;
  background: var(--color-success-bg);
  border-color: var(--color-success);
}

.mastery-banner h2 {
  color: #065F46;
}

.mastery-banner p {
  color: #065F46;
  margin-bottom: 1rem;
}

/* ── Lesson navigation ───────────────────────────────────────────── */

.lesson-nav {
  display: flex;
  justify-content: space-between;
  margin-top: 2rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--color-border);
}

/* ── Module overview ─────────────────────────────────────────────── */

.module-overview { margin-bottom: 2rem; }
.module-overview p { line-height: 1.7; }

/* ── Login page ──────────────────────────────────────────────────── */

.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--color-primary-bg) 0%, var(--color-bg) 100%);
}

.login-container {
  text-align: center;
  max-width: 400px;
  width: 100%;
  padding: 2.5rem;
}

.login-icon { margin-bottom: 1.5rem; }

.login-container h1 {
  font-size: 2rem;
  margin-bottom: 0.5rem;
}

.login-subtitle {
  color: var(--color-text-light);
  margin-bottom: 2rem;
  font-size: 1.05rem;
}

.login-form {
  text-align: left;
}

.login-form label {
  display: block;
  font-weight: 500;
  margin-bottom: 0.5rem;
}

.login-form input {
  width: 100%;
  padding: 0.75rem 1rem;
  border: 2px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-size: 1.05rem;
  font-family: var(--font-sans);
  margin-bottom: 1rem;
  outline: none;
  transition: border-color 0.15s;
}

.login-form input:focus {
  border-color: var(--color-primary);
}

.login-form .btn {
  width: 100%;
}

/* ── Alerts ──────────────────────────────────────────────────────── */

.alert {
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  margin-bottom: 1rem;
  font-size: 0.9rem;
}

.alert-error {
  background: var(--color-error-bg);
  color: #991B1B;
}

/* ── Challenge list (dashboard) ───────────────────────────────────── */

.challenge-list { margin-bottom: 1rem; }
.challenge-list h2 { margin-bottom: 0.25rem; }

.challenge-row {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1rem 1.25rem;
  border-radius: var(--radius-sm);
  margin-bottom: 0.5rem;
  text-decoration: none;
  color: var(--color-text);
  transition: all 0.15s ease;
  border: 1px solid var(--color-border);
  background: var(--color-white);
}

.challenge-row.active-gate {
  border: 2px solid #F59E0B;
  background: var(--color-warning-bg);
  box-shadow: var(--shadow);
}

.challenge-row.active-gate:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

.challenge-row.completed-gate {
  background: var(--color-success-bg);
  border-color: var(--color-success);
}

.challenge-row.locked-gate {
  opacity: 0.45;
}

.challenge-row-icon {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  font-weight: 700;
  flex-shrink: 0;
}

.challenge-row-icon.locked-icon {
  color: var(--color-text-light);
}

.challenge-row-body {
  flex: 1;
  min-width: 0;
}

.challenge-row-body h3 { font-size: 1rem; margin-bottom: 0.15rem; }
.challenge-row-body p { font-size: 0.85rem; color: var(--color-text-light); margin-bottom: 0.4rem; }

/* ── Challenge gate (dashboard, legacy) ──────────────────────────── */

/* ── Challenge gate (dashboard) ───────────────────────────────────── */

.challenge-gate {
  margin-bottom: 2rem;
}

.challenge-gate-card {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1.25rem 1.5rem;
  background: var(--color-warning-bg);
  border: 2px solid #F59E0B;
  border-radius: var(--radius);
  text-decoration: none;
  color: var(--color-text);
  transition: all 0.15s ease;
  box-shadow: var(--shadow);
}

.challenge-gate-card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

.challenge-gate-card.completed-gate {
  background: var(--color-success-bg);
  border-color: var(--color-success);
  cursor: default;
}

.challenge-gate-card.completed-gate:hover {
  transform: none;
  box-shadow: var(--shadow);
}

.challenge-gate-icon {
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: #92400E;
}

.challenge-gate-body {
  flex: 1;
  min-width: 0;
}

.challenge-gate-body h3 { margin-bottom: 0.2rem; }
.challenge-gate-body p {
  font-size: 0.9rem;
  color: var(--color-text-light);
  margin-bottom: 0.5rem;
}

/* ── Challenge page ──────────────────────────────────────────────── */

.challenge-container { max-width: 720px; }

.challenge-header {
  margin-bottom: 1.5rem;
}

.challenge-stats-bar {
  display: flex;
  gap: 2rem;
  margin-bottom: 1rem;
  padding: 1rem 1.25rem;
  background: var(--color-white);
  border-radius: var(--radius);
  border: 1px solid var(--color-border);
  box-shadow: var(--shadow);
}

.challenge-progress-bar {
  margin-bottom: 2rem;
}

/* Problem display */

.challenge-problem-area {
  text-align: center;
  padding: 2.5rem 1.5rem;
  margin-bottom: 2rem;
  transition: background 0.3s ease;
  position: relative;
}

.challenge-problem-area.flash {
  background: var(--color-primary-bg);
}

.challenge-problem {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}

.challenge-operand {
  font-size: 3rem;
  font-weight: 700;
  font-family: var(--font-serif);
  color: var(--color-text);
  min-width: 60px;
  text-align: center;
}

.challenge-operator {
  font-size: 2rem;
  font-weight: 600;
  color: var(--color-primary);
}

.challenge-equals {
  font-size: 2rem;
  font-weight: 600;
  color: var(--color-text-light);
}

/* Problem visual area */

.problem-visual-area {
  margin: 0 auto 1rem;
  max-width: 100%;
  overflow: hidden;
}

.number-line-svg {
  width: 100%;
  max-width: 560px;
  height: auto;
  display: block;
  margin: 0 auto;
}

.array-visual-svg {
  max-width: 180px;
  height: auto;
  display: block;
  margin: 0 auto;
}

/* Variation label */

.variation-label {
  text-align: center;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--color-text-light);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.5rem;
}

/* Blank/missing slot styling */

.challenge-blank {
  color: var(--color-primary);
  background: var(--color-primary-bg);
  border-radius: var(--radius-sm);
  padding: 0.1rem 0.5rem;
  border-bottom: 3px solid var(--color-primary);
}

.answer-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  margin-top: 1rem;
  margin-bottom: 1rem;
}

.challenge-answer-form {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}

.submit-answer-btn {
  font-size: 1.1rem;
  padding: 0.5rem 1.25rem;
  border-radius: 10px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

/* Answer hint (below input) */

.answer-hint {
  text-align: center;
  font-size: 0.8rem;
  color: var(--color-text-light);
  margin-top: 0.25rem;
  min-height: 1.2em;
}

/* Mic button */

.mic-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 2px solid var(--color-border);
  background: var(--color-white);
  color: var(--color-text-light);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s ease;
  flex-shrink: 0;
}

.mic-btn:hover {
  border-color: var(--color-primary-light);
  color: var(--color-primary);
  background: var(--color-primary-bg);
}

.mic-btn.voice-active {
  border-color: var(--color-primary);
  color: var(--color-primary);
  background: var(--color-primary-bg);
}

.mic-btn.listening {
  border-color: #EF4444;
  color: #EF4444;
  background: #FEE2E2;
  animation: micPulse 1s ease infinite;
}

@keyframes micPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(239,68,68,0.3); }
  50% { box-shadow: 0 0 0 8px rgba(239,68,68,0); }
}

.challenge-answer-input {
  width: 80px;
  font-size: 2.5rem;
  font-weight: 700;
  font-family: var(--font-serif);
  text-align: center;
  border: none;
  border-bottom: 3px solid var(--color-primary);
  background: transparent;
  outline: none;
  padding: 0.25rem;
  color: var(--color-primary);
  -moz-appearance: textfield;
}

.challenge-answer-input::placeholder {
  font-size: 1.8rem;
  color: #CBD5E1;
}

.challenge-answer-input::-webkit-outer-spin-button,
.challenge-answer-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

/* Running streak counter (top of problem area) */

.run-streak {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 0.4rem;
  margin-bottom: 1rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--color-border);
}

.run-streak-number {
  font-size: 1.75rem;
  font-weight: 800;
  font-family: var(--font-sans);
  color: var(--color-text-light);
  transition: all 0.3s ease;
  min-width: 2ch;
  text-align: center;
}

.run-streak-number.hot {
  color: var(--color-primary);
}

.run-streak-number.fire {
  color: #F59E0B;
}

.run-streak-number.blaze {
  color: #EF4444;
  font-size: 2rem;
}

.run-streak-label {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--color-text-light);
}

/* Streak dots (kept for mastery grid cells) */

.streak-dots {
  display: flex;
  justify-content: center;
  gap: 0.5rem;
}

.streak-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--color-border);
  transition: all 0.3s ease;
}

.streak-dot.filled {
  background: var(--color-primary);
  transform: scale(1.15);
}

.streak-dot.mastered-dot {
  background: var(--color-success);
}

/* Challenge feedback */

.challenge-feedback {
  min-height: 2.5rem;
  margin-top: 0.75rem;
}

.challenge-fb {
  display: block;
  padding: 0.75rem 1.25rem;
  border-radius: var(--radius);
  font-size: 0.95rem;
  font-weight: 500;
  animation: fadeIn 0.2s ease;
  text-align: center;
  overflow: visible;
}

.challenge-fb.correct {
  background: var(--color-success-bg);
  color: #065F46;
  border: 1px solid #A7F3D0;
}

.challenge-fb.incorrect {
  background: var(--color-error-bg);
  color: #991B1B;
  border: 1px solid #FECACA;
}

/* Walkthrough inside feedback needs room */
.challenge-fb .explanation-visual {
  margin-top: 0.75rem;
  background: var(--color-white);
  border-radius: var(--radius-sm);
  padding: 0.75rem;
  border: 1px solid var(--color-border);
  color: var(--color-text);
}

.challenge-fb .wt-wrapper {
  color: var(--color-text);
}

.challenge-fb .wt-frame {
  min-height: 60px;
}

/* Persistent last-answer strip */

.last-answer {
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  font-size: 0.85rem;
  text-align: center;
  margin-bottom: 1.5rem;
  cursor: default;
  transition: opacity 0.3s ease;
  overflow: visible;
}

.last-answer.was-correct {
  background: var(--color-success-bg);
  color: #065F46;
  border: 1px solid #A7F3D0;
}

.last-answer.was-incorrect {
  background: var(--color-error-bg);
  color: #991B1B;
  border: 1px solid #FECACA;
}

.time-badge {
  display: inline-block;
  margin-left: 0.5rem;
  padding: 0.1rem 0.5rem;
  background: rgba(0,0,0,0.08);
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
  font-family: var(--font-sans);
}

/* Fact grid */

.fact-grid-section {
  margin-top: 1rem;
}

.fact-grid-section h2 { margin-bottom: 0.25rem; }

.grid-category {
  margin-bottom: 1rem;
}

.grid-category-label {
  font-size: 0.85rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.4rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.grid-category-label.mastered-label { color: #065F46; }
.grid-category-label.accuracy-label { color: #92400E; }
.grid-category-label.not-started-label { color: var(--color-text-light); }

.grid-category-count {
  font-size: 0.75rem;
  font-weight: 600;
  background: rgba(0,0,0,0.06);
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
}

.fact-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(64px, 1fr));
  gap: 6px;
  margin-top: 1rem;
}

.fact-cell {
  position: relative;
  background: var(--color-white);
  border: 1px solid var(--color-border);
  border-radius: 6px;
  padding: 0.4rem 0.25rem;
  text-align: center;
  font-size: 0.75rem;
  color: var(--color-text-light);
  transition: all 0.3s ease;
}

.fact-cell.in-progress {
  background: var(--color-warning-bg);
  border-color: #F59E0B;
  color: #92400E;
}

.fact-cell.mastered {
  background: var(--color-success-bg);
  border-color: var(--color-success);
  color: #065F46;
}

.fact-text {
  display: block;
  font-weight: 500;
  font-size: 0.8rem;
}

.fact-check {
  display: block;
  font-size: 0.7rem;
  color: var(--color-success);
  font-weight: 700;
}

.fact-streak {
  display: block;
  font-size: 0.65rem;
  font-weight: 600;
}

/* Skill grid (for skill-based challenges — bigger cells with names) */

.skill-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 8px;
  margin-top: 1rem;
}

.skill-cell {
  position: relative;
  background: var(--color-white);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 0.6rem 0.75rem;
  text-align: center;
  font-size: 0.8rem;
  color: var(--color-text-light);
  transition: all 0.3s ease;
}

.skill-cell.in-progress {
  background: var(--color-warning-bg);
  border-color: #F59E0B;
  color: #92400E;
}

.skill-cell.mastered {
  background: var(--color-success-bg);
  border-color: var(--color-success);
  color: #065F46;
}

.skill-cell .fact-text {
  font-weight: 500;
  font-size: 0.8rem;
  display: block;
  line-height: 1.3;
}

/* Skill prompt display */

.challenge-skill-prompt {
  font-size: 1.3rem;
  font-family: var(--font-serif);
  text-align: center;
  padding: 1rem 0.5rem;
  line-height: 1.6;
}

.hundred-grid-svg {
  display: block;
  margin: 0 auto;
  max-width: 160px;
  height: auto;
}

.answer-wide {
  width: 140px !important;
  max-width: 200px !important;
}

/* ── Stacked fraction display ────────────────────────────────────── */

.sf {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  vertical-align: middle;
  margin: 0 0.2rem;
  line-height: 1.1;
}

.sf-n {
  font-weight: 700;
  font-size: 1.1em;
  padding: 0 0.3rem 0.15rem;
  border-bottom: 2.5px solid currentColor;
}

.sf-d {
  font-weight: 700;
  font-size: 1.1em;
  padding: 0.15rem 0.3rem 0;
}

.sf.sf-lg .sf-n,
.sf.sf-lg .sf-d {
  font-size: 1.4em;
  padding: 0 0.4rem 0.2rem;
}

.sf.sf-lg .sf-d {
  padding: 0.2rem 0.4rem 0;
}

/* ── Fraction bar visuals ────────────────────────────────────────── */

.frac-bar-svg {
  display: block;
  height: auto;
}

.frac-visual-center {
  display: flex;
  justify-content: center;
  margin: 0.75rem 0;
}

.frac-op-row {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin: 0.75rem 0;
}

.frac-op-item {
  flex-shrink: 0;
  text-align: center;
}

.frac-op-item .frac-bar-svg {
  width: 140px;
}

.frac-op-symbol {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--color-text-light);
  flex-shrink: 0;
  /* Align symbol with the bar, not the label below */
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 24px;
}

/* Explanation visual in feedback */
.explanation-visual {
  margin-top: 0.75rem;
  padding: 0.75rem;
  background: var(--color-bg);
  border-radius: var(--radius-sm);
  border: 1px solid var(--color-border);
}

.explanation-visual .frac-op-item .frac-bar-svg {
  width: 110px;
}

.explanation-visual .frac-op-symbol {
  font-size: 1.1rem;
  height: 32px;
}

/* ── Comparison buttons (> < =) ──────────────────────────────────── */

.compare-btns {
  display: flex;
  gap: 0.75rem;
  justify-content: center;
  margin-top: 1rem;
}

.compare-btn {
  width: 60px;
  height: 60px;
  border-radius: var(--radius);
  border: 2px solid var(--color-border);
  background: var(--color-white);
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--color-text);
  cursor: pointer;
  transition: all 0.15s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-sans);
}

.compare-btn:hover {
  border-color: var(--color-primary);
  color: var(--color-primary);
  background: var(--color-primary-bg);
  transform: scale(1.05);
}

.compare-btn:active {
  transform: scale(0.97);
}

.compare-btn.selected {
  border-color: var(--color-primary);
  background: var(--color-primary);
  color: white;
}

@media (max-width: 600px) {
  .frac-op-item .frac-bar-svg { width: 100px; }
  .frac-op-row { gap: 0.3rem; }
  .frac-op-symbol { font-size: 1.1rem; height: 28px; }
  .explanation-visual .frac-op-item .frac-bar-svg { width: 80px; }
  .compare-btn { width: 50px; height: 50px; font-size: 1.4rem; }
}

/* ── Walkthrough (stacked steps, revealed one at a time) ──────────── */

.wt-stack {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.wt-step-box {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 0.75rem;
  background: var(--color-white);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  animation: stepReveal 0.4s ease;
}

.wt-step-box.hidden {
  display: none;
}

.wt-step-num {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--color-primary-bg);
  color: var(--color-primary);
  font-size: 0.75rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-top: 0.1rem;
}

.wt-step-content {
  flex: 1;
  min-width: 0;
}

/* Ghost box (previous fraction version) */
.wt-ghost {
  display: inline-flex;
  padding: 0.15rem 0.4rem;
  background: #F1F5F9;
  border: 1px dashed #CBD5E1;
  border-radius: 6px;
  opacity: 0.55;
  vertical-align: middle;
}

.wt-convert {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  vertical-align: middle;
  margin: 0 0.2rem;
}

.wt-arrow {
  color: #94A3B8;
  font-size: 1rem;
}

/* Shadow-boxed bar: shows original grouping over the new subdivisions */
.wt-boxed-bar {
  position: relative;
  display: inline-block;
}

.wt-boxed-overlay {
  position: absolute;
  inset: 0;
  background-image: linear-gradient(to right, rgba(0,0,0,0.15) 1px, transparent 1px);
  background-repeat: repeat;
  border-radius: 3px;
  pointer-events: none;
}

@keyframes stepReveal {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Help button (?) */

.help-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 2px solid var(--color-border);
  background: var(--color-white);
  color: var(--color-text-light);
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
  flex-shrink: 0;
}

.help-btn:hover {
  border-color: var(--color-primary);
  color: var(--color-primary);
  background: var(--color-primary-bg);
}

.help-modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 200;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.help-modal.open { display: flex; }

.help-modal-content {
  background: var(--color-white);
  border-radius: var(--radius);
  padding: 1.5rem;
  max-width: 680px;
  width: 100%;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  position: relative;
}

.help-modal-close {
  position: absolute;
  top: 0.5rem;
  right: 0.75rem;
  background: none;
  border: none;
  font-size: 1.5rem;
  color: var(--color-text-light);
  cursor: pointer;
  line-height: 1;
}

.help-modal-title {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--color-text-light);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.75rem;
}

/* ── Tutorial progress dots ───────────────────────────────────────── */

.tutorial-progress {
  text-align: center;
  margin-bottom: 1.5rem;
}

.tutorial-progress-text {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--color-text-light);
}

.tutorial-dots {
  display: flex;
  justify-content: center;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.tutorial-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--color-border);
  transition: all 0.3s ease;
}

.tutorial-dot.done {
  background: var(--color-success);
}

.tut-current-step {
  min-height: 2rem;
}

/* ── Tutorial modal ───────────────────────────────────────────────── */

.tutorial-modal-bg {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 300;
  padding: 1rem;
}

.tutorial-modal {
  background: white;
  border-radius: 16px;
  padding: 2rem 1.5rem;
  max-width: 420px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 40px rgba(0,0,0,0.15);
  text-align: center;
}

/* Tutorial input field */
.tut-ans-input {
  width: 44px;
  height: 38px;
  border: 2.5px solid var(--color-primary);
  border-radius: 8px;
  text-align: center;
  font-size: 1.3rem;
  font-weight: 700;
  font-family: var(--font-serif);
  outline: none;
  background: #EEF2FF;
  -moz-appearance: textfield;
}

.tut-ans-input::-webkit-outer-spin-button,
.tut-ans-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
}

/* Legacy alias */
.tutorial-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.tutorial-card {
  background: var(--color-white);
  border-radius: var(--radius);
  padding: 2rem 1.5rem;
  max-width: 520px;
  width: 100%;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  text-align: center;
}

.tutorial-card h2 {
  margin-bottom: 1.25rem;
  color: var(--color-primary);
}

.tutorial-card .wt-step-box {
  text-align: left;
  margin-bottom: 0.5rem;
}

/* ── Multi-digit / left-to-right visuals ──────────────────────────── */

.md-stacked {
  display: inline-flex;
  flex-direction: column;
  align-items: flex-end;
  margin: 0.5rem auto;
}

.md-row {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.4rem;
}

.md-num {
  font-size: 2.5rem;
  font-family: var(--font-serif);
  letter-spacing: 0.15em;
}

.md-op {
  font-size: 1.8rem;
  font-weight: 600;
  color: var(--color-text-light);
  margin-right: 0.2rem;
}

.md-line {
  width: 100%;
  height: 3px;
  background: var(--color-text);
  margin-top: 0.25rem;
  border-radius: 2px;
}

.ltr-explain {
  text-align: center;
}

.ltr-header {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
  padding-bottom: 0.5rem;
  border-bottom: 2px solid var(--color-border);
}

.ltr-num {
  font-size: 1.5rem;
  font-family: var(--font-serif);
  letter-spacing: 0.05em;
}

.ltr-op {
  font-size: 1.2rem;
  font-weight: 600;
  color: var(--color-text-light);
}

.ltr-steps {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-bottom: 0.75rem;
}

.ltr-step {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  justify-content: center;
  font-size: 1rem;
  font-family: var(--font-sans);
}

.ltr-step-label {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  width: 70px;
  text-align: right;
  flex-shrink: 0;
}

.ltr-step-calc {
  font-family: var(--font-serif);
  font-size: 1.05rem;
}

.ltr-total {
  padding-top: 0.5rem;
  border-top: 2px solid var(--color-border);
  font-family: var(--font-serif);
  font-size: 1.1rem;
}

@media (max-width: 600px) {
  .md-num { font-size: 1.8rem; letter-spacing: 0.1em; }
  .md-op { font-size: 1.3rem; }
  .ltr-num { font-size: 1.2rem; }
  .ltr-step-label { width: 55px; font-size: 0.65rem; }
}

/* ── Retention ────────────────────────────────────────────────────── */

.retention-section { margin-bottom: 1rem; }

.retention-card {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1rem 1.25rem;
  background: var(--color-primary-bg);
  border: 2px solid var(--color-primary-light);
  border-radius: var(--radius);
  text-decoration: none;
  color: var(--color-text);
  transition: all 0.15s ease;
  box-shadow: var(--shadow);
}

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

.retention-card-icon {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-primary);
  flex-shrink: 0;
}

.retention-card-body { flex: 1; min-width: 0; }
.retention-card-body h3 { font-size: 1rem; margin-bottom: 0.15rem; }
.retention-card-body p { font-size: 0.85rem; color: var(--color-text-light); margin-bottom: 0.3rem; }

.retention-progress { margin-bottom: 1.5rem; }

.retention-source {
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 1rem;
  text-align: center;
}

.retry-banner {
  background: var(--color-warning-bg);
  color: #92400E;
  padding: 0.5rem 1rem;
  border-radius: 999px;
  font-weight: 600;
  font-size: 0.9rem;
  text-align: center;
  margin: 0.75rem 0;
  animation: fadeIn 0.3s ease;
}

.reset-fb {
  border-left: 3px solid var(--color-error);
}

.reset-item {
  padding: 0.4rem 0.75rem;
  background: var(--color-error-bg);
  border-radius: var(--radius-sm);
  margin: 0.3rem 0;
  font-size: 0.9rem;
  color: #991B1B;
}

/* ── Animations ──────────────────────────────────────────────────── */

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ── Responsive ──────────────────────────────────────────────────── */

@media (max-width: 600px) {
  .container { padding: 1.25rem 1rem 3rem; }
  h1 { font-size: 1.4rem; }
  .stats-bar { gap: 1rem; padding: 1rem; }
  .stat-value { font-size: 1.25rem; }
  .page-header { flex-direction: column; }
  .module-header-icon { width: 44px; height: 44px; font-size: 1.3rem; }
  .fraction-visual-grid { gap: 1rem; }
  .challenge-operand { font-size: 2.25rem; min-width: 40px; }
  .challenge-answer-input { width: 60px; font-size: 2rem; }
  .challenge-stats-bar { gap: 1rem; }
  .fact-grid { grid-template-columns: repeat(auto-fill, minmax(56px, 1fr)); }
}
