(function injectGuideCss() {
  let st = document.getElementById('cg-css');
  if (!st) { st = document.createElement('style'); st.id = 'cg-css'; }
  st.textContent = `
.cg-stage{position:relative;width:100%;aspect-ratio:16/8;border-radius:14px;overflow:hidden;background:linear-gradient(160deg,#EEF1F6,#E3E8F0);border:1px solid var(--border-default)}
.cg-page{position:absolute;background:white;box-shadow:0 8px 24px rgba(14,34,71,.16);border-radius:4px}
.cg-chip{position:absolute;display:flex;align-items:center;gap:6px;height:26px;padding:0 10px;border-radius:7px;background:white;border:1px solid #d5dbe5;font:600 11px var(--font-body);color:#0E2247;white-space:nowrap;box-shadow:0 2px 6px rgba(14,34,71,.08)}
.cg-side{position:absolute;left:0;top:0;bottom:0;width:26%;background:white;border-right:1px solid #dde2ea;padding:10px;box-sizing:border-box;display:flex;flex-direction:column;gap:7px}
.cg-bar{height:8px;border-radius:4px;background:#dfe4ec}
.cg-cursor{position:absolute;width:18px;height:18px;z-index:5;pointer-events:none}
.cg-pink{position:absolute;background:#E0408A}
@keyframes cgDragChip{0%,12%{left:5%;top:30%;opacity:1;transform:scale(1)}18%{transform:scale(1.06);box-shadow:0 10px 22px rgba(14,34,71,.25)}55%{left:52%;top:46%;opacity:1;transform:scale(1.06)}62%,100%{left:52%;top:46%;opacity:0;transform:scale(.9)}}
@keyframes cgDragCursor{0%,12%{left:11%;top:36%}55%{left:58%;top:52%}62%,100%{left:58%;top:52%;opacity:1}100%{opacity:1}}
@keyframes cgDropEl{0%,58%{opacity:0;transform:scale(.85)}66%,92%{opacity:1;transform:scale(1)}100%{opacity:0}}
@keyframes cgSlide{0%,10%{left:24%}50%,80%{left:calc(50% - 15%)}100%{left:24%}}
@keyframes cgGuide{0%,44%{opacity:0}50%,80%{opacity:1}86%,100%{opacity:0}}
@keyframes cgNames{0%,4%{opacity:0;transform:translateY(6px)}8%,28%{opacity:1;transform:none}33%,100%{opacity:0;transform:translateY(-6px)}}
@keyframes cgDraw{0%{stroke-dashoffset:520}60%,85%{stroke-dashoffset:0}100%{stroke-dashoffset:0;opacity:0}}
@keyframes cgScheme{0%,22%{--cgD:#0E2247;--cgA:#F49B52}33%,55%{--cgD:#2B2414;--cgA:#B8892B}66%,88%{--cgD:#0F3B3A;--cgA:#D9A55B}100%{--cgD:#0E2247;--cgA:#F49B52}}
@keyframes cgSwapA{0%,30%{transform:translateY(0)}45%,85%{transform:translateY(calc(100% + 8px))}100%{transform:translateY(0)}}
@keyframes cgSwapB{0%,30%{transform:translateY(0)}45%,85%{transform:translateY(calc(-100% - 8px))}100%{transform:translateY(0)}}
@keyframes cgFan{0%,15%{transform:translate(0,0) rotate(0);opacity:0}25%{opacity:1}55%,85%{transform:translate(var(--fx),var(--fy)) rotate(var(--fr));opacity:1}100%{opacity:0}}
@keyframes cgPop{0%,60%{opacity:0;transform:scale(.6)}70%,90%{opacity:1;transform:scale(1)}100%{opacity:0}}
@keyframes cgFilter{0%,25%{opacity:1;transform:none}40%,75%{opacity:.15;transform:scale(.94)}90%,100%{opacity:1;transform:none}}
@keyframes cgPillOn{0%,25%{background:white;color:#0E2247}40%,75%{background:#0E2247;color:white}90%,100%{background:white;color:#0E2247}}
@keyframes cgRowIn{from{opacity:0;transform:translateX(-10px)}to{opacity:1;transform:none}}
@keyframes cgWarn{0%,30%{opacity:0;transform:scale(.6)}38%,62%{opacity:1;transform:scale(1)}70%,100%{opacity:0;transform:scale(.6)}}
@keyframes cgOk{0%,64%{opacity:0;transform:scale(.6)}72%,95%{opacity:1;transform:scale(1)}100%{opacity:0}}
@keyframes cgShrink{0%,30%{font-size:15px;letter-spacing:0}45%,85%{font-size:10px}100%{font-size:15px}}
@keyframes cgPulse{0%,100%{box-shadow:0 0 0 0 color-mix(in srgb,var(--brand-primary) 45%,transparent)}50%{box-shadow:0 0 0 8px transparent}}
@keyframes cgFadeIn{from{opacity:0;transform:translateY(10px)}to{opacity:1;transform:none}}
.cg-topic{animation:cgFadeIn .28s cubic-bezier(.2,.8,.2,1) both}
.cg-navbtn{transition:background-color .18s ease,color .18s ease}
.cg-navbtn:hover{background:color-mix(in srgb,var(--navy-700) 7%,white)!important}
.cg-fab{transition:transform .18s cubic-bezier(.2,.8,.2,1),box-shadow .2s ease,background-color .2s ease}
.cg-fab:hover{transform:translateY(-2px) scale(1.04);box-shadow:0 12px 26px rgba(14,34,71,.32)!important}
.cg-fab:active{transform:scale(.95)}
@keyframes cgStep{0%,8%{opacity:.25;transform:scale(.92)}14%,30%{opacity:1;transform:scale(1)}36%,100%{opacity:.25;transform:scale(.92)}}
@keyframes cgFlow{0%{left:12%;opacity:0}8%{opacity:1}33%{left:42%}66%{left:72%}90%{opacity:1}100%{left:80%;opacity:0}}
@keyframes cgPick{0%,20%{transform:none;box-shadow:0 2px 8px rgba(14,34,71,.12);border-color:#dde2ea}30%,55%{transform:translateY(-6px) scale(1.06);box-shadow:0 14px 28px rgba(14,34,71,.25);border-color:var(--brand-primary)}70%,100%{transform:none;box-shadow:0 2px 8px rgba(14,34,71,.12);border-color:#dde2ea}}
@keyframes cgPickCursor{0%{left:20%;top:80%}25%,55%{left:47%;top:52%}100%{left:20%;top:80%}}
@keyframes cgPress{0%,30%{transform:none;filter:none}36%{transform:scale(.94);filter:brightness(.92)}44%,100%{transform:none;filter:none}}
@keyframes cgToCursor{0%,10%{left:20%;top:85%}32%,60%{left:64%;top:66%}100%{left:20%;top:85%}}
@keyframes cgToast{0%,40%{opacity:0;transform:translateY(8px)}48%,80%{opacity:1;transform:none}90%,100%{opacity:0}}
@keyframes cgPaper{0%,25%{width:52%;height:66%;left:24%;top:17%}40%,75%{width:30%;height:80%;left:35%;top:10%}90%,100%{width:52%;height:66%;left:24%;top:17%}}
@keyframes cgSafe{0%,20%{opacity:0}30%,90%{opacity:1}100%{opacity:0}}
@keyframes cgEdgeWarn{0%,45%{opacity:0;transform:scale(.6)}52%,80%{opacity:1;transform:scale(1)}88%,100%{opacity:0}}
@keyframes cgLockShackle{0%,25%{transform:translateY(-6px)}35%,85%{transform:none}95%,100%{transform:translateY(-6px)}}
@keyframes cgShake{0%,40%,60%,100%{transform:none}44%{transform:translateX(-5px)}48%{transform:translateX(5px)}52%{transform:translateX(-4px)}56%{transform:translateX(3px)}}
@keyframes cgRetype{0%,62%{opacity:1}66%{opacity:0}70%,100%{opacity:1}}
@keyframes cgRetype2{0%,62%{opacity:0}66%{opacity:0}70%,96%{opacity:1}100%{opacity:0}}
@keyframes cgCutIn{0%,20%{opacity:0}30%,100%{opacity:1}}
@keyframes cgTick{0%,50%{opacity:0;transform:scale(.4)}60%,92%{opacity:1;transform:scale(1)}100%{opacity:0}}
@keyframes cgMorph{0%,18%{width:46%;height:58%;left:27%;top:14%;border-radius:4px}25%,43%{width:22%;height:72%;left:39%;top:10%;border-radius:10px}50%,68%{width:40%;height:48%;left:30%;top:22%;border-radius:4px}75%,93%{width:30%;height:80%;left:35%;top:8%;border-radius:2px}100%{width:46%;height:58%;left:27%;top:14%;border-radius:4px}}
@keyframes cgLbl{0%,4%{opacity:0;transform:translateY(6px)}8%,20%{opacity:1;transform:none}24%,100%{opacity:0}}
@keyframes cgKey{0%,10%{transform:none;box-shadow:0 4px 0 #b8c0cc}16%,30%{transform:translateY(3px);box-shadow:0 1px 0 #b8c0cc;background:#fff3e8}36%,100%{transform:none;box-shadow:0 4px 0 #b8c0cc}}
@keyframes cgKeyLbl{0%,12%{opacity:0}18%,30%{opacity:1}36%,100%{opacity:0}}
@media (prefers-reduced-motion:reduce){.cg-stage *{animation-duration:0s!important;animation-iteration-count:1!important}}
@media (max-width:760px){.cg-body{grid-template-columns:minmax(0,1fr)!important}.cg-nav{display:none!important}.cg-navsel{display:block!important}}
`;
  if (!st.parentNode) document.head.appendChild(st);
})();

const CG_LOOP = 'infinite';
function CgCursor({ anim }) {
  return <svg className="cg-cursor" viewBox="0 0 20 20" style={{ animation: anim }}><path d="M3 2l13 7-6 1.5L7.5 17z" fill="#0E2247" stroke="white" strokeWidth="1.2" strokeLinejoin="round" /></svg>;
}
function CgPage({ style, children }) { return <div className="cg-page" style={style}>{children}</div>; }

function CgDemo({ kind }) {
  const t = '4.2s ' + 'cubic-bezier(.45,.05,.3,1) ' + CG_LOOP;
  if (kind === 'drag') return (
    <div className="cg-stage">
      <div className="cg-side"><div style={{ font: '700 9px var(--font-body)', color: '#7A8699', letterSpacing: '.08em' }}>ELEMENTS</div>{[0, 1, 2, 3].map((i) => <div key={i} className="cg-bar" style={{ width: (85 - i * 12) + '%' }}></div>)}</div>
      <CgPage style={{ left: '34%', top: '14%', width: '58%', height: '72%' }}>
        <div style={{ position: 'absolute', left: '28%', top: '40%', width: '44%', height: 22, borderRadius: 4, border: '1.5px dashed var(--brand-primary)', background: 'color-mix(in srgb, var(--brand-primary) 8%, white)', display: 'flex', alignItems: 'center', justifyContent: 'center', font: '700 11px var(--font-display)', color: '#0E2247', animation: 'cgDropEl ' + t }}>Attendee name</div>
      </CgPage>
      <div className="cg-chip" style={{ animation: 'cgDragChip ' + t }}>＋ Attendee name</div>
      <CgCursor anim={'cgDragCursor ' + t} />
    </div>
  );
  if (kind === 'snap') return (
    <div className="cg-stage">
      <CgPage style={{ left: '12%', top: '10%', width: '76%', height: '80%' }}>
        <div className="cg-pink" style={{ left: '50%', top: 0, bottom: 0, width: 1.5, animation: 'cgGuide 4s ease ' + CG_LOOP }}></div>
        <div style={{ position: 'absolute', top: '36%', width: '30%', height: '24%', borderRadius: 4, background: '#0E2247', animation: 'cgSlide 4s cubic-bezier(.45,.05,.3,1) ' + CG_LOOP }}></div>
        <div style={{ position: 'absolute', left: '8%', top: '70%', width: '18%', height: '12%', borderRadius: 3, background: '#F49B52' }}></div>
        <div style={{ position: 'absolute', right: '8%', top: '70%', width: '18%', height: '12%', borderRadius: 3, background: '#F49B52' }}></div>
        <div style={{ position: 'absolute', left: '50%', top: '18%', transform: 'translateX(-50%)', background: '#E0408A', color: 'white', font: '700 9px var(--font-body)', padding: '2px 6px', borderRadius: 4, animation: 'cgGuide 4s ease ' + CG_LOOP }}>Centre</div>
      </CgPage>
    </div>
  );
  if (kind === 'fields') return (
    <div className="cg-stage">
      <CgPage style={{ left: '14%', top: '12%', width: '72%', height: '76%', border: '6px double #0E2247', boxSizing: 'border-box' }}>
        <div style={{ position: 'absolute', top: '16%', width: '100%', textAlign: 'center', font: '700 9px var(--font-body)', letterSpacing: '.18em', color: '#A8500E' }}>CERTIFICATE OF COMPLETION</div>
        <div style={{ position: 'absolute', top: '40%', width: '100%', height: 30 }}>
          {['Juan Dela Cruz', 'Maria Clara Santos', 'Jose P. Rizal III'].map((n, i) => <div key={n} style={{ position: 'absolute', inset: 0, textAlign: 'center', font: '700 20px "Playfair Display", serif', color: '#0E2247', opacity: 0, animation: 'cgNames 6s ease ' + (i * 2) + 's ' + CG_LOOP }}>{n}</div>)}
        </div>
        <div style={{ position: 'absolute', top: '66%', width: '100%', textAlign: 'center', font: '500 10px var(--font-body)', color: '#555' }}>Integrated Movement Coach · Day 1</div>
      </CgPage>
      <div className="cg-chip" style={{ left: '4%', bottom: '8%', background: 'color-mix(in srgb, var(--brand-primary) 12%, white)', borderColor: 'transparent' }}>Filled in for every attendee</div>
    </div>
  );
  if (kind === 'signature') return (
    <div className="cg-stage" style={{ background: 'white' }}>
      <svg viewBox="0 0 400 200" style={{ position: 'absolute', inset: 0, width: '100%', height: '100%' }}>
        <line x1="60" y1="150" x2="340" y2="150" stroke="#c4cad3" strokeDasharray="5 5" />
        <path d="M70 132c18-50 34-62 40-44s-14 54 0 44 26-58 34-40-6 38 10 30 18-36 30-22 4 28 20 18 28-30 40-14 20 4 40-6 30-6 50 2" fill="none" stroke="#0E2247" strokeWidth="3.4" strokeLinecap="round" strokeLinejoin="round" strokeDasharray="520" style={{ animation: 'cgDraw 3.6s ease-in-out ' + CG_LOOP }} />
      </svg>
      <div style={{ position: 'absolute', left: 0, right: 0, bottom: '9%', textAlign: 'center', font: '600 11px var(--font-body)', color: '#7A8699' }}>Sign with a mouse, finger or stylus</div>
    </div>
  );
  if (kind === 'colors') return (
    <div className="cg-stage">
      <CgPage style={{ left: '18%', top: '12%', width: '64%', height: '76%', overflow: 'hidden', animation: 'cgScheme 7s steps(1) ' + CG_LOOP }}>
        <div style={{ position: 'absolute', inset: 0, background: 'var(--cgD, #0E2247)', transition: 'background .5s ease' }}></div>
        <div style={{ position: 'absolute', inset: '9%', border: '1.5px solid var(--cgA, #F49B52)', borderRadius: 3, transition: 'border-color .5s ease' }}></div>
        <div style={{ position: 'absolute', top: '30%', width: '100%', textAlign: 'center', font: '700 9px var(--font-body)', letterSpacing: '.18em', color: 'var(--cgA, #F49B52)', transition: 'color .5s ease' }}>CERTIFICATE</div>
        <div style={{ position: 'absolute', top: '44%', width: '100%', textAlign: 'center', font: '700 18px "Playfair Display", serif', color: 'white' }}>Juan Dela Cruz</div>
        <div style={{ position: 'absolute', left: '40%', right: '40%', top: '66%', height: 2, background: 'var(--cgA, #F49B52)', transition: 'background .5s ease' }}></div>
      </CgPage>
      <div style={{ position: 'absolute', left: '4%', bottom: '8%', display: 'flex', gap: 5 }}>{[['#0E2247', '#F49B52'], ['#2B2414', '#B8892B'], ['#0F3B3A', '#D9A55B']].map((p, i) => <span key={i} className="cg-chip" style={{ position: 'static', gap: 3, padding: '0 6px' }}><i style={{ width: 10, height: 10, borderRadius: '50%', background: p[0] }}></i><i style={{ width: 10, height: 10, borderRadius: '50%', background: p[1] }}></i></span>)}</div>
    </div>
  );
  if (kind === 'layers') return (
    <div className="cg-stage">
      <div style={{ position: 'absolute', left: '20%', right: '20%', top: '16%', display: 'flex', flexDirection: 'column', gap: 8 }}>
        {[['Heading', 'cgSwapA'], ['Attendee name', 'cgSwapB'], ['Gold seal', ''], ['Background frame', '']].map(([n, a], i) => (
          <div key={n} style={{ height: 30, borderRadius: 8, background: 'white', border: '1px solid ' + (a === 'cgSwapA' ? 'var(--brand-primary)' : '#d5dbe5'), display: 'flex', alignItems: 'center', gap: 8, padding: '0 10px', font: '600 11px var(--font-body)', color: '#0E2247', boxShadow: a === 'cgSwapA' ? '0 8px 18px rgba(14,34,71,.16)' : 'none', position: 'relative', zIndex: a === 'cgSwapA' ? 2 : 1, animation: a ? a + ' 4.4s cubic-bezier(.45,.05,.3,1) ' + CG_LOOP : 'none' }}>
            <span style={{ color: '#9aa3b2', letterSpacing: 1 }}>⋮⋮</span>{n}<span style={{ flex: 1 }}></span><span style={{ color: '#9aa3b2' }}>👁</span>
          </div>
        ))}
      </div>
    </div>
  );
  if (kind === 'versions') return (
    <div className="cg-stage" style={{ background: 'white' }}>
      <div style={{ position: 'absolute', left: '10%', right: '10%', top: '12%', display: 'flex', flexDirection: 'column', gap: 7 }}>
        {[['v3', 'Fixed the coach’s name', true], ['v2', 'New gold frame', false], ['v1', 'First version', false]].map(([v, note, cur], i) => (
          <div key={v} style={{ display: 'flex', alignItems: 'center', gap: 10, height: 34, padding: '0 10px', borderRadius: 8, border: '1px solid ' + (cur ? 'color-mix(in srgb, var(--brand-primary) 45%, white)' : '#dde2ea'), background: cur ? 'color-mix(in srgb, var(--brand-primary) 6%, white)' : 'white', animation: 'cgRowIn .5s ease ' + (i * 0.25) + 's both' }}>
            <span style={{ width: 30, height: 22, borderRadius: 6, background: cur ? 'var(--brand-primary)' : '#0E2247', color: 'white', font: '700 10px var(--font-mono)', display: 'flex', alignItems: 'center', justifyContent: 'center' }}>{v}</span>
            <span style={{ font: '600 11px var(--font-body)', color: '#0E2247', flex: 1 }}>{note}</span>
            {cur ? <span style={{ font: '700 9px var(--font-body)', color: 'var(--status-success)' }}>Current</span> : <span style={{ font: '600 10px var(--font-body)', color: 'var(--brand-primary)', border: '1px solid #dde2ea', padding: '3px 7px', borderRadius: 6, animation: i === 1 ? 'cgPulse 1.8s ease ' + CG_LOOP : 'none' }}>Restore</span>}
          </div>
        ))}
      </div>
    </div>
  );
  if (kind === 'generate') return (
    <div className="cg-stage">
      {[[-34, -6, -9], [-12, -14, -3], [12, -14, 3], [34, -6, 9]].map(([x, y, r], i) => (
        <CgPage key={i} style={{ left: 'calc(50% - 15%)', top: '22%', width: '30%', height: '46%', '--fx': x * 4 + 'px', '--fy': y * 2 + 'px', '--fr': r + 'deg', animation: 'cgFan 4.4s cubic-bezier(.3,.8,.3,1) ' + (i * 0.08) + 's ' + CG_LOOP, border: '3px double #0E2247', boxSizing: 'border-box' }}>
          <div style={{ position: 'absolute', top: '42%', width: '100%', textAlign: 'center', font: '700 9px "Playfair Display", serif', color: '#0E2247' }}>{['J. Dela Cruz', 'M. Santos', 'A. Reyes', 'P. Garcia'][i]}</div>
        </CgPage>
      ))}
      <div className="cg-chip" style={{ left: 'calc(50% - 60px)', bottom: '9%', width: 120, justifyContent: 'center', background: 'var(--brand-primary)', color: 'white', border: 'none', animation: 'cgPop 4.4s ease ' + CG_LOOP }}>Ready to print ✓</div>
    </div>
  );
  if (kind === 'filters') return (
    <div className="cg-stage" style={{ background: 'white' }}>
      <div style={{ position: 'absolute', left: '6%', top: '9%', display: 'flex', gap: 6 }}>
        {['All', 'Certificates', 'Name badges', '★ Favourites'].map((p, i) => <span key={p} style={{ height: 22, padding: '0 9px', borderRadius: 999, border: '1.5px solid #0E2247', display: 'inline-flex', alignItems: 'center', font: '600 10px var(--font-body)', background: i === 0 ? '#0E2247' : 'white', color: i === 0 ? 'white' : '#0E2247', animation: i === 2 ? 'cgPillOn 4.4s ease ' + CG_LOOP : 'none' }}>{p}</span>)}
      </div>
      <div style={{ position: 'absolute', left: '6%', right: '6%', top: '30%', bottom: '10%', display: 'grid', gridTemplateColumns: 'repeat(4, 1fr)', gap: 10 }}>
        {[1, 0, 1, 0].map((badge, i) => (
          <div key={i} style={{ borderRadius: 8, border: '1px solid #dde2ea', background: '#f4f6f9', display: 'flex', alignItems: 'center', justifyContent: 'center', animation: badge ? 'none' : 'cgFilter 4.4s ease ' + CG_LOOP }}>
            <div style={{ width: badge ? '38%' : '66%', aspectRatio: badge ? '54/86' : '297/210', background: 'white', boxShadow: '0 2px 8px rgba(14,34,71,.14)', borderTop: '6px solid ' + (badge ? '#F49B52' : '#0E2247') }}></div>
          </div>
        ))}
      </div>
    </div>
  );
  if (kind === 'review') return (
    <div className="cg-stage" style={{ background: 'white' }}>
      <div style={{ position: 'absolute', left: '6%', right: '6%', top: '12%', bottom: '12%', display: 'grid', gridTemplateColumns: 'repeat(3, 1fr)', gap: 12 }}>
        {['Juan Dela Cruz', 'maria clara santos-villanueva de guzman', 'Ana Reyes'].map((n, i) => (
          <div key={i} style={{ position: 'relative', borderRadius: 8, border: '1px solid #dde2ea', background: '#f4f6f9', display: 'flex', alignItems: 'center', justifyContent: 'center', padding: 8 }}>
            <div style={{ width: '100%', aspectRatio: '297/210', background: 'white', boxShadow: '0 2px 8px rgba(14,34,71,.14)', display: 'flex', alignItems: 'center', justifyContent: 'center', textAlign: 'center', padding: 4, boxSizing: 'border-box', font: '700 11px "Playfair Display", serif', color: '#0E2247', overflow: 'hidden' }}>
              {i === 1 ? <span style={{ animation: 'cgShrink 5s ease ' + CG_LOOP }}><span style={{ animation: 'none' }}>{n}</span></span> : n}
            </div>
            {i === 1 && <span style={{ position: 'absolute', top: -8, right: -6, background: '#E8A317', color: 'white', font: '700 9px var(--font-body)', padding: '3px 7px', borderRadius: 999, animation: 'cgWarn 5s ease ' + CG_LOOP }}>Check name</span>}
            {i === 1 && <span style={{ position: 'absolute', top: -8, right: -6, background: 'var(--status-success)', color: 'white', font: '700 9px var(--font-body)', padding: '3px 7px', borderRadius: 999, animation: 'cgOk 5s ease ' + CG_LOOP }}>Fixed ✓</span>}
          </div>
        ))}
      </div>
    </div>
  );
  const stepLbl = { font: '700 10px var(--font-body)', color: '#0E2247', textAlign: 'center', marginTop: 6 };
  if (kind === 'overview') return (
    <div className="cg-stage" style={{ background: 'white' }}>
      <div style={{ position: 'absolute', left: '8%', right: '8%', top: '50%', height: 2, background: '#dde2ea' }}></div>
      {[['1', 'Design once', '0s'], ['2', 'Add details', '1.4s'], ['3', 'Print for everyone', '2.8s']].map(([n, l, d], i) => (
        <div key={n} style={{ position: 'absolute', left: (12 + i * 30) + '%', top: '28%', width: '16%', animation: 'cgStep 4.2s ease ' + d + ' infinite' }}>
          <div style={{ aspectRatio: '1', borderRadius: 14, background: i === 2 ? 'var(--brand-primary)' : '#0E2247', color: 'white', display: 'flex', alignItems: 'center', justifyContent: 'center', font: '800 20px var(--font-display)', boxShadow: '0 8px 18px rgba(14,34,71,.18)' }}>{n}</div>
          <div style={stepLbl}>{l}</div>
        </div>
      ))}
      <div style={{ position: 'absolute', top: 'calc(50% - 6px)', width: 12, height: 12, borderRadius: '50%', background: 'var(--brand-primary)', animation: 'cgFlow 4.2s linear infinite' }}></div>
    </div>
  );
  if (kind === 'starters') return (
    <div className="cg-stage" style={{ background: 'white' }}>
      <div style={{ position: 'absolute', left: '6%', right: '6%', top: '14%', display: 'grid', gridTemplateColumns: 'repeat(4, 1fr)', gap: 12 }}>
        {['#0E2247', '#FBF7EF', '#FFFFFF', '#050D1A'].map((bg, i) => (
          <div key={i} style={{ border: '2px solid #dde2ea', borderRadius: 10, padding: 6, background: 'white', animation: i === 1 ? 'cgPick 4s ease infinite' : 'none' }}>
            <div style={{ aspectRatio: '297/210', background: bg, borderRadius: 3, border: '3px double ' + (i === 1 ? '#B8892B' : i === 0 ? '#F49B52' : '#0E2247'), boxSizing: 'border-box' }}></div>
            <div style={{ font: '600 9px var(--font-body)', color: '#0E2247', marginTop: 5 }}>{['Navy Classic', 'Laurel Award', 'Minimal Line', 'Night Court'][i]}</div>
          </div>
        ))}
      </div>
      <div style={{ position: 'absolute', left: '6%', right: '6%', bottom: '10%', display: 'flex', gap: 8 }}>
        <span className="cg-chip" style={{ position: 'static' }}>Blank page</span><span className="cg-chip" style={{ position: 'static' }}>⇪ Upload PDF</span>
      </div>
      <CgCursor anim={'cgPickCursor 4s ease infinite'} />
    </div>
  );
  if (kind === 'tplwindow') return (
    <div className="cg-stage">
      <div style={{ position: 'absolute', left: '10%', right: '10%', top: '10%', bottom: '10%', background: 'white', borderRadius: 10, boxShadow: '0 12px 30px rgba(14,34,71,.2)', overflow: 'hidden', display: 'grid', gridTemplateColumns: '1.2fr 1fr', gap: 10, padding: 12, boxSizing: 'border-box' }}>
        <div style={{ background: '#f4f6f9', borderRadius: 6, display: 'flex', alignItems: 'center', justifyContent: 'center' }}><div style={{ width: '78%', aspectRatio: '297/210', background: '#0E2247', border: '3px double #F49B52', boxSizing: 'border-box' }}></div></div>
        <div style={{ display: 'flex', flexDirection: 'column', gap: 6 }}>
          <div className="cg-bar" style={{ width: '70%' }}></div><div className="cg-bar" style={{ width: '50%' }}></div>
          <div style={{ marginTop: 'auto', height: 24, borderRadius: 6, background: 'var(--brand-primary)', color: 'white', font: '700 9.5px var(--font-body)', display: 'flex', alignItems: 'center', justifyContent: 'center', animation: 'cgPress 4s ease infinite' }}>Generate certificates</div>
          <div style={{ height: 20, borderRadius: 6, border: '1.5px solid #0E2247', font: '700 9px var(--font-body)', color: '#0E2247', display: 'flex', alignItems: 'center', justifyContent: 'center' }}>Edit design</div>
          <div style={{ display: 'grid', gridTemplateColumns: 'repeat(3,1fr)', gap: 4 }}>{['Duplicate', 'Export', 'Test print'].map((l) => <div key={l} style={{ height: 22, borderRadius: 5, border: '1px solid #dde2ea', font: '600 8px var(--font-body)', color: '#0E2247', display: 'flex', alignItems: 'center', justifyContent: 'center' }}>{l}</div>)}</div>
        </div>
      </div>
      <CgCursor anim={'cgToCursor 4s ease infinite'} />
      <div className="cg-chip" style={{ right: '12%', top: '4%', background: '#0E2247', color: 'white', border: 'none', animation: 'cgToast 4s ease infinite' }}>Opening the print setup…</div>
    </div>
  );
  if (kind === 'paper') return (
    <div className="cg-stage">
      <CgPage style={{ animation: 'cgPaper 6s cubic-bezier(.45,.05,.3,1) infinite', overflow: 'hidden' }}>
        <div style={{ position: 'absolute', inset: '7%', border: '1.5px dashed #E0408A', borderRadius: 2, animation: 'cgSafe 6s ease infinite' }}></div>
        <div style={{ position: 'absolute', left: '15%', right: '15%', top: '38%', height: '12%', background: '#0E2247', borderRadius: 3 }}></div>
        <div style={{ position: 'absolute', left: '30%', right: '30%', top: '58%', height: '6%', background: '#F49B52', borderRadius: 3 }}></div>
        <div style={{ position: 'absolute', right: '2%', bottom: '3%', width: '18%', height: '8%', background: '#B8892B', borderRadius: 2 }}></div>
      </CgPage>
      <div className="cg-chip" style={{ left: '4%', top: '6%' }}>A4 landscape → portrait</div>
      <div className="cg-chip" style={{ right: '4%', bottom: '8%', background: '#FFF4E5', borderColor: '#E8A317', color: '#8a5a00', animation: 'cgEdgeWarn 6s ease infinite' }}>⚠ Too close to the edge</div>
    </div>
  );
  if (kind === 'lock') return (
    <div className="cg-stage" style={{ background: 'white' }}>
      <CgPage style={{ left: '22%', top: '12%', width: '56%', height: '76%', border: '1px solid #dde2ea' }}>
        <div style={{ position: 'absolute', left: '18%', top: '22%', width: '30%', height: '18%', background: '#0E2247', borderRadius: 3, animation: 'cgShake 4s ease infinite' }}></div>
        <div style={{ position: 'absolute', left: '12%', right: '12%', top: '56%', height: 22 }}>
          <div style={{ position: 'absolute', inset: 0, textAlign: 'center', font: '700 15px "Playfair Display", serif', color: '#0E2247', animation: 'cgRetype 4s ease infinite' }}>Juan Dela Cruz</div>
          <div style={{ position: 'absolute', inset: 0, textAlign: 'center', font: '700 15px "Playfair Display", serif', color: '#0E2247', opacity: 0, animation: 'cgRetype2 4s ease infinite' }}>Juan P. Dela Cruz</div>
        </div>
      </CgPage>
      <svg viewBox="0 0 40 48" style={{ position: 'absolute', right: '8%', top: '18%', width: 46, height: 56 }}>
        <g style={{ animation: 'cgLockShackle 4s ease infinite' }}><path d="M11 22V14a9 9 0 0118 0v8" fill="none" stroke="#0E2247" strokeWidth="4" strokeLinecap="round" /></g>
        <rect x="5" y="21" width="30" height="24" rx="5" fill="var(--brand-primary)" />
      </svg>
      <div className="cg-chip" style={{ left: '4%', bottom: '8%' }}>Layout locked · wording still editable</div>
    </div>
  );
  if (kind === 'sheet') return (
    <div className="cg-stage">
      <CgPage style={{ left: '30%', top: '6%', width: '40%', height: '88%', padding: '6%', boxSizing: 'border-box', display: 'grid', gridTemplateColumns: '1fr 1fr', gridTemplateRows: '1fr 1fr', gap: '6%' }}>
        {['J. Dela Cruz', 'M. Santos', 'A. Reyes', 'P. Garcia'].map((n, i) => (
          <div key={n} style={{ position: 'relative', background: '#0E2247', borderRadius: 2, display: 'flex', alignItems: 'center', justifyContent: 'center', font: '700 8px var(--font-body)', color: 'white' }}>
            {n}
            {[[-5, -5, 'h'], [-5, -5, 'v'], ['r', -5, 'h'], ['r', -5, 'v']].map((m, k) => <span key={k} style={{ position: 'absolute', [m[0] === 'r' ? 'right' : 'left']: -6, top: -6, width: m[2] === 'h' ? 5 : 1, height: m[2] === 'h' ? 1 : 5, background: '#7A8699', animation: 'cgCutIn 4.5s ease infinite' }}></span>)}
            <span style={{ position: 'absolute', right: -4, bottom: -4, width: 12, height: 12, borderRadius: '50%', background: 'var(--status-success)', color: 'white', font: '800 7px var(--font-body)', display: 'flex', alignItems: 'center', justifyContent: 'center', animation: 'cgTick 4.5s ease ' + (i * 0.15) + 's infinite' }}>✓</span>
          </div>
        ))}
      </CgPage>
      <div className="cg-chip" style={{ left: '4%', top: '8%' }}>4 per sheet · cut marks</div>
      <div className="cg-chip" style={{ right: '4%', bottom: '8%', background: 'color-mix(in srgb, var(--status-success) 14%, white)', borderColor: 'transparent', color: 'var(--status-success)', animation: 'cgTick 4.5s ease infinite' }}>Marked as printed</div>
    </div>
  );
  if (kind === 'types') return (
    <div className="cg-stage">
      <div className="cg-page" style={{ animation: 'cgMorph 8s cubic-bezier(.45,.05,.3,1) infinite', background: 'white', border: '3px double #0E2247', boxSizing: 'border-box' }}></div>
      <div style={{ position: 'absolute', left: 0, right: 0, bottom: '6%', height: 20 }}>
        {['Certificate · A4', 'Name badge · 54×86 mm', 'Table card · 100×70 mm', 'Sign · A4 portrait'].map((l, i) => <div key={l} style={{ position: 'absolute', inset: 0, textAlign: 'center', font: '700 12px var(--font-body)', color: '#0E2247', opacity: 0, animation: 'cgLbl 8s ease ' + (i * 2) + 's infinite' }}>{l}</div>)}
      </div>
    </div>
  );
  if (kind === 'keys') {
    const key = (k, d, w) => <span style={{ minWidth: w || 34, height: 34, padding: '0 10px', boxSizing: 'border-box', borderRadius: 7, background: 'white', border: '1px solid #c9d0db', boxShadow: '0 4px 0 #b8c0cc', display: 'inline-flex', alignItems: 'center', justifyContent: 'center', font: '700 12px var(--font-mono)', color: '#0E2247', animation: 'cgKey 6s ease ' + d + ' infinite' }}>{k}</span>;
    const rows = [[['Ctrl', 'Z'], 'Undo', '0s'], [['Ctrl', 'D'], 'Duplicate', '2s'], [['Ctrl', 'G'], 'Group', '4s']];
    return (
      <div className="cg-stage" style={{ background: 'white' }}>
        <div style={{ position: 'absolute', left: 0, right: 0, top: '22%', display: 'flex', justifyContent: 'center', gap: 34 }}>
          {rows.map(([ks, l, d]) => (
            <div key={l} style={{ display: 'flex', flexDirection: 'column', alignItems: 'center', gap: 12 }}>
              <div style={{ display: 'flex', gap: 6 }}>{key(ks[0], d, 52)}{key(ks[1], d)}</div>
              <div style={{ font: '700 12px var(--font-body)', color: 'var(--brand-primary)', animation: 'cgKeyLbl 6s ease ' + d + ' infinite', opacity: 0 }}>{l}</div>
            </div>
          ))}
        </div>
        <div style={{ position: 'absolute', left: 0, right: 0, bottom: '10%', textAlign: 'center', font: '600 11px var(--font-body)', color: '#7A8699' }}>Press ? in the editor to see every shortcut</div>
      </div>
    );
  }
  return null;
}

const CG_TOPICS = [
  { group: 'Getting started', items: [
    { id: 'intro', title: 'What the Design Creator does', demo: 'overview', intro: 'Design a certificate, name badge, table card or sign once, then print one for every attendee of a sub-event. Names, dates and other details are filled in for each person automatically.', steps: ['Make a template, or start from a ready-made design.', 'Add the details you want filled in, such as the attendee’s name and the event date.', 'Pick a sub-event and generate. You get one file per attendee, a single combined PDF, or you can print straight away.'], tips: ['Templates, saved images, tags and printed status are kept in this browser for now. Use the same computer and browser to keep your work.'] },
    { id: 'start', title: 'Starting a new design', demo: 'starters', intro: 'Press “New template” on the Design Creator page.', steps: ['Choose a ready-made certificate, name badge, table card or sign. You can change everything afterwards.', 'Or choose a blank page to build from scratch.', 'Or use “Upload PDF” to place names on top of a certificate you already have, such as one from FTI Global.'], tips: ['Your work saves itself as a draft while you edit. If the browser closes, you’ll be offered your unsaved changes next time.'] },
  ] },
  { group: 'Templates page', items: [
    { id: 'find', title: 'Finding templates', demo: 'filters', intro: 'The buttons above the templates narrow down the list.', steps: ['Use the search box to find a template by name, description or tag.', 'Press Certificates, Name badges, Table cards or Signs to show only that type.', 'Press ★ on any template to make it a favourite. Favourites appear first, and “★ Favourites” shows only those.', 'Use “Created by” and “Updated by” to see templates made or last saved by one person.', 'Press “Clear filters” to show everything again.'], tips: ['Add tags such as “imc” or “day-1” in the template window to group related designs.'] },
    { id: 'window', title: 'The template window', demo: 'tplwindow', intro: 'Click any template to open its window.', steps: ['“Generate …” prints or downloads one copy for each attendee.', '“Edit design” opens the editor.', 'Duplicate makes a copy to adjust. Export PDF saves a sample copy. Test print prints one alignment sheet so you can check your printer.', 'Change the type (certificate, name badge, table card or sign), add tags or mark it as a favourite at the top of the window.', '“Delete template” is at the bottom left. You’ll be asked to confirm first.'] },
  ] },
  { group: 'Designing', items: [
    { id: 'add', title: 'Adding elements', demo: 'drag', intro: 'Everything you can put on a design is in the Elements panel on the left.', steps: ['Click an element to add it to the middle of the page.', 'Or drag it from the panel and drop it exactly where you want it.', 'Use the search box at the top of the panel to find an element quickly, such as “seal” or “line”.', 'Groups include Text, Auto-filled details, Ready-made blocks, Decorations, Images, Frames, and Lines & shapes.'] },
    { id: 'move', title: 'Moving and lining things up', demo: 'snap', intro: 'Drag anything to move it, and drag a corner to resize it.', steps: ['Pink lines appear when an item lines up with the page centre or with another item. It snaps into place.', 'Grey lines show the gap to nearby items in millimetres. When the gaps are equal they turn pink with “=”.', 'Shift-click several items, or drag a box around them, to select a group. Then use the align and spacing buttons.', 'Use the arrow keys for tiny moves. Hold Shift to move further.', 'Hold Alt while dragging to place an item freely without snapping.'] },
    { id: 'text', title: 'Text and auto-filled details', demo: 'fields', intro: 'Auto-filled details change for every attendee. You don’t need to type any codes.', steps: ['Add an item from “Auto-filled details”, such as Attendee name, Event date, Organization or Licence number.', 'In a normal text box, press “Insert detail” to drop a detail into the middle of a sentence.', 'Change the font, size, colour, bold, italic, underline and alignment on the right.', 'Keep “Shrink to fit” on for names so long names still fit on one line.', 'Spelling mistakes are underlined while you type.'], tips: ['Organization, role and licence come from the attendee’s account profile. They stay blank for people without one.'] },
    { id: 'images', title: 'Images and signatures', demo: 'signature', intro: 'Logos, photos and signatures go under Images.', steps: ['“Upload image” adds a picture from your computer. It’s also kept in Saved images for later.', '“Draw a signature” lets you sign with a mouse, finger or stylus. Pick an ink colour and pen thickness.', 'Select an image and press “Remove white background” so a scanned signature sits cleanly on the design.', 'Use Crop to trim a picture, and the other settings for rounded corners or a fade.'] },
    { id: 'layers', title: 'Layers', demo: 'layers', intro: 'The Layers tab on the right lists everything on the page, from front to back.', steps: ['Drag a row up or down to bring an item in front of, or behind, others.', 'Use the eye button to hide an item and the lock button to stop it moving.', 'Select several items and press Group (Ctrl + G) so they move together.', 'Right-click any item on the page for quick options such as duplicate, bring forward and lock.'] },
    { id: 'colours', title: 'Colours and fonts for the whole design', demo: 'colors', intro: 'Click an empty part of the page to see the Page panel.', steps: ['Under “Colour scheme”, click a scheme to recolour the whole design in one go.', 'Under “Colours used”, change any colour and it changes everywhere it’s used.', 'Under “Fonts used”, pick a new font to replace one font everywhere.', 'Press Undo (Ctrl + Z) to go back if you don’t like a change.'] },
    { id: 'page', title: 'Page size, background and print margins', demo: 'paper', intro: 'Page settings are also in the Page panel.', steps: ['Change the paper size or orientation. Everything rescales to fit.', 'Set the background to a colour, a gradient, an image or an uploaded PDF.', 'Turn on the safe print area to see where office printers might cut off the edge. Items too close to the edge are flagged.', 'Turn on rulers or the snap grid if you like exact placement.'] },
    { id: 'lock', title: 'Lock design mode', demo: 'lock', intro: 'Lock the layout so other staff can only change the wording and details.', steps: ['In the Page panel, turn on “Lock design”.', 'Items can no longer be moved, resized or deleted by accident.', 'Wording and auto-filled details can still be changed.', 'Turn it off again when you need to change the layout. You’ll be asked to confirm.'] },
  ] },
  { group: 'Saving', items: [
    { id: 'save', title: 'Saving and versions', demo: 'versions', intro: 'Every save is kept as a new version, so nothing is lost.', steps: ['Press “Save new version” (Ctrl + S).', 'Use the small arrow next to it to add a note, such as “Fixed the coach’s name”.', 'In the template window, open Versions to view, restore or print from any older version.', '“Compare versions” shows two versions side by side with a list of what changed.'] },
  ] },
  { group: 'Printing', items: [
    { id: 'generate', title: 'Generating for attendees', demo: 'review', intro: 'Press “Generate …” in the template window.', steps: ['Pick the sub-event.', 'Choose who gets one: checked-in attendees, everyone who paid, or people you pick.', 'Choose the order: alphabetical by last name, or by order number.', 'Review every copy before printing. Long or oddly written names are flagged, and you can fix them right there.', 'Name fixes are remembered for that sub-event, so a reprint won’t need them fixed again.'] },
    { id: 'print', title: 'Printing and downloading', demo: 'sheet', intro: 'Choose how you want the finished files.', steps: ['ZIP downloads one PDF per person.', 'Combined PDF puts everyone in a single file.', 'Print opens the combined file ready for your printer.', 'For smaller designs, choose 2 or 4 per sheet, or “As many as fit”. Cut marks are added.', 'After printing or downloading, each person is marked “Printed” with the date. Tick “Skip already printed” to print only new people.'], tips: ['To reprint one person, open Generation history and reprint just their copy.'] },
    { id: 'types', title: 'Name badges, table cards and signs', demo: 'types', intro: 'These work the same way as certificates.', steps: ['Start from a ready-made name badge, lanyard ID, table card or welcome sign, or change any template’s type.', 'The wording follows the type, for example “Generate name badges”.', 'They default to “As many as fit” per sheet to save paper.'] },
  ] },
  { group: 'Extras', items: [
    { id: 'keys', title: 'Keyboard shortcuts', demo: 'keys', intro: 'In the editor, press ? at any time to see this list.', keys: true },
  ] },
];

function CertGuide({ open, onClose }) {
  const [shown, leaving] = window.useUdPresence(open, 200);
  const flat = CG_TOPICS.flatMap((g) => g.items);
  const [cur, setCur] = React.useState('intro');
  const [q, setQ] = React.useState('');
  const bodyRef = React.useRef(null);
  React.useEffect(() => { if (!open) return; const k = (e) => { if (e.key === 'Escape') onClose(); }; window.addEventListener('keydown', k); return () => window.removeEventListener('keydown', k); }, [open]);
  React.useEffect(() => { if (bodyRef.current) bodyRef.current.scrollTop = 0; }, [cur]);
  if (!shown) return null;
  const topic = flat.find((t) => t.id === cur) || flat[0];
  const idx = flat.indexOf(topic);
  const match = (t) => !q || (t.title + ' ' + t.intro + ' ' + (t.steps || []).join(' ')).toLowerCase().indexOf(q.toLowerCase()) !== -1;
  const shortcuts = window.CERT_SHORTCUTS || [];
  return ReactDOM.createPortal(
    <div className={'ce-modal-bd' + (leaving ? ' ce-out' : '')} onClick={onClose} style={{ position: 'fixed', inset: 0, zIndex: 1280, background: 'rgba(8,21,27,0.6)', display: 'flex', alignItems: 'center', justifyContent: 'center', padding: 16, fontFamily: 'var(--font-body)' }}>
      <div className="ce-modal-panel" onClick={(e) => e.stopPropagation()} role="dialog" aria-label="Design Creator guide" style={{ width: 'min(80vw, 1280px)', height: '80vh', minWidth: 'min(100%, 340px)', background: 'white', borderRadius: 16, boxShadow: '0 30px 70px rgba(5,13,26,.35)', display: 'flex', flexDirection: 'column', overflow: 'hidden' }}>
        <div style={{ display: 'flex', alignItems: 'center', gap: 12, padding: '16px 20px', background: 'var(--navy-950)', color: 'white' }}>
          <div style={{ width: 34, height: 34, borderRadius: 10, background: 'var(--brand-primary)', display: 'flex', alignItems: 'center', justifyContent: 'center', fontWeight: 800, fontSize: 18 }}>?</div>
          <div style={{ flex: 1, minWidth: 0 }}>
            <div style={{ fontFamily: 'var(--font-display)', fontWeight: 700, fontSize: 18 }}>Design Creator guide</div>
            <div style={{ fontSize: 12.5, color: 'rgba(255,255,255,.65)' }}>Step-by-step help for every feature</div>
          </div>
          <button type="button" onClick={onClose} aria-label="Close guide" className="ce-btn" style={{ width: 34, height: 34, borderRadius: '50%', border: '1px solid rgba(255,255,255,.25)', background: 'transparent', color: 'white', fontSize: 18, cursor: 'pointer' }}>×</button>
        </div>
        <div className="cg-body" style={{ flex: 1, minHeight: 0, display: 'grid', gridTemplateColumns: '260px minmax(0,1fr)' }}>
          <nav className="cg-nav" style={{ borderRight: '1px solid var(--border-default)', overflowY: 'auto', padding: '14px 10px', background: 'var(--bg-sunken)', display: 'flex', flexDirection: 'column', gap: 2 }}>
            <input value={q} onChange={(e) => setQ(e.target.value)} placeholder="Search the guide" style={{ height: 36, minHeight: 36, boxSizing: 'border-box', flexShrink: 0, borderRadius: 8, border: '1.5px solid var(--border-default)', padding: '0 12px', fontSize: 13, fontFamily: 'var(--font-body)', marginBottom: 8, outline: 'none', background: 'white' }} />
            {CG_TOPICS.map((g) => {
              const items = g.items.filter(match); if (!items.length) return null;
              return (
                <div key={g.group} style={{ marginBottom: 8 }}>
                  <div style={{ fontSize: 10.5, fontWeight: 800, letterSpacing: '.08em', textTransform: 'uppercase', color: 'var(--text-muted)', padding: '8px 10px 4px' }}>{g.group}</div>
                  {items.map((t) => (
                    <button key={t.id} type="button" className="cg-navbtn" onClick={() => setCur(t.id)} style={{ display: 'block', width: '100%', textAlign: 'left', border: 'none', borderRadius: 8, padding: '8px 10px', fontSize: 13.5, fontWeight: t.id === cur ? 700 : 500, color: t.id === cur ? 'var(--navy-900)' : 'var(--text-secondary)', background: t.id === cur ? 'white' : 'transparent', boxShadow: t.id === cur ? 'inset 3px 0 0 var(--brand-primary), 0 1px 3px rgba(14,34,71,.08)' : 'none', cursor: 'pointer', fontFamily: 'var(--font-body)' }}>{t.title}</button>
                  ))}
                </div>
              );
            })}
          </nav>
          <div ref={bodyRef} style={{ overflowY: 'auto', minWidth: 0 }}>
            <div className="cg-navsel" style={{ display: 'none', padding: '14px 18px 0' }}>
              <window.CertSelect value={cur} onChange={setCur} options={flat.map((t) => ({ value: t.id, label: t.title }))} />
            </div>
            <div key={topic.id} className="cg-topic" style={{ padding: '24px 32px 32px', maxWidth: 860, margin: '0 auto', display: 'flex', flexDirection: 'column', gap: 18 }}>
              <div>
                <div style={{ fontSize: 11, fontWeight: 800, letterSpacing: '.08em', textTransform: 'uppercase', color: 'var(--brand-primary)' }}>{CG_TOPICS.find((g) => g.items.indexOf(topic) !== -1).group}</div>
                <h2 style={{ fontFamily: 'var(--font-display)', fontSize: 26, margin: '4px 0 8px', color: 'var(--navy-900)', textWrap: 'pretty' }}>{topic.title}</h2>
                <p style={{ margin: 0, fontSize: 15, lineHeight: 1.6, color: 'var(--text-secondary)', textWrap: 'pretty' }}>{topic.intro}</p>
              </div>
              {topic.demo && <CgDemo key={topic.id + topic.demo} kind={topic.demo} />}
              {topic.steps && (
                <ol style={{ margin: 0, padding: 0, listStyle: 'none', display: 'flex', flexDirection: 'column', gap: 10 }}>
                  {topic.steps.map((st, i) => (
                    <li key={i} style={{ display: 'flex', gap: 12, alignItems: 'flex-start', fontSize: 14.5, lineHeight: 1.55, color: 'var(--text-primary)' }}>
                      <span style={{ flexShrink: 0, width: 26, height: 26, borderRadius: '50%', background: 'var(--navy-900)', color: 'white', fontWeight: 700, fontSize: 12.5, display: 'flex', alignItems: 'center', justifyContent: 'center', marginTop: 1 }}>{i + 1}</span>
                      <span style={{ textWrap: 'pretty' }}>{st}</span>
                    </li>
                  ))}
                </ol>
              )}
              {topic.keys && (
                <div style={{ display: 'grid', gridTemplateColumns: 'repeat(auto-fill, minmax(300px, 1fr))', columnGap: 24 }}>
                  {shortcuts.map((r) => (
                    <div key={r[0]} style={{ display: 'flex', alignItems: 'center', gap: 12, padding: '9px 0', borderBottom: '1px solid var(--border-default)' }}>
                      <span style={{ flex: 1, fontSize: 13.5 }}>{r[1]}</span>
                      <span style={{ fontFamily: 'var(--font-mono)', fontSize: 11.5, background: 'var(--bg-sunken)', border: '1px solid var(--border-default)', borderRadius: 6, padding: '3px 7px', whiteSpace: 'nowrap', color: 'var(--navy-900)' }}>{r[0]}</span>
                    </div>
                  ))}
                  <div style={{ fontSize: 12, color: 'var(--text-muted)', marginTop: 10 }}>On a Mac, use Cmd instead of Ctrl, and Option instead of Alt.</div>
                </div>
              )}
              {topic.tips && topic.tips.map((tp, i) => (
                <div key={i} style={{ display: 'flex', gap: 10, padding: '12px 14px', borderRadius: 10, background: 'color-mix(in srgb, var(--brand-primary) 9%, white)', fontSize: 13.5, lineHeight: 1.5, color: 'var(--navy-900)' }}>
                  <span style={{ fontWeight: 800, color: 'var(--brand-primary)' }}>Tip</span><span>{tp}</span>
                </div>
              ))}
              <div style={{ display: 'flex', gap: 10, borderTop: '1px solid var(--border-default)', paddingTop: 16, marginTop: 4 }}>
                {idx > 0 && <button type="button" className="ce-btn ce-btn-outline" onClick={() => setCur(flat[idx - 1].id)} style={{ height: 40, padding: '0 16px', borderRadius: 10, border: '1.5px solid var(--navy-900)', background: 'white', color: 'var(--navy-900)', fontWeight: 700, fontSize: 13.5, cursor: 'pointer', fontFamily: 'var(--font-body)', maxWidth: '48%', overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>← {flat[idx - 1].title}</button>}
                <span style={{ flex: 1 }}></span>
                {idx < flat.length - 1 && <button type="button" className="ce-btn ce-btn-primary" onClick={() => setCur(flat[idx + 1].id)} style={{ height: 40, padding: '0 16px', borderRadius: 10, border: 'none', background: 'var(--brand-primary)', color: 'white', fontWeight: 700, fontSize: 13.5, cursor: 'pointer', fontFamily: 'var(--font-body)', maxWidth: '48%', overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>{flat[idx + 1].title} →</button>}
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>, document.body);
}

function CertGuideButton() {
  const [open, setOpen] = React.useState(false);
  return (
    <>
      <button type="button" className="cg-fab" onClick={() => setOpen(true)} aria-label="Open the Design Creator guide" title="How to use the Design Creator" style={{ position: 'fixed', right: 24, bottom: 24, zIndex: 1200, width: 54, height: 54, borderRadius: '50%', border: 'none', background: 'var(--brand-primary)', color: 'white', fontSize: 24, fontWeight: 800, fontFamily: 'var(--font-display)', cursor: 'pointer', boxShadow: '0 8px 20px rgba(14,34,71,.25)' }}>?</button>
      <CertGuide open={open} onClose={() => setOpen(false)} />
    </>
  );
}

window.CertGuide = CertGuide;
window.CertGuideButton = CertGuideButton;
