:root {
  --bg: #0d0d14;
  --surface: #161622;
  --surface-2: #1f1f2e;
  --surface-3: #2a2a3d;
  --border: #2c2c40;
  --text: #ececf4;
  --muted: #9a9ab3;
  --accent: #7c5cff;
  --accent-2: #a48bff;
  --ok: #2ec27e;
  --radius: 14px;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { font: 15px/1.55 "Segoe UI", system-ui, -apple-system, Roboto, sans-serif; min-height: 100vh; }
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; cursor: pointer; }

/* ---------- Barre du haut ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20; height: 60px;
  display: flex; align-items: center; gap: 20px; padding: 0 20px;
  background: rgba(13,13,20,.88); backdrop-filter: blur(10px); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; white-space: nowrap; }
.logo { width: 32px; height: 32px; border-radius: 9px; background: linear-gradient(135deg, var(--accent), #ff5c9d); display: grid; place-items: center; color: #fff; }
.logo svg { width: 22px; height: 22px; }
.crumbs { flex: 1; min-width: 0; display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 14px; overflow: hidden; white-space: nowrap; }
.crumbs a:hover { color: var(--text); }
.crumbs .sep { opacity: .5; }
.crumbs span:last-child { overflow: hidden; text-overflow: ellipsis; color: var(--text); }
.search-wrap { position: relative; width: 300px; max-width: 40vw; }
#search { width: 100%; padding: 9px 14px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); color: var(--text); outline: none; }
#search:focus { border-color: var(--accent); }
.search-results { position: absolute; right: 0; top: 46px; width: 460px; max-width: 90vw; max-height: 70vh; overflow: auto; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: 0 20px 50px rgba(0,0,0,.5); padding: 6px; }
.search-results a { display: block; padding: 8px 12px; border-radius: 8px; }
.search-results a:hover, .search-results a.active { background: var(--surface-3); }
.search-results small { display: block; color: var(--muted); font-size: 12px; }
.search-results .empty { padding: 12px; color: var(--muted); }

main { min-height: calc(100vh - 60px); }
.loading { padding: 80px; text-align: center; color: var(--muted); }

/* ---------- Catalogue ---------- */
.hero { padding: 56px 24px 24px; max-width: 1200px; margin: 0 auto; }
.hero h1 { font-size: 38px; margin: 0 0 6px; letter-spacing: -.5px; }
.hero p { color: var(--muted); margin: 0; font-size: 17px; }
.stats { display: flex; gap: 12px; margin-top: 22px; flex-wrap: wrap; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 10px 16px; }
.stat b { font-size: 20px; display: block; }
.stat span { color: var(--muted); font-size: 13px; }
.section-title { max-width: 1200px; margin: 26px auto 0; padding: 0 24px; font-size: 20px; }
.grid { max-width: 1200px; margin: 0 auto; padding: 16px 24px 60px; display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 22px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; transition: transform .18s, border-color .18s, box-shadow .18s; display: flex; flex-direction: column; }
.card:hover { transform: translateY(-4px); border-color: var(--c1); box-shadow: 0 16px 40px -12px var(--c1); }
.card-cover { height: 150px; position: relative; background: linear-gradient(135deg, var(--c1), var(--c2)); display: grid; place-items: center; overflow: hidden; }
.card-cover::after { content: ""; position: absolute; inset: 0; background: radial-gradient(circle at 80% 10%, rgba(255,255,255,.25), transparent 50%); }
.card-cover .mono { font-size: 64px; font-weight: 800; color: rgba(255,255,255,.95); letter-spacing: -2px; text-shadow: 0 6px 24px rgba(0,0,0,.25); z-index: 1; }
.card-body { padding: 18px; flex: 1; display: flex; flex-direction: column; gap: 10px; }
.card-body h3 { margin: 0; font-size: 19px; }
.meta { display: flex; gap: 14px; color: var(--muted); font-size: 13px; flex-wrap: wrap; }
.progress { height: 6px; background: var(--surface-3); border-radius: 99px; overflow: hidden; }
.progress > i { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); border-radius: 99px; transition: width .3s; }
.progress-label { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); }
.card-body .spacer { flex: 1; }

/* ---------- Page formation ---------- */
.course-hero { background: linear-gradient(135deg, var(--c1), var(--c2)); position: relative; }
.course-hero::before { content: ""; position: absolute; inset: 0; background: linear-gradient(180deg, rgba(13,13,20,.15), rgba(13,13,20,.85)); }
.course-hero-inner { position: relative; max-width: 1000px; margin: 0 auto; padding: 56px 24px 36px; }
.course-hero h1 { font-size: 42px; margin: 0 0 10px; }
.course-hero .meta { color: rgba(255,255,255,.85); font-size: 15px; }
.course-hero .actions { margin-top: 24px; display: flex; gap: 14px; align-items: center; flex-wrap: wrap; }
.course-hero .progress { max-width: 340px; flex: 1; background: rgba(255,255,255,.2); }
.btn { display: inline-flex; align-items: center; gap: 8px; padding: 11px 20px; border-radius: 999px; border: 1px solid transparent; background: var(--accent); color: #fff; font-weight: 600; transition: filter .15s, background .15s; }
.btn:hover { filter: brightness(1.12); }
.btn.ghost { background: var(--surface-2); border-color: var(--border); color: var(--text); }
.btn.ghost:hover { background: var(--surface-3); }
.btn.ok { background: var(--ok); }
.btn.small { padding: 7px 14px; font-size: 14px; }
.btn[disabled] { opacity: .4; pointer-events: none; }

.chapters { max-width: 1000px; margin: 0 auto; padding: 28px 24px 70px; display: flex; flex-direction: column; gap: 12px; }
.chapter { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.chapter > summary { list-style: none; cursor: pointer; padding: 16px 20px; display: flex; align-items: center; gap: 14px; }
.chapter > summary::-webkit-details-marker { display: none; }
.chapter > summary:hover { background: var(--surface-2); }
.ch-num { width: 38px; height: 38px; flex: none; border-radius: 10px; background: var(--surface-3); display: grid; place-items: center; font-weight: 700; color: var(--accent-2); }
.ch-num.done { background: var(--ok); color: #fff; }
.ch-title { flex: 1; min-width: 0; }
.ch-title b { display: block; }
.ch-title small { color: var(--muted); }
.chev { transition: transform .2s; color: var(--muted); }
.chapter[open] .chev { transform: rotate(90deg); }
.lesson-list { border-top: 1px solid var(--border); }
.lesson-row { display: flex; align-items: center; gap: 12px; padding: 11px 20px 11px 72px; border-bottom: 1px solid rgba(255,255,255,.03); }
.lesson-row:hover { background: var(--surface-2); }
.lesson-row .lt { flex: 1; min-width: 0; }
.lesson-row .dur { color: var(--muted); font-size: 13px; white-space: nowrap; }
.check { width: 20px; height: 20px; flex: none; border-radius: 50%; border: 2px solid var(--surface-3); display: grid; place-items: center; }
.check.done { background: var(--ok); border-color: var(--ok); }
.check.done::after { content: ""; width: 5px; height: 9px; border: solid #fff; border-width: 0 2px 2px 0; transform: rotate(45deg) translate(-1px,-1px); }
.icons { display: flex; gap: 6px; color: var(--muted); }
.icons svg { width: 16px; height: 16px; }

/* ---------- Lecteur ---------- */
.learn { display: grid; grid-template-columns: 340px 1fr; height: calc(100vh - 60px); }
.sidebar { border-right: 1px solid var(--border); background: var(--surface); overflow-y: auto; }
.sidebar-head { padding: 16px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--surface); z-index: 1; }
.sidebar-head b { display: block; margin-bottom: 8px; }
.side-ch > summary { list-style: none; cursor: pointer; padding: 12px 16px; font-weight: 600; font-size: 14px; display: flex; gap: 10px; align-items: flex-start; border-bottom: 1px solid var(--border); }
.side-ch > summary::-webkit-details-marker { display: none; }
.side-ch > summary small { display: block; color: var(--muted); font-weight: 400; }
.side-ch > summary:hover { background: var(--surface-2); }
.side-ch .chev { margin-left: auto; margin-top: 2px; }
.side-ch[open] .chev { transform: rotate(90deg); }
.side-lesson { display: flex; gap: 10px; align-items: center; padding: 9px 16px 9px 22px; font-size: 14px; color: var(--muted); border-left: 3px solid transparent; }
.side-lesson:hover { background: var(--surface-2); color: var(--text); }
.side-lesson.active { background: rgba(124,92,255,.13); border-left-color: var(--accent); color: var(--text); }
.side-lesson .lt { flex: 1; min-width: 0; }
.side-lesson .dur { font-size: 12px; }
.check.sm { width: 16px; height: 16px; }
.check.sm.done::after { width: 4px; height: 7px; }

.stage { overflow-y: auto; }
.player-wrap { background: #000; }
.player-wrap video { display: block; width: 100%; max-height: 72vh; background: #000; margin: 0 auto; }
.no-video { padding: 60px; text-align: center; color: var(--muted); background: var(--surface); }
.lesson-head { max-width: 960px; margin: 0 auto; padding: 22px 28px 0; display: flex; gap: 16px; align-items: flex-start; flex-wrap: wrap; }
.lesson-head h1 { flex: 1; min-width: 240px; margin: 0; font-size: 26px; }
.lesson-head .eyebrow { color: var(--accent-2); font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: .6px; margin-bottom: 4px; }
.toolbar { max-width: 960px; margin: 0 auto; padding: 14px 28px; display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.speed { display: inline-flex; background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; padding: 3px; }
.speed button { border: 0; background: none; padding: 5px 10px; border-radius: 999px; font-size: 13px; color: var(--muted); }
.speed button.on { background: var(--accent); color: #fff; }
.toggle { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); font-size: 14px; cursor: pointer; user-select: none; }
.toolbar .grow { flex: 1; }
.tabs { max-width: 960px; margin: 6px auto 0; padding: 0 28px; display: flex; gap: 4px; border-bottom: 1px solid var(--border); }
.tabs button { background: none; border: 0; padding: 12px 16px; color: var(--muted); font-weight: 600; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs button.on { color: var(--text); border-bottom-color: var(--accent); }
.tab-body { max-width: 960px; margin: 0 auto; padding: 24px 28px 80px; }
.attach { display: flex; align-items: center; gap: 12px; padding: 12px 16px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; margin-bottom: 10px; }
.attach:hover { border-color: var(--accent); }
.muted { color: var(--muted); }
.attach .btn { flex: none; }
.card-cover .logo-img { width: 92px; height: 92px; border-radius: 20px; z-index: 1; box-shadow: 0 10px 30px rgba(0,0,0,.35); }
.course-title { display: flex; align-items: center; gap: 18px; }
.course-title img { width: 72px; height: 72px; border-radius: 16px; box-shadow: 0 10px 30px rgba(0,0,0,.35); }
.course-title h1 { margin: 0; }
.course-desc { font-size: 17px; color: rgba(255,255,255,.9); margin: 14px 0 10px; max-width: 640px; }
.toc { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 14px 18px; margin-bottom: 26px; display: flex; flex-direction: column; gap: 2px; font-size: 14px; }
.toc b { margin-bottom: 6px; }
.toc a { color: var(--muted); cursor: pointer; padding: 2px 0; }
.toc a:hover { color: var(--accent-2); }
.toc .lvl-h4 { padding-left: 16px; }
.lesson-text h3, .lesson-text h4 { scroll-margin-top: 20px; }
.lesson-text .course-image-zoom { display: inline-block; }

/* Contenu texte importé des cours */
.lesson-text { line-height: 1.75; font-size: 16px; }
.lesson-text h1, .lesson-text h2, .lesson-text h3, .lesson-text h4 { line-height: 1.3; margin: 1.8em 0 .6em; }
.lesson-text h3 { font-size: 22px; } .lesson-text h4 { font-size: 18px; color: var(--accent-2); }
.lesson-text > :first-child { margin-top: 0; }
.lesson-text a { color: var(--accent-2); text-decoration: underline; }
.lesson-text img { max-width: 100%; border-radius: 10px; }
.lesson-text :not(pre) > code { background: var(--surface-3); padding: 2px 6px; border-radius: 6px; font-size: .88em; color: #ffcb6b; }
.lesson-text pre { padding: 16px 18px; border-radius: 12px; overflow-x: auto; font-size: 14px; line-height: 1.6; margin: 0; }
.lesson-text .code-container { margin: 1em 0; position: relative; }
.lesson-text .code-container .copy { position: absolute; top: 8px; right: 8px; background: rgba(255,255,255,.1); border: 0; border-radius: 6px; padding: 4px 10px; font-size: 12px; opacity: 0; transition: opacity .15s; }
.lesson-text .code-container:hover .copy { opacity: 1; }
.lesson-text table { border-collapse: collapse; width: 100%; margin: 1em 0; }
.lesson-text th, .lesson-text td { border: 1px solid var(--border); padding: 8px 12px; text-align: left; }
.lesson-text th { background: var(--surface-2); }
.lesson-text blockquote { margin: 1em 0; padding: 10px 18px; border-left: 4px solid var(--accent); background: var(--surface); border-radius: 0 10px 10px 0; }
.lesson-text ul, .lesson-text ol { padding-left: 1.4em; }

.nav-btns { display: flex; justify-content: space-between; gap: 12px; margin-top: 40px; padding-top: 20px; border-top: 1px solid var(--border); }
.nav-btns a { max-width: 48%; }
.nav-btns small { display: block; color: var(--muted); font-size: 12px; font-weight: 400; }
.menu-btn { display: none; }

/* ---------- Comptes ---------- */
body.logged-out .crumbs, body.logged-out .search-wrap { visibility: hidden; }
.auth-box { max-width: 400px; margin: 9vh auto; padding: 36px 32px; background: var(--surface); border: 1px solid var(--border); border-radius: 18px; text-align: center; }
.auth-box h1 { margin: 16px 0 4px; }
.logo.big { width: 56px; height: 56px; border-radius: 16px; margin: 0 auto; }
.logo.big svg { width: 36px; height: 36px; }
form label { display: flex; flex-direction: column; gap: 6px; text-align: left; font-size: 14px; color: var(--muted); margin-bottom: 14px; }
form input, form select, .users select { padding: 10px 12px; border-radius: 10px; border: 1px solid var(--border); background: var(--bg); color: var(--text); font: inherit; outline: none; }
form input:focus, form select:focus { border-color: var(--accent); }
.auth-box form { margin-top: 24px; }
.auth-box .btn { width: 100%; justify-content: center; }
.form-error { color: #ff6b6b; min-height: 1em; margin: 4px 0 12px; font-size: 14px; }
.form-ok { color: var(--ok); min-height: 1em; margin: 4px 0 12px; font-size: 14px; }
.user-menu { position: relative; }
.user-btn { display: flex; align-items: center; gap: 8px; background: none; border: 1px solid var(--border); border-radius: 999px; padding: 4px 12px 4px 4px; }
.user-btn:hover { background: var(--surface-2); }
.avatar { width: 30px; height: 30px; border-radius: 50%; background: linear-gradient(135deg, var(--accent), #ff5c9d); display: grid; place-items: center; font-weight: 700; color: #fff; }
.user-drop { position: absolute; right: 0; top: 46px; min-width: 210px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 6px; box-shadow: 0 20px 50px rgba(0,0,0,.5); }
.user-drop a { display: block; padding: 9px 12px; border-radius: 8px; }
.user-drop a:hover { background: var(--surface-3); }
.page-narrow { max-width: 980px; margin: 0 auto; padding: 36px 24px 80px; }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px 22px; margin-top: 20px; }
.panel h3 { margin: 0 0 16px; }
.panel .row { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 0 14px; }
.users { width: 100%; border-collapse: collapse; font-size: 14px; }
.users th, .users td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.users th { color: var(--muted); font-weight: 600; }
.users .acts { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.btn.danger { color: #ff6b6b; }
.panel { overflow-x: auto; }

@media (max-width: 900px) {
  .uname { display: none; }
  .user-btn { padding: 4px; }
  .learn { grid-template-columns: 1fr; height: auto; }
  .sidebar { position: fixed; inset: 60px auto 0 0; width: 320px; max-width: 88vw; z-index: 15; transform: translateX(-100%); transition: transform .2s; box-shadow: 0 0 40px rgba(0,0,0,.6); }
  .sidebar.open { transform: none; }
  .menu-btn { display: inline-flex; }
  .search-wrap { width: 160px; }
  .crumbs { display: none; }
  .lesson-row { padding-left: 20px; }
  .hero h1, .course-hero h1 { font-size: 30px; }
}
