~ knotless Search/
↑↓ move↵ open⇧↵ all results

chadtmiller.com/hud

A remote MCP server that shows atproto records as interactive UI inside MCP Apps hosts

0
0
860 lines · 27.6 KB Raw History
<script lang="ts">
	import { Loading, LoadMore, type UiInteractionHandler } from '@hud/renderer';
	import { untrack } from 'svelte';
	import { CLICKTHROUGH, SEEN } from '@hud/shared/interactions';
	import Result from '@hud/shared/Result.svelte';
	import { accountOf, append, feedOf, isNewer, latestOf, listPage, loadingLabel, nextPage, ownsPaging, pageOf, read, text, type Call, type Entry } from '@hud/shared/result';
	import Avatar from '../atoms/Avatar.svelte';
	import Dot from '../atoms/Dot.svelte';
	import Handle from '../atoms/Handle.svelte';
	import Icon from '../atoms/Icon.svelte';
	import Time from '../atoms/Time.svelte';
	import { getTileContext } from '../context';
	import { launcher } from '../launcher.svelte';
	import { NowPlaying } from '../nowplaying.svelte';
	import type { Actor, Tile } from '../model';
	import TileMark from '../molecules/TileMark.svelte';
	import { preview, type Preview } from '../preview';
	import { profile } from '../profiles.svelte';
	import { actorOf, appOf, atUriOf, callKey, learn, nsidOf, type Learned } from '../tiles';
	import { callTool } from '../tools';

	/** How often a list newest first asks whether something newer came, and how long after it was read or asked it asks again as it comes back into view. */
	const PEEK_EVERY = 60_000;
	const PEEK_AFTER = 30_000;

	/**
	 * A tile: its header (its icon, which opens its app's page, its title
	 * as people read it and the handle of the account it shows; the tile it
	 * was opened from; who added it, when someone else or an agent did; its
	 * column's width, zoom, refresh and close, on hover; and its details,
	 * the call and what it names, behind an info button), and its body, the
	 * call's result drawn as the MCP App view draws it, scrolling inside the
	 * column. What opens from it opens in a column of its own, right of it.
	 * To a viewer, nothing changes the canvas: no width, no close.
	 * A list newest first (a tree with `latest`) is asked now and then,
	 * while drawn, whether something newer came: then its refresh shows with
	 * a dot, and scrolled down, a button over its body goes to its top and
	 * reads it again. Nothing newer is put in under the reader.
	 */
	let {
		tile,
		canvas,
		title,
		account,
		me,
		focused,
		arrived,
		chain,
		source,
		author,
		readonly,
		width,
		zoomed,
		live,
		onfocus,
		onsource,
		onwidth,
		onzoom,
		onclose,
		onpreview,
		onlabel
	}: {
		tile: Tile;
		/** The canvas it is on: with its id, where its players' music comes from. */
		canvas: string;
		/** Its title, as people read it. */
		title: string;
		/** The account whose data it shows, by DID or handle, or null for none (a feed). */
		account: string | null;
		/** Who is signed in: an account of theirs is "You". */
		me: Actor;
		focused: boolean;
		arrived: boolean;
		chain: number | undefined;
		/** The tile it was opened from, on this canvas, and which way it is. */
		source: { title: string; arrow: '←' | '→' | '↑' | '↓' } | null;
		/** Who added it, when not this person. */
		author: string | null;
		readonly: boolean;
		/** Its column's width, as said (1/3), or null when a stack's lower tile, which takes its head's. */
		width: string | null;
		zoomed: boolean;
		/** Whether to draw its body: near enough to the view, on the tab on screen. Not drawn, it keeps what it read and where its body was scrolled; a player's music goes on, in the workspace's player, but a video or an audio field in it stops. */
		live: boolean;
		onfocus: () => void;
		onsource: () => void;
		onwidth: () => void;
		onzoom: () => void;
		onclose: () => void;
		/** What it drew, in short, each time it draws: its card in the overview. */
		onpreview: (preview: Preview) => void;
		/** What it learned of itself, each time it draws: its label and its collection's name, for its title. */
		onlabel: (learned: Learned) => void;
	} = $props();

	const context = getTileContext();
	/** A tab chosen on a canvas this person can only view: drawn here alone, until the tile's own call changes. */
	let chosen = $state.raw<Call | null>(null);
	const call: Call = $derived(chosen ?? { name: tile.tool, args: tile.arguments });
	/** The tile's own call, and the one drawn, as text: another (a tab chosen, here or on another page) is read afresh. */
	const ownKey = $derived(callKey(tile.tool, tile.arguments));
	const drawnKey = $derived(callKey(call.name, call.args));
	const known = $derived(account ? profile(account) : undefined);
	/** The account as the answer names it, once drawn: a page's or a repository's DID and handle. */
	const answered = $derived.by(() => {
		const view = entry?.view;
		const page = view ? pageOf(view) : null;
		if (page) return { did: page.did, handle: page.handle };
		const account = view ? accountOf(view) : null;
		if (account) return { did: account.did, handle: account.handle };
		return null;
	});
	/** The account's handle: as its call names it, else as its profile or the answer gives it; never its DID. */
	const handle = $derived.by(() => {
		if (!account) return null;
		if (!account.startsWith('did:')) return account;
		return known?.handle ?? (answered?.did === account ? answered.handle : null) ?? null;
	});
	/** Whether the account is the person's own: then the header says "You", not their handle. */
	const mine = $derived(account !== null && (account === me.did || (handle !== null && handle === me.handle)));
	const did = $derived(account?.startsWith('did:') ? account : (known?.did ?? answered?.did ?? null));
	/** Open the account's profile across its apps, from its handle (or "You") in the header; none on that profile itself. */
	const openWhole = $derived.by(() => {
		const actor = did ?? handle;
		return actor && tile.tool !== 'describe_repo' ? () => open({ name: 'describe_repo', args: { actor } }) : null;
	});
	const atUri = $derived(atUriOf(tile.tool, tile.arguments, did));
	const nsid = $derived(nsidOf(tile.tool, tile.arguments));
	/** The app whose data it shows, to open its page from its icon: none for a profile, or an app's page itself. */
	const app = $derived.by(() => {
		const domain = tile.tool === 'describe_app' ? null : appOf(tile.tool, tile.arguments);
		return domain ? { domain, name: launcher.names.app(domain) ?? domain } : null;
	});
	/** The call, as an agent or a person would make it again. */
	const callText = $derived(JSON.stringify({ tool: tile.tool, arguments: tile.arguments }, null, 2));
	/** Which copy button just copied, for a moment. */
	let copied = $state<'uri' | 'call' | null>(null);
	/** A profile tile of the very account that added it: its face is its mark already, so it is not drawn twice. */
	const showsAuthor = $derived.by(() => {
		const actor = actorOf(tile.tool, tile.arguments);
		return actor !== null && author !== null && (actor === author || actor === profile(author)?.handle);
	});
	/** What it read, as read: never made deeply reactive (a page more replaces it), as a feed's answer is large. */
	let entry = $state.raw<Entry | null>(null);
	let more: { loading: boolean; error: string | null } = $state({ loading: false, error: null });
	/** Counts loads, so an answer to an older one is dropped. */
	let generation = 0;
	let body: HTMLElement | undefined = $state();
	/** Where its body was scrolled as it stopped drawing, to scroll back to when it draws again. */
	let kept = 0;
	/** Whether its body is scrolled down from its top. */
	let down = $state(false);
	/** Whether something newer came than the items drawn. */
	let fresh = $state(false);
	/** When it was last read, or asked whether something newer came. */
	let checked = 0;
	let peeking = false;

	$effect.pre(() => {
		if (!live && body) kept = body.scrollTop;
	});
	$effect(() => {
		if (!live || !entry || !body || !kept) return;
		body.scrollTop = kept;
		kept = 0;
	});

	const errorText = (error: unknown) => (error instanceof Error ? error.message : String(error));
	const following = $derived(entry ? nextPage(entry) : null);
	const feed = $derived(entry ? feedOf(entry.view) : null);

	async function load() {
		const current = ++generation;
		const made = call;
		entry = null;
		fresh = false;
		checked = Date.now();
		more = { loading: false, error: null };
		let next: Entry;
		let summary = '';
		try {
			const result = await callTool(made.name, made.args);
			summary = text(result);
			next = { view: read(result), call: made };
		} catch (error) {
			next = { view: { renderer: 'error', message: errorText(error) }, call: made };
		}
		if (current !== generation) return;
		entry = next;
		onlabel(learn(next.view, summary));
	}

	/** Its call made again, what it answers drawn in place of what was, never a loading state between (a conversation, read again once a message is sent); a failure throws with the server's words. */
	async function reload() {
		const current = ++generation;
		const made = call;
		const result = await callTool(made.name, made.args);
		const view = read(result);
		if (current !== generation) return;
		if (view.renderer === 'error') throw new Error(view.message);
		entry = { view, call: made };
		fresh = false;
		checked = Date.now();
		more = { loading: false, error: null };
		onlabel(learn(view, text(result)));
	}

	/** How to tell something newer came than what it drew, and what its items are. */
	const latest = $derived(entry ? latestOf(entry.view) : null);
	const noun = $derived(latest?.noun ?? 'items');

	/** Ask whether something newer came: its newest item alone, as `latest` calls it. A failure says nothing, and the next ask asks again. */
	async function peek() {
		const at = latest;
		const current = generation;
		if (!at || peeking) return;
		peeking = true;
		checked = Date.now();
		try {
			const peeked = read(await callTool(at.call.name, at.call.args));
			if (current === generation && isNewer(peeked, at)) fresh = true;
		} catch {
			// Not answered: nothing newer is said, and the next ask asks again.
		} finally {
			peeking = false;
		}
	}

	// While drawn on a page in view, and nothing newer said yet: asked every minute, and as it comes into view again half a minute or more after it was last read or asked.
	$effect(() => {
		if (!live || !latest || fresh) return;
		const due = () => {
			if (document.visibilityState === 'visible' && Date.now() - checked >= PEEK_AFTER) void peek();
		};
		untrack(due);
		const timer = setInterval(due, PEEK_EVERY);
		document.addEventListener('visibilitychange', due);
		return () => {
			clearInterval(timer);
			document.removeEventListener('visibilitychange', due);
		};
	});

	/** The newer read: its body to its top, and its call made again. */
	function toNewest() {
		body?.scrollTo({ top: 0 });
		refresh();
	}

	/** Earlier messages, asked for at a conversation's top rather than after it. */
	const paging = $derived(entry && following && ownsPaging(entry) ? { load: () => void loadMore(), loading: more.loading, error: more.error } : null);

	async function copy(what: 'uri' | 'call', value: string) {
		await navigator.clipboard.writeText(value);
		copied = what;
		setTimeout(() => {
			if (copied === what) copied = null;
		}, 1500);
	}

	// Its card in the overview shows what it drew last.
	$effect(() => {
		if (entry) onpreview(preview(entry.view));
	});

	/** A list's own page more (its `p.next`, a profile's pane): what it answers. */
	const listMore = async (next: Call) => listPage(await callTool(next.name, $state.snapshot(next.args)));

	async function loadMore() {
		const page = entry && nextPage(entry);
		if (!entry || !page) return;
		const current = generation;
		more = { loading: true, error: null };
		try {
			const next = read(await callTool(page.name, $state.snapshot(page.args)));
			if (current !== generation) return;
			if (next.renderer === 'error') more = { loading: false, error: next.message };
			else {
				const grown = append(entry.view, next);
				if (grown) entry = { ...entry, view: grown };
				more = { loading: false, error: grown ? null : 'The next page is not of this list.' };
			}
		} catch (error) {
			if (current === generation) more = { loading: false, error: errorText(error) };
		}
	}

	const open = (next: Call) => context.open(tile.id, { name: next.name, args: $state.snapshot(next.args) });

	/** A tab chosen: its call drawn in this tile, in its place, kept on the canvas for every page; on one this person only views, here alone. */
	async function replace(next: Call) {
		const made: Call = { name: next.name, args: $state.snapshot(next.args) };
		if (!(await context.replace(tile.id, made))) chosen = made;
	}

	/** Open a call, as a tree's item (`item`, the report its feed is told of) names it, in a column of its own; from a reported feed, the feed hears the post was opened. */
	function openCall(next: Call, item: unknown) {
		const to = feed;
		const opened = to?.signedIn && item !== null ? to.of(CLICKTHROUGH, item) : null;
		if (to && opened) context.feedback.add(to.feed, opened);
		open(next);
	}

	/** The posts this tile has told its feed were seen, as each load counts afresh. */
	let told = new Set<string>();
	const onseen = $derived.by(() => {
		const to = feed;
		if (!to?.signedIn) return undefined;
		return (item: unknown) => {
			const found = to.of(SEEN, item);
			if (!found || told.has(found.item)) return;
			told.add(found.item);
			context.feedback.add(to.feed, found);
		};
	});

	const interact: UiInteractionHandler | undefined = $derived.by(() => {
		const to = feed;
		if (!to) return undefined;
		return async (event: string, item: unknown) => {
			const found = to.of(event, item);
			if (!found) throw new Error('This item names no post to tell the feed of.');
			await context.feedback.now(to.feed, found);
		};
	});

	function refresh() {
		void context.feedback.flush();
		told = new Set();
		void load();
	}

	// The tile's own call changed (a tab chosen on another page, or here): it is drawn, not one chosen here alone.
	$effect.pre(() => {
		void ownKey;
		untrack(() => (chosen = null));
	});

	/** The call last read; another drawn is read afresh, its feed told of it anew. */
	let loaded: string | null = null;
	$effect(() => {
		const key = drawnKey;
		if (key === loaded) return;
		const again = loaded !== null;
		loaded = key;
		untrack(() => {
			if (again) told = new Set();
			void load();
		});
	});
</script>

<!-- svelte-ignore a11y_no_noninteractive_element_interactions (a pointer anywhere in a tile focuses it; the keys move focus too) -->
<article class="tile" class:focused class:arrived class:chained={chain !== undefined} style:--chain={chain === undefined ? undefined : `var(--chain-${chain})`} aria-label={title} data-tile={tile.id} onpointerdown={onfocus}>
	<!-- Its header: what it shows, then whose, in what, and where it was opened from; on a phone, one line (what and the handle), the tile it was opened from a back button. -->
	<header class="head">
		{#if source}
			<button type="button" class="icon-button back" title="Back to {source.title}" onclick={onsource}><Icon name="back" label="Back to {source.title}" /></button>
		{/if}
		{#if app}
			<button type="button" class="app-mark" title="Open {app.name}" aria-label="Open {app.name}" onclick={() => open({ name: 'describe_app', args: { domain: app.domain } })}><TileMark {tile} /></button>
		{:else}
			<TileMark {tile} />
		{/if}
		<div class="titles">
			<div class="title-row">
				<h2 {title}>{title}</h2>
				{#if mine && openWhole}
					<button type="button" class="inline-who whole" title="Your profile across your apps" onclick={openWhole}>You</button>
				{:else if mine}
					<span class="inline-who">You</span>
				{:else if handle}
					{#if openWhole}<button type="button" class="inline-who whole" title="@{handle} across their apps" onclick={openWhole}>@{handle}</button>{:else}<span class="inline-who">@{handle}</span>{/if}
				{/if}
				{#if tile.by === 'agent'}
					<span class="by-agent" title="Added by an agent"><Icon name="agent" /><span class="word">Agent</span></span>
				{/if}
				{#if author && !showsAuthor}<Avatar did={author} size="sm" prefix="Added by " />{/if}
			</div>
			<div class="about">
				{#if mine && openWhole}<button type="button" class="who whole" title="Your profile across your apps" onclick={openWhole}>You</button>{:else if mine}<span class="who">You</span>{:else if handle && openWhole}<button type="button" class="who whole" title="@{handle} across their apps" onclick={openWhole}><Handle did={did ?? handle} {handle} /></button>{:else if handle}<span class="who"><Handle did={did ?? handle} {handle} /></span>{/if}
				{#if app}<span>{app.name}</span>{/if}
				{#if source}
					<button type="button" class="crumb" title="Opened from {source.title}: go there" onclick={onsource}>from <span>{source.title}</span></button>
				{/if}
			</div>
		</div>
		<details class="popover sheet end info">
			<summary class="icon-button" title="Details" aria-label="Details"><Icon name="info" /></summary>
			<div class="menu details">
				<p class="menu-head">Details</p>
				<dl>
					<dt>Call</dt>
					<dd><code>{tile.tool}</code><pre>{JSON.stringify(tile.arguments, null, 2)}</pre></dd>
					{#if atUri}<dt>AT URI</dt><dd class="mono">{atUri}</dd>{/if}
					{#if did}<dt>DID</dt><dd class="mono">{did}</dd>{/if}
					{#if nsid}<dt>NSID</dt><dd class="mono">{nsid}</dd>{/if}
					<dt>Added</dt>
					<dd>
						{tile.by === 'agent' ? 'By an agent for' : 'By'}
						{#if author}<Handle did={author} handle={profile(author)?.handle} />{:else}you{/if}
						· <Time at={tile.at} />
					</dd>
				</dl>
				<div class="copies">
					{#if atUri}
						<button type="button" class="btn sm" onclick={() => void copy('uri', atUri)}><Icon name="copy" />{copied === 'uri' ? 'Copied' : 'Copy AT URI'}</button>
					{/if}
					<button type="button" class="btn sm" onclick={() => void copy('call', callText)}><Icon name="copy" />{copied === 'call' ? 'Copied' : 'Copy call'}</button>
				</div>
			</div>
		</details>
		<div class="controls" class:fresh>
			{#if width && !readonly}
				<button type="button" class="icon-button width" title="Width (R)" aria-label="Width {width}, change" onclick={onwidth}>{width}</button>
			{/if}
			<button type="button" class="icon-button zoom" aria-pressed={zoomed} title="Zoom (Z)" aria-label="Zoom" onclick={onzoom}><Icon name="zoom" /></button>
			{#if fresh}
				<button type="button" class="icon-button refresh" title="New {noun}: refresh" aria-label="Refresh, new {noun}" onclick={refresh}><Icon name="refresh" /><Dot label="New {noun}" /></button>
			{:else}
				<button type="button" class="icon-button refresh" title="Refresh" aria-label="Refresh" onclick={refresh}><Icon name="refresh" /></button>
			{/if}
			{#if !readonly}
				<button type="button" class="icon-button" title="Close (W)" aria-label="Close" onclick={onclose}><Icon name="close" /></button>
			{/if}
		</div>
		{#if fresh && down}
			<button type="button" class="btn sm newer" onclick={toNewest}><Icon name="newer" />New {noun}</button>
		{/if}
	</header>
	<div bind:this={body} class="body" tabindex="-1" aria-busy={entry === null} onscroll={() => (down = (body?.scrollTop ?? 0) > 0)}>
		{#if !live}
			<!-- Out of view: what it read is kept, and drawn again as it comes near. -->
		{:else if entry === null}
			<Loading label={loadingLabel(tile.tool)} />
		{:else}
			<Result
				{entry}
				oncall={openCall}
				onreplace={(next) => void replace(next)}
				onaction={context.act}
				onopenlink={(url) => void window.open(url, '_blank', 'noopener,noreferrer')}
				oninteraction={interact}
				{onseen}
				onretry={() => void load()}
				player={context.player}
				playerOrigin={NowPlaying.origin(canvas, tile.id)}
				{paging}
				onreload={reload}
				ontool={context.tool}
				onlistmore={listMore}
				onupload={context.upload}
				shown={{ title, handle }}
			/>
			{#if following && !paging}
				<LoadMore onload={loadMore} loading={more.loading} error={more.error} />
			{/if}
		{/if}
	</div>
</article>

<style>
	.tile {
		position: relative;
		display: flex;
		flex: 1 1 0;
		flex-direction: column;
		min-height: 0;
		border: var(--border);
		border-radius: var(--radius-lg);
		background: var(--bg);
		transition: box-shadow var(--quick);
	}

	.tile.chained::before {
		content: '';
		position: absolute;
		inset: 0 0 auto;
		height: 3px;
		border-radius: var(--radius-lg) var(--radius-lg) 0 0;
		background: var(--chain);
		pointer-events: none;
		/* Over the header, which is positioned for its details. */
		z-index: 1;
	}

	.tile.focused {
		border-color: var(--primary);
		box-shadow: 0 0 0 1px var(--primary);
	}

	.tile.arrived {
		border-color: var(--agent);
		box-shadow: 0 0 0 2px var(--agent);
	}

	@media (prefers-reduced-motion: no-preference) {
		.tile.arrived {
			animation: glow 1.3s ease-in-out 3;
		}
	}

	@keyframes glow {
		50% {
			box-shadow: 0 0 0 6px var(--agent-soft);
		}
	}

	/* The tile does not clip, so its details open over its body: its header and body round its corners themselves. */
	.head {
		position: relative;
		display: flex;
		flex: none;
		align-items: center;
		gap: var(--space-2);
		min-height: var(--strip);
		padding: var(--space-1-5) var(--space-2) var(--space-1-5) var(--space-3);
		border-bottom: var(--border);
		border-radius: var(--radius-lg) var(--radius-lg) 0 0;
		background: var(--panel);
	}

	.head > :global(.i),
	.app-mark {
		color: var(--mute);
	}

	.app-mark {
		display: inline-flex;
		flex: none;
		align-items: center;
		justify-content: center;
		width: var(--control-sm);
		height: var(--control-sm);
		margin-inline: calc(-1 * var(--space-1-5));
		padding: 0;
		border: 0;
		border-radius: var(--radius-md);
		background: none;
		cursor: pointer;
	}

	.app-mark:hover {
		background: var(--hover);
	}

	.titles {
		flex: 1;
		min-width: 0;
	}

	.title-row {
		display: flex;
		align-items: center;
		gap: var(--space-1-5);
		min-width: 0;
	}

	h2 {
		min-width: 3rem;
		overflow: hidden;
		font-size: var(--text-base);
		line-height: var(--leading-tight);
		text-overflow: ellipsis;
		white-space: nowrap;
	}

	/* The one it was opened from: words on the line under the title, its name a link back. */
	.crumb {
		min-width: 0;
		overflow: hidden;
		padding: 0;
		border: 0;
		background: none;
		color: inherit;
		font: inherit;
		text-overflow: ellipsis;
		white-space: nowrap;
		cursor: pointer;
	}

	.crumb span {
		text-decoration: underline;
		text-decoration-color: var(--link-line);
		text-underline-offset: 2px;
	}

	.crumb:hover {
		color: var(--fg);
	}

	/* Whose it is, its app, where it was opened from, apart by dots: always a line, so every header is as tall. */
	.about {
		display: flex;
		align-items: center;
		min-height: 1lh;
		min-width: 0;
		margin-top: var(--space-0-5);
		overflow: hidden;
		color: var(--mute);
		font-size: var(--text-xs);
		line-height: var(--leading-tight);
		white-space: nowrap;
	}

	.about > :global(* + *)::before {
		content: '·';
		margin-inline: var(--space-1-5);
		color: var(--faint);
	}

	.who {
		flex: none;
	}

	/* The handle, opening the account across its apps: words, not a button's look. */
	.whole {
		padding: 0;
		border: 0;
		background: none;
		color: inherit;
		font: inherit;
		cursor: pointer;
	}

	.whole:hover {
		color: var(--fg);
		text-decoration: underline;
		text-decoration-color: var(--link-line);
		text-underline-offset: 2px;
	}

	/* The phone's alone: the handle beside the title, and a way back. */
	.inline-who,
	.back {
		display: none;
	}

	.inline-who {
		flex: none;
		color: var(--mute);
		font-size: var(--text-xs);
		white-space: nowrap;
	}

	/* As a button, a finger's target, padded out past its words without moving them. */
	.inline-who.whole {
		margin: calc(-1 * var(--space-3)) calc(-1 * var(--space-1-5));
		padding: var(--space-3) var(--space-1-5);
	}

	.back {
		margin-inline: calc(-1 * var(--space-1)) calc(-1 * var(--space-1-5));
	}

	/* Width, zoom, refresh and close: where a pointer hovers, on hover or focus; always on touch. Close is outermost, as everywhere. */
	.controls {
		display: none;
		flex: none;
		align-items: center;
		gap: var(--space-2);
	}

	.tile:hover .controls,
	.head:focus-within .controls {
		display: flex;
	}

	/* With something newer come: refresh in its place without hover, the rest kept hidden till then, so nothing moves as a pointer comes. */
	.controls.fresh {
		display: flex;
	}

	.controls.fresh > :not(.refresh) {
		visibility: hidden;
	}

	.tile:hover .controls.fresh > *,
	.head:focus-within .controls.fresh > * {
		visibility: visible;
	}

	@media (hover: none) {
		.controls {
			display: flex;
		}

		.controls.fresh > :not(.refresh) {
			visibility: visible;
		}
	}

	/* On a phone a column is the screen's width already: no width to choose, nothing to zoom; and its header one line, the title giving way before the handle. */
	@media (max-width: 640px) {
		.width,
		.zoom {
			display: none;
		}

		.about,
		.by-agent .word {
			display: none;
		}

		.inline-who,
		.back {
			display: inline-flex;
		}

		.title-row {
			align-items: baseline;
		}
	}

	/* The details open under the header, as wide as it; on a phone, a sheet. */
	.info {
		position: static;
	}

	.info > .details {
		right: var(--space-2);
		left: var(--space-2);
		width: auto;
		padding: var(--space-1) 0 var(--space-3);
	}

	.info[open] > summary {
		background: var(--hover);
		color: var(--fg);
	}

	dl {
		display: grid;
		grid-template-columns: max-content minmax(0, 1fr);
		align-items: baseline;
		gap: var(--space-2) var(--space-3);
		padding: var(--space-1) var(--space-3) 0;
	}

	dt {
		color: var(--mute);
		font-size: var(--text-xs);
		line-height: var(--leading);
	}

	dd {
		min-width: 0;
		overflow-wrap: anywhere;
	}

	.mono,
	code,
	pre {
		font: var(--text-xs) / var(--leading) var(--font-mono);
	}

	pre {
		max-height: 12rem;
		margin-top: var(--space-1);
		padding: var(--space-2);
		overflow: auto;
		border-radius: var(--radius-sm);
		background: var(--soft);
		white-space: pre;
	}

	.copies {
		display: flex;
		flex-wrap: wrap;
		gap: var(--space-2);
		margin-top: var(--space-3);
		padding: 0 var(--space-3);
	}

	/* Added by an agent: its mark and the word, in the agent's colour; on a phone, the mark alone. */
	.by-agent {
		display: inline-flex;
		flex: none;
		align-items: center;
		gap: var(--space-1);
		padding: 0 var(--space-1-5);
		border-radius: var(--radius-full);
		background: var(--agent-soft);
		color: var(--agent-fg);
		font-size: var(--text-2xs);
		font-weight: var(--weight-medium);
		line-height: var(--leading-tight);
	}

	.width {
		width: auto;
		min-width: var(--control-sm);
		padding: 0 var(--space-1);
		font: var(--text-xs) var(--font-mono);
	}

	/* Refresh, with something newer come: its dot on its corner, ringed apart from its arrow. */
	.fresh > .refresh {
		position: relative;
		color: var(--fg);
	}

	.refresh > :global(.dot) {
		position: absolute;
		top: 0;
		right: 0;
		box-shadow: 0 0 0 var(--space-0-5) var(--panel);
	}

	/* Scrolled down, with something newer come: over the top of its body, under the header's line; a finger's height on touch. */
	.newer {
		position: absolute;
		top: calc(100% + var(--space-2));
		left: 50%;
		z-index: 1;
		border-color: var(--line-strong);
		border-radius: var(--radius-full);
		box-shadow: var(--shadow-pop);
		translate: -50% 0;
	}

	@media (hover: none) {
		.newer {
			height: var(--control);
		}
	}

	.body {
		flex: 1;
		min-height: 0;
		padding: var(--space-3);
		--hud-bleed: var(--space-3);
		overflow-x: hidden;
		overflow-y: auto;
		/* Its own scroll up and down stays its own; a swipe sideways over it goes on to the strip. */
		overscroll-behavior-y: contain;
		border-radius: 0 0 var(--radius-lg) var(--radius-lg);
		outline: 0;
	}

	/* Its top padding is `--hud-lead` to what is first in it alone: a
	   picture or map that bleeds there meets the header's line. */
	.body > :global(*) {
		--hud-lead: 0px;
	}

	.body > :global(:first-child) {
		--hud-lead: var(--space-3);
	}

	/* A tile that is a list of rows: its first row meets the header's line
	   and its last the tile's foot, as its sides meet the tile's edges. */
	.body > :global(.rows:first-child) {
		margin-top: calc(-1 * var(--space-3));
	}

	.body > :global(.rows:last-child) {
		margin-bottom: calc(-1 * var(--space-3));
	}
</style>