// KLIK section pages — Cover, System, ClickSystem, Catalog, Materials

function PageHead({ eyebrow, title, sub }) {
  return (
    <header className="klik-pagehead">
      <div className="klik-pagehead-eyebrow">{eyebrow}</div>
      <h1 className="klik-pagehead-title">{title}</h1>
      <p className="klik-pagehead-sub">{sub}</p>
      <div className="klik-pagehead-rule"/>
    </header>
  );
}

function CoverPage() {
  return (
    <div className="klik-page klik-cover">
      <div className="klik-cover-frame">
        <div className="klik-cover-top">
          <div className="klik-cover-eyebrow">
            <span className="klik-dot"/> SYSTEM.01 · INTRODUCING
          </div>
          <div className="klik-cover-meta">
            <span>DOC. KLK-001</span>
            <span>REV. 06.2026</span>
            <span>CONFIDENTIAL</span>
          </div>
        </div>

        <div className="klik-cover-hero">
          <img src="/static/hero.png" alt="KLIK assembled pipe — brushed copper head, brushed steel tube, polished steel mouthpiece"/>
          <div className="klik-cover-hero-overlay">
            <div className="klik-overlay-tag klik-overlay-tag-tl">
              <div className="klik-overlay-line"/>
              <div>
                <div className="klik-overlay-k">HEAD</div>
                <div className="klik-overlay-v">H-CHAMBER · BRUSHED Cu</div>
              </div>
            </div>
            <div className="klik-overlay-tag klik-overlay-tag-tr">
              <div className="klik-overlay-line klik-overlay-line-r"/>
              <div>
                <div className="klik-overlay-k">MOUTHPIECE</div>
                <div className="klik-overlay-v">M-MEDIUM · POLISHED Steel</div>
              </div>
            </div>
            <div className="klik-overlay-tag klik-overlay-tag-bl">
              <div className="klik-overlay-line"/>
              <div>
                <div className="klik-overlay-k">JOINT</div>
                <div className="klik-overlay-v">N52 NEODYMIUM · ⌀14 · 4.2kg PULL</div>
              </div>
            </div>
          </div>
        </div>

        <div className="klik-cover-bottom">
          <div>
            <h1 className="klik-wordmark">
              <span className="klik-wm-k">K</span>
              <span className="klik-wm-l">L</span>
              <span className="klik-wm-i">I</span>
              <span className="klik-wm-k2">K</span>
            </h1>
            <p className="klik-cover-blurb">
              A modular dry-herb pipe system. Click-on heads, tubes and mouthpieces in
              copper, steel and brass — held together by precision-aligned neodymium
              rings and food-grade silicone seals. <strong>Thirty-six combinations.</strong>
              <strong> One pipe that grows with you.</strong>
            </p>
          </div>
          <div>
            <div className="klik-tagline">SNAP. SEAL. SMOKE.</div>
            <div className="klik-cover-stats">
              <div className="klik-stat">
                <div className="klik-stat-v">36</div>
                <div className="klik-stat-k">combinations from 10 parts</div>
              </div>
              <div className="klik-stat">
                <div className="klik-stat-v">&lt;1s</div>
                <div className="klik-stat-k">swap any part, no tools</div>
              </div>
              <div className="klik-stat">
                <div className="klik-stat-v">N52</div>
                <div className="klik-stat-k">neodymium ring-magnet joint</div>
              </div>
              <div className="klik-stat">
                <div className="klik-stat-v">FDA</div>
                <div className="klik-stat-k">food-grade silicone seal</div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  );
}

function SystemPage() {
  return (
    <div className="klik-page klik-system">
      <PageHead eyebrow="02 / THE SYSTEM" title="Ten parts. Thirty-six pipes." sub="Four tubes. Three heads. Three mouthpieces. Mix them freely — every joint speaks the same magnetic language."/>
      <div className="klik-sys-grid">
        <div className="klik-sys-block">
          <div className="klik-sys-head"><span>HEADS</span><span className="klik-sys-count">× 3</span></div>
          <div className="klik-sys-row">
            {window.HEADS.map(h => (
              <div key={h.id} className="klik-sys-card">
                <div className="klik-sys-svg klik-sys-svg-head">
                  <svg viewBox={`0 0 ${h.vbWidth} 200`} preserveAspectRatio="xMidYMid meet" style={{ width: '100%', height: '100%' }}>
                    <window.HeadGeo part={h} material="brushed-copper"/>
                  </svg>
                </div>
                <div className="klik-sys-id">{h.id}</div>
                <div className="klik-sys-name">{h.name}</div>
                <div className="klik-sys-meta">{h.desc}</div>
              </div>
            ))}
          </div>
        </div>
        <div className="klik-sys-block">
          <div className="klik-sys-head"><span>TUBES</span><span className="klik-sys-count">× 4</span></div>
          <div className="klik-sys-row klik-sys-row-4">
            {window.TUBES.map(t => (
              <div key={t.id} className="klik-sys-card">
                <div className="klik-sys-svg klik-sys-svg-tube">
                  <svg viewBox={`0 0 ${t.vbWidth} 200`} preserveAspectRatio="xMidYMid meet" style={{ width: '100%', height: '100%' }}>
                    <window.TubeGeo part={t} material="brushed-steel"/>
                  </svg>
                </div>
                <div className="klik-sys-id">{t.id}</div>
                <div className="klik-sys-name">⌀{t.diameter}mm · {t.lengthIn}</div>
                <div className="klik-sys-meta">{t.lengthMm} mm · {t.weight}g</div>
              </div>
            ))}
          </div>
        </div>
        <div className="klik-sys-block">
          <div className="klik-sys-head"><span>MOUTHPIECES</span><span className="klik-sys-count">× 3</span></div>
          <div className="klik-sys-row">
            {window.MOUTHPIECES.map(m => (
              <div key={m.id} className="klik-sys-card">
                <div className="klik-sys-svg klik-sys-svg-mp">
                  <svg viewBox={`0 0 ${m.vbWidth} 200`} preserveAspectRatio="xMidYMid meet" style={{ width: '100%', height: '100%' }}>
                    <window.MouthpieceGeo part={m} material="polished-steel"/>
                  </svg>
                </div>
                <div className="klik-sys-id">{m.id}</div>
                <div className="klik-sys-name">{m.name}</div>
                <div className="klik-sys-meta">{m.desc}</div>
              </div>
            ))}
          </div>
        </div>
      </div>
      <div className="klik-sys-math">
        <span className="klik-sys-math-eq"><span className="klik-sys-math-n">3</span> heads</span>
        <span className="klik-sys-math-op">×</span>
        <span className="klik-sys-math-eq"><span className="klik-sys-math-n">4</span> tubes</span>
        <span className="klik-sys-math-op">×</span>
        <span className="klik-sys-math-eq"><span className="klik-sys-math-n">3</span> mouthpieces</span>
        <span className="klik-sys-math-op">=</span>
        <span className="klik-sys-math-eq klik-sys-math-result"><span className="klik-sys-math-n">36</span> base configurations</span>
        <span className="klik-sys-math-aside">× 5 materials per part = 4,860 unique builds</span>
      </div>
    </div>
  );
}

function ClickCutaway() {
  const blue = '#7fd4ff';
  const copper = '#e8a878';
  const steel = '#c8d4e0';
  return (
    <svg viewBox="0 0 700 500" style={{ width: '100%', height: '100%', display: 'block' }}>
      <defs>
        <pattern id="hatch" patternUnits="userSpaceOnUse" width="6" height="6" patternTransform="rotate(45)">
          <line x1="0" y1="0" x2="0" y2="6" stroke={blue} strokeWidth="0.4" opacity="0.5"/>
        </pattern>
        <pattern id="hatchCu" patternUnits="userSpaceOnUse" width="6" height="6" patternTransform="rotate(45)">
          <line x1="0" y1="0" x2="0" y2="6" stroke={copper} strokeWidth="0.4" opacity="0.6"/>
        </pattern>
      </defs>
      <g opacity="0.18">
        {Array.from({length: 14}).map((_, i) => (
          <line key={'h'+i} x1={0} y1={i * 40} x2={700} y2={i * 40} stroke={blue} strokeWidth="0.3"/>
        ))}
        {Array.from({length: 18}).map((_, i) => (
          <line key={'v'+i} x1={i * 40} y1={0} x2={i * 40} y2={500} stroke={blue} strokeWidth="0.3"/>
        ))}
      </g>
      {/* LEFT PART body */}
      <path d="M 40 200 L 300 200 L 300 180 L 320 180 L 320 320 L 300 320 L 300 300 L 40 300 Z" fill="url(#hatchCu)" stroke={copper} strokeWidth="1.4"/>
      {/* RIGHT PART body */}
      <path d="M 380 180 L 360 180 L 360 200 L 660 200 L 660 300 L 360 300 L 360 320 L 380 320 Z" fill="url(#hatch)" stroke={steel} strokeWidth="1.4"/>
      {/* Inner bore */}
      <line x1={40} y1={230} x2={660} y2={230} stroke={copper} strokeWidth="0.8" strokeDasharray="6 3" opacity="0.6"/>
      <line x1={40} y1={270} x2={660} y2={270} stroke={copper} strokeWidth="0.8" strokeDasharray="6 3" opacity="0.6"/>
      <text x={350} y={252} textAnchor="middle" fill={blue} fontFamily="'JetBrains Mono', ui-monospace, monospace" fontSize="9" opacity="0.6">⌀8 BORE</text>
      {/* Magnet rings */}
      <rect x={300} y={170} width={20} height={20} fill={blue} opacity="0.18" stroke={blue} strokeWidth="0.6"/>
      <rect x={300} y={310} width={20} height={20} fill={blue} opacity="0.18" stroke={blue} strokeWidth="0.6"/>
      <rect x={360} y={170} width={20} height={20} fill={blue} opacity="0.18" stroke={blue} strokeWidth="0.6"/>
      <rect x={360} y={310} width={20} height={20} fill={blue} opacity="0.18" stroke={blue} strokeWidth="0.6"/>
      <text x={310} y={184} fill={blue} fontFamily="'JetBrains Mono', ui-monospace, monospace" fontSize="7" textAnchor="middle">N</text>
      <text x={310} y={326} fill={blue} fontFamily="'JetBrains Mono', ui-monospace, monospace" fontSize="7" textAnchor="middle">S</text>
      <text x={370} y={184} fill={blue} fontFamily="'JetBrains Mono', ui-monospace, monospace" fontSize="7" textAnchor="middle">S</text>
      <text x={370} y={326} fill={blue} fontFamily="'JetBrains Mono', ui-monospace, monospace" fontSize="7" textAnchor="middle">N</text>
      {/* O-ring */}
      <circle cx={340} cy={180} r={4.5} fill="rgba(255,150,80,0.4)" stroke="#ff9650" strokeWidth="1"/>
      <circle cx={340} cy={320} r={4.5} fill="rgba(255,150,80,0.4)" stroke="#ff9650" strokeWidth="1"/>
      {/* Alignment lug */}
      <rect x={335} y={222} width={10} height={6} fill={blue} opacity="0.5" stroke={blue} strokeWidth="0.5"/>
      <rect x={335} y={272} width={10} height={6} fill={blue} opacity="0.5" stroke={blue} strokeWidth="0.5"/>
      {/* Centerline */}
      <line x1={20} y1={250} x2={680} y2={250} stroke={blue} strokeWidth="0.35" strokeDasharray="6 2 1 2" opacity="0.4"/>
      {/* Callout 01 — Magnet */}
      <line x1={310} y1={180} x2={310} y2={80} stroke={blue} strokeWidth="0.5"/>
      <line x1={310} y1={80} x2={250} y2={80} stroke={blue} strokeWidth="0.5"/>
      <circle cx={240} cy={80} r={10} fill="#0a2540" stroke={blue} strokeWidth="0.8"/>
      <text x={240} y={84} textAnchor="middle" fill={blue} fontFamily="'JetBrains Mono', ui-monospace, monospace" fontSize="10" fontWeight="600">01</text>
      {/* Callout 02 — O-ring */}
      <line x1={340} y1={180} x2={340} y2={120} stroke="#ff9650" strokeWidth="0.5"/>
      <line x1={340} y1={120} x2={420} y2={120} stroke="#ff9650" strokeWidth="0.5"/>
      <circle cx={432} cy={120} r={10} fill="#0a2540" stroke="#ff9650" strokeWidth="0.8"/>
      <text x={432} y={124} textAnchor="middle" fill="#ff9650" fontFamily="'JetBrains Mono', ui-monospace, monospace" fontSize="10" fontWeight="600">02</text>
      {/* Callout 03 — Alignment lug */}
      <line x1={340} y1={278} x2={340} y2={400} stroke={blue} strokeWidth="0.5"/>
      <line x1={340} y1={400} x2={420} y2={400} stroke={blue} strokeWidth="0.5"/>
      <circle cx={432} cy={400} r={10} fill="#0a2540" stroke={blue} strokeWidth="0.8"/>
      <text x={432} y={404} textAnchor="middle" fill={blue} fontFamily="'JetBrains Mono', ui-monospace, monospace" fontSize="10" fontWeight="600">03</text>
      {/* Callout 04 — Internal bore */}
      <line x1={150} y1={250} x2={150} y2={420} stroke={blue} strokeWidth="0.5"/>
      <line x1={150} y1={420} x2={230} y2={420} stroke={blue} strokeWidth="0.5"/>
      <circle cx={240} cy={420} r={10} fill="#0a2540" stroke={blue} strokeWidth="0.8"/>
      <text x={240} y={424} textAnchor="middle" fill={blue} fontFamily="'JetBrains Mono', ui-monospace, monospace" fontSize="10" fontWeight="600">04</text>
      {/* Force arrows */}
      <g opacity="0.7">
        <line x1={290} y1={250} x2={310} y2={250} stroke={blue} strokeWidth="1.2"/>
        <polygon points="310,250 305,247 305,253" fill={blue}/>
        <line x1={390} y1={250} x2={370} y2={250} stroke={blue} strokeWidth="1.2"/>
        <polygon points="370,250 375,247 375,253" fill={blue}/>
        <text x={340} y={245} textAnchor="middle" fill={blue} fontFamily="'JetBrains Mono', ui-monospace, monospace" fontSize="8" opacity="0.85">4.2 kgf</text>
      </g>
      <text x={150} y={195} textAnchor="middle" fill={copper} fontFamily="'JetBrains Mono', ui-monospace, monospace" fontSize="9" opacity="0.85">HEAD-SIDE · Cu</text>
      <text x={530} y={195} textAnchor="middle" fill={steel} fontFamily="'JetBrains Mono', ui-monospace, monospace" fontSize="9" opacity="0.85">TUBE-SIDE · Steel</text>
      <g opacity="0.55">
        <line x1={300} y1={460} x2={380} y2={460} stroke={blue} strokeWidth="0.5"/>
        <line x1={300} y1={455} x2={300} y2={465} stroke={blue} strokeWidth="0.5"/>
        <line x1={380} y1={455} x2={380} y2={465} stroke={blue} strokeWidth="0.5"/>
        <text x={340} y={478} textAnchor="middle" fill={blue} fontFamily="'JetBrains Mono', ui-monospace, monospace" fontSize="9">JOINT · 14.0 mm</text>
      </g>
    </svg>
  );
}

function ClickSystemPage() {
  return (
    <div className="klik-page klik-click">
      <PageHead eyebrow="04 / THE CLICK" title="Magnetic. Aligned. Sealed." sub="Every KLIK joint is engineered to land in one of three positions, snap with 4.2 kg of pull, and seal to the equivalent of a threaded fitting."/>
      <div className="klik-click-grid">
        <div className="klik-click-stage">
          <ClickCutaway/>
        </div>
        <div className="klik-click-side">
          <div className="klik-click-callout">
            <div className="klik-click-callout-n">01</div>
            <div>
              <div className="klik-click-callout-t">Neodymium Ring</div>
              <div className="klik-click-callout-d">N52 grade, ⌀14×⌀10×2mm. Provides 4.2 kg axial pull — strong enough to hold mid-draw, weak enough to release with a slight twist.</div>
            </div>
          </div>
          <div className="klik-click-callout">
            <div className="klik-click-callout-n">02</div>
            <div>
              <div className="klik-click-callout-t">Silicone O-Ring</div>
              <div className="klik-click-callout-d">FDA food-grade, 70A durometer. Compresses 0.4 mm under magnetic load — establishes a near-airtight pneumatic seal. Pull-tested to 4 kPa.</div>
            </div>
          </div>
          <div className="klik-click-callout">
            <div className="klik-click-callout-n">03</div>
            <div>
              <div className="klik-click-callout-t">Alignment Lugs (×3)</div>
              <div className="klik-click-callout-d">120° tri-symmetric. Force a rotational lock — the bowl always orients up, the mouthpiece always orients to the user. No fiddling, no mis-aligned screen.</div>
            </div>
          </div>
          <div className="klik-click-callout">
            <div className="klik-click-callout-n">04</div>
            <div>
              <div className="klik-click-callout-t">Internal Bore</div>
              <div className="klik-click-callout-d">⌀8 mm continuous airway. All parts share the same internal diameter so airflow is never restricted by a joint — only at the mouthpiece taper.</div>
            </div>
          </div>
        </div>
      </div>
      <div className="klik-click-stats">
        <div className="klik-stat-bar"><div className="klik-stat-bar-k">PULL FORCE</div><div className="klik-stat-bar-v">4.2 kg</div></div>
        <div className="klik-stat-bar"><div className="klik-stat-bar-k">SEAL PRESSURE</div><div className="klik-stat-bar-v">4 kPa</div></div>
        <div className="klik-stat-bar"><div className="klik-stat-bar-k">CONNECT/DISCONNECT</div><div className="klik-stat-bar-v">&lt; 0.4 s</div></div>
        <div className="klik-stat-bar"><div className="klik-stat-bar-k">RATED CYCLES</div><div className="klik-stat-bar-v">50,000+</div></div>
      </div>
    </div>
  );
}

function CatalogPage() {
  return (
    <div className="klik-page klik-catalog">
      <PageHead eyebrow="05 / PARTS CATALOG" title="Every part. To scale." sub="Technical drawings with full dimensions. All parts manufactured to ±0.05 mm tolerance."/>
      <div className="klik-cat-section">
        <h3 className="klik-cat-section-title">Heads · 3 variants</h3>
        <div className="klik-cat-grid klik-cat-grid-3">
          {window.HEADS.map(h => (
            <div key={h.id} className="klik-cat-card">
              <div className="klik-cat-card-svg">
                <svg viewBox={`0 0 ${h.vbWidth} 240`} preserveAspectRatio="xMidYMid meet" style={{ width: '100%', height: '100%' }}>
                  <g transform="translate(0 20)"><window.HeadGeo part={h} material="brushed-copper" showCallouts={true}/></g>
                </svg>
              </div>
              <div className="klik-cat-card-foot">
                <div>
                  <div className="klik-cat-id">{h.id}</div>
                  <div className="klik-cat-name">{h.name}</div>
                </div>
                <div className="klik-cat-spec">
                  <div><span>CAP</span><b>{h.capacity}</b></div>
                  <div><span>WT</span><b>{h.weight}g</b></div>
                  <div><span>$</span><b>{h.price}</b></div>
                </div>
              </div>
            </div>
          ))}
        </div>
      </div>
      <div className="klik-cat-section">
        <h3 className="klik-cat-section-title">Tubes · 4 variants</h3>
        <div className="klik-cat-grid klik-cat-grid-2">
          {window.TUBES.map(t => (
            <div key={t.id} className="klik-cat-card">
              <div className="klik-cat-card-svg">
                <svg viewBox={`0 0 ${t.vbWidth} 240`} preserveAspectRatio="xMidYMid meet" style={{ width: '100%', height: '100%' }}>
                  <g transform="translate(0 20)"><window.TubeGeo part={t} material="brushed-steel" showCallouts={true}/></g>
                </svg>
              </div>
              <div className="klik-cat-card-foot">
                <div>
                  <div className="klik-cat-id">{t.id}</div>
                  <div className="klik-cat-name">⌀{t.diameter} × {t.lengthMm} mm</div>
                </div>
                <div className="klik-cat-spec">
                  <div><span>LEN</span><b>{t.lengthIn}</b></div>
                  <div><span>WT</span><b>{t.weight}g</b></div>
                  <div><span>$</span><b>{t.price}</b></div>
                </div>
              </div>
              {t.id === 'T-16-S' && <div className="klik-cat-flag">★ FLAGSHIP / 16mm × 5″</div>}
            </div>
          ))}
        </div>
      </div>
      <div className="klik-cat-section">
        <h3 className="klik-cat-section-title">Mouthpieces · 3 variants</h3>
        <div className="klik-cat-grid klik-cat-grid-3">
          {window.MOUTHPIECES.map(m => (
            <div key={m.id} className="klik-cat-card">
              <div className="klik-cat-card-svg">
                <svg viewBox={`0 0 ${m.vbWidth} 240`} preserveAspectRatio="xMidYMid meet" style={{ width: '100%', height: '100%' }}>
                  <g transform="translate(0 20)"><window.MouthpieceGeo part={m} material="polished-steel" showCallouts={true}/></g>
                </svg>
              </div>
              <div className="klik-cat-card-foot">
                <div>
                  <div className="klik-cat-id">{m.id}</div>
                  <div className="klik-cat-name">{m.name}</div>
                </div>
                <div className="klik-cat-spec">
                  <div><span>WT</span><b>{m.weight}g</b></div>
                  <div><span>$</span><b>{m.price}</b></div>
                </div>
              </div>
            </div>
          ))}
        </div>
      </div>
    </div>
  );
}

function MaterialsPage() {
  const matMeta = {
    'brushed-copper': { story: 'Patinas over time. The pipe you bought becomes the pipe you own.', use: 'Heads · Tubes · Mouthpieces', care: 'Wipe with lemon oil monthly.' },
    'polished-copper': { story: 'Mirror finish. Reflects warm light. Shows every fingerprint — proudly.', use: 'Heads · Mouthpieces', care: 'Microfibre. Avoid abrasives.' },
    'brushed-steel': { story: 'Surgical, quiet, indestructible. The workhorse.', use: 'Tubes · Mouthpieces', care: 'Dishwasher safe.' },
    'polished-steel': { story: 'Cold, sharp, optical. Pairs with copper. Mirror to your hands.', use: 'Tubes · Mouthpieces', care: 'Dishwasher safe.' },
    'brass': { story: 'Gold-tone alloy. Antimicrobial. Grows a living patina.', use: 'Heads · Mouthpieces', care: 'Beeswax annually.' },
  };
  return (
    <div className="klik-page klik-materials">
      <PageHead eyebrow="06 / MATERIALS" title="Five finishes." sub="Each part can be ordered in any of these five materials. Mix freely. Patinas welcome."/>
      <div className="klik-mat-grid">
        {Object.entries(window.MATERIALS).map(([key, m]) => (
          <div key={key} className="klik-mat-card">
            <div className="klik-mat-swatch-big" style={{ background: m.swatch }}>
              <span className="klik-mat-tone-badge">{m.tone}</span>
            </div>
            <div className="klik-mat-card-body">
              <div className="klik-mat-card-id">{key.toUpperCase().replace('-', ' · ')}</div>
              <div className="klik-mat-card-name">{m.name}</div>
              <p className="klik-mat-card-story">{matMeta[key].story}</p>
              <div className="klik-mat-card-rows">
                <div className="klik-mat-card-row">
                  <span>APPLIES TO</span><b>{matMeta[key].use}</b>
                </div>
                <div className="klik-mat-card-row">
                  <span>CARE</span><b>{matMeta[key].care}</b>
                </div>
              </div>
            </div>
          </div>
        ))}
      </div>
      <div className="klik-mat-foot">
        <div>
          <div className="klik-mat-foot-eyebrow">FUTURE / SYSTEM.02</div>
          <div className="klik-mat-foot-title">Anodized titanium and walnut burl coming late 2026.</div>
        </div>
        <div className="klik-mat-foot-line"/>
      </div>
    </div>
  );
}

Object.assign(window, { CoverPage, SystemPage, ClickSystemPage, CatalogPage, MaterialsPage, ClickCutaway, PageHead });
