/* DOODEE — site.jsx — root + section components */
const { useState, useEffect, useRef } = React;
const { COPY, LINKS, LINE_OA } = window.DOODEE;

/* ---------- helpers ---------- */
function useScrolled(threshold = 40) {
  const [s, setS] = useState(false);
  useEffect(() => {
    const f = () => setS(window.scrollY > threshold);
    f(); window.addEventListener("scroll", f, { passive: true });
    return () => window.removeEventListener("scroll", f);
  }, [threshold]);
  return s;
}

function Reveal({ children, delay = 0, as = "div", className = "", style = {} }) {
  const Tag = as;
  const ref = useRef(null);
  const [shown, setShown] = useState(false);
  useEffect(() => {
    const el = ref.current; if (!el) return;
    const io = new IntersectionObserver(
      ([e]) => { if (e.isIntersecting) { setShown(true); io.disconnect(); } },
      { threshold: 0.12, rootMargin: "0px 0px -40px 0px" }
    );
    io.observe(el);
    return () => io.disconnect();
  }, []);
  return (
    <Tag ref={ref}
      className={"reveal " + (shown ? "in " : "") + className}
      style={{ transitionDelay: delay + "ms", ...style }}>
      {children}
    </Tag>
  );
}

function GoldStars({ count = 5 }) {
  return (
    <span className="stars" aria-hidden="true">
      {Array.from({ length: count }).map((_, i) => (
        <svg key={i} viewBox="0 0 24 24" width="14" height="14">
          <path fill="currentColor" d="M12 2l2.9 6.9L22 10l-5.5 4.8L18 22l-6-3.7L6 22l1.5-7.2L2 10l7.1-1.1z"/>
        </svg>
      ))}
    </span>
  );
}

/* Service scenes — each card leads with an evocative illustrated banner */
function SvcScene({ name }) {
  const svgProps = { viewBox: "0 0 240 140", preserveAspectRatio: "xMidYMid slice", "aria-hidden": true, className: "svc-scene__svg" };

  // shared backdrop: purple gradient + soft star field, used inside each scene
  const Defs = () => (
    <defs>
      <linearGradient id="svc-bg" x1="0%" y1="0%" x2="100%" y2="100%">
        <stop offset="0%"  stopColor="#3D1B5C"/>
        <stop offset="55%" stopColor="#2A1147"/>
        <stop offset="100%" stopColor="#1A0B2E"/>
      </linearGradient>
      <radialGradient id="svc-glow" cx="50%" cy="55%" r="45%">
        <stop offset="0%"   stopColor="#D4A574" stopOpacity=".42"/>
        <stop offset="60%"  stopColor="#D4A574" stopOpacity=".12"/>
        <stop offset="100%" stopColor="#D4A574" stopOpacity="0"/>
      </radialGradient>
      <linearGradient id="svc-gold" x1="0%" y1="0%" x2="100%" y2="100%">
        <stop offset="0%"  stopColor="#E8C99F"/>
        <stop offset="100%" stopColor="#D4A574"/>
      </linearGradient>
    </defs>
  );

  const Backdrop = () => (
    <g>
      <rect x="0" y="0" width="240" height="140" fill="url(#svc-bg)"/>
      <rect x="0" y="0" width="240" height="140" fill="url(#svc-glow)"/>
      {/* star field */}
      <g fill="#E8C99F">
        <circle cx="22"  cy="24"  r="1"   opacity=".55"/>
        <circle cx="212" cy="30"  r=".8"  opacity=".5"/>
        <circle cx="34"  cy="108" r=".9"  opacity=".4"/>
        <circle cx="206" cy="114" r="1.1" opacity=".55"/>
        <circle cx="120" cy="14"  r=".7"  opacity=".4"/>
        <circle cx="60"  cy="66"  r=".5"  opacity=".35"/>
        <circle cx="178" cy="72"  r=".5"  opacity=".35"/>
        <circle cx="96"  cy="124" r=".5"  opacity=".3"/>
      </g>
    </g>
  );

  // 4-point spark used in several scenes
  const Spark = ({ cx, cy, s = 4, opacity = 1 }) => (
    <g transform={`translate(${cx} ${cy})`} stroke="#E8C99F" strokeWidth=".7" opacity={opacity}>
      <line x1={-s} y1="0" x2={s} y2="0"/>
      <line x1="0" y1={-s} x2="0" y2={s}/>
      <line x1={-s*0.45} y1={-s*0.45} x2={s*0.45} y2={s*0.45} opacity=".5"/>
      <line x1={-s*0.45} y1={s*0.45} x2={s*0.45} y2={-s*0.45} opacity=".5"/>
    </g>
  );

  const scenes = {
    /* NEW: Love Reading — outlined heart with inner glow + stars */
    love: (
      <svg {...svgProps}>
        <Defs /><Backdrop />
        <g fill="none" stroke="url(#svc-gold)" strokeWidth="2.4" strokeLinejoin="round" strokeLinecap="round">
          <path d="M120 114 C 88 92, 66 76, 66 56 C 66 44, 76 36, 88 36 C 100 36, 110 44, 120 56 C 130 44, 140 36, 152 36 C 164 36, 174 44, 174 56 C 174 76, 152 92, 120 114 Z"/>
        </g>
        <path d="M120 92 C 104 80, 94 70, 94 60 C 94 54, 99 50, 105 50 C 111 50, 116 53, 120 58 C 124 53, 129 50, 135 50 C 141 50, 146 54, 146 60 C 146 70, 136 80, 120 92 Z" fill="#D4A574" opacity=".22"/>
        <circle cx="120" cy="66" r="1.5" fill="#E8C99F"/>
        <Spark cx={56}  cy={50}  s={4}/>
        <Spark cx={186} cy={56}  s={3.5}/>
        <Spark cx={68}  cy={104} s={3}/>
        <Spark cx={178} cy={108} s={3}/>
        <Spark cx={120} cy={22}  s={4.5}/>
      </svg>
    ),

    /* NEW: When Will I Meet Love — two dotted paths converging to a heart */
    meetlove: (
      <svg {...svgProps}>
        <Defs /><Backdrop />
        <g fill="none" stroke="url(#svc-gold)" strokeWidth="2" strokeLinejoin="round" strokeLinecap="round" strokeDasharray="3 4">
          <path d="M28 122 C 60 102, 88 84, 120 70"/>
          <path d="M212 122 C 180 102, 152 84, 120 70"/>
        </g>
        {/* path origin dots */}
        <circle cx="28"  cy="122" r="2.2" fill="#E8C99F"/>
        <circle cx="212" cy="122" r="2.2" fill="#E8C99F"/>
        {/* meeting heart */}
        <g transform="translate(120 56)">
          <path d="M0 16 C -12 6, -20 -4, -20 -10 C -20 -16, -16 -20, -10 -20 C -5 -20, -1 -17, 0 -13 C 1 -17, 5 -20, 10 -20 C 16 -20, 20 -16, 20 -10 C 20 -4, 12 6, 0 16 Z" fill="url(#svc-gold)"/>
        </g>
        <Spark cx={60}  cy={42} s={3.5}/>
        <Spark cx={180} cy={42} s={3.5}/>
      </svg>
    ),

    /* NEW: Ex Return — hourglass with falling stars */
    ex: (
      <svg {...svgProps}>
        <Defs /><Backdrop />
        <g fill="none" stroke="url(#svc-gold)" strokeWidth="2.2" strokeLinejoin="round" strokeLinecap="round">
          <line x1="94"  y1="28" x2="146" y2="28"/>
          <line x1="94"  y1="118" x2="146" y2="118"/>
          <path d="M98 28 L 142 28 L 124 70 L 142 118 L 98 118 L 116 70 Z"/>
        </g>
        {/* sand top (depleting) */}
        <path d="M104 36 L 136 36 L 124 64 L 116 64 Z" fill="#D4A574" opacity=".55"/>
        {/* sand bottom (growing) */}
        <path d="M104 110 L 136 110 L 132 88 L 108 88 Z" fill="#D4A574" opacity=".45"/>
        {/* falling grain */}
        <circle cx="120" cy="74" r="1.3" fill="#E8C99F"/>
        <circle cx="120" cy="80" r="1"   fill="#E8C99F" opacity=".75"/>
        <circle cx="120" cy="85" r=".8"  fill="#E8C99F" opacity=".55"/>
        <Spark cx={56}  cy={62}  s={3.5}/>
        <Spark cx={184} cy={62}  s={3.5}/>
        <Spark cx={66}  cy={108} s={3}/>
        <Spark cx={176} cy={108} s={3}/>
      </svg>
    ),

    /* NEW: Marriage Timing — calendar page with rings on a marked date */
    wedding: (
      <svg {...svgProps}>
        <Defs /><Backdrop />
        <g fill="none" stroke="url(#svc-gold)" strokeWidth="2" strokeLinejoin="round">
          <circle cx="96"  cy="30" r="3"/>
          <circle cx="144" cy="30" r="3"/>
          <line x1="96"  y1="33" x2="96"  y2="40"/>
          <line x1="144" y1="33" x2="144" y2="40"/>
          <rect x="66" y="38" width="108" height="82" rx="3"/>
          <line x1="78" y1="54" x2="162" y2="54" opacity=".6"/>
        </g>
        {/* tiny calendar grid dots */}
        <g fill="#E8C99F" opacity=".4">
          {Array.from({length:4}).map((_,r)=>(
            Array.from({length:6}).map((_,c)=>(
              <circle key={r+'_'+c} cx={84 + c*15} cy={68 + r*13} r=".8"/>
            ))
          ))}
        </g>
        {/* highlighted date box */}
        <rect x="99" y="80" width="42" height="28" rx="3" fill="#D4A574" opacity=".18"/>
        {/* interlocking rings on the date */}
        <g fill="none" stroke="url(#svc-gold)" strokeWidth="2">
          <circle cx="114" cy="94" r="10"/>
          <circle cx="128" cy="94" r="10"/>
        </g>
        <Spark cx={48}  cy={66} s={3}/>
        <Spark cx={200} cy={84} s={3}/>
        <Spark cx={120} cy={18} s={3.5}/>
      </svg>
    ),

    /* 1. Marriage — interlocking rings with a spark at the seam */
    marriage: (
      <svg {...svgProps}>
        <Defs /><Backdrop />
        <g fill="none" stroke="url(#svc-gold)" strokeWidth="2.4">
          <circle cx="100" cy="70" r="28"/>
          <circle cx="140" cy="70" r="28"/>
        </g>
        <g fill="none" stroke="#E8C99F" strokeWidth="0.6" opacity=".55">
          <circle cx="100" cy="70" r="23.5"/>
          <circle cx="140" cy="70" r="23.5"/>
        </g>
        <Spark cx={120} cy={70} s={6}/>
        <circle cx="120" cy="70" r="2" fill="#E8C99F"/>
      </svg>
    ),

    /* 2. Baby — lotus blossom with rising stars */
    baby: (
      <svg {...svgProps}>
        <Defs /><Backdrop />
        {/* lotus */}
        <g fill="none" stroke="url(#svc-gold)" strokeWidth="2" strokeLinejoin="round" strokeLinecap="round">
          {/* base waterline */}
          <line x1="78" y1="112" x2="162" y2="112" opacity=".55"/>
          {/* outer petals */}
          <path d="M120 112 C 86 102, 70 86, 80 70 C 88 78, 102 84, 114 90 Z"/>
          <path d="M120 112 C 154 102, 170 86, 160 70 C 152 78, 138 84, 126 90 Z"/>
          {/* middle petals */}
          <path d="M120 112 C 100 100, 92 80, 102 64 C 108 76, 116 88, 120 96 Z"/>
          <path d="M120 112 C 140 100, 148 80, 138 64 C 132 76, 124 88, 120 96 Z"/>
          {/* bud */}
          <path d="M120 112 C 112 98, 114 80, 120 64 C 126 80, 128 98, 120 112 Z"/>
        </g>
        <circle cx="120" cy="82" r="1.6" fill="#E8C99F"/>
        {/* rising stars */}
        <Spark cx={100} cy={46} s={3.5} opacity={.85}/>
        <Spark cx={120} cy={32} s={5} opacity={1}/>
        <Spark cx={142} cy={48} s={3} opacity={.7}/>
      </svg>
    ),

    /* 3. Business — shopfront with a hanging sign */
    biz: (
      <svg {...svgProps}>
        <Defs /><Backdrop />
        <g fill="none" stroke="url(#svc-gold)" strokeWidth="2" strokeLinejoin="round" strokeLinecap="round">
          {/* awning peak */}
          <path d="M70 56 L120 30 L170 56"/>
          {/* facade walls */}
          <path d="M76 56 L76 120 L164 120 L164 56"/>
          {/* door */}
          <path d="M108 120 L108 88 L132 88 L132 120"/>
          <circle cx="128" cy="104" r="1.2" fill="#E8C99F" stroke="none"/>
          {/* side windows */}
          <rect x="82" y="66" width="18" height="14" rx="1"/>
          <rect x="140" y="66" width="18" height="14" rx="1"/>
          {/* hanging sign */}
          <line x1="120" y1="56" x2="120" y2="68"/>
          <rect x="104" y="68" width="32" height="14" rx="2"/>
        </g>
        {/* star on sign */}
        <g transform="translate(120 75)" fill="#E8C99F">
          <path d="M0 -4.5 L1.3 -1.5 L4.5 -1 L2.2 1.3 L2.8 4.5 L0 3 L-2.8 4.5 L-2.2 1.3 L-4.5 -1 L-1.3 -1.5 Z"/>
        </g>
        <Spark cx={188} cy={42} s={3.5} opacity={.7}/>
      </svg>
    ),

    /* 4. Career — mountain peaks with rising sun and dotted ascent */
    career: (
      <svg {...svgProps}>
        <Defs /><Backdrop />
        {/* sun */}
        <circle cx="168" cy="58" r="18" fill="none" stroke="url(#svc-gold)" strokeWidth="2"/>
        <circle cx="168" cy="58" r="10" fill="#D4A574" opacity=".25"/>
        {/* mountain back */}
        <path d="M30 120 L96 56 L132 92 L160 70 L210 120 Z" fill="none" stroke="url(#svc-gold)" strokeWidth="2" strokeLinejoin="round"/>
        {/* mountain front (snow ridges) */}
        <path d="M64 96 L84 76 L96 88 M120 100 L140 84" fill="none" stroke="#E8C99F" strokeWidth=".9" opacity=".7" strokeLinejoin="round"/>
        {/* dotted path */}
        <g fill="#E8C99F">
          <circle cx="60"  cy="112" r="1.4"/>
          <circle cx="72"  cy="100" r="1.4"/>
          <circle cx="84"  cy="88"  r="1.4"/>
          <circle cx="96"  cy="72"  r="1.6"/>
        </g>
        <Spark cx={96} cy={50} s={4}/>
      </svg>
    ),

    /* 5. Auspicious Timing — calendar page with a starred date */
    timing: (
      <svg {...svgProps}>
        <Defs /><Backdrop />
        <g fill="none" stroke="url(#svc-gold)" strokeWidth="2" strokeLinejoin="round">
          {/* binding rings */}
          <circle cx="94"  cy="30" r="3"/>
          <circle cx="146" cy="30" r="3"/>
          <line x1="94"  y1="33" x2="94"  y2="40"/>
          <line x1="146" y1="33" x2="146" y2="40"/>
          {/* page */}
          <rect x="70" y="38" width="100" height="78" rx="3"/>
          {/* heading line */}
          <line x1="82" y1="54" x2="158" y2="54" opacity=".6"/>
          {/* grid */}
          <g opacity=".4">
            <line x1="82"  y1="68"  x2="158" y2="68"/>
            <line x1="82"  y1="82"  x2="158" y2="82"/>
            <line x1="82"  y1="96"  x2="158" y2="96"/>
            <line x1="101" y1="60"  x2="101" y2="110"/>
            <line x1="120" y1="60"  x2="120" y2="110"/>
            <line x1="139" y1="60"  x2="139" y2="110"/>
          </g>
        </g>
        {/* highlighted date — the auspicious day */}
        <rect x="101.5" y="82.5" width="18" height="13" rx="2" fill="#D4A574" opacity=".18"/>
        <g transform="translate(110.5 89.5)" fill="#E8C99F">
          <path d="M0 -4.2 L1.2 -1.3 L4.2 -1 L2 1.3 L2.6 4.2 L0 2.7 L-2.6 4.2 L-2 1.3 L-4.2 -1 L-1.2 -1.3 Z"/>
        </g>
        <Spark cx={50} cy={60} s={3}/>
        <Spark cx={196} cy={92} s={3}/>
      </svg>
    ),

    /* 6. Lucky Phone — phone with floating auspicious digits */
    phone: (
      <svg {...svgProps}>
        <Defs /><Backdrop />
        <g fill="none" stroke="url(#svc-gold)" strokeWidth="2" strokeLinejoin="round">
          <rect x="94" y="28" width="52" height="94" rx="7"/>
          <line x1="110" y1="34" x2="130" y2="34" opacity=".7"/>
          <circle cx="120" cy="114" r="1.6" fill="#E8C99F" stroke="none"/>
        </g>
        {/* digit on screen */}
        <text x="120" y="82" fontFamily="Cormorant Garamond, serif" fontStyle="italic" fontWeight="600" fontSize="36" fill="#E8C99F" textAnchor="middle">9</text>
        {/* floating digits */}
        <text x="58"  y="58" fontFamily="Cormorant Garamond, serif" fontStyle="italic" fontSize="18" fill="#D4A574" opacity=".7" textAnchor="middle">8</text>
        <text x="180" y="50" fontFamily="Cormorant Garamond, serif" fontStyle="italic" fontSize="22" fill="#D4A574" opacity=".85" textAnchor="middle">6</text>
        <text x="196" y="104" fontFamily="Cormorant Garamond, serif" fontStyle="italic" fontSize="16" fill="#D4A574" opacity=".6" textAnchor="middle">3</text>
        <Spark cx={66} cy={92} s={3}/>
        <Spark cx={176} cy={28} s={3.5}/>
      </svg>
    ),

    /* 7. Feng Shui — bagua compass over a house */
    fengshui: (
      <svg {...svgProps}>
        <Defs /><Backdrop />
        {/* house */}
        <g fill="none" stroke="url(#svc-gold)" strokeWidth="2" strokeLinejoin="round" strokeLinecap="round">
          <path d="M70 122 L70 92 L120 64 L170 92 L170 122 Z"/>
          <path d="M108 122 L108 102 L132 102 L132 122"/>
        </g>
        {/* bagua */}
        <g transform="translate(120 50)">
          <polygon points="0,-26 18,-18 26,0 18,18 0,26 -18,18 -26,0 -18,-18" fill="none" stroke="url(#svc-gold)" strokeWidth="2"/>
          <polygon points="0,-18 12.7,-12.7 18,0 12.7,12.7 0,18 -12.7,12.7 -18,0 -12.7,-12.7" fill="none" stroke="#E8C99F" strokeWidth=".7" opacity=".55"/>
          {/* taiji center */}
          <circle r="7" fill="none" stroke="#E8C99F" strokeWidth="1.2"/>
          <path d="M0 -7 A 3.5 3.5 0 0 1 0 0 A 3.5 3.5 0 0 0 0 7 A 7 7 0 0 1 0 -7 Z" fill="#E8C99F"/>
          <circle cx="0" cy="-3.5" r="1" fill="#1A0B2E"/>
          <circle cx="0" cy="3.5"  r="1" fill="#E8C99F"/>
          {/* trigram ticks */}
          <g stroke="#E8C99F" strokeWidth="1" opacity=".7">
            <line x1="0"   y1="-26" x2="0"   y2="-22"/>
            <line x1="0"   y1="22"  x2="0"   y2="26"/>
            <line x1="-26" y1="0"   x2="-22" y2="0"/>
            <line x1="22"  y1="0"   x2="26"  y2="0"/>
          </g>
        </g>
        <Spark cx={52} cy={66} s={3}/>
        <Spark cx={196} cy={84} s={3}/>
      </svg>
    ),

    /* 8. Birthday Year — zodiac / 12-month wheel with sun */
    year: (
      <svg {...svgProps}>
        <Defs /><Backdrop />
        <g transform="translate(120 70)">
          {/* outer wheel */}
          <circle r="42" fill="none" stroke="url(#svc-gold)" strokeWidth="2"/>
          <circle r="34" fill="none" stroke="#E8C99F" strokeWidth=".7" opacity=".55"/>
          {/* 12 month ticks */}
          {Array.from({length:12}).map((_,i)=>{
            const a = (i / 12) * Math.PI * 2 - Math.PI / 2;
            const x1 = Math.cos(a) * 34, y1 = Math.sin(a) * 34;
            const x2 = Math.cos(a) * 42, y2 = Math.sin(a) * 42;
            return <line key={i} x1={x1} y1={y1} x2={x2} y2={y2} stroke="#E8C99F" strokeWidth="1.2"/>;
          })}
          {/* dots at outer ring */}
          {Array.from({length:12}).map((_,i)=>{
            const a = (i / 12) * Math.PI * 2 - Math.PI / 2;
            const x = Math.cos(a) * 46, y = Math.sin(a) * 46;
            return <circle key={i} cx={x} cy={y} r="1" fill="#E8C99F" opacity={i===0?1:.55}/>;
          })}
          {/* sun face center */}
          <circle r="14" fill="#D4A574" opacity=".25"/>
          <circle r="10" fill="none" stroke="#E8C99F" strokeWidth="1.3"/>
          {/* sun rays */}
          <g stroke="#E8C99F" strokeWidth="1" strokeLinecap="round">
            {Array.from({length:8}).map((_,i)=>{
              const a = (i / 8) * Math.PI * 2;
              const x1 = Math.cos(a) * 14, y1 = Math.sin(a) * 14;
              const x2 = Math.cos(a) * 18, y2 = Math.sin(a) * 18;
              return <line key={i} x1={x1} y1={y1} x2={x2} y2={y2}/>;
            })}
          </g>
        </g>
      </svg>
    ),
  };

  return <div className="svc-scene">{scenes[name] || scenes.marriage}</div>;
}

/* ---------- nav ---------- */
function Nav({ lang, setLang, t }) {
  const scrolled = useScrolled(40);
  const [open, setOpen] = useState(false);
  return (
    <nav className={"nav " + (scrolled || open ? "nav--scrolled" : "")}>
      <div className="nav__inner">
        <a href="#top" className="nav__brand" onClick={() => setOpen(false)}>
          <span className="nav__avatar">
            <img src="assets/doodee-master-logo.jpg" alt="" />
          </span>
          <span className="nav__wordmark">DOODEE</span>
          <span className="nav__brandTag">{t.tagline_small}</span>
        </a>

        <div className="nav__links">
          <a href="#about">{t.nav.about}</a>
          <a href="#services">{t.nav.services}</a>
          <a href="#pricing">{t.nav.pricing}</a>
          <a href="#faq">{t.nav.faq}</a>
        </div>

        <div className="nav__right">
          <div className="langtoggle" role="tablist" aria-label="Language">
            <button className={lang === "th" ? "active" : ""} onClick={() => setLang("th")} aria-pressed={lang === "th"}>ไทย</button>
            <span className="langtoggle__sep">|</span>
            <button className={lang === "en" ? "active" : ""} onClick={() => setLang("en")} aria-pressed={lang === "en"}>EN</button>
          </div>
          <a href={LINKS.default} className="btn btn--pill btn--gold nav__cta" target="_blank" rel="noopener">{t.nav.cta}</a>
          <button className={"nav__burger " + (open ? "is-open" : "")} aria-label="Menu" onClick={() => setOpen(v => !v)}>
            <span></span><span></span><span></span>
          </button>
        </div>
      </div>

      {open && (
        <div className="nav__sheet">
          <a href="#about" onClick={() => setOpen(false)}>{t.nav.about}</a>
          <a href="#services" onClick={() => setOpen(false)}>{t.nav.services}</a>
          <a href="#pricing" onClick={() => setOpen(false)}>{t.nav.pricing}</a>
          <a href="#faq" onClick={() => setOpen(false)}>{t.nav.faq}</a>
          <a href={LINKS.default} className="btn btn--pill btn--gold" target="_blank" rel="noopener">{t.nav.cta}</a>
        </div>
      )}
    </nav>
  );
}

/* ---------- hero ---------- */
function Hero({ lang, t }) {
  const h1Cls = "h1 " + (lang === "th" ? "h1--th" : "h1--en");
  return (
    <header className="hero" id="top">
      <div className="hero__bg" aria-hidden="true">
        <div className="hero__stars"></div>
        <div className="hero__particles">
          {Array.from({ length: 12 }).map((_, i) => (
            <span key={i} className={"particle particle--" + (i + 1)}></span>
          ))}
        </div>
      </div>
      <div className="hero__inner">
        <div className="hero__text">
          <Reveal as="div" className="eyebrow eyebrow--gold">{t.hero.eyebrow}</Reveal>
          <Reveal as="h1" className={h1Cls} delay={80}>
            <span className="h1__line h1--grad">{t.hero.h1[0]}</span>
            <span className="h1__line h1--grad">{t.hero.h1[1]}</span>
          </Reveal>
          <Reveal as="div" className="hero__tagline" delay={160}>
            {t.hero.tagline}
            <span className="hero__taglineSub">{t.hero.tagline_sub}</span>
          </Reveal>
          <Reveal as="p" className="hero__sub" delay={220}>{t.hero.sub}</Reveal>
          <Reveal as="div" className="hero__ctaRow" delay={300}>
            <a href={LINKS.default} className="btn btn--pill btn--gold btn--lg btn--pulse" target="_blank" rel="noopener">{t.hero.cta}</a>
          </Reveal>
          <Reveal as="div" className="hero__trust" delay={380}>{t.hero.trust}</Reveal>
        </div>

        <div className="hero__portrait">
          <div className="portrait">
            <img src="assets/doodee-master-logo.jpg" alt="ป้าหมอดูดี — DOODEE" width="480" height="480" fetchpriority="high" decoding="async" />
          </div>
          <div className="portrait__caption">{t.hero.caption}</div>
        </div>
      </div>
    </header>
  );
}

/* ---------- trust band ---------- */
function TrustBand({ t }) {
  return (
    <section className="trust">
      <div className="trust__inner">
        {t.trust.map((item, i) => (
          <React.Fragment key={i}>
            <span className="trust__item">{item}</span>
            {i < t.trust.length - 1 && <span className="trust__dot">·</span>}
          </React.Fragment>
        ))}
      </div>
    </section>
  );
}

/* ---------- about ---------- */
function About({ t }) {
  return (
    <section className="about" id="about">
      <div className="about__paper" aria-hidden="true"></div>
      <div className="container about__grid">
        <Reveal as="div" className="about__media">
          <div className="about__portrait">
            <img src="assets/doodee-master-logo.jpg" alt="" />
          </div>
          <div className="about__cap">{t.about.caption}</div>
          <div className="about__capSub">{t.about.caption_sub}</div>
        </Reveal>

        <div className="about__body">
          <Reveal as="div" className="eyebrow eyebrow--gold">{t.about.eyebrow}</Reveal>
          <Reveal as="h2" className="h2 h2--purple about__h2" delay={80}>
            {t.about.h2_a} <span className="h2__accent">{t.about.h2_b}</span>
          </Reveal>
          <div className="about__copy">
            {t.about.body.map((p, i) => (
              <Reveal as="p" key={i} delay={140 + i * 80}>{p}</Reveal>
            ))}
          </div>
          <Reveal as="div" className="about__pull" delay={520}>{t.about.pull}</Reveal>
          <Reveal as="div" className="about__where" delay={580}>
            <span aria-hidden="true">📍</span> {t.about.where}
          </Reveal>
        </div>
      </div>
    </section>
  );
}

/* ---------- why accurate ---------- */
function Accurate({ t }) {
  return (
    <section className="accurate">
      <div className="accurate__bg" aria-hidden="true"></div>
      <div className="container">
        <Reveal as="div" className="eyebrow eyebrow--gold eyebrow--center">{t.accurate.eyebrow}</Reveal>
        <Reveal as="h2" className="h2 h2--cream" delay={80}>
          {t.accurate.h2_a} <span className="h2__accent h2__accent--gold">{t.accurate.h2_b}</span>
        </Reveal>
        <Reveal as="p" className="accurate__sub" delay={160}>{t.accurate.sub}</Reveal>

        <div className="pillars">
          {t.accurate.pillars.map((p, i) => (
            <Reveal as="div" className="pillar" key={i} delay={200 + i * 100}>
              <div className="pillar__glyph">{p.glyph}</div>
              <h3 className="pillar__title">{p.title}</h3>
              <div className="pillar__sub">{p.sub}</div>
              <div className="pillar__row">
                <div className="pillar__label">{p.src_label}</div>
                <div className="pillar__val">{p.src}</div>
              </div>
              <div className="pillar__row">
                <div className="pillar__label">{p.spec_label}</div>
                <div className="pillar__val">{p.spec}</div>
              </div>
              <div className="pillar__badge">{p.acc}</div>
            </Reveal>
          ))}
        </div>

        <Reveal as="div" className="accurate__closing" delay={520}>{t.accurate.closing}</Reveal>

        <div className="accurate__strip">
          {t.accurate.strip.map((s, i) => (
            <React.Fragment key={i}>
              <span>{s}</span>
              {i < t.accurate.strip.length - 1 && <span className="accurate__stripDot">·</span>}
            </React.Fragment>
          ))}
        </div>
      </div>
    </section>
  );
}

/* Comparison marks — custom svg, no emoji */
function Mark({ type }) {
  if (type === "yes") return (
    <svg className="mk mk--yes" viewBox="0 0 24 24" width="22" height="22" aria-hidden="true">
      <path d="M5 12.5 L10 17.5 L19 7.5" fill="none" stroke="currentColor" strokeWidth="2.4" strokeLinecap="round" strokeLinejoin="round"/>
    </svg>
  );
  if (type === "part") return (
    <svg className="mk mk--part" viewBox="0 0 24 24" width="22" height="22" aria-hidden="true">
      <circle cx="12" cy="12" r="8" fill="none" stroke="currentColor" strokeWidth="2" />
      <line x1="7.5" y1="12" x2="16.5" y2="12" stroke="currentColor" strokeWidth="2.4" strokeLinecap="round"/>
    </svg>
  );
  return (
    <svg className="mk mk--no" viewBox="0 0 24 24" width="22" height="22" aria-hidden="true">
      <line x1="7" y1="7" x2="17" y2="17" stroke="currentColor" strokeWidth="2.4" strokeLinecap="round"/>
      <line x1="17" y1="7" x2="7" y2="17" stroke="currentColor" strokeWidth="2.4" strokeLinecap="round"/>
    </svg>
  );
}

function Compare({ t }) {
  const c = t.compare;
  return (
    <section className="compare">
      <span className="compare__rule" aria-hidden="true"></span>
      <div className="container">
        <Reveal as="div" className="eyebrow eyebrow--gold eyebrow--center">{c.eyebrow}</Reveal>
        <Reveal as="h2" className="h2 h2--purple" delay={80}>
          {c.h2_a} <span className="h2__accent h2__accent--gold">{c.h2_b}</span>
        </Reveal>
        <Reveal as="p" className="compare__sub" delay={140}>{c.sub}</Reveal>

        {/* DESKTOP scorecard */}
        <Reveal as="div" className="scorecard" delay={200}>
          <div className="scorecard__inner">
            {/* Header row */}
            <div className="sc-row sc-row--head">
              <div className="sc-cell sc-cell--lbl">
                <div className="sc-leg">
                  <span className="sc-leg__item"><Mark type="yes"  /> {c.legend.yes}</span>
                  <span className="sc-leg__item"><Mark type="part" /> {c.legend.part}</span>
                  <span className="sc-leg__item"><Mark type="no"   /> {c.legend.no}</span>
                </div>
              </div>
              {c.cols.map(col => (
                <div key={col.id} className={"sc-cell sc-head sc-head--" + col.id + (col.id === "us" ? " sc-head--us" : "")}>
                  <div className="sc-head__name">{col.name}</div>
                  <div className="sc-head__tag">{col.tag}</div>
                  <div className="sc-head__score">{col.score}</div>
                </div>
              ))}
            </div>

            {/* Rows */}
            {c.rows.map((row, i) => (
              <div className="sc-row" key={i}>
                <div className="sc-cell sc-cell--lbl">
                  <div className="sc-feat">
                    <span className="sc-feat__num">{String(i + 1).padStart(2, "0")}</span>
                    <div>
                      <div className="sc-feat__name">{row.label}</div>
                      <div className="sc-feat__note">{row.note}</div>
                    </div>
                  </div>
                </div>
                {c.cols.map(col => (
                  <div key={col.id} className={"sc-cell sc-cell--mark sc-cell--" + col.id + (col.id === "us" ? " sc-cell--us" : "")}>
                    <Mark type={row.marks[col.id]} />
                    <span className="sc-val">{row.vals[col.id]}</span>
                  </div>
                ))}
              </div>
            ))}
          </div>

          {/* Floating DOODEE crown over its column */}
          <div className="scorecard__crown" aria-hidden="true">
            <span className="scorecard__crownLine"></span>
            <span className="scorecard__crownLbl">{c.score_lbl}</span>
            <span className="scorecard__crownNum">{c.score_us}</span>
          </div>
        </Reveal>

        {/* MOBILE stacked competitor cards */}
        <div className="sc-mobile">
          {c.cols.map(col => (
            <Reveal as="div" className={"scm__card " + (col.id === "us" ? "scm__card--us" : "")} key={col.id}>
              <div className="scm__head">
                <div>
                  <div className="scm__name">{col.name}</div>
                  <div className="scm__tag">{col.tag}</div>
                </div>
                <div className="scm__score">{col.score}</div>
              </div>
              <ul className="scm__list">
                {c.rows.map((row, i) => (
                  <li key={i}>
                    <span className="scm__feat">{row.label}</span>
                    <span className="scm__cell">
                      <Mark type={row.marks[col.id]} />
                      <span className="scm__val">{row.vals[col.id]}</span>
                    </span>
                  </li>
                ))}
              </ul>
            </Reveal>
          ))}
        </div>

        <Reveal as="div" className="compare__punch" delay={260}>{c.punch}</Reveal>
      </div>
    </section>
  );
}

/* ---------- pricing ---------- */
function Pricing({ t }) {
  return (
    <section className="pricing" id="pricing">
      <div className="pricing__bg" aria-hidden="true"></div>
      <div className="container">
        <Reveal as="div" className="eyebrow eyebrow--gold eyebrow--center">{t.pricing.eyebrow}</Reveal>
        <Reveal as="h2" className="h2 h2--cream" delay={80}>{t.pricing.h2}</Reveal>
        <Reveal as="p" className="pricing__sub" delay={140}>{t.pricing.sub}</Reveal>

        <div className="tier-grid">
          {t.pricing.tiers.map((tier, i) => (
            <Reveal as="div" key={i} delay={140 + i * 80}
              className={"tier tier--" + tier.style + (tier.popular ? " tier--popular" : "")}>
              {tier.popular && <div className="tier__badge">{t.pricing.popular_badge}</div>}
              <div className="tier__head">
                <div className="tier__name">{tier.name}</div>
                <div className="tier__sub">{tier.sub}</div>
              </div>
              <div className="tier__price">
                <span className="tier__priceNum">{tier.price}</span>
                <span className="tier__per">{t.pricing.per}</span>
              </div>
              <div className="tier__div"></div>
              <ul className="tier__feats">
                {tier.features.map((f, j) => (
                  <li key={j}><span className="tier__check">✓</span>{f}</li>
                ))}
              </ul>
              <a href={LINKS[tier.link]} target="_blank" rel="noopener"
                 className={"btn btn--pill tier__cta " + (
                   tier.style === "popular" ? "btn--night" :
                   tier.style === "solid" ? "btn--gold" : "btn--ghost"
                 )}>{tier.cta}</a>
            </Reveal>
          ))}
        </div>
      </div>
    </section>
  );
}

/* ---------- premium services ---------- */
function Services({ t }) {
  return (
    <section className="services" id="services">
      <span className="services__leaf services__leaf--tl" aria-hidden="true"></span>
      <span className="services__leaf services__leaf--br" aria-hidden="true"></span>
      <div className="container">
        <Reveal as="div" className="eyebrow eyebrow--gold eyebrow--center">{t.services.eyebrow}</Reveal>
        <Reveal as="h2" className="h2 h2--purple" delay={80}>
          {t.services.h2_a} <span className="h2__accent">{t.services.h2_b}</span>
        </Reveal>
        <Reveal as="p" className="services__sub" delay={140}>{t.services.sub}</Reveal>

        <div className="svc-grid">
          {t.services.items.map((s, i) => (
            <Reveal as="div" className="svc-card" key={i} delay={140 + i * 60}>
              <div className="svc-card__hero"><SvcScene name={s.icon} /></div>
              <div className="svc-card__body">
                <h3 className="svc-card__title">{s.name}</h3>
                <div className="svc-card__en">{s.en}</div>
                <p className="svc-card__desc">{s.desc}</p>
                <div className="svc-card__price">{s.price}</div>
                <div className="svc-card__time">{s.time}</div>
                <a href={LINKS[s.link]} target="_blank" rel="noopener" className="btn btn--pill btn--gold svc-card__cta">{t.services.cta}</a>
              </div>
            </Reveal>
          ))}
        </div>

        <Reveal as="div" className="services__strip" delay={200}>
          {t.services.strip.map((s, i) => (
            <React.Fragment key={i}>
              <span>{s}</span>
              {i < t.services.strip.length - 1 && <span className="services__stripDot">·</span>}
            </React.Fragment>
          ))}
        </Reveal>
      </div>
    </section>
  );
}

/* ---------- how it works ---------- */
function HowItWorks({ t }) {
  return (
    <section className="how">
      <div className="container">
        <Reveal as="h2" className="h2 h2--purple h2--center">{t.how.h2}</Reveal>
        <div className="how__steps">
          {t.how.steps.map((s, i) => (
            <Reveal as="div" className="step" key={i} delay={80 + i * 100}>
              <div className="step__num">{s.n}</div>
              <h3 className="step__title">{s.t}</h3>
              <p className="step__desc">{s.d}</p>
              {i < t.how.steps.length - 1 && <div className="step__arrow" aria-hidden="true">→</div>}
            </Reveal>
          ))}
        </div>
        <Reveal as="div" className="how__cta" delay={400}>
          <a href={LINKS.default} target="_blank" rel="noopener" className="btn btn--pill btn--gold btn--xl btn--pulse">{t.how.cta}</a>
          <div className="how__ctaSub">{t.how.cta_sub}</div>
        </Reveal>
      </div>
    </section>
  );
}

/* ---------- testimonials ---------- */
function Testimonials({ t }) {
  return (
    <section className="tmn">
      <div className="tmn__bg" aria-hidden="true"></div>
      <div className="container">
        <Reveal as="div" className="eyebrow eyebrow--gold eyebrow--center">{t.testimonials.eyebrow}</Reveal>
        <Reveal as="h2" className="h2 h2--cream" delay={80}>{t.testimonials.h2}</Reveal>

        <div className="tmn__grid">
          {t.testimonials.items.map((it, i) => (
            <Reveal as="figure" className="tmn__card" key={i} delay={140 + i * 100}>
              <div className="tmn__quote" aria-hidden="true">“</div>
              <blockquote className="tmn__text">{it.quote}</blockquote>
              <div className="tmn__stars" aria-label="5 stars"><GoldStars count={5} /></div>
              <figcaption className="tmn__attr">— {it.attr}</figcaption>
            </Reveal>
          ))}
        </div>

        <div className="tmn__strip">{t.testimonials.strip}</div>
      </div>
    </section>
  );
}

/* ---------- FAQ accordion ---------- */
function FaqRow({ q, a, idx, open, setOpen }) {
  const ref = useRef(null);
  const isOpen = open === idx;
  return (
    <div className={"faq__row " + (isOpen ? "faq__row--open" : "")}>
      <button className="faq__q" onClick={() => setOpen(isOpen ? -1 : idx)} aria-expanded={isOpen}>
        <span>{q}</span>
        <span className="faq__chev" aria-hidden="true">
          <svg viewBox="0 0 24 24" width="20" height="20"><path fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" d="M6 9l6 6 6-6"/></svg>
        </span>
      </button>
      <div className="faq__a" ref={ref} style={{ maxHeight: isOpen ? (ref.current ? ref.current.scrollHeight + "px" : "800px") : 0 }}>
        <div className="faq__aInner">{a}</div>
      </div>
    </div>
  );
}

function Faq({ t }) {
  const [open, setOpen] = useState(0);
  return (
    <section className="faq" id="faq">
      <div className="container">
        <Reveal as="div" className="eyebrow eyebrow--gold eyebrow--center">{t.faq.eyebrow}</Reveal>
        <Reveal as="h2" className="h2 h2--purple" delay={80}>{t.faq.h2}</Reveal>

        <div className="faq__list">
          {t.faq.items.map((it, i) => (
            <FaqRow key={i} idx={i} q={it.q} a={it.a} open={open} setOpen={setOpen} />
          ))}
        </div>

        <div className="faq__foot">
          <span className="faq__footText">{t.faq.foot}</span>
          <a href={LINKS.default} target="_blank" rel="noopener" className="btn btn--pill btn--gold faq__footCta">{t.faq.foot_cta}</a>
        </div>
      </div>
    </section>
  );
}

/* ---------- finale ---------- */
function Finale({ t }) {
  return (
    <section className="finale">
      <div className="finale__bg" aria-hidden="true"></div>
      <div className="container finale__inner">
        <Reveal as="div" className="finale__avatar">
          <img src="assets/doodee-master-logo.jpg" alt="" />
        </Reveal>
        <Reveal as="h2" className="finale__h2" delay={80}>
          {t.finale.h2_a} <span className="finale__accent">{t.finale.h2_b}</span>
        </Reveal>
        <Reveal as="p" className="finale__sub" delay={160}>{t.finale.sub}</Reveal>
        <Reveal as="a" delay={220} className="btn btn--pill btn--gold btn--giant btn--pulse"
          {...{ href: LINKS.default, target: "_blank", rel: "noopener" }}>
          {t.finale.cta}
        </Reveal>
        <Reveal as="div" className="finale__ctaSub" delay={280}>{t.finale.cta_sub}</Reveal>
      </div>
    </section>
  );
}

/* ---------- footer ---------- */
function Footer({ t }) {
  return (
    <footer className="foot">
      <div className="foot__inner">
        <div className="foot__mark">DOODEE</div>
        <div className="foot__tag1">{t.footer.tag1}</div>
        <div className="foot__tag2">{t.footer.tag2}</div>
        <div className="foot__rule"></div>
        <div className="foot__disclaimer">{t.footer.disclaimer}</div>
        <div className="foot__links">
          {t.footer.links.map((l, i) => (
            <React.Fragment key={i}>
              <a href="#">{l}</a>
              {i < t.footer.links.length - 1 && <span className="foot__sep">·</span>}
            </React.Fragment>
          ))}
        </div>
        <div className="foot__copy">{t.footer.copy}</div>
      </div>
    </footer>
  );
}

/* ---------- root ---------- */
function App() {
  const [lang, setLang] = useState(() => {
    try { return localStorage.getItem("doodee_lang") || "th"; } catch (_) { return "th"; }
  });
  useEffect(() => {
    try { localStorage.setItem("doodee_lang", lang); } catch (_) {}
    document.documentElement.lang = lang === "th" ? "th" : "en";
    document.documentElement.setAttribute("data-lang", lang);
  }, [lang]);
  const t = COPY[lang];
  return (
    <React.Fragment>
      <Nav lang={lang} setLang={setLang} t={t} />
      <Hero lang={lang} t={t} />
      <TrustBand t={t} />
      <About t={t} />
      <Accurate t={t} />
      <Compare t={t} />
      <Pricing t={t} />
      <Services t={t} />
      <HowItWorks t={t} />
      <Testimonials t={t} />
      <Faq t={t} />
      <Finale t={t} />
      <Footer t={t} />
    </React.Fragment>
  );
}

ReactDOM.createRoot(document.getElementById("root")).render(<App />);
