/* global React */

// ---------------------------------------------------------------
// boat-heart-anim.jsx — Cambridge Ark brand mark in motion.
//
// BoatHeartAnim  — original (kept for reference)
// BoatHeartAnimB — Sailing Dinghy: realistic single-sail dinghy
// BoatHeartAnimC — Classic Sloop:  elegant two-sail yacht, tiny heart
// BoatHeartAnimD — Cambridge Punt: flat punt with pole, small heart
// ---------------------------------------------------------------

// ── Shared keyframes ──────────────────────────────────────────
const SHARED_CSS = `
  @keyframes ca-rock    { 0%,100% { transform: translateY(0) rotate(-1.5deg);} 50% { transform: translateY(-4px) rotate(1.5deg);} }
  @keyframes ca-rock-s  { 0%,100% { transform: translateY(0) rotate(-1deg);}  50% { transform: translateY(-3px) rotate(1deg);} }
  @keyframes ca-drift   { 0%,100% { transform: translateX(0) translateY(0);}  50% { transform: translateX(6px) translateY(-2px);} }
  @keyframes ca-bob     { 0%,100% { transform: translateY(0);}  50% { transform: translateY(-5px);} }
  @keyframes ca-pulse   { 0%,100% { transform: scale(1);}       50% { transform: scale(1.06);} }
  @keyframes ca-sail    { 0%,100% { transform: skewX(0deg);}    50% { transform: skewX(-1.5deg);} }
  @keyframes ca-w1 { 0% {transform:translateX(0);}  100% {transform:translateX(-160px);} }
  @keyframes ca-w2 { 0% {transform:translateX(0);}  100% {transform:translateX(-200px);} }
  @keyframes ca-w3 { 0% {transform:translateX(0);}  100% {transform:translateX(-120px);} }
  @keyframes ca-glow  { 0%,100% { opacity:.45;} 50%{ opacity:.75;} }
  @keyframes ca-shimmer { 0%,100% { opacity:.18;} 50% { opacity:.32;} }
  .ca-boat   { animation: ca-rock   5.5s ease-in-out infinite; transform-origin: 50% 95%; }
  .ca-boat-s { animation: ca-rock-s 6.2s ease-in-out infinite; transform-origin: 50% 95%; }
  .ca-punt   { animation: ca-drift  7s   ease-in-out infinite; }
  .ca-heart  { animation: ca-bob    4.2s ease-in-out infinite; transform-origin: 50% 80%; }
  .ca-heart-inner { animation: ca-pulse 2.8s ease-in-out infinite; transform-origin: 50% 50%; }
  .ca-sail   { animation: ca-sail   4.8s ease-in-out infinite; transform-origin: 0% 100%; }
  .ca-w1 { animation: ca-w1 14s linear infinite; }
  .ca-w2 { animation: ca-w2 22s linear infinite; }
  .ca-w3 { animation: ca-w3 32s linear infinite; }
  .ca-glow { animation: ca-glow 3.2s ease-in-out infinite; }
  .ca-shimmer { animation: ca-shimmer 4s ease-in-out infinite; }
  @media (prefers-reduced-motion: reduce) {
    .ca-boat,.ca-boat-s,.ca-punt,.ca-heart,.ca-heart-inner,.ca-sail,
    .ca-w1,.ca-w2,.ca-w3,.ca-glow,.ca-shimmer { animation: none !important; }
  }
`;

// ── Shared water section ──────────────────────────────────────
function Water({ y = 390, twilight = false }) {
  const navyStroke = twilight ? "#6f8da6" : "#1d567c";
  const midStroke  = twilight ? "#eb9a85" : "#003f65";
  const nearStroke = twilight ? "#fdfaf3" : "#003f65";
  return (
    <>
      <defs>
        <linearGradient id="caWater2" x1="0" x2="0" y1="0" y2="1">
          <stop offset="0%"   stopColor="#003f65" stopOpacity={twilight ? "0.28" : "0.18"}/>
          <stop offset="100%" stopColor="#003f65" stopOpacity={twilight ? "0.65" : "0.48"}/>
        </linearGradient>
        <clipPath id="caWaterClip2"><rect x="0" y={y} width="600" height={600 - y}/></clipPath>
      </defs>
      <g clipPath="url(#caWaterClip2)">
        <rect x="0" y={y} width="600" height={600 - y} fill="url(#caWater2)" opacity={twilight ? "0.9" : "0.6"}/>
        {/* shimmer highlight */}
        <rect className="ca-shimmer" x="80" y={y + 8} width="120" height="6" rx="3" fill="white"/>
        <rect className="ca-shimmer" x="350" y={y + 14} width="80" height="4" rx="2" fill="white" style={{animationDelay:"1.4s"}}/>
        {/* far waves */}
        <g className="ca-w1" opacity={twilight ? "0.55" : "0.4"}>
          {[0,160,320,480,640].map(x => (
            <path key={x} d={`M${x} ${y+38} q 40-10 80 0 t 80 0`} stroke={navyStroke} strokeWidth="1.4" fill="none" strokeLinecap="round"/>
          ))}
        </g>
        {/* mid waves */}
        <g className="ca-w2" opacity={twilight ? "0.7" : "0.5"}>
          {[0,200,400,600,800].map(x => (
            <path key={x} d={`M${x} ${y+78} q 50-13 100 0 t 100 0`} stroke={midStroke} strokeWidth="1.7" fill="none" strokeLinecap="round" opacity=".7"/>
          ))}
        </g>
        {/* near waves */}
        <g className="ca-w3" opacity={twilight ? "0.85" : "0.65"}>
          {[0,120,240,360,480,600,720].map(x => (
            <path key={x} d={`M${x} ${y+128} q 30-15 60 0 t 60 0`} stroke={nearStroke} strokeWidth="2" fill="none" strokeLinecap="round"/>
          ))}
        </g>
      </g>
      {/* horizon */}
      <line x1="0" y1={y+6} x2="600" y2={y+6} stroke={twilight ? "rgba(253,250,243,.15)" : "rgba(0,63,101,.1)"} strokeWidth="1"/>
    </>
  );
}

// ── Small heart (used by all new variants) ────────────────────
// cx/cy = center-bottom tip. w = half-width.
function SmallHeart({ cx = 300, cy = 165, w = 28, fill = "var(--coral)", stroke = "var(--coral-deep)" }) {
  // cubic-bezier heart drawn from the bottom tip upward
  const h = w * 0.92;
  return (
    <path
      d={`M${cx} ${cy}
         C ${cx-2} ${cy-h*0.3}, ${cx-w} ${cy-h*0.55}, ${cx-w} ${cy-h*0.78}
         C ${cx-w} ${cy-h*1.08}, ${cx-w*0.5} ${cy-h*1.22}, ${cx} ${cy-h*0.95}
         C ${cx+w*0.5} ${cy-h*1.22}, ${cx+w} ${cy-h*1.08}, ${cx+w} ${cy-h*0.78}
         C ${cx+w} ${cy-h*0.55}, ${cx+2} ${cy-h*0.3}, ${cx} ${cy} Z`}
      fill={fill}
      stroke={stroke}
      strokeWidth="1.5"
      strokeLinejoin="round"
    />
  );
}

// ── Glow halo ─────────────────────────────────────────────────
function Halo({ cx = 300, cy = 200, r = 110, twilight = false }) {
  const id = `caHalo${twilight ? "N" : "D"}2`;
  return (
    <>
      <defs>
        <radialGradient id={id} cx="50%" cy="50%" r="50%">
          <stop offset="0%"   stopColor={twilight ? "#eb9a85" : "#fbe7df"} stopOpacity={twilight ? "0.6" : "0.9"}/>
          <stop offset="55%"  stopColor={twilight ? "#eb9a85" : "#fbe7df"} stopOpacity={twilight ? "0.2" : "0.35"}/>
          <stop offset="100%" stopColor={twilight ? "#eb9a85" : "#fbe7df"} stopOpacity="0"/>
        </radialGradient>
      </defs>
      <circle className="ca-glow" cx={cx} cy={cy} r={r} fill={`url(#${id})`}/>
    </>
  );
}

// ================================================================
// VARIANT B — Sailing Dinghy
// Realistic wooden dinghy: flat-plan hull, triangular mainsail,
// boom, tiller, small floating heart above masthead.
// ================================================================
function BoatHeartAnimB({ size = 520, mood = "day" }) {
  const tw = mood === "twilight";
  const hullFill   = tw ? "#1d567c" : "var(--ink-navy)";
  const hullStroke = tw ? "#003f65" : "#002940";
  const deckFill   = tw ? "#2a6a8a" : "#1a4f72";
  const sailFill   = tw ? "rgba(253,250,243,.92)" : "rgba(253,250,243,.96)";
  const sailStroke = tw ? "rgba(253,250,243,.4)" : "rgba(0,63,101,.18)";
  const accentLine = tw ? "var(--coral)" : "var(--coral-soft)";

  return (
    <div style={{ position:"relative", width:"100%", maxWidth:size, aspectRatio:"1/1", margin:"0 auto" }}>
      <style>{SHARED_CSS}</style>
      <svg viewBox="0 0 600 600" width="100%" height="100%" style={{ display:"block", overflow:"visible" }}>

        <Halo cx={300} cy={200} r={100} twilight={tw}/>

        {/* heart + wisp */}
        <g className="ca-heart">
          <g className="ca-heart-inner">
            <SmallHeart cx={300} cy={175} w={26}
              fill={tw ? "var(--coral)" : "var(--coral)"}
              stroke="var(--coral-deep)"/>
          </g>
        </g>
        <path d="M300 178 C 298 200, 302 215, 300 240" stroke="var(--coral-deep)"
          strokeWidth="1.2" strokeDasharray="2 5" fill="none" opacity=".3" strokeLinecap="round"/>

        {/* boat group */}
        <g className="ca-boat">
          {/* mast */}
          <line x1="300" y1="248" x2="300" y2="385" stroke={hullFill} strokeWidth="3.5" strokeLinecap="round"/>
          {/* forestay (rigging line from masthead to bow) */}
          <line x1="300" y1="252" x2="210" y2="383" stroke={hullFill} strokeWidth="1" opacity=".45" strokeLinecap="round"/>
          {/* mainsail — filled triangle with slight belly */}
          <g className="ca-sail">
            <path
              d={`M300 255 C 320 285, 395 340, 420 382 L 300 382 Z`}
              fill={sailFill} stroke={sailStroke} strokeWidth="1.5"
            />
            {/* sail batten lines */}
            <line x1="300" y1="295" x2="370" y2="290" stroke={sailStroke} strokeWidth=".8" opacity=".6"/>
            <line x1="300" y1="322" x2="390" y2="316" stroke={sailStroke} strokeWidth=".8" opacity=".6"/>
            <line x1="300" y1="350" x2="405" y2="344" stroke={sailStroke} strokeWidth=".8" opacity=".6"/>
          </g>
          {/* boom */}
          <line x1="300" y1="382" x2="432" y2="374" stroke={hullFill} strokeWidth="2.5" strokeLinecap="round"/>

          {/* hull — realistic dinghy profile */}
          {/* outer hull */}
          <path
            d={`M202 388
               C 210 388, 220 392, 300 396
               C 380 392, 390 388, 398 388
               L 420 380
               C 400 366, 380 360, 300 358
               C 220 360, 200 366, 180 380 Z`}
            fill={deckFill} stroke={hullStroke} strokeWidth="1.5"
          />
          {/* hull side below waterline */}
          <path
            d={`M185 382 Q 300 416 415 382
               L 405 398 Q 300 435 195 398 Z`}
            fill={hullFill} stroke={hullStroke} strokeWidth="1.5"
          />
          {/* waterline accent */}
          <path d={`M195 396 Q 300 432 405 396`}
            stroke={accentLine} strokeWidth="2" fill="none" strokeLinecap="round" opacity=".7"/>
          {/* deck detail — cockpit recess */}
          <ellipse cx="300" cy="374" rx="62" ry="9"
            fill={hullFill} opacity=".55"/>
          {/* tiller */}
          <line x1="390" y1="374" x2="370" y2="384" stroke={hullFill} strokeWidth="2" strokeLinecap="round" opacity=".7"/>
          {/* planking lines */}
          <path d={`M210 388 Q 300 392 390 388`} stroke={accentLine} strokeWidth=".8" fill="none" opacity=".35"/>
          <path d={`M200 384 Q 300 389 400 384`} stroke={accentLine} strokeWidth=".8" fill="none" opacity=".25"/>
        </g>

        <Water y={400} twilight={tw}/>
      </svg>
    </div>
  );
}

// ================================================================
// VARIANT C — Classic Sloop
// Elegant cruising yacht: deep keel, cabin top, mainsail + jib,
// shrouds, very small delicate heart at masthead.
// ================================================================
function BoatHeartAnimC({ size = 520, mood = "day" }) {
  const tw = mood === "twilight";
  const hullFill   = tw ? "#1d567c" : "var(--ink-navy)";
  const hullStroke = tw ? "#002940" : "#002940";
  const cabinFill  = tw ? "#2a6a8a" : "#1a4f72";
  const sailFill   = tw ? "rgba(253,250,243,.9)"  : "rgba(253,250,243,.97)";
  const sailStroke = tw ? "rgba(253,250,243,.35)" : "rgba(0,63,101,.14)";
  const ropeLine   = tw ? "rgba(253,250,243,.3)"  : "rgba(0,63,101,.25)";
  const accentLine = tw ? "var(--coral-soft)"     : "var(--coral-soft)";

  return (
    <div style={{ position:"relative", width:"100%", maxWidth:size, aspectRatio:"1/1", margin:"0 auto" }}>
      <style>{SHARED_CSS}</style>
      <svg viewBox="0 0 600 600" width="100%" height="100%" style={{ display:"block", overflow:"visible" }}>

        <Halo cx={300} cy={185} r={90} twilight={tw}/>

        {/* tiny heart at masthead */}
        <g className="ca-heart">
          <g className="ca-heart-inner">
            <SmallHeart cx={295} cy={168} w={20}
              fill="var(--coral)" stroke="var(--coral-deep)"/>
          </g>
        </g>

        {/* yacht group */}
        <g className="ca-boat-s" style={{animation:"ca-rock-s 6.2s ease-in-out infinite", transformOrigin:"50% 95%"}}>

          {/* mast */}
          <line x1="295" y1="172" x2="295" y2="388" stroke={hullFill} strokeWidth="3" strokeLinecap="round"/>

          {/* shrouds (standing rigging) */}
          <line x1="295" y1="220" x2="240" y2="375" stroke={ropeLine} strokeWidth="1" strokeLinecap="round"/>
          <line x1="295" y1="220" x2="350" y2="375" stroke={ropeLine} strokeWidth="1" strokeLinecap="round"/>
          {/* forestay */}
          <line x1="295" y1="176" x2="192" y2="375" stroke={ropeLine} strokeWidth="1" strokeLinecap="round"/>

          {/* jib (foresail) */}
          <g className="ca-sail">
            <path d={`M295 182 C 265 220, 205 310, 192 375 L 295 375 Z`}
              fill={sailFill} stroke={sailStroke} strokeWidth="1.2" opacity=".88"/>
          </g>

          {/* mainsail */}
          <g className="ca-sail" style={{animationDelay:".6s"}}>
            <path d={`M295 178 C 322 230, 390 320, 415 375 L 295 375 Z`}
              fill={sailFill} stroke={sailStroke} strokeWidth="1.5"/>
            {/* batten pockets */}
            {[260,305,345].map((y,i) => (
              <line key={i} x1="295" y1={y} x2={295 + (y-178)*0.44} y2={y-2}
                stroke={sailStroke} strokeWidth=".7" opacity=".7"/>
            ))}
          </g>

          {/* boom */}
          <line x1="295" y1="375" x2="430" y2="362" stroke={hullFill} strokeWidth="2.5" strokeLinecap="round"/>
          {/* boom vang */}
          <line x1="295" y1="388" x2="350" y2="368" stroke={ropeLine} strokeWidth="1" strokeLinecap="round"/>

          {/* hull — elegant sloop profile */}
          {/* main hull body */}
          <path
            d={`M165 378
               C 175 368, 210 358, 295 356
               C 365 356, 405 364, 430 374
               L 435 382 L 160 382 Z`}
            fill={cabinFill} stroke={hullStroke} strokeWidth="1.5"
          />
          {/* hull underbody */}
          <path
            d={`M165 380 Q 295 418 435 380 L 425 395 Q 295 438 175 395 Z`}
            fill={hullFill} stroke={hullStroke} strokeWidth="1.5"
          />
          {/* keel */}
          <path d={`M285 418 L 278 448 L 315 448 L 308 418 Z`}
            fill={hullFill} stroke={hullStroke} strokeWidth="1.5"/>

          {/* cabin top */}
          <rect x="255" y="356" width="90" height="22" rx="5"
            fill={cabinFill} stroke={hullStroke} strokeWidth="1.5"/>
          {/* cabin windows */}
          <rect x="264" y="361" width="20" height="12" rx="3" fill="rgba(253,250,243,.18)" stroke={ropeLine} strokeWidth="1"/>
          <rect x="298" y="361" width="20" height="12" rx="3" fill="rgba(253,250,243,.18)" stroke={ropeLine} strokeWidth="1"/>
          <rect x="332" y="361" width="14" height="12" rx="3" fill="rgba(253,250,243,.18)" stroke={ropeLine} strokeWidth="1"/>

          {/* waterline stripe */}
          <path d={`M175 394 Q 295 434 425 394`}
            stroke={accentLine} strokeWidth="2.2" fill="none" strokeLinecap="round" opacity=".75"/>
          {/* boot stripe */}
          <path d={`M170 382 Q 295 420 432 382`}
            stroke="rgba(255,255,255,.15)" strokeWidth="1.2" fill="none" strokeLinecap="round"/>
        </g>

        <Water y={395} twilight={tw}/>
      </svg>
    </div>
  );
}

// ================================================================
// VARIANT D — Cambridge Punt
// Distinctly Cambridge: long flat-bottomed punt, wooden planks,
// vertical pole at stern, small heart tied to the top of the pole.
// Drifts lazily side to side instead of rocking.
// ================================================================
function BoatHeartAnimD({ size = 520, mood = "day" }) {
  const tw = mood === "twilight";
  const hullFill   = tw ? "#1d567c"            : "var(--ink-navy)";
  const hullStroke = tw ? "#002940"            : "#002940";
  const woodLight  = tw ? "#2a6a8a"            : "#1a4f72";
  const woodDark   = tw ? "#003f65"            : "#002d50";
  const accentLine = tw ? "var(--coral-soft)"  : "var(--coral-soft)";
  const poleColor  = tw ? "#2a6a8a"            : "#1d567c";

  return (
    <div style={{ position:"relative", width:"100%", maxWidth:size, aspectRatio:"1/1", margin:"0 auto" }}>
      <style>{SHARED_CSS}</style>
      <svg viewBox="0 0 600 600" width="100%" height="100%" style={{ display:"block", overflow:"visible" }}>

        <Halo cx={390} cy={225} r={85} twilight={tw}/>

        {/* punt drifts as a whole */}
        <g className="ca-punt">

          {/* pole — at stern right side */}
          <line x1="405" y1="170" x2="405" y2="400" stroke={poleColor} strokeWidth="4" strokeLinecap="round"/>
          {/* pole grip wrap */}
          {[200,220,240].map(y => (
            <line key={y} x1="402" y1={y} x2="408" y2={y} stroke={accentLine} strokeWidth="2.5" strokeLinecap="round" opacity=".6"/>
          ))}

          {/* heart on top of pole */}
          <g className="ca-heart">
            <g className="ca-heart-inner">
              <SmallHeart cx={405} cy={197} w={24}
                fill="var(--coral)" stroke="var(--coral-deep)"/>
            </g>
          </g>
          {/* ribbon from heart to pole tip */}
          <path d="M405 200 C 407 208, 405 215, 405 220"
            stroke="var(--coral-deep)" strokeWidth="1.2" fill="none" opacity=".4" strokeLinecap="round"/>

          {/* punt hull — long and flat */}
          {/* upper deck / gunwale */}
          <path
            d={`M148 385
               C 155 372, 170 365, 430 365
               C 448 365, 458 372, 462 385 Z`}
            fill={woodLight} stroke={hullStroke} strokeWidth="1.5"
          />
          {/* hull underbody */}
          <path
            d={`M148 385 L 462 385 L 455 404 Q 305 415 150 404 Z`}
            fill={hullFill} stroke={hullStroke} strokeWidth="1.5"
          />
          {/* flat punt bottom */}
          <path
            d={`M150 403 Q 305 413 455 403 L 455 408 Q 305 420 150 408 Z`}
            fill={woodDark} stroke={hullStroke} strokeWidth="1"
          />
          {/* waterline accent stripe */}
          <path d={`M152 404 Q 305 415 454 404`}
            stroke={accentLine} strokeWidth="2" fill="none" strokeLinecap="round" opacity=".7"/>

          {/* deck planking — horizontal lines */}
          {[372, 376, 380].map(y => (
            <path key={y} d={`M162 ${y} Q 305 ${y+2} 450 ${y}`}
              stroke={hullStroke} strokeWidth=".9" fill="none" opacity=".35"/>
          ))}

          {/* thwarts (cross-seats) */}
          {[220, 300, 365].map(x => (
            <g key={x}>
              <rect x={x} y="368" width="38" height="8" rx="3"
                fill={woodLight} stroke={hullStroke} strokeWidth="1.2"/>
            </g>
          ))}

          {/* bow and stern decoration */}
          <path d={`M148 378 C 148 372, 152 368, 158 365`}
            stroke={accentLine} strokeWidth="2" fill="none" strokeLinecap="round" opacity=".5"/>
          <path d={`M462 378 C 462 372, 458 368, 452 365`}
            stroke={accentLine} strokeWidth="2" fill="none" strokeLinecap="round" opacity=".5"/>
        </g>

        <Water y={408} twilight={tw}/>
      </svg>
    </div>
  );
}

// ================================================================
// ORIGINAL — preserved unchanged
// ================================================================
function BoatHeartAnim({ size = 520, mood = "day" }) {
  const isTwilight = mood === "twilight";
  return (
    <div style={{ position:"relative", width:"100%", maxWidth:size, aspectRatio:"1/1", margin:"0 auto" }}>
      <style>{`
        @keyframes ca-rock  { 0%,100%{transform:translateY(0) rotate(-2deg);}  50%{transform:translateY(-3px) rotate(2deg);} }
        @keyframes ca-bob   { 0%,100%{transform:translateY(0);}                50%{transform:translateY(-6px);} }
        @keyframes ca-pulse { 0%,100%{transform:scale(1);}                     50%{transform:scale(1.04);} }
        @keyframes ca-w1    { 0%{transform:translateX(0);}  100%{transform:translateX(-160px);} }
        @keyframes ca-w2    { 0%{transform:translateX(0);}  100%{transform:translateX(-200px);} }
        @keyframes ca-w3    { 0%{transform:translateX(0);}  100%{transform:translateX(-120px);} }
        @keyframes ca-glow  { 0%,100%{opacity:.55;}         50%{opacity:.85;} }
        .ca-boat        { animation: ca-rock  5.5s ease-in-out infinite; transform-origin:50% 90%; }
        .ca-heart       { animation: ca-bob   4.2s ease-in-out infinite; transform-origin:50% 80%; }
        .ca-heart-inner { animation: ca-pulse 2.6s ease-in-out infinite; transform-origin:50% 50%; }
        .ca-w1 { animation: ca-w1 14s linear infinite; }
        .ca-w2 { animation: ca-w2 22s linear infinite; }
        .ca-w3 { animation: ca-w3 32s linear infinite; }
        .ca-glow { animation: ca-glow 3.2s ease-in-out infinite; }
        @media (prefers-reduced-motion:reduce) {
          .ca-boat,.ca-heart,.ca-heart-inner,.ca-w1,.ca-w2,.ca-w3,.ca-glow { animation:none !important; }
        }
      `}</style>
      <svg viewBox="0 0 600 600" width="100%" height="100%" style={{ display:"block", overflow:"visible" }}>
        <defs>
          <radialGradient id="caHaloDay" cx="50%" cy="50%" r="50%">
            <stop offset="0%"   stopColor="#fbe7df" stopOpacity="0.95"/>
            <stop offset="60%"  stopColor="#fbe7df" stopOpacity="0.4"/>
            <stop offset="100%" stopColor="#fbe7df" stopOpacity="0"/>
          </radialGradient>
          <radialGradient id="caHaloNight" cx="50%" cy="50%" r="50%">
            <stop offset="0%"   stopColor="#eb9a85" stopOpacity="0.55"/>
            <stop offset="60%"  stopColor="#eb9a85" stopOpacity="0.16"/>
            <stop offset="100%" stopColor="#eb9a85" stopOpacity="0"/>
          </radialGradient>
          <linearGradient id="caWater" x1="0" x2="0" y1="0" y2="1">
            <stop offset="0%"   stopColor={isTwilight ? "#1d567c" : "#003f65"} stopOpacity="0.22"/>
            <stop offset="100%" stopColor="#003f65" stopOpacity="0.55"/>
          </linearGradient>
          <clipPath id="caWaterClip"><rect x="0" y="360" width="600" height="240"/></clipPath>
        </defs>
        <circle className="ca-glow" cx="300" cy="220" r="180" fill={`url(#${isTwilight ? "caHaloNight" : "caHaloDay"})`}/>
        <g className="ca-heart">
          <g className="ca-heart-inner">
            <path d="M300 280 C 300 280 230 240 230 195 C 230 168 252 150 275 150 C 290 150 300 160 300 168 C 300 160 310 150 325 150 C 348 150 370 168 370 195 C 370 240 300 280 300 280 Z"
              fill="var(--coral)" stroke="var(--coral-deep)" strokeWidth="2"/>
          </g>
        </g>
        <g opacity="0.35">
          <path d="M300 290 C 295 320, 305 330, 300 360" stroke="var(--coral-deep)" strokeWidth="1.5" strokeLinecap="round" strokeDasharray="2 6" fill="none"/>
        </g>
        <g className="ca-boat">
          <line x1="300" y1="305" x2="300" y2="380" stroke="var(--ink-navy)" strokeWidth="3" strokeLinecap="round"/>
          <path d="M170 380 Q 300 470 430 380 L 410 410 Q 300 480 190 410 Z" fill="var(--ink-navy)"/>
          <path d="M180 382 Q 300 410 420 382" stroke={isTwilight ? "var(--coral)" : "var(--coral-soft)"} strokeWidth="2.5" fill="none" strokeLinecap="round" opacity=".85"/>
        </g>
        <g clipPath="url(#caWaterClip)">
          <rect x="0" y="360" width="600" height="240" fill="url(#caWater)" opacity={isTwilight ? "0.9" : "0.55"}/>
          <g className="ca-w1" opacity={isTwilight ? "0.55" : "0.45"}>
            {[0,160,320,480,640].map(x=><path key={x} d={`M${x} 430 q 40-10 80 0 t 80 0`} stroke={isTwilight?"#6f8da6":"#1d567c"} strokeWidth="1.5" fill="none" strokeLinecap="round"/>)}
          </g>
          <g className="ca-w2" opacity={isTwilight ? "0.7" : "0.55"}>
            {[0,200,400,600,800].map(x=><path key={x} d={`M${x} 470 q 50-12 100 0 t 100 0`} stroke={isTwilight?"#eb9a85":"#003f65"} strokeWidth="1.8" fill="none" strokeLinecap="round" opacity=".7"/>)}
          </g>
          <g className="ca-w3" opacity={isTwilight ? "0.85" : "0.7"}>
            {[0,120,240,360,480,600,720].map(x=><path key={x} d={`M${x} 520 q 30-14 60 0 t 60 0`} stroke={isTwilight?"#fdfaf3":"#003f65"} strokeWidth="2.2" fill="none" strokeLinecap="round"/>)}
          </g>
        </g>
        <line x1="0" y1="395" x2="600" y2="395" stroke={isTwilight ? "rgba(253,250,243,.18)" : "rgba(0,63,101,.12)"} strokeWidth="1"/>
      </svg>
    </div>
  );
}

// ================================================================
// LOGO-FAITHFUL BOAT — hull traced from the brand mark:
// navy rowing boat with cream plank stripes, upswept notched prow,
// two chunky stylised waves, fat coral heart floating above.
//
// One scene, three motion modes:
//   scroll="none"   — ambient rocking only (like the current boat)
//   scroll="voyage" — as the page scrolls, the boat sails forward,
//                     the water slides beneath, the heart drifts up
//   scroll="drift"  — as the page scrolls, the boat settles into the
//                     rising water while the heart floats upward
// ================================================================

// Scroll progress (0→1 while the scene scrolls out of view), written to
// a CSS custom property --p so transforms update without re-rendering.
// Written synchronously in the scroll handler (no rAF dependency — rAF can
// be throttled); smoothing comes from a CSS transition on the transformed
// groups instead. Measured via getBoundingClientRect so it stays correct
// under the site's global zoom. Respects reduced motion.
function useScrollProgress(ref, enabled) {
  React.useEffect(() => {
    if (!enabled) return;
    const el = ref.current;
    if (!el) return;
    if (window.matchMedia("(prefers-reduced-motion: reduce)").matches) return;

    const measure = () => {
      // Progress runs from the very first scroll (p=0 at page top) to ~1 by
      // the time the scene has scrolled mostly out of view, so the boat
      // responds the moment the visitor starts scrolling.
      const r = el.getBoundingClientRect();
      const docTop = r.top + window.scrollY;
      const total = Math.max(1, docTop + r.height * 0.7);
      const p = Math.min(1, Math.max(0, window.scrollY / total));
      el.style.setProperty("--p", p.toFixed(4));
    };
    el.style.setProperty("--p", "0");
    measure();
    window.addEventListener("scroll", measure, { passive: true });
    window.addEventListener("resize", measure);
    return () => {
      window.removeEventListener("scroll", measure);
      window.removeEventListener("resize", measure);
    };
  }, [enabled]);
}

// Chunky logo-style wave line: n rounded humps of width w on baseline y.
function humpPath(y, w, n, x0 = -280) {
  let d = `M ${x0} ${y}`;
  for (let i = 0; i < n; i++) d += ` q ${w / 2} ${-w * 0.26} ${w} 0`;
  return d;
}

function LogoBoatScene({ size = 520, scroll = "none", idSuffix = "L" }) {
  const ref = React.useRef(null);
  useScrollProgress(ref, scroll !== "none");

  // Scroll-linked transforms (no-ops when --p stays 0 / scroll="none")
  const boatT =
    scroll === "voyage" ? "translate(calc(var(--p,0)*169px), calc(var(--p,0)*-10px)) rotate(calc(var(--p,0)*5.2deg))"
    : scroll === "drift" ? "translateY(calc(var(--p,0)*36px)) rotate(calc(var(--p,0)*-3deg))"
    : undefined;
  const heartT =
    scroll === "voyage" ? "translate(calc(var(--p,0)*110px), calc(var(--p,0)*-98px))"
    : scroll === "drift" ? "translateY(calc(var(--p,0)*-95px)) scale(calc(1 + var(--p,0)*0.12))"
    : undefined;
  const waveT =
    scroll === "voyage" ? "translateX(calc(var(--p,0)*-91px))"
    : scroll === "drift" ? "translateY(calc(var(--p,0)*-24px))"
    : undefined;
  const heartOp = scroll === "voyage" ? "calc(1 - var(--p,0)*0.3)" : undefined;

  // Deeper, chunkier hull traced from the logo: upswept notched prow (right),
  // tapered stern tip (left), fat solid belly below the plank stripes.
  const hull = `M 150 310
    C 196 334, 248 344, 302 344
    C 356 343, 404 326, 438 296
    L 462 270
    L 452 306
    C 448 344, 428 384, 386 408
    C 352 424, 326 430, 300 430
    C 244 429, 200 408, 178 372
    C 166 352, 156 330, 150 310 Z`;
  const clipId = `caLogoHull${idSuffix}`;
  const waterId = `caLogoWater${idSuffix}`;

  const gStyle = (t, extra = {}) =>
    t ? {
      transform: t, transformBox: "fill-box", transformOrigin: "50% 50%",
      // scroll updates land per scroll-event; this transition smooths between
      // them (replaces the old rAF lerp, which stalled when rAF was throttled)
      transition: "transform .35s cubic-bezier(.22,.61,.36,1), opacity .35s ease",
      ...extra,
    } : extra;

  return (
    <div ref={ref} style={{ position: "relative", width: "100%", maxWidth: size, aspectRatio: "1/1", margin: "0 auto", "--p": 0 }}>
      <style>{SHARED_CSS}</style>
      {/* overflow hidden: the wave paths extend far past the viewBox so their
          ambient drift never shows a gap — they must clip at the edges */}
      <svg viewBox="0 0 600 600" width="100%" height="100%" style={{ display: "block", overflow: "hidden" }}>
        <defs>
          <clipPath id={clipId}><path d={hull}/></clipPath>
          <linearGradient id={waterId} x1="0" x2="0" y1="0" y2="1">
            <stop offset="0%" stopColor="#003f65" stopOpacity="0.1"/>
            <stop offset="100%" stopColor="#003f65" stopOpacity="0.3"/>
          </linearGradient>
        </defs>

        {/* heart + halo (drift up on scroll) */}
        <g style={gStyle(heartT, heartOp ? { opacity: heartOp } : {})}>
          <Halo cx={300} cy={205} r={105}/>
          <g className="ca-heart">
            <g className="ca-heart-inner">
              <path d="M300 280 C 300 280 230 240 230 195 C 230 168 252 150 275 150 C 290 150 300 160 300 168 C 300 160 310 150 325 150 C 348 150 370 168 370 195 C 370 240 300 280 300 280 Z"
                fill="var(--coral)" stroke="var(--coral-deep)" strokeWidth="2"/>
            </g>
          </g>
          <path d="M300 292 C 297 312, 303 322, 300 340" stroke="var(--coral-deep)"
            strokeWidth="1.5" strokeDasharray="2 6" fill="none" opacity=".3" strokeLinecap="round"/>
        </g>

        {/* soft water body (behind boat) */}
        <g style={gStyle(waveT)}>
          <rect x="-100" y="436" width="800" height="200" fill={`url(#${waterId})`}/>
        </g>

        {/* logo boat (scroll transform outside, ambient rock inside) */}
        <g style={gStyle(boatT)}>
          <g className="ca-boat">
            <path d={hull} fill="var(--ink-navy)"/>
            {/* cream plank stripes in the upper hull, clipped to the hull —
                thin gaps like the logo, leaving a fat solid belly below */}
            <g clipPath={`url(#${clipId})`} fill="none" stroke="var(--paper)" strokeWidth="5" strokeLinecap="round">
              <path d="M 150 324 C 198 348, 250 358, 302 358 C 356 357, 406 340, 456 300"/>
              <path d="M 156 340 C 204 364, 252 374, 302 374 C 354 373, 402 356, 450 320"/>
              <path d="M 164 358 C 212 382, 256 392, 302 392 C 352 391, 396 374, 442 342"/>
            </g>
          </g>
        </g>

        {/* chunky logo waves (in front of hull bottom) */}
        <g style={gStyle(waveT)}>
          <g className="ca-w1">
            <path d={humpPath(432, 96, 14)} stroke="var(--ink-navy)" strokeWidth="12" fill="none" strokeLinecap="round"/>
          </g>
          <g className="ca-w2" opacity=".75">
            <path d={humpPath(474, 78, 16)} stroke="var(--ink-navy)" strokeWidth="9" fill="none" strokeLinecap="round"/>
          </g>
        </g>
      </svg>
    </div>
  );
}

const BoatHeartLogo       = (p) => <LogoBoatScene scroll="none"   idSuffix="Lg" {...p}/>;
const BoatHeartLogoVoyage = (p) => <LogoBoatScene scroll="voyage" idSuffix="Lv" {...p}/>;
const BoatHeartLogoDrift  = (p) => <LogoBoatScene scroll="drift"  idSuffix="Ld" {...p}/>;

Object.assign(window, {
  BoatHeartAnim, BoatHeartAnimB, BoatHeartAnimC, BoatHeartAnimD,
  LogoBoatScene, BoatHeartLogo, BoatHeartLogoVoyage, BoatHeartLogoDrift,
});
