/* ============================================================
   MonMiniLab — Module JavaScript
   ============================================================ */

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

:root {
  --navy:   #09183a;
  --navy2:  #122050;
  --blue:   #0052e0;
  --blue2:  #3b82f6;
  --green:  #16a34a;
  --amber:  #d97706;
  --js:     #f59e0b;
  --js2:    #fbbf24;
  --js-bg:  #fffbeb;
  --purple: #7c3aed;
  --white:  #ffffff;
  --off:    #f4f6fb;
  --text:   #1a2744;
  --muted:  #6b7a99;
  --border: #dde3f0;
  --code-bg: #0f1c3f;
  --sidebar-w: 280px;
}

html { scroll-behavior: smooth; }
body {
  font-family: 'IBM Plex Sans', sans-serif;
  background: var(--white); color: var(--text);
  overflow-x: hidden; font-size: 16px; line-height: 1.6;
}

/* ---- NAV ---- */
nav:not(.lesson-nav) {
  position: sticky; top: 0; z-index: 200;
  background: var(--navy); padding: 0 2.5rem; height: 60px;
  display: flex; align-items: center; justify-content: space-between;
}
.nav-brand {
  display: flex; align-items: center; gap: 0.6rem;
  color: var(--white); text-decoration: none;
  font-weight: 800; font-size: 1.1rem; letter-spacing: -0.01em;
}
.nav-pip {
  width: 28px; height: 28px; border-radius: 7px;
  background: rgba(255,255,255,0.12);
  display: flex; align-items: center; justify-content: center; font-size: 0.9rem;
}
.nav-breadcrumb {
  display: flex; align-items: center; gap: 0.5rem;
  font-size: 0.78rem; color: rgba(255,255,255,0.45);
}
.nav-breadcrumb a { color: rgba(255,255,255,0.45); text-decoration: none; transition: color 0.15s; }
.nav-breadcrumb a:hover { color: rgba(255,255,255,0.8); }
.nav-breadcrumb span { color: rgba(255,255,255,0.2); }
.nav-breadcrumb strong { color: rgba(255,255,255,0.75); }
.nav-right { display: flex; align-items: center; gap: 1.5rem; }
.nav-link { color: rgba(255,255,255,0.55); font-size: 0.82rem; text-decoration: none; transition: color 0.15s; }
.nav-link:hover { color: var(--white); }

/* ---- LAYOUT ---- */
.layout { display: grid; grid-template-columns: var(--sidebar-w) 1fr; min-height: calc(100vh - 60px); }

/* ---- SIDEBAR ---- */
.sidebar {
  position: sticky; top: 60px; height: calc(100vh - 60px);
  overflow-y: auto; border-right: 1px solid var(--border);
  background: var(--off); padding: 1.5rem 0 3rem;
}
.sidebar::-webkit-scrollbar { width: 3px; }
.sidebar::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }
.sidebar-title {
  font-family: 'IBM Plex Mono', monospace; font-size: 0.65rem;
  color: var(--muted); letter-spacing: 0.1em; text-transform: uppercase;
  padding: 0 1.25rem; margin-bottom: 1rem;
}
.sidebar-overview { padding: 0 0 0.75rem; border-bottom: 1px solid var(--border); margin-bottom: 0.5rem; }
.chapter-label {
  font-size: 0.65rem; font-weight: 700; color: var(--muted);
  letter-spacing: 0.08em; text-transform: uppercase; padding: 0.75rem 1.25rem 0.25rem;
}
.lesson-link {
  display: flex; align-items: center; gap: 0.65rem;
  padding: 0.42rem 1.25rem; font-size: 0.81rem; color: var(--text);
  text-decoration: none; transition: background 0.12s, color 0.12s;
  border-left: 2px solid transparent; line-height: 1.35;
}
.lesson-link:hover { background: rgba(245,158,11,0.08); color: var(--amber); }
.lesson-link.active { background: rgba(245,158,11,0.1); color: var(--amber); border-left-color: var(--js); font-weight: 600; }
.lesson-link.overview { font-weight: 600; color: var(--navy); }
.lesson-link.overview.active { border-left-color: var(--js); color: var(--amber); }
.lesson-dot { width: 6px; height: 6px; border-radius: 50%; flex-shrink: 0; background: var(--border); transition: background 0.12s; margin-top: 1px; }
.lesson-link:hover .lesson-dot, .lesson-link.active .lesson-dot { background: var(--js); }
.lesson-link.overview .lesson-dot { background: var(--navy); }
.lesson-link.overview.active .lesson-dot { background: var(--js); }

/* ---- MAIN ---- */
.main { padding: 3rem 4rem 6rem; }

/* ---- INDEX ---- */
.module-tag {
  display: inline-flex; align-items: center; gap: 0.5rem;
  font-family: 'IBM Plex Mono', monospace; font-size: 0.72rem;
  color: var(--amber); background: var(--js-bg); border-radius: 4px;
  padding: 0.3rem 0.7rem; margin-bottom: 1.5rem; letter-spacing: 0.04em;
}
.module-tag::before { content: ''; width: 5px; height: 5px; border-radius: 50%; background: var(--js); }

h1 {
  font-family: 'IBM Plex Sans', sans-serif; font-weight: 800;
  font-size: clamp(1.9rem, 3vw, 2.7rem); color: var(--navy);
  letter-spacing: -0.03em; line-height: 1.08; margin-bottom: 1.1rem;
}
h1 span { color: var(--amber); }
.module-desc { font-size: 1rem; line-height: 1.75; color: var(--muted); max-width: 560px; margin-bottom: 1.75rem; }
.module-meta { display: flex; gap: 1.75rem; flex-wrap: wrap; margin-bottom: 2rem; font-size: 0.83rem; color: var(--muted); }
.meta-item { display: flex; align-items: center; gap: 0.4rem; }
.meta-val { color: var(--text); font-weight: 500; }

.btn-primary {
  display: inline-block; background: var(--js); color: var(--navy);
  font-weight: 700; font-size: 0.9rem; padding: 0.7rem 1.6rem;
  border-radius: 8px; text-decoration: none; transition: background 0.15s, transform 0.1s;
}
.btn-primary:hover { background: var(--js2); transform: translateY(-1px); }

.divider { border: none; border-top: 1px solid var(--border); margin: 2.5rem 0; }

.section-label {
  font-family: 'IBM Plex Mono', monospace; font-size: 0.72rem;
  color: var(--amber); letter-spacing: 0.08em; text-transform: uppercase; margin-bottom: 0.6rem;
}

h2 { font-family: 'IBM Plex Sans', sans-serif; font-weight: 700; font-size: 1.2rem; color: var(--navy); margin-bottom: 1rem; letter-spacing: -0.015em; }

.obj-list { list-style: none; display: flex; flex-direction: column; gap: 0.5rem; margin-bottom: 2.5rem; }
.obj-list li { display: flex; align-items: flex-start; gap: 0.6rem; font-size: 0.9rem; color: var(--text); line-height: 1.55; }
.obj-list li::before { content: '✓'; color: var(--green); font-weight: 700; font-size: 0.85rem; flex-shrink: 0; margin-top: 0.1rem; }

.prereq-box { background: var(--off); border: 1px solid var(--border); border-radius: 10px; padding: 1.25rem 1.5rem; margin-bottom: 2.5rem; }
.prereq-box p { font-size: 0.88rem; color: var(--muted); line-height: 1.7; }
.prereq-box strong { color: var(--text); }

.chapters-list { display: flex; flex-direction: column; gap: 1rem; }
.chapter-card { border: 1px solid var(--border); border-radius: 12px; overflow: hidden; }
.chapter-header { background: var(--off); padding: 0.9rem 1.25rem; display: flex; align-items: center; gap: 0.75rem; border-bottom: 1px solid var(--border); }
.chapter-num { width: 30px; height: 30px; border-radius: 50%; flex-shrink: 0; background: var(--js); color: var(--navy); font-weight: 800; font-size: 0.8rem; display: flex; align-items: center; justify-content: center; }
.chapter-header h3 { font-size: 0.93rem; font-weight: 700; color: var(--navy); letter-spacing: -0.01em; }
.chapter-lessons { list-style: none; }
.chapter-lesson { display: flex; align-items: center; justify-content: space-between; padding: 0.72rem 1.25rem; border-bottom: 1px solid var(--border); gap: 0.75rem; }
.chapter-lesson:last-child { border-bottom: none; }
.lesson-left { display: flex; align-items: center; gap: 0.65rem; }
.lesson-num { font-family: 'IBM Plex Mono', monospace; font-size: 0.68rem; color: var(--muted); width: 26px; text-align: right; flex-shrink: 0; }
.lesson-name { font-size: 0.86rem; color: var(--text); text-decoration: none; transition: color 0.12s; }
.lesson-name:hover { color: var(--amber); }
.lesson-badge { font-family: 'IBM Plex Mono', monospace; font-size: 0.65rem; color: var(--muted); background: var(--off); border: 1px solid var(--border); border-radius: 3px; padding: 0.1rem 0.45rem; white-space: nowrap; flex-shrink: 0; }

/* ---- LESSON content ---- */
.lesson-header { margin-bottom: 2.5rem; }
.lesson-tag {
  display: inline-flex; align-items: center; gap: 0.5rem;
  font-family: 'IBM Plex Mono', monospace; font-size: 0.72rem;
  color: var(--muted); border: 1px solid var(--border); border-radius: 4px;
  padding: 0.25rem 0.65rem; margin-bottom: 1.25rem; letter-spacing: 0.04em;
}
.lesson-content h2 { font-size: 1.35rem; font-weight: 700; color: var(--navy); letter-spacing: -0.02em; margin-top: 2.5rem; margin-bottom: 0.75rem; line-height: 1.25; }
.lesson-content h2:first-child { margin-top: 0; }
.lesson-content h3 { font-size: 1rem; font-weight: 700; color: var(--navy); margin-top: 1.75rem; margin-bottom: 0.5rem; }
.lesson-content p { font-size: 0.95rem; line-height: 1.8; color: var(--text); margin-bottom: 1rem; }
.lesson-content ul, .lesson-content ol { font-size: 0.95rem; line-height: 1.8; color: var(--text); padding-left: 1.5rem; margin-bottom: 1rem; }
.lesson-content li { margin-bottom: 0.25rem; }
.lesson-content strong { font-weight: 700; color: var(--navy); }

.lesson-content code {
  font-family: 'IBM Plex Mono', monospace; font-size: 0.82em;
  background: var(--js-bg); color: var(--amber); border-radius: 3px; padding: 0.1em 0.35em;
}

/* ---- CODE BLOCK ---- */
.code-block { background: var(--code-bg); border-radius: 10px; overflow: hidden; margin: 1.5rem 0; font-family: 'IBM Plex Mono', monospace; }
.code-block-header { display: flex; align-items: center; justify-content: space-between; padding: 0.6rem 1rem; border-bottom: 1px solid rgba(255,255,255,0.08); }
.code-dots { display: flex; gap: 0.4rem; }
.code-dot { width: 10px; height: 10px; border-radius: 50%; }
.code-dot.r { background: #ff5f57; }
.code-dot.y { background: #febc2e; }
.code-dot.g { background: #28c840; }
.code-lang { font-family: 'IBM Plex Mono', monospace; font-size: 0.65rem; color: rgba(255,255,255,0.3); letter-spacing: 0.08em; text-transform: uppercase; }
.code-block pre { padding: 1.25rem; margin: 0; overflow-x: auto; font-size: 0.85rem; line-height: 1.7; }
.code-block code { background: none; color: rgba(255,255,255,0.85); padding: 0; font-size: inherit; border-radius: 0; }

/* JavaScript Syntax highlighting */
.hl-kw     { color: #569cd6; }            /* let, const, function, if, return... — bleu */
.hl-str    { color: #ce9178; }            /* "chaîne" — orange */
.hl-num    { color: #b5cea8; }            /* 42, 3.14 — vert clair */
.hl-fn     { color: #dcdcaa; }            /* nomDeFonction() — jaune */
.hl-comment { color: rgba(255,255,255,0.3); font-style: italic; }
.hl-prop   { color: #9cdcfe; }            /* .propriété — bleu clair */
.hl-bool   { color: #569cd6; }            /* true, false — bleu */
.hl-tag    { color: #79b8ff; }            /* balises HTML dans strings */
.hl-method { color: #dcdcaa; }            /* .méthode() — jaune */
.hl-dom    { color: #4ec9b0; }            /* document, window — cyan */

/* ---- OUTPUT BLOCK ---- */
.output-block { border: 1px solid var(--border); border-radius: 10px; overflow: hidden; margin: 0.5rem 0 1.5rem; }
.output-block-header {
  background: var(--off); padding: 0.5rem 1rem;
  display: flex; align-items: center; gap: 0.5rem;
  border-bottom: 1px solid var(--border);
  font-family: 'IBM Plex Mono', monospace; font-size: 0.65rem;
  color: var(--muted); letter-spacing: 0.08em; text-transform: uppercase;
}
.output-block-header::before { content: '▶'; color: var(--green); font-size: 0.55rem; }
.output-block pre { padding: 1rem 1.25rem; font-family: 'IBM Plex Mono', monospace; font-size: 0.85rem; line-height: 1.7; color: var(--text); margin: 0; white-space: pre-wrap; background: white; }

/* ---- INFO BOX ---- */
.info-box {
  display: flex; gap: 0.85rem; align-items: flex-start;
  background: var(--js-bg); border-left: 3px solid var(--js);
  border-radius: 0 8px 8px 0; padding: 1rem 1.25rem; margin: 1.5rem 0;
}
.info-box.tip { background: #f0fdf4; border-left-color: var(--green); }
.info-box.warn { background: #fffbeb; border-left-color: var(--amber); }
.info-box.danger { background: #fff1f2; border-left-color: #e11d48; }
.info-icon { font-size: 1rem; flex-shrink: 0; margin-top: 0.05rem; }
.info-box p { font-size: 0.88rem; line-height: 1.65; color: var(--text); margin: 0; }
.info-box strong { color: var(--navy); }

/* ---- À RETENIR ---- */
.retenir { background: var(--off); border: 1px solid var(--border); border-radius: 12px; padding: 1.5rem; margin: 2rem 0; }
.retenir-title { font-family: 'IBM Plex Mono', monospace; font-size: 0.68rem; color: var(--amber); letter-spacing: 0.08em; text-transform: uppercase; margin-bottom: 0.75rem; }
.retenir ul { list-style: none; padding: 0; display: flex; flex-direction: column; gap: 0.4rem; }
.retenir li { display: flex; align-items: flex-start; gap: 0.6rem; font-size: 0.88rem; line-height: 1.6; }
.retenir li::before { content: '→'; color: var(--amber); font-weight: 700; flex-shrink: 0; }

/* ---- JS PLAYGROUND ---- */
.js-playground {
  border: 2px solid var(--js); border-radius: 12px;
  overflow: hidden; margin: 2rem 0;
  box-shadow: 0 4px 20px rgba(245,158,11,0.15);
}
.playground-header {
  background: var(--navy); padding: 0.75rem 1rem;
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem;
}
.playground-title {
  font-family: 'IBM Plex Mono', monospace; font-size: 0.65rem;
  color: rgba(255,255,255,0.4); letter-spacing: 0.1em; text-transform: uppercase;
  display: flex; align-items: center; gap: 0.5rem;
}
.playground-title::before { content: '⚡'; font-size: 0.75rem; }
.playground-run {
  background: var(--js); color: var(--navy); border: none;
  font-family: 'IBM Plex Sans', sans-serif; font-size: 0.82rem; font-weight: 700;
  padding: 0.45rem 1.1rem; border-radius: 6px; cursor: pointer;
  transition: background 0.15s, transform 0.1s; flex-shrink: 0;
}
.playground-run:hover { background: var(--js2); transform: translateY(-1px); }
.playground-run:active { transform: translateY(0); }
.playground-reset {
  background: transparent; color: rgba(255,255,255,0.35); border: 1px solid rgba(255,255,255,0.15);
  font-family: 'IBM Plex Sans', sans-serif; font-size: 0.78rem; font-weight: 500;
  padding: 0.4rem 0.9rem; border-radius: 6px; cursor: pointer;
  transition: color 0.15s, border-color 0.15s; flex-shrink: 0;
}
.playground-reset:hover { color: rgba(255,255,255,0.7); border-color: rgba(255,255,255,0.35); }
.playground-btns { display: flex; align-items: center; gap: 0.5rem; }
.playground-editor {
  font-family: 'IBM Plex Mono', monospace; font-size: 0.85rem; line-height: 1.7;
  color: rgba(255,255,255,0.88); background: #0a1628;
  border: none; outline: none; width: 100%; display: block;
  padding: 1.25rem; resize: vertical; min-height: 120px;
  tab-size: 2;
}
.playground-editor:focus { background: #0c1d34; }
.playground-output-wrap {
  border-top: 1px solid rgba(255,255,255,0.07);
  background: white;
}
.playground-output-header {
  padding: 0.5rem 1rem; background: var(--off);
  border-bottom: 1px solid var(--border);
  font-family: 'IBM Plex Mono', monospace; font-size: 0.65rem;
  color: var(--muted); letter-spacing: 0.08em; text-transform: uppercase;
  display: flex; align-items: center; gap: 0.5rem;
}
.playground-output-header::before { content: '▶'; color: var(--green); font-size: 0.55rem; }
.playground-output {
  padding: 1rem 1.25rem; font-family: 'IBM Plex Mono', monospace; font-size: 0.84rem;
  line-height: 1.7; min-height: 60px; white-space: pre-wrap; color: var(--text);
}
.playground-output.empty { color: var(--muted); font-style: italic; }
.playground-output.error { color: #dc2626; }
.playground-output .log-line { display: block; }
.playground-output .log-line.warn-line { color: var(--amber); }
.playground-output .log-line.error-line { color: #dc2626; }

/* ---- LESSON NAV ---- */
.lesson-nav { display: flex; justify-content: space-between; align-items: center; margin-top: 3.5rem; padding-top: 2rem; border-top: 1px solid var(--border); gap: 1rem; }
.lesson-nav a { display: flex; align-items: center; gap: 0.5rem; font-size: 0.85rem; font-weight: 600; color: var(--navy); text-decoration: none; padding: 0.6rem 1rem; border: 1.5px solid var(--border); border-radius: 8px; transition: border-color 0.15s, background 0.15s; }
.lesson-nav a:not(.next):hover { border-color: var(--navy); background: var(--off); }
.lesson-nav a.next { background: var(--js); color: var(--navy); border-color: var(--js); }
.lesson-nav a.next:hover { background: var(--js2); border-color: var(--js2); }
.lesson-nav .empty { flex: 1; }

/* ---- FOOTER ---- */
footer { background: var(--navy); border-top: 1px solid rgba(255,255,255,0.07); padding: 1.5rem 2.5rem; display: flex; align-items: center; justify-content: space-between; }
.footer-brand { color: rgba(255,255,255,0.4); font-size: 0.8rem; }
.footer-brand strong { color: rgba(255,255,255,0.7); }
.footer-links { display: flex; gap: 1.5rem; }
footer a { color: rgba(255,255,255,0.4); font-size: 0.8rem; text-decoration: none; transition: color 0.15s; }
footer a:hover { color: var(--white); }

/* ---- RESPONSIVE ---- */
@media (max-width: 768px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .main { padding: 2rem 1.25rem 4rem; }
  nav { padding: 0 1rem; }
  .nav-breadcrumb { display: none; }
  footer { flex-direction: column; gap: 0.5rem; text-align: center; padding: 1.25rem 1rem; }
  .lesson-nav { flex-direction: column; }
  .lesson-nav a { width: 100%; justify-content: center; }
}
