/* CinematicHero.jsx — adapted from shadcn/Tailwind component to vanilla JSX
   Uses GSAP + ScrollTrigger from CDN (already loaded in HTML head).
   No Tailwind: all styling lives in the INJECTED_STYLES block + className→CSS in styles.css.
*/

const { useEffect, useRef } = React;

const CINEMATIC_INJECTED_STYLES = `
  .ch-root {
    position: relative;
    width: 100vw;
    height: 100vh;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--fg);
    background: var(--bg);
    perspective: 1500px;
    font-family: var(--font-body, ui-sans-serif, system-ui);
    -webkit-font-smoothing: antialiased;
  }

  .ch-gsap-reveal { visibility: hidden; }

  .ch-grain {
    position: absolute; inset: 0; width: 100%; height: 100%;
    pointer-events: none; z-index: 50; opacity: 0.05; mix-blend-mode: overlay;
    background: url('data:image/svg+xml;utf8,<svg viewBox="0 0 200 200" xmlns="http://www.w3.org/2000/svg"><filter id="noiseFilter"><feTurbulence type="fractalNoise" baseFrequency="0.8" numOctaves="3" stitchTiles="stitch"/></filter><rect width="100%" height="100%" filter="url(%23noiseFilter)"/></svg>');
  }

  .ch-grid {
    position: absolute; inset: 0; z-index: 0; pointer-events: none; opacity: 0.5;
    background-size: 60px 60px;
    background-image:
      linear-gradient(to right, color-mix(in oklch, var(--fg) 5%, transparent) 1px, transparent 1px),
      linear-gradient(to bottom, color-mix(in oklch, var(--fg) 5%, transparent) 1px, transparent 1px);
    mask-image: radial-gradient(ellipse at center, black 0%, transparent 70%);
    -webkit-mask-image: radial-gradient(ellipse at center, black 0%, transparent 70%);
  }

  /* Hero text — outside card */
  .ch-hero-text-wrapper {
    position: absolute; z-index: 10;
    display: flex; flex-direction: column;
    align-items: center; justify-content: center; text-align: center;
    width: 100vw; padding: 0 16px;
    will-change: transform;
    transform-style: preserve-3d;
  }
  .ch-text-3d-matte {
    color: var(--fg);
    font-family: var(--font-display);
    font-weight: 400;
    font-size: clamp(48px, 9vw, 128px);
    line-height: 0.95;
    letter-spacing: -0.025em;
    margin: 0 0 0.05em;
    text-wrap: balance;
    text-shadow:
      0 10px 30px color-mix(in oklch, var(--fg) 20%, transparent),
      0 2px 4px color-mix(in oklch, var(--fg) 10%, transparent);
  }
  .ch-text-silver-matte {
    font-family: var(--font-display);
    font-weight: 400;
    font-style: italic;
    font-size: clamp(48px, 9vw, 128px);
    line-height: 0.95;
    letter-spacing: -0.03em;
    margin: 0;
    text-wrap: balance;
    background: linear-gradient(180deg, var(--fg) 0%, color-mix(in oklch, var(--fg) 40%, transparent) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    transform: translateZ(0);
    filter:
      drop-shadow(0 10px 20px color-mix(in oklch, var(--accent) 25%, transparent))
      drop-shadow(0 2px 4px color-mix(in oklch, var(--fg) 10%, transparent));
  }

  /* Inside card — hardcoded silver/white for the dark blue background */
  .ch-text-card-silver-matte {
    background: linear-gradient(180deg, #FFFFFF 0%, #A1A1AA 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    transform: translateZ(0);
    filter:
      drop-shadow(0 12px 24px rgba(0,0,0,0.8))
      drop-shadow(0 4px 8px rgba(0,0,0,0.6));
  }

  /* Eyebrow above tagline */
  .ch-eyebrow {
    font-family: var(--font-mono);
    font-size: 10px;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: rgba(107, 163, 214, 0.4);
    margin-bottom: 28px;
    display: inline-flex; align-items: center; gap: 24px;
    flex-wrap: wrap; justify-content: center;
  }
  .ch-eyebrow .dot {
    width: 6px; height: 6px; border-radius: 50%;
    background: #22c55e;
    box-shadow: 0 0 10px rgba(34, 197, 94, 0.7);
    animation: chPulse 2s infinite;
  }
  .ch-eyebrow-text { white-space: nowrap; }
  .ch-eyebrow-mark {
    color: rgba(107, 163, 214, 0.7);
    letter-spacing: 0.22em;
    font-weight: 500;
    white-space: nowrap;
  }

  /* Premium card */
  .ch-card-wrap {
    position: absolute; inset: 0; z-index: 20;
    display: flex; align-items: center; justify-content: center;
    pointer-events: none;
    perspective: 1500px;
  }
  .ch-main-card {
    position: relative;
    overflow: hidden;
    display: flex; align-items: center; justify-content: center;
    pointer-events: auto;
    width: 92vw; height: 92vh;
    border-radius: 32px;
    background: linear-gradient(145deg, #162C6D 0%, #0A101D 100%);
    box-shadow:
      0 40px 100px -20px rgba(0,0,0,0.9),
      0 20px 40px -20px rgba(0,0,0,0.8),
      inset 0 1px 2px rgba(255,255,255,0.2),
      inset 0 -2px 4px rgba(0,0,0,0.8);
    border: 1px solid rgba(255,255,255,0.04);
  }
  @media (min-width: 768px) {
    .ch-main-card { width: 85vw; height: 85vh; border-radius: 40px; }
  }

  .ch-card-sheen {
    position: absolute; inset: 0; border-radius: inherit;
    pointer-events: none; z-index: 50;
    background: radial-gradient(800px circle at var(--mouse-x, 50%) var(--mouse-y, 50%), rgba(255,255,255,0.06) 0%, transparent 40%);
    mix-blend-mode: screen; transition: opacity 0.3s ease;
  }

  .ch-card-grid {
    position: relative;
    width: 100%; height: 100%;
    max-width: 1280px;
    margin: 0 auto;
    padding: 24px 16px;
    display: flex; flex-direction: column;
    justify-content: space-evenly;
    align-items: center;
    z-index: 10;
  }
  @media (min-width: 1024px) {
    .ch-card-grid {
      display: grid;
      grid-template-columns: 1fr 1.1fr 1fr;
      gap: 32px;
      padding: 24px 48px;
    }
  }

  .ch-brand-col {
    order: 1; display: flex; justify-content: center;
    width: 100%; z-index: 20;
  }
  @media (min-width: 1024px) {
    .ch-brand-col { order: 3; justify-content: flex-end; }
  }
  .ch-brand-name {
    font-family: var(--font-display);
    font-weight: 900;
    font-style: italic;
    text-transform: uppercase;
    letter-spacing: -0.04em;
    font-size: clamp(64px, 14vw, 160px);
    margin: 0;
    line-height: 0.85;
  }

  .ch-mockup-wrapper {
    order: 2;
    position: relative;
    width: 100%; height: 380px;
    display: flex; align-items: center; justify-content: center;
    z-index: 10;
    perspective: 1000px;
  }
  @media (min-width: 1024px) {
    .ch-mockup-wrapper { height: 600px; }
  }
  .ch-mockup-inner {
    position: relative;
    width: 100%; height: 100%;
    display: flex; align-items: center; justify-content: center;
    transform: scale(0.7);
  }
  @media (min-width: 768px)  { .ch-mockup-inner { transform: scale(0.85); } }
  @media (min-width: 1024px) { .ch-mockup-inner { transform: scale(1); } }

  /* iPhone bezel */
  .ch-iphone {
    position: relative;
    width: 280px; height: 580px;
    border-radius: 3rem;
    background-color: #111;
    box-shadow:
      inset 0 0 0 2px #52525B,
      inset 0 0 0 7px #000,
      0 40px 80px -15px rgba(0,0,0,0.9),
      0 15px 25px -5px rgba(0,0,0,0.7);
    transform-style: preserve-3d;
    will-change: transform;
    display: flex; flex-direction: column;
  }

  .ch-hardware-btn {
    position: absolute;
    background: linear-gradient(90deg, #404040 0%, #171717 100%);
    box-shadow:
      -2px 0 5px rgba(0,0,0,0.8),
      inset -1px 0 1px rgba(255,255,255,0.15),
      inset 1px 0 2px rgba(0,0,0,0.8);
    border-left: 1px solid rgba(255,255,255,0.05);
    z-index: 0;
  }

  .ch-screen {
    position: absolute; inset: 7px;
    background: #050914;
    border-radius: 2.5rem;
    overflow: hidden;
    box-shadow: inset 0 0 15px rgba(0,0,0,1);
    color: #fff;
    z-index: 10;
  }
  .ch-screen-glare {
    position: absolute; inset: 0; z-index: 40; pointer-events: none;
    background: linear-gradient(110deg, rgba(255,255,255,0.08) 0%, rgba(255,255,255,0) 45%);
  }
  .ch-island {
    position: absolute;
    top: 5px; left: 50%; transform: translateX(-50%);
    width: 100px; height: 28px;
    background: #000; border-radius: 999px;
    z-index: 50;
    display: flex; align-items: center; justify-content: flex-end;
    padding: 0 12px;
    box-shadow: inset 0 -1px 2px rgba(255,255,255,0.1);
  }
  .ch-island-dot {
    width: 6px; height: 6px; border-radius: 50%;
    background: #22C55E;
    box-shadow: 0 0 8px rgba(34,197,94,0.8);
    animation: chPulse 2s infinite;
  }
  @keyframes chPulse { 0%,100% { opacity: 1; } 50% { opacity: 0.4; } }

  .ch-app {
    position: relative;
    width: 100%; height: 100%;
    padding: 44px 16px 28px;
    display: flex; flex-direction: column;
  }

  /* PrintTrack header */
  .ch-pt-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 0 4px 14px;
    border-bottom: 1px solid rgba(107, 163, 214, 0.08);
    margin-bottom: 14px;
  }
  .ch-pt-brand {
    font-family: var(--font-mono);
    font-size: 11px;
    font-weight: 500;
    color: #c8ddf0;
    letter-spacing: 0.14em;
    text-transform: uppercase;
  }
  .ch-pt-count {
    font-family: var(--font-mono);
    font-size: 10px;
    font-weight: 500;
    color: rgba(200, 221, 240, 0.55);
    letter-spacing: 0.06em;
  }
  .ch-pt-count [data-counter] {
    font-family: var(--font-display);
    font-style: italic;
    font-size: 18px;
    color: #fff;
    letter-spacing: -0.02em;
    margin-right: 4px;
  }

  /* Stage pills row */
  .ch-pt-pills {
    display: flex; gap: 6px;
    margin-bottom: 14px;
  }
  .ch-pt-pill {
    flex: 1;
    border-radius: 10px;
    border: 1px solid;
    padding: 7px 4px 6px;
    text-align: center;
    box-shadow: inset 0 1px 1px rgba(255,255,255,0.04);
  }
  .ch-pt-pill-label {
    font-family: var(--font-mono);
    font-size: 8px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin-bottom: 2px;
    opacity: 0.85;
  }
  .ch-pt-pill-count {
    font-family: var(--font-display);
    font-style: italic;
    font-size: 18px;
    color: #fff;
    line-height: 1;
    letter-spacing: -0.02em;
  }

  /* Order cards */
  .ch-pt-cards {
    display: flex; flex-direction: column; gap: 8px;
  }
  .ch-pt-card {
    display: flex; align-items: center; justify-content: space-between;
    padding: 10px 12px;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid rgba(107, 163, 214, 0.06);
    box-shadow:
      0 4px 12px rgba(0,0,0,0.25),
      inset 0 1px 1px rgba(255,255,255,0.03);
  }
  .ch-pt-card-left {
    display: flex; flex-direction: column; gap: 2px;
    min-width: 0;
  }
  .ch-pt-card-name {
    font-size: 11px; font-weight: 600;
    color: rgba(255, 255, 255, 0.92);
    letter-spacing: -0.01em;
  }
  .ch-pt-card-item {
    font-family: var(--font-mono);
    font-size: 9px;
    color: rgba(200, 221, 240, 0.45);
    letter-spacing: 0.04em;
  }
  .ch-pt-card-right {
    display: flex; flex-direction: column; align-items: flex-end; gap: 4px;
  }
  .ch-pt-card-price {
    font-family: var(--font-display);
    font-style: italic;
    font-size: 14px;
    color: #c8ddf0;
    letter-spacing: -0.02em;
    line-height: 1;
  }
  .ch-pt-card-stage {
    font-family: var(--font-mono);
    font-size: 8px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    padding: 2px 7px;
    border-radius: 999px;
    border: 1px solid;
  }
  .ch-home-indicator {
    position: absolute; bottom: 8px; left: 50%; transform: translateX(-50%);
    width: 120px; height: 4px;
    background: rgba(255,255,255,0.2);
    border-radius: 999px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.5);
  }

  /* Floating glass badges */
  .ch-floating-badge {
    position: absolute;
    display: flex; align-items: center;
    padding: 12px;
    border-radius: 14px;
    background: linear-gradient(135deg, rgba(255,255,255,0.08) 0%, rgba(255,255,255,0.01) 100%);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    box-shadow:
      0 0 0 1px rgba(255,255,255,0.1),
      0 25px 50px -12px rgba(0,0,0,0.8),
      inset 0 1px 1px rgba(255,255,255,0.2),
      inset 0 -1px 1px rgba(0,0,0,0.5);
    gap: 12px;
    z-index: 30;
  }
  @media (min-width: 1024px) {
    .ch-floating-badge { padding: 16px; gap: 16px; border-radius: 18px; }
  }
  .ch-badge-icon {
    width: 32px; height: 32px;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    box-shadow: inset 0 1px 2px rgba(255,255,255,0.08);
  }
  @media (min-width: 1024px) { .ch-badge-icon { width: 40px; height: 40px; } }
  .ch-badge-icon.blue {
    background: linear-gradient(180deg, rgba(59,130,246,0.2) 0%, rgba(30,58,138,0.1) 100%);
    border: 1px solid rgba(96,165,250,0.3);
    color: #60A5FA;
  }
  .ch-badge-icon.indigo {
    background: linear-gradient(180deg, rgba(99,102,241,0.2) 0%, rgba(49,46,129,0.1) 100%);
    border: 1px solid rgba(129,140,248,0.3);
    color: #818CF8;
  }
  .ch-badge-icon svg { width: 16px; height: 16px; }
  .ch-badge-emoji {
    font-size: 16px;
    line-height: 1;
    filter: drop-shadow(0 1px 2px rgba(0,0,0,0.5));
  }
  @media (min-width: 1024px) { .ch-badge-emoji { font-size: 20px; } }
  .ch-badge-title {
    color: #fff; font-size: 11px; font-weight: 700;
    letter-spacing: -0.01em; line-height: 1.2;
  }
  @media (min-width: 1024px) { .ch-badge-title { font-size: 13px; } }
  .ch-badge-meta {
    color: rgba(180,200,255,0.5);
    font-size: 9px;
    font-family: var(--font-mono);
    letter-spacing: 0.02em;
    margin-top: 2px;
  }
  @media (min-width: 1024px) { .ch-badge-meta { font-size: 10px; } }
  .ch-badge-top-left   { top: 24px; left: -15px; }
  .ch-badge-bottom-right { bottom: 48px; right: -15px; }
  @media (min-width: 1024px) {
    .ch-badge-top-left     { top: 48px;  left: -80px; }
    .ch-badge-bottom-right { bottom: 80px; right: -80px; }
  }

  /* Left text col */
  .ch-left-text {
    order: 3;
    display: flex; flex-direction: column;
    text-align: center;
    z-index: 20;
    width: 100%;
    padding: 0 16px;
  }
  @media (min-width: 1024px) {
    .ch-left-text {
      order: 1; text-align: left;
      max-width: none; padding: 0;
    }
  }
  .ch-card-heading {
    color: #fff;
    font-family: var(--font-display);
    font-weight: 400;
    font-style: italic;
    font-size: clamp(24px, 3.4vw, 40px);
    letter-spacing: -0.02em;
    line-height: 1.05;
    margin: 0 0 16px;
    text-wrap: balance;
  }
  .ch-card-desc {
    color: rgba(180,200,255,0.7);
    font-size: 14px;
    line-height: 1.55;
    font-weight: 400;
    margin: 0 auto;
    max-width: 360px;
    display: none;
    text-wrap: pretty;
  }
  @media (min-width: 768px) {
    .ch-card-desc { display: block; font-size: 15px; max-width: 380px; }
  }
  @media (min-width: 1024px) {
    .ch-card-desc { font-size: 16px; max-width: none; margin: 0; }
  }
  .ch-card-stat-row {
    display: none;
  }
  @media (min-width: 1024px) {
    .ch-card-stat-row {
      display: flex; gap: 28px; margin-top: 28px;
    }
    .ch-card-stat .num {
      font-family: var(--font-display);
      font-style: italic;
      font-size: 28px;
      color: var(--accent, #99c5ff);
      letter-spacing: -0.02em;
    }
    .ch-card-stat .lbl {
      font-family: var(--font-mono);
      font-size: 10px;
      color: rgba(180,200,255,0.6);
      text-transform: uppercase;
      letter-spacing: 0.1em;
      margin-top: 4px;
    }
  }

  /* CTA wrapper */
  .ch-cta-wrapper {
    position: absolute; z-index: 10;
    display: flex; flex-direction: column;
    align-items: center; justify-content: center; text-align: center;
    width: 100vw; padding: 0 16px;
    pointer-events: auto;
    will-change: transform;
  }
  .ch-cta-heading {
    font-family: var(--font-display);
    font-weight: 400;
    font-size: clamp(36px, 6.5vw, 88px);
    letter-spacing: -0.025em;
    margin: 0 0 24px;
    text-wrap: balance;
    line-height: 1.0;
  }
  .ch-cta-heading .it { font-style: italic; }
  .ch-cta-desc {
    color: var(--mute);
    font-size: clamp(15px, 1.4vw, 19px);
    font-weight: 300;
    line-height: 1.55;
    margin: 0 auto 48px;
    max-width: 580px;
    text-wrap: pretty;
  }
  .ch-cta-actions {
    display: flex; flex-direction: column;
    gap: 16px;
  }
  @media (min-width: 640px) {
    .ch-cta-actions { flex-direction: row; gap: 20px; }
  }

  /* CTA pill buttons */
  .ch-btn {
    display: inline-flex; align-items: center; justify-content: center;
    padding: 14px 26px;
    border-radius: 999px;
    text-decoration: none;
    transition: all 0.4s cubic-bezier(0.25,1,0.5,1);
    cursor: pointer;
    font-family: var(--font-body);
    font-size: 15px;
    font-weight: 600;
    letter-spacing: -0.01em;
    line-height: 1;
  }
  .ch-btn-primary {
    background: linear-gradient(135deg, #6BA3D6 0%, #8baac8 100%);
    color: #0B0E18;
    box-shadow:
      0 0 0 1px rgba(107,163,214,0.2),
      0 12px 24px -4px rgba(107,163,214,0.25);
  }
  .ch-btn-primary:hover {
    transform: translateY(-2px);
    box-shadow:
      0 0 0 1px rgba(107,163,214,0.3),
      0 18px 32px -6px rgba(107,163,214,0.35);
  }
  .ch-btn-ghost {
    background: transparent;
    color: #8A8880;
    border: 1px solid rgba(255,255,255,0.06);
    font-weight: 500;
  }
  .ch-btn-ghost:hover {
    transform: translateY(-2px);
    color: #6BA3D6;
    border-color: rgba(107,163,214,0.3);
  }

  /* CTA footer meta */
  .ch-cta-footer-meta {
    margin-top: 36px;
    display: inline-flex; align-items: center;
    flex-wrap: wrap; justify-content: center;
    gap: 28px;
    font-family: var(--font-mono);
    font-size: 11px;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: rgba(107,163,214,0.3);
  }
`;

// ── PrintTrack pipeline mockup ───────────────────────────
const PT_STAGES = [
  { label: "Recv",   count: 5, color: "#64748b" },
  { label: "Quoted", count: 5, color: "#eab308" },
  { label: "Paid",   count: 5, color: "#22c55e" },
  { label: "Prod",   count: 4, color: "#f97316" },
  { label: "Ready",  count: 1, color: "#3b82f6" },
];

const PT_ORDERS = [
  { name: "Evelyn M.",   item: "Magnet × 1",       price: "$137.50", stage: "Paid",     color: "#22c55e" },
  { name: "Marcus C.",   item: "Flyers × 1000",    price: "$110.00", stage: "Paid",     color: "#22c55e" },
  { name: "Jonathan A.", item: "Banner × 1",       price: "$330.00", stage: "Quoted",   color: "#eab308" },
  { name: "Sofia R.",    item: "Retractable × 2",  price: "$180.00", stage: "In Prod.", color: "#f97316" },
];

function CRMScreen() {
  return (
    <div className="ch-screen">
      <div className="ch-screen-glare" aria-hidden="true" />
      <div className="ch-island">
        <div className="ch-island-dot" aria-hidden="true" />
      </div>
      <div className="ch-app">
        <div className="phone-widget ch-pt-header">
          <div className="ch-pt-brand">PrintTrack</div>
          <div className="ch-pt-count">
            <span data-counter>0</span> orders
          </div>
        </div>

        <div className="phone-widget ch-pt-pills">
          {PT_STAGES.map((s) => (
            <div
              key={s.label}
              className="ch-pt-pill"
              style={{
                background: s.color + "1a",
                borderColor: s.color + "33",
              }}
            >
              <div className="ch-pt-pill-label" style={{ color: s.color }}>{s.label}</div>
              <div className="ch-pt-pill-count">{s.count}</div>
            </div>
          ))}
        </div>

        <div className="ch-pt-cards">
          {PT_ORDERS.map((o) => (
            <div className="phone-widget ch-pt-card" key={o.name}>
              <div className="ch-pt-card-left">
                <div className="ch-pt-card-name">{o.name}</div>
                <div className="ch-pt-card-item">{o.item}</div>
              </div>
              <div className="ch-pt-card-right">
                <div className="ch-pt-card-price">{o.price}</div>
                <div
                  className="ch-pt-card-stage"
                  style={{
                    color: o.color,
                    background: o.color + "1a",
                    borderColor: o.color + "33",
                  }}
                >
                  {o.stage}
                </div>
              </div>
            </div>
          ))}
        </div>

        <div className="ch-home-indicator" aria-hidden="true" />
      </div>
    </div>
  );
}

function CinematicHero({
  brandName = "IAMAI",
  eyebrow = "Miami · Q3 '26 builds open",
  tagline1 = "We build the system",
  tagline2 = "your shop is missing.",
  cardHeading = "Your shop deserves better than WhatsApp.",
  cardDescription = "Dashboard, client portal, automations — custom-built around how your business actually works. Ibrahim visits your shop. Oussama builds your system. Live in days. From $799.",
  metricValue = 20,
  metricLabel = "Active orders",
  ctaHeading = "Show us what's slowing you down.",
  ctaHeadingItalic = "Let's fix it.",
  ctaDescription = "A free visit. No commitment. Ibrahim comes to your shop, sees what's broken, and shows you what a system would look like. You decide.",
}) {
  const containerRef = useRef(null);
  const mainCardRef  = useRef(null);
  const mockupRef    = useRef(null);
  const requestRef   = useRef(0);

  // Mouse interaction (sheen + parallax)
  useEffect(() => {
    const handleMouseMove = (e) => {
      if (window.scrollY > window.innerHeight * 2) return;
      cancelAnimationFrame(requestRef.current);
      requestRef.current = requestAnimationFrame(() => {
        if (mainCardRef.current && mockupRef.current) {
          const rect = mainCardRef.current.getBoundingClientRect();
          mainCardRef.current.style.setProperty("--mouse-x", `${e.clientX - rect.left}px`);
          mainCardRef.current.style.setProperty("--mouse-y", `${e.clientY - rect.top}px`);
          const xVal = (e.clientX / window.innerWidth - 0.5) * 2;
          const yVal = (e.clientY / window.innerHeight - 0.5) * 2;
          window.gsap?.to(mockupRef.current, {
            rotationY: xVal * 12,
            rotationX: -yVal * 12,
            ease: "power3.out",
            duration: 1.2,
          });
        }
      });
    };
    window.addEventListener("mousemove", handleMouseMove);
    return () => {
      window.removeEventListener("mousemove", handleMouseMove);
      cancelAnimationFrame(requestRef.current);
    };
  }, []);

  // Cinematic scroll timeline
  useEffect(() => {
    if (!window.gsap || !window.ScrollTrigger) return;
    const gsap = window.gsap;
    gsap.registerPlugin(window.ScrollTrigger);

    const isMobile = window.innerWidth < 768;

    const ctx = gsap.context(() => {
      gsap.set(".ch-text-track", { autoAlpha: 0, y: 60, scale: 0.85, filter: "blur(20px)", rotationX: -20 });
      gsap.set(".ch-text-days",  { autoAlpha: 1, clipPath: "inset(0 100% 0 0)" });
      gsap.set(".ch-eyebrow",    { autoAlpha: 0, y: 20 });
      gsap.set(".ch-main-card",  { y: window.innerHeight + 200, autoAlpha: 1 });
      gsap.set([".ch-left-text", ".ch-brand-col", ".ch-mockup-wrapper", ".ch-floating-badge", ".phone-widget"], { autoAlpha: 0 });
      gsap.set(".ch-cta-wrapper", { autoAlpha: 0, scale: 0.8, filter: "blur(30px)" });

      // Intro
      const introTl = gsap.timeline({ delay: 0.3 });
      introTl
        .to(".ch-eyebrow",    { duration: 1.0, autoAlpha: 1, y: 0, ease: "power2.out" }, 0)
        .to(".ch-text-track", { duration: 1.8, autoAlpha: 1, y: 0, scale: 1, filter: "blur(0px)", rotationX: 0, ease: "expo.out" }, 0.1)
        .to(".ch-text-days",  { duration: 1.4, clipPath: "inset(0 0% 0 0)", ease: "power4.inOut" }, "-=1.0");

      // Scroll-pinned timeline
      const scrollTl = gsap.timeline({
        scrollTrigger: {
          trigger: containerRef.current,
          start: "top top",
          end: "+=7000",
          pin: true,
          scrub: 1,
          anticipatePin: 1,
        },
      });

      scrollTl
        .to([".ch-hero-text-wrapper", ".ch-grid"], { scale: 1.15, filter: "blur(20px)", opacity: 0.2, ease: "power2.inOut", duration: 2 }, 0)
        .to(".ch-main-card", { y: 0, ease: "power3.inOut", duration: 2 }, 0)
        .to(".ch-main-card", { width: "100%", height: "100%", borderRadius: "0px", ease: "power3.inOut", duration: 1.5 })
        .fromTo(".ch-mockup-wrapper",
          { y: 300, z: -500, rotationX: 50, rotationY: -30, autoAlpha: 0, scale: 0.6 },
          { y: 0, z: 0, rotationX: 0, rotationY: 0, autoAlpha: 1, scale: 1, ease: "expo.out", duration: 2.5 }, "-=0.8"
        )
        .fromTo(".phone-widget", { y: 40, autoAlpha: 0, scale: 0.95 }, { y: 0, autoAlpha: 1, scale: 1, stagger: 0.15, ease: "back.out(1.2)", duration: 1.5 }, "-=1.5")
        .to(".ch-progress-ring", { strokeDashoffset: 60, duration: 2, ease: "power3.inOut" }, "-=1.2")
        .to("[data-counter]", { innerHTML: metricValue, snap: { innerHTML: 1 }, duration: 2, ease: "expo.out" }, "-=2.0")
        .fromTo(".ch-floating-badge", { y: 100, autoAlpha: 0, scale: 0.7, rotationZ: -10 }, { y: 0, autoAlpha: 1, scale: 1, rotationZ: 0, ease: "back.out(1.5)", duration: 1.5, stagger: 0.2 }, "-=2.0")
        .fromTo(".ch-left-text", { x: -50, autoAlpha: 0 }, { x: 0, autoAlpha: 1, ease: "power4.out", duration: 1.5 }, "-=1.5")
        .fromTo(".ch-brand-col", { x: 50, autoAlpha: 0, scale: 0.8 }, { x: 0, autoAlpha: 1, scale: 1, ease: "expo.out", duration: 1.5 }, "<")
        .to({}, { duration: 2.5 })
        .set(".ch-hero-text-wrapper", { autoAlpha: 0 })
        .set(".ch-cta-wrapper", { autoAlpha: 1 })
        .to({}, { duration: 1.5 })
        .to([".ch-mockup-wrapper", ".ch-floating-badge", ".ch-left-text", ".ch-brand-col"], {
          scale: 0.9, y: -40, z: -200, autoAlpha: 0, ease: "power3.in", duration: 1.2, stagger: 0.05,
        })
        .to(".ch-main-card", {
          width:  isMobile ? "92vw" : "85vw",
          height: isMobile ? "92vh" : "85vh",
          borderRadius: isMobile ? "32px" : "40px",
          ease: "expo.inOut", duration: 1.8,
        }, "pullback")
        .to(".ch-cta-wrapper", { scale: 1, filter: "blur(0px)", ease: "expo.inOut", duration: 1.8 }, "pullback")
        .to(".ch-main-card", { y: -window.innerHeight - 300, ease: "power3.in", duration: 1.5 });
    }, containerRef);

    return () => ctx.revert();
  }, [metricValue]);

  return (
    <div ref={containerRef} className="ch-root">
      <style dangerouslySetInnerHTML={{ __html: CINEMATIC_INJECTED_STYLES }} />
      <div className="ch-grain" aria-hidden="true" />
      <div className="ch-grid" aria-hidden="true" />

      {/* Hero text */}
      <div className="ch-hero-text-wrapper">
        <div className="ch-eyebrow ch-gsap-reveal">
          <span className="dot" aria-hidden="true" />
          <span className="ch-eyebrow-text">{eyebrow}</span>
          <span className="ch-eyebrow-mark">I · AM · AI</span>
          <span className="ch-eyebrow-text">Custom software for shops</span>
        </div>
        <h1 className="ch-text-track ch-text-3d-matte ch-gsap-reveal">{tagline1}</h1>
        <h1 className="ch-text-days ch-text-silver-matte ch-gsap-reveal">{tagline2}</h1>
      </div>

      {/* CTA layer (revealed at end of scroll) */}
      <div className="ch-cta-wrapper ch-gsap-reveal">
        <h2 className="ch-cta-heading ch-text-silver-matte">
          {ctaHeading} <span className="it">{ctaHeadingItalic}</span>
        </h2>
        <p className="ch-cta-desc">{ctaDescription}</p>
        <div className="ch-cta-actions">
          <a href="#contact" className="ch-btn ch-btn-primary" aria-label="Book a free visit">
            Book a free visit →
          </a>
          <a
            href="https://wa.me/17739394430"
            target="_blank"
            rel="noopener noreferrer"
            className="ch-btn ch-btn-ghost"
            aria-label="WhatsApp us"
          >
            WhatsApp us
          </a>
        </div>
        <div className="ch-cta-footer-meta" aria-hidden="false">
          <span>Miami · EN / ES</span>
          <span>Response &lt; 24h</span>
          <span>By a founder</span>
        </div>
      </div>

      {/* Premium card */}
      <div className="ch-card-wrap" aria-hidden="false">
        <div ref={mainCardRef} className="ch-main-card ch-gsap-reveal">
          <div className="ch-card-sheen" aria-hidden="true" />

          <div className="ch-card-grid">
            {/* Brand */}
            <div className="ch-brand-col ch-gsap-reveal">
              <h2 className="ch-brand-name ch-text-card-silver-matte">{brandName}</h2>
            </div>

            {/* iPhone mockup */}
            <div className="ch-mockup-wrapper">
              <div className="ch-mockup-inner">
                <div ref={mockupRef} className="ch-iphone">
                  <div className="ch-hardware-btn" style={{ top: 120, left: -3, width: 3, height: 25, borderRadius: "4px 0 0 4px" }} aria-hidden="true" />
                  <div className="ch-hardware-btn" style={{ top: 160, left: -3, width: 3, height: 45, borderRadius: "4px 0 0 4px" }} aria-hidden="true" />
                  <div className="ch-hardware-btn" style={{ top: 220, left: -3, width: 3, height: 45, borderRadius: "4px 0 0 4px" }} aria-hidden="true" />
                  <div className="ch-hardware-btn" style={{ top: 170, right: -3, width: 3, height: 70, borderRadius: "0 4px 4px 0", transform: "scaleX(-1)" }} aria-hidden="true" />

                  <CRMScreen />
                </div>

                <div className="ch-floating-badge ch-badge-top-left">
                  <div className="ch-badge-icon blue" aria-hidden="true">
                    <span className="ch-badge-emoji">📦</span>
                  </div>
                  <div>
                    <div className="ch-badge-title">Order Ready</div>
                    <div className="ch-badge-meta">Customer notified</div>
                  </div>
                </div>

                <div className="ch-floating-badge ch-badge-bottom-right">
                  <div className="ch-badge-icon indigo" aria-hidden="true">
                    <span className="ch-badge-emoji">✅</span>
                  </div>
                  <div>
                    <div className="ch-badge-title">Invoice Paid</div>
                    <div className="ch-badge-meta">$330.00 collected</div>
                  </div>
                </div>
              </div>
            </div>

            {/* Left text col */}
            <div className="ch-left-text ch-gsap-reveal">
              <h3 className="ch-card-heading">{cardHeading}</h3>
              <p className="ch-card-desc">{cardDescription}</p>
              <div className="ch-card-stat-row">
                <div className="ch-card-stat">
                  <div className="num">2 days</div>
                  <div className="lbl">to first ship</div>
                </div>
                <div className="ch-card-stat">
                  <div className="num">8 weeks</div>
                  <div className="lbl">first module live</div>
                </div>
                <div className="ch-card-stat">
                  <div className="num">$0</div>
                  <div className="lbl">per-seat fee</div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  );
}

window.CinematicHero = CinematicHero;
