# Legal

> Publish terms and privacy people can read, with a plain summary over each clause.

Page: https://uicontext.com/blocks/legal

A screen in Marketing site. Preview it at https://uicontext.com/blocks/legal/preview.

## Installation

```sh
pnpm dlx shadcn@latest add checkfu/uicontext/legal
```

With npm: `npx shadcn@latest add checkfu/uicontext/legal`. With yarn: `yarn dlx shadcn@latest add checkfu/uicontext/legal`. With bun: `bunx --bun shadcn@latest add checkfu/uicontext/legal`.

## Components used

- [Button](https://uicontext.com/docs/components/button.md) (`button`): A button, and a link that looks like one, in every tone and three sizes.

## Source

As written in the repository. `src/blocks/marketing/Legal.ts` is the screen; the other files are pieces it imports.

```ts title="src/blocks/marketing/Legal.ts"
import type { Html } from "effect/ui/html"
import * as stylex from "@stylexjs/stylex"
import { sx } from "../../Sx.ts"
import { color, corner, font, space, stroke } from "../../tokens.stylex.ts"
import { longDate } from "./Content.ts"
import { rhythm, type as marketingType } from "./marketing.stylex.ts"
import { sectionStyles } from "./Section.ts"

// A legal document: terms, privacy, cookies. The other documents as links across the top, the
// day it last changed, then each section with a short plain-language summary above the binding
// text. Its sections are listed beside it on a wide screen and above it on a phone, each an anchor,
// so support can link to the exact clause.

export interface LegalSection {
	/** the anchor: "payment" */
	readonly id: string
	readonly title: string
	/** what the section means, in one or two plain sentences; not binding */
	readonly summary: string
	readonly paragraphs: ReadonlyArray<string>
}

export interface LegalDocument {
	readonly label: string
	readonly href: string
}

export interface LegalOptions {
	readonly title: string
	/** the ISO day it last changed */
	readonly updated: string
	/** what changed last time, and how people heard: "We emailed workspace owners on October 30." */
	readonly changeNote?: string
	/** every legal document, this one marked by `current` */
	readonly documents: ReadonlyArray<LegalDocument>
	readonly current: string
	readonly sections: ReadonlyArray<LegalSection>
	/** "Questions? legal@tidewater.example" */
	readonly contact?: { readonly text: string; readonly email: string }
	readonly locale?: string
}

const styles = stylex.create({
	inner: {
		boxSizing: "border-box",
		maxInlineSize: `calc(${rhythm.page} + 2 * ${rhythm.gutter})`,
		marginInline: "auto",
		paddingInline: rhythm.gutter,
		paddingBlock: rhythm.section,
		display: "grid",
		gap: { default: space.xxl, "@container (min-width: 1024px)": 40 },
		gridTemplateColumns: { default: "minmax(0, 1fr)", "@container (min-width: 1024px)": "15rem minmax(0, 44rem)" },
		columnGap: { default: 0, "@container (min-width: 1024px)": 64 },
	},
	header: { display: "grid", gap: space.lg, gridColumn: { default: "auto", "@container (min-width: 1024px)": "2" } },
	docs: { display: "flex", flexWrap: "wrap", gap: space.xs, margin: 0, padding: 0, listStyle: "none" },
	doc: {
		display: "inline-flex",
		alignItems: "center",
		minBlockSize: { default: 32, "@media (pointer: coarse)": 44 },
		paddingInline: space.lg,
		borderRadius: corner.pill,
		fontSize: font.sm,
		fontWeight: 500,
		color: { default: color.muted, ":hover": { default: null, "@media (hover: hover) and (pointer: fine)": color.fg } },
		textDecoration: "none",
		borderWidth: stroke.hairline,
		borderStyle: "solid",
		borderColor: "transparent",
	},
	docCurrent: { color: color.fg, backgroundColor: color.raised, borderColor: color.line },
	updated: { margin: 0, fontSize: font.sm, color: color.muted },
	toc: {
		gridRow: { default: "auto", "@container (min-width: 1024px)": "1 / span 2" },
		alignSelf: "start",
		position: { default: "static", "@container (min-width: 1024px)": "sticky" },
		insetBlockStart: space.xxl,
		padding: { default: space.xl, "@container (min-width: 1024px)": 0 },
		borderWidth: { default: 1, "@container (min-width: 1024px)": 0 },
		borderStyle: "solid",
		borderColor: color.line,
		borderRadius: corner.card,
		fontSize: font.sm,
	},
	tocTitle: { margin: 0, marginBlockEnd: space.md, fontSize: font.sm, fontWeight: 600 },
	tocList: { display: "grid", gap: space.xxs, margin: 0, paddingInlineStart: "1.6em", color: color.muted, fontVariantNumeric: "tabular-nums" },
	tocLink: {
		display: "block",
		paddingBlock: { default: space.xs, "@media (pointer: coarse)": space.md },
		color: { default: color.muted, ":hover": { default: null, "@media (hover: hover) and (pointer: fine)": color.fg } },
		lineHeight: 1.45,
		textDecoration: "none",
	},
	body: { display: "grid", gap: 40, gridColumn: { default: "auto", "@container (min-width: 1024px)": "2" }, minInlineSize: 0, counterReset: "clause" },
	section: { display: "grid", gap: space.lg, scrollMarginBlockStart: 96 },
	h2: { margin: 0, fontSize: "1.375rem", lineHeight: 1.3, fontWeight: 650, letterSpacing: "-0.02em", fontVariantNumeric: "tabular-nums" },
	number: { color: color.muted, marginInlineEnd: "0.5em" },
	summary: {
		margin: 0,
		padding: space.xl,
		borderInlineStartWidth: 2,
		borderInlineStartStyle: "solid",
		borderInlineStartColor: color.brand,
		backgroundColor: color.app,
		borderStartEndRadius: corner.control,
		borderEndEndRadius: corner.control,
		fontSize: font.base,
		lineHeight: 1.6,
	},
	summaryLabel: { display: "block", marginBlockEnd: space.xxs, fontSize: font.xs, fontWeight: 600, letterSpacing: "0.04em", textTransform: "uppercase", color: color.muted },
	p: { margin: 0, fontSize: marketingType.prose, lineHeight: 1.75, color: color.fg, textWrap: "pretty" },
	contact: { margin: 0, paddingBlockStart: space.xxl, borderBlockStartWidth: stroke.hairline, borderBlockStartStyle: "solid", borderBlockStartColor: color.line, fontSize: font.base, color: color.muted },
	email: { color: color.brand, fontWeight: 550, textUnderlineOffset: 3 },
})

export const Legal = <M>(h: Html.H<M>, options: LegalOptions) =>
	h.article.attrs({ "aria-labelledby": "legal-title", ...sx(sectionStyles.root) }).children(
		h.div.attrs(sx(styles.inner)).children(
			h.header.attrs(sx(styles.header)).children(
				h.nav.attrs({ "aria-label": "Legal documents" }).children(
					h.ul.attrs(sx(styles.docs)).children(
						options.documents.map((doc) =>
							h.li.key(doc.href).children(
								h.a.attrs({ href: doc.href, "aria-current": doc.label === options.current ? "page" : undefined, ...sx(styles.doc, doc.label === options.current && styles.docCurrent, sectionStyles.focus) }).children(doc.label),
							),
						),
					),
				),
				h.h1.attrs({ id: "legal-title", ...sx(sectionStyles.display) }).children(options.title),
				h.p.attrs(sx(styles.updated)).children(
					"Last updated ",
					h.time.attrs({ datetime: options.updated }).children(longDate(options.updated, options.locale)),
					options.changeNote === undefined ? "." : `. ${options.changeNote}`,
				),
			),
			h.nav.attrs({ "aria-labelledby": "legal-toc", ...sx(styles.toc) }).children(
				h.h2.attrs({ id: "legal-toc", ...sx(styles.tocTitle) }).children("Sections"),
				h.ol.attrs(sx(styles.tocList)).children(
					options.sections.map((section) => h.li.key(section.id).children(h.a.attrs({ href: `#${section.id}`, ...sx(styles.tocLink, sectionStyles.focus) }).children(section.title))),
				),
			),
			h.div.attrs(sx(styles.body)).children(
				options.sections.map((section, index) =>
					h.section.key(section.id).attrs({ id: section.id, "aria-labelledby": `${section.id}-title`, ...sx(styles.section) }).children(
						h.h2.attrs({ id: `${section.id}-title`, ...sx(styles.h2) }).children(h.span.attrs(sx(styles.number)).children(`${index + 1}.`), section.title),
						h.p.attrs(sx(styles.summary)).children(h.span.attrs(sx(styles.summaryLabel)).children("In short"), section.summary),
						section.paragraphs.map((text, i) => h.p.key(`${i}`).attrs(sx(styles.p)).children(text)),
					),
				),
				options.contact !== undefined && h.p.attrs(sx(styles.contact)).children(
					`${options.contact.text} `,
					h.a.attrs({ href: `mailto:${options.contact.email}`, ...sx(styles.email, sectionStyles.focus) }).children(options.contact.email),
				),
			),
		),
	)
```

```ts title="src/blocks/marketing/Content.ts"
import type { View } from "effect/ui"
import type { Html } from "effect/ui/html"
import * as stylex from "@stylexjs/stylex"
import { Avatar } from "../../Avatar.ts"
import { sx } from "../../Sx.ts"
import { color, corner, font, motion, space, stroke } from "../../tokens.stylex.ts"
import { type Action, ArrowLink, Section, SectionHeader, sectionStyles } from "./Section.ts"

// The pages that change every week: the changelog and the blog's index. (The article itself is
// `BlogPost`, in Article.ts.) Dates arrive as ISO days ("2026-11-28") and are written for the
// reader's locale; each sits in a `<time>` with the machine-readable day.

export interface Author {
	readonly name: string
	readonly role?: string
	readonly avatar?: string
}

export interface Change {
	readonly kind: "Added" | "Improved" | "Fixed"
	readonly text: string
}

export interface ChangelogEntry<M = never> {
	/** the anchor: "2026-11-28" */
	readonly id: string
	/** the ISO day it shipped */
	readonly date: string
	readonly version?: string
	readonly title: string
	readonly body: string
	readonly changes?: ReadonlyArray<Change>
	/** a ProductShot of what changed */
	readonly media?: View.Content<M>
}

export interface Post {
	readonly href: string
	readonly title: string
	readonly excerpt: string
	readonly category: string
	readonly date: string
	readonly minutes: number
	readonly author: Author
}

/** "November 28, 2026", in UTC so the day doesn't move with the reader's time zone. */
export const longDate = (iso: string, locale?: string) =>
	new Intl.DateTimeFormat(locale, { year: "numeric", month: "long", day: "numeric", timeZone: "UTC" }).format(new Date(`${iso}T00:00:00Z`))

/** "6 min read" */
export const readingTime = (minutes: number) => `${Math.max(1, Math.round(minutes))} min read`

const styles = stylex.create({
	entries: { display: "grid", margin: 0, padding: 0, listStyle: "none" },
	entry: {
		display: "grid",
		gap: { default: space.lg, "@container (min-width: 768px)": 40 },
		gridTemplateColumns: { default: "minmax(0, 1fr)", "@container (min-width: 768px)": "11rem minmax(0, 1fr)" },
		paddingBlock: { default: space.xxl, "@container (min-width: 768px)": 40 },
		borderBlockStartWidth: stroke.hairline,
		borderBlockStartStyle: "solid",
		borderBlockStartColor: color.line,
	},
	when: {
		display: "flex",
		flexDirection: { default: "row", "@container (min-width: 768px)": "column" },
		alignItems: { default: "center", "@container (min-width: 768px)": "flex-start" },
		gap: space.md,
		alignSelf: "start",
		position: { default: "static", "@container (min-width: 768px)": "sticky" },
		insetBlockStart: space.xxl,
		fontSize: font.sm,
		color: color.muted,
	},
	version: {
		fontFamily: font.mono,
		fontSize: font.xs,
		paddingInline: space.sm,
		paddingBlock: space.xxs,
		borderRadius: corner.tag,
		backgroundColor: color.raised,
		borderWidth: stroke.hairline,
		borderStyle: "solid",
		borderColor: color.line,
		color: color.fg,
	},
	entryBody: { display: "grid", gap: space.lg, minInlineSize: 0, maxInlineSize: "44rem" },
	entryTitle: { margin: 0, fontSize: "clamp(1.25rem, 1.1rem + 0.6cqi, 1.5rem)", lineHeight: 1.25, fontWeight: 650, letterSpacing: "-0.02em" },
	anchor: {
		color: "inherit",
		textDecoration: { default: "none", ":hover": { default: null, "@media (hover: hover) and (pointer: fine)": "underline" } },
		textUnderlineOffset: 4,
		textDecorationThickness: 1,
		borderRadius: corner.tag,
		outline: { default: "none", ":focus-visible": `2px solid ${color.focusRing}` },
		outlineOffset: 2,
	},
	text: { margin: 0, fontSize: font.lg, lineHeight: 1.6, color: color.muted, maxInlineSize: "65ch" },
	changes: { display: "grid", gap: space.md, margin: 0, padding: 0, listStyle: "none", fontSize: font.base, lineHeight: 1.55 },
	change: { display: "grid", gridTemplateColumns: "5.5rem minmax(0, 1fr)", gap: space.md, alignItems: "baseline" },
	kind: { fontSize: font.xs, fontWeight: 600, letterSpacing: "0.02em" },
	added: { color: color.success },
	improved: { color: color.info },
	fixed: { color: color.warning },
	media: { marginBlockStart: space.md },
	// the blog index: the newest post large, then the rest in a grid
	posts: {
		display: "grid",
		gap: { default: space.xl, "@container (min-width: 768px)": space.xxl },
		gridTemplateColumns: { default: "minmax(0, 1fr)", "@container (min-width: 768px)": "repeat(2, minmax(0, 1fr))", "@container (min-width: 1024px)": "repeat(3, minmax(0, 1fr))" },
	},
	post: {
		position: "relative",
		display: "flex",
		flexDirection: "column",
		gap: space.md,
		padding: space.xxl,
		borderWidth: stroke.hairline,
		borderStyle: "solid",
		borderColor: { default: color.line, ":has(a:hover)": { default: null, "@media (hover: hover) and (pointer: fine)": color.lineStrong } },
		borderRadius: `calc(${corner.card} + 4px)`,
		backgroundColor: { default: color.panel, ":has(a:hover)": { default: null, "@media (hover: hover) and (pointer: fine)": color.raised } },
		transitionProperty: "background-color, border-color",
		transitionDuration: motion.fast,
		minInlineSize: 0,
		outline: { default: "none", ":has(a:focus-visible)": `2px solid ${color.focusRing}` },
		outlineOffset: 2,
	},
	lead: {
		gridColumn: { default: "auto", "@container (min-width: 768px)": "1 / -1" },
		padding: { default: space.xxl, "@container (min-width: 1024px)": 40 },
		backgroundColor: { default: color.app, ":has(a:hover)": { default: null, "@media (hover: hover) and (pointer: fine)": color.raised } },
	},
	category: { margin: 0, fontSize: font.sm, fontWeight: 600, color: color.muted },
	postTitle: { margin: 0, fontSize: "1.0625rem", lineHeight: 1.3, fontWeight: 600, letterSpacing: "-0.015em", textWrap: "balance" },
	leadTitle: { fontSize: "clamp(1.5rem, 1.2rem + 1.4cqi, 2.25rem)", lineHeight: 1.15, letterSpacing: "-0.025em", maxInlineSize: "24ch" },
	// the title's link covers the whole card, so the card is one target and one tab stop
	postLink: {
		color: "inherit",
		textDecoration: "none",
		outline: "none",
		"::after": { content: "''", position: "absolute", inset: 0, borderRadius: `calc(${corner.card} + 4px)` },
	},
	excerpt: { margin: 0, flexGrow: 1, fontSize: font.base, lineHeight: 1.6, color: color.muted, textWrap: "pretty" },
	leadExcerpt: { fontSize: font.lg, maxInlineSize: "60ch" },
	byline: { display: "flex", alignItems: "center", gap: space.md, marginBlockStart: space.md, fontSize: font.sm, color: color.muted, minInlineSize: 0 },
	bylineText: { display: "grid", minInlineSize: 0, lineHeight: 1.4 },
	bylineName: { color: color.fg, fontWeight: 500, overflowWrap: "anywhere" },
	sep: { color: color.faint },
	nowrap: { whiteSpace: "nowrap" },
})

const kindStyle = { Added: styles.added, Improved: styles.improved, Fixed: styles.fixed }

/** What shipped, newest first: the day and version, a headline, why it matters, and each change. */
export const Changelog = <M>(
	h: Html.H<M>,
	options: {
		readonly id?: string
		readonly title: string
		readonly lede?: string
		/** 1 when the changelog is the page */
		readonly level?: 1 | 2
		readonly entries: ReadonlyArray<ChangelogEntry<M>>
		/** under the header: a feed, a newsletter */
		readonly subscribe?: Action
		readonly locale?: string
	},
) => {
	const id = options.id ?? "changelog-title"
	const entryHeading = options.level === 1 ? h.h2 : h.h3
	return Section(h, {
		labelledBy: id,
		children: [
			SectionHeader(h, {
				id,
				title: options.title,
				...(options.level === 1 ? { level: 1 as const } : {}),
				...(options.lede === undefined ? {} : { lede: options.lede }),
				...(options.subscribe === undefined ? {} : { actions: ArrowLink(h, options.subscribe) }),
			}),
			h.ol.attrs({ reversed: "", ...sx(styles.entries) }).children(
				options.entries.map((entry) =>
					h.li.key(entry.id).attrs({ id: entry.id, ...sx(styles.entry) }).children(
						h.div.attrs(sx(styles.when)).children(
							h.time.attrs({ datetime: entry.date }).children(longDate(entry.date, options.locale)),
							entry.version !== undefined && h.span.attrs(sx(styles.version)).children(entry.version),
						),
						h.article.attrs({ "aria-labelledby": `${entry.id}-title`, ...sx(styles.entryBody) }).children(
							entryHeading.attrs({ id: `${entry.id}-title`, ...sx(styles.entryTitle) }).children(
								h.a.attrs({ href: `#${entry.id}`, ...sx(styles.anchor) }).children(entry.title),
							),
							h.p.attrs(sx(styles.text)).children(entry.body),
							entry.media !== undefined && h.div.attrs(sx(styles.media)).children(entry.media),
							entry.changes !== undefined && entry.changes.length > 0 && h.ul.attrs({ "aria-label": "Changes", ...sx(styles.changes) }).children(
								entry.changes.map((change, i) =>
									h.li.key(`${i}`).attrs(sx(styles.change)).children(h.span.attrs(sx(styles.kind, kindStyle[change.kind])).children(change.kind), h.span.children(change.text)),
								),
							),
						),
					),
				),
			),
		],
	})
}

/** The blog's index: the newest post across the top, the rest in a grid, each card one link. */
export const BlogIndex = <M>(
	h: Html.H<M>,
	options: { readonly id?: string; readonly title: string; readonly lede?: string; readonly level?: 1 | 2; readonly posts: ReadonlyArray<Post>; readonly locale?: string; readonly more?: Action },
) => {
	const id = options.id ?? "blog-title"
	const postHeading = options.level === 1 ? h.h2 : h.h3
	return Section(h, {
		labelledBy: id,
		children: [
			SectionHeader(h, {
				id,
				title: options.title,
				...(options.level === 1 ? { level: 1 as const } : {}),
				...(options.lede === undefined ? {} : { lede: options.lede }),
			}),
			h.ul.attrs(sx(sectionStyles.list, styles.posts)).children(
				options.posts.map((post, i) => {
					const lead = i === 0
					return h.li.key(post.href).attrs(sx(styles.post, lead && styles.lead)).children(
						h.p.attrs(sx(styles.category)).children(post.category),
						postHeading.attrs(sx(styles.postTitle, lead && styles.leadTitle)).children(h.a.attrs({ href: post.href, ...sx(styles.postLink) }).children(post.title)),
						h.p.attrs(sx(styles.excerpt, lead && styles.leadExcerpt)).children(post.excerpt),
						h.p.attrs(sx(styles.byline)).children(
							Avatar(h, { key: `${post.href}:${post.author.name}`, id: post.author.name, name: post.author.name, size: "sm", decorative: true, ...(post.author.avatar === undefined ? {} : { image: post.author.avatar }) }),
							h.span.attrs(sx(styles.bylineText)).children(
								h.span.attrs(sx(styles.bylineName)).children(post.author.name),
								h.span.children(
									h.time.attrs({ datetime: post.date, ...sx(styles.nowrap) }).children(longDate(post.date, options.locale)),
									h.span.attrs({ "aria-hidden": "true", ...sx(styles.sep) }).children(" · "),
									h.span.attrs(sx(styles.nowrap)).children(readingTime(post.minutes)),
								),
							),
						),
					)
				}),
			),
			options.more !== undefined && ArrowLink(h, options.more),
		],
	})
}
```

```ts title="src/blocks/marketing/Section.ts"
import { Mount, type View } from "effect/ui"
import type { Html } from "effect/ui/html"
import * as stylex from "@stylexjs/stylex"
import { Effect, Schema, Stream } from "effect"
import { buttonStyle } from "../../Button.ts"
import { type Style, sx } from "../../Sx.ts"
import { color, corner, density, elevation, font, motion, space, stroke, typography } from "../../tokens.stylex.ts"
import { Icon } from "../saas/Icons.ts"
import { rhythm, type } from "./marketing.stylex.ts"

// What the marketing sections share: the section frame (a container, so every section lays itself
// out by its own width), a header with an optional eyebrow, links drawn as buttons, the product's
// mark, and the frame that shows a real screen of the product, scaled down.

/** A link a section offers: "Start free" to /signup. */
export const Action = Schema.Struct({ label: Schema.String, href: Schema.String })
export type Action = typeof Action.Type

/** The product's name and mark. `letter` draws the mark when there's no logo file. */
export const SiteBrand = Schema.Struct({ name: Schema.String, letter: Schema.String, href: Schema.String })
export type SiteBrand = typeof SiteBrand.Type

export const sectionStyles = stylex.create({
	root: {
		containerType: "inline-size",
		boxSizing: "border-box",
		inlineSize: "100%",
		color: color.fg,
		fontFamily: font.sans,
		backgroundColor: color.panel,
	},
	muted: { backgroundColor: color.app },
	inner: {
		boxSizing: "border-box",
		display: "grid",
		gap: rhythm.header,
		maxInlineSize: `calc(${rhythm.page} + 2 * ${rhythm.gutter})`,
		marginInline: "auto",
		paddingInline: rhythm.gutter,
		paddingBlock: rhythm.section,
	},
	header: { display: "grid", gap: space.lg, justifyItems: "start", maxInlineSize: "44rem" },
	headerCenter: { justifyItems: "center", textAlign: "center", marginInline: "auto" },
	eyebrow: { margin: 0, fontSize: font.sm, fontWeight: 600, color: color.brand, letterSpacing: "0.01em" },
	// headlines take the theme's display face and weight, so a design language carries its own voice
	title: {
		margin: 0,
		fontFamily: typography.displayFamily,
		fontSize: type.title,
		lineHeight: 1.12,
		fontWeight: typography.displayWeight,
		letterSpacing: type.tight,
		textWrap: "balance",
	},
	display: {
		margin: 0,
		fontFamily: typography.displayFamily,
		fontSize: type.display,
		lineHeight: 1.04,
		fontWeight: typography.displayWeight,
		letterSpacing: "-0.035em",
		textWrap: "balance",
	},
	lede: {
		margin: 0,
		maxInlineSize: "38rem",
		fontSize: type.lede,
		lineHeight: 1.55,
		color: color.muted,
		textWrap: "pretty",
	},
	heading: { margin: 0, fontSize: type.heading, lineHeight: 1.3, fontWeight: 600, letterSpacing: "-0.015em", textWrap: "balance" },
	body: { margin: 0, fontSize: font.base, lineHeight: 1.6, color: color.muted, textWrap: "pretty" },
	actions: { display: "flex", flexWrap: "wrap", gap: space.lg, alignItems: "center" },
	actionsCenter: { justifyContent: "center" },
	// marketing buttons sit a step above the app's largest, and stretch to the width on a phone
	action: {
		height: `calc(${density.control} + 12px)`,
		paddingInline: 20,
		fontSize: 15,
		textDecoration: "none",
		flexGrow: { default: 1, "@container (min-width: 560px)": 0 },
	},
	list: { margin: 0, padding: 0, listStyle: "none" },
	srOnly: { position: "absolute", width: 1, height: 1, overflow: "hidden", clipPath: "inset(50%)", whiteSpace: "nowrap" },
	focus: { outline: { default: "none", ":focus-visible": `2px solid ${color.focusRing}` }, outlineOffset: 2, borderRadius: corner.tag },
	textLink: {
		display: "inline-flex",
		alignItems: "center",
		gap: space.xs,
		minBlockSize: { default: null, "@media (pointer: coarse)": density.control },
		fontSize: font.base,
		fontWeight: 550,
		color: color.brand,
		textDecoration: { default: "none", ":hover": { default: null, "@media (hover: hover) and (pointer: fine)": "underline" } },
		textUnderlineOffset: 4,
		textDecorationThickness: 1,
	},
	arrow: {
		display: "inline-flex",
		transitionProperty: "transform",
		transitionDuration: motion.fast,
		transitionTimingFunction: motion.easeOut,
		transform: {
			default: null,
			":is(:hover > *)": { default: null, "@media (hover: hover) and (pointer: fine)": `translateX(${motion.shift})` },
		},
	},
	arrowFlip: { display: "inline-flex", transform: { default: null, ":dir(rtl)": "scaleX(-1)" } },
	brand: {
		display: "inline-flex",
		alignItems: "center",
		gap: space.md,
		minBlockSize: 40,
		color: color.fg,
		textDecoration: "none",
		fontSize: font.lg,
		fontWeight: 650,
		letterSpacing: "-0.02em",
		whiteSpace: "nowrap",
	},
	mark: {
		display: "grid",
		placeItems: "center",
		flexShrink: 0,
		inlineSize: 28,
		blockSize: 28,
		borderRadius: corner.control,
		backgroundColor: color.fg,
		color: color.panel,
		fontSize: font.base,
		fontWeight: 700,
		letterSpacing: 0,
	},
})

// a shot in a narrow frame (a phone's) shows the screen's first 520 by 420px, so its text stays legible
const roomy = "@container (min-width: 560px)"
const cropWidth = 520
const cropHeight = 420

const shotStyles = stylex.create({
	frame: {
		position: "relative",
		containerType: "inline-size",
		overflow: "hidden",
		inlineSize: "100%",
		borderWidth: stroke.hairline,
		borderStyle: "solid",
		borderColor: color.lineStrong,
		borderRadius: { default: corner.card, "@container (min-width: 768px)": `calc(${corner.card} + 4px)` },
		backgroundColor: color.app,
		boxShadow: elevation.menu,
		// the screen's own type, whatever the section sets
		fontSize: font.base,
		lineHeight: "normal",
		textAlign: "start",
	},
	bare: { boxShadow: "none", borderRadius: corner.card },
	// a tall screen is cut at the size's height; a short one keeps its own
	clip: { overflow: "hidden" },
	clipDesktop: { maxBlockSize: { default: `calc(100cqi * ${cropHeight} / ${cropWidth})`, [roomy]: "calc(100cqi * 800 / 1280)" } },
	clipLaptop: { maxBlockSize: { default: `calc(100cqi * ${cropHeight} / ${cropWidth})`, [roomy]: "calc(100cqi * 720 / 1024)" } },
	clipTablet: { maxBlockSize: { default: `calc(100cqi * ${cropHeight} / ${cropWidth})`, [roomy]: "calc(100cqi * 680 / 820)" } },
	// the screen laid out at the width it was designed for, then zoomed to the frame: 100cqi over
	// that width. Zoom, unlike a transform, shrinks its box too, so the frame fits the screen. In a
	// frame narrower than 560px the whole screen would shrink past reading, so the frame shows its
	// start instead, at a scale that keeps its text legible. Not every engine divides lengths this way
	// (Safari 26 drops it), so FitScreen measures the frame and sets the zoom the same way.
	screen: { pointerEvents: "none", userSelect: "none" },
	screenDesktop: { inlineSize: 1280, zoom: { default: `tan(atan2(100cqi, ${cropWidth}px))`, [roomy]: "tan(atan2(100cqi, 1280px))" } },
	screenLaptop: { inlineSize: 1024, zoom: { default: `tan(atan2(100cqi, ${cropWidth}px))`, [roomy]: "tan(atan2(100cqi, 1024px))" } },
	screenTablet: { inlineSize: 820, zoom: { default: `tan(atan2(100cqi, ${cropWidth}px))`, [roomy]: "tan(atan2(100cqi, 820px))" } },
})

export type ShotSize = "desktop" | "laptop" | "tablet"

const designWidth = { desktop: 1280, laptop: 1024, tablet: 820 } as const

/** Zooms the screen to its frame: the frame's width over the width the screen was designed at. */
const FitScreen = Mount.makeStream("ProductShot.FitScreen", { args: { width: Schema.Number } }, (node: HTMLElement, args) =>
	Stream.callback<never>(() =>
		Effect.acquireRelease(
			Effect.sync(() => {
				const frame = node.parentElement
				if (frame === null) return () => undefined
				// only a change in width rezooms: the zoom changes the frame's height, which would call this again
				let width = -1
				const sized = new ResizeObserver(([entry]) => {
					if (entry === undefined || entry.contentRect.width === width) return
					width = entry.contentRect.width
					// as the styles above: under 560px the frame shows the screen's start, 520px of it
					node.style.zoom = String(width / (width < 560 ? cropWidth : args.width))
				})
				sized.observe(frame)
				return () => sized.disconnect()
			}),
			(cleanup) => Effect.sync(cleanup),
		),
	),
)

const screenSize = { desktop: shotStyles.screenDesktop, laptop: shotStyles.screenLaptop, tablet: shotStyles.screenTablet }
const clipSize = { desktop: shotStyles.clipDesktop, laptop: shotStyles.clipLaptop, tablet: shotStyles.clipTablet }

export interface ProductShotOptions<M, C extends View.Input<M>> {
	/** What the picture shows, read in place of the screen: "The issue list, with a filter applied". */
	readonly label: string
	/**
	 * The width the screen is laid out at before it's scaled to fit, and the most of its height that
	 * shows: `desktop` 1280 by 800 (by default), `laptop` 1024 by 720, `tablet` 820 by 680. Its
	 * layout is the one people see at that size.
	 */
	readonly size?: ShotSize
	/** No shadow, for a shot inside a card. */
	readonly bare?: boolean
	/** The screen: a live component, or an image with its width and height. */
	readonly children: C
	readonly style?: Style
}

/**
 * A screen of the product at the size it was designed for, scaled down to the frame's width, so a
 * hero or a feature shows the real thing at any width. The screen can't be focused or clicked, and
 * is read as one picture by its label.
 */
export const ProductShot = <M, C extends View.Input<M>>(h: Html.H<M>, options: ProductShotOptions<M, C>) => {
	const size = options.size ?? "desktop"
	return h.div.attrs({ role: "img", "aria-label": options.label, ...sx(shotStyles.frame, options.bare === true && shotStyles.bare, options.style) }).children(
		h.div.attrs(sx(shotStyles.clip, clipSize[size])).children(
			h.div.attrs({ inert: "", "aria-hidden": "true", ...sx(shotStyles.screen, screenSize[size]) }).onMount(FitScreen({ width: designWidth[size] })).children(options.children),
		),
	)
}

export interface SectionOptions<M, C extends View.Input<M>> {
	/** The id of the heading that names the section. */
	readonly labelledBy?: string
	/** The section's name, when it has no heading of its own. */
	readonly label?: string
	/** The page's background in place of the panel's, to set one section apart from the next. */
	readonly muted?: boolean
	readonly id?: string
	readonly children: C
	/** StyleX styles for the section. */
	readonly style?: Style
	/** StyleX styles for the column inside it. */
	readonly innerStyle?: Style
}

/** A page section: a container with the page's gutters and the space above and below. */
export const Section = <M, C extends View.Input<M>>(h: Html.H<M>, options: SectionOptions<M, C>) =>
	h.section
		.attrs({
			id: options.id,
			"aria-labelledby": options.labelledBy,
			"aria-label": options.labelledBy === undefined ? options.label : undefined,
			...sx(sectionStyles.root, options.muted === true && sectionStyles.muted, options.style),
		})
		.children(h.div.attrs(sx(sectionStyles.inner, options.innerStyle)).children(options.children))

export interface SectionHeaderOptions<M> {
	/** The heading's id, which the section points at. */
	readonly id: string
	/** A short line above the headline that says what part of the product this is: "Automations". */
	readonly eyebrow?: string
	readonly title: string
	readonly lede?: string
	/** Centered, or at the start; at the start by default. */
	readonly align?: "start" | "center"
	/** 1 for the page's headline (a hero), 2 by default. */
	readonly level?: 1 | 2
	/** Links under the lede. */
	readonly actions?: View.Content<M> | null
	readonly style?: Style
}

export const SectionHeader = <M>(h: Html.H<M>, options: SectionHeaderOptions<M>) => {
	const center = options.align === "center"
	const heading = options.level === 1 ? h.h1 : h.h2
	return h.header.attrs(sx(sectionStyles.header, center && sectionStyles.headerCenter, options.style)).children(
		options.eyebrow !== undefined && h.p.attrs(sx(sectionStyles.eyebrow)).children(options.eyebrow),
		heading.attrs({ id: options.id, ...sx(options.level === 1 ? sectionStyles.display : sectionStyles.title) }).children(options.title),
		options.lede !== undefined && h.p.attrs(sx(sectionStyles.lede)).children(options.lede),
		options.actions,
	)
}

/** A link drawn as a large button: the section's call to action. */
export const ActionLink = <M>(h: Html.H<M>, action: Action, options: { readonly primary?: boolean; readonly style?: Style } = {}) =>
	h.a
		.attrs({
			href: action.href,
			...sx(...buttonStyle({ size: "lg", tone: options.primary === true ? "primary" : "neutral" }), sectionStyles.action, options.style),
		})
		.children(action.label)

/** One or two links as buttons, the main one first. */
export const Actions = <M>(h: Html.H<M>, options: { readonly primary?: Action | undefined; readonly secondary?: Action | undefined; readonly center?: boolean; readonly style?: Style }) =>
	options.primary === undefined && options.secondary === undefined
		? null
		: h.div.attrs(sx(sectionStyles.actions, options.center === true && sectionStyles.actionsCenter, options.style)).children(
				options.primary !== undefined && ActionLink(h, options.primary, { primary: true }),
				options.secondary !== undefined && ActionLink(h, options.secondary),
			)

/** "Read the changelog →": a link in a sentence's place. */
export const ArrowLink = <M>(h: Html.H<M>, action: Action, style?: Style) =>
	h.a.attrs({ href: action.href, ...sx(sectionStyles.textLink, sectionStyles.focus, style) }).children(
		action.label,
		h.span.attrs(sx(sectionStyles.arrow)).children(h.span.attrs(sx(sectionStyles.arrowFlip)).children(Icon(h, "arrowRight", 16))),
	)

/** The product's mark and name, linking home. */
export const BrandLink = <M>(h: Html.H<M>, brand: SiteBrand, style?: Style) =>
	h.a.attrs({ href: brand.href, ...sx(sectionStyles.brand, sectionStyles.focus, style) }).children(
		h.span.attrs({ "aria-hidden": "true", ...sx(sectionStyles.mark) }).children(brand.letter),
		brand.name,
	)
```
