/* Study-guide chapter visuals (pilot design only; loaded on guide pages with design-pilot.css).
   1. Reading fixes   2. Mind map (.ma-mindmap)   3. Self-drawing diagrams (svg[data-draw]) and figure cards
   Every rule is scoped with .ma-guides:not(#ma-sg): the single :not(#id) lifts specificity above the site's
   long "body.ma-cp.ma-cp .site-inner ..." selectors without !important.
   All content is visible without JavaScript; guide-visuals.js only arms and plays the motion,
   and never does so under prefers-reduced-motion. */
.ma-guides {
  --gv-ink: #1A2B48; --gv-body: #3c4763; --gv-muted: #5a6482; --gv-line: #e3e7ef;
  --gv-1: var(--cp-lv, #6D5BD0); --gv-2: #8E7CF0; --gv-accent: #5b4fd6; --gv-pink: #d6457f;
  --gv-tint: var(--cp-lv-t, #EEEBFC); --gv-r: 12px; --gv-ease: cubic-bezier(.23, 1, .32, 1);
}

/* ---------- 1. Reading ---------- */
/* One marker: the theme's disc (and decimal) marker sat beside the guide's own dot (and number badge). */
.ma-guides:not(#ma-sg) .chapter :is(ul, ol) > li { list-style: none; }
/* A list straight after a heading or a sentence needs the same gap as a paragraph. */
.ma-guides:not(#ma-sg) .chapter .section > * + :is(ul, ol) { margin-top: 20px; }
.ma-guides:not(#ma-sg) .chapter :is(.concept, .warning, .worked-example) > * + :is(ul, ol) { margin-top: 12px; }
/* Keep short inline maths on one line on wider screens (phones already scroll long inline maths). */
@media (min-width: 601px) { .ma-guides:not(#ma-sg) .chapter p .katex { white-space: nowrap; } }
/* Line length: about 65 to 75 characters of Inter at 17 px. Cards and figures keep the full column. */
.ma-guides:not(#ma-sg) .chapter :is(.section, .worked-example, .concept, .warning) > :is(p, ul, ol) { max-width: 37em; }
/* Display maths: set flush left in one column with the prose, the same everywhere, so aligned
   working reads down the page instead of floating centred in the card. */
.ma-guides:not(#ma-sg) .chapter .katex-display { margin: 14px 0; padding: 4px 0; text-align: left; }
.ma-guides:not(#ma-sg) .chapter .katex-display > .katex { text-align: left; }
.ma-guides:not(#ma-sg) .chapter :is(.concept, .worked-example, .warning) > .katex-display { margin: 12px 0; }
.ma-guides:not(#ma-sg) .chapter :is(.concept, .worked-example, .warning) > .katex-display:last-child { margin-bottom: 0; }
/* Results laid out as two short lists (for example "In MF27" and "Not in MF27"). */
.ma-guides:not(#ma-sg) .ma-split-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr)); gap: 12px; margin-top: 16px; }
.ma-guides:not(#ma-sg) .ma-split-list > div { margin: 0; padding: 14px 16px; border-radius: var(--gv-r); background: rgba(255,255,255,.72); box-shadow: inset 0 0 0 1px rgba(124,101,241,.16); }
.ma-guides:not(#ma-sg) .ma-split-list .ma-split-head { margin: 0 0 6px; font-size: 14px; line-height: 1.4; font-weight: 650; color: var(--gv-1); }
.ma-guides:not(#ma-sg) .ma-split-list ul { display: grid; gap: 4px; margin: 0; padding: 0; }
.ma-guides:not(#ma-sg) .ma-split-list li { margin: 0; padding-left: 18px; font-size: 16px; line-height: 1.6; }
.ma-guides:not(#ma-sg) .ma-split-list li::before { left: 2px; top: .7em; width: 6px; height: 6px; }

/* ---------- 2. Mind map ----------
   Markup (data in the HTML, nothing generated but the connectors):
   div.ma-mindmap[data-mindmap] > p.ma-mm-label + ul.ma-mm-root > li.ma-mm-hub > p.ma-mm-topic + ul.ma-mm-branches > li.ma-mm-node*
   Each node: a[href="#section"] (the name), p.ma-mm-cue, p.ma-mm-eg; numbered in reading order by CSS.
   Narrow: the topic on top and a vertical tree. Wide (container >= 600 px): the topic on the left and the branches fanning out to the nodes. */
.ma-guides:not(#ma-sg) .ma-mindmap { container-type: inline-size; position: relative; margin-top: 24px; padding: 20px 20px 24px; border-radius: var(--gv-r);
  background: linear-gradient(180deg, #fbfaff, #f3f0ff); box-shadow: inset 0 0 0 1px #e6e1fb; }
.ma-guides:not(#ma-sg) .ma-mindmap :is(ul, li, p) { margin: 0; padding: 0; max-width: none; list-style: none; }
.ma-guides:not(#ma-sg) .ma-mindmap li::before { content: none; }
.ma-guides:not(#ma-sg) .ma-mindmap .ma-mm-label { font-size: 14px; line-height: 1.4; font-weight: 650; color: var(--gv-muted); }
.ma-guides:not(#ma-sg) .ma-mindmap .ma-mm-root { display: block; margin-top: 16px; }
.ma-guides:not(#ma-sg) .ma-mindmap .ma-mm-hub { position: relative; padding: 0; font-size: 16px; }
.ma-guides:not(#ma-sg) .ma-mindmap .ma-mm-topic { position: relative; z-index: 1; display: inline-flex; align-items: center; min-height: 48px; padding: 8px 22px; border-radius: 999px;
  background: linear-gradient(120deg, #4b3fc0, var(--gv-1) 55%, var(--gv-2)); color: #fff; font-size: 20px; line-height: 1.2; font-weight: 650; letter-spacing: -0.01em;
  box-shadow: 0 12px 28px -14px rgba(91,79,214,.9); }
.ma-guides:not(#ma-sg) .ma-mindmap .ma-mm-branches { counter-reset: mm; display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; margin-top: 16px; padding-left: 28px; }
.ma-guides:not(#ma-sg) .ma-mindmap:not(.mm-js) .ma-mm-branches { border-left: 2px solid #d9d2fb; margin-left: 13px; padding-left: 15px; }
.ma-guides:not(#ma-sg) .ma-mindmap .ma-mm-node { counter-increment: mm; position: relative; z-index: 1; min-width: 0; padding: 12px 16px 13px 50px; border-radius: var(--gv-r); background: #fff;
  box-shadow: 0 0 0 1px var(--gv-line), 0 16px 32px -26px rgba(26,43,72,.5); transition: box-shadow .2s ease; font-size: 16px; line-height: 1.5; color: var(--gv-body); }
.ma-guides:not(#ma-sg) .ma-mindmap .ma-mm-node::before { content: counter(mm); position: absolute; left: 14px; top: 12px; width: 26px; height: 26px; border-radius: 50%;
  display: grid; place-items: center; font-size: 13px; font-weight: 700; line-height: 1; color: var(--gv-accent); background: var(--gv-tint); font-variant-numeric: tabular-nums; }
.ma-guides:not(#ma-sg) .ma-mindmap .ma-mm-node:hover { box-shadow: 0 0 0 1px #c9c0f7, 0 16px 32px -22px rgba(26,43,72,.55); }
.ma-guides:not(#ma-sg) .ma-mindmap .ma-mm-node:focus-within { box-shadow: 0 0 0 2px var(--gv-accent), 0 16px 32px -22px rgba(26,43,72,.55); }
.ma-guides:not(#ma-sg) .ma-mindmap .ma-mm-node > a { display: block; font-size: 16px; line-height: 1.4; font-weight: 650; color: var(--gv-ink); text-decoration: none; }
.ma-guides:not(#ma-sg) .ma-mindmap .ma-mm-node > a::after { content: ""; position: absolute; inset: 0; border-radius: var(--gv-r); }
.ma-guides:not(#ma-sg) .ma-mindmap .ma-mm-node > a:focus-visible { outline: none; }
.ma-guides:not(#ma-sg) .ma-mindmap .ma-mm-cue { margin-top: 4px; font-size: 15px; line-height: 1.5; color: var(--gv-body); }
.ma-guides:not(#ma-sg) .ma-mindmap .ma-mm-eg { margin-top: 6px; font-size: 15px; line-height: 1.5; color: var(--gv-muted); }
.ma-guides:not(#ma-sg) .ma-mindmap .ma-mm-eg .katex { font-size: 1em; color: var(--gv-ink); }
.ma-guides:not(#ma-sg) .ma-mindmap .ma-mm-links { position: absolute; left: 0; top: 0; z-index: 0; overflow: visible; pointer-events: none; }
.ma-guides:not(#ma-sg) .ma-mindmap .ma-mm-links path { fill: none; stroke-width: 2; stroke-linecap: round; }

@container (min-width: 600px) {
  /* Wide: the topic on the left, the branches fanning out to a column of nodes in reading order. */
  .ma-guides:not(#ma-sg) .ma-mindmap .ma-mm-hub { --mm-radial: 1; }
  .ma-guides:not(#ma-sg) .ma-mindmap .ma-mm-topic { position: absolute; left: 0; top: 50%; transform: translateY(-50%); }
  .ma-guides:not(#ma-sg) .ma-mindmap .ma-mm-branches { gap: 10px; margin-top: 0; padding-left: 216px; }
  .ma-guides:not(#ma-sg) .ma-mindmap .ma-mm-node { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 13rem); column-gap: 20px; align-items: center; }
  .ma-guides:not(#ma-sg) .ma-mindmap .ma-mm-node > a { grid-column: 1 / -1; }
  .ma-guides:not(#ma-sg) .ma-mindmap .ma-mm-eg { margin-top: 4px; }
}

/* Motion states: only while guide-visuals.js has armed the map (never with reduced motion or without JS). */
.ma-guides:not(#ma-sg) .ma-mindmap.mm-armed .ma-mm-topic { opacity: 0; scale: .86; }
.ma-guides:not(#ma-sg) .ma-mindmap.mm-armed .ma-mm-node { opacity: 0; translate: 0 10px; }
.ma-guides:not(#ma-sg) .ma-mindmap.mm-armed .ma-mm-node.mm-left { translate: 14px 0; }
.ma-guides:not(#ma-sg) .ma-mindmap.mm-armed .ma-mm-node.mm-right { translate: -14px 0; }
.ma-guides:not(#ma-sg) .ma-mindmap.mm-armed .ma-mm-links path { opacity: 0; stroke-dasharray: 1; stroke-dashoffset: 1; }
.ma-guides:not(#ma-sg) .ma-mindmap.mm-armed .ma-mm-topic.on { opacity: 1; scale: 1; transition: opacity .35s ease, scale .55s cubic-bezier(.3,1.5,.5,1); }
.ma-guides:not(#ma-sg) .ma-mindmap.mm-armed .ma-mm-node.on { opacity: 1; translate: 0 0; transition: opacity .4s ease, translate .6s var(--gv-ease), box-shadow .2s ease; }
.ma-guides:not(#ma-sg) .ma-mindmap.mm-armed .ma-mm-links path.on { opacity: 1; stroke-dashoffset: 0; transition: stroke-dashoffset .5s cubic-bezier(.45,.05,.3,1); }

/* ---------- 2b. Two-level mind map (the standard from 6 Nov) ----------
   ul.ma-mm-root > li.ma-mm-hub > p.ma-mm-topic + ul.ma-mm-trunks > li.ma-mm-trunk >
   p.ma-mm-trunk-label + ul.ma-mm-branches > li.ma-mm-node[data-n] (a, p.ma-mm-cue, p.ma-mm-key or .ma-key).
   data-n is the section number shown in the badge, so grouping can change the order. */
.ma-guides:not(#ma-sg) .ma-mindmap .ma-mm-trunks { display: grid; gap: 18px; margin-top: 14px; padding-left: 20px; }
.ma-guides:not(#ma-sg) .ma-mindmap:not(.mm-js) .ma-mm-trunks { border-left: 2px solid #d9d2fb; margin-left: 13px; padding-left: 15px; }
.ma-guides:not(#ma-sg) .ma-mindmap .ma-mm-trunk { position: relative; padding: 0; }
.ma-guides:not(#ma-sg) .ma-mindmap .ma-mm-trunk-label { position: relative; z-index: 1; display: inline-flex; align-items: center; min-height: 36px; padding: 6px 14px; border-radius: var(--gv-r);
  background: var(--gv-tint); color: #4a3fc0; font-size: 15px; line-height: 1.3; font-weight: 650; box-shadow: inset 0 0 0 1px #ddd5fb; }
.ma-guides:not(#ma-sg) .ma-mindmap .ma-mm-trunk .ma-mm-branches { margin-top: 10px; padding-left: 24px; gap: 10px; }
.ma-guides:not(#ma-sg) .ma-mindmap:not(.mm-js) .ma-mm-trunk .ma-mm-branches { margin-left: 13px; padding-left: 15px; }
.ma-guides:not(#ma-sg) .ma-mindmap .ma-mm-trunk .ma-mm-node { display: block; }
.ma-guides:not(#ma-sg) .ma-mindmap .ma-mm-trunk .ma-mm-node::before { content: attr(data-n); }
.ma-guides:not(#ma-sg) .ma-mindmap .ma-mm-node .ma-key { margin-top: 6px; }
@container (min-width: 600px) {
  /* Wide: three columns, topic | trunks | leaves. */
  .ma-guides:not(#ma-sg) .ma-mindmap .ma-mm-hub:has(> .ma-mm-trunks) > .ma-mm-topic { max-width: 118px; text-align: center; justify-content: center; padding: 8px 16px; font-size: 18px; }
  .ma-guides:not(#ma-sg) .ma-mindmap .ma-mm-trunks { margin-top: 0; padding-left: 150px; gap: 22px; }
  /* Long topic names (data-long on the topic): a smaller pill and a wider first column. Added for v6. */
  .ma-guides:not(#ma-sg) .ma-mindmap .ma-mm-hub:has(> .ma-mm-trunks) > .ma-mm-topic[data-long] { max-width: 136px; padding: 8px 10px; font-size: 15px; }
  .ma-guides:not(#ma-sg) .ma-mindmap .ma-mm-hub:has(> .ma-mm-topic[data-long]) > .ma-mm-trunks { padding-left: 166px; }
  .ma-guides:not(#ma-sg) .ma-mindmap .ma-mm-trunk { display: grid; grid-template-columns: 124px minmax(0, 1fr); column-gap: 40px; align-items: center; }
  .ma-guides:not(#ma-sg) .ma-mindmap .ma-mm-trunk-label { justify-self: start; }
  .ma-guides:not(#ma-sg) .ma-mindmap .ma-mm-trunk .ma-mm-branches { margin-top: 0; padding-left: 0; }
}
.ma-guides:not(#ma-sg) .ma-mindmap.mm-armed .ma-mm-trunk-label { opacity: 0; scale: .85; }
.ma-guides:not(#ma-sg) .ma-mindmap.mm-armed .ma-mm-trunk-label.on { opacity: 1; scale: 1; transition: opacity .3s ease, scale .5s cubic-bezier(.3,1.5,.5,1); }

/* ---------- 4. Key ideas (.ma-key[data-key]) ----------
   data-key: sequence (mnemonic letters unfold), morph (A then arrow then B), split (a whole, then its parts),
   pair (highlight matching parts). Children: [data-k="n"] appear in order; [data-mark="n"] are visible and get
   a marker sweep in order. .ma-key-letter > b + span unfolds a mnemonic letter into its word.
   Only while armed by guide-visuals.js is anything hidden; the static markup is the final frame. */
.ma-guides:not(#ma-sg) .ma-key { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; margin: 0; max-width: none; font-size: 15px; line-height: 1.5; color: var(--gv-ink); }
.ma-guides:not(#ma-sg) .ma-key > * { white-space: nowrap; }
.ma-guides:not(#ma-sg) .ma-key[data-key="pair"] { gap: 4px 3px; }
.ma-guides:not(#ma-sg) .ma-key[data-key="pair"] > .ma-key-word { margin-left: 8px; }
.ma-guides:not(#ma-sg) .chapter p.ma-key { font-size: 15px; line-height: 1.5; color: var(--gv-ink); max-width: none; }
.ma-guides:not(#ma-sg) .ma-key .katex { font-size: 1.04em; }
.ma-guides:not(#ma-sg) .ma-key .ma-key-arrow { color: var(--gv-accent); font-weight: 600; }
.ma-guides:not(#ma-sg) .ma-key .ma-key-word { color: var(--gv-muted); font-size: 1em; }
.ma-guides:not(#ma-sg) .ma-key .ma-key-to { padding: 0 .3em; border-radius: 6px; background: rgba(124,101,241,.12); }
.ma-guides:not(#ma-sg) .ma-key .ma-key-letter > b { display: inline-grid; place-items: center; min-width: 1.45em; height: 1.45em; margin-right: 2px; border-radius: 6px;
  background: linear-gradient(135deg, #4b3fc0, #8E7CF0); color: #fff; font-size: max(.9em, 14px); font-weight: 700; line-height: 1; }
.ma-guides:not(#ma-sg) .ma-key .ma-key-letter > span { display: inline-block; overflow: hidden; vertical-align: bottom; max-width: 10em; }
.ma-guides:not(#ma-sg) .ma-key .ma-key-mark { padding: 0 .15em; border-radius: 4px; background: linear-gradient(rgba(124,101,241,.24), rgba(124,101,241,.24)) no-repeat 0 0 / 100% 100%; }
.ma-guides:not(#ma-sg) .ma-key .ma-key-mark[data-tone="pink"] { background-image: linear-gradient(rgba(236,118,176,.3), rgba(236,118,176,.3)); }
.ma-guides:not(#ma-sg) .ma-key.key-armed [data-k] { opacity: 0; translate: 0 5px; }
.ma-guides:not(#ma-sg) .ma-key.key-armed [data-k].on { opacity: 1; translate: 0 0; transition: opacity .3s ease, translate .4s var(--gv-ease); }
.ma-guides:not(#ma-sg) .ma-key.key-armed .ma-key-letter > b { scale: .5; }
.ma-guides:not(#ma-sg) .ma-key.key-armed .ma-key-letter.on > b { scale: 1; transition: scale .35s cubic-bezier(.3,1.6,.5,1); }
.ma-guides:not(#ma-sg) .ma-key.key-armed .ma-key-letter > span { max-width: 0; }
.ma-guides:not(#ma-sg) .ma-key.key-armed .ma-key-letter.on > span { max-width: 10em; transition: max-width .5s ease .12s; }
.ma-guides:not(#ma-sg) .ma-key.key-armed [data-mark] { background-size: 0% 100%; }
.ma-guides:not(#ma-sg) .ma-key.key-armed [data-mark].on { background-size: 100% 100%; transition: background-size .5s ease; }
.ma-guides:not(#ma-sg) .ma-key.key-snap, .ma-guides:not(#ma-sg) .ma-key.key-snap * { transition: none !important; }
/* Section banner: the same key idea at a readable size, compact. */
.ma-guides:not(#ma-sg) .chapter .ma-key-banner { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 16px; margin-top: 16px; padding: 12px 18px; border-radius: var(--gv-r);
  background: linear-gradient(120deg, #f4f1ff, #fbfaff 70%); box-shadow: inset 0 0 0 1px #e6e1fb; }
.ma-guides:not(#ma-sg) .chapter .ma-key-banner .ma-key-label { margin: 0; font-size: 13px; line-height: 1.4; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--gv-1); }
.ma-guides:not(#ma-sg) .chapter .ma-key-banner .ma-key, .ma-guides:not(#ma-sg) .chapter .ma-key-banner p.ma-key { margin: 0; font-size: 19px; gap: 6px 10px; }
.ma-guides:not(#ma-sg) .chapter .ma-key-banner .ma-key + .ma-key { flex-basis: 100%; padding-left: 0; }
@media (max-width: 600px) { .ma-guides:not(#ma-sg) .chapter .ma-key-banner .ma-key, .ma-guides:not(#ma-sg) .chapter .ma-key-banner p.ma-key { font-size: 17px; } }
@media (prefers-reduced-motion: reduce) { .ma-guides:not(#ma-sg) .ma-key * { transition: none !important; } }

/* ---------- 3. Figure cards and self-drawing diagrams ---------- */
.ma-guides:not(#ma-sg) .chapter .ma-figure { margin: 24px 0 0; padding: 24px 24px 20px; border-radius: var(--gv-r); background: #fff; position: relative; overflow: hidden;
  box-shadow: 0 0 0 1px var(--gv-line), 0 30px 60px -44px rgba(26,43,72,.5); }
.ma-guides:not(#ma-sg) .chapter .ma-figure::before { content: ""; position: absolute; inset: 0 0 auto 0; height: 4px; background: linear-gradient(90deg, #4b3fc0, var(--gv-1) 35%, var(--gv-2) 70%, #EC76B0); }
.ma-guides:not(#ma-sg) .chapter .ma-figure .visual { margin: 0; }
.ma-guides:not(#ma-sg) .chapter .ma-figure .visual .diagram-scroll { max-width: 520px; margin: 0 auto; padding: 0; border: 0; border-radius: var(--gv-r); background: none; box-shadow: none; overflow: visible; }
.ma-guides:not(#ma-sg) .chapter .ma-figure .visual svg { display: block; width: 100%; height: auto; min-width: 0; }
.ma-guides:not(#ma-sg) .chapter .ma-figure [data-controls] { display: flex; align-items: center; gap: 16px; max-width: 520px; margin: 16px auto 0; }
.ma-guides:not(#ma-sg) .chapter .ma-figure [data-controls][hidden] { display: none; }
.ma-guides:not(#ma-sg) .chapter .ma-figure [data-controls] label { flex: none; margin: 0; font-size: 15px; font-weight: 600; color: var(--gv-ink); }
.ma-guides:not(#ma-sg) .chapter .ma-figure [data-controls] input[type=range] { flex: 1; min-width: 0; margin: 0; accent-color: var(--gv-accent); }
.ma-guides:not(#ma-sg) .chapter .ma-figure [data-status] { max-width: 520px; margin: 10px auto 0; font-size: 15px; line-height: 1.55; color: var(--gv-muted); font-variant-numeric: tabular-nums; }

/* Armed diagram: every step is hidden until its turn, so nothing shows half formed. */
.ma-guides:not(#ma-sg) :is(.chapter, .ma-guide-art) svg.mad-armed [data-step] { opacity: 0; }
.ma-guides:not(#ma-sg) :is(.chapter, .ma-guide-art) svg.mad-armed [data-anim="stroke"] { stroke-dasharray: 1; stroke-dashoffset: 1; }
.ma-guides:not(#ma-sg) :is(.chapter, .ma-guide-art) svg.mad-armed [data-anim="pop"] { transform-box: fill-box; transform-origin: 50% 50%; scale: .7; }
.ma-guides:not(#ma-sg) :is(.chapter, .ma-guide-art) svg.mad-armed [data-step].on { opacity: 1; transition: opacity .4s ease; }
.ma-guides:not(#ma-sg) :is(.chapter, .ma-guide-art) svg.mad-armed [data-anim="stroke"].on { stroke-dashoffset: 0; transition: stroke-dashoffset var(--mad-dur, .9s) cubic-bezier(.45,.05,.3,1); }
.ma-guides:not(#ma-sg) :is(.chapter, .ma-guide-art) svg.mad-armed [data-anim="pop"].on { scale: 1; transition: opacity .3s ease, scale .5s cubic-bezier(.3,1.6,.5,1); }
.ma-guides:not(#ma-sg) :is(.chapter, .ma-guide-art) svg.mad-armed [data-anim="sweep"].on { transition: none; }

@media (max-width: 600px) {
  .ma-guides:not(#ma-sg) .chapter :is(.concept, .warning) { padding-left: 18px; padding-right: 16px; }
  .ma-guides:not(#ma-sg) .ma-mindmap { padding: 16px 14px 18px; }
  .ma-guides:not(#ma-sg) .chapter .ma-figure { padding: 20px 12px 16px; }
  .ma-guides:not(#ma-sg) .chapter .ma-figure [data-controls] { flex-wrap: wrap; gap: 6px 12px; }
  .ma-guides:not(#ma-sg) .chapter .ma-figure [data-controls] input[type=range] { flex-basis: 100%; }
}
@media (prefers-reduced-motion: reduce) {
  .ma-guides:not(#ma-sg) .ma-mindmap *, .ma-guides:not(#ma-sg) :is(.chapter, .ma-guide-art) svg[data-draw] * { transition: none !important; }
}
