// Alt I — Karesansui (枯山水 · dry rock garden)
// The page is a Zen garden seen from above. Raked sand fills the canvas;
// "stones" sit asymmetrically — each stone is one color. Text is sparse,
// pushed to the edges. Reading is contemplative, not informational.

function AltKaresansui() {
  // sand pattern — concentric ripples around each "stone"
  const sandPattern = `
    <svg xmlns='http://www.w3.org/2000/svg' width='1200' height='2200'>
      <defs>
        <pattern id='lines' patternUnits='userSpaceOnUse' width='1200' height='12'>
          <path d='M0 6 L1200 6' stroke='rgba(120,100,70,0.18)' stroke-width='1' fill='none'/>
        </pattern>
      </defs>
      <rect width='100%' height='100%' fill='url(%23lines)'/>
    </svg>`;

  // Use SVG rings for the rakes around stones. Stones are positioned in a few
  // groups, like real karesansui placement (asymmetric, with breathing room).
  const stones = [
    { id: "S1", x: 28, y: 14, size: 92,  color: "#1B1B1B", name: "墨色", romaji: "Sumi-iro", hex: "#1B1B1B" },
    { id: "S2", x: 60, y: 22, size: 60,  color: "#264653", name: "藍色", romaji: "Ai-iro",   hex: "#264653" },
    { id: "S3", x: 78, y: 16, size: 36,  color: "#5F9EA0", name: "浅葱", romaji: "Asagi",    hex: "#5F9EA0" },

    { id: "S4", x: 18, y: 42, size: 56,  color: "#B33A3A", name: "紅",   romaji: "Beni",     hex: "#B33A3A" },
    { id: "S5", x: 35, y: 50, size: 40,  color: "#D8A431", name: "山吹", romaji: "Yamabuki", hex: "#D8A431" },

    { id: "S6", x: 70, y: 48, size: 78,  color: "#7A8B55", name: "抹茶", romaji: "Matcha",   hex: "#7A8B55" },

    { id: "S7", x: 22, y: 74, size: 44,  color: "#F1C6C1", name: "桜",   romaji: "Sakura",   hex: "#F1C6C1" },
    { id: "S8", x: 55, y: 80, size: 50,  color: "#6B4C7A", name: "紫",   romaji: "Murasaki", hex: "#6B4C7A" },
    { id: "S9", x: 82, y: 78, size: 30,  color: "#E8DDCB", name: "和紙", romaji: "Washi",    hex: "#F4EFE6" },
  ];

  return (
    <div className="jca" style={{ background: "#E8DDCB", color: "var(--sumi)", minHeight: "100%", position: "relative", overflow: "hidden" }}>

      {/* SAND background — repeating horizontal raked lines */}
      <div style={{ position: "absolute", inset: 0, backgroundImage: "linear-gradient(to bottom, rgba(120,100,70,0.18) 1px, transparent 1px)", backgroundSize: "100% 11px", pointerEvents: "none", opacity: 0.7 }}></div>
      {/* paper noise */}
      <div className="washi-tex" style={{ position: "absolute", inset: 0, pointerEvents: "none" }}></div>

      {/* TOP CHROME — minimal */}
      <div className="row" style={{ padding: "28px 56px", justifyContent: "space-between", alignItems: "center", position: "relative", zIndex: 2 }}>
        <div className="row gap-3" style={{ alignItems: "center" }}>
          <Hanko char="石" size={34} rotate={-3} />
          <span className="serif" style={{ fontSize: 15 }}>Japanese Color Atlas <span style={{ color: "var(--nezumi)", marginLeft: 4 }}>· 石庭</span></span>
        </div>
        <div className="row gap-6 mono" style={{ fontSize: 10, letterSpacing: "0.22em", color: "rgba(27,27,27,0.55)" }}>
          <a>ATLAS</a><a>PALETTES</a><a>GUIDES</a><a>· SEARCH</a>
        </div>
      </div>

      {/* TATEGAKI title — right margin */}
      <div className="tate serif" style={{ position: "absolute", right: 28, top: 110, fontSize: 18, letterSpacing: "0.5em", color: "rgba(27,27,27,0.55)", zIndex: 2 }}>
        日本色譜 · 石庭抄
      </div>
      {/* tategaki — left margin, sub-line */}
      <div className="tate" style={{ position: "absolute", left: 32, top: 110, fontSize: 10, letterSpacing: "0.4em", color: "rgba(27,27,27,0.55)", fontFamily: "var(--mono)" }}>
        WALK SLOWLY — NINE STONES
      </div>

      {/* CENTER — the garden itself */}
      <main style={{ padding: "60px 100px 80px", position: "relative", height: 2000, zIndex: 1 }}>
        <svg viewBox="0 0 1000 1700" style={{ position: "absolute", inset: 0, width: "100%", height: "100%", pointerEvents: "none" }} preserveAspectRatio="none">
          {/* raked rings around each stone */}
          {stones.map((s, i) => {
            const cx = (s.x / 100) * 1000;
            const cy = (s.y / 100) * 1700;
            const rSteps = 6;
            return (
              <g key={s.id} fill="none" stroke="rgba(120,100,70,0.35)" strokeWidth="1">
                {Array.from({ length: rSteps }).map((_, k) => {
                  const r = s.size * 0.6 + 16 + k * 14;
                  return <ellipse key={k} cx={cx} cy={cy} rx={r * 1.15} ry={r * 0.85} />;
                })}
              </g>
            );
          })}
        </svg>

        {/* Each stone, absolutely placed */}
        {stones.map((s, i) => {
          const left = `${s.x}%`;
          const top = `${s.y}%`;
          const isLight = ["#F1C6C1", "#E8DDCB", "#F4EFE6", "#D8A431", "#5F9EA0"].includes(s.color);
          return (
            <div key={s.id} style={{ position: "absolute", left, top, transform: "translate(-50%, -50%)", display: "flex", flexDirection: "column", alignItems: "center", gap: 14 }}>
              {/* stone */}
              <div style={{
                width: s.size, height: s.size * 0.78,
                background: s.color,
                borderRadius: "55% 45% 50% 50% / 60% 60% 40% 40%",
                boxShadow: "0 6px 14px rgba(0,0,0,0.18), inset 0 -8px 12px rgba(0,0,0,0.25), inset 0 4px 6px rgba(255,255,255,0.08)",
                position: "relative",
              }}>
                <span style={{ position: "absolute", inset: 0, display: "flex", alignItems: "center", justifyContent: "center", color: isLight ? "rgba(27,27,27,0.7)" : "rgba(244,239,230,0.85)" }} className="serif" >
                  <span style={{ fontSize: s.size * 0.42, letterSpacing: "0.04em", lineHeight: 1 }}>{s.name}</span>
                </span>
              </div>
              {/* label below */}
              <div className="col" style={{ alignItems: "center", lineHeight: 1.3 }}>
                <span style={{ fontSize: 11, color: "rgba(27,27,27,0.7)", fontStyle: "italic" }} className="serif">{s.romaji}</span>
                <span className="mono" style={{ fontSize: 9, letterSpacing: "0.15em", color: "rgba(27,27,27,0.5)", marginTop: 2 }}>{s.hex}</span>
              </div>
            </div>
          );
        })}

        {/* A wandering footpath line, suggesting walking order */}
        <svg viewBox="0 0 1000 1700" style={{ position: "absolute", inset: 0, width: "100%", height: "100%", pointerEvents: "none", opacity: 0.3 }} preserveAspectRatio="none">
          <path d="M 280 240 Q 500 320, 600 380 Q 700 460, 350 480 Q 180 720, 220 1260 Q 500 1380, 800 1300" stroke="rgba(27,27,27,0.7)" strokeWidth="1.2" strokeDasharray="2 6" fill="none" />
        </svg>
      </main>

      {/* BOTTOM — pavilion */}
      <section style={{ padding: "32px 56px 40px", borderTop: "1px solid rgba(120,100,70,0.4)", background: "rgba(232,221,203,0.85)", position: "relative", zIndex: 3, display: "grid", gridTemplateColumns: "1.4fr 1fr 1fr", gap: 36, alignItems: "flex-start" }}>
        <div>
          <Eyebrow>From the verandah · 縁側より</Eyebrow>
          <p className="serif" style={{ fontSize: 22, lineHeight: 1.5, margin: "12px 0 16px", fontStyle: "italic", maxWidth: 540, fontWeight: 400 }}>
            "There is no order to a karesansui garden — you choose where to look. We have placed nine stones in the sand. Each one is a color."
          </p>
          <p style={{ fontSize: 13, color: "rgba(27,27,27,0.7)", lineHeight: 1.65, margin: 0, maxWidth: 520 }}>
            The rest of the atlas — 81 source-aware records, the seasonal koyomi, the palette builder — is through the gate to your right. This is the entrance garden. Walk slowly.
          </p>
        </div>

        <div className="col gap-3">
          <Eyebrow num="入口">Enter</Eyebrow>
          <a className="row" style={{ marginTop: 4, padding: "12px 16px", border: "1px solid rgba(60,40,20,0.4)", background: "var(--washi)", justifyContent: "space-between", alignItems: "center" }}>
            <span className="serif" style={{ fontSize: 16 }}>All 81 source-aware colors</span>
            <span className="serif" style={{ fontSize: 18, color: "var(--beni)" }}>門 →</span>
          </a>
          <a className="row" style={{ padding: "12px 16px", border: "1px solid rgba(60,40,20,0.4)", background: "var(--washi)", justifyContent: "space-between", alignItems: "center" }}>
            <span className="serif" style={{ fontSize: 16 }}>The koyomi · 72 micro-seasons</span>
            <span className="serif" style={{ fontSize: 18, color: "var(--beni)" }}>暦 →</span>
          </a>
          <a className="row" style={{ padding: "12px 16px", border: "1px solid rgba(60,40,20,0.4)", background: "var(--washi)", justifyContent: "space-between", alignItems: "center" }}>
            <span className="serif" style={{ fontSize: 16 }}>Palette builder · tools</span>
            <span className="serif" style={{ fontSize: 18, color: "var(--beni)" }}>具 →</span>
          </a>
        </div>

        <div className="col gap-3">
          <Eyebrow num="今">Today's stone</Eyebrow>
          <div style={{ marginTop: 4, background: "var(--washi)", border: "1px solid rgba(60,40,20,0.4)", padding: "14px 18px 16px" }}>
            <div className="row gap-3" style={{ alignItems: "center" }}>
              <div style={{ width: 42, height: 32, background: "#F1C6C1", borderRadius: "55% 45% 50% 50% / 60% 60% 40% 40%", boxShadow: "inset 0 -3px 6px rgba(0,0,0,0.18)" }}></div>
              <div className="col" style={{ lineHeight: 1.3 }}>
                <span className="serif" style={{ fontSize: 18 }}>桜</span>
                <span style={{ fontSize: 11, color: "var(--nezumi)" }}>sakura · 桜始開</span>
              </div>
            </div>
            <p style={{ fontSize: 12, color: "rgba(27,27,27,0.7)", lineHeight: 1.55, margin: "10px 0 0" }}>
              March 26 — the 11th kō. Cherry blossoms first open. The garden offers Sakura today.
            </p>
          </div>
        </div>
      </section>

      {/* Tiny colophon */}
      <div className="row" style={{ padding: "16px 56px", borderTop: "1px solid rgba(120,100,70,0.4)", justifyContent: "space-between", background: "#DAC9A8", position: "relative", zIndex: 3 }}>
        <span className="mono" style={{ fontSize: 10, letterSpacing: "0.22em", color: "rgba(27,27,27,0.6)" }}>CHROMA CATHAY · KARESANSUI ENTRY · 入庭 二〇二六</span>
        <span className="serif" style={{ fontSize: 12, fontStyle: "italic", color: "rgba(27,27,27,0.6)" }}>— hosted by Chroma Cathay, vol. II —</span>
      </div>
    </div>
  );
}
window.AltKaresansui = AltKaresansui;
