/* global React */
const { useState: useStateS, useEffect: useEffectS } = React;

// ============== LOGO MARQUEE ==============
function LogoStrip() {
  const logos = [
    'Halberd Builders', 'Forge & Iron Co.', 'Meridian Drywall', 'Ash Carpentry',
    'Northpoint Concrete', 'Birch Mechanical', 'Stonecut Roofing', 'Lantern Electric',
    'Atlas Glazing', 'Veridian Civil',
  ];
  return (
    <section className="logo-strip section-sm">
      <div className="wrap">
        <div className="logo-strip-label mono">Used daily by independent contractors across the trades</div>
        <div className="logo-strip-rail">
          <div className="marquee-track">
            {[...logos, ...logos].map((l, i) => (
              <span className="logo-strip-item serif-it" key={i}>{l}</span>
            ))}
          </div>
        </div>
      </div>
      <style>{`
        .logo-strip { padding: 64px 0 56px; border-top: 1px solid color-mix(in srgb, var(--ink) 10%, transparent); }
        .logo-strip-label { font-size: 11px; color: var(--ink-mute); text-align: center; margin-bottom: 28px; }
        .logo-strip-rail { overflow: hidden; mask-image: linear-gradient(90deg, transparent, #000 12%, #000 88%, transparent); }
        .logo-strip-item {
          font-size: 28px; color: var(--ink-soft);
          opacity: 0.78;
          padding: 0 12px;
          white-space: nowrap;
        }
      `}</style>
    </section>
  );
}

// ============== VALUE BENTO ==============
function ValueBento() {
  return (
    <section id="benefits" className="section">
      <div className="wrap">
        <Reveal>
          <div className="bento-head">
            <Eyebrow>Why teams switch</Eyebrow>
            <h2 className="display bento-h2">
              Stop quoting at <span className="serif-it">the kitchen table.</span><br/>
              Start quoting on <span className="squiggle">the clock.</span>
            </h2>
            <p className="bento-sub">
              ProTakeoff strips out the bloat of legacy estimators. Five tools.
              Three exports. One keyboard. Built for the bid you need to send tonight.
            </p>
          </div>
        </Reveal>

        <div className="feature-rows">
          {[
            {
              tag: 'Precision',
              icon: <IconRuler size={14}/>,
              title: <>A tape measure that<br/><span className="serif-it">actually keeps up.</span></>,
              copy: 'Point-and-click areas, lengths, and counts with auto-snap, ortho lock, and the keyboard shortcuts your CAD-trained brain already knows.',
              bullets: ['Auto-snap & ortho lock', 'Keyboard-first hotkeys', 'Per-sheet calibration'],
              gif: 'assets/feature-precision.gif',
              alt: 'Live takeoff measurement on a floor plan',
            },
            {
              tag: 'AI Indexing',
              icon: <IconBolt size={14}/>,
              title: <>Sheet renaming<br/><span className="serif-it">in seconds.</span></>,
              copy: 'Drag in a 200-page PDF. ProTakeoff reads each title block and renames every page — A-201, A-301, S-100 — before your coffee cools.',
              bullets: ['Reads every title block', 'Auto-numbers in CSI order', 'Re-runnable on revisions'],
              gif: 'assets/feature-rename.gif',
              alt: 'AI batch-renaming PDF sheets',
            },
            {
              tag: 'Net Logic',
              icon: <IconScissors size={14}/>,
              title: <>Cutouts that math<br/><span className="serif-it">themselves.</span></>,
              copy: 'Punch as many windows, doors, and openings as you want into an area. The net square-footage updates the moment you click.',
              bullets: ['Nested cutouts', 'Live net SF', 'Audit trail per area'],
              gif: 'assets/feature-cutout.gif',
              alt: 'Cutouts subtracting from net area',
            },
            {
              tag: 'Overlay review',
              icon: <IconLayers size={14}/>,
              title: <>Compare drawing sets<br/><span className="serif-it">right on top.</span></>,
              copy: 'Compare revised drawing sets directly on top of your base plans. Blue + red overlays make scope changes easier to review before takeoff, pricing, or coordination.',
              bullets: ['Blue + red overlays', 'Opacity controls', 'Scope-change review'],
              video: 'assets/feature-overlay-comparison.mp4',
              videoRatio: '938 / 794',
              alt: 'Overlay comparison showing blue and red revised construction drawings',
            },
            {
              tag: 'Auto Count',
              icon: <IconCount size={14}/>,
              title: <>Instant takeoffs<br/><span className="serif-it">with AutoCount.</span></>,
              copy: 'Auto Count finds repeated symbols across the sheet, then routes each match through review and approval before it becomes a count point. Fast symbol takeoffs with a human check built in.',
              bullets: ['Instant symbol counts', 'Review + approve matches', 'Accepted takeoff points'],
              video: 'assets/autocount.mp4',
              videoRatio: '16 / 10',
              alt: 'Auto Count finding repeated symbols on a dark construction drawing',
            },
            {
              tag: 'Dark / Light',
              icon: <IconSparkle size={14}/>,
              title: <>Choose the mode<br/><span className="serif-it">that fits the job.</span></>,
              copy: 'Switch between dark and light workspaces when you need more contrast, less glare, or a cleaner plan view. The same tools stay exactly where your hands expect them.',
              bullets: ['Dark mode for low glare', 'Light mode for crisp plans', 'Same takeoff workflow'],
              video: 'assets/dark-light-mode-native.mp4',
              videoRatio: '21 / 16',
              alt: 'Switching ProTakeoff between dark and light mode workspaces',
            },
          ].map((f, i) => (
            <Reveal key={f.tag} delay={60}>
              <article className={`feature-row ${i % 2 === 1 ? 'is-flipped' : ''}`}>
                <div className="feature-copy">
                  <div className="feature-tag">
                    <span className="feature-icon">{f.icon}</span>
                    <span className="mono">{f.tag}</span>
                  </div>
                  <h3 className="serif feature-title">{f.title}</h3>
                  <p className="feature-body">{f.copy}</p>
                  <ul className="feature-bullets">
                    {f.bullets.map(b => (
                      <li key={b}><IconCheck size={12}/> <span className="mono">{b}</span></li>
                    ))}
                  </ul>
                </div>
                <div className="feature-media">
                  {f.visual || (f.video ? (
                    <video
                      src={f.video}
                      aria-label={f.alt}
                      autoPlay
                      muted
                      loop
                      playsInline
                      preload="metadata"
                      style={f.videoRatio ? { aspectRatio: f.videoRatio } : undefined}
                    />
                  ) : (
                    <img src={f.gif} alt={f.alt} loading="lazy"/>
                  ))}
                </div>
              </article>
            </Reveal>
          ))}
        </div>
      </div>

      <style>{`
        .bento-head { max-width: 760px; margin-bottom: 80px; }
        .bento-h2 {
          font-size: clamp(2.4rem, 6vw, 4.8rem);
          margin-top: 18px;
          color: var(--ink);
        }
        .bento-h2 .serif-it { color: var(--ink-soft); }
        .bento-sub { margin-top: 22px; max-width: 580px; font-size: 1.05rem; color: var(--ink-soft); font-weight: 500; line-height: 1.55; }

        .feature-rows { display: flex; flex-direction: column; gap: 96px; }

        .feature-row {
          display: grid;
          grid-template-columns: 1fr;
          gap: 32px;
          align-items: center;
        }
        @media (min-width: 880px) {
          .feature-row { grid-template-columns: minmax(0, 5fr) minmax(0, 7fr); gap: 64px; }
          .feature-row.is-flipped .feature-copy { order: 2; }
          .feature-row.is-flipped .feature-media { order: 1; }
        }

        .feature-copy { max-width: 460px; }
        .feature-tag {
          display: inline-flex; align-items: center; gap: 10px;
          margin-bottom: 22px;
        }
        .feature-tag .mono {
          font-size: 10px;
          color: var(--ink-mute);
          letter-spacing: 0.12em;
          text-transform: uppercase;
        }
        .feature-icon {
          width: 26px; height: 26px; border-radius: 999px;
          background: rgba(255,255,255,0.04);
          border: 1px solid rgba(255,255,255,0.08);
          display: inline-flex; align-items: center; justify-content: center;
          color: var(--ink);
        }
        html[data-theme="cream"] .feature-icon {
          background: var(--cream);
          border-color: color-mix(in srgb, var(--ink) 12%, transparent);
          color: var(--forest);
        }

        .feature-title {
          font-size: clamp(2rem, 3.6vw, 3.4rem);
          line-height: 1.02;
          color: var(--ink);
          margin-bottom: 20px;
          letter-spacing: -0.02em;
        }
        .feature-title .serif-it { color: var(--ink-soft); }

        .feature-body {
          font-size: 1.02rem;
          line-height: 1.6;
          color: var(--ink-soft);
          margin-bottom: 24px;
        }

        .feature-bullets {
          list-style: none;
          padding: 0;
          margin: 0;
          display: flex; flex-direction: column;
          gap: 10px;
          border-top: 1px solid color-mix(in srgb, var(--ink) 10%, transparent);
          padding-top: 18px;
        }
        .feature-bullets li {
          display: flex; align-items: center; gap: 10px;
          font-size: 11px;
          color: var(--ink-soft);
        }
        .feature-bullets li .mono {
          letter-spacing: 0.08em;
          text-transform: uppercase;
        }
        .feature-bullets li svg {
          color: var(--lime, var(--forest));
          flex-shrink: 0;
        }

        .feature-media {
          position: relative;
          border-radius: 12px;
          overflow: hidden;
          border: 1px solid rgba(255,255,255,0.08);
          background: #000;
          box-shadow: 0 30px 80px -30px rgba(0,0,0,0.6);
        }
        html[data-theme="cream"] .feature-media {
          border-color: var(--cream-border);
          background: var(--cream-soft);
          box-shadow: 0 24px 60px -28px rgba(26,26,26,0.18);
        }
        .feature-media::after {
          content: "";
          position: absolute; inset: 0;
          border-radius: inherit;
          box-shadow: inset 0 0 0 1px rgba(255,255,255,0.04);
          pointer-events: none;
        }
        .feature-media img,
        .feature-media video {
          display: block;
          width: 100%;
        }
        .feature-media img {
          height: auto;
        }
        .feature-media video {
          aspect-ratio: 16 / 10;
          height: auto;
          object-fit: contain;
        }
      `}</style>
    </section>
  );
}

function SpecCell({ label, value }) {
  return (
    <div className="spec-cell">
      <span className="mono">{label}</span>
      <span className="serif-it">{value}</span>
      <style>{`
        .spec-cell {
          flex: 1; min-width: 100px;
          padding: 12px 14px;
          background: var(--cream);
          border: 1px solid color-mix(in srgb, var(--ink) 10%, transparent);
          border-radius: 14px;
          display: flex; flex-direction: column; gap: 2px;
        }
        .spec-cell .mono { font-size: 9px; color: var(--ink-mute); }
        .spec-cell .serif-it { font-size: 22px; line-height: 1; color: var(--ink); }
      `}</style>
    </div>
  );
}

function AutoCountFeatureMock() {
  const markers = [
    [12, 22], [28, 16], [45, 17], [82, 14], [79, 24], [13, 40],
    [13, 57], [14, 73], [24, 80], [50, 80], [66, 70], [72, 69],
    [82, 39], [82, 58], [82, 72], [86, 82],
  ];
  const rows = [100, 99, 92, 92, 91, 90, 89, 89, 88, 88, 88, 88, 88, 87, 86, 86];

  return (
    <div className="autocount-feature" aria-label="Auto Count review with accepted symbol matches">
      <div className="autocount-plan">
        <svg viewBox="0 0 940 520" preserveAspectRatio="none">
          <defs>
            <pattern id="auto-hatch" width="18" height="18" patternUnits="userSpaceOnUse" patternTransform="rotate(45)">
              <path d="M0 0V18" stroke="rgba(255,255,255,0.12)" strokeWidth="1"/>
            </pattern>
            <filter id="count-glow" x="-80%" y="-80%" width="260%" height="260%">
              <feGaussianBlur stdDeviation="3.5" result="blur"/>
              <feMerge>
                <feMergeNode in="blur"/>
                <feMergeNode in="SourceGraphic"/>
              </feMerge>
            </filter>
          </defs>
          <rect width="940" height="520" fill="#020403"/>
          <path d="M78 58H436V420H78zM556 50h228v430H556z" fill="none" stroke="rgba(255,255,255,0.55)" strokeWidth="1.2"/>
          <path d="M105 92h304v72H105zM105 164h304M105 304h304M105 420h304M556 105h184M556 225h184M556 345h184" fill="none" stroke="rgba(255,255,255,0.22)" strokeWidth="1"/>
          <path d="M420 58h96v362h-96zM784 50h92v430h-92z" fill="url(#auto-hatch)" opacity="0.6"/>
          <path d="M72 58H32M72 164H32M72 304H32M72 420H32M436 26V58M556 26V50M784 26V50" stroke="rgba(255,255,255,0.24)" strokeDasharray="6 6"/>
          <path d="M330 360h92v60h-92zM352 378h44v26h-44" fill="none" stroke="rgba(255,255,255,0.32)" strokeWidth="1"/>
          <circle cx="470" cy="485" r="17" fill="none" stroke="rgba(255,255,255,0.75)" strokeWidth="2"/>
          {markers.map(([x, y], i) => (
            <g key={i} transform={`translate(${x * 9.4} ${y * 5.2})`} filter="url(#count-glow)">
              <rect x="-8" y="-8" width="16" height="16" rx="2" fill="#10D98B"/>
              <path d="M-3 0l3 3 6-7" fill="none" stroke="#022A1A" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"/>
            </g>
          ))}
        </svg>
        <div className="autocount-toolbar">
          <strong>Markups</strong>
          <span className="autocount-scale">1/4&quot; = 1&apos;0&quot;</span>
          <span className="autocount-mode"><i/> Count</span>
        </div>
      </div>

      <aside className="autocount-review">
        <div className="autocount-review-head">
          <span className="autocount-review-icon"><IconCount size={17}/></span>
          <div>
            <strong>Auto Count Review</strong>
            <p>Review current-page matches before recording them as count points.</p>
          </div>
        </div>
        <div className="autocount-review-body">
          <div className="autocount-sample">
            <span className="mono">Sample</span>
            <div className="autocount-symbol">
              <svg viewBox="0 0 74 88">
                <circle cx="37" cy="32" r="24" fill="none" stroke="#6B7280" strokeWidth="4"/>
                <path d="M37 8v48M25 56h24v25H25z" fill="none" stroke="#6B7280" strokeWidth="4"/>
              </svg>
            </div>
            <div className="autocount-threshold">
              <span className="mono">Threshold</span>
              <b>78%</b>
            </div>
            <div className="autocount-slider"><i/></div>
            <div className="autocount-stats">
              <span><b>16</b>Accept</span>
              <span><b>0</b>Review</span>
              <span><b>0</b>Reject</span>
            </div>
          </div>
          <div className="autocount-results">
            <p>Click canvas boxes to toggle accepted/rejected. Use row controls for the same review step.</p>
            <div className="autocount-result-list">
              {rows.map((pct, i) => (
                <div className="autocount-result" key={i}>
                  <span>#{i + 1}</span>
                  <i><IconCheck size={10}/></i>
                  <small>{pct}%</small>
                  <b>Accepted</b>
                </div>
              ))}
            </div>
          </div>
        </div>
      </aside>

      <style>{`
        .autocount-feature {
          position: relative;
          width: 100%;
          aspect-ratio: 16 / 9;
          min-height: 390px;
          background: #020403;
          color: #F5F5F5;
          overflow: hidden;
        }
        .autocount-plan {
          position: absolute;
          inset: 0;
          width: 64%;
          opacity: 0.92;
        }
        .autocount-plan svg {
          width: 100%;
          height: calc(100% - 56px);
        }
        .autocount-toolbar {
          position: absolute;
          left: 0;
          right: 0;
          bottom: 0;
          height: 56px;
          display: flex;
          align-items: center;
          gap: 14px;
          padding: 0 18px;
          background: #121214;
          border-top: 1px solid rgba(255,255,255,0.12);
          font-family: 'Inter', sans-serif;
          font-size: 13px;
        }
        .autocount-scale {
          padding: 9px 16px;
          border: 1px solid rgba(255,255,255,0.16);
          border-radius: 7px;
          background: #1A1A1D;
          font-weight: 700;
        }
        .autocount-mode {
          display: inline-flex;
          align-items: center;
          gap: 8px;
          color: #D4D4D8;
        }
        .autocount-mode i {
          width: 8px;
          height: 8px;
          border-radius: 999px;
          background: #12D891;
        }
        .autocount-review {
          position: absolute;
          top: 0;
          right: 0;
          bottom: 0;
          width: 46%;
          background: #1B1B1C;
          border-left: 1px solid rgba(255,255,255,0.12);
          box-shadow: -28px 0 60px rgba(0,0,0,0.42);
          font-family: 'Inter', sans-serif;
        }
        .autocount-review-head {
          display: flex;
          align-items: flex-start;
          gap: 14px;
          padding: 24px 26px;
          border-bottom: 1px solid rgba(255,255,255,0.1);
        }
        .autocount-review-icon {
          width: 36px;
          height: 36px;
          border-radius: 10px;
          display: inline-flex;
          align-items: center;
          justify-content: center;
          background: rgba(255,255,255,0.08);
          color: #E5E7EB;
          flex: 0 0 auto;
        }
        .autocount-review-head strong {
          display: block;
          font-size: clamp(16px, 1.6vw, 19px);
          line-height: 1.15;
          color: #FFFFFF;
        }
        .autocount-review-head p {
          margin: 7px 0 0;
          color: #B7B7BD;
          font-size: 12px;
          line-height: 1.35;
        }
        .autocount-review-body {
          display: grid;
          grid-template-columns: 36% 64%;
          height: calc(100% - 85px);
        }
        .autocount-sample {
          padding: 18px 18px 20px;
          border-right: 1px solid rgba(255,255,255,0.1);
        }
        .autocount-sample .mono,
        .autocount-threshold .mono {
          color: #A1A1AA;
          font-size: 10px;
        }
        .autocount-symbol {
          height: 118px;
          margin-top: 10px;
          border-radius: 9px;
          background: #050505;
          display: grid;
          place-items: center;
        }
        .autocount-symbol svg {
          width: 86px;
          height: 86px;
          border-radius: 7px;
          background: #F8F8F8;
        }
        .autocount-threshold {
          margin-top: 18px;
          display: flex;
          align-items: center;
          justify-content: space-between;
          color: #BDBDC4;
          font-size: 11px;
        }
        .autocount-slider {
          height: 5px;
          margin-top: 9px;
          border-radius: 999px;
          background: rgba(255,255,255,0.12);
          position: relative;
        }
        .autocount-slider i {
          position: absolute;
          left: 72%;
          top: 50%;
          width: 16px;
          height: 16px;
          border-radius: 999px;
          background: #FFFFFF;
          transform: translate(-50%, -50%);
        }
        .autocount-stats {
          display: grid;
          grid-template-columns: repeat(3, 1fr);
          gap: 7px;
          margin-top: 16px;
        }
        .autocount-stats span {
          min-height: 58px;
          border-radius: 7px;
          border: 1px solid rgba(255,255,255,0.12);
          background: rgba(255,255,255,0.035);
          padding: 9px;
          color: #A1A1AA;
          font-size: 10px;
          text-transform: uppercase;
          font-weight: 800;
        }
        .autocount-stats span:first-child {
          border-color: rgba(16,217,139,0.55);
          background: rgba(16,217,139,0.14);
          color: #63FFC2;
        }
        .autocount-stats span:nth-child(2) {
          border-color: rgba(245,158,11,0.42);
          background: rgba(245,158,11,0.12);
          color: #FACC15;
        }
        .autocount-stats b {
          display: block;
          margin-top: 5px;
          font-size: 19px;
          color: #FFFFFF;
        }
        .autocount-results {
          padding: 18px 18px 20px;
          overflow: hidden;
        }
        .autocount-results > p {
          margin: 0 0 13px;
          color: #D4D4D8;
          font-size: 11px;
          line-height: 1.45;
        }
        .autocount-result-list {
          display: flex;
          flex-direction: column;
          gap: 5px;
        }
        .autocount-result {
          height: 34px;
          display: grid;
          grid-template-columns: 32px 28px 52px 1fr;
          align-items: center;
          border: 1px solid rgba(16,217,139,0.45);
          border-radius: 7px;
          background: rgba(16,217,139,0.08);
          color: #A7F3D0;
          padding: 0 9px;
          font-size: 11px;
        }
        .autocount-result i {
          width: 20px;
          height: 20px;
          border-radius: 999px;
          display: inline-flex;
          align-items: center;
          justify-content: center;
          background: #12D891;
          color: #052E1C;
        }
        .autocount-result small {
          color: #A1A1AA;
          font-size: 10px;
        }
        .autocount-result b {
          color: #F4F4F5;
          font-size: 12px;
          font-weight: 700;
        }
        @media (max-width: 720px) {
          .autocount-feature {
            aspect-ratio: auto;
            min-height: 620px;
          }
          .autocount-plan {
            width: 100%;
            height: 45%;
          }
          .autocount-review {
            top: 45%;
            width: 100%;
            border-left: 0;
            border-top: 1px solid rgba(255,255,255,0.12);
          }
          .autocount-review-body {
            grid-template-columns: 1fr 1.45fr;
          }
          .autocount-review-head {
            padding: 18px;
          }
        }
      `}</style>
    </div>
  );
}

function BentoMeasureMock() {
  return (
    <div className="bento-measure-mock">
      <svg viewBox="0 0 480 200" preserveAspectRatio="xMidYMid meet">
        <defs>
          <pattern id="bm-grid" width="16" height="16" patternUnits="userSpaceOnUse">
            <path d="M16 0 H0 V16" fill="none" stroke="rgba(45,64,234,0.10)" strokeWidth="0.5"/>
          </pattern>
        </defs>
        <rect width="480" height="200" fill="#FFFDF9"/>
        <rect width="480" height="200" fill="url(#bm-grid)"/>
        <path d="M40 40 L240 40 L240 110 L380 110 L380 170 L40 170 Z" fill="rgba(45,64,234,0.08)" stroke="#1A1A1A" strokeWidth="1.6"/>
        <line x1="40" y1="28" x2="240" y2="28" stroke="#2D40EA" strokeWidth="0.8"/>
        <text x="140" y="22" fontFamily="JetBrains Mono" fontSize="10" fill="#1A1A1A" textAnchor="middle">26'-4"</text>
        <line x1="392" y1="110" x2="392" y2="170" stroke="#2D40EA" strokeWidth="0.8"/>
        <text x="406" y="142" fontFamily="JetBrains Mono" fontSize="10" fill="#1A1A1A">11'-2"</text>
        <circle cx="40" cy="40" r="4" fill="#C2352D"/>
        <circle cx="240" cy="40" r="4" fill="#C2352D"/>
        <circle cx="240" cy="110" r="4" fill="#C2352D"/>
        <circle cx="380" cy="110" r="4" fill="#C2352D"/>
        <circle cx="380" cy="170" r="4" fill="#C2352D"/>
        <circle cx="40" cy="170" r="4" fill="#C2352D"/>
      </svg>
      <style>{`
        .bento-measure-mock {
          margin-top: auto;
          padding-top: 24px;
        }
        .bento-measure-mock svg {
          width: 100%; height: auto;
          border-radius: 16px;
          border: 1px solid color-mix(in srgb, var(--ink) 8%, transparent);
        }
      `}</style>
    </div>
  );
}

// ============== HOW IT WORKS ==============
function HowItWorks() {
  const features = [
    {
      tag: 'Assemblies',
      icon: <IconLayers size={14}/>,
      title: <>Build assemblies<br/><span className="serif-it">that price themselves.</span></>,
      copy: 'Bundle material, labor, waste, and unit cost into reusable assemblies. Measure once, stamp the assembly onto the takeoff, and keep pricing logic tied to the quantity.',
      bullets: ['Material + labor templates', 'Reusable across projects', 'Unit pricing tied to takeoff'],
      visual: <AssemblyTemplatePreview/>,
    },
    {
      tag: 'Estimate generation',
      icon: <IconPdf size={14}/>,
      title: <>Generate estimates<br/><span className="serif-it">from measured work.</span></>,
      copy: 'Measured rows roll into sections, quantities, unit costs, and export-ready totals. Send a polished PDF, Excel workbook, or CSV without rebuilding the bid by hand.',
      bullets: ['Sectioned bid structure', 'PDF / Excel / CSV outputs', 'Totals from source quantities'],
      visual: <EstimateTemplatePreview/>,
    },
  ];

  return (
    <section id="how" className="section workflow-section">
      <div className="wrap">
        <Reveal>
          <div className="workflow-head">
            <Eyebrow>Assemblies to estimates</Eyebrow>
            <h2 className="display workflow-h2">
              Turn measured scope<br/>
              into <span className="serif-it">priced work.</span>
            </h2>
            <p className="workflow-sub">
              After the takeoff is measured, ProTakeoff keeps the numbers moving:
              reusable assemblies become priced rows, and priced rows become bid-ready exports.
            </p>
          </div>
        </Reveal>

        <div className="workflow-rows">
          {features.map((feature, index) => (
            <Reveal key={feature.tag} delay={60}>
              <article className={`workflow-row ${index % 2 === 1 ? 'is-flipped' : ''}`}>
                <div className="workflow-copy">
                  <div className="workflow-tag">
                    <span className="workflow-icon">{feature.icon}</span>
                    <span className="mono">{feature.tag}</span>
                  </div>
                  <h3 className="serif workflow-title">{feature.title}</h3>
                  <p className="workflow-body">{feature.copy}</p>
                  <ul className="workflow-bullets">
                    {feature.bullets.map((bullet) => (
                      <li key={bullet}><IconCheck size={12}/> <span className="mono">{bullet}</span></li>
                    ))}
                  </ul>
                </div>
                <div className="workflow-media">
                  {feature.visual}
                </div>
              </article>
            </Reveal>
          ))}
        </div>
      </div>

      <style>{`
        .workflow-section {
          background: var(--cream-soft);
          border-top: 1px solid var(--cream-border);
          border-bottom: 1px solid var(--cream-border);
        }
        .workflow-head {
          max-width: 780px;
          margin-bottom: 80px;
        }
        .workflow-h2 {
          font-size: clamp(2.4rem, 6vw, 4.8rem);
          margin-top: 18px;
          color: var(--ink);
        }
        .workflow-h2 .serif-it { color: var(--ink-soft); }
        .workflow-sub {
          margin-top: 22px;
          max-width: 620px;
          font-size: 1.05rem;
          color: var(--ink-soft);
          font-weight: 500;
          line-height: 1.55;
        }

        .workflow-rows {
          display: flex;
          flex-direction: column;
          gap: 96px;
        }
        .workflow-row {
          display: grid;
          grid-template-columns: 1fr;
          gap: 32px;
          align-items: center;
        }
        @media (min-width: 880px) {
          .workflow-row {
            grid-template-columns: minmax(0, 5fr) minmax(0, 7fr);
            gap: 64px;
          }
          .workflow-row.is-flipped .workflow-copy { order: 2; }
          .workflow-row.is-flipped .workflow-media { order: 1; }
        }

        .workflow-copy { max-width: 460px; }
        .workflow-tag {
          display: inline-flex;
          align-items: center;
          gap: 10px;
          margin-bottom: 22px;
        }
        .workflow-tag .mono {
          font-size: 10px;
          color: var(--ink-mute);
          letter-spacing: 0.12em;
        }
        .workflow-icon {
          width: 26px;
          height: 26px;
          border-radius: 999px;
          background: rgba(255,255,255,0.04);
          border: 1px solid rgba(255,255,255,0.08);
          display: inline-flex;
          align-items: center;
          justify-content: center;
          color: var(--ink);
        }
        .workflow-title {
          font-size: clamp(2rem, 3.6vw, 3.4rem);
          line-height: 1.02;
          color: var(--ink);
          margin-bottom: 20px;
          letter-spacing: -0.02em;
        }
        .workflow-title .serif-it { color: var(--ink-soft); }
        .workflow-body {
          font-size: 1.02rem;
          line-height: 1.6;
          color: var(--ink-soft);
          margin-bottom: 24px;
        }
        .workflow-bullets {
          list-style: none;
          padding: 18px 0 0;
          margin: 0;
          display: flex;
          flex-direction: column;
          gap: 10px;
          border-top: 1px solid color-mix(in srgb, var(--ink) 10%, transparent);
        }
        .workflow-bullets li {
          display: flex;
          align-items: center;
          gap: 10px;
          font-size: 11px;
          color: var(--ink-soft);
        }
        .workflow-bullets li .mono {
          letter-spacing: 0.08em;
        }
        .workflow-bullets li svg {
          color: var(--signal);
          flex-shrink: 0;
        }
        .workflow-media {
          position: relative;
          overflow: hidden;
          border-radius: 12px;
          border: 1px solid rgba(255,255,255,0.08);
          background: #050505;
          box-shadow: 0 30px 80px -30px rgba(0,0,0,0.6);
          padding: 16px;
        }
        .workflow-media::after {
          content: "";
          position: absolute;
          inset: 0;
          border-radius: inherit;
          box-shadow: inset 0 0 0 1px rgba(255,255,255,0.04);
          pointer-events: none;
        }
        html[data-theme="cream"] .workflow-media {
          border-color: var(--cream-border);
          background: #0A0A0A;
          box-shadow: 0 24px 60px -28px rgba(26,26,26,0.18);
        }

        @media (max-width: 767px) {
          .workflow-head {
            margin-bottom: 42px;
          }
          .workflow-h2 {
            font-size: 2.55rem;
            line-height: 0.96;
            letter-spacing: -0.035em;
            text-wrap: balance;
          }
          .workflow-sub {
            font-size: 0.96rem;
            line-height: 1.5;
          }
          .workflow-rows {
            gap: 58px;
          }
          .workflow-row {
            gap: 18px;
          }
          .workflow-copy {
            max-width: none;
          }
          .workflow-tag {
            margin-bottom: 16px;
          }
          .workflow-title {
            font-size: 2rem;
            margin-bottom: 14px;
          }
          .workflow-body {
            font-size: 0.94rem;
            margin-bottom: 18px;
          }
          .workflow-media {
            padding: 12px;
            border-radius: 14px;
          }
        }
      `}</style>
    </section>
  );
}

function AssemblyTemplatePreview() {
  return (
    <div className="ill ill-asm">
      <h4 className="serif-it asm-title">Assembly: 5/8" Drywall (Painted)</h4>
      <div className="asm-row"><span>5/8" gypsum board</span><span className="mono">1.05 SF/SF</span></div>
      <div className="asm-row"><span>Joint compound</span><span className="mono">0.04 GAL/SF</span></div>
      <div className="asm-row"><span>Tape</span><span className="mono">2.1 LF/SF</span></div>
      <div className="asm-row"><span>Primer + 2 coats latex</span><span className="mono">0.012 GAL/SF</span></div>
      <div className="asm-row"><span>Labor — installer</span><span className="mono">0.04 HR/SF</span></div>
      <div className="asm-foot">
        <span className="mono">Stamp on any area</span>
        <span className="serif-it">$3.84 / sf</span>
      </div>
      <style>{`
        .ill-asm {
          width: 100%;
          min-height: 380px;
          display: flex;
          flex-direction: column;
          justify-content: center;
          gap: 6px;
          padding: 28px;
          color: rgba(255,255,235,0.85);
          background:
            radial-gradient(circle at 82% 16%, rgba(132,204,22,0.1), transparent 34%),
            linear-gradient(180deg, rgba(255,255,255,0.04), transparent);
        }
        .asm-title {
          font-size: clamp(1.25rem, 3vw, 1.75rem);
          color: #FFFFEB;
          margin-bottom: 16px;
          letter-spacing: -0.02em;
        }
        .asm-row {
          display: flex;
          justify-content: space-between;
          align-items: center;
          gap: 14px;
          padding: 12px 14px;
          font-size: 13px;
          background: rgba(255,255,235,0.04);
          border: 1px solid rgba(255,255,235,0.07);
          border-radius: 10px;
        }
        .asm-row .mono {
          white-space: nowrap;
          font-size: 10px;
          color: rgba(255,255,235,0.84);
        }
        .asm-foot {
          margin-top: 16px;
          display: flex;
          justify-content: space-between;
          align-items: baseline;
          gap: 14px;
          padding: 15px 18px;
          background: rgba(132,204,22,0.1);
          border: 1px solid rgba(132,204,22,0.18);
          border-radius: 12px;
        }
        .asm-foot .mono {
          font-size: 10px;
          color: rgba(255,255,235,0.64);
        }
        .asm-foot .serif-it {
          font-size: 24px;
          color: var(--signal);
          white-space: nowrap;
        }
        @media (max-width: 767px) {
          .ill-asm {
            min-height: 330px;
            padding: 18px;
          }
          .asm-row {
            padding: 10px 11px;
            font-size: 12px;
          }
          .asm-row .mono {
            font-size: 8px;
          }
          .asm-foot {
            padding: 13px;
          }
          .asm-foot .serif-it {
            font-size: 20px;
          }
        }
      `}</style>
    </div>
  );
}

function EstimateTemplatePreview() {
  const sections = [
    {
      number: '01',
      title: 'General Requirements',
      total: '$23,550.00',
      items: [
        ['1.1', 'Project Management & Supervision', '1', 'LS', '$12,500.00'],
        ['1.2', 'Temporary Facilities', '1', 'LS', '$4,250.00'],
      ],
    },
    {
      number: '02',
      title: 'Concrete',
      total: '$58,742.50',
      items: [
        ['2.1', 'Concrete Slab on Grade (4")', '4,250', 'SF', '$18,062.50'],
        ['2.2', 'Concrete Footings', '160', 'LF', '$3,600.00'],
        ['2.3', 'Concrete Walls', '1,200', 'SF', '$14,580.00'],
      ],
    },
    {
      number: '03',
      title: 'Structural Steel',
      total: '$76,320.00',
      items: [
        ['3.1', 'Structural Steel Supply', '12,000', 'LB', '$61,200.00'],
        ['3.2', 'Structural Steel Erection', '12,000', 'LB', '$15,120.00'],
      ],
    },
  ];

  return (
    <div className="ill ill-estimate-preview">
      <div className="estimate-window">
        <div className="estimate-topbar">
          <span className="dot dot-r"></span>
          <span className="dot dot-y"></span>
          <span className="dot dot-g"></span>
          <span className="mono estimate-toolbar-title">estimate preview</span>
          <span className="mono estimate-status">ready</span>
        </div>

        <div className="estimate-paper">
          <header className="estimate-head">
            <div>
              <span className="estimate-brand">ProTakeoff</span>
              <h4 className="estimate-title serif-it">Estimate</h4>
              <span className="mono estimate-id">EST-4821 · valid for 30 days</span>
            </div>
            <div className="estimate-address">
              <span className="mono">Project</span>
              <strong>Riverside Office Building</strong>
              <span>1234 Riverside Drive</span>
            </div>
            <div className="estimate-address">
              <span className="mono">Client</span>
              <strong>Bluewater Construction</strong>
              <span>Attn: Alex Morgan</span>
            </div>
          </header>

          <div className="estimate-table">
            <div className="estimate-table-head mono">
              <span>#</span>
              <span>Description</span>
              <span>Qty</span>
              <span>Total</span>
            </div>

            {sections.map((section) => (
              <React.Fragment key={section.number}>
                <div className="estimate-section-row">
                  <span className="mono">{section.number}</span>
                  <strong>{section.title}</strong>
                  <span></span>
                  <strong>{section.total}</strong>
                </div>
                {section.items.map((item) => (
                  <div className="estimate-line-row" key={item[0]}>
                    <span className="mono">{item[0]}</span>
                    <span>{item[1]}</span>
                    <span className="mono">{item[2]} {item[3]}</span>
                    <span>{item[4]}</span>
                  </div>
                ))}
              </React.Fragment>
            ))}
          </div>

          <footer className="estimate-footer">
            <div>
              <span className="mono">Notes</span>
              <p>Generated from measured takeoff quantities. Ready for PDF or Excel export.</p>
            </div>
            <div className="estimate-total">
              <span className="mono">Total</span>
              <strong>$171,694.53</strong>
            </div>
          </footer>
        </div>
      </div>

      <div className="export-formats">
        <span className="export-fmt"><IconPdf size={14}/> PDF</span>
        <span className="export-fmt"><IconExcel size={14}/> Excel</span>
        <span className="export-fmt"><IconCsv size={14}/> CSV</span>
      </div>

      <style>{`
        .ill-estimate-preview { display: flex; flex-direction: column; gap: 12px; width: 100%; max-width: 620px; }
        .estimate-window {
          overflow: hidden;
          border: 1px solid rgba(255,255,235,0.1);
          border-radius: 16px;
          background: rgba(255,255,235,0.05);
          box-shadow: 0 22px 56px rgba(0,0,0,0.34);
        }
        .estimate-topbar {
          display: flex;
          align-items: center;
          gap: 8px;
          padding: 8px 12px;
          background: rgba(0,0,0,0.24);
          border-bottom: 1px solid rgba(255,255,235,0.08);
        }
        .estimate-topbar .dot { width: 8px; height: 8px; border-radius: 999px; }
        .estimate-toolbar-title { margin-left: 8px; font-size: 8px; color: rgba(255,255,235,0.52); }
        .estimate-status { margin-left: auto; font-size: 8px; color: var(--signal); }
        .estimate-paper {
          background: #fffaf0;
          color: #22322f;
          padding: 16px 18px 14px;
        }
        .estimate-head {
          display: grid;
          grid-template-columns: 1.15fr 1fr 1fr;
          gap: 18px;
          padding-bottom: 14px;
          border-bottom: 1px solid rgba(34,50,47,0.12);
        }
        .estimate-brand { display: inline-flex; margin-bottom: 8px; font-size: 11px; font-weight: 700; color: #064e3b; }
        .estimate-title { display: block; font-size: 34px; line-height: 0.9; color: #22322f; }
        .estimate-id { display: block; margin-top: 7px; font-size: 8px; color: #c76a24; }
        .estimate-address { display: flex; flex-direction: column; gap: 3px; font-size: 10px; color: rgba(34,50,47,0.68); }
        .estimate-address .mono { font-size: 8px; color: rgba(34,50,47,0.42); }
        .estimate-address strong { color: #22322f; font-size: 11px; }
        .estimate-table { margin-top: 12px; font-size: 9px; }
        .estimate-table-head,
        .estimate-section-row,
        .estimate-line-row {
          display: grid;
          grid-template-columns: 42px minmax(0, 1fr) 76px 90px;
          gap: 10px;
          align-items: center;
        }
        .estimate-table-head {
          padding-bottom: 7px;
          border-bottom: 1px solid rgba(34,50,47,0.12);
          color: rgba(34,50,47,0.44);
          font-size: 7px;
        }
        .estimate-section-row {
          padding: 8px 0 6px;
          border-bottom: 1px solid rgba(34,50,47,0.1);
          color: #064e3b;
        }
        .estimate-section-row strong:last-child,
        .estimate-line-row span:last-child {
          text-align: right;
        }
        .estimate-line-row {
          padding: 5px 0;
          border-bottom: 1px solid rgba(34,50,47,0.05);
          color: rgba(34,50,47,0.68);
        }
        .estimate-line-row .mono { color: rgba(34,50,47,0.5); font-size: 7px; }
        .estimate-footer {
          display: grid;
          grid-template-columns: 1fr 180px;
          gap: 20px;
          margin-top: 14px;
          padding-top: 12px;
          border-top: 1px solid rgba(34,50,47,0.16);
        }
        .estimate-footer .mono { font-size: 8px; color: rgba(34,50,47,0.45); }
        .estimate-footer p { margin: 5px 0 0; max-width: 280px; font-size: 9px; line-height: 1.45; color: rgba(34,50,47,0.62); }
        .estimate-total { display: flex; flex-direction: column; align-items: flex-end; justify-content: flex-end; }
        .estimate-total strong { margin-top: 4px; font-size: 24px; line-height: 1; color: #2563eb; }
        .export-formats { display: flex; gap: 8px; justify-content: center; }
        .export-fmt {
          display: inline-flex; align-items: center; gap: 6px;
          font-size: 11px; padding: 8px 14px;
          background: rgba(255,255,235,0.06);
          border: 1px solid rgba(255,255,235,0.1);
          border-radius: 999px; color: rgba(255,255,235,0.85);
        }
        @media (max-width: 720px) {
          .estimate-paper { padding: 12px; }
          .estimate-head { grid-template-columns: 1fr; gap: 8px; }
          .estimate-address { display: none; }
          .estimate-table-head,
          .estimate-section-row,
          .estimate-line-row { grid-template-columns: 28px minmax(0, 1fr) 52px 62px; gap: 7px; }
          .estimate-footer { grid-template-columns: 1fr; }
          .estimate-total { align-items: flex-start; }
        }
      `}</style>
    </div>
  );
}

// ============== TESTIMONIALS ==============
function Testimonials() {
  const quotes = [
    { q: "Replaced a $4,200/yr PlanSwift seat in an afternoon. Estimators didn't even need a training session.", a: "Rachel Voorhees", r: "Estimating Lead, Halberd Builders" },
    { q: "At $10 a month, this is the easiest software bill I approve. Nothing else in takeoff comes close to this much value for the price.", a: "Marcus Bell", r: "Owner, Bell & Co Drywall" },
    { q: "Built for the way contractors actually work. Local files, keyboard-first, no logged-in dashboard nonsense.", a: "Imani Roth", r: "Civil PM, Veridian" },
  ];
  return (
    <section className="section testimonials">
      <div className="wrap">
        <Reveal>
          <div className="testimonials-head">
            <Eyebrow>From the field</Eyebrow>
            <h2 className="display testimonials-h2">
              <span className="serif-it">Bid faster.</span><br/>
              Sleep better.
            </h2>
          </div>
        </Reveal>
        <div className="testimonials-grid">
          {quotes.map((t, i) => (
            <Reveal key={i} delay={i * 80}>
              <figure className="quote-card">
                <span className="quote-mark serif">"</span>
                <blockquote className="serif quote-body">{t.q}</blockquote>
                <figcaption className="quote-cite">
                  <span className="quote-name">{t.a}</span>
                  <span className="quote-role mono">{t.r}</span>
                </figcaption>
              </figure>
            </Reveal>
          ))}
        </div>
      </div>
      <style>{`
        .testimonials-head { max-width: 720px; margin-bottom: 56px; }
        .testimonials-h2 { font-size: clamp(2.4rem, 5.5vw, 4.6rem); margin-top: 18px; color: var(--ink); }
        .testimonials-h2 .serif-it { color: var(--brick); }

        .testimonials-grid {
          display: grid; gap: 18px;
          grid-template-columns: 1fr;
        }
        @media (min-width: 768px) { .testimonials-grid { grid-template-columns: repeat(3, 1fr); } }

        .quote-card {
          margin: 0;
          padding: 32px 28px;
          background: var(--cream-soft);
          border: 1px solid var(--cream-border);
          border-radius: 24px;
          display: flex; flex-direction: column; gap: 18px;
          position: relative;
          transition: transform 0.3s var(--ease-haptic);
        }
        .quote-card:hover { transform: translateY(-4px); }
        .quote-card:nth-child(2) { background: var(--forest); border-color: var(--forest-deep); color: var(--cream); }
        .quote-card:nth-child(2) .quote-name { color: var(--cream); }
        .quote-card:nth-child(2) .quote-role { color: rgba(255,255,235,0.6); }
        .quote-card:nth-child(2) .quote-mark { color: var(--orange); }
        .quote-mark { position: absolute; top: 16px; right: 24px; font-size: 80px; line-height: 1; color: var(--ink-mute); opacity: 0.4; }
        .quote-body { margin: 0; font-size: 18px; line-height: 1.45; }
        .quote-card:nth-child(2) .quote-body { color: var(--cream); }
        .quote-cite { display: flex; flex-direction: column; gap: 4px; margin-top: auto; padding-top: 14px; border-top: 1px solid color-mix(in srgb, var(--ink) 12%, transparent); }
        .quote-card:nth-child(2) .quote-cite { border-color: rgba(255,255,235,0.15); }
        .quote-name { font-weight: 600; font-size: 14px; color: var(--ink); }
        .quote-role { font-size: 10px; color: var(--ink-mute); }
      `}</style>
    </section>
  );
}

// ============== PRICING ==============
function Pricing() {
  const [yearly, setYearly] = useStateS(false);
  return (
    <section id="pricing" className="section">
      <div className="wrap">
        <Reveal>
          <div className="pricing-head">
            <Eyebrow>Honest pricing</Eyebrow>
            <h2 className="display pricing-h2">
              Two tiers. <span className="serif-it">No upsell.</span><br/>
              <span className="squiggle">No surprises.</span>
            </h2>
            <div className="pricing-toggle">
              <button className={!yearly ? 'on' : ''} onClick={() => setYearly(false)}>Monthly</button>
              <button className={yearly ? 'on' : ''} onClick={() => setYearly(true)}>
                Yearly <span className="save-pill">SAVE 23%</span>
              </button>
            </div>
          </div>
        </Reveal>

        <div className="pricing-grid">
          <Reveal>
            <PriceCard
              tier="Solo"
              price={yearly ? 120 : 13}
              cycle={yearly ? '/yr' : '/mo'}
              caption={yearly ? 'Billed yearly · save $36' : 'Or $120/yr — save $36'}
              features={['1 user license', 'Point-and-click measure', 'Auto-snap & ortho', 'Custom annotations', 'Export PDF / Excel / CSV', 'Runs on any old laptop']}
              cta="Start 30-day trial"
            />
          </Reveal>
          <Reveal delay={120}>
            <PriceCard
              tier="Team"
              price={yearly ? 500 : 76}
              cycle={yearly ? '/yr' : '/mo'}
              caption={yearly ? 'Billed yearly · save $412' : 'Or $500/yr — save $412'}
              features={['6 user licenses', 'Shared template library', 'Real-time team sync', 'Branded quotes & exports', 'Priority email support', 'Cheapest team option · period']}
              cta="Deploy to your team"
              highlight
              badge="6 LICENSES"
            />
          </Reveal>
        </div>

        <Reveal delay={200}>
          <div className="pricing-foot mono">
            <span><IconCheck size={11}/> 30-day full trial · no credit card</span>
            <span><IconCheck size={11}/> Cancel anytime</span>
            <span><IconCheck size={11}/> 5-pack volume discount above 30 seats</span>
          </div>
        </Reveal>
      </div>

      <style>{`
        .pricing-head { display: flex; flex-direction: column; align-items: center; text-align: center; margin-bottom: 56px; }
        .pricing-h2 { font-size: clamp(2.4rem, 6vw, 4.8rem); margin-top: 18px; }
        .pricing-h2 .serif-it { color: var(--ink-soft); }

        .pricing-toggle {
          margin-top: 32px;
          display: inline-flex; gap: 4px; padding: 4px;
          background: var(--cream-soft);
          border: 1px solid var(--cream-border);
          border-radius: 999px;
        }
        .pricing-toggle button {
          padding: 10px 22px;
          border-radius: 999px;
          font-size: 13px; font-weight: 600;
          color: var(--ink-soft);
          transition: background 0.3s, color 0.3s;
          display: inline-flex; align-items: center; gap: 8px;
        }
        .pricing-toggle button.on { background: var(--ink); color: var(--cream); }
        .save-pill {
          font-family: 'JetBrains Mono', monospace;
          font-size: 9px; padding: 3px 7px;
          background: var(--brick); color: var(--cream);
          border-radius: 999px; letter-spacing: 0.1em;
        }
        .pricing-toggle button.on .save-pill { background: var(--orange); color: var(--ink); }

        .pricing-grid {
          display: grid; gap: 18px;
          grid-template-columns: 1fr;
          max-width: 920px; margin: 0 auto;
        }
        @media (min-width: 768px) { .pricing-grid { grid-template-columns: 1fr 1fr; } }

        .pricing-foot {
          display: flex; flex-wrap: wrap; gap: 20px; justify-content: center;
          margin-top: 40px;
          font-size: 10px; color: var(--ink-mute);
        }
        .pricing-foot span { display: inline-flex; align-items: center; gap: 6px; }
        .pricing-foot svg { color: var(--forest); }
      `}</style>
    </section>
  );
}

function PriceCard({ tier, price, cycle, caption, features, cta, highlight, badge }) {
  return (
    <div className={`price-card ${highlight ? 'price-card-hl' : ''}`}>
      {badge && <span className="price-badge mono">{badge}</span>}
      <span className="price-tier mono">{tier}</span>
      <div className="price-num">
        <span className="serif-it">${price}</span>
        <span className="price-cycle">{cycle}</span>
      </div>
      <span className="price-caption">{caption}</span>
      <ul className="price-features">
        {features.map((f, i) => (
          <li key={i}><span className="price-check"><IconCheck size={11}/></span>{f}</li>
        ))}
      </ul>
      <a href="#download" className={`btn ${highlight ? 'btn-secondary' : 'btn-primary'} price-cta`}>
        {cta}
        <span className="arrow"><IconArrow size={13}/></span>
      </a>
      <style>{`
        .price-card {
          position: relative;
          padding: 40px 36px;
          background: var(--cream-soft);
          border: 1px solid var(--cream-border);
          border-radius: 28px;
          display: flex; flex-direction: column;
        }
        .price-card-hl {
          background: var(--forest);
          color: var(--cream);
          border-color: var(--forest-deep);
          box-shadow: 0 24px 60px rgba(3,79,70,0.2);
        }
        .price-badge {
          position: absolute; top: 20px; right: 24px;
          padding: 6px 12px;
          background: var(--brick); color: var(--cream);
          border-radius: 999px;
          font-size: 9px; letter-spacing: 0.16em;
        }
        .price-tier { font-size: 11px; color: var(--ink-mute); margin-bottom: 12px; }
        .price-card-hl .price-tier { color: var(--sky); }
        .price-num { display: flex; align-items: baseline; gap: 6px; }
        .price-num .serif-it { font-size: 72px; line-height: 1; color: var(--ink); }
        .price-card-hl .price-num .serif-it { color: var(--cream); }
        .price-cycle { font-size: 13px; color: var(--ink-mute); }
        .price-card-hl .price-cycle { color: rgba(255,255,235,0.6); }
        .price-caption { margin-top: 8px; font-size: 12px; color: var(--ink-soft); }
        .price-card-hl .price-caption { color: var(--sky); }

        .price-features { margin: 28px 0 32px; display: flex; flex-direction: column; gap: 12px; flex: 1; }
        .price-features li { display: flex; align-items: flex-start; gap: 10px; font-size: 14px; color: var(--ink-soft); line-height: 1.4; }
        .price-card-hl .price-features li { color: rgba(255,255,235,0.85); }
        .price-check {
          flex: 0 0 18px; width: 18px; height: 18px; border-radius: 999px;
          background: var(--forest); color: var(--cream);
          display: inline-flex; align-items: center; justify-content: center;
          margin-top: 1px;
        }
        .price-card-hl .price-check { background: var(--orange); color: var(--ink); }

        .price-cta { width: 100%; padding: 16px 22px; }
      `}</style>
    </div>
  );
}

// ============== FAQ ==============
function FAQ() {
  const [open, setOpen] = useStateS(0);
  const items = [
    { q: 'Does ProTakeoff need an internet connection?', a: 'Nope. The whole app is local. We sign you in once to validate the license, then you can run offline indefinitely. Files stay on your machine — perfect for jobsite trailers and locked-down enterprise networks.' },
    { q: 'How does this compare to Bluebeam, PlanSwift, or On-Screen Takeoff?', a: 'It\'s narrower on purpose. We don\'t do markup review or RFI tracking — we focus on the takeoff and quote loop. The result: 4× faster on quantity work, ~10% the price, and no mandatory cloud account.' },
    { q: 'Can I import my existing assemblies and templates?', a: 'Yes. We import .pst, .csv, and Excel-format assemblies. Most teams transfer their entire library in one drag-and-drop and are billing the next morning.' },
    { q: 'What does the AI page-renaming actually do?', a: 'It runs OCR on every sheet\'s title block and rewrites the filename to match the sheet number and title — A‑201 Floor Plan, S‑101 Foundation, etc. It runs locally; pages never leave your machine.' },
    { q: 'Do you offer volume pricing for general contractors?', a: 'Above 30 seats we offer custom pricing and a deployment script for IT. Email info@protakeoff.org and we\'ll send it the same day.' },
  ];
  return (
    <section id="faq" className="section faq">
      <div className="wrap faq-wrap">
        <Reveal>
          <div className="faq-head">
            <Eyebrow>Questions, answered</Eyebrow>
            <h2 className="display faq-h2">Before you <span className="serif-it">click download.</span></h2>
          </div>
        </Reveal>
        <div className="faq-list">
          {items.map((it, i) => (
            <Reveal key={i} delay={i * 50}>
              <div className={`faq-item ${open === i ? 'open' : ''}`}>
                <button className="faq-q" onClick={() => setOpen(open === i ? -1 : i)}>
                  <span className="faq-q-text serif">{it.q}</span>
                  <span className="faq-q-icon">{open === i ? <IconMinus size={18}/> : <IconPlus size={18}/>}</span>
                </button>
                <div className="faq-a-wrap">
                  <p className="faq-a">{it.a}</p>
                </div>
              </div>
            </Reveal>
          ))}
        </div>
      </div>
      <style>{`
        .faq-wrap { display: grid; gap: 48px; grid-template-columns: 1fr; }
        @media (min-width: 1024px) { .faq-wrap { grid-template-columns: 1fr 1.4fr; gap: 80px; } }
        .faq-head { position: sticky; top: 110px; align-self: start; }
        .faq-h2 { font-size: clamp(2.4rem, 5.5vw, 4rem); margin-top: 18px; }
        .faq-h2 .serif-it { color: var(--blue); }

        .faq-list { display: flex; flex-direction: column; }
        .faq-item { border-top: 1px solid color-mix(in srgb, var(--ink) 14%, transparent); }
        .faq-item:last-child { border-bottom: 1px solid color-mix(in srgb, var(--ink) 14%, transparent); }
        .faq-q {
          width: 100%;
          display: flex; justify-content: space-between; align-items: center; gap: 24px;
          padding: 28px 4px;
          text-align: left;
        }
        .faq-q-text { font-size: clamp(1.1rem, 1.4vw + 0.6rem, 1.55rem); color: var(--ink); }
        .faq-q-icon { color: var(--ink-mute); flex: 0 0 auto; }
        .faq-a-wrap {
          display: grid; grid-template-rows: 0fr;
          transition: grid-template-rows 0.4s var(--ease-haptic);
        }
        .faq-item.open .faq-a-wrap { grid-template-rows: 1fr; }
        .faq-a {
          overflow: hidden;
          margin: 0;
          padding: 0 4px 24px;
          font-size: 15px; line-height: 1.6; color: var(--ink-soft);
          max-width: 56ch;
        }
      `}</style>
    </section>
  );
}

// ============== DOWNLOAD CTA ==============
function DownloadCTA() {
  return (
    <section id="download" className="section download-section">
      <div className="wrap">
        <Reveal>
          <div className="download-card">
            <div className="download-card-bg blueprint-bg" aria-hidden="true"></div>
            <div className="download-content">
              <Eyebrow>Free 30-day trial</Eyebrow>
              <h2 className="display download-h2">
                Quote tonight's bid<br/>
                <span className="serif-it">on tonight's clock.</span>
              </h2>
              <p className="download-sub">
                One installer. Two minutes. Zero credit card. The next time
                you sit down to a stack of plans, ProTakeoff will be there.
              </p>
              <div className="download-ctas">
                <a href="https://pub-35fd315700b04af3ac688f85a235e2a7.r2.dev/ProTakeoff_0.1.16_x64-setup.exe" className="btn btn-primary download-btn">
                  <IconWindows size={16}/>
                  Download for Windows
                  <span className="arrow"><IconArrow size={13}/></span>
                </a>
                <a href="https://pub-35fd315700b04af3ac688f85a235e2a7.r2.dev/ProTakeoff_0.1.16_aarch64.dmg" className="btn btn-secondary download-btn">
                  <IconApple size={16}/>
                  Download for macOS
                  <span className="arrow"><IconArrow size={13}/></span>
                </a>
              </div>
              <div className="download-meta mono">
                <span>v0.1.16 · 85.4MB · April 2026</span>
                <span>Win 10+ · macOS 12+</span>
              </div>
            </div>
            <div className="download-art">
              <DownloadArt/>
            </div>
          </div>
        </Reveal>
      </div>
      <style>{`
        .download-section { padding: 64px 0 128px; }
        .download-card {
          position: relative;
          background: var(--forest);
          color: var(--cream);
          border-radius: 36px;
          padding: 64px 48px;
          overflow: hidden;
          display: grid;
          grid-template-columns: 1fr;
          gap: 48px;
        }
        @media (min-width: 1024px) {
          .download-card { grid-template-columns: 1.2fr 1fr; padding: 88px 72px; align-items: center; }
        }
        .download-card-bg {
          position: absolute; inset: 0;
          opacity: 0.6;
          mask-image: radial-gradient(ellipse at right, #000 30%, transparent 80%);
        }
        .download-content { position: relative; z-index: 1; }
        .download-card .eyebrow { background: rgba(255,255,235,0.08); border-color: rgba(255,255,235,0.15); color: rgba(255,255,235,0.85); }
        .download-card .eyebrow .dot { background: var(--orange); }

        .download-h2 { font-size: clamp(2.6rem, 6vw, 5rem); margin-top: 22px; color: var(--cream); }
        .download-h2 .serif-it { color: var(--orange); }
        .download-sub { margin-top: 22px; max-width: 480px; font-size: 1.05rem; color: rgba(255,255,235,0.75); line-height: 1.5; }
        .download-ctas { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 32px; }
        .download-btn { padding: 16px 22px; }
        .download-card .btn-primary {
          background: var(--orange); color: var(--ink); border-color: var(--ink);
        }
        .download-card .btn-primary:hover { background: var(--cream); }
        .download-card .btn-secondary {
          background: rgba(255,255,235,0.08);
          color: var(--cream);
          border-color: rgba(255,255,235,0.15);
        }
        .download-card .btn-secondary:hover { background: rgba(255,255,235,0.14); }
        .download-card .btn .arrow { background: var(--ink); color: var(--orange); }
        .download-card .btn-secondary .arrow { background: rgba(255,255,235,0.18); color: var(--cream); }

        .download-meta { display: flex; gap: 20px; flex-wrap: wrap; margin-top: 28px; font-size: 10px; color: rgba(255,255,235,0.5); }

        .download-art { position: relative; z-index: 1; }
      `}</style>
    </section>
  );
}

function DownloadArt() {
  return (
    <div className="dl-art">
      <div className="dl-art-stack">
        <div className="dl-stamp" aria-label="1 month free trial, no credit card required">
          <div className="dl-stamp-copy">
            <span className="dl-stamp-kicker mono">1 month</span>
            <span className="dl-stamp-main">Free</span>
            <span className="dl-stamp-sub">trial</span>
            <span className="dl-stamp-fine mono">no card needed</span>
          </div>
        </div>
      </div>
      <style>{`
        .dl-art { display: flex; justify-content: center; align-items: center; }
        .dl-art-stack { display: flex; flex-direction: column; gap: 20px; align-items: center; }
        .dl-stamp {
          --badge-ink: #050505;
          --badge-shadow: rgba(132,204,22,0.24);
          position: relative;
          width: clamp(190px, 22vw, 248px);
          aspect-ratio: 1;
          display: grid;
          place-items: center;
          text-align: center;
          color: var(--badge-ink);
          isolation: isolate;
          filter: drop-shadow(0 24px 54px var(--badge-shadow));
          transform: rotate(-8deg);
          animation: badge-float 5.8s var(--ease-haptic) infinite;
        }
        .dl-stamp::before {
          content: "";
          position: absolute;
          inset: 0;
          background:
            radial-gradient(circle at 36% 28%, rgba(255,255,255,0.32), transparent 30%),
            linear-gradient(145deg, rgba(255,255,255,0.12), transparent 44%),
            var(--signal);
          clip-path: polygon(
            50% 0%, 56% 11%, 66% 4%, 70% 17%, 83% 11%, 84% 25%,
            97% 26%, 91% 39%, 100% 50%, 91% 61%, 97% 74%, 84% 75%,
            83% 89%, 70% 83%, 66% 96%, 56% 89%, 50% 100%, 44% 89%,
            34% 96%, 30% 83%, 17% 89%, 16% 75%, 3% 74%, 9% 61%,
            0% 50%, 9% 39%, 3% 26%, 16% 25%, 17% 11%, 30% 17%,
            34% 4%, 44% 11%
          );
          z-index: -2;
        }
        .dl-stamp::after {
          content: "";
          position: absolute;
          inset: 31px;
          border: 1px dashed rgba(5,5,5,0.36);
          border-radius: 999px;
          box-shadow: inset 0 0 0 1px rgba(255,255,255,0.14);
          opacity: 0.74;
          z-index: -1;
        }
        .dl-stamp-copy {
          display: flex;
          flex-direction: column;
          align-items: center;
          justify-content: center;
          gap: 2px;
          transform: rotate(8deg);
        }
        .dl-stamp-kicker,
        .dl-stamp-fine {
          color: rgba(5,5,5,0.72);
          font-size: 10px;
          letter-spacing: 0.18em;
          text-transform: uppercase;
        }
        .dl-stamp-main {
          color: var(--badge-ink);
          font-size: clamp(54px, 6vw, 78px);
          line-height: 0.82;
          font-weight: 950;
          letter-spacing: -0.07em;
          text-transform: uppercase;
        }
        .dl-stamp-sub {
          color: var(--badge-ink);
          font-size: clamp(22px, 3vw, 34px);
          line-height: 0.94;
          font-weight: 850;
          letter-spacing: -0.04em;
          text-transform: uppercase;
        }
        .dl-stamp-fine {
          margin-top: 8px;
          font-size: 8px;
          letter-spacing: 0.16em;
        }
        [data-theme="cream"] .download-card .dl-stamp {
          --badge-ink: #FFFFEB;
          --badge-shadow: rgba(3,79,70,0.28);
        }
        [data-theme="cream"] .download-card .dl-stamp::after {
          border-color: rgba(255,255,235,0.34);
          box-shadow: inset 0 0 0 1px rgba(255,255,235,0.12);
        }
        [data-theme="cream"] .download-card .dl-stamp-kicker,
        [data-theme="cream"] .download-card .dl-stamp-fine {
          color: rgba(255,255,235,0.72);
        }
        @keyframes badge-float {
          0%, 100% { transform: rotate(-8deg) translateY(0) scale(1); }
          50% { transform: rotate(-6deg) translateY(-6px) scale(1.015); }
        }
      `}</style>
    </div>
  );
}

// ============== FOOTER ==============
function Footer() {
  return (
    <footer className="footer">
      <div className="wrap">
        <div className="footer-top">
          <div className="footer-brand">
            <Logo/>
            <p className="footer-tag">Takeoff and estimating, the way contractors would have built it themselves.</p>
            <a className="footer-email" href="mailto:info@protakeoff.org">info@protakeoff.org</a>
            <div className="footer-socials" aria-label="ProTakeoff social links">
              <a href="https://www.youtube.com/@protakeoff" target="_blank" rel="noopener noreferrer" aria-label="ProTakeoff on YouTube">
                <IconYoutube size={15}/>
              </a>
              <a href="https://www.linkedin.com/company/protakeof/" target="_blank" rel="noopener noreferrer" aria-label="ProTakeoff on LinkedIn">
                <IconLinkedin size={15}/>
              </a>
              <a href="https://x.com/protakeoff" target="_blank" rel="noopener noreferrer" aria-label="ProTakeoff on X">
                <IconXBrand size={14}/>
              </a>
            </div>
          </div>
          <div className="footer-cols">
            <FooterCol title="Product" links={[
              { label: 'Features', href: '#benefits' },
              { label: 'How it works', href: '#how' },
              { label: 'Pricing', href: '#pricing' },
              { label: 'FAQ', href: '#faq' },
              { label: 'Download', href: '#download' },
            ]}/>
            <FooterCol title="Workflows" links={[
              { label: 'Overlay review', href: '#benefits' },
              { label: 'Auto Count', href: '#benefits' },
              { label: 'Estimate exports', href: '#how' },
              { label: 'Dark / Light mode', href: '#benefits' },
              { label: 'Windows trial', href: '#download' },
            ]}/>
            <FooterCol title="Company" links={[
              { label: 'Contact', href: 'mailto:info@protakeoff.org' },
              { label: 'Support', href: 'mailto:info@protakeoff.org?subject=ProTakeoff%20support' },
              { label: 'Sitemap', href: '/sitemap.xml' },
              { label: 'Status', href: '/api/health' },
              { label: 'Home', href: '/' },
            ]}/>
          </div>
        </div>
      </div>
      <style>{`
        .footer {
          padding: 80px 0 48px;
          border-top: 1px solid color-mix(in srgb, var(--ink) 14%, transparent);
        }
        .footer-top {
          display: grid; grid-template-columns: 1fr; gap: 48px;
        }
        @media (min-width: 768px) { .footer-top { grid-template-columns: 1.2fr 2fr; gap: 72px; } }

        .footer-brand .nav-logo { padding-right: 0; border-right: none; margin-right: 0; }
        .footer-tag { margin-top: 18px; max-width: 320px; font-size: 14px; color: var(--ink-soft); line-height: 1.5; }
        .footer-email { display: inline-flex; margin-top: 14px; font-size: 13px; font-weight: 500; color: var(--ink); transition: color 0.2s; }
        .footer-email:hover { color: var(--ink-soft); }
        .footer-socials {
          display: flex;
          align-items: center;
          gap: 10px;
          margin-top: 18px;
        }
        .footer-socials a {
          width: 38px;
          height: 38px;
          display: inline-flex;
          align-items: center;
          justify-content: center;
          color: var(--ink);
          border: 1px solid color-mix(in srgb, var(--ink) 16%, transparent);
          border-radius: 999px;
          background: color-mix(in srgb, var(--ink) 4%, transparent);
          transition: transform 0.22s var(--ease-haptic), background 0.22s, color 0.22s, border-color 0.22s;
        }
        .footer-socials a:hover {
          transform: translateY(-2px);
          color: var(--bg);
          background: var(--ink);
          border-color: var(--ink);
        }
        .footer-socials a:active { transform: translateY(0); }

        .footer-cols { display: grid; grid-template-columns: 1fr; gap: 28px; }
        @media (min-width: 640px) { .footer-cols { grid-template-columns: repeat(3, 1fr); gap: 24px; } }
        .footer-col h4 { font-family: 'JetBrains Mono', monospace; font-size: 10px; letter-spacing: 0.18em; text-transform: uppercase; color: var(--ink-mute); margin-bottom: 16px; font-weight: 500; }
        .footer-col ul { display: flex; flex-direction: column; gap: 10px; }
        .footer-col a { font-size: 14px; color: var(--ink-soft); transition: color 0.2s; }
        .footer-col a:hover { color: var(--ink); }
        @media (max-width: 639px) {
          .footer { padding: 56px 0 40px; }
          .footer-top { gap: 30px; }
          .footer-brand {
            padding: 18px;
            border: 1px solid color-mix(in srgb, var(--ink) 12%, transparent);
            border-radius: 18px;
            background: color-mix(in srgb, var(--ink) 3%, transparent);
          }
          .footer-brand .nav-logo { height: 34px; }
          .footer-brand .nav-logo-wordmark { height: 30px; }
          .footer-tag { margin-top: 16px; max-width: none; }
          .footer-socials a { width: 42px; height: 42px; }
          .footer-cols {
            grid-template-columns: repeat(2, minmax(0, 1fr));
            gap: 28px 20px;
          }
          .footer-col h4 { margin-bottom: 13px; font-size: 9px; }
          .footer-col ul { gap: 9px; }
          .footer-col a { font-size: 13px; line-height: 1.25; }
          .footer-col:nth-child(3) {
            grid-column: 1 / -1;
            padding-top: 22px;
            border-top: 1px solid color-mix(in srgb, var(--ink) 10%, transparent);
          }
          .footer-col:nth-child(3) ul {
            display: grid;
            grid-template-columns: repeat(2, minmax(0, 1fr));
            gap: 9px 20px;
          }
        }
      `}</style>
    </footer>
  );
}

function FooterCol({ title, links }) {
  return (
    <div className="footer-col">
      <h4>{title}</h4>
      <ul>
        {links.map(link => (
          <li key={link.label}><a href={link.href}>{link.label}</a></li>
        ))}
      </ul>
    </div>
  );
}

// ============== NAV ==============
function Nav() {
  const [open, setOpen] = useState(false);
  const links = [
    { label: 'Features', href: '#benefits' },
    { label: 'How it works', href: '#how' },
    { label: 'Pricing', href: '#pricing' },
    { label: 'FAQ', href: '#faq' },
  ];

  useEffect(() => {
    if (!open) return;
    const onKey = (event) => {
      if (event.key === 'Escape') setOpen(false);
    };
    window.addEventListener('keydown', onKey);
    return () => window.removeEventListener('keydown', onKey);
  }, [open]);

  return (
    <nav className={`nav ${open ? 'nav-open' : ''}`} aria-label="Primary">
      <div className="nav-inner">
        <div className="nav-brand-desktop"><Logo/></div>
        <div className="nav-brand-mobile"><Logo/></div>
        <div className="nav-links">
          {links.map(link => (
            <a key={link.href} href={link.href} className="nav-link">{link.label}</a>
          ))}
        </div>
        <a href="#download" className="nav-cta nav-cta-desktop">Download</a>
        <button
          className="nav-menu-btn"
          type="button"
          aria-label={open ? 'Close menu' : 'Open menu'}
          aria-expanded={open}
          onClick={() => setOpen(v => !v)}
        >
          <span></span>
          <span></span>
        </button>
      </div>
      <div className="nav-mobile-panel">
        {links.map(link => (
          <a key={link.href} href={link.href} onClick={() => setOpen(false)}>{link.label}</a>
        ))}
        <a className="nav-mobile-download" href="#download" onClick={() => setOpen(false)}>Download</a>
      </div>
    </nav>
  );
}

Object.assign(window, {
  LogoStrip, ValueBento, HowItWorks, Testimonials, Pricing, FAQ, DownloadCTA, Footer, Nav,
});
