// Landing page — wordmark, nav, and featured saint composition.
const NAV_ITEMS = [
{ label: "Popular Saints", key: "saints" },
{ label: "Topics & Themes", key: "topics" },
{ label: "About Saints", key: "about" }];


function Wordmark({ subtitle, compact = false }) {
  return (
    <div className={"wordmark" + (compact ? " is-compact" : "")}>
      <h1 className="wordmark-name">Saints</h1>
      <style>{`
        .wordmark { text-align: center; }
        .wordmark-name {
          font-family: "Fraunces", serif;
          font-weight: 400;
          font-size: clamp(48px, 6.4vw, 84px);
          margin: 0;
          letter-spacing: -0.025em;
          font-style: normal;
          color: var(--ink);
          line-height: 1;
          font-variation-settings: "opsz" 144, "SOFT" 30;
        }
        .wordmark.is-compact .wordmark-name {
          font-size: clamp(28px, 3.2vw, 38px);
        }
        .wordmark-rule { display: none; }
        .wordmark-rule:first-child { margin-bottom: 18px; }
        .wordmark-rule:nth-child(3) { margin-top: 18px; }
        .wordmark.is-compact .wordmark-rule { display: none; }
        .wordmark-sub {
          font-family: var(--font-body);
          font-size: 13px;
          font-weight: 400;
          letter-spacing: 0.18em;
          text-transform: uppercase;
          color: var(--ink-mute);
          margin: 18px auto 0;
          max-width: 640px;
          line-height: 1.6;
          text-wrap: balance;
        }
        @media (max-width: 640px) {
          .wordmark-sub { font-size: 11px; letter-spacing: 0.14em; }
        }
      `}</style>
    </div>);

}

function NavRow({ orientation = "horizontal", onOpenDrawer, route, onNavigate }) {
  return (
    <nav className={"nav-row nav-" + orientation}>
      {NAV_ITEMS.map((item, i) =>
      <a
        key={item.key}
        href={"#" + item.key}
        className={"nav-link" + (route === item.key ? " is-active" : "")}
        onClick={(e) => {e.preventDefault();onNavigate && onNavigate(item.key);}}>
          <span className="nav-label">{item.label}</span>
        </a>
      )}
      <style>{`
        .nav-row {
          display: flex;
          gap: clamp(20px, 4vw, 56px);
          justify-content: center;
          align-items: center;
        }
        .nav-vertical { flex-direction: column; gap: 24px; align-items: flex-start; }
        .nav-link {
          display: inline-flex;
          align-items: baseline;
          gap: 6px;
          color: var(--ink);
          text-decoration: none;
          font-family: var(--font-body);
          font-size: 12px;
          letter-spacing: 0.22em;
          text-transform: uppercase;
          font-weight: 500;
          padding: 6px 0;
          border-bottom: 1px solid transparent;
          transition: color 200ms, border-color 200ms;
          position: relative;
        }
        .nav-link:hover { color: var(--accent); border-bottom-color: var(--accent); }
        .nav-num {
          font-family: var(--font-display);
          font-style: normal;
          font-weight: 400;
          font-size: 11px;
          color: var(--ink-mute);
          letter-spacing: 0;
        }
        @media (max-width: 720px) {
          .nav-row.nav-horizontal { gap: 18px; flex-wrap: wrap; }
          .nav-link { font-size: 10.5px; letter-spacing: 0.18em; }
          .nav-num { display: none; }
        }
      `}</style>
    </nav>);

}

function CompactHeader({ route, onNavigate }) {
  const [visible, setVisible] = React.useState(true);
  const [menuOpen, setMenuOpen] = React.useState(false);

  React.useEffect(() => {
    let lastY = window.scrollY;
    let ticking = false;
    const onScroll = () => {
      if (ticking) return;
      ticking = true;
      requestAnimationFrame(() => {
        const y = window.scrollY;
        const dy = y - lastY;
        lastY = y;
        ticking = false;
        if (Math.abs(dy) < 2) return;
        // visible whenever the most recent motion was upward (or at top)
        setVisible(dy < 0 || y <= 0);
      });
    };
    window.addEventListener("scroll", onScroll, { passive: true });
    return () => window.removeEventListener("scroll", onScroll);
  }, []);

  // Close on Esc or any click outside the header (mobile menu only).
  // Also auto-collapse when the user scrolls while the menu is open.
  React.useEffect(() => {
    if (!menuOpen) return;
    const onKey = (e) => { if (e.key === "Escape") setMenuOpen(false); };
    const onDown = (e) => {
      const header = document.querySelector(".compact-header");
      const backdrop = document.querySelector(".compact-backdrop");
      if (
        (header && header.contains(e.target)) ||
        (backdrop && backdrop.contains(e.target))
      ) return;
      setMenuOpen(false);
    };
    const onScroll = () => setMenuOpen(false);
    window.addEventListener("keydown", onKey);
    document.addEventListener("pointerdown", onDown);
    window.addEventListener("scroll", onScroll, { passive: true });
    window.addEventListener("wheel", onScroll, { passive: true });
    window.addEventListener("touchmove", onScroll, { passive: true });
    return () => {
      window.removeEventListener("keydown", onKey);
      document.removeEventListener("pointerdown", onDown);
      window.removeEventListener("scroll", onScroll);
      window.removeEventListener("wheel", onScroll);
      window.removeEventListener("touchmove", onScroll);
    };
  }, [menuOpen]);

  const handleNav = (key) => {
    setMenuOpen(false);
    onNavigate && onNavigate(key);
  };

  return (
    <header className={"compact-header" + (visible ? " is-visible" : " is-hidden") + (menuOpen ? " is-expanded" : "")}>
      <div className="compact-inner">
        <button
          type="button"
          className="compact-mark"
          onClick={() => handleNav("saints")}>
          Saints
        </button>

        {/* Desktop inline nav */}
        <nav className="compact-nav">
          {NAV_ITEMS.map((item) =>
          <a
            key={item.key}
            href={"#" + item.key}
            className={"compact-link" + (route === item.key ? " is-active" : "")}
            onClick={(e) => {e.preventDefault();onNavigate && onNavigate(item.key);}}>
              {item.label}
            </a>
          )}
        </nav>

        {/* Mobile chevron — hidden on desktop via media query */}
        <button
          type="button"
          className={"compact-chevron" + (menuOpen ? " is-open" : "")}
          aria-label={menuOpen ? "Collapse menu" : "Expand menu"}
          aria-expanded={menuOpen}
          onClick={() => setMenuOpen((v) => !v)}>
          <svg viewBox="0 0 16 16" width="16" height="16" aria-hidden="true">
            <path d="M3 6 L8 11 L13 6"
                  fill="none" stroke="currentColor" strokeWidth="1.6"
                  strokeLinecap="round" strokeLinejoin="round" />
          </svg>
        </button>
      </div>

      {/* Mobile expanded nav — stacked items below the bar */}
      <nav className="compact-mobile-nav" aria-hidden={!menuOpen}>
        {NAV_ITEMS.map((item) =>
        <a
          key={item.key}
          href={"#" + item.key}
          className={"compact-mobile-link" + (route === item.key ? " is-active" : "")}
          onClick={(e) => { e.preventDefault(); handleNav(item.key); }}>
            {item.label}
          </a>
        )}
      </nav>

      {/* Mobile-only backdrop — blurs page behind the expanded header */}
      <div
        className={"compact-backdrop" + (menuOpen ? " is-open" : "")}
        onClick={() => setMenuOpen(false)}
        aria-hidden="true" />

      <style>{`
        .compact-header {
          position: fixed;
          top: 0; left: 0; right: 0;
          z-index: 1000;
          background: var(--bg);
          isolation: isolate;
          transition: transform 280ms cubic-bezier(.4,0,.2,1), opacity 200ms ease, box-shadow 280ms ease;
          opacity: 1;
        }
        .compact-header.is-expanded {
          box-shadow: 0 24px 60px -16px rgba(14,22,34,0.32), 0 10px 24px -10px rgba(14,22,34,0.18);
        }
        .compact-header.is-hidden {
          transform: translateY(-100%);
          opacity: 0;
          pointer-events: none;
        }
        .compact-inner {
          max-width: 1240px;
          margin: 0 auto;
          padding: 14px clamp(24px, 5vw, 72px);
          display: flex;
          align-items: center;
          justify-content: space-between;
          gap: 32px;
        }
        .compact-mark {
          appearance: none;
          background: transparent;
          border: 0;
          padding: 0;
          cursor: pointer;
          color: var(--ink);
          font-family: "Fraunces", serif;
          font-weight: 400;
          font-size: 24px;
          letter-spacing: -0.02em;
          line-height: 1;
          font-variation-settings: "opsz" 144;
        }
        .compact-mark:hover { color: var(--accent); }

        .compact-nav {
          display: flex;
          align-items: center;
          gap: clamp(18px, 3.2vw, 40px);
        }
        .compact-link {
          font-family: var(--font-body);
          font-size: 11.5px;
          letter-spacing: 0.22em;
          text-transform: uppercase;
          color: var(--ink-mute);
          text-decoration: none;
          font-weight: 500;
          padding: 6px 0;
          transition: color 200ms;
        }
        .compact-link:hover { color: var(--accent); }
        .compact-link.is-active { color: var(--accent); }

        /* Chevron button — only visible on narrow screens */
        .compact-chevron {
          display: none;
          appearance: none;
          background: transparent;
          border: 0;
          padding: 8px;
          margin: -8px;
          cursor: pointer;
          color: var(--ink);
          line-height: 0;
          border-radius: 999px;
          transition: color 180ms ease, background-color 180ms ease;
        }
        .compact-chevron:hover {
          color: var(--accent);
          background: rgba(14, 22, 34, 0.04);
        }
        .compact-chevron svg {
          display: block;
          transition: transform 320ms cubic-bezier(.4,0,.2,1);
        }
        .compact-chevron.is-open svg {
          transform: rotate(180deg);
        }

        /* Expanded mobile nav — grows from inside the header */
        .compact-mobile-nav {
          display: flex;
          flex-direction: column;
          overflow: hidden;
          max-height: 0;
          opacity: 0;
          transition: max-height 360ms cubic-bezier(.4,0,.2,1),
                      opacity 240ms ease,
                      padding 360ms cubic-bezier(.4,0,.2,1);
          padding: 0 clamp(24px, 5vw, 72px);
        }
        .compact-header.is-expanded .compact-mobile-nav {
          max-height: 360px;
          opacity: 1;
          padding: 4px clamp(24px, 5vw, 72px) 18px;
        }
        .compact-mobile-link {
          font-family: var(--font-body);
          font-size: 13px;
          letter-spacing: 0.22em;
          text-transform: uppercase;
          color: var(--ink);
          text-decoration: none;
          font-weight: 500;
          padding: 14px 0;
          transition: color 180ms ease;
        }
        .compact-mobile-link:hover,
        .compact-mobile-link:active { color: var(--accent); }
        .compact-mobile-link.is-active { color: var(--accent); }

        /* Mobile backdrop — sits BELOW the expanded header, blurs the page,
           leaves the header itself unaffected. Positioned absolutely inside
           the header so its top edge follows the header's grown height. */
        .compact-backdrop {
          display: none;
          position: absolute;
          top: 100%;
          left: 0; right: 0;
          height: 100vh;
          background: rgba(243, 245, 248, 0.85);
          backdrop-filter: blur(16px);
          -webkit-backdrop-filter: blur(16px);
          opacity: 0;
          pointer-events: none;
          transition: opacity 240ms ease;
          z-index: 1;
        }
        .compact-backdrop.is-open {
          opacity: 1;
          pointer-events: auto;
        }
        @media (max-width: 640px) {
          .compact-backdrop { display: block; }
        }

        @media (max-width: 640px) {
          .compact-nav { display: none; }
          .compact-chevron { display: inline-flex; align-items: center; justify-content: center; }
        }
      `}</style>
    </header>);

}

function HeaderTop({ subtitle, navPlacement, route, onNavigate }) {
  // header layout depends on nav placement
  if (navPlacement === "top-bar") {
    return (
      <header className="header header-topbar">
        <div className="topbar">
          <div className="topbar-mark" onClick={() => onNavigate && onNavigate("saints")} style={{ cursor: "pointer" }}>
            <span className="topbar-name">Saints</span>
          </div>
          <NavRow orientation="horizontal" route={route} onNavigate={onNavigate} />
          <div className="topbar-meta">A.D. MMXXVI</div>
        </div>
        <div className="header-hero">
          <Wordmark subtitle={subtitle} />
        </div>
        <style>{`
          .header-topbar { padding: 0; }
          .topbar {
            display: grid;
            grid-template-columns: 1fr auto 1fr;
            align-items: center;
            padding: 22px clamp(24px, 5vw, 64px);
                        gap: 24px;
          }
          .topbar-mark { display: flex; align-items: center; gap: 10px; }
          .topbar-asterisk { color: var(--accent); font-size: 18px; }
          .topbar-name {
            font-family: "Fraunces", serif;
            font-style: normal;
            font-weight: 400;
            font-size: 26px;
            letter-spacing: -0.02em;
            font-variation-settings: "opsz" 144;
          }
          .topbar-meta {
            justify-self: end;
            font-family: var(--font-body);
            font-size: 10.5px;
            letter-spacing: 0.3em;
            color: var(--ink-mute);
            text-transform: uppercase;
          }
          .header-hero {
            padding: clamp(48px, 8vh, 96px) 24px clamp(36px, 6vh, 72px);
          }
          @media (max-width: 860px) {
            .topbar { grid-template-columns: 1fr; gap: 16px; }
            .topbar-meta { display: none; }
          }
        `}</style>
      </header>);

  }

  if (navPlacement === "left-rail") {
    return (
      <header className="header header-rail">
        <div className="header-hero">
          <Wordmark subtitle={subtitle} />
        </div>
        <style>{`
          .header-rail { padding: clamp(48px, 9vh, 110px) 24px clamp(36px, 6vh, 72px); }
        `}</style>
      </header>);

  }

  // default: centered floating nav under wordmark
  return (
    <header className="header header-centered">
      <div className="header-meta-row">
        <div className="meta-edge"></div>
        <div className="meta-asterisk"></div>
        <div className="meta-edge meta-edge-right"></div>
      </div>
      <div onClick={() => onNavigate && onNavigate("saints")} style={{ cursor: "pointer" }}>
        <Wordmark subtitle={subtitle} />
      </div>
      <div className="header-nav-wrap" style={{ textAlign: "center" }}>
        <NavRow orientation="horizontal" route={route} onNavigate={onNavigate} />
      </div>
      <style>{`
        .header-centered {
          padding: clamp(48px, 8vh, 96px) 24px clamp(40px, 6vh, 80px);
          position: relative;
        }
        .header-meta-row {
          display: flex;
          justify-content: space-between;
          align-items: center;
          max-width: 1200px;
          margin: 0 auto clamp(40px, 6vh, 72px);
          padding: 0 clamp(8px, 3vw, 32px);
        }
        .meta-edge {
          font-family: var(--font-body);
          font-size: 10.5px;
          letter-spacing: 0.3em;
          color: var(--ink-mute);
          text-transform: uppercase;
        }
        .meta-asterisk { color: var(--accent); font-size: 18px; opacity: 0.8; }
        .header-nav-wrap {
          margin-top: clamp(36px, 5vh, 56px);
          display: flex;
          justify-content: center;
        }
      `}</style>
    </header>);

}

function LeftRail({ route, onNavigate }) {
  return (
    <aside className="leftrail">
      <div className="leftrail-mark" onClick={() => onNavigate && onNavigate("saints")} style={{ cursor: "pointer" }}>
        <span className="leftrail-name">Saints</span>
      </div>
      <NavRow orientation="vertical" route={route} onNavigate={onNavigate} />
      <div className="leftrail-foot">
        <div>A.D.</div>
        <div>MMXXVI</div>
      </div>
      <style>{`
        .leftrail {
          position: fixed;
          top: 0; left: 0; bottom: 0;
          width: 220px;
          padding: 36px 28px;
                    background: var(--bg);
          display: flex;
          flex-direction: column;
          gap: 48px;
          z-index: 10;
        }
        .leftrail-mark { display: flex; flex-direction: column; gap: 6px; }
        .leftrail-asterisk { color: var(--accent); font-size: 22px; }
        .leftrail-name {
          font-family: "Fraunces", serif;
          font-style: normal;
          font-weight: 400;
          font-size: 32px;
          letter-spacing: -0.02em;
          font-variation-settings: "opsz" 144;
        }
        .leftrail-foot {
          margin-top: auto;
          font-family: var(--font-body);
          font-size: 10.5px;
          letter-spacing: 0.3em;
          color: var(--ink-mute);
          text-transform: uppercase;
          line-height: 1.8;
        }
        @media (max-width: 900px) {
          .leftrail { display: none; }
        }
      `}</style>
    </aside>);

}

function SaintCopy({ compact = false, hideName = false }) {
  return (
    <div className={"saint-copy" + (compact ? " is-compact" : "")}>
      <div className="kicker">
        <span className="kicker-num"></span>
        <span className="kicker-label"></span>
      </div>

      {!hideName &&
      <h2 className="saint-name">
        <span className="saint-name-st"></span>
        <span className="saint-name-given" style={{ fontSize: "24px" }}>St. John of Matha</span>
      </h2>
      }

      <div className="saint-meta">
        <div className="meta-cell">
          <div className="meta-cap">Born</div>
          <div className="meta-val">1160 · Provence, France</div>
        </div>
        <div className="meta-cell">
          <div className="meta-cap">Died</div>
          <div className="meta-val">17 Dec 1213 · Rome</div>
        </div>
        <div className="meta-cell">
          <div className="meta-cap">Feast Day</div>
          <div className="meta-val">8 February</div>
        </div>
        <div className="meta-cell">
          <div className="meta-cap">Patron of</div>
          <div className="meta-val">Captives · The Trinitarian Order</div>
        </div>
      </div>

      <figure className="quote">
        <span className="quote-mark">“</span>
        <blockquote className="quote-text" style={{ fontSize: "20px" }}>
          Gloria Tibi Trinitas, et captivis libertas.
        </blockquote>
        <figcaption className="quote-trans">
          Glory to thee, O Trinity, and freedom to the captives.
        </figcaption>
      </figure>

      <section className="passage">
        <div className="passage-cap">How he loved God exceedingly</div>
        <p className="passage-text">Born to a noble Provençal house, John surrendered every inheritance to embrace the priesthood — and chose, as the form of his love, the ransom of strangers. He crossed into North Africa, walked unarmed into the markets of Tunis and Morocco, and bought back Christian captives one by one with the silver of his order. When the silver ran out, his brothers offered themselves in exchange. To love God, he taught, was to count no soul beyond reach.






        </p>
      </section>

      <section className="passage">
        <div className="passage-cap">The vision at the chalice</div>
        <p className="passage-text">
          Paris, 1193 — at the moment of the elevation, John saw above the chalice an angel
          robed in white, his hands resting on the heads of two captives, one Christian, one
          Moor, joined by a single chain. From that vision came the Order of the Most Holy
          Trinity, founded five years later, and a life given to the freeing of the bound.
        </p>
      </section>

      <section className="passage">
        <div className="passage-cap">The hermit of Cerfroid</div>
        <p className="passage-text">
          After his ordination he withdrew with Felix of Valois to the forest of Cerfroid, north
          of Meaux, and lived there as a hermit for two years. The vision returned. The two men
          walked to Rome together in the winter of 1198 and, on the 17th of December, Innocent
          III approved the rule of the Trinitarians and gave them a sign — a red-and-blue
          cross — that their ransomed captives could wear without fear in either country.
        </p>
      </section>

      <section className="passage">
        <div className="passage-cap">Tunis, Morocco, and the silver chain</div>
        <p className="passage-text">
          The first expedition sailed in 1201. John walked into the slave markets with nothing
          but the silver his order had begged across Provence and Languedoc, and bought back
          captives one by one. When the silver ran out, his brothers offered themselves in
          exchange — a clause written into the Trinitarian rule from the founding: <em>tertia
          pars</em>, a third of every income reserved forever for ransom, and the friars
          themselves the final coin. By the time he died, more than 140 Christians had returned
          home in his ships.
        </p>
      </section>

      <section className="passage">
        <div className="passage-cap">The last years in Rome</div>
        <p className="passage-text">
          He died on the 17th of December, 1213, in the small Roman house Innocent III had given
          his order — old before his time, his body broken by the Mediterranean crossings. He
          was canonized only in 1665, after centuries during which the Trinitarians kept
          themselves to the work and let the saint be forgotten. The order he founded still
          exists. Its motto is still his prayer.
        </p>
      </section>

      <section className="timeline-section">
        <div className="passage-cap">A life in dates</div>
        <ol className="timeline">
          <li className="tl-row"><span className="tl-year">1160</span><span className="tl-event">Born at Faucon-de-Barcelonnette in Provence, son of a knight.</span></li>
          <li className="tl-row"><span className="tl-year">1190</span><span className="tl-event">Sent to Paris to read theology; ordained priest within the year.</span></li>
          <li className="tl-row"><span className="tl-year">1193</span><span className="tl-event">Vision at his first Mass: the angel, the chain, the two captives.</span></li>
          <li className="tl-row"><span className="tl-year">1194–96</span><span className="tl-event">Withdraws to the forest of Cerfroid with Felix of Valois.</span></li>
          <li className="tl-row"><span className="tl-year">1198</span><span className="tl-event">Innocent III approves the Rule of the Holy Trinity in Rome.</span></li>
          <li className="tl-row"><span className="tl-year">1201</span><span className="tl-event">First Trinitarian ransoming voyage; sails for Tunis.</span></li>
          <li className="tl-row"><span className="tl-year">1213</span><span className="tl-event">Dies in Rome, December 17. Canonized in 1665.</span></li>
        </ol>
      </section>

      <section className="prayer-block">
        <div className="passage-cap">Novena to St. John of Matha</div>
        <p className="prayer-intro">
          The traditional Trinitarian novena, prayed for nine consecutive days — especially
          in the days before his feast (Feb 8 in the Extraordinary Form; Dec 17 on the current
          calendar) — for those held in any form of captivity.
        </p>
        <blockquote className="prayer-body">
          <p className="prayer-sub">Prayer to the Most Holy Trinity (for the imprisoned)</p>
          <p>
            Holy Trinity — Father, Son, and Holy Spirit — Thou didst call John de Matha to be a
            liberator of those who suffered the pains of captivity. Through his intercession,
            give patience and love to those who are persecuted for their faith in Christ;
            bestow Thy liberating grace on all who are enchained by any form of addiction; and
            instill a sense of purifying purposefulness in all who serve time in correctional
            institutions.
          </p>
          <p>
            Holy and Blessed Trinity, instill in my heart, and in the hearts of all who are
            associated with the Trinitarian Order, that love which moved John de Matha to
            labour for the spiritual and physical freedom of all Thy sons and daughters.
            Instill in us a deep compassion for the poor and the less fortunate of society,
            and transform us into apostles of Thy kingdom of justice and peace in our world.
          </p>
          <p className="prayer-sub">Prayer to St. John de Matha</p>
          <p>
            Holy Founder, John de Matha, the loving plan of God has willed that we be thy
            spiritual heirs. Protect us and all members of the Trinitarian Family. Obtain for
            us the grace to be filled with thy dynamic love for God-Trinity and a deep
            compassion for suffering humanity.
          </p>
          <p>
            May thine example inspire us to live a personal and social life rooted in the
            Gospel, and exemplifying the love and unity of the Holy Trinity. May thy redemptive
            spirit animate us to imitate Christ the Redeemer, and uphold the freedom of all
            people, especially those marked with the hardship of the human condition. May our
            commitment to the ideal of Christian love bring us, one day, to enjoy with thee the
            beatific vision of God-Trinity.
          </p>
          <p className="prayer-closing">
            We make this prayer through Christ, our Lord. Amen.
          </p>
        </blockquote>
        <div className="prayer-coda">
          <span>Mention your intention · Pater Noster · Ave Maria · Gloria Patri</span>
          <span className="prayer-versicle">St. John de Matha, pray for us.</span>
        </div>
        <div className="prayer-source">
          Text from the Order of the Most Holy Trinity (Trinitarians) ·{" "}
          <a
            href="https://trinitarians.ph/stjohndematha/"
            target="_blank"
            rel="noopener noreferrer">
            
            trinitarians.ph/stjohndematha ↗
          </a>
        </div>
      </section>

      <aside className="further">
        <div className="passage-cap">Further reading</div>
        <ul className="further-list">
          <li>Joseph Gross, <em>The Trinitarians' Rule of Life</em> (2003).</li>
          <li>Pope John Paul II, homily at the 8th centenary of the Order, 1998.</li>
          <li>James Brodrick S.J., <em>Saints of Hospitality and Ransom</em> (1955), ch. III.</li>
        </ul>
      </aside>

      <style>{`
        .saint-copy {
          font-family: var(--font-body);
          color: var(--ink);
          max-width: 560px;
        }
        .saint-copy.is-compact { max-width: 520px; }

        .kicker {
          display: flex; align-items: center; gap: 12px;
          margin-bottom: 28px;
        }
        .kicker-num {
          font-family: var(--font-display);
          font-style: normal;
          font-size: 14px;
          color: var(--accent);
          letter-spacing: 0.04em;
        }
        .kicker-rule { display: none; }
        .kicker-label {
          font-size: 10.5px; letter-spacing: 0.32em;
          text-transform: uppercase; color: var(--ink-mute);
          font-weight: 500;
        }

        .saint-name {
          font-family: var(--font-display);
          font-weight: 400;
          margin: 0 0 28px;
          line-height: 1.0;
          letter-spacing: -0.005em;
          color: var(--ink);
        }
        .saint-name-st {
          display: block;
          font-style: normal;
          font-size: clamp(24px, 2.6vw, 32px);
          color: var(--accent);
          font-weight: 400;
          margin-bottom: 6px;
          letter-spacing: 0.02em;
        }
        .saint-name-given {
          display: block;
          font-size: clamp(46px, 6vw, 84px);
          font-weight: 500;
          font-feature-settings: "liga", "dlig";
          text-wrap: balance;
        }

        .saint-meta {
          display: grid;
          grid-template-columns: 1fr 1fr;
          gap: 18px 28px;
          padding: 22px 0;
                              margin-bottom: 32px;
        }
        .meta-cap {
          font-size: 10px;
          letter-spacing: 0.28em;
          text-transform: uppercase;
          color: var(--ink-mute);
          margin-bottom: 4px;
        }
        .meta-val {
          font-family: var(--font-display);
          font-size: 15.5px;
          color: var(--ink);
          line-height: 1.4;
        }

        .quote {
          margin: 0 0 36px;
          padding: 4px 0 4px 28px;
                    position: relative;
        }
        .quote-mark {
          position: absolute;
          top: -18px; left: 12px;
          font-family: var(--font-display);
          font-size: 64px;
          color: var(--accent);
          opacity: 0.32;
          line-height: 1;
        }
        .quote-text {
          margin: 0 0 8px;
          font-family: var(--font-quote);
          font-style: normal;
          font-weight: 400;
          font-size: clamp(20px, 2.1vw, 26px);
          line-height: 1.4;
          color: var(--ink);
          font-feature-settings: "liga", "dlig";
        }
        .quote-trans {
          font-family: var(--font-body);
          font-size: 12px;
          letter-spacing: 0.16em;
          text-transform: uppercase;
          color: var(--ink-mute);
        }

        .passage { margin-bottom: 28px; }
        .passage-cap {
          font-size: 10.5px;
          letter-spacing: 0.32em;
          text-transform: uppercase;
          color: var(--accent);
          margin-bottom: 10px;
          font-weight: 500;
        }
        .passage-text {
          font-family: var(--font-quote);
          font-size: clamp(15px, 1.15vw, 17px);
          line-height: 1.65;
          color: var(--ink-soft);
          margin: 0;
          font-feature-settings: "liga", "kern";
          text-wrap: pretty;
        }
        .passage-text::first-line { letter-spacing: 0.02em; }
        .passage-text em { font-style: italic; color: var(--ink); }

        .timeline-section { margin: 40px 0 32px; }
        .timeline {
          list-style: none; padding: 0; margin: 16px 0 0;
          border-top: 1px solid var(--bg-deep);
        }
        .tl-row {
          display: grid; grid-template-columns: 110px 1fr; gap: 24px;
          padding: 14px 0;
          border-bottom: 1px solid var(--bg-deep);
        }
        .tl-year {
          font-family: var(--font-display);
          font-size: 13px; letter-spacing: 0.18em;
          color: var(--accent); font-weight: 500;
          padding-top: 2px;
        }
        .tl-event {
          font-family: var(--font-quote);
          font-size: 15px; line-height: 1.55;
          color: var(--ink-soft);
        }

        .prayer-block {
          margin: 48px 0 8px;
          padding: 32px clamp(20px, 4vw, 44px);
          background: var(--bg-warm);
          position: relative;
        }
        .prayer-block::before {
          content: "✻";
          position: absolute;
          top: 18px; right: 24px;
          color: var(--accent);
          font-size: 14px;
          opacity: 0.6;
        }
        .prayer-intro {
          font-family: var(--font-body);
          font-size: 13px; line-height: 1.55;
          color: var(--ink-mute);
          margin: 12px 0 22px;
          max-width: 520px;
        }
        .prayer-body {
          margin: 0;
          font-family: var(--font-quote);
          font-size: clamp(15px, 1.2vw, 17px);
          line-height: 1.7;
          color: var(--ink-soft);
          text-wrap: pretty;
        }
        .prayer-body p { margin: 0 0 14px; }
        .prayer-body p:last-child { margin-bottom: 0; }
        .prayer-sub {
          font-family: var(--font-body);
          font-size: 11px;
          letter-spacing: 0.28em;
          text-transform: uppercase;
          color: var(--accent);
          font-weight: 600;
          margin: 22px 0 4px !important;
        }
        .prayer-sub:first-child { margin-top: 0 !important; }
        .prayer-blank {
          display: inline-block;
          color: var(--ink-mute);
          letter-spacing: 0.1em;
        }
        .prayer-closing {
          font-style: italic;
          color: var(--ink);
        }
        .prayer-coda {
          margin-top: 22px;
          padding-top: 16px;
          border-top: 1px solid var(--bg-deep);
          font-family: var(--font-body);
          font-size: 10.5px;
          letter-spacing: 0.32em;
          text-transform: uppercase;
          color: var(--accent);
          text-align: center;
          display: flex;
          flex-direction: column;
          gap: 8px;
        }
        .prayer-versicle {
          color: var(--ink);
          letter-spacing: 0.18em;
          font-weight: 500;
          font-style: italic;
          text-transform: none;
          font-size: 12px;
        }
        .prayer-source {
          margin-top: 14px;
          font-family: var(--font-body);
          font-size: 11.5px;
          color: var(--ink-mute);
          line-height: 1.5;
          text-align: center;
        }
        .prayer-source a {
          color: var(--accent);
          text-decoration: none;
          border-bottom: 1px solid currentColor;
          transition: opacity 200ms;
        }
        .prayer-source a:hover { opacity: 0.7; }

        .further {
          margin-top: 40px; padding-top: 22px;
          border-top: 1px solid var(--bg-deep);
        }
        .further-list {
          list-style: none; padding: 0; margin: 14px 0 0;
          font-family: var(--font-quote);
          font-size: 14px; line-height: 1.7;
          color: var(--ink-mute);
        }
        .further-list em { font-style: italic; color: var(--ink-soft); }

        .readmore { margin-top: 36px; }
        .readmore-link {
          display: inline-flex; align-items: center; gap: 12px;
          color: var(--ink);
          text-decoration: none;
          font-family: var(--font-body);
          font-size: 11.5px;
          letter-spacing: 0.28em;
          text-transform: uppercase;
          font-weight: 600;
          padding-bottom: 6px;
                    transition: color 200ms, border-color 200ms, gap 200ms;
        }
        .readmore-link:hover {
          color: var(--accent);
          border-bottom-color: var(--accent);
          gap: 18px;
        }
        .readmore-arrow {
          font-family: var(--font-display);
          font-size: 14px;
        }
      `}</style>
    </div>);

}

function FeaturedSaint({ layout, pageMode, previousRoute, onNavigate }) {
  if (pageMode === "deepdive") {
    return (
      <section className="feat-dd">
        <div className="feat-dd-hero" style={{ background: "#1d2330" }}>
          <img
            src="assets/saint-john-matha.png"
            alt="St. John of Matha"
            style={{ width: "100%", height: "100%", objectFit: "cover", objectPosition: "center 25%", display: "block" }} />
        </div>
        <div className="feat-dd-body">
          <div className="saint-copy">
            <button
              type="button"
              className="feat-dd-backlink"
              onClick={() => onNavigate && onNavigate(previousRoute || "saints")}>
              ← Back
            </button>
            <h1 className="feat-dd-name">St. John of Matha</h1>
            <SaintCopy hideName />
          </div>
        </div>
        <style>{`
          .feat-dd {
            display: flex; flex-direction: column;
            padding-bottom: clamp(80px, 10vw, 140px);
          }
          .feat-dd-hero {
            position: relative; width: 100%;
            height: clamp(280px, 40vh, 420px);
            overflow: hidden;
            background: #1d2330;
          }
          .feat-dd-hero image-slot {
            position: absolute; inset: 0;
          }
          .feat-dd-body {
            max-width: 1240px; width: 100%; margin: 0 auto;
            padding: clamp(32px, 5vw, 64px) clamp(28px, 5vw, 72px) 0;
          }
          .feat-dd-body .saint-copy { max-width: 720px; margin: 0 auto; }
          .feat-dd-name {
            font-family: var(--font-display);
            font-weight: 500;
            line-height: 1.05;
            letter-spacing: -0.02em;
            text-wrap: balance;
            color: var(--ink);
            font-size: clamp(36px, 5vw, 56px);
            text-align: left;
            margin: 0 0 clamp(8px, 1vw, 12px);
          }
          .feat-dd-backlink {
            appearance: none;
            background: transparent;
            border: 0;
            padding: 0;
            margin: 0 0 clamp(16px, 2vw, 24px);
            cursor: pointer;
            color: var(--ink-mute);
            font-family: var(--font-body);
            font-size: 12px;
            letter-spacing: 0.04em;
            line-height: 1;
            white-space: nowrap;
            align-self: flex-start;
            display: inline-block;
            transition: color 180ms ease;
          }
          .feat-dd-backlink:hover { color: var(--accent); }
        `}</style>
      </section>);

  }

  if (layout === "full-bleed") {
    return (
      <section className="feat-bleed">
        <div className="feat-bleed-img">
          <SaintFigure tall fillBleed />
        </div>
        <div className="feat-bleed-card">
          <SaintCopy compact />
        </div>
        <style>{`
          .feat-bleed {
            position: relative;
            min-height: clamp(720px, 90vh, 1000px);
            display: grid;
            grid-template-columns: 1.1fr 1fr;
            align-items: stretch;
          }
          .feat-bleed-img {
            position: relative;
            padding: 0;
          }
          .feat-bleed-img .saint-figure {
            max-width: none;
            width: 100%;
            height: 100%;
          }
          .feat-bleed-img .saint-figure-frame {
            aspect-ratio: auto;
            height: 100%;
            border-radius: 0;
            border-left: none;
            border-top: none;
            border-bottom: none;
          }
          .feat-bleed-img .saint-plate { display: none; }
          .feat-bleed-card {
            padding: clamp(40px, 6vw, 88px) clamp(32px, 5vw, 72px);
            display: flex;
            align-items: center;
          }
          @media (max-width: 900px) {
            .feat-bleed { grid-template-columns: 1fr; }
            .feat-bleed-img { min-height: 520px; }
          }
        `}</style>
      </section>);

  }

  if (layout === "centered") {
    return (
      <section className="feat-centered">
        <div className="feat-centered-img">
          <SaintFigure tall />
        </div>
        <div className="feat-centered-copy">
          <SaintCopy />
        </div>
        <style>{`
          .feat-centered {
            display: flex;
            flex-direction: column;
            align-items: center;
            gap: clamp(48px, 6vw, 80px);
            padding: clamp(40px, 6vw, 80px) clamp(24px, 5vw, 72px) clamp(80px, 10vw, 140px);
          }
          .feat-centered-img { width: min(420px, 80vw); }
          .feat-centered-copy { max-width: 640px; text-align: left; }
        `}</style>
      </section>);

  }

  if (layout === "image-left") {
    return (
      <section className="feat-split feat-image-left">
        <div className="feat-img-col">
          <SaintFigure />
        </div>
        <div className="feat-copy-col">
          <SaintCopy />
        </div>
        <style>{`
          .feat-split {
            display: grid;
            grid-template-columns: 1fr 1fr;
            gap: clamp(48px, 6vw, 96px);
            align-items: center;
            padding: clamp(40px, 6vw, 80px) clamp(32px, 6vw, 96px) clamp(80px, 10vw, 140px);
            max-width: 1480px;
            margin: 0 auto;
          }
          .feat-image-left .feat-img-col { display: flex; justify-content: flex-end; }
          .feat-image-left .feat-copy-col { display: flex; justify-content: flex-start; }
          @media (max-width: 900px) {
            .feat-split { grid-template-columns: 1fr; }
            .feat-image-left .feat-img-col,
            .feat-image-left .feat-copy-col { justify-content: center; }
          }
        `}</style>
      </section>);

  }

  // default: editorial-split — copy left, figure right
  return (
    <section className="feat-split feat-editorial">
      <div className="feat-copy-col">
        <SaintCopy />
      </div>
      <div className="feat-img-col">
        <SaintFigure />
      </div>
      <style>{`
        .feat-editorial {
          display: grid;
          grid-template-columns: 1fr 1fr;
          gap: clamp(48px, 6vw, 96px);
          align-items: center;
          padding: clamp(40px, 6vw, 80px) clamp(32px, 6vw, 96px) clamp(80px, 10vw, 140px);
          max-width: 1480px;
          margin: 0 auto;
        }
        .feat-editorial .feat-copy-col { display: flex; justify-content: flex-end; }
        .feat-editorial .feat-img-col { display: flex; justify-content: flex-start; }
        @media (max-width: 900px) {
          .feat-editorial { grid-template-columns: 1fr; gap: 48px; }
          .feat-editorial .feat-copy-col,
          .feat-editorial .feat-img-col { justify-content: center; }
          .feat-editorial .feat-copy-col { order: 2; }
          .feat-editorial .feat-img-col { order: 1; }
        }
      `}</style>
    </section>);

}

function Footer() {
  return (
    <footer className="site-footer">
      <div className="footer-row">
        <div className="footer-mark">
          <span className="foot-asterisk"></span>
          <span className="foot-name" style={{ fontSize: "12px" }}></span>
        </div>
        <div className="footer-tag">

        </div>
        <div className="footer-meta"></div>
      </div>
      <style>{`
        .site-footer {
                    padding: 28px clamp(24px, 5vw, 64px);
          background: var(--bg);
        }
        .footer-row {
          display: flex;
          align-items: center;
          justify-content: space-between;
          gap: 24px;
          max-width: 1480px;
          margin: 0 auto;
          flex-wrap: wrap;
        }
        .footer-mark { display: flex; align-items: center; gap: 8px; }
        .foot-asterisk { color: var(--accent); }
        .foot-name { font-family: var(--font-display); font-style: normal; font-size: 18px; }
        .footer-tag {
          font-family: var(--font-quote);
          font-style: normal;
          color: var(--ink-mute);
          font-size: 14px;
        }
        .footer-meta {
          font-family: var(--font-body);
          font-size: 10.5px;
          letter-spacing: 0.3em;
          color: var(--ink-mute);
          text-transform: uppercase;
        }
      `}</style>
    </footer>);

}

function FeaturedDeepDiveCard({ onNavigate }) {
  return (
    <section className="ddc-wrap">
      <div className="ddc-eyebrow">
        <span className="ddc-eyebrow-mark">✻</span>
        <span>Featured Deep Dive</span>
      </div>
      <button
        type="button"
        className="ddc-card"
        onClick={() => onNavigate && onNavigate("saint")}>
        <div className="ddc-portrait">
          <div className="ddc-portrait-glow" />
          <div className="ddc-portrait-mono">J</div>
        </div>
        <div className="ddc-meta">
          <div className="ddc-years">1160 — 1213</div>
          <h3 className="ddc-name">
            St. John<br />
            <span className="ddc-of">of Matha</span>
          </h3>
          <p className="ddc-deck">
            Founder of the Trinitarians — a 12th-century order whose vocation was to ransom
            captives. Read the deep dive →
          </p>
        </div>
      </button>
      <style>{`
        .ddc-wrap {
          max-width: 1240px; margin: 0 auto;
          padding: 0 clamp(24px, 5vw, 72px) clamp(80px, 10vh, 120px);
          font-family: var(--font-body); color: var(--ink);
        }
        .ddc-eyebrow {
          display: flex; align-items: center; gap: 12px;
          font-size: 11px; letter-spacing: 0.32em; text-transform: uppercase;
          color: var(--ink-mute); margin-bottom: 24px;
        }
        .ddc-eyebrow-mark { color: var(--accent); font-size: 14px; }
        .ddc-card {
          appearance: none; background: transparent; border: 1px solid var(--bg-deep);
          padding: 28px; cursor: pointer; width: 100%; max-width: 360px;
          display: flex; flex-direction: column; gap: 22px; text-align: left;
          color: inherit; font: inherit;
          transition: border-color 200ms, transform 200ms;
        }
        .ddc-card:hover { border-color: var(--ink); transform: translateY(-2px); }
        .ddc-card:hover .ddc-portrait-mono { transform: scale(1.04); }
        .ddc-portrait {
          aspect-ratio: 1 / 1; width: 100%;
          background: #1d2330; color: rgba(255,255,255,0.92);
          position: relative; overflow: hidden;
        }
        .ddc-portrait-glow {
          position: absolute; inset: 0;
          background: radial-gradient(120% 80% at 30% 20%, rgba(255,255,255,0.18), transparent 60%);
        }
        .ddc-portrait-label {
          position: absolute; top: 14px; right: 16px;
          font-size: 10px; letter-spacing: 0.32em; text-transform: uppercase;
          opacity: 0.55;
        }
        .ddc-portrait-mono {
          position: absolute; left: 20px; bottom: 14px;
          font-family: Inter, sans-serif;
          font-size: clamp(80px, 12vw, 160px); font-weight: 300;
          letter-spacing: -0.04em; line-height: 0.85;
          transition: transform 600ms cubic-bezier(.2,.7,.2,1);
        }
        .ddc-years {
          font-size: 10px; letter-spacing: 0.28em; text-transform: uppercase;
          color: var(--accent); margin-bottom: 6px;
        }
        .ddc-name {
          font-family: var(--font-display); font-weight: 500;
          font-size: 26px; line-height: 1.1; letter-spacing: -0.01em;
          margin: 0 0 10px;
        }
        .ddc-of { color: var(--ink-mute); font-weight: 400; }
        .ddc-deck {
          font-size: 13px; line-height: 1.55; color: var(--ink-mute);
          margin: 0;
        }
      `}</style>
    </section>);

}

function Landing({ subtitle, layout, navPlacement, route = "home", previousRoute, onNavigate }) {
  const showLeftRail = navPlacement === "left-rail";
  const useTopBar = navPlacement === "top-bar";
  const showFloatingNav = navPlacement === "centered";

  return (
    <div className={"landing has-nav-" + navPlacement + " route-" + route + " is-inner"}>
      <div className="landing-inner">
        <CompactHeader route={route} onNavigate={onNavigate} />
        {route === "topics" &&
        <div className="route-content" key={route}>
            <FindByCircumstance onNavigate={onNavigate} />
          </div>
        }
        {route === "saint" &&
        <div className="route-content" key={route}>
            <FeaturedSaint pageMode="deepdive" previousRoute={previousRoute} onNavigate={onNavigate} />
          </div>
        }
        {route && route.startsWith("saint-") &&
        <div className="route-content" key={route}>
            <SaintDeepDive slug={route} previousRoute={previousRoute} onNavigate={onNavigate} />
          </div>
        }
        {route === "about" &&
        <div className="route-content" key={route}>
            <WhyStudy />
          </div>
        }
        {route === "saints" &&
        <div className="route-content" key={route}>
            <PopularSaints onNavigate={onNavigate} />
          </div>
        }
        <Footer />
      </div>
      <style>{`
        .landing { position: relative; min-height: 100vh; }
        .landing-inner.has-left-rail {
          margin-left: 220px;
        }
        @media (max-width: 900px) {
          .landing-inner.has-left-rail { margin-left: 0; }
        }
        .route-content {
          animation: routeFadeIn 600ms cubic-bezier(.2,.7,.2,1) both;
        }
        @keyframes routeFadeIn {
          from { opacity: 0; }
          to   { opacity: 1; }
        }
        .topics-eyebrow {
          display: flex;
          align-items: center;
          justify-content: center;
          gap: 14px;
          padding: clamp(20px, 3vh, 36px) 24px clamp(8px, 2vh, 20px);
          font-family: var(--font-body);
          font-size: 11px;
          letter-spacing: 0.32em;
          text-transform: uppercase;
          color: var(--ink-mute);
        }
        .topics-eyebrow-mark { color: var(--accent); font-size: 14px; }
        .saint-backlink {
          max-width: 1240px; margin: 0 auto;
          padding: clamp(24px, 4vh, 40px) clamp(24px, 5vw, 72px) 0;
        }
        .saint-backlink a {
          font-size: 11px; letter-spacing: 0.28em; text-transform: uppercase;
          color: var(--ink-mute); text-decoration: none;
          transition: color 200ms;
        }
        .saint-backlink a:hover { color: var(--accent); }
        .route-placeholder {
          padding: clamp(60px, 12vh, 140px) clamp(24px, 5vw, 64px);
          text-align: center;
          font-family: var(--font-body);
          color: var(--ink-soft);
          min-height: 50vh;
        }
        .placeholder-eyebrow {
          font-family: var(--font-display);
          font-size: clamp(28px, 4vw, 44px);
          font-weight: 500;
          color: var(--ink);
          margin-bottom: 18px;
        }
        .placeholder-body {
          font-size: 13px;
          letter-spacing: 0.3em;
          text-transform: uppercase;
          color: var(--ink-mute);
          margin: 0;
        }
        .nav-link.is-active { color: var(--accent); }
      `}</style>
    </div>);

}

window.Landing = Landing;