// Alt H — Ukiyo-e woodblock (木版画)
// The page is a print shop. One ukiyo-e composition is built up plate by
// plate: keyblock (line), then color blocks 1-8. Kentō registration marks
// frame each plate. Tools, paper, baren strewn around.

function AltWoodblock() {
  // Build-up sequence: each plate adds one color over the previous.
  const plates = [
    { num: "墨版 · KEY",  romaji: "Sumi · line block",   add: "#1B1B1B" },
    { num: "01",         romaji: "Indigo · 藍",          add: "#264653" },
    { num: "02",         romaji: "Asagi · 浅葱",         add: "#5F9EA0" },
    { num: "03",         romaji: "Sakura · 桜",          add: "#F1C6C1" },
    { num: "04",         romaji: "Beni · 紅",            add: "#B33A3A" },
    { num: "05",         romaji: "Yamabuki · 山吹",      add: "#D8A431" },
    { num: "06",         romaji: "Matcha · 抹茶",        add: "#7A8B55" },
    { num: "07",         romaji: "Murasaki · 紫",        add: "#6B4C7A" },
  ];

  // A plate: paper rectangle with kentō (L-shape + line) and a single
  // colored region that hints at the print composition. We make the
  // composition geometric, not figurative — bands that build up.
  function Plate({ idx, label, fill, cumulative }) {
    return (
      <div style={{ position: "relative", background: "#F8F2E4", border: "1px solid rgba(60,40,20,0.35)", padding: 16, paddingTop: 28, boxShadow: "1px 2px 0 rgba(0,0,0,0.08)" }}>
        {/* kentō marks — L bottom-right + line bottom-left */}
        <svg style={{ position: "absolute", right: 4, bottom: 4 }} width="22" height="22" viewBox="0 0 22 22">
          <path d="M22 2 L22 22 L2 22" stroke="#1B1B1B" strokeWidth="1.4" fill="none" />
        </svg>
        <svg style={{ position: "absolute", left: 4, bottom: 4 }} width="34" height="6" viewBox="0 0 34 6">
          <path d="M0 5 L34 5" stroke="#1B1B1B" strokeWidth="1.4" />
        </svg>

        {/* plate label */}
        <div className="row mono" style={{ position: "absolute", top: 6, left: 8, right: 8, fontSize: 8.5, letterSpacing: "0.15em", color: "rgba(27,27,27,0.65)", justifyContent: "space-between" }}>
          <span>{idx}</span>
          <span>{label}</span>
        </div>

        {/* the "image" — abstract composition that builds up */}
        <div style={{ position: "relative", height: 220, background: "#F8F2E4" }}>
          {cumulative}
        </div>
      </div>
    );
  }

  // Build up cumulative composition for each plate
  function Composition({ upto }) {
    // Layers (bottom to top, drawn in order):
    // 0: key block lines
    // 1: indigo sky band (top half)
    // 2: asagi mid band
    // 3: sakura flower clusters
    // 4: beni accents
    // 5: yamabuki moon disk
    // 6: matcha ground band
    // 7: murasaki silhouette
    const layers = [
      // 0: key block — sumi outlines
      <g key="k">
        {/* ground line */}
        <line x1="0" y1="160" x2="100%" y2="160" stroke="#1B1B1B" strokeWidth="1" />
        {/* horizon */}
        <line x1="0" y1="78" x2="100%" y2="78" stroke="#1B1B1B" strokeWidth="0.8" />
        {/* tree trunk */}
        <path d="M50 160 L48 100 L52 60" stroke="#1B1B1B" strokeWidth="1.6" fill="none" strokeLinecap="round" />
        {/* mountain outline */}
        <path d="M120 78 L155 35 L190 78" stroke="#1B1B1B" strokeWidth="1.2" fill="none" />
        {/* small bird */}
        <path d="M195 40 q3 -3 6 0 q-3 -1 -6 0" stroke="#1B1B1B" strokeWidth="0.8" fill="none" />
        <path d="M180 48 q3 -3 6 0 q-3 -1 -6 0" stroke="#1B1B1B" strokeWidth="0.8" fill="none" />
        {/* signature box */}
        <rect x="6" y="184" width="14" height="20" fill="none" stroke="#1B1B1B" strokeWidth="0.6" />
      </g>,
      // 1: indigo sky top
      <rect key="1" x="0" y="0" width="100%" height="78" fill="#264653" />,
      // 2: asagi mid band
      <rect key="2" x="0" y="78" width="100%" height="40" fill="#5F9EA0" opacity="0.55" />,
      // 3: sakura blossom clusters
      <g key="3">
        {[[40, 90, 10], [55, 70, 8], [70, 95, 9], [38, 110, 7]].map((b, i) => (
          <circle key={i} cx={b[0]} cy={b[1]} r={b[2]} fill="#F1C6C1" />
        ))}
      </g>,
      // 4: beni accents — bird, signature
      <g key="4">
        <rect x="6" y="184" width="14" height="20" fill="#B33A3A" />
        <circle cx="198" cy="40" r="2" fill="#B33A3A" />
      </g>,
      // 5: yamabuki — moon
      <circle key="5" cx="220" cy="40" r="22" fill="#D8A431" />,
      // 6: matcha ground band
      <rect key="6" x="0" y="160" width="100%" height="60" fill="#7A8B55" opacity="0.7" />,
      // 7: murasaki silhouette
      <g key="7">
        <path d="M120 160 L120 78 L155 35 L190 78 L190 160 Z" fill="#6B4C7A" opacity="0.5" />
      </g>,
    ];
    return (
      <svg viewBox="0 0 250 220" style={{ width: "100%", height: "100%", position: "absolute", inset: 0 }} preserveAspectRatio="xMidYMid slice">
        {/* paper noise */}
        <rect x="0" y="0" width="250" height="220" fill="#F8F2E4" />
        {/* always draw the new layer for THIS plate only (so you see the contribution),
            plus all preceding layers so it builds visually */}
        {layers.slice(0, upto + 1)}
      </svg>
    );
  }

  return (
    <div className="jca washi-tex" style={{ background: "var(--warm-paper)", color: "var(--sumi)", minHeight: "100%", position: "relative" }}>

      {/* Top folio */}
      <div className="row mono" style={{ padding: "16px 48px", fontSize: 10, letterSpacing: "0.22em", color: "var(--nezumi)", justifyContent: "space-between", borderBottom: "1px solid rgba(60,40,20,0.3)" }}>
        <span>CHROMA CATHAY · PRINT WORKSHOP</span>
        <span>METHODOLOGY · 02 / WOODBLOCK</span>
        <span>INDEX · PALETTES · GUIDES · LOG</span>
      </div>

      {/* Masthead */}
      <header style={{ padding: "44px 48px 32px", display: "grid", gridTemplateColumns: "1.2fr 1fr", gap: 48, alignItems: "flex-end" }}>
        <div className="col">
          <Eyebrow num="METHODOLOGY 02">A print, one plate at a time</Eyebrow>
          <h1 className="serif" style={{ fontSize: 76, lineHeight: 0.95, margin: "14px 0 12px", letterSpacing: "-0.02em", fontWeight: 400 }}>
            木版画 <span style={{ fontStyle: "italic", color: "var(--nezumi)", fontSize: 56 }}>Mokuhanga</span>
          </h1>
          <p style={{ fontSize: 15, lineHeight: 1.65, margin: 0, maxWidth: 620, opacity: 0.85 }}>
            An Edo-era ukiyo-e print is not one image but eight — a key block of sumi lines, and then a separate carved block for every color, registered to a hairsbreadth. We use the same logic: every palette in this atlas is a stack of plates.
          </p>
        </div>
        <div className="col" style={{ alignItems: "flex-end", gap: 12 }}>
          <div className="row gap-4">
            <Hanko char="版" size={48} rotate={-3} />
            <Hanko char="元" size={36} rotate={2} />
          </div>
          <span className="mono" style={{ fontSize: 10, letterSpacing: "0.18em", color: "var(--nezumi)" }}>KEY + 7 COLOR PLATES</span>
          <span className="serif" style={{ fontSize: 12, fontStyle: "italic", color: "var(--nezumi)" }}>"Spring evening at Yoshino" — a printer's diagram</span>
        </div>
      </header>

      {/* The plates row */}
      <section style={{ padding: "16px 48px 36px", borderTop: "1px solid rgba(60,40,20,0.25)", borderBottom: "1px solid rgba(60,40,20,0.25)" }}>
        <div className="row" style={{ justifyContent: "space-between", alignItems: "flex-end", marginBottom: 20 }}>
          <Eyebrow>The build-up · 摺り重ね</Eyebrow>
          <span className="mono" style={{ fontSize: 10, letterSpacing: "0.15em", color: "var(--nezumi)" }}>← READ LEFT TO RIGHT · EIGHT PASSES</span>
        </div>

        <div className="row" style={{ gap: 14, alignItems: "flex-start" }}>
          {plates.map((p, i) => (
            <div key={i} className="col" style={{ flex: 1, gap: 10 }}>
              {/* swatch tag */}
              <div className="row" style={{ alignItems: "center", gap: 8, padding: "4px 0" }}>
                <span style={{ width: 18, height: 18, background: p.add, border: "1px solid rgba(0,0,0,0.15)" }}></span>
                <div className="col" style={{ lineHeight: 1.2 }}>
                  <span className="mono" style={{ fontSize: 9, letterSpacing: "0.12em", color: "var(--nezumi)" }}>{p.num}</span>
                  <span style={{ fontSize: 11 }} className="serif">{p.romaji}</span>
                </div>
              </div>
              <Plate idx={p.num} label={p.add} fill={p.add} cumulative={<Composition upto={i} />} />
              <span className="mono" style={{ fontSize: 9, letterSpacing: "0.12em", color: "var(--nezumi)", textAlign: "center" }}>{p.add}</span>
            </div>
          ))}
        </div>
      </section>

      {/* Two columns: tools + palette of THIS print */}
      <section style={{ padding: "32px 48px 32px", display: "grid", gridTemplateColumns: "1fr 1.1fr 1fr", gap: 28 }}>
        {/* Tools on the bench */}
        <div>
          <Eyebrow num="01">In the workshop · 道具</Eyebrow>
          <div className="col gap-3" style={{ marginTop: 14 }}>
            {[
              { glyph: "彫", t: "Carving knife", note: "the to" },
              { glyph: "刷", t: "Baren disk",    note: "for burnishing" },
              { glyph: "墨", t: "Sumi ink",      note: "for the key block" },
              { glyph: "和", t: "Hōsho washi",   note: "kozo paper, sized" },
              { glyph: "見", t: "Kentō marks",   note: "L + line registration" },
            ].map((t, i) => (
              <div key={i} className="row" style={{ padding: "12px 14px", border: "1px solid rgba(60,40,20,0.25)", background: "var(--washi)", alignItems: "center", gap: 14 }}>
                <span className="serif" style={{ fontSize: 32, lineHeight: 1, color: "var(--sumi)" }}>{t.glyph}</span>
                <div className="col" style={{ flex: 1, lineHeight: 1.3 }}>
                  <span className="serif" style={{ fontSize: 15 }}>{t.t}</span>
                  <span style={{ fontSize: 11, color: "var(--nezumi)", fontStyle: "italic" }}>{t.note}</span>
                </div>
              </div>
            ))}
          </div>
        </div>

        {/* The composite — final print */}
        <div>
          <Eyebrow num="02">The finished impression · 摺上り</Eyebrow>
          <div style={{ marginTop: 14, background: "#F8F2E4", padding: 18, border: "1px solid rgba(60,40,20,0.35)", position: "relative", boxShadow: "1px 3px 6px rgba(0,0,0,0.1)" }}>
            <div style={{ height: 320, position: "relative", background: "#F8F2E4", overflow: "hidden" }}>
              <Composition upto={7} />
            </div>
            <div className="row mono" style={{ marginTop: 12, justifyContent: "space-between", fontSize: 9.5, letterSpacing: "0.15em", color: "var(--nezumi)" }}>
              <span>EDITION 1 / 200</span>
              <span>EIGHT-COLOR · NISHIKI-E</span>
              <span>FOLIO Nº 24</span>
            </div>
          </div>
        </div>

        {/* Palette of this print, as exportable tokens */}
        <div>
          <Eyebrow num="03">Palette · this print's eight</Eyebrow>
          <div className="col" style={{ marginTop: 14, border: "1px solid rgba(60,40,20,0.25)", background: "var(--washi)" }}>
            {plates.map((p, i) => (
              <div key={i} className="row" style={{ padding: "10px 14px", alignItems: "center", gap: 12, borderTop: i ? "1px dashed rgba(60,40,20,0.18)" : "none" }}>
                <span className="mono" style={{ fontSize: 9, color: "var(--nezumi)", width: 28, letterSpacing: "0.1em" }}>{i === 0 ? "KEY" : String(i).padStart(2, "0")}</span>
                <span style={{ width: 28, height: 28, background: p.add, border: "1px solid rgba(0,0,0,0.1)" }}></span>
                <div className="col" style={{ flex: 1, lineHeight: 1.3 }}>
                  <span className="serif" style={{ fontSize: 14 }}>{p.romaji.split(" · ")[1] || p.romaji}</span>
                  <span className="mono" style={{ fontSize: 9.5, color: "var(--nezumi)" }}>{p.add}</span>
                </div>
                <span className="mono" style={{ fontSize: 9, color: "var(--nezumi)" }}>+</span>
              </div>
            ))}
            <div className="row" style={{ padding: "12px 14px", borderTop: "1px solid rgba(60,40,20,0.25)", justifyContent: "space-between" }}>
              <span className="mono" style={{ fontSize: 9.5, color: "var(--nezumi)", letterSpacing: "0.12em" }}>8 PLATES · 1 IMPRESSION</span>
              <a className="mono" style={{ fontSize: 10, letterSpacing: "0.15em" }}>EXPORT PALETTE →</a>
            </div>
          </div>

          {/* Other prints */}
          <div className="col gap-2" style={{ marginTop: 18 }}>
            <Eyebrow>Other prints in this folio</Eyebrow>
            {[
              ["Autumn moon at Tama", "9 plates"],
              ["Winter pine, dawn",   "5 plates"],
              ["Wisteria at Kameido", "11 plates"],
            ].map((r, i) => (
              <div key={i} className="row" style={{ marginTop: 4, padding: "8px 0", borderTop: "1px dashed rgba(60,40,20,0.18)", justifyContent: "space-between", fontSize: 12 }}>
                <span className="serif">{r[0]}</span>
                <span className="mono" style={{ color: "var(--nezumi)", letterSpacing: "0.1em" }}>{r[1]}</span>
              </div>
            ))}
          </div>
        </div>
      </section>

      {/* Bottom: printer's mark */}
      <footer style={{ padding: "28px 48px 40px", borderTop: "1px solid rgba(60,40,20,0.25)", display: "flex", justifyContent: "space-between", alignItems: "center" }}>
        <span className="serif" style={{ fontSize: 13, fontStyle: "italic", color: "var(--nezumi)" }}>— from the workshop of Chroma Cathay · 朱華工房 —</span>
        <div className="row gap-3">
          <span className="mono" style={{ fontSize: 10, letterSpacing: "0.2em", color: "var(--nezumi)" }}>WOODBLOCK · MOKUHANGA · 二〇二六</span>
          <Hanko char="刷" size={32} rotate={-3} />
        </div>
      </footer>
    </div>
  );
}
window.AltWoodblock = AltWoodblock;
