// Hero: Pathrule desktop app mockup, auto-tab rotation
const { useState, useEffect, useRef, useMemo } = React;

// ──────────────────────────────────────────────────────────────
// Lucide icons — inline SVG paths from lucide.dev
// ──────────────────────────────────────────────────────────────
const Icon = ({ children, size = 14, stroke = 1.6, color = 'currentColor', style }) => (
  <svg
    width={size} height={size} viewBox="0 0 24 24"
    fill="none" stroke={color} strokeWidth={stroke}
    strokeLinecap="round" strokeLinejoin="round"
    style={{ flexShrink: 0, display: 'inline-block', ...style }}
  >
    {children}
  </svg>
);

const Search         = (p) => <Icon {...p}><circle cx="11" cy="11" r="8"/><path d="m21 21-4.3-4.3"/></Icon>;
const ChevronDown    = (p) => <Icon {...p}><path d="m6 9 6 6 6-6"/></Icon>;
const ChevronRight   = (p) => <Icon {...p}><path d="m9 18 6-6-6-6"/></Icon>;
const ChevronsUpDown = (p) => <Icon {...p}><path d="m7 15 5 5 5-5"/><path d="m7 9 5-5 5 5"/></Icon>;
const Settings2      = (p) => <Icon {...p}><path d="M20 7h-9"/><path d="M14 17H5"/><circle cx="17" cy="17" r="3"/><circle cx="7" cy="7" r="3"/></Icon>;
const Plus           = (p) => <Icon {...p}><path d="M5 12h14"/><path d="M12 5v14"/></Icon>;
const Hash           = (p) => <Icon {...p}><line x1="4" y1="9" x2="20" y2="9"/><line x1="4" y1="15" x2="20" y2="15"/><line x1="10" y1="3" x2="8" y2="21"/><line x1="16" y1="3" x2="14" y2="21"/></Icon>;
const Folder         = (p) => <Icon {...p}><path d="M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.7-.9l-.8-1.2A2 2 0 0 0 7.9 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2z"/></Icon>;
const FolderOpen     = (p) => <Icon {...p}><path d="m6 14 1.5-2.9A2 2 0 0 1 9.24 10H20a2 2 0 0 1 1.94 2.5l-1.54 6a2 2 0 0 1-1.95 1.5H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h3.9a2 2 0 0 1 1.69.9l.81 1.2a2 2 0 0 0 1.67.9H18a2 2 0 0 1 2 2v2"/></Icon>;
const FileIcon       = (p) => <Icon {...p}><path d="M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7z"/><path d="M14 2v4a2 2 0 0 0 2 2h4"/></Icon>;
const Clock          = (p) => <Icon {...p}><circle cx="12" cy="12" r="10"/><polyline points="12 6 12 12 16 14"/></Icon>;
// Tab icons (matching the attached screenshots)
const PanelTop       = (p) => <Icon {...p}><rect width="18" height="18" x="3" y="3" rx="2"/><path d="M3 9h18"/></Icon>; // Summary
const Columns2       = (p) => <Icon {...p}><rect width="18" height="18" x="3" y="3" rx="2"/><path d="M12 3v18"/></Icon>; // Memories
const Scale          = (p) => <Icon {...p}><path d="M12 3v18"/><path d="m19 8 3 8a5 5 0 0 1-6 0zV7"/><path d="M3 7h1a17 17 0 0 0 8-2 17 17 0 0 0 8 2h1"/><path d="m5 8 3 8a5 5 0 0 1-6 0zV7"/><path d="M7 21h10"/></Icon>; // Rules
const SparklesIcon   = (p) => <Icon {...p}><path d="M11.017 2.814a1 1 0 0 1 1.966 0l1.051 5.558a2 2 0 0 0 1.594 1.594l5.558 1.051a1 1 0 0 1 0 1.966l-5.558 1.051a2 2 0 0 0-1.594 1.594l-1.051 5.558a1 1 0 0 1-1.966 0l-1.051-5.558a2 2 0 0 0-1.594-1.594l-5.558-1.051a1 1 0 0 1 0-1.966l5.558-1.051a2 2 0 0 0 1.594-1.594z"/><path d="M20 2v4"/><path d="M22 4h-4"/><circle cx="4" cy="20" r="2"/></Icon>; // Skills
const Shield         = (p) => <Icon {...p}><path d="M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z"/></Icon>; // Permissions
const GithubIcon     = (p) => <Icon {...p}><path d="M15 22v-4a4.8 4.8 0 0 0-1-3.5c3 0 6-2 6-5.5.08-1.25-.27-2.48-1-3.5.28-1.15.28-2.35 0-3.5 0 0-1 0-3 1.5-2.64-.5-5.36-.5-8 0C6 2 5 2 5 2c-.3 1.15-.3 2.35 0 3.5A5.403 5.403 0 0 0 4 9c0 3.5 3 5.5 6 5.5-.39.49-.68 1.05-.85 1.65-.17.6-.22 1.23-.15 1.85v4"/><path d="M9 18c-4.51 2-5-2-7-2"/></Icon>;
const BookOpen       = (p) => <Icon {...p}><path d="M12 7v14"/><path d="M3 18a1 1 0 0 1-1-1V4a1 1 0 0 1 1-1h5a4 4 0 0 1 4 4 4 4 0 0 1 4-4h5a1 1 0 0 1 1 1v13a1 1 0 0 1-1 1h-6a3 3 0 0 0-3 3 3 3 0 0 0-3-3z"/></Icon>;

// ──────────────────────────────────────────────────────────────
// App Mockup — cycles through Summary → Memories → Rules
// ──────────────────────────────────────────────────────────────
function AppMockup() {
  const TAB_ORDER = ['Memories', 'Rules', 'Skills'];
  const [tabIdx, setTabIdx] = useState(0); // start on Memories
  const [tick, setTick] = useState(0);

  // Auto-rotate
  useEffect(() => {
    const id = setInterval(() => {
      setTabIdx(i => (i + 1) % TAB_ORDER.length);
      setTick(t => t + 1);
    }, 4800);
    return () => clearInterval(id);
  }, []);

  const activeTab = TAB_ORDER[tabIdx];

  const tabs = [
    { name: 'Memories', icon: BookOpen },
    { name: 'Rules',    icon: Scale },
    { name: 'Skills',   icon: SparklesIcon },
  ];

  const tree = [
    { name: '.claude',   type: 'dir',  depth: 1 },
    { name: 'apps',      type: 'dir',  depth: 1, open: true },
    { name: 'web',       type: 'dir',  depth: 2, open: true },
    { name: 'checkout',  type: 'dir',  depth: 3, active: true, open: true },
    { name: 'cart.tsx',     type: 'file', depth: 4 },
    { name: 'payment.tsx',  type: 'file', depth: 4 },
    { name: 'services',  type: 'dir',  depth: 1 },
    { name: 'packages',  type: 'dir',  depth: 1 },
    { name: 'README.md', type: 'file', depth: 1 },
  ];

  return (
    <div className="app-mockup" style={{
      position: 'relative', width: '100%', maxWidth: 1080, margin: '0 auto',
      borderRadius: 12, overflow: 'hidden',
      border: '1px solid var(--border)',
      background: 'hsl(0 0% 6%)',
      boxShadow: '0 40px 80px -20px rgb(0 0 0 / 0.6), 0 0 0 1px hsl(0 0% 14%)',
      textAlign: 'left',
    }}>
      {/* title bar */}
      <div className="mock-titlebar" style={{
        height: 40, display: 'flex', alignItems: 'center',
        padding: '0 14px', borderBottom: '1px solid hsl(0 0% 12%)',
        background: 'hsl(0 0% 7%)', gap: 14,
      }}>
        <div style={{ display: 'flex', gap: 6 }}>
          <span style={{ width: 11, height: 11, borderRadius: 6, background: '#ff5f57' }} />
          <span style={{ width: 11, height: 11, borderRadius: 6, background: '#febc2e' }} />
          <span style={{ width: 11, height: 11, borderRadius: 6, background: '#28c840' }} />
        </div>
        <div className="mock-title-text" style={{ fontSize: 12.5, color: 'var(--foreground)', fontWeight: 500, letterSpacing: '-0.01em' }}>Pathrule</div>
        <div className="mock-search" style={{
          flex: 1, maxWidth: 380, margin: '0 auto',
          height: 24, borderRadius: 6,
          background: 'hsl(0 0% 10%)', border: '1px solid hsl(0 0% 14%)',
          display: 'flex', alignItems: 'center', padding: '0 10px', gap: 8,
          fontSize: 11.5, color: 'hsl(0 0% 42%)', fontFamily: 'var(--font-mono)',
        }}>
          <Search size={12} color="hsl(0 0% 45%)" />
          Search memories, rules, skills
        </div>
        <div style={{ display: 'flex', alignItems: 'center', gap: 12, marginLeft: 'auto', fontSize: 11, fontFamily: 'var(--font-mono)', color: 'var(--muted-foreground)' }}>
          <span className="mock-status-mcp" style={{ display: 'inline-flex', alignItems: 'center', gap: 6 }}>
            <span style={{ width: 7, height: 7, borderRadius: 4, background: 'hsl(152 60% 52%)' }} />
            MCP ready
          </span>
          <span className="mock-share" style={{
            padding: '4px 12px', borderRadius: 5,
            background: 'hsl(212 92% 58%)', color: 'white',
            fontSize: 11, fontWeight: 600, letterSpacing: 0.2,
          }}>Share</span>
        </div>
      </div>

      {/* body */}
      <div className="mock-body" style={{ display: 'grid', gridTemplateColumns: '180px 220px 1fr', minHeight: 520 }}>
        {/* sidebar */}
        <aside className="mock-sidebar" style={{
          borderRight: '1px solid hsl(0 0% 12%)',
          padding: '14px 10px', background: 'hsl(0 0% 5.5%)',
          display: 'flex', flexDirection: 'column', gap: 2, textAlign: 'left',
        }}>
          <div style={{
            display: 'flex', alignItems: 'center', gap: 8,
            padding: '6px 8px', borderRadius: 6,
            border: '1px solid hsl(0 0% 12%)', marginBottom: 16,
          }}>
            <div style={{
              width: 22, height: 22, borderRadius: 4,
              background: 'hsl(212 92% 58% / 0.18)',
              border: '1px solid hsl(212 92% 58% / 0.3)',
              display: 'inline-flex', alignItems: 'center', justifyContent: 'center',
              fontSize: 10, color: 'hsl(212 92% 70%)', fontWeight: 600,
            }}>MR</div>
            <div style={{ flex: 1, minWidth: 0 }}>
              <div style={{ fontSize: 11.5, color: 'var(--foreground)', whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis' }}>Mira's Workspace</div>
            </div>
            <ChevronDown size={11} color="hsl(0 0% 45%)" />
          </div>

          <div className="mono" style={{
            fontSize: 9.5, letterSpacing: '0.12em', textTransform: 'uppercase',
            color: 'hsl(0 0% 40%)', padding: '4px 8px', marginBottom: 4,
            display: 'flex', justifyContent: 'space-between', alignItems: 'center',
          }}>
            <span>Workspaces</span>
            <Plus size={11} color="hsl(0 0% 45%)" />
          </div>

          <div style={{
            padding: '8px 10px', borderRadius: 6,
            background: 'hsl(0 0% 10%)', border: '1px solid hsl(0 0% 14%)',
          }}>
            <div style={{ fontSize: 12, color: 'var(--foreground)' }}>acme-shop</div>
            <div className="mono" style={{ fontSize: 10, color: 'hsl(0 0% 40%)', marginTop: 2 }}>acme/acme-shop</div>
          </div>

          <div style={{ marginTop: 10, display: 'flex', flexDirection: 'column', gap: 10, padding: '0 10px' }}>
            {[0, 1].map(i => (
              <div key={i} style={{ opacity: 0.35 }}>
                <div style={{ height: 10, width: '62%', background: 'hsl(0 0% 14%)', borderRadius: 3, marginBottom: 4 }} />
                <div style={{ height: 7, width: '42%', background: 'hsl(0 0% 11%)', borderRadius: 3 }} />
              </div>
            ))}
          </div>
        </aside>

        {/* tree */}
        <div className="mock-tree" style={{
          borderRight: '1px solid hsl(0 0% 12%)',
          background: 'hsl(0 0% 5%)',
          display: 'flex', flexDirection: 'column', textAlign: 'left',
        }}>
          <div style={{
            height: 34, padding: '0 14px',
            display: 'flex', alignItems: 'center', justifyContent: 'space-between',
            borderBottom: '1px solid hsl(0 0% 12%)',
            fontFamily: 'var(--font-mono)', fontSize: 10.5, letterSpacing: '0.1em',
            color: 'hsl(0 0% 45%)', textTransform: 'uppercase',
          }}>
            <span>Tree</span>
            <span style={{ display: 'inline-flex', gap: 10, alignItems: 'center', color: 'hsl(0 0% 50%)' }}>
              <Hash size={12} />
              <ChevronsUpDown size={12} />
              <Settings2 size={12} />
            </span>
          </div>
          <div style={{ padding: '8px 0', flex: 1 }}>
            <div style={{
              padding: '5px 14px', fontSize: 12,
              color: 'var(--foreground)', fontFamily: 'var(--font-mono)',
              display: 'flex', alignItems: 'center', gap: 6,
            }}>
              <ChevronDown size={11} color="hsl(0 0% 50%)" />
              <FolderOpen size={13} color="hsl(212 92% 68%)" />
              <span>acme-shop</span>
            </div>
            {tree.map((n, i) => (
              <div key={i} style={{
                padding: `5px ${14 + n.depth * 14}px`,
                fontSize: 12, fontFamily: 'var(--font-mono)',
                color: n.active ? 'hsl(212 92% 72%)' : 'hsl(0 0% 62%)',
                background: n.active ? 'hsl(212 92% 58% / 0.1)' : 'transparent',
                borderLeft: n.active ? '2px solid hsl(212 92% 58%)' : '2px solid transparent',
                display: 'flex', alignItems: 'center', gap: 6,
              }}>
                <span style={{ width: 11, display: 'inline-flex', alignItems: 'center', color: n.active ? 'hsl(212 92% 70%)' : 'hsl(0 0% 40%)' }}>
                  {n.type === 'dir'
                    ? (n.open ? <ChevronDown size={10}/> : <ChevronRight size={10}/>)
                    : null}
                </span>
                {n.type === 'dir'
                  ? (n.open
                      ? <FolderOpen size={12} color={n.active ? 'hsl(212 92% 70%)' : 'hsl(0 0% 55%)'} />
                      : <Folder size={12} color={n.active ? 'hsl(212 92% 70%)' : 'hsl(0 0% 55%)'} />)
                  : <FileIcon size={12} color={'hsl(0 0% 45%)'} />}
                <span>{n.name}</span>
              </div>
            ))}
          </div>
        </div>

        {/* node detail */}
        <div className="mock-detail" style={{ background: 'hsl(0 0% 5%)', display: 'flex', flexDirection: 'column', minWidth: 0, textAlign: 'left' }}>
          {/* crumb */}
          <div className="mock-crumb" style={{
            height: 36, padding: '0 18px',
            display: 'flex', alignItems: 'center', justifyContent: 'space-between',
            borderBottom: '1px solid hsl(0 0% 12%)',
            fontSize: 12.5, color: 'var(--foreground)', fontFamily: 'var(--font-mono)',
          }}>
            <span style={{ display: 'inline-flex', alignItems: 'center', gap: 8 }}>
              <Folder size={13} color="hsl(212 92% 68%)" />
              <span style={{ color: 'hsl(0 0% 60%)' }}>apps</span>
              <span style={{ color: 'hsl(0 0% 30%)' }}>/</span>
              <span style={{ color: 'hsl(0 0% 60%)' }}>web</span>
              <span style={{ color: 'hsl(0 0% 30%)' }}>/</span>
              <span style={{ color: 'hsl(212 92% 70%)' }}>checkout</span>
            </span>
            <Clock size={13} color="hsl(0 0% 45%)" />
          </div>

          {/* tabs */}
          <div className="mock-tabs" style={{
            display: 'flex', gap: 2, padding: '6px 14px 0',
            borderBottom: '1px solid hsl(0 0% 12%)',
            position: 'relative',
          }}>
            {tabs.map((t, i) => {
              const IC = t.icon;
              const isActive = t.name === activeTab;
              return (
                <div key={t.name} className="mock-tab" style={{
                  padding: '8px 12px', fontSize: 12,
                  color: isActive ? 'var(--foreground)' : 'hsl(0 0% 52%)',
                  position: 'relative',
                  marginBottom: -1, letterSpacing: '-0.01em',
                  display: 'inline-flex', alignItems: 'center', gap: 7,
                  transition: 'color .25s ease',
                }}>
                  <IC size={13} color={isActive ? 'hsl(212 92% 68%)' : 'currentColor'} stroke={1.8} />
                  {t.name}
                  {isActive && <span style={{
                    position: 'absolute', left: 0, right: 0, bottom: -1, height: 2,
                    background: 'hsl(212 92% 58%)', borderRadius: 1,
                    animation: 'tabInk .35s ease both',
                  }}/>}
                </div>
              );
            })}
          </div>

          {/* content panel */}
          <div key={activeTab + ':' + tick} className="mock-panel" style={{
            padding: '20px 22px', flex: 1, display: 'flex', flexDirection: 'column',
            animation: 'tabContent .45s ease both',
          }}>
            {activeTab === 'Memories' && <MemoriesView tick={tick} />}
            {activeTab === 'Rules'    && <RulesView tick={tick} />}
            {activeTab === 'Skills'   && <SkillsView tick={tick} />}
          </div>
        </div>
      </div>

      <style>{`
        @keyframes tabInk {
          from { transform: scaleX(0); opacity: 0; }
          to   { transform: scaleX(1); opacity: 1; }
        }
        @keyframes tabContent {
          from { opacity: 0; transform: translateY(6px); }
          to   { opacity: 1; transform: translateY(0); }
        }
        @keyframes stagger {
          from { opacity: 0; transform: translateY(8px); }
          to   { opacity: 1; transform: translateY(0); }
        }
        @keyframes pulseGlow {
          0%, 100% { box-shadow: 0 0 0 3px hsl(212 92% 58% / 0.04); }
          50%      { box-shadow: 0 0 0 6px hsl(212 92% 58% / 0.08); }
        }
        @keyframes numberPop {
          from { transform: translateY(4px); opacity: 0; }
          to   { transform: translateY(0); opacity: 1; }
        }
        @keyframes drawLine {
          from { stroke-dashoffset: 200; }
          to   { stroke-dashoffset: 0; }
        }
      `}</style>
    </div>
  );
}

// ──────────────────────────────────────────────────────────────
// Memories view
// ──────────────────────────────────────────────────────────────
function MemoriesView() {
  const focused = {
    title: 'Checkout Field Map',
    body: 'Coupons live on lineItem, never on total. Legacy total.coupon field is a no-op; existing data kept for analytics only. Do not write to it.',
    author: 'MR', color: 'hsl(212 92% 58%)',
    updated: 'updated 2 days ago',
  };
  const skeletons = [
    { c: 'hsl(152 60% 52%)' }, { c: 'hsl(35 92% 58%)' }, { c: 'hsl(280 60% 65%)' },
  ];

  return (
    <>
      <div className="mock-panel-header" style={{ display: 'flex', alignItems: 'flex-start', justifyContent: 'space-between', marginBottom: 18 }}>
        <div>
          <div style={{ fontSize: 16, letterSpacing: '-0.01em', color: 'var(--foreground)', fontWeight: 500 }}>Memories</div>
          <div style={{ fontSize: 12, color: 'hsl(0 0% 50%)', marginTop: 3 }}>What Claude should remember for this node</div>
        </div>
        <button style={btnSm()}>
          <Plus size={12} color="hsl(0 0% 70%)" />
          New memory
        </button>
      </div>

      <div style={{ display: 'flex', flexDirection: 'column', gap: 8 }}>
        <div style={{
          padding: '14px 16px', borderRadius: 8,
          background: 'hsl(0 0% 8%)',
          border: '1px solid hsl(212 92% 58% / 0.3)',
          display: 'flex', alignItems: 'flex-start', gap: 14,
          animation: 'stagger .5s ease both, pulseGlow 3s ease-in-out .6s infinite',
        }}>
          <div style={{ flex: 1, minWidth: 0 }}>
            <div style={{ display: 'flex', alignItems: 'center', gap: 10, marginBottom: 6 }}>
              <BookOpen size={13} color="hsl(212 92% 68%)" stroke={1.8} />
              <div style={{ fontSize: 13, color: 'var(--foreground)', fontWeight: 500 }}>{focused.title}</div>
              <span className="mono" style={{
                fontSize: 9.5, color: 'hsl(212 92% 70%)',
                background: 'hsl(212 92% 58% / 0.12)',
                border: '1px solid hsl(212 92% 58% / 0.25)',
                padding: '1px 6px', borderRadius: 3, letterSpacing: '0.04em',
              }}>MEMORY</span>
            </div>
            <div style={{ fontSize: 12, color: 'hsl(0 0% 68%)', lineHeight: 1.55 }}>{focused.body}</div>
            <div className="mono" style={{ fontSize: 10, color: 'hsl(0 0% 40%)', marginTop: 8, letterSpacing: '0.04em', display: 'inline-flex', alignItems: 'center', gap: 5 }}>
              <Clock size={10} color="hsl(0 0% 40%)" />
              {focused.updated}
            </div>
          </div>
          <div style={avatarStyle(focused.color, focused.author)}>{focused.author}</div>
        </div>

        {skeletons.map((s, i) => (
          <div key={i} style={{
            padding: '14px 16px', borderRadius: 8,
            background: 'hsl(0 0% 6.5%)',
            border: '1px solid hsl(0 0% 11%)',
            display: 'flex', alignItems: 'flex-start', gap: 14,
            opacity: 0.55,
            animation: `stagger .55s ease ${0.15 + i * 0.08}s both`,
          }}>
            <div style={{ flex: 1, minWidth: 0 }}>
              <div style={{ display: 'flex', alignItems: 'center', gap: 8, marginBottom: 9 }}>
                <div style={{ width: 13, height: 13, borderRadius: 3, background: 'hsl(0 0% 14%)' }} />
                <div style={{ height: 10, width: `${[48, 42, 55][i]}%`, background: 'hsl(0 0% 14%)', borderRadius: 3 }} />
              </div>
              <div style={{ height: 7, width: '95%', background: 'hsl(0 0% 11%)', borderRadius: 3, marginBottom: 5 }} />
              <div style={{ height: 7, width: `${[78, 72, 84][i]}%`, background: 'hsl(0 0% 11%)', borderRadius: 3 }} />
            </div>
            <div style={skeletonAvatar(s.c)} />
          </div>
        ))}
      </div>
    </>
  );
}

// ──────────────────────────────────────────────────────────────
// Rules view
// ──────────────────────────────────────────────────────────────
function RulesView() {
  const focused = {
    title: 'Coupons only on lineItem',
    body: 'Never write coupon values to order.total. All discount logic must live on the lineItem. Violations block the commit.',
    level: 'HIGH', scope: 'PROJECT',
    author: 'MR', color: 'hsl(0 72% 55%)',
    updated: 'updated today',
  };
  const skeletons = [
    { c: 'hsl(280 60% 65%)', lvl: 'HIGH',   lvlColor: 'hsl(0 72% 55%)' },
    { c: 'hsl(152 60% 52%)', lvl: 'MEDIUM', lvlColor: 'hsl(35 92% 58%)' },
    { c: 'hsl(212 92% 58%)', lvl: 'HIGH',   lvlColor: 'hsl(0 72% 55%)' },
  ];

  return (
    <>
      <div className="mock-panel-header" style={{ display: 'flex', alignItems: 'flex-start', justifyContent: 'space-between', marginBottom: 18 }}>
        <div>
          <div style={{ fontSize: 16, letterSpacing: '-0.01em', color: 'var(--foreground)', fontWeight: 500 }}>Rules</div>
          <div style={{ fontSize: 12, color: 'hsl(0 0% 50%)', marginTop: 3 }}>Hard constraints Claude must follow in this scope</div>
        </div>
        <button style={btnSm()}>
          <Plus size={12} color="hsl(0 0% 70%)" />
          New rule
        </button>
      </div>

      <div style={{ display: 'flex', flexDirection: 'column', gap: 8 }}>
        <div style={{
          padding: '14px 16px', borderRadius: 8,
          background: 'hsl(0 0% 8%)',
          border: '1px solid hsl(0 72% 55% / 0.32)',
          display: 'flex', alignItems: 'flex-start', gap: 14,
          animation: 'stagger .5s ease both',
        }}>
          <div style={{ flex: 1, minWidth: 0 }}>
            <div style={{ display: 'flex', alignItems: 'center', gap: 10, marginBottom: 6, flexWrap: 'wrap' }}>
              <Scale size={13} color="hsl(0 72% 62%)" stroke={1.8} />
              <div style={{ fontSize: 13, color: 'var(--foreground)', fontWeight: 500 }}>{focused.title}</div>
              <span className="mono" style={levelPill('hsl(0 72% 55%)')}>{focused.level}</span>
              <span className="mono" style={scopePill()}>{focused.scope}</span>
            </div>
            <div style={{ fontSize: 12, color: 'hsl(0 0% 68%)', lineHeight: 1.55 }}>{focused.body}</div>
            <div className="mono" style={{ fontSize: 10, color: 'hsl(0 0% 40%)', marginTop: 8, letterSpacing: '0.04em', display: 'inline-flex', alignItems: 'center', gap: 5 }}>
              <Clock size={10} color="hsl(0 0% 40%)" />
              {focused.updated}
            </div>
          </div>
          <div style={avatarStyle(focused.color, focused.author)}>{focused.author}</div>
        </div>

        {skeletons.map((s, i) => (
          <div key={i} style={{
            padding: '14px 16px', borderRadius: 8,
            background: 'hsl(0 0% 6.5%)',
            border: '1px solid hsl(0 0% 11%)',
            display: 'flex', alignItems: 'flex-start', gap: 14,
            opacity: 0.55,
            animation: `stagger .55s ease ${0.15 + i * 0.08}s both`,
          }}>
            <div style={{ flex: 1, minWidth: 0 }}>
              <div style={{ display: 'flex', alignItems: 'center', gap: 8, marginBottom: 9 }}>
                <div style={{ width: 13, height: 13, borderRadius: 3, background: 'hsl(0 0% 14%)' }} />
                <div style={{ height: 10, width: `${[45, 52, 40][i]}%`, background: 'hsl(0 0% 14%)', borderRadius: 3 }} />
                <div style={{ height: 9, width: 28, background: `${s.lvlColor.replace(')', ' / 0.15)')}`, border: `1px solid ${s.lvlColor.replace(')', ' / 0.3)')}`, borderRadius: 3 }} />
                <div style={{ height: 9, width: 36, background: 'hsl(0 0% 13%)', borderRadius: 3 }} />
              </div>
              <div style={{ height: 7, width: '95%', background: 'hsl(0 0% 11%)', borderRadius: 3, marginBottom: 5 }} />
              <div style={{ height: 7, width: `${[78, 62, 82][i]}%`, background: 'hsl(0 0% 11%)', borderRadius: 3 }} />
            </div>
            <div style={skeletonAvatar(s.c)} />
          </div>
        ))}
      </div>
    </>
  );
}

// ──────────────────────────────────────────────────────────────
// Skills view
// ──────────────────────────────────────────────────────────────
function SkillsView() {
  const focused = {
    title: 'Stripe webhook replay',
    body: 'Replay failed webhooks from dashboard with idempotency key preserved. Use scripts/replay-webhook.ts; requires STRIPE_CLI_TOKEN env.',
    tag: 'SKILL', scope: 'PROJECT',
    author: 'MR', color: 'hsl(280 60% 65%)',
    updated: 'updated 4 days ago',
  };
  const skeletons = [
    { c: 'hsl(212 92% 58%)', source: 'github' },
    { c: 'hsl(152 60% 52%)', source: 'manual' },
    { c: 'hsl(35 92% 58%)',  source: 'github' },
  ];

  return (
    <>
      <div className="mock-panel-header" style={{ display: 'flex', alignItems: 'flex-start', justifyContent: 'space-between', marginBottom: 18 }}>
        <div>
          <div style={{ fontSize: 16, letterSpacing: '-0.01em', color: 'var(--foreground)', fontWeight: 500 }}>Skills</div>
          <div style={{ fontSize: 12, color: 'hsl(0 0% 50%)', marginTop: 3 }}>Procedures Claude can invoke on demand</div>
        </div>
        <div className="mock-panel-header-actions" style={{ display: 'inline-flex', gap: 6 }}>
          <button style={btnSm()}>
            <GithubIcon size={12} color="hsl(0 0% 70%)" />
            From GitHub
          </button>
          <button style={btnSm()}>
            <Plus size={12} color="hsl(0 0% 70%)" />
            New skill
          </button>
        </div>
      </div>

      <div style={{ display: 'flex', flexDirection: 'column', gap: 8 }}>
        <div style={{
          padding: '14px 16px', borderRadius: 8,
          background: 'hsl(0 0% 8%)',
          border: '1px solid hsl(280 60% 65% / 0.32)',
          display: 'flex', alignItems: 'flex-start', gap: 14,
          animation: 'stagger .5s ease both',
        }}>
          <div style={{ flex: 1, minWidth: 0 }}>
            <div style={{ display: 'flex', alignItems: 'center', gap: 10, marginBottom: 6, flexWrap: 'wrap' }}>
              <SparklesIcon size={13} color="hsl(280 60% 70%)" stroke={1.8} />
              <div style={{ fontSize: 13, color: 'var(--foreground)', fontWeight: 500 }}>{focused.title}</div>
              <span className="mono" style={levelPill('hsl(280 60% 65%)')}>{focused.tag}</span>
              <span className="mono" style={{
                ...scopePill(),
                display: 'inline-flex', alignItems: 'center', gap: 4,
                color: 'hsl(0 0% 70%)',
              }}>
                <GithubIcon size={9} color="hsl(0 0% 70%)" />
                GITHUB
              </span>
            </div>
            <div style={{ fontSize: 12, color: 'hsl(0 0% 68%)', lineHeight: 1.55 }}>{focused.body}</div>
            <div className="mono" style={{ fontSize: 10, color: 'hsl(0 0% 40%)', marginTop: 8, letterSpacing: '0.04em', display: 'inline-flex', alignItems: 'center', gap: 5 }}>
              <Clock size={10} color="hsl(0 0% 40%)" />
              {focused.updated}
            </div>
          </div>
          <div style={avatarStyle(focused.color, focused.author)}>{focused.author}</div>
        </div>

        {skeletons.map((s, i) => (
          <div key={i} style={{
            padding: '14px 16px', borderRadius: 8,
            background: 'hsl(0 0% 6.5%)',
            border: '1px solid hsl(0 0% 11%)',
            display: 'flex', alignItems: 'flex-start', gap: 14,
            opacity: 0.55,
            animation: `stagger .55s ease ${0.15 + i * 0.08}s both`,
          }}>
            <div style={{ flex: 1, minWidth: 0 }}>
              <div style={{ display: 'flex', alignItems: 'center', gap: 8, marginBottom: 9 }}>
                <div style={{ width: 13, height: 13, borderRadius: 3, background: 'hsl(0 0% 14%)' }} />
                <div style={{ height: 10, width: `${[50, 44, 58][i]}%`, background: 'hsl(0 0% 14%)', borderRadius: 3 }} />
                <div style={{ height: 9, width: 34, background: 'hsl(280 60% 65% / 0.15)', border: '1px solid hsl(280 60% 65% / 0.3)', borderRadius: 3 }} />
                {s.source === 'github' && (
                  <span style={{
                    display: 'inline-flex', alignItems: 'center', gap: 3,
                    padding: '1px 5px', borderRadius: 3,
                    background: 'hsl(0 0% 10%)', border: '1px solid hsl(0 0% 16%)',
                  }}>
                    <GithubIcon size={9} color="hsl(0 0% 55%)" />
                    <span style={{ height: 6, width: 24, background: 'hsl(0 0% 16%)', borderRadius: 2 }} />
                  </span>
                )}
              </div>
              <div style={{ height: 7, width: '95%', background: 'hsl(0 0% 11%)', borderRadius: 3, marginBottom: 5 }} />
              <div style={{ height: 7, width: `${[72, 66, 80][i]}%`, background: 'hsl(0 0% 11%)', borderRadius: 3 }} />
            </div>
            <div style={skeletonAvatar(s.c)} />
          </div>
        ))}
      </div>
    </>
  );
}

// ──────────────────────────────────────────────────────────────
// Summary view
// ──────────────────────────────────────────────────────────────
function SummaryView() {
  const tiles = [
    { val: '1,419', label: 'Rule reminded',  sub: 'times your rule was shown to the AI', color: 'hsl(152 60% 55%)', path: 'M0 22 L20 18 L40 23 L60 14 L80 20 L100 8 L120 15' },
    { val: '242',   label: 'Memory shown',   sub: 'times your memory was shown to us…',  color: 'hsl(212 92% 62%)', path: 'M0 20 L20 16 L40 22 L60 10 L80 14 L100 5  L120 12' },
    { val: '73%',   label: 'File-scoped info', sub: '142 / 195 files',                   color: 'hsl(35 92% 60%)',  path: 'M0 18 L20 20 L40 12 L60 16 L80 6  L100 12 L120 4' },
    { val: '64%',   label: 'Got it right first try', sub: '125 files, 70 revisits',      color: 'hsl(280 60% 65%)', path: 'M0 22 L20 14 L40 18 L60 8  L80 14 L100 6  L120 10' },
  ];

  return (
    <>
      {/* impact hero */}
      <div style={{
        position: 'relative', borderRadius: 10, overflow: 'hidden',
        padding: '22px 22px 20px',
        background: 'linear-gradient(180deg, hsl(0 0% 8%), hsl(0 0% 5%))',
        border: '1px solid hsl(0 0% 12%)',
        animation: 'stagger .5s ease both',
        marginBottom: 14,
      }}>
        <div style={{
          position: 'absolute', inset: 0,
          background: 'radial-gradient(ellipse 460px 200px at 100% 0%, hsl(212 92% 58% / 0.08), transparent 70%)',
          pointerEvents: 'none',
        }}/>
        <div className="mono" style={{ fontSize: 10, letterSpacing: '0.14em', textTransform: 'uppercase', color: 'hsl(0 0% 50%)', marginBottom: 12, display: 'inline-flex', alignItems: 'center', gap: 6 }}>
          <SparklesIcon size={10} color="hsl(212 92% 68%)" /> Pathrule · Impact Summary
        </div>
        <div style={{ display: 'flex', alignItems: 'flex-end', gap: 12 }}>
          <div style={{ fontSize: 48, fontWeight: 600, letterSpacing: '-0.03em', lineHeight: 1, fontVariantNumeric: 'tabular-nums', animation: 'numberPop .5s ease both' }}>
            1,661
          </div>
        </div>
        <div className="mono" style={{ fontSize: 10, letterSpacing: '0.12em', textTransform: 'uppercase', color: 'hsl(0 0% 50%)', marginTop: 8 }}>
          Reminders Delivered · Last 30 days
        </div>
        <div style={{ fontSize: 12, color: 'hsl(0 0% 62%)', marginTop: 10, lineHeight: 1.55 }}>
          In the last 30 days Pathrule reminded the AI <span style={{ color: 'var(--foreground)' }}>1,419 times</span> of your rules, <span style={{ color: 'var(--foreground)' }}>242 times</span> of your memories.
        </div>
        <div style={{ display: 'flex', flexWrap: 'wrap', gap: 6, marginTop: 12 }}>
          <Pill color="hsl(212 92% 58%)">242 memory reminders</Pill>
          <Pill color="hsl(152 60% 52%)">1,419 rule reminders</Pill>
          <Pill color="hsl(35 92% 58%)">73% files covered</Pill>
          <Pill color="hsl(280 60% 65%)">67% workspace coverage</Pill>
        </div>
      </div>

      {/* added this month strip */}
      <div style={{
        padding: '8px 16px', borderRadius: 999,
        background: 'hsl(0 0% 7%)', border: '1px solid hsl(0 0% 12%)',
        display: 'flex', alignItems: 'center', gap: 16, flexWrap: 'wrap',
        fontSize: 11,
        marginBottom: 14,
        animation: 'stagger .55s ease .1s both',
      }}>
        <span className="mono" style={{ color: 'hsl(0 0% 50%)', letterSpacing: '0.1em', textTransform: 'uppercase', fontSize: 9.5 }}>↗ Added this month</span>
        {[ [28, 58], [22, 50], [20, 54] ].map(([numW, labelW], i) => (
          <span key={i} style={{ display: 'inline-flex', alignItems: 'center', gap: 6, opacity: 0.55 }}>
            <span style={{ width: 6, height: 6, borderRadius: 1, background: 'hsl(0 0% 18%)' }} />
            <span style={{ height: 9, width: numW, background: 'hsl(0 0% 18%)', borderRadius: 2 }} />
            <span style={{ height: 7, width: labelW, background: 'hsl(0 0% 13%)', borderRadius: 2 }} />
          </span>
        ))}
      </div>

      {/* metric tiles — skeleton */}
      <div style={{ display: 'grid', gridTemplateColumns: 'repeat(4, 1fr)', gap: 10 }}>
        {tiles.map((t, i) => (
          <div key={t.label} style={{
            padding: 14, borderRadius: 10,
            background: 'hsl(0 0% 7%)', border: '1px solid hsl(0 0% 11%)',
            opacity: 0.55,
            animation: `stagger .55s ease ${0.15 + i * 0.07}s both`,
          }}>
            <div style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between', marginBottom: 10 }}>
              <div style={{
                width: 22, height: 22, borderRadius: 5,
                background: 'hsl(0 0% 12%)',
                border: '1px solid hsl(0 0% 14%)',
              }}/>
              <div style={{ width: 8, height: 8, borderRadius: 4, background: 'hsl(0 0% 14%)' }}/>
            </div>
            {/* value */}
            <div style={{ height: 18, width: `${[62, 42, 48, 48][i]}%`, background: 'hsl(0 0% 14%)', borderRadius: 4 }}/>
            {/* label */}
            <div style={{ height: 8, width: `${[72, 58, 78, 82][i]}%`, background: 'hsl(0 0% 12%)', borderRadius: 3, marginTop: 8 }}/>
            {/* sub */}
            <div style={{ height: 6, width: `${[55, 38, 62, 50][i]}%`, background: 'hsl(0 0% 10%)', borderRadius: 3, marginTop: 5 }}/>
            {/* sparkline */}
            <svg viewBox="0 0 120 28" width="100%" height="28" style={{ marginTop: 12, display: 'block' }}>
              <path d={t.path} fill="none" stroke="hsl(0 0% 18%)" strokeWidth="1.4" strokeLinecap="round" strokeLinejoin="round"
                style={{ strokeDasharray: 200, animation: 'drawLine .9s ease both' }} />
            </svg>
          </div>
        ))}
      </div>
    </>
  );
}

// ──────────────────────────────────────────────────────────────
// Shared small bits
// ──────────────────────────────────────────────────────────────
function Pill({ color, children }) {
  return (
    <span style={{
      display: 'inline-flex', alignItems: 'center', gap: 6,
      padding: '4px 10px', borderRadius: 999,
      background: `${color.replace(')', ' / 0.1)')}`,
      border: `1px solid ${color.replace(')', ' / 0.22)')}`,
      fontSize: 10.5, color: 'var(--foreground)',
    }}>
      <span style={{ width: 5, height: 5, borderRadius: 3, background: color }} />
      {children}
    </span>
  );
}

function AnimatedRing() {
  return (
    <svg width="14" height="14" viewBox="0 0 14 14" style={{ display: 'inline-block', verticalAlign: 'middle' }}>
      <circle cx="7" cy="7" r="5.5" fill="none" stroke="hsl(0 0% 20%)" strokeWidth="1.5" />
      <circle cx="7" cy="7" r="5.5" fill="none"
        stroke="hsl(212 92% 58%)" strokeWidth="1.5"
        strokeDasharray="18 100" strokeLinecap="round"
        style={{ transformOrigin: 'center', animation: 'spinRing 2s linear infinite' }} />
      <style>{`@keyframes spinRing { to { transform: rotate(360deg); } }`}</style>
    </svg>
  );
}

const btnSm = () => ({
  height: 28, padding: '0 12px', borderRadius: 6,
  background: 'hsl(0 0% 10%)', border: '1px solid hsl(0 0% 18%)',
  color: 'var(--foreground)', fontSize: 11.5, cursor: 'pointer',
  display: 'inline-flex', alignItems: 'center', gap: 6,
});

const avatarStyle = (color, label) => ({
  width: 26, height: 26, borderRadius: 13,
  background: `${color.replace(')', ' / 0.2)')}`,
  border: `1px solid ${color.replace(')', ' / 0.45)')}`,
  color: color, fontSize: 10, fontWeight: 600,
  display: 'inline-flex', alignItems: 'center', justifyContent: 'center',
  flexShrink: 0,
});

const skeletonAvatar = (color) => ({
  width: 26, height: 26, borderRadius: 13,
  background: `${color.replace(')', ' / 0.15)')}`,
  border: `1px solid ${color.replace(')', ' / 0.3)')}`,
  flexShrink: 0,
});

const levelPill = (color) => ({
  fontSize: 9.5, color: color,
  background: `${color.replace(')', ' / 0.14)')}`,
  border: `1px solid ${color.replace(')', ' / 0.3)')}`,
  padding: '1px 6px', borderRadius: 3, letterSpacing: '0.06em',
});

const scopePill = () => ({
  fontSize: 9.5, color: 'hsl(0 0% 60%)',
  background: 'hsl(0 0% 12%)',
  border: '1px solid hsl(0 0% 16%)',
  padding: '1px 6px', borderRadius: 3, letterSpacing: '0.06em',
});

// ──────────────────────────────────────────────────────────────
// Hero
// ──────────────────────────────────────────────────────────────
function Hero() {
  return (
    <section className="hero-section" style={{ position: 'relative', overflow: 'hidden', paddingTop: 88, paddingBottom: 120 }}>
      <div className="hero-bg" />
      <div className="hero-grid" />
<div className="container" style={{ position: 'relative', textAlign: 'center' }}>
        <div className="reveal in hero-eyebrow-chip" style={{ display: 'inline-flex', alignItems: 'center', gap: 10, padding: '5px 12px 5px 5px', borderRadius: 999, border: '1px solid var(--border)', background: 'var(--muted)', marginBottom: 28, fontSize: 12 }}>
          <span className="badge badge-success" style={{ borderRadius: 999 }}>Closed Beta</span>
          <span className="muted">Invitations rolling out weekly</span>
        </div>

        <h1 className="display reveal in" style={{ margin: '0 auto 24px' }}>
          Team knowledge,<br/>
          <span style={{ color: 'var(--muted-foreground)' }}>delivered to every AI session.</span>
        </h1>

        <p className="lede reveal in" style={{ margin: '0 auto 36px', textAlign: 'center' }}>
          Pathrule routes your team's memory, rules and skills into Claude Code, Cursor and Codex.
          Path-scoped, just-in-time, without context bloat. Claude shouldn't be smarter for one person than for the team.
        </p>

        <div className="reveal in hero-ctas" style={{ display: 'flex', gap: 10, justifyContent: 'center', marginBottom: 56, alignItems: 'center' }}>
          <a href="#waitlist" className="btn btn-primary btn-lg">Join the waitlist</a>
          <a href="#how" className="btn btn-outline btn-lg">See how it works</a>
        </div>

        <div className="reveal in">
          <AppMockup />
        </div>

        {/* logo strip */}
        <div className="hero-logo-strip" style={{ marginTop: 72, display: 'flex', flexDirection: 'column', alignItems: 'center', gap: 18 }}>
          <div className="mono" style={{ fontSize: 11, letterSpacing: '0.14em', textTransform: 'uppercase', color: 'var(--muted-foreground)', textAlign: 'center' }}>
            Works with the tools your team already uses
          </div>
          <div className="tools-row" style={{ display: 'flex', gap: 40, flexWrap: 'wrap', justifyContent: 'center', opacity: 0.85 }}>
            {['Claude Code', 'Cursor', 'Codex', 'Windsurf'].map(tool => (
              <div key={tool} style={{
                fontFamily: 'var(--font-mono)', fontSize: 13,
                color: 'var(--foreground)', letterSpacing: '-0.01em',
                display: 'inline-flex', alignItems: 'center', gap: 8,
              }}>
                <span style={{ width: 5, height: 5, borderRadius: 1, background: 'hsl(0 0% 40%)' }} />
                {tool}
              </div>
            ))}
          </div>
        </div>
      </div>
    </section>
  );
}

Object.assign(window, { Hero, AppMockup });
