/* global React */
// Botanical-plate quality plants. Each fits 200×280 viewBox, crown at ~y=50, roots at y=280.
// Uses hand-tuned bezier curves, dual-tone washes, subtle stroke weight variation.

const LINE = "#2d1e12";          // warm sepia ink
const LINE_SOFT = "#4a3f35";
const LEAF_WASH = "#b8ccae";     // soft sage wash
const LEAF_WASH_2 = "#9cb692";
const LEAF_DEEP = "#6f8a66";
const SOIL_TONE = "#4a3420";
const PETAL_WASH = "#f5d4cf";
const PETAL_WASH_2 = "#edb8b2";
const BERRY = "#b83c3c";
const BERRY_DEEP = "#8a2929";
const GOLD = "#d9a85c";
const WHEAT = "#dfb768";
const LAVENDER = "#a68fc9";
const LAVENDER_DEEP = "#7e66a5";

// Reusable soft-wash SVG filter (only needs to be defined once per page)
function BotanicalDefs() {
  return (
    <defs>
      <filter id="v2-wash" x="-20%" y="-20%" width="140%" height="140%">
        <feTurbulence type="fractalNoise" baseFrequency="0.9" numOctaves="2" seed="3"/>
        <feColorMatrix values="0 0 0 0 0  0 0 0 0 0  0 0 0 0 0  0 0 0 0.08 0"/>
        <feComposite in2="SourceGraphic" operator="in"/>
        <feMerge>
          <feMergeNode in="SourceGraphic"/>
          <feMergeNode/>
        </feMerge>
      </filter>
      <radialGradient id="v2-petal-grad" cx="50%" cy="60%" r="60%">
        <stop offset="0%" stopColor="#fdebe7"/>
        <stop offset="70%" stopColor={PETAL_WASH}/>
        <stop offset="100%" stopColor={PETAL_WASH_2}/>
      </radialGradient>
      <radialGradient id="v2-leaf-grad" cx="50%" cy="40%" r="70%">
        <stop offset="0%" stopColor="#c8dbbe"/>
        <stop offset="60%" stopColor={LEAF_WASH}/>
        <stop offset="100%" stopColor={LEAF_WASH_2}/>
      </radialGradient>
      <radialGradient id="v2-berry-grad" cx="35%" cy="35%" r="70%">
        <stop offset="0%" stopColor="#e66a5e"/>
        <stop offset="60%" stopColor={BERRY}/>
        <stop offset="100%" stopColor={BERRY_DEEP}/>
      </radialGradient>
      <radialGradient id="v2-gold-grad" cx="35%" cy="35%" r="70%">
        <stop offset="0%" stopColor="#f0cd8a"/>
        <stop offset="70%" stopColor={GOLD}/>
        <stop offset="100%" stopColor="#a67d3e"/>
      </radialGradient>
      <radialGradient id="v2-lavender-grad" cx="35%" cy="35%" r="70%">
        <stop offset="0%" stopColor="#c9b5e1"/>
        <stop offset="70%" stopColor={LAVENDER}/>
        <stop offset="100%" stopColor={LAVENDER_DEEP}/>
      </radialGradient>
    </defs>
  );
}

// Progressive stroke draw
function Drawn({ d, dash = 400, grow = 1, stroke = LINE, sw = 1.3, fill = "none", delay = 0 }) {
  const off = dash * (1 - Math.max(0, Math.min(1, grow)));
  return (
    <path d={d} stroke={stroke} strokeWidth={sw} fill={fill}
      strokeLinecap="round" strokeLinejoin="round"
      strokeDasharray={dash} strokeDashoffset={off}
      style={{ transition: `stroke-dashoffset 1.1s var(--v2-ease) ${delay}ms` }}/>
  );
}

function Wash({ d, fill, grow = 1, delay = 0, opacity = 0.9 }) {
  return (
    <path d={d} fill={fill}
      style={{ opacity: grow * opacity, transition: `opacity .8s var(--v2-ease) ${delay}ms` }}/>
  );
}

// Leaf with vein detail
function BotanicalLeaf({ d, flip = false, grow = 1, delay = 0, veins = [] }) {
  return (
    <g style={{ transition: `opacity .6s var(--v2-ease) ${delay}ms`, opacity: grow }}>
      <Wash d={d} fill="url(#v2-leaf-grad)" grow={grow} delay={delay}/>
      <Drawn d={d} dash={200} grow={grow} sw={1.2} delay={delay}/>
      {veins.map((v, i) => (
        <Drawn key={i} d={v} dash={60} grow={grow} sw={0.7} stroke={LINE_SOFT} delay={delay + 100 + i*30}/>
      ))}
    </g>
  );
}

// Soil mound
function SoilMound() {
  return (
    <g>
      <ellipse cx="100" cy="274" rx="42" ry="7" fill={SOIL_TONE} opacity="0.35"/>
      <ellipse cx="100" cy="272" rx="34" ry="4" fill="#3d2a18" opacity="0.45"/>
      <path d="M70 272 C 78 268 90 270 100 268 C 110 266 122 270 130 272" stroke="#2d1a0c" strokeWidth="0.8" fill="none" opacity="0.4"/>
    </g>
  );
}

// ============= COFFEE CHERRY =============
function CoffeeCherry({ grow = 1, bloom = 0 }) {
  const g = grow, b = bloom;
  return (
    <g>
      <SoilMound/>
      {/* main stem */}
      <Drawn d="M100 272 C 98 240 102 210 99 175 C 96 140 102 110 100 75 C 99 60 100 52 100 48" dash={260} grow={g*1.1} sw={1.6}/>
      {/* leaf 1: lower left */}
      {g > 0.18 && <BotanicalLeaf
        d="M99 220 C 72 218 52 202 46 182 C 50 180 70 180 88 196 C 96 204 99 210 99 220 Z"
        veins={["M99 220 C 84 214 72 204 56 184"]}
        grow={(g - 0.18)/0.25}/>}
      {/* leaf 2: lower right */}
      {g > 0.28 && <BotanicalLeaf
        d="M100 190 C 128 188 148 170 152 148 C 148 146 128 148 114 162 C 106 170 100 180 100 190 Z"
        veins={["M100 190 C 116 182 130 170 146 150"]}
        grow={(g - 0.28)/0.25} delay={200}/>}
      {/* leaf 3: mid left */}
      {g > 0.42 && <BotanicalLeaf
        d="M99 150 C 74 148 56 128 52 108 C 56 106 76 110 90 124 C 96 130 99 140 99 150 Z"
        veins={["M99 150 C 82 140 72 130 58 112"]}
        grow={(g - 0.42)/0.25} delay={400}/>}
      {/* leaf 4: upper right */}
      {g > 0.56 && <BotanicalLeaf
        d="M100 118 C 124 118 142 102 146 82 C 140 80 122 84 110 96 C 104 102 100 110 100 118 Z"
        veins={["M100 118 C 116 108 128 98 142 82"]}
        grow={(g - 0.56)/0.25} delay={600}/>}
      {/* topmost small leaves */}
      {g > 0.72 && <>
        <BotanicalLeaf d="M99 85 C 86 82 78 72 76 62 C 82 62 92 70 99 80 Z" veins={[]} grow={(g-0.72)/0.25} delay={800}/>
        <BotanicalLeaf d="M100 75 C 112 72 120 64 122 54 C 116 54 108 62 100 70 Z" veins={[]} grow={(g-0.76)/0.25} delay={900}/>
      </>}
      {/* coffee cherries (bloom) */}
      {b > 0 && <g style={{ opacity: b, transition: "opacity .8s var(--v2-ease)" }}>
        {/* cluster at leaf junctions */}
        {[
          {x: 86, y: 200, r: 6, d: 0},
          {x: 96, y: 208, r: 7, d: 100},
          {x: 112, y: 170, r: 6, d: 200},
          {x: 108, y: 162, r: 5, d: 280},
          {x: 90, y: 130, r: 5, d: 380},
          {x: 110, y: 100, r: 6, d: 480},
        ].map((c, i) => (
          <g key={i} style={{ animation: `v2-rise .6s var(--v2-ease-spring) ${c.d}ms both` }}>
            <circle cx={c.x} cy={c.y} r={c.r} fill="url(#v2-berry-grad)" stroke={BERRY_DEEP} strokeWidth="0.6"/>
            <circle cx={c.x - c.r*0.35} cy={c.y - c.r*0.35} r={c.r*0.25} fill="rgba(255,220,200,0.7)"/>
            <path d={`M${c.x} ${c.y - c.r} L ${c.x} ${c.y - c.r - 3}`} stroke={LINE} strokeWidth="0.6" fill="none"/>
          </g>
        ))}
      </g>}
    </g>
  );
}

// ============= WHEAT STALK =============
function WheatStalk({ grow = 1, bloom = 0 }) {
  const g = grow, b = bloom;
  const grains = [];
  for (let i = 0; i < 8; i++) {
    const y = 74 + i * 11;
    const side = i % 2 ? 1 : -1;
    grains.push(
      <g key={i} style={{ opacity: b, transition: `opacity .4s var(--v2-ease) ${i*50}ms`,
        transform: `translateY(${b ? 0 : 4}px)` }}>
        <ellipse cx={100 + side*9} cy={y} rx="6" ry="10" fill={WHEAT} stroke={LINE} strokeWidth="0.9"/>
        {/* awn */}
        <path d={`M${100+side*9} ${y-10} L${100+side*14} ${y-24}`} stroke={LINE} strokeWidth="0.7" fill="none" strokeLinecap="round"/>
        <path d={`M${100+side*7} ${y-8} L${100+side*10} ${y-20}`} stroke={LINE_SOFT} strokeWidth="0.5" fill="none" opacity="0.6"/>
      </g>
    );
  }
  return (
    <g>
      <SoilMound/>
      {/* base leaves */}
      {g > 0.15 && <>
        <Drawn d="M100 268 C 86 240 78 208 82 178" dash={120} grow={(g-0.15)/0.3} sw={1.4} stroke={LEAF_DEEP}/>
        <Drawn d="M100 268 C 114 240 124 210 120 180" dash={120} grow={(g-0.2)/0.3} sw={1.4} stroke={LEAF_DEEP}/>
      </>}
      {/* main stem */}
      <Drawn d="M100 272 L 100 74" dash={200} grow={g*1.2} sw={1.6}/>
      {/* joints on stem */}
      {[200, 160, 120].map((y, i) => g > 0.4 + i*0.1 && (
        <circle key={i} cx="100" cy={y} r="1.5" fill={LINE} style={{ opacity: (g - (0.4+i*0.1))/0.2 }}/>
      ))}
      {/* head wrapper */}
      {g > 0.75 && <g>{grains}</g>}
    </g>
  );
}

// ============= LOTUS =============
function Lotus({ grow = 1, bloom = 0 }) {
  const g = grow, b = bloom;
  return (
    <g>
      {/* water lines */}
      <path d="M8 268 C 40 266 70 270 100 268 C 130 266 160 270 192 268" stroke={LINE_SOFT} strokeWidth="0.8" fill="none" opacity="0.5"/>
      <path d="M0 274 C 30 272 60 276 100 274 C 140 272 170 276 200 274" stroke={LINE_SOFT} strokeWidth="0.7" fill="none" opacity="0.3"/>
      <path d="M10 280 C 50 278 90 282 100 280 C 140 278 180 282 190 280" stroke={LINE_SOFT} strokeWidth="0.6" fill="none" opacity="0.2"/>
      {/* lily pad */}
      {g > 0.15 && <g style={{ opacity: (g-0.15)/0.3, transition: "opacity .6s var(--v2-ease)" }}>
        <ellipse cx="100" cy="266" rx="58" ry="10" fill="url(#v2-leaf-grad)" stroke={LINE} strokeWidth="1.1"/>
        <path d="M44 266 L 98 266" stroke={LINE_SOFT} strokeWidth="0.6" opacity="0.5"/>
        <path d="M156 266 L 102 266" stroke={LINE_SOFT} strokeWidth="0.6" opacity="0.5"/>
        {/* pad vein */}
        <path d="M100 258 L 100 274" stroke={LINE_SOFT} strokeWidth="0.5" opacity="0.4"/>
      </g>}
      {/* second pad behind */}
      {g > 0.3 && <g style={{ opacity: (g-0.3)/0.3 * 0.6 }}>
        <ellipse cx="70" cy="270" rx="26" ry="5" fill={LEAF_WASH_2} stroke={LINE_SOFT} strokeWidth="0.9"/>
      </g>}
      {/* stem */}
      <Drawn d="M100 266 C 99 230 101 200 100 160" dash={110} grow={g*1.2} sw={1.5}/>
      {/* lotus flower: layered petals */}
      {g > 0.55 && <g transform="translate(100 150)">
        {/* outer petals */}
        {[-72, -36, 0, 36, 72].map((rot, i) => {
          const open = 0.2 + b * 0.8;
          return (
            <g key={`o${i}`} transform={`rotate(${rot * open})`}
              style={{ transition: "transform 1.2s var(--v2-ease-spring)",
                opacity: (g-0.55)/0.25 }}>
              <path d="M0 -4 C -14 -22 -16 -58 0 -80 C 16 -58 14 -22 0 -4 Z"
                fill="url(#v2-petal-grad)" stroke={LINE} strokeWidth="1"/>
              <path d="M0 -8 L 0 -72" stroke={LINE_SOFT} strokeWidth="0.5" opacity="0.4"/>
            </g>
          );
        })}
        {/* inner petals (slightly smaller) */}
        {b > 0.3 && [-50, -18, 18, 50].map((rot, i) => (
          <g key={`i${i}`} transform={`rotate(${rot})`} style={{ opacity: (b-0.3)/0.4 }}>
            <path d="M0 0 C -10 -18 -10 -44 0 -60 C 10 -44 10 -18 0 0 Z"
              fill="#fff4f1" stroke={LINE} strokeWidth="0.9"/>
          </g>
        ))}
        {/* center */}
        <circle cx="0" cy="-4" r={3 + b*5} fill="url(#v2-gold-grad)" stroke={LINE} strokeWidth="0.8"/>
        {/* stamen dots */}
        {b > 0.5 && Array.from({ length: 8 }).map((_, i) => (
          <circle key={`s${i}`} cx={Math.cos(i * Math.PI / 4) * 4} cy={-4 + Math.sin(i * Math.PI / 4) * 4}
            r="0.8" fill={LINE} style={{ opacity: (b-0.5)/0.3 }}/>
        ))}
      </g>}
    </g>
  );
}

// ============= SUNFLOWER =============
function Sunflower({ grow = 1, bloom = 0 }) {
  const g = grow, b = bloom;
  return (
    <g>
      <SoilMound/>
      {/* thick stem */}
      <Drawn d="M100 272 L 100 80" dash={200} grow={g*1.2} sw={2.2} stroke={LEAF_DEEP}/>
      {/* hairs on stem */}
      {g > 0.5 && [220, 180, 140, 110].map((y, i) => (
        <g key={i}>
          <path d={`M100 ${y} L 97 ${y-3}`} stroke={LINE_SOFT} strokeWidth="0.5" opacity="0.5"/>
          <path d={`M100 ${y} L 103 ${y-3}`} stroke={LINE_SOFT} strokeWidth="0.5" opacity="0.5"/>
        </g>
      ))}
      {/* leaves */}
      {g > 0.3 && <BotanicalLeaf
        d="M100 210 C 70 206 50 184 46 160 C 56 158 76 170 90 188 C 96 196 100 204 100 210 Z"
        veins={["M100 210 C 82 198 72 186 56 162", "M100 210 L 72 194", "M100 210 L 82 174"]}
        grow={(g-0.3)/0.3}/>}
      {g > 0.42 && <BotanicalLeaf
        d="M100 160 C 130 158 150 138 154 114 C 144 112 124 122 112 140 C 106 148 100 154 100 160 Z"
        veins={["M100 160 C 118 150 130 138 146 116", "M100 160 L 128 144", "M100 160 L 118 128"]}
        grow={(g-0.42)/0.3} delay={200}/>}
      {/* sunflower head */}
      {b > 0 && <g transform="translate(100 70)" style={{ opacity: b, transition: "opacity .8s var(--v2-ease)" }}>
        {/* back layer of petals */}
        {Array.from({ length: 18 }).map((_, i) => (
          <g key={`b${i}`} transform={`rotate(${i*20})`}>
            <path d="M0 -14 C -5 -24 -3 -36 0 -40 C 3 -36 5 -24 0 -14 Z"
              fill="url(#v2-gold-grad)" stroke={LINE} strokeWidth="0.7"/>
          </g>
        ))}
        {/* front layer shorter petals */}
        {Array.from({ length: 14 }).map((_, i) => (
          <g key={`f${i}`} transform={`rotate(${i*25.7 + 10})`}>
            <path d="M0 -12 C -4 -20 -3 -30 0 -33 C 3 -30 4 -20 0 -12 Z"
              fill="#f0cd8a" stroke={LINE} strokeWidth="0.6"/>
          </g>
        ))}
        {/* center disk */}
        <circle cx="0" cy="0" r="13" fill="#5a3818" stroke={LINE} strokeWidth="1.2"/>
        {/* seed pattern */}
        {Array.from({ length: 24 }).map((_, i) => {
          const a = i * 137.5 * Math.PI / 180;
          const r = Math.sqrt(i) * 2.2;
          return r < 11 ? (
            <circle key={i} cx={Math.cos(a)*r} cy={Math.sin(a)*r} r="0.8" fill="#8a5a28"/>
          ) : null;
        })}
      </g>}
    </g>
  );
}

// ============= LAVENDER =============
function Lavender({ grow = 1, bloom = 0 }) {
  const g = grow, b = bloom;
  const stems = [
    { x: 78, h: 110, d: 0 },
    { x: 100, h: 145, d: 80 },
    { x: 122, h: 118, d: 160 },
    { x: 88, h: 95, d: 240 },
    { x: 112, h: 100, d: 320 }
  ];
  return (
    <g>
      <SoilMound/>
      {/* base leaves */}
      {g > 0.12 && <>
        <Drawn d="M100 272 C 80 270 68 264 58 252" dash={50} grow={(g-0.12)/0.3} sw={1.2} stroke={LEAF_DEEP}/>
        <Drawn d="M100 272 C 120 270 132 264 142 252" dash={50} grow={(g-0.15)/0.3} sw={1.2} stroke={LEAF_DEEP}/>
      </>}
      {/* stems */}
      {stems.map((s, i) => (
        <g key={i}>
          <Drawn d={`M${s.x} 272 L ${s.x} ${272 - s.h}`} dash={s.h} grow={g*1.3} sw={1.3} stroke={LEAF_DEEP} delay={s.d}/>
          {/* blossom spikes */}
          {b > 0 && <g style={{ opacity: b, transition: `opacity .6s var(--v2-ease) ${s.d}ms` }}>
            {Array.from({ length: 7 }).map((_, k) => {
              const y = 272 - s.h + 8 + k * 7;
              return (
                <g key={k}>
                  <circle cx={s.x - 2.5} cy={y} r="2" fill="url(#v2-lavender-grad)" stroke={LINE} strokeWidth="0.5"/>
                  <circle cx={s.x + 2.5} cy={y - 2} r="2" fill="url(#v2-lavender-grad)" stroke={LINE} strokeWidth="0.5"/>
                </g>
              );
            })}
          </g>}
        </g>
      ))}
    </g>
  );
}

// ============= OLIVE TREE =============
function OliveTree({ grow = 1, bloom = 0 }) {
  const g = grow, b = bloom;
  return (
    <g>
      <SoilMound/>
      {/* trunk with character */}
      <Drawn d="M100 272 C 97 232 102 200 99 168 C 96 140 102 116 100 96" dash={180} grow={g*1.2} sw={3} stroke="#6b4a2a"/>
      {/* trunk shading */}
      {g > 0.3 && <path d="M98 272 C 95 230 100 198 97 166" stroke="#4a3420" strokeWidth="1" fill="none" opacity="0.5"/>}
      {/* branches */}
      {g > 0.35 && <>
        <Drawn d="M100 190 C 86 180 70 176 58 168" dash={50} grow={(g-0.35)/0.3} sw={2} stroke="#6b4a2a" delay={200}/>
        <Drawn d="M100 160 C 114 150 128 146 140 140" dash={50} grow={(g-0.4)/0.3} sw={2} stroke="#6b4a2a" delay={300}/>
        <Drawn d="M100 130 C 88 124 78 118 72 108" dash={40} grow={(g-0.5)/0.25} sw={1.8} stroke="#6b4a2a" delay={400}/>
        <Drawn d="M100 110 C 112 104 120 96 124 84" dash={40} grow={(g-0.55)/0.25} sw={1.8} stroke="#6b4a2a" delay={500}/>
      </>}
      {/* silver-green olive foliage */}
      {b > 0 && <g style={{ opacity: b, transition: "opacity .8s var(--v2-ease)" }}>
        {[
          { cx: 56, cy: 166, r: 22 },
          { cx: 142, cy: 138, r: 24 },
          { cx: 70, cy: 104, r: 20 },
          { cx: 124, cy: 80, r: 22 },
          { cx: 100, cy: 70, r: 24 },
          { cx: 100, cy: 140, r: 18 }
        ].map((c, i) => (
          <g key={i}>
            <circle cx={c.cx} cy={c.cy} r={c.r} fill="url(#v2-leaf-grad)" stroke={LINE_SOFT} strokeWidth="0.8" opacity="0.85"/>
            {/* olives */}
            {Array.from({ length: 3 }).map((_, k) => (
              <ellipse key={k} cx={c.cx + Math.cos(k*2)*c.r*0.5} cy={c.cy + Math.sin(k*2)*c.r*0.5}
                rx="2" ry="3" fill="#4a5a3a" stroke={LINE} strokeWidth="0.5"/>
            ))}
          </g>
        ))}
      </g>}
    </g>
  );
}

// ============= MINT SPRIG =============
function MintSprig({ grow = 1, bloom = 0 }) {
  const g = grow, b = bloom;
  return (
    <g>
      <SoilMound/>
      <Drawn d="M100 272 C 99 240 101 200 99 160 C 97 120 101 80 100 56" dash={230} grow={g*1.2} sw={1.3}/>
      {/* mint leaf pairs (opposite arrangement) */}
      {[
        { y: 220, l: 48, r: 152 },
        { y: 170, l: 50, r: 150 },
        { y: 120, l: 56, r: 144 },
        { y: 78, l: 64, r: 136 }
      ].map((p, i) => g > 0.2 + i*0.15 && (
        <g key={i}>
          <BotanicalLeaf
            d={`M100 ${p.y} C ${p.l+8} ${p.y-4} ${p.l} ${p.y-16} ${p.l+6} ${p.y-30} C ${p.l+22} ${p.y-26} 92 ${p.y-8} 100 ${p.y} Z`}
            veins={[`M100 ${p.y} L ${p.l+10} ${p.y-22}`]}
            grow={(g - (0.2+i*0.15))/0.2} delay={i*150}/>
          <BotanicalLeaf
            d={`M100 ${p.y} C ${p.r-8} ${p.y-4} ${p.r} ${p.y-16} ${p.r-6} ${p.y-30} C ${p.r-22} ${p.y-26} 108 ${p.y-8} 100 ${p.y} Z`}
            veins={[`M100 ${p.y} L ${p.r-10} ${p.y-22}`]}
            grow={(g - (0.2+i*0.15))/0.2} delay={i*150 + 60}/>
        </g>
      ))}
      {/* tiny white flower clusters */}
      {b > 0 && <g style={{ opacity: b }}>
        {[70, 50, 40].map((y, i) => (
          <g key={i}>
            {Array.from({length: 5}).map((_,k)=>(
              <circle key={k} cx={100 + (k-2)*3} cy={y} r="1.4" fill="#fdf0e4" stroke={LINE} strokeWidth="0.5"/>
            ))}
          </g>
        ))}
      </g>}
    </g>
  );
}

// ============= FIG BRANCH =============
function FigBranch({ grow = 1, bloom = 0 }) {
  const g = grow, b = bloom;
  return (
    <g>
      <SoilMound/>
      <Drawn d="M100 272 C 98 236 104 200 100 162 C 96 130 102 100 100 72" dash={220} grow={g*1.2} sw={2}/>
      {/* branches */}
      {g > 0.4 && <>
        <Drawn d="M100 190 C 82 180 70 172 58 158" dash={50} grow={(g-0.4)/0.2} sw={1.4} delay={150}/>
        <Drawn d="M100 150 C 118 142 130 134 140 120" dash={50} grow={(g-0.45)/0.2} sw={1.4} delay={250}/>
      </>}
      {/* fig leaves — lobed shape */}
      {g > 0.55 && <>
        <g style={{ opacity: (g-0.55)/0.25 }}>
          <path d="M58 158 C 38 158 26 146 20 130 C 28 122 42 122 54 130 C 56 118 66 112 74 118 C 70 128 74 140 82 138 C 80 150 70 160 58 158 Z"
            fill="url(#v2-leaf-grad)" stroke={LINE} strokeWidth="1"/>
        </g>
        <g style={{ opacity: (g-0.6)/0.25 }}>
          <path d="M140 120 C 160 120 172 108 178 92 C 170 84 156 84 144 92 C 142 80 132 74 124 80 C 128 90 124 102 116 100 C 118 112 128 122 140 120 Z"
            fill="url(#v2-leaf-grad)" stroke={LINE} strokeWidth="1"/>
        </g>
      </>}
      {/* top fig leaf */}
      {g > 0.7 && <g style={{ opacity: (g-0.7)/0.2 }}>
        <path d="M100 72 C 86 64 74 52 72 36 C 82 28 92 32 100 42 C 108 32 118 28 128 36 C 126 52 114 64 100 72 Z"
          fill="url(#v2-leaf-grad)" stroke={LINE} strokeWidth="1"/>
      </g>}
      {/* figs */}
      {b > 0 && <g style={{ opacity: b }}>
        {[
          {x:90, y:200, r:7},
          {x:108, y:168, r:6},
          {x:82, y:142, r:5}
        ].map((f, i) => (
          <g key={i}>
            <ellipse cx={f.x} cy={f.y} rx={f.r} ry={f.r*1.15} fill="#6b3a5e" stroke={LINE} strokeWidth="0.7"/>
            <ellipse cx={f.x - f.r*0.3} cy={f.y - f.r*0.4} rx={f.r*0.3} ry={f.r*0.2} fill="rgba(255,220,230,0.4)"/>
            <path d={`M${f.x} ${f.y-f.r} L ${f.x} ${f.y-f.r-3}`} stroke={LINE} strokeWidth="0.6"/>
          </g>
        ))}
      </g>}
    </g>
  );
}

// ============= OAK =============
function OakTree({ grow = 1, bloom = 0 }) {
  const g = grow, b = bloom;
  return (
    <g>
      <SoilMound/>
      {/* massive trunk */}
      <Drawn d="M100 272 C 96 238 102 204 98 170 C 94 140 100 118 100 106" dash={170} grow={g*1.2} sw={3.5} stroke="#6b4a2a"/>
      <path d="M96 272 C 92 238 98 204 94 170" stroke="#4a3420" strokeWidth="1.2" fill="none" opacity="0.5"/>
      {/* branches spread wide */}
      {g > 0.35 && <>
        <Drawn d="M100 160 C 80 150 60 140 44 124" dash={60} grow={(g-0.35)/0.3} sw={2.2} stroke="#6b4a2a" delay={200}/>
        <Drawn d="M100 150 C 122 138 144 130 160 116" dash={60} grow={(g-0.4)/0.3} sw={2.2} stroke="#6b4a2a" delay={300}/>
        <Drawn d="M100 130 C 84 118 72 102 66 86" dash={50} grow={(g-0.5)/0.25} sw={1.8} stroke="#6b4a2a" delay={400}/>
        <Drawn d="M100 120 C 118 108 128 92 134 76" dash={50} grow={(g-0.55)/0.25} sw={1.8} stroke="#6b4a2a" delay={500}/>
      </>}
      {/* canopy — clustered circles */}
      {b > 0 && <g style={{ opacity: b }}>
        {[
          { cx: 44, cy: 122, r: 28 },
          { cx: 100, cy: 80, r: 36 },
          { cx: 160, cy: 116, r: 30 },
          { cx: 66, cy: 84, r: 24 },
          { cx: 134, cy: 74, r: 26 },
          { cx: 100, cy: 130, r: 22 }
        ].map((c, i) => (
          <circle key={i} cx={c.cx} cy={c.cy} r={c.r}
            fill="url(#v2-leaf-grad)" stroke={LINE_SOFT} strokeWidth="1" opacity="0.9"
            style={{ animation: `v2-rise .6s var(--v2-ease-spring) ${i*100}ms both` }}/>
        ))}
        {/* acorns */}
        {[{x:80,y:130},{x:120,y:132},{x:100,y:120}].map((a, i) => (
          <g key={`a${i}`}>
            <ellipse cx={a.x} cy={a.y} rx="3" ry="4" fill="#a87642" stroke={LINE} strokeWidth="0.6"/>
            <path d={`M${a.x-3} ${a.y-3} L ${a.x+3} ${a.y-3} L ${a.x+2.5} ${a.y-1} L ${a.x-2.5} ${a.y-1} Z`}
              fill="#6b4a2a" stroke={LINE} strokeWidth="0.5"/>
          </g>
        ))}
      </g>}
    </g>
  );
}

// Map
const SPECIES = {
  "Coffee shop":  { C: CoffeeCherry, label: "Coffee cherry", latin: "Coffea arabica",   widget: "order",   q: "any oat-milk lattes near me?" },
  "Bakery":       { C: WheatStalk,   label: "Wheat stalk",   latin: "Triticum aestivum", widget: "order",   q: "sourdough today?" },
  "Yoga studio":  { C: Lotus,        label: "Sacred lotus",  latin: "Nelumbo nucifera",  widget: "booking", q: "next beginner class?" },
  "Restaurant":   { C: OliveTree,    label: "Olive",         latin: "Olea europaea",     widget: "booking", q: "table for 2 tonight?" },
  "Dentist":      { C: MintSprig,    label: "Peppermint",    latin: "Mentha piperita",   widget: "booking", q: "cleaning this week?" },
  "Law firm":     { C: MintSprig,    label: "Bay laurel",    latin: "Laurus nobilis",    widget: "booking", q: "15-min consult?" },
  "Consultant":   { C: Lavender,     label: "Lavender",      latin: "Lavandula",         widget: "booking", q: "book 30 min?" },
  "Creator":      { C: Sunflower,    label: "Sunflower",     latin: "Helianthus annuus", widget: "product", q: "what's new this week?" },
  "Online store": { C: FigBranch,    label: "Fig",           latin: "Ficus carica",      widget: "product", q: "what should I get?" },
  "Real estate":  { C: OakTree,      label: "English oak",   latin: "Quercus robur",     widget: "product", q: "anything under 700k?" },
  "Other":        { C: GenericSprout, label: "Seedling",      latin: "Plantae",            widget: "booking", q: "how can I help you today?" }
};

Object.assign(window, { SPECIES, BotanicalDefs,
  CoffeeCherry, WheatStalk, Lotus, Sunflower, Lavender, OliveTree, MintSprig, FigBranch, OakTree,
  GenericSprout });

// Fallback pre-species sprout
function GenericSprout({ grow = 1, bloom = 0 }) {
  return (
    <g>
      <ellipse cx="100" cy="274" rx="30" ry="5" fill={SOIL_TONE} opacity="0.35"/>
      <Drawn d="M100 272 C 100 240 100 200 100 160" dash={120} grow={grow} sw={1.6}/>
      {grow > 0.4 && <BotanicalLeaf d="M100 200 C 82 198 68 186 66 170 C 78 168 92 180 100 196 Z" veins={[]} grow={(grow-0.4)/0.3}/>}
      {grow > 0.55 && <BotanicalLeaf d="M100 180 C 118 178 130 168 134 150 C 122 150 108 162 100 176 Z" veins={[]} grow={(grow-0.55)/0.3}/>}
    </g>
  );
}
