:root {
  --blue: #2F6BFF;
  --blue-deep: #1D4ED8;
  --sun: #FFD23F;
  --coral: #FF6B5B;
  --paper: #FAFAF7;
  --ink: #14213D;
  --ink-soft: #4A5578;
  --line: rgba(20, 33, 61, .12);
  --glass: rgba(255, 255, 255, .78);
  --radius: 22px;
  --shadow: 0 18px 50px -18px rgba(20, 33, 61, .35);
  --font-display: "Bricolage Grotesque", "Figtree", system-ui, sans-serif;
  --font-body: "Figtree", system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: var(--font-body);
  color: var(--ink);
  background: linear-gradient(180deg, #CFE3FF 0%, #FFF4D6 100%);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

/* ---------- scène 3D ---------- */
#scene { position: fixed; inset: 0; width: 100%; height: 100%; display: block; z-index: 0; }
.scene-veil { position: fixed; inset: 0; z-index: 1; pointer-events: none; background: transparent; transition: background .5s ease; }
body.in-app .scene-veil { background: rgba(250, 250, 247, .82); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); }

/* ---------- barre du haut ---------- */
.topbar {
  position: fixed; z-index: 20; top: 0; left: 0; right: 0;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(14px + env(safe-area-inset-top, 0px)) clamp(16px, 4vw, 40px) 14px;
}
.brand {
  display: inline-flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink);
  font-family: var(--font-display); font-weight: 800; font-size: 1.5rem;
  background: var(--glass); padding: 6px 16px 6px 8px; border-radius: 999px; box-shadow: var(--shadow);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
}
.topnav { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.topnav .who { background: var(--glass); padding: 8px 14px; border-radius: 999px; font-weight: 600; font-size: .9rem; backdrop-filter: blur(10px); }

/* ---------- boutons (chacun son identité) ---------- */
.btn-sun, .btn-coral, .btn-outline, .btn-blue, .btn-ghost, .btn-danger {
  border: 0; border-radius: 999px; padding: 13px 24px; font-weight: 700; font-size: 1rem;
  transition: transform .15s ease, box-shadow .15s ease, background .15s ease;
}
.btn-sun { background: var(--sun); color: var(--ink); box-shadow: 0 6px 0 #D9A900; }
.btn-sun:hover { transform: translateY(-2px); box-shadow: 0 8px 0 #D9A900; }
.btn-sun:active { transform: translateY(3px); box-shadow: 0 2px 0 #D9A900; }
.btn-coral { background: var(--coral); color: #fff; box-shadow: 0 6px 0 #D8483A; }
.btn-coral:hover { transform: translateY(-2px); box-shadow: 0 8px 0 #D8483A; }
.btn-coral:active { transform: translateY(3px); box-shadow: 0 2px 0 #D8483A; }
.btn-blue { background: var(--blue); color: #fff; box-shadow: 0 10px 24px -10px var(--blue); }
.btn-blue:hover { background: var(--blue-deep); }
.btn-outline { background: rgba(255,255,255,.6); color: var(--ink); box-shadow: inset 0 0 0 2.5px var(--ink); }
.btn-outline:hover { background: var(--ink); color: #fff; }
.btn-ghost { background: var(--glass); color: var(--ink); padding: 9px 16px; font-size: .92rem; backdrop-filter: blur(10px); }
.btn-ghost:hover { background: #fff; }
.btn-danger { background: transparent; color: #C62828; padding: 7px 12px; font-size: .88rem; box-shadow: inset 0 0 0 1.5px rgba(198,40,40,.4); }
.btn-danger:hover { background: #C62828; color: #fff; }
button:disabled { opacity: .55; cursor: not-allowed; transform: none !important; }
.full { width: 100%; }
.link-btn { background: none; border: 0; padding: 0; color: var(--blue); font-weight: 700; text-decoration: underline; }
:focus-visible { outline: 3px solid var(--blue); outline-offset: 3px; }

/* ---------- accueil ---------- */
#landing { position: relative; z-index: 5; }
.chapter { min-height: 100vh; display: flex; align-items: center; padding: 110px clamp(16px, 6vw, 80px) 60px; }
.chapter-hero, .chapter-final { justify-content: center; flex-direction: column; }
.chapter-left { justify-content: flex-start; }
.chapter-right { justify-content: flex-end; }
.glass {
  background: var(--glass); border-radius: var(--radius); box-shadow: var(--shadow);
  backdrop-filter: blur(14px) saturate(1.3); -webkit-backdrop-filter: blur(14px) saturate(1.3);
  border: 1px solid rgba(255,255,255,.7);
}
.hero-card { max-width: 720px; padding: clamp(24px, 5vw, 48px); text-align: center; animation: rise .8s ease both; }
.story-card { max-width: 460px; padding: clamp(22px, 4vw, 36px); }
.kicker { margin: 0 0 10px; font-weight: 700; color: var(--coral); text-transform: uppercase; letter-spacing: .08em; font-size: .82rem; }
h1, h2, h3 { font-family: var(--font-display); line-height: 1.05; margin: 0 0 14px; }
h1 { font-size: clamp(2.3rem, 6vw, 4.2rem); font-weight: 800; }
h2 { font-size: clamp(1.7rem, 4vw, 2.6rem); font-weight: 800; }
h3 { font-size: 1.25rem; font-weight: 700; }
.hl-blue { color: var(--blue); }
.lead { font-size: clamp(1.02rem, 2vw, 1.2rem); color: var(--ink-soft); line-height: 1.55; margin: 0 auto 26px; max-width: 560px; }
.story-card p { color: var(--ink-soft); line-height: 1.6; margin: 0; font-size: 1.05rem; }
.hero-actions { display: flex; gap: 14px; justify-content: center; flex-wrap: wrap; }
.scroll-hint { margin: 26px 0 0; font-size: .9rem; color: var(--ink-soft); }
.scroll-hint::after { content: "↓"; display: block; margin-top: 6px; font-size: 1.3rem; animation: bob 1.6s ease-in-out infinite; }
.small { font-size: .95rem; color: var(--ink-soft); margin: 20px 0 0; }
.tag { display: inline-block; padding: 6px 14px; border-radius: 999px; font-weight: 700; font-size: .82rem; margin-bottom: 14px; }
.tag-coral { background: var(--coral); color: #fff; }
.tag-blue { background: var(--blue); color: #fff; }
.tag-sun { background: var(--sun); color: var(--ink); }
.foot { margin-top: 40px; text-align: center; font-size: .9rem; color: var(--ink-soft); background: var(--glass); padding: 8px 16px; border-radius: 999px; }

@keyframes rise { from { transform: translateY(24px); } to { transform: none; } }
@keyframes bob { 0%,100% { transform: translateY(0); } 50% { transform: translateY(6px); } }

/* ---------- modales ---------- */
.modal {
  border: 0; border-radius: var(--radius); padding: 28px; width: min(460px, calc(100vw - 24px));
  max-height: calc(100vh - 40px); overflow: auto; box-shadow: 0 30px 80px -20px rgba(20,33,61,.5);
  background: var(--paper); color: var(--ink);
}
.modal::backdrop { background: rgba(20, 33, 61, .45); backdrop-filter: blur(3px); }
.modal-close-form { position: absolute; top: 10px; right: 12px; margin: 0; }
.icon-close { border: 0; background: transparent; font-size: 1.8rem; line-height: 1; padding: 4px 10px; border-radius: 10px; color: var(--ink-soft); }
.icon-close:hover { background: rgba(20,33,61,.08); }
.auth-tabs { display: flex; gap: 6px; background: rgba(20,33,61,.06); padding: 5px; border-radius: 999px; margin: 6px 0 20px; }
.tab { flex: 1; border: 0; background: transparent; padding: 10px; border-radius: 999px; font-weight: 700; color: var(--ink-soft); }
.tab.active { background: #fff; color: var(--ink); box-shadow: 0 4px 12px -6px rgba(20,33,61,.4); }
.form { display: flex; flex-direction: column; gap: 14px; }
.form label { display: flex; flex-direction: column; gap: 6px; font-weight: 600; font-size: .92rem; }
.form input, .form select, .form textarea, .field {
  border: 1.5px solid var(--line); border-radius: 14px; padding: 12px 14px; background: #fff; font-weight: 500; width: 100%;
}
.form input:focus, .form select:focus, .form textarea:focus, .field:focus { outline: none; border-color: var(--blue); box-shadow: 0 0 0 4px rgba(47,107,255,.15); }
.form textarea { min-height: 90px; resize: vertical; }
.form-msg { margin: 0; min-height: 1.2em; font-weight: 600; font-size: .92rem; color: #C62828; }
.form-msg.ok { color: #1B7F3B; }
.role-pick { border: 0; padding: 0; margin: 0; display: flex; gap: 10px; }
.role-pick legend { font-weight: 600; font-size: .92rem; margin-bottom: 6px; }
.role-chip { flex: 1; }
.role-chip input { position: absolute; opacity: 0; pointer-events: none; }
.role-chip span { display: block; text-align: center; padding: 12px; border-radius: 14px; border: 2px solid var(--line); font-weight: 700; background: #fff; transition: all .15s; }
.role-chip input:checked + span { border-color: var(--blue); background: rgba(47,107,255,.08); color: var(--blue); }
.role-chip input:focus-visible + span { outline: 3px solid var(--blue); outline-offset: 2px; }

.viewer { width: min(1000px, calc(100vw - 24px)); }
#viewer-body iframe { width: 100%; height: min(75vh, 900px); border: 0; border-radius: 14px; background: #eee; }
#viewer-body img, #viewer-body video { max-width: 100%; max-height: 75vh; display: block; margin: 0 auto; border-radius: 14px; }

/* ---------- espace connecté ---------- */
#app { position: relative; z-index: 5; }
.app-wrap { max-width: 1120px; margin: 0 auto; padding: calc(96px + env(safe-area-inset-top, 0px)) clamp(14px, 4vw, 32px) 60px; }
.app-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 22px; }
.app-head p { margin: 0; color: var(--ink-soft); }
.panel { background: #fff; border-radius: var(--radius); padding: clamp(18px, 3vw, 28px); box-shadow: 0 10px 30px -18px rgba(20,33,61,.35); border: 1px solid var(--line); margin-bottom: 20px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.filters { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 10px; margin-bottom: 18px; }
.courses { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.course {
  background: #fff; border-radius: 18px; padding: 18px; border: 1px solid var(--line);
  display: flex; flex-direction: column; gap: 10px; position: relative; overflow: hidden;
}
.course::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 6px; background: var(--accent, var(--blue)); }
.course h3 { margin: 0; font-size: 1.15rem; }
.course .meta { display: flex; gap: 6px; flex-wrap: wrap; }
.pill { font-size: .78rem; font-weight: 700; padding: 4px 10px; border-radius: 999px; background: rgba(47,107,255,.1); color: var(--blue-deep); }
.pill.sun { background: rgba(255,210,63,.3); color: #7A5B00; }
.pill.coral { background: rgba(255,107,91,.15); color: #B23A2E; }
.course .desc { color: var(--ink-soft); font-size: .95rem; line-height: 1.5; margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.course .by { font-size: .85rem; color: var(--ink-soft); margin: 0; }
.files { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 6px; }
.file-row { display: flex; align-items: center; gap: 8px; }
.file-open {
  flex: 1; display: flex; align-items: center; gap: 10px; text-align: left; background: var(--paper);
  border: 1px solid var(--line); border-radius: 12px; padding: 9px 12px; font-weight: 600; font-size: .9rem; min-width: 0;
}
.file-open:hover { border-color: var(--blue); background: rgba(47,107,255,.05); }
.file-open .fname { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ficon { flex: none; width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center; font-size: .7rem; font-weight: 800; color: #fff; }
.ficon.pdf { background: var(--coral); }
.ficon.image { background: var(--blue); }
.ficon.video { background: #1B998B; }
.course-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: auto; }
.empty { text-align: center; padding: 40px 20px; color: var(--ink-soft); }
.drop {
  border: 2.5px dashed rgba(47,107,255,.4); border-radius: 18px; padding: 26px; text-align: center; background: rgba(47,107,255,.04);
  transition: all .15s; cursor: pointer;
}
.drop.over { border-color: var(--blue); background: rgba(47,107,255,.1); }
.drop strong { color: var(--blue); }
.pending { list-style: none; padding: 0; margin: 10px 0 0; display: flex; flex-direction: column; gap: 6px; }
.pending li { display: flex; justify-content: space-between; gap: 8px; align-items: center; font-size: .9rem; background: var(--paper); padding: 8px 12px; border-radius: 10px; }
.pending .st { font-weight: 700; font-size: .8rem; }
.st.ok { color: #1B7F3B; } .st.err { color: #C62828; } .st.wait { color: var(--ink-soft); }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 20px; }
.stat { background: #fff; border-radius: 18px; padding: 18px; border: 1px solid var(--line); }
.stat b { display: block; font-family: var(--font-display); font-size: 2rem; }
.stat span { color: var(--ink-soft); font-size: .9rem; font-weight: 600; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { font-size: .8rem; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-soft); }
.tabs-app { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 18px; }
.tabs-app .tab { flex: none; background: rgba(255,255,255,.7); padding: 10px 18px; }
.tabs-app .tab.active { background: var(--ink); color: #fff; }

#toast {
  position: fixed; z-index: 100; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%) translateY(140%);
  background: var(--ink); color: #fff; padding: 12px 20px; border-radius: 999px; font-weight: 600; box-shadow: var(--shadow);
  transition: transform .3s ease; max-width: calc(100vw - 32px); text-align: center;
}
#toast.show { transform: translateX(-50%) translateY(0); }
#toast.err { background: #C62828; }

.spinner { width: 22px; height: 22px; border: 3px solid rgba(20,33,61,.15); border-top-color: var(--blue); border-radius: 50%; animation: spin .8s linear infinite; margin: 30px auto; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 720px) {
  .chapter { min-height: 92vh; padding-top: 100px; }
  .chapter-left, .chapter-right { justify-content: center; }
  .grid-2, .filters { grid-template-columns: 1fr; }
  .brand span { display: none; }
  .brand { padding: 6px; }
  .hero-actions button { width: 100%; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
