/* global React, RC, FONTS, rgba, ELEV, IcGradCap, IcChevRight, IcMapPin, IcHeart,
   IcSpeaker, IcX, IcCheck, IcCrown, IcGift, IcUserCircle, IcWechat, IcQrCode, IcSync, IcLogout, IcDevicePhone, IcTrash,
   SkipIcon, Skipping, PhoneFrame, TabHeader, TopBar, SCREEN_W, SCREEN_H */
// ─────────────────────────────────────────────────────────────
// RopeCounter V3 — Settings · WeChat Account Sheets · Paywall (4 tiers) · Sheets · Onboarding
// Synchronized with iOS SettingsView.swift, RCAccountSheetsV3_claudecode_20261103.swift,
// PaywallView.swift, RCMemberSheetV3, RCAboutSheetV3, RCMinorProtectionSheetV3,
// RCContactPageV3 & OnboardingView.swift (commit 4bc8d57b, _claudecode_20261104) // 2026.11.04 Naron
// ─────────────────────────────────────────────────────────────
const { useState: useStateS, useEffect: useEffectS } = React;

const WECHAT_GREEN = '#07C160';
const PLAN_PRICE = { '1m': 12, '1y': 48, '3y': 108, forever: 128 };
const planName = (p) => p === 'forever' ? '永久版' : p === '3y' ? '3 年版' : p === '1m' ? '月卡' : '1 年版';
const planBadgeText = (p) => p === 'forever' ? '永久' : p === '3y' ? '3 年' : p === '1m' ? '月卡' : '1 年';
const planTierMark = (p) => p === 'forever' ? 'LIFETIME' : p === '3y' ? '3 YEARS' : p === '1m' ? '1 MONTH' : '1 YEAR';

// ── primitives ──
function Section({ c, font, header, children, dark }) {
  return (
    <div style={{ marginBottom: 18 }}>
      {header && <div style={{ fontSize: 13, fontWeight: 600, color: c.textSec, padding: '0 6px 8px' }}>{header}</div>}
      <div style={{ background: c.surface, borderRadius: 16, overflow: 'hidden',
        border: dark ? `1px solid ${c.border}` : 'none', boxShadow: dark ? 'none' : ELEV[1] }}>{children}</div>
    </div>
  );
}
function Row({ c, font, icon, title, detail, trailing, onClick, last, chevron }) {
  return (
    <div onClick={onClick} style={{ display: 'flex', alignItems: 'center', gap: 12, minHeight: 50, padding: '10px 14px',
      cursor: onClick ? 'pointer' : 'default', borderBottom: last ? 'none' : `1px solid ${c.border}` }}>
      {icon && <div style={{ width: 30, height: 30, borderRadius: 8, background: rgba(icon.bg, 0.14), display: 'flex', alignItems: 'center', justifyContent: 'center', flexShrink: 0 }}>{icon.el}</div>}
      <div style={{ flex: 1, fontSize: 16, color: c.textPri, whiteSpace: 'nowrap' }}>{title}</div>
      {detail && <span style={{ fontSize: 15, color: c.textSec, minWidth: 0, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>{detail}</span>}
      {trailing}
      {chevron && <IcChevRight size={14} color={c.textTer} />}
    </div>
  );
}
function Toggle({ c, on }) {
  const trackOn = c.textSec;
  return (
    <div style={{ width: 50, height: 30, borderRadius: 999, background: on ? trackOn : c.surfaceMuted, position: 'relative', transition: 'background 160ms', flexShrink: 0 }}>
      <div style={{ position: 'absolute', top: 2, left: on ? 22 : 2, width: 26, height: 26, borderRadius: 999, background: '#fff', boxShadow: '0 1px 3px rgba(0,0,0,0.3)', transition: 'left 160ms' }} />
    </div>
  );
}
function Segmented({ c, font, options, value, onPick }) {
  return (
    <div style={{ display: 'flex', background: c.surfaceMuted, borderRadius: 10, padding: 3 }}>
      {options.map((o) => {
        const on = o.code === value;
        return (
          <div key={o.code} onClick={() => onPick && onPick(o.code)} style={{ flex: 1, height: 34, borderRadius: 8, cursor: 'pointer',
            display: 'flex', alignItems: 'center', justifyContent: 'center', background: on ? c.surface : 'transparent',
            boxShadow: on ? ELEV[1] : 'none', fontSize: 14, fontWeight: on ? 600 : 500, color: on ? c.textPri : c.textSec, transition: 'background 120ms' }}>{o.label}</div>
        );
      })}
    </div>
  );
}

// ── Top-Right WeChat Login / Account Capsule Button (RCAccountHeaderButton_claudecode_20261104) ── // 2026.11.04 Naron
function WechatHeaderCapsule({ c, font, account, onTapLogin, onTapManage }) {
  const truncate6 = (s) => {
    const arr = Array.from(s || '');
    return arr.length > 6 ? arr.slice(0, 6).join('') + '…' : s;
  };
  if (account) {
    return (
      <button type="button" onClick={onTapManage} style={{
        display: 'inline-flex', alignItems: 'center', gap: 6,
        padding: '5px 10px 5px 6px', borderRadius: 999,
        background: c.surface, border: `1px solid ${c.border}`,
        cursor: 'pointer', fontFamily: font.sans
      }}>
        <span style={{ position: 'relative', width: 24, height: 24, display: 'inline-flex', flexShrink: 0 }}>
          <span style={{
            width: 24, height: 24, borderRadius: 999, background: c.accentSoft, color: c.accent,
            display: 'flex', alignItems: 'center', justifyContent: 'center',
            fontFamily: font.rounded, fontSize: 11, fontWeight: 700
          }}>{account.initial || '天'}</span>
          <span style={{
            position: 'absolute', right: -0.5, bottom: -0.5, width: 7, height: 7, borderRadius: 999,
            background: WECHAT_GREEN, border: `1.2px solid ${c.surface}`, boxSizing: 'border-box'
          }}/>
        </span>
        <span style={{ fontSize: 13.5, fontWeight: 600, color: c.textPri, whiteSpace: 'nowrap' }}>{truncate6(account.nickname || '天天向上')}</span>
        <svg width="11" height="11" viewBox="0 0 14 14" fill="none" stroke={c.textSec} strokeWidth="2.2" strokeLinecap="round" strokeLinejoin="round"><path d="M5 2l5 5-5 5"/></svg>
      </button>
    );
  }
  return (
    <button type="button" onClick={onTapLogin} style={{
      display: 'inline-flex', alignItems: 'center', gap: 5,
      padding: '6.5px 12px', borderRadius: 999,
      background: c.surface, border: `1px solid ${c.border}`,
      cursor: 'pointer', fontFamily: font.sans
    }}>
      <IcUserCircle size={14} color={WECHAT_GREEN}/>
      <span style={{ fontSize: 13.5, fontWeight: 600, color: c.textPri, whiteSpace: 'nowrap' }}>点击登录</span>
    </button>
  );
}

// ── Screen F: Settings (Tab 3「小天天」, synchronized with SettingsView.swift commit 4bc8d57b) ── // 2026.11.04 Naron
function SettingsScreen({
  platform = 'ios', dark = false, tab = 'settings', onTab,
  onProvince, onMinor, onPaywall, onMember, onAbout, onContact, onHowto,
  member = null, account = null, onTapLogin, onTapManage
}) {
  const c = dark ? RC.dark : RC.light;
  const font = platform === 'android' ? FONTS.android : FONTS.ios;
  const [theme, setTheme] = useStateS('auto');
  const isPro = !!member;

  return (
    <PhoneFrame platform={platform} dark={dark} statusDark={!dark} tab={tab} onTab={onTab}>
      <div style={{ position: 'absolute', inset: 0, background: c.bg }} />
      <TabHeader
        c={c} font={font} platform={platform} title="小天天" subtitle={null}
        trailing={<WechatHeaderCapsule c={c} font={font} account={account} onTapLogin={onTapLogin} onTapManage={onTapManage}/>}
      />
      <div style={{ position: 'absolute', top: platform === 'android' ? 110 : 112, left: 0, right: 0, bottom: platform === 'android' ? 84 : 90,
        overflow: 'auto', padding: '12px 16px 16px' }}>

        {/* First card: Membership banner (upsellBanner_claudecode_20260904 — no large account card above it!) */}
        {!member ? (
          <div onClick={onPaywall} style={{
            display: 'flex', alignItems: 'center', gap: 14, padding: '22px 18px', borderRadius: 20, cursor: 'pointer',
            background: rgba(c.accent, dark ? 0.18 : 0.12), border: `1px solid ${rgba(c.accent, 0.34)}`,
            boxShadow: dark ? 'none' : ELEV[1], marginBottom: 18
          }} data-comment-anchor="9690166212-div-68-9">
            <div style={{ width: 48, height: 48, borderRadius: 14, background: c.warning, display: 'flex', alignItems: 'center', justifyContent: 'center', flexShrink: 0 }}>
              <IcGift size={26} color="#FFFFFF" />
            </div>
            <div style={{ flex: 1 }}>
              <div style={{ fontSize: 19, fontWeight: 700, color: c.textPri, letterSpacing: -0.3 }}>解锁会员大礼包</div>
              <div style={{ fontSize: 13, color: c.textSec, marginTop: 3 }}>工信部备案产品 · 买断制安全省心</div>
            </div>
            <IcChevRight size={16} color={c.accent} />
          </div>
        ) : (
          <div style={{ borderRadius: 16, overflow: 'hidden', marginBottom: 18, background: c.surface, border: dark ? `1px solid ${c.border}` : 'none', boxShadow: dark ? 'none' : ELEV[1] }}>
            <div onClick={onMember} style={{ display: 'flex', alignItems: 'center', gap: 12, padding: '14px 16px', cursor: 'pointer', background: rgba(c.accent, dark ? 0.16 : 0.10) }}>
              <div style={{ width: 38, height: 38, borderRadius: 11, background: member.plan === 'forever' ? '#1E293B' : c.accent, display: 'flex', alignItems: 'center', justifyContent: 'center', flexShrink: 0 }}>
                <IcCrown size={20} color={member.plan === 'forever' ? '#F4B942' : c.onAccent} filled={member.plan === 'forever'} />
              </div>
              <div style={{ flex: 1 }}>
                <div style={{ display: 'flex', alignItems: 'center', gap: 8 }}>
                  <span style={{ fontSize: 15, fontWeight: 600, color: c.textPri }}>会员已开通</span>
                  <span style={{ fontSize: 11.5, fontWeight: 700, padding: '2px 8px', borderRadius: 999, background: member.plan === 'forever' ? '#1E293B' : c.accent, color: member.plan === 'forever' ? '#F4B942' : c.onAccent }}>
                    {planBadgeText(member.plan)}
                  </span>
                </div>
                <div style={{ fontSize: 12.5, color: c.textSec, marginTop: 2 }}>
                  {member.plan === 'forever' ? '一次买断 · 终身有效' : `有效期至 ${member.until} · 到期不自动续费`}
                </div>
              </div>
              <IcChevRight size={13} color={c.accent} />
            </div>
          </div>
        )}

        <Section c={c} font={font} dark={dark}>
          <Row c={c} font={font} title="恢复购买" chevron last />
        </Section>

        <Section c={c} font={font} dark={dark} header="中考">
          <Row c={c} font={font} title="中考评分标准" onClick={onProvince} chevron />
          <Row c={c} font={font} title="未成年人保护说明" onClick={onMinor} chevron />
          <div style={{ padding: '12px 14px', borderBottom: `1px solid ${c.border}` }}>
            <div style={{ fontSize: 16, color: c.textPri, marginBottom: 10 }}>主题设置</div>
            <Segmented c={c} font={font} value={theme} onPick={setTheme} options={[{ code: 'auto', label: '跟随系统' }, { code: 'light', label: '浅色' }, { code: 'dark', label: '深色' }]} />
          </div>
          <Row
            c={c} font={font}
            icon={{ bg: c.success, el: <IcHeart size={16} color={c.success} /> }}
            title={platform === 'android' ? '健康连接' : '健康'}
            onClick={!isPro ? onPaywall : undefined}
            trailing={
              <span style={{ display: 'inline-flex', alignItems: 'center', gap: 6, fontSize: 14, color: isPro ? c.success : c.warning, fontWeight: 500 }}>
                <span style={{ width: 8, height: 8, borderRadius: 999, background: isPro ? c.success : c.warning }} />
                {isPro ? '已连接' : 'Pro 解锁'}
              </span>
            }
            last
          />
        </Section>

        <Section c={c} font={font} dark={dark} header="隐私">
          <Row c={c} font={font} title="隐私政策" chevron />
          <Row c={c} font={font} title="用户协议" chevron last />
        </Section>

        <Section c={c} font={font} dark={dark} header="关于">
          <Row c={c} font={font} title="关于我们" onClick={onAbout} chevron />
          <Row c={c} font={font} title="联系我们" onClick={onContact} chevron />
          <Row c={c} font={font} title="使用说明" onClick={onHowto} chevron last />
        </Section>

        <div style={{ textAlign: 'center', fontSize: 12, color: c.textTer, padding: '4px 0 8px', lineHeight: 1.7 }}>
          小天天练跳绳 · 2026.11.04<br />苏ICP备18044027号-9A
        </div>
      </div>
    </PhoneFrame>
  );
}

// ── WeChat Login Sheet (RCAccountLoginSheet_claudecode_20261103) ── // 2026.11.04 Naron
function WechatLoginSheet({ platform = 'ios', dark = false, qrMode: initialQR = false, onClose, onLoginSuccess }) {
  const c = dark ? RC.dark : RC.light;
  const font = platform === 'android' ? FONTS.android : FONTS.ios;
  const [isQR, setIsQR] = useStateS(initialQR);
  const [agreed, setAgreed] = useStateS(true);
  const [showTestCode, setShowTestCode] = useStateS(false);
  const [testCode, setTestCode] = useStateS('');
  const [statusMsg, setStatusMsg] = useStateS('');

  const handleLogin = () => {
    if (!agreed) {
      setStatusMsg('请先勾选同意《用户协议》和《隐私政策》');
      return;
    }
    setStatusMsg('');
    if (onLoginSuccess) onLoginSuccess({ nickname: '天天向上', initial: '天', devicesCount: 2, deviceLimit: 2 });
  };

  return (
    <div onClick={onClose} style={{ position: 'absolute', inset: 0, zIndex: 200, background: rgba('#0F172A', dark ? 0.6 : 0.42), display: 'flex', flexDirection: 'column', justifyContent: 'flex-end', fontFamily: font.sans }}>
      <div onClick={(e) => e.stopPropagation()} style={{ position: 'relative', background: c.bg, borderTopLeftRadius: 24, borderTopRightRadius: 24, padding: '8px 20px 28px', boxShadow: '0 -8px 32px rgba(0,0,0,0.3)' }}>
        <div style={{ display: 'flex', justifyContent: 'center', padding: '2px 0 8px' }}><div style={{ width: 36, height: 5, borderRadius: 999, background: c.border }} /></div>
        {/* Navigation Bar Header */}
        <div style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between', height: 36, marginBottom: 12 }}>
          <span style={{ width: 40 }}/>
          <span style={{ fontSize: 16, fontWeight: 600, color: c.textPri }}>{isQR ? '微信扫码登录' : '微信登录'}</span>
          <button type="button" onClick={onClose} style={{ border: 'none', background: 'none', color: c.textSec, fontSize: 15, cursor: 'pointer', padding: 0, width: 40, textAlign: 'right' }}>关闭</button>
        </div>

        {/* Header block */}
        <div style={{ display: 'flex', flexDirection: 'column', alignItems: 'center', gap: 10 }}>
          <div style={{ width: 56, height: 56, borderRadius: 999, background: rgba(WECHAT_GREEN, 0.14), display: 'flex', alignItems: 'center', justifyContent: 'center' }}>
            {isQR ? <IcQrCode size={24} color={WECHAT_GREEN}/> : <IcWechat size={26} color={WECHAT_GREEN}/>}
          </div>
          <div style={{ fontSize: 20, fontWeight: 700, color: c.textPri }}>{isQR ? '使用微信扫一扫登录' : '微信登录'}</div>
          <div style={{ fontSize: 13, color: c.textSec, textAlign: 'center', lineHeight: 1.45 }}>
            登录微信账号，跨设备同步已购会员权益（最多 2 台设备同时在线）
          </div>
        </div>

        {/* Body: One-Click Buttons vs QR Code */}
        {!isQR ? (
          <div style={{ display: 'flex', flexDirection: 'column', gap: 12, marginTop: 18 }}>
            <button type="button" onClick={handleLogin} style={{
              height: 48, borderRadius: 999, border: 'none', background: WECHAT_GREEN, color: '#FFFFFF',
              display: 'flex', alignItems: 'center', justifyContent: 'center', gap: 8,
              fontSize: 16, fontWeight: 700, cursor: 'pointer'
            }}>
              <IcWechat size={18} color="#FFFFFF"/>
              <span>微信一键登录</span>
            </button>
            <button type="button" onClick={() => { if (!agreed) { setStatusMsg('请先勾选同意《用户协议》和《隐私政策》'); return; } setStatusMsg(''); setIsQR(true); }} style={{
              height: 46, borderRadius: 999, border: `1px solid ${c.border}`, background: c.surface, color: WECHAT_GREEN,
              display: 'flex', alignItems: 'center', justifyContent: 'center', gap: 6,
              fontSize: 15, fontWeight: 600, cursor: 'pointer'
            }}>
              <IcQrCode size={16} color={WECHAT_GREEN}/>
              <span>微信扫码登录</span>
            </button>
          </div>
        ) : (
          <div style={{ display: 'flex', flexDirection: 'column', alignItems: 'center', gap: 12, marginTop: 16 }}>
            <div style={{
              width: 184, height: 184, borderRadius: 16, background: '#FFFFFF', border: `1px solid ${c.border}`,
              display: 'flex', alignItems: 'center', justifyContent: 'center', padding: 14
            }}>
              {/* Crisp SVG QR Code representation */}
              <svg width="152" height="152" viewBox="0 0 29 29" fill="#0F172A" shapeRendering="crispEdges">
                <path d="M1 1h7v7H1V1zm1 1v5h5V2H2zm1 1h3v3H3V3zm18-2h7v7h-7V1zm1 1v5h5V2h-5zm1 1h3v3h-3V3zM1 21h7v7H1v-7zm1 1v5h5v-5H2zm1 1h3v3H3v-3zM10 1h2v2h-2V1zm4 0h3v1h-3V1zm5 1h1v3h-1V2zM10 5h3v2h-3V5zm5 0h3v3h-3V5zM1 10h3v2H1v-2zm5 0h2v3H6v-3zm4 0h4v2h-4v-2zm6 0h2v4h-2v-4zm5 0h3v2h-3v-2zm5 0h2v3h-2v-3zM2 14h2v3H2v-3zm5 1h4v2H7v-2zm6-1h3v4h-3v-4zm5 2h4v2h-4v-2zm6 0h3v3h-3v-3zM1 18h4v2H1v-2zm7 1h3v3H8v-3zm5 0h4v2h-4v-2zm6 1h2v4h-2v-4zm4 1h4v3h-4v-3zM10 24h3v4h-3v-4zm5 1h3v3h-3v-3zm5 1h3v2h-3v-2zm5 0h3v2h-3v-2z"/>
              </svg>
            </div>
            <div style={{ fontSize: 12.5, color: c.textSec }}>请使用另一台手机的微信扫一扫上方二维码</div>
            <button type="button" onClick={() => setIsQR(false)} style={{ border: 'none', background: 'none', color: c.textSec, fontSize: 14, fontWeight: 600, cursor: 'pointer', padding: '4px 8px' }}>
              返回微信一键登录
            </button>
          </div>
        )}

        {/* Agreement Row */}
        <div style={{ display: 'flex', alignItems: 'center', justifyContent: 'center', gap: 8, marginTop: 18 }}>
          <button type="button" onClick={() => { setAgreed(!agreed); setStatusMsg(''); }} style={{
            width: 18, height: 18, borderRadius: 999, border: agreed ? 'none' : `1.6px solid ${c.textTer}`,
            background: agreed ? WECHAT_GREEN : 'transparent', display: 'flex', alignItems: 'center', justifyContent: 'center',
            cursor: 'pointer', padding: 0, flexShrink: 0
          }}>
            {agreed && <IcCheck size={11} color="#FFFFFF"/>}
          </button>
          <div style={{ fontSize: 12.5, color: c.textSec }}>
            已阅读并同意 <span style={{ color: c.accent, fontWeight: 500 }}>《用户协议》</span> 和 <span style={{ color: c.accent, fontWeight: 500 }}>《隐私政策》</span>
          </div>
        </div>

        {statusMsg && (
          <div style={{ fontSize: 13, fontWeight: 500, color: c.warning, textAlign: 'center', marginTop: 10 }}>{statusMsg}</div>
        )}

        {/* Reviewer test code entry */}
        {!showTestCode ? (
          <div style={{ textAlign: 'center', marginTop: 14 }}>
            <button type="button" onClick={() => setShowTestCode(true)} style={{ border: 'none', background: 'none', color: c.textTer, opacity: 0.75, fontSize: 11.5, cursor: 'pointer' }}>
              使用测试码登录
            </button>
          </div>
        ) : (
          <div style={{ marginTop: 14, paddingTop: 12, borderTop: `1px solid ${c.border}`, display: 'flex', flexDirection: 'column', gap: 8 }}>
            <div style={{ fontSize: 12, fontWeight: 600, color: c.textSec, textAlign: 'center' }}>测试授权码登录（仅审核/联调使用）</div>
            <div style={{ display: 'flex', gap: 8 }}>
              <input value={testCode} onChange={(e) => setTestCode(e.target.value)} placeholder="输入测试授权码" style={{
                flex: 1, height: 38, borderRadius: 10, border: `1px solid ${c.border}`, background: c.surface,
                padding: '0 12px', fontSize: 14, color: c.textPri, outline: 'none'
              }}/>
              <button type="button" onClick={handleLogin} style={{
                height: 38, padding: '0 14px', borderRadius: 10, border: 'none', background: c.accent, color: '#FFFFFF',
                fontSize: 13, fontWeight: 600, cursor: 'pointer'
              }}>验证登录</button>
            </div>
          </div>
        )}
      </div>
    </div>
  );
}

// ── Account & Device Manage Sheet (RCAccountManageSheet_claudecode_20261103) ── // 2026.11.04 Naron
function AccountManageSheet({ platform = 'ios', dark = false, account, onClose, onLogout }) {
  const c = dark ? RC.dark : RC.light;
  const font = platform === 'android' ? FONTS.android : FONTS.ios;
  const user = account || { nickname: '天天向上', initial: '天' };
  const [devices, setDevices] = useStateS([
    { id: 'd1', name: 'iPhone 15 Pro', platform: 'iOS', lastLogin: '今天 14:20', current: true },
    { id: 'd2', name: 'Xiaomi 14', platform: 'Android', lastLogin: '昨天 20:15', current: false },
  ]);
  const [banner, setBanner] = useStateS('');

  return (
    <div onClick={onClose} style={{ position: 'absolute', inset: 0, zIndex: 200, background: rgba('#0F172A', dark ? 0.6 : 0.42), display: 'flex', flexDirection: 'column', justifyContent: 'flex-end', fontFamily: font.sans }}>
      <div onClick={(e) => e.stopPropagation()} style={{ position: 'relative', background: c.bg, borderTopLeftRadius: 24, borderTopRightRadius: 24, maxHeight: SCREEN_H - 96, display: 'flex', flexDirection: 'column', boxShadow: '0 -8px 32px rgba(0,0,0,0.3)' }}>
        <div style={{ display: 'flex', justifyContent: 'center', padding: '8px 0 6px' }}><div style={{ width: 36, height: 5, borderRadius: 999, background: c.border }} /></div>
        {/* Navigation Bar */}
        <div style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between', padding: '4px 20px 10px' }}>
          <span style={{ width: 40 }}/>
          <span style={{ fontSize: 16, fontWeight: 600, color: c.textPri }}>账号与设备管理</span>
          <button type="button" onClick={onClose} style={{ border: 'none', background: 'none', color: c.accent, fontSize: 15, fontWeight: 600, cursor: 'pointer', padding: 0, width: 40, textAlign: 'right' }}>完成</button>
        </div>

        <div style={{ flex: 1, overflow: 'auto', padding: '8px 16px 28px', display: 'flex', flexDirection: 'column', gap: 18 }}>
          {/* Profile Header Card */}
          <div style={{
            background: c.surface, borderRadius: 16, padding: 16,
            border: dark ? `1px solid ${c.border}` : 'none', boxShadow: dark ? 'none' : ELEV[1],
            display: 'flex', alignItems: 'center', gap: 14
          }}>
            <div style={{
              width: 54, height: 54, borderRadius: 999, background: c.accentSoft, color: c.accent,
              display: 'flex', alignItems: 'center', justifyContent: 'center',
              fontFamily: font.rounded, fontSize: 22, fontWeight: 700, flexShrink: 0
            }}>{user.initial || '天'}</div>
            <div style={{ flex: 1, minWidth: 0 }}>
              <div style={{ display: 'flex', alignItems: 'center', gap: 8 }}>
                <span style={{ fontSize: 18, fontWeight: 700, color: c.textPri }}>{user.nickname || '天天向上'}</span>
                <span style={{ fontSize: 11, fontWeight: 600, color: c.accent, background: c.accentSoft, padding: '3px 8px', borderRadius: 999 }}>已绑定微信</span>
              </div>
              <div style={{ fontSize: 13, color: c.textSec, marginTop: 5 }}>
                跨设备同步已购会员权益（最多 2 台设备同时在线）
              </div>
            </div>
          </div>

          {/* Online Devices Section (X/2) */}
          <div>
            <div style={{ fontSize: 13, fontWeight: 600, color: c.textSec, padding: '0 6px 8px' }}>在线设备 ({devices.length}/2)</div>
            <div style={{ background: c.surface, borderRadius: 16, overflow: 'hidden', border: dark ? `1px solid ${c.border}` : 'none', boxShadow: dark ? 'none' : ELEV[1] }}>
              {devices.map((d, idx) => (
                <div key={d.id} style={{
                  display: 'flex', alignItems: 'center', gap: 12, padding: '12px 14px',
                  borderBottom: idx === devices.length - 1 ? 'none' : `1px solid ${c.border}`
                }}>
                  <div style={{ width: 34, height: 34, borderRadius: 9, background: c.accentSoft, display: 'flex', alignItems: 'center', justifyContent: 'center', flexShrink: 0 }}>
                    <IcDevicePhone size={16} color={c.accent}/>
                  </div>
                  <div style={{ flex: 1, minWidth: 0 }}>
                    <div style={{ display: 'flex', alignItems: 'center', gap: 6 }}>
                      <span style={{ fontSize: 15, fontWeight: 600, color: c.textPri }}>{d.name}</span>
                      {d.current && (
                        <span style={{ fontSize: 11, fontWeight: 600, color: c.accent, background: c.accentSoft, padding: '2px 6px', borderRadius: 999 }}>本机</span>
                      )}
                    </div>
                    <div style={{ fontSize: 12, color: c.textSec, marginTop: 3 }}>{d.platform} · 最近登录 {d.lastLogin}</div>
                  </div>
                  {!d.current && (
                    <button type="button" onClick={() => { setDevices(devices.filter(x => x.id !== d.id)); setBanner(`已移除设备「${d.name}」`); }} style={{
                      border: 'none', background: 'none', color: c.danger, fontSize: 13, fontWeight: 600, cursor: 'pointer', padding: '6px 10px'
                    }}>移除</button>
                  )}
                </div>
              ))}
            </div>
          </div>

          {banner && (
            <div style={{ fontSize: 13, fontWeight: 500, color: c.warning, padding: '0 6px' }}>{banner}</div>
          )}

          {/* Actions Section */}
          <div>
            <div style={{ background: c.surface, borderRadius: 16, overflow: 'hidden', border: dark ? `1px solid ${c.border}` : 'none', boxShadow: dark ? 'none' : ELEV[1] }}>
              <Row
                c={c} font={font}
                icon={{ bg: c.accent, el: <IcSync size={15} color={c.accent}/> }}
                title="同步会员权益"
                detail="跨设备同步已购会员权益"
                onClick={() => setBanner('会员权益已同步')}
                chevron
              />
              <Row
                c={c} font={font}
                icon={{ bg: c.textSec, el: <IcLogout size={15} color={c.textSec}/> }}
                title="退出登录"
                onClick={onLogout}
                chevron
              />
              <Row
                c={c} font={font}
                icon={{ bg: c.danger, el: <IcTrash size={15} color={c.danger}/> }}
                title="注销账号"
                detail="永久解除云端账号绑定"
                onClick={onLogout}
                chevron
                last
              />
            </div>
            <div style={{ fontSize: 12, color: c.textTer, marginTop: 12, padding: '0 6px', lineHeight: 1.5 }}>
              同一微信账号最多支持 2 台设备同时在线；在第 3 台设备登录时，最早登录的设备将自动下线。
            </div>
          </div>
        </div>
      </div>
    </div>
  );
}

// ── Purchase success — rendered INSIDE the paywall sheet (content swaps in place).
const CONFETTI = Array.from({ length: 34 }, (_, i) => ({ x: 6 + ((i * 41) % 88), delay: (i * 37) % 420, dur: 1500 + (i * 53) % 700, sway: ((i % 2 ? 1 : -1) * (14 + (i * 7) % 26)), rot: (i * 97) % 360, w: 5 + (i * 3) % 5, h: 9 + (i * 5) % 6, k: i % 4, round: i % 7 === 0 }));
function Confetti({ c }) {
  const cols = [c.accent, c.examMid, '#F4B942', '#7DD3FC'];
  return (
    <div style={{ position: 'absolute', inset: 0, pointerEvents: 'none', zIndex: 30, overflow: 'hidden' }}>
      <style>{`@keyframes rcFall{0%{transform:translate3d(0,-40px,0) rotate(0deg);opacity:0}8%{opacity:1}100%{transform:translate3d(var(--sway),560px,0) rotate(var(--rot));opacity:0}}@keyframes rcRise{0%{transform:translateY(18px) scale(.96);opacity:0}100%{transform:translateY(0) scale(1);opacity:1}}@keyframes rcSheen{0%{transform:translateX(-140%) skewX(-18deg)}100%{transform:translateX(240%) skewX(-18deg)}}@keyframes rcFade{0%{opacity:0;transform:translateY(8px)}100%{opacity:1;transform:none}}`}</style>
      {CONFETTI.map((p, i) => <span key={i} style={{ position: 'absolute', left: `${p.x}%`, top: 0, width: p.w, height: p.round ? p.w : p.h, borderRadius: p.round ? 999 : 1.5, background: cols[p.k], '--sway': `${p.sway}px`, '--rot': `${p.rot + 540}deg`,
        animation: `rcFall ${p.dur}ms cubic-bezier(.25,.4,.45,1) ${p.delay}ms both`, willChange: 'transform,opacity' }} />)}
    </div>
  );
}
const RC_KEYFRAMES = `@keyframes rcRise{0%{transform:translateY(18px) scale(.96);opacity:0}100%{transform:translateY(0) scale(1);opacity:1}}@keyframes rcSheen{0%{transform:translateX(-140%) skewX(-18deg)}100%{transform:translateX(240%) skewX(-18deg)}}@keyframes rcFade{0%{opacity:0;transform:translateY(8px)}100%{opacity:1;transform:none}}`;

// Membership card — shared by success state and member-detail sheet (RCMemberCardV3_claudecode_20260907: fixed height 220, radius 22) // 2026.11.04 Naron
function MemberCard({ c, font, plan, until, style }) {
  const isForever = plan === 'forever';
  const cardBg = isForever ? 'linear-gradient(135deg,#1E293B 0%,#334155 60%,#475569 100%)' : `linear-gradient(135deg,${c.accent} 0%,${rgba(c.accent, 0.78)} 100%)`;
  const ink = '#FFFFFF';
  return (
    <>
      <style>{RC_KEYFRAMES}</style>
      <div style={{
        position: 'relative', height: 220, borderRadius: 22, padding: '18px 20px 16px',
        color: ink, background: cardBg, overflow: 'hidden',
        boxShadow: '0 18px 40px rgba(15,23,42,0.28)',
        display: 'flex', flexDirection: 'column', justifyContent: 'space-between',
        animation: 'rcRise 480ms cubic-bezier(.2,.8,.2,1) 120ms both', ...style
      }}>
        <div style={{ position: 'absolute', top: 0, bottom: 0, left: 0, width: '38%', background: 'linear-gradient(90deg,transparent,rgba(255,255,255,0.22),transparent)', animation: 'rcSheen 1400ms ease-out 500ms both', pointerEvents: 'none' }} />
        <div style={{ position: 'absolute', right: -26, bottom: -30, opacity: isForever ? 0.22 : 0.14 }}><IcCrown size={170} color={isForever ? '#F4B942' : ink} filled /></div>
        <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'flex-start' }}>
          <div style={{ display: 'flex', alignItems: 'center', gap: 8 }}>
            <div style={{ width: 34, height: 34, borderRadius: 10, background: 'rgba(255,255,255,0.18)', display: 'flex', alignItems: 'center', justifyContent: 'center' }}><IcCrown size={19} color={isForever ? '#F4B942' : ink} filled={isForever} /></div>
            <div><div style={{ fontSize: 14, fontWeight: 700 }}>小天天练跳绳</div><div style={{ fontSize: 11.5, opacity: 0.8 }}>会员</div></div>
          </div>
          <span style={{ fontSize: 11.5, fontWeight: 700, padding: '4px 10px', borderRadius: 999, background: 'rgba(255,255,255,0.2)', letterSpacing: 0.3, color: isForever ? '#F4B942' : ink }}>{planTierMark(plan)}</span>
        </div>
        <div style={{ fontFamily: font.rounded, fontSize: 32, fontWeight: 700, letterSpacing: -1, lineHeight: 1 }}>{planName(plan)}</div>
        <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'flex-end' }}>
          <div><div style={{ fontSize: 10.5, opacity: 0.75, letterSpacing: 0.6 }}>{isForever ? '有效期' : '有效期至'}</div><div style={{ fontFamily: font.mono, fontSize: 15, fontWeight: 600, marginTop: 2 }}>{until}</div></div>
          <div style={{ textAlign: 'right' }}><div style={{ fontSize: 10.5, opacity: 0.75, letterSpacing: 0.6 }}>会员</div><div style={{ fontSize: 15, fontWeight: 600, marginTop: 2 }}>小天天</div></div>
        </div>
      </div>
    </>
  );
}

// SuccessBody (PaywallView.swift:540-585 + RCBenefitTilesV3_claudecode_20260907: 无限测量 / 多种模式 / 趋势分析 + "知道了") // 2026.11.04 Naron
function SuccessBody({ c, font, dark, plan, onDone }) {
  const until = plan === 'forever' ? '终身有效' : plan === '3y' ? '2029-11-04' : plan === '1m' ? '2026-12-04' : '2027-11-04';
  return (
    <div style={{ display: 'flex', flexDirection: 'column', flex: 1, animation: 'rcFade 320ms ease-out both' }}>
      <div style={{ textAlign: 'center', marginTop: 6 }}>
        <div style={{ fontSize: 13, fontWeight: 600, color: c.accent, letterSpacing: 1 }}>WELCOME</div>
        <div style={{ fontSize: 28, fontWeight: 700, color: c.textPri, letterSpacing: -0.5, marginTop: 4 }}>开通成功</div>
        <div style={{ fontSize: 14.5, color: c.textSec, marginTop: 6, lineHeight: 1.45 }}>全部功能已解锁，去跳第一组吧</div>
      </div>
      <MemberCard c={c} font={font} plan={plan} until={until} style={{ marginTop: 18 }} />
      <div style={{ marginTop: 14, display: 'grid', gridTemplateColumns: 'repeat(3,1fr)', gap: 8 }}>
        {[
          ['无限测量', '次数不限随便测'],
          ['多种模式', '定时定数自由练'],
          ['趋势分析', '看见每天的进步'],
        ].map(([t, d]) => (
          <div key={t} style={{ background: c.surface, borderRadius: 14, padding: '12px 10px', textAlign: 'center', border: dark ? `1px solid ${c.border}` : 'none', boxShadow: dark ? 'none' : ELEV[1] }}>
            <div style={{ display: 'flex', justifyContent: 'center', marginBottom: 6 }}><span style={{ width: 22, height: 22, borderRadius: 999, background: rgba(c.accent, dark ? 0.22 : 0.12), display: 'flex', alignItems: 'center', justifyContent: 'center' }}><IcCheck size={11} color={c.accent} /></span></div>
            <div style={{ fontSize: 13, fontWeight: 600, color: c.textPri }}>{t}</div>
            <div style={{ fontSize: 11, color: c.textTer, marginTop: 2 }}>{d}</div>
          </div>
        ))}
      </div>
      <div style={{ flex: 1, minHeight: 18 }} />
      <button onClick={onDone} style={{ height: 54, flexShrink: 0, borderRadius: 16, border: 'none', background: c.accent, color: c.onAccent, fontFamily: font.sans, fontSize: 17, fontWeight: 600, cursor: 'pointer', boxShadow: ELEV[2] }}>知道了</button>
    </div>
  );
}

// ── Member detail sheet (RCMemberSheetV3_claudecode_20260907: MemberCard 220pt + "知道了", no 3-tile grid, no diff-price upgrade) ── // 2026.11.04 Naron
function MemberSheet({ platform = 'ios', dark = false, member, onClose }) {
  const c = dark ? RC.dark : RC.light;
  const font = platform === 'android' ? FONTS.android : FONTS.ios;
  return (
    <div style={{ position: 'absolute', inset: 0, zIndex: 200, background: rgba('#0F172A', dark ? 0.6 : 0.42), display: 'flex', flexDirection: 'column', justifyContent: 'flex-end', fontFamily: font.sans }} onClick={onClose}>
      <div onClick={(e) => e.stopPropagation()} style={{ position: 'relative', background: c.surface, borderTopLeftRadius: 24, borderTopRightRadius: 24, padding: '10px 20px 30px', boxShadow: '0 -8px 32px rgba(0,0,0,0.3)' }}>
        <div style={{ display: 'flex', justifyContent: 'center', padding: '4px 0 12px' }}><div style={{ width: 36, height: 5, borderRadius: 999, background: c.border }} /></div>
        <div onClick={onClose} style={{ position: 'absolute', top: 22, right: 16, width: 30, height: 30, borderRadius: 999, background: c.surfaceMuted, display: 'flex', alignItems: 'center', justifyContent: 'center', cursor: 'pointer' }}><IcX size={12} color={c.textSec} /></div>
        <div style={{ textAlign: 'center', marginTop: 4 }}>
          <div style={{ fontSize: 13, fontWeight: 600, color: c.accent, letterSpacing: 1 }}>MEMBER</div>
          <div style={{ fontSize: 26, fontWeight: 700, color: c.textPri, letterSpacing: -0.5, marginTop: 4 }}>我的会员</div>
          <div style={{ fontSize: 14, color: c.textSec, marginTop: 6 }}>{member.plan === 'forever' ? '终身有效 · 一次买断' : '一次付费，到期不自动续费'}</div>
        </div>
        <MemberCard c={c} font={font} plan={member.plan} until={member.plan === 'forever' ? '终身有效' : member.until} style={{ marginTop: 18 }} />
        <button onClick={onClose} style={{ width: '100%', marginTop: 18, height: 54, borderRadius: 16, border: 'none', background: c.surfaceMuted, color: c.textPri, fontFamily: font.sans, fontSize: 16, fontWeight: 600, cursor: 'pointer' }}>知道了</button>
      </div>
    </div>
  );
}

// ── 中考评分标准 (RCExamStandardSheetV3_claudecode_20260907) ──
const SOURCES = [
  ['北京', '北京市教委《2025 年初中毕业升学体育考试方案》', '2026-04-12'],
  ['上海', '上海市教委《2025 年初中毕业升学体育考试实施方案》', '2026-03-28'],
  ['广东', '广东省教育厅《初中学业水平体育与健康考试指导意见》', '2026-02-19'],
  ['江苏', '江苏省教育厅《初中毕业生升学体育考试工作方案》', '2026-04-02'],
  ['浙江', '浙江省教育厅《初中毕业升学体育考试指导意见》', '2026-01-30'],
  ['山东', '山东省教育厅《初中体育与健康学业水平考试方案》', '2026-03-11'],
  ['四川', '四川省教育厅《初中毕业生体育与健康考试方案》', '2025-12-20'],
  ['河南', '河南省教育厅《初中毕业生升学体育考试实施意见》', '2026-02-06'],
  ['通用国标', '教育部《国家学生体质健康标准（2014 年修订）》', '2025-09-01'],
];
function ExamStandardSheet({ platform = 'ios', dark = false, onClose }) {
  const c = dark ? RC.dark : RC.light;
  const font = platform === 'android' ? FONTS.android : FONTS.ios;
  return (
    <div onClick={onClose} style={{ position: 'absolute', inset: 0, zIndex: 200, background: rgba('#0F172A', dark ? 0.6 : 0.42), display: 'flex', flexDirection: 'column', justifyContent: 'flex-end', fontFamily: font.sans }}>
      <div onClick={(e) => e.stopPropagation()} style={{ position: 'relative', background: c.bg, borderTopLeftRadius: 24, borderTopRightRadius: 24, height: SCREEN_H - 92, display: 'flex', flexDirection: 'column', boxShadow: '0 -8px 32px rgba(0,0,0,0.3)' }}>
        <div style={{ display: 'flex', justifyContent: 'center', padding: '10px 0 12px' }}><div style={{ width: 36, height: 5, borderRadius: 999, background: c.border }} /></div>
        <div onClick={onClose} style={{ position: 'absolute', top: 22, right: 16, width: 30, height: 30, borderRadius: 999, background: c.surfaceMuted, display: 'flex', alignItems: 'center', justifyContent: 'center', cursor: 'pointer' }}><IcX size={12} color={c.textSec} /></div>
        <div style={{ padding: '0 20px 4px' }}>
          <div style={{ fontSize: 24, fontWeight: 700, color: c.textPri, letterSpacing: -0.5 }}>中考评分标准</div>
          <div style={{ fontSize: 13.5, color: c.textSec, marginTop: 5, lineHeight: 1.45 }}>分数换算依据以下各省市教委公开文件，随文件更新同步</div>
        </div>
        <div style={{ flex: 1, overflow: 'auto', padding: '14px 16px 6px' }}>
          <div style={{ background: c.surface, borderRadius: 16, overflow: 'hidden', border: dark ? `1px solid ${c.border}` : 'none', boxShadow: dark ? 'none' : ELEV[1] }}>
            {SOURCES.map(([prov, doc, date], i) => (
              <div key={prov} style={{ padding: '13px 14px', borderBottom: i === SOURCES.length - 1 ? 'none' : `1px solid ${c.border}` }}>
                <div style={{ display: 'flex', alignItems: 'baseline', justifyContent: 'space-between', gap: 10 }}>
                  <span style={{ fontSize: 15.5, fontWeight: 600, color: c.textPri }}>{prov}</span>
                  <span style={{ fontFamily: font.mono, fontSize: 12, color: c.textTer, flexShrink: 0 }}>{date}</span>
                </div>
                <div style={{ fontSize: 12.5, color: c.textSec, marginTop: 3, lineHeight: 1.45 }}>{doc}</div>
              </div>
            ))}
          </div>
          <div style={{ fontSize: 12, color: c.textTer, marginTop: 12, lineHeight: 1.6, padding: '0 4px' }}>未列出的省市按通用国标换算。文件由各地教委发布，如与最新政策不一致请通过「联系我们」告知。</div>
        </div>
        <div style={{ padding: '10px 16px 26px', borderTop: `1px solid ${c.border}` }}>
          <button onClick={onClose} style={{ width: '100%', height: 52, borderRadius: 16, border: 'none', background: c.surfaceMuted, color: c.textPri, fontFamily: font.sans, fontSize: 16, fontWeight: 600, cursor: 'pointer' }}>知道了</button>
        </div>
      </div>
    </div>
  );
}

// ── 未成年人保护说明弹层 (RCMinorProtectionSheetV3_claudecode_20260908) ── // 2026.11.04 Naron
function MinorProtectionSheet({ platform = 'ios', dark = false, onClose }) {
  const c = dark ? RC.dark : RC.light;
  const font = platform === 'android' ? FONTS.android : FONTS.ios;
  const bodyLines = [
    '本 App 主要用户是中小学生（10-15 岁），未成年人保护承诺：',
    '',
    '• 不索取姓名、学校、班级等真实身份信息',
    '• 不要求注册账号',
    '• 不收集设备 ID / IP / 安装来源等可追踪信息',
    '• paywall 顶部明确"建议在家长指导下开通订阅"',
    '• 无社交、排行榜、好友 PK，避免攀比与沉迷',
    '• 严格遵守《未成年人保护法》《未成年人个人信息网络保护规定》',
    '',
    '完整条款见本页「隐私政策」第四章「未成年人保护专章」。'
  ];
  return (
    <div onClick={onClose} style={{ position: 'absolute', inset: 0, zIndex: 200, background: rgba('#0F172A', dark ? 0.6 : 0.42), display: 'flex', flexDirection: 'column', justifyContent: 'flex-end', fontFamily: font.sans }}>
      <div onClick={(e) => e.stopPropagation()} style={{ position: 'relative', background: c.bg, borderTopLeftRadius: 24, borderTopRightRadius: 24, maxHeight: SCREEN_H * 0.9, display: 'flex', flexDirection: 'column', boxShadow: '0 -8px 32px rgba(0,0,0,0.3)' }}>
        <div style={{ display: 'flex', justifyContent: 'center', padding: '10px 0 12px' }}><div style={{ width: 36, height: 5, borderRadius: 999, background: c.border }} /></div>
        <div onClick={onClose} style={{ position: 'absolute', top: 22, right: 16, width: 30, height: 30, borderRadius: 999, background: c.surfaceMuted, display: 'flex', alignItems: 'center', justifyContent: 'center', cursor: 'pointer' }}><IcX size={12} color={c.textSec} /></div>
        <div style={{ padding: '0 20px 4px' }}>
          <div style={{ fontSize: 24, fontWeight: 700, color: c.textPri, letterSpacing: -0.5 }}>未成年人保护说明</div>
          <div style={{ fontSize: 13.5, color: c.textSec, marginTop: 5, lineHeight: 1.45 }}>本 App 的主要用户是中小学生，以下是我们对未成年人保护的承诺</div>
        </div>
        <div style={{ padding: '14px 16px 6px' }}>
          <div style={{ background: c.surface, borderRadius: 16, padding: 14, border: `0.5px solid ${c.border}`, fontSize: 14.5, lineHeight: 1.6, color: c.textSec, whiteSpace: 'pre-line' }}>
            {bodyLines.join('\n')}
          </div>
        </div>
        <div style={{ padding: '10px 16px 26px', borderTop: `1px solid ${c.border}` }}>
          <button onClick={onClose} style={{ width: '100%', height: 52, borderRadius: 16, border: 'none', background: c.surfaceMuted, color: c.textPri, fontFamily: font.sans, fontSize: 16, fontWeight: 600, cursor: 'pointer' }}>知道了</button>
        </div>
      </div>
    </div>
  );
}

// ── 关于我们弹层 (RCAboutSheetV3_claudecode_20260907) ── // 2026.11.04 Naron
function AboutSheet({ platform = 'ios', dark = false, onClose }) {
  const c = dark ? RC.dark : RC.light;
  const font = platform === 'android' ? FONTS.android : FONTS.ios;
  return (
    <div onClick={onClose} style={{ position: 'absolute', inset: 0, zIndex: 200, background: rgba('#0F172A', dark ? 0.6 : 0.42), display: 'flex', flexDirection: 'column', justifyContent: 'flex-end', fontFamily: font.sans }}>
      <div onClick={(e) => e.stopPropagation()} style={{ position: 'relative', background: c.bg, borderTopLeftRadius: 24, borderTopRightRadius: 24, display: 'flex', flexDirection: 'column', boxShadow: '0 -8px 32px rgba(0,0,0,0.3)' }}>
        <div style={{ display: 'flex', justifyContent: 'center', padding: '10px 0 12px' }}><div style={{ width: 36, height: 5, borderRadius: 999, background: c.border }} /></div>
        <div onClick={onClose} style={{ position: 'absolute', top: 22, right: 16, width: 30, height: 30, borderRadius: 999, background: c.surfaceMuted, display: 'flex', alignItems: 'center', justifyContent: 'center', cursor: 'pointer' }}><IcX size={12} color={c.textSec} /></div>
        <div style={{ padding: '22px 32px 0', display: 'flex', flexDirection: 'column', alignItems: 'center' }}>
          <div style={{ width: 72, height: 72, borderRadius: 16, background: c.accent, display: 'flex', alignItems: 'center', justifyContent: 'center' }}>
            <SkipIcon size={42} color="#FFFFFF"/>
          </div>
          <div style={{ fontSize: 19, fontWeight: 700, color: c.textPri, marginTop: 14 }}>小天天练跳绳</div>
          <div style={{ fontFamily: font.mono, fontSize: 13, color: c.textTer, marginTop: 4 }}>2026.11.04</div>
          <div style={{ marginTop: 14, display: 'flex', flexDirection: 'column', gap: 10, fontSize: 14, lineHeight: 1.5, color: c.textSec, textAlign: 'left' }}>
            <div>为保护用户隐私及数据安全，小天天不会主动收集或要求用户提供独立账号身份信息，应用使用设备自带的账号能力。本产品不存在跨设备、全网统一的用户账号系统，用户在本应用内生成的训练数据与视频仅本地化存储于用户当前使用的设备中，不会上传至远端服务器；为改进产品，应用仅上传不含个人身份的匿名使用统计。</div>
            <div>重要提示：本地存储数据会受设备重置、卸载应用、清除本地缓存等操作影响而丢失，请用户自行做好数据备份。</div>
          </div>
          <div style={{ fontSize: 12, color: c.textTer, marginTop: 14 }}>苏ICP备18044027号-9A</div>
        </div>
        <div style={{ padding: '26px 16px 26px' }}>
          <button onClick={onClose} style={{ width: '100%', height: 52, borderRadius: 16, border: 'none', background: c.surfaceMuted, color: c.textPri, fontFamily: font.sans, fontSize: 16, fontWeight: 600, cursor: 'pointer' }}>知道了</button>
        </div>
      </div>
    </div>
  );
}

// ── 联系我们独立页面 (RCContactPageV3_claudecode_20260910: full screen push page with TopBar(.back), 2 cards, "发送完成") ── // 2026.11.04 Naron
function ContactSheet({ platform = 'ios', dark = false, onClose, onSubmit, sent = false }) {
  const c = dark ? RC.dark : RC.light;
  const font = platform === 'android' ? FONTS.android : FONTS.ios;
  const [desc, setDesc] = useStateS('');
  const [contact, setContact] = useStateS('');
  const [ok, setOk] = useStateS(sent);
  const can = desc.trim().length > 0;
  const label = (t, req) => <div style={{ fontSize: 14, fontWeight: 600, color: c.textPri, marginBottom: 10 }}>{t}{req && <span style={{ color: c.danger || '#DC2626' }}>*</span>}</div>;
  const card = { background: c.surface, borderRadius: 16, padding: 14, border: `0.5px solid ${c.border}`, marginBottom: 12 };

  return (
    <PhoneFrame platform={platform} dark={dark} statusDark={!dark} hideTab>
      <div style={{ position: 'absolute', inset: 0, background: c.bg }}/>
      <TopBar c={c} font={font} leading="back" title="联系我们" onLeading={onClose}/>
      <div style={{ position: 'absolute', top: 98, left: 0, right: 0, bottom: 0, display: 'flex', flexDirection: 'column', fontFamily: font.sans }}>
        {ok ? (
          <div style={{ flex: 1, display: 'flex', flexDirection: 'column', alignItems: 'center', justifyContent: 'center', padding: '0 32px 40px', textAlign: 'center' }}>
            <div style={{ width: 62, height: 62, borderRadius: 999, background: rgba(c.accent, dark ? 0.22 : 0.12), display: 'flex', alignItems: 'center', justifyContent: 'center' }}><IcCheck size={26} color={c.accent} /></div>
            <div style={{ fontSize: 19, fontWeight: 700, color: c.textPri, marginTop: 16 }}>发送完成</div>
            <div style={{ fontSize: 14, color: c.textSec, marginTop: 6, lineHeight: 1.5 }}>感谢您的反馈，我们已经收到。</div>
            <button onClick={onClose} style={{ marginTop: 26, width: '100%', height: 52, borderRadius: 16, border: 'none', background: c.accent, color: c.onAccent, fontFamily: font.sans, fontSize: 17, fontWeight: 600, cursor: 'pointer' }}>完成</button>
          </div>
        ) : (
          <>
            <div style={{ flex: 1, overflow: 'auto', padding: '14px 16px 4px' }}>
              <div style={card}>
                {label('问题描述', true)}
                <div style={{ position: 'relative', background: c.surfaceMuted, borderRadius: 12, padding: '12px 12px 26px' }}>
                  <textarea value={desc} maxLength={200} onChange={(e) => setDesc(e.target.value)}
                    placeholder="请描述问题发生的场景，越详细，越有助于排查并解决问题；文明留言，快乐运动。"
                    style={{ width: '100%', height: 116, border: 'none', outline: 'none', resize: 'none', background: 'transparent', fontFamily: font.sans, fontSize: 14.5, lineHeight: 1.55, color: c.textPri, padding: 0 }} />
                  <div style={{ position: 'absolute', right: 12, bottom: 8, fontFamily: font.mono, fontSize: 12, color: c.textTer }}>{desc.length}/200</div>
                </div>
              </div>
              <div style={card}>
                {label('联系方式')}
                <input value={contact} onChange={(e) => setContact(e.target.value)} placeholder="选填：邮箱或手机号，方便必要时联系您"
                  style={{ width: '100%', height: 44, boxSizing: 'border-box', border: 'none', outline: 'none', background: c.surfaceMuted, borderRadius: 12, padding: '0 12px', fontFamily: font.sans, fontSize: 14.5, color: c.textPri }} />
              </div>
            </div>
            <div style={{ padding: '10px 16px 26px', borderTop: `1px solid ${c.border}` }}>
              <button onClick={() => { if (can) { setOk(true); onSubmit && onSubmit({ desc, contact }); } }}
                style={{ width: '100%', height: 52, borderRadius: 16, border: 'none', background: can ? c.accent : c.surfaceMuted, color: can ? c.onAccent : c.textTer, fontFamily: font.sans, fontSize: 17, fontWeight: 600, cursor: can ? 'pointer' : 'default' }}>提交</button>
            </div>
          </>
        )}
      </div>
    </PhoneFrame>
  );
}

// ── S2: Province Picker (sheet overlay) ──
const PROVINCES = [['BJ', '北京'], ['SH', '上海'], ['GD', '广东'], ['JS', '江苏'], ['ZJ', '浙江'], ['SD', '山东'], ['SC', '四川'], ['HA', '河南']];
const GRADES = [['g5', '小五'], ['g6', '小六'], ['g7', '初一'], ['g8', '初二'], ['g9', '初三'], ['gen', '通用']];

function ProvincePickerSheet({ platform = 'ios', dark = false, onClose, onSave, preset = true }) {
  const c = dark ? RC.dark : RC.light;
  const font = platform === 'android' ? FONTS.android : FONTS.ios;
  const [prov, setProv] = useStateS(preset ? 'BJ' : null);
  const [grade, setGrade] = useStateS(preset ? 'g9' : null);
  const [gender, setGender] = useStateS(preset ? 'M' : null);
  const can = prov && grade && gender;

  const chip = (sel, label, onClick, full, key) => (
    <div key={key} onClick={onClick} style={{ height: full ? 54 : 46, borderRadius: 12, cursor: 'pointer',
      display: 'flex', alignItems: 'center', justifyContent: full ? 'space-between' : 'center', padding: full ? '0 16px' : 0,
      background: sel ? c.accent : c.surface, border: `1px solid ${sel ? c.accent : c.border}`,
      color: sel ? c.onAccent : c.textPri, fontSize: 16, fontWeight: sel ? 600 : 500 }}>
      {full ? <><div><div style={{ fontSize: 16, fontWeight: sel ? 600 : 500 }}>通用国标</div><div style={{ fontSize: 12, opacity: 0.8, color: sel ? c.onAccent : c.textSec }}>《国家学生体质健康标准》</div></div><span style={{ fontFamily: font.mono, fontSize: 13, opacity: 0.85 }}>CN</span></> : label}
    </div>
  );

  return (
    <div style={{ position: 'absolute', inset: 0, zIndex: 200, background: rgba('#0F172A', dark ? 0.6 : 0.42),
      display: 'flex', flexDirection: 'column', justifyContent: 'flex-end' }} onClick={onClose}>
      <div onClick={(e) => e.stopPropagation()} style={{ background: c.surface, borderTopLeftRadius: 24, borderTopRightRadius: 24,
        height: SCREEN_H - 52, display: 'flex', flexDirection: 'column', boxShadow: '0 -8px 32px rgba(0,0,0,0.3)' }}>
        <div style={{ padding: '10px 20px 6px' }}>
          <div style={{ display: 'flex', justifyContent: 'center', padding: '4px 0 12px' }}><div style={{ width: 36, height: 5, borderRadius: 999, background: c.border }} /></div>
          <div onClick={onClose} style={{ width: 30, height: 30, borderRadius: 999, background: c.surfaceMuted, display: 'flex', alignItems: 'center', justifyContent: 'center', cursor: 'pointer' }}><IcX size={12} color={c.textSec} /></div>
          <div style={{ fontSize: 26, fontWeight: 700, color: c.textPri, marginTop: 10, letterSpacing: -0.5 }}>选择评分标准</div>
          <div style={{ fontSize: 14, color: c.textSec, marginTop: 4, lineHeight: 1.4 }}>用于换算你所在地的体测分数对照，不影响自由模式</div>
        </div>
        <div style={{ flex: 1, overflow: 'auto', padding: '16px 20px 0' }}>
          <div style={{ fontSize: 17, fontWeight: 600, color: c.textPri, marginBottom: 12 }}>省份</div>
          <div style={{ display: 'grid', gridTemplateColumns: 'repeat(3,1fr)', gap: 10 }}>
            {PROVINCES.map(([code, label]) => chip(prov === code, label, () => setProv(code), false, code))}
          </div>
          <div style={{ display: 'flex', alignItems: 'center', gap: 10, margin: '14px 2px' }}>
            <div style={{ flex: 1, height: 1, background: c.border }} /><span style={{ fontSize: 12, color: c.textTer }}>未列出本省</span><div style={{ flex: 1, height: 1, background: c.border }} />
          </div>
          {chip(prov === 'CN', null, () => setProv('CN'), true, 'CN')}

          <div style={{ fontSize: 17, fontWeight: 600, color: c.textPri, margin: '22px 0 12px' }}>年级</div>
          <Segmented c={c} font={font} value={grade} onPick={setGrade} options={GRADES.map(([code, label]) => ({ code, label }))} />

          <div style={{ fontSize: 17, fontWeight: 600, color: c.textPri, margin: '22px 0 12px' }}>性别</div>
          <div style={{ display: 'grid', gridTemplateColumns: 'repeat(2,1fr)', gap: 10 }}>
            {[['M', '男'], ['F', '女']].map(([code, label]) => chip(gender === code, label, () => setGender(code), false, code))}
          </div>
          <div style={{ fontSize: 12, color: c.textTer, marginTop: 18, lineHeight: 1.5 }}>数据来源 · 依据 北京市教委《2025 年初中毕业升学体育考试方案》<br />最后更新 2026-04-12</div>
        </div>
        <div style={{ padding: '12px 16px', borderTop: `1px solid ${c.border}` }}>
          <button onClick={() => can && onSave && onSave({ prov, grade, gender })} style={{ width: '100%', height: 52, borderRadius: 14, border: 'none',
            background: can ? c.accent : c.surfaceMuted, color: can ? c.onAccent : c.textTer,
            fontFamily: font.sans, fontSize: 17, fontWeight: 600, cursor: can ? 'pointer' : 'default' }}>
            {can ? '保存' : '保存（请先完成 3 项选择）'}
          </button>
          <div style={{ height: 18 }} />
        </div>
      </div>
    </div>
  );
}

// ── Screen G: Paywall (PaywallView.swift 2026.10.13/14: Quote header + 4 benefit rows + 4-tier cards row 月卡¥12 / 1年¥48推荐 / 3年¥108 / 永久¥128) ── // 2026.11.04 Naron
function PaywallScreen({ current = null, platform = 'ios', dark = false, onClose, onBuy, onDone, success = null }) {
  const [done, setDone] = useStateS(success);
  const sheetRef = React.useRef(null);
  const [lockH, setLockH] = useStateS(null);
  const c = dark ? RC.dark : RC.light;
  const font = platform === 'android' ? FONTS.android : FONTS.ios;
  const [plan, setPlan] = useStateS('1y'); // 1-year is the default recommended hero tier (2026.10.13)

  const benefits = [
    '小天天出自华为匠心奖设计团队',
    '小天天是买断制，不会自动续费',
    '小天天是工信部备案产品，安全省心',
    '小天天信奉极简和专注，助力孩子备战中考跳绳',
  ];

  const PlanCard = ({ id, title, price, note, badge, hero }) => {
    const on = plan === id, owned = current === id;
    return (
      <div onClick={() => !owned && setPlan(id)} style={{
        opacity: owned ? 0.55 : 1, cursor: owned ? 'default' : 'pointer',
        flex: hero ? 1.25 : 1, minWidth: 0, position: 'relative',
        padding: hero ? '26px 7px 22px' : '22px 7px 22px', borderRadius: 16,
        background: on && hero ? rgba(c.accent, dark ? 0.16 : 0.07) : c.surface,
        border: `2px solid ${on ? c.accent : c.border}`,
        marginTop: hero ? -6 : 0
      }}>
        {(owned || badge) && (
          <div style={{
            position: 'absolute', top: -10, right: 8,
            background: owned ? c.textSec : c.examMid, color: '#fff',
            fontSize: 11, fontWeight: 700, padding: '3px 9px', borderRadius: 999
          }}>{owned ? '当前' : badge}</div>
        )}
        <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', gap: 2 }}>
          <span style={{ fontSize: 13, fontWeight: 600, color: c.textPri, whiteSpace: 'nowrap' }}>{title}</span>
          <div style={{
            width: 16, height: 16, borderRadius: 999, flexShrink: 0,
            border: `2px solid ${on ? c.accent : c.border}`,
            background: on ? c.accent : 'transparent',
            display: 'flex', alignItems: 'center', justifyContent: 'center'
          }}>
            {on && <IcCheck size={10} color={c.onAccent} />}
          </div>
        </div>
        <div style={{ marginTop: 10, height: hero ? 38 : 31, display: 'flex', alignItems: 'center' }}>
          <span style={{
            fontFamily: font.rounded, fontSize: hero ? 27 : 23, fontWeight: 700,
            color: hero ? c.accent : c.textPri, whiteSpace: 'nowrap', letterSpacing: -0.5
          }}>{price}</span>
        </div>
        <div style={{ fontSize: 12, color: c.textSec, marginTop: 4, whiteSpace: 'nowrap' }}>{note}</div>
      </div>
    );
  };

  const [shown, setShown] = useStateS(false);
  useEffectS(() => { const t = requestAnimationFrame(() => setShown(true)); return () => cancelAnimationFrame(t); }, []);

  return (
    <div onClick={done ? undefined : onClose} style={{
      position: 'absolute', inset: 0, zIndex: 200, fontFamily: font.sans,
      background: rgba('#0F172A', shown ? (dark ? 0.6 : 0.42) : 0),
      transition: 'background 220ms', display: 'flex', flexDirection: 'column', justifyContent: 'flex-end'
    }}>
      <div ref={sheetRef} onClick={(e) => e.stopPropagation()} style={{
        position: 'relative', background: c.bg, borderTopLeftRadius: 24, borderTopRightRadius: 24,
        maxHeight: SCREEN_H - 120, height: lockH || 'auto', display: 'flex', flexDirection: 'column',
        boxShadow: '0 -8px 32px rgba(0,0,0,0.3)',
        transform: shown ? 'translateY(0)' : 'translateY(40px)', opacity: shown ? 1 : 0,
        transition: 'transform 260ms cubic-bezier(.2,.8,.2,1), opacity 200ms'
      }}>
        <div style={{ display: 'flex', justifyContent: 'center', padding: '10px 0 0' }}><div style={{ width: 36, height: 5, borderRadius: 999, background: c.border }} /></div>
        {done && <Confetti c={c} />}
        {!done && (
          <div onClick={onClose} style={{
            position: 'absolute', top: 22, right: 16, zIndex: 20, width: 32, height: 32,
            borderRadius: 999, background: c.surfaceMuted, display: 'flex', alignItems: 'center', justifyContent: 'center', cursor: 'pointer'
          }}><IcX size={14} color={c.textSec} /></div>
        )}

        {done ? (
          <div style={{ padding: '14px 20px 26px', overflow: 'auto', display: 'flex', flexDirection: 'column', flex: 1, minHeight: 0 }}>
            <SuccessBody c={c} font={font} dark={dark} plan={done.plan} onDone={onDone} />
          </div>
        ) : (
          <div style={{ padding: '14px 20px 26px', overflow: 'auto', display: 'flex', flexDirection: 'column' }}>
            {/* Quote Header (PaywallView.swift:185-201) */}
            <div style={{ display: 'flex', flexDirection: 'column', alignItems: 'center' }}>
              <div style={{ fontSize: 22, fontWeight: 700, color: c.textPri, letterSpacing: -0.5 }}>工欲善其事，必先利其器</div>
              <div style={{ fontSize: 13, fontWeight: 500, color: c.textSec, marginTop: 6, transform: 'translateX(48px)' }}>《论语・卫灵公》</div>
            </div>

            {/* 4 Benefit Rows (PaywallView.swift:204-228) */}
            <div style={{ marginTop: 16, display: 'flex', flexDirection: 'column', gap: 10 }}>
              {benefits.map((title, i) => (
                <div key={i} style={{ display: 'flex', gap: 10, alignItems: 'center' }}>
                  <div style={{
                    width: 22, height: 22, borderRadius: 999, background: rgba(c.accent, 0.12),
                    display: 'flex', alignItems: 'center', justifyContent: 'center', flexShrink: 0
                  }}><IcCheck size={11} color={c.accent} /></div>
                  <div style={{ fontSize: 14, fontWeight: 500, color: c.textPri, whiteSpace: 'nowrap' }}>{title}</div>
                </div>
              ))}
            </div>

            {/* 4-tier cards in one horizontal row (PaywallView.swift:235-252) */}
            <div style={{ marginTop: 42, display: 'flex', gap: 5, alignItems: 'flex-start' }}>
              <PlanCard id="1m" title="月卡" price="¥12" note="冲刺1个月" />
              <PlanCard id="1y" title="1 年" price="¥48" note="备考1年" badge="推荐" hero />
              <PlanCard id="3y" title="3 年" price="¥108" note="整个初中" />
              <PlanCard id="forever" title="永久" price="¥128" note="省心优选" />
            </div>

            <button onClick={() => { if (sheetRef.current) setLockH(sheetRef.current.offsetHeight); setDone({ plan }); onBuy && onBuy(plan); }} style={{
              marginTop: 42, height: 54, borderRadius: 16, border: 'none', background: c.accent, color: c.onAccent,
              fontFamily: font.sans, fontSize: 17, fontWeight: 600, cursor: 'pointer', flexShrink: 0
            }}>{`立即解锁 ¥${PLAN_PRICE[plan]}`}</button>

            {/* Footer links (PaywallView.swift:521-536) */}
            <div style={{ marginTop: 18, display: 'flex', alignItems: 'center', justifyContent: 'center', gap: 12, fontSize: 12, color: c.textSec }}>
              <span style={{ cursor: 'pointer' }}>隐私政策</span>
              <span style={{ color: c.textTer }}>·</span>
              <span style={{ cursor: 'pointer' }}>用户协议</span>
              <span style={{ color: c.textTer }}>·</span>
              <span onClick={onClose} style={{ color: c.accent, cursor: 'pointer', fontWeight: 500 }}>恢复购买</span>
            </div>
          </div>
        )}
      </div>
    </div>
  );
}

// ── Screen J: Onboarding (3-page, OnboardingView.swift X149-A / X150-A2: 70% art panel + 3 distinct tints) ── // 2026.11.04 Naron
function OnboardingScreen({ platform = 'ios', dark = false, onDone }) {
  const c = dark ? RC.dark : RC.light;
  const font = platform === 'android' ? FONTS.android : FONTS.ios;
  const [page, setPage] = useStateS(0);
  const next = () => page < 2 ? setPage(page + 1) : onDone && onDone();

  const pages = [
    {
      title: '摄像头帮你计数',
      body: '模式1：靠墙自拍（前置摄像头）\n模式2：家长手持（后置摄像头）',
      cta: '下一步',
      tint: '#0284C7',
      art: 'camera',
    },
    {
      title: '全身要进入画面',
      body: '距离1.5~2米，确保全身进入画面',
      cta: '下一步',
      tint: c.accent,
      art: 'distance',
    },
    {
      title: '跳完可回看录像',
      body: '跳完之后，可以回看录像，据此来优化动作',
      cta: '开始使用',
      tint: c.warning,
      art: 'replay',
    },
  ];

  const p = pages[page];

  return (
    <PhoneFrame platform={platform} dark={dark} statusDark={!dark} hideTab>
      <div style={{ position: 'absolute', inset: 0, background: c.bg }} />
      <div style={{ position: 'absolute', top: 0, left: 0, right: 0, bottom: 0, display: 'flex', flexDirection: 'column', padding: '90px 28px 34px' }}>
        <div style={{ flex: 1, display: 'flex', alignItems: 'center', justifyContent: 'center' }}>
          <div style={{
            width: '70%', height: 196, borderRadius: 16.8,
            background: rgba(p.tint, 0.12), display: 'flex', alignItems: 'center', justifyContent: 'center'
          }}>
            {p.art === 'distance' ? (
              <Skipping width={84} height={133} opacity={0.95}/>
            ) : p.art === 'camera' ? (
              <svg width="78" height="78" viewBox="0 0 24 24" fill={p.tint}><path d="M9 3 7.17 5H4c-1.1 0-2 .9-2 2v12c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V7c0-1.1-.9-2-2-2h-3.17L15 3H9zm3 15c-2.76 0-5-2.24-5-5s2.24-5 5-5 5 2.24 5 5-2.24 5-5 5z"/></svg>
            ) : (
              <svg width="78" height="78" viewBox="0 0 24 24" fill={p.tint}><rect x="2" y="4" width="20" height="16" rx="3"/><polygon points="10 8.5 16 12 10 15.5" fill="#FFFFFF"/></svg>
            )}
          </div>
        </div>
        <div style={{ textAlign: 'center', marginBottom: 24 }}>
          <div style={{ fontSize: 26, fontWeight: 700, color: c.textPri, letterSpacing: -0.5 }}>{p.title}</div>
          <div style={{ fontSize: 16, color: c.textSec, marginTop: 10, lineHeight: 1.5, minHeight: 48, whiteSpace: 'pre-line' }}>{p.body}</div>
        </div>
        <div style={{ display: 'flex', justifyContent: 'center', gap: 7, marginBottom: 18 }}>
          {[0, 1, 2].map((i) => <div key={i} style={{ width: i === page ? 22 : 7, height: 7, borderRadius: 999, background: i === page ? c.accent : c.border, transition: 'width 200ms' }} />)}
        </div>
        <button onClick={next} style={{ height: 54, borderRadius: 16, border: 'none', background: c.accent, color: c.onAccent, fontFamily: font.sans, fontSize: 17, fontWeight: 600, cursor: 'pointer' }}>{p.cta}</button>
        {page < 2 ? (
          <button onClick={onDone} style={{ height: 40, marginTop: 4, border: 'none', background: 'none', color: c.textTer, fontSize: 14, cursor: 'pointer' }}>跳过</button>
        ) : (
          <div style={{ height: 44 }}/>
        )}
      </div>
    </PhoneFrame>
  );
}

Object.assign(window, {
  SettingsScreen, WechatHeaderCapsule, WechatLoginSheet, AccountManageSheet,
  ContactSheet, ExamStandardSheet, MinorProtectionSheet, AboutSheet,
  ProvincePickerSheet, PaywallScreen, OnboardingScreen, MemberSheet,
  Confetti, SuccessBody, MemberCard, PLAN_PRICE
});
