/* =========================================================
   LESSON CONTENT STYLES   (css/lesson-content.css)
   ---------------------------------------------------------
   Shared styling for lesson HTML that is fetched from the
   Supabase bucket and injected into #lessonBody.

   • Every rule is scoped under .lesson-scope (#lessonBody
     carries that class) so nothing leaks into the app shell.
   • Colours come from the host theme tokens (--background,
     --card, --border, --muted-foreground, --foreground) so
     the lesson follows the host's light / dark toggle.
   • Only lesson-specific tokens (green, code colours) are
     defined here.
   • Lesson files contain NO <style> block, topbar, dark-mode
     toggle, prev/next links, completion button or footer —
     the host page already provides all of those.
========================================================= */

/* ---------- Tokens ---------- */
.lesson-scope {
  /* host tokens, each with a fallback so a missing token can never blank out a rule */
  --lc-text:      var(--text-color, var(--foreground, #342e2e));
  --lc-bg:        var(--background, #f5f5f5);
  --lc-card:      var(--card, #ece9e8);
  --lc-border:    var(--border, #c9b8ac);
  --lc-muted:     var(--muted-foreground, #ad6c43);
  --lc-accent:    var(--primary, #ff6b35);          /* primary buttons: same orange as "Mark as Complete" */
  --lc-accent-fg: var(--primary-foreground, #ffffff);
  --lc-radius: 10px;
  --lc-shadow: 0 1px 2px rgba(0, 0, 0, 0.05), 0 6px 16px rgba(0, 0, 0, 0.05);

  /* Soft neutral lines + tints. Semi-transparent grey reads correctly on light AND dark
     surfaces, so lesson components stay light-touch even if the host's --border is a heavy colour. */
  --lc-line:        rgba(127, 127, 127, 0.28);
  --lc-line-strong: rgba(127, 127, 127, 0.50);
  --lc-tint:        rgba(127, 127, 127, 0.10);
  --lc-accent-tint: rgba(255, 107, 53, 0.08);
  --lc-ring:        rgba(255, 107, 53, 0.25);
  --lc-ring:        color-mix(in srgb, var(--lc-accent) 28%, transparent);   /* follows the host accent where supported */
  --lc-green:  #297a44;

  /* code box — GitHub Light */
  --lc-codebg:       #ffffff;
  --lc-codeheaderbg: #f6f8fa;
  --lc-codetext:     #24292e;
  --lc-codeborder:   #e1e4e8;
  --tok-keyword: #d73a49;
  --tok-string:  #032f62;
  --tok-number:  #005cc5;
  --tok-func:    #6f42c1;
  --tok-comment: #6a737d;
  --tok-self:    #e36209;
}

.dark .lesson-scope {
  /* same host tokens, but with DARK fallbacks for when a token is undefined */
  --lc-text:   var(--text-color, var(--foreground, #f2f2f2));
  --lc-bg:     var(--background, #2c2c2c);
  --lc-card:   var(--card, #1f1919);
  --lc-muted:  var(--muted-foreground, #d28c5f);
  --lc-green: #30b85d;

  /* code box — One Dark Pro */
  --lc-codebg:       #282c34;
  --lc-codeheaderbg: #21252b;
  --lc-codetext:     #abb2bf;
  --lc-codeborder:   #181a1f;
  --tok-keyword: #c678dd;
  --tok-string:  #98c379;
  --tok-number:  #d19a66;
  --tok-func:    #61afef;
  --tok-comment: #5c6370;
  --tok-self:    #e06c75;
}

/* ---------- Defensive reset ----------
   Other stylesheets on the page (landing-page .hero, .card, section, header, button …)
   use the same class / element names as lessons. `all: unset` wipes whatever they apply
   to lesson components, then each rule below sets the full look again.
   (`all: unset` also drops display + box-sizing, so they are restored here.) */
.lesson-scope section,
.lesson-scope .hero,
.lesson-scope .learning-points,
.lesson-scope .card,
.lesson-scope .try,
.lesson-scope .output,
.lesson-scope .quiz-q,
.lesson-scope .score-box,
.lesson-scope .progress-wrap,
.lesson-scope .progress-bar,
.lesson-scope .ccb-box,
.lesson-scope .ccb-content,
.lesson-scope p.intro {
  all: unset;
  display: block;
  box-sizing: border-box;
}

.lesson-scope .grid2,
.lesson-scope .ccb-header,
.lesson-scope .ccb-copy-btn,
.lesson-scope .ccb-lang,
.lesson-scope .badge,
.lesson-scope .feedback,
.lesson-scope button.act,
.lesson-scope button.ghost,
.lesson-scope label.opt,
.lesson-scope input[type=text],
.lesson-scope textarea.reflect {
  all: unset;
  box-sizing: border-box;
}

/* decorative ::before / ::after that site-wide styles add to these names */
.lesson-scope section::before,        .lesson-scope section::after,
.lesson-scope .hero::before,          .lesson-scope .hero::after,
.lesson-scope .card::before,          .lesson-scope .card::after,
.lesson-scope .try::before,           .lesson-scope .try::after,
.lesson-scope .learning-points::before, .lesson-scope .learning-points::after,
.lesson-scope h1::before, .lesson-scope h1::after,
.lesson-scope h2::before, .lesson-scope h2::after,
.lesson-scope h3::before, .lesson-scope h3::after {
  content: none;
  display: none;
}

/* ---------- Base typography ----------
   The host resets margin/padding on everything (* { margin:0; padding:0 }),
   so spacing the lessons rely on is restored explicitly here. */
.lesson-scope {
  color: var(--lc-text);
  line-height: 1.6;
  padding: 4px 8px 12px;
}

.lesson-scope p {
  margin: 0 0 1em;
  color: var(--lc-text);
}

.lesson-scope strong { color: var(--lc-muted); }

.lesson-scope ul,
.lesson-scope ol {
  margin: 0 0 1em;
  padding-left: 1.4rem;
}
.lesson-scope ul { list-style: disc; }
.lesson-scope ol { list-style: decimal; }

.lesson-scope li { margin-bottom: 4px; }

.lesson-scope section { margin: 32px 0; }

.lesson-scope h1,
.lesson-scope h2,
.lesson-scope h3,
.lesson-scope p,
.lesson-scope li {
  text-align: left;
  text-transform: none;
  letter-spacing: normal;
  text-shadow: none;
}

.lesson-scope h2 {
  font-size: 21px;
  font-weight: 700;
  line-height: 1.3;
  margin: 0 0 14px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--lc-line);
  color: var(--lc-text);
  font-family: inherit;
}

.lesson-scope h3 {
  font-family: inherit;
  font-size: 15.5px;
  font-weight: 700;
  margin: 0 0 8px;
  color: var(--lc-muted);
}

/* The host styles bare <code> as a block (for its own error panel);
   inside lessons it must stay inline. */
.lesson-scope code {
  display: inline;
  white-space: normal;
  font-family: Consolas, Menlo, monospace;
  font-size: 0.9em;
  line-height: inherit;
  background: var(--lc-tint);
  color: var(--lc-muted);
  padding: 2px 6px;
  border-radius: 6px;
}

/* ---------- Hero + learning points ---------- */
.lesson-scope .hero { padding: 6px 0 0; }

.lesson-scope .hero h1 {
  font-family: inherit;
  font-size: clamp(22px, 3.2vw, 28px);
  font-weight: 700;
  line-height: 1.25;
  margin: 0 0 10px;
  max-width: none;
  color: var(--lc-text);
  opacity: 1;
  animation: none;
}

.lesson-scope p.intro {
  font-size: 16.5px;
  line-height: 1.6;
  font-style: normal;
  max-width: 64ch;
  margin: 0;
  color: var(--lc-text);
  opacity: 0.88;
}

.lesson-scope .learning-points {
  background: var(--lc-bg);
  border: 1px solid var(--lc-line);
  border-radius: var(--lc-radius);
  padding: 16px 20px;
  margin: 22px 0 28px;
  box-shadow: var(--lc-shadow);
}

.lesson-scope .learning-points p.lp-label {
  margin: 0 0 8px;
  font-size: 13px;
  font-weight: 700;
  color: var(--lc-muted);
}

.lesson-scope .learning-points ul {
  margin: 0;
  padding-left: 20px;
  list-style: disc;
}

.lesson-scope .learning-points li {
  margin-bottom: 4px;
  color: var(--lc-text);
}

/* ---------- Cards / grid ---------- */
.lesson-scope .card {
  background: var(--lc-bg);
  border: 1px solid var(--lc-line);
  border-radius: 12px;
  padding: 20px 22px;
  box-shadow: var(--lc-shadow);
}
/* stacked cards breathe */
.lesson-scope .card + .card { margin-top: 16px; }

.lesson-scope .grid2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

@media (max-width: 640px) {
  .lesson-scope .grid2 { grid-template-columns: 1fr; }
}

/* ---------- "Try it" blocks ---------- */
.lesson-scope .try {
  border: 1px solid var(--lc-line);
  border-left: 4px solid var(--lc-accent);
  border-radius: var(--lc-radius);
  padding: 16px 20px;
  background: var(--lc-bg);
  margin: 14px 0;
}

.lesson-scope .try h3 { margin-top: 0; }
.lesson-scope .try .output { margin-top: 12px; }

.lesson-scope input[type=text] {
  display: inline-block;
  width: 60%;
  max-width: 280px;
  padding: 8px 12px;
  border-radius: 7px;
  border: 1px solid var(--lc-line);
  background: var(--lc-bg);
  color: var(--lc-text);
  font-family: Consolas, Menlo, monospace;
  font-size: 14px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.lesson-scope input[type=text]:focus {
  outline: none;
  border-color: var(--lc-accent);
  box-shadow: 0 0 0 3px var(--lc-ring);
}

.lesson-scope input[type=text],
.lesson-scope textarea {
  -webkit-user-select: text;
  user-select: text;
}

.lesson-scope button.act {
  display: inline-block;
  background: var(--lc-accent);
  color: var(--lc-accent-fg);
  border: 1px solid var(--lc-accent);
  padding: 9px 16px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  line-height: 1.2;
  font-family: inherit;
  cursor: pointer;
}

.lesson-scope button.act:hover { opacity: 0.88; }

.lesson-scope button.ghost {
  display: inline-block;
  line-height: 1.2;
  background: transparent;
  border: 1px solid var(--lc-line);
  color: var(--lc-text);
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  cursor: pointer;
}

.lesson-scope button.ghost:hover {
  border-color: var(--lc-muted);
  color: var(--lc-muted);
}

.lesson-scope button.act:focus-visible,
.lesson-scope button.ghost:focus-visible,
.lesson-scope .ccb-copy-btn:focus-visible,
.lesson-scope input[type=text]:focus-visible,
.lesson-scope textarea:focus-visible,
.lesson-scope label.opt:focus-within {
  outline: 2px solid var(--lc-muted);
  outline-offset: 2px;
}

.lesson-scope .output {
  margin-top: 12px;
  background: var(--lc-codebg);
  color: var(--lc-codetext);
  padding: 11px 15px;
  border: 1px solid var(--lc-codeborder);
  border-radius: 8px;
  font-family: Consolas, Menlo, monospace;
  font-size: 14px;
  min-height: 20px;
  white-space: pre-wrap;
}

/* ---------- Quiz ---------- */
.lesson-scope .quiz-q { margin-bottom: 18px; }

.lesson-scope .quiz-q p.qtext {
  font-weight: 700;
  margin: 0 0 8px;
  color: var(--lc-text);
}

.lesson-scope label.opt {
  display: block;
  border: 1px solid var(--lc-line);
  border-radius: var(--lc-radius);
  padding: 10px 14px;
  margin-bottom: 8px;
  cursor: pointer;
  background: var(--lc-bg);
  color: var(--lc-text);
  transition: border-color 0.15s ease, background-color 0.15s ease;
}

.lesson-scope label.opt:hover { border-color: var(--lc-line-strong); background: var(--lc-tint); }

/* the chosen answer is highlighted (needs :has — ignored harmlessly by very old browsers) */
.lesson-scope label.opt:has(input:checked) {
  border-color: var(--lc-accent);
  background: var(--lc-accent-tint);
}

/* radios / checkboxes: site-wide `input { width:100%; … }` rules must not stretch them */
.lesson-scope label.opt input[type=radio],
.lesson-scope label.opt input[type=checkbox] {
  display: inline-block;
  width: auto;
  height: auto;
  margin: 0 8px 0 0;
  padding: 0;
  vertical-align: middle;
  border-radius: 50%;
  box-shadow: none;
}
.lesson-scope label.opt input[type=checkbox] { border-radius: 2px; }

.lesson-scope .feedback {
  display: none;              /* gradeQuiz() switches this to block */
  font-size: 14px;
  font-weight: 600;
  margin-top: 8px;
  padding: 9px 12px;
  border-radius: 8px;
  border-left: 3px solid transparent;
}

.lesson-scope .feedback.correct {
  background: rgba(41, 122, 68, 0.12);
  border-left-color: var(--lc-green);
  color: var(--lc-green);
}

.lesson-scope .feedback.incorrect {
  background: rgba(214, 69, 69, 0.10);
  border-left-color: #d64545;
  color: var(--lc-text);
}

.lesson-scope .badge {
  display: inline-block;
  background: rgba(173, 108, 67, 0.14);
  color: var(--lc-muted);
  font-size: 12px;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 999px;
  margin-bottom: 10px;
}

/* ---------- Assessment: progress + score + reflection ---------- */
.lesson-scope .progress-wrap {
  position: relative;
  height: 8px;
  margin: 14px 0;
  border-radius: 999px;
  overflow: hidden;
}

.lesson-scope .progress-wrap::before {
  content: '';
  display: block;
  position: absolute;
  inset: 0;
  background: var(--lc-line);
}

.lesson-scope .progress-wrap .progress-bar {
  position: relative;
  height: 100%;
  width: 0;
  background: var(--lc-green);
  border-radius: 999px;
  transition: width 0.4s ease;
}

.lesson-scope .score-box {
  text-align: center;
  padding: 24px;
}
.lesson-scope .score-box p,
.lesson-scope .score-box .big,
.lesson-scope .score-box .badge { text-align: center; }

.lesson-scope .score-box .big {
  font-size: 42px;
  font-weight: 800;
  color: var(--lc-green);
}

.lesson-scope textarea.reflect {
  display: block;
  width: 100%;
  min-height: 132px;
  padding: 14px 16px;
  border: 1px solid var(--lc-line);
  border-radius: var(--lc-radius);
  background: var(--lc-bg);
  color: var(--lc-text);
  font-family: inherit;
  font-size: 15px;
  line-height: 1.6;
  overflow: auto;              /* `all: unset` resets this; resizing needs it */
  resize: vertical;
  scrollbar-width: thin;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.lesson-scope textarea.reflect::placeholder { color: var(--lc-muted); opacity: 0.65; }
.lesson-scope textarea.reflect:hover        { border-color: var(--lc-line-strong); }

.lesson-scope textarea.reflect:focus,
.lesson-scope textarea.reflect:focus-visible {
  outline: none;
  border-color: var(--lc-accent);
  box-shadow: 0 0 0 3px var(--lc-ring);
}

/* The browser's native resize grip is two thick dark slashes. Replace it with a light,
   thin two-line handle (Chromium / Edge / Safari; Firefox keeps its own grip). */
.lesson-scope textarea.reflect::-webkit-resizer {
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 14 14'%3E%3Cpath d='M12 5 5 12M12 9.5 9.5 12' stroke='%23999' stroke-opacity='.75' stroke-width='1.3' stroke-linecap='round' fill='none'/%3E%3C/svg%3E") no-repeat center / 14px 14px;
  border: 0;
}

/* ---------- Code copy box ---------- */
.lesson-scope .ccb-box {
  background: var(--lc-codebg);
  border: 1px solid var(--lc-codeborder);
  border-radius: 10px;
  box-shadow: var(--lc-shadow);
  overflow: hidden;
  margin: 20px 0;
}

.lesson-scope .ccb-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--lc-codeheaderbg);
  color: var(--lc-codetext);
  padding: 11px 16px;
  border-bottom: 1px solid var(--lc-codeborder);
}

.lesson-scope .ccb-lang {
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  opacity: 0.7;
}

.lesson-scope .ccb-copy-btn {
  display: flex;
  line-height: 1.2;
  align-items: center;
  gap: 6px;
  background: var(--lc-green);
  color: #fff;
  border: none;
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 0.78rem;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.2s ease, transform 0.15s ease;
}

.lesson-scope .ccb-copy-btn:hover  { opacity: 0.9; }
.lesson-scope .ccb-copy-btn:active { transform: scale(0.95); }
.lesson-scope .ccb-copy-btn.copied { background: #4299e1; }

.lesson-scope .ccb-content { background: var(--lc-codebg); }

/* the host also styles bare <pre>; reset it for lesson code boxes */
.lesson-scope .ccb-content pre {
  margin: 0;
  padding: 16px 18px;
  overflow-x: auto;
  border-radius: 0;
  background: transparent;
}

.lesson-scope .ccb-content code {
  display: block;
  background: none;
  color: var(--lc-codetext);
  font-family: Consolas, Menlo, monospace;
  font-size: 0.9rem;
  line-height: 1.6;
  white-space: pre;
  padding: 0;
  border-radius: 0;
}

.lesson-scope .tok-keyword { color: var(--tok-keyword); }
.lesson-scope .tok-string  { color: var(--tok-string); }
.lesson-scope .tok-number  { color: var(--tok-number); }
.lesson-scope .tok-func    { color: var(--tok-func); }
.lesson-scope .tok-comment { color: var(--tok-comment); font-style: italic; }
.lesson-scope .tok-self    { color: var(--tok-self);    font-style: italic; }
