/* ==========================================================================
   lesson.css — modern lesson design system (sans-serif, dashboard-matching).
   Pairs with tokens.css. A lesson links both, sets its track accent
   (e.g. <html style="--accent:var(--track-bloom)"> or :root override), and
   uses these component classes. Change a rule here -> every lesson updates.
   ========================================================================== */

*{box-sizing:border-box}
html{font-size:17px; scroll-behavior:smooth}
body{margin:0; background:var(--bg); color:var(--ink); line-height:1.6;
  font-family:var(--font-sans);
  -webkit-font-smoothing:antialiased; text-rendering:optimizeLegibility}
.wrap{max-width:44rem; margin:0 auto; padding:2.6rem clamp(1rem,4vw,1.6rem) 5rem}

/* ---- hub bar (sticky header with prev/next + theme toggle) ---- */
#hubbar{position:sticky; top:0; z-index:50; display:flex; justify-content:space-between;
  align-items:center; gap:1rem; margin:-2.6rem calc(-1 * clamp(1rem,4vw,1.6rem)) 1.6rem; padding:.6rem clamp(1rem,4vw,1.6rem);
  background:color-mix(in srgb, var(--bg) 82%, transparent); -webkit-backdrop-filter:blur(10px);
  backdrop-filter:blur(10px); border-bottom:1px solid var(--line); font-size:.8rem}
#hubbar a{color:var(--accent); text-decoration:none; font-weight:600}
#hubbar .pn{display:flex; gap:.9rem; align-items:center}
.themebtn{cursor:pointer; background:var(--card); border:1px solid var(--line); border-radius:8px;
  padding:.25rem .5rem; font-size:.95rem; line-height:1; color:var(--ink)}
.themebtn:hover{background:var(--chip)}
/* reading-progress bar: thin accent line pinned to the top edge of the viewport,
   width grows with scroll position (driven by assets/reading-progress.js). Sits
   above the sticky #hubbar; theme-aware via --accent; never intercepts clicks. */
#reading-progress{position:fixed; top:0; left:0; height:3px; width:0;
  background:var(--accent); z-index:60; transition:width .08s linear; pointer-events:none}
@media (prefers-reduced-motion:reduce){
  html{scroll-behavior:auto}
  #reading-progress{transition:none}
  *,*::before,*::after{animation-duration:.01ms!important; animation-iteration-count:1!important; transition-duration:.01ms!important}
}

/* ---- masthead ---- */
.kicker{font-size:.7rem; letter-spacing:.16em; text-transform:uppercase; color:var(--accent); font-weight:700}
h1{font-size:clamp(1.45rem,6vw,2.2rem); line-height:1.13; margin:.3rem 0 .4rem; letter-spacing:-.02em; font-weight:700; overflow-wrap:break-word}
h1 em{font-style:normal; color:var(--accent)}
h2{font-size:1.3rem; margin:2.4rem 0 .5rem; font-weight:700; letter-spacing:-.01em}
h2.sec{padding-bottom:.3rem; border-bottom:2px solid var(--accent)}
h3{font-size:1.08rem; margin:1.5rem 0 .3rem; font-weight:700; letter-spacing:-.01em}
p{margin:.6rem 0}
.meta{font-size:.78rem; color:var(--muted)}
.lede{font-size:1.05rem; color:var(--muted)}
/* topic tags under the masthead — the page's keyword tags, made visible (the
   same terms carried in <meta name="keywords">). Each chip gets its own hue
   (cycled) so the row reads multi-colour, not one flat accent. Theme-aware:
   text mixes the hue toward --ink so it stays legible in light and dark. */
.ltags{display:flex; flex-wrap:wrap; gap:.4rem; margin:.7rem 0 .2rem}
.ltags .lt{font-size:.7rem; font-weight:600; line-height:1; white-space:nowrap;
  padding:.32rem .56rem; border-radius:6px;
  color:color-mix(in srgb, var(--lt-c,var(--text-muted)) 88%, var(--ink));
  background:color-mix(in srgb, var(--lt-c,var(--border)) 55%, transparent);
  border:1px solid var(--line)}
/* Topic chips are neutral metadata, not highlights — slate by default so amber
   reads as a deliberate accent. A page MAY set --lt-c for a semantic accent. */
a{color:var(--link)}
a:hover{color:var(--link-hover)}
sup a{text-decoration:none; font-weight:700; padding:0 1px}
code{background:var(--chip); padding:.05rem .35rem; border-radius:4px; font-size:.86em;
  font-family:var(--font-mono)}
blockquote{margin:1.1rem 0; padding:.3rem 0 .3rem 1rem; border-left:3px solid var(--line); color:var(--muted)}
hr.note,hr{border:0; border-top:1px solid var(--line); margin:2.2rem 0}

/* closing meta-note at the end of every lesson (injected by inject-lesson-endnote.py) */
.lesson-endnote{margin:1rem 0 .5rem; padding-top:1rem; border-top:1px solid var(--line);
  font-size:.82rem; font-style:italic; line-height:1.55; color:var(--muted)}

/* ---- callouts ---- */
.mission{background:var(--card); border:1px solid var(--line); border-left:3px solid var(--accent);
  border-radius:10px; padding:.8rem 1rem; font-size:.92rem; margin:1.1rem 0 1.6rem}
.pull{font-size:1.05rem; font-weight:600; background:color-mix(in srgb,var(--accent) 8%,transparent);
  border-radius:10px; padding:.9rem 1rem; margin:1.5rem 0}
.rule{background:color-mix(in srgb,var(--accent) 10%,transparent); border-radius:10px;
  padding:.8rem 1rem; margin:1.4rem 0; font-size:1rem}
.constraint{margin:.5rem 0; padding-bottom:.5rem; border-bottom:1px dotted var(--line)}
.constraint b{color:var(--accent)}
.miscon,.myth .m{background:color-mix(in srgb,var(--bad) 12%,transparent); border-radius:8px; padding:.6rem .8rem}
.myth .t{background:color-mix(in srgb,var(--good) 14%,transparent); border-radius:8px; padding:.6rem .8rem; margin-top:.4rem}

/* ---- figures / diagrams ---- */
figure{margin:1.3rem 0}
figure svg,figure img{width:100%; height:auto; background:var(--diagram-bg); border:1px solid var(--line); border-radius:10px}
figcaption{font-size:.76rem; color:var(--muted); margin-top:.4rem}
pre.dgm{background:var(--card); border:1px solid var(--line); border-radius:10px; padding:.8rem 1rem;
  overflow:auto; font-family:var(--font-mono); font-size:.8rem; line-height:1.4}

/* ---- visual primitives: steps, cards, fact grid ---- */
.steps{display:flex; gap:.5rem; align-items:stretch; margin:1.2rem 0}
.step{flex:1; background:var(--card); border:1px solid var(--line); border-radius:10px; padding:.6rem .75rem}
.step .lab{font-size:.64rem; letter-spacing:.12em; text-transform:uppercase; color:var(--muted)}
.step .big{font-size:1rem; font-weight:700; color:var(--accent); margin-top:.2rem; line-height:1.2}
.step .sub{font-size:.74rem; color:var(--muted); margin-top:.2rem}
.arrow{display:flex; align-items:center; color:var(--accent); font-weight:700}
.cards{display:flex; gap:.6rem; margin:1.1rem 0; flex-wrap:wrap}
.card{flex:1; min-width:8rem; background:var(--card); border:1px solid var(--line); border-radius:10px; padding:.7rem .85rem; text-align:center}
.card .v{font-size:1.1rem; font-weight:700; color:var(--accent)}
.card .l{font-size:.74rem; color:var(--muted); margin-top:.25rem}
.facts{display:grid; grid-template-columns:repeat(auto-fit,minmax(min(100%,13rem),1fr)); gap:.6rem; margin:1.1rem 0}
.fact{background:var(--card); border:1px solid var(--line); border-radius:10px; padding:.6rem .8rem; font-size:.9rem}

/* ---- tables ---- */
table{border-collapse:collapse; width:100%; margin:1.1rem 0; font-size:.9rem}
th,td{border:1px solid var(--line); padding:.5rem .65rem; text-align:left; vertical-align:top}
th{background:var(--chip); font-size:.82rem; font-weight:700}

/* ---- quiz ---- */
.quiz{background:var(--card); border:1px solid var(--line); border-radius:12px; padding:1.1rem 1.2rem; margin:1.2rem 0}
.q{font-weight:700; margin:.2rem 0 .7rem}
.qn{color:var(--accent)}
.opt{display:block; width:100%; text-align:left; font:inherit; font-size:.9rem; color:var(--ink);
  background:var(--bg); border:1px solid var(--line); border-radius:8px; padding:.55rem .7rem;
  margin:.35rem 0; cursor:pointer; transition:background .12s,border-color .12s}
.opt:hover{background:var(--chip)}
.opt.correct{border-color:var(--good); background:color-mix(in srgb,var(--good) 14%,transparent); color:var(--good); font-weight:700}
.opt.wrong{border-color:var(--bad); background:color-mix(in srgb,var(--bad) 12%,transparent); color:var(--bad)}
.opt:disabled{cursor:default}
.fb{font-size:.84rem; margin:.5rem 0 0; min-height:1.1rem}
.fb.ok{color:var(--good)} .fb.no{color:var(--bad)}

/* ---- rehearse / interview / memory-check ---- */
.rehearse textarea{width:100%; min-height:6rem; font:inherit; font-size:.92rem; padding:.6rem .7rem;
  border:1px solid var(--line); border-radius:8px; background:var(--card); color:var(--ink); resize:vertical}
.btn{font:inherit; font-size:.82rem; cursor:pointer; background:var(--accent-soft); color:var(--on-accent); border:0;
  border-radius:8px; padding:.45rem .9rem; margin-top:.6rem}
.btn.ghost{background:transparent; color:var(--accent); border:1px solid var(--accent)}
.model{display:none; margin-top:.8rem; background:var(--chip); border-radius:8px; padding:.8rem 1rem; font-size:.9rem}
.model.show{display:block}
details.iq,details.mc,.memcheck{background:var(--card); border:1px solid var(--line); border-radius:8px; padding:.6rem .85rem; margin:.6rem 0}
details.iq summary,details.mc summary{cursor:pointer; font-weight:600}

/* ---- in-page section nav (nav.toc): tappable chips/tags by DEFAULT (phones,
   tablets, narrow windows), upgrading to a sticky clickable right rail only on
   wide screens (>=1240px) where the gutter has room. Targeted as `nav.toc` so its
   specificity (0,1,1) beats each lesson's inline `.toc` rule (0,1,0) — no
   per-lesson HTML edits. Only ai-agents + context-engineering lessons carry
   <nav class="toc">; its links already anchor to section IDs, so jumping works. ---- */
nav.toc{display:flex; flex-wrap:wrap; gap:.4rem; margin:1rem 0 0; font-size:.82rem}
nav.toc a{padding:.32rem .7rem; border:1px solid var(--line); border-radius:999px;
  background:var(--chip); font-weight:600; line-height:1.25; color:var(--accent);
  text-decoration:none; white-space:nowrap}
nav.toc a:hover{background:color-mix(in srgb, var(--accent) 10%, var(--chip))}
nav.toc a:active{background:color-mix(in srgb, var(--accent) 18%, var(--chip))}

@media (min-width:1240px){
  nav.toc{position:fixed; top:5.5rem; right:calc((100vw - 44rem)/2 - 14.5rem);
    width:13rem; max-height:calc(100vh - 8rem); overflow:auto; z-index:40;
    flex-direction:column; flex-wrap:nowrap; gap:.1rem; margin:0; padding:.8rem .9rem;
    border:1px solid var(--line); border-radius:12px;
    background:color-mix(in srgb, var(--card) 90%, transparent);
    -webkit-backdrop-filter:blur(8px); backdrop-filter:blur(8px)}
  nav.toc::before{content:"On this page"; display:block; font-size:.64rem; letter-spacing:.12em;
    text-transform:uppercase; font-weight:700; color:var(--muted); margin-bottom:.4rem}
  nav.toc a{padding:.22rem .35rem; border:0; background:none; border-radius:6px; font-size:.78rem;
    line-height:1.3; white-space:nowrap; overflow:hidden; text-overflow:ellipsis;
    color:color-mix(in srgb, var(--accent) 86%, var(--ink))}
  nav.toc a:hover{background:color-mix(in srgb, var(--accent) 12%, transparent)}
}

/* ---- footer chrome: ask / next / sources ---- */
.ask{background:color-mix(in srgb,var(--accent) 7%,transparent); border:1px solid var(--line);
  border-radius:10px; padding:.85rem 1.1rem; font-size:.88rem; margin:2rem 0}
.next{display:flex; justify-content:space-between; gap:1rem; margin-top:2.4rem; padding-top:1rem;
  border-top:1px solid var(--line); font-size:.85rem}
footer{margin-top:2.4rem; font-size:.78rem; color:var(--muted)}
#sources{border-top:1px solid var(--line); padding-top:1rem}
.src{font-size:.82rem; color:var(--muted)}

@media (max-width:540px){
  .steps,.cards{flex-direction:column} .arrow{justify-content:center; transform:rotate(90deg)}
  /* Compact the sticky lesson header so the back-link, Prev/Next pager, and
     theme toggle stay on one clean line instead of wrapping mid-item. The
     track name is hidden here because the lesson title right below already
     names the topic. */
  #hubbar{gap:.55rem; font-size:.74rem}
  #hubbar .pn{gap:.6rem; white-space:nowrap}
  #hubbar > span:last-child{gap:.45rem!important}
  #hubbar > span:last-child > span{display:none}
  /* masthead: smaller, tighter eyebrow + heading so they read cleanly on a
     narrow phone instead of overflowing / breaking awkwardly */
  .kicker{font-size:.63rem; letter-spacing:.08em; line-height:1.4}
  h1{font-size:clamp(1.45rem,7vw,1.95rem); line-height:1.18}
  .meta{font-size:.74rem}
}
@media print{#hubbar,.themebtn,#reading-progress{display:none!important} a{color:var(--ink)} body{background:#fff}}

/* ── Consolidated lesson-body classes (Astro migration) ─────────────────────
   These rules were duplicated verbatim in every lesson's per-page inline
   <style> on the old site; the MDX conversion intentionally dropped the inline
   blocks in favour of shared CSS. Carried here ONCE (the de-duplication win),
   scoped under #main so they style the lesson body only and never reach the
   hub (#grid) — e.g. lesson `.lvl` is a section divider, hub `.lvl` is the
   difficulty-dot meter. Rules are verbatim from the originals. */
#main .nav{display:flex; justify-content:space-between; gap:1rem; margin-top:2rem; padding-top:1rem; border-top:1px solid var(--line); font-size:.84rem}
#main .lvltop{display:flex; align-items:center; gap:.6rem; margin-bottom:.2rem}
#main .lvltop .num{display:inline-grid; place-items:center; width:1.9rem; height:1.9rem; border-radius:50%; background:var(--accent-soft); color:var(--on-accent); font-weight:700; font-size:.95rem; flex:none}
#main .lvl{margin:2.6rem 0 0; padding-top:1rem; border-top:2px solid var(--ink)}
#main .chips{display:flex; flex-wrap:wrap; gap:.4rem; margin:1rem 0}
#main .chip{font-size:.78rem; padding:.35rem .6rem; border-radius:20px; border:1px solid var(--line); background:var(--card)}

/* ---- long-form reading comfort (typography pass) ----
   Relax leading on the lesson BODY only. Scoped to #main > p (true prose
   paragraphs — slot content is a direct child of #main) so callout, card,
   quiz, and chip text keep their tighter, compact metrics. Headings already
   carry tight line-height + negative tracking (see h1/h2/h3 above), so they
   are left as-is. */
#main > p{line-height:var(--leading-relaxed)}
#main li{line-height:var(--leading-normal)}
#main li + li{margin-top:.3rem}

/* ── Theme/alignment fixes (apply once, reach every lesson + interview page) ──
   1. `.lvltop` numbered section header: the badge and heading share a flex row
      with align-items:center, but the default h2 margin (2.4rem top / .5rem
      bottom) is NOT collapsed inside a flex item — so center-alignment pivots on
      the h2's margin-box and the heading text drops ~0.95rem below the badge.
      Zeroing the heading margin inside .lvltop lets it truly center on the badge.
      (Higher specificity than the bare h2 rule; only sets margin, so the two
      per-lesson files that also set font-size keep it.) */
#main .lvltop h2{margin:0}

/* 2. Interview Q&A (<details class="iq">): the bold <summary> question and the
      <div class="a"> answer are both --ink with no gap, so in dark mode you
      can't tell where the question ends and the answer begins. When open, split
      them with a theme-aware divider — works in both themes, no contrast change,
      and covers every interview page plus in-lesson M-disclosures in one place. */
details.iq[open] > summary{padding-bottom:.5rem; margin-bottom:.55rem; border-bottom:1px solid var(--line)}

/* 3. myth → truth cards: the shared .myth pattern only tinted the background,
      and in dark mode that tint is too faint to signal bad-vs-good — every
      card read as plain white text. Add the semantic left border (matching the
      per-lesson _0005/_0003 treatment) so myth/truth is scannable in both
      themes. Scoped to .myth so the .miscon callout is unaffected. */
.myth .m{border-left:3px solid var(--bad)}
.myth .t{border-left:3px solid var(--good)}
