/* The design product page's own rules: the design form, its live preview and
   the Advanced editing editor (islands/DesignBuyForm.tsx, DesignPreview.tsx,
   DesignEditor.tsx). The page's v2 design:
   docs/superpowers/specs/2026-11-01-design-page-v2.md.

   Loaded after configurator.css and product.css, and only where the
   customiser is the design form (`productStylesheets` in
   src/lib/product-page.ts: /products/<slug> and the admin's preview), and by
   the admin's template editor when its layout opens (`EDITOR_STYLESHEETS` in
   islands/DesignTemplateEditor.tsx). product.css is render-blocking on every
   product page, so these rules stay out of it: a keychain, options or photo
   page never downloads them.

   It wears the keychain designer's own pieces from configurator.css (`.field`,
   `.field-label`, `.text-input`, `.chips`, `.chip`) and dresses them from
   outside, as personalised.css does, never forking them; and it leans on
   product.css for what the design form shares with the photo and options
   forms (`.photo-buy__*`, `.photo-stage__*`, `.options-buy__*`). */

/* ---- The page: title across the top, the designer under it -----------------
   As /personalised/<slug>: the heading and price at reading width, then the
   designer's two columns at the page's full width. The photographs go under
   the designer (ProductPage.astro), so the hero is one column. */

.product-page__hero--design {
  grid-template-columns: minmax(0, 1fr);
}

.product-page__hero--design .product-page__buy {
  grid-column: auto;
  max-width: none;
  gap: var(--space-sm);
}

.product-page__hero--design .product-page__title,
.product-page__hero--design .product-page__summary {
  max-width: var(--measure);
}

.product-page__hero--design .design-buy {
  margin-top: var(--space-md);
}

/* ---- With photographs: the finished thing first ------------------------------
   A design product with photographs (`productLayout`): the photos beside the
   title, price, "Personalise yours" and the description, as any product
   page's hero, then "Make it yours" and the designer under both columns,
   since the designer's own two columns need the page's width. The buying
   column steps aside (`display: contents`) so its intro is the column
   beside the photos and its customiser (the heading and the form, one
   region) and slot are the hero's own rows under both. Phone: one column,
   in that order. Spaced by margins, not the hero's gap, so the heading sits
   close to its form and well clear of the photos. */

.product-page__hero--photos {
  row-gap: 0;
}

.product-page__hero--photos .product-page__buy {
  display: contents;
}

.product-page__hero--photos .product-page__intro {
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
  min-width: 0;
  margin-top: var(--space-xl);
}

.product-page__hero--photos .product-page__buy > :not(.product-page__intro) {
  grid-column: 1 / -1;
  margin-top: var(--space-md);
}

.product-page__hero--photos .product-page__buy > .product-page__customise {
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
  min-width: 0;
  margin-top: var(--space-2xl);
}

.product-page__hero--photos .product-page__make {
  font-size: var(--text-xl);
  /* The site header is sticky: the link lands the heading under it, not behind it. */
  scroll-margin-top: var(--space-3xl);
}

.product-page__personalise {
  align-self: flex-start;
}

@media (min-width: 900px) {
  .product-page__hero--photos .product-page__intro {
    margin-top: 0;
  }
}

/* ---- The design form: two columns, simple first -----------------------------
   The keychain designer's bench (configurator.css `.configurator`): from 54rem
   the live preview on the left and the steps on the right, behind a hairline;
   narrower, one column with the preview first. Nothing has a width of its own
   below 54rem, so the form keeps the 16px phone gutter and never scrolls the
   page sideways at 320px; tiles, chips and swatches wrap.

   The preview stays in view while the steps scroll, on every width (spec §3:
   the shopper watches the product change as they type): sticky, just under
   the site's own sticky header (its height is measured into
   `--design-preview-top` by the island). On a phone it is capped at about a
   third of the screen so the field being typed in stays in view under it,
   with the picture letterboxed inside the cap (`object-fit: contain`), never
   stretched; every field keeps clear of it when scrolled to, by
   `--design-preview-bottom`, which the island measures (WCAG 2.4.11). */

.design-buy {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--space-lg);
  align-items: start;
  min-width: 0;
}

.design-buy__controls {
  display: flex;
  flex-direction: column;
  gap: var(--space-lg);
  min-width: 0;
}

.design-buy__elements {
  display: flex;
  flex-direction: column;
  gap: var(--space-lg);
  min-width: 0;
}

.design-buy__step {
  display: flex;
  flex-direction: column;
  gap: var(--space-lg);
  min-width: 0;
}

@media (min-width: 54rem) {
  .design-buy {
    grid-template-columns: minmax(0, 1fr) minmax(300px, 380px);
    gap: var(--space-2xl);
  }

  /* Not a card: the controls sit on the paper behind a hairline, as the
     keychain's do (personalised.css `.pers .controls`). The preview keeps the
     only frame. */
  .design-buy__controls {
    padding-left: var(--space-lg);
    border-left: 1px solid var(--line);
  }
}

/* Advanced editing open in the page: the editor takes both columns' place. */
.design-buy--editing > .design-preview,
.design-buy--editing > .design-buy__controls {
  display: none;
}

.design-buy__editor {
  grid-column: 1 / -1;
  min-width: 0;
}

/* ---- The preview ------------------------------------------------------------- */

.design-preview {
  position: sticky;
  top: var(--design-preview-top, 0px);
  /* Under the site header's own layer, over the fields it slides across. */
  z-index: var(--z-base);
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
  min-width: 0;
  padding-block: var(--space-xs);
  margin-block: calc(-1 * var(--space-xs));
  background: var(--paper);
  box-shadow: 0 1px 0 var(--line);
}

.design-preview__stage {
  position: relative;
  min-width: 0;
}

/* Two classes, so `.product-page img`-style page rules cannot reach it. The
   stage the object sits in, as the keychain's (configurator.css `.stage`):
   sunken, hairlined, the one framed thing on the page. */
.design-preview .design-preview__canvas {
  display: block;
  box-sizing: border-box;
  width: 100%;
  height: auto;
  margin-inline: auto;
  /* No wider than the capped height's worth of the picture
     (`--design-preview-ratio`, set by the island), so the frame hugs the
     mockup instead of letterboxing it. */
  max-width: min(100%, calc(35vh * var(--design-preview-ratio, 1)));
  max-width: min(100%, calc(35svh * var(--design-preview-ratio, 1)));
  max-height: 35vh;
  max-height: 35svh;
  object-fit: contain;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--paper-2);
}

@media (min-width: 54rem) {
  .design-preview {
    top: calc(var(--design-preview-top, 0px) + var(--space-md));
    padding-block: 0;
    margin-block: 0;
    box-shadow: none;
  }

  /* The screen less the header, the gap above and room under it for the
     placing hint, so the whole preview stays in view while it sticks. */
  .design-preview .design-preview__canvas {
    max-width: min(100%, calc((100vh - var(--design-preview-top, 0px) - var(--space-2xl) - var(--space-xl)) * var(--design-preview-ratio, 1)));
    max-width: min(100%, calc((100svh - var(--design-preview-top, 0px) - var(--space-2xl) - var(--space-xl)) * var(--design-preview-ratio, 1)));
    max-height: calc(100vh - var(--design-preview-top, 0px) - var(--space-2xl) - var(--space-xl));
    max-height: calc(100svh - var(--design-preview-top, 0px) - var(--space-2xl) - var(--space-xl));
    border-radius: var(--radius-lg);
    box-shadow: inset 0 1px 0 var(--paper-3);
  }
}

/* A photo's handle on the preview (`PhotoHandle`): invisible until the
   pointer is over it, it is grabbed or it has the focus, then ringed white
   inside ink (`--paper-3`, `--ink`), which reads on any photo. Its
   corners follow the frame's (inline). `touch-action: none` on the frame
   alone, so a finger anywhere else on the preview still scrolls the page. */
.design-preview__handle {
  position: absolute;
  box-sizing: border-box;
  touch-action: none;
  cursor: grab;
  transform-origin: center;
  transition: box-shadow var(--dur-fast) var(--ease-out);
}

.design-preview__handle:hover,
.design-preview__handle--dragging {
  box-shadow: 0 0 0 2px var(--paper-3), 0 0 0 4px var(--ink);
}

.design-preview__handle--dragging {
  cursor: grabbing;
}

.design-preview__handle:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 4px;
  box-shadow: 0 0 0 2px var(--paper-3), 0 0 0 4px var(--ink);
}

.design-preview__handle[aria-disabled='true'] {
  cursor: default;
}

/* Where nothing hovers (a phone), a dashed ring says the photo is there to
   drag, until it has been dragged once: ink dashes just inside a thin white
   band, so one of the two reads on a light photo and the other on a dark one.
   Never over the keyboard's own focus ring, which keeps its solid outline. */
@media (hover: none) {
  .design-preview__handle--fresh:not([aria-disabled='true']):not(:focus-visible) {
    outline: 2px dashed var(--ink);
    outline-offset: -4px;
    box-shadow: inset 0 0 0 2px var(--paper-3);
  }
}

/* How to place the photo: under the preview where it stands beside the steps;
   on a phone the photo step says it instead, so the sticky preview stays as
   short as it can. */
.design-preview__hint {
  display: none;
  margin: 0;
  color: var(--ink-2);
  font-size: var(--text-sm);
}

@media (min-width: 54rem) {
  .design-preview__hint {
    display: block;
  }

  .design-buy__place-hint {
    display: none;
  }
}

.design-preview__status {
  margin: 0;
  color: var(--ink-2);
  font-size: var(--text-sm);
}

.design-preview__status:empty {
  display: none;
}

.design-preview__alert {
  color: var(--danger);
}

/* Scrolled to — by Tab, or a refusal's focus — a field stops below the
   sticky preview, never under it. */
.design-buy input,
.design-buy textarea,
.design-buy select,
.design-buy fieldset,
.design-buy button {
  scroll-margin-top: calc(var(--design-preview-bottom, 0px) + var(--space-sm));
}

/* "Hold Shift", "the arrow keys": said only with a keyboard beside a fine pointer. */
.design-buy__shift {
  display: none;
}

@media (hover: hover) and (pointer: fine) {
  .design-buy__shift {
    display: inline;
  }
}

/* ---- The steps -----------------------------------------------------------------
   Each a `.field` with its `.field-label`, as the keychain's are. The answer
   chosen sits beside the question, in sentence case: read as the answer, not
   as more of the question. */

.design-buy__choice-name {
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
  color: var(--ink-2);
}

/* The name is the product, so its input is set in the display face, as on
   the keychain's page (personalised.css `.pers .text-input`). */
.design-buy .text-input {
  box-sizing: border-box;
  width: 100%;
  font-family: var(--font-display);
  font-size: var(--text-lg);
  line-height: 1.25;
}

.design-buy textarea.text-input {
  resize: vertical;
}

.design-buy .text-input:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 1px;
  border-color: var(--accent);
}

.design-buy .text-input[aria-invalid='true'] {
  border-color: var(--danger);
}

.design-buy .text-input::placeholder {
  color: var(--ink-3);
}

.design-buy__count {
  align-self: flex-end;
  margin-top: calc(-1 * var(--space-2xs));
  color: var(--ink-3);
  font-size: var(--text-xs);
  font-variant-numeric: tabular-nums;
}

.design-buy .chip:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

.design-buy .chip:disabled {
  cursor: not-allowed;
  opacity: 0.6;
}

/* A text's wordings to choose from, above its box. A wording can be longer
   than a phone is wide, so unlike a font chip it may wrap inside its chip
   rather than push the page sideways. */
.design-buy__presets .chip {
  max-width: 100%;
  white-space: normal;
  overflow-wrap: anywhere;
  text-align: start;
}

.design-buy__presets-note {
  color: var(--ink-3);
  font-size: var(--text-xs);
}

/* What is wrong with a field, beside it: words on a tint, never colour alone,
   and nothing (taking no room) when there is nothing to say. */
.design-buy__problem {
  margin: 0;
  color: var(--danger);
  font-size: var(--text-sm);
}

.design-buy__problem:not(:empty) {
  padding: var(--space-xs) var(--space-sm);
  background: var(--danger-soft);
  border-radius: var(--radius-sm);
}

.design-buy__problem:empty {
  display: none;
}

/* ---- The picture ----------------------------------------------------------------
   Thumbnails of the product's artwork, then "Your photo", all one row of
   squares chosen the same way; as many to a row as fit, never under the touch
   floor. The radio stays in the page and the tab order, drawn as its tile. */

.design-buy__tiles {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(4.5rem, 1fr));
  gap: var(--space-xs);
}

.design-buy__tile {
  position: relative;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-3xs);
  aspect-ratio: 1;
  min-width: 44px;
  min-height: 44px;
  padding: var(--space-2xs);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--paper-3);
  color: var(--ink-2);
  cursor: pointer;
  overflow: hidden;
  transition:
    border-color var(--dur-fast) var(--ease-out),
    box-shadow var(--dur-fast) var(--ease-out);
}

.design-buy__tile:hover {
  border-color: var(--ink-3);
}

.design-buy__swatch input,
.design-buy__tile input {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: 0;
  opacity: 0;
}

.design-buy .design-buy__tile img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

/* An artwork tile: the picture in a square well on a mid-grey checker, its
   name under it. Mid-grey (fixed, not a theme colour, so dark mode does not
   change it) is the one background white, black and coloured artwork all
   stand out on: white symbols for a coloured star were blank on the paper
   tile, and a colour picture behind the chosen base colour would vanish on
   a base of its own colour. The tile grows to hold the name; the well keeps
   the square. */
.design-buy__tile--art {
  aspect-ratio: auto;
  justify-content: flex-start;
}

.design-buy__tile-well {
  display: block;
  width: 100%;
  aspect-ratio: 1;
  border-radius: calc(var(--radius-sm) - 1px);
  background: repeating-conic-gradient(#8c8c8c 0 25%, #a6a6a6 0 50%) 0 0 / 10px 10px;
  overflow: hidden;
}
/* The chosen one: the ink ring the keychain's chosen swatch wears. */
.design-buy__tile:has(input:checked) {
  border-color: var(--ink);
  box-shadow: inset 0 0 0 2px var(--ink);
}

.design-buy__tile:has(input:focus-visible),
.design-buy__swatch:has(input:focus-visible),
.photo-buy__file:focus-visible + .design-buy__tile {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

.design-buy__tile--none span,
.design-buy__tile-name {
  font-size: var(--text-xs);
  font-weight: 600;
  line-height: 1.15;
  text-align: center;
  overflow-wrap: anywhere;
}

/* "Your photo" before there is one: an empty square to fill, dashed. */
.design-buy__tile-upload {
  display: contents;
}

.design-buy__tile--upload {
  border-style: dashed;
  background: var(--paper);
  color: var(--ink);
}

.design-buy__tile-mark {
  flex: none;
  width: var(--space-lg);
  height: var(--space-lg);
}

/* With one: the shopper's photo fills the tile; its name is for the radio. */
.design-buy__tile--photo {
  padding: 0;
}

.design-buy__tile-photo {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.design-buy__tile--photo .design-buy__tile-name {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

fieldset:disabled .design-buy__swatch,
fieldset:disabled .design-buy__tile,
.photo-buy__file:disabled + .design-buy__tile,
.design-buy__tile:has(input:disabled) {
  color: var(--ink-3);
  opacity: 0.6;
  cursor: not-allowed;
}

.design-buy__picture {
  gap: var(--space-sm);
}

.design-buy__picture:focus {
  outline: none;
}

/* "Choose a different photo": a quiet text button under the row, at the
   touch floor, so the tiles stay the way to choose. Element and two classes,
   to outrank product.css's pill for the photo form's button. */
.design-buy__own {
  display: flex;
}

.design-buy__own > label.design-buy__replace {
  min-height: 44px;
  padding: 0;
  border: 0;
  background: none;
  color: var(--ink-2);
  font-size: var(--text-sm);
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 0.18em;
}

.design-buy__own > label.design-buy__replace:hover {
  color: var(--ink);
}

.design-buy__photo {
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
  min-width: 0;
}

/* ---- The base colour --------------------------------------------------------------
   Each a pill with a glimpse of its mockup and its name. */

.design-buy__swatches {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-xs);
}

.design-buy__swatch {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: var(--space-xs);
  min-height: 44px;
  padding: var(--space-2xs) var(--space-md) var(--space-2xs) var(--space-2xs);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-pill);
  background: var(--paper-3);
  color: var(--ink);
  font-size: var(--text-sm);
  font-weight: 500;
  cursor: pointer;
  overflow-wrap: anywhere;
}

.design-buy .design-buy__swatch img {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--paper-2);
}

.design-buy__swatch:has(input:checked) {
  border-color: var(--ink);
  box-shadow: inset 0 0 0 1px var(--ink);
}

/* ---- Advanced editing ---------------------------------------------------------------
   A button that opens the editor, closed until asked for: a full-width row
   over a hairline with a chevron pointing on, and a line under it saying
   what it offers. Quiet on
   purpose, so Add to cart stays the one accent on the page. */

.design-buy__advanced {
  display: flex;
  flex-direction: column;
  gap: var(--space-2xs);
  padding-block: var(--space-2xs) var(--space-sm);
  /* One rule, under it: a rule above would double the stuck phone
     preview's own line whenever the row slides up to meet it. */
  border-bottom: 1px solid var(--line);
}

.design-buy__advanced-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-sm);
  width: 100%;
  min-height: 44px;
  padding: var(--space-xs) 0;
  border: 0;
  background: none;
  color: var(--ink);
  font: inherit;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
}

.design-buy__advanced-toggle:hover:not(:disabled) span {
  text-decoration: underline;
  text-underline-offset: 0.18em;
}

.design-buy__advanced-toggle:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

.design-buy__advanced-toggle:disabled {
  color: var(--ink-3);
  cursor: not-allowed;
}

.design-buy__chevron {
  flex: none;
  width: var(--space-md);
  height: var(--space-md);
  transition: transform var(--dur-base) var(--ease-out);
}


.design-buy__advanced-note {
  margin: 0;
  color: var(--ink-3);
  font-size: var(--text-sm);
}

/* ---- Quantity, price and Add to cart -------------------------------------------------
   Above a hairline, as the keychain's summary is, so the money reads as the
   end of the column rather than one more step. */

.design-buy__buy {
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
}

/* Every question in the form asked in one voice: the keychain's
   `.field-label` (configurator.css), the other options' and the quantity's
   labels and the zoom's included. */
.design-buy .options-buy__field > label:not(.options-buy__choice),
.design-buy .options-buy__field > legend,
.design-buy .photo-stage__zoom {
  font-size: var(--text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--ink-3);
}

.design-buy .options-buy__colour-name {
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
  color: var(--ink-2);
}

.design-buy__buy .options-buy__cta {
  width: 100%;
}

/* "Add to cart and make another" (a text that changes for each one): the
   same size and shape, as the secondary choice, so Add to cart stays the one
   accent. A full-width 44px target on a phone, as the main button is. */
.design-buy__buy .design-buy__another:not(:disabled) {
  background: var(--paper);
  color: var(--ink);
  border-color: var(--line-strong);
  box-shadow: none;
}
.design-buy__buy .design-buy__another:hover:not(:disabled) {
  background: var(--paper-2);
  box-shadow: none;
}

/* What an add that stayed says. Empty, it takes no room, but stays in the
   page (never `display: none`), so a screen reader hears it when it fills. */
.design-buy__added {
  margin: 0;
  color: var(--ink-2);
  font-size: var(--text-sm);
}
.design-buy__added:empty {
  margin-top: calc(-1 * var(--space-md));
}

/* The editor's buttons, which the admin's template editor shares: a
   secondary pill, so Done is the one accent there. */
.design-editor__button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: var(--space-xs) var(--space-md);
  border: 1px solid var(--ink);
  border-radius: var(--radius-pill);
  background: var(--paper-3);
  color: var(--ink);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.design-editor__button:hover:not(:disabled) {
  background: var(--paper-2);
}

.design-editor__button:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

.design-editor__button:disabled {
  border-color: var(--line-strong);
  color: var(--ink-3);
  cursor: not-allowed;
}

@media (prefers-reduced-motion: reduce) {
  .design-buy__tile,
  .design-buy__chevron,
  .design-preview__handle {
    transition: none;
  }
}

/* ---- The editor (islands/DesignEditor.tsx) ---------------------------------
   Advanced editing in the shop, and the owner's template layout in the admin.

   As a modal (`dialog`, the admin's; `sheet`, the shop's on a phone) it
   covers the page. On a phone (under 720px) it is a column: the bar with
   Cancel and Done, the canvas at no more than about two fifths of the screen,
   and the toolbar under it, which scrolls on its own while the canvas stays
   put. Wider, the canvas takes the room on the left and the toolbar is a
   side panel. The shop's sheet rises from the bottom of the screen over a
   scrim, a strip of the page left showing above it.

   In the page (`inline`, the shop's on a wide screen) it takes the design
   form's two columns: the canvas where the preview was, sticky as it was,
   and the bar and the toolbar where the steps were, behind the same
   hairline.

   Nothing has a width of its own: the canvas is sized to its box by the
   island, and every control wraps, so at 320px nothing scrolls sideways. */

.design-editor {
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--paper);
  color: var(--ink);
}

.design-editor--dialog,
.design-editor--sheet {
  position: fixed;
  inset: 0;
  z-index: var(--z-modal);
  overflow: hidden;
}

.design-editor--sheet {
  top: var(--space-lg);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  box-shadow: var(--shadow-lg);
  animation: design-sheet-rise var(--dur-base) var(--ease-out) both;
}

.design-editor--sheet .design-editor__bar {
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}

@keyframes design-sheet-rise {
  from { transform: translateY(var(--space-xl)); opacity: 0; }
  to { transform: none; opacity: 1; }
}

/* The page under the sheet, dimmed: the sheet is modal. */
.design-buy__scrim {
  position: fixed;
  inset: 0;
  z-index: var(--z-modal);
  background: var(--line-strong);
}

.design-editor--inline {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 0;
  scroll-margin-top: calc(var(--design-preview-top, 0px) + var(--space-md));
}

.design-editor--inline .design-editor__body {
  display: contents;
}

.design-editor--inline .design-editor__canvas {
  height: 50vh;
  height: 50svh;
  border-radius: var(--radius-md);
}

.design-editor--inline .design-editor__panel {
  width: auto;
  overflow: visible;
}

@media (min-width: 54rem) {
  .design-editor--inline {
    grid-template-columns: minmax(0, 1fr) minmax(300px, 380px);
    grid-template-areas:
      'canvas bar'
      'canvas panel';
    grid-template-rows: auto 1fr;
    column-gap: var(--space-2xl);
    align-items: start;
  }

  .design-editor--inline .design-editor__canvas {
    grid-area: canvas;
    position: sticky;
    top: calc(var(--design-preview-top, 0px) + var(--space-md));
    height: calc(100vh - var(--design-preview-top, 0px) - var(--space-2xl));
    height: calc(100svh - var(--design-preview-top, 0px) - var(--space-2xl));
    padding: var(--space-md);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
  }

  .design-editor--inline .design-editor__bar {
    grid-area: bar;
    padding: 0 0 var(--space-sm) var(--space-lg);
    border-left: 1px solid var(--line);
    background: none;
  }

  .design-editor--inline .design-editor__panel {
    grid-area: panel;
    width: auto;
    padding: var(--space-md) 0 var(--space-lg) var(--space-lg);
    overflow: visible;
    background: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .design-editor--sheet {
    animation: none;
  }
}

.design-editor__bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-xs);
  padding: var(--space-xs) var(--space-md);
  border-bottom: 1px solid var(--line);
  background: var(--paper-3);
}

.design-editor__title {
  margin: 0;
  font-family: var(--font-display);
  font-size: var(--text-lg);
}

.design-editor__exit {
  display: flex;
  gap: var(--space-xs);
}

/* Done is the one action the editor wants: the accent. */
.design-editor .design-editor__done {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--accent-ink);
}

.design-editor .design-editor__done:hover:not(:disabled) {
  border-color: var(--accent-deep);
  background: var(--accent-deep);
}

.design-editor__body {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-height: 0;
}

.design-editor__canvas {
  display: flex;
  flex: none;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2xs);
  height: 42vh;
  height: 42svh;
  min-width: 0;
  padding: var(--space-xs) var(--space-md) 0;
  background: var(--paper-2);
}

/* The box the island fits the stage into, in the mockup's own shape: the
   canvas's room less the hint under it. */
.design-editor__fit {
  display: flex;
  flex: 1;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-width: 0;
  min-height: 0;
}

.design-editor__stage {
  flex: none;
  max-width: 100%;
  border-radius: var(--radius-sm);
  background: var(--paper-2);
  /* Dragging a part of the design must not scroll or zoom the page. */
  touch-action: none;
}

.design-editor__stage:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

.design-editor__hint {
  margin: 0;
  max-width: var(--measure);
  color: var(--ink-2);
  font-size: var(--text-xs);
  text-align: center;
}

.design-editor__panel {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: var(--space-md);
  min-width: 0;
  min-height: 0;
  padding: var(--space-md);
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.design-editor__section {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  min-width: 0;
}

.design-editor__heading {
  margin: 0;
  font-size: var(--text-md);
}

.design-editor__field {
  display: flex;
  flex-direction: column;
  gap: var(--space-2xs);
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.design-editor__field > label:not(.design-editor__choice),
.design-editor__field > legend,
.design-editor__label,
.design-editor__number > label {
  padding: 0;
  color: var(--ink-2);
  font-size: var(--text-sm);
  font-weight: 600;
}

.design-editor__field input[type="text"],
.design-editor__field textarea,
.design-editor__field select,
.design-editor__number input {
  box-sizing: border-box;
  width: 100%;
  min-width: 0;
  min-height: 44px;
  padding: var(--space-xs) var(--space-sm);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--paper-3);
  color: var(--ink);
  font: inherit;
}

.design-editor__field textarea {
  resize: vertical;
}

.design-editor__field input:focus-visible,
.design-editor__field textarea:focus-visible,
.design-editor__field select:focus-visible,
.design-editor__number input:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

.design-editor__note {
  margin: 0;
  color: var(--ink-2);
  font-size: var(--text-sm);
}

/* Size: − [number] + on one line, the number taking what is left. */
.design-editor__stepper {
  display: flex;
  align-items: flex-end;
  gap: var(--space-xs);
  min-width: 0;
}

.design-editor__stepper > button {
  flex: none;
  min-width: 44px;
  min-height: 44px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-pill);
  background: var(--paper-3);
  color: var(--ink);
  font: inherit;
  font-size: var(--text-md);
  line-height: 1;
  cursor: pointer;
}

.design-editor__stepper > button:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

.design-editor__stepper > button:disabled {
  color: var(--ink-3);
  cursor: not-allowed;
}

.design-editor__stepper > .design-editor__number {
  flex: 1;
}

.design-editor__number {
  display: flex;
  flex-direction: column;
  gap: var(--space-2xs);
  min-width: 0;
}

.design-editor__number-input {
  display: flex;
  align-items: center;
  gap: var(--space-2xs);
  min-width: 0;
}

/* Position and size: as many 7rem columns as fit, one on the narrowest. */
.design-editor__placement {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 7rem), 1fr));
  align-items: end;
  gap: var(--space-xs);
}

.design-editor__placement > legend {
  margin-bottom: var(--space-2xs);
}

.design-editor__choices {
  flex-flow: row wrap;
  gap: var(--space-xs);
}

.design-editor__choices > legend {
  width: 100%;
  margin-bottom: var(--space-2xs);
}

/* A choice is a pill, its radio kept in the page and the tab order. */
.design-editor__choice {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: var(--space-xs);
  min-height: 44px;
  padding: var(--space-2xs) var(--space-md);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-pill);
  background: var(--paper-3);
  cursor: pointer;
}

.design-editor__choice input {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: 0;
  opacity: 0;
}

.design-editor__choice:has(input:checked) {
  border-color: var(--ink);
  box-shadow: inset 0 0 0 1px var(--ink);
}

.design-editor__choice:has(input:focus-visible) {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

.design-editor__ink {
  width: var(--space-lg);
  height: var(--space-lg);
  border: 1px solid var(--line-strong);
  border-radius: 50%;
}

/*
  A text's ink in the simple form: small labelled roundels as the keychain
  designer's colour row draws them (configurator.css `.swatch`), each a 32 px
  disc ringed when chosen, its name under it, a 44 px target in all. The
  discs are filled inline with the inks; everything else is tokens.
*/
.design-buy__inks {
  min-width: 0;
}

.design-buy__ink-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-xs) var(--space-sm);
  min-width: 0;
}

.design-buy__ink {
  position: relative;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2xs);
  min-width: 44px;
  max-width: 5.5rem;
  padding-top: var(--space-2xs);
  cursor: pointer;
  text-align: center;
}

.design-buy__ink input {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: 0;
  opacity: 0;
}

.design-buy__ink-disc {
  width: 32px;
  height: 32px;
  border: 2px solid transparent;
  border-radius: 50%;
  box-shadow: 0 0 0 1px var(--line-strong);
  transition: box-shadow var(--dur-fast) var(--ease-out);
}

/* Selection is the ring, which a keyboard user sees too: never colour alone. */
.design-buy__ink:has(input:checked) .design-buy__ink-disc {
  border-color: var(--paper);
  box-shadow: 0 0 0 2px var(--ink);
}

.design-buy__ink:has(input:focus-visible) .design-buy__ink-disc {
  outline: 2px solid var(--focus-ring);
  outline-offset: 4px;
}

.design-buy__ink:has(input:disabled) {
  cursor: not-allowed;
  opacity: 0.5;
}

.design-buy__ink-name {
  color: var(--ink-2);
  font-size: var(--text-xs);
  line-height: 1.2;
  overflow-wrap: anywhere;
}

.design-buy__ink:has(input:checked) .design-buy__ink-name {
  color: var(--ink);
  font-weight: 600;
}

@media (prefers-reduced-motion: reduce) {
  .design-buy__ink-disc {
    transition: none;
  }
}

/*
  "Any colour": the roundel picker under the swatches. Its wheel, thumb,
  chip and lightness track are filled inline with inks (the product's
  colours, not the site's, as each swatch's disc is); everything else here is
  the site's tokens. The thumb is ringed as the keychain designer's chosen
  swatch is (configurator.css `.swatch-on`), and so is a focused one, more
  boldly, so the state never rests on colour alone.
*/
.ink-picker {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  flex-basis: 100%;
  min-width: 0;
  padding-top: var(--space-xs);
}

/*
  22 px round the wheel: half the thumb's 44 px target, which is also as far
  as the 28 px thumb, its ring and its focus outline reach past the rim. So
  the thumb, at any point on the rim, stays inside the picker and never
  covers the choices above it or the fields below.
*/
.ink-picker__wheel {
  position: relative;
  box-sizing: border-box;
  width: min(calc(100% - 44px), 13.5rem);
  margin: 22px;
  aspect-ratio: 1;
  border-radius: 50%;
  box-shadow: 0 0 0 1px var(--line-strong);
  touch-action: none;
  cursor: crosshair;
}

.ink-picker__thumb {
  position: absolute;
  box-sizing: border-box;
  width: 28px;
  height: 28px;
  margin: -14px 0 0 -14px;
  border: 2px solid var(--paper);
  border-radius: 50%;
  box-shadow: 0 0 0 2px var(--ink);
  cursor: grab;
}

/* The touch floor: 44 × 44 around the 28 px disc, as the swatches' hit area. */
/* 44 × 44: the 24 px inside the thumb's border, and 10 px more all round. */
.ink-picker__thumb::after {
  content: '';
  position: absolute;
  inset: -10px;
  border-radius: 50%;
}

.ink-picker__thumb:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 4px;
}

.ink-picker__keys {
  margin: 0;
  color: var(--ink-3);
  font-size: var(--text-xs);
}

.ink-picker__field {
  display: flex;
  flex-direction: column;
  gap: var(--space-2xs);
  min-width: 0;
}

.ink-picker__field > label {
  color: var(--ink-2);
  font-size: var(--text-sm);
  font-weight: 600;
}

/* Its own track, black through the colour to white (inline), as a band in a 44 px row. */
.ink-picker__lightness {
  appearance: none;
  box-sizing: border-box;
  width: 100%;
  height: 44px;
  margin: 0;
  padding: var(--space-sm) 0;
  border-radius: var(--radius-pill);
  background-clip: content-box;
  cursor: pointer;
}

.ink-picker__lightness::-webkit-slider-thumb {
  appearance: none;
  width: 28px;
  height: 28px;
  border: 2px solid var(--paper);
  border-radius: 50%;
  background: var(--paper-3);
  box-shadow: 0 0 0 2px var(--ink);
}

.ink-picker__lightness::-moz-range-thumb {
  width: 24px;
  height: 24px;
  border: 2px solid var(--paper);
  border-radius: 50%;
  background: var(--paper-3);
  box-shadow: 0 0 0 2px var(--ink);
}

.ink-picker__lightness::-moz-range-track {
  background: transparent;
}

.ink-picker__lightness:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

.ink-picker__code {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  min-width: 0;
}

.ink-picker__code input {
  box-sizing: border-box;
  flex: 1;
  width: 100%;
  min-width: 0;
  max-width: 12rem;
  min-height: 44px;
  padding: var(--space-xs) var(--space-sm);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--paper-3);
  color: var(--ink);
  font: inherit;
}

.ink-picker__code input:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

.ink-picker__code input[aria-invalid='true'] {
  border-color: var(--danger);
}

.ink-picker__chip {
  flex: none;
  width: var(--space-xl);
  height: var(--space-xl);
  border: 2px solid var(--paper);
  border-radius: 50%;
  box-shadow: 0 0 0 1px var(--line-strong);
}

.design-editor__row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-xs);
}

/* The warnings: words on a tint, never colour alone; nothing when all is well. */
.design-editor__warnings ul {
  display: flex;
  flex-direction: column;
  gap: var(--space-2xs);
  margin: 0;
  padding: var(--space-xs) var(--space-sm);
  list-style: none;
  border-radius: var(--radius-sm);
  background: var(--accent-soft);
  color: var(--ink);
  font-size: var(--text-sm);
}

@media (min-width: 720px) {
  .design-editor__body {
    flex-direction: row;
  }

  .design-editor__canvas {
    flex: 1;
    justify-content: center;
    height: auto;
    padding: var(--space-lg);
  }

  .design-editor__panel {
    flex: none;
    width: min(26rem, 42vw);
    border-left: 1px solid var(--line);
    background: var(--paper);
  }

  .design-editor__hint {
    font-size: var(--text-sm);
  }
}
