// ─────────────────────────────────────────────────────────────
// Personal DM · Tree view — brainstorm board
//
// Premise: the existing Tree view (image 1) shows a skeleton of every
// node as a dot, connected by faint hairlines. At ~10 nodes that looks
// alive. At 332 nodes it reads as static — clinical data-viz, not
// "the conversation you and Marina have grown."
//
// Canvas (image 2) is the primary read/write surface and the user
// likes it. Tree is the SECOND surface: a condensed overview of the
// conversation's shape — what got talked about, when, how much.
//
// Each variant below tries a different answer to the same question:
//     "What does a 332-node DM look like when you zoom out, and
//     why is it ForestLynk?"
// ─────────────────────────────────────────────────────────────

const PHONE_W = 390;
const PHONE_H = 760;


// ───────────────── Premise card ─────────────────

function PremiseCard() {
  return (
    <div style={{ width: 440, height: 880, boxSizing: 'border-box',
                  background: '#0B1306',
                  border: '0.5px solid #2D3A22', borderRadius: 14,
                  padding: '24px 26px',
                  font: '400 13.5px/1.55 var(--font-sans)', color: '#C9D2BB',
                  display: 'flex', flexDirection: 'column' }}>
      <div style={{ font: '500 10.5px var(--font-sans)', color: '#F4DCA0',
                    letterSpacing: '0.14em', textTransform: 'uppercase',
                    marginBottom: 12 }}>
        The challenge
      </div>
      <p style={{ margin: '0 0 12px' }}>
        Tree view of a personal DM with marina_k:&nbsp;
        <b>332 nodes</b>, mostly leaves. The current draft renders every
        single node as a dot with hairline connectors — it works for ~10
        but reads as <i>noise</i> for hundreds.
      </p>
      <p style={{ margin: '0 0 12px' }}>
        Tree isn&apos;t the primary surface — Canvas is. Tree&apos;s job
        is to answer "what is the <b>shape</b> of this conversation?"
        That&apos;s a <b>~16-element</b> problem (the roots) dressed up
        as a 332-element one.
      </p>

      <SkeletonDelta/>

      <div style={{ font: '500 10.5px var(--font-sans)', color: '#D6BFA8',
                    letterSpacing: '0.14em', textTransform: 'uppercase',
                    marginTop: 4, marginBottom: 8 }}>
        What we can honestly show
      </div>
      <p style={{ margin: '0 0 8px',
                  font: 'italic 400 12.5px/1.55 var(--font-serif)',
                  color: '#A8C5A0' }}>
        There is no topic-classifier in the product. A &quot;root&quot;
        is just a message that got at least one reply. The only labels
        available per root are:
      </p>
      <div style={{ display: 'flex', flexWrap: 'wrap', gap: 6,
                    marginBottom: 12 }}>
        {[
          'first words',
          'who sent it',
          'when',
          'branches',
          'leaves',
          'depth',
        ].map(t => (
          <span key={t} style={{
            padding: '4px 10px',
            background: '#111D0A', border: '0.5px solid #1F2B16',
            borderRadius: 999,
            font: '500 10.5px var(--font-mono)', color: '#C9D2BB',
          }}>{t}</span>
        ))}
      </div>

      <div style={{ font: '500 10.5px var(--font-sans)', color: '#76AB78',
                    letterSpacing: '0.14em', textTransform: 'uppercase',
                    marginTop: 4, marginBottom: 8 }}>
        Brand commitments
      </div>
      <ul style={{ margin: 0, paddingLeft: 18, color: '#C9D2BB' }}>
        <li style={{ marginBottom: 6 }}>
          Quietly confident, observational, a little literary.&nbsp;
          <i>Italic serif</i> for voice; mono for ids/counts.
        </li>
        <li style={{ marginBottom: 6 }}>
          No emoji. No left-border accent stripes. No data-viz polish.
        </li>
        <li style={{ marginBottom: 6 }}>
          Node depth encoded in color (Canopy → Moss → Dew). Sunlight
          is rare and means "this matters right now."
        </li>
        <li>
          The tree metaphor earns its place when it adds clarity; if it
          can&apos;t, drop it for a calmer treatment.
        </li>
      </ul>

      <div style={{ marginTop: 'auto', padding: 12,
                    background: '#111D0A', border: '0.5px solid #1F2B16',
                    borderRadius: 10,
                    font: 'italic 400 12px/1.55 var(--font-serif)',
                    color: '#A8C5A0' }}>
        Six directions follow. None is a finished design; they bracket
        the space from "skip the tree altogether" (A) to "lean fully
        into spatial structure" (D/F). Trade-offs on each.
      </div>
    </div>
  );
}

// Tiny inline diagram: "raw skeleton vs. roots-only" — the count-based
// argument for what Tree should focus on.
function SkeletonDelta() {
  return (
    <div style={{ display: 'flex', gap: 12, padding: '8px 0 14px' }}>
      <div style={{ flex: 1, padding: '10px', background: '#0F1A09',
                    border: '0.5px solid #1F2B16', borderRadius: 10 }}>
        <div style={{ font: '500 10px var(--font-sans)', color: '#D6BFA8',
                      letterSpacing: '0.10em', textTransform: 'uppercase',
                      marginBottom: 6 }}>Current · 332 dots</div>
        <svg width="100%" height="120" viewBox="0 0 180 120">
          {/* dense stack */}
          {Array.from({ length: 110 }).map((_, i) => {
            const r = i % 8 === 0 ? 2.2 : 1.4;
            const x = 90 + ((i * 19) % 47 - 23);
            const y = 4 + i * 1.05;
            return <circle key={i} cx={x} cy={y} r={r}
              fill="#76AB78" fillOpacity={0.5}/>;
          })}
          {Array.from({ length: 40 }).map((_, i) => {
            const a = i * 1.3;
            const x = 90 + Math.cos(a) * 38;
            const y = 8 + i * 2.6;
            return <line key={i} x1="90" y1={y} x2={x} y2={y + 4}
              stroke="#5E8048" strokeOpacity="0.2" strokeWidth="0.4"/>;
          })}
        </svg>
        <div style={{ font: 'italic 400 11px var(--font-serif)', color: '#D6BFA8',
                      marginTop: 4 }}>
          shape is hidden in the noise.
        </div>
      </div>
      <div style={{ flex: 1, padding: '10px', background: '#0F1A09',
                    border: '0.5px solid #1F2B16', borderRadius: 10 }}>
        <div style={{ font: '500 10px var(--font-sans)', color: '#76AB78',
                      letterSpacing: '0.10em', textTransform: 'uppercase',
                      marginBottom: 6 }}>Tree&apos;s job · 16 roots</div>
        <svg width="100%" height="120" viewBox="0 0 180 120">
          {/* ~16 sparse plant glyphs */}
          {Array.from({ length: 16 }).map((_, i) => {
            const x = 22 + (i % 4) * 42;
            const y = 16 + Math.floor(i / 4) * 28;
            const big = i % 3 === 0;
            return (
              <g key={i}>
                <circle cx={x} cy={y} r={big ? 8 : 5}
                  stroke="#4F8E51" strokeOpacity="0.4" strokeWidth="0.8" fill="none"/>
                <circle cx={x} cy={y} r={big ? 4 : 2.5}
                  fill={big ? '#D4960C' : '#76AB78'} fillOpacity="0.75"/>
              </g>
            );
          })}
        </svg>
        <div style={{ font: 'italic 400 11px var(--font-serif)',
                      color: '#A8C5A0', marginTop: 4 }}>
          the shape <i>is</i> the information.
        </div>
      </div>
    </div>
  );
}


// ───────────────── Note card (per-variant trade-offs) ─────────────────

function VariantNote({ title, accent, children, pros, cons }) {
  return (
    <div style={{ width: 300, height: 760, boxSizing: 'border-box',
                  padding: '22px 22px',
                  background: '#0B1306',
                  border: '0.5px solid #2D3A22', borderRadius: 14,
                  color: '#C9D2BB',
                  font: '400 13px/1.55 var(--font-sans)',
                  display: 'flex', flexDirection: 'column' }}>
      <div style={{ font: '500 10.5px var(--font-sans)', color: accent,
                    letterSpacing: '0.14em', textTransform: 'uppercase',
                    marginBottom: 10 }}>
        {title}
      </div>
      <div style={{ flex: 1, color: '#C9D2BB' }}>{children}</div>
      <div style={{ display: 'flex', gap: 14, marginTop: 14,
                    paddingTop: 14, borderTop: '0.5px solid #1F2B16' }}>
        <div style={{ flex: 1 }}>
          <div style={{ font: '500 9.5px var(--font-sans)', color: '#76AB78',
                        letterSpacing: '0.10em', textTransform: 'uppercase',
                        marginBottom: 4 }}>+ Bets on</div>
          <ul style={{ margin: 0, paddingLeft: 14,
                       font: '400 11.5px/1.5 var(--font-sans)', color: '#C9D2BB' }}>
            {pros.map((p, i) => <li key={i}>{p}</li>)}
          </ul>
        </div>
        <div style={{ flex: 1 }}>
          <div style={{ font: '500 9.5px var(--font-sans)', color: '#D6BFA8',
                        letterSpacing: '0.10em', textTransform: 'uppercase',
                        marginBottom: 4 }}>− Risks</div>
          <ul style={{ margin: 0, paddingLeft: 14,
                       font: '400 11.5px/1.5 var(--font-sans)', color: '#A39B89' }}>
            {cons.map((c, i) => <li key={i}>{c}</li>)}
          </ul>
        </div>
      </div>
    </div>
  );
}


// ───────────────── App ─────────────────

function App() {
  return (
    <DesignCanvas>

      {/* ───── 0 · Premise ───── */}
      <DCSection
        id="premise"
        title="Personal DM · Tree view"
        subtitle="The 332-node skeleton draft is clinical. Tree's job is to show conversational shape, not every dot. Six directions below."
      >
        <DCArtboard id="premise-card" label="The problem in one card"
                    width={440} height={880}>
          <PremiseCard/>
        </DCArtboard>
      </DCSection>


      {/* ───── 1 · Brainstorms ───── */}
      <DCSection
        id="brainstorms"
        title="Brainstorms · six directions"
        subtitle="Each is a complete answer to the same brief. Pick one (or mix two) to prototype. Trade-off note next to each variant."
      >
        {/* A — Chronicle */}
        <DCArtboard id="a-tree" label="A · Chronicle" width={PHONE_W} height={PHONE_H}>
          <AndroidPhone><TreeA_Chronicle/></AndroidPhone>
        </DCArtboard>
        <DCArtboard id="a-note" label="A · trade-offs" width={300} height={PHONE_H}>
          <VariantNote
            title="A · Chronicle"
            accent="#A8C5A0"
            pros={[
              'No tree-drawing — never fails at scale',
              'Italic-serif quotes feel deeply on-brand',
              'Each row is fully scannable as text',
              'Cheapest to build & test',
            ]}
            cons={[
              'Loses the "tree" feeling entirely',
              'No sense of relative size/density',
              'Risks feeling like just a list',
            ]}
          >
            <p style={{ marginTop: 0 }}>
              Drops the tree-rendering ambition and surfaces the
              <b> 16 roots</b> as a literary list: a date column, a soft
              from-dot, an italic-serif preview of the opening line, and
              a tiny &quot;branch pip&quot; row giving a sense of how
              much grew off it.
            </p>
            <p>
              Reads like a <i>chronicle</i> — an unhurried index of what
              the two of you have planted. The selected row gets a
              quiet sunlight stripe on the left.
            </p>
            <p style={{ font: 'italic 400 12.5px/1.55 var(--font-serif)',
                        color: '#A8C5A0' }}>
              The honest answer to &quot;Tree isn&apos;t the place to
              navigate the DM&quot; — make it the place to <i>remember
              it</i>.
            </p>
          </VariantNote>
        </DCArtboard>

        {/* B — Trunk */}
        <DCArtboard id="b-tree" label="B · Trunk" width={PHONE_W} height={PHONE_H}>
          <AndroidPhone><TreeB_Trunk/></AndroidPhone>
        </DCArtboard>
        <DCArtboard id="b-note" label="B · trade-offs" width={300} height={PHONE_H}>
          <VariantNote
            title="B · Trunk"
            accent="#F4DCA0"
            pros={[
              'Keeps the living-tree feeling honestly',
              'Bounded geometry: never more than ~12 spurs',
              'Alternating L/R sides = breathing rhythm',
              "Sunlight-tipped trunk reads as 'recent first'",
            ]}
            cons={[
              "From/To attribution is harder when card is right-aligned",
              'Long quotes get clipped to 2 lines',
              'Requires layout solver if any card is taller',
            ]}
          >
            <p style={{ marginTop: 0 }}>
              A single organic <b>gradient trunk</b> down the middle,
              top tipped with sunlight (most recent), fading to deep
              moss at the older end. Each root hangs off the trunk on
              alternating sides via a soft spur curve.
            </p>
            <p>
              Each root card is small — a date, an italic-serif
              fragment, and the counts. The selected root&apos;s spur
              and trunk-node are sunlight-tinted. At the bottom: faint
              mycelium dots, suggesting depth below.
            </p>
            <p style={{ font: 'italic 400 12.5px/1.55 var(--font-serif)',
                        color: '#F4DCA0' }}>
              The closest to the existing Tree draft&apos;s feeling —
              but obeying scale by only ever drawing <b>roots</b>, not
              every node.
            </p>
          </VariantNote>
        </DCArtboard>

        {/* C — Strata */}
        <DCArtboard id="c-tree" label="C · Strata" width={PHONE_W} height={PHONE_H}>
          <AndroidPhone><TreeC_Strata/></AndroidPhone>
        </DCArtboard>
        <DCArtboard id="c-note" label="C · trade-offs" width={300} height={PHONE_H}>
          <VariantNote
            title="C · Strata"
            accent="#76AB78"
            pros={[
              'Time hierarchy is information, not decoration',
              'Older years scale infinitely — they compress',
              'Depth pips give a quick read of how deep each thread went',
              'Easy to add filter UI on top later',
            ]}
            cons={[
              'Heaviest visual chrome of the six',
              'Time-bands are an editorial decision (per-DM tuning)',
              'Less "tree", more "archive"',
            ]}
          >
            <p style={{ marginTop: 0 }}>
              Honest about how memory actually works: <b>recency
              matters more</b>. Recent bands get full root cards with
              their italic-serif opener; older bands collapse into a
              row of tiny pebble chips — from-dot + opening words +
              leaf count.
            </p>
            <p>
              The bands are calm hairline dividers — &quot;today&quot;,
              &quot;this week&quot;, on down. A 2-year-old DM with
              hundreds of roots stays scannable because almost all of
              them collapse into a single line of chips.
            </p>
            <p style={{ font: 'italic 400 12.5px/1.55 var(--font-serif)',
                        color: '#76AB78' }}>
              Best at high-volume DMs (your case at 332 nodes is
              honestly mid-size). Strata scales gracefully to 10k.
            </p>
          </VariantNote>
        </DCArtboard>

        {/* D — Constellation */}
        <DCArtboard id="d-tree" label="D · Constellation" width={PHONE_W} height={PHONE_H}>
          <AndroidPhone><TreeD_Constellation/></AndroidPhone>
        </DCArtboard>
        <DCArtboard id="d-note" label="D · trade-offs" width={300} height={PHONE_H}>
          <VariantNote
            title="D · Constellation"
            accent="#D4960C"
            pros={[
              'A signature view nobody else has',
              'Brand mark (concentric rings) IS the node glyph',
              'Date anchors on the side give an absolute reference',
              'Sparse — no dot-spaghetti at any scale',
            ]}
            cons={[
              'Sub-30 root DMs may feel "empty"',
              "Spatial layout is gestural — hard to find a specific date",
              'Labels collide if many roots share x-range',
              "Doesn't auto-explain itself; needs the legend pill",
            ]}
          >
            <p style={{ marginTop: 0 }}>
              The closest evolution of the original draft, but with the
              dots replaced by <b>small brand-mark rings</b>. Core
              color = who sent it (canopy = you, dew = Marina); ring
              size = leaves; brightness = recency.
            </p>
            <p>
              Position descends with time but sways organically so it
              looks <i>grown, not plotted</i>. Date anchors run down
              the left edge as absolute reference. Labels are the
              <i>first words of the message</i> — the only honest label
              we can show — and only the selected/biggest/active roots
              wear one by default. Tap any to reveal its label.
            </p>
            <p style={{ font: 'italic 400 12.5px/1.55 var(--font-serif)',
                        color: '#F4DCA0' }}>
              Powerful when the user wants to <i>see</i> the
              conversation — &quot;oh, we&apos;ve actually talked
              about the lake five times this month.&quot;
            </p>
          </VariantNote>
        </DCArtboard>

        {/* E — Garden */}
        <DCArtboard id="e-tree" label="E · Garden" width={PHONE_W} height={PHONE_H}>
          <AndroidPhone><TreeE_Garden/></AndroidPhone>
        </DCArtboard>
        <DCArtboard id="e-note" label="E · trade-offs" width={300} height={PHONE_H}>
          <VariantNote
            title="E · Garden"
            accent="#76AB78"
            pros={[
              'Brand mark literally becomes the UI',
              'Equal weight per root — democratic',
              'Tiled grid is the easiest spatial system there is',
              'Each tile is a self-contained brand artifact',
            ]}
            cons={[
              'Sequence/time relationships are flattened within each section',
              'At 60+ roots needs aggressive month-collapse',
              "Labels are first-words: short, sometimes cryptic",
            ]}
          >
            <p style={{ marginTop: 0 }}>
              Each root is its own tiny <b>plant glyph</b> — three
              concentric brand-mark rings with a core colored by who
              sent it (canopy = you, dew = Marina) and small leaf-dots
              around the outer ring (one per branch).
            </p>
            <p>
              Tiled in a 3-wide grid <b>grouped by time band</b> with
              section headers (today / this week / this month / …).
              Older bands collapse to a single line you can grow.
              Caption beneath each tile is italic-serif — the message's
              opening words (no classifier).
            </p>
            <p style={{ font: 'italic 400 12.5px/1.55 var(--font-serif)',
                        color: '#A8C5A0' }}>
              The version where the brand mark is doing the most work.
              Beautiful, but flattens chronology.
            </p>
          </VariantNote>
        </DCArtboard>

        {/* F — Trellis */}
        <DCArtboard id="f-tree" label="F · Trellis" width={PHONE_W} height={PHONE_H}>
          <AndroidPhone><TreeF_Trellis/></AndroidPhone>
        </DCArtboard>
        <DCArtboard id="f-note" label="F · trade-offs" width={300} height={PHONE_H}>
          <VariantNote
            title="F · Trellis"
            accent="#A37145"
            pros={[
              'Time + thread are both readable at once',
              'You can see when threads ran in parallel',
              'Strand width / leaf-dots = depth at a glance',
            ]}
            cons={[
              'Most novel — needs the most onboarding',
              'Horizontal scroll has discoverability cost',
              'Strand label is short (first words only)',
              'Less obviously "ForestLynk" — could be anything',
            ]}
          >
            <p style={{ marginTop: 0 }}>
              Most experimental. Each root becomes a <b>vertical
              strand</b> running down the screen; leaf-dots along it
              mark branches at their depth. Strand colour = who
              started it; strand width = how many leaves grew.
            </p>
            <p>
              Critically: only <b>one time-window at a time</b> — a
              bottom scrubber walks you back through <i>this week →
              this month → earlier</i>. Strands never stack into the
              hundreds; the timeline does the stacking.
            </p>
            <p>
              Header labels are the first words of each message in
              italic serif (no classifier).
            </p>
            <p style={{ font: 'italic 400 12.5px/1.55 var(--font-serif)',
                        color: '#D6BFA8' }}>
              A power-user view. Worth including for contrast — and
              probably the best second-screen if Tree later gets a
              detail-mode toggle.
            </p>
          </VariantNote>
        </DCArtboard>
      </DCSection>


      {/* ───── 2 · Recommendation ───── */}
      <DCSection
        id="recommend"
        title="If I had to pick"
        subtitle="A composition, not a winner."
      >
        <DCArtboard id="rec-card" label="Recommendation" width={440} height={620}>
          <div style={{ width: 440, height: 620, boxSizing: 'border-box',
                        background: '#0B1306',
                        border: '0.5px solid #2D3A22', borderRadius: 14,
                        padding: '24px 26px',
                        font: '400 13.5px/1.6 var(--font-sans)', color: '#C9D2BB' }}>
            <div style={{ font: '500 10.5px var(--font-sans)', color: '#D4960C',
                          letterSpacing: '0.14em', textTransform: 'uppercase',
                          marginBottom: 10 }}>
              My pick
            </div>
            <p style={{ margin: '0 0 12px' }}>
              Ship <b>A (Chronicle)</b> as the default Tree view, and
              expose <b>D (Constellation)</b> behind a sub-toggle.
            </p>
            <ul style={{ margin: '0 0 14px', paddingLeft: 20 }}>
              <li style={{ marginBottom: 6 }}>
                <b>Chronicle</b> is the highest-utility, lowest-cost,
                most-on-brand answer. Reads as ForestLynk
                immediately — italic-serif voice, calm gutter, no
                spaghetti.
              </li>
              <li style={{ marginBottom: 6 }}>
                <b>Constellation</b> is the &quot;see the shape&quot;
                view people will love showing off. Behind an explicit
                toggle, not a gesture — power-users opt in.
              </li>
              <li>
                Borrow <b>Strata&apos;s time-band collapse</b> from C
                into Chronicle for DMs older than a few months:
                today/this week stay full-width cards; older auto-
                compresses to chips. Same component, two densities.
              </li>
            </ul>
            <p style={{ margin: '0 0 12px',
                        font: 'italic 400 13.5px/1.55 var(--font-serif)',
                        color: '#A8C5A0' }}>
              Trunk (B) is gorgeous but the alternating layout is
              fragile on small screens and at small DMs (~5 roots)
              feels staged. Garden (E) and Trellis (F) are second-
              release experiments — keep them on the shelf.
            </p>
            <div style={{ marginTop: 14, padding: 12, background: '#111D0A',
                          border: '0.5px solid #1F2B16', borderRadius: 10,
                          font: 'italic 400 12px/1.55 var(--font-serif)',
                          color: '#A8C5A0' }}>
              Open questions: what counts as a &quot;root&quot;? Any
              message that has a reply, or only messages that branched
              the canvas? And: should the bottom Branch CTA mirror the
              Canvas one exactly, or is it permissible to differ here?
            </div>
          </div>
        </DCArtboard>
      </DCSection>
    </DesignCanvas>
  );
}

// ─── Embed backdrop: same gradient the other brainstorm boards use,
//     sized to wrap a single AndroidPhone with a thin border visible. ───
function EmbedBackdrop({ children }) {
  return (
    <div style={{
      background: 'linear-gradient(180deg, #1A2812 0%, #0B1306 100%)',
      display: 'flex', alignItems: 'center', justifyContent: 'center',
      padding: '12px 20px', boxSizing: 'border-box',
    }}>
      {children}
    </div>
  );
}

// ─── Router: ?board=<id> renders one artboard; no param renders the
//     full DesignCanvas as the prototype was originally authored. ───
function EmbedOrApp() {
  const board = new URLSearchParams(location.search).get('board');
  switch (board) {
    case 'a-tree':
      return <EmbedBackdrop><AndroidPhone><TreeA_Chronicle/></AndroidPhone></EmbedBackdrop>;
    case 'd-tree':
      return <EmbedBackdrop><AndroidPhone><TreeD_Constellation/></AndroidPhone></EmbedBackdrop>;
    default:
      return <App/>;
  }
}

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