/* 彩云间 — 首页 / 云图鉴 / 我的 */

// 按真实时段给问候语，每段多条随机轮换
const CY_GREETINGS = {
  earlyMorning: ['天刚亮，第一缕云也醒了','清晨好，趁人少去看看云','早起的人，能遇见最干净的天'],
  morning:      ['上午好，云在天上慢慢铺开','新的一天，抬头看看云吧','阳光正好，云也轻快'],
  noon:         ['正午了，云被晒得发亮','日头正高，云影也短了','中午好，云在头顶打了个盹'],
  afternoon:    ['午后正好，云在慢慢散步','下午的云，最适合发呆','喝杯茶，顺便看看今天的云'],
  evening:      ['傍晚了，留意天边会不会有霞','日头偏西，云开始换颜色','黄昏将近，最美的云要来了'],
  night:        ['入夜了，云躲进了暮色里','晚上好，云也准备休息了','华灯初上，抬头还有夜云'],
  lateNight:    ['夜深了，抬头有星也有云','这么晚还醒着，陪你看看夜空','深夜的云，安安静静的'],
};
function greetSlot(hour) {
  if (hour < 5)  return 'lateNight';
  if (hour < 8)  return 'earlyMorning';
  if (hour < 11) return 'morning';
  if (hour < 13) return 'noon';
  if (hour < 17) return 'afternoon';
  if (hour < 19) return 'evening';
  if (hour < 23) return 'night';
  return 'lateNight';
}
function pickGreeting(hour) {
  const list = CY_GREETINGS[greetSlot(hour)];
  return list[Math.floor(Math.random() * list.length)];
}

// 根据小时判断天色：只分白天 / 夜晚
function dayPartFor(hour) {
  return (hour < 6 || hour >= 19) ? 'night' : 'day';
}

// 四套天色配置
const HERO_SKY = {
  dawn: {
    grad: 'linear-gradient(180deg,#f8dcc2 0%,#f6cdcd 50%,#e7d4ee 100%)',
    orb: { bg:'radial-gradient(circle at 42% 40%,#fff4de,#ffcf9b)', glow:'#ffcf9b55', pos:{ right:34, top:120 }, size:50 },
    clouds: [
      { shape:'wisp', tone:'white', s:{ right:-4, top:42, width:150, height:92 }, soft:true },
      { shape:'roll', tone:'soft',  s:{ left:-30, bottom:-10, width:210, height:120 }, soft:true },
    ],
    label: '清晨', stars: 0,
  },
  day: {
    grad: 'linear-gradient(180deg,#bfe0f7 0%,#d8edfb 70%,#f4fafe 100%)',
    orb: { bg:'radial-gradient(circle at 40% 38%,#fff6dd,#ffe39c)', glow:'#ffe9a855', pos:{ right:26, top:20 }, size:54 },
    clouds: [
      { shape:'wisp', tone:'ice',   s:{ left:-16, top:34, width:150, height:92 }, soft:true },
      { shape:'puff', tone:'white', s:{ right:18, bottom:18, width:158, height:108 }, soft:true },
    ],
    label: '午后', stars: 0,
  },
  dusk: {
    grad: 'linear-gradient(180deg,#5d5388 0%,#cf7088 44%,#f0975a 84%,#f8d28c 100%)',
    orb: { bg:'radial-gradient(circle at 45% 45%,#fff0c2,#ff9456)', glow:'#ff945666', pos:{ right:30, top:120 }, size:62 },
    clouds: [
      { shape:'wisp', tone:'sunset', s:{ left:-8, top:46, width:170, height:96 }, soft:true },
      { shape:'roll', tone:'storm',  s:{ left:-30, bottom:-12, width:220, height:124 }, soft:true },
    ],
    label: '黄昏', stars: 0,
  },
  night: {
    grad: 'linear-gradient(180deg,#0e1b33 0%,#1c3052 58%,#33507a 100%)',
    orb: { bg:'radial-gradient(circle at 38% 36%,#f3f8ff,#c9dbf2)', glow:'#cfe0f566', pos:{ right:28, top:22 }, size:46 },
    clouds: [
      { shape:'wisp', tone:'night', s:{ left:-20, top:78, width:170, height:108 }, soft:true },
      { shape:'roll', tone:'storm', s:{ right:-16, bottom:30, width:150, height:96 }, soft:true },
    ],
    label: '夜晚', stars: 26,
  },
};

function HeroSky({ part, tag, greet }) {
  const cfg = HERO_SKY[part] || HERO_SKY.day;
  const dark = part==='night'||part==='dusk';
  const stars = React.useMemo(() =>
    Array.from({ length: cfg.stars }).map(() => ({
      x: Math.random()*100, y: Math.random()*55, r: Math.random()*1.4+0.6, o: Math.random()*0.6+0.3,
    })), [part]);
  const orbPos = cfg.orb.pos;
  return (
    <div style={{ position:'relative', borderRadius:26, overflow:'hidden', boxShadow:'var(--cy-shadow)',
      background: cfg.grad, height:228, transition:'background .6s ease' }}>
      {/* 星星（夜晚）*/}
      {stars.map((s, i) => (
        <div key={i} style={{ position:'absolute', left:`${s.x}%`, top:`${s.y}%`, width:s.r*2, height:s.r*2,
          borderRadius:99, background:'#fff', opacity:s.o, boxShadow:`0 0 ${s.r*3}px #fff` }}/>
      ))}
      {/* 日/月 */}
      <div style={{ position:'absolute', ...orbPos, width:cfg.orb.size, height:cfg.orb.size, borderRadius:99,
        background:cfg.orb.bg, boxShadow:`0 0 38px 12px ${cfg.orb.glow}` }}/>
      {/* 云 */}
      {cfg.clouds.map((c, i) => (
        <div key={i} style={{ position:'absolute', ...c.s }}>
          <CloudArt shape={c.shape} tone={c.tone} style={{ width:'100%', height:'100%' }} soft={c.soft}/>
        </div>
      ))}
      {/* 问候 */}
      <div style={{ position:'absolute', left:0, right:0, bottom:0, padding:'34px 20px 16px',
        background: dark ? 'linear-gradient(transparent, rgba(0,0,0,.28))' : 'linear-gradient(transparent, rgba(255,255,255,.0))' }}>
        <div style={{ fontSize:11.5, fontWeight:600, letterSpacing:1, marginBottom:3,
          color: dark ? 'rgba(255,255,255,.78)' : 'var(--cy-accent2)' }}>{tag}的天空</div>
        <div style={{ fontSize:15.5, fontWeight:600,
          color: dark ? '#fff' : 'var(--cy-ink)',
          textShadow: dark ? '0 1px 10px rgba(0,0,0,.4)' : '0 1px 10px rgba(255,255,255,.6)' }}>
          {greet}
        </div>
      </div>
    </div>
  );
}

// ── 首页：今日天空 ───────────────────────────────────────
function HomeScreen({ state, level, daypart, onCapture, onOpenCloud, goTab }) {
  const poem = React.useMemo(() => window.CY_POEMS[new Date().getDate() % window.CY_POEMS.length], []);
  const recent = state.collected.slice().reverse().slice(0, 8).map(id => window.CY_CLOUDS.find(c => c.id === id)).filter(Boolean);
  const total = window.CY_CLOUDS.length, got = state.collected.length;
  const dateStr = `${new Date().getMonth()+1}月${new Date().getDate()}日`;
  const hour = new Date().getHours();
  const part = (daypart && daypart !== 'auto') ? daypart : dayPartFor(hour);
  const slotTags = { earlyMorning:'清晨', morning:'上午', noon:'正午', afternoon:'午后', evening:'傍晚', night:'夜晚', lateNight:'深夜' };
  const tag = slotTags[greetSlot(hour)];
  // 每次进页随机一条，刷新会换
  const greet = React.useMemo(() => pickGreeting(hour), []);

  return (
    <div className="cy-scroll" style={{ paddingBottom: 150 }}>
      {/* 顶栏 */}
      <div style={{ display:'flex', alignItems:'flex-start', justifyContent:'space-between', padding:'8px 22px 6px' }}>
        <div>
          <div style={{ fontFamily:'var(--cy-brand)', fontSize:34, lineHeight:1, color:'var(--cy-ink)' }}>彩云间</div>
          <div style={{ fontSize:12.5, color:'var(--cy-ink-soft)', marginTop:6, letterSpacing:.5 }}>{dateStr} · 宜抬头观云</div>
        </div>
        <button onClick={() => goTab('me')} className="cy-tap" style={{ border:'none', background:'none', cursor:'pointer', padding:0 }}>
          <ProgressRing pct={level.next ? (got-level.min)/(level.next.min-level.min) : 1} size={48} stroke={3.5}>
            <div style={{ width:36, height:36, borderRadius:99, background:'var(--cy-accent2)',
              display:'grid', placeItems:'center', color:'#fff' }}><Icon name="user" size={20}/></div>
          </ProgressRing>
        </button>
      </div>

      {/* 诗句 */}
      <div style={{ padding:'10px 24px 14px' }}>
        <div style={{ fontFamily:'var(--cy-brand)', fontSize:21, lineHeight:1.5, color:'var(--cy-ink)', opacity:.92 }}>{poem.text}</div>
        <div style={{ fontSize:12, color:'var(--cy-ink-soft)', marginTop:6, textAlign:'right' }}>— {poem.from}</div>
      </div>

      {/* 今日天空 hero（随时间变天色）*/}
      <div style={{ padding:'0 18px' }}>
        <HeroSky part={part} tag={tag} greet={greet}/>
      </div>

      {/* 拍云 CTA */}
      <div style={{ padding:'16px 18px 4px' }}>
        <button onClick={onCapture} className="cy-btn-primary cy-tap" style={{ width:'100%', height:56, fontSize:17 }}>
          <Icon name="camera" size={22}/> 抬头，拍朵云
        </button>
      </div>

      {/* 收集进度 */}
      <div style={{ padding:'14px 18px 4px' }}>
        <div className="cy-card" style={{ padding:'16px 18px' }}>
          <div style={{ display:'flex', alignItems:'center', justifyContent:'space-between', marginBottom:12 }}>
            <div style={{ display:'flex', alignItems:'baseline', gap:9 }}>
              <span style={{ fontFamily:'var(--cy-serif)', fontSize:19, fontWeight:700, color:'var(--cy-ink)' }}>{level.title}</span>
              <span style={{ fontSize:12.5, color:'var(--cy-ink-soft)' }}>Lv.{level.index}</span>
            </div>
            <div style={{ fontSize:13, color:'var(--cy-ink-soft)' }}>
              已收集 <b style={{ color:'var(--cy-accent)', fontSize:17, fontFamily:'var(--cy-serif)' }}>{got}</b> / {total} 种
            </div>
          </div>
          <ProgressBar pct={level.next ? (got-level.min)/(level.next.min-level.min) : 1}/>
          <div style={{ fontSize:12.5, color:'var(--cy-ink-soft)', marginTop:10 }}>
            {level.next
              ? <>再收集 <b style={{ color:'var(--cy-ink)' }}>{level.next.min - got}</b> 种，解锁称号「{level.next.title}」</>
              : '已集齐天空所有的云，了不起的云间隐者。'}
          </div>
        </div>
      </div>

      {/* 最近收集 */}
      <div style={{ padding:'18px 0 0' }}>
        <div style={{ display:'flex', alignItems:'center', justifyContent:'space-between', padding:'0 22px 12px' }}>
          <div style={{ fontFamily:'var(--cy-serif)', fontSize:17, fontWeight:700, color:'var(--cy-ink)' }}>最近收集</div>
          <button onClick={() => goTab('gallery')} className="cy-tap" style={{ border:'none', background:'none', color:'var(--cy-accent)', fontSize:13, cursor:'pointer', display:'flex', alignItems:'center', gap:2 }}>
            云图鉴 <Icon name="chev" size={15}/>
          </button>
        </div>
        <div className="cy-hscroll" style={{ display:'flex', gap:12, padding:'2px 18px 6px', overflowX:'auto' }}>
          {recent.length === 0 && (
            <div style={{ color:'var(--cy-ink-soft)', fontSize:13.5, padding:'18px 4px' }}>还没有收集到云，去拍下第一朵吧。</div>
          )}
          {recent.map(c => (
            <button key={c.id} onClick={() => onOpenCloud(c.id)} className="cy-card cy-tap" style={{ flex:'0 0 132px', border:'none', cursor:'pointer', padding:'10px 10px 11px' }}>
              <div style={{ height:78 }}><CloudArt shape={c.art.shape} tone={c.art.tone} style={{ width:'100%', height:'100%' }}/></div>
              <div style={{ fontFamily:'var(--cy-serif)', fontSize:14.5, fontWeight:600, color:'var(--cy-ink)', marginTop:4 }}>{c.name}</div>
              <div style={{ fontSize:11, color:'var(--cy-ink-soft)', marginTop:1 }}>{c.tagline}</div>
            </button>
          ))}
        </div>
      </div>
    </div>
  );
}

// ── 云图鉴 ──────────────────────────────────────────────
function GalleryScreen({ state, onOpenCloud }) {
  const [cat, setCat] = React.useState('all');
  const total = window.CY_CLOUDS.length, got = state.collected.length;
  const cats = window.CY_CATEGORIES;
  const shown = cats.filter(c => cat === 'all' || c.id === cat);

  return (
    <div className="cy-scroll" style={{ paddingBottom: 150 }}>
      <div style={{ padding:'10px 22px 4px' }}>
        <div style={{ fontFamily:'var(--cy-brand)', fontSize:30, color:'var(--cy-ink)' }}>云图鉴</div>
        <div style={{ display:'flex', alignItems:'center', gap:10, marginTop:8 }}>
          <div style={{ flex:1 }}><ProgressBar pct={got/total}/></div>
          <div style={{ fontSize:13, color:'var(--cy-ink-soft)', whiteSpace:'nowrap' }}>
            <b style={{ color:'var(--cy-accent)', fontFamily:'var(--cy-serif)', fontSize:16 }}>{got}</b> / {total}
          </div>
        </div>
      </div>

      {/* 分类筛选 */}
      <div className="cy-hscroll" style={{ display:'flex', gap:8, padding:'14px 18px 6px', overflowX:'auto' }}>
        <button className={'cy-chip cy-tap'+(cat==='all'?' on':'')} onClick={() => setCat('all')}>全部</button>
        {cats.map(c => (
          <button key={c.id} className={'cy-chip cy-tap'+(cat===c.id?' on':'')} onClick={() => setCat(c.id)}>{c.name}</button>
        ))}
      </div>

      {shown.map(c => {
        const list = window.CY_CLOUDS.filter(x => x.cat === c.id);
        const gotN = list.filter(x => state.collected.includes(x.id)).length;
        return (
          <div key={c.id} style={{ padding:'14px 18px 2px' }}>
            <div style={{ display:'flex', alignItems:'baseline', gap:9, marginBottom:3 }}>
              <span style={{ fontFamily:'var(--cy-serif)', fontSize:17, fontWeight:700, color:'var(--cy-ink)' }}>{c.name}</span>
              <span style={{ fontSize:12, color:'var(--cy-ink-soft)' }}>{c.sub}</span>
              <span style={{ marginLeft:'auto', fontSize:12.5, color:'var(--cy-ink-soft)' }}>{gotN}/{list.length}</span>
            </div>
            <div style={{ fontSize:12.5, color:'var(--cy-ink-soft)', lineHeight:1.5, marginBottom:12 }}>{c.hint}</div>
            <div style={{ display:'grid', gridTemplateColumns:'1fr 1fr', gap:12 }}>
              {list.map(cl => {
                const locked = !state.collected.includes(cl.id);
                return <CloudThumb key={cl.id} cloud={cl} locked={locked} onClick={() => !locked && onOpenCloud(cl.id)}/>;
              })}
            </div>
          </div>
        );
      })}
    </div>
  );
}

// ── 我的 ────────────────────────────────────────────────
function badges(state) {
  const has = id => state.collected.includes(id);
  const cat = id => window.CY_CLOUDS.filter(c => c.cat === id);
  const allCat = id => cat(id).every(c => has(c.id));
  const anyRare = window.CY_CLOUDS.some(c => c.rarity === 'rare' && has(c.id));
  return [
    { id:'first', name:'拾云之始',  desc:'收集第一朵云',     on: state.collected.length >= 1, tone:'white', shape:'puff' },
    { id:'storm', name:'风暴追逐者', desc:'收集积雨云',       on: has('cb'),                  tone:'storm', shape:'anvil' },
    { id:'high',  name:'高云收藏家', desc:'集齐所有高云',     on: allCat('high'),             tone:'ice',   shape:'wisp' },
    { id:'rare',  name:'稀客来访',   desc:'收集任意稀有云',   on: anyRare,                    tone:'pearl', shape:'iris' },
    { id:'sunset',name:'追霞人',     desc:'收集火烧云',       on: has('sun'),                 tone:'sunset',shape:'sunset' },
    { id:'all',   name:'云间隐者',   desc:'集齐全部 24 种云', on: state.collected.length >= window.CY_CLOUDS.length, tone:'night', shape:'wisp' },
  ];
}

function ProfileScreen({ state, level, onOpenCloud, onOpenJournal, onPickAvatar }) {
  const total = window.CY_CLOUDS.length, got = state.collected.length;
  const pct = level.next ? (got-level.min)/(level.next.min-level.min) : 1;
  const recent = state.collected.slice().reverse().slice(0,4).map(id => window.CY_CLOUDS.find(c=>c.id===id)).filter(Boolean);
  const bdg = badges(state);

  return (
    <div className="cy-scroll" style={{ paddingBottom: 150 }}>
      {/* 身份卡 */}
      <div style={{ padding:'12px 18px 0' }}>
        <div className="cy-card" style={{ padding:'22px 20px', textAlign:'center', position:'relative', overflow:'hidden' }}>
          <div style={{ position:'absolute', inset:0, opacity:.5,
            background:'linear-gradient(180deg, var(--cy-sky1), transparent 60%)' }}/>
          <div style={{ position:'relative' }}>
            <ProgressRing pct={pct} size={92} stroke={5}>
              <div style={{ width:74, height:74, borderRadius:99, background:'var(--cy-accent2)',
                display:'grid', placeItems:'center', color:'#fff' }}><Icon name="user" size={34}/></div>
            </ProgressRing>
            <div style={{ fontFamily:'var(--cy-serif)', fontSize:25, fontWeight:700, color:'var(--cy-ink)', marginTop:12 }}>{level.title}</div>
            <div style={{ fontSize:13, color:'var(--cy-ink-soft)', marginTop:5, lineHeight:1.5 }}>{level.blurb}</div>
            <div style={{ marginTop:14, padding:'0 14px' }}>
              <ProgressBar pct={pct}/>
              <div style={{ fontSize:12, color:'var(--cy-ink-soft)', marginTop:8 }}>
                {level.next ? <>距「{level.next.title}」还差 {level.next.min - got} 种</> : '已抵达观云之路的尽头'}
              </div>
            </div>
          </div>
        </div>
      </div>

      {/* 数据 */}
      <div style={{ padding:'14px 18px 0', display:'grid', gridTemplateColumns:'1fr 1fr 1fr', gap:12 }}>
        {[
          { icon:'book', n:`${got}/${total}`, l:'收集种类' },
          { icon:'eye',  n:state.captures,    l:'拍云次数' },
          { icon:'flame',n:state.streak,      l:'连续观云' },
        ].map((s,i) => (
          <div key={i} className="cy-card" style={{ padding:'15px 8px', textAlign:'center' }}>
            <div style={{ color:'var(--cy-accent)', display:'grid', placeItems:'center' }}><Icon name={s.icon} size={20}/></div>
            <div style={{ fontFamily:'var(--cy-serif)', fontSize:21, fontWeight:700, color:'var(--cy-ink)', marginTop:6 }}>{s.n}</div>
            <div style={{ fontSize:11.5, color:'var(--cy-ink-soft)', marginTop:2 }}>{s.l}</div>
          </div>
        ))}
      </div>

      {/* 观云记录入口 */}
      <div style={{ padding:'14px 18px 0' }}>
        <button onClick={onOpenJournal} className="cy-card cy-tap" style={{ width:'100%', border:'none', cursor:'pointer',
          padding:'15px 18px', display:'flex', alignItems:'center', gap:13, textAlign:'left' }}>
          <div style={{ width:42, height:42, borderRadius:14, flexShrink:0, display:'grid', placeItems:'center',
            background:'var(--cy-accent2)', color:'#fff' }}><Icon name="cal" size={22}/></div>
          <div style={{ flex:1 }}>
            <div style={{ fontFamily:'var(--cy-serif)', fontSize:16, fontWeight:600, color:'var(--cy-ink)' }}>我的观云记录</div>
            <div style={{ fontSize:12, color:'var(--cy-ink-soft)', marginTop:2 }}>
              共 {(state.records || []).length} 次观云 · 每一次相遇都留痕
            </div>
          </div>
          <Icon name="chev" size={20} style={{ color:'var(--cy-ink-soft)' }}/>
        </button>
      </div>

      {/* 称号之路 */}
      <div style={{ padding:'20px 18px 0' }}>
        <div style={{ fontFamily:'var(--cy-serif)', fontSize:17, fontWeight:700, color:'var(--cy-ink)', marginBottom:12 }}>称号之路</div>
        <div className="cy-card" style={{ padding:'6px 18px' }}>
          {window.CY_LEVELS.map((lv, i) => {
            const reached = got >= lv.min, current = lv.title === level.title;
            return (
              <div key={i} style={{ display:'flex', alignItems:'center', gap:13, padding:'12px 0',
                borderBottom: i < window.CY_LEVELS.length-1 ? '1px solid var(--cy-line)' : 'none' }}>
                <div style={{ width:30, height:30, borderRadius:99, flexShrink:0, display:'grid', placeItems:'center',
                  background: reached ? 'var(--cy-accent)' : 'var(--cy-line)', color: reached ? '#fff' : 'var(--cy-ink-soft)' }}>
                  {reached ? <Icon name="check" size={17}/> : <span style={{ fontSize:12, fontWeight:700 }}>{i}</span>}
                </div>
                <div style={{ flex:1 }}>
                  <div style={{ fontFamily:'var(--cy-serif)', fontSize:15.5, fontWeight:600,
                    color: reached ? 'var(--cy-ink)' : 'var(--cy-ink-soft)' }}>
                    {lv.title} {current && <span style={{ fontSize:11, color:'var(--cy-accent)', fontFamily:'var(--cy-sans)' }}>· 当前</span>}
                  </div>
                  <div style={{ fontSize:11.5, color:'var(--cy-ink-soft)', marginTop:1 }}>{lv.blurb}</div>
                </div>
                <div style={{ fontSize:12, color:'var(--cy-ink-soft)' }}>{lv.min === 0 ? '起点' : `${lv.min} 种`}</div>
              </div>
            );
          })}
        </div>
      </div>

      {/* 徽章 */}
      <div style={{ padding:'20px 18px 0' }}>
        <div style={{ fontFamily:'var(--cy-serif)', fontSize:17, fontWeight:700, color:'var(--cy-ink)', marginBottom:12 }}>我的徽章</div>
        <div style={{ display:'grid', gridTemplateColumns:'1fr 1fr 1fr', gap:12 }}>
          {bdg.map(b => (
            <div key={b.id} className="cy-card" style={{ padding:'12px 8px', textAlign:'center', opacity: b.on ? 1 : .5 }}>
              <div style={{ height:50, filter: b.on ? 'none' : 'grayscale(1)', opacity: b.on ? 1 : .55 }}>
                <CloudArt shape={b.shape} tone={b.tone} style={{ width:'100%', height:'100%' }}/>
              </div>
              <div style={{ fontFamily:'var(--cy-serif)', fontSize:13, fontWeight:600, color:'var(--cy-ink)', marginTop:4 }}>{b.name}</div>
              <div style={{ fontSize:10.5, color:'var(--cy-ink-soft)', marginTop:2, lineHeight:1.35 }}>{b.on ? '已获得' : b.desc}</div>
            </div>
          ))}
        </div>
      </div>
    </div>
  );
}

// ── 头像选择器 ──────────────────────────────────────────
function AvatarPicker({ current = 0, onPick, onClose }) {
  return (
    <div style={{ position:'absolute', inset:0, zIndex:50, display:'flex', alignItems:'flex-end' }}>
      <div onClick={onClose} style={{ position:'absolute', inset:0, background:'rgba(30,50,70,.32)', backdropFilter:'blur(2px)', animation:'cy-fadeup .25s ease' }}/>
      <div style={{ position:'relative', width:'100%', background:'var(--cy-bg)', borderRadius:'26px 26px 0 0',
        padding:'22px 20px calc(env(safe-area-inset-bottom) + 24px)', boxShadow:'0 -10px 30px rgba(60,90,120,.18)' }}>
        <div style={{ width:40, height:4, borderRadius:99, background:'var(--cy-line)', margin:'0 auto 16px' }}/>
        <div style={{ fontFamily:'var(--cy-serif)', fontSize:18, fontWeight:700, color:'var(--cy-ink)', textAlign:'center' }}>选择头像</div>
        <div style={{ fontSize:12.5, color:'var(--cy-ink-soft)', textAlign:'center', marginTop:4, marginBottom:20 }}>挑一片云做你的样子</div>
        <div style={{ display:'grid', gridTemplateColumns:'1fr 1fr 1fr', gap:16 }}>
          {window.CY_AVATARS.map(a => {
            const on = a.id === current;
            return (
              <button key={a.id} onClick={() => onPick(a.id)} className="cy-tap" style={{ border:'none', background:'none', cursor:'pointer',
                display:'flex', flexDirection:'column', alignItems:'center', gap:7, padding:0 }}>
                <div style={{ borderRadius:99, padding:3, background: on ? 'var(--cy-accent)' : 'transparent' }}>
                  <Avatar id={a.id} size={66} ring/>
                </div>
                <span style={{ fontSize:12.5, fontWeight: on ? 700 : 500, color: on ? 'var(--cy-accent)' : 'var(--cy-ink-soft)' }}>{a.name}</span>
              </button>
            );
          })}
        </div>
      </div>
    </div>
  );
}

Object.assign(window, { HomeScreen, GalleryScreen, ProfileScreen, AvatarPicker });
