# Surface: the stage, a picture set in the page with the look around it

> A picture set in the page: the stage drawn in its own medium (Three.js for depth and 3D infographics, SVG for flat, exact and printable, D3 for data-driven layout, canvas for pixels), framed in a Card with kit controls beside it, coloured from the theme and in the literal colours the subject names, every target reachable by keyboard.

Source: https://good.vibes.diy/docs/reference/surface-stage

The look dresses the chrome. The picture is a stage of its own, and the chrome sits around it.

An app whose subject is a picture has two layers. The stage is the picture itself: a 3D
infographic, a model turned in the hand, a map of districts, a floor plan, a diagram, a chart of
its own design. The app draws it in the medium it asks for. The chrome is everything around it:
the heading, the controls that act on the picture, the records, the share row. The chrome is the
kit's components, and the stage is drawn shape by shape, so a district keeps its outline, a bar
keeps its height and a room keeps its proportions to the pixel.

A picture of a thing is a painted picture, never a stage: a product in a catalog, a bag of coffee,
a mug, a candle, a dish, a creature or a cover is one `<ImgGen>` saved on its record, or the photo
the owner uploads. The stage is for pictures whose geometry is the point.

**Pick the medium the picture asks for, and reach.**

- **Three.js** for depth, motion and anything explored: a voxel world, a scene, a model, and an
  infographic told in 3D, with bars rising off a map, layers pulled apart and a camera that walks
  the story chapter by chapter. It is the most striking stage, so choose it whenever a picture
  can stand up.
- **SVG** for flat, exact and printable: a district map, a floor plan, a certificate, a chart
  drawn to scale, a figure matched to a reference. Its geometry is data in `viewBox` units, so it
  prints sharp at any size and every shape lands where it was drawn at any width.
- **D3** to lay out data-driven shapes (scales, force graphs, trees, projections), drawn into SVG.
- **Canvas** for per-pixel work and simulations.

**One component per stage, set as one block with its controls.** The stage is its own component
(`DistrictMap`, `HarborScene`) with its geometry as data at the top of the file. It sits in the
page inside a `Card` with a `Heading`, or at the column's full width, and every control that acts
on it — the picker, the year, the sliders, Play, Reset, Save — is docked right against it, so a
change and its picture share one glance on a phone and a laptop alike. Size the stage to leave the
controls their room: a fixed aspect box (`aspect-video`, or `aspect-square` for a square subject)
holds the layout while it draws, and the controls sit in one `Row` that wraps directly under it.
From `md:` up the stage and its controls become two columns, the controls a side panel beside the
stage. The caption, legend notes and any explainer come after the stage and its controls.

```jsx
import { Slider } from "@vibes.diy/ui/interactive";

<Card>
  <Stack gap={3}>
    <Heading level={2}>Harbor traffic, 2015 to 2025</Heading>
    <div className="grid gap-3 md:grid-cols-3">
      <div ref={mountRef} className="w-full aspect-video overflow-hidden select-none touch-none md:col-span-2" />
      <Stack gap={2}>
        <Segmented label="Chapter" tone="info" value={chapter} onChange={setChapter} options={CHAPTER_OPTIONS} />
        <Slider label="Year" value={[year]} onChange={([y]) => setYear(y)} min={2015} max={2025} />
        <Button variant="quiet" onClick={reset}>Reset view</Button>
      </Stack>
    </div>
    <Text size="sm" muted>
      Drag to turn the harbor. Each chapter flies the camera to its part of the story.
    </Text>
  </Stack>
</Card>
```

A canvas or WebGL stage paints its own box and follows that box with a `ResizeObserver`, so it
keeps the size the layout gives it on every screen.

**When the stage is the whole app, it fills one screen with its controls.** When the whole app
is one live surface the person plays or steers as it runs (a drawing or pixel canvas, a synth, theremin, EQ or drum machine, a step sequencer, or a generative visual or particle toy), it opens with the block
_A surface and its controls share one screen_ shows. The block is exactly one screen tall
(`flex h-dvh max-h-240 flex-col`) and holds three things: a one-line heading row, the stage taking
the space left (`relative min-h-48 flex-1`), and every slider and button standing open in a strip
docked under it, a side panel from `md:` up. The look's section cards come after that block. A
picture set in a page, like the harbor above, keeps its `Card` and aspect box.

**The stage wears the theme's colours.** SVG fills and strokes are theme utility classes:
`fill-card`, `fill-muted`, `fill-primary`, `fill-accent`, `fill-foreground`, `stroke-border`,
`stroke-foreground`. Two sides of a story whose colours the subject leaves open are two of those tokens, and the legend beside the
stage draws its swatches with the same classes. A canvas or WebGL stage paints from the same
tokens resolved to colours when it mounts, so a palette change recolours every stage while its
shapes hold.

**A colour the subject names is painted as that colour.** When the colour is part of the meaning —
a district painted blue or red, the red team and the blue team, a traffic light's red, amber and
green — the stage paints that literal colour from a hex in its data, set on the shape's `fill`
attribute, and the legend swatch is a small `<svg>` square with the same `fill`. Theme classes
carry every fill the subject leaves open: an unpainted district, the borders, the labels, the
frame. A painted shape carries the hex alone, since a `fill-*` class would paint over it.

```jsx
const PAINT = { blue: "#2563eb", red: "#dc2626" };
const side = colors[d.id];
<path d={d.d} strokeWidth="2" fill={PAINT[side]} className={side ? "stroke-foreground" : "fill-muted stroke-foreground"} />
<svg viewBox="0 0 10 10" className="size-3" aria-hidden="true"><rect width="10" height="10" rx="2" fill={PAINT.blue} /></svg>
```

**Every target is reachable by touch and keyboard.** A shape the person taps in SVG is a labelled
group with `onClick` and an Enter/Space `onKeyDown` that calls `preventDefault()` first, and the
`<svg>` carries `touch-manipulation select-none`:

```jsx
const DISTRICTS = [
  { id: "d1", name: "Riverside", d: "M0 0 H120 V80 H60 V140 H0 Z" },
  { id: "d2", name: "Hilltop", d: "M120 0 H240 V140 H60 V80 H120 Z" },
];
function DistrictMap({ colors, onPick }) {
  const fillOf = (id) => (colors[id] === "a" ? "fill-primary" : colors[id] === "b" ? "fill-accent" : "fill-muted");
  return (
    <svg viewBox="0 0 240 140" className="w-full h-auto touch-manipulation select-none" role="group" aria-label="District map">
      {DISTRICTS.map((d) => (
        <g
          key={d.id}
          role="button"
          tabIndex={0}
          aria-label={d.name}
          onClick={() => onPick(d.id)}
          onKeyDown={(e) => {
            if (e.key === "Enter" || e.key === " ") {
              e.preventDefault();
              onPick(d.id);
            }
          }}
        >
          <path d={d.d} strokeWidth="2" className={fillOf(d.id) + " stroke-foreground"} />
        </g>
      ))}
    </svg>
  );
}
```

A pick inside a 3D or canvas stage is offered beside it as well, as a `Select` or `Segmented`
of the same items, so every choice is one keyboard press away.

**A picture made to print stays SVG.** A map handout, a certificate or a poster is SVG with a
`viewBox`, and a 3D stage the person wants on paper offers a flat SVG view beside it.
