/* CodeTrain — the try-a-lesson demo, shared by / and /solo.

   Extracted from web/index.html rather than copied into the second page. The block is ~160 lines
   and both pages mount the same component, so a duplicate would have drifted the first time one
   of them was touched. web/demo/demo.js renders into #demo-lesson on either page and does not
   depend on any static markup, so this file plus that mount point is the whole dependency.

   Loaded AFTER each page's inline <style>, which is what keeps the cascade order it had when it
   lived inline. Class names deliberately mirror the study screen (web/app/study/index.html) so the
   preview reads as the product rather than as a facsimile: .study-grid, .step-k, .step-h, .prose,
   .task, .feedback, .fb-tag, .checks, .prog, .langbadge are the same names doing the same jobs
   there. */

/* Sits directly under the hero, so the stock 74px section padding on top of the hero's own 52px
   opened a gap that broke the two apart. They are one moment: read the headline, use the thing. */
#try{padding-top:30px}
.demo-shell{border:1px solid var(--line);border-radius:var(--radius);background:linear-gradient(180deg,rgba(23,29,38,.86),rgba(19,24,31,.76));padding:18px;margin-top:26px}
.demo-head{display:flex;align-items:center;justify-content:space-between;gap:14px;flex-wrap:wrap;margin-bottom:16px}
.prog{display:flex;flex-direction:column;gap:5px;min-width:190px}
.prog-track{height:7px;border-radius:999px;background:var(--panel-2);overflow:hidden;border:1px solid var(--line)}
.prog-fill{display:block;height:100%;background:linear-gradient(90deg,var(--mint),#5fc6c6);border-radius:999px;transition:width .5s var(--ease)}
.prog-label{font-size:11.5px;color:var(--muted);font-family:var(--mono)}
.langbadge{font-family:var(--mono);font-size:11px;color:var(--muted);border:1px solid var(--line);border-radius:999px;padding:3px 10px;white-space:nowrap}
.langbadge.browser{color:var(--mint);border-color:rgba(57,170,170,.3)}
.study-grid{display:grid;grid-template-columns:minmax(0,1fr) minmax(0,1.05fr);gap:18px;align-items:start}
/* minmax(0,1fr), never a bare 1fr: `1fr` means `minmax(auto,1fr)`, and `auto` takes its floor
   from the widest unbreakable thing inside, which here is a line of code. That let the editor
   push the whole page wider than a phone and scroll the prose off the right edge. */
@media(max-width:860px){.study-grid{grid-template-columns:minmax(0,1fr)}}
.step-k{font-family:var(--mono);font-size:12px;color:var(--mint);text-transform:uppercase;letter-spacing:.05em}
.step-h{font-family:var(--serif);font-weight:600;font-size:20px;margin:6px 0 10px}
#try .prose{font-size:14.5px;color:#cdd5e0;line-height:1.62}
#try .prose code{font-family:var(--mono);background:var(--panel-2);padding:1px 5px;border-radius:5px;font-size:.9em;color:var(--ink)}
.task{border-left:2px solid var(--mint);padding:8px 0 8px 12px;margin:14px 0;color:var(--ink)}
.feedback{margin-top:14px;border-radius:10px;padding:12px 14px;font-size:14px;border:1px solid var(--line);background:var(--panel-2)}
.feedback.pass{border-color:#39aa6b} .feedback.retry{border-color:var(--amber)} .feedback.comment{border-color:var(--line)}
.fb-tag{font-family:var(--mono);font-size:11px;text-transform:uppercase;letter-spacing:.05em;margin-right:8px}
.pass .fb-tag{color:#39aa6b} .retry .fb-tag{color:var(--amber)} .comment .fb-tag{color:var(--mint)}
/* Always-on honesty label. Same slot the real product uses for its model badge, so a learner
   never sees a reply here without also seeing what wrote it. */
.fb-rec{font-family:var(--mono);font-size:10px;letter-spacing:.05em;text-transform:uppercase;color:var(--muted);border:1px solid var(--line);border-radius:999px;padding:1px 7px;cursor:help}
.feedback .prose{margin-top:9px}
.checks{margin:10px 0 0;padding-left:0;list-style:none;font-size:13px}
.checks li{padding-left:18px;position:relative;color:var(--muted);margin:3px 0}
.checks li.ok:before{content:"\2713";position:absolute;left:0;color:#39aa6b}
.checks li.no:before{content:"\2717";position:absolute;left:0;color:var(--amber)}
.checks li.no{color:var(--ink)}
.demo-editor{display:flex;background:#0c1117;border:1px solid var(--line);border-radius:10px;overflow:hidden;font-family:var(--mono);font-size:13px;line-height:1.6}
.demo-gutter{padding:12px 8px 12px 12px;color:#3d4b5c;text-align:right;user-select:none;white-space:pre;overflow:hidden;flex:none}
/* white-space:pre with wrap="off" keeps one code line on one row, which is what keeps the
   gutter's numbers pointing at the right lines. Long lines scroll sideways, like an editor. */
.demo-editor textarea{flex:1;min-width:0;background:transparent;border:0;color:var(--ink);font:inherit;padding:12px 12px 12px 6px;resize:vertical;min-height:132px;outline:none;tab-size:2;white-space:pre;overflow-x:auto}
.demo-editor textarea:focus-visible{outline:none}
.demo-editor:focus-within{border-color:rgba(57,170,170,.45)}
.demo-static{margin:0;flex:1;min-width:0;padding:12px 12px 12px 6px;overflow-x:auto;color:#cdd5e0;white-space:pre}
.demo-static code{font:inherit;background:none;padding:0}
.demo-runrow{display:flex;gap:9px;margin-top:11px;flex-wrap:wrap;align-items:center}
.demo-sm{border-radius:9px;padding:8px 15px;font-size:13.5px;font-weight:600;border:1px solid transparent;cursor:pointer;font-family:inherit;text-decoration:none;display:inline-block}
button.demo-sm:disabled{opacity:.55;cursor:default}
/* .demo-sm's shorthand border lands after .btn-ghost's border-color and wins, which left the
   ghost buttons looking like bare text. Restate both states at matching specificity. */
.btn-ghost.demo-sm{border-color:var(--line)}
.btn-ghost.demo-sm:hover{border-color:var(--mint)}
.demo-out{margin-top:12px;border:1px solid var(--line);border-radius:10px;overflow:hidden;background:#0c1117}
.demo-out-bar{padding:6px 12px;background:var(--panel-2);font-family:var(--mono);font-size:10.5px;text-transform:uppercase;letter-spacing:.06em;color:var(--muted)}
.demo-out pre{margin:0;padding:11px 12px;font-family:var(--mono);font-size:12.5px;color:#cdd5e0;overflow-x:auto;white-space:pre}
.demo-ret{display:flex;gap:9px;align-items:baseline;padding:9px 12px;border-top:1px solid var(--line);font-family:var(--mono);font-size:12.5px;flex-wrap:wrap}
.demo-ret span{color:var(--muted);font-size:10.5px;text-transform:uppercase;letter-spacing:.06em}
.demo-ret code{color:var(--mint)}
.demo-hints{margin-top:14px}
.demo-hint{border-left:2px solid rgba(170,57,57,.5);padding:6px 0 6px 12px;margin-bottom:10px}
.demo-hint-n{font-family:var(--mono);font-size:10.5px;text-transform:uppercase;letter-spacing:.05em;color:var(--amber)}
.demo-note{color:var(--muted);font-size:13px}
.demo-done{text-align:center;padding:14px 6px 6px}
.demo-done-k{font-family:var(--mono);font-size:11.5px;text-transform:uppercase;letter-spacing:.06em;color:#39aa6b}
.demo-done h3{font-family:var(--serif);font-size:24px;margin:10px 0 14px}
.demo-done p{color:#cdd5e0;font-size:15px;max-width:600px;margin:0 auto 14px}
.demo-cta{display:flex;gap:12px;justify-content:center;flex-wrap:wrap;margin:22px 0 16px}
.demo-disclose{color:var(--muted);font-size:14px;max-width:660px;margin:10px 0 0}
/* lesson title bar, mirroring the real study screen's topbar */
.demo-topbar{display:flex;align-items:flex-start;justify-content:space-between;gap:14px;flex-wrap:wrap;padding-bottom:13px;margin-bottom:14px;border-bottom:1px solid var(--line)}
.demo-eyebrow{font-family:var(--mono);font-size:10.5px;text-transform:uppercase;letter-spacing:.07em;color:var(--muted);margin-bottom:3px}
.demo-title{font-family:var(--serif);font-size:20px;line-height:1.25}
/* whose checks these are. The caption is the reframe, so it must never be mistaken for a check */
.checks-cap{font-family:var(--mono);font-size:10.5px;text-transform:uppercase;letter-spacing:.06em;color:var(--muted);margin-top:11px}
.checks-cap+.checks{margin-top:5px}
.demo-real{border:1px solid var(--line);border-radius:10px;background:var(--panel-2);padding:14px 16px;margin:20px auto 0;max-width:600px;text-align:left}
.demo-real-k{font-family:var(--mono);font-size:10.5px;text-transform:uppercase;letter-spacing:.06em;color:var(--mint);margin-bottom:7px}
.demo-real p{font-size:14px;color:var(--muted);margin:0 0 9px;max-width:none}
.demo-real p:last-child{margin-bottom:0}
a.fb-rec{text-decoration:none}
a.fb-rec:hover{color:var(--mint);border-color:var(--mint)}

/* Everything below is ported from web/app/study/index.html so the demo reads as the product.
   Same class names on purpose: a change to one is a reminder to look at the other. */

/* aside cards (study index.html:202-212) */
.asides{display:flex;flex-direction:column;gap:10px;margin-top:16px}
.aside{border:1px solid var(--line);border-left-width:3px;border-radius:10px;padding:12px 14px;background:var(--panel-2)}
.aside-k{font-family:var(--mono);font-size:10px;text-transform:uppercase;letter-spacing:.07em;color:var(--muted);margin-bottom:3px}
.aside-t{font-weight:600;font-size:14px}
.aside-b{font-size:13.5px;color:var(--muted);margin-top:5px;line-height:1.6}
.aside-b code{font-family:var(--mono);background:#0c1117;padding:1px 5px;border-radius:5px;font-size:.9em;color:var(--ink)}
.aside-link{display:inline-block;margin-top:8px;font-size:12.5px;font-family:var(--mono);color:var(--mint)}
.aside-note{border-left-color:var(--mint)} .aside-note .aside-k{color:var(--mint)}
.aside-try-local{border-left-color:#39aa6b;border-style:dashed;background:transparent}
.aside-try-local .aside-k{color:#39aa6b}

/* reference overlay (study index.html:267-274) */
.overlay{position:fixed;inset:0;background:rgba(0,0,0,.62);z-index:9999;display:flex;align-items:center;justify-content:center;padding:24px}
.overlay-box{background:var(--panel);border:1px solid var(--line);border-radius:12px;max-width:680px;width:100%;max-height:86vh;display:flex;flex-direction:column;box-shadow:0 20px 60px rgba(0,0,0,.5)}
.overlay-head{display:flex;align-items:center;justify-content:space-between;padding:13px 18px;border-bottom:1px solid var(--line);font-size:14px}
.overlay-body{padding:16px 18px;overflow:auto}
.reftab{width:100%;border-collapse:collapse;font-size:13.5px}
.reftab td{padding:6px 10px;border-bottom:1px solid var(--line);vertical-align:top;color:var(--muted)}
.reftab td:first-child{white-space:nowrap}
.reftab code{font-family:var(--mono);color:var(--mint)}

/* the ask row + aim chip (study index.html:317-318) */
.ask-row{display:flex;gap:8px;margin-top:10px}
.ask-row input{flex:1;min-width:0;background:var(--panel-2);border:1px solid var(--line);color:var(--ink);border-radius:9px;padding:9px 11px;font-family:inherit;font-size:14px}
.ask-row input:focus-visible{outline:none;border-color:rgba(57,170,170,.45)}
.aimchip{display:inline-flex;align-items:center;gap:6px;margin-top:12px;font-family:var(--mono);font-size:11.5px;color:var(--mint);border:1px solid rgba(57,170,170,.4);border-radius:999px;padding:3px 6px 3px 10px}
.aimchip button{background:none;border:0;color:var(--mint);cursor:pointer;font-size:12px;line-height:1;padding:2px 4px}
/* a failing check is a button; a passing one is not, since there is nothing to ask about */
.check-ask{background:none;border:0;padding:0;font:inherit;color:inherit;text-align:left;cursor:pointer;border-bottom:1px dotted var(--line)}
.check-ask:hover{color:var(--mint);border-bottom-color:var(--mint)}
.feedback.answer{border-color:rgba(57,170,170,.35)}
.answer .fb-tag{color:var(--mint)}
.qaq{color:var(--muted);font-style:italic;margin-bottom:7px}

/* the Q&A log (study renderQa) */
.qalog{margin-top:12px;border:1px solid var(--line);border-radius:10px;background:var(--panel-2);font-size:13.5px}
.qalog summary{cursor:pointer;padding:9px 13px;color:var(--muted);font-size:13px}
.qalog summary:hover{color:var(--ink)}
.qaitem{padding:11px 13px;border-top:1px solid var(--line)}
.qameta{font-family:var(--mono);font-size:11px;color:var(--muted);margin-bottom:5px}

/* editor theme picker. The real palettes live inside cm6.js, the 550KB bundle this page
   deliberately does not load, so these are hand-written equivalents for a plain textarea. */
.demo-edbar{display:flex;justify-content:flex-end;margin-bottom:7px}
.themesel{background:var(--panel-2);border:1px solid var(--line);color:var(--muted);border-radius:8px;padding:5px 8px;font-size:12.5px;font-family:inherit;cursor:pointer}
.demo-editor[data-edtheme="midnight"]{background:#070b14}
.demo-editor[data-edtheme="midnight"] textarea{color:#c4d0e8}
.demo-editor[data-edtheme="hacker"]{background:#04120a}
.demo-editor[data-edtheme="hacker"] textarea{color:#4ee08a}
.demo-editor[data-edtheme="hacker"] .demo-gutter{color:#2b6b45}
.demo-editor[data-edtheme="high-contrast"]{background:#000;border-color:#5a6577}
.demo-editor[data-edtheme="high-contrast"] textarea{color:#fff}
.demo-editor[data-edtheme="high-contrast"] .demo-gutter{color:#9aa6b8}
.demo-editor[data-edtheme="light"]{background:#f6f8fb;border-color:#c9d3e0}
.demo-editor[data-edtheme="light"] textarea{color:#16202e}
.demo-editor[data-edtheme="light"] .demo-gutter{color:#94a2b5}
.demo-noscript{color:var(--muted);font-size:14px;margin-top:14px}
/* real-repo examples band, directly under the demo */
.ex-band{margin-top:40px}
.ex-h{font-family:var(--serif);font-weight:600;font-size:21px;margin:0 0 8px}
.ex-lead{color:var(--muted);font-size:15.5px;margin:0 0 20px;max-width:660px}
.ex-grid{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:14px}
@media(max-width:760px){.ex-grid{grid-template-columns:1fr}}
.ex-card{display:block;text-decoration:none;border:1px solid var(--line);border-radius:12px;padding:16px 18px;background:linear-gradient(180deg,rgba(23,29,38,.7),rgba(19,24,31,.5));transition:border-color .16s,transform .16s var(--ease)}
.ex-card:hover{border-color:rgba(57,170,170,.42);transform:translateY(-2px)}
.ex-repo{font-family:var(--mono);font-size:13px;color:var(--mint);margin-bottom:9px;display:flex;justify-content:space-between;gap:10px;align-items:baseline;flex-wrap:wrap}
.ex-repo span{color:var(--muted);font-size:11px;text-transform:uppercase;letter-spacing:.05em}
.ex-q{color:#cdd5e0;font-size:14.5px;margin:0;line-height:1.55}
.ex-q code{font-family:var(--mono);background:var(--panel-2);padding:1px 5px;border-radius:5px;font-size:.9em;color:var(--ink)}
.ex-note{color:var(--muted);font-size:14px;margin:18px 0 0;max-width:660px}
@media (prefers-reduced-motion:reduce){.prog-fill,.ex-card{transition:none}}
