/* ============================================================
   Exponents & Surds — Grade 11 IEB Core Maths
   Design System CSS
   ============================================================ */

/* ============================================================
   1. CSS Custom Properties (Design Tokens)
   ============================================================ */

:root {
  /* Topic group accent colours */
  --color-exponent: #3B82F6;
  --color-exponent-light: #EFF6FF;
  --color-exponent-mid: #BFDBFE;

  --color-surd: #10B981;
  --color-surd-light: #ECFDF5;
  --color-surd-mid: #A7F3D0;

  --color-combined: #8B5CF6;
  --color-combined-light: #F5F3FF;
  --color-combined-mid: #DDD6FE;

  /* Cognitive level badge colours */
  --color-level-1: #22C55E;
  --color-level-1-bg: #F0FDF4;
  --color-level-2: #EAB308;
  --color-level-2-bg: #FEFCE8;
  --color-level-3: #F97316;
  --color-level-3-bg: #FFF7ED;
  --color-level-4: #EF4444;
  --color-level-4-bg: #FEF2F2;

  /* Feedback colours */
  --color-correct: #22C55E;
  --color-correct-bg: #F0FDF4;
  --color-correct-border: #86EFAC;
  --color-mistake: #F59E0B;
  --color-mistake-bg: #FFFBEB;
  --color-mistake-border: #FCD34D;
  --color-wrong: #EF4444;
  --color-wrong-bg: #FEF2F2;
  --color-wrong-border: #FCA5A5;

  /* Neutral palette */
  --bg: #F8FAFC;
  --bg-card: #FFFFFF;
  --bg-muted: #F1F5F9;
  --bg-example: #F8FAFC;

  --text-primary: #1E293B;
  --text-secondary: #64748B;
  --text-muted: #94A3B8;

  --border: #E2E8F0;
  --border-strong: #CBD5E1;

  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.07), 0 2px 4px -1px rgba(0, 0, 0, 0.04);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.08), 0 4px 6px -2px rgba(0, 0, 0, 0.04);

  /* Typography */
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'SF Mono', 'Fira Code', 'Consolas', monospace;

  /* Spacing */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;
  --space-10: 40px;

  /* Layout */
  --header-height: 56px;
  --footer-height: 44px;
  --sidebar-width: 200px;
  --content-max-width: 900px;

  /* Border radius */
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  --radius-pill: 9999px;

  /* Transitions */
  --transition: all 0.15s ease;
  --transition-slow: all 0.3s ease;
}

/* ============================================================
   2. Reset & Base
   ============================================================ */

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

html {
  scroll-behavior: smooth;
}

body {
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.6;
  color: var(--text-primary);
  background: var(--bg);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a {
  color: inherit;
  text-decoration: none;
}

button {
  font-family: var(--font);
  cursor: pointer;
  border: none;
  background: none;
}

h1, h2, h3, h4, h5, h6 {
  line-height: 1.3;
  font-weight: 600;
  color: var(--text-primary);
}

/* ============================================================
   3. App Shell & Layout
   ============================================================ */

#app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* --- Header ------------------------------------------------- */

.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--header-height);
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--space-6);
  gap: var(--space-4);
}

.app-title {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.app-icon {
  font-size: 22px;
  line-height: 1;
}

.app-header h1 {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-primary);
}

.app-subtitle {
  font-size: 13px;
  color: var(--text-secondary);
  font-weight: 400;
  padding-left: var(--space-2);
  border-left: 1px solid var(--border);
}

/* --- App Layout: CSS Grid with named areas ------------------ */
/* Named areas allow a future "notes" column to be added as
   a third column without reworking the layout structure.     */

.app-layout {
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  grid-template-areas: "sidebar content";
  flex: 1;
  min-height: 0;
}

/* --- Footer ------------------------------------------------- */

.app-footer {
  position: sticky;
  bottom: 0;
  z-index: 100;
  height: var(--footer-height);
  background: var(--bg-card);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  padding: 0 var(--space-6);
}

/* ============================================================
   4. Sidebar Navigation
   ============================================================ */

.sidebar {
  grid-area: sidebar;
  background: var(--bg-card);
  border-right: 1px solid var(--border);
  padding: var(--space-4) 0;
  overflow-y: auto;
  position: sticky;
  top: var(--header-height);
  height: calc(100vh - var(--header-height) - var(--footer-height));
}

.nav-group {
  padding: var(--space-3) 0 var(--space-4);
  border-bottom: 1px solid var(--border);
}

.nav-group:last-child {
  border-bottom: none;
}

.nav-group-title {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 0 var(--space-4) var(--space-2);
  display: block;
}

/* Topic group accent colours on nav headings */
.nav-group-exponents {
  color: var(--color-exponent);
}

.nav-group-surds {
  color: var(--color-surd);
}

.nav-group-combined {
  color: var(--color-combined);
}

.nav-link {
  display: block;
  padding: var(--space-2) var(--space-4);
  font-size: 14px;
  color: var(--text-secondary);
  border-left: 3px solid transparent;
  transition: var(--transition);
}

.nav-link:hover {
  background: var(--bg-muted);
  color: var(--text-primary);
}

/* Active state — accent colour varies by topic group */
.nav-link.active {
  font-weight: 600;
  color: var(--text-primary);
}

/* Active link colours set by JS adding topic-group class,
   but we define the pattern here with data-topic selectors */
.nav-link[data-topic="exponent-basics"].active,
.nav-link[data-topic="exponent-laws"].active {
  border-left-color: var(--color-exponent);
  background: var(--color-exponent-light);
  color: var(--color-exponent);
}

.nav-link[data-topic="surds-basics"].active,
.nav-link[data-topic="surds-arithmetic"].active,
.nav-link[data-topic="rationalising"].active {
  border-left-color: var(--color-surd);
  background: var(--color-surd-light);
  color: var(--color-surd);
}

.nav-link[data-topic="mixed-problems"].active {
  border-left-color: var(--color-combined);
  background: var(--color-combined-light);
  color: var(--color-combined);
}

/* Mobile hamburger button — hidden on desktop */
.hamburger-btn {
  display: none;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 20px;
  transition: var(--transition);
}

.hamburger-btn:hover {
  background: var(--bg-muted);
}

/* ============================================================
   5. Main Content Area
   ============================================================ */

.content {
  grid-area: content;
  padding: var(--space-8);
  padding-bottom: calc(var(--space-8) + var(--footer-height));
  max-width: calc(var(--content-max-width) + var(--space-8) * 2);
  width: 100%;
  overflow-y: auto;
  scroll-padding-bottom: var(--footer-height);
}

/* ============================================================
   6. Learn Zone & Practice Zone Containers
   ============================================================ */

.learn-zone {
  margin-bottom: var(--space-8);
}

.learn-zone > h2 {
  font-size: 22px;
  margin-bottom: var(--space-4);
  padding-bottom: var(--space-2);
  border-bottom: 2px solid var(--border);
}

.learn-zone section {
  margin-bottom: var(--space-5);
}

.learn-zone h3 {
  font-size: 16px;
  font-weight: 600;
  margin-top: 0;
  margin-bottom: var(--space-2);
  color: var(--text-primary);
}

.learn-zone section p {
  margin-top: 0;
  margin-bottom: var(--space-3);
  line-height: 1.6;
}

.learn-zone section p:last-child {
  margin-bottom: 0;
}

.practice-zone {
  margin-top: var(--space-8);
  margin-bottom: var(--space-8);
  padding: var(--space-5) var(--space-6);
  background: var(--color-level-1-bg);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  transition: background 0.3s ease, border-color 0.3s ease;
}

/* Tint practice zone background by current question's cognitive level */
.practice-zone.practice-level-1 { background: var(--color-level-1-bg); border-color: #86EFAC; }
.practice-zone.practice-level-2 { background: var(--color-level-2-bg); border-color: #FDE68A; }
.practice-zone.practice-level-3 { background: var(--color-level-3-bg); border-color: #FDBA74; }
.practice-zone.practice-level-4 { background: var(--color-level-4-bg); border-color: #FCA5A5; }

.practice-zone > .practice-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--space-2);
  font-size: 18px;
  font-weight: 700;
  margin-top: 0;
  margin-bottom: var(--space-4);
  padding-bottom: var(--space-2);
  border-bottom: 2px solid var(--border);
}

/* ============================================================
   7. Rule Cards
   ============================================================ */

.rule-card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  border-left: 4px solid var(--border-strong);
  padding: var(--space-4) var(--space-5);
  margin-top: var(--space-2);
  margin-bottom: var(--space-4);
  box-shadow: var(--shadow-sm);
  transition: var(--transition);
}

.rule-card ul {
  margin: var(--space-2) 0;
  padding-left: var(--space-5);
}

.rule-card li {
  margin-bottom: var(--space-1);
  line-height: 1.5;
}

.rule-card:hover {
  box-shadow: var(--shadow-md);
}

.rule-card h3 {
  font-size: 15px;
  font-weight: 700;
  margin-bottom: var(--space-3);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* Rule card topic variants */
.rule-card-exponents {
  border-left-color: var(--color-exponent);
  background: linear-gradient(to right, var(--color-exponent-light) 0%, var(--bg-card) 60%);
}

.rule-card-exponents h3 {
  color: var(--color-exponent);
}

.rule-card-surds {
  border-left-color: var(--color-surd);
  background: linear-gradient(to right, var(--color-surd-light) 0%, var(--bg-card) 60%);
}

.rule-card-surds h3 {
  color: var(--color-surd);
}

.rule-card-combined {
  border-left-color: var(--color-combined);
  background: linear-gradient(to right, var(--color-combined-light) 0%, var(--bg-card) 60%);
}

.rule-card-combined h3 {
  color: var(--color-combined);
}

/* ============================================================
   8. Example Blocks
   ============================================================ */

.example-block {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-4) var(--space-5);
  margin-bottom: var(--space-3);
  box-shadow: var(--shadow-sm);
  counter-reset: step;
}

.example-block .breakdown-note {
  font-size: 14px;
  color: var(--text-secondary);
  margin-top: var(--space-3);
  margin-bottom: var(--space-1);
}

.example-block h4 {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-secondary);
  margin-bottom: var(--space-4);
}

.example-block .example-step {
  display: flex;
  gap: var(--space-3);
  padding: var(--space-2) 0;
  counter-increment: step;
}

.example-block .example-step::before {
  content: counter(step);
  display: flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  min-width: 22px;
  background: var(--text-secondary);
  color: white;
  border-radius: var(--radius-pill);
  font-size: 11px;
  font-weight: 700;
  margin-top: 2px;
}

/* ============================================================
   9. Mistake Blocks
   ============================================================ */

.mistake-block {
  border-radius: var(--radius-lg);
  overflow: hidden;
  margin-bottom: var(--space-5);
  border: 1px solid var(--border);
}

.mistake-block-header {
  padding: var(--space-2) var(--space-4);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  background: var(--bg-muted);
  color: var(--text-secondary);
}

.mistake-wrong {
  background: var(--color-wrong-bg);
  border-left: 4px solid var(--color-wrong);
  padding: var(--space-4) var(--space-5);
  color: var(--text-primary);
}

.mistake-wrong::before {
  content: "✗ Common mistake: ";
  font-weight: 700;
  color: var(--color-wrong);
}

.mistake-right {
  background: var(--color-correct-bg);
  border-left: 4px solid var(--color-correct);
  padding: var(--space-4) var(--space-5);
  color: var(--text-primary);
}

.mistake-right::before {
  content: "✓ Correct: ";
  font-weight: 700;
  color: var(--color-correct);
}

/* ============================================================
   10. Animation Container (Visual Breakdowns)
   ============================================================ */

.animate-container {
  margin: var(--space-5) 0;
  padding: var(--space-5);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

.animate-step {
  opacity: 0;
  display: none;
  transition: var(--transition-slow);
}

.animate-step.visible {
  opacity: 1;
  display: block;
  animation: fadeIn 0.2s ease forwards;
}

/* ============================================================
   11. Try First Prompt
   ============================================================ */

.try-first {
  background: var(--bg-muted);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-5);
  margin-bottom: var(--space-5);
  font-size: 14px;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.try-first::before {
  content: "💡";
  font-size: 16px;
}

/* ============================================================
   12. Practice Zone — Header & Question
   ============================================================ */

.practice-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-5);
  flex-wrap: wrap;
  gap: var(--space-2);
}

.question-counter {
  font-size: 13px;
  color: var(--text-secondary);
  font-weight: 500;
}

/* Question navigator — numbered dots to jump between questions */
.question-nav {
  display: flex;
  gap: 6px;
  margin-bottom: var(--space-4);
  flex-wrap: wrap;
}

.q-dot {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: var(--bg-card);
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
}

.q-dot:hover {
  border-color: var(--color-exponent);
  color: var(--color-exponent);
}

.q-dot-current {
  background: var(--color-exponent);
  border-color: var(--color-exponent);
  color: white;
}

.q-dot-correct {
  background: var(--color-correct);
  border-color: var(--color-correct);
  color: white;
}

.q-dot-partial {
  background: var(--color-mistake-bg);
  border-color: var(--color-mistake);
  color: var(--color-mistake);
}

.q-dot-wrong {
  background: var(--color-wrong-bg);
  border-color: var(--color-wrong);
  color: var(--color-wrong);
}

.question-text {
  font-size: 18px;
  font-weight: 500;
  color: var(--text-primary);
  line-height: 1.5;
  margin-bottom: var(--space-5);
}

/* ============================================================
   13. Answer Area & MCQ Options
   ============================================================ */

.answer-area {
  margin-bottom: var(--space-5);
}

.mcq-options {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.mcq-option {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  background: var(--bg-card);
  border: 2px solid var(--border);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: var(--transition);
  font-size: 15px;
  user-select: none;
}

.mcq-option:hover {
  border-color: var(--border-strong);
  background: var(--bg-muted);
}

.mcq-option.selected {
  border-color: var(--color-exponent);
  background: var(--color-exponent-light);
  font-weight: 500;
}

.mcq-option input[type="radio"] {
  accent-color: var(--color-exponent);
  width: 18px;
  height: 18px;
  cursor: pointer;
}

/* MathLive math-field element */
math-field.answer-input,
.answer-input {
  display: block;
  min-height: 50px;
  width: 100%;
  max-width: 400px;
  border: 2px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-2) var(--space-3);
  font-size: 18px;
  background: var(--bg-card);
  transition: var(--transition);
  outline: none;
}

math-field.answer-input:focus,
.answer-input:focus {
  border-color: var(--color-exponent);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

/* Hide MathLive's menu toggle — prevents access to calculus/matrices/complex */
math-field::part(menu-toggle) {
  display: none;
}

/* When the virtual keyboard is open, extra space at bottom lets
   the input scroll above the keyboard */
body.keyboard-open .practice-zone {
  padding-bottom: 320px;
}

/* ============================================================
   14. Buttons
   ============================================================ */

/* Shared button base — consistent size for all action buttons */
.check-btn,
.next-step-btn,
.next-question-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  width: 100%;
  padding: var(--space-3) var(--space-5);
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
}

/* Check Answer — filled accent */
.check-btn {
  background: var(--color-exponent);
  color: white;
  border-color: var(--color-exponent);
}

.check-btn:hover {
  background: #2563EB;
  border-color: #2563EB;
}

/* Show Next Step — outlined accent */
.next-step-btn {
  background: white;
  color: var(--color-exponent);
  border-color: var(--color-exponent);
  margin-top: var(--space-2);
}

.next-step-btn:hover {
  background: var(--color-exponent-light);
}

/* Next Question — filled accent, hidden until .visible */
.next-question-btn {
  display: none;
  background: var(--color-exponent);
  color: white;
  border-color: var(--color-exponent);
  margin-top: var(--space-3);
}

.next-question-btn.visible {
  display: flex;
}

.next-question-btn:hover {
  background: #2563EB;
  border-color: #2563EB;
}

/* Tighten feedback panel internals */
.feedback-header {
  margin-bottom: var(--space-2);
}

.worked-solution {
  margin-top: var(--space-2);
}

.solution-label {
  font-size: 13px;
  color: var(--text-secondary);
  margin: 0 0 var(--space-1) 0;
}

.notes-btn {
  padding: var(--space-2) var(--space-4);
  background: var(--bg-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  transition: var(--transition);
}

.notes-btn:not(:disabled):hover {
  background: var(--border);
  color: var(--text-primary);
}

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

/* ============================================================
   15. Level Badges
   ============================================================ */

.level-badge {
  display: inline-flex;
  align-items: center;
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-pill);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

/* Active-filter indicators next to the "Practice" heading (always visible —
   the selected topic + difficulty, even when the pill rows are scrolled). */
.practice-badges {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: wrap;
  justify-content: flex-end;
}

.topic-badge {
  display: inline-flex;
  align-items: center;
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-pill);
  font-size: 12px;
  font-weight: 700;
  background: var(--color-combined-light);
  color: var(--color-combined);
  border: 1px solid var(--color-combined-mid);
  max-width: 60vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.level-1 {
  background: var(--color-level-1-bg);
  color: var(--color-level-1);
  border: 1px solid #86EFAC;
}

.level-2 {
  background: var(--color-level-2-bg);
  color: #92400E;
  border: 1px solid #FDE047;
}

.level-3 {
  background: var(--color-level-3-bg);
  color: #9A3412;
  border: 1px solid #FDBA74;
}

.level-4 {
  background: var(--color-level-4-bg);
  color: var(--color-wrong);
  border: 1px solid #FCA5A5;
}

/* ============================================================
   16. Feedback Panel
   ============================================================ */

.feedback-panel {
  display: none;
  border-radius: var(--radius-lg);
  padding: var(--space-5) var(--space-6);
  margin-top: var(--space-4);
  border-width: 1px;
  border-style: solid;
}

.feedback-icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  vertical-align: middle;
  display: inline-block;
}

.feedback-panel.visible {
  display: block;
  animation: slideDown 0.3s ease forwards;
}

.feedback-correct {
  background: var(--color-correct-bg);
  border-color: var(--color-correct-border);
}

.feedback-mistake {
  background: var(--color-mistake-bg);
  border-color: var(--color-mistake-border);
}

.feedback-wrong {
  background: var(--color-wrong-bg);
  border-color: var(--color-wrong-border);
}

/* Feedback header text — rendered by JS (renderFeedback), NOT by CSS ::before */
.feedback-header {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-weight: 700;
  font-size: 16px;
  margin-bottom: var(--space-3);
}

.feedback-correct .feedback-header { color: var(--color-correct); }
.feedback-mistake .feedback-header { color: var(--color-mistake); }
.feedback-wrong .feedback-header { color: var(--color-wrong); }

/* ============================================================
   17. Step Reveal (Worked Solutions)
   ============================================================ */

.step-reveal {
  opacity: 0;
  max-height: 0;
  overflow: hidden;
  transition: opacity 0.3s ease, max-height 0.3s ease;
}

.step-reveal.visible {
  opacity: 1;
  max-height: 600px;   /* generous cap so a long step (KaTeX + wrapped text) isn't clipped on mobile */
}

/* ============================================================
   18. Study Tip Banner
   ============================================================ */

.study-tip-banner {
  position: relative;
  background: #FFFBEB;
  border: 1px solid var(--color-mistake-border);
  border-left: 4px solid var(--color-mistake);
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-8) var(--space-3) var(--space-4);
  margin-bottom: var(--space-4);
  font-size: 14px;
  line-height: 1.6;
  color: var(--text-primary);
}

.study-tip-banner.hidden {
  display: none;
}

.study-tip-banner p {
  margin: 0;
}

.study-tip-dismiss {
  position: absolute;
  top: var(--space-2);
  right: var(--space-2);
  padding: var(--space-1);
  color: var(--text-muted);
  font-size: 14px;
  line-height: 1;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: var(--transition);
}

.study-tip-dismiss:hover {
  color: var(--text-primary);
  background: rgba(0, 0, 0, 0.06);
}

.study-tip-link {
  display: block;
  margin-top: var(--space-2);
  font-size: 13px;
  color: var(--color-exponent);
  font-weight: 500;
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
  transition: var(--transition);
}

.study-tip-link:hover {
  color: #2563EB;
}

/* ============================================================
   19. Self-Explanation Prompt
   ============================================================ */

.self-explanation {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-5) var(--space-6);
  margin-top: var(--space-5);
}

.self-explanation h4 {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: var(--space-3);
  color: var(--text-secondary);
}

.self-explanation textarea {
  width: 100%;
  min-height: 80px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-3);
  font-family: var(--font);
  font-size: 14px;
  color: var(--text-primary);
  background: var(--bg);
  resize: vertical;
  transition: var(--transition);
  outline: none;
}

.self-explanation textarea:focus {
  border-color: var(--color-exponent);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.12);
}

.self-explanation .btn-row {
  display: flex;
  gap: var(--space-2);
  margin-top: var(--space-3);
}

.self-explanation-note {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.5;
  margin-top: var(--space-2);
  margin-bottom: 0;
}

.self-explanation-actions {
  display: flex;
  gap: var(--space-2);
  margin-top: var(--space-3);
}

/* ============================================================
   20. KaTeX & Math Display
   ============================================================ */

.katex-display {
  margin: var(--space-4) 0;
  overflow-x: auto;
  overflow-y: hidden;
}

.math-inline {
  font-size: 1.05em;
}

/* ============================================================
   21. Animations
   ============================================================ */

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

@keyframes slideDown {
  /* Fade + slide only — NO max-height. With `forwards`, a max-height here would
     stay applied and cap the panel (it capped at 500px), so a long worked
     solution on mobile overflowed and overlapped the self-explanation card. */
  from {
    opacity: 0;
    transform: translateY(-8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ============================================================
   22. Responsive — Mobile (< 768px)
   ============================================================ */

@media (max-width: 768px) {
  /* Show hamburger, hide sidebar by default on mobile */
  .hamburger-btn {
    display: flex;
  }

  .app-header {
    padding: 0 var(--space-4);
  }

  .app-subtitle {
    display: none;
  }

  /* Switch to single-column layout */
  .app-layout {
    grid-template-columns: 1fr;
    grid-template-areas: "content";
  }

  /* Sidebar becomes an overlay */
  .sidebar {
    position: fixed;
    top: var(--header-height);
    left: 0;
    bottom: var(--footer-height);
    width: var(--sidebar-width);
    z-index: 200;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    box-shadow: var(--shadow-lg);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  /* Content takes full width */
  .content {
    padding: var(--space-5) var(--space-4);
  }

  /* MCQ options stack naturally (already column) */
  .mcq-option {
    padding: var(--space-3);
  }

  /* Footer wraps badges */
  .app-footer {
    height: auto;
    min-height: var(--footer-height);
    flex-wrap: wrap;
    padding: var(--space-2) var(--space-4);
    gap: var(--space-2);
  }

  /* Practice header stacks */
  .practice-header {
    flex-direction: column;
    align-items: flex-start;
  }

  /* Buttons full-width on mobile */
  .check-btn,
  .next-question-btn {
    width: 100%;
    justify-content: center;
  }

  /* Math field full width */
  math-field.answer-input,
  .answer-input {
    max-width: 100%;
  }
}

/* ============================================================
   23. Print Styles (Future-Proofing)
   ============================================================ */

@media print {
  .sidebar,
  .app-footer,
  .check-btn,
  .next-step-btn,
  .next-question-btn,
  .notes-btn,
  .hamburger-btn,
  .study-tip-dismiss {
    display: none !important;
  }

  .app-layout {
    grid-template-columns: 1fr;
    grid-template-areas: "content";
  }

  .content {
    padding: 0;
    max-width: 100%;
  }

  .app-header {
    position: static;
    box-shadow: none;
    border-bottom: 1px solid #ccc;
  }

  .rule-card,
  .example-block {
    break-inside: avoid;
  }

  .step-reveal {
    opacity: 1;
    max-height: none;
  }

  .animate-step {
    opacity: 1;
    display: block;
  }
}

/* ============================================================
   24. Difficulty Filter (Practice Zone)
   ============================================================ */

.practice-filter {
  margin-bottom: var(--space-4);
}

/* Labelled filter groups (Topic / Difficulty). The pills live in .filter-pills
   so the label stays put while the pills wrap (desktop) or scroll (mobile). */
.filter-group-label {
  display: block;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin-bottom: var(--space-1);
}

.filter-pills {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.filter-btn {
  padding: var(--space-1) var(--space-3);
  border: 1.5px solid var(--border-strong);
  border-radius: var(--radius-pill);
  background: var(--bg-card);
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 600;
  line-height: 1.5;
  cursor: pointer;
  transition: var(--transition);
}

.filter-btn:hover:not(:disabled):not(.active) {
  border-color: var(--text-secondary);
  color: var(--text-primary);
  background: var(--bg-muted);
}

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

/* Topic facet (global "All Questions" pool only) */
.practice-topic-filter {
  margin-bottom: var(--space-3);
}

.practice-topic-filter:empty {
  display: none;
}

.topic-filter-btn {
  padding: var(--space-1) var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  background: var(--bg-card);
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
}

.topic-filter-btn:hover:not(.active) {
  border-color: var(--text-secondary);
  color: var(--text-primary);
  background: var(--bg-muted);
}

.topic-filter-btn.active {
  background: var(--color-combined);
  border-color: var(--color-combined);
  color: white;
}

/* Inline empty-state when a chosen level has no questions in the current scope */
.empty-level {
  text-align: center;
  padding: var(--space-6) var(--space-4);
  color: var(--text-secondary);
}

.empty-level p {
  margin-bottom: var(--space-4);
  line-height: 1.6;
}

.empty-level .empty-level-action {
  width: auto;
  display: inline-flex;
}

/* Active filter — filled, strong signifier (NN/g: make the control obvious) */
.filter-btn.active {
  background: var(--text-primary);
  border-color: var(--text-primary);
  color: white;
}

.filter-btn.filter-level-1.active { background: var(--color-level-1); border-color: var(--color-level-1); color: white; }
.filter-btn.filter-level-2.active { background: var(--color-level-2); border-color: var(--color-level-2); color: #1E293B; }
.filter-btn.filter-level-3.active { background: var(--color-level-3); border-color: var(--color-level-3); color: white; }
.filter-btn.filter-level-4.active { background: var(--color-level-4); border-color: var(--color-level-4); color: white; }

/* ============================================================
   25. Back-to-Notes Button (Practice Zone)
   ============================================================ */

.notes-link-btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-2) var(--space-3);
  background: transparent;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
}

.notes-link-btn:hover {
  color: var(--text-primary);
  border-color: var(--text-secondary);
  background: var(--bg-muted);
}

/* ============================================================
   26. Footer Legend (informational — NOT a control)
   ============================================================ */

.footer-legend-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  font-size: 12px;
  color: var(--text-secondary);
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: var(--transition);
}

.legend-item:hover {
  background: var(--bg-muted);
  color: var(--text-primary);
}

.legend-item::before {
  content: "";
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.legend-1::before { background: var(--color-level-1); }
.legend-2::before { background: var(--color-level-2); }
.legend-3::before { background: var(--color-level-3); }
.legend-4::before { background: var(--color-level-4); }

/* ============================================================
   27. Mobile Topic Bar (visible "combo" navigation)
   ============================================================ */

.topic-bar {
  display: none;  /* desktop uses the sidebar */
}

@media (max-width: 768px) {
  /* Filter pills: one swipeable line per group (Topic / Difficulty) instead of a
     cramped multi-row wrap. The cut-off last pill is the scroll affordance. */
  .filter-pills {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding-bottom: var(--space-1);
  }
  .filter-pills::-webkit-scrollbar { display: none; }
  .filter-pills .filter-btn,
  .filter-pills .topic-filter-btn {
    flex: 0 0 auto;
    white-space: nowrap;
  }

  .topic-bar {
    display: flex;
    gap: var(--space-2);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding: var(--space-2) var(--space-4);
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: var(--header-height);
    z-index: 90;
  }

  .topic-chip {
    flex: 0 0 auto;
    padding: var(--space-1) var(--space-3);
    border: 1px solid var(--border);
    border-radius: var(--radius-pill);
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    background: var(--bg-muted);
    white-space: nowrap;
    transition: var(--transition);
  }

  .topic-chip.active {
    background: var(--color-exponent);
    border-color: var(--color-exponent);
    color: white;
  }

  .topic-chip-all {
    color: var(--text-primary);
    border-color: var(--border-strong);
  }
}

/* ============================================================
   29. Maths keyboard help (just-in-time hint + cheat-sheet)
   ============================================================ */

/* Just-in-time hint — appears under the input the moment a box is opened */
.kb-hint {
  margin: var(--space-2) 0 var(--space-3);
  padding: var(--space-2) var(--space-3);
  background: var(--color-exponent-light);
  border: 1px solid var(--color-exponent-mid);
  border-left: 3px solid var(--color-exponent);
  border-radius: var(--radius-md);
  font-size: 13px;
  color: var(--text-primary);
  line-height: 1.5;
}

/* Row holding the secondary actions under the Check button */
.practice-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: stretch;   /* equal-height buttons so tops/bottoms line up */
  gap: var(--space-2);
  margin-top: var(--space-2);
}

/* Both action buttons share one line-height so differing glyphs (↑ vs ⌨)
   can't change their height and break alignment. */
.practice-actions .notes-link-btn,
.practice-actions .kb-help-link {
  line-height: 1.3;
}

.kb-help-link {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-2) var(--space-3);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
}

.kb-help-link:hover {
  color: var(--color-exponent);
  border-color: var(--color-exponent);
  background: var(--color-exponent-light);
}

/* Cheat-sheet modal */
.kb-help-overlay {
  position: fixed;
  inset: 0;
  z-index: 500;
  background: rgba(15, 23, 42, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
  animation: fadeIn 0.15s ease;
}

.kb-help-card {
  position: relative;
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: var(--space-6);
  max-width: 460px;
  width: 100%;
  max-height: 85vh;
  overflow-y: auto;
}

.kb-help-card h3 {
  font-size: 18px;
  margin-bottom: var(--space-3);
  padding-right: var(--space-6);
}

.kb-help-close {
  position: absolute;
  top: var(--space-3);
  right: var(--space-3);
  width: 32px;
  height: 32px;
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  transition: var(--transition);
}

.kb-help-close:hover {
  background: var(--bg-muted);
  color: var(--text-primary);
}

.kb-help-rule {
  background: var(--color-level-1-bg);
  border-left: 3px solid var(--color-level-1);
  border-radius: var(--radius-md);
  padding: var(--space-3);
  font-size: 14px;
  line-height: 1.55;
  margin-bottom: var(--space-4);
}

.kb-help-eg-title {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: var(--space-2);
}

.kb-help-steps {
  margin: 0 0 var(--space-4) var(--space-5);
  font-size: 14px;
  line-height: 1.8;
}

.kb-help-legend {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.kb-help-legend td {
  padding: var(--space-2) var(--space-3);
  border-top: 1px solid var(--border);
  vertical-align: top;
}

.kb-help-legend td:first-child {
  font-weight: 700;
  white-space: nowrap;
  color: var(--text-primary);
  width: 1%;
}

.kb-help-legend td:last-child {
  color: var(--text-secondary);
}

/* ============================================================
   28. All Questions pool + new nav accents
   ============================================================ */

.pool-intro {
  margin-bottom: var(--space-6);
}

.pool-intro h2 {
  font-size: 22px;
  margin-bottom: var(--space-3);
  padding-bottom: var(--space-2);
  border-bottom: 2px solid var(--border);
}

.pool-intro p {
  color: var(--text-secondary);
}

/* "Practice / All Questions" nav group accent */
.nav-group-all {
  color: var(--text-primary);
}

.nav-link-all {
  font-weight: 600;
}

/* Active-state colours for the new nav links (match their topic group) */
.nav-link[data-topic="all-practice"].active {
  border-left-color: var(--text-primary);
  background: var(--bg-muted);
  color: var(--text-primary);
}

.nav-link[data-topic="exponential-equations"].active {
  border-left-color: var(--color-exponent);
  background: var(--color-exponent-light);
  color: var(--color-exponent);
}

.nav-link[data-topic="surd-equations"].active {
  border-left-color: var(--color-surd);
  background: var(--color-surd-light);
  color: var(--color-surd);
}

/* ============================================================
   17. Step-based "working" questions (per-step mark allocation)
   ============================================================ */

.working-lines {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  margin-bottom: var(--space-2);
}

.working-row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.working-field {
  flex: 1;
  min-width: 0;
}

.working-field .answer-input {
  width: 100%;
}

/* Per-line badge: +N earned (green), ✓ valid no-new-mark (grey), ✗ wrong (red) */
.work-mark {
  width: 28px;
  height: 28px;
  flex: 0 0 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
}
.work-mark.ok   { background: var(--color-correct-bg); color: var(--color-correct); }
.work-mark.valid{ background: var(--bg-muted); color: var(--text-muted); }
.work-mark.bad  { background: var(--color-wrong-bg); color: var(--color-wrong); }
.work-mark.warn { background: var(--color-mistake-bg); color: var(--color-mistake); }
.work-mark.dot  { color: var(--border-strong); }

.work-rm {
  border: none;
  background: none;
  color: var(--text-muted);
  font-size: 16px;
  cursor: pointer;
  flex: 0 0 auto;
  padding: var(--space-1);
  line-height: 1;
}
.work-rm:hover { color: var(--color-wrong); }

.root-hint {
  font-size: 12px;
  color: var(--text-secondary);
  margin: var(--space-1) 0 var(--space-3);
}

.add-line-btn {
  display: block;
  width: 100%;
  background: transparent;
  border: 1px dashed var(--border-strong);
  color: var(--text-secondary);
  padding: var(--space-2);
  border-radius: var(--radius-md);
  cursor: pointer;
  font-size: 13px;
  margin-bottom: var(--space-3);
}
.add-line-btn:hover { background: var(--bg-muted); }

/* Mark-scheme checklist inside the feedback panel */
.checklist {
  margin-top: var(--space-3);
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}
.ms {
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
}
.ms.got  { color: #166534; background: var(--color-correct-bg); border-color: var(--color-correct-border); }
.ms.miss { color: var(--text-secondary); }
.ms .mstick { font-weight: 800; width: 15px; text-align: center; flex: 0 0 auto; }
.ms .msm    { margin-left: auto; font-weight: 700; font-size: 12px; white-space: nowrap; }

.ai-note {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: var(--space-3);
  font-style: italic;
}
