/* The circuits course's pages (Tools/course/build.py): the Manual's look (manual.css), a light theme for a light screen, and
   the live circuit (course.js), which stays a dark instrument in both themes, as the app draws its schematic and Scope. */
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) body.course {
    --bg: #f7f8fb; --panel: #ffffff; --panel2: #eef0f5; --line: #dde1ea; --text: #14161d; --muted: #5a6072; --accent: #1f6fe5;
    --part: #1f6fe5; color-scheme: light;
  }
}
:root[data-theme="light"] body.course {
  --bg: #f7f8fb; --panel: #ffffff; --panel2: #eef0f5; --line: #dde1ea; --text: #14161d; --muted: #5a6072; --accent: #1f6fe5;
  --part: #1f6fe5; color-scheme: light;
}
body.course { background: var(--bg); color: var(--text); }
body.course .code { background: var(--panel2); }
body.course h2 .n { color: #fff; }

/* ——— The answer, under the title ——— */
.course .hero { padding-bottom: 20px; }
.course .lede.answer { color: var(--text); max-width: 36em; }
.course .soon { color: inherit; }
.course section.step { padding-top: 34px; margin-top: 30px; }
.course section.step h2 { font-size: clamp(23px, 2.8vw, 28px); }
.course .col ul, .course .col ol { padding-left: 22px; margin: 0 0 16px; }
.course .col li { margin-bottom: 8px; }
.course blockquote { margin: 0 0 16px; padding: 4px 0 4px 16px; border-left: 3px solid var(--part); color: var(--muted); }
.course .views { font-variant-numeric: tabular-nums; }
.course .views td:first-child { white-space: normal; }
.course .hublink { margin: 18px 0 0; font-weight: 600; }
.course .pager:empty { display: none; }
.course .pager { margin: 8px 0 18px; }
.course .pager .prev:only-child { grid-column: 1; }

/* ——— The live circuit: a dark instrument, whatever the page's theme ——— */
.cp {
  --bg: #101116; --panel: #181a22; --panel2: #1e2029; --line: #262a36; --text: #eef0f6; --muted: #9aa0b2; --accent: #3d8bff; --part: #4fa1ff;
  color-scheme: dark; color: var(--text);
  margin: 10px 0 30px; max-width: 1040px; background: var(--panel); border: 1px solid var(--line); border-radius: 18px; overflow: hidden;
  transition: box-shadow .2s, border-color .2s;
}
.cp.playing { border-color: var(--part); box-shadow: 0 0 0 3px color-mix(in srgb, var(--part) 35%, transparent); }
.cp-variants { display: flex; flex-wrap: wrap; gap: 8px; padding: 12px 12px 0; }
.cp-variants button { font: 600 14px/1.2 -apple-system, BlinkMacSystemFont, sans-serif; color: var(--text); background: var(--panel2); border: 1px solid var(--line);
  border-radius: 999px; padding: 8px 14px; cursor: pointer; }
.cp-variants button[aria-pressed="true"] { background: var(--part); border-color: var(--part); color: #0b0c10; }
.cp-variants button:focus-visible { outline: 3px solid #fff; outline-offset: 2px; }
.cp-top { display: grid; grid-template-columns: minmax(0, 4fr) minmax(0, 7fr); gap: 10px; padding: 12px 12px 0; }
@media (max-width: 860px) { .cp-top { grid-template-columns: minmax(0, 1fr); } }
.cp .code { margin: 0; background: #0c0d12; }
.cp .code pre { font-size: 13px; }
.cp-schem, .cp-scope { position: relative; min-width: 0; background: #111217; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.cp-name { display: block; padding: 7px 10px 0; font: 600 11.5px/1 -apple-system, BlinkMacSystemFont, sans-serif; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); }
.cp-svg { padding: 6px 10px 10px; display: flex; align-items: center; min-height: 150px; }
.cp-svg[hidden] { display: none; }
.cp-svg svg { display: block; width: 100%; height: auto; max-height: 320px; }
/* A phone: the schematic keeps a readable size and pans sideways in its own box (the page never scrolls sideways). */
@media (max-width: 600px) { .cp-svg { overflow-x: auto; overscroll-behavior-x: contain; } .cp-svg svg { min-width: 560px; } }
.cp-scope { margin: 10px 12px 0; }
.cp-scope canvas { display: block; width: 100%; height: 170px; color: var(--part); }
.cp-idle { position: absolute; inset: 24px 0 0; display: grid; place-items: center; margin: 0; color: var(--muted); font-size: 14.5px; text-align: center; padding: 0 16px; pointer-events: none; }
.cp.playing .cp-idle, .cp[data-state="playing"] .cp-idle { display: none; }
.cp-knobs { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px 30px; padding: 12px 12px 4px; }
.cp .knob { --k: var(--part); display: flex; flex-direction: column; align-items: center; gap: 2px; cursor: ns-resize; touch-action: none; user-select: none;
  -webkit-user-select: none; border-radius: 12px; padding: 4px 8px; outline: none; color: var(--text); }
.cp .knob.still { cursor: default; opacity: .85; }
.cp .knob:focus-visible { box-shadow: 0 0 0 2px var(--part); }
.cp .knob svg { width: 58px; height: 58px; overflow: visible; }
.cp .knob .track { fill: none; stroke: rgba(255, 255, 255, 0.12); stroke-width: 6; stroke-linecap: round; }
.cp .knob .arc { fill: none; stroke: var(--k); stroke-width: 6; stroke-linecap: round; }
.cp .knob .pointer { fill: #fff; }
.cp .knob .mod, .cp .knob .moddot { display: none; }
.cp .knob b { font: 600 13px/1.2 var(--mono); }
.cp .knob small { font-size: 12.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
.cp-ctl { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; padding: 10px 12px; border-top: 1px solid var(--line); margin-top: 8px; }
.cp-play { flex: none; display: inline-flex; align-items: center; gap: 8px; font: 700 15px/1 -apple-system, BlinkMacSystemFont, sans-serif; border-radius: 999px;
  border: 0; padding: 11px 20px 11px 16px; background: var(--part); color: #0b0c10; cursor: pointer; }
.cp-play svg { width: 18px; height: 18px; }
.cp-play[aria-pressed="true"] svg { display: none; }
.cp-play[aria-pressed="true"]::before { content: ""; width: 12px; height: 12px; margin: 0 3px; border-radius: 2px; background: currentColor; }
.cp-play:focus-visible { outline: 3px solid #fff; outline-offset: 3px; }
.cp-hint { flex: 1 1 200px; font-size: 14.5px; color: var(--muted); line-height: 1.4; }
.cp-open { flex: 0 1 auto; margin-left: auto; font-weight: 600; font-size: 14.5px; text-align: right; color: var(--accent); }
.cp-sorry { padding: 0 12px 10px; margin: 0; color: #ffb4b4; font-size: 14.5px; }
@media (max-width: 600px) { .cp-open { margin-left: 0; text-align: left; } .cp-scope canvas { height: 140px; } }

/* ——— The video: a picture until it's tapped (nothing from the video site loads before) ——— */
.cp-video { margin: 6px 0 18px; max-width: 640px; }
.cp-yt { position: relative; display: block; width: 100%; aspect-ratio: 16 / 9; padding: 0; border: 1px solid var(--line); border-radius: 14px; overflow: hidden;
  background: #000; cursor: pointer; color: #fff; text-align: left; }
.cp-yt img { width: 100%; height: 100%; object-fit: cover; opacity: .85; }
.cp-ytplay { position: absolute; left: 50%; top: 50%; width: 68px; height: 48px; margin: -24px 0 0 -34px; border-radius: 14px; background: rgba(0,0,0,.72); display: grid; place-items: center; }
.cp-ytplay svg { width: 26px; height: 26px; }
.cp-yt:hover .cp-ytplay, .cp-yt:focus-visible .cp-ytplay { background: var(--part); color: #0b0c10; }
.cp-ytname { position: absolute; left: 0; right: 0; bottom: 0; padding: 26px 14px 10px; font: 600 15px/1.3 -apple-system, BlinkMacSystemFont, sans-serif;
  background: linear-gradient(transparent, rgba(0,0,0,.8)); }
.cp-video iframe { display: block; width: 100%; aspect-ratio: 16 / 9; border: 0; border-radius: 14px; }

/* ——— The hub ——— */
.chapters { display: grid; gap: 8px; margin-top: 8px; }
.chap { border-top: 1px solid var(--line); padding: 26px 0 8px; }
.chap h2 { font-size: clamp(22px, 2.6vw, 27px); }
.chap.empty h2 { color: var(--muted); font-weight: 600; margin: 0; }
.chap.empty h2 .n { background: var(--panel2); color: var(--muted); }
.chap ul.pages { list-style: none; margin: 6px 0 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(min(300px, 100%), 1fr)); gap: 12px; }
.chap ul.pages a { display: block; height: 100%; border: 1px solid var(--line); border-radius: 16px; padding: 14px 16px 16px; background: var(--panel); color: var(--text); position: relative; }
.chap ul.pages a:hover { text-decoration: none; border-color: color-mix(in srgb, var(--part) 60%, var(--line)); }
.chap ul.pages a::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; border-radius: 16px 0 0 16px; background: var(--part); }
.chap ul.pages b { display: block; font-size: 18px; letter-spacing: -.01em; line-height: 1.25; margin-bottom: 6px; }
.chap ul.pages span { display: block; color: var(--muted); font-size: 15px; line-height: 1.45; }
/* A page's picture at the top of its card (Tools/course/thumbs.mjs), edge to edge, cropped to 16:9 at the sides. */
.chap ul.pages a:has(img.th) { overflow: hidden; }
.chap ul.pages img.th { display: block; width: calc(100% + 32px); max-width: none; height: auto; aspect-ratio: 16 / 9; object-fit: cover; margin: -14px -16px 12px; background: #101116; border-bottom: 1px solid var(--line); }

@media print { .cp-ctl, .cp-variants, .cp-video { display: none !important; } }
/* A parts list's lines start at its edge (manual.css keeps room for numbered lines) */
.course .code .ln::before { display: none; }
.course .code .ln { padding: 0 16px; }
/* The hub's Start here: the course's first page */
.course .start { display: inline-grid; grid-template-columns: auto auto; column-gap: 14px; align-items: center; margin: 22px 0 0; padding: 12px 18px 12px 20px;
  border-radius: 16px; background: var(--part); color: #0b0c10; max-width: 100%; }
.course .start:hover { text-decoration: none; filter: brightness(1.06); }
.course .start small { grid-column: 1; font-size: 12.5px; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; opacity: .8; }
.course .start b { grid-column: 1; font-size: 18px; line-height: 1.25; }
.course .start span { grid-column: 2; grid-row: 1 / 3; font-size: 24px; font-weight: 700; }
/* Dates: when a page was added and last changed */
.course .dates { margin: 14px 0 0; font-size: 14px; color: var(--muted); }
/* The hub's Recently added */
.course .recent { margin: 0 0 18px; padding: 16px 18px 6px; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; max-width: 720px; }
.course .recent h2 { font-size: 15px; letter-spacing: .05em; text-transform: uppercase; color: var(--part); margin: 0 0 8px; }
.course .recent ol { list-style: none; margin: 0; padding: 0; }
.course .recent li { display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 12px; padding: 8px 0; border-top: 1px solid var(--line); }
.course .recent li:first-child { border-top: 0; }
.course .recent li a { font-weight: 600; }
.course .recent .dates { margin: 0; font-size: 13px; }

/* ——— The papers (/papers/): a reading list in groups ——— */
.part-papers { --part: #c9a3ff; }   /* lavender: reading */
@media (prefers-color-scheme: light) { :root:not([data-theme="dark"]) body.course.part-papers { --part: #7a4fd6; } }
:root[data-theme="light"] body.course.part-papers { --part: #7a4fd6; }
.course .groups ol { list-style: none; margin: 8px 0 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.course .groups a { display: inline-block; padding: 6px 12px; border: 1px solid var(--line); border-radius: 999px; background: var(--panel); color: var(--text); font-size: 14.5px; font-weight: 600; }
.course .groups a:hover { text-decoration: none; border-color: var(--part); }
.course .groups small { color: var(--muted); font-size: 12.5px; margin-left: 2px; }
.course .paper { padding: 16px 0 6px; border-top: 1px solid var(--line); scroll-margin-top: 80px; }
.course .paper h3 { margin: 0 0 6px; font-size: 18.5px; line-height: 1.3; }
.course .paper h3 a { color: var(--text); }
.course .paper .meta { font-size: 14.5px; color: var(--muted); margin: 0 0 8px; overflow-wrap: anywhere; }
.course .paper .explained { display: inline-block; margin: 0 0 12px; font-weight: 700; font-size: 14.5px; }
.course .paper:target { background: color-mix(in srgb, var(--part) 9%, transparent); border-radius: 10px; }
/* Each paper as a card, as its picture draws it (Tools/course/thumbs.mjs): dark in both themes, its group's colour (--g, on
   its section) along the top and in its year, readable at grid size. A grid wider than the text column, one card a row on a phone. */
.course section.papers h2::before { content: ""; display: inline-block; vertical-align: middle; width: 26px; height: 5px; border-radius: 3px; background: var(--g, var(--part)); margin: -3px 12px 0 0; }
.course .pgrid { max-width: 1040px; display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 290px), 1fr)); gap: 16px; margin: 16px 0 0; }
.course .pgrid .paper { position: relative; display: flex; flex-direction: column; padding: 20px 18px 14px; border: 1px solid #262a36; border-radius: 16px; overflow: hidden;
  color-scheme: dark; color: #eef0f6; background: radial-gradient(420px 220px at 100% 0%, color-mix(in srgb, var(--g) 15%, transparent), transparent 70%), #13151c; }
.course .pgrid .paper::before { content: ""; position: absolute; left: 0; right: 0; top: 0; height: 3px; background: linear-gradient(90deg, var(--g), color-mix(in srgb, var(--g) 35%, transparent)); }
.course .pgrid .pc-year { display: block; margin: 0 0 10px; font-size: 42px; line-height: 1; font-weight: 800; letter-spacing: -.04em; font-variant-numeric: tabular-nums;
  color: var(--g); background: linear-gradient(180deg, var(--g) 10%, color-mix(in srgb, var(--g) 30%, transparent) 95%); -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent; }
.course .pgrid .paper h3 { margin: 0 0 8px; font-size: 19px; line-height: 1.25; letter-spacing: -.01em; color: #eef0f6; text-wrap: balance; }
.course .pgrid .paper h3 a { color: #eef0f6; }
.course .pgrid .paper p { margin: 0 0 10px; font-size: 15px; line-height: 1.45; color: #b4bacb; }
.course .pgrid .paper p a { color: #8cb8ff; }
.course .pgrid .paper .meta { margin: auto 0 0; padding-top: 10px; border-top: 1px solid #262a36; font-size: 13px; line-height: 1.4; color: #9aa0b2; }
.course .pgrid .paper .explained { margin: 10px 0 0; color: var(--g); }
.course .pgrid .paper:target { background: radial-gradient(420px 220px at 100% 0%, color-mix(in srgb, var(--g) 26%, transparent), transparent 70%), #13151c; box-shadow: 0 0 0 2px var(--g); }

/* ——— A paper's own page (/papers/<slug>/): a read-along ——— */
.paperpage .pmeta { color: var(--muted); font-size: 16px; margin: 0 0 14px; overflow-wrap: anywhere; }
.paperpage .pread { margin: 0 0 18px; }
.paperpage .pread .start b { overflow-wrap: anywhere; }
.paperpage blockquote.says { margin: 0 0 16px; padding: 12px 16px; border-left: 3px solid var(--part); border-radius: 0 10px 10px 0;
  background: color-mix(in srgb, var(--part) 7%, transparent); color: var(--text); font-family: Georgia, "Iowan Old Style", "Times New Roman", serif; font-size: 17px; line-height: 1.55; }
.paperpage blockquote.says p { margin: 0; }
.paperpage blockquote.abstract p + p { margin-top: 10px; }
.paperpage .pnote { color: var(--muted); font-size: 14px; }
.paperpage .steplist { columns: 2 280px; column-gap: 28px; }
.paperpage .steplist li { break-inside: avoid; }
.paperpage section.rstep { scroll-margin-top: 70px; }
.paperpage section.rstep h3 { font-size: clamp(21px, 2.5vw, 25px); margin: 0 0 14px; line-height: 1.25; }
.paperpage h4 { margin: 22px 0 8px; font-size: 13px; letter-spacing: .06em; text-transform: uppercase; color: var(--part); }
.paperpage .pfig { margin: 6px 0 20px; max-width: 900px; }
.paperpage .pfig img { display: block; width: auto; max-width: 100%; max-height: 460px; height: auto; background: #fff; border-radius: 10px; border: 1px solid var(--line); }
.paperpage .pfig figcaption { margin-top: 8px; font-size: 14.5px; color: var(--muted); line-height: 1.45; }
.paperpage .pfig .pf-cap { display: block; }
.paperpage .pfig .pf-credit { display: block; margin-top: 3px; font-size: 13px; }
.paperpage .pfig .pf-credit a { color: var(--muted); text-decoration: underline; text-underline-offset: 2px; }
.paperpage .pf-card { display: flex; flex-direction: column; gap: 6px; padding: 18px; border: 1px dashed var(--line); border-radius: 12px; background: var(--panel); }
.paperpage .pf-card b { font-size: 15px; }
.paperpage .pf-card span { color: var(--muted); font-size: 14.5px; }
.paperpage .pf-card a { font-weight: 600; font-size: 14.5px; }
.paperpage dl.words { margin: 0 0 16px; }
.paperpage dl.words dt { font-weight: 700; margin-top: 12px; }
.paperpage dl.words dd { margin: 2px 0 0; color: var(--text); }
.cp-views { position: absolute; top: 4px; right: 6px; display: flex; gap: 4px; z-index: 1; }
.cp-views button { font: 600 11.5px/1 -apple-system, BlinkMacSystemFont, sans-serif; color: var(--muted); background: var(--panel2); border: 1px solid var(--line); border-radius: 999px; padding: 5px 10px; cursor: pointer; }
.cp-views button[aria-pressed="true"] { color: #0b0c10; background: var(--part); border-color: var(--part); }
.cp-nosch { margin: 0; padding: 18px 8px; color: var(--muted); font-size: 14.5px; }
.cp-knobs:empty { display: none; }
.cp-wide .cp-top { grid-template-columns: minmax(0, 7fr) minmax(0, 4fr); }
@media (max-width: 860px) { .cp-wide .cp-top { grid-template-columns: minmax(0, 1fr); } }
@media (max-width: 600px) { .cp-variants { gap: 6px; } .cp-variants button { font-size: 13px; padding: 6px 11px; } }
/* An explained paper's card: one link to its page (the title's link stretched over the whole card), its picture on top; the
   link to the original (and any other link in it) sits above the stretched one, so it stays its own. */
.course .pgrid .paper.has-page { cursor: pointer; transition: box-shadow .15s, transform .15s; }
.course .pgrid .paper.has-page:hover { box-shadow: 0 0 0 2px var(--g); }
.course .pgrid .paper.has-page:focus-within { box-shadow: 0 0 0 3px var(--g); }
.course .pgrid .paper .pc-link::after { content: ""; position: absolute; inset: 0; z-index: 1; border-radius: 16px; }
.course .pgrid .paper .pc-link:focus-visible { outline: none; }
.course .pgrid .paper.has-page .meta a, .course .pgrid .paper.has-page .explained, .course .pgrid .paper.has-page p a { position: relative; z-index: 2; }
.course .pgrid .paper .pc-thumb { display: block; width: calc(100% + 36px); height: auto; margin: -20px -18px 14px; border-bottom: 1px solid #262a36; }
/* Jorge, 11 Nov: the explained papers stand out: full brightness in the settings' green, the others dimmed until pointed at;
   a strip at the top lists the explained ones. */
.course .pgrid .paper:not(.has-page) { opacity: .55; transition: opacity .15s; }
.course .pgrid .paper:not(.has-page):hover, .course .pgrid .paper:not(.has-page):focus-within, .course .pgrid .paper:not(.has-page):target { opacity: 1; }
.course .pgrid .paper.has-page { --g: #52db8f; }
.course .explained-strip { margin: 6px auto 4px; padding: 14px 18px; border: 1px solid color-mix(in srgb, #52db8f 45%, var(--line)); border-radius: 14px;
  background: color-mix(in srgb, #52db8f 8%, transparent); }
.course .explained-strip h2 { margin: 0 0 6px; font-size: 15px; letter-spacing: .04em; text-transform: uppercase; }
.course .explained-strip h2 small { color: var(--muted); font-size: 13px; }
.course .explained-strip ul { margin: 0; padding-left: 18px; }
.course .explained-strip li { margin: 4px 0; }
.course .explained-strip li small { color: var(--muted); margin-left: 4px; }

/* Jorge, 11 Nov: code in the app's own syntax colours (Tools/course/colour.mjs), and never clipped: a long line wraps with a
   hanging indent. The live circuit stays dark in both themes; code elsewhere follows the page's theme. */
.course .code .kw { color: #c49bff; font-weight: 600; }
.course .code .fn { color: #8cb8ff; }
.course .code .number { color: #ffcf6b; }
.course .code .comment { color: #7c8296; font-style: italic; }
.course .code .past { color: #ff9e7a; }
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) body.course .code:not(.cp .code) .kw { color: #7a3fd6; }
  :root:not([data-theme="dark"]) body.course .code:not(.cp .code) .fn { color: #1f5fbf; }
  :root:not([data-theme="dark"]) body.course .code:not(.cp .code) .number { color: #9a5b00; }
  :root:not([data-theme="dark"]) body.course .code:not(.cp .code) .comment { color: #6b7080; }
  :root:not([data-theme="dark"]) body.course .code:not(.cp .code) .past { color: #b4471f; }
}
:root[data-theme="light"] body.course .code:not(.cp .code) .kw { color: #7a3fd6; }
:root[data-theme="light"] body.course .code:not(.cp .code) .fn { color: #1f5fbf; }
:root[data-theme="light"] body.course .code:not(.cp .code) .number { color: #9a5b00; }
:root[data-theme="light"] body.course .code:not(.cp .code) .comment { color: #6b7080; }
:root[data-theme="light"] body.course .code:not(.cp .code) .past { color: #b4471f; }
.course .code pre { overflow-x: hidden; }
.course .code .ln { white-space: pre-wrap; overflow-wrap: anywhere; padding-left: calc(16px + 4ch); text-indent: -4ch; }
/* The parts list section: code and schematic side by side, stacked on a phone (code first). */
.course .cp-pair { display: grid; grid-template-columns: minmax(0, 4fr) minmax(0, 7fr); gap: 10px; margin: 0 0 16px; max-width: 1040px; }
.course .cp-pair .code { margin: 0; }
.course .cp-pair .cp-schem { --line: #262a36; --muted: #9aa0b2; color-scheme: dark; }
@media (max-width: 860px) { .course .cp-pair { grid-template-columns: minmax(0, 1fr); } }
.course .code pre code { min-width: 0; }
.course .pgrid .paper .pc-thumb { max-width: none; }
/* A heavy player playing its recording (course.js): a small note, and live on request. */
.cp-clipnote { margin: 0; padding: 0 14px 12px; font-size: 13.5px; color: var(--muted); display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; }
.cp-clipnote button { font: 600 13px/1 -apple-system, BlinkMacSystemFont, sans-serif; color: var(--text); background: var(--panel2); border: 1px solid var(--line); border-radius: 999px; padding: 6px 12px; cursor: pointer; }
.cp-clipnote button:hover { border-color: var(--part); }
