// Atmospheric — Crossing Cloud landing page
// Full-bleed sky hero, glass UI, dreamy. Tweakable sky palette, accent, headline, weave intensity.

const TWEAK_DEFAULTS = /*EDITMODE-BEGIN*/{
  "sky": "twilight",
  "accent": "amber",
  "weaveIntensity": 1,
  "headline": "Software\nthat respects\nyour time.",
  "italicWord": "",
  "showStars": false,
  "sectionOrder": "hero,studio,about,work,contact"
} /*EDITMODE-END*/;

const SKY_PRESETS = {
  twilight: {
    name: "Twilight",
    grad: "radial-gradient(ellipse 90% 70% at 50% 28%, #6FA3D8 0%, #3B7BBE 35%, #1F4E83 70%, #0E2540 100%)",
    night: "#0E2540",
    deep: "#1F4E83"
  },
  dawn: {
    name: "Dawn",
    grad: "radial-gradient(ellipse 100% 80% at 30% 20%, #F4C9A2 0%, #C68DA8 28%, #6F7DB8 55%, #2E4476 85%, #14223D 100%)",
    night: "#14223D",
    deep: "#2E4476"
  },
  overcast: {
    name: "Overcast",
    grad: "radial-gradient(ellipse 110% 80% at 50% 30%, #C9D7E5 0%, #8AA1BB 35%, #4F6584 70%, #2A3B55 100%)",
    night: "#2A3B55",
    deep: "#4F6584"
  },
  midnight: {
    name: "Midnight",
    grad: "radial-gradient(ellipse 100% 80% at 50% 30%, #2A4A78 0%, #15294A 45%, #0A1528 100%)",
    night: "#0A1528",
    deep: "#15294A"
  }
};

const ACCENT_PRESETS = {
  amber: { name: "Amber", color: "oklch(82% 0.13 70)", deep: "oklch(68% 0.14 55)", rgb: "232,170,108" },
  rose: { name: "Rose", color: "oklch(80% 0.11 25)", deep: "oklch(64% 0.14 20)", rgb: "232,150,150" },
  sage: { name: "Sage", color: "oklch(82% 0.07 145)", deep: "oklch(64% 0.10 145)", rgb: "160,200,170" },
  paper: { name: "Paper", color: "oklch(95% 0.02 80)", deep: "oklch(78% 0.04 80)", rgb: "240,232,218" }
};

function Atmospheric() {
  const [tw, setTweak] = useTweaks(TWEAK_DEFAULTS);
  const sky = SKY_PRESETS[tw.sky] || SKY_PRESETS.twilight;
  const acc = ACCENT_PRESETS[tw.accent] || ACCENT_PRESETS.amber;

  // Expose accent & sky to descendants via inline CSS vars
  const pageStyle = {
    "--sky-night": sky.night,
    "--sky-deep": sky.deep,
    "--sky-grad": sky.grad,
    "--accent": acc.color,
    "--accent-deep": acc.deep,
    "--accent-rgb": acc.rgb
  };

  return (
    <div className="cc-page" style={pageStyle}>
      <Nav />
      <StickyNav />
      {(tw.sectionOrder || "hero,studio,about,work,contact").split(",").map((id) => {
        const k = id.trim();
        if (k === "hero") return <Hero key={k} tw={tw} sky={sky} acc={acc} />;
        if (k === "studio") return <Studio key={k} acc={acc} />;
        if (k === "about") return <About key={k} />;
        if (k === "work") return <Work key={k} acc={acc} />;
        if (k === "contact") return <Contact key={k} acc={acc} />;
        return null;
      })}
      <Tweaks tw={tw} setTweak={setTweak} />
    </div>);

}

// Sticky mini-nav appears after scrolling past the hero
function StickyNav() {
  const [show, setShow] = React.useState(false);
  React.useEffect(() => {
    const onScroll = () => setShow(window.scrollY > 700);
    onScroll();
    window.addEventListener("scroll", onScroll, { passive: true });
    return () => window.removeEventListener("scroll", onScroll);
  }, []);
  const link = { color: "rgba(255,255,255,0.85)", textDecoration: "none", fontSize: 13, padding: "8px 14px", borderRadius: 999 };
  return (
    <div style={{
      position: "fixed", top: 16, left: "50%",
      transform: `translateX(-50%) translateY(${show ? 0 : -80}px)`,
      opacity: show ? 1 : 0,
      pointerEvents: show ? "auto" : "none",
      transition: "transform 360ms cubic-bezier(.2,.8,.2,1), opacity 280ms ease",
      zIndex: 100,
      display: "flex", alignItems: "center", gap: 8,
      padding: "8px 8px 8px 14px",
      background: "rgba(14,37,64,0.55)",
      border: "1px solid rgba(255,255,255,0.18)",
      borderRadius: 999,
      backdropFilter: "blur(24px) saturate(160%)",
      WebkitBackdropFilter: "blur(24px) saturate(160%)",
      boxShadow: "0 10px 30px -10px rgba(0,0,0,0.35)"
    }}>
      <a href="#" style={{ display: "flex", alignItems: "center", gap: 8, textDecoration: "none", color: "white", paddingRight: 8, borderRight: "1px solid rgba(255,255,255,0.18)" }}>
        <img src="assets/logo.png" alt="" style={{ width: 22, height: 22, borderRadius: 5 }} />
        <span style={{ fontWeight: 600, fontSize: 13, letterSpacing: "-0.01em" }}>Crossing Cloud</span>
      </a>
      {["Work", "About", "Contact"].map((t) =>
      <a key={t} href={"#" + t.toLowerCase()} style={link}>{t}</a>
      )}
    </div>);

}

// ─────────────────────────────────────────────────────────────
// NAV
// ─────────────────────────────────────────────────────────────
function Nav() {
  const link = { color: "rgba(255,255,255,0.85)", textDecoration: "none", fontSize: 14, letterSpacing: "-0.005em" };
  return (
    <header style={{
      position: "absolute", top: 0, left: 0, right: 0, zIndex: 10,
      display: "flex", alignItems: "center", justifyContent: "space-between",
      padding: "26px clamp(24px, 4vw, 64px)"
    }}>
      <a href="#" style={{ display: "flex", alignItems: "center", gap: 12, textDecoration: "none" }}>
        <img src="assets/logo.png" alt="" style={{ width: 36, height: 36, borderRadius: 8 }} />
        <span style={{ color: "white", fontWeight: 600, fontSize: 16, letterSpacing: "-0.01em" }}>Crossing Cloud</span>
      </a>
      <nav style={{
        display: "flex", gap: 4, padding: "6px 8px",
        background: "rgba(255,255,255,0.08)", border: "1px solid rgba(255,255,255,0.18)",
        borderRadius: 999, backdropFilter: "blur(20px)", WebkitBackdropFilter: "blur(20px)"
      }}>
        {["Work", "About", "Contact"].map((t) =>
        <a key={t} href={"#" + t.toLowerCase()} style={{ ...link, padding: "8px 16px", borderRadius: 999 }}>{t}</a>
        )}
      </nav>
      <a href="#contact" style={{
        color: "var(--sky-night)", background: "white",
        padding: "10px 20px", borderRadius: 999, fontWeight: 500, fontSize: 14, textDecoration: "none"
      }}>Say hello</a>
    </header>);

}

// ─────────────────────────────────────────────────────────────
// HERO
// ─────────────────────────────────────────────────────────────
function WeaveArc({ intensity = 1 }) {
  if (intensity <= 0) return null;
  return (
    <svg viewBox="0 0 1440 900" preserveAspectRatio="xMidYMid slice"
    style={{ position: "absolute", inset: 0, width: "100%", height: "100%", pointerEvents: "none", opacity: 0.5 + intensity * 0.5 }}>
      <defs>
        <linearGradient id="atm-arc-cool" x1="0" x2="1" y1="0" y2="0">
          <stop offset="0" stopColor="rgba(255,255,255,0)" />
          <stop offset="0.3" stopColor="rgba(255,255,255,0.55)" />
          <stop offset="1" stopColor="rgba(255,255,255,0.85)" />
        </linearGradient>
        <linearGradient id="atm-arc-warm" x1="0" x2="1" y1="0" y2="0">
          <stop offset="0" stopColor="rgba(var(--accent-rgb),0.9)" />
          <stop offset="0.7" stopColor="rgba(var(--accent-rgb),0.45)" />
          <stop offset="1" stopColor="rgba(var(--accent-rgb),0)" />
        </linearGradient>
        <filter id="atm-blur" x="-10%" y="-10%" width="120%" height="120%">
          <feGaussianBlur stdDeviation="0.6" />
        </filter>
      </defs>

      {/* Strand A — under at center. Animates: slow drift + a slow draw-on. */}
      <g style={{ animation: "ccDriftA 28s ease-in-out infinite" }}>
        <path d="M -80 720 C 320 720, 520 80, 820 80 S 1280 540, 1520 360"
        fill="none" stroke="url(#atm-arc-cool)" strokeWidth={1.6 * intensity} filter="url(#atm-blur)"
        strokeDasharray="2400" strokeDashoffset="2400"
        style={{ animation: "ccDraw 3.4s ease-out 0.2s forwards" }} />
      </g>
      {/* Strand B — over at center */}
      <g style={{ animation: "ccDriftB 32s ease-in-out infinite" }}>
        <path d="M 1520 740 C 1120 720, 920 80, 620 80 S 160 540, -80 360"
        fill="none" stroke="url(#atm-arc-warm)" strokeWidth={1.6 * intensity} filter="url(#atm-blur)"
        strokeDasharray="2400" strokeDashoffset="2400"
        style={{ animation: "ccDraw 3.6s ease-out 0.5s forwards" }} />
      </g>

      {/* second softer pair, offset, for depth */}
      <g style={{ animation: "ccDriftA 38s ease-in-out infinite" }}>
        <path d="M -80 820 C 360 820, 560 180, 880 180"
        fill="none" stroke="rgba(255,255,255,0.18)" strokeWidth={1 * intensity}
        strokeDasharray="1800" strokeDashoffset="1800"
        style={{ animation: "ccDraw 4s ease-out 0.8s forwards" }} />
      </g>
      <g style={{ animation: "ccDriftB 42s ease-in-out infinite" }}>
        <path d="M 1520 820 C 1080 820, 880 180, 560 180"
        fill="none" stroke={`rgba(var(--accent-rgb),0.22)`} strokeWidth={1 * intensity}
        strokeDasharray="1800" strokeDashoffset="1800"
        style={{ animation: "ccDraw 4.2s ease-out 1s forwards" }} />
      </g>
    </svg>);

}

function Stars() {
  // a constellation of soft white pinpricks
  const pts = React.useMemo(() => {
    const seed = 1234;
    let s = seed;
    const rand = () => {s = (s * 9301 + 49297) % 233280;return s / 233280;};
    return Array.from({ length: 70 }, () => ({
      x: rand() * 100,
      y: rand() * 70,
      r: 0.6 + rand() * 1.2,
      o: 0.25 + rand() * 0.55
    }));
  }, []);
  return (
    <svg viewBox="0 0 100 100" preserveAspectRatio="none"
    style={{ position: "absolute", inset: 0, width: "100%", height: "100%", pointerEvents: "none" }}>
      {pts.map((p, i) =>
      <circle key={i} cx={p.x} cy={p.y} r={p.r * 0.08} fill="white" opacity={p.o} />
      )}
    </svg>);

}

function Hero({ tw, sky, acc }) {
  const lines = (tw.headline || "").split("\n");
  const renderLine = (line, i) => {
    if (!tw.italicWord) return <span key={i} style={{ display: "block" }}>{line}</span>;
    const idx = line.toLowerCase().indexOf(tw.italicWord.toLowerCase());
    if (idx < 0) return <span key={i} style={{ display: "block" }}>{line}</span>;
    const before = line.slice(0, idx);
    const target = line.slice(idx, idx + tw.italicWord.length);
    const after = line.slice(idx + tw.italicWord.length);
    return (
      <span key={i} style={{ display: "block" }}>
        {before}
        <em style={{ fontStyle: "italic", fontWeight: 400, color: "var(--accent)" }}>{target}</em>
        {after}
      </span>);

  };

  return (
    <section style={{
      position: "relative",
      minHeight: 900,
      background: sky.grad,
      overflow: "hidden"
    }}>
      <div style={{ position: "absolute", inset: 0, background: "radial-gradient(circle at 22% 78%, rgba(255,255,255,0.18), transparent 40%), radial-gradient(circle at 80% 60%, rgba(var(--accent-rgb),0.18), transparent 45%)" }} />
      {tw.showStars && <Stars />}
      <WeaveArc intensity={tw.weaveIntensity} />

      <div style={{
        position: "relative", zIndex: 2,
        padding: "200px clamp(24px, 4vw, 64px) 0",
        color: "white", maxWidth: 1280, margin: "0 auto"
      }}>
        <div className="cc-mono" style={{
          fontSize: 12, letterSpacing: "0.18em", textTransform: "uppercase",
          color: "rgba(255,255,255,0.7)", marginBottom: 28,
          display: "flex", alignItems: "center", gap: 12
        }}>
          <span style={{ width: 28, height: 1, background: "rgba(255,255,255,0.5)", fontSize: "1px" }} />
          Independent software studio &nbsp;·&nbsp; Salt Lake City
        </div>

        <h1 style={{
          fontSize: "clamp(56px, 9vw, 132px)", lineHeight: 0.98,
          letterSpacing: "-0.04em", fontWeight: 500,
          margin: 0, color: "white", maxWidth: 1100, textWrap: "balance"
        }}>
          {lines.map(renderLine)}
        </h1>

        <p style={{
          marginTop: 44, fontSize: "clamp(17px, 1.5vw, 22px)", lineHeight: 1.5,
          color: "rgba(255,255,255,0.82)", maxWidth: 600
        }}>Smart, useful, honest applications. Built with care. No nonsense.


        </p>

        <div style={{ display: "flex", gap: 14, marginTop: 44, flexWrap: "wrap" }}>
          <a href="#work" style={{
            background: "white", color: "var(--sky-night)",
            padding: "16px 28px", borderRadius: 999, textDecoration: "none",
            fontSize: 15, fontWeight: 500, display: "inline-flex", alignItems: "center", gap: 10
          }}>See what we make <span>→</span></a>
          <a href="#studio" style={{
            background: "rgba(255,255,255,0.08)", color: "white",
            border: "1px solid rgba(255,255,255,0.3)",
            padding: "16px 28px", borderRadius: 999, textDecoration: "none",
            fontSize: 15, fontWeight: 500, backdropFilter: "blur(12px)"
          }}>About the studio</a>
        </div>
      </div>

      {/* Glass status card — bottom right */}
      <div style={{
        position: "absolute", right: "clamp(24px, 4vw, 56px)", bottom: 56, width: 320, padding: 22,
        background: "rgba(255,255,255,0.08)", border: "1px solid rgba(255,255,255,0.2)",
        borderRadius: 18, backdropFilter: "blur(20px)", WebkitBackdropFilter: "blur(20px)",
        color: "white", zIndex: 3
      }}>
        <div className="cc-mono" style={{ fontSize: 11, color: "rgba(255,255,255,0.65)", letterSpacing: "0.14em", textTransform: "uppercase", marginBottom: 12, display: "flex", alignItems: "center", gap: 8 }}>
          <span style={{ width: 6, height: 6, borderRadius: 999, background: "var(--accent)", boxShadow: "0 0 12px var(--accent)" }} />
          Now in the workshop
        </div>
        <div style={{ fontSize: 17, fontWeight: 500, marginBottom: 6 }}>Duly · Life admin made easy</div>
        <div style={{ fontSize: 13, color: "rgba(255,255,255,0.7)", lineHeight: 1.5 }}>Life admin the way it should be. No streaks. No nags. Just today, tended to.</div>
        <div style={{ display: "flex", justifyContent: "space-between", alignItems: "center", marginTop: 16, paddingTop: 14, borderTop: "1px solid rgba(255,255,255,0.14)", fontSize: 12, color: "rgba(255,255,255,0.6)" }}>
          <span className="cc-mono">In development 2026</span>
          <span>↗</span>
        </div>
      </div>

      <div style={{ position: "absolute", left: 0, right: 0, bottom: 0, height: 240, background: "linear-gradient(to bottom, transparent, var(--sky-night) 90%)" }} />
    </section>);

}

// ─────────────────────────────────────────────────────────────
// STUDIO
// ─────────────────────────────────────────────────────────────
function Studio({ acc }) {
  return (
    <section id="studio" style={{
      background: "var(--sky-night)", color: "white",
      padding: "140px clamp(24px, 4vw, 64px)",
      backgroundImage: "radial-gradient(ellipse 80% 60% at 80% 30%, rgba(110,160,210,0.22), transparent 60%)",
      position: "relative"
    }}>
      {/* Top fade — mirrors the hero's bottom fade so the section boundary
          blends across a wide band of pure sky-night. */}
      <div style={{
        position: "absolute", left: 0, right: 0, top: 0, height: 240,
        background: "linear-gradient(to top, transparent, var(--sky-night) 90%)",
        pointerEvents: "none", zIndex: 0
      }} />
      <div style={{ maxWidth: 1280, margin: "0 auto", position: "relative", zIndex: 1 }}>
        <div className="cc-mono" style={{ fontSize: 11, letterSpacing: "0.18em", color: "var(--accent)", textTransform: "uppercase", marginBottom: 28 }}>
          ☁ &nbsp; The studio
        </div>
        <div style={{ display: "grid", gridTemplateColumns: "1.4fr 1fr", gap: "clamp(40px, 6vw, 100px)", alignItems: "center" }}>
          <h2 style={{ fontSize: "clamp(34px, 4.5vw, 64px)", fontWeight: 400, lineHeight: 1.1, letterSpacing: "-0.025em", margin: 0, textWrap: "balance" }}>
            The apps we use every day shouldn't <em style={{ fontStyle: "italic", color: "var(--accent)" }}>exploit our attention</em>, deal shadily with our data, or treat us like a metric to be optimized.
          </h2>
          <p style={{
            margin: 0,
            fontSize: "clamp(28px, 3.4vw, 48px)",
            fontWeight: 400,
            lineHeight: 1.15,
            letterSpacing: "-0.02em",
            color: "rgba(255,255,255,0.92)",
            textWrap: "balance"
          }}>
            We aim to <em style={{ fontStyle: "italic", color: "var(--accent)" }}>change</em> that.
          </p>
        </div>

        <div style={{ marginTop: 100, display: "grid", gridTemplateColumns: "repeat(4, 1fr)", gap: 0, borderTop: "1px solid rgba(255,255,255,0.18)" }}>
          {[
          ["Built with intent", "Made carefully, shipped ready."],
          ["You're not the product", "Your data isn't sold or mined."],
          ["You stay in control", "Tools that work for you."],
          ["No nags", "Built for focus, not engagement."]].
          map(([t, d], i) =>
          <div key={t} style={{
            padding: "32px 24px 0",
            borderRight: i < 3 ? "1px solid rgba(255,255,255,0.18)" : "none"
          }}>
              <div className="cc-mono" style={{ fontSize: 11, color: "var(--accent)", letterSpacing: "0.14em" }}>0{i + 1}</div>
              <div style={{ fontSize: 22, fontWeight: 500, margin: "14px 0 10px", letterSpacing: "-0.01em" }}>{t}</div>
              <div style={{ fontSize: 14, color: "rgba(255,255,255,0.7)", lineHeight: 1.55 }}>{d}</div>
            </div>
          )}
        </div>
      </div>
    </section>);

}

// ─────────────────────────────────────────────────────────────
// ABOUT
// A more personal counterpoint to Studio. Lighter background to give
// the page a clear breath between the two dark sections.
// ─────────────────────────────────────────────────────────────
function About() {
  return (
    <section id="about" style={{
      background: "var(--cc-paper)",
      color: "var(--cc-ink)",
      padding: "clamp(80px, 10vw, 140px) clamp(24px, 4vw, 64px)",
      position: "relative",
      overflow: "hidden"
    }}>
      {/* Faint weave watermark */}
      <svg viewBox="0 0 1440 700" preserveAspectRatio="xMidYMid slice"
      style={{ position: "absolute", inset: 0, width: "100%", height: "100%", pointerEvents: "none", opacity: 0.5 }}>
        <path d="M -80 580 C 320 580, 520 60, 820 60 S 1280 440, 1520 280"
        fill="none" stroke="rgba(45,108,176,0.16)" strokeWidth="1.2" />
        <path d="M 1520 600 C 1120 580, 920 60, 620 60 S 160 440, -80 280"
        fill="none" stroke="rgba(217,119,87,0.16)" strokeWidth="1.2" />
      </svg>

      <div style={{ maxWidth: 1180, margin: "0 auto", position: "relative" }}>
        <div className="cc-mono" style={{ fontSize: 11, letterSpacing: "0.18em", color: "var(--cc-blue)", textTransform: "uppercase", marginBottom: 32 }}>
          §  About
        </div>
        <div style={{ display: "grid", gridTemplateColumns: "1fr 1.5fr", gap: "clamp(40px, 6vw, 96px)", alignItems: "start" }}>
          {/* Portrait card */}
          <div>
            <div style={{
              aspectRatio: "4 / 5",
              borderRadius: 16,
              background: "var(--cc-blue)",
              border: "1px solid var(--cc-rule)",
              position: "relative",
              overflow: "hidden",
              boxShadow: "0 30px 60px -30px rgba(45,108,176,0.35)"
            }}>
              <img
                src="assets/logo.png"
                alt="Crossing Cloud"
                style={{
                  position: "absolute", inset: 0, width: "100%", height: "100%",
                  objectFit: "cover", display: "block"
                }} />
              
              <div className="cc-mono" style={{
                position: "absolute", bottom: 16, left: 16,
                fontSize: 10, color: "rgba(255,255,255,0.72)", letterSpacing: "0.16em", textTransform: "uppercase"
              }}>Crossing Cloud · 2026</div>
            </div>
            <div style={{
              marginTop: 18,
              display: "grid", gridTemplateColumns: "1fr 1fr",
              gap: 0, fontSize: 13,
              border: "1px solid var(--cc-rule)", borderRadius: 12, overflow: "hidden"
            }}>
              {[
              ["Founded", "2026"],
              ["Based", "Salt Lake City"]].
              map(([k, v], i) =>
              <div key={k} style={{
                padding: "14px 16px",
                background: i % 2 ? "var(--cc-cream)" : "var(--cc-paper)",
                borderRight: i % 2 === 0 ? "1px solid var(--cc-rule)" : "none"
              }}>
                  <div className="cc-mono" style={{ fontSize: 10, color: "var(--cc-mute)", letterSpacing: "0.14em", textTransform: "uppercase" }}>{k}</div>
                  <div style={{ marginTop: 4, fontSize: 15, color: "var(--cc-ink)" }}>{v}</div>
                </div>
              )}
            </div>
          </div>

          {/* The note */}
          <div>
            <h2 style={{
              fontFamily: "'Cormorant Garamond', Georgia, serif",
              fontStyle: "italic", fontWeight: 400,
              fontSize: "clamp(38px, 4.6vw, 64px)",
              lineHeight: 1.05, letterSpacing: "-0.02em",
              margin: "0 0 36px",
              color: "var(--cc-ink)",
              textWrap: "balance"
            }}>After years of using management software and productivity apps, somewhere along the way it started feeling worse to use, not better.


            </h2>
            <div style={{ fontSize: 17, lineHeight: 1.7, color: "var(--cc-ink-2)", maxWidth: 600, display: "flex", flexDirection: "column", gap: 18 }}>
              <p style={{ margin: 0 }}>Crossing Cloud is our answer to that. A software studio for people who'd rather use a small, finished thing than be stuck in a sprawling one. We design and build intuitive and useful apps — the kind your grandmother could open and use, the kind that still work when the cell tower is down.




              </p>
              <p style={{ margin: 0 }}>Between our own products, we take on a small number of outside engagements — usually those who want a thoughtful first version, or teams who need an honest second opinion on software before they commit.



              </p>
            </div>

            {/* Signature row */}
            <div style={{
              marginTop: 44, paddingTop: 24,
              borderTop: "1px solid var(--cc-rule)",
              display: "flex", alignItems: "center", justifyContent: "space-between", gap: 20, flexWrap: "wrap"
            }}>
              <div style={{ display: "flex", alignItems: "center", gap: 14 }}>
                <span style={{
                  fontFamily: "'Cormorant Garamond', Georgia, serif",
                  fontStyle: "italic", fontSize: 36, color: "var(--cc-blue)", lineHeight: 1, letterSpacing: "-0.01em"
                }}>Zachary Ferries</span>
                <span className="cc-mono" style={{ fontSize: 11, color: "var(--cc-mute)", letterSpacing: "0.14em", textTransform: "uppercase" }}>
                  · Founder
                </span>
              </div>
              <a href="#contact" style={{
                display: "inline-flex", alignItems: "center", gap: 10,
                background: "var(--cc-ink)", color: "var(--cc-paper)",
                padding: "12px 20px", borderRadius: 999, textDecoration: "none",
                fontSize: 14, fontWeight: 500
              }}>Say hello <span>→</span></a>
            </div>
          </div>
        </div>
      </div>
    </section>);

}

// ─────────────────────────────────────────────────────────────
// WORK
// ─────────────────────────────────────────────────────────────
function Work({ acc }) {
  return (
    <section id="work" style={{ background: "var(--cc-paper)", padding: "140px clamp(24px, 4vw, 64px)", color: "var(--cc-ink)" }}>
      <div style={{ maxWidth: 1280, margin: "0 auto" }}>
        <div style={{ display: "flex", justifyContent: "space-between", alignItems: "baseline", marginBottom: 56, flexWrap: "wrap", gap: 16 }}>
          <div>
            <div className="cc-mono" style={{ fontSize: 11, letterSpacing: "0.18em", color: "var(--cc-blue)", textTransform: "uppercase", marginBottom: 14 }}>The work</div>
            <h2 style={{ fontSize: "clamp(36px, 4.5vw, 56px)", fontWeight: 500, margin: 0, letterSpacing: "-0.025em" }}></h2>
          </div>
          <div className="cc-mono" style={{ fontSize: 12, color: "var(--cc-mute)", letterSpacing: "0.06em" }}>01 / 01</div>
        </div>

        <article style={{
          position: "relative",
          borderRadius: 24, overflow: "hidden",
          background: "linear-gradient(160deg, var(--sky-deep) 0%, var(--sky-night) 100%)",
          color: "white", padding: 0, minHeight: 560,
          display: "grid", gridTemplateColumns: "1fr 1.1fr",
          boxShadow: "0 40px 80px -40px rgba(14,37,64,0.35)"
        }}>
          {/* subtle weave on the card too */}
          <svg viewBox="0 0 800 600" preserveAspectRatio="xMidYMid slice"
          style={{ position: "absolute", inset: 0, width: "100%", height: "100%", pointerEvents: "none", opacity: 0.5 }}>
            <path d="M -40 480 C 240 480, 320 80, 520 80 S 760 360, 880 280"
            fill="none" stroke="rgba(255,255,255,0.35)" strokeWidth="1.4" />
            <path d="M 880 480 C 600 480, 520 80, 320 80"
            fill="none" stroke="rgba(var(--accent-rgb),0.55)" strokeWidth="1.4" />
          </svg>

          <div style={{ padding: "56px 56px 56px", position: "relative" }}>
            <div className="cc-mono" style={{ fontSize: 11, color: "var(--accent)", letterSpacing: "0.16em", textTransform: "uppercase", marginBottom: 20 }}>
              ▲ &nbsp;Coming 2026
            </div>
            <h3 style={{ fontSize: "clamp(44px, 5vw, 72px)", letterSpacing: "-0.03em", margin: "0 0 14px", fontStyle: "italic", fontFamily: "sans-serif", lineHeight: "1", fontWeight: "100" }}>
              Duly
            </h3>
            <p style={{ fontSize: 18, lineHeight: 1.55, color: "rgba(255,255,255,0.82)", margin: "0 0 30px", maxWidth: 380 }}>A life admin app for people who'd rather get on with their day. The recurring stuff, handled. Everything. On time.


            </p>
            <div style={{ display: "flex", flexDirection: "column", gap: 0, fontSize: 14 }}>
              {[
              ["Platform", "iOS · Android"],
              ["Pricing", "Free with optional in app purchases"],
              ["Status", "In development - 2026 Release"]].
              map(([k, v]) =>
              <div key={k} style={{ display: "grid", gridTemplateColumns: "120px 1fr", borderTop: "1px solid rgba(255,255,255,0.18)", padding: "12px 0" }}>
                  <span className="cc-mono" style={{ color: "rgba(255,255,255,0.6)", fontSize: 11, letterSpacing: "0.14em", textTransform: "uppercase" }}>{k}</span>
                  <span>{v}</span>
                </div>
              )}
            </div>
            <div style={{ display: "flex", gap: 12, marginTop: 32, flexWrap: "wrap" }}>
              <span className="cc-mono" style={{
                display: "inline-flex", alignItems: "center",
                background: "rgba(255,255,255,0.06)",
                color: "rgba(255,255,255,0.55)",
                border: "1px solid rgba(255,255,255,0.18)",
                padding: "14px 22px", borderRadius: 999,
                fontSize: 12, fontWeight: 500,
                letterSpacing: "0.18em", textTransform: "uppercase",
                cursor: "default", userSelect: "none"
              }}>Coming soon</span>
            </div>
          </div>
          <div style={{ position: "relative", margin: 18, marginLeft: 0, borderRadius: 16, overflow: "hidden", border: "1px solid rgba(255,255,255,0.14)", display: "grid", placeItems: "center", backgroundImage: "initial", backgroundPosition: "initial", backgroundSize: "initial", backgroundRepeat: "initial", backgroundAttachment: "initial", backgroundOrigin: "initial", backgroundClip: "initial", background: "rgb(122, 155, 118)" }}>
            <img src="assets/duly-icon.png" alt="Duly" style={{ width: "55%", maxWidth: 320, opacity: 0.95 }} />
          </div>
        </article>
      </div>
    </section>);

}

// ─────────────────────────────────────────────────────────────
// SERVICES
// ─────────────────────────────────────────────────────────────
function Services() {
  const items = [
  ["Product partnership", "Design, code, and judgment from concept to ship.", "Monthly retainer"],
  ["Technical due diligence", "Honest written assessment of a codebase before you sign.", "Fixed engagement"],
  ["Native app rescue", "Slow, fragile, or stuck on a dead framework? We rebuild it.", "Project-based"]];

  return (
    <section id="services" style={{ background: "var(--cc-paper)", padding: "0 clamp(24px, 4vw, 64px) 140px", color: "var(--cc-ink)" }}>
      <div style={{
        maxWidth: 1280, margin: "0 auto",
        background: "var(--cc-cream)", borderRadius: 28, padding: "clamp(48px, 6vw, 80px) clamp(28px, 5vw, 60px)",
        position: "relative", overflow: "hidden"
      }}>
        <div style={{ position: "absolute", right: -120, top: -120, width: 480, height: 480, borderRadius: "50%", background: "radial-gradient(circle, rgba(45,108,176,0.12), transparent 60%)" }} />
        <div className="cc-mono" style={{ fontSize: 11, letterSpacing: "0.18em", color: "var(--cc-blue)", textTransform: "uppercase", marginBottom: 18 }}>Services</div>
        <h2 style={{ fontSize: "clamp(34px, 4.2vw, 52px)", fontWeight: 500, margin: "0 0 56px", letterSpacing: "-0.025em", maxWidth: 720, lineHeight: 1.05 }}>
          When the calendar allows, we take on a small number of outside engagements.
        </h2>
        <div style={{ display: "grid", gridTemplateColumns: "repeat(auto-fit, minmax(260px, 1fr))", gap: 20 }}>
          {items.map(([t, d, p]) =>
          <div key={t} style={{
            background: "var(--cc-paper)", padding: 28, borderRadius: 18,
            border: "1px solid var(--cc-rule)",
            display: "flex", flexDirection: "column", gap: 14, minHeight: 200
          }}>
              <h3 style={{ fontSize: 22, fontWeight: 500, margin: 0, letterSpacing: "-0.005em" }}>{t}</h3>
              <p style={{ fontSize: 15, color: "var(--cc-ink-2)", lineHeight: 1.55, margin: 0, flex: 1 }}>{d}</p>
              <div className="cc-mono" style={{ fontSize: 11, letterSpacing: "0.14em", color: "var(--cc-mute)", textTransform: "uppercase", paddingTop: 14, borderTop: "1px solid var(--cc-rule)" }}>{p}</div>
            </div>
          )}
        </div>
      </div>
    </section>);

}

// ─────────────────────────────────────────────────────────────
// CONTACT + FOOTER
// ─────────────────────────────────────────────────────────────
function Contact({ acc }) {
  return (
    <section id="contact" style={{
      background: "linear-gradient(180deg, var(--sky-night) 0%, var(--sky-deep) 100%)",
      color: "white", padding: "140px clamp(24px, 4vw, 64px) 60px", position: "relative", overflow: "hidden"
    }}>
      <div style={{ position: "absolute", inset: 0, background: "radial-gradient(circle at 20% 100%, rgba(var(--accent-rgb),0.20), transparent 50%)" }} />
      <div style={{ maxWidth: 1280, margin: "0 auto", position: "relative" }}>
        <div style={{ display: "grid", gridTemplateColumns: "1.1fr 1fr", gap: "clamp(40px, 6vw, 80px)" }}>
          <div>
            <div className="cc-mono" style={{ fontSize: 11, letterSpacing: "0.18em", color: "var(--accent)", textTransform: "uppercase", marginBottom: 18 }}>Contact</div>
            <h2 style={{ fontSize: "clamp(48px, 6vw, 84px)", fontWeight: 400, margin: "0 0 28px", letterSpacing: "-0.03em", lineHeight: 0.98 }}>
              Let's make<br />something<br /><em style={{ fontStyle: "italic", color: "var(--accent)" }}>built right.</em>
            </h2>
            <p style={{ fontSize: 18, color: "rgba(255,255,255,0.78)", lineHeight: 1.55, margin: 0, maxWidth: 460 }}>We read every email and we'll get back within a few business days. Usually with a real answer, not a discovery call.


            </p>
            <div style={{ marginTop: 48, display: "flex", flexDirection: "column", gap: 10, fontFamily: "var(--cc-mono)", fontSize: 13, color: "rgba(255,255,255,0.78)" }}>
              <div><span style={{ color: "rgba(255,255,255,0.45)" }}>email&nbsp;&nbsp;</span> contact@crossingcloud.dev</div>
              <div><span style={{ color: "rgba(255,255,255,0.45)" }}>where&nbsp;&nbsp;</span> Salt Lake City, UT</div>
            </div>
          </div>

          <ContactForm />
        </div>

        <div style={{ marginTop: 100, paddingTop: 28, borderTop: "1px solid rgba(255,255,255,0.18)", display: "flex", justifyContent: "space-between", alignItems: "center", fontFamily: "var(--cc-mono)", fontSize: 12, color: "rgba(255,255,255,0.55)", letterSpacing: "0.04em", flexWrap: "wrap", gap: 12 }}>
          <span style={{ display: "flex", alignItems: "center", gap: 10 }}>
            <img src="assets/logo.png" alt="" style={{ width: 18, height: 18, borderRadius: 3 }} />
            © 2026 Crossing Cloud LLC
          </span>
          <span style={{ display: "flex", gap: 22, flexWrap: "wrap" }}>
            <a href="Privacy Policy.html" style={{ color: "rgba(255,255,255,0.7)", textDecoration: "none" }}>Privacy Policy</a>
            <a href="Terms of Use.html" style={{ color: "rgba(255,255,255,0.7)", textDecoration: "none" }}>Terms of Use</a>
          </span>
          <span>Made deliberately in Utah</span>
          <span>v1.0 · 04 May 2026</span>
        </div>
      </div>
    </section>);

}

function ContactForm() {
  const [status, setStatus] = React.useState("idle"); // idle | sending | sent | error
  const [error, setError] = React.useState("");

  const onSubmit = async (e) => {
    e.preventDefault();
    setStatus("sending");
    setError("");
    const fd = new FormData(e.target);
    const payload = {
      name: fd.get("name"),
      email: fd.get("email"),
      company: fd.get("company"),
      message: fd.get("message"),
      website: fd.get("website") // honeypot
    };
    try {
      const resp = await fetch("/api/contact", {
        method: "POST",
        headers: { "Content-Type": "application/json" },
        body: JSON.stringify(payload)
      });
      const body = await resp.json().catch(() => ({}));
      if (!resp.ok) {
        setError(body.error || "Something went wrong. Please try again.");
        setStatus("error");
        return;
      }
      setStatus("sent");
    } catch {
      setError("Couldn't reach the server. Check your connection and try again.");
      setStatus("error");
    }
  };

  if (status === "sent") {
    return (
      <div style={{
        background: "rgba(255,255,255,0.06)", border: "1px solid rgba(255,255,255,0.18)",
        borderRadius: 18, padding: 40, backdropFilter: "blur(20px)",
        display: "flex", flexDirection: "column", gap: 14, alignItems: "flex-start", justifyContent: "center"
      }}>
        <div className="cc-mono" style={{ fontSize: 11, color: "var(--accent)", letterSpacing: "0.18em", textTransform: "uppercase" }}>✓ Sent</div>
        <h3 style={{ fontSize: 28, fontWeight: 500, margin: 0, letterSpacing: "-0.015em" }}>Thanks — we'll be in touch.</h3>
        <p style={{ fontSize: 15, color: "rgba(255,255,255,0.72)", lineHeight: 1.55, margin: 0 }}>
          We read every email and we'll get back within two business days. In the meantime, take care.
        </p>
        <button onClick={() => { setStatus("idle"); setError(""); }} style={{
          background: "transparent", color: "rgba(255,255,255,0.7)", border: "1px solid rgba(255,255,255,0.3)",
          padding: "10px 18px", borderRadius: 999, fontSize: 13, cursor: "pointer", fontFamily: "inherit", marginTop: 6
        }}>Send another</button>
      </div>);

  }

  const sending = status === "sending";

  return (
    <form style={{
      background: "rgba(255,255,255,0.06)", border: "1px solid rgba(255,255,255,0.18)",
      borderRadius: 18, padding: 32, backdropFilter: "blur(20px)",
      display: "flex", flexDirection: "column", gap: 18
    }} onSubmit={onSubmit} noValidate={false}>
      {[
        ["Your name", "text", "name", true],
        ["Email", "email", "email", true],
        ["Company (optional)", "text", "company", false]
      ].map(([l, t, n, req]) =>
      <label key={n} style={{ display: "flex", flexDirection: "column", gap: 6 }}>
          <span className="cc-mono" style={{ fontSize: 11, color: "rgba(255,255,255,0.6)", letterSpacing: "0.12em", textTransform: "uppercase" }}>{l}</span>
          <input type={t} name={n} required={req} disabled={sending} style={{
          background: "rgba(255,255,255,0.08)", border: "1px solid rgba(255,255,255,0.18)",
          color: "white", padding: "12px 14px", borderRadius: 10, fontSize: 16, outline: "none", fontFamily: "inherit"
        }} />
        </label>
      )}
      <label style={{ display: "flex", flexDirection: "column", gap: 6 }}>
        <span className="cc-mono" style={{ fontSize: 11, color: "rgba(255,255,255,0.6)", letterSpacing: "0.12em", textTransform: "uppercase" }}>What's on your mind?</span>
        <textarea rows={4} name="message" required disabled={sending} style={{
          background: "rgba(255,255,255,0.08)", border: "1px solid rgba(255,255,255,0.18)",
          color: "white", padding: 14, borderRadius: 10, fontSize: 15, outline: "none", resize: "none", fontFamily: "inherit"
        }} />
      </label>

      {/* Honeypot — visually hidden field that real users won't fill but bots will. */}
      <div aria-hidden="true" style={{ position: "absolute", left: "-9999px", top: "-9999px" }}>
        <label>
          Don&apos;t fill this in
          <input type="text" name="website" tabIndex={-1} autoComplete="off" />
        </label>
      </div>

      {status === "error" &&
        <div style={{
          fontSize: 14, lineHeight: 1.5,
          color: "rgba(255,210,210,0.95)",
          background: "rgba(180,60,60,0.18)",
          border: "1px solid rgba(255,180,180,0.35)",
          borderRadius: 10, padding: "10px 14px"
        }}>{error}</div>
      }

      <button type="submit" disabled={sending} style={{
        background: "white", color: "var(--sky-night)", border: "none",
        padding: "16px 24px", borderRadius: 999, fontSize: 15, fontWeight: 500,
        cursor: sending ? "default" : "pointer", marginTop: 6, fontFamily: "inherit",
        opacity: sending ? 0.6 : 1
      }}>{sending ? "Sending…" : "Send a message →"}</button>
    </form>);

}

// ─────────────────────────────────────────────────────────────
// TWEAKS
// ─────────────────────────────────────────────────────────────
function SectionOrderTweak({ value, onChange }) {
  const ids = (value || "hero,studio,about,work,contact").split(",").map((s) => s.trim());
  const labels = { hero: "Hero", studio: "Studio", about: "About", work: "Work", contact: "Contact" };
  const [dragIdx, setDragIdx] = React.useState(null);
  const [overIdx, setOverIdx] = React.useState(null);

  const move = (from, to) => {
    if (from === to) return;
    const next = ids.slice();
    const [it] = next.splice(from, 1);
    next.splice(to, 0, it);
    onChange(next.join(","));
  };

  return (
    <div style={{ padding: "0 12px 4px" }}>
      <div style={{ fontSize: 10, color: "rgba(11,18,32,0.55)", letterSpacing: "0.06em", textTransform: "uppercase", margin: "8px 0 6px" }}>
        Drag to reorder
      </div>
      <ul style={{ listStyle: "none", margin: 0, padding: 0, display: "flex", flexDirection: "column", gap: 4 }}>
        {ids.map((id, i) =>
        <li key={id}
        draggable
        onDragStart={(e) => {setDragIdx(i);e.dataTransfer.effectAllowed = "move";}}
        onDragOver={(e) => {e.preventDefault();setOverIdx(i);}}
        onDragLeave={() => setOverIdx((cur) => cur === i ? null : cur)}
        onDrop={(e) => {e.preventDefault();if (dragIdx !== null) move(dragIdx, i);setDragIdx(null);setOverIdx(null);}}
        onDragEnd={() => {setDragIdx(null);setOverIdx(null);}}
        style={{
          display: "flex", alignItems: "center", gap: 10,
          padding: "8px 10px", borderRadius: 8,
          background: dragIdx === i ? "rgba(45,108,176,0.18)" : overIdx === i ? "rgba(45,108,176,0.10)" : "rgba(11,18,32,0.04)",
          border: overIdx === i && dragIdx !== i ? "1px dashed rgba(45,108,176,0.6)" : "1px solid transparent",
          fontSize: 13, color: "#0B1220",
          cursor: "grab", userSelect: "none",
          opacity: dragIdx === i ? 0.5 : 1,
          transition: "background 120ms ease, border-color 120ms ease"
        }}>
          
            <span aria-hidden style={{ color: "rgba(11,18,32,0.4)", fontSize: 14, lineHeight: 1, letterSpacing: "-2px" }}>⋮⋮</span>
            <span style={{ flex: 1 }}>{labels[id] || id}</span>
            <span style={{ fontFamily: "var(--cc-mono)", fontSize: 10, color: "rgba(11,18,32,0.4)", letterSpacing: "0.08em" }}>
              {String(i + 1).padStart(2, "0")}
            </span>
          </li>
        )}
      </ul>
      <button
        type="button"
        onClick={() => onChange("hero,studio,about,work,contact")}
        style={{
          marginTop: 10, fontSize: 11, color: "rgba(11,18,32,0.6)",
          background: "transparent", border: "none", padding: 0, cursor: "pointer",
          textDecoration: "underline", textUnderlineOffset: 3
        }}>
        Reset to default order</button>
    </div>);

}

function Tweaks({ tw, setTweak }) {
  // Headline uses " / " as a line separator since the input is single-line.
  const headlineFlat = (tw.headline || "").replace(/\n/g, " / ");
  const onHeadline = (v) => setTweak("headline", v.split(" / ").join("\n"));

  return (
    <TweaksPanel title="Tweaks">
      <TweakSection label="Sky" />
      <TweakRadio label="Palette" value={tw.sky}
      options={[
      { value: "twilight", label: "Twilight" },
      { value: "dawn", label: "Dawn" },
      { value: "overcast", label: "Overcast" },
      { value: "midnight", label: "Midnight" }]
      } onChange={(v) => setTweak("sky", v)} />
      <TweakToggle label="Stars" value={tw.showStars} onChange={(v) => setTweak("showStars", v)} />

      <TweakSection label="Accent" />
      <TweakRadio label="Color" value={tw.accent}
      options={[
      { value: "amber", label: "Amber" },
      { value: "rose", label: "Rose" },
      { value: "sage", label: "Sage" },
      { value: "paper", label: "Paper" }]
      } onChange={(v) => setTweak("accent", v)} />

      <TweakSection label="Weave" />
      <TweakSlider label="Intensity" value={tw.weaveIntensity} min={0} max={2} step={0.1}
      onChange={(v) => setTweak("weaveIntensity", v)} />

      <TweakSection label="Headline" />
      <TweakText label='Text (use " / " for line break)' value={headlineFlat} onChange={onHeadline} />
      <TweakText label="Italicized word" value={tw.italicWord} onChange={(v) => setTweak("italicWord", v)} />

      <TweakSection label="Section order" />
      <SectionOrderTweak value={tw.sectionOrder} onChange={(v) => setTweak("sectionOrder", v)} />
    </TweaksPanel>);

}

window.Atmospheric = Atmospheric;