/* global React, ReactDOM, Icon, Wordmark */
// ============================================================
// Coming soon — standalone marketing page template.
// Reuses the shared design tokens (styles.css) + Wordmark/Icon so it
// stays on-brand. Swap copy / launch date freely; this is a template.
// ============================================================
const { useState: useStateCS } = React;

// Launch target — change this date to drive the countdown.
const LAUNCH_TS = new Date('2026-08-15T17:00:00Z').getTime();

function useCountdown(target) {
  const [now, setNow] = useStateCS(Date.now());
  React.useEffect(() => {
    const id = setInterval(() => setNow(Date.now()), 1000);
    return () => clearInterval(id);
  }, []);
  const diff = Math.max(0, target - now);
  const d = Math.floor(diff / 86400000);
  const h = Math.floor((diff % 86400000) / 3600000);
  const m = Math.floor((diff % 3600000) / 60000);
  const s = Math.floor((diff % 60000) / 1000);
  return { d, h, m, s, done: diff === 0 };
}

function CountUnit({ value, label }) {
  return (
    <div className="cs-count-unit">
      <div className="cs-count-val num">{String(value).padStart(2, '0')}</div>
      <div className="cs-count-lab">{label}</div>
    </div>
  );
}

function ComingSoon() {
  const t = useCountdown(LAUNCH_TS);
  const [email, setEmail] = useStateCS('');
  const [sent, setSent] = useStateCS(false);
  const valid = /.+@.+\..+/.test(email);

  function submit(e) {
    e.preventDefault();
    if (!valid) return;
    setSent(true);
  }

  return (
    <div className="cs-root">
      <div className="cs-grid"></div>
      <div className="cs-glow"></div>

      <header className="cs-top">
        <Wordmark size={17} />
        <a className="btn ghost small" href="#" target="_blank" rel="noreferrer">
        </a>
      </header>

      <main className="cs-main">
        <div className="cs-gem" aria-hidden="true">
          <Icon.Mark />
        </div>

        <span className="cs-eyebrow">
          <span className="cs-eyebrow-dot"></span>
          Beta coming soon
        </span>

        <h1 className="cs-h1">
          A calmer home for your<br />characters, grinds &amp; static.
        </h1>

        <p className="cs-sub">
          Crystaltide ties together what's scattered across spreadsheets and single-purpose
          sites; synced from public data, tracked the way your group actually plays.
          We're putting on the finishing touches.
        </p>

      </main>

      <footer className="cs-foot">
        <span className="faint">
            © 2026 Crystaltide · crystaltide.gg · Not affiliated with Square Enix
            <br />
            FINAL FANTASY & FFXIV are registered trademarks of SQUARE ENIX CO., LTD.
            <br />
            All FFXIV content and images © 2002-2026 SQUARE ENIX CO., LTD. 
        </span>
        <span className="row gap-16">
          <a href="#" className="faint">Privacy</a>
          <a href="#" className="faint">Status</a>
        </span>
      </footer>

      <style>{`
        .cs-root {
          position: relative;
          min-height: 100vh;
          display: flex;
          flex-direction: column;
          background: var(--bg);
          overflow: hidden;
        }
        .cs-grid {
          position: absolute; inset: 0;
          background-image:
            linear-gradient(var(--border-soft) 1px, transparent 1px),
            linear-gradient(90deg, var(--border-soft) 1px, transparent 1px);
          background-size: 56px 56px;
          mask-image: radial-gradient(ellipse 80% 60% at center 38%, black 0%, transparent 70%);
          opacity: 0.35;
          pointer-events: none;
        }
        .cs-glow {
          position: absolute;
          top: -180px; left: 50%;
          width: 720px; height: 720px;
          transform: translateX(-50%);
          background: radial-gradient(circle, var(--primary-bg) 0%, transparent 62%);
          opacity: 0.7;
          pointer-events: none;
        }
        .cs-top {
          position: relative; z-index: 1;
          display: flex; align-items: center; justify-content: space-between;
          padding: 22px 30px;
          max-width: 1100px; width: 100%;
          margin: 0 auto;
        }
        .cs-main {
          position: relative; z-index: 1;
          flex: 1;
          display: flex; flex-direction: column; align-items: center;
          text-align: center;
          padding: 40px 28px 56px;
          max-width: 680px;
          margin: 0 auto;
        }
        .cs-gem {
          width: 68px; height: 68px;
          border-radius: 16px;
          display: grid; place-items: center;
          background: linear-gradient(140deg, var(--primary) 0%, oklch(0.55 0.16 295) 100%);
          box-shadow:
            0 0 0 1px oklch(1 0 0 / 0.10) inset,
            0 10px 40px -8px var(--primary-dim),
            0 0 60px -10px var(--primary-dim);
          margin-bottom: 26px;
          animation: cs-float 5.5s ease-in-out infinite;
        }
        .cs-gem svg { width: 34px; height: 34px; }
        @keyframes cs-float {
          0%, 100% { transform: translateY(0) rotate(0deg); }
          50% { transform: translateY(-7px) rotate(-1.5deg); }
        }
        .cs-eyebrow {
          display: inline-flex; align-items: center; gap: 8px;
          font-size: 12px; font-weight: 500;
          color: var(--primary-hi);
          background: var(--primary-bg);
          border: 1px solid oklch(0.55 0.13 275 / 0.4);
          padding: 5px 12px; border-radius: 999px;
          margin-bottom: 24px;
          letter-spacing: 0.01em;
        }
        .cs-eyebrow-dot {
          width: 6px; height: 6px; border-radius: 50%;
          background: var(--primary-hi);
          box-shadow: 0 0 0 0 var(--primary-hi);
          animation: cs-pulse 2.2s ease-out infinite;
        }
        @keyframes cs-pulse {
          0% { box-shadow: 0 0 0 0 oklch(0.78 0.16 275 / 0.6); }
          70% { box-shadow: 0 0 0 7px oklch(0.78 0.16 275 / 0); }
          100% { box-shadow: 0 0 0 0 oklch(0.78 0.16 275 / 0); }
        }
        .cs-h1 {
          font-size: 46px; font-weight: 600;
          letter-spacing: -0.028em; line-height: 1.08;
          color: var(--text-strong);
          margin: 0 0 18px;
          text-wrap: balance;
        }
        .cs-sub {
          font-size: 15.5px; line-height: 1.6;
          color: var(--text-muted);
          margin: 0 0 34px;
          max-width: 520px;
          text-wrap: pretty;
        }
        .cs-count {
          display: flex; align-items: flex-start; gap: 14px;
          margin-bottom: 36px;
        }
        .cs-count-unit {
          display: flex; flex-direction: column; align-items: center;
          min-width: 64px;
          background: var(--surface);
          border: 1px solid var(--border-soft);
          border-radius: 12px;
          padding: 12px 8px 10px;
          box-shadow: var(--shadow-1);
        }
        .cs-count-val {
          font-size: 30px; font-weight: 600;
          color: var(--text-strong);
          line-height: 1; letter-spacing: -0.02em;
          font-variant-numeric: tabular-nums;
        }
        .cs-count-lab {
          font-size: 10.5px; text-transform: uppercase;
          letter-spacing: 0.08em;
          color: var(--text-faint);
          margin-top: 7px;
        }
        .cs-count-sep {
          font-size: 26px; font-weight: 600;
          color: var(--border-hi);
          padding-top: 12px;
        }
        .cs-form {
          display: flex; gap: 10px;
          width: 100%; max-width: 440px;
        }
        .cs-field {
          flex: 1;
          display: flex; align-items: center; gap: 9px;
          height: 44px; padding: 0 14px;
          background: var(--bg-elev);
          border: 1px solid var(--border);
          border-radius: 11px;
          transition: border-color 120ms, box-shadow 120ms;
        }
        .cs-field:focus-within {
          border-color: var(--primary);
          box-shadow: 0 0 0 3px oklch(0.55 0.15 275 / 0.18);
        }
        .cs-field svg { color: var(--text-faint); flex: 0 0 16px; }
        .cs-input {
          flex: 1; min-width: 0;
          border: none; background: none; outline: none;
          color: var(--text); font-family: inherit; font-size: 14px;
        }
        .cs-input::placeholder { color: var(--text-faint); }
        .cs-form .btn.large { height: 44px; border-radius: 11px; flex: 0 0 auto; }
        .cs-sent {
          display: flex; align-items: center; gap: 14px;
          text-align: left;
          width: 100%; max-width: 440px;
          background: var(--surface);
          border: 1px solid oklch(0.50 0.13 152 / 0.3);
          border-radius: 12px;
          padding: 16px 18px;
        }
        .cs-sent-ic {
          width: 38px; height: 38px; flex: 0 0 38px;
          border-radius: 50%;
          background: var(--success-bg);
          border: 1px solid oklch(0.50 0.13 152 / 0.5);
          color: var(--success);
          display: grid; place-items: center;
        }
        .cs-sent-ic svg { width: 18px; height: 18px; }
        .cs-sent-t { font-size: 14px; font-weight: 600; color: var(--text-strong); margin-bottom: 2px; }
        .cs-sent-s { font-size: 12.5px; color: var(--text-muted); }
        .cs-sent-s strong { color: var(--text); font-weight: 600; }
        .cs-mini {
          display: flex; align-items: center; gap: 8px;
          font-size: 12px; color: var(--text-faint);
          margin: 22px 0 0;
        }
        .cs-mini svg { flex: 0 0 13px; width: 13px; height: 13px; }
        .cs-foot {
          position: relative; z-index: 1;
          display: flex; align-items: center; justify-content: space-between;
          gap: 16px; flex-wrap: wrap;
          padding: 20px 30px;
          max-width: 1100px; width: 100%;
          margin: 0 auto;
          border-top: 1px solid var(--border-soft);
          font-size: 12px;
        }
        .cs-foot a { color: var(--text-faint); text-decoration: none; }
        .cs-foot a:hover { color: var(--text-muted); }

        @media (max-width: 640px) {
          .cs-h1 { font-size: 34px; }
          .cs-count-unit { min-width: 56px; }
          .cs-count-val { font-size: 26px; }
          .cs-form { flex-direction: column; }
          .cs-form .btn.large { width: 100%; }
          .cs-foot { justify-content: center; text-align: center; }
        }
      `}</style>
    </div>
  );
}

ReactDOM.createRoot(document.getElementById('root')).render(<ComingSoon />);
