// layout.jsx
// The shared page layout: brand marks, Nav, Footer.
// Loaded before landing.jsx and legal.jsx, which call into these directly
// (these scripts share one global scope — there are no modules here).
//
// Hooks are fully qualified (React.useEffect) on purpose: landing.jsx owns the
// top-level `const { useState, useEffect, useRef } = React` destructuring, and a
// second top-level `const` for the same names would be a redeclaration SyntaxError.

const BRAND_ACCENT = "#205FA6";

const LogoFull = () => (
  <svg viewBox="0 0 178 36" fill="none">
    <path
      d="M52.2604 20.0896H45.7011L44.4505 23.1184H41.0977L47.3962 8.9881H50.6265L56.9429 23.1184H53.5111L52.2604 20.0896ZM51.2311 17.6062L48.9906 12.1967L46.7502 17.6062H51.2311Z"
      fill="#205FA6"
    />
    <path
      d="M75.313 23.1184L75.2933 14.6406L71.1344 21.6248H69.6605L65.5214 14.8224V23.1184H62.4551V8.9881H65.1598L70.4488 17.7682L75.6568 8.9881H78.3418L78.3813 23.1184H75.313Z"
      fill="#205FA6"
    />
    <path
      d="M98.0417 17.051C98.4981 17.6496 98.7273 18.3866 98.7273 19.2618C98.7273 20.5006 98.2452 21.4509 97.283 22.1187C96.3209 22.7845 94.9181 23.1184 93.0747 23.1184H85.7686V8.9881H92.6717C94.3945 8.9881 95.7163 9.31804 96.6389 9.97793C97.5616 10.6378 98.0219 11.5328 98.0219 12.6629C98.0219 13.3485 97.858 13.961 97.528 14.5003C97.1981 15.0397 96.7377 15.4625 96.145 15.7727C96.9511 16.0256 97.5833 16.4523 98.0417 17.051ZM89.0186 11.4498V14.7809H92.2687C93.0767 14.7809 93.6892 14.6406 94.1061 14.3561C94.5229 14.0736 94.7324 13.6567 94.7324 13.1055C94.7324 12.5543 94.5229 12.1394 94.1061 11.8647C93.6892 11.5881 93.0767 11.4518 92.2687 11.4518H89.0186V11.4498ZM94.7818 20.2319C95.2184 19.9494 95.4377 19.5127 95.4377 18.92C95.4377 17.7484 94.5704 17.1636 92.8337 17.1636H89.0186V20.6547H92.8337C93.6951 20.6547 94.3432 20.5144 94.7818 20.2319Z"
      fill="#205FA6"
    />
    <path d="M105.247 8.9881H108.517V23.1184H105.247V8.9881Z" fill="#205FA6" />
    <path
      d="M118.832 11.6514H114.31V8.98615H126.622V11.6514H122.1V23.1165H118.83V11.6514H118.832Z"
      fill="#205FA6"
    />
    <path d="M132.417 8.9881H135.687V23.1184H132.417V8.9881Z" fill="#205FA6" />
    <path
      d="M145.951 22.4111C144.773 21.7789 143.851 20.9076 143.185 19.7972C142.519 18.6869 142.185 17.4382 142.185 16.0533C142.185 14.6683 142.519 13.4196 143.185 12.3093C143.851 11.1989 144.773 10.3276 145.951 9.69541C147.128 9.06318 148.45 8.74707 149.918 8.74707C151.384 8.74707 152.704 9.06318 153.873 9.69541C155.045 10.3276 155.966 11.1989 156.639 12.3093C157.311 13.4196 157.649 14.6683 157.649 16.0533C157.649 17.4402 157.313 18.6869 156.639 19.7972C155.966 20.9076 155.045 21.7789 153.873 22.4111C152.702 23.0433 151.384 23.3595 149.918 23.3595C148.45 23.3595 147.128 23.0433 145.951 22.4111ZM152.178 19.9988C152.85 19.6155 153.379 19.0801 153.763 18.3945C154.146 17.7089 154.338 16.9285 154.338 16.0533C154.338 15.178 154.146 14.3976 153.763 13.712C153.379 13.0265 152.852 12.491 152.178 12.1078C151.505 11.7245 150.752 11.5328 149.918 11.5328C149.084 11.5328 148.33 11.7245 147.658 12.1078C146.984 12.491 146.457 13.0265 146.073 13.712C145.69 14.3976 145.498 15.18 145.498 16.0533C145.498 16.9285 145.69 17.7089 146.073 18.3945C146.457 19.0801 146.984 19.6155 147.658 19.9988C148.33 20.3821 149.084 20.5737 149.918 20.5737C150.752 20.5737 151.505 20.3821 152.178 19.9988Z"
      fill="#205FA6"
    />
    <path
      d="M177.108 8.9881V23.1184H174.423L167.378 14.5399V23.1184H164.147V8.9881H166.852L173.876 17.5667V8.9881H177.108Z"
      fill="#205FA6"
    />
    <path
      d="M14.0895 30.2605C15.2038 33.3821 16.2431 36 16.2431 36C16.2431 36 17.2823 33.3821 18.3966 30.2605C18.9281 28.7728 17.8217 27.2061 16.2431 27.2061C14.6625 27.208 13.5581 28.7728 14.0895 30.2605Z"
      fill="#205FA6"
    />
    <path
      d="M16.2432 22.6284C17.306 22.6284 18.1675 21.7668 18.1675 20.704C18.1675 19.6412 17.306 18.7797 16.2432 18.7797C15.1804 18.7797 14.3188 19.6412 14.3188 20.704C14.3188 21.7668 15.1804 22.6284 16.2432 22.6284Z"
      fill="#205FA6"
    />
    <path
      d="M29.2315 29.4189H23.6007L20.7873 25.6038C20.9888 24.5507 21.1074 23.4483 21.1074 22.3083C21.1074 15.0693 16.2431 9.2014 16.2431 9.2014C16.2431 9.2014 11.375 15.0693 11.375 22.3083C11.375 23.4483 11.4935 24.5507 11.699 25.6038L8.88163 29.4189H3.25084C0.751559 29.4189 -0.811226 26.7141 0.441378 24.5488L13.7992 1.40918C14.8858 -0.469726 17.6005 -0.469726 18.6831 1.40918L32.0449 24.5488C33.2936 26.7141 31.7308 29.4189 29.2315 29.4189Z"
      fill="#205FA6"
    />
  </svg>
);

const LogoIcon = ({ color = "#205FA6" }) => (
  <svg width="109" height="120" viewBox="0 0 109 120" fill="none">
    <path
      d="M46.9581 100.872C50.6735 111.276 54.1385 120 54.1385 120C54.1385 120 57.6016 111.274 61.317 100.872C63.088 95.9132 59.403 90.6934 54.1385 90.6934C48.8721 90.6934 45.1872 95.9114 46.9581 100.872Z"
      fill={color}
    />
    <path
      d="M54.1393 75.4271C57.6821 75.4271 60.5541 72.5552 60.5541 69.0124C60.5541 65.4696 57.6821 62.5977 54.1393 62.5977C50.5966 62.5977 47.7246 65.4696 47.7246 69.0124C47.7246 72.5552 50.5966 75.4271 54.1393 75.4271Z"
      fill={color}
    />
    <path
      d="M97.4329 98.0613H78.6645L69.2857 85.3481C69.9565 81.8366 70.3536 78.1606 70.3536 74.3629C70.3536 50.2352 54.1396 30.6744 54.1396 30.6744C54.1396 30.6744 37.915 50.2352 37.915 74.3629C37.915 78.1606 38.3121 81.8366 38.9936 85.3481L29.6041 98.0613H10.8375C2.50512 98.0613 -2.70216 89.0456 1.46939 81.8259L45.9951 4.69702C49.6157 -1.56567 58.6654 -1.56567 62.2752 4.69702L106.812 81.8259C110.972 89.0456 105.765 98.0613 97.4329 98.0613Z"
      fill={color}
    />
  </svg>
);

// ── Brand mark ────────────────────────────────────────────────────
const LogoMark = ({ color = "#fff", size = 18 }) => (
  <svg width={size} height={size * 1.15} viewBox="0 0 100 115" fill="none">
    {/* A-shape (rocket exterior) */}
    <path
      d="M50 5 L92 90 H8 Z M50 28 L28 78 H72 Z"
      fill={color}
      fillRule="evenodd"
    />
    {/* astronaut head */}
    <circle cx="50" cy="58" r="6" fill={color} />
    {/* rocket fin/tail */}
    <path d="M44 67 L50 92 L56 67 Z" fill={color} />
  </svg>
);

// ── Sticky nav scroll-state ──────────────────────────────────────
function useScrollClass() {
  React.useEffect(() => {
    const nav = document.querySelector(".nav");
    const fn = () => nav?.classList.toggle("scrolled", window.scrollY > 8);
    fn();
    window.addEventListener("scroll", fn, { passive: true });
    return () => window.removeEventListener("scroll", fn);
  }, []);
}

// ── App store buttons (real-looking) ─────────────────────────────
const AppleSVG = (
  <svg viewBox="0 0 24 24" fill="currentColor">
    <path d="M17.05 11.97c-.03-2.83 2.31-4.19 2.42-4.26-1.32-1.93-3.38-2.19-4.11-2.22-1.75-.18-3.42 1.03-4.31 1.03-.91 0-2.27-1.01-3.74-.98-1.92.03-3.7 1.12-4.69 2.84-2 3.47-.51 8.6 1.44 11.42.95 1.38 2.08 2.92 3.55 2.87 1.43-.06 1.97-.92 3.7-.92 1.72 0 2.21.92 3.71.89 1.54-.03 2.51-1.4 3.45-2.78 1.09-1.6 1.54-3.15 1.56-3.23-.03-.01-2.99-1.14-3.02-4.54zm-2.83-8.34c.78-.94 1.31-2.25 1.16-3.55-1.13.05-2.49.75-3.3 1.69-.72.83-1.36 2.16-1.19 3.44 1.26.1 2.55-.64 3.33-1.58z" />
  </svg>
);

const GoogleSVG = (
  <svg viewBox="0 0 64 64" strokeWidth="3" stroke="currentColor" fill="none">
    <path d="M12.36,53.33V10.67a1,1,0,0,1,1.56-.91L51.11,31a1,1,0,0,1,0,1.81L13.93,54.24A1.05,1.05,0,0,1,12.36,53.33Z" />
    <line x1="12.36" y1="10.67" x2="42.07" y2="38.02" />
    <line x1="12.36" y1="53.33" x2="41.24" y2="25.35" />
  </svg>
);

const StoreButton = ({ store = "apple", accent }) => {
  const storeLinks = {
    apple:
      "https://apps.apple.com/us/app/ambition-shape-your-future/id1557562279",
    google:
      "https://play.google.com/store/apps/details?id=com.theambitionapp.ambitionappRN",
  };
  return (
    <a
      href={storeLinks[store]}
      className="store-btn"
      style={accent ? { background: accent } : undefined}
      target="_blank"
    >
      {store === "apple" ? AppleSVG : GoogleSVG}
      <div>
        <div className="small">
          {store === "apple" ? "Download on the" : "Get it on"}
        </div>
        <div className="big">
          {store === "apple" ? "App Store" : "Google Play"}
        </div>
      </div>
    </a>
  );
};

// ── Section: Nav ─────────────────────────────────────────────────
// `base` prefixes the section anchors so they still resolve off the home page.
// Home passes "" (plain "#how"); subpages pass "/" (so "#how" → "/#how").
function Nav({ ctaCopy = "Get Ambition", accent = BRAND_ACCENT, base = "" }) {
  return (
    <nav className="nav">
      <div className="container nav-row">
        <a href={base || "#"} className="nav-logo">
          <LogoFull />
        </a>
        <div className="nav-links">
          <a href={`${base}#how`}>How it works</a>
          <a href={`${base}#features`}>Features</a>
          <a href={`${base}#pricing`}>Pricing</a>
        </div>
        <div className="nav-actions">
          <a
            href={`${base}#cta`}
            className="btn btn-primary"
            style={{ padding: "10px 18px", fontSize: 14 }}
          >
            {ctaCopy}
          </a>
        </div>
      </div>
    </nav>
  );
}

// ── Footer ──────────────────────────────────────────────────────
function Footer({ accent = BRAND_ACCENT }) {
  return (
    <footer>
      <div className="container">
        <div className="footer-main">
          <div>
            <div className="nav-logo">
              <span className="mark" style={{ background: accent }}>
                <LogoIcon color="#fff" />
              </span>
              <span>Ambition</span>
            </div>
            <p className="footer-tagline">
              The app that helps families prepare teens for adulthood — through
              career exploration, life skills, and real conversations.
            </p>
          </div>
          <div className="footer-contact">
            <h4>Get in touch</h4>
            <a href="mailto:info@theambitionapp.com" className="footer-email">
              info@theambitionapp.com
            </a>
            <p className="footer-note">
              Questions, press, partnerships, or school inquiries — we read
              everything.
            </p>
          </div>
        </div>
        <div className="footer-bottom">
          <div>© 2026 Ambition, Inc. Made for families who care.</div>
        </div>
      </div>
    </footer>
  );
}
