// Phone mock — Estimado opt-in hero animation.
//
// Scenes:
//   1. Camera app  — viewfinder over real bathroom shots; contractor snaps 3 photos.
//   2. Transition  — quick Estimado-icon pop.
//   3. Estimado    — chat thread: photos uploaded → contractor types scope fast
//                    → AI thinks → AI returns the estimate.
//
// All scenes share one iPhone bezel so it reads as a single device session.

const PD_PHOTOS = [
  '/waitlist/assets/bath-1.jpg',  // shower w/ glass doors close-up
  '/waitlist/assets/bath-2.jpg',  // dark vanity + tall mirror
  '/waitlist/assets/bath-3.jpg',  // shower + toilet wider shot
];

// Contractor's scope message — typed out into the chat thread.
const PD_USER_MESSAGE = [
  "10×5 shower — make it modern.",
  "• Full white 10×10 tile",
  "• Modern white vanity",
  "• 7×5 mirror, floor to ceiling",
  "• Frameless shower door",
].join('\n');

// AI's estimate — each line maps back to a request in the message.
const PD_LINES = [
  ['Demo',                            '$1,230'],
  ['Shower prep',                     '$1,350'],
  ['Tile · labor + materials',        '$4,870'],
  ['Frameless shower + install',      '$3,120'],
  ['Modern white vanity + install',   '$3,530'],
  ['7×5 mirror',                      '$985'  ],
  ['Plumbing + misc',                 '$1,150'],
];
const PD_TOTAL   = '$16,235';
const PD_PROJECT = 'Bathroom Remodel';

// Scene timeline (each tick = 600ms):
//   0       camera open, viewfinder = bath-1, no snaps
//   1       SNAP photo 1 → viewfinder advances to bath-2
//   2       SNAP photo 2 → bath-3
//   3       SNAP photo 3 (hold)
//   4       brief Estimado-icon transition
//   5       app opens (empty chat)
//   6       photos upload bubble (right)
//   7..8    contractor sends text message (typewriter, 1.2s budget)
//   9       AI thinking dots (left)
//   10..16  estimate line items reveal (7 items, one per tick)
//   17      total appears
//   18..20  hold
const PD_TOTAL_TICKS = 21;
const TICK_MS = 600;
const CAMERA_END     = 3;
const TRANSITION_TICK= 4;
const APP_START_TICK = 5;

function PhoneDemo({ height = 400 }) {
  const [tick, setTick] = React.useState(0);
  React.useEffect(() => {
    const id = setInterval(() => setTick((t) => (t + 1) % PD_TOTAL_TICKS), TICK_MS);
    return () => clearInterval(id);
  }, []);

  let scene = 'camera';
  if (tick === TRANSITION_TICK) scene = 'transition';
  else if (tick >= APP_START_TICK) scene = 'app';

  const width  = Math.round(height * 0.50);
  const radius = Math.round(height * 0.105);
  const innerRadius = radius - 5;

  return (
    <div style={{
      width: '100%',
      display: 'flex', justifyContent: 'center', alignItems: 'flex-start',
      position: 'relative',
    }}>
      <div aria-hidden="true" style={{
        position: 'absolute', inset: '-8% -20%',
        background: 'radial-gradient(ellipse at center, rgba(21,20,15,0.07), transparent 60%)',
        pointerEvents: 'none', zIndex: 0,
      }} />

      <div style={{
        width, height,
        background: '#0A0907',
        borderRadius: radius,
        padding: 4,
        position: 'relative', zIndex: 1,
        boxShadow: `
          0 0 0 1.5px rgba(255,255,255,0.06) inset,
          0 0 0 1px #2A2822,
          0 30px 60px -28px rgba(21,20,15,0.55),
          0 8px 16px -10px rgba(21,20,15,0.3)
        `,
      }}>
        <div style={{
          width: '100%', height: '100%',
          background: '#000',
          borderRadius: innerRadius,
          overflow: 'hidden',
          position: 'relative',
          fontFamily: F.ui,
        }}>
          {scene === 'camera'     && <CameraScene tick={tick} />}
          {scene === 'transition' && <TransitionScene />}
          {scene === 'app'        && <AppScene appTick={tick - APP_START_TICK} />}
          <DynamicIsland />
        </div>

        {/* Side buttons */}
        <div aria-hidden="true" style={{
          position: 'absolute', left: -2, top: '18%',
          width: 2, height: 22, background: '#1f1d18', borderRadius: 2,
        }} />
        <div aria-hidden="true" style={{
          position: 'absolute', left: -2, top: '26%',
          width: 2, height: 36, background: '#1f1d18', borderRadius: 2,
        }} />
        <div aria-hidden="true" style={{
          position: 'absolute', right: -2, top: '22%',
          width: 2, height: 52, background: '#1f1d18', borderRadius: 2,
        }} />
      </div>
    </div>
  );
}

function DynamicIsland() {
  return (
    <span aria-hidden="true" style={{
      position: 'absolute', left: '50%', top: 9,
      transform: 'translateX(-50%)',
      width: '32%', height: 16,
      background: '#000', borderRadius: 999,
      zIndex: 50,
    }} />
  );
}

// ─── STATUS BAR ─────────────────────────────────────────────
function StatusBar({ dark = false }) {
  const color = dark ? C.ink : '#fff';
  return (
    <div style={{
      position: 'absolute', top: 0, left: 0, right: 0,
      display: 'flex', alignItems: 'center', justifyContent: 'space-between',
      padding: '11px 16px 0',
      fontFamily: F.mono, fontSize: 8.5, letterSpacing: '0.02em',
      color, zIndex: 40,
    }}>
      <span style={{ fontWeight: 600 }}>9:41</span>
      <span style={{ display: 'inline-flex', alignItems: 'center', gap: 4, opacity: 0.95 }}>
        <svg width="10" height="7" viewBox="0 0 11 8" fill="none">
          <rect x="0" y="5" width="2" height="3" rx="0.4" fill="currentColor"/>
          <rect x="3" y="3.5" width="2" height="4.5" rx="0.4" fill="currentColor"/>
          <rect x="6" y="2" width="2" height="6" rx="0.4" fill="currentColor"/>
          <rect x="9" y="0.5" width="2" height="7.5" rx="0.4" fill="currentColor"/>
        </svg>
        <svg width="14" height="7" viewBox="0 0 16 8" fill="none">
          <rect x="0.5" y="0.5" width="13" height="7" rx="1.6" stroke="currentColor" strokeOpacity="0.7"/>
          <rect x="2" y="2" width="9" height="4" rx="0.6" fill="currentColor"/>
          <rect x="14.2" y="2.6" width="1" height="2.8" rx="0.4" fill="currentColor"/>
        </svg>
      </span>
    </div>
  );
}

// ─── SCENE 1 · CAMERA ────────────────────────────────────────
function CameraScene({ tick }) {
  const viewfinderIdx = Math.min(PD_PHOTOS.length - 1, tick);
  const snappedCount  = Math.min(PD_PHOTOS.length, tick);
  const justSnapped   = tick > 0 && tick <= CAMERA_END;

  return (
    <div style={{
      position: 'absolute', inset: 0, background: '#000',
      display: 'flex', flexDirection: 'column',
    }}>
      <StatusBar />

      {/* Top camera UI bar */}
      <div style={{
        position: 'absolute', top: 22, left: 0, right: 0,
        display: 'flex', justifyContent: 'space-between', alignItems: 'center',
        padding: '4px 14px',
        zIndex: 30,
      }}>
        <span style={{
          color: '#fff', opacity: 0.85,
          width: 18, height: 18, borderRadius: 999,
          background: 'rgba(255,255,255,0.18)',
          display: 'inline-flex', alignItems: 'center', justifyContent: 'center',
        }}>
          <svg width="10" height="10" viewBox="0 0 10 10" fill="none">
            <path d="M6 1L3.5 5.2H5.5L4 9L7 4.5H4.8L6 1Z" fill="#fff"/>
          </svg>
        </span>
        <span style={{
          color: '#FACC15',
          fontFamily: F.mono, fontSize: 7.5, letterSpacing: '0.12em',
          textTransform: 'uppercase',
        }}>● Photo</span>
        <span style={{
          color: '#fff', opacity: 0.85,
          width: 18, height: 18, borderRadius: 999,
          background: 'rgba(255,255,255,0.18)',
          display: 'inline-flex', alignItems: 'center', justifyContent: 'center',
        }}>
          <svg width="10" height="10" viewBox="0 0 10 10" fill="none">
            <circle cx="5" cy="5" r="1" fill="#fff"/>
            <circle cx="5" cy="5" r="3.5" stroke="#fff" strokeWidth="0.8" fill="none"/>
          </svg>
        </span>
      </div>

      {/* Viewfinder — leaves room for 96px bottom controls */}
      <div style={{
        position: 'absolute', top: 44, left: 0, right: 0,
        bottom: 96,
        overflow: 'hidden',
        background: '#1A1815',
      }}>
        <img
          key={viewfinderIdx}
          src={PD_PHOTOS[viewfinderIdx]}
          alt=""
          style={{
            width: '100%', height: '100%',
            objectFit: 'cover', display: 'block',
            animation: 'pd-viewfinder-in 0.35s ease',
          }}
        />
        {/* Rule of thirds grid */}
        <svg style={{ position: 'absolute', inset: 0, width: '100%', height: '100%', pointerEvents: 'none', opacity: 0.4 }}>
          <line x1="33.33%" y1="0" x2="33.33%" y2="100%" stroke="#fff" strokeWidth="0.4" strokeOpacity="0.5"/>
          <line x1="66.66%" y1="0" x2="66.66%" y2="100%" stroke="#fff" strokeWidth="0.4" strokeOpacity="0.5"/>
          <line x1="0" y1="33.33%" x2="100%" y2="33.33%" stroke="#fff" strokeWidth="0.4" strokeOpacity="0.5"/>
          <line x1="0" y1="66.66%" x2="100%" y2="66.66%" stroke="#fff" strokeWidth="0.4" strokeOpacity="0.5"/>
        </svg>
        {/* Focus square */}
        <div style={{
          position: 'absolute', top: '50%', left: '50%',
          transform: 'translate(-50%, -50%)',
          width: 36, height: 36,
          border: '1px solid #FACC15',
          opacity: 0.85,
        }} />

        {/* Flash overlay */}
        {justSnapped && (
          <div key={`flash-${tick}`} style={{
            position: 'absolute', inset: 0, background: '#fff',
            animation: 'pd-flash 0.36s ease forwards',
            pointerEvents: 'none',
          }} />
        )}
      </div>

      {/* Bottom controls */}
      <div style={{
        position: 'absolute', bottom: 0, left: 0, right: 0,
        height: 96, background: '#000',
        display: 'flex', flexDirection: 'column',
        alignItems: 'stretch', justifyContent: 'flex-start',
        padding: '6px 0 10px',
        zIndex: 30,
      }}>
        {/* Zoom indicators */}
        <div style={{
          display: 'flex', justifyContent: 'center', gap: 8,
          marginBottom: 4,
        }}>
          {['.5', '1×', '2'].map((z, i) => (
            <span key={z} style={{
              width: 16, height: 16, borderRadius: 999,
              background: i === 1 ? 'rgba(255,255,255,0.22)' : 'rgba(255,255,255,0.10)',
              color: i === 1 ? '#FACC15' : '#fff',
              display: 'inline-flex', alignItems: 'center', justifyContent: 'center',
              fontFamily: F.ui, fontSize: 8, fontWeight: 500,
            }}>{z}</span>
          ))}
        </div>

        {/* Mode picker */}
        <div style={{
          display: 'flex', justifyContent: 'center', gap: 12,
          color: 'rgba(255,255,255,0.55)',
          fontFamily: F.mono, fontSize: 7, letterSpacing: '0.16em',
          textTransform: 'uppercase',
          marginBottom: 6,
        }}>
          <span>Video</span>
          <span style={{ color: '#FACC15', fontWeight: 600 }}>Photo</span>
          <span>Portrait</span>
        </div>

        {/* Shutter row */}
        <div style={{
          display: 'flex', alignItems: 'center', justifyContent: 'space-between',
          padding: '0 16px',
          flex: 1,
        }}>
          {/* Photo thumbnail */}
          <div style={{
            width: 26, height: 26, borderRadius: 5,
            background: '#1A1815', overflow: 'hidden',
            border: '1.2px solid rgba(255,255,255,0.22)',
            position: 'relative',
            boxShadow: snappedCount > 1
              ? '2px 2px 0 -1px #1A1815, 2px 2px 0 0 rgba(255,255,255,0.22)'
              : 'none',
            transition: 'box-shadow 0.3s ease',
            flexShrink: 0,
          }}>
            {snappedCount > 0 && (
              <img
                key={snappedCount}
                src={PD_PHOTOS[Math.min(snappedCount - 1, PD_PHOTOS.length - 1)]}
                alt=""
                style={{
                  width: '100%', height: '100%',
                  objectFit: 'cover', display: 'block',
                  animation: 'pd-thumb-pop 0.4s ease',
                }}
              />
            )}
            {snappedCount > 0 && (
              <span style={{
                position: 'absolute', top: -4, right: -4,
                minWidth: 14, height: 14, padding: '0 3px',
                borderRadius: 999, background: '#FACC15', color: '#15140F',
                fontFamily: F.mono, fontSize: 8.5, fontWeight: 700,
                display: 'inline-flex', alignItems: 'center', justifyContent: 'center',
                boxShadow: '0 0 0 1.2px #000',
              }}>{snappedCount}</span>
            )}
          </div>

          {/* Shutter button — smaller so it fits */}
          <span style={{
            width: 36, height: 36, borderRadius: 999,
            background: '#fff',
            boxShadow: '0 0 0 2.5px #000, 0 0 0 4px #fff',
            transform: justSnapped ? 'scale(0.88)' : 'scale(1)',
            transition: 'transform 0.12s ease',
            flexShrink: 0,
          }} />

          {/* Flip cam */}
          <span style={{
            width: 26, height: 26, borderRadius: 999,
            background: 'rgba(255,255,255,0.18)',
            color: '#fff', flexShrink: 0,
            display: 'inline-flex', alignItems: 'center', justifyContent: 'center',
          }}>
            <svg width="13" height="13" viewBox="0 0 14 14" fill="none">
              <path d="M3 5.5L4.4 3.7C4.7 3.3 5.2 3 5.7 3H8.3C8.8 3 9.3 3.3 9.6 3.7L11 5.5" stroke="currentColor" strokeWidth="1" fill="none" strokeLinecap="round" strokeLinejoin="round"/>
              <rect x="2" y="5.5" width="10" height="5.5" rx="1" stroke="currentColor" strokeWidth="1" fill="none"/>
              <circle cx="7" cy="8.2" r="1.6" stroke="currentColor" strokeWidth="1" fill="none"/>
              <path d="M11.5 7.5L12.5 8.5L11.5 9.5" stroke="currentColor" strokeWidth="0.9" fill="none" strokeLinecap="round" strokeLinejoin="round"/>
            </svg>
          </span>
        </div>
      </div>
    </div>
  );
}

// ─── SCENE 2 · TRANSITION ────────────────────────────────────
function TransitionScene() {
  return (
    <div style={{
      position: 'absolute', inset: 0,
      background: 'linear-gradient(180deg, #2A2822 0%, #15140F 100%)',
      display: 'flex', alignItems: 'center', justifyContent: 'center',
      flexDirection: 'column', gap: 12,
    }}>
      <StatusBar />
      <div style={{
        width: 56, height: 56, borderRadius: 14,
        background: C.paper, color: C.ink,
        display: 'inline-flex', alignItems: 'center', justifyContent: 'center',
        fontFamily: F.display, fontSize: 40, fontWeight: 500, lineHeight: 1,
        paddingTop: 4,
        boxShadow: '0 12px 36px -12px rgba(0,0,0,0.6)',
        animation: 'pd-icon-pop 0.5s cubic-bezier(0.2,0.8,0.2,1)',
      }}>E</div>
      <span style={{
        color: '#fff', opacity: 0.8,
        fontFamily: F.display, fontSize: 14, fontWeight: 420, letterSpacing: '-0.03em',
      }}>Estimado</span>
    </div>
  );
}

// ─── SCENE 3 · ESTIMADO APP (chat thread, light theme) ───────
function AppScene({ appTick }) {
  // Phase chart by appTick (app starts at tick 5; appTick = tick - 5):
  //   0:     app open, empty thread
  //   1:     photos upload bubble (right)
  //   2..3:  contractor text bubble (typewriter ~1.2s)
  //   4:     AI thinking dots (left)
  //   5..8:  estimate line items reveal
  //   9:     total appears
  //   10..13 hold
  const showPhotos      = appTick >= 1;
  const showUserMsg     = appTick >= 2;
  const showThinking    = appTick >= 4 && appTick < 5;
  const showEstimate    = appTick >= 5;
  const linesRevealed   = Math.max(0, Math.min(PD_LINES.length, appTick - 4));
  const totalShown      = appTick >= 5 + PD_LINES.length;
  const overall         = Math.min(1, Math.max(0, appTick / (5 + PD_LINES.length)));

  return (
    <div style={{
      position: 'absolute', inset: 0,
      background: C.paper, color: C.ink,
      display: 'flex', flexDirection: 'column',
      animation: 'pd-app-in 0.35s ease',
    }}>
      <StatusBar dark={true} />

      {/* Top progress bar */}
      <div style={{
        position: 'absolute', top: 0, left: 0, right: 0,
        height: 2, background: 'rgba(21,20,15,0.06)', zIndex: 41,
      }}>
        <div style={{
          height: '100%', width: `${overall * 100}%`,
          background: C.ink, transition: 'width 0.4s ease',
        }} />
      </div>

      {/* App header */}
      <div style={{
        padding: '30px 10px 8px',
        display: 'flex', alignItems: 'center', justifyContent: 'space-between',
        borderBottom: `1px solid ${C.rule}`,
      }}>
        <span style={{ display: 'inline-flex', alignItems: 'center', gap: 5 }}>
          <span style={{
            width: 14, height: 14, borderRadius: 3.5,
            background: C.ink, color: C.paper,
            display: 'inline-flex', alignItems: 'center', justifyContent: 'center',
            fontFamily: F.display, fontSize: 10.5, fontWeight: 500, lineHeight: 1, paddingTop: 1,
          }}>E</span>
          <span style={{
            fontFamily: F.display, fontSize: 11.5, fontWeight: 420, letterSpacing: '-0.03em',
            color: C.ink,
          }}>{PD_PROJECT}</span>
        </span>
        <span style={{ display: 'inline-flex', alignItems: 'center', gap: 4 }}>
          <span className="om-pulse-dot" style={{ width: 5, height: 5 }} />
          <span style={{
            fontFamily: F.mono, fontSize: 7, letterSpacing: '0.1em',
            textTransform: 'uppercase', color: C.muted,
          }}>{totalShown ? 'Done' : 'Live'}</span>
        </span>
      </div>

      {/* Chat thread */}
      <div style={{
        flex: 1, minHeight: 0,
        display: 'flex', flexDirection: 'column', justifyContent: 'flex-end',
        gap: 5,
        padding: '8px 8px 22px',
      }}>
        {showPhotos    && <PhotoBubble />}
        {showUserMsg   && <UserMessageBubble key="user-msg" />}
        {showThinking  && <ThinkingBubble />}
        {showEstimate  && <EstimateBubble linesRevealed={linesRevealed} totalShown={totalShown} />}
      </div>
    </div>
  );
}

// ─── Chat bubble: photo upload (right) ──────────────────────
function PhotoBubble() {
  return (
    <div style={{
      alignSelf: 'flex-end',
      maxWidth: '88%',
      background: C.ink, color: C.paper,
      borderRadius: 10, borderBottomRightRadius: 3,
      padding: '5px 6px 6px',
      animation: 'pd-bubble-in 0.3s ease',
      flexShrink: 0,
    }}>
      <div style={{ display: 'flex', gap: 3, marginBottom: 3 }}>
        {PD_PHOTOS.map((src, i) => (
          <div key={i} style={{
            width: 30, height: 30, borderRadius: 4,
            overflow: 'hidden', background: '#222',
            border: '0.5px solid rgba(250,248,243,0.18)',
          }}>
            <img src={src} alt="" style={{
              width: '100%', height: '100%', objectFit: 'cover', display: 'block',
            }} />
          </div>
        ))}
      </div>
      <div style={{
        fontFamily: F.mono, fontSize: 7,
        color: 'rgba(250,248,243,0.65)',
        letterSpacing: '0.04em',
      }}>3 photos · 4.8 MB</div>
    </div>
  );
}

// ─── Chat bubble: user text with typewriter ──────────────────
function UserMessageBubble() {
  const [chars, setChars] = React.useState(0);
  React.useEffect(() => {
    const id = setInterval(() => {
      setChars((c) => {
        if (c >= PD_USER_MESSAGE.length) { clearInterval(id); return c; }
        return Math.min(PD_USER_MESSAGE.length, c + 3);
      });
    }, 16);
    return () => clearInterval(id);
  }, []);

  const text = PD_USER_MESSAGE.slice(0, chars);
  const typing = chars < PD_USER_MESSAGE.length;

  return (
    <div style={{
      alignSelf: 'flex-end',
      maxWidth: '92%',
      background: C.ink, color: C.paper,
      borderRadius: 10, borderBottomRightRadius: 3,
      padding: '6px 8px',
      fontSize: 8.5, lineHeight: 1.35,
      whiteSpace: 'pre-line',
      letterSpacing: '-0.005em',
      animation: 'pd-bubble-in 0.3s ease',
      flexShrink: 0,
    }}>
      {text}
      {typing && (
        <span aria-hidden="true" style={{
          display: 'inline-block', width: 1, height: 9,
          background: C.paper, marginLeft: 1,
          transform: 'translateY(1px)',
          animation: 'pd-caret 0.6s steps(1) infinite',
        }} />
      )}
    </div>
  );
}

// ─── Chat bubble: AI thinking dots ──────────────────────────
function ThinkingBubble() {
  return (
    <div style={{
      alignSelf: 'flex-start',
      display: 'inline-flex', alignItems: 'center', gap: 6,
      padding: '6px 10px',
      background: C.paper2, color: C.muted,
      border: `1px solid ${C.rule}`,
      borderRadius: 10, borderBottomLeftRadius: 3,
      animation: 'pd-bubble-in 0.3s ease',
      flexShrink: 0,
    }}>
      <span style={{
        fontFamily: F.mono, fontSize: 7.5, letterSpacing: '0.08em', textTransform: 'uppercase',
      }}>Estimating</span>
      <span style={{ display: 'inline-flex', gap: 2.5 }}>
        {[0, 1, 2].map((i) => (
          <span key={i} style={{
            width: 4, height: 4, borderRadius: 999, background: C.ink,
            opacity: 0.4,
            animation: `pd-think 1.2s ease-in-out ${i * 0.18}s infinite`,
          }} />
        ))}
      </span>
    </div>
  );
}

// ─── Chat bubble: AI estimate response ──────────────────────
function EstimateBubble({ linesRevealed, totalShown }) {
  return (
    <div style={{
      alignSelf: 'flex-start',
      width: '95%',
      background: C.paper2, color: C.ink,
      border: `1px solid ${C.rule}`,
      borderRadius: 10, borderBottomLeftRadius: 3,
      padding: '6px 8px 0',
      animation: 'pd-bubble-in 0.3s ease',
      display: 'flex', flexDirection: 'column',
      overflow: 'hidden',
      flexShrink: 0,
    }}>
      <div style={{
        fontFamily: F.mono, fontSize: 6, letterSpacing: '0.12em',
        textTransform: 'uppercase', color: C.muted,
        marginBottom: 4,
      }}>Estimate · {PD_LINES.length} items</div>

      <div style={{ display: 'flex', flexDirection: 'column', gap: 0 }}>
        {PD_LINES.map(([label, price], i) => {
          const lit = i < linesRevealed;
          return (
            <div key={label} style={{
              display: 'flex', justifyContent: 'space-between', alignItems: 'baseline',
              gap: 6,
              opacity: lit ? 1 : 0,
              transform: lit ? 'translateY(0)' : 'translateY(3px)',
              transition: 'opacity 0.3s ease, transform 0.3s ease',
            }}>
              <span style={{
                fontSize: 8, color: C.ink, lineHeight: 1.5,
                whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis',
                flex: 1, minWidth: 0,
              }}>{label}</span>
              <span style={{
                fontFamily: F.mono, fontSize: 7.5, lineHeight: 1.5,
                color: C.ink2, whiteSpace: 'nowrap', flexShrink: 0,
              }}>{price}</span>
            </div>
          );
        })}
      </div>

      {/* Total */}
      <div style={{
        marginTop: 4,
        marginLeft: -8, marginRight: -8, marginBottom: 0,
        background: C.ink, color: C.paper,
        padding: '5px 8px 6px',
        display: 'flex', justifyContent: 'space-between', alignItems: 'baseline',
        opacity: totalShown ? 1 : 0.3,
        transition: 'opacity 0.4s ease',
      }}>
        <span style={{
          fontFamily: F.mono, fontSize: 7, letterSpacing: '0.12em',
          textTransform: 'uppercase', color: 'rgba(250,248,243,0.6)',
          whiteSpace: 'nowrap',
        }}>Total</span>
        <span style={{
          fontFamily: F.display, fontWeight: 420, fontSize: 14,
          letterSpacing: '-0.025em', color: C.paper, lineHeight: 1,
        }}>{totalShown ? PD_TOTAL : '$—'}</span>
      </div>
    </div>
  );
}

// ─── Keyframes ──────────────────────────────────────────────
if (typeof document !== 'undefined' && !document.getElementById('pd-keyframes')) {
  const s = document.createElement('style');
  s.id = 'pd-keyframes';
  s.textContent = `
    @keyframes pd-viewfinder-in { from { opacity: 0; transform: scale(1.04); } to { opacity: 1; transform: scale(1); } }
    @keyframes pd-flash { 0% { opacity: 0.92; } 60% { opacity: 0.6; } 100% { opacity: 0; } }
    @keyframes pd-thumb-pop { 0% { opacity: 0; transform: scale(0.6); } 60% { transform: scale(1.08); } 100% { opacity: 1; transform: scale(1); } }
    @keyframes pd-icon-pop { 0% { opacity: 0; transform: scale(0.6); } 60% { transform: scale(1.06); } 100% { opacity: 1; transform: scale(1); } }
    @keyframes pd-app-in { from { opacity: 0; } to { opacity: 1; } }
    @keyframes pd-bubble-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }
    @keyframes pd-caret { 50% { opacity: 0; } }
    @keyframes pd-think {
      0%, 80%, 100% { opacity: 0.3; transform: translateY(0); }
      40% { opacity: 1; transform: translateY(-1.5px); }
    }
  `;
  document.head.appendChild(s);
}

window.PhoneDemo = PhoneDemo;
