/* ===== FIRE simulator — accumulation + post-FIRE drawdown ===== */
function ScreenFire() {
  const [mode, setMode] = React.useState('acc');
  // shared assumptions
  const [corpus, setCorpus] = React.useState(7900000);
  const [monthly, setMonthly] = React.useState(85000);
  const [ret, setRet] = React.useState(11);
  const [infl, setInfl] = React.useState(6);
  const [swr, setSwr] = React.useState(3.2);
  const [exp, setExp] = React.useState(TRACKED_ANNUAL);
  const [fireType, setFireType] = React.useState('regular');
  // drawdown-only
  const [fireCorpus, setFireCorpus] = React.useState(35000000);
  const [retireAge, setRetireAge] = React.useState(45);
  const [endAge, setEndAge] = React.useState(95);

  const shared = { ret, setRet, infl, setInfl, exp, setExp };

  return (
    <div className="scroll" style={{ padding:'4px 16px 96px' }}>
      <div style={{ padding:'14px 2px 12px' }}>
        <div className="eyebrow">FIRE simulator</div>
      </div>

      {/* mode toggle */}
      <div className="seg" style={{ marginBottom:16 }}>
        <button className={mode==='acc'?'on':''} onClick={()=>setMode('acc')}>
          <Icon name="arrowUp" size={15} color={mode==='acc'?'#1a1407':'var(--dim)'}/> Journey to FI
        </button>
        <button className={mode==='draw'?'on':''} onClick={()=>setMode('draw')}>
          <Icon name="shield" size={15} color={mode==='draw'?'#1a1407':'var(--dim)'}/> Life after FI
        </button>
      </div>

      {mode==='acc'
        ? <AccView {...shared} corpus={corpus} setCorpus={setCorpus} monthly={monthly} setMonthly={setMonthly} swr={swr} setSwr={setSwr} fireType={fireType} setFireType={setFireType}/>
        : <DrawView {...shared} fireCorpus={fireCorpus} setFireCorpus={setFireCorpus}
            retireAge={retireAge} setRetireAge={setRetireAge} endAge={endAge} setEndAge={setEndAge} swr={swr}/>}
    </div>
  );
}

/* ---------- accumulation ---------- */
function AccView({ corpus, setCorpus, monthly, setMonthly, ret, setRet, infl, setInfl, swr, setSwr, exp, setExp, fireType, setFireType }) {
  const realReturn = (1+ret/100)/(1+infl/100)-1;
  const tt = fireTypeTarget(fireType, exp, swr, realReturn, USER.age);
  const r = fireProject({ corpus, monthly, returnPct:ret, inflationPct:infl, swrPct:swr, annualExpense:exp, targetCorpus:tt.target });
  const fiAge = USER.age + r.years;
  const succColor = r.success >= 80 ? 'var(--green)' : r.success >= 55 ? 'var(--gold)' : 'var(--red)';
  const t = tt.t;
  const pickType = (id) => {
    setFireType(id);
    setExp(Math.round(TRACKED_ANNUAL * fireTypeById(id).mult / 20000) * 20000);
  };
  return (
    <div className="fade-soft">
      <div className="card" style={{ padding:'20px 18px 16px', position:'relative', overflow:'hidden',
        background:'linear-gradient(160deg,#1a1d20,#121417 75%)' }}>
        <div style={{ position:'absolute', right:-50, top:-40, width:150, height:150, borderRadius:'50%', background:'var(--gold-glow)', filter:'blur(6px)' }}/>
        <div className="row" style={{ justifyContent:'space-between', alignItems:'flex-start' }}>
          <div>
            <div style={{ fontSize:13, color:'var(--dim)' }}>{t.coast ? 'Coast point reached in' : t.label+' FIRE in'}</div>
            <div className="serif" style={{ fontSize:42, lineHeight:1, marginTop:6 }}>
              {r.reached ? <>{r.years} <span style={{ fontSize:22, color:'var(--dim)' }}>years</span></> : <span style={{ fontSize:26, color:'var(--red)' }}>Not on track</span>}
            </div>
            {r.reached && <div style={{ fontSize:13, color:'var(--gold-bright)', marginTop:8, fontWeight:600 }}>
              {t.coast ? `stop investing at ${fiAge} · FI by 60` : `at age ${fiAge} · year ${2026 + r.years}`}
            </div>}
          </div>
          <div style={{ textAlign:'center' }}>
            <Ring pct={r.success/100} size={72} stroke={7} color={succColor}>
              <div className="serif tnum" style={{ fontSize:18, color:succColor }}>{r.success}%</div>
            </Ring>
            <div className="eyebrow" style={{ fontSize:8, marginTop:6 }}>success</div>
          </div>
        </div>
        <div style={{ marginTop:18 }}>
          <ProjectionChart series={r.series} fiNumber={tt.target} years={r.years} w={300} label={t.coast?'Coast':'FI'}/>
          <div className="row" style={{ justifyContent:'space-between', marginTop:6 }}>
            <span style={{ fontSize:10, color:'var(--faint)' }} className="mono">2026</span>
            <span style={{ fontSize:10, color:'var(--faint)' }} className="mono">+{r.years} yrs · {2026+r.years}</span>
          </div>
        </div>
      </div>

      {/* which FIRE? — target from tracked spend, editable */}
      <div className="card" style={{ padding:16, marginTop:14 }}>
        <div className="row" style={{ justifyContent:'space-between', marginBottom:13 }}>
          <div style={{ fontSize:14.5, fontWeight:700 }}>Which kind of FIRE?</div>
          <span style={{ fontSize:10.5, color:'var(--faint)' }} className="mono">from ₹{Math.round(TRACKED_MONTHLY/1000)}k/mo tracked</span>
        </div>
        <div style={{ display:'flex', gap:8, overflowX:'auto', margin:'0 -16px', padding:'0 16px 4px' }} className="scroll">
          {FIRE_TYPES.map(ft=>(
            <button key={ft.id} className={'chip'+(ft.id===fireType?' on':'')} onClick={()=>pickType(ft.id)}>{ft.label}</button>
          ))}
        </div>
        <div style={{ fontSize:11.5, color:'var(--dim)', margin:'12px 0 14px', lineHeight:1.45 }}>{t.blurb}</div>
        <div style={{ display:'flex', alignItems:'flex-end', justifyContent:'space-between', gap:12, padding:'13px 14px', borderRadius:14, background:'var(--bg)', border:'1px solid var(--line)' }}>
          <div>
            <div className="eyebrow" style={{ marginBottom:6 }}>{t.coast ? 'Coast target now' : 'Your FI number'}</div>
            <div className="serif tnum" style={{ fontSize:26, color:'var(--gold-bright)', whiteSpace:'nowrap' }}>{fmtINR(tt.target,2)}</div>
          </div>
          <div style={{ textAlign:'right', fontSize:10.5, color:'var(--faint)', lineHeight:1.5 }} className="mono">
            {t.coast
              ? <>compounds to<br/>{fmtINR(tt.fiNumber,1)} by 60</>
              : t.baristaIncome
                ? <>covers {fmtINR(tt.covered,1)}/yr<br/>+{fmtINR(t.baristaIncome,1)} part-time</>
                : <>{swr}% of<br/>{fmtINR(exp,1)}/yr</>}
          </div>
        </div>
      </div>

      <SectionAssumptions title="Your assumptions"
        summary={`${fmtINR(corpus,1)} corpus · ${fmtINR(monthly,1)}/mo · ${ret}% return · ${swr}% SWR`}>
        <Slider label="Current corpus" value={corpus} min={1000000} max={30000000} step={100000} fmt={v=>fmtINR(v,2)} onChange={setCorpus}/>
        <Slider label="Monthly investment" value={monthly} min={10000} max={300000} step={5000} fmt={v=>fmtINR(v,1)+'/mo'} onChange={setMonthly}/>
        <Slider label="Yearly spend in retirement" value={exp} min={300000} max={4000000} step={20000} fmt={v=>fmtINR(v,1)+'/yr'} onChange={setExp} hint={`≈ ${fmtINR(exp/12,0)}/mo · edit to set your FI number`}/>
        <Slider label="Expected return" value={ret} min={6} max={15} step={0.5} fmt={v=>v+'%'} onChange={setRet} hint="Nifty 50 long-run ≈ 11%"/>
        <Slider label="Inflation" value={infl} min={3} max={10} step={0.5} fmt={v=>v+'%'} onChange={setInfl}/>
        <Slider label="Safe withdrawal rate" value={swr} min={2.6} max={4} step={0.1} fmt={v=>v+'%'} onChange={setSwr} last/>
      </SectionAssumptions>

      <InfoNote>
        For India, research suggests a <b style={{ color:'var(--text)' }}>3.0–3.5%</b> withdrawal rate rather than the US 4% rule.
        <span style={{ color:'var(--faint)' }}> — Raju &amp; Saraogi (2024), Safe Withdrawal Rates in the Indian Context.</span>
      </InfoNote>

      <FIOptimise/>
    </div>
  );
}

/* ---------- optimise your FI ---------- */
function FIOptimise() {
  return (
    <div style={{ marginTop:6 }}>
      <SectionTitle>Optimise your FI</SectionTitle>
      <OptCard icon="tax" iconColor="var(--gold)" title="Tax regime check" amount={fmtINR(taxScenarios().npsSaving,0)} amountSub="/yr saved">
        <div style={{ fontSize:11.5, color:'var(--dim)', lineHeight:1.5, marginBottom:4 }}>
          You’re on the <b style={{ color:'var(--text)' }}>new regime</b> (now default) — 80C, 80D &amp; 80CCD(1B) give zero benefit here.
          But employer <b style={{ color:'var(--text)' }}>NPS via 80CCD(2)</b> (up to 14% of basic) still reduces tax — routing it could save ~{fmtINR(taxScenarios().npsSaving,0)}/yr.
        </div>
        <OptCTA label="Run old vs new comparison" act={{ kind:'tax' }}/>
      </OptCard>
      <OptCard icon="bolt" iconColor="var(--green)" title="Boost your SIP" amount="−3 yrs" amountSub="to FI" amountColor="var(--green)">
        <div style={{ fontSize:11.5, color:'var(--dim)', lineHeight:1.5, marginBottom:12 }}>
          Raising your SIP by <b style={{ color:'var(--text)' }}>₹15,000/mo</b> could pull FI roughly 3 years closer. Even ₹5k/mo trims about a year.
        </div>
        <div className="row" style={{ justifyContent:'space-between', padding:'10px 12px', borderRadius:12, background:'var(--bg)', border:'1px solid var(--line)' }}>
          <span className="tnum" style={{ fontSize:13, color:'var(--dim)' }}>{fmtINR(85000,1)}/mo</span>
          <Icon name="arrowR" size={15} color="var(--green)"/>
          <span className="tnum" style={{ fontSize:13, fontWeight:700, color:'var(--green)' }}>{fmtINR(100000,1)}/mo</span>
        </div>
        <OptCTA label="Model a higher SIP" act={{ title:'Model a higher SIP', body:'Increases your monthly SIP from ₹85,000 to ₹1,00,000 and re-runs the projection. You can fund it from the ₹612/mo of card rewards and recurring leaks we found.', impact:'Pulls FI roughly 3 years closer', cta:'Apply ₹1L/mo SIP', icon:'bolt', color:'var(--green)' }}/>
      </OptCard>
      <OptCard icon="trendDown" iconColor="var(--blue)" title="Trim the FI number" amount={fmtINR(3000000,1)} amountSub="lower target" amountColor="var(--blue)">
        <div style={{ fontSize:11.5, color:'var(--dim)', lineHeight:1.5 }}>
          Cutting <b style={{ color:'var(--text)' }}>₹8,000/mo</b> of recurring spends (subscriptions, unused memberships) lowers your FI number by ~₹30L and pulls FI about 2 years closer.
        </div>
        <OptCTA label="Find recurring leaks" act={{ title:'Find recurring leaks', body:'Scans your SMS-tracked spend for subscriptions, memberships and auto-debits you rarely use — surfacing recurring charges you can cancel to lower your FI number.', impact:'~₹8,000/mo found · FI ₹30L lower', cta:'Review subscriptions', icon:'receipt', color:'var(--blue)' }}/>
      </OptCard>
    </div>
  );
}

/* ---------- post-FIRE drawdown ---------- */
function DrawView({ fireCorpus, setFireCorpus, ret, setRet, infl, setInfl, exp, setExp, retireAge, setRetireAge, endAge, setEndAge, swr }) {
  const d = drawdownProject({ corpus:fireCorpus, annualExpense:exp, returnPct:ret, inflationPct:infl, retireAge, endAge });
  const succColor = d.success >= 80 ? 'var(--green)' : d.success >= 55 ? 'var(--gold)' : 'var(--red)';
  const wrColor = d.wr <= swr ? 'var(--green)' : d.wr <= swr + 0.7 ? 'var(--gold)' : 'var(--red)';
  return (
    <div className="fade-soft">
      <div className="card" style={{ padding:'20px 18px 16px', position:'relative', overflow:'hidden',
        background:'linear-gradient(160deg,#1a1d20,#121417 75%)' }}>
        <div style={{ position:'absolute', right:-50, top:-40, width:150, height:150, borderRadius:'50%',
          background:d.lasts?'var(--gold-glow)':'rgba(229,129,99,.14)', filter:'blur(6px)' }}/>
        <div className="row" style={{ justifyContent:'space-between', alignItems:'flex-start' }}>
          <div>
            <div style={{ fontSize:13, color:'var(--dim)' }}>{d.lasts ? 'Your corpus is funded through' : 'Your corpus runs dry at'}</div>
            <div className="serif" style={{ fontSize:42, lineHeight:1, marginTop:6, color:d.lasts?'var(--text)':'var(--red)' }}>
              {d.lasts ? <>{endAge}<span style={{ fontSize:24, color:'var(--gold)' }}>+</span></> : <>age {d.depleteAge}</>}
            </div>
            <div style={{ fontSize:13, color:d.lasts?'var(--gold-bright)':'var(--red)', marginTop:8, fontWeight:600 }}>
              {d.lasts ? 'survives a full retirement ✓' : `${d.depleteAge - retireAge} yrs of cover only`}
            </div>
          </div>
          <div style={{ textAlign:'center' }}>
            <Ring pct={d.success/100} size={72} stroke={7} color={succColor}>
              <div className="serif tnum" style={{ fontSize:18, color:succColor }}>{d.success}%</div>
            </Ring>
            <div className="eyebrow" style={{ fontSize:8, marginTop:6 }}>survival</div>
          </div>
        </div>
        <div style={{ marginTop:18 }}>
          <DrawdownChart med={d.med} hi={d.hi} lo={d.lo} depleteAge={d.lo.dep} retireAge={retireAge} endAge={endAge} w={300}/>
          <div className="row" style={{ justifyContent:'space-between', marginTop:2 }}>
            <span style={{ fontSize:10, color:'var(--faint)' }} className="mono">retire {retireAge}</span>
            <span style={{ fontSize:10, color:'var(--gold)' }} className="mono">{fmtINR(exp/12,0)}/mo</span>
            <span style={{ fontSize:10, color:'var(--faint)' }} className="mono">age {endAge}</span>
          </div>
        </div>
        {/* legend */}
        <div className="row" style={{ gap:14, marginTop:12 }}>
          <span style={{ display:'flex', alignItems:'center', gap:6, fontSize:10.5, color:'var(--dim)' }}><i style={{ width:14, height:3, borderRadius:2, background:'var(--gold)' }}/>expected path</span>
          <span style={{ display:'flex', alignItems:'center', gap:6, fontSize:10.5, color:'var(--dim)' }}><i style={{ width:14, height:8, borderRadius:2, background:'rgba(212,175,92,.18)' }}/>good vs bad markets</span>
        </div>
      </div>

      {/* monthly withdrawal + inflation path */}
      {(function(){
        const monToday = exp/12;
        const midAge = Math.min(retireAge+15, endAge);
        const nominalAt = (age)=> monToday * Math.pow(1+infl/100, age-retireAge);
        const points = [
          { lbl:'Today', val:monToday, today:true },
          { lbl:`Age ${midAge}`, val:nominalAt(midAge) },
          { lbl:`Age ${endAge}`, val:nominalAt(endAge) },
        ];
        return (
          <div className="card" style={{ padding:16, marginTop:14 }}>
            <div className="row" style={{ justifyContent:'space-between', alignItems:'flex-end', marginBottom:14 }}>
              <div>
                <div className="eyebrow" style={{ marginBottom:6 }}>Monthly withdrawal</div>
                <div className="serif tnum" style={{ fontSize:27, lineHeight:1 }}>{fmtINR(monToday,0)}<span style={{ fontSize:14, color:'var(--dim)' }}>/mo</span></div>
              </div>
              <div style={{ textAlign:'right' }}>
                <div className="tnum" style={{ fontSize:14, fontWeight:700 }}>{fmtINR(exp,1)}<span style={{ fontSize:11, color:'var(--faint)', fontWeight:500 }}>/yr</span></div>
                <div style={{ fontSize:10, color:'var(--faint)', marginTop:2 }} className="mono">inflation-indexed</div>
              </div>
            </div>
            <div style={{ display:'flex', gap:8 }}>
              {points.map((p,i)=>(
                <div key={i} style={{ flex:1, padding:'10px 6px', borderRadius:11, textAlign:'center',
                  background:p.today?'rgba(212,175,92,.1)':'var(--bg)', border:`1px solid ${p.today?'rgba(212,175,92,.25)':'var(--line)'}` }}>
                  <div style={{ fontSize:9.5, color:'var(--faint)' }} className="mono">{p.lbl}</div>
                  <div className="serif tnum" style={{ fontSize:15, marginTop:5, color:p.today?'var(--gold-bright)':'var(--text)' }}>{fmtINR(p.val,0)}</div>
                  <div style={{ fontSize:8.5, color:'var(--faint)' }}>/mo{p.today?'':' nominal'}</div>
                </div>
              ))}
            </div>
            <div style={{ fontSize:10.5, color:'var(--faint)', marginTop:11, lineHeight:1.45 }}>
              You draw {fmtINR(monToday,0)}/mo in today’s money — with {infl}% inflation that’s the rising nominal cash you actually spend each month.
            </div>
          </div>
        );
      })()}

      {/* withdrawal-rate health */}
      <div className="card" style={{ padding:16, marginTop:14 }}>
        <div className="row" style={{ justifyContent:'space-between', marginBottom:13 }}>
          <div>
            <div className="eyebrow" style={{ marginBottom:5 }}>Withdrawal rate</div>
            <div className="serif tnum" style={{ fontSize:26, color:wrColor, lineHeight:1 }}>{d.wr.toFixed(1)}%</div>
          </div>
          <div style={{ textAlign:'right' }}>
            <span className="tag" style={{ background:d.wr<=swr?'var(--green-dim)':'var(--red-dim)', color:wrColor }}>
              {d.wr<=swr ? <><Icon name="check" size={11} color={wrColor}/> within safe zone</> : <><Icon name="info" size={11} color={wrColor}/> above safe rate</>}
            </span>
            <div style={{ fontSize:10.5, color:'var(--faint)', marginTop:6 }}>safe ≤ {swr}% · India SWR 3.0–3.5%</div>
          </div>
        </div>
        <WRGauge wr={d.wr} swr={swr}/>
      </div>

      {/* legacy / estate */}
      <div className="card" style={{ padding:16, marginTop:14, display:'flex', gap:14 }}>
        <Stat label={`Estate at ${endAge}`} value={d.lasts?fmtINR(d.legacy,2):'₹0'} sub={d.lasts?'left to heirs (today\u2019s ₹)':'corpus exhausted'} accent={d.lasts?'var(--green)':'var(--red)'}/>
        <div style={{ width:1, background:'var(--line)' }}/>
        <Stat label="Years funded" value={(d.lasts?endAge:d.depleteAge)-retireAge+' yrs'} sub={`age ${retireAge} → ${d.lasts?endAge:d.depleteAge}`} accent="var(--gold)"/>
      </div>

      <SectionAssumptions title="Post-FIRE assumptions"
        summary={`${fmtINR(fireCorpus,1)} corpus · ${ret}% return · retire ${retireAge}–${endAge}`}>
        <Slider label="Corpus at FIRE" value={fireCorpus} min={10000000} max={80000000} step={500000} fmt={v=>fmtINR(v,2)} onChange={setFireCorpus}/>
        <Slider label="Annual expenses (today)" value={exp} min={300000} max={3000000} step={20000} fmt={v=>fmtINR(v,1)+'/yr'} onChange={setExp}/>
        <Slider label="Expected return" value={ret} min={6} max={15} step={0.5} fmt={v=>v+'%'} onChange={setRet} hint="real return = return − inflation"/>
        <Slider label="Inflation" value={infl} min={3} max={10} step={0.5} fmt={v=>v+'%'} onChange={setInfl}/>
        <Slider label="Retire at age" value={retireAge} min={35} max={60} step={1} fmt={v=>v} onChange={setRetireAge}/>
        <Slider label="Plan until age" value={endAge} min={80} max={100} step={1} fmt={v=>v} onChange={setEndAge} last/>
      </SectionAssumptions>

      <InfoNote color="var(--red)">
        <b style={{ color:'var(--text)' }}>Sequence-of-returns risk:</b> a market crash in your first retirement years does far more damage than a later one.
        The shaded band shows how good vs bad early markets change when your corpus runs out.
      </InfoNote>
    </div>
  );
}

/* withdrawal-rate gauge with safe zone */
function WRGauge({ wr, swr }) {
  const min = 2, max = 6;
  const pos = Math.max(0, Math.min(1, (wr - min) / (max - min))) * 100;
  const safeA = ((2.6 - min) / (max - min)) * 100;
  const safeB = ((swr - min) / (max - min)) * 100;
  return (
    <div>
      <div style={{ position:'relative', height:10, borderRadius:6, background:'linear-gradient(90deg,#5cc89a55,#d4af5c55 55%,#e5816355)' }}>
        <div style={{ position:'absolute', left:safeA+'%', width:(safeB-safeA)+'%', top:0, bottom:0, background:'var(--green)', opacity:.35, borderRadius:2 }}/>
        <div style={{ position:'absolute', left:'calc('+pos+'% - 8px)', top:-3, width:16, height:16, borderRadius:'50%',
          background:'#f3efe7', boxShadow:'0 2px 6px rgba(0,0,0,.5)', border:'3px solid var(--bg)' }}/>
      </div>
      <div className="row" style={{ justifyContent:'space-between', marginTop:7 }}>
        <span style={{ fontSize:10, color:'var(--faint)' }} className="mono">2%</span>
        <span style={{ fontSize:10, color:'var(--green)' }} className="mono">safe 2.6–{swr}%</span>
        <span style={{ fontSize:10, color:'var(--faint)' }} className="mono">6%</span>
      </div>
    </div>
  );
}

function SectionAssumptions({ title, summary, children }) {
  const [open, setOpen] = React.useState(false);
  return (
    <div style={{ marginTop:2 }}>
      <button onClick={()=>setOpen(o=>!o)} style={{ ...plainBtn, width:'100%' }}>
        <div className="row" style={{ justifyContent:'space-between', alignItems:'flex-start', gap:10, padding:'2px 2px 12px', textAlign:'left' }}>
          <div style={{ minWidth:0 }}>
            <div style={{ fontSize:15.5, fontWeight:700, letterSpacing:'-.01em', whiteSpace:'nowrap' }}>{title}</div>
            {!open && summary && <div style={{ fontSize:10.5, color:'var(--faint)', marginTop:5, whiteSpace:'nowrap', overflow:'hidden', textOverflow:'ellipsis' }} className="mono">{summary}</div>}
          </div>
          <span className="row" style={{ gap:5, color:'var(--gold)', fontSize:12.5, fontWeight:600, flexShrink:0, marginTop:1 }}>
            {open ? 'Done' : 'Edit'}
            <Icon name="chevD" size={15} color="var(--gold)" style={{ transform:open?'rotate(180deg)':'none', transition:'transform .2s' }}/>
          </span>
        </div>
      </button>
      {open && <div className="card fade-soft" style={{ padding:'8px 16px 16px' }}>{children}</div>}
    </div>
  );
}

function InfoNote({ children, color = 'var(--blue)' }) {
  return (
    <div style={{ display:'flex', gap:10, padding:'13px 14px', marginTop:14, borderRadius:16,
      background:'var(--surface)', border:'1px solid var(--line)' }}>
      <Icon name="info" size={17} color={color} style={{ flexShrink:0, marginTop:1 }}/>
      <div style={{ fontSize:11.5, color:'var(--dim)', lineHeight:1.5 }}>{children}</div>
    </div>
  );
}

function Slider({ label, value, min, max, step, fmt, onChange, hint, last }) {
  const pct = ((value - min) / (max - min)) * 100;
  return (
    <div style={{ padding:'13px 0', borderBottom:last?'none':'1px solid var(--line)' }}>
      <div className="row" style={{ justifyContent:'space-between', marginBottom:10 }}>
        <span style={{ fontSize:13, color:'var(--dim)', fontWeight:600 }}>{label}</span>
        <span className="serif tnum" style={{ fontSize:16, color:'var(--gold-bright)', whiteSpace:'nowrap' }}>{fmt(value)}</span>
      </div>
      <div style={{ position:'relative', height:22, display:'flex', alignItems:'center' }}>
        <div style={{ position:'absolute', left:0, right:0, height:5, borderRadius:4, background:'rgba(243,239,231,.1)' }}/>
        <div style={{ position:'absolute', left:0, width:pct+'%', height:5, borderRadius:4, background:'linear-gradient(90deg,var(--gold-deep),var(--gold))' }}/>
        <div style={{ position:'absolute', left:'calc('+pct+'% - 11px)', width:22, height:22, borderRadius:'50%',
          background:'radial-gradient(circle at 35% 30%,var(--gold-bright),var(--gold) 60%,var(--gold-deep))',
          boxShadow:'0 2px 8px rgba(0,0,0,.5),0 0 0 4px rgba(212,175,92,.14)', pointerEvents:'none' }}/>
        <input type="range" min={min} max={max} step={step} value={value}
          onChange={e=>onChange(parseFloat(e.target.value))}
          style={{ position:'absolute', left:0, right:0, width:'100%', height:22, margin:0, opacity:0, cursor:'pointer' }}/>
      </div>
      {hint && <div style={{ fontSize:10.5, color:'var(--faint)', marginTop:6 }} className="mono">{hint}</div>}
    </div>
  );
}

Object.assign(window, { ScreenFire, AccView, DrawView, FIOptimise, WRGauge, InfoNote, Slider });
