// arcai-learner.jsx — L01 Home, L02 Lesson Player, L03 Quiz Result,
//                     L04 Path, L05 Liga, L06 Profile

// ── Inline Icons ─────────────────────────────────────────────────────────────
const LIcon = {
  home: (s=20,c='currentColor') => <svg width={s} height={s} viewBox="0 0 24 24" fill="none" stroke={c} strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><path d="M3 12l9-8 9 8"/><path d="M5 10v10h14V10"/></svg>,
  path: (s=20,c='currentColor') => <svg width={s} height={s} viewBox="0 0 24 24" fill="none" stroke={c} strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><circle cx="6" cy="5" r="2.5"/><circle cx="18" cy="12" r="2.5"/><circle cx="6" cy="19" r="2.5"/><path d="M8.5 5 Q 15 5, 15.5 12" strokeDasharray="2 2"/><path d="M15.5 12 Q 15 19, 8.5 19" strokeDasharray="2 2"/></svg>,
  practice: (s=20,c='currentColor') => <svg width={s} height={s} viewBox="0 0 24 24" fill="none" stroke={c} strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><path d="M12 2 L14 8 L20 8 L15 12 L17 19 L12 15 L7 19 L9 12 L4 8 L10 8 Z"/></svg>,
  league: (s=20,c='currentColor') => <svg width={s} height={s} viewBox="0 0 24 24" fill="none" stroke={c} strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><path d="M7 4h10v4a5 5 0 01-10 0V4z"/><path d="M4 4h3v2a3 3 0 01-3 3V4z M20 4h-3v2a3 3 0 003 3V4z"/><path d="M9 14v2h6v-2"/><path d="M8 20h8"/></svg>,
  profile: (s=20,c='currentColor') => <svg width={s} height={s} viewBox="0 0 24 24" fill="none" stroke={c} strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><circle cx="12" cy="8" r="4"/><path d="M4 21c0-4.4 3.6-8 8-8s8 3.6 8 8"/></svg>,
  flame: (s=20,c='#FFC400') => <svg width={s} height={s} viewBox="0 0 24 24" fill={c}><path d="M12 2 C 12 6, 16 8, 16 13 C 19 11, 19 14, 19 15 A 7 7 0 0 1 5 15 C 5 12, 7 11, 7 8 C 9 9, 10 7, 10 5 C 11 6, 12 5, 12 2 Z"/></svg>,
  bolt: (s=20,c='currentColor') => <svg width={s} height={s} viewBox="0 0 24 24" fill={c}><path d="M13 2 L4 14 L11 14 L10 22 L20 9 L13 9 Z"/></svg>,
  check: (s=20,c='currentColor') => <svg width={s} height={s} viewBox="0 0 24 24" fill="none" stroke={c} strokeWidth="3" strokeLinecap="round" strokeLinejoin="round"><path d="M4 12l5 5 11-11"/></svg>,
  play: (s=20,c='currentColor') => <svg width={s} height={s} viewBox="0 0 24 24" fill={c}><path d="M7 4 L19 12 L7 20 Z"/></svg>,
  lock: (s=20,c='currentColor') => <svg width={s} height={s} viewBox="0 0 24 24" fill="none" stroke={c} strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><rect x="5" y="11" width="14" height="10" rx="2"/><path d="M8 11V7a4 4 0 018 0v4"/></svg>,
  trophy: (s=18,c='currentColor') => <svg width={s} height={s} viewBox="0 0 24 24" fill="none" stroke={c} strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><path d="M7 4h10v4a5 5 0 01-10 0V4z"/><path d="M4 4h3v2a3 3 0 01-3 3V4z M20 4h-3v2a3 3 0 003 3V4z"/><path d="M9 14v2h6v-2M8 20h8"/></svg>,
  arrowUp: (s=14,c='#7BED6F') => <svg width={s} height={s} viewBox="0 0 24 24" fill="none" stroke={c} strokeWidth="3" strokeLinecap="round" strokeLinejoin="round"><path d="M12 19V5M5 12l7-7 7 7"/></svg>,
  arrowDown: (s=14,c='#FF4B91') => <svg width={s} height={s} viewBox="0 0 24 24" fill="none" stroke={c} strokeWidth="3" strokeLinecap="round" strokeLinejoin="round"><path d="M12 5v14M5 12l7 7 7-7"/></svg>,
  arrowLeft: (s=20,c='currentColor') => <svg width={s} height={s} viewBox="0 0 24 24" fill="none" stroke={c} strokeWidth="2.5" strokeLinecap="round" strokeLinejoin="round"><path d="M15 6l-6 6 6 6"/></svg>,
  target: (s=18,c='currentColor') => <svg width={s} height={s} viewBox="0 0 24 24" fill="none" stroke={c} strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><circle cx="12" cy="12" r="9"/><circle cx="12" cy="12" r="5"/><circle cx="12" cy="12" r="1.5" fill={c}/></svg>,
  clock: (s=14,c='currentColor') => <svg width={s} height={s} viewBox="0 0 24 24" fill="none" stroke={c} strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><circle cx="12" cy="12" r="9"/><path d="M12 7v5l3 2"/></svg>,
  lightbulb: (s=18,c='currentColor') => <svg width={s} height={s} viewBox="0 0 24 24" fill="none" stroke={c} strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><path d="M9 18h6M10 22h4"/><path d="M12 2a6 6 0 00-4 10.5c1 1 1.5 1.8 1.5 3.5h5c0-1.7.5-2.5 1.5-3.5A6 6 0 0012 2z"/></svg>,
  x: (s=20,c='currentColor') => <svg width={s} height={s} viewBox="0 0 24 24" fill="none" stroke={c} strokeWidth="2.5" strokeLinecap="round" strokeLinejoin="round"><path d="M6 6l12 12M18 6L6 18"/></svg>,
  settings: (s=20,c='currentColor') => <svg width={s} height={s} viewBox="0 0 24 24" fill="none" stroke={c} strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><circle cx="12" cy="12" r="3"/><path d="M12 2v2m0 16v2M4.22 4.22l1.42 1.42m12.72 12.72l1.42 1.42M2 12h2m16 0h2M4.22 19.78l1.42-1.42M18.36 5.64l1.42-1.42"/></svg>,
  star: (s=20,c='currentColor') => <svg width={s} height={s} viewBox="0 0 24 24" fill={c} stroke={c} strokeWidth="1"><path d="M12 2l3.09 6.26L22 9.27l-5 4.87 1.18 6.88L12 17.77l-6.18 3.25L7 14.14 2 9.27l6.91-1.01z"/></svg>,
};

// ── Mascot ────────────────────────────────────────────────────────────────────
function Mascot({ size = 78 }) {
  return (
    <svg width={size} height={size} viewBox="0 0 120 120" style={{ display: 'block' }}>
      <defs>
        <radialGradient id="mGlow" cx="0.5" cy="0.5" r="0.7">
          <stop offset="0%" stopColor="#D4FF3A" stopOpacity="0.35"/>
          <stop offset="100%" stopColor="#D4FF3A" stopOpacity="0"/>
        </radialGradient>
        <linearGradient id="mBody" x1="0" y1="0" x2="0" y2="1">
          <stop offset="0%" stopColor="#D4FF3A"/>
          <stop offset="100%" stopColor="#9BC624"/>
        </linearGradient>
      </defs>
      <circle cx="60" cy="62" r="56" fill="url(#mGlow)"/>
      <line x1="60" y1="26" x2="60" y2="14" style={{stroke:'var(--accent-deep)'}} strokeWidth="2.5" strokeLinecap="round"/>
      <circle cx="60" cy="11" r="4" style={{fill:'var(--accent)'}}/>
      <circle cx="60" cy="11" r="6.5" style={{fill:'var(--accent)',opacity:0.25}}/>
      <path d="M 60 28 C 32 28, 20 42, 20 66 C 20 90, 34 102, 60 102 C 86 102, 100 90, 100 66 C 100 42, 88 28, 60 28 Z" fill="url(#mBody)"/>
      <ellipse cx="44" cy="46" rx="14" ry="8" fill="#fff" opacity="0.22"/>
      <circle cx="46" cy="62" r="4.5" fill="#0B0F14"/>
      <circle cx="74" cy="62" r="4.5" fill="#0B0F14"/>
      <circle cx="47.2" cy="60.8" r="1.4" fill="#fff"/>
      <circle cx="75.2" cy="60.8" r="1.4" fill="#fff"/>
      <path d="M 52 78 Q 60 84, 68 78" stroke="#0B0F14" strokeWidth="2.5" fill="none" strokeLinecap="round"/>
      <circle cx="38" cy="74" r="3.5" fill="#FF4B91" opacity="0.35"/>
      <circle cx="82" cy="74" r="3.5" fill="#FF4B91" opacity="0.35"/>
    </svg>
  );
}

// ── Bottom Nav (5 tabs) ───────────────────────────────────────────────────────
function BottomNav({ active, onNavigate }) {
  const tabs = [
    { key: 'home',     screen: 'L01', label: 'Home',     icon: LIcon.home },
    { key: 'path',     screen: 'L04', label: 'Path',     icon: LIcon.path },
    { key: 'practice', screen: 'L02', label: 'Practice', icon: LIcon.practice },
    { key: 'league',   screen: 'L05', label: 'Liga',     icon: LIcon.league },
    { key: 'profile',  screen: 'L06', label: 'Profil',   icon: LIcon.profile },
  ];
  return (
    <div style={{
      position: 'absolute', bottom: 0, left: 0, right: 0,
      display: 'flex', justifyContent: 'space-around', alignItems: 'flex-start',
      padding: '10px 6px 26px',
      background: 'rgba(11,15,20,0.92)',
      backdropFilter: 'blur(20px)',
      WebkitBackdropFilter: 'blur(20px)',
      borderTop: '1px solid rgba(255,255,255,0.06)',
      zIndex: 20,
    }}>
      {tabs.map(t => {
        const isActive = active === t.key;
        return (
          <button key={t.key} onClick={() => onNavigate && onNavigate(t.screen)}
            style={{
              flex: 1, display: 'flex', flexDirection: 'column', alignItems: 'center', gap: 4,
              background: 'transparent', border: 'none', cursor: 'pointer',
              padding: '6px 2px', position: 'relative',
              color: isActive ? 'var(--accent)' : 'var(--text-dim)',
              transition: 'color 0.2s',
            }}>
            {isActive && (
              <div style={{
                position: 'absolute', top: -1, left: '50%', transform: 'translateX(-50%)',
                width: 26, height: 2, borderRadius: 2,
                background: 'var(--accent)',
                boxShadow: '0 0 10px var(--accent)',
              }}/>
            )}
            <div style={{ filter: isActive ? 'drop-shadow(0 0 6px var(--accent-glow))' : 'none' }}>
              {t.icon(22, isActive ? 'var(--accent)' : '#5A6472')}
            </div>
            <span style={{
              fontFamily: 'var(--font-body)', fontSize: 10,
              fontWeight: isActive ? 600 : 500, letterSpacing: 0.2,
            }}>{t.label}</span>
          </button>
        );
      })}
    </div>
  );
}

// ── L01 Home / Today ──────────────────────────────────────────────────────────
function ScreenL01({ onNavigate }) {
  const [xpAnim, setXpAnim] = React.useState(false);

  return (
    <div style={{ height: '100%', overflowY: 'auto', paddingTop: 44, display: 'flex', flexDirection: 'column', background: 'var(--bg)' }}>
      {/* Header */}
      <div style={{ padding: '12px 20px 10px', display: 'flex', alignItems: 'center', gap: 8 }}>
        {/* Streak pill */}
        <div style={{ display: 'flex', alignItems: 'center', gap: 5, padding: '6px 10px 6px 8px', borderRadius: 999, background: 'var(--surface-1)', border: '1px solid rgba(255,196,0,0.2)' }}>
          <div style={{ animation: 'flicker 1.6s ease-in-out infinite', display: 'inline-block' }}>{LIcon.flame(16,'#FFC400')}</div>
          <span style={{ fontFamily: 'var(--font-display)', fontWeight: 700, fontSize: 13 }}>7</span>
          <span style={{ fontSize: 11, color: 'var(--text-muted)' }}>hari</span>
        </div>
        {/* XP pill */}
        <div onClick={() => { setXpAnim(true); setTimeout(() => setXpAnim(false), 1000); }}
          style={{ display: 'flex', alignItems: 'center', gap: 5, padding: '6px 10px 6px 8px', borderRadius: 999, background: 'var(--surface-1)', border: '1px solid var(--accent-overlay-mid)', cursor: 'pointer', position: 'relative' }}>
          {LIcon.bolt(14,'var(--accent)')}
          <span style={{ fontFamily: 'var(--font-display)', fontWeight: 700, fontSize: 13 }}>2,340</span>
          <span style={{ fontSize: 11, color: 'var(--text-muted)' }}>XP</span>
          {xpAnim && (
            <span style={{ position: 'absolute', top: -14, left: '50%', transform: 'translateX(-50%)', color: 'var(--accent)', fontWeight: 800, fontSize: 13, whiteSpace: 'nowrap', animation: 'xpburst 0.9s cubic-bezier(0.34,1.56,0.64,1) forwards', pointerEvents: 'none' }}>+30 XP</span>
          )}
        </div>
        <div style={{ flex: 1 }}/>
        <Avatar name="Rayis Ananda" size={32}/>
      </div>

      {/* Mascot + greeting */}
      <div style={{ padding: '4px 20px 14px', display: 'flex', alignItems: 'center', gap: 14 }}>
        <Mascot size={78}/>
        <div style={{ flex: 1 }}>
          <div style={{ fontFamily: 'var(--font-display)', fontSize: 18, fontWeight: 700, letterSpacing: '-0.02em', lineHeight: 1.15, marginBottom: 4 }}>Pagi, Rayis!</div>
          <div style={{ fontSize: 12, color: 'var(--text-muted)', lineHeight: 1.45 }}>Lu on fire — jangan putus streak hari ini ya 🔥</div>
        </div>
      </div>

      {/* Today's lesson card */}
      <div style={{ margin: '0 20px 12px', padding: '18px', background: 'var(--surface-1)', borderRadius: 20, border: '1px solid var(--border)', position: 'relative', overflow: 'hidden' }}>
        <div style={{ position: 'absolute', top: -40, right: -40, width: 140, height: 140, borderRadius: '50%', background: 'var(--accent)', opacity: 0.1, filter: 'blur(30px)', pointerEvents: 'none' }}/>
        <div style={{ fontSize: 10, letterSpacing: 2, textTransform: 'uppercase', color: 'var(--accent)', fontWeight: 700, marginBottom: 8, fontFamily: 'var(--font-display)' }}>Pelajaran Hari Ini</div>
        <div style={{ fontFamily: 'var(--font-display)', fontWeight: 700, fontSize: 18, letterSpacing: '-0.02em', lineHeight: 1.2, marginBottom: 6 }}>Prompt Engineering:<br/>Chain-of-Thought</div>
        <div style={{ display: 'flex', alignItems: 'center', gap: 6, color: 'var(--text-muted)', fontSize: 11, marginBottom: 14 }}>
          {LIcon.clock(12,'var(--text-muted)')}
          <span>6 menit</span>
          <span style={{ opacity: 0.4 }}>•</span>
          <span>Pelajaran 5 / 12</span>
        </div>
        <BtnPrimary onClick={() => onNavigate('L02')} fullWidth>Mulai Sekarang →</BtnPrimary>
      </div>

      {/* Path progress strip */}
      <button onClick={() => onNavigate('L04')} style={{ display: 'block', margin: '0 20px 12px', background: 'var(--surface-1)', border: '1px solid var(--border)', borderRadius: 14, padding: '12px 14px', cursor: 'pointer', textAlign: 'left' }}>
        <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: 6 }}>
          <span style={{ fontSize: 11, color: 'var(--text-muted)' }}>Path · AI untuk Marketer</span>
          <span style={{ fontFamily: 'var(--font-display)', fontSize: 12, fontWeight: 700, color: 'var(--accent)' }}>40%</span>
        </div>
        <div style={{ height: 5, borderRadius: 4, background: 'rgba(255,255,255,0.06)', overflow: 'hidden' }}>
          <div style={{ height: '100%', width: '40%', background: 'linear-gradient(90deg, var(--accent-deep), var(--accent))', borderRadius: 4, boxShadow: '0 0 8px var(--accent-glow)' }}/>
        </div>
      </button>

      {/* Daily Challenge */}
      <div style={{ margin: '0 20px 80px', background: 'var(--surface-1)', border: '1px dashed rgba(255,196,0,0.25)', borderRadius: 16, padding: 14 }}>
        <div style={{ display: 'flex', alignItems: 'center', gap: 6, marginBottom: 6 }}>
          <div style={{ width: 22, height: 22, borderRadius: 7, background: 'rgba(255,196,0,0.15)', display: 'flex', alignItems: 'center', justifyContent: 'center' }}>
            {LIcon.target(13,'#FFC400')}
          </div>
          <div style={{ fontFamily: 'var(--font-display)', fontSize: 12, fontWeight: 700 }}>Daily Challenge</div>
          <div style={{ flex: 1 }}/>
          <div style={{ fontSize: 10, color: '#FFC400', fontWeight: 700, fontFamily: 'var(--font-display)', background: 'rgba(255,196,0,0.12)', padding: '2px 6px', borderRadius: 6 }}>+50 XP</div>
        </div>
        <div style={{ fontSize: 12, color: 'var(--text-muted)', lineHeight: 1.5 }}>
          Bikin 1 prompt CoT buat kerjaan lu hari ini, trus lapor hasilnya untuk bonus XP.
        </div>
      </div>

      <BottomNav active="home" onNavigate={onNavigate}/>
    </div>
  );
}

// ── L02 Lesson Player ─────────────────────────────────────────────────────────
function ScreenL02({ onNavigate }) {
  const [selected, setSelected] = React.useState(null);
  const [submitted, setSubmitted] = React.useState(false);
  const [showHint, setShowHint] = React.useState(false);
  const [showExit, setShowExit] = React.useState(false);
  const step = 3, total = 5;

  const options = [
    { id: 'a', text: '"Tolong tulis email maaf untuk client kami."', correct: false, hint: 'Terlalu umum — AI nggak tau tone, konteks, atau format.' },
    { id: 'b', text: '"Kamu adalah manajer profesional. Client kami kecewa karena deadline terlewat 2 hari. Tulis email permintaan maaf yang tulus, formal, dan sertakan rencana perbaikan konkret."', correct: true, hint: 'Persona + konteks + format = sempurna!' },
    { id: 'c', text: '"Buatkan email yang sopan untuk client yang marah."', correct: false, hint: '"Sopan" itu subjektif — AI perlu guidance lebih.' },
    { id: 'd', text: '"Email apology: client kecewa, deadline terlewat, minta maaf, ada solusi."', correct: false, hint: 'Pendek, tapi kurang konteks dan persona.' },
  ];

  const current = selected ? options.find(o => o.id === selected) : null;
  const isCorrect = submitted && current?.correct;

  return (
    <div style={{ height: '100%', display: 'flex', flexDirection: 'column', background: 'var(--bg)', paddingTop: 44, position: 'relative' }}>
      {/* Header */}
      <div style={{ padding: '10px 16px 0', display: 'flex', alignItems: 'center', gap: 10 }}>
        <button onClick={() => setShowExit(true)} style={{ width: 28, height: 28, borderRadius: 8, background: 'var(--surface-1)', border: 'none', display: 'flex', alignItems: 'center', justifyContent: 'center', cursor: 'pointer', padding: 0 }}>
          {LIcon.x(16,'var(--text-muted)')}
        </button>
        <div style={{ flex: 1, height: 10, borderRadius: 5, background: 'rgba(255,255,255,0.06)', overflow: 'hidden', position: 'relative' }}>
          <div style={{ height: '100%', width: `${(step/total)*100}%`, background: 'linear-gradient(90deg, var(--accent-deep), var(--accent))', borderRadius: 5, boxShadow: '0 0 6px var(--accent-glow)', position: 'relative' }}>
            <div style={{ position: 'absolute', top: 1, left: 2, right: 2, height: 2, borderRadius: 2, background: 'rgba(255,255,255,0.4)' }}/>
          </div>
        </div>
        <span style={{ fontFamily: 'var(--font-display)', fontSize: 11, fontWeight: 700, color: 'var(--accent)', minWidth: 20 }}>{step}/{total}</span>
      </div>
      <div style={{ padding: '4px 16px 10px' }}>
        <div style={{ fontSize: 10, color: 'var(--text-dim)', letterSpacing: 1, textTransform: 'uppercase', fontFamily: 'var(--font-display)', fontWeight: 600 }}>Prompt Engineering · Challenge</div>
      </div>

      {/* Question */}
      <div style={{ padding: '0 16px 10px' }}>
        <div style={{ fontFamily: 'var(--font-display)', fontSize: 15, fontWeight: 700, letterSpacing: '-0.02em', lineHeight: 1.3, marginBottom: 6 }}>Prompt mana yang paling efektif?</div>
        <div style={{ fontSize: 11.5, color: 'var(--text-muted)', lineHeight: 1.5 }}>
          Kamu <b style={{ color: 'var(--text)', fontWeight: 600 }}>project manager</b>. Mau AI buatin email apology ke client yang profesional.
        </div>
      </div>

      {/* Options */}
      <div style={{ flex: 1, overflowY: 'auto', padding: '4px 16px 10px', display: 'flex', flexDirection: 'column', gap: 8 }}>
        {options.map(opt => {
          const isSel = selected === opt.id;
          const showResult = submitted && isSel;
          return (
            <button key={opt.id} onClick={() => !submitted && setSelected(opt.id)} disabled={submitted}
              style={{
                textAlign: 'left', background: showResult ? (opt.correct ? 'rgba(123,237,111,0.08)' : 'rgba(255,75,145,0.08)') : (isSel ? 'var(--accent-overlay-soft)' : 'var(--surface-1)'),
                border: `1.5px solid ${showResult ? (opt.correct ? 'var(--success)' : 'var(--danger)') : (isSel ? 'var(--accent)' : 'rgba(255,255,255,0.06)')}`,
                borderRadius: 14, padding: '10px 12px', cursor: submitted ? 'default' : 'pointer',
                display: 'flex', alignItems: 'flex-start', gap: 10, transition: 'all 0.15s', color: 'var(--text)',
              }}>
              <div style={{ width: 22, height: 22, minWidth: 22, borderRadius: 7, background: isSel ? 'var(--accent)' : 'var(--surface-2)', border: isSel ? 'none' : '1px solid rgba(255,255,255,0.08)', display: 'flex', alignItems: 'center', justifyContent: 'center', fontFamily: 'var(--font-display)', fontWeight: 700, fontSize: 11, color: isSel ? '#0B0F14' : 'var(--text-muted)', marginTop: 1, flexShrink: 0 }}>
                {opt.id.toUpperCase()}
              </div>
              <div style={{ flex: 1, fontFamily: 'var(--font-body)', fontSize: 12, lineHeight: 1.5, color: isSel ? 'var(--text)' : 'var(--text-muted)' }}>{opt.text}</div>
            </button>
          );
        })}

        {showHint && current && (
          <div style={{ background: 'rgba(255,196,0,0.08)', border: '1px solid rgba(255,196,0,0.2)', borderRadius: 12, padding: '8px 10px', display: 'flex', gap: 8 }}>
            {LIcon.lightbulb(14,'#FFC400')}
            <div style={{ fontSize: 11, color: 'var(--text)', lineHeight: 1.45 }}><b style={{ color: '#FFC400' }}>Hint:</b> {current.hint}</div>
          </div>
        )}
      </div>

      {/* Bottom action */}
      <div style={{ padding: '10px 16px 28px', borderTop: '1px solid rgba(255,255,255,0.05)', background: submitted ? (isCorrect ? 'rgba(212,255,58,0.06)' : 'rgba(255,75,145,0.06)') : 'transparent' }}>
        {submitted && (
          <div style={{ fontFamily: 'var(--font-display)', fontSize: 13, fontWeight: 700, color: isCorrect ? 'var(--accent)' : 'var(--danger)', marginBottom: 8 }}>
            {isCorrect ? '✓ Mantap! Persona + konteks = prompt juara.' : '✗ Belum pas. Persona dan konteks harus spesifik.'}
          </div>
        )}
        <div style={{ display: 'flex', gap: 8 }}>
          {!submitted && (
            <button onClick={() => setShowHint(v => !v)} disabled={!selected}
              style={{ padding: '11px 12px', borderRadius: 12, background: 'transparent', border: '1.5px solid rgba(255,255,255,0.08)', color: selected ? 'var(--text-muted)' : 'var(--surface-3)', fontFamily: 'var(--font-display)', fontWeight: 600, fontSize: 12, cursor: selected ? 'pointer' : 'default', display: 'flex', alignItems: 'center', gap: 4 }}>
              {LIcon.lightbulb(14, selected ? '#FFC400' : '#3A4250')}<span>Hint</span>
            </button>
          )}
          <button onClick={() => { if (!selected) return; if (!submitted) setSubmitted(true); else onNavigate('L03'); }} disabled={!selected}
            style={{ flex: 1, padding: '11px 16px', borderRadius: 12, border: 'none', background: !selected ? 'var(--surface-2)' : (submitted ? (isCorrect ? 'var(--accent)' : '#FF4B91') : 'var(--accent)'), color: !selected ? 'var(--text-dim)' : '#0B0F14', fontFamily: 'var(--font-display)', fontWeight: 700, fontSize: 13, letterSpacing: '-0.02em', cursor: selected ? 'pointer' : 'default', boxShadow: selected ? `0 4px 0 ${submitted ? (isCorrect ? 'var(--accent-deep)' : '#C6245D') : 'var(--accent-deep)'}` : 'none' }}>
            {submitted ? (isCorrect ? 'Lanjut →' : 'Coba Lagi') : 'Cek Jawaban'}
          </button>
        </div>
      </div>

      {/* Exit sheet */}
      {showExit && (
        <div style={{ position: 'absolute', inset: 0, zIndex: 100, background: 'rgba(0,0,0,0.65)', display: 'flex', alignItems: 'flex-end', backdropFilter: 'blur(4px)' }} onClick={() => setShowExit(false)}>
          <div onClick={e => e.stopPropagation()} style={{ width: '100%', background: 'var(--surface-2)', borderTopLeftRadius: 24, borderTopRightRadius: 24, padding: '18px 16px 32px', borderTop: '1px solid rgba(255,255,255,0.08)' }}>
            <div style={{ width: 36, height: 4, borderRadius: 2, background: 'rgba(255,255,255,0.15)', margin: '0 auto 14px' }}/>
            <div style={{ fontFamily: 'var(--font-display)', fontSize: 18, fontWeight: 700, marginBottom: 4 }}>Yakin keluar?</div>
            <div style={{ fontSize: 12, color: 'var(--text-muted)', marginBottom: 16, lineHeight: 1.4 }}>Progress lesson ini bakal hilang. Streak lu aman sampai jam 23:59 WIB.</div>
            <div style={{ display: 'flex', gap: 8 }}>
              <button onClick={() => setShowExit(false)} style={{ flex: 1, padding: '11px', borderRadius: 12, background: 'var(--surface-3)', border: 'none', color: 'var(--text)', fontFamily: 'var(--font-display)', fontWeight: 700, fontSize: 13, cursor: 'pointer' }}>Lanjut Belajar</button>
              <button onClick={() => onNavigate('L01')} style={{ flex: 1, padding: '11px', borderRadius: 12, background: '#FF4B91', border: 'none', color: '#0B0F14', fontFamily: 'var(--font-display)', fontWeight: 700, fontSize: 13, cursor: 'pointer', boxShadow: '0 4px 0 #C6245D' }}>Keluar</button>
            </div>
          </div>
        </div>
      )}
    </div>
  );
}

// ── L03 Quiz Result ───────────────────────────────────────────────────────────
function ScreenL03({ onNavigate }) {
  const [showXP, setShowXP] = React.useState(false);
  React.useEffect(() => { const t = setTimeout(() => setShowXP(true), 600); return () => clearTimeout(t); }, []);

  return (
    <div style={{ height: '100%', overflowY: 'auto', paddingTop: 44, background: 'var(--bg)' }}>
      <div style={{ background: 'linear-gradient(160deg, rgba(212,255,58,0.08) 0%, transparent 60%)', padding: '32px 20px 24px', textAlign: 'center', borderBottom: '1px solid var(--border)' }}>
        <div style={{ fontSize: 56, marginBottom: 8, animation: 'scalein 0.5s cubic-bezier(0.34,1.56,0.64,1)' }}>✅</div>
        <div style={{ fontFamily: 'var(--font-display)', fontSize: 32, fontWeight: 700, letterSpacing: '-0.03em', marginBottom: 4, animation: 'fadein 0.4s 0.2s both' }}>Mantap!</div>
        <div style={{ fontSize: 13, color: 'var(--text-muted)', animation: 'fadein 0.4s 0.3s both' }}>Lesson selesai · Streak aman</div>
      </div>

      <div style={{ padding: '20px 20px 100px' }}>
        {/* Score */}
        <div style={{ textAlign: 'center', marginBottom: 20, animation: 'fadein 0.4s 0.2s both' }}>
          <div style={{ fontFamily: 'var(--font-display)', fontSize: 52, fontWeight: 700, letterSpacing: '-0.03em', lineHeight: 1 }}>
            85<span style={{ fontSize: 24, color: 'var(--text-muted)' }}>/100</span>
          </div>
          <div style={{ fontSize: 12, color: 'var(--text-muted)', marginTop: 4, marginBottom: 12 }}>Skor Anda</div>
          <div style={{ display: 'flex', justifyContent: 'center', gap: 10, position: 'relative' }}>
            {showXP && (
              <div style={{ position: 'relative' }}>
                <XPChip xp="+50 XP"/>
                <span style={{ position: 'absolute', top: -4, left: '50%', transform: 'translateX(-50%)', color: 'var(--accent)', fontWeight: 800, fontSize: 14, whiteSpace: 'nowrap', animation: 'xpburst 0.9s cubic-bezier(0.34,1.56,0.64,1) forwards', pointerEvents: 'none' }}>+50 XP</span>
              </div>
            )}
            <StreakChip days={8}/>
          </div>
        </div>

        {/* Streak update */}
        <div style={{ background: 'rgba(255,196,0,0.08)', border: '1px solid rgba(255,196,0,0.2)', borderRadius: 12, padding: '12px 14px', marginBottom: 16, display: 'flex', alignItems: 'center', gap: 10, animation: 'fadein 0.4s 0.4s both' }}>
          <span style={{ fontSize: 24, animation: 'flicker 1.6s ease-in-out infinite' }}>🔥</span>
          <div>
            <div style={{ fontSize: 13, fontWeight: 700, color: 'var(--streak)' }}>+1 hari · 8 hari total</div>
            <div style={{ fontSize: 11, color: 'var(--text-muted)' }}>2 hari lagi ke milestone 🏅</div>
          </div>
        </div>

        {/* AI Feedback */}
        <div style={{ marginBottom: 16, animation: 'fadein 0.4s 0.5s both' }}>
          <div style={{ fontSize: 11, color: 'var(--text-muted)', fontWeight: 700, letterSpacing: '0.08em', textTransform: 'uppercase', marginBottom: 10 }}>AI FEEDBACK</div>
          {[
            { icon: '✅', label: 'Yang bagus', text: 'Anda memahami pentingnya konteks dalam prompt dan memilih jawaban yang paling spesifik.' },
            { icon: '📈', label: 'Bisa diperbaiki', text: 'Coba tambah instruksi format output (e.g. "3 paragraf singkat") untuk hasil yang lebih konsisten.' },
            { icon: '💡', label: 'Tip berikutnya', text: 'Pelajari "role prompting" — memberi AI persona spesifik meningkatkan kualitas output 40%.' },
          ].map((f, i) => (
            <div key={i} style={{ display: 'flex', gap: 10, padding: '10px 12px', background: 'var(--surface-1)', borderRadius: 10, marginBottom: 8, border: '1px solid var(--border)' }}>
              <span style={{ fontSize: 16 }}>{f.icon}</span>
              <div>
                <div style={{ fontSize: 11, fontWeight: 700, color: 'var(--text-muted)', textTransform: 'uppercase', letterSpacing: '0.06em', marginBottom: 3 }}>{f.label}</div>
                <div style={{ fontSize: 12, color: 'var(--text)', lineHeight: 1.5 }}>{f.text}</div>
              </div>
            </div>
          ))}
        </div>

        {/* Level progress */}
        <div style={{ marginBottom: 20, padding: '14px 16px', background: 'var(--surface-1)', borderRadius: 12, border: '1px solid var(--border)', animation: 'fadein 0.4s 0.6s both' }}>
          <div style={{ display: 'flex', justifyContent: 'space-between', marginBottom: 8 }}>
            <span style={{ fontSize: 12, color: 'var(--text-muted)', fontWeight: 600 }}>Level 2 → Level 3</span>
            <span style={{ fontSize: 12, color: 'var(--accent)', fontFamily: 'var(--font-mono)', fontWeight: 700 }}>240 / 400 XP</span>
          </div>
          <ProgressBar value={240} max={400} height={8}/>
        </div>

        <div style={{ display: 'flex', flexDirection: 'column', gap: 10, animation: 'fadein 0.4s 0.7s both' }}>
          <BtnPrimary onClick={() => onNavigate('L01')} fullWidth>Lesson Berikutnya →</BtnPrimary>
          <BtnGhost onClick={() => onNavigate('L01')}>Balik ke Home</BtnGhost>
        </div>
      </div>
    </div>
  );
}

// ── L04 Skill Path (hex-node tree) ────────────────────────────────────────────
function ScreenL04({ onNavigate }) {
  const nodes = [
    { id: 1, label: 'Dasar ChatGPT',      status: 'done' },
    { id: 2, label: 'Prompt Dasar',        status: 'done' },
    { id: 3, label: 'Output Format',       status: 'done' },
    { id: 4, label: 'Prompt Patterns',     status: 'done' },
    { id: 5, label: 'Chain-of-Thought',    status: 'current' },
    { id: 6, label: 'Content Generation',  status: 'locked' },
    { id: 7, label: 'Iklan Copy',          status: 'locked' },
    { id: 8, label: 'Riset Audience',      status: 'locked' },
    { id: 9, label: 'A/B Test dgn AI',     status: 'locked' },
    { id: 10, label: 'Otomasi Email',      status: 'locked' },
    { id: 11, label: 'Zapier + AI',        status: 'locked' },
    { id: 12, label: 'Certification',      status: 'locked', boss: true },
  ];

  const cols = [52, 140, 228];
  const pattern = [1, 2, 1, 0, 1, 2, 1, 0, 1, 2, 1, 1];
  const positioned = nodes.map((n, i) => ({ ...n, x: cols[pattern[i]], y: 30 + i * 88 }));
  const totalH = positioned[positioned.length - 1].y + 110;
  const currentNode = positioned.find(n => n.status === 'current');

  const HexNode = ({ node }) => {
    const isDone = node.status === 'done';
    const isCurrent = node.status === 'current';
    const isLocked = node.status === 'locked';
    const size = node.boss ? 72 : 62;
    const half = size / 2;

    const fill = (isDone || isCurrent) ? 'var(--accent)' : 'var(--surface-2)';
    const shadow = (isDone || isCurrent) ? 'var(--accent-deep)' : '#1a2030';
    const iconColor = (isDone || isCurrent) ? '#0B0F14' : 'var(--text-dim)';
    const labelColor = isCurrent ? 'var(--accent)' : (isDone ? 'var(--text)' : 'var(--text-dim)');

    return (
      <div onClick={() => !isLocked && onNavigate('L02')}
        style={{ position: 'absolute', left: node.x - half, top: node.y - half, width: size, height: size, cursor: isLocked ? 'default' : 'pointer' }}>
        {isCurrent && (
          <div style={{ position: 'absolute', inset: -8, borderRadius: '50%', border: '2px solid var(--accent)', animation: 'pulsering 1.8s ease-out infinite' }}/>
        )}
        {!isLocked && (
          <div style={{ position: 'absolute', top: 6, left: 0, right: 0, bottom: -6, background: shadow, clipPath: 'polygon(50% 0%,100% 25%,100% 75%,50% 100%,0% 75%,0% 25%)', opacity: 0.9 }}/>
        )}
        <div style={{ position: 'absolute', inset: 0, background: fill, clipPath: 'polygon(50% 0%,100% 25%,100% 75%,50% 100%,0% 75%,0% 25%)', display: 'flex', alignItems: 'center', justifyContent: 'center' }}>
          {isDone && LIcon.check(node.boss ? 30 : 24, iconColor)}
          {isCurrent && LIcon.play(node.boss ? 28 : 22, iconColor)}
          {isLocked && !node.boss && LIcon.lock(20, iconColor)}
          {isLocked && node.boss && LIcon.trophy(26, iconColor)}
        </div>
        {!isLocked && (
          <div style={{ position: 'absolute', inset: 0, clipPath: 'polygon(50% 0%,100% 25%,100% 75%,50% 100%,0% 75%,0% 25%)', background: 'linear-gradient(180deg,rgba(255,255,255,0.25),transparent 50%)', pointerEvents: 'none' }}/>
        )}
        <div style={{ position: 'absolute', top: size + 6, left: '50%', transform: 'translateX(-50%)', whiteSpace: 'nowrap', fontFamily: 'var(--font-body)', fontSize: 10, fontWeight: 600, color: labelColor, textAlign: 'center', lineHeight: 1.1 }}>
          {node.label}
        </div>
      </div>
    );
  };

  const connectors = [];
  for (let i = 0; i < positioned.length - 1; i++) {
    const a = positioned[i], b = positioned[i+1];
    connectors.push(
      <line key={i} x1={a.x} y1={a.y} x2={b.x} y2={b.y}
        stroke={i < 4 ? 'var(--accent-deep)' : 'var(--surface-3)'}
        strokeWidth="2" strokeDasharray="3 5" strokeLinecap="round"/>
    );
  }

  return (
    <div style={{ height: '100%', display: 'flex', flexDirection: 'column', background: 'var(--bg)', paddingTop: 44 }}>
      {/* Header */}
      <div style={{ padding: '12px 16px 14px', background: 'rgba(11,15,20,0.95)', backdropFilter: 'blur(20px)', WebkitBackdropFilter: 'blur(20px)', borderBottom: '1px solid var(--border)', zIndex: 10 }}>
        <div style={{ display: 'flex', alignItems: 'center', gap: 10, marginBottom: 8 }}>
          <button onClick={() => onNavigate('L01')} style={{ width: 32, height: 32, borderRadius: 10, background: 'var(--surface-1)', border: 'none', display: 'flex', alignItems: 'center', justifyContent: 'center', color: 'var(--text)', cursor: 'pointer', padding: 0 }}>
            {LIcon.arrowLeft(18,'var(--text)')}
          </button>
          <div style={{ flex: 1 }}>
            <div style={{ fontFamily: 'var(--font-display)', fontSize: 15, fontWeight: 700, letterSpacing: '-0.02em', lineHeight: 1 }}>AI untuk Marketer</div>
            <div style={{ fontSize: 10, color: 'var(--text-muted)', marginTop: 2 }}>4 dari 12 pelajaran selesai</div>
          </div>
          <div style={{ fontFamily: 'var(--font-display)', fontSize: 14, fontWeight: 700, color: 'var(--accent)' }}>40%</div>
        </div>
        <div style={{ height: 5, borderRadius: 4, background: 'rgba(255,255,255,0.06)', overflow: 'hidden' }}>
          <div style={{ height: '100%', width: '40%', background: 'linear-gradient(90deg, var(--accent-deep), var(--accent))', borderRadius: 4, boxShadow: '0 0 8px var(--accent-glow)' }}/>
        </div>
      </div>

      {/* Canvas */}
      <div style={{ flex: 1, overflowY: 'auto', overflowX: 'hidden', paddingBottom: 80 }}>
        <div style={{ position: 'relative', width: 280, height: totalH, margin: '0 auto' }}>
          <div style={{ position: 'absolute', left: 140-80, top: 0, width: 160, height: totalH, background: 'radial-gradient(ellipse at center top, rgba(212,255,58,0.08), transparent 60%)', pointerEvents: 'none' }}/>
          <svg width="280" height={totalH} style={{ position: 'absolute', inset: 0, pointerEvents: 'none' }}>
            {connectors}
          </svg>
          {positioned.map(n => <HexNode key={n.id} node={n}/>)}
          {currentNode && (
            <div style={{ position: 'absolute', left: currentNode.x, top: currentNode.y + 58, transform: 'translateX(-50%)', background: 'var(--surface-2)', border: '1px solid var(--accent-overlay-mid)', borderRadius: 12, padding: '8px 12px', fontSize: 10.5, color: 'var(--text)', whiteSpace: 'nowrap', boxShadow: '0 8px 20px rgba(0,0,0,0.5)', zIndex: 5 }}>
              <div style={{ position: 'absolute', top: -5, left: '50%', transform: 'translateX(-50%) rotate(45deg)', width: 10, height: 10, background: 'var(--surface-2)', borderLeft: '1px solid var(--accent-overlay-mid)', borderTop: '1px solid var(--accent-overlay-mid)' }}/>
              <span style={{ fontWeight: 600 }}>Tinggal 3 lesson lagi</span>
              <span style={{ color: 'var(--text-muted)' }}> sampai level berikutnya</span> 💪
            </div>
          )}
        </div>
      </div>

      <BottomNav active="path" onNavigate={onNavigate}/>
    </div>
  );
}

// ── L05 Liga / Leaderboard ────────────────────────────────────────────────────
function ScreenL05({ onNavigate }) {
  const entries = [
    { rank: 1, name: 'Rina Wulandari',  meta: 'UI/UX · Jakarta',     xp: 4820, trend: 'up',   medal: 'gold' },
    { rank: 2, name: 'Budi Prasetyo',   meta: 'Growth · Bandung',    xp: 4230, trend: 'up',   medal: 'silver' },
    { rank: 3, name: 'Citra Mahendra',  meta: 'Content · Surabaya',  xp: 3980, trend: 'same', medal: 'bronze' },
    { rank: 4, name: 'Aditya Nugroho',  meta: 'PM · Jakarta',        xp: 3540, trend: 'up' },
    { rank: 5, name: 'Fajar Hidayat',   meta: 'Data · Tangerang',    xp: 3210, trend: 'down' },
    { rank: 6, name: 'Sarah Putri',     meta: 'Marketing · Depok',   xp: 2890, trend: 'up' },
    { rank: 7, name: 'Rayis Ananda',    meta: 'Lu',                  xp: 2340, trend: 'up',   you: true },
    { rank: 8, name: 'Randi Kusuma',    meta: 'SEO · Jakarta',       xp: 2180, trend: 'down' },
    { rank: 9, name: 'Tika Handayani',  meta: 'Ops · Semarang',      xp: 1950, trend: 'same' },
    { rank: 10, name: 'Yoga Pratama',   meta: 'BD · Medan',          xp: 1720, trend: 'down' },
  ];
  const medalColor = { gold: '#FFC400', silver: '#B8C0CC', bronze: '#D48556' };

  return (
    <div style={{ height: '100%', display: 'flex', flexDirection: 'column', background: 'var(--bg)', paddingTop: 44 }}>
      {/* Hero header */}
      <div style={{ padding: '12px 16px 14px', background: 'linear-gradient(180deg, rgba(212,255,58,0.1), transparent 90%)', borderBottom: '1px solid var(--border)' }}>
        <div style={{ display: 'flex', alignItems: 'center', gap: 10 }}>
          <div style={{ width: 48, height: 48, borderRadius: 14, background: 'linear-gradient(135deg, #B8C0CC, #6B7280)', display: 'flex', alignItems: 'center', justifyContent: 'center', boxShadow: '0 4px 12px rgba(184,192,204,0.3), inset 0 1px 0 rgba(255,255,255,0.3)' }}>
            {LIcon.trophy(26,'#0B0F14')}
          </div>
          <div style={{ flex: 1 }}>
            <div style={{ fontFamily: 'var(--font-display)', fontSize: 17, fontWeight: 700, letterSpacing: '-0.02em', lineHeight: 1 }}>Liga Perak</div>
            <div style={{ fontSize: 11, color: 'var(--text-muted)', marginTop: 3, display: 'flex', alignItems: 'center', gap: 4 }}>
              {LIcon.clock(11,'var(--text-muted)')}
              <span>3 hari 4 jam tersisa</span>
            </div>
          </div>
          <div style={{ display: 'flex', gap: 3 }}>
            {[1,2,3,4,5,6,7].map(i => (
              <div key={i} style={{ width: 5, height: 5, borderRadius: 5, background: i <= 4 ? 'var(--accent)' : 'var(--surface-3)', boxShadow: i <= 4 ? '0 0 4px var(--accent)' : 'none' }}/>
            ))}
          </div>
        </div>
        <div style={{ marginTop: 12, display: 'flex', gap: 6, fontSize: 10, fontFamily: 'var(--font-display)', fontWeight: 600 }}>
          <div style={{ flex: 1, padding: '6px 8px', borderRadius: 8, background: 'rgba(123,237,111,0.1)', border: '1px solid rgba(123,237,111,0.25)', color: 'var(--success)', display: 'flex', alignItems: 'center', gap: 4 }}>
            {LIcon.arrowUp(10,'#7BED6F')}<span>Top 5 → Liga Emas</span>
          </div>
          <div style={{ padding: '6px 8px', borderRadius: 8, background: 'rgba(255,75,145,0.08)', border: '1px solid rgba(255,75,145,0.2)', color: 'var(--danger)', display: 'flex', alignItems: 'center', gap: 4 }}>
            {LIcon.arrowDown(10,'#FF4B91')}<span>Btm 3</span>
          </div>
        </div>
      </div>

      {/* Leaderboard */}
      <div style={{ flex: 1, overflowY: 'auto', padding: '8px 10px', paddingBottom: 80 }}>
        {entries.map((e, i) => (
          <div key={e.rank} style={{ display: 'flex', alignItems: 'center', gap: 10, padding: '8px 10px', margin: '2px 0', borderRadius: 12, background: e.you ? 'rgba(212,255,58,0.07)' : 'transparent', border: e.you ? '1px solid rgba(212,255,58,0.3)' : '1px solid transparent', boxShadow: e.you ? '0 0 16px rgba(212,255,58,0.12)' : 'none', position: 'relative' }}>
            {e.rank === 5 && <div style={{ position: 'absolute', bottom: -3, left: 8, right: 8, height: 1, borderTop: '1px dashed rgba(123,237,111,0.3)' }}/>}
            {e.rank === 7 && <div style={{ position: 'absolute', top: -3, left: 8, right: 8, height: 1, borderTop: '1px dashed rgba(255,75,145,0.25)' }}/>}

            {/* Rank */}
            <div style={{ width: 24, textAlign: 'center', fontFamily: 'var(--font-display)', fontWeight: 700, fontSize: 14, color: e.medal ? medalColor[e.medal] : (e.you ? 'var(--accent)' : 'var(--text-dim)') }}>
              {e.medal ? (
                <div style={{ width: 22, height: 22, borderRadius: 22, margin: '0 auto', background: `linear-gradient(135deg, ${medalColor[e.medal]}, ${medalColor[e.medal]}99)`, color: '#0B0F14', display: 'flex', alignItems: 'center', justifyContent: 'center', fontSize: 11, fontWeight: 800, boxShadow: `0 2px 6px ${medalColor[e.medal]}55, inset 0 1px 0 rgba(255,255,255,0.4)` }}>
                  {e.rank}
                </div>
              ) : e.rank}
            </div>

            {/* Avatar */}
            <div style={{ width: 30, height: 30, borderRadius: 999, background: e.you ? 'linear-gradient(135deg, #FF4B91, #FFC400)' : `linear-gradient(135deg, hsl(${e.rank*37%360},60%,55%), hsl(${(e.rank*37+40)%360},55%,45%))`, display: 'flex', alignItems: 'center', justifyContent: 'center', fontFamily: 'var(--font-display)', fontWeight: 700, fontSize: 11, color: '#0B0F14', flexShrink: 0 }}>
              {e.name.split(' ').map(n=>n[0]).slice(0,2).join('')}
            </div>

            <div style={{ flex: 1, minWidth: 0 }}>
              <div style={{ fontSize: 12, fontWeight: 600, color: e.you ? 'var(--accent)' : 'var(--text)', overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap', fontFamily: e.you ? 'var(--font-display)' : 'var(--font-body)' }}>{e.you ? 'Lu' : e.name}</div>
              <div style={{ fontSize: 10, color: 'var(--text-muted)', marginTop: 1 }}>{e.meta}</div>
            </div>

            {e.trend === 'up' && LIcon.arrowUp(11,'#7BED6F')}
            {e.trend === 'down' && LIcon.arrowDown(11,'#FF4B91')}
            {e.trend === 'same' && <div style={{ width: 11, height: 2, borderRadius: 2, background: 'var(--text-dim)' }}/>}

            <div style={{ fontFamily: 'var(--font-display)', fontWeight: 700, fontSize: 12, color: e.you ? 'var(--accent)' : 'var(--text)', minWidth: 52, textAlign: 'right' }}>
              {e.xp.toLocaleString()}<span style={{ fontSize: 9, color: 'var(--text-dim)', marginLeft: 2, fontWeight: 500 }}>XP</span>
            </div>
          </div>
        ))}

        <div style={{ margin: '12px 4px 4px', padding: '10px 12px', borderRadius: 12, background: 'var(--accent-overlay-soft)', border: '1px dashed rgba(212,255,58,0.3)', display: 'flex', alignItems: 'center', gap: 8 }}>
          <div style={{ fontSize: 18 }}>🚀</div>
          <div style={{ flex: 1, fontSize: 11, lineHeight: 1.4 }}>
            <b style={{ color: 'var(--accent)', fontFamily: 'var(--font-display)' }}>Naik 3 liga</b>
            <span style={{ color: 'var(--text-muted)' }}> kalo lu masuk Top 5 minggu ini. Tinggal 870 XP lagi!</span>
          </div>
        </div>
      </div>

      <BottomNav active="league" onNavigate={onNavigate}/>
    </div>
  );
}

// ── L06 Profile ───────────────────────────────────────────────────────────────
function ScreenL06({ onNavigate }) {
  const stats = [
    { icon: '🔥', label: 'Streak',    value: '7',   unit: 'hari' },
    { icon: '⚡', label: 'Total XP',  value: '2,340', unit: 'xp' },
    { icon: '📚', label: 'Lesson',    value: '14',  unit: 'selesai' },
    { icon: '🏆', label: 'Level',     value: '2',   unit: 'AI-Fluent' },
  ];
  const badges = [
    { icon: '🔥', label: '7-Day Streak', done: true },
    { icon: '⚡', label: '2000 XP',      done: true },
    { icon: '🎯', label: 'First Quiz',   done: true },
    { icon: '🚀', label: '30-Day',       done: false },
    { icon: '💎', label: 'Level 3',      done: false },
    { icon: '🏅', label: 'Top 10',       done: false },
  ];

  return (
    <div style={{ height: '100%', overflowY: 'auto', background: 'var(--bg)', paddingTop: 44, paddingBottom: 80 }}>
      {/* Hero */}
      <div style={{ padding: '20px 20px 0', textAlign: 'center', position: 'relative', overflow: 'hidden' }}>
        <div style={{ position: 'absolute', top: -60, left: '50%', transform: 'translateX(-50%)', width: 300, height: 300, background: 'radial-gradient(circle, rgba(212,255,58,0.08), transparent 70%)', pointerEvents: 'none' }}/>
        <Avatar name="Rayis Ananda" size={72} style={{ margin: '0 auto 12px' }}/>
        <div style={{ fontFamily: 'var(--font-display)', fontSize: 22, fontWeight: 700, letterSpacing: '-0.02em', marginBottom: 4 }}>Rayis Ananda</div>
        <div style={{ fontSize: 12, color: 'var(--text-muted)', marginBottom: 12 }}>Product · PT Acme</div>
        <div style={{ display: 'flex', justifyContent: 'center', gap: 8, marginBottom: 20 }}>
          <LevelChip level={2} label="AI-FLUENT"/>
          <StreakChip days={7}/>
        </div>
      </div>

      {/* Stats grid */}
      <div style={{ margin: '0 16px 16px', display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 10 }}>
        {stats.map(s => (
          <div key={s.label} style={{ background: 'var(--surface-1)', border: '1px solid var(--border)', borderRadius: 14, padding: '14px 12px', textAlign: 'center' }}>
            <div style={{ fontSize: 22, marginBottom: 6 }}>{s.icon}</div>
            <div style={{ fontFamily: 'var(--font-display)', fontSize: 22, fontWeight: 700, letterSpacing: '-0.02em', color: 'var(--text)' }}>{s.value}</div>
            <div style={{ fontSize: 10, color: 'var(--text-muted)', fontWeight: 600, textTransform: 'uppercase', letterSpacing: '0.06em', marginTop: 2 }}>{s.unit}</div>
          </div>
        ))}
      </div>

      {/* XP progress */}
      <div style={{ margin: '0 16px 16px', padding: '14px 16px', background: 'var(--surface-1)', border: '1px solid var(--border)', borderRadius: 14 }}>
        <div style={{ display: 'flex', justifyContent: 'space-between', marginBottom: 8 }}>
          <span style={{ fontSize: 12, color: 'var(--text-muted)', fontWeight: 600 }}>Level 2 → Level 3</span>
          <span style={{ fontSize: 12, color: 'var(--accent)', fontFamily: 'var(--font-mono)', fontWeight: 700 }}>240 / 400 XP</span>
        </div>
        <ProgressBar value={240} max={400} height={8}/>
        <div style={{ fontSize: 11, color: 'var(--text-dim)', marginTop: 6 }}>160 XP lagi untuk naik level 🎯</div>
      </div>

      {/* Badges */}
      <div style={{ margin: '0 16px 16px' }}>
        <div style={{ fontSize: 11, color: 'var(--text-muted)', fontWeight: 700, letterSpacing: '0.08em', textTransform: 'uppercase', marginBottom: 12 }}>BADGE</div>
        <div style={{ display: 'grid', gridTemplateColumns: 'repeat(3,1fr)', gap: 10 }}>
          {badges.map(b => (
            <div key={b.label} style={{ background: b.done ? 'var(--accent-overlay-mid)' : 'var(--surface-1)', border: `1px solid ${b.done ? 'var(--accent-deep)' : 'var(--border)'}`, borderRadius: 14, padding: '14px 8px', textAlign: 'center', opacity: b.done ? 1 : 0.45 }}>
              <div style={{ fontSize: 26, marginBottom: 6 }}>{b.done ? b.icon : '🔒'}</div>
              <div style={{ fontSize: 10, fontWeight: 600, color: b.done ? 'var(--text)' : 'var(--text-dim)', lineHeight: 1.2 }}>{b.label}</div>
            </div>
          ))}
        </div>
      </div>

      {/* Settings row */}
      <div style={{ margin: '0 16px 16px', background: 'var(--surface-1)', border: '1px solid var(--border)', borderRadius: 14, overflow: 'hidden' }}>
        {[
          { icon: '🎯', label: 'Goals & Target' },
          { icon: '🔔', label: 'Notifikasi' },
          { icon: '🌙', label: 'Preferensi' },
        ].map((item, i, arr) => (
          <div key={item.label} style={{ display: 'flex', alignItems: 'center', gap: 12, padding: '14px 16px', borderBottom: i < arr.length-1 ? '1px solid var(--border)' : 'none', cursor: 'pointer' }}
            onMouseEnter={e => e.currentTarget.style.background='var(--bg-soft)'}
            onMouseLeave={e => e.currentTarget.style.background='transparent'}>
            <span style={{ fontSize: 18 }}>{item.icon}</span>
            <span style={{ flex: 1, fontSize: 13, fontWeight: 500, color: 'var(--text)' }}>{item.label}</span>
            <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="var(--text-dim)" strokeWidth="2"><path d="M9 18l6-6-6-6"/></svg>
          </div>
        ))}
      </div>

      <BottomNav active="profile" onNavigate={onNavigate}/>
    </div>
  );
}

Object.assign(window, { ScreenL01, ScreenL02, ScreenL03, ScreenL04, ScreenL05, ScreenL06, BottomNav, LIcon, Mascot });
