/* CoursMission LaTeX Lessons — Dedicated Frontend Stylesheet */

/* Lesson Container & Typography */
.cm-template--lesson {
  width: min(940px, calc(100% - 32px)) !important;
  margin: 36px auto 72px !important;
}

/* Prevent nested .cm-template from adding extra margin/width restrictions */
.cm-template .cm-template,
.entry-content > .cm-template,
.cm-template--lesson .cm-template--lesson {
  width: 100% !important;
  max-width: 100% !important;
  margin: 0 !important;
  padding: 0 !important;
}

.cm-template--lesson .entry-content {
  font-family: 'Nunito Sans', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.75;
  color: #334155;
}

/* Page Hero Header in Lesson */
.cm-template .cm-page-hero,
.cm-template .cm-math-hub-hero {
  border-radius: 24px;
  padding: 34px 38px;
  margin-bottom: 28px;
  background: radial-gradient(circle at 90% 10%, rgba(255, 106, 56, .14), transparent 30%), linear-gradient(120deg, #fff, #faf6f0);
  border: 1.5px solid #eee8df;
  box-shadow: 0 8px 24px rgba(14, 31, 56, .03);
}

.cm-template .cm-page-hero .kicker {
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .08em;
  color: #ff6a38;
  text-transform: uppercase;
  margin-bottom: 8px;
}

.cm-template .cm-page-hero h2 {
  font-family: 'Baloo 2', sans-serif;
  font-size: clamp(26px, 4vw, 36px);
  font-weight: 800;
  color: #0e1f38;
  margin: 6px 0 12px;
  line-height: 1.15;
}

.cm-template .cm-page-hero .sub {
  font-size: 16px;
  color: #55637a;
  line-height: 1.6;
  margin: 0 0 20px;
}

.cm-template .cm-page-hero .cm-home-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
}

/* Interactive Sommaire (Table of Contents) */
.cm-lesson-toc {
  background: #fff;
  border: 1.5px solid #eee8df;
  border-radius: 20px;
  padding: 22px 28px;
  margin: 28px 0 34px;
  box-shadow: 0 6px 20px rgba(14, 31, 56, .04);
}

.cm-toc-header {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 18px;
  font-weight: 800;
  color: #0e1f38;
  border-bottom: 2px solid #fff0eb;
  padding-bottom: 12px;
  margin-bottom: 16px;
  font-family: 'Baloo 2', sans-serif;
}

.cm-toc-icon {
  font-size: 20px;
}

.cm-toc-list {
  list-style: none !important;
  margin: 0 !important;
  padding-left: 0 !important;
}

.cm-toc-item {
  margin: 9px 0 !important;
  font-size: 15px !important;
  font-weight: 700 !important;
}

.cm-toc-item a {
  color: #0e1f38 !important;
  text-decoration: none !important;
  transition: color .15s ease;
}

.cm-toc-item a:hover {
  color: #ff6a38 !important;
  text-decoration: underline !important;
}

.cm-toc-sub {
  margin-left: 24px !important;
  font-weight: 600 !important;
  font-size: 14px !important;
  color: #64748b !important;
}

.cm-toc-sub a {
  color: #64748b !important;
}

.cm-toc-sub a:hover {
  color: #ff6a38 !important;
}

/* Chapter & Subchapter Headings */
.cm-lesson-chapter {
  margin-top: 36px;
  padding-top: 24px;
  border-top: 1px solid #f1f5f9;
}

.cm-chapter-title {
  font-family: 'Baloo 2', sans-serif;
  font-size: clamp(22px, 3.5vw, 28px);
  font-weight: 800;
  color: #0e1f38;
  margin: 0 0 16px;
  display: block;
  line-height: 1.35;
  scroll-margin-top: 90px;
}

.cm-chapter-title .cm-anchor-link,
.cm-subchapter-title .cm-anchor-link {
  display: inline-block;
  margin-right: 8px;
  color: #ff6a38;
  text-decoration: none;
  font-weight: 700;
}

.cm-chapter-title .katex,
.cm-subchapter-title .katex {
  font-size: 0.92em;
}

.cm-subchapter-title {
  font-family: 'Baloo 2', sans-serif;
  font-size: 20px;
  font-weight: 800;
  color: #1e293b;
  margin: 26px 0 14px;
  display: block;
  line-height: 1.35;
  scroll-margin-top: 90px;
}

.cm-anchor-link {
  color: #ff6a38;
  opacity: .35;
  text-decoration: none;
  font-weight: 700;
  transition: opacity .15s;
}

.cm-anchor-link:hover {
  opacity: 1;
}

/* The Core Lesson Cards (.cm-box) */
.cm-box {
  background: #fff;
  border: 1.5px solid #e2e8f0;
  border-radius: 18px;
  padding: 22px 26px;
  margin: 22px 0;
  box-shadow: 0 6px 20px rgba(14, 31, 56, .04);
  position: relative;
  transition: transform .15s ease, box-shadow .15s ease;
}

.cm-box:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 24px rgba(14, 31, 56, .06);
}

/* Category Accent Borders */
.cm-box-def {
  border-left: 6px solid #ff6a38 !important;
}

.cm-box-prop {
  border-left: 6px solid #0e1f38 !important;
}

.cm-box-theoreme {
  border-left: 6px solid #d97706 !important;
  background: #fffdfa;
}

.cm-box-formule {
  border-left: 6px solid #f59e0b !important;
  background: #fffefb;
}

.cm-box-methode {
  border-left: 6px solid #3b82f6 !important;
  background: #fafcff;
}

.cm-box-remarque {
  border-left: 6px solid #64748b !important;
  background: #f8fafc;
}

.cm-box-exemple {
  border-left: 6px solid #10b981 !important;
  background: #f0fdf4;
}

/* Tag Pills inside Cards */
.cm-box-tag {
  display: inline-block;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .06em;
  text-transform: uppercase;
  padding: 4px 10px;
  border-radius: 999px;
  margin-bottom: 10px;
  line-height: 1.2;
}

.cm-box-tag.tag-orange {
  background: rgba(255, 106, 56, .12);
  color: #ff6a38;
  border: 1px solid rgba(255, 106, 56, .25);
}

.cm-box-tag.tag-navy {
  background: #0e1f38;
  color: #fff;
}

.cm-box-tag.tag-yellow {
  background: #fef3c7;
  color: #92400e;
  border: 1px solid #fde68a;
}

.cm-box-tag.tag-blue {
  background: #eff6ff;
  color: #1d4ed8;
  border: 1px solid #bfdbfe;
}

.cm-box-tag.tag-green {
  background: #ecfdf5;
  color: #047857;
  border: 1px solid #a7f3d0;
}

.cm-box-tag.tag-purple {
  background: #f5f3ff;
  color: #6d28d9;
  border: 1px solid #ddd6fe;
}

/* Box Headings & Content */
.cm-box h4 {
  font-family: 'Baloo 2', sans-serif;
  font-size: 19px;
  font-weight: 800;
  color: #0e1f38;
  margin: 0 0 10px;
  line-height: 1.3;
}

.cm-box-content {
  font-size: 15.5px;
  line-height: 1.72;
  color: #334155;
}

.cm-box-content p {
  margin: 0 0 10px;
}

.cm-box-content p:last-child {
  margin-bottom: 0;
}

/* Callout Warning & Trap Alerts */
.cm-callout-warning {
  background: #fffbeb;
  border: 1.5px solid #fde68a;
  border-radius: 16px;
  padding: 18px 24px;
  margin: 22px 0;
  box-shadow: 0 4px 14px rgba(245, 158, 11, .06);
}

.cm-callout-head {
  font-family: 'Baloo 2', sans-serif;
  font-size: 16px;
  font-weight: 800;
  color: #92400e;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.cm-callout-body {
  font-size: 14.5px;
  line-height: 1.65;
  color: #78350f;
}

.cm-callout-body p {
  margin: 0 0 8px;
}

.cm-callout-body p:last-child {
  margin-bottom: 0;
}

/* Exercise Cards & Collapsible Solutions */
.cm-exo-card {
  background: #fff;
  border: 1.5px solid #fed7aa;
  border-radius: 20px;
  padding: 24px 28px;
  margin: 26px 0;
  box-shadow: 0 8px 24px rgba(255, 106, 56, .06);
}

.cm-exo-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}

.cm-exo-header h3 {
  font-family: 'Baloo 2', sans-serif;
  margin: 0;
  font-size: 20px;
  font-weight: 800;
  color: #0e1f38;
}

.cm-exo-enonce {
  font-size: 15.5px;
  line-height: 1.72;
  color: #334155;
  margin-bottom: 16px;
}

.cm-exo-solution {
  margin-top: 14px;
}

.cm-exo-solution summary {
  cursor: pointer;
  font-weight: 700;
  user-select: none;
  display: inline-block;
  outline: none;
}

.cm-solution-body {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 14px;
  padding: 20px;
  margin-top: 14px;
  font-size: 15px;
  line-height: 1.7;
  color: #1e293b;
}

/* Lists in LaTeX */
.cm-latex-list {
  padding-left: 24px;
  margin: 14px 0;
}

.cm-latex-list li {
  margin: 6px 0;
  line-height: 1.65;
  color: #334155;
}

.cm-latex-list .cm-sub-bullet {
  margin: 4px 0;
  line-height: 1.6;
}

/* Code styling inside lessons, boxes and exercises */
.cm-lesson-body code,
.cm-box-content code,
.cm-exo-card code {
  font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 0.88em;
  background: #f1f5f9;
  color: #0f172a;
  padding: 2.5px 6.5px;
  border-radius: 6px;
  border: 1px solid #e2e8f0;
}

.cm-exo-enonce p,
.cm-solution-body p {
  margin: 0 0 10px;
}

.cm-exo-enonce p:last-child,
.cm-solution-body p:last-child {
  margin-bottom: 0;
}

/* Objectifs Step Grid in Lessons */
.cm-objectifs-section {
  background: #fff;
  border: 1.5px solid #eee8df;
  border-radius: 22px;
  padding: 28px 32px;
  margin: 28px 0;
  box-shadow: 0 6px 20px rgba(14, 31, 56, .03);
}

.cm-objectifs-section .kicker {
  font-size: 11.5px;
  font-weight: 800;
  color: #ff6a38;
  letter-spacing: .08em;
  margin-bottom: 6px;
}

.cm-objectifs-section h2 {
  font-family: 'Baloo 2', sans-serif;
  font-size: 24px;
  font-weight: 800;
  color: #0e1f38;
  margin: 0 0 20px;
}

.cm-objectifs-section .cm-step-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px;
}

.cm-objectifs-section .cm-step-grid article {
  background: #faf6f0;
  border: 1px solid #eee8df;
  border-radius: 16px;
  padding: 18px 20px;
}

.cm-objectifs-section .step-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #ff6a38;
  color: #fff;
  font-weight: 800;
  font-size: 13px;
  padding: 4px 10px;
  border-radius: 8px;
  margin-bottom: 10px;
}

.cm-objectifs-section .cm-step-grid h3 {
  font-family: 'Baloo 2', sans-serif;
  font-size: 18px;
  font-weight: 800;
  color: #0e1f38;
  margin: 0 0 6px;
}

.cm-objectifs-section .cm-step-grid p {
  font-size: 14px;
  color: #55637a;
  line-height: 1.55;
  margin: 0;
}

/* Math Formulas & KaTeX Wrapping on Mobile */
.cm-math-display,
.entry-content .katex-display {
  display: block !important;
  text-align: center !important;
  margin: 18px 0 !important;
  overflow-x: visible !important;
}

.entry-content .katex-display > .katex {
  display: block !important;
  text-align: center !important;
  white-space: normal !important;
}

.entry-content .katex-display > .katex > .katex-html {
  display: flex !important;
  flex-wrap: wrap !important;
  justify-content: center !important;
  align-items: baseline !important;
  column-gap: 4px !important;
  row-gap: 8px !important;
  white-space: normal !important;
}

.entry-content .katex-display .base {
  display: inline-flex !important;
  align-items: baseline !important;
  white-space: nowrap !important;
}

.cm-math-inline {
  display: inline-block;
}

/* ==========================================================================
   Mobile Optimization (Reduced Padding & Margins on Mobile Devices)
   ========================================================================== */
@media (max-width: 640px) {
  /* 1. Outer Container fits screen width with clean minimal gutter */
  .cm-template,
  .cm-template--lesson,
  .cm-template--hub,
  .cm-template--service,
  .cm-template--standard {
    width: calc(100% - 16px) !important;
    max-width: 100% !important;
    margin: 14px auto 40px !important;
    padding: 0 !important;
  }

  /* 2. Title & Introduction Hero Box */
  .cm-template .cm-page-hero,
  .cm-template .cm-math-hub-hero,
  .cm-template .cm-service-hero,
  .cm-template .cm-lesson-hero,
  .cm-template .cm-resource-hero,
  .cm-template .cm-hero-panel {
    padding: 20px 14px 18px 14px !important;
    border-radius: 18px !important;
    margin: 0 0 18px !important;
  }

  .cm-template .cm-page-hero .kicker,
  .cm-template .cm-math-hub-hero .kicker,
  .cm-template .cm-eyebrow,
  .cm-template-kicker {
    font-size: 11px !important;
    letter-spacing: .06em !important;
    margin-bottom: 6px !important;
  }

  .cm-template .cm-page-hero h2,
  .cm-template .cm-math-hub-hero h2,
  .cm-template .cm-service-hero h2,
  .cm-template .cm-lesson-hero h2,
  .cm-template .cm-resource-hero h2,
  .cm-template .cm-hero-panel h2 {
    font-size: clamp(22px, 5.8vw, 29px) !important;
    line-height: 1.18 !important;
    margin: 6px 0 10px !important;
  }

  .cm-template .cm-page-hero .sub,
  .cm-template .cm-math-hub-hero .sub {
    font-size: 14.5px !important;
    line-height: 1.55 !important;
    margin: 0 0 16px !important;
  }

  .cm-template .cm-page-hero .cm-home-actions,
  .cm-template .cm-math-hub-hero .cm-home-actions {
    display: flex !important;
    flex-direction: column !important;
    gap: 10px !important;
    width: 100% !important;
    margin: 16px 0 4px !important;
  }

  .cm-template .cm-page-hero .cm-home-actions .btn,
  .cm-template .cm-math-hub-hero .cm-home-actions .btn {
    width: 100% !important;
    min-height: 46px !important;
    padding: 12px 16px !important;
    font-size: 15px !important;
    text-align: center !important;
    justify-content: center !important;
    margin: 0 !important;
    box-sizing: border-box !important;
  }

  /* 3. Interactive Sommaire / Table of Contents */
  .cm-lesson-toc {
    padding: 15px 12px !important;
    border-radius: 16px !important;
    margin: 16px 0 22px !important;
  }

  .cm-toc-header {
    font-size: 16.5px !important;
    padding-bottom: 9px !important;
    margin-bottom: 11px !important;
  }

  .cm-toc-item {
    font-size: 14px !important;
    margin: 6px 0 !important;
  }

  .cm-toc-sub {
    margin-left: 14px !important;
    font-size: 13px !important;
  }

  /* 4. Objectifs Section ("Ce que l'élève doit maîtriser") */
  .cm-objectifs-section {
    padding: 18px 12px !important;
    border-radius: 16px !important;
    margin: 18px 0 !important;
  }

  .cm-objectifs-section h2 {
    font-size: 20px !important;
    margin: 0 0 12px !important;
  }

  .cm-objectifs-section .cm-step-grid {
    gap: 10px !important;
  }

  .cm-objectifs-section .cm-step-grid article {
    padding: 13px 11px !important;
    border-radius: 12px !important;
  }

  .cm-objectifs-section .cm-step-grid h3 {
    font-size: 16px !important;
  }

  .cm-objectifs-section .cm-step-grid p {
    font-size: 13.5px !important;
  }

  /* 5. Core Lesson Content Boxes (.cm-box) */
  .cm-box {
    padding: 14px 12px 14px 12px !important;
    border-left-width: 4px !important;
    border-radius: 14px !important;
    margin: 15px 0 !important;
  }

  .cm-box h4 {
    font-size: 17px !important;
    margin: 0 0 8px !important;
    line-height: 1.28 !important;
  }

  .cm-box-content {
    font-size: 14.5px !important;
    line-height: 1.62 !important;
  }

  .cm-box-tag {
    font-size: 10.5px !important;
    padding: 3px 8px !important;
    margin-bottom: 8px !important;
  }

  /* 6. Warnings & Callouts */
  .cm-callout-warning {
    padding: 13px 12px !important;
    border-radius: 13px !important;
    margin: 15px 0 !important;
  }

  .cm-callout-head {
    font-size: 14.5px !important;
    margin-bottom: 6px !important;
  }

  .cm-callout-body {
    font-size: 13.5px !important;
    line-height: 1.55 !important;
  }

  /* 7. Exercise Cards & Solution */
  .cm-exo-card {
    padding: 15px 12px !important;
    border-radius: 15px !important;
    margin: 16px 0 !important;
  }

  .cm-exo-header {
    margin-bottom: 10px !important;
    gap: 8px !important;
  }

  .cm-exo-header h3 {
    font-size: 17px !important;
  }

  .cm-exo-enonce {
    font-size: 14.5px !important;
    line-height: 1.6 !important;
    margin-bottom: 12px !important;
  }

  .cm-solution-body {
    padding: 12px 10px !important;
    border-radius: 10px !important;
    font-size: 13.5px !important;
    margin-top: 10px !important;
  }

  /* 8. Headings outside boxes */
  .cm-lesson-chapter {
    margin-top: 22px !important;
    padding-top: 16px !important;
  }

  .cm-chapter-title {
    font-size: 20px !important;
    margin: 0 0 12px !important;
    line-height: 1.28 !important;
  }

  .cm-subchapter-title {
    font-size: 17px !important;
    margin: 18px 0 10px !important;
    line-height: 1.28 !important;
  }

  /* 9. Hub & Portal Cards */
  .grade-card,
  .cm-resource-card,
  .cm-service-card,
  .tutoring-plan-card {
    padding: 16px 14px !important;
    border-radius: 16px !important;
  }

  /* 10. Bottom CTA */
  .cm-template .cm-final-cta,
  .cm-standard-final-cta {
    padding: 20px 14px !important;
    border-radius: 16px !important;
    margin: 24px 0 16px !important;
  }

  .cm-template .cm-final-cta h2,
  .cm-standard-final-cta h2 {
    font-size: 20px !important;
  }
}

/* Extra small mobile screens (<= 380px) */
@media (max-width: 380px) {
  .cm-template,
  .cm-template--lesson {
    width: calc(100% - 12px) !important;
  }

  .cm-template .cm-page-hero,
  .cm-template .cm-math-hub-hero,
  .cm-template .cm-service-hero,
  .cm-template .cm-lesson-hero,
  .cm-template .cm-resource-hero,
  .cm-template .cm-hero-panel {
    padding: 18px 10px 16px 10px !important;
    border-radius: 14px !important;
  }

  .cm-box {
    padding: 12px 10px 12px 10px !important;
    border-left-width: 3.5px !important;
    border-radius: 12px !important;
  }

  .cm-lesson-toc,
  .cm-objectifs-section,
  .cm-exo-card {
    padding: 12px 10px !important;
    border-radius: 12px !important;
  }
}

