// ————————————————————————————————————————————————
// BIBLIOTECA · Recursos — ebooks gratuitos
// ————————————————————————————————————————————————

const { useState: useStateB } = React;

const pal = {
  cream: '#EDE4D3',
  creamDeep: '#E4D9C3',
  creamLighter: '#F3ECDD',
  olive: '#3F4528',
  oliveMid: '#5E6337',
  oliveDeep: '#2B3A2B',
  mustard: '#A8792B',
  mustardDark: '#8A6320',
  clay: '#8A4B2C',
  clayDeep: '#5C3218',
};

const RuleB = ({ opacity = 0.18, my = 0 }) => (
  <div style={{ height: 1, background: pal.olive, opacity, margin: `${my}px 0` }} />
);

const EyebrowB = ({ children, color = pal.clay, style }) => (
  <div style={{
    fontFamily: 'Inter, sans-serif',
    fontSize: 10.5,
    fontWeight: 500,
    letterSpacing: '0.22em',
    textTransform: 'uppercase',
    color,
    ...style,
  }}>{children}</div>
);

// ————————————————————————————————————————————————
// Mockup pequeno de livro para cada guia — cores variam
// ————————————————————————————————————————————————
const GuideMock = ({ color = pal.mustard, accent = pal.mustardDark, iconPath, placeholder = false, coverVariant }) => (
  <div style={{
    width: '100%',
    aspectRatio: '3/4',
    position: 'relative',
  }}>
    {/* Sombra */}
    <div style={{
      position: 'absolute',
      bottom: -4,
      left: 8,
      right: 8,
      height: 6,
      background: pal.olive,
      opacity: 0.14,
      filter: 'blur(5px)',
      borderRadius: '50%',
    }} />
    {/* Lombada */}
    {!placeholder && (
      <div style={{
        position: 'absolute',
        left: -3,
        top: 2,
        bottom: 2,
        width: 5,
        background: accent,
        transform: 'skewY(-3deg)',
        transformOrigin: 'right',
      }} />
    )}
    {/* Capa */}
    <div style={{
      position: 'absolute',
      inset: 0,
      background: placeholder
        ? `repeating-linear-gradient(135deg, ${pal.creamDeep} 0px, ${pal.creamDeep} 7px, #DDD0B5 7px, #DDD0B5 8px)`
        : coverVariant === 'jardim' ? '#243322'
        : coverVariant === 'parasitas' ? '#F3ECDD'
        : coverVariant === 'ciclo' ? '#F3ECDD'
        : coverVariant === 'sono' ? '#1B2838'
        : color,
      border: placeholder ? `1px dashed ${pal.olive}44` : `1px solid ${accent}`,
      display: 'flex',
      alignItems: 'center',
      justifyContent: 'center',
      boxShadow: placeholder ? 'none' : `inset -3px 0 5px ${accent}55`,
      overflow: 'hidden',
    }}>
      {!placeholder && coverVariant === 'jardim' && (
        <img
          src={(typeof window !== 'undefined' && window.__resources && window.__resources.jardimImg) || 'assets/jardim-cover.png'}
          alt="Intestino e imunidade da criança"
          style={{ width: '100%', height: '100%', objectFit: 'cover', display: 'block' }}
        />
      )}
      {!placeholder && coverVariant === 'parasitas' && (
        <img
          src={(typeof window !== 'undefined' && window.__resources && window.__resources.parasitasImg) || 'assets/parasitas-cover.png'}
          alt="Guia dos Parasitas — Parasitas e o Intestino da Criança"
          style={{ width: '100%', height: '100%', objectFit: 'cover', display: 'block' }}
        />
      )}
      {!placeholder && coverVariant === 'ciclo' && (
        <img
          src={(typeof window !== 'undefined' && window.__resources && window.__resources.cicloImg) || 'assets/ciclo-cover.png'}
          alt="Mapa do ciclo da doença na criança"
          style={{ width: '100%', height: '100%', objectFit: 'cover', display: 'block' }}
        />
      )}
      {!placeholder && coverVariant === 'sono' && (
        <img
          src={(typeof window !== 'undefined' && window.__resources && window.__resources.sonoImg) || 'assets/sono-cover.png'}
          alt="Rituais do sono para honrar a noite"
          style={{ width: '100%', height: '100%', objectFit: 'cover', display: 'block' }}
        />
      )}
      {!placeholder && !coverVariant && (
        <svg viewBox="0 0 40 40" width="38%" height="38%" fill="none" stroke={pal.cream} strokeWidth="1.2" strokeLinecap="round" strokeLinejoin="round">
          {iconPath}
        </svg>
      )}
      {placeholder && (
        <div style={{
          fontFamily: 'Inter, sans-serif',
          fontSize: 8.5,
          letterSpacing: '0.22em',
          textTransform: 'uppercase',
          color: pal.oliveMid,
          opacity: 0.7,
          background: pal.cream,
          padding: '5px 8px',
          border: `1px solid ${pal.olive}33`,
        }}>em breve</div>
      )}
    </div>
  </div>
);

// ————————————————————————————————————————————————
// Capa especial "O Jardim Interior" — espelha a arte original
// fundo verde escuro · silhueta de criança · flora + intestino · título serif coral
// ————————————————————————————————————————————————
const JardimCover = () => (
  <svg viewBox="0 0 120 160" width="100%" height="100%" style={{ display: 'block' }}>
    <defs>
      <radialGradient id="jc-glow" cx="0.5" cy="0.58" r="0.5">
        <stop offset="0%" stopColor="#5A6A3A" stopOpacity="0.55" />
        <stop offset="55%" stopColor="#3B4A2A" stopOpacity="0.25" />
        <stop offset="100%" stopColor="#243322" stopOpacity="0" />
      </radialGradient>
      <linearGradient id="jc-child" x1="0" y1="0" x2="0" y2="1">
        <stop offset="0%" stopColor="#D4A58A" />
        <stop offset="100%" stopColor="#B47460" />
      </linearGradient>
      <linearGradient id="jc-gut" x1="0" y1="0" x2="0" y2="1">
        <stop offset="0%" stopColor="#E89A82" />
        <stop offset="100%" stopColor="#C87A5E" />
      </linearGradient>
    </defs>

    {/* Fundo verde profundo */}
    <rect x="0" y="0" width="120" height="160" fill="#243322" />
    <ellipse cx="60" cy="92" rx="55" ry="50" fill="url(#jc-glow)" />

    {/* Moldura botânica fina */}
    <g stroke="#3D5030" strokeWidth="0.5" fill="none" opacity="0.9">
      <path d="M4 8 Q10 24 6 44 Q12 60 4 80" />
      <path d="M116 8 Q110 24 114 44 Q108 60 116 80" />
      <path d="M4 152 Q10 140 6 124" />
      <path d="M116 152 Q110 140 114 124" />
    </g>
    <g fill="#3D5030" opacity="0.85">
      <ellipse cx="8" cy="20" rx="2.2" ry="1" transform="rotate(-30 8 20)" />
      <ellipse cx="10" cy="64" rx="2.2" ry="1" transform="rotate(20 10 64)" />
      <ellipse cx="112" cy="20" rx="2.2" ry="1" transform="rotate(30 112 20)" />
      <ellipse cx="110" cy="64" rx="2.2" ry="1" transform="rotate(-20 110 64)" />
    </g>

    {/* Título coral */}
    <text x="60" y="22" textAnchor="middle" fill="#E89A82"
      fontFamily="Cormorant Garamond, serif" fontSize="11" fontWeight="600"
      letterSpacing="-0.1">O Jardim Interior</text>
    <text x="60" y="32" textAnchor="middle" fill="#D4B683"
      fontFamily="Cormorant Garamond, serif" fontStyle="italic" fontSize="4" fontWeight="400">
      Intestino + imunidade da criança
    </text>

    {/* ——— Criança (esquerda) + Intestino (direita) ——— */}

    {/* Criança — silhueta de perfil, pequena, à esquerda */}
    <g>
      {/* cabelo-folhas */}
      <path d="M30 58 Q28 52 32 50 Q35 48 38 52 Q42 50 44 54 Q42 58 38 58 Q34 58 30 58 Z"
        fill="#6A8040" stroke="#4A5C30" strokeWidth="0.4" />
      <ellipse cx="29" cy="54" rx="1.6" ry="0.8" transform="rotate(-40 29 54)" fill="#7A9050" />
      <ellipse cx="43" cy="54" rx="1.6" ry="0.8" transform="rotate(40 43 54)" fill="#7A9050" />

      {/* cabeça */}
      <path d="M32 62 Q30 70 34 76 Q40 80 44 76 Q46 70 44 62 Q40 58 36 58 Q32 58 32 62 Z"
        fill="url(#jc-child)" stroke="#8F5540" strokeWidth="0.4" />
      {/* olho */}
      <circle cx="42" cy="68" r="0.6" fill="#3F2A18" />
      {/* bochecha */}
      <circle cx="43" cy="72" r="1.2" fill="#E89A82" opacity="0.4" />

      {/* pescoço */}
      <rect x="36" y="79" width="6" height="4" fill="url(#jc-child)" />

      {/* tronco */}
      <path d="M30 84 Q28 100 32 116 L46 116 Q50 100 48 84 Q46 82 42 82 L36 82 Q32 82 30 84 Z"
        fill="url(#jc-child)" stroke="#8F5540" strokeWidth="0.4" />

      {/* coração no peito — pequenina flor */}
      <path d="M38 92 C 37 90, 35 90, 35 92 C 35 94, 38 96, 38 96 C 38 96, 41 94, 41 92 C 41 90, 39 90, 38 92 Z"
        fill="#E89A82" />
    </g>

    {/* Linha de conexão delicada entre criança e intestino */}
    <g stroke="#D7A350" strokeWidth="0.5" strokeDasharray="1.5 1.5" fill="none" opacity="0.7">
      <path d="M48 100 Q60 98 72 100" />
    </g>
    {/* pequeno coração a meio */}
    <path d="M60 99 C 59.3 97.8, 57.8 97.8, 57.8 99.3 C 57.8 100.6, 60 102.2, 60 102.2 C 60 102.2, 62.2 100.6, 62.2 99.3 C 62.2 97.8, 60.7 97.8, 60 99 Z"
      fill="#E89A82" opacity="0.85" />

    {/* Intestino — forma anatómica à direita, em coral */}
    <g>
      {/* "vaso" que o contém — oval suave */}
      <ellipse cx="86" cy="94" rx="18" ry="26" fill="#2E3D25" stroke="#4A5C30" strokeWidth="0.5" />
      <ellipse cx="86" cy="94" rx="14" ry="22" fill="none" stroke="#A87830" strokeWidth="0.3" strokeDasharray="1 1" opacity="0.5" />

      {/* intestino enrolado — laços */}
      <g fill="none" stroke="url(#jc-gut)" strokeWidth="3.2" strokeLinecap="round">
        <path d="M82 78 Q76 82 82 88 Q92 90 94 84 Q96 80 92 78" />
        <path d="M78 92 Q74 98 80 102 Q92 104 94 98 Q96 94 92 92" />
        <path d="M80 106 Q76 112 82 116 Q92 118 94 112 Q96 108 92 106" />
      </g>
      {/* microbiota — pontos + flores minúsculas dentro */}
      <g>
        <circle cx="80" cy="84" r="0.6" fill="#D4B683" />
        <circle cx="92" cy="88" r="0.5" fill="#8FA55E" />
        <circle cx="84" cy="98" r="0.7" fill="#E89A82" />
        <circle cx="91" cy="102" r="0.5" fill="#D4B683" />
        <circle cx="82" cy="112" r="0.6" fill="#8FA55E" />
        <circle cx="93" cy="114" r="0.5" fill="#E89A82" />
      </g>
    </g>

    {/* Flora a sair do intestino (brotos de saúde) */}
    <g>
      <path d="M86 68 Q84 64 86 60" stroke="#6A8040" strokeWidth="0.6" fill="none" />
      <ellipse cx="85" cy="62" rx="1.8" ry="0.9" transform="rotate(-30 85 62)" fill="#8FA55E" />
      <ellipse cx="88" cy="64" rx="1.6" ry="0.8" transform="rotate(30 88 64)" fill="#7A9050" />
      <circle cx="86" cy="58" r="1.3" fill="#E89A82" />
      <circle cx="86" cy="58" r="0.5" fill="#FFF0D4" />
    </g>

    {/* Pequenos frutos/flores entre ambos — simboliza equilíbrio */}
    <g>
      <circle cx="52" cy="108" r="1.2" fill="#D7A350" />
      <circle cx="56" cy="114" r="1" fill="#E89A82" />
      <circle cx="64" cy="112" r="1" fill="#8FA55E" />
      <circle cx="70" cy="108" r="1.2" fill="#D4B683" />
    </g>

    {/* Folhas decorativas laterais da composição */}
    <g>
      <path d="M20 84 Q14 86 12 92" stroke="#6A8040" strokeWidth="0.5" fill="none" />
      <ellipse cx="14" cy="90" rx="2" ry="1" transform="rotate(-30 14 90)" fill="#6A8040" />
      <path d="M108 128 Q114 126 116 120" stroke="#6A8040" strokeWidth="0.5" fill="none" />
      <ellipse cx="114" cy="124" rx="2" ry="1" transform="rotate(30 114 124)" fill="#6A8040" />
    </g>

    {/* Rodapé */}
    <line x1="44" y1="148" x2="76" y2="148" stroke="#A87830" strokeWidth="0.4" opacity="0.7" />
    <text x="60" y="154" textAnchor="middle" fill="#D4B683"
      fontFamily="Inter, sans-serif" fontSize="3" fontWeight="500"
      letterSpacing="0.5" opacity="0.85">DRA. BRUNA · 2026</text>
  </svg>
);


// ————————————————————————————————————————————————
// Capa especial "Guia Prático: Parasitas e o Intestino da Criança"
// fundo creme · título sans-serif navy · jardim + silhueta de criança agachada
// ————————————————————————————————————————————————
const ParasitasCover = () => (
  <svg viewBox="0 0 120 160" width="100%" height="100%" style={{ display: 'block' }}>
    <defs>
      <radialGradient id="pc-glow" cx="0.5" cy="0.62" r="0.42">
        <stop offset="0%" stopColor="#FFE8B8" stopOpacity="0.85" />
        <stop offset="60%" stopColor="#F3ECDD" stopOpacity="0.3" />
        <stop offset="100%" stopColor="#F3ECDD" stopOpacity="0" />
      </radialGradient>
      <linearGradient id="pc-body" x1="0" y1="0" x2="0" y2="1">
        <stop offset="0%" stopColor="#D4A58A" />
        <stop offset="100%" stopColor="#B47460" />
      </linearGradient>
      <linearGradient id="pc-gut" x1="0" y1="0" x2="0" y2="1">
        <stop offset="0%" stopColor="#E89A82" />
        <stop offset="100%" stopColor="#C87A5E" />
      </linearGradient>
    </defs>

    {/* Fundo creme */}
    <rect x="0" y="0" width="120" height="160" fill="#F3ECDD" />

    {/* Halo quente atrás da criança */}
    <ellipse cx="60" cy="105" rx="40" ry="28" fill="url(#pc-glow)" />

    {/* Título — navy, 3 linhas */}
    <text x="60" y="16" textAnchor="middle" fill="#1F3044"
      fontFamily="Inter, sans-serif" fontSize="8.5" fontWeight="700"
      letterSpacing="-0.25">O Guia Prático:</text>
    <text x="60" y="26" textAnchor="middle" fill="#1F3044"
      fontFamily="Inter, sans-serif" fontSize="7.8" fontWeight="700"
      letterSpacing="-0.25">Parasitas e o Intestino</text>
    <text x="60" y="35" textAnchor="middle" fill="#1F3044"
      fontFamily="Inter, sans-serif" fontSize="7.8" fontWeight="700"
      letterSpacing="-0.25">da Criança</text>

    {/* Subtítulo — serif mustard itálico */}
    <text x="60" y="46" textAnchor="middle" fill="#A87830"
      fontFamily="Cormorant Garamond, serif" fontStyle="italic" fontSize="4" fontWeight="400">
      O que todos os pais precisam de saber
    </text>
    <text x="60" y="52" textAnchor="middle" fill="#A87830"
      fontFamily="Cormorant Garamond, serif" fontStyle="italic" fontSize="4" fontWeight="400">
      sobre estes intrusos invisíveis.
    </text>

    {/* ——— CENA: CORPO + INTESTINO + PARASITAS ——— */}
    {/* Halo quente central */}
    <ellipse cx="60" cy="100" rx="42" ry="34" fill="url(#pc-glow)" />

    {/* Torso/contorno de criança — enquadramento anatómico editorial */}
    <g>
      {/* silhueta do tronco (ombros + abdómen) */}
      <path d="M38 72 Q38 68 42 66 Q50 63 60 63 Q70 63 78 66 Q82 68 82 72 L84 130 Q84 134 80 134 L40 134 Q36 134 36 130 Z"
        fill="url(#pc-body)" opacity="0.85" stroke="#8F5540" strokeWidth="0.4" />
      {/* pescoço */}
      <rect x="55" y="58" width="10" height="8" fill="url(#pc-body)" opacity="0.85" stroke="#8F5540" strokeWidth="0.4" />
      {/* sombra na base do pescoço */}
      <ellipse cx="60" cy="66" rx="6" ry="1.5" fill="#8F5540" opacity="0.25" />
    </g>

    {/* "Janela anatómica" — oval creme que abre o abdómen */}
    <ellipse cx="60" cy="100" rx="22" ry="26" fill="#FFF6DD" opacity="0.72" stroke="#A87830" strokeWidth="0.4" strokeDasharray="1.5 1" />

    {/* INTESTINO enrolado — coral, dentro da janela */}
    <g fill="none" stroke="url(#pc-gut)" strokeWidth="3.6" strokeLinecap="round" strokeLinejoin="round">
      <path d="M52 84 Q48 90 52 94 Q62 96 68 92 Q72 90 68 86" />
      <path d="M48 96 Q44 102 50 106 Q62 110 70 104 Q74 100 70 96" />
      <path d="M48 108 Q46 114 52 118 Q64 120 72 116 Q74 114 72 108" />
    </g>
    {/* traços claros no intestino para textura */}
    <g stroke="#FFD4B8" strokeWidth="0.4" fill="none" opacity="0.8">
      <path d="M54 88 Q58 89 64 88" />
      <path d="M52 100 Q60 101 68 100" />
      <path d="M54 112 Q62 113 70 112" />
    </g>

    {/* PARASITAS — vermes estilizados dentro e fora da janela */}
    <g>
      {/* verme 1 — dentro, em curva S */}
      <path d="M56 90 Q58 88 60 90 Q62 92 64 90 Q66 88 68 90"
        fill="none" stroke="#3F4528" strokeWidth="1" strokeLinecap="round" />
      <circle cx="55.5" cy="90" r="0.7" fill="#3F4528" />

      {/* verme 2 — maior, dentro inferior */}
      <path d="M52 114 Q55 112 58 114 Q61 116 64 114 Q67 112 70 114"
        fill="none" stroke="#5A3A28" strokeWidth="1.1" strokeLinecap="round" />
      <circle cx="51.5" cy="114" r="0.75" fill="#5A3A28" />

      {/* quisto oval */}
      <ellipse cx="66" cy="102" rx="2" ry="1.1" fill="#8B6A3B" stroke="#5A3A28" strokeWidth="0.4" />
      <circle cx="66" cy="102" r="0.4" fill="#3F2A18" />

      {/* quisto 2 */}
      <ellipse cx="54" cy="104" rx="1.6" ry="0.9" fill="#A87830" stroke="#5A3A28" strokeWidth="0.3" />

      {/* verme solto flutuando fora da janela — direita */}
      <path d="M92 92 Q94 90 96 92 Q98 94 100 92 Q102 90 104 92"
        fill="none" stroke="#5A3A28" strokeWidth="0.9" strokeLinecap="round" opacity="0.75" />
      <circle cx="91.5" cy="92" r="0.6" fill="#5A3A28" opacity="0.75" />

      {/* verme solto fora — esquerda */}
      <path d="M16 110 Q18 108 20 110 Q22 112 24 110"
        fill="none" stroke="#5A3A28" strokeWidth="0.9" strokeLinecap="round" opacity="0.7" />
      <circle cx="15.5" cy="110" r="0.55" fill="#5A3A28" opacity="0.7" />

      {/* ovos pequenos (pontos duplos) */}
      <g fill="#5A3A28" opacity="0.6">
        <circle cx="88" cy="108" r="0.6" />
        <circle cx="90" cy="109" r="0.5" />
        <circle cx="28" cy="94" r="0.55" />
        <circle cx="30" cy="95" r="0.45" />
        <circle cx="100" cy="120" r="0.6" />
      </g>
    </g>

    {/* Lupa editorial — canto superior direito sobre o corpo */}
    <g>
      <line x1="94" y1="78" x2="100" y2="84" stroke="#3F4528" strokeWidth="1.2" strokeLinecap="round" />
      <circle cx="90" cy="74" r="7" fill="#FFF6DD" stroke="#3F4528" strokeWidth="1" opacity="0.92" />
      {/* mini verme dentro da lupa */}
      <path d="M86 74 Q88 72 90 74 Q92 76 94 74"
        fill="none" stroke="#5A3A28" strokeWidth="0.9" strokeLinecap="round" />
      <circle cx="85.8" cy="74" r="0.5" fill="#5A3A28" />
    </g>

    {/* Folhinhas de ervas/plantas medicinais a enquadrar em baixo */}
    <g>
      <path d="M14 138 Q10 134 12 128 Q16 130 18 134 Z" fill="#7A9050" stroke="#4A5C30" strokeWidth="0.3" />
      <path d="M20 142 Q18 136 22 132 Q26 136 24 142 Z" fill="#8FA55E" stroke="#4A5C30" strokeWidth="0.3" />
      <path d="M106 138 Q110 134 108 128 Q104 130 102 134 Z" fill="#7A9050" stroke="#4A5C30" strokeWidth="0.3" />
      <path d="M100 142 Q102 136 98 132 Q94 136 96 142 Z" fill="#8FA55E" stroke="#4A5C30" strokeWidth="0.3" />
      {/* pequenas flores */}
      <circle cx="17" cy="132" r="1.4" fill="#E89A82" />
      <circle cx="17" cy="132" r="0.5" fill="#FFF6DD" />
      <circle cx="103" cy="132" r="1.4" fill="#D7A350" />
      <circle cx="103" cy="132" r="0.5" fill="#FFF6DD" />
    </g>

    {/* Tag-pill no rodapé */}
    <rect x="18" y="145" width="84" height="9" rx="4.5" fill="#D8E3E8" stroke="#9BB8C8" strokeWidth="0.3" />
    <text x="60" y="151" textAnchor="middle" fill="#3E5462"
      fontFamily="Cormorant Garamond, serif" fontStyle="italic" fontSize="3.8" fontWeight="500">
      Um manual visual de sintomas e soluções.
    </text>
  </svg>
);

// ————————————————————————————————————————————————
// Capa especial "Mapa do ciclo da doença"
// fundo creme · círculo das 4 fases com setas e pontos mustard
// ————————————————————————————————————————————————
const CicloCover = () => {
  const cx = 60, cy = 92, r = 30;
  // 4 pontos cardinais: topo, direita, baixo, esquerda
  const pts = [
    { x: cx, y: cy - r, label: 'Crise aguda', fase: '01', sub: 'Febre. Otite.' },
    { x: cx + r, y: cy, label: 'Resposta', fase: '02', sub: 'Consulta.' },
    { x: cx, y: cy + r, label: 'Melhora', fase: '03', sub: 'Uma semana boa.' },
    { x: cx - r, y: cy, label: 'Recaída', fase: '04', sub: 'Outra vez.' },
  ];
  return (
    <svg viewBox="0 0 120 160" width="100%" height="100%" style={{ display: 'block' }}>
      {/* Fundo creme */}
      <rect x="0" y="0" width="120" height="160" fill="#F3ECDD" />

      {/* Título topo */}
      <text x="60" y="16" textAnchor="middle" fill="#3F4528"
        fontFamily="Cormorant Garamond, serif" fontSize="9.5" fontWeight="600"
        letterSpacing="-0.1">Mapa do ciclo</text>
      <text x="60" y="26" textAnchor="middle" fill="#3F4528"
        fontFamily="Cormorant Garamond, serif" fontSize="9.5" fontWeight="600"
        letterSpacing="-0.1">da doença</text>

      {/* Filete mustard */}
      <line x1="48" y1="32" x2="72" y2="32" stroke="#A87830" strokeWidth="0.5" />

      {/* Círculo principal — linha mustard */}
      <circle cx={cx} cy={cy} r={r} fill="none" stroke="#A87830" strokeWidth="0.6" />
      {/* Círculo interno pontilhado */}
      <circle cx={cx} cy={cy} r={r - 10} fill="none" stroke="#A87830" strokeWidth="0.3" strokeDasharray="1 1.5" opacity="0.6" />

      {/* Centro — pergunta */}
      <text x={cx} y={cy - 2} textAnchor="middle" fill="#B65A3E"
        fontFamily="Inter, sans-serif" fontSize="3" fontWeight="600"
        letterSpacing="0.5">O QUE VÊS</text>
      <line x1={cx - 8} y1={cy + 1} x2={cx + 8} y2={cy + 1} stroke="#A87830" strokeWidth="0.3" />
      <text x={cx} y={cy + 6} textAnchor="middle" fill="#3F4528"
        fontFamily="Cormorant Garamond, serif" fontStyle="italic" fontSize="4">E se não</text>
      <text x={cx} y={cy + 11} textAnchor="middle" fill="#3F4528"
        fontFamily="Cormorant Garamond, serif" fontStyle="italic" fontSize="4">estiver no</text>
      <text x={cx} y={cy + 16} textAnchor="middle" fill="#3F4528"
        fontFamily="Cormorant Garamond, serif" fontStyle="italic" fontSize="4">
        ciclo, mas por <tspan fill="#B65A3E" fontWeight="600">baixo</tspan> dele?
      </text>

      {/* Pontos + setas nas fases */}
      {pts.map((p, i) => (
        <circle key={i} cx={p.x} cy={p.y} r="1.6" fill="#B65A3E" />
      ))}

      {/* Setas verde-olive direcionais nos quadrantes (entre pontos) */}
      <g fill="#4A5C30">
        {/* NE (entre topo e direita) */}
        <polygon points="86,86 82,84 85,90" transform="rotate(45 84 87)" />
        {/* SE (entre direita e baixo) */}
        <polygon points="86,98 82,100 85,94" transform="rotate(-45 84 97)" />
        {/* SW (entre baixo e esquerda) */}
        <polygon points="34,98 38,100 35,94" transform="rotate(45 36 97)" />
        {/* NW (entre esquerda e topo) */}
        <polygon points="34,86 38,84 35,90" transform="rotate(-45 36 87)" />
      </g>

      {/* Labels das 4 fases */}
      {/* Topo — Crise aguda */}
      <text x={cx} y={cy - r - 10} textAnchor="middle" fill="#B65A3E"
        fontFamily="Cormorant Garamond, serif" fontStyle="italic" fontSize="3" fontWeight="500"
        letterSpacing="0.3">FASE · 01</text>
      <text x={cx} y={cy - r - 4} textAnchor="middle" fill="#3F4528"
        fontFamily="Cormorant Garamond, serif" fontSize="5.5" fontWeight="600">Crise aguda</text>

      {/* Direita — Resposta */}
      <text x={cx + r + 4} y={cy - 4} fill="#B65A3E"
        fontFamily="Cormorant Garamond, serif" fontStyle="italic" fontSize="2.8" fontWeight="500"
        letterSpacing="0.3">FASE · 02</text>
      <text x={cx + r + 4} y={cy + 2} fill="#3F4528"
        fontFamily="Cormorant Garamond, serif" fontSize="5" fontWeight="600">Resposta</text>

      {/* Baixo — Melhora */}
      <text x={cx} y={cy + r + 8} textAnchor="middle" fill="#B65A3E"
        fontFamily="Cormorant Garamond, serif" fontStyle="italic" fontSize="3" fontWeight="500"
        letterSpacing="0.3">FASE · 03</text>
      <text x={cx} y={cy + r + 14} textAnchor="middle" fill="#3F4528"
        fontFamily="Cormorant Garamond, serif" fontSize="5" fontWeight="600">Melhora aparente</text>

      {/* Esquerda — Recaída */}
      <text x={cx - r - 4} y={cy - 4} textAnchor="end" fill="#B65A3E"
        fontFamily="Cormorant Garamond, serif" fontStyle="italic" fontSize="2.8" fontWeight="500"
        letterSpacing="0.3">FASE · 04</text>
      <text x={cx - r - 4} y={cy + 2} textAnchor="end" fill="#3F4528"
        fontFamily="Cormorant Garamond, serif" fontSize="5" fontWeight="600">Recaída</text>

      {/* Rodapé — filete de fecho */}
      <line x1="50" y1="148" x2="70" y2="148" stroke="#A87830" strokeWidth="0.4" opacity="0.6" />
    </svg>
  );
};

// ————————————————————————————————————————————————
// Capa especial "Rituais do sono"
// fundo azul-noite profundo · lua + estrelas · criança adormecida + halo
// ————————————————————————————————————————————————
const SonoCover = () => (
  <svg viewBox="0 0 120 160" width="100%" height="100%" style={{ display: 'block' }}>
    <defs>
      <radialGradient id="sc-sky" cx="0.5" cy="0.3" r="0.8">
        <stop offset="0%" stopColor="#2C3E56" />
        <stop offset="60%" stopColor="#1F2E42" />
        <stop offset="100%" stopColor="#141E2C" />
      </radialGradient>
      <radialGradient id="sc-glow" cx="0.5" cy="0.62" r="0.38">
        <stop offset="0%" stopColor="#F5D88A" stopOpacity="0.55" />
        <stop offset="50%" stopColor="#E3A868" stopOpacity="0.2" />
        <stop offset="100%" stopColor="#1B2838" stopOpacity="0" />
      </radialGradient>
      <radialGradient id="sc-moon" cx="0.4" cy="0.4" r="0.6">
        <stop offset="0%" stopColor="#FDF1CE" />
        <stop offset="100%" stopColor="#E8C77A" />
      </radialGradient>
      <linearGradient id="sc-blanket" x1="0" y1="0" x2="0" y2="1">
        <stop offset="0%" stopColor="#C87A5E" />
        <stop offset="100%" stopColor="#8F4D36" />
      </linearGradient>
    </defs>

    {/* Céu noturno */}
    <rect x="0" y="0" width="120" height="160" fill="url(#sc-sky)" />

    {/* Estrelas esparsas */}
    <g fill="#F5E8C4" opacity="0.85">
      <circle cx="14" cy="20" r="0.6" />
      <circle cx="28" cy="14" r="0.4" />
      <circle cx="38" cy="22" r="0.5" />
      <circle cx="18" cy="34" r="0.4" />
      <circle cx="102" cy="18" r="0.5" />
      <circle cx="110" cy="28" r="0.4" />
      <circle cx="96" cy="40" r="0.5" />
      <circle cx="8" cy="48" r="0.4" />
      <circle cx="112" cy="54" r="0.4" />
      <circle cx="4" cy="72" r="0.4" />
      <circle cx="116" cy="80" r="0.5" />
      <circle cx="22" cy="68" r="0.3" />
      <circle cx="100" cy="72" r="0.3" />
    </g>
    {/* Estrelas 4-ponta — algumas mais vincadas */}
    <g fill="#FDF1CE" opacity="0.95">
      <path d="M30 40 L30.6 41 L32 41.4 L30.6 41.8 L30 43 L29.4 41.8 L28 41.4 L29.4 41 Z" />
      <path d="M92 30 L92.6 31 L94 31.4 L92.6 31.8 L92 33 L91.4 31.8 L90 31.4 L91.4 31 Z" />
      <path d="M14 58 L14.6 59 L16 59.4 L14.6 59.8 L14 61 L13.4 59.8 L12 59.4 L13.4 59 Z" />
    </g>

    {/* Lua crescente no canto superior */}
    <g>
      <circle cx="92" cy="54" r="10" fill="url(#sc-moon)" opacity="0.95" />
      {/* sombra da lua — recorte crescente */}
      <circle cx="96" cy="52" r="9" fill="#1F2E42" />
      {/* brilho subtil */}
      <circle cx="92" cy="54" r="10" fill="none" stroke="#F5D88A" strokeWidth="0.3" opacity="0.4" />
    </g>

    {/* Título — cream serif */}
    <text x="60" y="22" textAnchor="middle" fill="#F5E8C4"
      fontFamily="Cormorant Garamond, serif" fontSize="11" fontWeight="600"
      letterSpacing="-0.15">Rituais do Sono</text>

    {/* Subtítulo — dusty blue italic */}
    <text x="60" y="34" textAnchor="middle" fill="#9BB4CC"
      fontFamily="Cormorant Garamond, serif" fontStyle="italic" fontSize="4.2" fontWeight="400">
      Um guia para honrar a noite
    </text>
    <text x="60" y="40" textAnchor="middle" fill="#9BB4CC"
      fontFamily="Cormorant Garamond, serif" fontStyle="italic" fontSize="4.2" fontWeight="400">
      dos teus filhos
    </text>

    {/* Halo quente em redor da cama */}
    <ellipse cx="60" cy="108" rx="44" ry="32" fill="url(#sc-glow)" />

    {/* ——— Cena: criança adormecida em cama ——— */}

    {/* Sombra sob a cama */}
    <ellipse cx="60" cy="138" rx="32" ry="2.5" fill="#0E1620" opacity="0.5" />

    {/* Cama — base de madeira */}
    <rect x="30" y="128" width="60" height="8" fill="#3D2C22" />
    <rect x="30" y="128" width="60" height="2" fill="#5A4030" />
    {/* pés da cama */}
    <rect x="30" y="134" width="4" height="4" fill="#2A1E16" />
    <rect x="86" y="134" width="4" height="4" fill="#2A1E16" />

    {/* Colchão / lençol por baixo do cobertor */}
    <path d="M30 118 Q30 114 34 114 L86 114 Q90 114 90 118 L90 128 L30 128 Z"
      fill="#E8DCC0" />

    {/* Almofada */}
    <ellipse cx="40" cy="118" rx="10" ry="4" fill="#F5E8C4" />
    <ellipse cx="40" cy="117" rx="9" ry="3" fill="#FDF1CE" />

    {/* Cobertor — coral terracota cobrindo corpo */}
    <path d="M48 120 Q50 116 54 116 L84 116 Q88 116 88 120 L88 128 L48 128 Z"
      fill="url(#sc-blanket)" />
    {/* Dobra decorativa do cobertor */}
    <path d="M48 120 L88 120" stroke="#F5E8C4" strokeWidth="0.4" opacity="0.6" />
    <path d="M52 123 Q54 122 56 123 M60 123 Q62 122 64 123 M68 123 Q70 122 72 123 M76 123 Q78 122 80 123"
      stroke="#F5E8C4" strokeWidth="0.3" fill="none" opacity="0.5" />

    {/* Criança a dormir — cabeça no travesseiro, perfil */}
    <g>
      {/* cabeça */}
      <ellipse cx="44" cy="114" rx="5.5" ry="5" fill="#D4A084" />
      {/* cabelo */}
      <path d="M40 111 Q42 107 46 108 Q50 108 50 112 Q48 111 45 112 Q42 112 40 111 Z"
        fill="#3D2820" />
      {/* olho fechado — linha curva */}
      <path d="M42 115 Q44 116 46 115" stroke="#3D2820" strokeWidth="0.5" fill="none" strokeLinecap="round" />
      {/* bochecha rosada */}
      <circle cx="44" cy="117" r="1.2" fill="#E89A82" opacity="0.5" />
    </g>

    {/* Bolha de sonho — pequenos Z's */}
    <g fill="#F5E8C4" opacity="0.7">
      <text x="52" y="108" fontFamily="Cormorant Garamond, serif" fontSize="4" fontStyle="italic">z</text>
      <text x="56" y="104" fontFamily="Cormorant Garamond, serif" fontSize="5" fontStyle="italic">z</text>
      <text x="61" y="99" fontFamily="Cormorant Garamond, serif" fontSize="6" fontStyle="italic">z</text>
    </g>

    {/* Partículas douradas subindo (ambiente de sonho) */}
    <g fill="#F5D88A" opacity="0.65">
      <circle cx="70" cy="100" r="0.5" />
      <circle cx="76" cy="92" r="0.4" />
      <circle cx="82" cy="96" r="0.4" />
      <circle cx="66" cy="90" r="0.3" />
    </g>

    {/* Filete + assinatura no rodapé */}
    <line x1="44" y1="148" x2="76" y2="148" stroke="#9BB4CC" strokeWidth="0.4" opacity="0.6" />
    <text x="60" y="154" textAnchor="middle" fill="#9BB4CC"
      fontFamily="Inter, sans-serif" fontSize="3" fontWeight="500"
      letterSpacing="0.5" opacity="0.85">DRA. BRUNA · 2026</text>
  </svg>
);

// ————————————————————————————————————————————————
// Card de guia
// ————————————————————————————————————————————————
const GuideCard = ({ number, title, description, href, color, accent, iconPath, placeholder, coverVariant }) => {
  const [hover, setHover] = useStateB(false);
  const isLink = !!href;
  const Tag = isLink ? 'a' : 'div';
  const linkProps = isLink ? { href, target: '_blank', rel: 'noopener noreferrer' } : {};

  return (
    <Tag
      {...linkProps}
      onMouseEnter={() => isLink && setHover(true)}
      onMouseLeave={() => isLink && setHover(false)}
      style={{
        display: 'flex',
        flexDirection: 'column',
        gap: 16,
        padding: '20px 16px 22px',
        background: hover ? pal.creamLighter : `${pal.creamDeep}88`,
        border: placeholder
          ? `1px dashed ${pal.olive}33`
          : `1px solid ${hover ? pal.olive + '55' : pal.olive + '22'}`,
        textDecoration: 'none',
        color: 'inherit',
        cursor: isLink ? 'pointer' : 'default',
        transition: 'background 220ms ease, border-color 220ms ease, transform 220ms ease',
        transform: hover ? 'translateY(-2px)' : 'translateY(0)',
        opacity: placeholder ? 0.7 : 1,
        position: 'relative',
      }}
    >
      <div style={{
        position: 'absolute',
        top: 14,
        right: 14,
        fontFamily: '"Cormorant Garamond", serif',
        fontStyle: 'italic',
        fontSize: 15,
        color: placeholder ? pal.oliveMid : pal.mustardDark,
        opacity: placeholder ? 0.5 : 0.9,
        lineHeight: 1,
      }}>{number}</div>

      <GuideMock color={color} accent={accent} iconPath={iconPath} placeholder={placeholder} coverVariant={coverVariant} />

      <div style={{ minHeight: 60 }}>
        <EyebrowB color={placeholder ? pal.oliveMid : pal.clay} style={{
          marginBottom: 6,
          fontSize: 9,
          letterSpacing: '0.2em',
          opacity: placeholder ? 0.6 : 1,
        }}>
          {placeholder ? 'guia · em breve' : 'guia · grátis'}
        </EyebrowB>
        <h3 style={{
          fontFamily: '"Cormorant Garamond", serif',
          fontWeight: 500,
          fontSize: 18,
          lineHeight: 1.15,
          color: placeholder ? pal.oliveMid : pal.olive,
          margin: 0,
          letterSpacing: '-0.01em',
        }}>{title}</h3>
      </div>

      {!placeholder && (
        <div style={{
          display: 'flex',
          alignItems: 'center',
          justifyContent: 'space-between',
          gap: 8,
          paddingTop: 12,
          borderTop: `1px solid ${pal.olive}1A`,
        }}>
          <span style={{
            fontFamily: 'Inter, sans-serif',
            fontSize: 10.5,
            letterSpacing: '0.2em',
            textTransform: 'uppercase',
            color: pal.clay,
            fontWeight: 600,
          }}>abrir</span>
          <span style={{
            fontSize: 16,
            color: pal.mustardDark,
            transform: hover ? 'translateX(4px)' : 'translateX(0)',
            transition: 'transform 220ms ease',
          }}>→</span>
        </div>
      )}
    </Tag>
  );
};

// ————————————————————————————————————————————————
// Ícones para cada guia (SVG paths)
// ————————————————————————————————————————————————
const icons = {
  parasitas: <React.Fragment>
    <path d="M20 8c-4-2-8-2-12 0M20 14c-4-2-8-2-12 0M20 20c-4-2-8-2-12 0M20 26c-4-2-8-2-12 0M20 32c-4-2-8-2-12 0"/>
    <circle cx="8" cy="8" r="1" fill={pal.cream}/>
    <circle cx="8" cy="14" r="1" fill={pal.cream}/>
    <circle cx="8" cy="20" r="1" fill={pal.cream}/>
  </React.Fragment>,
  jardim: <React.Fragment>
    <path d="M20 34V18"/>
    <path d="M20 24c-4 0-7-3-7-7 0-2 1-4 3-5 1 2 4 3 6 3-1-2-1-5 1-6 3 3 4 7 3 10-1 3-3 5-6 5z"/>
    <path d="M20 28c3 0 5-2 5-5"/>
  </React.Fragment>,
  ciclo: <React.Fragment>
    <circle cx="20" cy="20" r="12"/>
    <path d="M20 8v4M32 20h-4M20 32v-4M8 20h4"/>
    <path d="M28 12l-2 2M28 28l-2-2M12 28l2-2M12 12l2 2"/>
  </React.Fragment>,
};

// ————————————————————————————————————————————————
// Página Biblioteca
// ————————————————————————————————————————————————
const BibliotecaPage = () => {
  return (
    <div style={{
      width: '100%',
      minHeight: '100%',
      background: pal.cream,
      fontFamily: 'Inter, sans-serif',
      color: pal.olive,
      position: 'relative',
      overflow: 'hidden',
    }}>
      {/* watermark */}
      <div aria-hidden style={{
        position: 'absolute',
        top: 180,
        right: -60,
        fontFamily: '"Cormorant Garamond", serif',
        fontStyle: 'italic',
        fontSize: 260,
        lineHeight: 1,
        color: pal.olive,
        opacity: 0.035,
        fontWeight: 400,
        pointerEvents: 'none',
        letterSpacing: '-0.04em',
      }}>b</div>

      {/* Topo — voltar */}
      <div style={{
        padding: '18px 18px 0',
        display: 'flex',
        alignItems: 'center',
        justifyContent: 'space-between',
      }}>
        <a href="Link da Bio.html" style={{
          fontFamily: 'Inter, sans-serif',
          fontSize: 10.5,
          letterSpacing: '0.22em',
          textTransform: 'uppercase',
          color: pal.oliveMid,
          textDecoration: 'none',
          fontWeight: 500,
          display: 'flex',
          alignItems: 'center',
          gap: 6,
        }}>
          <span style={{ fontSize: 14 }}>←</span> voltar
        </a>
        <EyebrowB color={pal.oliveMid}>cláudia santos</EyebrowB>
      </div>

      {/* Hero */}
      <div style={{ padding: '40px 18px 28px' }}>
        <EyebrowB color={pal.clay} style={{ marginBottom: 16 }}>biblioteca · recursos</EyebrowB>
        <h1 style={{
          fontFamily: '"Cormorant Garamond", serif',
          fontWeight: 400,
          fontSize: 44,
          lineHeight: 1.05,
          color: pal.olive,
          margin: 0,
          letterSpacing: '-0.018em',
          textWrap: 'pretty',
        }}>
          Ebooks <span style={{ fontStyle: 'italic', color: pal.clay }}>gratuitos</span>
        </h1>
        <p style={{
          marginTop: 22,
          fontFamily: '"Cormorant Garamond", serif',
          fontStyle: 'italic',
          fontSize: 18,
          lineHeight: 1.4,
          color: pal.oliveMid,
          maxWidth: 320,
          letterSpacing: '-0.005em',
        }}>
          Materiais de leitura para famílias que querem aprofundar o tema antes de qualquer consulta.
        </p>
      </div>

      <div style={{ padding: '0 18px' }}>
        <RuleB opacity={0.2} />
      </div>

      {/* Grid de 6 guias */}
      <div style={{ padding: '28px 18px 40px' }}>
        <div style={{
          display: 'grid',
          gridTemplateColumns: 'repeat(2, 1fr)',
          gap: 12,
        }}>
          <GuideCard
            number="i"
            title="Guia prático dos parasitas"
            color={pal.clay}
            accent={pal.clayDeep}
            iconPath={icons.parasitas}
            coverVariant="parasitas"
            href="https://homeopatiainfantil.com/guia/guia-pratico-parasitas"
          />
          <GuideCard
            number="ii"
            title="Qual a relação do intestino com a imunidade do teu filho?"
            color="#6B7A3F"
            accent={pal.olive}
            iconPath={icons.jardim}
            coverVariant="jardim"
            href="https://homeopatiainfantil.com/guia/intestinoeimunidade"
          />
          <GuideCard
            number="iii"
            title="Mapa do ciclo da doença"
            color={pal.mustard}
            accent={pal.mustardDark}
            iconPath={icons.ciclo}
            coverVariant="ciclo"
            href="https://homeopatiainfantil.com/guia/mapa-ciclo-doenca"
          />
          <GuideCard
            number="iv"
            title="Rituais do sono para honrar a noite"
            color={pal.olive}
            accent={pal.oliveDeep}
            iconPath={icons.jardim}
            coverVariant="sono"
            href="https://homeopatiainfantil.com/guia/guia-gratuito-noiteteufilho"
          />
          <GuideCard number="v" title="Em preparação" placeholder />
          <GuideCard number="vi" title="Em preparação" placeholder />
        </div>
      </div>

      {/* Nota editorial */}
      <div style={{ padding: '12px 22px 40px' }}>
        <p style={{
          fontFamily: '"Cormorant Garamond", serif',
          fontStyle: 'italic',
          fontSize: 17,
          lineHeight: 1.45,
          color: pal.clayDeep,
          textAlign: 'center',
          margin: 0,
          letterSpacing: '-0.005em',
          textWrap: 'balance',
        }}>
          Seis guias no total. Quatro já podes ler. Os outros dois chegarão em breve.
        </p>
      </div>

      {/* Ornamento */}
      <div style={{ padding: '24px 18px 20px', display: 'flex', alignItems: 'center', justifyContent: 'center', gap: 14 }}>
        <div style={{ height: 1, background: pal.mustard, flex: 1, opacity: 0.55 }} />
        <svg viewBox="0 0 20 20" width="14" height="14" fill="none" stroke={pal.mustardDark} strokeWidth="1.2" strokeLinecap="round" strokeLinejoin="round">
          <path d="M10 3c-3 3-3 7 0 10 3-3 3-7 0-10zM10 13v5" />
        </svg>
        <div style={{ height: 1, background: pal.mustard, flex: 1, opacity: 0.55 }} />
      </div>

      {/* Rodapé */}
      <div style={{ padding: '0 18px 36px' }}>
        <RuleB opacity={0.22} my={0} />
        <div style={{ paddingTop: 28 }}>
          <a href="Link da Bio.html" style={{
            display: 'flex',
            alignItems: 'center',
            justifyContent: 'center',
            gap: 8,
            padding: '14px 16px',
            background: pal.oliveDeep,
            color: pal.cream,
            border: `1px solid ${pal.oliveDeep}`,
            borderRadius: 2,
            textDecoration: 'none',
            fontFamily: 'Inter, sans-serif',
            fontSize: 13,
            fontWeight: 500,
            letterSpacing: '0.04em',
          }}>
            <span style={{ fontSize: 14 }}>←</span>
            <span>Voltar ao início</span>
          </a>
        </div>
      </div>
    </div>
  );
};

window.BibliotecaPage = BibliotecaPage;
