// Solari · Landing · Animated Recipes loop (v2)
// Story: capture from 2 sources → land in a RICH recipe overview
// → after cooking, leave a voice note → it forks into family's version.
// Self-contained; relies on PhoneShell from landing-plan-anim.jsx.

const { useState: useStateR, useEffect: useEffectR, useRef: useRefR } = React;

// ─── Tokens ────────────────────────────────────────────────────
const RC = {
  ink:      'var(--ink-900, #1f1f1c)',
  ink2:     'var(--ink-700, #3b3b35)',
  ink3:     'var(--ink-500, #76736a)',
  ink4:     'var(--ink-400, #a39f93)',
  paper:    'var(--paper-50, #faf6e9)',
  paper2:   'var(--paper-100, #f3ecd6)',
  paper3:   'var(--paper-200, #e8dfcc)',
  paper4:   'var(--paper-300, #d8cfb8)',
  sage:     'var(--sage-700, #4f7a3a)',
  sageWash: 'var(--sage-100, #e8efd9)',
  amberD:   'var(--amber-700, #c77a1f)',
  amberS:   'var(--amber-100, #f5e3c2)',
  clay:     'var(--terra-600, #b8542e)',
};

// ─── Choreography ──────────────────────────────────────────────
// Single source (Instagram cacio) → rich recipe overview → voice-note feedback.
const RECIPE_SEQUENCE = [
  // ── Source: Instagram ──
  { t: 0,     state: 'src1-show',      caption: 'You see something good on Instagram…' },
  { t: 2600,  state: 'src1-import',    caption: 'Send it to Solari.' },
  { t: 4400,  state: 'src1-parsing',   caption: 'Solari reads it for you.' },
  { t: 7200,  state: 'src1-card',      caption: 'Saved.' },

  // ── The recipe overview · LONG dwell ──
  { t: 9400,  state: 'overview-hero',     caption: 'Every recipe, the same beautiful page.' },
  { t: 12800, state: 'overview-changed',  caption: 'It remembers your tweaks across versions.' },
  { t: 16400, state: 'overview-ing',      caption: 'Ingredients with your notes inline.' },
  { t: 19800, state: 'overview-steps',    caption: 'Steps, written like you’d say them.' },
  { t: 23000, state: 'overview-feedback', caption: 'Family feedback. Notes. Everything in one place.' },

  // ── Feedback / family fork ──
  { t: 26600, state: 'fb-ask',         caption: 'And after you cook it… leave a voice note.' },
  { t: 29200, state: 'fb-record',      caption: 'Hold to talk.' },
  { t: 32200, state: 'fb-transcribe',  caption: '“More pepper next time. Salt the water harder.”' },
  { t: 35400, state: 'fb-fork',        caption: 'Saved to your family’s version. V2 → V3.' },
  { t: 38600, state: 'fb-rest',        caption: 'The recipe grows up with you.' },
];
const RECIPE_LOOP = 42000;

const useChoreoR = (sequence, duration) => {
  const [t, setT] = useStateR(0);
  const startRef = useRefR(performance.now());
  useEffectR(() => {
    let raf;
    const tick = (now) => {
      setT((now - startRef.current) % duration);
      raf = requestAnimationFrame(tick);
    };
    raf = requestAnimationFrame(tick);
    return () => cancelAnimationFrame(raf);
  }, [duration]);
  let current = sequence[0];
  for (const ev of sequence) { if (ev.t <= t) current = ev; else break; }
  return { t, state: current.state, caption: current.caption || '' };
};

// ─── The 2 incoming recipes ────────────────────────────────────
const RECIPES = [
  {
    src: 'instagram',
    handle: '@kitchen.notes',
    title: 'Cacio e pepe',
    familyName: 'Hartley family cacio',
    eyebrow: '★ FAMILY · V2',
    blurb: 'one pot · 20 min · serves 4',
    time: '20 min',
    serves: 'serves 4',
    tag: 'cook',
    stats: [['20', 'min'], ['4', 'serves'], ['1', 'pot'], ['3×', 'cooked']],
    story: 'A weeknight one-pot cacio, leaning on more pepper and a generous toss of pasta water. Quick to throw together; everyone in the house eats it.',
    changed: 'You doubled the pepper. Added pecorino + parm together (Lily). Salted the water more heavily. We kept it.',
    ingredients: [
      ['1 lb',   'bucatini',                 ''],
      ['1½ cups','pecorino, finely grated', 'your blend'],
      ['½ cup', 'parmigiano',                'added'],
      ['2 tsp',  'black pepper, cracked',     'your double'],
      ['',       'kosher salt',               'to taste'],
      ['',       'reserved pasta water',      ''],
    ],
    steps: [
      'Boil pasta in well-salted water until al dente.',
      'Toast cracked pepper in a dry pan until fragrant.',
      'Off heat, add a ladle of pasta water + cheeses, whisk to a cream.',
      'Toss in pasta, glossing with more pasta water as needed.',
    ],
    feedback: [
      ['M', 'Mike',  'sage',       '"this is the version"',         '★★★★★'],
      ['L', 'Lily',  'amber',      '"more pepper, just like that"', '★★★★★'],
      ['T', 'Theo',  'terracotta', '"can we have it again Friday"', '★★★★'],
    ],
    notes: [
      ['"reserve a full mug of pasta water, always wish I had more"', 'Mar 12'],
      ['"grate the cheese fine, like snow"', ''],
    ],
    serveWith: ['a sharp green salad', 'lemony broccolini'],
    leftover: ['fold into a frittata', 'tossed with rocket, lunch'],
    photo: 'assets/photo-pasta.jpg',
  },
  {
    src: 'cookbook',
    book: 'Mom’s recipe binder',
    title: 'Sunday roast chicken',
    blurb: 'oven · 90 min · serves 6',
    time: '90 min',
    serves: 'serves 6',
    tag: 'batch',
    ingredients: [
      '1 whole chicken (4 lb)', '2 lemons, halved', '4 cloves garlic',
      'rosemary sprigs', 'olive oil', 'salt, pepper',
    ],
    steps: [
      'Pat chicken dry. Salt generously, inside and out.',
      'Stuff cavity with lemons, garlic, rosemary.',
      '425\u00b0 for 75 min. Baste twice.',
      'Rest 15 min before carving.',
    ],
    serveWith: ['roasted potatoes', 'lemony greens', 'pan jus'],
    leftover: ['Tuesday wraps with yogurt + herbs', 'stock from the carcass'],
    photo: 'assets/photo-roast-chicken.jpg',
  },
];

// ─── Source preview cards ──────────────────────────────────────
const SourceCardIG = ({ recipe }) => (
  <div style={{
    background: 'white', borderRadius: 14, overflow: 'hidden',
    boxShadow: '0 8px 24px rgba(31,31,28,0.10)', width: 244,
  }}>
    <div style={{
      display: 'flex', alignItems: 'center', gap: 8,
      padding: '10px 12px', borderBottom: '1px solid #eee',
    }}>
      <div style={{
        width: 28, height: 28, borderRadius: '50%',
        background: 'linear-gradient(135deg, #d97557, #c77a1f)',
      }} />
      <div style={{ fontFamily: 'system-ui, sans-serif', fontSize: 12, fontWeight: 600, color: '#262626' }}>
        {recipe.handle}
      </div>
    </div>
    <div style={{
      width: '100%', height: 184,
      backgroundImage: `url(${recipe.photo})`,
      backgroundSize: 'cover', backgroundPosition: 'center',
    }} />
    <div style={{ padding: '10px 12px' }}>
      <div style={{ display: 'flex', gap: 14, marginBottom: 8 }}>
        <svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="#262626" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round"><path d="M20.84 4.61a5.5 5.5 0 0 0-7.78 0L12 5.67l-1.06-1.06a5.5 5.5 0 0 0-7.78 7.78l8.84 8.84 8.84-8.84a5.5 5.5 0 0 0 0-7.78z"/></svg>
        <svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="#262626" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round"><path d="M21 11.5a8.38 8.38 0 0 1-.9 3.8 8.5 8.5 0 0 1-7.6 4.7 8.38 8.38 0 0 1-3.8-.9L3 21l1.9-5.7a8.38 8.38 0 0 1-.9-3.8 8.5 8.5 0 0 1 4.7-7.6 8.38 8.38 0 0 1 3.8-.9h.5a8.48 8.48 0 0 1 8 8v.5z"/></svg>
        <div style={{ flex: 1 }}/>
        <svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="#262626" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round"><path d="M19 21l-7-5-7 5V5a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2z"/></svg>
      </div>
      <div style={{ fontFamily: 'system-ui, sans-serif', fontSize: 12, color: '#262626', lineHeight: 1.4 }}>
        <span style={{ fontWeight: 600 }}>{recipe.handle}</span>{' '}
        cacio e pepe, weeknight magic. recipe in caption ✨
      </div>
    </div>
  </div>
);

const SourceCardCookbook = ({ recipe }) => (
  <div style={{
    background: '#f5e8c9', borderRadius: 6, overflow: 'hidden',
    boxShadow: '0 12px 32px rgba(31,31,28,0.18), inset 0 0 0 1px rgba(138,90,38,0.2)',
    width: 234, transform: 'rotate(-2.5deg)', position: 'relative',
  }}>
    <div style={{
      position: 'absolute', inset: 0,
      backgroundImage: 'repeating-linear-gradient(transparent, transparent 19px, rgba(138,90,38,0.18) 19px, rgba(138,90,38,0.18) 20px)',
      pointerEvents: 'none',
    }} />
    <div style={{
      position: 'absolute', left: 28, top: 0, bottom: 0,
      width: 1, background: 'rgba(180,60,60,0.4)',
    }} />
    <div style={{ padding: '20px 16px 22px 36px', position: 'relative' }}>
      <div style={{
        fontFamily: 'Georgia, serif', fontStyle: 'italic',
        fontSize: 17, color: '#5a3614', marginBottom: 4,
        textDecoration: 'underline',
      }}>
        Sunday Roast Chicken
      </div>
      <div style={{
        fontFamily: 'Georgia, serif', fontSize: 10.5, color: '#7a4a1c',
        marginBottom: 12, fontStyle: 'italic',
      }}>
        from Mom, est. 1987
      </div>
      <div style={{
        fontFamily: 'Georgia, serif', fontSize: 11.5, color: '#3a2510',
        lineHeight: '20px',
      }}>
        1 whole chicken (4 lb)<br/>
        2 lemons, halved<br/>
        4 cloves garlic<br/>
        sprigs of rosemary<br/>
        olive oil, salt, pepper<br/>
        <br/>
        <span style={{ fontStyle: 'italic' }}>425° for 75 min, baste twice…</span>
      </div>
    </div>
  </div>
);

// ─── View 1 · Source ───────────────────────────────────────────
const SourceView = ({ recipeIdx, importing }) => {
  const r = RECIPES[recipeIdx];
  const Card = recipeIdx === 0 ? SourceCardIG : SourceCardCookbook;
  return (
    <div style={{
      position: 'absolute', inset: 0, paddingTop: 50,
      display: 'flex', flexDirection: 'column', alignItems: 'center',
      background: RC.paper2,
    }}>
      <div style={{
        fontFamily: 'var(--font-sans, system-ui)',
        fontSize: 9.5, fontWeight: 700, letterSpacing: '0.16em',
        color: RC.ink3, padding: '14px 18px 4px', textAlign: 'center',
      }}>
        {recipeIdx === 0 ? 'INSTAGRAM' : 'CAMERA'}
      </div>
      <div style={{
        fontFamily: 'var(--font-display, Georgia, serif)',
        fontSize: 14.5, color: RC.ink, fontStyle: 'italic',
        marginBottom: 16, padding: '0 16px', textAlign: 'center',
      }}>
        {recipeIdx === 0 ? 'Saw it scrolling.' : 'Mom’s binder.'}
      </div>

      <div style={{
        position: 'relative',
        transform: importing ? 'translateY(-30px) scale(0.86)' : 'translateY(0) scale(1)',
        transition: 'transform 900ms cubic-bezier(.5,0,.2,1)',
        opacity: importing ? 0.5 : 1,
        marginBottom: 16,
      }}>
        <Card recipe={r} />
      </div>

      <div style={{
        marginTop: 'auto', marginBottom: 0,
        background: RC.paper, padding: '14px 16px 26px',
        borderTopLeftRadius: 22, borderTopRightRadius: 22,
        boxShadow: '0 -8px 24px rgba(31,31,28,0.08)',
        width: '100%', boxSizing: 'border-box',
        transform: importing ? 'translateY(0)' : 'translateY(20%)',
        opacity: importing ? 1 : 0,
        transition: 'transform 600ms cubic-bezier(.32,.72,0,1), opacity 400ms ease',
      }}>
        <div style={{
          width: 38, height: 4, borderRadius: 2,
          background: RC.paper4, margin: '0 auto 12px',
        }} />
        <div style={{
          display: 'flex', alignItems: 'center', gap: 12, padding: '8px 4px',
        }}>
          <div style={{
            width: 44, height: 44, borderRadius: 12,
            background: RC.sage, color: RC.paper,
            display: 'flex', alignItems: 'center', justifyContent: 'center',
            fontFamily: 'var(--font-display, Georgia, serif)',
            fontSize: 22, fontStyle: 'italic',
          }}>S</div>
          <div>
            <div style={{
              fontFamily: 'var(--font-display, Georgia, serif)', fontSize: 15, fontWeight: 600,
              color: RC.ink,
            }}>Send to Solari</div>
            <div style={{
              fontFamily: 'var(--font-sans, system-ui)', fontSize: 11, color: RC.ink3,
              fontStyle: 'italic', marginTop: 2,
            }}>save to your cookbook</div>
          </div>
          <div style={{ flex: 1 }}/>
          <svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke={RC.sage} strokeWidth="3" strokeLinecap="round" strokeLinejoin="round">
            <polyline points="20 6 9 17 4 12"/>
          </svg>
        </div>
      </div>
    </div>
  );
};

// ─── View 2 · Parsing (slowed; richer fields) ──────────────────
const ParsingView = ({ t, recipeIdx, baseT }) => {
  const r = RECIPES[recipeIdx];
  const elapsed = Math.max(0, t - baseT);
  const fields = [
    { label: 'TITLE',       value: r.title,                       t: 200 },
    { label: 'TIME',        value: r.time,                        t: 600 },
    { label: 'SERVES',      value: r.serves,                      t: 1000 },
    { label: 'INGREDIENTS', value: `${r.ingredients.length} items`, t: 1400 },
    { label: 'STEPS',       value: `${r.steps.length} steps`,     t: 1800 },
    { label: 'SERVE WITH',  value: `${r.serveWith.length} ideas`, t: 2200 },
  ];
  return (
    <div style={{
      position: 'absolute', inset: 0,
      padding: '60px 22px 22px', background: RC.paper,
      display: 'flex', flexDirection: 'column',
    }}>
      <div style={{
        fontFamily: 'var(--font-sans, system-ui)', fontSize: 10, fontWeight: 700,
        letterSpacing: '0.16em', color: RC.sage, textAlign: 'center',
      }}>
        SOLARI · READING
      </div>
      <div style={{
        fontFamily: 'var(--font-display, Georgia, serif)', fontSize: 22, lineHeight: 1.15,
        textAlign: 'center', color: RC.ink, marginTop: 6, letterSpacing: '-0.015em',
      }}>
        Pulling out the <em style={{ color: RC.sage, fontStyle: 'italic' }}>recipe</em>…
      </div>

      <div style={{ marginTop: 22, display: 'flex', flexDirection: 'column', gap: 9 }}>
        {fields.map((f) => {
          const visible = elapsed >= f.t;
          return (
            <div key={f.label} style={{
              display: 'grid', gridTemplateColumns: '110px 1fr 18px',
              gap: 10, alignItems: 'center',
              padding: '11px 14px', borderRadius: 10,
              background: visible ? RC.sageWash : RC.paper2,
              border: '1px solid ' + (visible ? RC.sage : RC.paper3),
              opacity: visible ? 1 : 0.45,
              transform: visible ? 'translateY(0)' : 'translateY(8px)',
              transition: 'background 320ms ease, opacity 320ms ease, transform 360ms cubic-bezier(.34,1.5,.64,1), border-color 320ms ease',
            }}>
              <div style={{
                fontFamily: 'var(--font-sans, system-ui)', fontSize: 9, fontWeight: 700,
                letterSpacing: '0.14em', color: RC.ink3,
              }}>{f.label}</div>
              <div style={{
                fontFamily: 'var(--font-display, Georgia, serif)', fontSize: 13.5, fontWeight: 600,
                color: RC.ink, lineHeight: 1.2,
                whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis',
              }}>{f.value}</div>
              <div style={{ display: 'flex', justifyContent: 'flex-end' }}>
                {visible ? (
                  <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke={RC.sage} strokeWidth="3" strokeLinecap="round" strokeLinejoin="round">
                    <polyline points="20 6 9 17 4 12"/>
                  </svg>
                ) : (
                  <div style={{
                    width: 12, height: 12, borderRadius: '50%',
                    border: `1.5px solid ${RC.paper4}`,
                    borderTopColor: RC.sage,
                    animation: 'rcSpin 0.8s linear infinite',
                  }} />
                )}
              </div>
            </div>
          );
        })}
      </div>
    </div>
  );
};

// ─── View 3 · "Saved" toast (brief confirm) ────────────────────
const SavedView = ({ recipeIdx }) => {
  const r = RECIPES[recipeIdx];
  return (
    <div style={{
      position: 'absolute', inset: 0, paddingTop: 56,
      background: RC.paper,
      display: 'flex', flexDirection: 'column', alignItems: 'center',
    }}>
      <div style={{
        fontFamily: 'var(--font-sans, system-ui)', fontSize: 9.5, fontWeight: 700,
        letterSpacing: '0.14em', color: RC.sage, padding: '14px 18px 4px',
        textAlign: 'center',
      }}>
        SAVED TO COOKBOOK
      </div>
      <div style={{
        fontFamily: 'var(--font-display, Georgia, serif)', fontSize: 13.5, fontStyle: 'italic',
        color: RC.ink3, marginBottom: 18, padding: '0 18px', textAlign: 'center',
      }}>
        ready when you are.
      </div>

      <div style={{
        width: 270, background: 'white',
        borderRadius: 16, overflow: 'hidden',
        boxShadow: '0 12px 32px rgba(31,31,28,0.12), inset 0 0 0 1px rgba(31,31,28,0.04)',
        animation: 'rcLand 600ms cubic-bezier(.34,1.4,.64,1)',
      }}>
        <div style={{
          width: '100%', height: 152,
          backgroundImage: `url(${r.photo})`,
          backgroundSize: 'cover', backgroundPosition: 'center',
        }} />
        <div style={{ padding: '14px 16px 16px' }}>
          <div style={{
            fontFamily: 'var(--font-display, Georgia, serif)', fontSize: 19, fontWeight: 600,
            color: RC.ink, lineHeight: 1.15, letterSpacing: '-0.01em',
          }}>{r.title}</div>
          <div style={{
            fontFamily: 'var(--font-sans, system-ui)', fontSize: 11, color: RC.ink3,
            marginTop: 4, fontStyle: 'italic',
          }}>{r.blurb}</div>
          <div style={{
            marginTop: 12, padding: '8px 12px',
            borderRadius: 10, background: RC.sageWash,
            display: 'flex', alignItems: 'center', gap: 8,
            fontFamily: 'var(--font-display, Georgia, serif)', fontSize: 12, fontStyle: 'italic',
            color: RC.sage,
          }}>
            <svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke={RC.sage} strokeWidth="2.4" strokeLinecap="round" strokeLinejoin="round">
              <polyline points="20 6 9 17 4 12"/>
            </svg>
            saved {recipeIdx === 0 ? 'from Instagram' : 'from Mom’s binder'}
          </div>
        </div>
      </div>
    </div>
  );
};

// ─── View 4 · Recipe Overview (the rich page) ──────────────────
// Scrollable phone view with hero photo, ingredients, steps, and extras.
// We "scroll" by translating an inner column based on the sub-state.
const OverviewView = ({ subState, recipe, recordingState, t, baseT }) => {
  const r = recipe;
  // Scroll positions tuned to the real RecipeDetail layout
  const scrollMap = {
    'overview-hero':     0,
    'overview-changed':  220,
    'overview-ing':      420,
    'overview-steps':    640,
    'overview-feedback': 920,
    'fb-ask':            340,   // scroll back up to the Ask button
    'fb-record':         340,
    'fb-transcribe':     340,
    'fb-fork':           220,   // scroll up to show the WHAT'S CHANGED card update
    'fb-rest':           220,
  };
  const scrollY = scrollMap[subState] ?? 0;
  const elapsed = Math.max(0, t - baseT);

  // Highlight which section the caption is talking about
  const hi = {
    changed:  subState === 'overview-changed' || subState === 'fb-fork' || subState === 'fb-rest',
    ask:      subState === 'fb-ask' || subState === 'fb-record' || subState === 'fb-transcribe',
    ing:      subState === 'overview-ing',
    steps:    subState === 'overview-steps',
    feedback: subState === 'overview-feedback',
  };
  const recording      = subState === 'fb-record';
  const showTranscript = subState === 'fb-transcribe' || subState === 'fb-fork' || subState === 'fb-rest';
  const showFork       = subState === 'fb-fork' || subState === 'fb-rest';
  const isV3           = showFork;

  // Animated waveform for record state
  const bars = Array.from({ length: 18 }, (_, i) => {
    const phase = (elapsed / 80) + i * 0.6;
    return recording ? (5 + Math.abs(Math.sin(phase)) * 18) : 4;
  });

  return (
    <div style={{
      position: 'absolute', inset: 0, paddingTop: 50,
      background: RC.paper, overflow: 'hidden',
    }}>
      {/* scroll column */}
      <div style={{
        transform: `translateY(${-scrollY}px)`,
        transition: 'transform 1100ms cubic-bezier(.5,0,.2,1)',
      }}>
        {/* Hero photo full bleed with title overlay */}
        <div style={{ position: 'relative' }}>
          <div style={{
            width: '100%', height: 240,
            backgroundImage: `url(${r.photo})`,
            backgroundSize: 'cover', backgroundPosition: 'center',
          }} />
          <div style={{
            position: 'absolute', inset: 0,
            background: 'linear-gradient(180deg, rgba(31,31,28,.45) 0%, transparent 30%, transparent 60%, rgba(31,31,28,.6) 100%)',
          }} />
          {/* nav buttons */}
          <div style={{
            position: 'absolute', top: 12, left: 12, right: 12,
            display: 'flex', justifyContent: 'space-between',
          }}>
            <div style={{
              padding: 8, borderRadius: 10,
              background: 'rgba(250,246,233,.85)', backdropFilter: 'blur(10px)',
            }}>
              <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke={RC.ink} strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><polyline points="15 18 9 12 15 6"/></svg>
            </div>
            <div style={{ display: 'flex', gap: 6 }}>
              {['heart','edit'].map(n => (
                <div key={n} style={{
                  padding: 8, borderRadius: 10,
                  background: 'rgba(250,246,233,.85)', backdropFilter: 'blur(10px)',
                }}>
                  <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke={RC.ink} strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round">
                    {n === 'heart'
                      ? <path d="M20.84 4.61a5.5 5.5 0 0 0-7.78 0L12 5.67l-1.06-1.06a5.5 5.5 0 0 0-7.78 7.78l8.84 8.84 8.84-8.84a5.5 5.5 0 0 0 0-7.78z"/>
                      : <><path d="M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"/><path d="M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"/></>}
                  </svg>
                </div>
              ))}
            </div>
          </div>
          {/* title overlay */}
          <div style={{
            position: 'absolute', left: 18, right: 18, bottom: 14, color: RC.paper,
          }}>
            <div style={{
              fontFamily: 'var(--font-sans, system-ui)', fontSize: 9.5, fontWeight: 700,
              letterSpacing: '0.16em', opacity: 0.92,
              transition: 'color 320ms ease',
              color: isV3 ? '#C8E2A6' : RC.paper,
            }}>{isV3 ? '★ FAMILY · V3' : r.eyebrow}</div>
            <div style={{
              fontFamily: 'var(--font-display, Georgia, serif)', fontSize: 26, lineHeight: 1.05,
              letterSpacing: '-0.02em', marginTop: 4,
            }}>{r.familyName}</div>
          </div>
        </div>

        {/* Stats row */}
        <div style={{
          padding: '12px 18px', display: 'flex', justifyContent: 'space-between',
          borderBottom: `1px solid ${RC.paper3}`,
        }}>
          {r.stats.map(([n, l]) => (
            <div key={l} style={{ textAlign: 'center' }}>
              <div style={{ fontFamily: 'var(--font-display, Georgia, serif)', fontSize: 17, color: RC.ink }}>{n}</div>
              <div style={{
                fontFamily: 'var(--font-sans, system-ui)', fontSize: 8.5, fontWeight: 700,
                letterSpacing: '0.12em', color: RC.ink3, marginTop: 2, textTransform: 'uppercase',
              }}>{l}</div>
            </div>
          ))}
        </div>

        {/* Story */}
        <div style={{
          padding: '14px 18px 6px',
          fontFamily: 'var(--font-display, Georgia, serif)', fontSize: 12.5,
          fontStyle: 'italic', color: RC.ink2, lineHeight: 1.55,
        }}>{r.story}</div>

        {/* WHAT'S CHANGED · amber card */}
        <div style={{
          margin: '8px 18px',
          padding: '12px 14px', borderRadius: 12,
          background: '#f5e3c2',
          border: hi.changed ? `1.5px solid ${RC.amberD}` : '1.5px solid transparent',
          transform: hi.changed ? 'scale(1.012)' : 'scale(1)',
          transition: 'border-color 320ms ease, transform 320ms ease',
        }}>
          <div style={{
            fontFamily: 'var(--font-sans, system-ui)', fontSize: 9, fontWeight: 700,
            letterSpacing: '0.14em', color: RC.amberD, marginBottom: 4,
          }}>WHAT’S CHANGED · {isV3 ? 'V2 → V3' : 'V1 → V2'}</div>
          <div style={{
            fontFamily: 'var(--font-display, Georgia, serif)', fontSize: 13.5,
            color: RC.ink2, lineHeight: 1.4, fontStyle: 'italic',
          }}>{r.changed}</div>
          {/* New v3 line — slides in when forked */}
          <div style={{
            marginTop: showFork ? 8 : 0,
            maxHeight: showFork ? 60 : 0,
            opacity: showFork ? 1 : 0,
            overflow: 'hidden',
            transition: 'max-height 480ms cubic-bezier(.32,.72,.2,1), opacity 380ms ease, margin-top 480ms ease',
            display: 'flex', gap: 6, alignItems: 'flex-start',
          }}>
            <span style={{
              color: RC.sage, fontFamily: 'var(--font-display, Georgia, serif)',
              fontSize: 14, lineHeight: 1.3,
            }}>+</span>
            <div style={{
              fontFamily: 'var(--font-display, Georgia, serif)', fontSize: 13,
              color: RC.ink, lineHeight: 1.4, fontStyle: 'italic',
            }}>
              <em style={{ color: RC.sage }}>More pepper</em> next time. Salt the water harder.
              <span style={{ color: RC.ink3, fontStyle: 'italic', marginLeft: 4 }}>just now</span>
            </div>
          </div>
        </div>

        {/* Ask Solari button */}
        <div style={{ padding: '8px 18px 0', position: 'relative' }}>
          <div style={{
            display: 'flex', alignItems: 'center', gap: 10,
            padding: '12px 14px',
            background: RC.sageWash, borderRadius: 14,
            boxShadow: hi.ask
              ? `inset 0 0 0 1.5px ${RC.sage}, 0 4px 14px rgba(79,122,58,.14)`
              : `inset 0 0 0 1px rgba(79,122,58,.20)`,
            transform: hi.ask ? 'scale(1.012)' : 'scale(1)',
            transition: 'box-shadow 320ms ease, transform 320ms ease',
          }}>
            <div style={{
              width: 32, height: 32, borderRadius: 9,
              background: recording ? RC.clay : RC.sage, color: RC.paper,
              display: 'flex', alignItems: 'center', justifyContent: 'center',
              flexShrink: 0,
              boxShadow: recording ? '0 0 0 5px rgba(184,84,46,0.18)' : 'none',
              transition: 'background 320ms ease, box-shadow 320ms ease',
            }}>
              {recording ? (
                <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke={RC.paper} strokeWidth="2.2" strokeLinecap="round" strokeLinejoin="round">
                  <rect x="9" y="3" width="6" height="12" rx="3"/><path d="M5 11a7 7 0 0 0 14 0"/><line x1="12" y1="18" x2="12" y2="22"/>
                </svg>
              ) : (
                <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke={RC.paper} strokeWidth="2" strokeLinecap="round" strokeLinejoin="round">
                  <path d="M12 3v4M12 17v4M3 12h4M17 12h4M5.6 5.6l2.8 2.8M15.6 15.6l2.8 2.8M5.6 18.4l2.8-2.8M15.6 8.4l2.8-2.8"/>
                </svg>
              )}
            </div>
            {recording ? (
              <div style={{ flex: 1, height: 24, display: 'flex', alignItems: 'center', gap: 2 }}>
                {bars.map((h, i) => (
                  <div key={i} style={{
                    width: 3, height: h, borderRadius: 2, background: RC.clay,
                    transition: 'height 120ms ease',
                  }} />
                ))}
              </div>
            ) : (
              <div style={{ flex: 1, minWidth: 0 }}>
                <div style={{
                  fontFamily: 'var(--font-display, Georgia, serif)', fontSize: 13,
                  fontWeight: 600, color: RC.ink, lineHeight: 1.2,
                }}>Add your thoughts</div>
                <div style={{
                  fontFamily: 'var(--font-display, Georgia, serif)', fontSize: 11,
                  color: RC.ink3, fontStyle: 'italic', marginTop: 2,
                }}>subs · scaling · leave a note for next time</div>
              </div>
            )}
            <div style={{
              fontFamily: 'var(--font-sans, system-ui)', fontSize: 10, fontWeight: 600,
              color: recording ? RC.clay : RC.sage,
              minWidth: recording ? 28 : 0, textAlign: 'right',
            }}>{recording ? '0:08' : ''}</div>
          </div>
          {/* Tap pulse on Ask button when fb-ask */}
          {subState === 'fb-ask' && (
            <div style={{
              position: 'absolute', left: 18, right: 18, top: 8,
              display: 'flex', justifyContent: 'flex-start', pointerEvents: 'none',
            }}>
              <div style={{
                width: 50, height: 50, borderRadius: '50%',
                border: `1.5px solid ${RC.sage}`,
                opacity: 0.55, animation: 'shopRipple 700ms ease-out infinite',
                marginLeft: -4, marginTop: -4,
              }} />
            </div>
          )}
          {/* Transcript bubble appears under button */}
          <div style={{
            marginTop: showTranscript ? 10 : 0,
            maxHeight: showTranscript ? 120 : 0,
            opacity: showTranscript ? 1 : 0,
            overflow: 'hidden',
            transition: 'max-height 420ms cubic-bezier(.32,.72,.2,1), opacity 320ms ease, margin-top 420ms ease',
          }}>
            <div style={{
              background: '#fff', padding: '11px 13px',
              borderRadius: 14, borderTopLeftRadius: 4,
              boxShadow: '0 4px 14px rgba(31,31,28,0.06), inset 0 0 0 1px rgba(31,31,28,0.04)',
              fontFamily: 'var(--font-display, Georgia, serif)', fontSize: 12.5,
              fontStyle: 'italic', color: RC.ink, lineHeight: 1.4,
            }}>“More pepper next time. Salt the water harder.”</div>
            <div style={{
              fontFamily: 'var(--font-sans, system-ui)', fontSize: 9.5, color: RC.ink3,
              marginTop: 5, marginLeft: 4, letterSpacing: '0.06em',
            }}>YOU · just now</div>
          </div>
        </div>

        {/* INGREDIENTS · 4 SERVINGS */}
        <div style={{ padding: '14px 18px 4px' }}>
          <div style={{
            fontFamily: 'var(--font-sans, system-ui)', fontSize: 9, fontWeight: 700,
            letterSpacing: '0.14em', color: hi.ing ? RC.sage : RC.sage,
          }}>INGREDIENTS · 4 SERVINGS</div>
        </div>
        <div style={{
          margin: '4px 18px', padding: '4px 12px',
          borderRadius: 10,
          background: hi.ing ? RC.sageWash : 'transparent',
          transition: 'background 320ms ease',
        }}>
          {r.ingredients.map(([q, n, note], i) => (
            <div key={i} style={{
              display: 'flex', gap: 10, padding: '8px 0',
              borderTop: i ? `1px solid ${RC.paper3}` : '0', alignItems: 'baseline',
            }}>
              <span style={{
                width: 60, fontFamily: 'var(--font-sans, system-ui)', fontSize: 10,
                color: RC.ink3, fontWeight: 600, flexShrink: 0,
              }}>{q}</span>
              <span style={{
                flex: 1, fontFamily: 'var(--font-display, Georgia, serif)', fontSize: 12.5,
                color: RC.ink,
              }}>{n}</span>
              <span style={{
                fontFamily: 'var(--font-display, Georgia, serif)', fontSize: 10.5, fontStyle: 'italic',
                color: RC.ink3,
              }}>{note}</span>
            </div>
          ))}
        </div>

        {/* METHOD */}
        <div style={{ padding: '14px 18px 4px' }}>
          <div style={{
            fontFamily: 'var(--font-sans, system-ui)', fontSize: 9, fontWeight: 700,
            letterSpacing: '0.14em', color: RC.sage,
          }}>METHOD</div>
        </div>
        <div style={{
          margin: '4px 18px', padding: '4px 12px',
          borderRadius: 10,
          background: hi.steps ? RC.sageWash : 'transparent',
          transition: 'background 320ms ease',
        }}>
          {r.steps.map((s, i) => (
            <div key={i} style={{
              display: 'flex', gap: 12, padding: '9px 0',
              borderTop: i ? `1px solid ${RC.paper3}` : '0',
            }}>
              <span style={{
                fontFamily: 'var(--font-display, Georgia, serif)', fontSize: 17,
                color: RC.sage, minWidth: 18, lineHeight: 1, fontStyle: 'italic',
              }}>{i + 1}</span>
              <span style={{
                fontFamily: 'var(--font-display, Georgia, serif)', fontSize: 12.5,
                lineHeight: 1.5, color: RC.ink2, flex: 1,
              }}>{s}</span>
            </div>
          ))}
        </div>

        {/* SERVE WITH */}
        <div style={{ padding: '14px 18px 4px' }}>
          <div style={{
            fontFamily: 'var(--font-sans, system-ui)', fontSize: 9, fontWeight: 700,
            letterSpacing: '0.14em', color: RC.sage,
          }}>SERVE WITH</div>
        </div>
        <div style={{ padding: '4px 18px 0', display: 'flex', gap: 5, flexWrap: 'wrap' }}>
          {r.serveWith.map(x => (
            <span key={x} style={{
              padding: '4px 10px', borderRadius: 999,
              background: 'transparent', color: RC.ink2,
              boxShadow: `inset 0 0 0 1px ${RC.paper4}`,
              fontFamily: 'var(--font-sans, system-ui)', fontSize: 9.5,
            }}>+ {x}</span>
          ))}
        </div>

        {/* FAMILY FEEDBACK */}
        <div style={{ padding: '16px 18px 4px' }}>
          <div style={{
            fontFamily: 'var(--font-sans, system-ui)', fontSize: 9, fontWeight: 700,
            letterSpacing: '0.14em', color: RC.sage,
          }}>FAMILY FEEDBACK</div>
        </div>
        <div style={{
          margin: '4px 18px', padding: '4px 12px',
          borderRadius: 10,
          background: hi.feedback ? RC.sageWash : 'transparent',
          transition: 'background 320ms ease',
          display: 'flex', flexDirection: 'column', gap: 9,
        }}>
          {r.feedback.map(([init, name, color, quote, stars]) => {
            const colorMap = { sage: RC.sage, amber: RC.amberD, terracotta: RC.clay };
            return (
              <div key={name} style={{ display: 'flex', gap: 10, alignItems: 'flex-start', padding: '4px 0' }}>
                <div style={{
                  width: 26, height: 26, borderRadius: '50%',
                  background: colorMap[color], color: RC.paper,
                  display: 'flex', alignItems: 'center', justifyContent: 'center',
                  fontFamily: 'var(--font-display, Georgia, serif)', fontSize: 12, fontWeight: 600,
                  flexShrink: 0,
                }}>{init}</div>
                <div style={{ flex: 1, minWidth: 0 }}>
                  <div style={{
                    fontFamily: 'var(--font-display, Georgia, serif)', fontSize: 12,
                    fontStyle: 'italic', color: RC.ink2, lineHeight: 1.35,
                  }}>{quote}</div>
                  <div style={{
                    fontFamily: 'var(--font-sans, system-ui)', fontSize: 9.5,
                    color: RC.ink3, marginTop: 2,
                  }}>{name} · {stars}</div>
                </div>
              </div>
            );
          })}
        </div>

        {/* YOUR NOTES */}
        <div style={{ padding: '16px 18px 4px' }}>
          <div style={{
            fontFamily: 'var(--font-sans, system-ui)', fontSize: 9, fontWeight: 700,
            letterSpacing: '0.14em', color: RC.sage,
          }}>YOUR NOTES</div>
        </div>
        <div style={{ padding: '4px 18px 110px' }}>
          <div style={{
            background: RC.paper2, borderRadius: 10, padding: 12,
          }}>
            {r.notes.map(([note, date], i) => (
              <div key={i} style={{
                fontFamily: 'var(--font-display, Georgia, serif)', fontSize: 13,
                fontStyle: 'italic', color: RC.ink2, lineHeight: 1.4,
                marginTop: i ? 8 : 0,
              }}>
                {note}{date && <span style={{ color: RC.ink3 }}> · {date}</span>}
              </div>
            ))}
          </div>
        </div>
      </div>

      {/* Sticky bottom action bar — outside scroll column */}
      <div style={{
        position: 'absolute', left: 14, right: 14, bottom: 156,
        display: 'flex', gap: 8, padding: 7, borderRadius: 16,
        background: 'rgba(250,246,233,.88)',
        backdropFilter: 'blur(20px) saturate(140%)',
        WebkitBackdropFilter: 'blur(20px) saturate(140%)',
        boxShadow: '0 1px 2px rgba(0,0,0,.04), 0 12px 28px rgba(0,0,0,.10), inset 0 0 0 1px rgba(31,31,28,.04)',
      }}>
        <div style={{
          flex: 1, padding: '11px 12px', borderRadius: 11,
          background: RC.paper, color: RC.ink2, textAlign: 'center',
          fontFamily: 'var(--font-display, Georgia, serif)', fontSize: 12.5, fontWeight: 600,
          boxShadow: `inset 0 0 0 1px ${RC.paper3}`,
        }}>+ this week</div>
        <div style={{
          flex: 1.3, padding: '11px 12px', borderRadius: 11,
          background: RC.sage, color: RC.paper, textAlign: 'center',
          fontFamily: 'var(--font-display, Georgia, serif)', fontSize: 12.5, fontWeight: 600,
        }}>Cook it now →</div>
      </div>
    </div>
  );
};

// ─── View 5 (deprecated) · Feedback now lives inline in OverviewView ──
// eslint-disable-next-line no-unused-vars
const _FeedbackView_DEAD = ({ subState, recipe, t, baseT }) => {
  const r = recipe;
  const elapsed = Math.max(0, t - baseT);

  const showPrompt   = subState !== 'fb-after';        // prompt fades into mic UI quickly
  const showMic      = subState === 'fb-record' || subState === 'fb-transcribe' || subState === 'fb-fork' || subState === 'fb-rest';
  const recording    = subState === 'fb-record';
  const showTranscript = subState === 'fb-transcribe' || subState === 'fb-fork' || subState === 'fb-rest';
  const showFork     = subState === 'fb-fork' || subState === 'fb-rest';

  // Animated waveform for record state
  const bars = Array.from({ length: 22 }, (_, i) => {
    const phase = (elapsed / 80) + i * 0.6;
    const h = recording ? (6 + Math.abs(Math.sin(phase)) * 22) : 4;
    return h;
  });

  return (
    <div style={{
      position: 'absolute', inset: 0, paddingTop: 50,
      background: RC.paper, overflow: 'hidden',
      display: 'flex', flexDirection: 'column',
    }}>
      {/* Slim recipe header */}
      <div style={{
        display: 'flex', alignItems: 'center', gap: 10,
        padding: '14px 18px 12px', borderBottom: `1px solid ${RC.paper3}`,
      }}>
        <div style={{
          width: 42, height: 42, borderRadius: 8,
          backgroundImage: `url(${r.photo})`,
          backgroundSize: 'cover', backgroundPosition: 'center',
          flexShrink: 0,
        }} />
        <div style={{ minWidth: 0 }}>
          <div style={{
            fontFamily: 'var(--font-display, Georgia, serif)', fontSize: 14.5, fontWeight: 600,
            color: RC.ink, lineHeight: 1.15, whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis',
          }}>{r.title}</div>
          <div style={{
            fontFamily: 'var(--font-sans, system-ui)', fontSize: 10, color: RC.ink3,
            fontStyle: 'italic', marginTop: 2,
          }}>cooked tonight · 7:42 PM</div>
        </div>
      </div>

      {/* Prompt */}
      <div style={{
        padding: '18px 22px 10px', textAlign: 'center',
        opacity: showPrompt || subState === 'fb-after' ? 1 : 0,
        transition: 'opacity 320ms ease',
      }}>
        <div style={{
          fontFamily: 'var(--font-sans, system-ui)', fontSize: 9.5, fontWeight: 700,
          letterSpacing: '0.14em', color: RC.sage, marginBottom: 4,
        }}>HOW WAS IT?</div>
        <div style={{
          fontFamily: 'var(--font-display, Georgia, serif)', fontSize: 18, lineHeight: 1.2,
          color: RC.ink, letterSpacing: '-0.01em',
        }}>
          Leave a <em style={{ color: RC.sage, fontStyle: 'italic' }}>note</em> for next time.
        </div>
      </div>

      {/* Mic / waveform */}
      <div style={{
        margin: '6px 22px 0', padding: '14px 16px',
        borderRadius: 16, background: recording ? '#fff' : RC.paper2,
        border: '1px solid ' + (recording ? RC.clay : RC.paper3),
        boxShadow: recording ? '0 6px 20px rgba(184,84,46,0.18)' : 'none',
        opacity: showMic ? 1 : 0,
        transform: showMic ? 'translateY(0)' : 'translateY(8px)',
        transition: 'opacity 360ms ease, transform 420ms ease, background 320ms ease, border-color 320ms ease',
        display: 'flex', alignItems: 'center', gap: 12,
      }}>
        <div style={{
          width: 38, height: 38, borderRadius: '50%',
          background: recording ? RC.clay : RC.sage, color: RC.paper,
          display: 'flex', alignItems: 'center', justifyContent: 'center',
          flexShrink: 0,
          boxShadow: recording ? '0 0 0 6px rgba(184,84,46,0.18)' : 'none',
          transition: 'background 320ms ease, box-shadow 320ms ease',
        }}>
          <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.2" strokeLinecap="round" strokeLinejoin="round">
            <rect x="9" y="3" width="6" height="12" rx="3"/><path d="M5 11a7 7 0 0 0 14 0"/><line x1="12" y1="18" x2="12" y2="22"/>
          </svg>
        </div>
        <div style={{
          flex: 1, height: 28, display: 'flex', alignItems: 'center',
          gap: 2,
        }}>
          {bars.map((h, i) => (
            <div key={i} style={{
              width: 3, height: h, borderRadius: 2,
              background: recording ? RC.clay : RC.paper4,
              transition: 'height 120ms ease, background 320ms ease',
            }} />
          ))}
        </div>
        <div style={{
          fontFamily: 'var(--font-sans, system-ui)', fontSize: 10, fontWeight: 600,
          color: recording ? RC.clay : RC.ink3, minWidth: 28, textAlign: 'right',
        }}>{recording ? '0:08' : '0:00'}</div>
      </div>

      {/* Transcript bubble */}
      <div style={{
        margin: '14px 22px 0',
        opacity: showTranscript ? 1 : 0,
        transform: showTranscript ? 'translateY(0)' : 'translateY(10px)',
        transition: 'opacity 360ms ease, transform 420ms ease',
      }}>
        <div style={{
          background: '#fff', padding: '12px 14px',
          borderRadius: 14, borderTopLeftRadius: 4,
          boxShadow: '0 4px 14px rgba(31,31,28,0.06), inset 0 0 0 1px rgba(31,31,28,0.04)',
          fontFamily: 'var(--font-display, Georgia, serif)', fontSize: 13.5,
          fontStyle: 'italic', color: RC.ink, lineHeight: 1.4,
        }}>
          “Loved this. Next time let’s do bucatini and add a little lemon zest at the end.”
        </div>
        <div style={{
          fontFamily: 'var(--font-sans, system-ui)', fontSize: 9.5, color: RC.ink3,
          marginTop: 6, marginLeft: 4, letterSpacing: '0.06em',
        }}>YOU · just now</div>
      </div>

      {/* Fork badge sliding into recipe */}
      <div style={{
        margin: '14px 22px 18px',
        padding: '12px 14px',
        borderRadius: 14,
        background: RC.sageWash,
        border: `1px solid ${RC.sage}`,
        opacity: showFork ? 1 : 0,
        transform: showFork ? 'translateY(0) scale(1)' : 'translateY(14px) scale(0.96)',
        transition: 'opacity 380ms ease, transform 480ms cubic-bezier(.34,1.4,.64,1)',
      }}>
        <div style={{
          display: 'flex', alignItems: 'center', gap: 8, marginBottom: 8,
        }}>
          <svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke={RC.sage} strokeWidth="2.2" strokeLinecap="round" strokeLinejoin="round">
            <circle cx="6" cy="6" r="2"/><circle cx="18" cy="6" r="2"/><circle cx="12" cy="20" r="2"/>
            <path d="M6 8v3a3 3 0 0 0 3 3h6a3 3 0 0 0 3-3V8"/><path d="M12 14v4"/>
          </svg>
          <div style={{
            fontFamily: 'var(--font-sans, system-ui)', fontSize: 9, fontWeight: 700,
            letterSpacing: '0.14em', color: RC.sage,
          }}>THE HARTLEY VERSION</div>
        </div>
        <div style={{
          fontFamily: 'var(--font-display, Georgia, serif)', fontSize: 12.5,
          color: RC.ink2, lineHeight: 1.5,
        }}>
          <div style={{ display: 'flex', gap: 6 }}>
            <span style={{ color: RC.sage }}>+</span>
            <span><em>Add lemon zest at the end</em> · added by you</span>
          </div>
          <div style={{ display: 'flex', gap: 6, marginTop: 4 }}>
            <span style={{ color: RC.sage }}>★</span>
            <span><em>Family loved it</em> · 1st time cooked</span>
          </div>
        </div>
      </div>
    </div>
  );
};

// ─── Main ──────────────────────────────────────────────────────
const RecipeAnimatedPhone = () => {
  const { t, state, caption } = useChoreoR(RECIPE_SEQUENCE, RECIPE_LOOP);

  let view = 'source', recipeIdx = 0, importing = false, parsingBaseT = 0, fbBaseT = 0;

  const m = state.match(/^src(\d)-(.+)$/);
  if (m) {
    recipeIdx = parseInt(m[1], 10) - 1;
    const phase = m[2];
    if (phase === 'show')    { view = 'source'; importing = false; }
    else if (phase === 'import')  { view = 'source'; importing = true; }
    else if (phase === 'parsing') {
      view = 'parsing';
      const ev = RECIPE_SEQUENCE.find(e => e.state === state);
      parsingBaseT = ev ? ev.t : 0;
    }
    else if (phase === 'card') { view = 'saved'; }
  } else if (state.startsWith('overview') || state.startsWith('fb-')) {
    view = 'overview';
    recipeIdx = 0;
    const ev = RECIPE_SEQUENCE.find(e => e.state === 'fb-record');
    fbBaseT = ev ? ev.t : 0;
  }

  return (
    <div style={{ display: 'flex', flexDirection: 'column', alignItems: 'center', gap: 28 }}>
      <PhoneShell>
        <div style={{ position: 'relative', height: '100%', overflow: 'hidden' }}>
          {view === 'source'   && <SourceView   recipeIdx={recipeIdx} importing={importing} />}
          {view === 'parsing'  && <ParsingView  t={t} recipeIdx={recipeIdx} baseT={parsingBaseT} />}
          {view === 'saved'    && <SavedView    recipeIdx={recipeIdx} />}
          {view === 'overview' && <OverviewView subState={state} recipe={RECIPES[0]} t={t} baseT={fbBaseT} />}

          {window.LandingTabBar && <window.LandingTabBar active="book" />}
        </div>
      </PhoneShell>

      {/* Caption — lifted out of the phone, editorial italic */}
      <div style={{
        maxWidth: 360, textAlign: 'center',
        fontFamily: 'var(--font-display, Georgia, serif)',
        fontSize: 18, fontStyle: 'italic',
        color: RC.ink, lineHeight: 1.35, letterSpacing: '-0.01em',
        minHeight: 56, padding: '0 16px',
      }}>{caption}</div>
    </div>
  );
};

// ─── Mount ─────────────────────────────────────────────────────
const mountRecipePhone = () => {
  const el = document.getElementById('recipe-anim-mount');
  if (!el) return;
  ReactDOM.createRoot(el).render(<RecipeAnimatedPhone />);
};
if (document.readyState === 'loading') {
  document.addEventListener('DOMContentLoaded', mountRecipePhone);
} else {
  mountRecipePhone();
}

// Keyframes
(function injectRecipeKeyframes() {
  if (document.getElementById('recipe-anim-keyframes')) return;
  const s = document.createElement('style');
  s.id = 'recipe-anim-keyframes';
  s.textContent = `
    @keyframes rcSpin { to { transform: rotate(360deg); } }
    @keyframes rcLand {
      0%   { opacity: 0; transform: translateY(40px) scale(0.85); }
      60%  { opacity: 1; transform: translateY(-6px) scale(1.03); }
      100% { opacity: 1; transform: translateY(0)    scale(1); }
    }
  `;
  document.head.appendChild(s);
})();
