// corner-system.jsx — "Corner marks as system, not mark."
//
// Argument made visually:
//   (1) W2 standalone — clean, scales down, reads as a glyph.
//   (2) Corner registration pips live on the LAYOUT, not on the logo.
//   (3) The two pieces meet across a page, never inside the mark.
//
// Six artboards:
//   R6-A  Specimen — the two primitives, one rule
//   R6-B  Scale test — W2 alone vs V1 (W2 + crop marks) at 16/32/64/120
//   R6-C  Letterhead — pips at the page corners, W2 in the lockup
//   R6-D  Business card — pips at the card bleed, W2 in the lockup
//   R6-E  Datasheet section block — pips framing the part-no register
//   R6-F  Web content card — pips as a recurring module frame

const CS_BLUE = '#003DA5';
const CS_INK  = '#111111';
const CS_GREY = '#666666';
const CS_RULE = '#dcd9d2';
const CS_BG   = '#f0eee9';

// ─────────────────────────────────────────────────────────────
// Primitive: page-corner registration pips.
// Renders four filled squares at the corners of its parent box.
// `inset` is the distance from the parent edge to the OUTER edge
// of the pip (in px). `size` is the pip side length.
// ─────────────────────────────────────────────────────────────
function CornerPips({ size = 8, inset = 16, color = CS_BLUE }) {
  const s = { position:'absolute', width: size, height: size, background: color };
  return (
    <React.Fragment>
      <div style={{ ...s, top: inset,    left: inset    }} />
      <div style={{ ...s, top: inset,    right: inset   }} />
      <div style={{ ...s, bottom: inset, left: inset    }} />
      <div style={{ ...s, bottom: inset, right: inset   }} />
    </React.Fragment>
  );
}

// Variant: tick-style crop marks (two-line registration ticks),
// closer to printer's setup marks than filled pips. Used at
// page-scale where filled squares would feel decorative.
function CornerTicks({ length = 14, thickness = 1.25, inset = 20, color = CS_INK, gap = 6 }) {
  const tickHoriz = (x, y) => ({
    position:'absolute', height: thickness, width: length,
    background: color, left: x, top: y,
  });
  const tickVert = (x, y) => ({
    position:'absolute', width: thickness, height: length,
    background: color, left: x, top: y,
  });
  return (
    <React.Fragment>
      {/* TL */}
      <div style={tickHoriz(inset, inset + gap)} />
      <div style={tickVert(inset + gap, inset)} />
      {/* TR */}
      <div style={{ ...tickHoriz(0, inset + gap), right: inset, left: 'auto' }} />
      <div style={{ ...tickVert(0, inset), right: inset + gap, left: 'auto' }} />
      {/* BL */}
      <div style={{ ...tickHoriz(inset, 0), bottom: inset + gap, top: 'auto' }} />
      <div style={{ ...tickVert(inset + gap, 0), bottom: inset, top: 'auto' }} />
      {/* BR */}
      <div style={{ ...tickHoriz(0, 0), right: inset, left: 'auto', bottom: inset + gap, top: 'auto' }} />
      <div style={{ ...tickVert(0, 0), right: inset + gap, left: 'auto', bottom: inset, top: 'auto' }} />
    </React.Fragment>
  );
}

// ─────────────────────────────────────────────────────────────
// R6-A · Specimen — the two primitives, side by side.
// Left column: W2 mark, big, isolated.
// Right column: the four corner pips, isolated.
// Rule at the bottom: "they meet on the page, not inside the mark."
// ─────────────────────────────────────────────────────────────
function CSSpecimen() {
  return (
    <div style={{
      width: 1380, height: 460, background:'#fff', color: CS_INK,
      padding:'36px 56px 32px', boxSizing:'border-box',
      display:'flex', flexDirection:'column', justifyContent:'space-between',
      boxShadow:'inset 0 0 0 1px #ececec', position:'relative',
      fontFamily:'"Helvetica Neue", Helvetica, Arial, sans-serif',
    }}>
      <div style={{
        display:'flex', justifyContent:'space-between',
        fontFamily:'"IBM Plex Mono", monospace', fontSize: 11,
        letterSpacing:'0.08em', color: CS_GREY,
      }}>
        <span>ROUND 08 · SYSTEM SPLIT · MARK + LAYOUT PRIMITIVE</span>
        <span>R6-A · SPECIMEN</span>
      </div>

      <div style={{ display:'grid', gridTemplateColumns:'1fr 1px 1fr', gap: 48, alignItems:'stretch' }}>
        {/* Mark column */}
        <div style={{ display:'flex', flexDirection:'column', alignItems:'flex-start', gap: 18 }}>
          <div style={{
            fontFamily:'"IBM Plex Mono", monospace', fontSize: 10,
            letterSpacing:'0.1em', color: CS_BLUE,
          }}>PRIMITIVE 01 · MARK</div>
          <div style={{ display:'flex', alignItems:'center', gap: 32 }}>
            <MarkBuiltNarrow size={180} color={CS_BLUE} />
            <div style={{ maxWidth: 360 }}>
              <div style={{ fontSize: 22, lineHeight: 1.25, letterSpacing:'-0.01em', marginBottom: 10 }}>
                W2 alone. Narrow, upright, typographic.
              </div>
              <div style={{ fontSize: 12, lineHeight: 1.55, color:'#444' }}>
                Carries the semiconductor read by proportion, not by
                ornament. Survives 16&nbsp;px. Locks up cleanly with the
                wordmark with nothing extra to balance.
              </div>
            </div>
          </div>
        </div>

        <div style={{ background: CS_RULE }} />

        {/* Layout primitive column */}
        <div style={{ display:'flex', flexDirection:'column', alignItems:'flex-start', gap: 18 }}>
          <div style={{
            fontFamily:'"IBM Plex Mono", monospace', fontSize: 10,
            letterSpacing:'0.1em', color: CS_BLUE,
          }}>PRIMITIVE 02 · LAYOUT</div>
          <div style={{ display:'flex', alignItems:'center', gap: 32 }}>
            <div style={{
              position:'relative', width: 180, height: 180,
              boxShadow:'inset 0 0 0 1px #ececec', background:'#fafaf7',
            }}>
              <CornerPips size={10} inset={10} color={CS_BLUE} />
            </div>
            <div style={{ maxWidth: 360 }}>
              <div style={{ fontSize: 22, lineHeight: 1.25, letterSpacing:'-0.01em', marginBottom: 10 }}>
                Corner pips. A page rule, not a logo rule.
              </div>
              <div style={{ fontSize: 12, lineHeight: 1.55, color:'#444' }}>
                Sit at the corners of pages, cards, and section blocks
                across the system. Read as registration / crop marks
                from print &mdash; the same vocabulary as a fab
                datasheet.
              </div>
            </div>
          </div>
        </div>
      </div>

      <div style={{
        fontFamily:'"IBM Plex Mono", monospace', fontSize: 10,
        letterSpacing:'0.08em', color: CS_GREY,
        borderTop:`1px solid ${CS_RULE}`, paddingTop: 14,
      }}>
        RULE — THE TWO PRIMITIVES MEET ACROSS A LAYOUT. THEY NEVER COMBINE INSIDE THE MARK.
      </div>
    </div>
  );
}

// ─────────────────────────────────────────────────────────────
// R6-B · Scale test
// W2 alone vs W6 (W2 + crop marks baked in) at 16 / 32 / 64 / 120 px.
// The point: at favicon / nav-bar scale, the bolted-on pips
// disappear into noise. W2 stays legible. So the pips weren't
// adding signal where it mattered — better to spend that
// surface on the layout.
// ─────────────────────────────────────────────────────────────
function CSScaleTest() {
  const sizes = [16, 32, 64, 120];
  const Row = ({ label, Comp, sub }) => (
    <div style={{ display:'flex', flexDirection:'column', gap: 10 }}>
      <div style={{
        display:'flex', justifyContent:'space-between',
        fontFamily:'"IBM Plex Mono", monospace', fontSize: 10,
        letterSpacing:'0.08em', color: CS_GREY,
      }}>
        <span>{label}</span>
        <span>{sub}</span>
      </div>
      <div style={{
        display:'flex', alignItems:'flex-end', gap: 32,
        padding:'18px 22px', background:'#fafaf7',
        boxShadow:`inset 0 0 0 1px ${CS_RULE}`,
      }}>
        {sizes.map((s) => (
          <div key={s} style={{ display:'flex', flexDirection:'column', alignItems:'center', gap: 8 }}>
            <Comp size={s} color={CS_BLUE} />
            <span style={{
              fontFamily:'"IBM Plex Mono", monospace', fontSize: 9,
              letterSpacing:'0.06em', color: CS_GREY,
            }}>{s}px</span>
          </div>
        ))}
      </div>
    </div>
  );
  return (
    <div style={{
      width: 1380, height: 380, background:'#fff', color: CS_INK,
      padding:'30px 40px', boxSizing:'border-box',
      display:'flex', flexDirection:'column', gap: 18,
      boxShadow:'inset 0 0 0 1px #ececec',
      fontFamily:'"Helvetica Neue", Helvetica, Arial, sans-serif',
    }}>
      <div style={{
        display:'flex', justifyContent:'space-between',
        fontFamily:'"IBM Plex Mono", monospace', fontSize: 11,
        letterSpacing:'0.08em', color: CS_GREY,
      }}>
        <span>R6-B · SCALE TEST · WHERE THE BAKED-IN PIPS GO TO DIE</span>
        <span>16 / 32 / 64 / 120 PX</span>
      </div>
      <Row label="W2 — MARK ALONE"            sub="legible at 16px" Comp={MarkBuiltNarrow} />
      <Row label="W6 — W2 + CROP MARKS BAKED" sub="pips collapse below 32px" Comp={MarkBuiltCrop} />
      <div style={{ fontSize: 12, lineHeight: 1.55, color:'#444', maxWidth: 1100 }}>
        Below ~32 px the corner squares stop being legible &mdash; they smear into the
        leg edges and reduce contrast around the N. Pushing the pips out to the layout
        gives them room to do their job, and gives the mark room to do its.
      </div>
    </div>
  );
}

// ─────────────────────────────────────────────────────────────
// R6-C · Letterhead with corner registration marks at the page.
// Pips live on the page; mark lives in the lockup.
// ─────────────────────────────────────────────────────────────
function CSLetterhead() {
  return (
    <div style={{
      width: 612, height: 792, background:'#fff', color: CS_INK,
      position:'relative', boxShadow:'inset 0 0 0 1px #ececec',
      fontFamily:'"Helvetica Neue", Helvetica, Arial, sans-serif',
      overflow:'hidden',
    }}>
      <CornerPips size={7} inset={28} color={CS_BLUE} />

      {/* Top band — lockup */}
      <div style={{ padding:'72px 56px 0 56px' }}>
        <Lockup palette="B" markComp={MarkBuiltNarrow} size={13} />
        <div style={{
          marginTop: 18, display:'flex', justifyContent:'space-between',
          fontFamily:'"IBM Plex Mono", monospace', fontSize: 9,
          letterSpacing:'0.08em', color: CS_GREY,
        }}>
          <span>OFFICE OF THE CORPORATE SECRETARY</span>
          <span>TELEX&nbsp;&nbsp;510-3211 NATLSEMI</span>
        </div>
      </div>

      {/* Body block — memorandum to the file, no recipient, no street */}
      <div style={{ padding:'92px 56px 0 56px', fontSize: 11.5, lineHeight: 1.7, color:'#222', maxWidth: 460 }}>
        <div style={{ marginBottom: 24, fontFamily:'"IBM Plex Mono", monospace', fontSize: 10, color: CS_GREY, letterSpacing:'0.06em' }}>
          14 MAY 1986
        </div>
        <div style={{ marginBottom: 22, fontFamily:'"IBM Plex Mono", monospace', fontSize: 9, letterSpacing:'0.08em', color: CS_GREY }}>
          MEMORANDUM FOR THE FILE
        </div>
        <div style={{ marginBottom: 18 }}>
          The matter referenced above has been noted and recorded.
          No reply is invited or required.
        </div>
        <div style={{ marginBottom: 18 }}>
          Communications to the Company are not accepted by post,
          telephone or facsimile. Where a response is contemplated
          by these terms, it shall be made by telex or marine cable
          to the address shown in the header.
        </div>
        <div style={{ marginTop: 36 }}>For the Company,</div>
        <div style={{ marginTop: 38 }}>William&nbsp;S.&nbsp;Fraser</div>
        <div style={{ color:'#444' }}>Office of the Corporate Secretary</div>
      </div>

      {/* Footer — telex + marine cable, no street */}
      <div style={{
        position:'absolute', bottom: 56, left: 56, right: 56,
        display:'flex', justifyContent:'space-between',
        fontFamily:'"IBM Plex Mono", monospace', fontSize: 9,
        letterSpacing:'0.08em', color: CS_GREY,
        borderTop:`1px solid ${CS_RULE}`, paddingTop: 12,
      }}>
        <span>TELEX&nbsp;&nbsp;510-3211 NATLSEMI</span>
        <span>MARINE CABLE&nbsp;&nbsp;NATLSEMI&nbsp;NEW&nbsp;YORK</span>
      </div>

      {/* annotation badge */}
      <div style={{
        position:'absolute', top: 28, right: 64,
        fontFamily:'"IBM Plex Mono", monospace', fontSize: 8.5,
        letterSpacing:'0.1em', color: CS_BLUE,
      }}>
        ← PIPS LIVE HERE, NOT ON THE MARK
      </div>
    </div>
  );
}

// ─────────────────────────────────────────────────────────────
// R6-D · Business card
// Pips at card bleed. Mark in the lockup, no pips on the mark.
// ─────────────────────────────────────────────────────────────
function CSCard() {
  return (
    <div style={{
      width: 350, height: 200, background:'#fff', color: CS_INK,
      position:'relative', boxShadow:'inset 0 0 0 1px #ececec',
      fontFamily:'"Helvetica Neue", Helvetica, Arial, sans-serif',
      overflow:'hidden',
    }}>
      <CornerPips size={4} inset={9} color={CS_BLUE} />

      <div style={{ padding:'22px 24px 20px', height:'100%', boxSizing:'border-box', display:'flex', flexDirection:'column', justifyContent:'space-between' }}>
        <div style={{ display:'flex', alignItems:'center', gap: 10 }}>
          <MarkBuiltNarrow size={28} color={CS_BLUE} />
          <div style={{
            fontFamily: 'Michroma, "Helvetica Neue", Arial, sans-serif',
            fontSize: 7.2, letterSpacing:'0.04em', color: CS_INK, lineHeight: 1.2,
          }}>
            NORTH ATLANTIC<br />SEMICONDUCTOR
          </div>
        </div>

        <div>
          <div style={{ fontSize: 13, fontWeight: 600, letterSpacing:'-0.005em' }}>
            William&nbsp;S.&nbsp;Fraser
          </div>
          <div style={{
            fontFamily:'"IBM Plex Mono", monospace', fontSize: 9,
            letterSpacing:'0.06em', color: CS_GREY, marginTop: 3,
          }}>
            OFFICE OF THE CORPORATE SECRETARY
          </div>
        </div>

        <div style={{
          fontFamily:'"IBM Plex Mono", monospace', fontSize: 8,
          letterSpacing:'0.08em', color: CS_INK, lineHeight: 1.55,
        }}>
          TELEX&nbsp;&nbsp;510-3211 NATLSEMI<br />
          MARINE&nbsp;CABLE&nbsp;&nbsp;NATLSEMI NEW YORK
        </div>
      </div>
    </div>
  );
}

// ─────────────────────────────────────────────────────────────
// R6-E · Datasheet header — pips frame a register block.
// The pips behave like fab crop marks around a die: they
// bracket the part-no / package data block, not the logo.
// ─────────────────────────────────────────────────────────────
function CSDatasheetHeader() {
  const Field = ({ label, value }) => (
    <div style={{ display:'flex', flexDirection:'column', gap: 4 }}>
      <div style={{
        fontFamily:'"IBM Plex Mono", monospace', fontSize: 8.5,
        letterSpacing:'0.1em', color: CS_GREY,
      }}>{label}</div>
      <div style={{
        fontFamily:'"IBM Plex Mono", monospace', fontSize: 13,
        letterSpacing:'0.04em', color: CS_INK,
      }}>{value}</div>
    </div>
  );
  return (
    <div style={{
      width: 720, height: 460, background:'#fff', color: CS_INK,
      padding: 36, boxSizing:'border-box',
      boxShadow:'inset 0 0 0 1px #ececec',
      fontFamily:'"Helvetica Neue", Helvetica, Arial, sans-serif',
      display:'flex', flexDirection:'column', gap: 22,
    }}>
      <div style={{
        display:'flex', justifyContent:'space-between',
        fontFamily:'"IBM Plex Mono", monospace', fontSize: 10,
        letterSpacing:'0.08em', color: CS_GREY,
      }}>
        <span>R6-E · DATASHEET REGISTER BLOCK</span>
        <span>PIPS AS DIE FRAME, NOT LOGO FRAME</span>
      </div>

      {/* Top lockup row */}
      <div style={{ display:'flex', justifyContent:'space-between', alignItems:'center' }}>
        <Lockup palette="B" markComp={MarkBuiltNarrow} size={11} />
        <div style={{
          fontFamily:'"IBM Plex Mono", monospace', fontSize: 9,
          letterSpacing:'0.08em', color: CS_GREY,
        }}>
          PRELIMINARY &middot; Q3 1986
        </div>
      </div>

      {/* The register block — this is where the pips live */}
      <div style={{
        position:'relative', flex:'1 1 auto',
        padding:'22px 28px',
        boxShadow:`inset 0 0 0 1px ${CS_RULE}`,
        display:'flex', flexDirection:'column', gap: 18,
      }}>
        <CornerPips size={6} inset={6} color={CS_BLUE} />

        <div style={{
          fontFamily:'"IBM Plex Mono", monospace', fontSize: 9,
          letterSpacing:'0.1em', color: CS_BLUE,
          paddingLeft: 14,
        }}>
          PART REGISTER
        </div>
        <div style={{
          fontSize: 30, letterSpacing:'-0.01em', fontWeight: 600,
          paddingLeft: 14,
        }}>
          NA-1804B
        </div>
        <div style={{
          fontSize: 12.5, lineHeight: 1.45, color:'#333',
          paddingLeft: 14, maxWidth: 540,
        }}>
          14-bit successive-approximation A/D converter &middot; 200 ksps &middot;
          on-chip 2.5&nbsp;V reference &middot; 28-pin DIP / SOIC
        </div>

        <div style={{
          display:'grid', gridTemplateColumns:'repeat(4, 1fr)', gap: 18,
          paddingLeft: 14, paddingRight: 14, marginTop: 6,
        }}>
          <Field label="RESOLUTION" value="14-BIT" />
          <Field label="THROUGHPUT" value="200 KSPS" />
          <Field label="SUPPLY"     value="±5 V" />
          <Field label="PACKAGE"    value="N28 / SO28" />
        </div>
      </div>
    </div>
  );
}

// ─────────────────────────────────────────────────────────────
// R6-F · Web content card module
// A repeating card on the website uses corner pips as its
// signature. The mark in the nav above stays clean (W2 only).
// ─────────────────────────────────────────────────────────────
function CSWebCards() {
  const Card = ({ kicker, title, body }) => (
    <div style={{
      position:'relative', background:'#fff',
      padding:'24px 22px', boxShadow:`inset 0 0 0 1px ${CS_RULE}`,
      display:'flex', flexDirection:'column', gap: 10,
      minHeight: 200, boxSizing:'border-box',
    }}>
      <CornerPips size={4} inset={6} color={CS_BLUE} />
      <div style={{
        fontFamily:'"IBM Plex Mono", monospace', fontSize: 9,
        letterSpacing:'0.1em', color: CS_BLUE,
      }}>{kicker}</div>
      <div style={{ fontSize: 18, lineHeight: 1.2, letterSpacing:'-0.01em' }}>{title}</div>
      <div style={{ fontSize: 11.5, lineHeight: 1.55, color:'#333' }}>{body}</div>
    </div>
  );

  return (
    <div style={{
      width: 960, height: 540, background: CS_BG, color: CS_INK,
      padding: 28, boxSizing:'border-box',
      boxShadow:'inset 0 0 0 1px #ececec',
      fontFamily:'"Helvetica Neue", Helvetica, Arial, sans-serif',
      display:'flex', flexDirection:'column', gap: 20,
    }}>
      {/* Nav */}
      <div style={{
        background:'#fff', padding:'14px 22px',
        boxShadow:`inset 0 0 0 1px ${CS_RULE}`,
        display:'flex', alignItems:'center', justifyContent:'space-between',
      }}>
        <Lockup palette="B" markComp={MarkBuiltNarrow} size={10} />
        <div style={{
          display:'flex', gap: 22,
          fontFamily:'"IBM Plex Mono", monospace', fontSize: 9.5,
          letterSpacing:'0.08em', color: CS_INK,
        }}>
          <span>PRODUCTS</span>
          <span>DATASHEETS</span>
          <span>COMPANY</span>
          <span style={{ color: CS_BLUE }}>CONTACT</span>
        </div>
      </div>

      {/* Hero strip */}
      <div style={{
        background:'#fff', padding:'24px 24px',
        boxShadow:`inset 0 0 0 1px ${CS_RULE}`,
      }}>
        <div style={{
          fontFamily:'"IBM Plex Mono", monospace', fontSize: 10,
          letterSpacing:'0.1em', color: CS_GREY, marginBottom: 6,
        }}>
          PRODUCT INDEX &middot; ANALOG &middot; CONVERTERS
        </div>
        <div style={{ fontSize: 22, lineHeight: 1.2, letterSpacing:'-0.01em' }}>
          Successive-approximation A/D &middot; 8 to 16 bit
        </div>
      </div>

      {/* Three cards */}
      <div style={{ display:'grid', gridTemplateColumns:'repeat(3, 1fr)', gap: 16, flex:'1 1 auto' }}>
        <Card kicker="NA-1804B" title="14-bit · 200 ksps" body="Bipolar / unipolar input. On-chip 2.5 V reference. 28-pin DIP." />
        <Card kicker="NA-1602"  title="16-bit · 100 ksps" body="Differential input. External reference. 28-pin SOIC." />
        <Card kicker="NA-0812"  title="12-bit · 1 Msps"   body="Pipeline. Single 5 V supply. 24-pin SSOP." />
      </div>
    </div>
  );
}

// ─────────────────────────────────────────────────────────────
// Hero panel for the section
// ─────────────────────────────────────────────────────────────
function CSHero() {
  return (
    <div style={{
      width: 1380, height: 220, background:'#fff', color: CS_INK,
      padding:'30px 56px', boxSizing:'border-box',
      display:'flex', flexDirection:'column', justifyContent:'space-between',
      boxShadow:'inset 0 0 0 1px #ececec',
      fontFamily:'"Helvetica Neue", Helvetica, Arial, sans-serif',
    }}>
      <div style={{
        fontFamily:'"IBM Plex Mono", monospace', fontSize: 11,
        letterSpacing:'0.08em', color: CS_GREY,
      }}>
        ROUND 08 · W2 STANDS ALONE · CORNER PIPS PROMOTED TO LAYOUT SYSTEM
      </div>
      <div style={{ fontSize: 22, lineHeight: 1.3, maxWidth: 1100, letterSpacing:'-0.01em' }}>
        The crop-mark idea was right — but it belongs on the page, not on the mark.
        W2 carries the brand. Corner pips bracket every page, card, register block
        and content module across the system. Two primitives, one rule: they never
        meet inside the logo.
      </div>
      <div style={{
        fontFamily:'"IBM Plex Mono", monospace', fontSize: 10,
        letterSpacing:'0.08em', color: CS_GREY,
      }}>
        ARTBOARDS &middot; R6-A SPECIMEN &middot; R6-B SCALE &middot; R6-C LETTERHEAD &middot;
        R6-D CARD &middot; R6-E DATASHEET BLOCK &middot; R6-F WEB
      </div>
    </div>
  );
}

Object.assign(window, {
  CSHero, CSSpecimen, CSScaleTest,
  CSLetterhead, CSCard, CSDatasheetHeader, CSWebCards,
  CornerPips, CornerTicks,
});
