:root {
  --bg: #fff8ef;
  --ink: #2d2a4a;
  --muted: #6b6889;
  --card: #ffffff;
  --brand: #ff7a3d;
  --brand-dark: #e85d1f;
  --accent: #6c5ce7;
  --ok: #10ac84;
  --line: #f0e3d3;
  --radius: 16px;
}

* { box-sizing: border-box; }
/* Un élément caché reste caché, même si une autre règle lui donne un display. */
[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: "Nunito", system-ui, sans-serif;
  background: var(--bg);
  color: var(--ink);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding: 10px 20px;
  background: var(--card);
  border-bottom: 3px solid var(--line);
}

.brand { font-weight: 800; font-size: 22px; display: flex; align-items: center; gap: 10px; color: var(--ink); text-decoration: none; }

.crumbs { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; font-weight: 700; font-size: 14px; color: var(--muted); }
.crumbs a { color: var(--accent); text-decoration: none; }
.crumbs a:hover { text-decoration: underline; }
.crumbs .sep { opacity: .5; }

.view[hidden] { display: none; }
.page { max-width: 1100px; margin: 0 auto; padding: 24px 16px 48px; }
.hero h1 { margin: 0 0 6px; font-size: 32px; }
.hero p { margin: 0; color: var(--muted); font-size: 17px; }
.eyebrow { font-weight: 800; color: var(--brand) !important; text-transform: uppercase; font-size: 13px !important; letter-spacing: .04em; margin-bottom: 4px !important; }

.module { margin-top: 28px; }
.module h2 { font-size: 20px; margin: 0 0 12px; }
.lessons { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; }
.lesson-card {
  display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; align-items: center;
  padding: 14px; background: var(--card); border-radius: 14px; border: 3px solid var(--line);
  color: var(--ink); text-decoration: none; font-weight: 700;
}
a.lesson-card:hover { border-color: var(--brand); }
.lesson-card .num {
  grid-row: span 2; width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center;
  background: #fff1e8; color: var(--brand); font-weight: 800;
}
.lesson-card.soon { opacity: .6; }
.lesson-card .tag { font-size: 12px; color: var(--muted); }

.bar { display: block; height: 8px; background: #f1ecff; border-radius: 99px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--ok); border-radius: 99px; }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; margin-top: 24px; }
.activity-card {
  display: flex; flex-direction: column; gap: 8px; padding: 20px;
  background: var(--card); border-radius: var(--radius); border: 3px solid var(--line);
  color: var(--ink); text-decoration: none;
}
.activity-card:hover { border-color: var(--brand); transform: translateY(-2px); }
.activity-card .icon { font-size: 40px; }
.activity-card strong { font-size: 19px; }
.activity-card span { color: var(--muted); }
.activity-card small { color: var(--muted); font-weight: 700; }

.game-bar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 10px 16px 0;
}
.game-bar strong { font-size: 18px; }

.quiz { margin-top: 24px; background: var(--card); border-radius: var(--radius); padding: 24px; max-width: 720px; }
.question { font-size: 22px; font-weight: 800; margin: 0 0 16px; }
.choices { display: grid; gap: 10px; }
.choice {
  font: inherit; font-size: 17px; font-weight: 700; text-align: left;
  padding: 14px 16px; border-radius: 12px; border: 3px solid var(--line); background: #fff; color: var(--ink); cursor: pointer;
}
.choice:hover:not(:disabled) { border-color: var(--accent); }
.choice.right { border-color: var(--ok); background: #e6f8f2; }
.choice.wrong { border-color: #ff4757; background: #ffecee; }
.choice:disabled { cursor: default; }
.feedback { margin: 16px 0 0; padding: 12px; border-radius: 10px; background: #fff7d6; }
.quiz .next { margin-top: 16px; }
.quiz-result { text-align: center; }
a.btn { text-decoration: none; display: inline-block; }
.logo {
  display: inline-grid; place-items: center;
  width: 36px; height: 36px; border-radius: 12px;
  background: var(--brand); color: #fff;
}

.level-map { display: flex; gap: 8px; flex-wrap: wrap; }
.level-btn {
  width: 52px; height: 52px; border-radius: 14px;
  border: 3px solid var(--line); background: var(--card);
  font: inherit; font-weight: 800; font-size: 18px; color: var(--ink);
  cursor: pointer; display: flex; flex-direction: column; align-items: center; justify-content: center;
  line-height: 1;
}
.level-btn small { font-size: 10px; letter-spacing: -1px; margin-top: 3px; }
.level-btn.current { border-color: var(--brand); background: #fff1e8; }
.level-btn.done { border-color: var(--ok); }
.level-btn:disabled { opacity: .45; cursor: not-allowed; }

.layout {
  display: grid;
  grid-template-columns: minmax(320px, 500px) 1fr;
  gap: 16px;
  padding: 16px;
  height: calc(100vh - 140px);
  min-height: 560px;
}

.stage {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px;
  display: flex; flex-direction: column; gap: 10px;
  overflow: auto;
}
.mission h1 { margin: 0 0 4px; font-size: 22px; }
.mission p { margin: 0; color: var(--muted); font-size: 16px; }

#scene {
  width: 100%;
  aspect-ratio: 1;
  border-radius: 12px;
  background: #4fb3e8;
}

.controls { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.btn {
  font: inherit; font-weight: 800; font-size: 16px;
  padding: 10px 16px; border-radius: 12px;
  border: 0; background: #f1ecff; color: var(--accent);
  cursor: pointer;
}
.btn:hover { filter: brightness(.96); }
.btn.go { background: var(--brand); color: #fff; box-shadow: 0 4px 0 var(--brand-dark); }
.btn:disabled { opacity: .5; cursor: wait; }
.btn.check { background: var(--ok); color: #fff; box-shadow: 0 4px 0 #0b8a69; }
.btn[hidden] { display: none; }
.speed { display: flex; align-items: center; gap: 6px; font-size: 14px; color: var(--muted); margin-left: auto; }

.hint { margin: 0; padding: 10px 12px; background: #fff7d6; border-radius: 10px; }
.counter { margin: 0; font-size: 14px; color: var(--muted); }

.editor { background: var(--card); border-radius: var(--radius); overflow: hidden; position: relative; }
#blockly, #studioBlockly { position: absolute; inset: 0; }

.studio-scene { width: 100%; aspect-ratio: 4 / 3; border-radius: 12px; background: #9fd8ff; }
.stage-info { display: flex; justify-content: space-between; font-size: 14px; color: var(--muted); font-weight: 700; }
.stage-info label { display: flex; gap: 6px; align-items: center; cursor: pointer; }
.scene-wrap { position: relative; }
.ask-box { position: absolute; left: 8px; right: 8px; bottom: 8px; margin: 0; }
#askBox { background: #fff; border-radius: 12px; padding: 10px 12px; box-shadow: 0 6px 20px rgba(0,0,0,.18); }
#askQuestion { font-weight: 800; display: block; margin-bottom: 6px; }
.ask-row { display: flex; gap: 8px; }
.ask-row input { flex: 1; font: inherit; font-size: 16px; padding: 8px 10px; border-radius: 10px; border: 2px solid var(--line); }
.studio-scene:fullscreen { width: 100vw; height: 100vh; object-fit: contain; background: #000; border-radius: 0; }

.project-panel { display: flex; flex-direction: column; gap: 10px; padding-top: 6px; border-top: 2px solid var(--line); }
.project-panel h3 { margin: 4px 0 0; font-size: 16px; }
.project-panel .decor { display: flex; gap: 8px; align-items: center; font-weight: 700; }
.project-panel select, .project-panel textarea {
  font: inherit; padding: 6px 8px; border-radius: 8px; border: 2px solid var(--line); background: #fff; color: var(--ink);
}
.project-panel details { background: #fff7d6; border-radius: 10px; padding: 8px 12px; }
.project-panel summary { font-weight: 800; cursor: pointer; }
.project-panel details label { display: flex; flex-direction: column; gap: 4px; margin-top: 8px; font-size: 14px; font-weight: 700; }
.checklist { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.checklist li { padding: 6px 10px; border-radius: 8px; background: #f7f5ff; font-size: 14px; }
.checklist li.ok { background: #e6f8f2; }

.modal {
  position: fixed; inset: 0; background: rgba(45, 42, 74, .45);
  display: grid; place-items: center; z-index: 100; padding: 16px;
}
.modal[hidden] { display: none; }
.modal-card {
  background: var(--card); border-radius: 20px; padding: 28px;
  max-width: 420px; width: 100%; text-align: center;
  box-shadow: 0 20px 60px rgba(0,0,0,.2);
}
.modal-card h2 { margin: 6px 0; }
.modal-card p { color: var(--muted); }
.stars { font-size: 40px; letter-spacing: 6px; }
.stars .off { filter: grayscale(1); opacity: .3; }
.modal-actions { display: flex; gap: 10px; justify-content: center; margin-top: 16px; }

@media (max-width: 820px) {
  .layout { grid-template-columns: 1fr; height: auto; }
  .editor { height: 460px; }
  .speed { margin-left: 0; }
}
