/* The design system page: a spec sheet of the tokens, and the panel that edits them.
   Every value is a token. The store writes the edited tokens onto .ds-sheet as the
   same custom properties styles.css uses, so the sheet previews an edit and the
   site around it, nav and panel included, keeps the file's values. Gray does the
   work; --color-link marks only state and direction: links, focus, the current
   item, a toggle that is on, the live point and one highlight. */

.ds {
  --ds-tap: calc(var(--space-2xl) - var(--space-xs));
  --ds-unit: var(--space-2xl);
  --ds-header: calc(var(--chrome-inset) * 2 + var(--chrome-size));
  /* What the editor itself is drawn with. Set here, outside the sheet, they hold the
     file's values, so an edit on the sheet, a focus ring of no width say, cannot
     take away the editor's own marks. */
  --ds-ring-width: var(--focus-width);
  --ds-ring-offset: var(--focus-offset);
  --ds-ring-color: var(--focus-color);
  --ds-outline: var(--border-medium);
  --ds-edge: var(--space-sm);
  --ds-accent: var(--color-link);
  --ds-quiet: var(--color-border);
  padding-bottom: var(--space-2xl);
}

.ds [hidden] { display: none; }

.ds-layout {
  display: grid;
  gap: var(--space-lg);
  padding: var(--space-2xl) var(--space-md) 0;
}

.ds-layout > .next-step { margin-top: var(--space-xl); }

/* The sheet is the measure its own layouts answer to: beside the panel on a small
   desktop it is narrower than a tablet's screen. A token edited to its limit can
   make a piece wider than the sheet; it is cut at the sheet's edge, a little past
   it so an outline there still shows, rather than scrolling the page sideways. */
.ds-sheet {
  container-type: inline-size;
  min-width: 0;
  max-width: var(--container-xl);
  margin-inline: calc(var(--ds-edge) * -1);
  padding-inline: var(--ds-edge);
  overflow-x: clip;
  color: var(--color-text-body);
  background: var(--color-bg);
  font-family: var(--font-ui);
  font-weight: var(--font-light);
  font-size: var(--text-base);
  line-height: var(--leading-normal);
  transition: background-color var(--duration-slow) var(--ease-in-out), color var(--duration-slow) var(--ease-in-out);
}

/* ------------------------------------------------------------ controls */

.ds-tool, .ds-button, .ds-panel-tab, .ds-tab, .ds-chip, .ds-panel-handle {
  font: inherit;
  font-size: var(--text-sm);
  line-height: var(--leading-tight);
  color: var(--color-text-muted);
  background: transparent;
  border: var(--border-thin) solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-xs) var(--space-sm);
  cursor: pointer;
  transition: color var(--duration-normal) var(--ease-in-out),
              background-color var(--duration-normal) var(--ease-in-out);
}

.ds-tool:hover, .ds-button:hover, .ds-panel-tab:hover, .ds-tab:hover, .ds-chip:hover {
  color: var(--color-text);
  background: var(--color-control-hover);
}

.ds-panel-tab[aria-selected="true"], .ds-tab[aria-selected="true"], .ds-tab[aria-current="true"],
.ds-more:has(+ .ds-more-list [aria-current="true"]) {
  color: var(--color-text);
  background: var(--color-control);
  box-shadow: inset 0 calc(var(--border-medium) * -1) 0 var(--color-link);
}

.ds-tool[aria-disabled="true"] { opacity: var(--opacity-faint); cursor: default; }

:is(.ds-tool, .ds-button, .ds-panel-tab, .ds-tab, .ds-chip, .ds-panel-handle, .ds-input, .ds-colour,
    .ds-range):focus-visible {
  outline: var(--ds-ring-width) solid var(--ds-ring-color);
  outline-offset: var(--ds-ring-offset);
}

.ds-actions { display: flex; flex-wrap: wrap; gap: var(--space-sm); }

/* Something on the sheet that opens its tokens in the panel: the piece, and laid
   over the whole of it the one button that does the opening. A piece inside
   another, a chart's canvas and its chips sit above the button around them. */
.ds-pick {
  position: relative;
  border-radius: var(--radius-md);
  outline: var(--ds-outline) solid transparent;
  outline-offset: var(--ds-outline);
  scroll-margin-top: var(--space-lg);
  transition: outline-color var(--duration-normal) var(--ease-in-out);
}

.ds-pick-edit {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  padding: 0;
  background: transparent;
  border: 0;
  border-radius: inherit;
  outline: none;
  cursor: pointer;
}

.ds-pick .ds-canvas, .ds-pick .ds-chips { position: relative; }
/* The chosen piece wears the accent, and the others of its kind, which change with it, a quiet line. */
.ds-pick:hover, .ds-pick.is-same { outline-color: var(--ds-quiet); }
.ds-pick.is-selected { outline-color: var(--ds-accent); }
.ds-pick:has(> .ds-pick-edit:focus-visible) { outline-color: var(--ds-ring-color); }
.ds-pick.is-inline { display: inline-block; }
.ds-pick.is-block { display: block; }

/* ---------------------------------------------------------------- panel */

.ds-panel {
  font-size: var(--text-sm);
  color: var(--color-text-body);
  background: var(--color-bg);
  border: var(--border-thin) solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-md);
}

.ds-panel-top {
  display: grid;
  gap: var(--space-sm);
  padding-bottom: var(--space-sm);
  border-bottom: var(--border-thin) solid var(--color-border-muted);
}

.ds-panel-bar { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-xs); }
.ds-panel-name { margin: 0 auto 0 0; color: var(--color-text); font-size: var(--text-base); }
.ds-panel-handle { display: none; }

/* The line is kept when it has nothing to say, so a message does not move what is being pressed. */
.ds-status {
  margin: 0;
  min-height: calc(var(--text-xs) * var(--leading-normal));
  color: var(--color-text-muted);
  font-size: var(--text-xs);
}

.ds-scope {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-sm);
  margin: var(--space-sm) 0;
  padding: var(--space-xs) var(--space-xs) var(--space-xs) var(--space-sm);
  border: var(--border-thin) solid var(--color-border);
  border-radius: var(--radius-md);
  color: var(--color-text-muted);
}

.ds-scope b { color: var(--color-text); font-weight: var(--font-regular); }
.ds-panel-tabs {
  display: grid;
  grid-template-columns: repeat(4, auto);
  gap: var(--space-xs);
  margin: var(--space-sm) 0;
}
.ds-panel-tab { padding-inline: var(--space-xs); font-size: var(--text-xs); }

.ds-field-heading {
  display: flex;
  justify-content: space-between;
  margin: var(--space-md) 0 var(--space-xs);
  color: var(--color-text-muted);
  font-size: var(--text-xs);
  font-weight: var(--font-regular);
  letter-spacing: var(--tracking-wider);
  text-transform: uppercase;
}

.ds-field {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: var(--space-xs) var(--space-sm);
  padding: var(--space-sm) 0;
  border-bottom: var(--border-thin) solid var(--color-border-muted);
}

.ds-field-name { color: var(--color-text); overflow-wrap: anywhere; }
.ds-field.is-edited .ds-field-name::after {
  content: '';
  display: inline-block;
  width: var(--space-xs);
  height: var(--space-xs);
  margin-left: var(--space-xs);
  vertical-align: middle;
  border-radius: var(--radius-full);
  background: var(--color-link);
}

.ds-field-meta { grid-area: 1 / 2; color: var(--color-text-muted); font-size: var(--text-xs); text-align: right; }
.ds-field-inputs { grid-column: 1 / -1; display: flex; align-items: center; gap: var(--space-sm); min-width: 0; }

.ds-input {
  min-width: 0;
  font: inherit;
  font-size: var(--text-xs);
  color: var(--color-text);
  background: var(--color-bg);
  border: var(--border-thin) solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: var(--space-xs) var(--space-sm);
}

.ds-input[aria-invalid="true"] { border-style: dashed; }
.ds-input.is-number { width: calc(var(--ds-unit) * 1.75); margin-left: auto; }
.ds-input.is-hex { width: calc(var(--ds-unit) * 2); text-transform: uppercase; }
.ds-input.is-text { flex: 1; }
.ds-range { flex: 1; min-width: 0; accent-color: var(--color-text); }

.ds-colour {
  flex: none;
  width: var(--icon-lg);
  height: var(--icon-lg);
  padding: 0;
  border: var(--border-thin) solid var(--color-border);
  border-radius: var(--radius-sm);
  background: none;
  cursor: pointer;
}

/* The colour fills its well, with no second box inside the first. */
.ds-colour::-webkit-color-swatch-wrapper { padding: 0; }
.ds-colour::-webkit-color-swatch, .ds-colour::-moz-color-swatch { border: 0; }

.ds-panel-note { margin: var(--space-sm) 0; color: var(--color-text-muted); font-size: var(--text-xs); }
.ds-presets { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-xs); }
.ds-readonly summary { padding: var(--space-sm) 0; color: var(--color-text-muted); cursor: pointer; }

.ds-curve { width: var(--icon-lg); height: var(--icon-lg); overflow: visible; }
.ds-curve path {
  fill: none;
  stroke: var(--color-text);
  stroke-width: var(--border-thin);
  vector-effect: non-scaling-stroke;
}

/* ------------------------------------------------------------- the sheet */

.ds-head {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: flex-end;
  gap: var(--space-md);
  padding-bottom: var(--space-lg);
}

.ds-title {
  color: var(--color-text);
  font-size: var(--h1-size);
  font-weight: var(--font-regular);
  line-height: var(--leading-tight);
  letter-spacing: var(--tracking-tight);
}

.ds-lede, .ds-section-lede { color: var(--color-text-muted); overflow-wrap: anywhere; }

.ds-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  border: var(--border-thin) solid var(--color-border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

/* A hairline between the cells keeps two of one colour from reading as one. */
.ds-strip-cell {
  display: flex;
  align-items: flex-end;
  min-height: calc(var(--ds-unit) * 2);
  padding: var(--space-sm);
  border-radius: 0;
  box-shadow: 0 0 0 var(--border-thin) var(--color-border);
  font-size: var(--text-xs);
  outline-offset: calc(var(--ds-outline) * -1);
}

/* A cell's own colour can be the accent's or the focus ring's: its marks take its ink instead. */
.ds-strip-cell.is-selected, .ds-strip-cell:has(> .ds-pick-edit:focus-visible) { outline-color: currentColor; }

.ds-stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--border-thin);
  margin: var(--space-md) 0 0;
  border: var(--border-thin) solid var(--color-border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  list-style: none;
}

.ds-stat {
  display: flex;
  flex-direction: column;
  padding: var(--space-md);
  background: var(--color-bg);
  border-radius: 0;
  box-shadow: 0 0 0 var(--border-thin) var(--color-border);
  outline-offset: calc(var(--ds-outline) * -1);
}

.ds-stat-value { color: var(--color-text); font-size: var(--text-xl); overflow-wrap: anywhere; }
.ds-stat-name { color: var(--color-text-muted); font-size: var(--text-sm); }

.ds-section {
  margin-top: var(--space-xl);
  padding-top: var(--space-xl);
  border-top: var(--border-thin) solid var(--color-border);
}

.ds-section-title {
  margin-bottom: var(--space-xs);
  color: var(--color-text);
  font-size: var(--h2-size);
  font-weight: var(--font-regular);
  line-height: var(--leading-tight);
}

.ds-section-lede { max-width: var(--container-reading); margin-bottom: var(--space-lg); }

.ds-group { margin-bottom: var(--space-lg); }
.ds-group-name {
  display: flex;
  justify-content: space-between;
  margin-bottom: var(--space-sm);
  padding-bottom: var(--space-xs);
  border-bottom: var(--border-thin) solid var(--color-border-muted);
  color: var(--color-text);
  font-size: var(--text-base);
  font-weight: var(--font-regular);
}

.ds-group-name span { color: var(--color-text-muted); font-size: var(--text-sm); }

.ds-swatches { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-md); }

.ds-swatch { display: flex; flex-direction: column; gap: var(--space-xs); font-size: var(--text-xs); }
.ds-swatch-chip {
  display: block;
  height: var(--ds-unit);
  border: var(--border-thin) solid var(--color-border);
  border-radius: var(--radius-md);
}

.ds-swatch-chip.is-small { display: inline-block; flex: none; width: var(--icon-md); height: var(--icon-md); }
.ds-swatch-name { color: var(--color-text); overflow-wrap: anywhere; }
.ds-swatch-hex { color: var(--color-text-muted); }

.ds-type-row {
  display: grid;
  grid-template-columns: calc(var(--ds-unit) * 4) minmax(0, 1fr);
  align-items: baseline;
  gap: var(--space-md);
  padding: var(--space-md) 0;
  border-bottom: var(--border-thin) solid var(--color-border-muted);
  border-radius: 0;
}

.ds-type-name { display: block; color: var(--color-text); font-size: var(--text-sm); }
.ds-type-spec { color: var(--color-text-muted); font-size: var(--text-xs); }
.ds-type-sample { color: var(--color-text); overflow-wrap: anywhere; }

.ds-columns {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(calc(var(--ds-unit) * 5), 1fr));
  gap: var(--space-xl);
}

.ds-radii { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: var(--space-xs); }
.ds-radius {
  display: grid;
  justify-items: start;
  gap: var(--space-xs);
  padding: var(--space-xs) 0;
  font-size: var(--text-xs);
}
.ds-radius-shape {
  width: var(--ds-unit);
  height: var(--ds-unit);
  background: var(--color-control);
  border: var(--border-medium) solid var(--color-text-subtle);
}

.ds-shape-name { color: var(--color-text); }
.ds-shape-value { color: var(--color-text-muted); }
.ds-space {
  display: grid;
  grid-template-columns: var(--ds-unit) var(--ds-unit) minmax(0, 1fr);
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-xs) 0;
  font-size: var(--text-xs);
}

.ds-space-bar { height: var(--space-sm); background: var(--color-text-muted); border-radius: var(--radius-sm); }

/* As many tiles a row as fit, never more than four: the twelve then fill every row. */
.ds-tiles {
  display: grid;
  grid-template-columns: repeat(auto-fill,
    minmax(max(calc(var(--ds-unit) * 4), calc((100% - var(--border-thin) * 3) / 4)), 1fr));
  gap: var(--border-thin);
  border: var(--border-thin) solid var(--color-border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.ds-tile {
  display: flex;
  flex-direction: column;
  background: var(--color-bg);
  border-radius: 0;
  box-shadow: 0 0 0 var(--border-thin) var(--color-border);
  outline-offset: calc(var(--ds-outline) * -1);
}

.ds-tile-canvas {
  flex: 1;
  display: grid;
  place-items: center;
  min-height: calc(var(--ds-unit) * 2.5);
  padding: var(--space-md);
  background: var(--color-bg);
}

.ds-tile-name {
  display: flex;
  flex-direction: column;
  padding: var(--space-sm) var(--space-md);
  border-top: var(--border-thin) solid var(--color-border-muted);
  color: var(--color-text);
  font-size: var(--text-sm);
}

.ds-tile-name span { color: var(--color-text-muted); font-size: var(--text-xs); }

/* ------------------------------------------------------------- specimens */

.ds-ui-button {
  display: inline-block;
  padding: var(--space-sm) var(--space-md);
  color: var(--color-bg);
  background: var(--color-text);
  border: var(--border-thin) solid var(--color-text);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  font-weight: var(--font-regular);
  line-height: var(--leading-tight);
}

.ds-ui-button.is-secondary { color: var(--color-text); background: transparent; border-color: var(--color-border); }

.ds-ui-link {
  color: var(--color-link);
  text-decoration: underline;
  text-decoration-thickness: var(--border-thin);
  text-underline-offset: var(--space-xs);
}

.ds-ui-input {
  display: block;
  min-width: calc(var(--ds-unit) * 3);
  padding: var(--space-sm) var(--space-md);
  color: var(--color-text-muted);
  background: var(--color-bg-elevated);
  border: var(--border-thin) solid var(--color-border);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
}

/* On a card, which wears the same fill, the field takes the page's. */
.ds-ui-card .ds-ui-input { background: var(--color-bg); }
.ds-ui-input.is-focused {
  border-color: var(--color-link);
  box-shadow: 0 0 0 var(--focus-offset) var(--color-bg),
              0 0 0 calc(var(--focus-offset) + var(--focus-width)) var(--color-link);
}

.ds-ui-badge {
  display: inline-block;
  padding: 0 var(--space-sm);
  color: var(--color-link);
  border: var(--border-thin) solid var(--color-link);
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
}

.ds-ui-badge.is-quiet { color: var(--color-text-muted); border-color: var(--color-border); }

.ds-ui-card {
  display: block;
  padding: var(--space-md);
  color: var(--color-text-body);
  background: var(--color-bg-elevated);
  border: var(--border-thin) solid var(--color-border);
  border-radius: var(--radius-lg);
  min-width: 0;
}

.ds-ui-card.is-panel { display: flex; flex-direction: column; gap: var(--space-sm); }

.ds-ui-nav {
  display: flex;
  align-items: baseline;
  gap: var(--space-md);
  color: var(--color-text-muted);
  font-size: var(--text-sm);
}
.ds-ui-nav b { color: var(--color-text); font-weight: var(--font-medium); }
.ds-ui-nav .is-current, .ds-ui-tabs .is-current {
  color: var(--color-text);
  box-shadow: inset 0 calc(var(--border-medium) * -1) 0 var(--color-link);
}

.ds-ui-headline {
  color: var(--color-text);
  font-size: var(--headline-size);
  font-weight: var(--font-regular);
  line-height: var(--leading-headline);
  letter-spacing: var(--tracking-tight);
}

/* In a card the headline steps down a size, to sit inside it. */
.ds-ui-card .ds-ui-headline { font-size: var(--h1-size); overflow-wrap: anywhere; }
.ds-ui-heading { color: var(--color-text); font-size: var(--h2-size); font-weight: var(--font-regular); }
.ds-ui-body {
  font-family: var(--font-reading);
  font-size: var(--body-size);
  font-weight: var(--font-light);
  line-height: var(--leading-relaxed);
}
.ds-ui-muted { color: var(--color-text-muted); font-size: var(--text-sm); }
.ds-ui-eyebrow { color: var(--color-text-muted); font-size: var(--text-xs); letter-spacing: var(--tracking-wide); }
.ds-ui-figure { color: var(--color-text); font-size: var(--text-xl); }
.ds-ui-caption { color: var(--color-text-muted); font-size: var(--text-xs); }
.ds-ui-up, .ds-ui-tick, .ds-ui-count { color: var(--color-link); }
.ds-ui-down { color: var(--color-text-muted); }

.ds-ui-footer {
  margin-top: var(--space-lg);
  padding-top: var(--space-sm);
  color: var(--color-text-muted);
  border-top: var(--border-thin) solid var(--color-border);
  font-size: var(--text-xs);
}

.ds-ui-toggle {
  position: relative;
  display: inline-block;
  flex: none;
  width: calc(var(--space-2xl) - var(--space-md));
  height: calc(var(--space-md) + var(--space-xs));
  vertical-align: middle;
  background: var(--color-border);
  border-radius: var(--radius-full);
  /* Off, the track keeps an edge: in the light theme its fill is close to a card's. */
  box-shadow: inset 0 0 0 var(--border-thin) var(--color-text-muted);
  transition: background-color var(--duration-normal) var(--ease-in-out);
}

.ds-ui-toggle::after {
  content: '';
  position: absolute;
  top: calc(var(--space-xs) / 2);
  left: calc(var(--space-xs) / 2);
  width: var(--space-md);
  height: var(--space-md);
  background: var(--color-text-muted);
  border-radius: var(--radius-full);
  transition: transform var(--duration-normal) var(--ease-out);
}

.ds-ui-toggle.is-on { background: var(--color-link); box-shadow: none; }
.ds-ui-toggle.is-on::after {
  background: var(--color-bg);
  transform: translateX(calc(var(--space-md) - var(--space-xs)));
}

.ds-ui-bubble {
  max-width: fit-content;
  padding: var(--space-xs) var(--space-sm);
  color: var(--color-text);
  background: var(--color-control);
  border-radius: var(--radius-lg);
  font-size: var(--text-sm);
}

.ds-ui-bubble.is-mine { margin-left: auto; color: var(--color-bg); background: var(--color-text); }

.ds-ui-row { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-sm); font-size: var(--text-sm); }
.ds-ui-row.is-spread { justify-content: space-between; }
.ds-ui-row.is-line { flex-wrap: nowrap; }
.ds-ui-row.is-line > span { min-width: 0; overflow-wrap: anywhere; }
.ds-sheet .is-centred { justify-content: center; text-align: center; }
.ds-sheet .is-right { text-align: right; }

/* Cards, figures and charts stack on a narrow sheet and sit in threes, or in twos, on a wider one. */
.ds-ui-grid, .ds-ui-pair, .ds-ui-trio, .ds-chart-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--space-md);
}

.ds-ui-calendar {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: var(--border-medium);
  font-size: var(--text-xs);
  text-align: center;
}

.ds-ui-day { padding: var(--space-xs) 0; border-radius: var(--radius-sm); }
.ds-ui-day.is-picked { color: var(--color-bg); background: var(--color-link); }

.ds-ui-table { width: 100%; border-collapse: collapse; font-size: var(--text-xs); }
.ds-ui-table th {
  padding: var(--space-xs);
  color: var(--color-text-muted);
  font-weight: var(--font-regular);
  text-align: left;
  border-bottom: var(--border-thin) solid var(--color-border);
}

.ds-ui-table td { padding: var(--space-xs); border-bottom: var(--border-thin) solid var(--color-border-muted); }

.ds-ui-app {
  display: grid;
  grid-template-columns: calc(var(--ds-unit) * 3) minmax(0, 1fr);
  gap: var(--space-md);
}

.ds-ui-side {
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
  color: var(--color-text-muted);
  font-size: var(--text-sm);
}
.ds-ui-side > span { padding: var(--space-xs) var(--space-sm); white-space: nowrap; }
.ds-ui-side .is-current, .ds-ui-thread.is-current {
  color: var(--color-text);
  background: var(--color-control);
  box-shadow: inset var(--border-medium) 0 0 var(--color-link);
}

.ds-ui-stack { display: grid; gap: var(--space-md); min-width: 0; }
.ds-ui-narrow { display: grid; justify-items: start; gap: var(--space-md); max-width: calc(var(--ds-unit) * 8); }
.ds-ui-narrow > :first-child { justify-self: stretch; }
.ds-ui-label { margin-top: var(--space-xs); color: var(--color-text-muted); font-size: var(--text-xs); }
.ds-ui-tabs { display: flex; gap: var(--space-md); color: var(--color-text-muted); font-size: var(--text-sm); }
.ds-ui-tabs span { padding-bottom: var(--space-xs); }

.ds-ui-toast {
  display: inline-block;
  padding: var(--space-xs) var(--space-md);
  color: var(--color-bg);
  background: var(--color-text);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
}

.ds-ui-hero {
  display: grid;
  justify-items: center;
  gap: var(--space-sm);
  padding: var(--space-xl) 0;
  text-align: center;
}

.ds-ui-mail {
  display: grid;
  grid-template-columns: calc(var(--ds-unit) * 2.5) minmax(0, 1fr) minmax(0, 1.5fr);
  border: var(--border-thin) solid var(--color-border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  font-size: var(--text-sm);
}

.ds-ui-mail > * { padding: var(--space-sm); border-right: var(--border-thin) solid var(--color-border); min-width: 0; }
.ds-ui-mail > .ds-ui-side { padding: 0; }
.ds-ui-mail > :last-child { border-right: 0; }
.ds-ui-list { padding: 0; }
.ds-ui-thread {
  display: flex;
  flex-direction: column;
  padding: var(--space-sm);
  border-bottom: var(--border-thin) solid var(--color-border-muted);
}
.ds-ui-thread:last-child { border-bottom: 0; }
.ds-ui-thread b { color: var(--color-text); font-weight: var(--font-regular); }
.ds-ui-thread span { color: var(--color-text-muted); font-size: var(--text-xs); }
.ds-ui-read { display: grid; align-content: start; gap: var(--space-sm); }

.ds-ui-specimen { display: grid; gap: var(--space-md); }
.ds-ui-specimen > .ds-pick { display: grid; gap: var(--space-xs); }
.ds-ui-sample { color: var(--color-text); line-height: var(--leading-tight); overflow-wrap: anywhere; }
.ds-ui-weights {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-md);
  color: var(--color-text);
  font-size: var(--text-xl);
}

/* ---------------------------------------------------------------- charts */

.ds-chart {
  display: grid;
  grid-template-rows: auto 1fr;
  gap: var(--space-sm);
  min-width: 0;
  padding: var(--space-md);
  border: var(--border-thin) solid var(--color-border);
  border-radius: var(--radius-lg);
}

.ds-chart-head {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-sm);
  /* As tall as a chip, so a title beside chips and one without sit on the same line. */
  min-height: calc(var(--text-sm) * var(--leading-tight) + (var(--space-xs) + var(--border-thin)) * 2);
  color: var(--color-text-muted);
  font-size: var(--text-sm);
}

.ds-chart-row { margin-top: var(--space-md); }

.ds-canvas { display: block; width: 100%; height: calc(var(--ds-unit) * 5); touch-action: pan-y; }
.ds-canvas.is-short { height: calc(var(--ds-unit) * 3.5); }

.ds-chips { display: flex; flex-wrap: wrap; gap: var(--space-xs); }
.ds-chip::before {
  content: '';
  display: inline-block;
  width: var(--space-sm);
  height: var(--border-medium);
  margin-right: var(--space-xs);
  vertical-align: middle;
  background: var(--color-text);
}

.ds-chip.is-quiet::before { background: var(--color-text-muted); }
.ds-chip[aria-pressed="false"] { text-decoration: line-through; }
.ds-chip[aria-pressed="false"]::before { background: var(--color-border); }

.ds-bars { display: flex; align-items: flex-end; gap: var(--space-xs); height: calc(var(--ds-unit) * 2.5); }
.ds-chart > .ds-bars { align-self: end; }
.ds-bars.is-short { height: calc(var(--ds-unit) * 1.5); }
.ds-bar {
  flex: 1;
  height: var(--ds-bar);
  background: var(--color-text-muted);
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
}

.ds-bar.is-best { background: var(--color-link); }

.ds-heat {
  display: grid;
  grid-template-rows: repeat(7, auto);
  grid-template-columns: repeat(20, minmax(0, var(--contributions-cell-size)));
  grid-auto-flow: column;
  align-self: start;
  gap: var(--contributions-gap);
}

/* The site's own contributions graph steps a colour up from the empty cell; here the ink does the stepping. */
.ds-heat-cell { aspect-ratio: 1; background: var(--color-border); border-radius: calc(var(--radius-sm) / 2); }
.ds-heat-cell[data-level="1"] { background: color-mix(in oklab, var(--color-text) 25%, var(--color-border)); }
.ds-heat-cell[data-level="2"] { background: color-mix(in oklab, var(--color-text) 50%, var(--color-border)); }
.ds-heat-cell[data-level="3"] { background: color-mix(in oklab, var(--color-text) 75%, var(--color-border)); }
.ds-heat-cell[data-level="4"] { background: var(--color-text); }
.ds-heat-cell[data-today] {
  outline: var(--border-medium) solid var(--color-link);
  outline-offset: var(--border-thin);
}

.ds-spark { display: block; width: 100%; height: var(--ds-unit); overflow: visible; }
.ds-spark polyline {
  fill: none;
  stroke: var(--color-text);
  stroke-width: var(--border-medium);
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
}

.ds-spark .ds-spark-end {
  stroke: var(--color-link);
  stroke-width: calc(var(--border-medium) * 3);
  stroke-linecap: round;
}

/* ---------------------------------------------------------------- in use */

/* The tab list lends its tabs to the row, so the menu button follows the last of them. */
.ds-tabs { display: flex; flex-wrap: wrap; gap: var(--space-xs); margin-bottom: var(--space-md); }
.ds-tablist { display: contents; }
.ds-more-list { display: flex; flex-wrap: wrap; flex-basis: 100%; gap: var(--space-xs); }
.ds-screen { min-width: 0; }

/* --------------------------------------------------------------- dialogs */

.ds-dialog {
  margin: auto;
  width: min(var(--container-reading), calc(100vw - var(--space-xl)));
  padding: var(--space-lg);
  color: var(--color-text);
  background: var(--color-dialog);
  border: var(--border-thin) solid var(--color-border);
  border-radius: var(--radius-lg);
}

.ds-dialog::backdrop { background: var(--color-dialog-backdrop); }
.ds-dialog form { display: grid; gap: var(--space-md); }
.ds-dialog-title { margin: 0; font-size: var(--h3-size); font-weight: var(--font-regular); }

.ds-code {
  max-height: max(calc(100dvh - var(--ds-unit) * 6), calc(var(--ds-unit) * 2));
  margin: 0;
  padding: var(--space-md);
  overflow: auto;
  color: var(--color-text-body);
  background: var(--color-bg);
  border: var(--border-thin) solid var(--color-border);
  border-radius: var(--radius-md);
  font-size: var(--text-xs);
}

.ds-import-text { width: 100%; resize: vertical; }
.ds-import-file { font: inherit; font-size: var(--text-xs); color: var(--color-text-muted); }
.ds-import-file::file-selector-button {
  margin-right: var(--space-sm);
  padding: var(--space-xs) var(--space-sm);
  font: inherit;
  color: var(--color-text-muted);
  background: transparent;
  border: var(--border-thin) solid var(--color-border);
  border-radius: var(--radius-md);
  cursor: pointer;
}

/* ---------------------------------------------------------------- widths */

/* A sheet no wider than the reading column, 680px, stacks what sat side by side, and a
   side list of places becomes one row of them. */
@container (max-width: 680px) {
  .ds-type-row { grid-template-columns: minmax(0, 1fr); gap: var(--space-xs); }
  .ds-ui-app, .ds-ui-mail { grid-template-columns: minmax(0, 1fr); }
  .ds-ui-side { flex-flow: row wrap; justify-content: space-between; font-size: var(--text-xs); }
  .ds-ui-side > span { padding-inline: var(--space-xs); }
  .ds-ui-mail > * { border-right: 0; border-bottom: var(--border-thin) solid var(--color-border); }
  .ds-ui-mail > :last-child { border-bottom: 0; }
  .ds-section > .ds-actions { flex-direction: column; align-items: stretch; }
}

/* A wider one sets its strip in one row, its stats, swatches and weights in fours, its
   cards, charts and figures in threes. */
@container (min-width: 681px) {
  .ds-strip { grid-template-columns: repeat(8, minmax(0, 1fr)); }
  .ds-stats, .ds-swatches, .ds-ui-weights { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .ds-ui-grid, .ds-ui-trio, .ds-chart-row { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .ds-ui-pair { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* Under a desktop's width the panel is a sheet along the bottom edge: a handle
   until something is chosen or the handle is pressed, then the panel itself. On a
   tall screen it leaves the top to what is being edited and takes no more than
   55% of the height; on a short one, a phone on its side, it takes what the
   header leaves. The page ends clear of it either way, and whatever is chosen or
   focused is brought to rest above it. */
@media (max-width: 1023px) {
  .ds {
    --ds-panel-height: max(min(calc(100dvh - var(--ds-header)), calc(var(--chrome-size) * 5)),
      min(calc(100dvh - var(--chrome-size) * 6), 55dvh));
    padding-bottom: calc(var(--chrome-size) * 2);
  }

  .ds:has(.ds-panel.is-open) { padding-bottom: calc(var(--ds-panel-height) + var(--space-lg)); }
  .ds:has(.ds-panel.is-open) :is(.ds-sheet .ds-pick, .ds-sheet button, .next-step a) {
    scroll-margin-bottom: var(--ds-panel-height);
  }

  .ds-panel {
    position: fixed;
    scroll-padding-top: calc(var(--ds-tap) * 3 + var(--space-md));
    inset: auto 0 0 0;
    z-index: calc(var(--z-header) - 1);
    max-height: var(--ds-panel-height);
    overflow-y: auto;
    padding: 0 var(--space-md) calc(var(--space-sm) + env(safe-area-inset-bottom, 0px));
    border-width: var(--border-thin) 0 0;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    box-shadow: var(--chrome-shadow);
  }

  /* The handle and the tools stay at the top of the sheet while its fields scroll under them. */
  .ds-panel-top {
    position: sticky;
    top: 0;
    z-index: 1;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    padding-top: var(--space-sm);
    background: var(--color-bg);
  }

  .ds-panel-handle { display: block; width: 100%; color: var(--color-text); }
  .ds-panel-name { display: none; }
  .ds-panel-bar + .ds-panel-bar, .ds-status { grid-column: 1 / -1; }
  .ds-panel:not(.is-open) .ds-panel-bar,
  .ds-panel:not(.is-open) .ds-panel-body,
  .ds-panel:not(.is-open) .ds-status:empty,
  .ds-panel.is-scoped .ds-panel-bar + .ds-panel-bar { display: none; }
  .ds-panel:not(.is-open) .ds-panel-top { grid-template-columns: minmax(0, 1fr); padding-bottom: 0; border-bottom: 0; }
}

/* A phone on its side has no height to give a sheet along the bottom: the open panel
   stands at the right instead, under the header, and the page keeps the left. */
@media (max-width: 1023px) and (orientation: landscape) and (max-height: 480px) {
  .ds:has(.ds-panel.is-open) { padding-right: 50%; padding-bottom: calc(var(--chrome-size) * 2); }
  .ds:has(.ds-panel.is-open) :is(.ds-sheet .ds-pick, .ds-sheet button, .next-step a) { scroll-margin-bottom: 0; }

  .ds-panel.is-open {
    inset: var(--ds-header) 0 0 auto;
    width: 50%;
    max-height: none;
    border-width: 0 0 0 var(--border-thin);
    border-radius: 0;
  }
}

/* From a tablet's width the page opens as far down as the site's other pages do. */
@media (min-width: 768px) {
  .ds-layout { padding-top: calc(var(--space-2xl) + var(--space-xl)); }
}

@media (min-width: 1024px) {
  .ds { padding-left: var(--nav-column); }

  .ds-layout {
    grid-template-columns: calc(var(--nav-column) * 1.5) minmax(0, 1fr);
    align-items: start;
    gap: var(--space-xl);
    padding-inline: 0 var(--space-lg);
  }

  .ds-layout > .next-step { grid-column: 2; }

  /* Held below the floating header, which would otherwise cover its first row. */
  .ds-panel {
    --ds-below-header: calc(var(--chrome-inset) + var(--chrome-size) + var(--space-md));
    position: sticky;
    top: var(--ds-below-header);
    max-height: calc(100vh - var(--ds-below-header) - var(--space-lg));
    overflow-y: auto;
  }
}

/* Every control a finger can reach is at least a fingertip across. */
@media (pointer: coarse) {
  .ds-tool, .ds-button, .ds-panel-tab, .ds-tab, .ds-chip, .ds-panel-handle, .ds-input, .ds-colour,
  .ds-readonly summary, .ds-import-file::file-selector-button {
    min-height: var(--ds-tap);
    min-width: var(--ds-tap);
  }

  .ds-range, .ds-pick:not(.ds-strip-cell) { min-height: var(--ds-tap); }
  /* Under 16px, a phone zooms the page in on a field it is typing into. */
  .ds-input { font-size: var(--text-base); }

  .ds-pick.is-inline {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: var(--ds-tap);
  }
}

@media (prefers-reduced-motion: reduce) {
  .ds-sheet, .ds-pick, .ds-ui-toggle, .ds-ui-toggle::after,
  .ds-tool, .ds-button, .ds-panel-tab, .ds-tab, .ds-chip, .ds-panel-handle { transition: none; }
}
