// screens-rewards.jsx — Duolingo-flavored gamified rewards.
// Stack: animated points bar with tier-up loop, streak flame, daily quests
// (buckets of XP), tier perks (concrete % off), leaderboard, achievements,
// redeem rail. Tenant-skinned via WVU.gold (primary).

function ScreenRewards({ onBack, onOpenMe }) {
  // ─── Tier model ─────────────────────────────────
  // Goes: Rookie → Loyal → Gold → Platinum → Mountain
  const TIERS = [
    { id: 'rookie',   label: 'Rookie',   min: 0,     perks: ['10% off concessions', '5% off shop', 'Profile flair'] },
    { id: 'loyal',    label: 'Loyal',    min: 2500,  perks: ['15% off concessions', '10% off shop', 'Early ticket access'] },
    { id: 'gold',     label: 'Gold',     min: 5000,  perks: ['20% off concessions', '15% off shop', 'Free pregame upgrade', '2× points weekends'] },
    { id: 'platinum', label: 'Platinum', min: 20000, perks: ['25% off concessions', '20% off shop', 'Sideline pass · 2/yr', 'Athlete meet-and-greet'] },
    { id: 'mountain', label: 'Mountain', min: 50000, perks: ['Free concessions', 'Free shop · monthly', 'Travel package', 'All-access laminate'] },
  ];

  const points = DEREK.points;
  const tierIdx = TIERS.reduce((acc, t, i) => points >= t.min ? i : acc, 0);
  const tier = TIERS[tierIdx];
  const next = TIERS[tierIdx + 1] || tier;
  const inTier = points - tier.min;
  const tierSpan = (next.min - tier.min) || 1;
  const tierPct = Math.min(1, inTier / tierSpan);
  const toNext = Math.max(0, next.min - points);

  // ─── Today's quests (Duolingo-style) ────────────
  const quests = [
    { id: 'q1', icon: 'ticket',   label: 'Check in to a game',  pts: 500, prog: 0, total: 1, cta: 'Saturday' },
    { id: 'q2', icon: 'play',     label: 'Watch 1 episode',     pts:  50, prog: 0, total: 1, cta: 'Open video' },
    { id: 'q3', icon: 'shop',     label: 'Buy team merch',      pts:  30, prog: 1, total: 1, cta: 'Done', done: true },
    { id: 'q4', icon: 'star',     label: 'Tip your athlete',    pts: 150, prog: 0, total: 1, cta: 'Open NIL' },
  ];
  const questsDone = quests.filter(q => q.done).length;

  // ─── Streak ─────────────────────────────────────
  const streakWeeks = 8;
  const streakMax = 12;

  // ─── Achievements (badges) ──────────────────────
  const achievements = [
    { id: 'a1', label: 'Tailgate VIP',     sub: '5 games',    on: true },
    { id: 'a2', label: 'Roadie',           sub: '1 away game', on: true },
    { id: 'a3', label: 'Big Spender',      sub: '$500 spend', on: true },
    { id: 'a4', label: 'Ride or Die',      sub: '8wk streak', on: true },
    { id: 'a5', label: 'Recruiter',        sub: 'Refer 3',    on: false },
    { id: 'a6', label: 'Sweep',            sub: 'Watch all',  on: false },
  ];

  // ─── Leaderboard ────────────────────────────────
  const leaderboard = [
    { rank: 110, name: 'Tasha P.',        pts: 14210 },
    { rank: 111, name: 'Marcus W.',       pts: 13720 },
    { rank: 112, name: DEREK.firstName + ' (you)', pts: points, you: true },
    { rank: 113, name: 'Sami O.',         pts: 13180 },
    { rank: 114, name: 'Kenji L.',        pts: 12940 },
  ];

  // Animated count-up for points
  const [displayPts, setDisplayPts] = React.useState(0);
  React.useEffect(() => {
    let raf;
    const start = performance.now();
    const dur = 900;
    const tick = (now) => {
      const t = Math.min(1, (now - start) / dur);
      const ease = 1 - Math.pow(1 - t, 3);
      setDisplayPts(Math.round(points * ease));
      if (t < 1) raf = requestAnimationFrame(tick);
    };
    raf = requestAnimationFrame(tick);
    return () => cancelAnimationFrame(raf);
  }, [points]);

  // Animated XP bar
  const [barPct, setBarPct] = React.useState(0);
  React.useEffect(() => {
    const t = setTimeout(() => setBarPct(tierPct), 100);
    return () => clearTimeout(t);
  }, [tierPct]);

  return (
    <div style={{
      position: 'absolute', inset: 0, overflow: 'auto',
      background: WVU.ink, color: WVU.cream,
      paddingTop: 104, paddingBottom: 130,
    }} className="mtn-scrollbar">

      {/* ─── HERO: Points + Tier + XP bar ─────────────── */}
      <div style={{ padding: '4px 16px 18px' }}>
        <div style={{
          position: 'relative', overflow: 'hidden',
          borderRadius: DS.r.xl,
          background: `
            radial-gradient(ellipse 80% 65% at 70% 25%, ${hexA(WVU.gold, 0.30)}, transparent 65%),
            radial-gradient(ellipse 60% 50% at 15% 100%, ${hexA(WVU.blue, 0.40)}, transparent 65%),
            linear-gradient(160deg, ${WVU.ink2}, #0a0805 90%)
          `,
          border: `0.5px solid ${hexA(WVU.gold, 0.25)}`,
          boxShadow: `0 18px 50px ${hexA(WVU.gold, 0.16)}, 0 0 0 1px rgba(245,236,217,0.04) inset`,
          padding: '20px 20px 18px',
        }}>
          {/* Tier crest in corner */}
          <div style={{
            position: 'absolute', top: -10, right: -10,
            opacity: 0.16, pointerEvents: 'none',
          }}>
            <RwTierCrest size={140} color={WVU.gold} />
          </div>

          {/* Rank pill */}
          <div style={{
            display: 'inline-flex', alignItems: 'center', gap: 6,
            padding: '5px 10px', borderRadius: DS.r.pill,
            background: `linear-gradient(135deg, ${WVU.gold}, ${WVU.goldDim})`,
            color: WVU.blueDim, marginBottom: 14,
            boxShadow: `0 4px 12px ${hexA(WVU.gold, 0.45)}`,
          }}>
            <RwTierIcon size={14} />
            <span style={{
              fontFamily: DS.sans, fontSize: 11, fontWeight: 800,
              letterSpacing: '0.06em', textTransform: 'uppercase',
            }}>{tier.label} Tier</span>
          </div>

          {/* Big point count */}
          <div style={{
            display: 'flex', alignItems: 'baseline', gap: 8,
            fontFamily: DS.display, fontWeight: 900,
            color: WVU.cream, lineHeight: 0.95,
            textShadow: `0 2px 18px ${hexA(WVU.gold, 0.4)}`,
            fontVariantNumeric: 'tabular-nums', letterSpacing: '-0.04em',
          }}>
            <span style={{ fontSize: 60 }}>{displayPts.toLocaleString()}</span>
            <span style={{ fontSize: 16, color: WVU.creamDim, fontWeight: 600, letterSpacing: 0 }}>pts</span>
          </div>

          {/* XP bar */}
          <div style={{ marginTop: 16 }}>
            <div style={{
              display: 'flex', justifyContent: 'space-between',
              fontFamily: DS.mono, fontSize: 10, letterSpacing: '0.08em',
              color: WVU.creamDim, marginBottom: 6,
            }}>
              <span>{tier.label}</span>
              <span style={{ color: WVU.gold, fontWeight: 700 }}>
                {toNext.toLocaleString()} TO {next.label.toUpperCase()}
              </span>
            </div>
            <div style={{
              height: 12, borderRadius: 6,
              background: 'rgba(0,0,0,0.4)',
              border: `0.5px solid rgba(245,236,217,0.08)`,
              overflow: 'hidden', position: 'relative',
            }}>
              <div style={{
                width: `${barPct * 100}%`, height: '100%',
                background: `linear-gradient(90deg, ${WVU.goldDim}, ${WVU.gold} 60%, ${WVU.goldLite})`,
                boxShadow: `0 0 12px ${hexA(WVU.gold, 0.7)}, inset 0 1px 0 rgba(255,255,255,0.4)`,
                transition: 'width 1200ms cubic-bezier(0.22,1,0.36,1)',
                position: 'relative',
              }}>
                {/* shimmer */}
                <div style={{
                  position: 'absolute', inset: 0,
                  background: 'linear-gradient(90deg, transparent, rgba(255,255,255,0.3), transparent)',
                  backgroundSize: '200% 100%',
                  animation: 'mtnShimmer 2.4s linear infinite',
                }} />
              </div>
            </div>
          </div>
        </div>
      </div>

      {/* ─── STREAK BLOCK (Duolingo flame) ────────────── */}
      <div style={{ padding: '0 16px 18px' }}>
        <div style={{
          display: 'flex', alignItems: 'center', gap: 14,
          padding: 16, borderRadius: DS.r.lg,
          background: `linear-gradient(135deg, ${hexA('#FF6A00', 0.16)}, ${hexA(WVU.gold, 0.10)})`,
          border: `0.5px solid ${hexA('#FF6A00', 0.30)}`,
        }}>
          {/* Flame icon */}
          <div style={{
            width: 56, height: 56, borderRadius: 28, flexShrink: 0,
            background: `radial-gradient(circle at 50% 60%, #FFD400, #FF6A00 60%, #B91D1D)`,
            display: 'flex', alignItems: 'center', justifyContent: 'center',
            boxShadow: `0 6px 20px rgba(255,106,0,0.5), inset 0 -3px 0 rgba(0,0,0,0.18)`,
            position: 'relative',
          }}>
            <svg width="26" height="26" viewBox="0 0 26 26" fill="none">
              <path d="M13 2c0 4-5 6-5 11a5 5 0 0010 0c0-2-1-3-1-5 3 2 5 5 5 8a8 8 0 11-16 0c0-6 5-9 7-14z"
                fill="#fff" opacity="0.95"/>
            </svg>
          </div>
          <div style={{ flex: 1, minWidth: 0 }}>
            <div style={{ display: 'flex', alignItems: 'baseline', gap: 6 }}>
              <span style={{
                fontFamily: DS.display, fontSize: 28, fontWeight: 900,
                color: WVU.cream, letterSpacing: '-0.025em',
                fontVariantNumeric: 'tabular-nums', lineHeight: 1,
              }}>{streakWeeks}</span>
              <span style={{
                fontFamily: DS.sans, fontSize: 13, fontWeight: 700, color: WVU.cream,
              }}>week streak</span>
            </div>
            <div style={{
              fontFamily: DS.sans, fontSize: 11, color: WVU.creamDim,
              marginTop: 3, lineHeight: 1.4,
            }}>
              Engage every week to keep it. Hit 12 for{' '}
              <span style={{ color: WVU.gold, fontWeight: 700 }}>+500 bonus</span>.
            </div>
            {/* dot bar */}
            <div style={{ display: 'flex', gap: 3, marginTop: 8 }}>
              {Array.from({ length: streakMax }).map((_, i) => (
                <div key={i} style={{
                  flex: 1, height: 5, borderRadius: 2,
                  background: i < streakWeeks
                    ? 'linear-gradient(180deg, #FFD400, #FF6A00)'
                    : 'rgba(245,236,217,0.10)',
                  boxShadow: i < streakWeeks ? '0 0 4px rgba(255,106,0,0.5)' : 'none',
                }} />
              ))}
            </div>
          </div>
        </div>
      </div>

      {/* ─── TODAY'S QUESTS ───────────────────────────── */}
      <MtnSection
        title="Today's quests"
        kicker={`${questsDone} of ${quests.length} done · +${quests.reduce((s,q) => s + (q.done ? 0 : q.pts), 0)} available`}
      >
        <div style={{ padding: '0 16px', display: 'flex', flexDirection: 'column', gap: 8 }}>
          {quests.map(q => <RwQuest key={q.id} {...q} />)}
        </div>
      </MtnSection>

      {/* ─── TIER PERKS (concrete) ────────────────────── */}
      <MtnSection
        title={`Your ${tier.label} perks`}
        kicker={tierIdx < TIERS.length - 1 ? `${TIERS[tierIdx + 1].label} unlocks at ${TIERS[tierIdx + 1].min.toLocaleString()} pts` : 'Top tier — congrats'}
      >
        <div style={{ padding: '0 16px' }}>
          <MtnCard padding={0}>
            {tier.perks.map((perk, i) => (
              <div key={i} style={{
                padding: '13px 14px',
                display: 'flex', alignItems: 'center', gap: 12,
                borderBottom: i === tier.perks.length - 1 ? 'none' : `0.5px solid ${WVU.line}`,
              }}>
                <div style={{
                  width: 24, height: 24, borderRadius: 12,
                  background: `linear-gradient(135deg, ${WVU.gold}, ${WVU.goldDim})`,
                  display: 'flex', alignItems: 'center', justifyContent: 'center',
                  flexShrink: 0,
                  boxShadow: `0 2px 6px ${hexA(WVU.gold, 0.4)}`,
                }}>
                  <svg width="12" height="12" viewBox="0 0 12 12" fill="none">
                    <path d="M2.5 6.5l2.5 2.5 4.5-5" stroke={WVU.blueDim} strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"/>
                  </svg>
                </div>
                <div style={{
                  flex: 1, fontFamily: DS.sans, fontSize: 13, fontWeight: 600,
                  color: WVU.cream, letterSpacing: '-0.005em',
                }}>{perk}</div>
                <div style={{
                  fontFamily: DS.mono, fontSize: 9, color: WVU.gold,
                  letterSpacing: '0.1em',
                }}>ACTIVE</div>
              </div>
            ))}
          </MtnCard>

          {/* Preview next tier */}
          {tierIdx < TIERS.length - 1 && (
            <div style={{
              marginTop: 10, padding: '12px 14px', borderRadius: DS.r.md,
              background: 'rgba(245,236,217,0.025)',
              border: `0.5px dashed ${hexA(WVU.gold, 0.30)}`,
              display: 'flex', alignItems: 'center', gap: 10,
            }}>
              <div style={{ flex: 1 }}>
                <div style={{
                  fontFamily: DS.sans, fontSize: 10, fontWeight: 600, color: WVU.gold, letterSpacing: '0.12em', textTransform: 'uppercase', marginBottom: 4, textTransform: 'uppercase',
                }}>Locked at {next.label}</div>
                <div style={{
                  fontFamily: DS.sans, fontSize: 11, color: WVU.creamDim,
                  lineHeight: 1.45,
                }}>
                  {next.perks.slice(0, 2).join(' · ')}
                </div>
              </div>
              <div style={{
                fontFamily: DS.mono, fontSize: 10, fontWeight: 700,
                color: WVU.gold, letterSpacing: '0.04em', whiteSpace: 'nowrap',
              }}>{toNext.toLocaleString()} pts away</div>
            </div>
          )}
        </div>
      </MtnSection>

      {/* ─── ACHIEVEMENTS ─────────────────────────────── */}
      <MtnSection title="Achievements" kicker={`${achievements.filter(a => a.on).length} of ${achievements.length}`}>
        <div style={{
          padding: '0 16px',
          display: 'grid', gridTemplateColumns: 'repeat(3, 1fr)', gap: 8,
        }}>
          {achievements.map(a => (
            <div key={a.id} style={{
              padding: 10, borderRadius: DS.r.md,
              background: a.on ? WVU.ink2 : 'rgba(245,236,217,0.02)',
              border: `0.5px solid ${a.on ? hexA(WVU.gold, 0.32) : WVU.line}`,
              opacity: a.on ? 1 : 0.5,
              display: 'flex', flexDirection: 'column', alignItems: 'center', gap: 6,
            }}>
              <RwBadge size={36} on={a.on} />
              <div style={{
                fontFamily: DS.sans, fontSize: 10.5, fontWeight: 700,
                color: a.on ? WVU.cream : WVU.creamDim, textAlign: 'center',
                letterSpacing: '-0.005em', lineHeight: 1.15,
              }}>{a.label}</div>
              <div style={{
                fontFamily: DS.mono, fontSize: 8, color: WVU.creamDim,
                letterSpacing: '0.08em', textAlign: 'center',
              }}>{a.sub}</div>
            </div>
          ))}
        </div>
      </MtnSection>

      {/* ─── LEADERBOARD ──────────────────────────────── */}
      <MtnSection title="Your league" kicker="Top 1% · This week">
        <div style={{ padding: '0 16px' }}>
          <MtnCard padding={0}>
            {leaderboard.map((row, i) => (
              <div key={i} style={{
                padding: '11px 14px',
                display: 'flex', alignItems: 'center', gap: 12,
                borderBottom: i === leaderboard.length - 1 ? 'none' : `0.5px solid ${WVU.line}`,
                background: row.you ? hexA(WVU.gold, 0.10) : 'transparent',
              }}>
                <div style={{
                  width: 28, fontFamily: DS.mono, fontSize: 11, fontWeight: 700,
                  color: row.you ? WVU.gold : WVU.creamDim,
                  letterSpacing: '0.04em', textAlign: 'right',
                  fontVariantNumeric: 'tabular-nums',
                }}>{row.rank}</div>
                <div style={{
                  width: 28, height: 28, borderRadius: 14,
                  background: row.you
                    ? `linear-gradient(135deg, ${WVU.gold}, ${WVU.goldDim})`
                    : 'rgba(245,236,217,0.06)',
                  border: row.you ? 'none' : `0.5px solid ${WVU.line}`,
                  display: 'flex', alignItems: 'center', justifyContent: 'center',
                  fontFamily: DS.sans, fontSize: 10, fontWeight: 800,
                  color: row.you ? WVU.blueDim : WVU.cream,
                  flexShrink: 0,
                }}>{row.name[0]}</div>
                <div style={{
                  flex: 1, fontFamily: DS.sans, fontSize: 12.5,
                  fontWeight: row.you ? 700 : 500,
                  color: row.you ? WVU.cream : WVU.cream,
                  letterSpacing: '-0.005em',
                }}>{row.name}</div>
                <div style={{
                  fontFamily: DS.mono, fontSize: 11, fontWeight: 700,
                  color: row.you ? WVU.gold : WVU.creamDim,
                  fontVariantNumeric: 'tabular-nums', letterSpacing: '0.02em',
                }}>{row.pts.toLocaleString()}</div>
              </div>
            ))}
          </MtnCard>
        </div>
      </MtnSection>

      {/* ─── REDEEM RAIL ──────────────────────────────── */}
      <MtnSection title="Spend your points" kicker={`${REWARDS.filter(r => points >= r.pts).length} unlocked`}>
        <div style={{
          padding: '0 16px',
          display: 'grid', gridTemplateColumns: 'repeat(2, 1fr)', gap: 10,
        }}>
          {REWARDS.slice(0, 4).map(rw => {
            const can = points >= rw.pts;
            return (
              <div key={rw.id} style={{
                padding: 14, borderRadius: DS.r.md,
                background: can ? WVU.ink2 : 'rgba(30,26,19,0.4)',
                border: `0.5px solid ${can ? hexA(WVU.gold, 0.30) : WVU.line}`,
                opacity: can ? 1 : 0.6,
                display: 'flex', flexDirection: 'column',
                cursor: can ? 'pointer' : 'default',
              }}>
                <div style={{
                  fontFamily: DS.mono, fontSize: 10, fontWeight: 800,
                  color: can ? WVU.gold : WVU.creamDim, letterSpacing: '0.08em',
                }}>{rw.pts.toLocaleString()} PTS</div>
                <div style={{
                  fontFamily: DS.sans, fontSize: 13, fontWeight: 700,
                  color: WVU.cream, marginTop: 6, lineHeight: 1.25, flex: 1,
                  letterSpacing: '-0.005em',
                }}>{rw.title}</div>
                <div style={{
                  fontFamily: DS.sans, fontSize: 10, color: WVU.creamDim,
                  marginTop: 3, lineHeight: 1.35,
                }}>{rw.sub}</div>
                <div style={{
                  marginTop: 10, padding: '6px 10px', textAlign: 'center',
                  background: can ? WVU.gold : 'transparent',
                  color: can ? WVU.blueDim : WVU.creamDim,
                  border: can ? 'none' : `0.5px solid ${WVU.line}`,
                  borderRadius: DS.r.pill,
                  fontFamily: DS.sans, fontSize: 10.5, fontWeight: 700,
                }}>{can ? 'Redeem' : `${(rw.pts - points).toLocaleString()} away`}</div>
              </div>
            );
          })}
        </div>
      </MtnSection>

      <div style={{
        textAlign: 'center', marginTop: 4,
        fontFamily: DS.mono, fontSize: 9, color: WVU.creamDim, letterSpacing: '0.16em',
      }}>
        ★ {WVU.nick.toUpperCase()} REWARDS · POWERED BY THE SPINE ★
      </div>
    </div>
  );
}

// ─── Quest row ────────────────────────────────────
function RwQuest({ icon, label, pts, prog, total, cta, done }) {
  const pct = prog / total;
  const icons = {
    ticket: <svg width="16" height="16" viewBox="0 0 16 16" fill="none"><path d="M2 5h12v2a1 1 0 000 2v2H2V9a1 1 0 000-2V5z" stroke="currentColor" strokeWidth="1.4" strokeLinejoin="round"/></svg>,
    play:   <svg width="16" height="16" viewBox="0 0 16 16" fill="none"><path d="M5 3l8 5-8 5V3z" fill="currentColor"/></svg>,
    shop:   <svg width="16" height="16" viewBox="0 0 16 16" fill="none"><path d="M3 5h10l-1 8H4L3 5z" stroke="currentColor" strokeWidth="1.4" strokeLinejoin="round"/><path d="M6 5V4a2 2 0 014 0v1" stroke="currentColor" strokeWidth="1.4"/></svg>,
    star:   <svg width="16" height="16" viewBox="0 0 16 16" fill="none"><path d="M8 2l1.9 4 4.1.4-3 3 1 4.1L8 11.5 4 13.5l1-4.1-3-3 4.1-.4L8 2z" fill="currentColor"/></svg>,
  };

  return (
    <div style={{
      padding: 14, borderRadius: DS.r.md,
      background: done ? hexA(WVU.gold, 0.06) : WVU.ink2,
      border: `0.5px solid ${done ? hexA(WVU.gold, 0.32) : WVU.line}`,
      display: 'flex', alignItems: 'center', gap: 12,
    }}>
      <div style={{
        width: 38, height: 38, borderRadius: DS.r.md,
        background: done
          ? `linear-gradient(135deg, ${WVU.gold}, ${WVU.goldDim})`
          : 'rgba(245,236,217,0.06)',
        border: done ? 'none' : `0.5px solid ${WVU.line}`,
        display: 'flex', alignItems: 'center', justifyContent: 'center',
        color: done ? WVU.blueDim : WVU.gold,
        flexShrink: 0,
        boxShadow: done ? `0 4px 12px ${hexA(WVU.gold, 0.4)}` : 'none',
      }}>
        {done ? (
          <svg width="18" height="18" viewBox="0 0 18 18" fill="none">
            <path d="M3 9.5l4 4 8-9" stroke="currentColor" strokeWidth="2.4" strokeLinecap="round" strokeLinejoin="round"/>
          </svg>
        ) : icons[icon] || icons.star}
      </div>
      <div style={{ flex: 1, minWidth: 0 }}>
        <div style={{
          display: 'flex', alignItems: 'baseline', gap: 8,
          fontFamily: DS.sans, fontSize: 13, fontWeight: 700,
          color: WVU.cream, letterSpacing: '-0.005em',
        }}>
          <span style={{ flex: 1, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>{label}</span>
        </div>
        <div style={{
          marginTop: 6, height: 4, borderRadius: 2,
          background: 'rgba(245,236,217,0.08)', overflow: 'hidden',
        }}>
          <div style={{
            width: `${pct * 100}%`, height: '100%',
            background: done
              ? `linear-gradient(90deg, ${WVU.gold}, ${WVU.goldLite})`
              : `linear-gradient(90deg, ${WVU.goldDim}, ${WVU.gold})`,
            boxShadow: done ? `0 0 6px ${hexA(WVU.gold, 0.5)}` : 'none',
          }} />
        </div>
      </div>
      <div style={{
        textAlign: 'right', flexShrink: 0,
      }}>
        <div style={{
          fontFamily: DS.display, fontSize: 16, fontWeight: 800,
          color: done ? WVU.gold : WVU.cream, letterSpacing: '-0.01em',
          fontVariantNumeric: 'tabular-nums',
        }}>+{pts}</div>
        <div style={{
          fontFamily: DS.mono, fontSize: 8, color: done ? WVU.gold : WVU.creamDim,
          letterSpacing: '0.12em', marginTop: 1,
        }}>{done ? 'CLAIMED' : cta.toUpperCase()}</div>
      </div>
    </div>
  );
}

// ─── Trophy crest (decorative) ─────────────────────
function RwTierCrest({ size = 100, color }) {
  const s = size;
  return (
    <svg width={s} height={s} viewBox="0 0 100 100" fill="none">
      <path d="M30 18h40v22a20 20 0 01-40 0V18z" stroke={color} strokeWidth="2.4" fill="none"/>
      <path d="M30 24H18a8 8 0 008 8" stroke={color} strokeWidth="2" fill="none" strokeLinecap="round"/>
      <path d="M70 24h12a8 8 0 01-8 8" stroke={color} strokeWidth="2" fill="none" strokeLinecap="round"/>
      <rect x="46" y="58" width="8" height="14" stroke={color} strokeWidth="2" fill="none"/>
      <rect x="32" y="72" width="36" height="6" rx="2" stroke={color} strokeWidth="2" fill="none"/>
      <path d="M50 26l2.5 5 5.5.5-4 4 1 5.5L50 38l-5 3 1-5.5-4-4 5.5-.5L50 26z" fill={color}/>
    </svg>
  );
}

// ─── Tiny tier icon for hero pill ───────────────────
function RwTierIcon({ size = 14 }) {
  return (
    <svg width={size} height={size} viewBox="0 0 14 14" fill="none">
      <path d="M4 2h6v3a3 3 0 01-6 0V2z" fill="currentColor"/>
      <rect x="6" y="7" width="2" height="3" fill="currentColor"/>
      <rect x="3.5" y="9.5" width="7" height="1.5" rx="0.5" fill="currentColor"/>
    </svg>
  );
}

// ─── Achievement badge SVG ──────────────────────────
function RwBadge({ size = 36, on = true }) {
  const s = size;
  const fill = on ? WVU.gold : 'rgba(245,236,217,0.20)';
  const fillDim = on ? WVU.goldDim : 'rgba(245,236,217,0.12)';
  return (
    <svg width={s} height={s} viewBox="0 0 36 36" fill="none">
      <defs>
        <linearGradient id={`bg${s}${on}`} x1="0" y1="0" x2="0" y2="1">
          <stop offset="0%" stopColor={fill}/>
          <stop offset="100%" stopColor={fillDim}/>
        </linearGradient>
      </defs>
      {/* outer star polygon */}
      <path d="M18 2l3.4 7.4 8.1.8-6 5.4 1.8 8L18 19.5l-7.3 4.1 1.8-8-6-5.4 8.1-.8L18 2z"
            fill={`url(#bg${s}${on})`}
            stroke={on ? WVU.goldLite : 'transparent'} strokeWidth="0.5"/>
      {/* inner circle */}
      <circle cx="18" cy="14" r="4.5" fill={on ? WVU.blueDim : 'rgba(0,0,0,0.4)'}/>
    </svg>
  );
}

Object.assign(window, { ScreenRewards });
