/* =========================================================================
   Minecraft Education — lesson-page chrome
   Loaded by app/_components/MinecraftLessonView.tsx, which renders every
   lesson from a `minecraft_lessons` row. Accent colour is driven by a
   per-section class on the page root (.level--m1 = MakeCode, .level--m2 =
   Command Block), so a single stylesheet styles both. Mirrors
   public/godot/godot_styles.css — the `.lesson-*` chrome is deliberately
   identical so an author moving between courses writes the same markup.

   The class names still say `level--m1/m2` rather than `section--`: they were
   named when the sections were folders, renaming them buys nothing, and every
   piece of visible copy says "Section" already.
   ========================================================================= */

.lesson-page {
  --accent:       #5FA845;   /* Section 1 grass green — overridden below */
  --accent-deep:  #4A8535;
  --accent-soft:  #F1F8EE;
  --accent-edge:  #CBE3BF;
  --ink:          #0F172A;
  --muted:        #64748B;
  --border:       #E2E8F0;

  color: var(--ink);
  background: #fff;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Section accents */
.level--m1 { --accent: #5FA845; --accent-deep: #4A8535; --accent-soft: #F1F8EE; --accent-edge: #CBE3BF; }
.level--m2 { --accent: #C8792B; --accent-deep: #A4611F; --accent-soft: #FDF6EE; --accent-edge: #F0D9BC; }
/* Section 3 · Game Basis — diamond blue */
.level--m3 { --accent: #2A93B0; --accent-deep: #1F7189; --accent-soft: #EEF8FB; --accent-edge: #BFE3EC; }

/* ---------- hero ---------- */

.lesson-hero {
  background: linear-gradient(135deg, var(--accent-soft) 0%, #fff 100%);
  border-bottom: 1px solid var(--border);
  padding: 32px 24px 36px;
}
.lesson-hero__inner { max-width: 820px; margin: 0 auto; }
.lesson-hero__crumbs { font-size: 0.85rem; color: var(--muted); margin: 0 0 16px; }
.lesson-hero__crumbs a { color: var(--accent-deep); text-decoration: none; }
.lesson-hero__crumbs a:hover { text-decoration: underline; }
.lesson-hero__crumbs .sep { margin: 0 8px; color: var(--accent-edge); }
.lesson-hero__crumbs .here { color: var(--ink); font-weight: 600; }

.lesson-hero__num {
  display: inline-block;
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  color: var(--accent-deep);
  background: #fff;
  border: 1px solid var(--accent-edge);
  border-radius: 999px;
  padding: 4px 12px;
}
.lesson-hero__title {
  margin: 12px 0 8px;
  font-size: 2.4rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.15;
}
.lesson-hero__sub {
  margin: 0 0 16px;
  font-size: 1.05rem;
  color: #334155;
  max-width: 620px;
  line-height: 1.55;
}
.lesson-hero__meta { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.lesson-hero__meta-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 12px;
}

/* ---------- body shell ---------- */

.lesson-body {
  flex: 1;
  max-width: 820px;
  width: 100%;
  margin: 0 auto;
  padding: 32px 24px 64px;
  display: grid;
  gap: 28px;
}

.lesson-section {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 16px;
  overflow: hidden;
}
.lesson-section__head {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px 22px;
  background: var(--accent-soft);
  border-bottom: 1px solid var(--accent-edge);
}
.lesson-section__num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  font-weight: 800;
  font-size: 0.85rem;
  color: #fff;
  background: var(--accent-deep);
  border-radius: 50%;
  flex-shrink: 0;
}
.lesson-section__title {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 800;
  flex: 1;
  min-width: 0;
}
.lesson-section__time {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--accent-deep);
  background: #fff;
  border: 1px solid var(--accent-edge);
  border-radius: 6px;
  padding: 3px 10px;
  white-space: nowrap;
}

.lesson-section__body { padding: 22px; line-height: 1.65; color: #1E293B; }
.lesson-section__body > * + * { margin-top: 14px; }
.lesson-section__body p { margin: 0; }
.lesson-section__body h3 {
  margin: 22px 0 10px;
  font-size: 1.02rem;
  font-weight: 700;
  color: var(--ink);
}
.lesson-section__body h4 {
  margin: 14px 0 6px;
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--ink);
}
.lesson-section__body ul,
.lesson-section__body ol { margin: 0; padding-left: 22px; display: grid; gap: 6px; }
.lesson-section__body li { line-height: 1.55; }
.lesson-section__body strong { color: var(--ink); }
.lesson-section__body a {
  color: var(--accent-deep);
  text-decoration: underline;
  text-underline-offset: 2px;
}
.lesson-section__body code {
  font-family: "JetBrains Mono", "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.88em;
  background: #F1F5F9;
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 1px 6px;
}
.lesson-section__body kbd {
  font-family: "JetBrains Mono", "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.82em;
  background: #fff;
  border: 1px solid #94A3B8;
  border-bottom-width: 2px;
  border-radius: 5px;
  padding: 1px 7px;
  color: #334155;
}
.lesson-section__body details {
  background: #F8FAFC;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 16px;
}
.lesson-section__body details > summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--accent-deep);
}
.lesson-section__body details[open] > summary { margin-bottom: 10px; }

.lesson-section--homework .lesson-section__head {
  background: linear-gradient(135deg, var(--accent-soft) 0%, #fff 100%);
}

/* ---------- MakeCode block stack (Section 1's "sample code") -------------
   MakeCode code is blocks, so a Minecraft lesson shows a stack of coloured
   pills rather than a wall of text. Mirrors Scratch's .block-stack / .blk:

     <div class="mc-stack">
       <span class="mcb mcb--player mcb--hat">on chat command "run"</span>
       <span class="mcb mcb--agent">agent teleport to player</span>
       <div class="mc-stack__nest">
         <span class="mcb mcb--loops">repeat 4 times</span>
       </div>
     </div>

   ⚠️ Colours: the core MakeCode (PXT) categories below — Loops, Logic,
   Variables, Math, Functions — are the real toolbox values and are shared with
   micro:bit. The Minecraft-only categories (Player, Agent, Blocks, Mobs,
   Gameplay, Positions) are close approximations; if a class notices a mismatch
   with minecraft.makecode.com, correct the hex HERE and every lesson follows.
   -------------------------------------------------------------------------- */

:root {
  /* Minecraft-only toolbox categories — approximate, see note above */
  --mcb-player:    #D83B01;
  --mcb-agent:     #4C7A34;
  --mcb-blocks:    #8A5A2B;
  --mcb-mobs:      #B4009E;
  --mcb-gameplay:  #0078D7;
  --mcb-positions: #00A5A5;
  /* Core MakeCode categories — real PXT values */
  --mcb-loops:     #107C10;
  --mcb-logic:     #006970;
  --mcb-variables: #A80000;
  --mcb-math:      #5C2D91;
  --mcb-functions: #005A9E;
}

.mc-stack {
  background: #F8FAF6;
  border: 1px solid var(--accent-edge);
  border-left: 4px solid var(--accent);
  border-radius: 10px;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
}
/* Blocks dropped inside a loop or an if are indented, the way MakeCode nests
   them. Nest divs can contain further nest divs. */
.mc-stack__nest {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  margin-left: 18px;
  padding-left: 10px;
  border-left: 3px solid var(--accent-edge);
  align-self: stretch;
}
.mcb {
  display: inline-block;
  padding: 6px 14px;
  border-radius: 6px;
  color: #fff;
  font-weight: 600;
  font-size: 0.9rem;
  line-height: 1.35;
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.18);
}
/* A hat block starts a program — rounded top, like the real thing. */
.mcb--hat { border-top-left-radius: 16px; border-top-right-radius: 16px; }

.mcb--player    { background: var(--mcb-player); }
.mcb--agent     { background: var(--mcb-agent); }
.mcb--blocks    { background: var(--mcb-blocks); }
.mcb--mobs      { background: var(--mcb-mobs); }
.mcb--gameplay  { background: var(--mcb-gameplay); }
.mcb--positions { background: var(--mcb-positions); }
.mcb--loops     { background: var(--mcb-loops); }
.mcb--logic     { background: var(--mcb-logic); }
.mcb--variables { background: var(--mcb-variables); }
.mcb--math      { background: var(--mcb-math); }
.mcb--functions { background: var(--mcb-functions); }
/* Unknown or missing category. A typo in the dashboard costs a colour, never
   the page — see app/_components/minecraft/MakeCodeBlocks.tsx. */
.mcb--neutral   { background: #64748B; }

/* A block named mid-sentence: "drag the <span class='mcb-inline …'>…</span>". */
.mcb-inline {
  display: inline-block;
  vertical-align: baseline;
  padding: 1px 8px;
  border-radius: 5px;
  color: #fff;
  font-weight: 600;
  font-size: 0.85em;
}

/* ---------- Minecraft custom widgets ---------- */

/* A command typed into the chat box, or a command-block command (Section 2). */
.mc-cmd {
  background: #0F172A;
  color: #E2E8F0;
  border-radius: 10px;
  padding: 12px 16px;
  font-family: "JetBrains Mono", "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.88rem;
  line-height: 1.6;
  overflow-x: auto;
  white-space: pre;
}
.mc-cmd code { background: transparent; border: 0; padding: 0; font-size: inherit; color: inherit; }
.mc-cmd--output { background: #0B1020; color: #86EFAC; }

/* Numbered in-game steps ("click Play, then Create New…"). */
.mc-steps {
  background: #F8FAFC;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px 20px 16px 38px !important;
}
.mc-steps li::marker { color: var(--accent-deep); font-weight: 800; }

/* Keyboard / mouse controls, as a wrapped row of chips. */
.mc-keys {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  list-style: none !important;
  padding-left: 0 !important;
}
.mc-keys > li {
  background: var(--accent-soft);
  border: 1px solid var(--accent-edge);
  color: var(--accent-deep);
  border-radius: 8px;
  padding: 6px 12px;
  font-weight: 600;
  font-size: 0.85rem;
}

/* World-settings / property rows — label (left), value (right). */
.mc-settings {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}
.mc-settings__row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 14px;
  border-top: 1px solid var(--border);
  font-size: 0.88rem;
}
.mc-settings__row:first-child { border-top: 0; }
.mc-settings__row > span:first-child { color: var(--muted); font-weight: 600; }
.mc-settings__row > span:last-child {
  font-family: "JetBrains Mono", "SF Mono", Menlo, Consolas, monospace;
  color: var(--ink);
}

/* Challenge cards — one per Challenge 1 / 2 / 3. */
.mc-tasks {
  display: grid;
  gap: 14px;
  list-style: none !important;
  padding-left: 0 !important;
}
.mc-tasks > li {
  background: #F8FAFC;
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: 10px;
  padding: 14px 16px;
}
.mc-tasks > li h4 { margin: 0 0 6px; color: var(--accent-deep); }
.mc-tasks > li ul { padding-left: 22px; }

/* "It works if…" success criterion — every challenge gets one, so a student
   can mark their own work without asking. */
.mc-works {
  background: var(--accent-soft);
  border: 1px solid var(--accent-edge);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 0.9rem;
}

/* Two-up comparison card. */
.mc-twocol { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.mc-twocol__item {
  background: #F8FAFC;
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: 10px;
  padding: 14px 16px;
}
.mc-twocol__item h4 { margin: 0 0 6px; color: var(--accent-deep); }
.mc-twocol__item p { margin: 6px 0 0; }
@media (max-width: 620px) { .mc-twocol { grid-template-columns: 1fr; } }

/* Answer reveal inside a challenge. */
.mc-answer {
  background: var(--accent-soft) !important;
  border-color: var(--accent-edge) !important;
}

/* Recap list. */
.mc-recap {
  background: var(--accent-soft);
  border: 1px solid var(--accent-edge);
  border-radius: 10px;
  padding: 14px 20px 14px 38px !important;
  display: grid;
  gap: 8px;
}
.mc-recap li::marker { color: var(--accent-deep); font-weight: 800; }

/* Figure — inline SVG sketch or screenshot. */
.mc-figure {
  background: #F8FAFC;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  text-align: center;
  margin: 0;
}
.mc-figure svg,
.mc-figure img { max-width: 100%; height: auto; border-radius: 6px; }
.mc-figure figcaption { margin-top: 10px; font-size: 0.85rem; color: var(--muted); }

/* ---------- screenshots ----------
   Every prose section of a DB-driven lesson can carry several images (the
   toolbox drawer, the block stack, the result in the world). One image fills
   the column; two or more share a responsive grid so a lesson does not become
   a vertical mile of screenshots. */
.mc-shots {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 12px;
}
.mc-shots--single { grid-template-columns: 1fr; }
.mc-shots img {
  width: 100%;
  height: auto;
  display: block;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #F8FAFC;
}

/* ---------- password-gated answer download ----------
   Adapted from public/arduino/lesson.css. The component holds no answers: it
   posts a password and the server replies with a finished PDF. */
.answer-dl {
  border: 1px solid var(--accent-edge);
  border-left: 5px solid var(--accent);
  border-radius: 12px;
  background: #fff;
  padding: 18px 22px;
}
.answer-dl__head { display: flex; gap: 12px; align-items: flex-start; margin-bottom: 14px; }
.answer-dl__icon { font-size: 1.3rem; line-height: 1.2; }
.answer-dl__note { margin: 2px 0 0; color: var(--muted); font-size: 0.88rem; }
.answer-dl__row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.answer-dl__label {
  font-size: 0.78rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.05em; color: var(--accent-deep);
}
.answer-dl__input {
  flex: 1 1 200px;
  min-width: 0;
  padding: 10px 14px;
  border: 1px solid #CBD5E1;
  border-radius: 8px;
  font: inherit;
  font-size: 0.95rem;
}
.answer-dl__input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(95, 168, 69, 0.18);
}
.answer-dl__btn {
  padding: 10px 20px;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}
.answer-dl__btn:hover:not(:disabled) { background: var(--accent-deep); }
.answer-dl__btn:disabled { opacity: 0.55; cursor: not-allowed; }
.answer-dl__error { margin: 12px 0 0; color: #B91C1C; font-size: 0.9rem; font-weight: 600; }
.answer-dl__ok { margin: 12px 0 0; color: #047857; font-size: 0.9rem; font-weight: 600; }

/* ---------- markdown body ----------
   LessonMarkdown wraps authored content in .lesson-md. The section body rules
   above style headings, lists, code and tables already; these are the bits a
   markdown body adds that a hand-written section did not have. */
.lesson-md > * + * { margin-top: 14px; }
.lesson-md table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}
.lesson-md th,
.lesson-md td {
  border: 1px solid var(--border);
  padding: 8px 12px;
  text-align: left;
  vertical-align: top;
}
.lesson-md th { background: var(--accent-soft); font-weight: 700; }
.lesson-md pre {
  background: #0F172A;
  color: #E2E8F0;
  border-radius: 10px;
  padding: 14px 18px;
  overflow-x: auto;
  font-size: 0.88rem;
  line-height: 1.6;
}
.lesson-md pre code { background: transparent; border: 0; padding: 0; color: inherit; }
.lesson-md blockquote {
  margin: 0;
  padding: 10px 16px;
  border-left: 4px solid var(--accent-edge);
  background: var(--accent-soft);
  border-radius: 0 8px 8px 0;
}
.lesson-md__error { color: #B91C1C; font-weight: 600; }

/* "Coming soon" — a seeded slot with no content yet. */
.mc-empty {
  background: var(--accent-soft);
  border: 1px dashed var(--accent-edge);
  border-radius: 12px;
  padding: 18px 22px;
  color: var(--muted);
}

/* Prev / next lesson nav. */
.lesson-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 12px;
  padding-top: 24px;
  border-top: 1px solid var(--border);
  font-size: 0.92rem;
  font-weight: 600;
}
.lesson-nav__prev { color: var(--muted); }
.lesson-nav__next {
  color: var(--accent-deep);
  text-decoration: none;
  padding: 8px 16px;
  background: var(--accent-soft);
  border: 1px solid var(--accent-edge);
  border-radius: 8px;
}
.lesson-nav__next:hover { background: var(--accent-edge); }
/* Not-yet-authored next lesson: plain text, never a link that 404s. */
.lesson-nav__next--pending {
  color: var(--muted);
  background: #F8FAFC;
  border-color: var(--border);
}

/* mobile tweaks */
@media (max-width: 720px) {
  .lesson-hero { padding: 28px 18px 30px; }
  .lesson-hero__title { font-size: 1.85rem; }
  .lesson-body { padding: 24px 18px 56px; }
  .lesson-section__head { padding: 14px 16px; }
  .lesson-section__body { padding: 18px; }
}
