/* ==========================================================================
   Concept Mastery — 3-Stage Typology-Driven UI (styles.css)
   Clean, Ergonomic Design for CBSE Class 10 Mathematics
   ========================================================================== */

:root {
  --bg-canvas: #f4f0e8;
  --bg-surface: #ffffff;
  --bg-surface-elevated: #ffffff;
  --bg-surface-soft: #f7f4ee;
  --bg-surface-inset: #ede7dc;
  --bg-surface-hover: #ebe4d8;

  --border-subtle: #e2dacd;
  --border-medium: #cfc5b4;
  --border-strong: #9e9480;
  --border-focus: #2563eb;

  --text-primary: #1e293b;
  --text-secondary: #475569;
  --text-muted: #64748b;
  --text-inverse: #ffffff;

  --brand-primary: #2563eb;
  --brand-primary-hover: #1d4ed8;
  --brand-soft: #eff6ff;
  --brand-soft-hover: #dbeafe;
  --brand-border: #bfdbfe;
  --brand-glow: rgba(37, 99, 235, 0.15);

  --success-primary: #16a34a;
  --success-text: #14532d;
  --success-soft: #f0fdf4;
  --success-border: #bbf7d0;

  --warning-primary: #d97706;
  --warning-text: #78350f;
  --warning-soft: #fffbeb;
  --warning-border: #fde68a;

  --error-primary: #dc2626;
  --error-text: #7f1d1d;
  --error-soft: #fef2f2;
  --error-border: #fecaca;

  --font-display: 'Outfit', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-body: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;

  --radius-xs: 6px;
  --radius-sm: 10px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-pill: 9999px;

  --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-sm: 0 2px 6px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 12px 28px -4px rgba(0, 0, 0, 0.08);

  --transition-fast: 0.18s cubic-bezier(0.16, 1, 0.3, 1);
  --transition-smooth: 0.28s cubic-bezier(0.16, 1, 0.3, 1);
}

/* ==========================================================================
   Pleasing Dark Theme (Warm Muted Charcoal/Slate, Soft Low-Glare Text)
   ========================================================================== */
[data-theme="dark"] {
  --bg-canvas: #1e222a;
  --bg-surface: #252a35;
  --bg-surface-elevated: #2d3340;
  --bg-surface-soft: #282e3a;
  --bg-surface-inset: #1a1d24;
  --bg-surface-hover: #333a4a;

  --border-subtle: #363d4e;
  --border-medium: #454e63;
  --border-strong: #5c6884;
  --border-focus: #4b88e8;

  --text-primary: #cbd5e1;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --text-inverse: #1e222a;

  --brand-primary: #4b88e8;
  --brand-primary-hover: #6ea4f4;
  --brand-soft: #253348;
  --brand-soft-hover: #2e3e58;
  --brand-border: #3b5278;
  --brand-glow: rgba(75, 136, 232, 0.15);

  --success-primary: #2eb872;
  --success-text: #a7f3d0;
  --success-soft: #1b2e23;
  --success-border: #28543b;

  --warning-primary: #e59819;
  --warning-text: #fde68a;
  --warning-soft: #302617;
  --warning-border: #524022;

  --error-primary: #e05252;
  --error-text: #fca5a5;
  --error-soft: #311d1d;
  --error-border: #572a2a;

  --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.2);
  --shadow-sm: 0 2px 6px rgba(0, 0, 0, 0.25);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 12px 28px -4px rgba(0, 0, 0, 0.4);
}

[data-theme="dark"] .template-math-display,
[data-theme="dark"] .calc-input-box,
[data-theme="dark"] .math-keypad {
  background: var(--bg-surface-elevated);
  color: var(--text-primary);
  border-color: var(--border-subtle);
}

[data-theme="dark"] .key-btn {
  background: var(--bg-surface-soft);
  color: var(--text-primary);
  border-color: var(--border-subtle);
}

[data-theme="dark"] .key-btn:hover {
  background: var(--bg-surface-hover);
}

[data-theme="dark"] .concept-card,
[data-theme="dark"] .worked-example-card,
[data-theme="dark"] .stage-workspace-card,
[data-theme="dark"] .problem-statement-card {
  background: var(--bg-surface);
  border-color: var(--border-subtle);
}

[data-theme="dark"] .concept-trap {
  background: #2b1919;
  border-color: #4a2727;
  color: #fca5a5;
}

[data-theme="dark"] .strategy-option-btn {
  background: var(--bg-surface-soft);
  border-color: var(--border-subtle);
  color: var(--text-primary);
}

[data-theme="dark"] .strategy-option-btn:hover:not(:disabled) {
  background: var(--bg-surface-hover);
  border-color: var(--brand-primary);
}

[data-theme="dark"] .strategy-option-btn.selected {
  background: rgba(75, 136, 232, 0.15) !important;
  border-color: var(--brand-primary) !important;
  color: #f8fafc !important;
}

[data-theme="dark"] .strategy-option-btn.correct {
  background: rgba(46, 184, 114, 0.18) !important;
  border-color: var(--success-primary) !important;
  color: #f0fdf4 !important;
}

[data-theme="dark"] .strategy-option-btn.wrong {
  background: rgba(224, 82, 82, 0.18) !important;
  border-color: var(--error-primary) !important;
  color: #fef2f2 !important;
}

[data-theme="dark"] .strategy-option-btn .option-letter {
  background: var(--bg-surface-elevated);
  color: var(--text-primary);
}

[data-theme="dark"] .strategy-option-btn.selected .option-letter {
  background: var(--brand-primary) !important;
  color: #ffffff !important;
}

[data-theme="dark"] .strategy-option-btn.correct .option-letter {
  background: var(--success-primary) !important;
  color: #ffffff !important;
}

[data-theme="dark"] .strategy-option-btn.wrong .option-letter {
  background: var(--error-primary) !important;
  color: #ffffff !important;
}

[data-theme="dark"] mjx-container {
  color: inherit !important;
}

[data-theme="dark"] .textbook-conclusion-block {
  background: var(--success-soft);
  border-color: var(--success-border);
}

[data-theme="dark"] .textbook-conclusion-block .conclusion-body-text,
[data-theme="dark"] .textbook-conclusion-block .conclusion-badge,
[data-theme="dark"] .textbook-conclusion-block mjx-container {
  color: var(--success-text) !important;
}

[data-theme="dark"] .step-feedback-banner.wrong {
  background: var(--error-soft);
  border-color: var(--error-border);
  color: var(--error-text);
}

[data-theme="dark"] .step-feedback-banner.correct {
  background: var(--success-soft);
  border-color: var(--success-border);
  color: var(--success-text);
}

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

html {
  overflow-x: hidden;
  max-width: 100vw;
  width: 100%;
}

body {
  font-family: var(--font-body);
  background-color: var(--bg-canvas);
  color: var(--text-primary);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  overflow-x: hidden;
  max-width: 100vw;
  width: 100%;
}

.app-root-wrapper {
  max-width: 1080px;
  margin: 0 auto;
  padding: 0.65rem 0.75rem 2.5rem;
  width: 100%;
  box-sizing: border-box;
  overflow-x: hidden;
}

.mastery-app-layout {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
}

/* ==========================================================================
   Navbar (Compact & Distraction-Free)
   ========================================================================== */
.mastery-navbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.4rem 0.75rem;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-xs);
  gap: 0.5rem;
}

.nav-left {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-width: 0;
}

.brand-link {
  text-decoration: none;
  flex-shrink: 0;
}

.brand-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.2rem;
  padding: 0.22rem 0.6rem 0.22rem 0.5rem;
  background: linear-gradient(135deg, #4338ca 0%, #6366f1 50%, #8b5cf6 100%);
  color: #ffffff;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 0.8rem;
  letter-spacing: 0.4px;
  border-radius: 7px;
  box-shadow: 0 2px 6px rgba(99, 102, 241, 0.25);
  transition: transform var(--transition-fast), box-shadow var(--transition-fast);
}

.brand-badge:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 10px rgba(99, 102, 241, 0.35);
}

.brand-integral {
  font-family: 'Times New Roman', 'Cambria Math', Georgia, serif;
  font-weight: 700;
  font-size: 1.05rem;
  line-height: 1;
  color: #fbbf24;
  display: inline-block;
  transform: translateY(-0.5px);
  margin-right: 0.05rem;
}

[data-theme="dark"] .brand-badge {
  background: linear-gradient(135deg, #3730a3 0%, #4f46e5 50%, #7c3aed 100%);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
}

.topic-meta-header {
  display: flex;
  align-items: center;
  min-width: 0;
}

.topic-title-h1 {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.92rem;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.nav-right {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-shrink: 0;
}

.btn-nav-icon {
  background: var(--bg-surface-soft);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-pill);
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.btn-nav-icon:hover {
  background: var(--bg-surface-hover);
}

.btn-nav-action {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.25rem 0.6rem;
  background: var(--bg-surface-soft);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-pill);
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.76rem;
  color: var(--text-primary);
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
}

.btn-nav-action:hover {
  background: var(--brand-soft);
  border-color: var(--brand-border);
  color: var(--brand-primary);
}

.btn-label-mobile {
  display: none;
}

.btn-label-desktop {
  display: inline;
}

.btn-nav-prev {
  text-decoration: none;
  font-size: 0.76rem;
  font-weight: 700;
  color: var(--text-secondary);
  flex-shrink: 0;
}

.btn-nav-prev:hover {
  background: var(--bg-surface-hover);
  color: var(--brand-primary);
}

.btn-theme-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.25rem 0.6rem;
  background: var(--bg-surface-soft);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-pill);
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.76rem;
  color: var(--text-primary);
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
}

.btn-theme-toggle:hover {
  background: var(--bg-surface-hover);
  border-color: var(--border-medium);
}

@media (max-width: 640px) {
  .btn-label-desktop {
    display: none !important;
  }
  .btn-label-mobile {
    display: inline !important;
  }
  .btn-theme-toggle,
  .btn-nav-action {
    padding: 0.25rem 0.45rem !important;
    gap: 0.15rem !important;
  }
}

/* ==========================================================================
   Ultra-Compact Segmented Stepper Bar
   ========================================================================== */
.stage-stepper-bar.compact-strip {
  display: flex;
  align-items: center;
  gap: 3px;
  padding: 3px;
  background: var(--bg-surface-soft);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-pill);
  overflow-x: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.stage-stepper-bar.compact-strip::-webkit-scrollbar {
  display: none;
}

.stage-step-pill {
  flex: 1;
  min-width: max-content;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 0.3rem 0.55rem;
  border: none;
  background: transparent;
  border-radius: var(--radius-pill);
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.76rem;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
}

.stage-step-pill:hover:not(:disabled) {
  background: var(--bg-surface-hover);
  color: var(--brand-primary);
}

.stage-step-pill.active {
  background: var(--brand-primary);
  color: var(--text-inverse);
  box-shadow: 0 1px 4px rgba(37, 99, 235, 0.3);
}

.stage-step-pill.completed {
  color: var(--success-text);
}

.stage-step-pill.completed.active {
  background: var(--success-primary);
  color: var(--text-inverse);
}

.stage-step-pill:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.stage-step-pill .step-badge {
  font-size: 0.68rem;
  font-weight: 700;
  opacity: 0.85;
  background: rgba(0, 0, 0, 0.06);
  padding: 0.05rem 0.3rem;
  border-radius: var(--radius-pill);
}

.stage-step-pill.active .step-badge {
  background: rgba(255, 255, 255, 0.25);
  color: var(--text-inverse);
}

/* ==========================================================================
   Typology Tabs (Compact)
   ========================================================================== */
.typology-nav-bar.compact {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.typology-pill-list {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  overflow-x: auto;
  padding-bottom: 0.15rem;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.typology-pill-list::-webkit-scrollbar {
  display: none;
}

.typology-pill-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.32rem 0.75rem;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-pill);
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.78rem;
  color: var(--text-secondary);
  cursor: pointer;
  white-space: nowrap;
  box-shadow: var(--shadow-xs);
  transition: all var(--transition-fast);
}

.typology-pill-btn:hover:not(:disabled) {
  border-color: var(--brand-primary);
  color: var(--brand-primary);
}

.typology-pill-btn.active {
  background: var(--brand-primary);
  border-color: var(--brand-primary);
  color: var(--text-inverse);
  box-shadow: 0 1px 5px rgba(37, 99, 235, 0.25);
}

.typology-pill-btn.mastered {
  border-color: var(--success-primary);
  color: var(--success-text);
  background: var(--success-soft);
}

.typology-pill-btn.mastered.active {
  background: var(--success-primary);
  color: var(--text-inverse);
}

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

/* ==========================================================================
  background: rgba(22, 163, 74, 0.1);
}

/* ==========================================================================
   Concepts View (NCERT Textbook Theory Presentation)
   ========================================================================== */
.concepts-grid {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.concept-card {
  padding: 1.35rem 1.5rem;
  background: var(--bg-surface);
  border: 1.5px solid var(--border-medium);
  border-radius: var(--radius-md);
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  box-shadow: var(--shadow-xs);
}

.concept-card-title {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.15rem;
  color: var(--text-primary);
}

.concept-statement-box {
  padding: 0.95rem 1.15rem;
  background: var(--bg-surface-soft);
  border-left: 4px solid var(--brand-primary);
  border-radius: var(--radius-xs);
}

.concept-formal-statement {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.55;
}

.concept-formula-chip {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.45rem;
  padding: 0.55rem 0.85rem;
  background: var(--brand-soft, rgba(59, 130, 246, 0.08));
  border: 1px solid var(--brand-border, rgba(59, 130, 246, 0.2));
  border-radius: var(--radius-sm, 6px);
  width: 100%;
  box-sizing: border-box;
}

.formula-chip-label {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--brand-primary, #2563eb);
  white-space: nowrap;
}

.formula-chip-math {
  font-size: 0.96rem;
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.5;
  word-break: break-word;
  overflow-wrap: break-word;
}

.formula-chip-math mjx-container {
  font-size: 100% !important;
  text-align: left !important;
  white-space: normal !important;
  word-break: break-word !important;
}

@media (max-width: 640px) {
  .concept-formula-chip {
    padding: 0.45rem 0.65rem;
    gap: 0.3rem;
  }
  .formula-chip-math {
    font-size: 0.88rem;
  }
}

.concept-explanation-text {
  font-size: 0.92rem;
  color: var(--text-secondary);
  line-height: 1.6;
}

.concept-trap-box {
  padding: 0.85rem 1.15rem;
  background: var(--error-soft);
  border: 1px solid var(--error-border);
  border-left: 4px solid var(--error-primary);
  border-radius: var(--radius-sm);
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-top: 0.75rem;
}

.concept-trap-header {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 0.82rem;
  text-transform: uppercase;
  color: var(--error-primary);
  letter-spacing: 0.4px;
}

.concept-trap-text {
  margin: 0;
  font-size: 0.92rem;
  color: var(--error-text);
  line-height: 1.55;
  font-weight: 500;
}

.concept-notes-box {
  padding: 0.85rem 1.15rem;
  background: var(--warning-soft);
  border: 1px solid var(--warning-border);
  border-radius: var(--radius-sm);
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.concept-notes-box strong {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 0.82rem;
  text-transform: uppercase;
  color: var(--warning-primary);
  letter-spacing: 0.4px;
}

.concept-notes-box ul {
  padding-left: 1.25rem;
  font-size: 0.92rem;
  color: var(--warning-text);
  line-height: 1.5;
}

/* ==========================================================================
   Textbook-Style Worked Solutions View
   ========================================================================== */
.worked-example-nav-pills {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  flex-wrap: wrap;
}

.example-nav-pill-btn {
  padding: 0.45rem 0.95rem;
  background: var(--bg-surface-soft);
  border: 1.5px solid var(--border-subtle);
  border-radius: var(--radius-pill);
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.84rem;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.example-nav-pill-btn:hover {
  border-color: var(--brand-primary);
  color: var(--brand-primary);
  transform: translateY(-1px);
}

.example-nav-pill-btn.active {
  background: var(--brand-primary);
  border-color: var(--brand-primary);
  color: var(--text-inverse);
  box-shadow: var(--shadow-xs);
}

/* Textbook Problem Card */
.textbook-problem-card {
  padding: 1.15rem 1.35rem;
  background: var(--bg-surface-soft);
  border: 1.5px solid var(--border-subtle);
  border-radius: var(--radius-md);
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.textbook-q-badge {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--brand-primary);
}

.textbook-problem-text {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.15rem;
  color: var(--text-primary);
  line-height: 1.45;
}

/* Textbook Solution Sheet */
.textbook-solution-sheet {
  background: var(--bg-surface);
  border: 2px solid var(--border-medium);
  border-left: 4px solid var(--brand-primary);
  border-radius: var(--radius-md);
  padding: 1.35rem 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  box-shadow: var(--shadow-xs);
}

.solution-header-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1.5px solid var(--border-subtle);
  padding-bottom: 0.75rem;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.solution-title-tag {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.05rem;
  color: var(--text-primary);
  text-decoration: underline;
  text-underline-offset: 4px;
}

.solution-hint-tag {
  font-size: 0.8rem;
  font-style: italic;
  color: var(--text-muted);
}

.textbook-stepwise-flow {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.textbook-step-row {
  display: flex;
  align-items: flex-start;
  gap: 0.85rem;
}

@media (max-width: 640px) {
  .textbook-step-row {
    flex-direction: column;
    gap: 0.35rem;
  }
}

.step-num-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.2rem 0.55rem;
  background: var(--brand-soft);
  color: var(--brand-primary);
  border: 1px solid var(--brand-border);
  border-radius: var(--radius-xs);
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 0.78rem;
  white-space: nowrap;
  flex-shrink: 0;
}

.step-content-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  min-width: 0;
  width: 100%;
}

.step-narrative-statement {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.5;
}

.step-math-block {
  padding: 0.2rem 0;
  background: transparent;
  border: none;
  margin: 0.15rem 0;
  font-size: 1.05rem;
  overflow-x: auto;
  overflow-y: hidden;
  max-width: 100%;
}

.step-reason-bracket {
  font-size: 0.88rem;
  color: var(--text-secondary);
  font-weight: 500;
  margin-top: 0.25rem;
  padding: 0.35rem 0.6rem;
  background: var(--bg-surface-soft);
  border-left: 3px solid var(--border-medium);
  border-radius: 0 var(--radius-xs) var(--radius-xs) 0;
  line-height: 1.5;
  max-width: 100%;
}

.reason-prefix {
  font-weight: 700;
  color: var(--brand-primary);
  margin-right: 0.25rem;
}

.textbook-conclusion-block {
  padding: 0.9rem 1.15rem;
  background: var(--success-soft);
  border: 1.5px solid var(--success-border);
  border-radius: var(--radius-sm);
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.conclusion-badge {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 0.82rem;
  text-transform: uppercase;
  color: var(--success-text);
  letter-spacing: 0.5px;
}

.conclusion-body-text {
  font-size: 0.93rem;
  color: var(--success-text);
  line-height: 1.55;
}

.stage-footer-actions {
  display: flex;
  justify-content: flex-end;
  padding-top: 1rem;
  border-top: 1px solid var(--border-subtle);
}

.stage-footer-actions.dual {
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.nav-button-group {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.btn-secondary-action {
  padding: 0.65rem 1.2rem;
  background: var(--bg-surface-soft);
  color: var(--text-primary);
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.88rem;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-pill);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.btn-secondary-action:hover {
  background: var(--bg-surface-hover);
  border-color: var(--brand-primary);
}

.panel-hero-bar {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 0.85rem 1rem;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-xs);
  width: 100%;
  box-sizing: border-box;
}

.problem-meta-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  width: 100%;
  flex-wrap: wrap;
}

.problem-meta-left {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.problem-tag {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--brand-primary);
  background: var(--brand-soft);
  border: 1px solid var(--brand-border);
  padding: 0.15rem 0.5rem;
  border-radius: var(--radius-pill);
}

.typology-sub-badge {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text-secondary);
  background: var(--bg-surface-soft);
  padding: 0.15rem 0.5rem;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border-subtle);
}

.problem-statement-text {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--text-primary);
  line-height: 1.45;
  margin: 0;
  width: 100%;
}

.stage-milestone-pill {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.74rem;
  color: var(--brand-primary);
  background: var(--brand-soft);
  padding: 0.2rem 0.55rem;
  border-radius: var(--radius-pill);
  border: 1px solid var(--brand-border);
  white-space: nowrap;
}

/* Active Step Card */
.active-step-card {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding: 1.25rem 1.35rem;
  background: var(--bg-surface);
  border: 1.5px solid var(--border-medium);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-xs);
}

/* Completed Steps Notebook Ledger (Left-Aligned Step Progress) */
.completed-steps-ledger {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 0.85rem 1.15rem;
  background: var(--bg-surface-elevated, #f8fafc);
  border: 1px solid var(--border-medium);
  border-left: 3.5px solid var(--success-primary, #10b981);
  border-radius: var(--radius-md);
  margin-bottom: 1.15rem;
  width: 100%;
  box-sizing: border-box;
  text-align: left;
}

[data-theme="dark"] .completed-steps-ledger {
  background: var(--bg-surface-elevated, #1a2234);
  border-color: var(--border-medium);
  border-left-color: var(--success-primary, #10b981);
}

.ledger-header {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  padding-bottom: 0.45rem;
  border-bottom: 1px dashed var(--border-medium);
  text-align: left;
  justify-content: flex-start;
}

.ledger-icon {
  font-size: 0.9rem;
}

.ledger-title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-secondary);
}

.ledger-list {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  width: 100%;
  text-align: left;
}

.ledger-step-row {
  display: flex;
  align-items: baseline;
  justify-content: flex-start;
  gap: 0.5rem;
  font-size: 0.9rem;
  color: var(--text-primary);
  width: 100%;
  text-align: left;
  padding: 0.2rem 0;
}

.ledger-check {
  font-weight: 800;
  color: var(--success-primary, #10b981);
  font-size: 0.9rem;
  flex-shrink: 0;
  line-height: 1;
}

.ledger-step-label {
  font-weight: 700;
  font-size: 0.88rem;
  color: var(--text-secondary);
  flex-shrink: 0;
  white-space: nowrap;
}

.ledger-step-focus {
  flex: 1;
  font-size: 0.92rem;
  color: var(--text-primary);
  font-weight: 500;
  line-height: 1.5;
  text-align: left;
}

.ledger-step-focus mjx-container,
.completed-steps-ledger mjx-container,
.step-math-block mjx-container,
.textbook-stepwise-flow mjx-container {
  max-width: 100% !important;
  margin: 0.15rem 0 !important;
  text-align: left !important;
}

.ledger-step-focus mjx-container[jax="CHTML"][display="true"],
.completed-steps-ledger mjx-container[jax="CHTML"][display="true"] {
  display: block !important;
  text-align: left !important;
  margin: 0.35rem 0 !important;
}

.step-card-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
}

.step-focus-title {
  font-weight: 700;
  font-size: 0.88rem;
  color: var(--text-primary);
}

.btn-hint-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.2rem 0.55rem;
  background: var(--bg-surface-soft);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-pill);
  font-family: var(--font-display);
  font-size: 0.76rem;
  font-weight: 700;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.btn-hint-toggle:hover {
  background: #fef9c3;
  border-color: #fde047;
  color: #854d0e;
}

.btn-hint-toggle.active {
  background: #fef08a;
  border-color: #eab308;
  color: #713f12;
}

.step-hint-callout {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  padding: 0.65rem 0.85rem;
  background: #fffdf0;
  border: 1px solid #fde68a;
  border-left: 3px solid #f59e0b;
  border-radius: var(--radius-xs);
  font-size: 0.86rem;
  color: #92400e;
  line-height: 1.45;
  animation: fadeIn var(--transition-fast);
}

.step-hint-callout .hint-icon {
  font-size: 1rem;
  line-height: 1;
}

.strategy-question-title,
.calc-prompt-title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.02rem;
  color: var(--text-primary);
  line-height: 1.45;
}

.step-focus-pill {
  display: inline-block;
  font-size: 0.76rem;
  font-weight: 700;
  color: var(--brand-primary);
  background: var(--brand-soft);
  padding: 0.15rem 0.55rem;
  border-radius: var(--radius-pill);
  border: 1px solid var(--brand-border);
}

/* Strategy Options (Modern & Interactive) */
.strategy-options-list {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.strategy-option-btn {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 0.8rem 1rem;
  background: #ffffff;
  border: 1.5px solid var(--border-medium);
  border-radius: 12px;
  cursor: pointer;
  text-align: left;
  font-size: 0.92rem;
  color: var(--text-primary);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
  transition: all 0.15s ease;
  line-height: 1.45;
  width: 100%;
  box-sizing: border-box;
}

.strategy-option-btn:hover:not(:disabled) {
  border-color: var(--brand-primary);
  background: #f8fafc;
  transform: translateY(-1px);
  box-shadow: 0 3px 8px rgba(37, 99, 235, 0.08);
}

.strategy-option-btn.selected {
  border-color: var(--brand-primary);
  background: #eff6ff;
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.2);
}

.strategy-option-btn.correct {
  border-color: var(--success-primary) !important;
  background: #ecfdf5 !important;
  box-shadow: 0 0 0 2px rgba(16, 185, 129, 0.25) !important;
  transform: translateY(-1px);
}

.strategy-option-btn.correct .option-letter {
  background: var(--success-primary) !important;
  color: #ffffff !important;
}

.strategy-option-btn.wrong {
  border-color: var(--error-primary) !important;
  background: #fff1f2 !important;
  box-shadow: 0 0 0 2px rgba(244, 63, 94, 0.25) !important;
  animation: shakeX 0.35s ease-in-out;
}

.strategy-option-btn.wrong .option-letter {
  background: var(--error-primary) !important;
  color: #ffffff !important;
}

@keyframes shakeX {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-4px); }
  40%, 80% { transform: translateX(4px); }
}

.option-letter {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  min-width: 26px;
  border-radius: 50%;
  background: #f1f5f9;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 0.8rem;
  color: #475569;
  flex-shrink: 0;
  margin-top: 1px;
  transition: all var(--transition-fast);
}

.strategy-option-btn.selected .option-letter {
  background: var(--brand-primary);
  color: var(--text-inverse);
}

.option-content {
  flex: 1;
  word-break: break-word;
  line-height: 1.45;
}

/* ==========================================================================
   Calculation Inputs & Keypad (Stage 2)
   ========================================================================== */
.calc-input-section {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.calc-template-box {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  background: var(--bg-surface-soft);
  border: 1.5px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 0.95rem;
}

.template-math-display {
  background: #ffffff;
  padding: 0.65rem 0.95rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
  text-align: center;
  font-size: 1.02rem;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.03);
  max-width: 100%;
  box-sizing: border-box;
  overflow-x: auto;
  overflow-y: hidden;
}

.template-math-display mjx-container {
  max-width: 100% !important;
  font-size: 100% !important;
  text-align: center !important;
}

@media (max-width: 640px) {
  .template-math-display {
    padding: 0.5rem 0.65rem;
    font-size: 0.88rem;
  }
  .template-math-display mjx-container {
    font-size: 85% !important;
  }
}

.template-fields-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.75rem;
}

.dual-calc-inputs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

@media (max-width: 540px) {
  .dual-calc-inputs {
    grid-template-columns: 1fr;
  }
}

.calc-field-group {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.calc-field-group label {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--text-secondary);
}

.calc-input-box {
  padding: 0.65rem 0.85rem;
  background: var(--bg-surface);
  border: 2px solid var(--border-medium);
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text-primary);
  outline: none;
  transition: all var(--transition-fast);
}

.calc-input-box:focus {
  border-color: var(--brand-primary);
  box-shadow: 0 0 0 3px var(--brand-glow);
}

.calc-input-box.field-error {
  border-color: #ef4444 !important;
  background: rgba(239, 68, 68, 0.08) !important;
  box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.2) !important;
}

.calc-input-box.field-success {
  border-color: #10b981 !important;
  background: rgba(16, 185, 129, 0.08) !important;
}

.calc-input-box.full-width {
  width: 100%;
}

.math-keypad-row {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  flex-wrap: wrap;
}

.keypad-key-btn {
  padding: 0.4rem 0.75rem;
  background: var(--bg-surface);
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-xs);
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 0.92rem;
  color: var(--text-primary);
  cursor: pointer;
  box-shadow: var(--shadow-xs);
  transition: all var(--transition-fast);
}

.keypad-key-btn:hover {
  background: var(--bg-surface-hover);
  border-color: var(--brand-primary);
  transform: translateY(-1px);
}

/* ==========================================================================
   Stage 3: Notebook Solve & Self-Audit Checklist
   ========================================================================== */
.notebook-prompt-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 1rem;
  padding: 2rem 1.5rem;
  background: var(--bg-surface-soft);
  border: 2px dashed var(--border-strong);
  border-radius: var(--radius-md);
}

.notebook-icon-header {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.25rem;
  color: var(--text-primary);
}

.notebook-instruction-text {
  max-width: 580px;
  font-size: 0.95rem;
  color: var(--text-secondary);
  line-height: 1.6;
}

.btn-reveal-rubric-action {
  padding: 0.85rem 1.5rem;
  background: var(--brand-primary);
  color: var(--text-inverse);
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 0.95rem;
  border: none;
  border-radius: var(--radius-pill);
  cursor: pointer;
  box-shadow: var(--shadow-md);
  transition: all var(--transition-fast);
}

.btn-reveal-rubric-action:hover {
  background: var(--brand-primary-hover);
  transform: translateY(-2px);
}

.rubric-checklist-card {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.rubric-header h3 {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.1rem;
  color: var(--text-primary);
}

.rubric-header p {
  font-size: 0.86rem;
  color: var(--text-secondary);
}

.rubric-items-list {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.rubric-item {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 1rem 1.25rem;
  background: var(--bg-surface-soft);
  border: 1.5px solid var(--border-subtle);
  border-radius: var(--radius-md);
  transition: all var(--transition-fast);
}

.rubric-item.marked-correct {
  border-color: var(--success-border);
  background: var(--success-soft);
}

.rubric-item.marked-wrong {
  border-color: var(--warning-border);
  background: var(--warning-soft);
}

.rubric-step-badge {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 0.84rem;
  color: var(--text-secondary);
}

.rubric-text-rule {
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-top: 0.25rem;
}

.rubric-math-box {
  margin-top: 0.35rem;
}

.rubric-toggle-buttons {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.btn-rubric-toggle {
  padding: 0.45rem 0.95rem;
  background: var(--bg-surface);
  border: 1.5px solid var(--border-medium);
  border-radius: var(--radius-pill);
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.84rem;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.btn-rubric-toggle.correct.selected {
  background: var(--success-primary);
  color: var(--text-inverse);
  border-color: var(--success-primary);
}

.btn-rubric-toggle.wrong.selected {
  background: var(--warning-primary);
  color: var(--text-inverse);
  border-color: var(--warning-primary);
}

.revisit-remediation-box {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  padding: 0.75rem 1rem;
  background: var(--bg-surface);
  border: 1px solid var(--warning-border);
  border-radius: var(--radius-sm);
  animation: fadeIn 0.2s ease-out;
}

.revisit-tip {
  font-size: 0.85rem;
  color: var(--warning-text);
  line-height: 1.45;
}

.btn-revisit-link {
  display: inline-flex;
  align-items: center;
  font-weight: 700;
  font-size: 0.82rem;
  color: var(--brand-primary);
  text-decoration: none;
}

.btn-revisit-link:hover {
  text-decoration: underline;
}

/* ==========================================================================
   Buttons & Feedback Banners
   ========================================================================== */
.step-actions-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.btn-primary-action {
  padding: 0.7rem 1.4rem;
  background: var(--brand-primary);
  color: var(--text-inverse);
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 0.92rem;
  border: none;
  border-radius: var(--radius-pill);
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: all var(--transition-fast);
}

.btn-primary-action:hover:not(:disabled) {
  background: var(--brand-primary-hover);
  transform: translateY(-1px);
}

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

.btn-success-action {
  padding: 0.7rem 1.4rem;
  background: var(--success-primary);
  color: var(--text-inverse);
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 0.92rem;
  border: none;
  border-radius: var(--radius-pill);
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: all var(--transition-fast);
}

.btn-success-action:hover {
  background: #15803d;
  transform: translateY(-1px);
}

.step-feedback-banner {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 0.85rem 1.15rem;
  border-radius: var(--radius-sm);
  animation: fadeIn 0.2s ease-out;
}

.step-feedback-banner.correct {
  background: var(--success-soft);
  border: 1.5px solid var(--success-border);
  color: var(--success-text);
}

.step-feedback-banner.wrong {
  background: var(--error-soft);
  border: 1.5px solid var(--error-border);
  color: var(--error-text);
}

.feedback-icon {
  font-size: 1.2rem;
}

.feedback-text-content p {
  font-size: 0.88rem;
  margin-top: 0.15rem;
}

.feedback-tip {
  font-style: italic;
  margin-top: 0.35rem;
}

/* ==========================================================================
   Reference Drawer
   ========================================================================== */
.reference-drawer {
  position: fixed;
  top: 0;
  right: -420px;
  width: 400px;
  max-width: 90vw;
  height: 100vh;
  background: var(--bg-surface);
  box-shadow: var(--shadow-lg);
  border-left: 1px solid var(--border-subtle);
  z-index: 9999;
  display: flex;
  flex-direction: column;
  transition: right 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  box-sizing: border-box;
}

.reference-drawer.open {
  right: 0;
}

.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  background: var(--bg-surface-soft);
  border-bottom: 1px solid var(--border-subtle);
}

.drawer-title {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.05rem;
}

.btn-drawer-close {
  background: none;
  border: none;
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--text-muted);
  cursor: pointer;
}

.btn-drawer-close:hover {
  color: var(--error-primary);
}

.drawer-body {
  padding: 1.25rem;
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.drawer-desc {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.reference-rules-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  width: 100%;
}

.ref-rule-card {
  padding: 0.75rem 1rem;
  background: var(--bg-surface-soft);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  max-width: 100%;
  box-sizing: border-box;
  overflow-x: hidden;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.ref-rule-tag {
  display: inline-block;
  font-weight: 800;
  font-size: 0.78rem;
  color: var(--brand-primary);
  text-transform: uppercase;
  margin-bottom: 0.25rem;
}

.ref-rule-text {
  font-size: 0.86rem;
  color: var(--text-primary);
  line-height: 1.45;
  word-break: break-word;
}

.ref-rule-example,
.ref-rule-formula {
  font-size: 0.82rem;
  color: var(--text-secondary);
  margin-top: 0.35rem;
  line-height: 1.45;
  overflow-x: auto;
  max-width: 100%;
  word-break: break-word;
}

.ref-rule-formula mjx-container,
.ref-rule-example mjx-container {
  font-size: 90% !important;
  max-width: 100% !important;
  overflow-x: auto !important;
  overflow-y: hidden !important;
}

@media (max-width: 480px) {
  .reference-drawer {
    width: 100vw;
    max-width: 100vw;
  }
}

.drawer-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(15, 23, 42, 0.4);
  backdrop-filter: blur(4px);
  z-index: 9998;
}

/* ==========================================================================
   Problem Completed Recap (Full Stepwise Model Solution)
   ========================================================================== */
.stage-solution-recap-panel {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  animation: fadeIn var(--transition-smooth);
}

.problem-completed-hero-card {
  padding: 1.25rem 1.5rem;
  background: linear-gradient(135deg, rgba(22, 163, 74, 0.08) 0%, rgba(37, 99, 235, 0.06) 100%);
  border: 1.5px solid var(--success-border);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.completed-hero-header {
  display: flex;
  align-items: center;
  gap: 0.85rem;
}

.completed-badge-icon {
  font-size: 2rem;
  line-height: 1;
}

.completed-hero-title {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.2rem;
  color: var(--success-text);
}

.completed-hero-sub {
  font-size: 0.9rem;
  color: var(--text-secondary);
}

.completed-milestone-bar {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.2rem;
}

.milestone-stage-tag {
  font-size: 0.75rem;
  font-weight: 800;
  text-transform: uppercase;
  color: var(--brand-primary);
  letter-spacing: 0.4px;
}

.milestone-streak-count {
  font-family: var(--font-display);
  font-size: 1rem;
  color: var(--text-primary);
}

.textbook-problem-summary {
  padding: 0.85rem 1.15rem;
  background: var(--bg-surface-soft);
  border-left: 3px solid var(--brand-primary);
  border-radius: var(--radius-xs);
  font-size: 0.94rem;
  color: var(--text-primary);
  line-height: 1.5;
}

.stage-footer-actions.center-align {
  display: flex;
  justify-content: center;
  padding-top: 1rem;
}

.btn-large {
  padding: 0.85rem 2rem;
  font-size: 1.05rem;
}

/* Loading & Error States */
.loading-state-wrapper,
.error-state-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 4rem 1.5rem;
  text-align: center;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
}

.loading-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border-subtle);
  border-top-color: var(--brand-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-bottom: 1rem;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

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

/* ==========================================================================
   Mobile & Small Screen Optimizations (< 640px)
   ========================================================================== */
@media (max-width: 640px) {
  .app-root-wrapper {
    padding: 0.35rem 0.4rem 2rem;
  }

  .mastery-navbar {
    padding: 0.35rem 0.5rem;
    gap: 0.4rem;
    flex-wrap: nowrap;
  }

  .nav-left {
    gap: 0.35rem;
    flex: 1;
    min-width: 0;
  }

  .brand-badge {
    padding: 0.18rem 0.4rem;
    font-size: 0.7rem;
  }

  .topic-meta-header {
    flex: 1;
    min-width: 0;
  }

  .topic-title-h1 {
    font-size: 0.84rem;
    max-width: 100%;
  }

  .nav-right {
    gap: 0.25rem;
    flex-shrink: 0;
  }

  .btn-nav-icon {
    width: 28px;
    height: 28px;
    font-size: 0.8rem;
  }

  .btn-nav-action {
    padding: 0.2rem 0.45rem !important;
    font-size: 0.72rem !important;
    height: 28px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .btn-nav-prev {
    padding: 0.2rem 0.45rem !important;
    height: 28px;
    font-size: 0.72rem !important;
  }

  /* Single-row clean pill scroller for worked examples */
  .worked-example-nav-pills {
    display: flex;
    flex-wrap: nowrap;
    overflow-x: auto;
    width: 100%;
    padding: 0.15rem 0;
    gap: 0.35rem;
    scrollbar-width: none;
    -ms-overflow-style: none;
    -webkit-overflow-scrolling: touch;
  }

  .worked-example-nav-pills::-webkit-scrollbar {
    display: none;
  }

  .example-nav-pill-btn {
    flex: 1 0 auto;
    padding: 0.3rem 0.65rem;
    font-size: 0.78rem;
    text-align: center;
    white-space: nowrap;
  }

  .stage-stepper-bar.compact-strip {
    gap: 2px;
    padding: 2px;
  }

  .stage-step-pill {
    padding: 0.25rem 0.4rem;
    font-size: 0.7rem;
    gap: 3px;
  }

  .stage-workspace-card {
    padding: 0.65rem 0.55rem;
    border-radius: var(--radius-sm);
  }

  /* Hero & Problem Statement */
  .panel-hero-bar {
    padding: 0.65rem 0.75rem;
    gap: 0.35rem;
  }

  .problem-statement-text {
    font-size: 0.98rem;
    line-height: 1.4;
  }

  .problem-tag,
  .typology-sub-badge {
    font-size: 0.68rem;
    padding: 0.1rem 0.4rem;
  }

  .stage-milestone-pill {
    font-size: 0.7rem;
    padding: 0.15rem 0.45rem;
  }

  /* Active Step Card */
  .active-step-card {
    padding: 0.75rem 0.65rem;
    gap: 0.65rem;
  }

  .completed-steps-ledger {
    padding: 0.2rem 0 0.35rem;
    margin-bottom: 0.35rem;
  }

  .ledger-step-row {
    font-size: 0.82rem;
    gap: 0.25rem;
  }

  .ledger-math {
    font-size: 0.85rem;
    max-width: 100%;
    overflow-x: auto;
  }

  .strategy-question-title,
  .calc-prompt-title {
    font-size: 0.95rem;
  }

  .strategy-option-btn {
    padding: 0.65rem 0.75rem;
    gap: 0.55rem;
    font-size: 0.85rem;
  }

  .option-letter {
    width: 24px;
    height: 24px;
    font-size: 0.76rem;
  }

  /* Concepts Mobile */
  .concept-card {
    padding: 0.95rem 0.85rem;
    gap: 0.65rem;
  }

  .concept-card-title {
    font-size: 1.02rem;
  }

  .concept-statement-box {
    padding: 0.75rem 0.85rem;
  }

  .concept-formal-statement {
    font-size: 0.9rem;
  }

  .concept-explanation-text {
    font-size: 0.88rem;
  }

  .concept-notes-box {
    padding: 0.75rem 0.85rem;
  }

  .concept-notes-box ul {
    padding-left: 1.1rem;
    font-size: 0.84rem;
  }

  /* Textbook Mobile */
  .textbook-problem-card {
    padding: 0.75rem 0.85rem;
  }

  .textbook-problem-text {
    font-size: 0.98rem;
  }

  .textbook-solution-sheet {
    padding: 0.85rem 0.75rem;
    border-left-width: 3px;
    gap: 0.85rem;
  }

  .solution-title-tag {
    font-size: 0.92rem;
  }

  .textbook-stepwise-flow {
    gap: 0.95rem;
  }

  .step-narrative-statement {
    font-size: 0.88rem;
  }

  .step-math-block {
    font-size: 0.95rem;
  }

  .step-reason-bracket {
    font-size: 0.8rem;
  }

  .textbook-conclusion-block {
    padding: 0.75rem 0.85rem;
  }

  .conclusion-body-text {
    font-size: 0.86rem;
  }

  /* Solution Recap Mobile */
  .problem-completed-hero-card {
    flex-direction: column;
    align-items: flex-start;
    padding: 1rem 0.85rem;
    gap: 0.75rem;
  }

  .completed-milestone-bar {
    align-items: flex-start;
  }

  .stage-footer-actions.dual {
    flex-direction: column;
    align-items: stretch;
  }

  .stage-footer-actions.dual .nav-button-group {
    justify-content: space-between;
    width: 100%;
  }

  .btn-primary-action,
  .btn-secondary-action {
    min-height: 42px;
  }

  .stage-footer-actions .btn-primary-action {
    width: 100%;
    text-align: center;
  }
}

/* Universal MathJax & Container Overflow Protection */
.concept-math-illustration,
.step-math-block,
.step-reason-bracket,
.rubric-math-box,
.textbook-conclusion-block,
.conclusion-body-text,
mjx-container {
  max-width: 100% !important;
  box-sizing: border-box !important;
}

.step-math-block,
.rubric-math-box,
mjx-container[jax="CHTML"][display="true"] {
  overflow-x: auto !important;
  overflow-y: hidden !important;
}

mjx-container[jax="CHTML"][display="true"] {
  margin: 0.25em 0 !important;
  padding-bottom: 2px;
}



/* ==========================================================================
   Stage Success — compact confirmation (Strategy / Guided Calc only).
   Deliberately small: the full worked-solution card belongs to See/Solutions.
   ========================================================================== */

.stage-success-panel {
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
}

.stage-success-banner {
  display: flex;
  align-items: flex-start;
  gap: 0.8rem;
  padding: 0.9rem 1.1rem;
  background: var(--success-soft);
  border: 1.5px solid var(--success-border);
  border-radius: var(--radius-md);
  color: var(--success-text);
}

.stage-success-icon {
  flex-shrink: 0;
  width: 1.9rem;
  height: 1.9rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--success-primary);
  color: var(--text-inverse);
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1rem;
}

.stage-success-title {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.02rem;
  margin: 0;
}

.stage-success-message {
  font-size: 0.88rem;
  line-height: 1.5;
  margin: 0.2rem 0 0;
  color: var(--text-secondary);
}

.stage-success-actions {
  display: flex;
  justify-content: flex-end;
}

@media (max-width: 768px) {
  .stage-success-banner {
    padding: 0.8rem 0.9rem;
  }

  .stage-success-title {
    font-size: 0.95rem;
  }

  .stage-success-message {
    font-size: 0.84rem;
  }

  .stage-success-actions {
    justify-content: stretch;
  }

  .stage-success-actions .btn-primary-action {
    width: 100%;
    text-align: center;
    min-height: 42px;
  }

}
