/* ============================================================
   EV3 Robotics lesson-page styles
   Loaded alongside the site-wide styles.css by app/ev3/level-<N>/layout.tsx.
   Mirrors the structure of scratch/lesson.css (same section IDs and
   semantic classes — .lesson-section, .task, .vocab, .callout, table.ref,
   details, .lesson-foot) so the EV3 lesson-builder skill produces lessons
   with the same pedagogical chrome. Only the palette and the EV3-specific
   block surfaces (.ev3blk pills, pre.ev3blocks, ol.build-steps,
   figure.mechanism-diagram) differ.

   EV3 Classroom is a Scratch-3 fork, so programs render as real blocks: write
   them in <pre class="ev3blocks"> and <EV3BlocksLoader> hands them to
   scratchblocks@3.6.4 (the EV3 palette is applied per block via a `:: #hex`
   colour override; the loader maps friendly names like `:: motors` to the hex).
   Put only plain block text inside that <pre> — HTML markup leaks as literal text.
   ============================================================ */

:root {
  --ev3:      #D8232A;   /* EV3 / Advaspire signature red */
  --ev3-soft: #FDE9E9;
  --ev3-dark: #9E1216;
  --ev3-ink:  #2A0608;

  /* EV3 Classroom block-category palette — matched to the official LEGO PDF
     (see EV3_Memory.md §9.1). Used by .ev3blk pills, the program left-rule
     accents, and mirrored in app/_components/EV3BlocksLoader.tsx. */
  --ev3-motors:    #0095CD;   /* Motors    — blue    */
  --ev3-movement:  #D6186F;   /* Movement  — magenta */
  --ev3-display:   #8C5BC7;   /* Display   — purple  */
  --ev3-sound:     #A95FC4;   /* Sound     — violet  */
  --ev3-events:    #FFD500;   /* Events    — yellow  */
  --ev3-control:   #FFAB19;   /* Control   — orange  */
  --ev3-sensors:   #5CB1D6;   /* Sensors   — sky     */
  --ev3-operators: #59C059;   /* Operators — green   */
  --ev3-variables: #FF8C1A;   /* Variables — orange  */
  --ev3-myblocks:  #FF6680;   /* My Blocks — red-pink*/
}

.lesson {
  font-family: 'Plus Jakarta Sans', system-ui, sans-serif;
  background: #FFFBFB;
  color: var(--ink, #0F172A);
  margin: 0;
  line-height: 1.55;
}

/* Per-level accent strip — same level-tinting as the sibling courses */
.lesson--level-1 { --lvl: #10B981; --lvl-soft: #E7FBF3; }
.lesson--level-2 { --lvl: #3B82F6; --lvl-soft: #E8F1FE; }
.lesson--level-3 { --lvl: #F59E0B; --lvl-soft: #FEF4E0; }
.lesson--level-4 { --lvl: #EC4899; --lvl-soft: #FDE8F1; }

/* ---------- Header ---------- */
.lesson-header {
  background: linear-gradient(135deg, var(--ev3) 0%, var(--ev3-dark) 100%);
  color: #fff;
  padding: 48px 32px 40px;
  border-bottom: 6px solid var(--lvl, var(--ev3));
}
.lesson-header .lesson-tag {
  display: inline-block;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  background: rgba(255,255,255,0.22);
  padding: 5px 12px;
  border-radius: 999px;
  margin-bottom: 14px;
  backdrop-filter: blur(4px);
}
.lesson-header h1 {
  font-size: clamp(1.7rem, 4vw, 2.6rem);
  font-weight: 800;
  letter-spacing: -0.02em;
  margin: 0 0 6px;
  max-width: 900px;
}
.lesson-header .lesson-sub {
  font-size: 0.95rem;
  opacity: 0.9;
  margin: 0;
}

/* ---------- Main column ---------- */
.lesson main {
  max-width: 880px;
  margin: 0 auto;
  padding: 32px 24px 80px;
}

/* ---------- Sections ---------- */
.lesson-section {
  background: #fff;
  border: 1px solid #F4D7D7;
  border-radius: 16px;
  padding: 28px 28px 24px;
  margin-bottom: 22px;
  position: relative;
  overflow: hidden;
}
.lesson-section::before {
  content: "";
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 4px;
  background: var(--lvl, var(--ev3));
}
.lesson-section h2 {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 1.25rem;
  font-weight: 800;
  letter-spacing: -0.01em;
  margin: 0 0 16px;
  color: var(--ev3-ink);
}
.lesson-section h2 .time {
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 0.7rem;
  font-weight: 600;
  background: var(--ev3-soft);
  color: var(--ev3-dark);
  padding: 3px 10px;
  border-radius: 999px;
  margin-left: auto;
}
.lesson-section h3 {
  font-size: 1.02rem;
  font-weight: 700;
  margin: 18px 0 8px;
  color: var(--ev3-ink);
}
.lesson-section p,
.lesson-section li,
.lesson-section dd { font-size: 0.95rem; }

/* ---------- Lists ---------- */
.lesson-section ul,
.lesson-section ol { padding-left: 22px; }
.lesson-section li { margin-bottom: 6px; }

/* ---------- Inline block pills (.ev3blk) — skill §5.4 ----------
   A single EV3 Classroom block named mid-sentence in prose:
     <span class="ev3blk ev3blk-motors">run motor [A v] for (2) seconds</span>
   ---------------------------------------------------------------- */
.ev3blk {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 6px;
  color: #fff;
  font-weight: 600;
  font-size: 0.84rem;
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  line-height: 1.5;
  box-shadow: 0 1px 0 rgba(0,0,0,0.15);
  white-space: nowrap;
}
.ev3blk-motors    { background: var(--ev3-motors); }
.ev3blk-movement  { background: var(--ev3-movement); }
.ev3blk-display   { background: var(--ev3-display); }
.ev3blk-sound     { background: var(--ev3-sound); }
.ev3blk-events    { background: var(--ev3-events);    color: #5A4500; }
.ev3blk-control   { background: var(--ev3-control);   color: #6B3D00; }
.ev3blk-sensors   { background: var(--ev3-sensors); }
.ev3blk-operators { background: var(--ev3-operators); color: #1F4A1F; }
.ev3blk-variables { background: var(--ev3-variables); }
.ev3blk-myblocks  { background: var(--ev3-myblocks); }

/* ---------- Full programs — pre.ev3-program inside figure.ev3-program-figure (skill §5.2) ----------
   Plain monospace pseudo-block text, one block per line, 2-space indent
   inside C-blocks. No inner markup (it would leak as literal text). ---------- */
figure.ev3-program-figure {
  margin: 16px 0;
}
pre.ev3-program {
  background: #FFFFFF;
  color: #1E1B16;
  padding: 16px 18px;
  border: 1px solid #F4D7D7;
  border-left: 4px solid var(--lvl, var(--ev3));
  border-radius: 10px;
  overflow-x: auto;
  font-family: 'JetBrains Mono', 'Courier New', ui-monospace, monospace;
  font-size: 0.86rem;
  line-height: 1.65;
  margin: 0;
  white-space: pre;
  tab-size: 2;
}
figure.ev3-program-figure figcaption {
  margin-top: 10px;
  font-size: 0.9rem;
  color: #7A5B5B;
}

/* ---------- Rendered EV3 Classroom blocks — pre.ev3program inside figure ----------
   EV3 Classroom is a Scratch-3 fork, so <EV3BlocksLoader> hands these <pre>
   tags to scratchblocks@3.6.4, which swaps the text for real block SVG. The EV3
   palette is applied per block via `:: #hex` colour overrides (the loader maps
   friendly category names like `:: motors` → the hex). Before the script loads,
   the raw block text shows briefly; we keep it monospace so the flash reads as
   code, then the SVG takes its place. */
pre.ev3blocks {
  font-family: 'JetBrains Mono', 'Courier New', ui-monospace, monospace;
  font-size: 0.86rem;
  line-height: 1.5;
  white-space: pre;
  margin: 0;
  padding: 4px 0;
  overflow-x: auto;
  color: #8A7777;            /* dim the pre-render text + any leftover :: tags */
}
pre.ev3blocks svg {
  max-width: 100%;
  height: auto;
}

/* ---------- Build steps — ol.build-steps (skill §5.3) ---------- */
ol.build-steps {
  counter-reset: build;
  list-style: none;
  padding-left: 0;
  margin: 14px 0;
}
ol.build-steps > li {
  position: relative;
  padding: 10px 14px 10px 46px;
  margin-bottom: 8px;
  background: #FFF8F4;
  border: 1px solid #F2DED2;
  border-radius: 10px;
  font-size: 0.95rem;
}
ol.build-steps > li::before {
  counter-increment: build;
  content: counter(build);
  position: absolute;
  left: 10px; top: 50%;
  transform: translateY(-50%);
  width: 26px; height: 26px;
  display: flex; align-items: center; justify-content: center;
  background: var(--ev3);
  color: #fff;
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-weight: 700;
  font-size: 0.82rem;
  border-radius: 999px;
}

/* ---------- Mechanism / robot mock-up — figure.mechanism-diagram (skill §5.5) ---------- */
figure.mechanism-diagram {
  background: #FFFFFF;
  border: 1px solid #F4D7D7;
  border-radius: 14px;
  padding: 18px;
  margin: 16px 0;
  text-align: center;
}
figure.mechanism-diagram svg {
  max-width: 100%;
  height: auto;
}
figure.mechanism-diagram figcaption {
  margin-top: 12px;
  font-size: 0.9rem;
  color: #7A5B5B;
  text-align: left;
}

/* ---------- Real-world intro photos — figure.real-world (skill §3.2) ----------
   The "Meet the Model" opening shows real, freely-licensed photos of the object
   the model represents, stored locally under public/lego_ev3/intro/<coordinate>/.
   One or two per lesson; the figcaption carries a description + source/licence. */
figure.real-world {
  margin: 16px 0;
  text-align: center;
}
figure.real-world img {
  max-width: 100%;
  height: auto;
  border-radius: 12px;
  border: 1px solid #F4D7D7;
  box-shadow: 0 8px 24px -18px rgba(216, 35, 42, 0.45);
}
figure.real-world figcaption {
  margin-top: 10px;
  font-size: 0.88rem;
  color: #7A5B5B;
}

/* ---------- Inline code (e.g. port numbers, values mid-paragraph) ---------- */
.lesson code:not(pre code) {
  background: var(--ev3-soft);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 0.85em;
  color: var(--ev3-ink);
}

/* ---------- Reference tables ---------- */
table.ref {
  width: 100%;
  border-collapse: collapse;
  margin: 14px 0;
  font-size: 0.9rem;
}
table.ref th,
table.ref td {
  text-align: left;
  padding: 9px 12px;
  border-bottom: 1px solid #F4D7D7;
  vertical-align: top;
}
table.ref thead th {
  background: var(--ev3-soft);
  color: var(--ev3-dark);
  font-weight: 700;
  letter-spacing: 0.02em;
}
/* The "Block" column renders real EV3 Classroom blocks (pre.ev3blocks), not
   text pills — give it room and let the rendered SVG scale to the cell. */
table.ref th:first-child,
table.ref td:first-child { width: 46%; }
table.ref td pre.ev3blocks { margin: 0; padding: 2px 0; white-space: normal; }
table.ref td pre.ev3blocks svg { max-width: 100%; height: auto; }

/* ---------- "Add this block" build steps — ol.block-steps (skill §3.5) ----------
   Each numbered step shows a short instruction with the real block rendered
   underneath it (a pre.ev3blocks per step), instead of an inline text pill. */
ol.block-steps > li { margin-bottom: 12px; }
ol.block-steps pre.ev3blocks { margin: 6px 0 0; }

/* ---------- Callouts ---------- */
.callout {
  background: #FEF3C7;
  border-left: 4px solid #F59E0B;
  padding: 14px 18px;
  border-radius: 8px;
  margin: 16px 0;
  font-size: 0.92rem;
}
.callout strong { color: #92400E; }
.callout ul { margin: 6px 0 0; }

/* ---------- Reveal blocks ---------- */
.lesson details {
  background: var(--ev3-soft);
  border-radius: 10px;
  padding: 10px 16px;
  margin: 12px 0;
}
.lesson details summary {
  cursor: pointer;
  font-weight: 700;
  color: var(--ev3-dark);
}
.lesson details[open] summary { margin-bottom: 8px; }

/* ---------- Try-It-Yourself tasks (same easy/medium/stretch palette) ---------- */
.task {
  border: 1px solid #F4D7D7;
  border-radius: 12px;
  padding: 16px 18px;
  margin: 14px 0;
  background: #FFFBFB;
}
.task-tag {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 3px 10px;
  border-radius: 999px;
  margin-bottom: 8px;
}
.task--easy    .task-tag { background: #DCFCE7; color: #166534; }
.task--medium  .task-tag { background: #FEF3C7; color: #92400E; }
.task--stretch .task-tag { background: #FEE2E2; color: #991B1B; }

/* ---------- Vocabulary card ---------- */
dl.vocab {
  background: var(--ev3-soft);
  border-radius: 12px;
  padding: 16px 20px;
  margin: 16px 0 0;
}
dl.vocab dt {
  font-weight: 700;
  color: var(--ev3-dark);
  margin-top: 8px;
}
dl.vocab dt:first-child { margin-top: 0; }
dl.vocab dd {
  margin: 2px 0 0 0;
  color: var(--ink, #0F172A);
}

/* ---------- Footer ---------- */
.lesson .site-footer {
  text-align: center;
  padding: 24px;
  border-top: 1px solid #F4D7D7;
  background: #fff;
}
.lesson .site-footer .muted { color: #94A3B8; font-size: 0.88rem; }

/* ============================================================
   Lesson chrome — breadcrumb + prev/next nav (mirrors scratch/lesson.css)
   ============================================================ */
.lesson-header .lesson-crumbs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.78rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.85);
  margin: 0 0 14px;
}
.lesson-header .lesson-crumbs a {
  color: rgba(255, 255, 255, 0.9);
  text-decoration: none;
}
.lesson-header .lesson-crumbs a:hover {
  color: #fff;
  text-decoration: underline;
}
.lesson-header .lesson-crumbs .sep { opacity: 0.55; }
.lesson-header .lesson-crumbs .here { color: #fff; font-weight: 600; }

.lesson-foot {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
  margin: 36px 0 8px;
}
.lesson-foot__btn {
  flex: 1;
  min-width: 220px;
  padding: 16px 18px;
  border: 1px solid var(--border, #E2E8F0);
  background: #fff;
  border-radius: 14px;
  text-decoration: none;
  color: var(--ink, #0F172A);
  display: block;
  transition: transform .15s ease, border-color .15s ease, box-shadow .15s ease;
}
.lesson-foot__btn:hover {
  transform: translateY(-2px);
  border-color: var(--ev3);
  box-shadow: 0 10px 24px -16px rgba(216, 35, 42, 0.5);
  text-decoration: none;
}
.lesson-foot__btn[aria-disabled="true"] {
  opacity: 0.55;
  pointer-events: none;
}
.lesson-foot__dir {
  display: block;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.72rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted, #64748B);
  margin-bottom: 4px;
}
.lesson-foot__title {
  display: block;
  font-weight: 700;
  font-size: 1rem;
  color: var(--ink, #0F172A);
}
.lesson-foot__btn--next { text-align: right; }

@media (max-width: 720px) {
  .lesson-foot { flex-direction: column; }
  .lesson-foot__btn--next { text-align: left; }
}
