// Mika · 主頁全段落。承接 A 版方向(室友的下午 / 奶茶色 / 水彩貓)。
//
// 插畫槽位 ─ 每個 <IllustrationSlot name=.../> 內部會依 window.MIKA_ILLUSTRATION_MODE
// 決定顯示 SVG 版本(現況)或 PNG 去背版(使用者之後畫)。這讓版面和插畫解耦,
// 未來換成水彩 PNG 不需要動任何段落排版。
//
// 文案集中在 window.MIKA_COPY,直接改字串就可以更新,不用碰版面。

const C = window.MIKA_COLORS;  // from hero-variants.jsx
const HS = window.heroStyles;  // ditto

// ─────────────────────────────────────────────────────────────
// 插畫槽位:三種姿勢,svg 版會用 nogold 版本,png 版會從 uploads/ 讀
// ─────────────────────────────────────────────────────────────
window.IllustrationSlot = function IllustrationSlot({ pose, size = 320, style }) {
  const mode = (window.MIKA_ILLUSTRATION_MODE || 'svg');
  // PNG 之後丟進 uploads/ 後再把這張 map 補上。
  const pngPaths = {
    sleeping: 'uploads/mika-sleeping.png',
    peeking:  'uploads/mika-peeking.png',
    sitting:  'uploads/mika-sitting.png',
  };
  if (mode === 'png' && pngPaths[pose]) {
    return <img src={pngPaths[pose]} width={size} style={{ display: 'block', ...style }} alt={`Mika ${pose}`} />;
  }
  const Svg =
    pose === 'sleeping' ? window.MikaSleepingNoGold :
    pose === 'peeking'  ? window.MikaPeekingNoGold  :
    pose === 'sitting'  ? window.MikaSittingNoGold  : null;
  return Svg ? <Svg size={size} style={style} /> : null;
};

// ─── 共用:SectionLabel ───
// 左側奶油色豎線 + 手寫 eyebrow + 小數字章節號。保持節奏統一。
const SectionLabel = ({ num, eyebrow }) => (
  <div style={{ display: 'flex', alignItems: 'center', gap: 14 }}>
    <span style={{
      fontFamily: '"JetBrains Mono", monospace', fontSize: 12,
      color: C.tea, letterSpacing: '0.25em', opacity: 0.7,
    }}>
      {num}
    </span>
    <span style={{ width: 28, height: 1, background: C.tea, opacity: 0.4 }} />
    <span style={{ ...HS.eyebrow, fontSize: 20 }}>{eyebrow}</span>
  </div>
);

// ─── 共用:PageWidth(主頁每段落都靠這個置中)───
const PageWidth = ({ children, style }) => (
  <div style={{ maxWidth: 1180, margin: '0 auto', padding: '0 80px', ...style }}>
    {children}
  </div>
);

// ═══════════════════════════════════════════════════════════════
// Section 2 · 她是誰 ─ 一段溫柔的自我介紹
// 版面:左窄右寬。左邊是大段 serif 手記;右邊放 peeking 貓 + 小簽名。
// ═══════════════════════════════════════════════════════════════
window.SectionWhoIsMika = function SectionWhoIsMika() {
  const K = window.MIKA_COPY.who;
  return (
    <section data-mika-bg="cream" style={{ padding: '140px 0 120px', position: 'relative' }}>
      <PageWidth>
        <div style={{ display: 'grid', gridTemplateColumns: '1.1fr 0.9fr', gap: 80, alignItems: 'center' }}>
          <div>
            <SectionLabel num="02" eyebrow={K.eyebrow} />
            <h2 style={{
              ...HS.tagline, fontSize: 48, lineHeight: 1.35, margin: '36px 0 28px',
              fontWeight: 400,
            }}>
              {K.title}
            </h2>
            <div style={{ ...HS.sub, fontSize: 18, maxWidth: 480 }}>
              {K.body.map((p, i) => (
                <p key={i} style={{ margin: '0 0 18px' }}>{p}</p>
              ))}
            </div>

            {/* 小簽名 ─ 手寫風 */}
            <div style={{
              marginTop: 44, fontFamily: '"Caveat", cursive', fontSize: 22,
              color: C.moss, display: 'flex', alignItems: 'center', gap: 10,
            }}>
              <span style={{ width: 24, height: 1, background: C.moss, opacity: 0.6 }} />
              {K.signature}
            </div>
          </div>

          <div style={{ display: 'flex', justifyContent: 'center', position: 'relative' }}>
            <window.IllustrationSlot pose="peeking" size={360} />
            {/* 小手寫 caption */}
            <div style={{
              position: 'absolute', bottom: 10, right: 0,
              fontFamily: '"Caveat", cursive', fontSize: 20, color: C.bark, opacity: 0.55,
              transform: 'rotate(-3deg)',
            }}>
              {K.caption}
            </div>
          </div>
        </div>
      </PageWidth>
    </section>
  );
};

// ═══════════════════════════════════════════════════════════════
// Section 3 · 她幫你做什麼 ─ 三個日常場景
// 版面:3 欄並排。每欄一個小圖 + 文字。各欄之間有豎線分隔。
// ═══════════════════════════════════════════════════════════════
window.SectionWhatMikaDoes = function SectionWhatMikaDoes() {
  const K = window.MIKA_COPY.does;
  return (
    <section data-mika-bg="paper" style={{ padding: '120px 0 120px', position: 'relative' }}>
      <PageWidth>
        <SectionLabel num="03" eyebrow={K.eyebrow} />
        <h2 style={{
          ...HS.tagline, fontSize: 48, lineHeight: 1.3, margin: '32px 0 80px',
          fontWeight: 400, maxWidth: 720,
        }}>
          {K.title}
        </h2>

        <div style={{
          display: 'grid', gridTemplateColumns: 'repeat(3, 1fr)', gap: 0,
          borderTop: `1px solid ${C.linen}`, borderBottom: `1px solid ${C.linen}`,
        }}>
          {K.items.map((item, i) => (
            <div key={i} style={{
              padding: '48px 40px',
              borderLeft: i > 0 ? `1px solid ${C.linen}` : 'none',
              position: 'relative',
            }}>
              {/* 小章節號 */}
              <div style={{
                fontFamily: '"JetBrains Mono", monospace', fontSize: 11,
                color: C.tea, opacity: 0.5, letterSpacing: '0.2em', marginBottom: 24,
              }}>
                ― {String(i + 1).padStart(2, '0')} ―
              </div>

              {/* 圖示槽位 ─ 用小 SVG 道具當配圖 */}
              <div style={{ height: 120, display: 'flex', alignItems: 'flex-end', marginBottom: 32 }}>
                <ServiceGlyph kind={item.glyph} />
              </div>

              <h3 style={{
                fontFamily: '"Noto Serif TC", serif', fontSize: 24, fontWeight: 500,
                color: C.tea, margin: '0 0 16px', lineHeight: 1.4,
              }}>
                {item.title}
              </h3>
              <p style={{ ...HS.sub, fontSize: 15, margin: 0 }}>
                {item.body}
              </p>

              {/* 手寫備註 */}
              <div style={{
                marginTop: 28, fontFamily: '"Caveat", cursive', fontSize: 18,
                color: C.moss, opacity: 0.85,
              }}>
                — {item.aside}
              </div>
            </div>
          ))}
        </div>
      </PageWidth>
    </section>
  );
};

// 小道具 SVG ─ 三種對應 item
const ServiceGlyph = ({ kind }) => {
  if (kind === 'folder') {
    // 疊起來的幾張紙 ─ 代表檔案整理
    return (
      <svg viewBox="0 0 140 110" width={110} height={86} aria-hidden="true">
        <defs>
          <filter id="glyph-wc-1"><feTurbulence baseFrequency="0.03" numOctaves="2" seed="4" /><feDisplacementMap in="SourceGraphic" scale="1.5" /></filter>
        </defs>
        <g filter="url(#glyph-wc-1)">
          <rect x="22" y="30" width="90" height="70" fill="#f3ede1" stroke="#8a6f4a" strokeWidth="1" opacity="0.9" transform="rotate(-4 67 65)" />
          <rect x="30" y="22" width="90" height="70" fill="#faf5e6" stroke="#8a6f4a" strokeWidth="1" transform="rotate(3 75 57)" />
          <rect x="26" y="18" width="90" height="70" fill="#f5efdf" stroke="#8a6f4a" strokeWidth="1" />
          <line x1="36" y1="36" x2="100" y2="36" stroke="#8a6f4a" strokeWidth="0.8" opacity="0.5" />
          <line x1="36" y1="48" x2="90" y2="48" stroke="#8a6f4a" strokeWidth="0.8" opacity="0.5" />
          <line x1="36" y1="60" x2="95" y2="60" stroke="#8a6f4a" strokeWidth="0.8" opacity="0.5" />
          <line x1="36" y1="72" x2="78" y2="72" stroke="#8a6f4a" strokeWidth="0.8" opacity="0.5" />
        </g>
      </svg>
    );
  }
  if (kind === 'note') {
    // 翻開的筆記本
    return (
      <svg viewBox="0 0 160 110" width={120} height={82} aria-hidden="true">
        <defs>
          <filter id="glyph-wc-2"><feTurbulence baseFrequency="0.025" numOctaves="2" seed="7" /><feDisplacementMap in="SourceGraphic" scale="1.5" /></filter>
        </defs>
        <g filter="url(#glyph-wc-2)">
          <path d="M 10 20 Q 8 65 12 100 L 80 98 Q 78 65 78 22 Q 45 18 10 20 Z" fill="#faf5e6" stroke="#8a6f4a" strokeWidth="1" />
          <path d="M 80 22 Q 82 65 80 98 L 148 100 Q 150 65 148 20 Q 115 18 80 22 Z" fill="#f5efdf" stroke="#8a6f4a" strokeWidth="1" />
          <g stroke="#8a6f4a" strokeWidth="0.9" fill="none" opacity="0.6" strokeLinecap="round">
            <path d="M 20 38 Q 40 36 65 38" />
            <path d="M 20 50 Q 45 48 70 51" />
            <path d="M 20 62 Q 35 60 55 62" />
            <path d="M 20 76 Q 48 74 72 77" />
            <path d="M 90 40 Q 112 38 140 40" />
            <path d="M 90 54 Q 105 52 125 54" />
            <path d="M 90 68 Q 118 66 140 68" />
          </g>
        </g>
      </svg>
    );
  }
  if (kind === 'cup') {
    // 茶杯(延續 A 版風格)
    return (
      <svg viewBox="0 0 140 120" width={90} height={77} aria-hidden="true">
        <defs>
          <filter id="glyph-wc-3"><feTurbulence baseFrequency="0.025" numOctaves="2" seed="2" /><feDisplacementMap in="SourceGraphic" scale="2" /></filter>
        </defs>
        <g filter="url(#glyph-wc-3)">
          <ellipse cx="70" cy="100" rx="52" ry="12" fill="#e8dfc9" opacity="0.9" />
          <ellipse cx="70" cy="92" rx="40" ry="10" fill="#d4b896" />
          <ellipse cx="70" cy="90" rx="34" ry="8" fill="#8a6f4a" />
          <ellipse cx="70" cy="89" rx="28" ry="6" fill="#a88a66" opacity="0.5" />
        </g>
        <g stroke="#b8a888" strokeWidth="1.2" fill="none" opacity="0.6" strokeLinecap="round">
          <path d="M 56 78 Q 52 64 58 54 Q 64 42 58 32" />
          <path d="M 70 78 Q 74 62 68 52 Q 62 40 70 30" />
          <path d="M 84 78 Q 88 64 82 54 Q 76 42 84 34" />
        </g>
      </svg>
    );
  }
  return null;
};

// ═══════════════════════════════════════════════════════════════
// Section 4 · 她怎麼工作 ─ 一天的時間軸
// 版面:水平時間軸。左 morning / 中 afternoon / 右 evening 三段。
// 中間放一隻睡覺的 Mika ─ 她一直在那,外面光在變。
// ═══════════════════════════════════════════════════════════════
window.SectionADayWith = function SectionADayWith() {
  const K = window.MIKA_COPY.day;
  return (
    <section data-mika-bg="cream" style={{
      padding: '140px 0 140px', position: 'relative', overflow: 'hidden',
    }}>
      {/* 背景:一整片由左到右的光線漸層,象徵一天 */}
      <div style={{
        position: 'absolute', inset: 0, pointerEvents: 'none',
        background: `linear-gradient(95deg,
          rgba(210,220,200,0.25) 0%,
          rgba(245,214,138,0.25) 35%,
          rgba(245,214,138,0.35) 55%,
          rgba(230,180,140,0.25) 80%,
          rgba(120,100,130,0.15) 100%)`,
      }} />

      <PageWidth style={{ position: 'relative' }}>
        <SectionLabel num="04" eyebrow={K.eyebrow} />
        <h2 style={{
          ...HS.tagline, fontSize: 48, lineHeight: 1.3, margin: '32px 0 24px',
          fontWeight: 400, maxWidth: 720,
        }}>
          {K.title}
        </h2>
        <p style={{ ...HS.sub, fontSize: 17, maxWidth: 560, margin: '0 0 80px' }}>
          {K.intro}
        </p>

        {/* 時間軸本體 */}
        <div style={{ position: 'relative', minHeight: 420 }}>
          {/* 橫線 */}
          <div style={{
            position: 'absolute', left: '4%', right: '4%', top: 96, height: 1,
            background: C.bark, opacity: 0.15,
          }} />

          <div style={{
            display: 'grid', gridTemplateColumns: 'repeat(3, 1fr)', gap: 60,
            position: 'relative',
          }}>
            {K.moments.map((m, i) => (
              <div key={i} style={{ position: 'relative', paddingTop: 120 }}>
                {/* 時間標 */}
                <div style={{
                  position: 'absolute', top: 0, left: 0,
                  fontFamily: '"JetBrains Mono", monospace', fontSize: 13,
                  color: C.tea, letterSpacing: '0.15em',
                }}>
                  {m.time}
                </div>
                {/* 小圓點在線上 */}
                <div style={{
                  position: 'absolute', top: 91, left: 0, width: 11, height: 11,
                  borderRadius: '50%', background: C.tea,
                  boxShadow: `0 0 0 4px ${C.cream}`,
                }} />
                {/* 手寫章節 */}
                <div style={{
                  fontFamily: '"Caveat", cursive', fontSize: 24, color: C.moss,
                  position: 'absolute', top: 28, left: 0,
                }}>
                  {m.label}
                </div>

                <h3 style={{
                  fontFamily: '"Noto Serif TC", serif', fontSize: 26, fontWeight: 500,
                  color: C.tea, margin: '0 0 18px', lineHeight: 1.4,
                }}>
                  {m.title}
                </h3>
                <p style={{ ...HS.sub, fontSize: 15, margin: 0 }}>
                  {m.body}
                </p>
              </div>
            ))}
          </div>

          {/* 右下角:睡貓縮圖 ─ 她一直在 */}
          <div style={{
            position: 'absolute', right: -20, bottom: -60, opacity: 0.9,
            transform: 'rotate(-2deg)',
          }}>
            <window.IllustrationSlot pose="sleeping" size={260} />
          </div>
        </div>
      </PageWidth>
    </section>
  );
};

// ═══════════════════════════════════════════════════════════════
// Section 5 · 安靜的承諾 ─ 隱私 / 不吵你 / 不催你
// 版面:置中,一段大段 serif 敘事。像書裡抽出來的一頁。
// ═══════════════════════════════════════════════════════════════
window.SectionQuietPromise = function SectionQuietPromise() {
  const K = window.MIKA_COPY.promise;
  return (
    <section data-mika-bg="paper" style={{
      padding: '160px 0 160px', position: 'relative',
    }}>
      <PageWidth>
        <div style={{ maxWidth: 720, margin: '0 auto', textAlign: 'center' }}>
          <SectionLabel num="05" eyebrow={K.eyebrow} />

          <h2 style={{
            ...HS.tagline, fontSize: 52, lineHeight: 1.35, margin: '40px 0 40px',
            fontWeight: 400, textAlign: 'center',
          }}>
            {K.title}
          </h2>

          {/* 三條小承諾,用橫線分隔 */}
          <div style={{ textAlign: 'left', margin: '48px 0 0' }}>
            {K.items.map((it, i) => (
              <div key={i} style={{
                display: 'grid', gridTemplateColumns: '100px 1fr', gap: 32,
                padding: '28px 0',
                borderTop: `1px solid ${C.linen}`,
                ...(i === K.items.length - 1 ? { borderBottom: `1px solid ${C.linen}` } : {}),
                alignItems: 'baseline',
              }}>
                <div style={{
                  fontFamily: '"Caveat", cursive', fontSize: 28,
                  color: C.moss,
                }}>
                  {it.word}
                </div>
                <div>
                  <h3 style={{
                    fontFamily: '"Noto Serif TC", serif', fontSize: 22, fontWeight: 500,
                    color: C.tea, margin: '0 0 8px',
                  }}>
                    {it.title}
                  </h3>
                  <p style={{ ...HS.sub, fontSize: 16, margin: 0 }}>
                    {it.body}
                  </p>
                </div>
              </div>
            ))}
          </div>
        </div>
      </PageWidth>
    </section>
  );
};

// ═══════════════════════════════════════════════════════════════
// Section 6 · 輕量版 ─ 免費試試(次要 CTA)
// 版面:大片留白,置中。一個坐姿的 Mika + 一個短 CTA。
// ═══════════════════════════════════════════════════════════════
window.SectionLightVersion = function SectionLightVersion() {
  const K = window.MIKA_COPY.light;
  return (
    <section data-mika-bg="cream" style={{
      padding: '140px 0 160px', position: 'relative', overflow: 'hidden',
    }}>
      {/* 窗光 */}
      <div style={{
        position: 'absolute', inset: 0, pointerEvents: 'none',
        background: 'radial-gradient(ellipse 800px 600px at 50% -10%, rgba(255,230,180,0.4), transparent 65%)',
      }} />

      <PageWidth style={{ position: 'relative' }}>
        <div style={{
          display: 'grid', gridTemplateColumns: '0.9fr 1.1fr', gap: 60, alignItems: 'center',
        }}>
          <div style={{ display: 'flex', justifyContent: 'center' }}>
            <window.IllustrationSlot pose="sitting" size={340} />
          </div>

          <div>
            <SectionLabel num="06" eyebrow={K.eyebrow} />
            <h2 style={{
              ...HS.tagline, fontSize: 48, lineHeight: 1.3, margin: '32px 0 24px',
              fontWeight: 400,
            }}>
              {K.title}
            </h2>
            <p style={{ ...HS.sub, fontSize: 18, maxWidth: 480, margin: '0 0 16px' }}>
              {K.body}
            </p>
            <p style={{
              ...HS.sub, fontSize: 14, maxWidth: 460, margin: '0 0 40px', opacity: 0.7,
            }}>
              {K.fineprint}
            </p>

            <div style={{ display: 'flex', gap: 20, alignItems: 'center', flexWrap: 'wrap' }}>
              <window.CTAButton>{K.ctaPrimary}</window.CTAButton>
              <a style={{
                fontFamily: '"Caveat", cursive', fontSize: 22, color: C.tea,
                textDecoration: 'underline', textDecorationStyle: 'wavy',
                textDecorationColor: C.moss, textUnderlineOffset: 6, cursor: 'pointer',
              }}>
                {K.ctaSecondary} →
              </a>
            </div>
          </div>
        </div>
      </PageWidth>
    </section>
  );
};

// ═══════════════════════════════════════════════════════════════
// Section 7 · Footer ─ 簽名式
// 版面:一大段置中的手寫 tagline 再出現一次,然後下面是極簡 links + 版權。
// ═══════════════════════════════════════════════════════════════
window.SectionFooter = function SectionFooter() {
  const K = window.MIKA_COPY.footer;
  return (
    <footer data-mika-bg="paper" style={{
      padding: '120px 0 48px', position: 'relative',
      borderTop: `1px solid ${C.linen}`,
    }}>
      <PageWidth>
        <div style={{ textAlign: 'center', marginBottom: 80 }}>
          <div style={{
            fontFamily: '"Homemade Apple", "Caveat", cursive', fontSize: 36,
            color: C.tea, margin: '0 0 16px', lineHeight: 1.6,
          }}>
            {K.signoff}
          </div>
          <div style={{
            fontFamily: '"Caveat", cursive', fontSize: 22,
            color: C.bark, opacity: 0.55,
          }}>
            — {K.signature}
          </div>
        </div>

        <div style={{
          display: 'grid', gridTemplateColumns: 'repeat(4, 1fr)', gap: 40,
          borderTop: `1px solid ${C.linen}`, paddingTop: 48, marginBottom: 64,
        }}>
          {K.columns.map((col, i) => (
            <div key={i}>
              <div style={{
                fontFamily: '"JetBrains Mono", monospace', fontSize: 11,
                color: C.tea, letterSpacing: '0.25em', opacity: 0.7, marginBottom: 18,
              }}>
                {col.head.toUpperCase()}
              </div>
              {col.links.map((l, j) => (
                <div key={j} style={{
                  ...HS.sub, fontSize: 15, margin: '0 0 10px', cursor: 'pointer',
                }}>
                  {l}
                </div>
              ))}
            </div>
          ))}
        </div>

        <div style={{
          display: 'flex', justifyContent: 'space-between', alignItems: 'center',
          fontFamily: '"JetBrains Mono", monospace', fontSize: 12,
          color: C.bark, opacity: 0.55, letterSpacing: '0.1em',
          paddingTop: 24, borderTop: `1px solid ${C.linen}`,
        }}>
          <div>© {new Date().getFullYear()} Mika · made slowly</div>
          <div>{K.madeIn}</div>
        </div>
      </PageWidth>
    </footer>
  );
};
