// PRYPCO Blocks · Investor Portfolio Prototype
// Mobile-first React app. Three screens + notification overlay.

const { useState, useEffect, useMemo, useRef } = React;

// ─────────────────────────────────────────────
// Design tokens (pulled from TWEAKS)
// ─────────────────────────────────────────────
const PRYPCO_DEFAULTS = /*EDITMODE-BEGIN*/{
  "primary": "#0F6E56",
  "primaryInk": "#0A4A3A",
  "accent": "#E8F3EF",
  "gold": "#C8A961",
  "ink": "#0B1512",
  "muted": "#6B7A75",
  "line": "#E8ECEA",
  "bg": "#FBFBF9",
  "card": "#FFFFFF"
}/*EDITMODE-END*/;

// ─────────────────────────────────────────────
// Data
// ─────────────────────────────────────────────
const PROPERTIES = [
  {
    id: 'dt',
    name: 'The Residences JLT',
    area: 'Downtown Dubai',
    type: '2 BR Apartment',
    invested: 12000,
    current: 13420,
    yearGain: 11.8,
    monthly: 91,
    yield: 9.1,
    blocks: 120,
    occupied: true,
    img: 'linear-gradient(135deg, #2C3E50 0%, #506878 55%, #8FA4B3 100%)',
    glyph: 'downtown',
    acquired: 'Mar 2025',
    occupancy: 96,
    belowMarket: 10.2,
    history6m: [12000, 12180, 12520, 12710, 13050, 13420],
    rental3m: [
      { m: 'Mar 2026', amt: 91, tenant: 'Rent · Occupied' },
      { m: 'Feb 2026', amt: 91, tenant: 'Rent · Occupied' },
      { m: 'Jan 2026', amt: 91, tenant: 'Rent · Occupied' }
    ]
  },
  {
    id: 'jvc',
    name: 'Belgravia Heights',
    area: 'JVC',
    type: 'Studio',
    invested: 8400,
    current: 8880,
    yearGain: 5.7,
    monthly: 56,
    yield: 8.4,
    blocks: 84,
    occupied: true,
    img: 'linear-gradient(135deg, #8B7355 0%, #B8976B 50%, #D4B896 100%)',
    glyph: 'jvc',
    acquired: 'Jul 2025',
    occupancy: 92,
    belowMarket: 7.8,
    history6m: [8400, 8440, 8510, 8620, 8740, 8880],
    rental3m: [
      { m: 'Mar 2026', amt: 56, tenant: 'Rent · Occupied' },
      { m: 'Feb 2026', amt: 56, tenant: 'Rent · Occupied' },
      { m: 'Jan 2026', amt: 56, tenant: 'Rent · Occupied' }
    ]
  },
  {
    id: 'marina',
    name: 'Marina Gate Tower',
    area: 'Dubai Marina',
    type: '1 BR Apartment',
    invested: 4200,
    current: 4692,
    yearGain: 11.7,
    monthly: 39,
    yield: 11.2,
    blocks: 42,
    occupied: true,
    img: 'linear-gradient(135deg, #1B3A4B 0%, #2E6B82 45%, #6BA9C4 100%)',
    glyph: 'marina',
    acquired: 'Nov 2025',
    occupancy: 98,
    belowMarket: 12.4,
    history6m: [4200, 4260, 4340, 4440, 4580, 4692],
    rental3m: [
      { m: 'Mar 2026', amt: 39, tenant: 'Rent · Occupied' },
      { m: 'Feb 2026', amt: 39, tenant: 'Rent · Occupied' },
      { m: 'Jan 2026', amt: 39, tenant: 'Rent · Occupied' }
    ]
  }
];

// ─────────────────────────────────────────────
// Formatters
// ─────────────────────────────────────────────
const fmt = (n) => n.toLocaleString('en-US');
const fmtAED = (n) => 'AED ' + fmt(n);

// ─────────────────────────────────────────────
// Icons (hand-picked, minimal strokes)
// ─────────────────────────────────────────────
const Icon = {
  home: (c = 'currentColor') => (
    <svg width="22" height="22" viewBox="0 0 24 24" fill="none"><path d="M3 11.5 12 4l9 7.5M5.5 10V20h13V10" stroke={c} strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round"/></svg>
  ),
  explore: (c = 'currentColor') => (
    <svg width="22" height="22" viewBox="0 0 24 24" fill="none"><circle cx="12" cy="12" r="8" stroke={c} strokeWidth="1.6"/><path d="m15 9-2.5 5.5L7 17l2.5-5.5L15 9Z" stroke={c} strokeWidth="1.6" strokeLinejoin="round"/></svg>
  ),
  wallet: (c = 'currentColor') => (
    <svg width="22" height="22" viewBox="0 0 24 24" fill="none"><path d="M4 7.5C4 6.7 4.7 6 5.5 6H18v3H5.5C4.7 9 4 8.3 4 7.5Z" stroke={c} strokeWidth="1.6"/><path d="M4 8v10c0 1 .8 2 2 2h13c.6 0 1-.4 1-1v-3" stroke={c} strokeWidth="1.6"/><path d="M14.5 13.5h6v3h-6a1.5 1.5 0 0 1 0-3Z" stroke={c} strokeWidth="1.6"/></svg>
  ),
  profile: (c = 'currentColor') => (
    <svg width="22" height="22" viewBox="0 0 24 24" fill="none"><circle cx="12" cy="9" r="3.5" stroke={c} strokeWidth="1.6"/><path d="M5 20c1.2-3.4 4-5 7-5s5.8 1.6 7 5" stroke={c} strokeWidth="1.6" strokeLinecap="round"/></svg>
  ),
  bell: (c = 'currentColor') => (
    <svg width="20" height="20" viewBox="0 0 24 24" fill="none"><path d="M6 16V11a6 6 0 0 1 12 0v5l1.5 2h-15L6 16Z" stroke={c} strokeWidth="1.6" strokeLinejoin="round"/><path d="M10 20a2 2 0 0 0 4 0" stroke={c} strokeWidth="1.6" strokeLinecap="round"/></svg>
  ),
  arrowUp: (c = 'currentColor') => (
    <svg width="12" height="12" viewBox="0 0 12 12" fill="none"><path d="M6 9.5V2.5M3 5.5 6 2.5l3 3" stroke={c} strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round"/></svg>
  ),
  chevR: (c = 'currentColor') => (
    <svg width="14" height="14" viewBox="0 0 16 16" fill="none"><path d="m6 3 5 5-5 5" stroke={c} strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round"/></svg>
  ),
  chevL: (c = 'currentColor') => (
    <svg width="16" height="16" viewBox="0 0 16 16" fill="none"><path d="m10 3-5 5 5 5" stroke={c} strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round"/></svg>
  ),
  close: (c = 'currentColor') => (
    <svg width="16" height="16" viewBox="0 0 16 16" fill="none"><path d="M4 4l8 8M12 4l-8 8" stroke={c} strokeWidth="1.6" strokeLinecap="round"/></svg>
  ),
  sparkle: (c = 'currentColor') => (
    <svg width="14" height="14" viewBox="0 0 14 14" fill="none"><path d="M7 1.5 8 5.5l4 1-4 1L7 11.5 6 7.5 2 6.5l4-1L7 1.5Z" fill={c}/></svg>
  ),
  plus: (c = 'currentColor') => (
    <svg width="14" height="14" viewBox="0 0 14 14" fill="none"><path d="M7 2v10M2 7h10" stroke={c} strokeWidth="1.8" strokeLinecap="round"/></svg>
  ),
  info: (c = 'currentColor') => (
    <svg width="14" height="14" viewBox="0 0 14 14" fill="none"><circle cx="7" cy="7" r="5.5" stroke={c} strokeWidth="1.4"/><path d="M7 6v3.5M7 4.5v.01" stroke={c} strokeWidth="1.4" strokeLinecap="round"/></svg>
  ),
  pin: (c = 'currentColor') => (
    <svg width="12" height="12" viewBox="0 0 14 14" fill="none"><path d="M7 12s4-3.5 4-7a4 4 0 1 0-8 0c0 3.5 4 7 4 7Z" stroke={c} strokeWidth="1.3" strokeLinejoin="round"/><circle cx="7" cy="5" r="1.3" fill={c}/></svg>
  ),
};

// Property photo placeholder glyphs (simple building silhouettes)
function PropertyGlyph({ kind, size = 70, color = 'rgba(255,255,255,0.35)' }) {
  if (kind === 'downtown') {
    return (
      <svg width={size} height={size} viewBox="0 0 100 100" fill="none">
        <rect x="20" y="30" width="14" height="60" fill={color}/>
        <rect x="38" y="12" width="16" height="78" fill={color}/>
        <rect x="58" y="40" width="14" height="50" fill={color}/>
        <rect x="76" y="55" width="10" height="35" fill={color}/>
        <rect x="42" y="20" width="8" height="3" fill="rgba(255,255,255,0.55)"/>
        <rect x="42" y="30" width="8" height="3" fill="rgba(255,255,255,0.45)"/>
        <rect x="42" y="40" width="8" height="3" fill="rgba(255,255,255,0.35)"/>
      </svg>
    );
  }
  if (kind === 'jvc') {
    return (
      <svg width={size} height={size} viewBox="0 0 100 100" fill="none">
        <rect x="18" y="45" width="22" height="45" fill={color}/>
        <rect x="40" y="32" width="26" height="58" fill={color}/>
        <rect x="66" y="50" width="18" height="40" fill={color}/>
        <path d="M40 32 L53 24 L66 32" fill={color}/>
        <rect x="48" y="55" width="10" height="14" fill="rgba(255,255,255,0.3)"/>
      </svg>
    );
  }
  // marina
  return (
    <svg width={size} height={size} viewBox="0 0 100 100" fill="none">
      <path d="M50 8 L54 14 L54 92 L46 92 L46 14 Z" fill={color}/>
      <rect x="32" y="28" width="12" height="62" fill={color}/>
      <rect x="56" y="22" width="12" height="68" fill={color}/>
      <rect x="72" y="40" width="10" height="50" fill={color}/>
      <rect x="20" y="50" width="10" height="40" fill={color}/>
      <circle cx="50" cy="8" r="1.5" fill="rgba(255,255,255,0.7)"/>
    </svg>
  );
}

// ─────────────────────────────────────────────
// Shared small components
// ─────────────────────────────────────────────
function Pill({ children, tone = 'neutral', style }) {
  const tones = {
    neutral: { bg: '#F1F4F2', fg: '#1C2B26' },
    good:    { bg: '#E4F1EB', fg: '#0F6E56' },
    warn:    { bg: '#FFF1DC', fg: '#8A5A12' },
    dim:     { bg: '#F4F2EE', fg: '#6B7A75' },
  }[tone];
  return (
    <span style={{
      display: 'inline-flex', alignItems: 'center', gap: 4,
      height: 22, padding: '0 9px', borderRadius: 11,
      background: tones.bg, color: tones.fg,
      fontSize: 11, fontWeight: 600, letterSpacing: 0.1,
      ...style
    }}>{children}</span>
  );
}

function Dot({ color, size = 6 }) {
  return <span style={{ display: 'inline-block', width: size, height: size, borderRadius: size, background: color }} />;
}

// ─────────────────────────────────────────────
// Screen 1 · Portfolio Overview
// ─────────────────────────────────────────────
function PortfolioScreen({ T, onOpen, onOpenNotif }) {
  const total = 24600;
  const gain = 8.2;
  const gainAbs = Math.round(total * gain / 108.2);
  const monthly = 186;

  return (
    <div data-screen-label="01 Portfolio Overview" style={{ background: T.bg, minHeight: '100%', paddingTop: 60, paddingBottom: 96 }}>
      {/* Header */}
      <div style={{ padding: '8px 20px 16px', display: 'flex', alignItems: 'center', justifyContent: 'space-between' }}>
        <div style={{ display: 'flex', alignItems: 'center', gap: 10 }}>
          <div style={{
            width: 38, height: 38, borderRadius: 12,
            background: T.primary, color: '#fff',
            display: 'flex', alignItems: 'center', justifyContent: 'center',
            fontWeight: 700, fontSize: 15, letterSpacing: -0.5,
            fontFamily: 'Inter, system-ui'
          }}>P</div>
          <div>
            <div style={{ fontSize: 11, color: T.muted, fontWeight: 500, letterSpacing: 0.3, textTransform: 'uppercase' }}>Good morning</div>
            <div style={{ fontSize: 15, color: T.ink, fontWeight: 600, marginTop: 1 }}>Haresh</div>
          </div>
        </div>
        <button onClick={onOpenNotif} style={{
          width: 38, height: 38, borderRadius: 12,
          background: T.card, border: `1px solid ${T.line}`,
          display: 'flex', alignItems: 'center', justifyContent: 'center',
          color: T.ink, cursor: 'pointer', position: 'relative'
        }}>
          {Icon.bell()}
          <span style={{
            position: 'absolute', top: 9, right: 10,
            width: 7, height: 7, borderRadius: 7, background: '#E5554F',
            boxShadow: `0 0 0 2px ${T.card}`
          }}/>
        </button>
      </div>

      {/* Hero value card */}
      <div style={{ padding: '0 16px' }}>
        <div style={{
          position: 'relative', borderRadius: 22, overflow: 'hidden',
          background: `linear-gradient(160deg, ${T.primary} 0%, ${T.primaryInk} 100%)`,
          color: '#fff', padding: '22px 22px 20px',
          boxShadow: '0 20px 40px -28px rgba(15,110,86,0.55)'
        }}>
          {/* Decorative ring */}
          <svg width="220" height="220" viewBox="0 0 220 220" style={{ position: 'absolute', top: -60, right: -60, opacity: 0.18 }}>
            <circle cx="110" cy="110" r="108" stroke="#fff" strokeWidth="1" fill="none"/>
            <circle cx="110" cy="110" r="78" stroke="#fff" strokeWidth="1" fill="none"/>
            <circle cx="110" cy="110" r="48" stroke="#fff" strokeWidth="1" fill="none"/>
          </svg>

          <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', gap: 10 }}>
            <div style={{ fontSize: 11, fontWeight: 500, opacity: 0.8, letterSpacing: 0.35, textTransform: 'uppercase', whiteSpace: 'nowrap' }}>Portfolio Value</div>
            <div style={{
              display: 'inline-flex', alignItems: 'center', gap: 4, padding: '4px 9px',
              background: 'rgba(255,255,255,0.18)', borderRadius: 999,
              fontSize: 11, fontWeight: 600, backdropFilter: 'blur(4px)',
              whiteSpace: 'nowrap', flex: 'none'
            }}>
              {Icon.arrowUp('#fff')} {gain}% YTD
            </div>
          </div>

          <div style={{ display: 'flex', alignItems: 'baseline', gap: 8, marginTop: 14 }}>
            <span style={{ fontSize: 13, opacity: 0.75, fontWeight: 500 }}>AED</span>
            <span style={{ fontSize: 38, fontWeight: 600, letterSpacing: -1.2, lineHeight: 1, fontFamily: '"Fraunces", Georgia, serif' }}>24,600</span>
          </div>
          <div style={{ fontSize: 12, opacity: 0.8, marginTop: 6, fontWeight: 500 }}>
            +AED {fmt(gainAbs)} this year · across 3 properties
          </div>

          {/* Quick rail */}
          <div style={{ display: 'flex', gap: 10, marginTop: 18 }}>
            <MiniMetric label="Monthly income" value={`AED ${monthly}`} sub="Next payout · 12 days"/>
            <MiniMetric label="Total blocks" value="246" sub="Across 3 assets"/>
          </div>
        </div>
      </div>

      {/* Insights · minimal hints for the investor */}
      <div style={{ padding: '14px 16px 0' }}>
        <div style={{
          display: 'flex', alignItems: 'center', gap: 6,
          fontSize: 10, fontWeight: 600, letterSpacing: 0.4,
          textTransform: 'uppercase', color: T.muted, marginBottom: 8, paddingLeft: 2
        }}>
          {Icon.sparkle(T.primary)} <span>Insights for you</span>
        </div>
        <div style={{ display: 'flex', flexDirection: 'column', gap: 8 }}>
          <div style={{
            background: T.card, border: `1px solid ${T.line}`, borderRadius: 14,
            padding: '12px 12px', display: 'flex', alignItems: 'center', gap: 10
          }}>
            <div style={{
              width: 34, height: 34, borderRadius: 10, flex: 'none',
              background: T.accent, color: T.primary,
              display: 'flex', alignItems: 'center', justifyContent: 'center'
            }}>{Icon.arrowUp(T.primary)}</div>
            <div style={{ flex: 1, minWidth: 0 }}>
              <div style={{ fontSize: 12.5, fontWeight: 600, color: T.ink, lineHeight: 1.3 }}>
                Marina is your top performer
              </div>
              <div style={{ fontSize: 11, color: T.muted, marginTop: 2 }}>
                11.2% yield · +AED 492 YTD · 98% occupied
              </div>
            </div>
          </div>

          <button onClick={onOpenNotif} style={{
            width: '100%', textAlign: 'left',
            background: T.card, border: `1px solid ${T.line}`, borderRadius: 14,
            padding: '12px 12px', display: 'flex', alignItems: 'center', gap: 10,
            cursor: 'pointer', fontFamily: 'inherit'
          }}>
            <div style={{
              width: 34, height: 34, borderRadius: 10, flex: 'none',
              background: '#FFF6E6', color: '#B07D1E',
              display: 'flex', alignItems: 'center', justifyContent: 'center',
              fontSize: 16
            }}>🏠</div>
            <div style={{ flex: 1, minWidth: 0 }}>
              <div style={{ fontSize: 12.5, fontWeight: 600, color: T.ink, lineHeight: 1.3 }}>
                New 10.8% listing just went live
              </div>
              <div style={{ fontSize: 11, color: T.muted, marginTop: 2 }}>
                Palm Vista Studio · 412 blocks available · tap to open
              </div>
            </div>
            <div style={{ color: T.primary }}>{Icon.chevR(T.primary)}</div>
          </button>
        </div>
      </div>

      {/* Your properties */}
      <div style={{ padding: '18px 20px 6px', display: 'flex', alignItems: 'center', justifyContent: 'space-between' }}>
        <div>
          <div style={{ fontSize: 16, color: T.ink, fontWeight: 600, letterSpacing: -0.2 }}>Your properties</div>
          <div style={{ fontSize: 12, color: T.muted, marginTop: 2 }}>Tap to view performance</div>
        </div>
        <div style={{ display: 'flex', gap: 4, alignItems: 'center', color: T.muted, fontSize: 12, fontWeight: 500 }}>
          3 active
        </div>
      </div>

      {/* Property cards */}
      <div style={{ padding: '8px 16px 8px', display: 'flex', flexDirection: 'column', gap: 12 }}>
        {PROPERTIES.map(p => <PropertyCard key={p.id} p={p} T={T} onClick={() => onOpen(p.id)} />)}
      </div>

      {/* Invest More CTA · concept only in prototype */}
      <div style={{
        padding: '18px 16px 0',
      }}>
        <button disabled title="Concept only in this prototype" style={{
          width: '100%', height: 54, borderRadius: 999,
          background: '#EEEBE3', color: '#8C9591',
          border: `1px dashed ${T.line}`,
          fontSize: 15, fontWeight: 600, letterSpacing: 0.1,
          display: 'flex', alignItems: 'center', justifyContent: 'center', gap: 8,
          cursor: 'not-allowed', fontFamily: 'inherit'
        }}>
          <span style={{
            width: 22, height: 22, borderRadius: 22,
            background: 'rgba(0,0,0,0.06)',
            display: 'inline-flex', alignItems: 'center', justifyContent: 'center'
          }}>{Icon.plus('#8C9591')}</span>
          Invest More
          <span style={{
            fontSize: 9.5, fontWeight: 700, letterSpacing: 0.5,
            color: '#8C9591', padding: '2px 6px', borderRadius: 6,
            background: 'rgba(0,0,0,0.05)', marginLeft: 2
          }}>CONCEPT</span>
        </button>
      </div>
    </div>
  );
}

function MiniMetric({ label, value, sub }) {
  return (
    <div style={{
      flex: 1, background: 'rgba(255,255,255,0.1)',
      backdropFilter: 'blur(8px)', borderRadius: 14,
      padding: '10px 12px',
      border: '1px solid rgba(255,255,255,0.14)'
    }}>
      <div style={{ fontSize: 10.5, opacity: 0.75, fontWeight: 500, letterSpacing: 0.3, textTransform: 'uppercase' }}>{label}</div>
      <div style={{ fontSize: 16, fontWeight: 600, marginTop: 3, fontFamily: '"Fraunces", Georgia, serif', letterSpacing: -0.3 }}>{value}</div>
      <div style={{ fontSize: 10.5, opacity: 0.7, marginTop: 2 }}>{sub}</div>
    </div>
  );
}

function PropertyCard({ p, T, onClick }) {
  const gain = ((p.current - p.invested) / p.invested * 100).toFixed(1);
  return (
    <button onClick={onClick} style={{
      width: '100%', background: T.card, border: `1px solid ${T.line}`,
      borderRadius: 18, padding: 12, display: 'flex', gap: 12,
      textAlign: 'left', cursor: 'pointer',
      boxShadow: '0 1px 2px rgba(11,21,18,0.02), 0 8px 20px -16px rgba(11,21,18,0.12)'
    }}>
      {/* photo */}
      <div style={{
        width: 84, height: 100, borderRadius: 12, flex: 'none',
        background: p.img, position: 'relative', overflow: 'hidden',
        display: 'flex', alignItems: 'flex-end', justifyContent: 'center'
      }}>
        <PropertyGlyph kind={p.glyph} size={68} />
        <div style={{
          position: 'absolute', left: 5, top: 5,
          background: 'rgba(255,255,255,0.9)', borderRadius: 5,
          padding: '2px 5px', fontSize: 8.5, fontWeight: 600, color: T.ink,
          letterSpacing: 0.2
        }}>{p.blocks} BLOCKS</div>
      </div>

      {/* body */}
      <div style={{ flex: 1, minWidth: 0, display: 'flex', flexDirection: 'column' }}>
        <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'flex-start', gap: 6 }}>
          <div style={{ minWidth: 0, flex: 1 }}>
            <div style={{ fontSize: 13.5, fontWeight: 600, color: T.ink, letterSpacing: -0.2, lineHeight: 1.25 }}>
              {p.name}
            </div>
            <div style={{ fontSize: 11, color: T.muted, marginTop: 3, display: 'flex', alignItems: 'center', gap: 3 }}>
              {Icon.pin(T.muted)} {p.area} · {p.type}
            </div>
          </div>
          <Pill tone={p.occupied ? 'good' : 'warn'} style={{ flex: 'none' }}>
            <Dot color={p.occupied ? T.primary : '#C18C2F'} size={5}/>
            {p.occupied ? 'Occupied' : 'Vacant'}
          </Pill>
        </div>

        <div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr 1fr', gap: 6, marginTop: 10 }}>
          <Stat label="Invested" value={`AED ${fmt(p.invested)}`} T={T}/>
          <Stat label="Current" value={`AED ${fmt(p.current)}`} T={T} trend={`+${gain}%`}/>
          <Stat label="Monthly" value={`AED ${p.monthly}`} T={T} sub={`${p.yield}% yield`} yieldTone/>
        </div>
      </div>
    </button>
  );
}

function Stat({ label, value, sub, trend, T, yieldTone }) {
  return (
    <div>
      <div style={{ fontSize: 9.5, color: T.muted, fontWeight: 500, letterSpacing: 0.3, textTransform: 'uppercase' }}>{label}</div>
      <div style={{ fontSize: 12.5, color: T.ink, fontWeight: 600, marginTop: 2, letterSpacing: -0.1 }}>{value}</div>
      {trend && <div style={{ fontSize: 10, color: T.primary, fontWeight: 600, marginTop: 1 }}>{trend}</div>}
      {sub && <div style={{ fontSize: 10, color: yieldTone ? T.primary : T.muted, fontWeight: 600, marginTop: 1 }}>{sub}</div>}
    </div>
  );
}

// ─────────────────────────────────────────────
// Screen 2 · Property Detail
// ─────────────────────────────────────────────
function DetailScreen({ T, property, onBack }) {
  const p = property;
  const gain = ((p.current - p.invested) / p.invested * 100).toFixed(1);
  const [range, setRange] = useState('6M');

  return (
    <div data-screen-label="02 Property Detail" style={{ background: T.bg, minHeight: '100%', paddingBottom: 24 }}>
      {/* Hero with photo */}
      <div style={{
        height: 300, background: p.img, position: 'relative', overflow: 'hidden'
      }}>
        {/* ambient glyph */}
        <div style={{ position: 'absolute', inset: 0, display: 'flex', alignItems: 'center', justifyContent: 'center' }}>
          <PropertyGlyph kind={p.glyph} size={180} color="rgba(255,255,255,0.22)"/>
        </div>
        <div style={{
          position: 'absolute', inset: 0,
          background: 'linear-gradient(180deg, rgba(0,0,0,0) 40%, rgba(0,0,0,0.35) 100%)'
        }}/>
        {/* back */}
        <button onClick={onBack} style={{
          position: 'absolute', top: 60, left: 16,
          width: 38, height: 38, borderRadius: 12,
          background: 'rgba(255,255,255,0.9)', backdropFilter: 'blur(8px)',
          border: 'none', display: 'flex', alignItems: 'center', justifyContent: 'center',
          color: T.ink, cursor: 'pointer', zIndex: 5
        }}>{Icon.chevL()}</button>
        <div style={{ position: 'absolute', top: 64, right: 16, display: 'flex', gap: 8, zIndex: 5 }}>
          <Pill tone="good" style={{ background: 'rgba(255,255,255,0.9)', backdropFilter: 'blur(8px)' }}>
            <Dot color={T.primary} size={5}/> Occupied
          </Pill>
        </div>

        {/* title */}
        <div style={{ position: 'absolute', left: 20, right: 20, bottom: 16, color: '#fff' }}>
          <div style={{ fontSize: 11, opacity: 0.9, fontWeight: 500, letterSpacing: 0.4, textTransform: 'uppercase' }}>
            {p.area} · {p.type}
          </div>
          <div style={{ fontSize: 22, fontWeight: 600, marginTop: 4, letterSpacing: -0.4, fontFamily: '"Fraunces", Georgia, serif' }}>
            {p.name}
          </div>
        </div>
      </div>

      {/* Your position card (floats over hero edge) */}
      <div style={{ padding: '12px 16px 0', marginTop: -22 }}>
        <div style={{
          background: T.card, borderRadius: 18, border: `1px solid ${T.line}`,
          padding: '14px 16px',
          boxShadow: '0 16px 30px -22px rgba(11,21,18,0.25)'
        }}>
          <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'flex-end' }}>
            <div>
              <div style={{ fontSize: 10.5, color: T.muted, fontWeight: 500, letterSpacing: 0.3, textTransform: 'uppercase' }}>Your position</div>
              <div style={{ display: 'flex', alignItems: 'baseline', gap: 6, marginTop: 4 }}>
                <span style={{ fontSize: 11, color: T.muted, fontWeight: 500 }}>AED</span>
                <span style={{ fontSize: 26, fontWeight: 600, color: T.ink, letterSpacing: -0.6, fontFamily: '"Fraunces", Georgia, serif' }}>{fmt(p.current)}</span>
              </div>
              <div style={{ fontSize: 11, color: T.primary, fontWeight: 600, marginTop: 3, display: 'flex', alignItems: 'center', gap: 3 }}>
                {Icon.arrowUp(T.primary)} +AED {fmt(p.current - p.invested)} (+{gain}%)
              </div>
            </div>
            <div style={{ textAlign: 'right' }}>
              <div style={{ fontSize: 10.5, color: T.muted, fontWeight: 500, letterSpacing: 0.3, textTransform: 'uppercase' }}>Invested</div>
              <div style={{ fontSize: 15, color: T.ink, fontWeight: 600, marginTop: 4 }}>AED {fmt(p.invested)}</div>
              <div style={{ fontSize: 11, color: T.muted, marginTop: 2 }}>{p.blocks} blocks · {p.acquired}</div>
            </div>
          </div>
        </div>
      </div>

      {/* Performance chart */}
      <div style={{ padding: '18px 16px 0' }}>
        <div style={{ background: T.card, borderRadius: 18, border: `1px solid ${T.line}`, padding: 16 }}>
          <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center' }}>
            <div>
              <div style={{ fontSize: 14, fontWeight: 600, color: T.ink, letterSpacing: -0.2 }}>Performance</div>
              <div style={{ fontSize: 11, color: T.muted, marginTop: 2 }}>Value over time</div>
            </div>
            <div style={{ display: 'flex', background: '#F4F2EE', borderRadius: 8, padding: 2 }}>
              {['1M','3M','6M','1Y'].map(r => (
                <button key={r} onClick={() => setRange(r)} style={{
                  height: 26, padding: '0 10px', border: 'none',
                  background: range === r ? T.card : 'transparent',
                  color: range === r ? T.ink : T.muted,
                  fontSize: 11, fontWeight: 600, borderRadius: 7, cursor: 'pointer',
                  boxShadow: range === r ? '0 1px 2px rgba(0,0,0,0.06)' : 'none'
                }}>{r}</button>
              ))}
            </div>
          </div>
          <PerformanceChart data={p.history6m} T={T}/>
        </div>
      </div>

      {/* Key stats */}
      <div style={{ padding: '14px 16px 0', display: 'grid', gridTemplateColumns: '1fr 1fr 1fr', gap: 10 }}>
        <StatCard T={T} label="Occupancy" value={`${p.occupancy}%`} detail="Last 12 mo"/>
        <StatCard T={T} label="Gross yield" value={`${p.yield}%`} detail="Annualized" emph/>
        <StatCard T={T} label="Below market" value={`${p.belowMarket}%`} detail="At acquisition"/>
      </div>

      {/* Rental income history */}
      <div style={{ padding: '18px 16px 0' }}>
        <div style={{ background: T.card, borderRadius: 18, border: `1px solid ${T.line}`, padding: '14px 4px 6px' }}>
          <div style={{ padding: '0 12px 10px', display: 'flex', justifyContent: 'space-between', alignItems: 'center' }}>
            <div>
              <div style={{ fontSize: 14, fontWeight: 600, color: T.ink, letterSpacing: -0.2 }}>Rental income</div>
              <div style={{ fontSize: 11, color: T.muted, marginTop: 2 }}>Last 3 payouts</div>
            </div>
            <div title="Concept only in this prototype" style={{ fontSize: 11, color: '#9CA5A1', fontWeight: 600, display: 'flex', alignItems: 'center', gap: 3 }}>
              View all {Icon.chevR('#9CA5A1')}
            </div>
          </div>
          {p.rental3m.map((r, i) => (
            <div key={i} style={{
              display: 'flex', alignItems: 'center', gap: 12,
              padding: '11px 12px',
              borderTop: i === 0 ? `1px solid ${T.line}` : 'none'
            }}>
              <div style={{
                width: 34, height: 34, borderRadius: 10,
                background: T.accent, color: T.primary,
                display: 'flex', alignItems: 'center', justifyContent: 'center',
                fontWeight: 600, fontSize: 11
              }}>
                {r.m.split(' ')[0].slice(0,3).toUpperCase()}
              </div>
              <div style={{ flex: 1, minWidth: 0 }}>
                <div style={{ fontSize: 13, fontWeight: 600, color: T.ink }}>Rent payout</div>
                <div style={{ fontSize: 11, color: T.muted, marginTop: 1 }}>{r.m} · {r.tenant}</div>
              </div>
              <div style={{ textAlign: 'right' }}>
                <div style={{ fontSize: 13, fontWeight: 600, color: T.primary }}>+AED {r.amt}</div>
                <div style={{ fontSize: 10.5, color: T.muted, marginTop: 1 }}>Paid</div>
              </div>
            </div>
          ))}
          {/* next payout row */}
          <div style={{ display: 'flex', alignItems: 'center', gap: 12, padding: '11px 12px', borderTop: `1px solid ${T.line}` }}>
            <div style={{
              width: 34, height: 34, borderRadius: 10,
              background: '#F4F2EE', color: T.muted,
              display: 'flex', alignItems: 'center', justifyContent: 'center',
              fontWeight: 600, fontSize: 11, border: `1px dashed ${T.line}`
            }}>APR</div>
            <div style={{ flex: 1 }}>
              <div style={{ fontSize: 13, fontWeight: 600, color: T.ink }}>Next payout</div>
              <div style={{ fontSize: 11, color: T.muted, marginTop: 1 }}>Apr 2026 · Scheduled in 12 days</div>
            </div>
            <div style={{ textAlign: 'right' }}>
              <div style={{ fontSize: 13, fontWeight: 600, color: T.muted }}>AED {p.monthly}</div>
            </div>
          </div>
        </div>
      </div>

      {/* Action buttons · concept only in this prototype */}
      <div style={{
        padding: '20px 16px 90px',
        display: 'flex', gap: 10
      }}>
        <button disabled title="Concept only in this prototype" style={{
          flex: 1, height: 52, borderRadius: 999,
          background: '#EEEBE3', color: '#8C9591',
          border: `1px dashed ${T.line}`,
          fontSize: 13.5, fontWeight: 600, cursor: 'not-allowed',
          fontFamily: 'inherit'
        }}>Sell Blocks</button>
        <button disabled title="Concept only in this prototype" style={{
          flex: 1.3, height: 52, borderRadius: 999,
          background: '#EEEBE3', color: '#8C9591',
          border: `1px dashed ${T.line}`,
          fontSize: 13.5, fontWeight: 600, cursor: 'not-allowed',
          fontFamily: 'inherit',
          display: 'flex', alignItems: 'center', justifyContent: 'center', gap: 6
        }}>
          {Icon.plus('#8C9591')} Invest More
        </button>
      </div>
    </div>
  );
}

function StatCard({ label, value, detail, T, emph }) {
  return (
    <div style={{
      background: emph ? T.accent : T.card,
      borderRadius: 14,
      border: `1px solid ${emph ? 'transparent' : T.line}`,
      padding: '12px 12px'
    }}>
      <div style={{ fontSize: 10, color: T.muted, fontWeight: 500, letterSpacing: 0.3, textTransform: 'uppercase' }}>{label}</div>
      <div style={{
        fontSize: 18, fontWeight: 600, color: emph ? T.primary : T.ink,
        marginTop: 4, letterSpacing: -0.4, fontFamily: '"Fraunces", Georgia, serif'
      }}>{value}</div>
      <div style={{ fontSize: 10.5, color: T.muted, marginTop: 2 }}>{detail}</div>
    </div>
  );
}

function PerformanceChart({ data, T }) {
  const W = 308, H = 140, pad = 8;
  const min = Math.min(...data) * 0.98;
  const max = Math.max(...data) * 1.02;
  const stepX = (W - pad * 2) / (data.length - 1);
  const points = data.map((v, i) => {
    const x = pad + i * stepX;
    const y = pad + (1 - (v - min) / (max - min)) * (H - pad * 2);
    return [x, y];
  });
  const pathD = points.map((pt, i) => (i === 0 ? 'M' : 'L') + pt[0].toFixed(1) + ' ' + pt[1].toFixed(1)).join(' ');
  const areaD = pathD + ` L${(W - pad).toFixed(1)} ${(H - pad).toFixed(1)} L${pad} ${(H - pad).toFixed(1)} Z`;
  const months = ['OCT','NOV','DEC','JAN','FEB','MAR'];
  const lastPt = points[points.length - 1];

  return (
    <div style={{ marginTop: 14 }}>
      <svg width="100%" viewBox={`0 0 ${W} ${H + 22}`} style={{ display: 'block' }}>
        <defs>
          <linearGradient id="chartFill" x1="0" y1="0" x2="0" y2="1">
            <stop offset="0%" stopColor={T.primary} stopOpacity="0.18"/>
            <stop offset="100%" stopColor={T.primary} stopOpacity="0"/>
          </linearGradient>
        </defs>
        {/* gridlines */}
        {[0.25, 0.5, 0.75].map((f, i) => (
          <line key={i} x1={pad} x2={W - pad} y1={pad + f * (H - pad * 2)} y2={pad + f * (H - pad * 2)} stroke={T.line} strokeDasharray="2 3"/>
        ))}
        <path d={areaD} fill="url(#chartFill)"/>
        <path d={pathD} fill="none" stroke={T.primary} strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"/>
        {/* points */}
        {points.map((pt, i) => (
          <circle key={i} cx={pt[0]} cy={pt[1]} r={i === points.length - 1 ? 4 : 0} fill={T.primary}/>
        ))}
        {points.length > 0 && (
          <circle cx={lastPt[0]} cy={lastPt[1]} r="7" fill={T.primary} fillOpacity="0.18"/>
        )}
        {/* month labels */}
        {months.map((m, i) => (
          <text key={m} x={pad + i * stepX} y={H + 14} textAnchor="middle" fontSize="9.5" fill={T.muted} fontFamily="Inter, system-ui" fontWeight="500">{m}</text>
        ))}
      </svg>
    </div>
  );
}

// ─────────────────────────────────────────────
// Tab bar
// ─────────────────────────────────────────────
function TabBar({ T, active, onChange }) {
  const tabs = [
    { id: 'portfolio', label: 'Portfolio', icon: Icon.home },
    { id: 'explore', label: 'Explore', icon: Icon.explore },
    { id: 'wallet', label: 'Wallet', icon: Icon.wallet },
    { id: 'profile', label: 'Profile', icon: Icon.profile },
  ];
  return (
    <div style={{
      position: 'absolute', left: 0, right: 0, bottom: 0,
      background: 'rgba(255,255,255,0.92)',
      backdropFilter: 'blur(20px)',
      borderTop: `1px solid ${T.line}`,
      paddingBottom: 22, paddingTop: 10,
      display: 'flex', justifyContent: 'space-around',
      zIndex: 8
    }}>
      {tabs.map(t => {
        const isActive = active === t.id;
        const dead = t.id !== 'portfolio';
        return (
          <button key={t.id} onClick={() => onChange(t.id)}
            title={dead ? 'Concept only in this prototype' : undefined}
            style={{
              border: 'none', background: 'transparent',
              cursor: dead ? 'not-allowed' : 'pointer',
              display: 'flex', flexDirection: 'column', alignItems: 'center', gap: 3,
              color: isActive ? T.primary : (dead ? '#BEC4C1' : T.muted),
              padding: '4px 12px', opacity: dead && !isActive ? 0.7 : 1,
              fontFamily: 'inherit'
            }}>
            {t.icon(isActive ? T.primary : (dead ? '#BEC4C1' : T.muted))}
            <span style={{ fontSize: 10, fontWeight: 600, letterSpacing: 0.2 }}>{t.label}</span>
          </button>
        );
      })}
    </div>
  );
}

// ─────────────────────────────────────────────
// Notification overlay
// ─────────────────────────────────────────────
function NotifBanner({ T, show, onClose, onInvest }) {
  return (
    <div style={{
      position: 'absolute', left: 0, right: 0, top: 0,
      pointerEvents: show ? 'auto' : 'none',
      zIndex: 30, padding: '12px'
    }}>
      <div style={{
        transform: show ? 'translateY(0)' : 'translateY(-120%)',
        opacity: show ? 1 : 0,
        transition: 'all 420ms cubic-bezier(.2,.8,.2,1)'
      }}>
        <div style={{
          background: 'rgba(20,28,26,0.78)',
          backdropFilter: 'blur(24px) saturate(180%)',
          WebkitBackdropFilter: 'blur(24px) saturate(180%)',
          borderRadius: 20,
          border: '1px solid rgba(255,255,255,0.08)',
          boxShadow: '0 20px 40px -20px rgba(0,0,0,0.45)',
          padding: '12px 12px 14px',
          color: '#fff'
        }}>
          <div style={{ display: 'flex', alignItems: 'center', gap: 10, paddingBottom: 8 }}>
            <div style={{
              width: 26, height: 26, borderRadius: 7,
              background: T.primary, color: '#fff',
              display: 'flex', alignItems: 'center', justifyContent: 'center',
              fontSize: 11, fontWeight: 700
            }}>P</div>
            <div style={{ flex: 1, display: 'flex', flexDirection: 'column' }}>
              <div style={{ fontSize: 11.5, fontWeight: 600, opacity: 0.95 }}>PRYPCO</div>
            </div>
            <div style={{ fontSize: 10.5, opacity: 0.55 }}>now</div>
            <button onClick={onClose} style={{
              width: 22, height: 22, borderRadius: 11,
              background: 'rgba(255,255,255,0.12)', border: 'none',
              color: '#fff', cursor: 'pointer',
              display: 'flex', alignItems: 'center', justifyContent: 'center'
            }}>{Icon.close('#fff')}</button>
          </div>
          <div style={{ fontSize: 13.5, fontWeight: 600, letterSpacing: -0.1, marginBottom: 4 }}>
            Your Marina property earned AED 186 this month 🏠
          </div>
          <div style={{ fontSize: 12.5, opacity: 0.85, lineHeight: 1.45 }}>
            A new property just listed at <span style={{ color: '#7FD4B3', fontWeight: 700 }}>10.8% yield</span>. Invest now before it fills.
          </div>

          {/* In-banner listing preview */}
          <div style={{
            marginTop: 10, padding: 10, borderRadius: 12,
            background: 'rgba(255,255,255,0.08)',
            display: 'flex', alignItems: 'center', gap: 10
          }}>
            <div style={{
              width: 42, height: 42, borderRadius: 9, flex: 'none',
              background: 'linear-gradient(135deg,#1B3A4B,#2E6B82)',
              display: 'flex', alignItems: 'center', justifyContent: 'center'
            }}>
              <PropertyGlyph kind="marina" size={34} color="rgba(255,255,255,0.55)"/>
            </div>
            <div style={{ flex: 1, minWidth: 0 }}>
              <div style={{ fontSize: 12, fontWeight: 600 }}>Palm Vista · Studio</div>
              <div style={{ fontSize: 10.5, opacity: 0.7, marginTop: 1 }}>Palm Jumeirah · 412 blocks available</div>
            </div>
            <div style={{ textAlign: 'right' }}>
              <div style={{ fontSize: 14, fontWeight: 700, color: '#7FD4B3', fontFamily: '"Fraunces", Georgia, serif' }}>10.8%</div>
              <div style={{ fontSize: 9.5, opacity: 0.65 }}>yield</div>
            </div>
          </div>

          <div style={{ display: 'flex', gap: 8, marginTop: 10 }}>
            <button onClick={onClose} style={{
              flex: 1, height: 36, borderRadius: 10, border: 'none',
              background: 'rgba(255,255,255,0.12)', color: '#fff',
              fontSize: 12, fontWeight: 600, cursor: 'pointer'
            }}>Later</button>
            <button onClick={onInvest} style={{
              flex: 1.3, height: 36, borderRadius: 10, border: 'none',
              background: '#fff', color: T.ink,
              fontSize: 12, fontWeight: 700, cursor: 'pointer',
              display: 'flex', alignItems: 'center', justifyContent: 'center', gap: 5
            }}>
              {Icon.sparkle(T.primary)} Invest now
            </button>
          </div>
        </div>
      </div>
    </div>
  );
}

// ─────────────────────────────────────────────
// Tweaks panel
// ─────────────────────────────────────────────
function TweaksPanel({ T, visible, onChange, onClose, tweaks }) {
  if (!visible) return null;
  return (
    <div style={{
      position: 'fixed', right: 20, bottom: 20, width: 260,
      background: 'rgba(20,25,24,0.94)', color: '#fff',
      borderRadius: 14, padding: 14, zIndex: 1000,
      fontFamily: 'Inter, system-ui', fontSize: 12,
      boxShadow: '0 30px 60px -10px rgba(0,0,0,0.4)',
      border: '1px solid rgba(255,255,255,0.08)'
    }}>
      <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: 10 }}>
        <div style={{ fontWeight: 700, letterSpacing: 0.2 }}>Tweaks</div>
        <button onClick={onClose} style={{
          background: 'rgba(255,255,255,0.1)', border: 'none', color: '#fff',
          width: 22, height: 22, borderRadius: 11, cursor: 'pointer'
        }}>×</button>
      </div>
      <div style={{ fontSize: 10.5, opacity: 0.6, marginBottom: 6, textTransform: 'uppercase', letterSpacing: 0.4 }}>Primary color</div>
      <div style={{ display: 'flex', gap: 6, marginBottom: 12 }}>
        {[
          ['#0F6E56', '#0A4A3A'],
          ['#134E4A', '#0B3331'],
          ['#0B3D2E', '#072A1F'],
          ['#1E5AA8', '#143E76'],
          ['#111111', '#000000'],
        ].map(([p, d]) => (
          <button key={p} onClick={() => onChange({ primary: p, primaryInk: d, accent: hexToAccent(p) })} style={{
            width: 30, height: 30, borderRadius: 8, border: tweaks.primary === p ? '2px solid #fff' : '1px solid rgba(255,255,255,0.15)',
            background: p, cursor: 'pointer'
          }}/>
        ))}
      </div>
      <div style={{ fontSize: 10.5, opacity: 0.6, marginBottom: 6, textTransform: 'uppercase', letterSpacing: 0.4 }}>Background</div>
      <div style={{ display: 'flex', gap: 6 }}>
        {[
          ['Warm', '#FBFBF9'],
          ['Cool', '#F6F8F7'],
          ['Pure', '#FFFFFF'],
          ['Sand', '#F6F3EC'],
        ].map(([label, bg]) => (
          <button key={bg} onClick={() => onChange({ bg })} style={{
            flex: 1, height: 34, borderRadius: 8,
            background: bg, color: '#111',
            border: tweaks.bg === bg ? '2px solid #fff' : '1px solid rgba(255,255,255,0.15)',
            fontSize: 10.5, fontWeight: 600, cursor: 'pointer'
          }}>{label}</button>
        ))}
      </div>
    </div>
  );
}

function hexToAccent(hex) {
  // super-simple tinted accent
  const map = {
    '#0F6E56': '#E8F3EF',
    '#134E4A': '#E4EFED',
    '#0B3D2E': '#E3EBE7',
    '#1E5AA8': '#E6ECF5',
    '#111111': '#F1F1F0',
  };
  return map[hex] || '#E8F3EF';
}

// ─────────────────────────────────────────────
// App
// ─────────────────────────────────────────────
function App() {
  const [tweaks, setTweaks] = useState(PRYPCO_DEFAULTS);
  const [tweaksVisible, setTweaksVisible] = useState(false);
  const [screen, setScreen] = useState('portfolio'); // portfolio | detail
  const [propertyId, setPropertyId] = useState('marina');
  const [activeTab, setActiveTab] = useState('portfolio');
  const [notif, setNotif] = useState(false);

  const T = tweaks;
  const currentProperty = PROPERTIES.find(p => p.id === propertyId);

  // edit-mode protocol
  useEffect(() => {
    const handler = (e) => {
      const d = e.data || {};
      if (d.type === '__activate_edit_mode') setTweaksVisible(true);
      if (d.type === '__deactivate_edit_mode') setTweaksVisible(false);
    };
    window.addEventListener('message', handler);
    window.parent.postMessage({ type: '__edit_mode_available' }, '*');
    return () => window.removeEventListener('message', handler);
  }, []);

  // Do NOT auto-open the notification · user triggers via bell icon
  // (still surfaced prominently: bell has a red dot badge)

  const changeTweaks = (patch) => {
    const next = { ...tweaks, ...patch };
    setTweaks(next);
    window.parent.postMessage({ type: '__edit_mode_set_keys', edits: patch }, '*');
  };

  const openDetail = (id) => {
    setPropertyId(id);
    setScreen('detail');
  };

  const onInvestFromNotif = () => {
    setNotif(false);
    // Navigate to Marina detail
    setPropertyId('marina');
    setScreen('detail');
  };

  return (
    <div style={{ width: '100%', height: '100%', background: T.bg, position: 'relative', overflow: 'hidden', fontFamily: 'Inter, system-ui, -apple-system' }}>
      {/* Screen stack */}
      <div style={{ position: 'absolute', inset: 0, overflow: 'auto', WebkitOverflowScrolling: 'touch' }}>
        <div style={{
          display: 'flex',
          width: '200%',
          transform: screen === 'detail' ? 'translateX(-50%)' : 'translateX(0)',
          transition: 'transform 380ms cubic-bezier(.2,.8,.2,1)'
        }}>
          <div style={{ width: '50%', minHeight: '100%' }}>
            <PortfolioScreen T={T} onOpen={openDetail} onOpenNotif={() => setNotif(true)}/>
          </div>
          <div style={{ width: '50%', minHeight: '100%' }}>
            <DetailScreen T={T} property={currentProperty} onBack={() => setScreen('portfolio')}/>
          </div>
        </div>
      </div>

      {/* Tab bar · only Portfolio is wired in this prototype */}
      <TabBar T={T} active={activeTab} onChange={(id) => {
        if (id !== 'portfolio') return;
        setActiveTab(id);
        setScreen('portfolio');
      }}/>

      {/* Notification */}
      <NotifBanner T={T} show={notif} onClose={() => setNotif(false)} onInvest={onInvestFromNotif}/>

      {/* Floating notif replay button (subtle) */}
      {!notif && (
        <button onClick={() => setNotif(true)} style={{
          position: 'absolute', top: 14, right: 70,
          background: 'transparent', border: 'none', cursor: 'pointer',
          fontSize: 0
        }}/>
      )}

      {/* Tweaks */}
      <TweaksPanel T={T} visible={tweaksVisible} tweaks={tweaks}
        onChange={changeTweaks} onClose={() => setTweaksVisible(false)}/>
    </div>
  );
}

window.PrypcoApp = App;
