// Technology — microfluidics explainer
const Technology = () => {
  return (
    <section id="technology" className="section" style={{ paddingTop: 160 }}>
      {/* Section header */}
      <div style={{
        display: 'grid',
        gridTemplateColumns: '1fr 2fr',
        gap: 64,
        marginBottom: 96,
        alignItems: 'start',
      }} className="tech-header">
        <div style={{ display: 'flex', flexDirection: 'column', gap: 16 }}>
          <span className="sec-num">— 01 / Technology</span>
          <span className="eyebrow">Microfluidics, refined</span>
        </div>
        <h2 className="h-section">
          A laboratory the size of<br/>
          a <em>credit card.</em>
        </h2>
      </div>

      {/* Three-column explainer */}
      <div style={{
        display: 'grid',
        gridTemplateColumns: '1fr 1fr 1fr',
        gap: 1,
        background: 'var(--rule-soft)',
        border: '1px solid var(--rule-soft)',
      }} className="tech-grid">
        {[
          {
            num: '01',
            title: 'Picoliter precision',
            body: 'Reagents move through etched channels in volumes a million times smaller than a standard pipette. Mixing happens by laminar flow, not stirring — every reaction is identical.',
            diagram: <DiagramChannels />,
          },
          {
            num: '02',
            title: 'Continuous flow chemistry',
            body: 'No tube transfers. No bench time. The full library prep — DNA extraction, fragmentation, tagmentation, PCR, clean-up — runs as one uninterrupted flow through a single cartridge.',
            diagram: <DiagramFlow />,
          },
          {
            num: '03',
            title: 'Massively parallel',
            body: 'Each cartridge runs 96 libraries in parallel. Stack cartridges into the NGI rack and scale linearly to 9,600+ libraries per shift, with zero cross-contamination.',
            diagram: <DiagramParallel />,
          },
        ].map((item, i) => (
          <div key={i} style={{
            background: 'var(--bone)',
            padding: '40px 32px',
            display: 'flex',
            flexDirection: 'column',
            gap: 24,
            minHeight: 480,
          }}>
            <div style={{
              display: 'flex',
              justifyContent: 'space-between',
              alignItems: 'center',
            }}>
              <span className="mono" style={{
                fontSize: 11,
                color: 'var(--ink-mute)',
                letterSpacing: '0.04em',
              }}>{item.num}</span>
              <span style={{
                width: 6, height: 6, borderRadius: '50%',
                background: 'var(--accent)',
              }}/>
            </div>

            <div style={{
              height: 160,
              borderTop: '1px solid var(--rule-soft)',
              borderBottom: '1px solid var(--rule-soft)',
              padding: '20px 0',
              display: 'flex',
              alignItems: 'center',
              justifyContent: 'center',
            }}>
              {item.diagram}
            </div>

            <h3 style={{
              fontFamily: 'var(--serif)',
              fontSize: 28,
              lineHeight: 1.05,
              letterSpacing: '-0.02em',
              fontWeight: 380,
            }}>{item.title}</h3>

            <p style={{
              fontSize: 14.5,
              lineHeight: 1.5,
              color: 'var(--ink-soft)',
              margin: 0,
            }}>{item.body}</p>
          </div>
        ))}
      </div>

      {/* Detail row */}
      <div style={{
        marginTop: 96,
        display: 'grid',
        gridTemplateColumns: '1fr 1fr',
        gap: 80,
        alignItems: 'center',
      }} className="tech-detail">
        <div>
          <span className="eyebrow" style={{display:'block', marginBottom: 24}}>
            <span className="marker"></span>Why microfluidics wins
          </span>
          <h3 style={{
            fontFamily: 'var(--serif)',
            fontSize: 'clamp(28px, 3vw, 44px)',
            lineHeight: 1.05,
            letterSpacing: '-0.02em',
            fontWeight: 380,
            marginBottom: 24,
          }}>
            Bench protocols were designed for human hands. Ours weren't.
          </h3>
          <p style={{
            fontSize: 16,
            lineHeight: 1.6,
            color: 'var(--ink-soft)',
            marginBottom: 32,
            maxWidth: '50ch',
          }}>
            Every step in conventional library prep — pipetting, vortexing, magnetic bead cleanup — exists because of the limits of plastic tubes. Microfluidics removes the tube. Reagents flow precisely where they need to be, when they need to be there. The reaction finishes when physics says it does, not when a robot finishes its arm sweep.
          </p>

          <div style={{display:'flex', flexDirection:'column', gap: 16, borderTop:'1px solid var(--rule)', paddingTop: 24}}>
            {[
              ['Reagent volume', '−98%', 'less consumable cost per library'],
              ['Hands-on time', '<2 min', 'load cartridge, press start'],
              ['Variance (CV)', '<3%', 'across 10,000 libraries'],
            ].map(([k, v, sub], i) => (
              <div key={i} className="tech-metric-row" style={{
                display: 'grid',
                gridTemplateColumns: '1fr auto 1.5fr',
                gap: 24,
                alignItems: 'baseline',
                paddingBottom: 12,
                borderBottom: i < 2 ? '1px solid var(--rule-soft)' : 'none',
              }}>
                <span style={{ fontSize: 14, color: 'var(--ink)' }}>{k}</span>
                <span className="serif" style={{
                  fontSize: 28,
                  letterSpacing: '-0.02em',
                  fontWeight: 380,
                  color: 'var(--accent)',
                }}>{v}</span>
                <span className="mono" style={{
                  fontSize: 11,
                  color: 'var(--ink-mute)',
                  letterSpacing: '0.04em',
                  textTransform: 'uppercase',
                }}>{sub}</span>
              </div>
            ))}
          </div>
        </div>

        {/* Cartridge cross-section */}
        <CartridgeCrossSection />
      </div>

      <style>{`
        @media (max-width: 900px) {
          .tech-header { grid-template-columns: 1fr !important; gap: 24px !important; }
          .tech-grid { grid-template-columns: 1fr !important; }
          .tech-detail { grid-template-columns: 1fr !important; gap: 48px !important; }
        }
        @media (max-width: 600px) {
          .tech-grid > div { padding: 32px 22px !important; min-height: 0 !important; }
          .tech-detail .tech-metric-row { grid-template-columns: 1fr auto !important; gap: 8px 16px !important; }
          .tech-detail .tech-metric-row > :last-child { grid-column: 1 / -1; }
        }
      `}</style>
    </section>
  );
};

// Small SVG diagrams for the three columns
const DiagramChannels = () => (
  <svg viewBox="0 0 200 120" width="100%" height="100%" style={{maxHeight: 140}}>
    {[0,1,2,3,4,5,6].map(i => (
      <path key={i}
        d={`M 10 ${20 + i*14} Q 100 ${20 + i*14 + (i%2?8:-8)} 190 ${20 + i*14}`}
        stroke="var(--ink)"
        strokeWidth="0.6"
        fill="none"
        opacity={0.3 + i*0.1}
      />
    ))}
    {/* Highlight active channel */}
    <path d="M 10 62 Q 100 70 190 62" stroke="var(--accent)" strokeWidth="1.2" fill="none"/>
    <circle cx="50" cy="65" r="2.5" fill="var(--accent)"/>
    <circle cx="120" cy="68" r="2.5" fill="var(--accent)"/>
    <text x="10" y="115" fontFamily="var(--mono)" fontSize="8" fill="var(--ink-mute)">100 µm</text>
    <text x="190" y="115" fontFamily="var(--mono)" fontSize="8" fill="var(--ink-mute)" textAnchor="end">PDMS / glass</text>
  </svg>
);

const DiagramFlow = () => (
  <svg viewBox="0 0 200 120" width="100%" height="100%" style={{maxHeight: 140}}>
    {/* Steps in a line */}
    {[20, 60, 100, 140, 180].map((x, i) => (
      <g key={i}>
        <circle cx={x} cy="60" r="10" fill="none" stroke="var(--ink)" strokeWidth="0.8"/>
        <text x={x} y="64" fontFamily="var(--mono)" fontSize="8" textAnchor="middle" fill="var(--ink)">{i+1}</text>
      </g>
    ))}
    {/* Connecting line */}
    <line x1="30" y1="60" x2="50" y2="60" stroke="var(--ink)" strokeWidth="0.6"/>
    <line x1="70" y1="60" x2="90" y2="60" stroke="var(--ink)" strokeWidth="0.6"/>
    <line x1="110" y1="60" x2="130" y2="60" stroke="var(--ink)" strokeWidth="0.6"/>
    <line x1="150" y1="60" x2="170" y2="60" stroke="var(--ink)" strokeWidth="0.6"/>
    {/* Continuous flow indicator */}
    <path d="M 10 60 H 190" stroke="var(--accent)" strokeWidth="0.5" strokeDasharray="2 3" opacity="0.6"/>
    <text x="100" y="25" fontFamily="var(--mono)" fontSize="8" fill="var(--ink-mute)" textAnchor="middle" letterSpacing="0.5">UNINTERRUPTED FLOW</text>
    <text x="20" y="100" fontFamily="var(--mono)" fontSize="7" fill="var(--ink-mute)">FRAG</text>
    <text x="60" y="100" fontFamily="var(--mono)" fontSize="7" fill="var(--ink-mute)">REPAIR</text>
    <text x="100" y="100" fontFamily="var(--mono)" fontSize="7" fill="var(--ink-mute)" textAnchor="middle">LIGATE</text>
    <text x="140" y="100" fontFamily="var(--mono)" fontSize="7" fill="var(--ink-mute)" textAnchor="middle">CLEAN</text>
    <text x="180" y="100" fontFamily="var(--mono)" fontSize="7" fill="var(--ink-mute)" textAnchor="middle">PCR</text>
  </svg>
);

const DiagramParallel = () => (
  <svg viewBox="0 0 200 120" width="100%" height="100%" style={{maxHeight: 140}}>
    {/* 8x12 grid of dots = 96 */}
    {Array.from({length: 8}).map((_, r) =>
      Array.from({length: 12}).map((_, c) => {
        const active = (r+c) % 4 !== 0;
        return (
          <circle
            key={`${r}-${c}`}
            cx={30 + c*12}
            cy={20 + r*10}
            r="2"
            fill={active ? 'var(--ink)' : 'var(--accent)'}
            opacity={active ? 0.7 : 1}
          />
        );
      })
    )}
    <text x="30" y="115" fontFamily="var(--mono)" fontSize="8" fill="var(--ink-mute)">96 wells / cartridge</text>
  </svg>
);

const CartridgeCrossSection = () => (
  <div style={{
    border: '1px solid var(--rule)',
    background: 'var(--paper)',
    padding: 32,
    aspectRatio: '4/5',
    position: 'relative',
    display: 'flex',
    flexDirection: 'column',
  }}>
    <div style={{
      display: 'flex', justifyContent: 'space-between',
      fontFamily: 'var(--mono)', fontSize: 10, color: 'var(--ink-mute)',
      letterSpacing: '0.04em', textTransform: 'uppercase',
      marginBottom: 16,
    }}>
      <span>Fig. 02</span>
      <span>NGI–01 Cartridge — top view</span>
    </div>

    <svg viewBox="0 0 320 400" style={{flex:1, width:'100%'}}>
      {/* Soft drop shadow */}
      <defs>
        <filter id="cart-shadow" x="-20%" y="-20%" width="140%" height="140%">
          <feGaussianBlur in="SourceAlpha" stdDeviation="3"/>
          <feOffset dx="0" dy="4"/>
          <feComponentTransfer><feFuncA type="linear" slope="0.12"/></feComponentTransfer>
          <feMerge><feMergeNode/><feMergeNode in="SourceGraphic"/></feMerge>
        </filter>
      </defs>

      {/* Cartridge body — rounded card */}
      <g filter="url(#cart-shadow)">
        <rect x="40" y="40" width="240" height="320" rx="14" fill="var(--bone)" stroke="var(--ink)" strokeWidth="1"/>
        {/* Inner panel — slightly inset, suggests window into channels */}
        <rect x="56" y="80" width="208" height="260" rx="6" fill="var(--paper)" stroke="var(--ink-mute)" strokeWidth="0.6"/>
      </g>

      {/* Top label area */}
      <g>
        <text x="64" y="62" fontFamily="var(--sans)" fontSize="11" fontWeight="500" fill="var(--ink)" letterSpacing="-0.01em">NGI–01</text>
        <text x="256" y="62" fontFamily="var(--mono)" fontSize="8" fill="var(--ink-mute)" textAnchor="end" letterSpacing="0.5">LOT 2026·041</text>
        {/* Barcode */}
        <g transform="translate(64, 68)">
          {[1,2,1,3,1,2,1,1,2,1,3,1,2,1,1,2,1].map((w, i, arr) => {
            const x = arr.slice(0, i).reduce((a,b) => a+b+1, 0);
            return <rect key={i} x={x} y="0" width={w} height="6" fill="var(--ink)"/>;
          })}
        </g>
      </g>

      {/* Sample inlet wells — left column */}
      {[0,1,2,3,4,5].map(i => (
        <g key={`in-${i}`}>
          <circle cx="76" cy={108 + i*38} r="6" fill="var(--bone-2)" stroke="var(--ink)" strokeWidth="0.8"/>
          <circle cx="76" cy={108 + i*38} r="2" fill="var(--ink)"/>
        </g>
      ))}
      <text x="76" y="350" fontFamily="var(--mono)" fontSize="7" fill="var(--ink-mute)" textAnchor="middle" letterSpacing="0.5">INLETS</text>

      {/* Library outlet wells — right column */}
      {[0,1,2,3,4,5].map(i => (
        <g key={`out-${i}`}>
          <circle cx="244" cy={108 + i*38} r="6" fill="var(--accent-soft)" stroke="var(--ink)" strokeWidth="0.8"/>
          <circle cx="244" cy={108 + i*38} r="2" fill="var(--accent)"/>
        </g>
      ))}
      <text x="244" y="350" fontFamily="var(--mono)" fontSize="7" fill="var(--ink-mute)" textAnchor="middle" letterSpacing="0.5">OUTLETS</text>

      {/* Channel network — flowing left to right through center */}
      <g stroke="var(--ink-mute)" strokeWidth="0.6" fill="none" opacity="0.55">
        {[0,1,2,3,4,5].map(i => {
          const y = 108 + i * 38;
          return (
            <path key={i}
              d={`M 84 ${y} L 110 ${y} Q 130 ${y}, 140 ${(y + 222) / 2} L 140 222 L 180 222 L 180 ${(y + 222) / 2} Q 190 ${y}, 210 ${y} L 236 ${y}`}
            />
          );
        })}
      </g>

      {/* Central reaction zone */}
      <rect x="124" y="200" width="72" height="44" rx="3" fill="var(--accent-soft)" stroke="var(--ink)" strokeWidth="0.7"/>
      <text x="160" y="218" fontFamily="var(--mono)" fontSize="8" fill="var(--ink)" textAnchor="middle" letterSpacing="0.5">REACTION</text>
      <text x="160" y="230" fontFamily="var(--mono)" fontSize="8" fill="var(--ink)" textAnchor="middle" letterSpacing="0.5">CHAMBER</text>
      <text x="160" y="240" fontFamily="var(--mono)" fontSize="6.5" fill="var(--ink-mute)" textAnchor="middle" letterSpacing="0.5">85 × 24 mm</text>

      {/* Tick scale at bottom of inner panel */}
      <g fontFamily="var(--mono)" fontSize="7" fill="var(--ink-mute)" letterSpacing="0.5">
        <line x1="64" y1="328" x2="256" y2="328" stroke="var(--ink-mute)" strokeWidth="0.4"/>
        {[64, 112, 160, 208, 256].map((x, i) => (
          <g key={i}>
            <line x1={x} y1="326" x2={x} y2="330" stroke="var(--ink-mute)" strokeWidth="0.4"/>
            <text x={x} y="338" textAnchor="middle">{[0,20,40,60,85][i]}</text>
          </g>
        ))}
        <text x="160" y="350" textAnchor="middle">MILLIMETERS</text>
      </g>

      {/* Footer — model meta */}
      <g fontFamily="var(--mono)" fontSize="6" fill="var(--ink-mute)" letterSpacing="0.6">
        <text x="40" y="384">CARTRIDGE</text>
        <text x="280" y="384" textAnchor="end">SINGLE-USE · STERILE</text>
      </g>
    </svg>
  </div>
);

window.Technology = Technology;
