/* Logo exploration — 6 master-mark directions for Obsidia
   Each is delivered as a self-contained <Mark/> + <Lockup/> pair.
   The sub-vertical pattern: master mark + small sub-glyph anchored
   bottom-right at ~35% size, inscribed in a soft circle so it reads
   as a "stamp" or "endorsement". */

/* =========================================================
   MARK 01 — SHARD: angular obsidian shard, hard cuts, gold
   highlight on one facet (premium, sharp)
   ========================================================= */
function MarkShard({ size = 64, fg = OBSIDIA.gold, bg = OBSIDIA.carbon, mono = false }) {
  return (
    <svg width={size} height={size} viewBox="0 0 64 64" fill="none">
      <defs>
        <linearGradient id="sh1" x1="0" y1="0" x2="1" y2="1">
          <stop offset="0" stopColor={fg} stopOpacity="0.95" />
          <stop offset="1" stopColor={fg} stopOpacity="0.55" />
        </linearGradient>
      </defs>
      <rect width="64" height="64" rx="14" fill={bg} />
      {/* outer shard */}
      <path d="M32 8 L52 26 L42 56 L22 56 L12 26 Z" fill="none" stroke={fg} strokeWidth="1.4" strokeLinejoin="round" />
      {/* facets */}
      <path d="M32 8 L32 36 L12 26 Z" fill={mono ? "none" : "url(#sh1)"} stroke={fg} strokeWidth="1" />
      <path d="M32 8 L52 26 L32 36 Z" fill={mono ? "none" : fg} fillOpacity={mono ? 0 : 0.18} stroke={fg} strokeWidth="1" />
      <path d="M32 36 L52 26 L42 56 Z" fill="none" stroke={fg} strokeWidth="1" />
      <path d="M32 36 L42 56 L22 56 Z" fill="none" stroke={fg} strokeWidth="1" />
      <path d="M12 26 L32 36 L22 56 Z" fill="none" stroke={fg} strokeWidth="1" />
    </svg>
  );
}

/* =========================================================
   MARK 02 — MONOLITH "O": geometric O carved with a slash
   facet, evokes obsidian fracture inside a letterform
   ========================================================= */
function MarkMonolith({ size = 64, fg = OBSIDIA.gold, bg = OBSIDIA.carbon }) {
  return (
    <svg width={size} height={size} viewBox="0 0 64 64" fill="none">
      <rect width="64" height="64" rx="14" fill={bg} />
      <circle cx="32" cy="32" r="20" stroke={fg} strokeWidth="2" />
      <circle cx="32" cy="32" r="11" stroke={fg} strokeWidth="1.4" opacity="0.7" />
      {/* fracture diagonal slicing the O */}
      <path d="M16 22 L48 42" stroke={fg} strokeWidth="1.2" />
      <path d="M16 22 L48 42 L48 32 L20 16 Z" fill={fg} fillOpacity="0.18" />
      {/* highlight dot */}
      <circle cx="42" cy="22" r="1.6" fill={fg} />
    </svg>
  );
}

/* =========================================================
   MARK 03 — KITE / FACETED DIAMOND: refined version of the
   diamond, sharper geometry + asymmetric light source
   ========================================================= */
function MarkKite({ size = 64, fg = OBSIDIA.gold, bg = OBSIDIA.carbon }) {
  return (
    <svg width={size} height={size} viewBox="0 0 64 64" fill="none">
      <rect width="64" height="64" rx="14" fill={bg} />
      <g transform="translate(32 32)">
        {/* outer kite */}
        <path d="M0 -22 L18 -2 L0 26 L-18 -2 Z" stroke={fg} strokeWidth="1.5" />
        {/* facet split */}
        <path d="M-18 -2 L18 -2" stroke={fg} strokeWidth="1.2" />
        <path d="M0 -22 L-9 -2 L0 -2 Z" fill={fg} fillOpacity="0.7" />
        <path d="M0 -22 L9 -2 L0 -2 Z" fill={fg} fillOpacity="0.4" />
        <path d="M-9 -2 L0 -2 L0 -22 Z" stroke={fg} strokeWidth="0.8" />
        {/* lower facets, hollow */}
        <path d="M-18 -2 L0 26 M18 -2 L0 26" stroke={fg} strokeWidth="0.8" opacity="0.7" />
        <path d="M-9 -2 L0 26 M9 -2 L0 26" stroke={fg} strokeWidth="0.6" opacity="0.5" />
      </g>
    </svg>
  );
}

/* =========================================================
   MARK 04 — RIDGE: stacked horizontal cuts that read as
   stratified obsidian / typographic horizon
   ========================================================= */
function MarkRidge({ size = 64, fg = OBSIDIA.gold, bg = OBSIDIA.carbon }) {
  return (
    <svg width={size} height={size} viewBox="0 0 64 64" fill="none">
      <rect width="64" height="64" rx="14" fill={bg} />
      {/* angled bars */}
      <path d="M14 22 L50 18 L46 24 L18 27 Z" fill={fg} fillOpacity="0.95" />
      <path d="M14 30 L50 26 L46 32 L18 35 Z" fill={fg} fillOpacity="0.55" />
      <path d="M14 38 L50 34 L46 40 L18 43 Z" fill={fg} fillOpacity="0.32" />
      <path d="M14 46 L50 42 L46 48 L18 51 Z" fill={fg} fillOpacity="0.18" />
    </svg>
  );
}

/* =========================================================
   MARK 05 — PRISM: triangular prism with golden core +
   chromatic split (premium tech vibe)
   ========================================================= */
function MarkPrism({ size = 64, fg = OBSIDIA.gold, bg = OBSIDIA.carbon }) {
  return (
    <svg width={size} height={size} viewBox="0 0 64 64" fill="none">
      <rect width="64" height="64" rx="14" fill={bg} />
      {/* triangle */}
      <path d="M32 12 L52 48 L12 48 Z" stroke={fg} strokeWidth="1.5" fill="none" />
      <path d="M32 12 L32 48" stroke={fg} strokeWidth="1" />
      {/* light ray entering */}
      <path d="M6 30 L32 30" stroke={fg} strokeWidth="1" opacity="0.5" />
      {/* dispersion */}
      <path d="M32 30 L58 22" stroke={fg} strokeWidth="1.2" opacity="0.95" />
      <path d="M32 30 L58 30" stroke={fg} strokeWidth="1.2" opacity="0.65" />
      <path d="M32 30 L58 38" stroke={fg} strokeWidth="1.2" opacity="0.35" />
      {/* core */}
      <path d="M32 24 L40 38 L24 38 Z" fill={fg} fillOpacity="0.25" />
    </svg>
  );
}

/* =========================================================
   MARK 06 — MERIDIAN: a custom Ø-style monogram — circle
   bisected by a sharp diagonal, highly recognizable at
   tiny sizes (favicon / app icon strength)
   ========================================================= */
function MarkMeridian({ size = 64, fg = OBSIDIA.gold, bg = OBSIDIA.carbon }) {
  return (
    <svg width={size} height={size} viewBox="0 0 64 64" fill="none">
      <rect width="64" height="64" rx="14" fill={bg} />
      <circle cx="32" cy="32" r="20" stroke={fg} strokeWidth="2.4" />
      {/* diagonal slash, thicker */}
      <path d="M14 48 L52 18" stroke={fg} strokeWidth="2.4" strokeLinecap="square" />
      {/* upper-right gold fill quadrant */}
      <path d="M32 12 a20 20 0 0 1 20 20 L32 32 Z" fill={fg} fillOpacity="0.22" />
    </svg>
  );
}

/* small sub-glyphs — refined */
function SubWig({ size = 22, color = "currentColor" }) {
  return (
    <svg width={size} height={size} viewBox="0 0 24 24" fill="none" stroke={color} strokeWidth="1.6" strokeLinecap="round">
      <path d="M5 9c0-3 3-5 7-5s7 2 7 5v2" />
      <path d="M5 11c-1 2-1 5 1 7M19 11c1 2 1 5-1 7" />
      <path d="M8 11v8M12 11v9M16 11v8" />
    </svg>
  );
}
function SubBake({ size = 22, color = "currentColor" }) {
  return (
    <svg width={size} height={size} viewBox="0 0 24 24" fill="none" stroke={color} strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round">
      <path d="M4 20h16" />
      <path d="M5 20v-7c0-3 3-5 7-5s7 2 7 5v7" />
      <path d="M9 13c1 1 2 1 3 0s2-1 3 0" />
      <path d="M12 8V4M10.5 4l1.5-1.5L13.5 4" />
    </svg>
  );
}
function SubTrade({ size = 22, color = "currentColor" }) {
  return (
    <svg width={size} height={size} viewBox="0 0 24 24" fill="none" stroke={color} strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round">
      <path d="M4 8h13M14 5l3 3-3 3" />
      <path d="M20 16H7M10 19l-3-3 3-3" />
    </svg>
  );
}
function SubLens({ size = 22, color = "currentColor" }) {
  return (
    <svg width={size} height={size} viewBox="0 0 24 24" fill="none" stroke={color} strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round">
      <circle cx="12" cy="12" r="8" />
      <circle cx="12" cy="12" r="3" />
      <path d="M12 4l3 5M20 12l-5 1M16 19l-3-5M8 19l3-5M4 12l5-1M8 5l3 5" />
    </svg>
  );
}
function SubInk({ size = 22, color = "currentColor" }) {
  return (
    <svg width={size} height={size} viewBox="0 0 24 24" fill="none" stroke={color} strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round">
      <path d="M5 19l3-1L19 7l-2-2L6 16l-1 3z" />
      <path d="M14 8l2 2" />
      <path d="M5 19h7" />
    </svg>
  );
}

const SUB_GLYPHS = { wig: SubWig, bake: SubBake, trade: SubTrade, lens: SubLens, ink: SubInk };

/* Master + endorsed sub-mark badge (sub-glyph in a soft circle, blurred) */
function VerticalLockup({ MarkComp, vertical, size = 96, fg = OBSIDIA.gold, bg = OBSIDIA.carbon, accent }) {
  const SG = SUB_GLYPHS[vertical];
  const v = VERTICALS[vertical];
  const a = accent || v.accent;
  const sub = size * 0.42;
  return (
    <div style={{ position: "relative", width: size, height: size }}>
      <MarkComp size={size} fg={fg} bg={bg} />
      {/* soft halo */}
      <div style={{
        position: "absolute",
        right: -sub * 0.25, bottom: -sub * 0.25,
        width: sub * 1.4, height: sub * 1.4,
        borderRadius: "50%",
        background: a,
        filter: "blur(10px)",
        opacity: 0.55,
      }} />
      {/* sub stamp */}
      <div style={{
        position: "absolute",
        right: -sub * 0.12, bottom: -sub * 0.12,
        width: sub, height: sub,
        borderRadius: "50%",
        background: a,
        display: "grid", placeItems: "center",
        boxShadow: `0 4px 12px ${a}66, 0 0 0 2px ${bg}`,
      }}>
        <SG size={sub * 0.55} color="#fff" />
      </div>
    </div>
  );
}

/* Wordmark version — "obsidia" + dot + "wig" with the master mark
   leading and a tiny sub-glyph diffused at the bottom-right of the wordmark */
function WordmarkLockup({ MarkComp, vertical, scale = 1, fg = OBSIDIA.surface, accent, bg = OBSIDIA.carbon }) {
  const v = VERTICALS[vertical];
  const a = accent || v.accent;
  const SG = SUB_GLYPHS[vertical];
  const s = 38 * scale;
  return (
    <div style={{ display: "inline-flex", alignItems: "center", gap: s * 0.4, position: "relative" }}>
      <div style={{ position: "relative" }}>
        <MarkComp size={s * 1.4} fg={a} bg={bg} />
      </div>
      <div style={{ position: "relative", display: "inline-flex", alignItems: "center", gap: s * 0.35 }}>
        <span style={{ fontFamily: "'Fraunces', serif", fontSize: s, fontWeight: 400, letterSpacing: "-0.025em", color: fg, lineHeight: 1 }}>obsidia</span>
        <span style={{ width: s * 0.13, height: s * 0.13, borderRadius: "50%", background: a, display: "inline-block" }} />
        <span style={{ fontFamily: "'Inter', sans-serif", fontSize: s * 0.5, fontWeight: 600, letterSpacing: "0.18em", textTransform: "uppercase", color: fg }}>{v.name}</span>
        {/* difuminated sub-glyph anchored bottom-right of wordmark */}
        <div style={{
          position: "absolute",
          right: -s * 0.6, bottom: -s * 0.45,
          width: s * 0.95, height: s * 0.95,
          opacity: 0.85, pointerEvents: "none",
        }}>
          <div style={{ position: "absolute", inset: -s * 0.1, background: a, opacity: 0.35, filter: `blur(${s * 0.3}px)`, borderRadius: "50%" }} />
          <div style={{ position: "absolute", inset: 0, color: a, display: "grid", placeItems: "center" }}>
            <SG size={s * 0.85} color={a} />
          </div>
        </div>
      </div>
    </div>
  );
}

/* ================ Showcase artboards ================ */

const LogoExploration = () => {
  const directions = [
    { id: "shard", name: "01 · Shard", desc: "Obsidiana facetada, cortes duros", Comp: MarkShard },
    { id: "monolith", name: "02 · Monolith", desc: "Anillo cortado por una fractura", Comp: MarkMonolith },
    { id: "kite", name: "03 · Kite", desc: "Diamante refinado, luz asimétrica", Comp: MarkKite },
    { id: "ridge", name: "04 · Ridge", desc: "Estratos paralelos, horizonte", Comp: MarkRidge },
    { id: "prism", name: "05 · Prism", desc: "Prisma con dispersión dorada", Comp: MarkPrism },
    { id: "meridian", name: "06 · Meridian", desc: "Monograma Ø, fuerza a tamaño mínimo", Comp: MarkMeridian },
  ];

  return (
    <div style={{ width: 1400, padding: 56, background: OBSIDIA.surface, fontFamily: "'Inter', sans-serif", color: OBSIDIA.ink }}>
      <div style={{ marginBottom: 48, display: "flex", justifyContent: "space-between", alignItems: "flex-end" }}>
        <div>
          <div style={{ fontSize: 11, letterSpacing: "0.3em", textTransform: "uppercase", color: OBSIDIA.mute }}>Exploración · Logo master</div>
          <h2 style={{ fontFamily: "'Fraunces', serif", fontSize: 56, fontWeight: 400, margin: "8px 0 0", letterSpacing: "-0.03em" }}>Seis direcciones</h2>
        </div>
        <p style={{ maxWidth: 360, color: OBSIDIA.mute, fontSize: 14, lineHeight: 1.6 }}>
          Cada dirección busca encarnar la obsidiana — piedra forjada, brillante, fracturada — con una geometría distinta. Elige una y refinamos.
        </p>
      </div>

      <div style={{ display: "grid", gridTemplateColumns: "repeat(3, 1fr)", gap: 20 }}>
        {directions.map((d, i) => (
          <div key={d.id} style={{
            background: OBSIDIA.carbon,
            borderRadius: 18,
            padding: 32,
            display: "flex", flexDirection: "column", gap: 24,
            border: "1px solid #1d1d20",
            position: "relative", overflow: "hidden",
            minHeight: 360,
          }}>
            {/* mark + lockup */}
            <div style={{ display: "flex", alignItems: "center", gap: 20, flex: 1 }}>
              <d.Comp size={84} fg={OBSIDIA.gold} bg="transparent" />
              <div style={{ display: "flex", flexDirection: "column", gap: 10 }}>
                <span style={{ fontFamily: "'Fraunces', serif", fontSize: 38, fontWeight: 400, letterSpacing: "-0.03em", color: OBSIDIA.surface, lineHeight: 1 }}>obsidia</span>
                <span style={{ fontFamily: "'JetBrains Mono', monospace", fontSize: 10, color: OBSIDIA.gold, letterSpacing: "0.2em" }}>FORJADO PARA TU NEGOCIO</span>
              </div>
            </div>

            {/* mini scale row */}
            <div style={{ display: "flex", alignItems: "center", gap: 16, paddingTop: 16, borderTop: "1px solid rgba(247,244,239,0.08)" }}>
              <d.Comp size={48} fg={OBSIDIA.gold} bg="transparent" />
              <d.Comp size={28} fg={OBSIDIA.gold} bg="transparent" />
              <d.Comp size={16} fg={OBSIDIA.gold} bg="transparent" />
              <div style={{ flex: 1 }} />
              <d.Comp size={32} fg={OBSIDIA.surface} bg="transparent" />
            </div>

            {/* footer label */}
            <div style={{ display: "flex", justifyContent: "space-between", alignItems: "center" }}>
              <div>
                <div style={{ fontSize: 11, letterSpacing: "0.2em", textTransform: "uppercase", color: OBSIDIA.gold, fontFamily: "'JetBrains Mono', monospace" }}>{d.name}</div>
                <div style={{ fontSize: 12, color: "rgba(247,244,239,0.65)", marginTop: 4 }}>{d.desc}</div>
              </div>
              <div style={{ width: 28, height: 28, borderRadius: "50%", border: `1px solid ${OBSIDIA.gold}`, color: OBSIDIA.gold, display: "grid", placeItems: "center", fontSize: 12 }}>→</div>
            </div>
          </div>
        ))}
      </div>
    </div>
  );
};

/* The endorsement pattern: master + sub at bottom-right, applied across verticals */
const EndorsedLockups = ({ MarkComp = MarkKite, name = "Kite" }) => (
  <div style={{ width: 1400, padding: 56, background: OBSIDIA.paper, fontFamily: "'Inter', sans-serif", color: OBSIDIA.ink }}>
    <div style={{ marginBottom: 40, display: "flex", justifyContent: "space-between", alignItems: "flex-end" }}>
      <div>
        <div style={{ fontSize: 11, letterSpacing: "0.3em", textTransform: "uppercase", color: OBSIDIA.mute }}>Patrón endorsado · {name}</div>
        <h2 style={{ fontFamily: "'Fraunces', serif", fontSize: 52, fontWeight: 400, margin: "8px 0 0", letterSpacing: "-0.03em" }}>obsidia<span style={{ color: OBSIDIA.gold }}>·</span> + sub-glifo</h2>
        <p style={{ marginTop: 16, fontSize: 14, color: OBSIDIA.mute, maxWidth: 520, lineHeight: 1.6 }}>
          La marca maestra siempre lidera. El sub-glifo del vertical aparece como sello difuminado en la esquina inferior-derecha del logo o del wordmark — visible pero subordinado.
        </p>
      </div>
    </div>

    {/* row 1 — badge style: master glyph with sub stamp */}
    <div style={{ marginBottom: 32 }}>
      <div style={{ fontSize: 10, letterSpacing: "0.25em", textTransform: "uppercase", color: OBSIDIA.mute, marginBottom: 16, fontFamily: "'JetBrains Mono', monospace" }}>A · Glifo + sello vertical</div>
      <div style={{ display: "grid", gridTemplateColumns: "repeat(5, 1fr)", gap: 16 }}>
        {Object.keys(VERTICALS).map(k => (
          <div key={k} style={{ background: OBSIDIA.carbon, borderRadius: 18, padding: "44px 24px", display: "flex", flexDirection: "column", alignItems: "center", gap: 24, border: "1px solid #1d1d20" }}>
            <VerticalLockup MarkComp={MarkComp} vertical={k} size={92} fg={OBSIDIA.gold} bg={OBSIDIA.carbon} />
            <div style={{ display: "flex", alignItems: "center", gap: 6 }}>
              <span style={{ fontFamily: "'Fraunces', serif", fontSize: 18, color: OBSIDIA.surface, letterSpacing: "-0.02em" }}>obsidia</span>
              <span style={{ width: 3, height: 3, borderRadius: "50%", background: VERTICALS[k].accent }} />
              <span style={{ fontSize: 10, letterSpacing: "0.18em", textTransform: "uppercase", color: OBSIDIA.surface, fontWeight: 600 }}>{VERTICALS[k].name}</span>
            </div>
          </div>
        ))}
      </div>
    </div>

    {/* row 2 — wordmark with diffused sub-glyph */}
    <div style={{ marginBottom: 32 }}>
      <div style={{ fontSize: 10, letterSpacing: "0.25em", textTransform: "uppercase", color: OBSIDIA.mute, marginBottom: 16, fontFamily: "'JetBrains Mono', monospace" }}>B · Wordmark con sub-glifo difuminado</div>
      <div style={{ display: "grid", gridTemplateColumns: "1fr 1fr", gap: 16 }}>
        {Object.keys(VERTICALS).slice(0, 2).map(k => (
          <div key={k} style={{ background: OBSIDIA.carbon, borderRadius: 18, padding: "56px 48px", display: "flex", alignItems: "center", justifyContent: "center", border: "1px solid #1d1d20", overflow: "hidden" }}>
            <WordmarkLockup MarkComp={MarkComp} vertical={k} scale={1.1} fg={OBSIDIA.surface} bg="transparent" />
          </div>
        ))}
      </div>
      <div style={{ display: "grid", gridTemplateColumns: "repeat(3, 1fr)", gap: 16, marginTop: 16 }}>
        {Object.keys(VERTICALS).slice(2).map(k => (
          <div key={k} style={{ background: "#fff", borderRadius: 18, padding: "44px 32px", display: "flex", alignItems: "center", justifyContent: "center", border: `1px solid ${OBSIDIA.line}`, overflow: "hidden" }}>
            <WordmarkLockup MarkComp={MarkComp} vertical={k} scale={0.85} fg={OBSIDIA.carbon} bg="transparent" />
          </div>
        ))}
      </div>
    </div>

    {/* row 3 — application: app icons */}
    <div>
      <div style={{ fontSize: 10, letterSpacing: "0.25em", textTransform: "uppercase", color: OBSIDIA.mute, marginBottom: 16, fontFamily: "'JetBrains Mono', monospace" }}>C · App icons (60×60 iOS)</div>
      <div style={{ display: "flex", gap: 16, alignItems: "center" }}>
        {Object.keys(VERTICALS).map(k => (
          <div key={k} style={{ display: "flex", flexDirection: "column", alignItems: "center", gap: 10 }}>
            <div style={{
              width: 96, height: 96, borderRadius: 22,
              background: `linear-gradient(135deg, ${OBSIDIA.carbon}, ${VERTICALS[k].accent}80)`,
              padding: 14,
              boxShadow: "0 12px 28px rgba(14,14,16,0.3), inset 0 1px 0 rgba(255,255,255,0.1)",
              display: "grid", placeItems: "center",
              position: "relative",
            }}>
              <MarkComp size={56} fg={OBSIDIA.gold} bg="transparent" />
              {/* tiny sub badge */}
              <div style={{
                position: "absolute", right: 8, bottom: 8,
                width: 22, height: 22, borderRadius: "50%",
                background: VERTICALS[k].accent,
                display: "grid", placeItems: "center",
                boxShadow: `0 0 0 2px ${OBSIDIA.carbon}`,
              }}>
                {React.createElement(SUB_GLYPHS[k], { size: 12, color: "#fff" })}
              </div>
            </div>
            <span style={{ fontSize: 10, letterSpacing: "0.18em", textTransform: "uppercase", color: OBSIDIA.mute, fontWeight: 600 }}>obsidia · {VERTICALS[k].name}</span>
          </div>
        ))}
      </div>
    </div>
  </div>
);

Object.assign(window, {
  MarkShard, MarkMonolith, MarkKite, MarkRidge, MarkPrism, MarkMeridian,
  SUB_GLYPHS, VerticalLockup, WordmarkLockup,
  LogoExploration, EndorsedLockups,
});
