/*
 * The builder page. Light and cartoon-like: warm paper behind, white cards
 * with a dark outline and a hard shadow like the line in the art, and one
 * yellow accent. The type comes from the Adobe Fonts kit in web/index.html:
 * Owners Narrow Bold for the wordmark and the headings (--font-head), and
 * Neue Haas Grotesk Text for everything else, in 400, 500 and 700. The
 * system face stands in until the kit loads, or when it can't.
 */
:root {
  --paper: #f7f3ea;
  --card: #ffffff;
  /* Text and outlines. 12.9:1 on paper. */
  --ink: #232e41;
  /* Secondary text. 5.6:1 on paper, 6.3:1 on white. */
  --muted: #5d6676;
  /* Hairlines between parts of a card. */
  --line: #e4ded1;
  /* The one accent: Randomize, a picked tile's check and a Lock that is on. */
  --accent: #f6d34b;
  --accent-hover: #f9dd6e;
  --error: #a4262c;

  /* The face of the wordmark and the headings. */
  --font-head: 'owners-narrow', system-ui, -apple-system, 'Segoe UI', sans-serif;

  /* One type scale. */
  --t-h1: clamp(2.125rem, 1.6rem + 2vw, 3rem);
  --t-title: 1.125rem;
  --t-body: 1rem;
  --t-small: 0.875rem;

  /* One radius for cards, one for tiles and inputs, and pills. */
  --r-card: 24px;
  --r-tile: 14px;
  --r-pill: 999px;

  /* The outline and the hard shadow under a card or a button. */
  --stroke: 2px solid var(--ink);
  --lift: 0 4px 0 var(--ink);

  /* The ground under a coming-soon character's picture: the yellow of the alien's first background. */
  --character-ground: #f6d44a;
  /* How wide a character tile gets at most. The pictures in styles/coming-soon/ are twice its 176 px picture. */
  --character-tile: 180px;

  /* How wide a thumbnail is. src/thumbnails.js has the same 120. */
  --thumbnail: 120px;
  /* How wide a swatch is in the column next to the preview. */
  --swatch: 34px;
  /* The room between swatches, and the ring around the picked one. */
  --swatch-gap: 8px;
  --ring: 3px;
  /* How far the picked ring and the focus ring reach past a swatch, at most. */
  --swatch-reach: 5px;

  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);

  color-scheme: light;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: 'neue-haas-grotesk-text', system-ui, -apple-system, 'Segoe UI', sans-serif;
  font-size: var(--t-body);
  line-height: 1.5;
  color: var(--ink);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
}

h1,
h2,
p {
  margin: 0;
}

button,
select,
input {
  font: inherit;
  color: inherit;
}

.visually-hidden,
.tile-name {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.icon {
  width: 20px;
  height: 20px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

:focus-visible {
  outline: 3px solid var(--ink);
  outline-offset: 3px;
}

/* ---- Top bar --------------------------------------------------------- */

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px 16px;
  max-width: 1280px;
  margin: 0 auto;
  padding: 20px 32px;
}

.wordmark {
  /* The name comes from src/brand.js. The line keeps its height while the page script fills it in. */
  min-height: 1em;
  font-family: var(--font-head);
  font-size: 2rem;
  font-weight: 700;
  line-height: 1;
}

/* ---- Page ------------------------------------------------------------ */

main {
  max-width: 1280px;
  margin: 0 auto;
  padding: 8px 32px 64px;
}

.intro {
  display: grid;
  gap: 6px;
  margin-bottom: 28px;
}

h1 {
  font-family: var(--font-head);
  font-size: var(--t-h1);
  font-weight: 700;
  line-height: 1.05;
  letter-spacing: 0;
  text-wrap: balance;
}

.lede {
  max-width: 36em;
  color: var(--muted);
  font-size: var(--t-title);
  /* Short copy breaks into lines of similar length. */
  text-wrap: balance;
}

.notice {
  color: var(--muted);
  font-size: var(--t-small);
}

.notice:empty {
  display: none;
}

/* ---- Character tab -------------------------------------------------- */

/*
 * The Character tab is the panel's first tab. Its tiles are the trait
 * tiles' (.tile in the panel) with a caption under the picture: the
 * character's name, and for a character that can't be picked yet a small
 * "Coming soon" tag. A style's tile is a label with a radio button. A
 * coming-soon tile is a div with its picture as an image, on the ground
 * the alien's tile opens on.
 */
.tiles.characters > * {
  max-width: var(--character-tile);
}

.base-caption {
  display: grid;
  justify-items: start;
  gap: 3px;
  padding: 6px 8px 7px;
  background: var(--card);
  font-size: var(--t-small);
  line-height: 1.25;
}

.base-name {
  max-width: 100%;
  overflow: hidden;
  font-weight: 500;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Muted text on paper is 5.6:1. */
.base-tag {
  padding: 0 7px;
  border-radius: var(--r-pill);
  background: var(--paper);
  color: var(--muted);
  white-space: nowrap;
}

.tile.coming-soon .thumb {
  background: var(--character-ground);
}

.tile.coming-soon:focus-visible {
  outline: 3px solid var(--ink);
  outline-offset: 3px;
}

/* Small fixture pictures are scaled up on a character tile, so keep their pixels sharp. */
.base-thumb.pixel-art {
  image-rendering: pixelated;
}

/*
 * Two columns on a wide page: the preview with its swatches and buttons,
 * then the trait panel. One column under 900 px.
 */
.layout {
  display: grid;
  grid-template-columns: minmax(0, 600px) minmax(0, 1fr);
  gap: 40px;
  align-items: start;
}

@media (max-width: 899px) {
  .layout {
    grid-template-columns: minmax(0, 1fr);
    gap: 28px;
  }
}

/*
 * On a wide page the preview column stays on screen while the trait panel
 * scrolls. Below 900 px the page scrolls as one.
 */
@media (min-width: 900px) {
  /*
   * In a window too short for the whole column, the column scrolls on its
   * own, so Download stays in reach. The 16 px of padding, taken back by
   * the margin, keeps the card's shadow, a focus ring and the Randomize
   * stars inside the scrolling box.
   */
  .stage-column {
    position: sticky;
    top: 8px;
    max-height: calc(100vh - 16px);
    overflow-y: auto;
    scrollbar-width: thin;
    padding: 16px;
    margin: -16px;
  }
}

.stage-column {
  display: grid;
  gap: 20px;
  min-width: 0;
}

/* ---- Preview and swatches -------------------------------------------- */

/*
 * On a wide page the preview is as big as the window's height allows, so
 * the buttons and the Size picker under it are on screen when the page
 * opens, at 900 px tall and on a 1366 x 768 laptop. In a window under
 * 820 px tall the swatches get smaller too, so ten of them and the Lock
 * still fit beside the preview.
 */
@media (min-width: 900px) {
  .stage-card {
    max-width: max(360px, calc(100vh - 400px));
  }
}

@media (min-width: 900px) and (max-height: 820px) {
  :root {
    --swatch: 26px;
    --swatch-gap: 5px;
  }
}

/*
 * The swatch column on the left of the preview. The column takes no height
 * of its own (contain: size), so the preview sets the row's height. When
 * the swatches don't all fit, in a short window or for a style with more
 * colours, the list of swatches scrolls with a thin scrollbar and the Lock
 * stays at the foot of the column, always in view.
 */
.stage-row {
  display: grid;
  grid-template-columns: calc(var(--swatch) + 12px) minmax(0, 1fr);
  gap: 16px;
  align-items: stretch;
}

.stage-row:has(.swatches[hidden]) {
  grid-template-columns: minmax(0, 1fr);
}

.swatches {
  contain: size;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--swatch-gap);
  /* Room for the Lock's focus ring, drawn 2 px outside it. */
  padding-bottom: 2px;
  overflow: hidden;
}

.swatches[hidden] {
  display: none;
}

.swatch-list {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex: 0 1 auto;
  align-self: stretch;
  min-height: 0;
  gap: var(--swatch-gap);
  /* Room at the ends of the list for the picked ring and the focus ring. */
  padding: var(--swatch-reach) 0;
  overflow-y: auto;
  scrollbar-width: thin;
}

label.swatch {
  position: relative;
  display: block;
  flex: none;
  width: var(--swatch);
  height: var(--swatch);
  border: var(--stroke);
  border-radius: 50%;
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.18s var(--ease-out);
}

label.swatch:hover {
  transform: scale(1.08);
}

label.swatch .thumb {
  display: block;
  width: 100%;
  height: 100%;
}

/* The picked swatch gets a ring in the page's colour and one in ink, so it doesn't show by colour alone. */
label.swatch:has(input:checked) {
  box-shadow:
    0 0 0 var(--ring) var(--paper),
    0 0 0 calc(var(--ring) + 2px) var(--ink);
}

/*
 * A focused swatch: a 3 px yellow halo inside a 2 px ink outline, 5 px out
 * in all (--swatch-reach), so the list's padding and the column's 6 px a
 * side hold it whole, at the first and last swatch too. In a radio group
 * focus and the pick move together, so the halo takes the place of the
 * picked ring while the swatch has focus.
 */
label.swatch:has(input:focus-visible) {
  outline: 2px solid var(--ink);
  outline-offset: 3px;
  box-shadow: 0 0 0 3px var(--accent);
}

.stage-card {
  position: relative;
  padding: 10px;
  border: var(--stroke);
  border-radius: var(--r-card);
  background: var(--card);
  box-shadow: 0 6px 0 var(--ink);
}

.stage {
  position: relative;
  border-radius: var(--r-tile);
  overflow: hidden;
  line-height: 0;
  transition: border-radius 0.38s var(--ease-out);
}

#preview {
  display: block;
  width: 100%;
  /* No fixed aspect ratio: the canvas takes its shape from the manifest's canvas size. */
  height: auto;
  transition: clip-path 0.38s var(--ease-out);
  clip-path: inset(0 round var(--r-tile));
}

/* Small fixture images are scaled up, so keep their pixels sharp. */
#preview.pixel-art,
.thumb.pixel-art {
  image-rendering: pixelated;
}

/*
 * The Circle switch shows the picture the way GitHub shows it: the circle
 * in the middle square. closest-side is half the shorter side, the circle
 * src/round-preview.js describes.
 */
.stage-card.round #preview {
  clip-path: circle(closest-side at 50% 50%);
}

.circle-switch {
  position: absolute;
  z-index: 1;
  top: 22px;
  right: 22px;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 34px;
  padding: 0 12px 0 8px;
  border: var(--stroke);
  border-radius: var(--r-pill);
  background: var(--card);
  font-size: var(--t-small);
  font-weight: 500;
  cursor: pointer;
}

/* A small switch drawn on the checkbox itself, so it keeps focus and its name. */
.circle-switch input {
  appearance: none;
  position: relative;
  width: 30px;
  height: 18px;
  margin: 0;
  border: var(--stroke);
  border-radius: var(--r-pill);
  background: var(--paper);
  cursor: pointer;
  transition: background-color 0.18s var(--ease-out);
}

.circle-switch input::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--ink);
  transition: transform 0.18s var(--ease-out);
}

.circle-switch input:checked {
  background: var(--accent);
}

.circle-switch input:checked::after {
  transform: translateX(12px);
}

/* The picture settles into place after it changes: a short soft scale. */
.stage-card.settle .stage {
  animation: settle 0.42s var(--ease-out);
}

@keyframes settle {
  0% {
    transform: scale(0.965);
  }
  60% {
    transform: scale(1.008);
  }
  100% {
    transform: none;
  }
}

/* Randomize sends a few four-point stars out from the edges of the preview card. */
.sparkles {
  position: absolute;
  z-index: 2;
  inset: -16px;
  pointer-events: none;
}

.sparkles span {
  position: absolute;
  width: 40px;
  height: 40px;
  opacity: 0;
  background: var(--ink);
  clip-path: polygon(50% 0, 62% 38%, 100% 50%, 62% 62%, 50% 100%, 38% 62%, 0 50%, 38% 38%);
}

/* A yellow star inside an ink one, so each star has the art's outline. */
.sparkles span::after {
  content: '';
  position: absolute;
  inset: 6px;
  background: var(--accent);
  clip-path: inherit;
}

.sparkles span:nth-child(1) {
  top: 0;
  left: 6%;
}

.sparkles span:nth-child(2) {
  top: 10%;
  right: 0;
  width: 30px;
  height: 30px;
}

.sparkles span:nth-child(3) {
  top: 52%;
  right: 0;
  width: 24px;
  height: 24px;
}

.sparkles span:nth-child(4) {
  bottom: 0;
  right: 18%;
  width: 34px;
  height: 34px;
}

.sparkles span:nth-child(5) {
  bottom: 14%;
  left: 0;
  width: 30px;
  height: 30px;
}

.sparkles span:nth-child(6) {
  top: 34%;
  left: 0;
  width: 22px;
  height: 22px;
}

.sparkles.go span {
  animation: sparkle 0.7s var(--ease-out) both;
}

.sparkles.go span:nth-child(2n) {
  animation-delay: 0.06s;
}

.sparkles.go span:nth-child(3n) {
  animation-delay: 0.12s;
}

@keyframes sparkle {
  0% {
    opacity: 0;
    transform: scale(0) rotate(-30deg);
  }
  35% {
    opacity: 1;
    transform: scale(1.15) rotate(0deg);
  }
  100% {
    opacity: 0;
    transform: scale(0.4) rotate(25deg);
  }
}

/* ---- Buttons --------------------------------------------------------- */

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.stage-row:has(.swatches:not([hidden])) ~ .actions,
.stage-row:has(.swatches:not([hidden])) ~ .size-picker,
.stage-row:has(.swatches:not([hidden])) ~ .status {
  margin-left: calc(var(--swatch) + 28px);
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  /* At a big zoom a button's text wraps inside it rather than run off the page. */
  max-width: 100%;
  min-height: 48px;
  padding: 0 20px;
  border: var(--stroke);
  border-radius: var(--r-pill);
  background: var(--card);
  box-shadow: var(--lift);
  font-weight: 500;
  cursor: pointer;
  transition:
    transform 0.18s var(--ease-out),
    box-shadow 0.18s var(--ease-out),
    background-color 0.18s var(--ease-out);
}

.button:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 5px 0 var(--ink);
}

.button:active:not(:disabled) {
  transform: translateY(3px);
  box-shadow: 0 1px 0 var(--ink);
}

.button.primary {
  background: var(--accent);
}

.button.primary:hover:not(:disabled) {
  background: var(--accent-hover);
}

.button.quiet {
  border-color: transparent;
  background: transparent;
  box-shadow: none;
  color: var(--ink);
}

.button.quiet:hover:not(:disabled) {
  border-color: var(--ink);
  box-shadow: none;
  transform: none;
}

.button:disabled {
  cursor: default;
  opacity: 0.45;
}

/* The size picker: a small row of pills under the buttons. */
.size-picker {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.size-picker[hidden] {
  display: none;
}

.size-picker legend {
  float: left;
  margin-right: 4px;
  padding: 0;
  color: var(--muted);
  font-size: var(--t-small);
  font-weight: 500;
}

.size-picker label {
  position: relative;
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 0 14px;
  border: 2px solid var(--line);
  border-radius: var(--r-pill);
  background: var(--card);
  font-size: var(--t-small);
  font-weight: 500;
  cursor: pointer;
}

.size-picker input {
  position: absolute;
  inset: 0;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

.size-picker label:has(input:checked) {
  border-color: var(--ink);
}

.size-picker label:has(input:focus-visible) {
  outline: 3px solid var(--ink);
  outline-offset: 3px;
}

.size-picker:disabled {
  opacity: 0.45;
}

.status {
  min-height: 1.5em;
  color: var(--muted);
  font-size: var(--t-small);
}

.status:empty {
  display: none;
}

.status.error {
  color: var(--error);
}

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

.panel {
  /* The tabs change shape with the panel's width (the container query below). */
  container-type: inline-size;
  min-width: 0;
  border: var(--stroke);
  border-radius: var(--r-card);
  background: var(--card);
  box-shadow: 0 6px 0 var(--ink);
  overflow: hidden;
}

/*
 * One row of tabs on a yellow bar when the panel has room for all of them.
 * When it doesn't, on a phone or in a narrow window, they wrap as pills
 * (the container query below), so no tab is ever cut off.
 */
.tabs {
  display: flex;
  gap: 4px;
  /* 10 px in from a 24 px card, so the tabs' 14 px corners are concentric with it. */
  padding: 10px 10px 0;
  border-bottom: 2px solid var(--line);
  overflow-x: auto;
  scrollbar-width: none;
}

.tabs[hidden] {
  display: none;
}

.tab {
  flex: none;
  position: relative;
  min-height: 44px;
  padding: 0 11px;
  border: 0;
  border-radius: var(--r-tile) var(--r-tile) 0 0;
  background: transparent;
  color: var(--muted);
  font-weight: 500;
  cursor: pointer;
  transition: color 0.18s var(--ease-out);
}

.tab:hover {
  color: var(--ink);
}

.tab[aria-selected='true'] {
  color: var(--ink);
}

/* The open tab sits on a yellow bar with the art's outline. */
.tab[aria-selected='true']::after {
  content: '';
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: -2px;
  height: 6px;
  border: var(--stroke);
  border-radius: var(--r-pill);
  background: var(--accent);
}

.tab:focus-visible {
  outline-offset: -3px;
}

/*
 * Six tabs need about 540 px in one row. In a narrower panel they wrap as
 * pills, and the open one is yellow with the art's outline, like a Lock
 * that is on.
 */
@container (max-width: 559px) {
  .tabs {
    flex-wrap: wrap;
    gap: 6px;
    padding: 12px;
    overflow: visible;
  }

  .tab {
    min-height: 36px;
    padding: 0 12px;
    border: 2px solid var(--line);
    border-radius: var(--r-pill);
    font-size: var(--t-small);
  }

  .tab:hover {
    border-color: var(--ink);
  }

  .tab[aria-selected='true'] {
    border-color: var(--ink);
    background: var(--accent);
  }

  .tab[aria-selected='true']::after {
    display: none;
  }

  .tab:focus-visible {
    outline-offset: 3px;
  }
}

.trait {
  display: grid;
  gap: 16px;
  min-width: 0;
  padding: 20px;
}

.trait[hidden] {
  display: none;
}

/* The group's name and its pick on the left, its Lock on the right. */
.trait-heading {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.trait-heading h2 {
  font-family: var(--font-head);
  font-size: 1.375rem;
  font-weight: 700;
  line-height: 1.1;
}

.pick {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  color: var(--muted);
  font-weight: 400;
  text-overflow: ellipsis;
  white-space: nowrap;
}

label.lock {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 36px;
  padding: 0 12px 0 10px;
  border: 2px solid var(--line);
  border-radius: var(--r-pill);
  background: var(--card);
  font-size: var(--t-small);
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
  transition:
    border-color 0.18s var(--ease-out),
    background-color 0.18s var(--ease-out);
}

/*
 * The checkbox is hidden on screen and covers the label, so a click
 * anywhere on it toggles the lock and the checkbox keeps focus and its name.
 */
label.lock input {
  position: absolute;
  inset: 0;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

label.lock:hover {
  border-color: var(--ink);
}

label.lock:has(input:checked) {
  border-color: var(--ink);
  background: var(--accent);
}

/* The shackle opens while the lock is off. */
.padlock .shackle {
  transition: transform 0.18s var(--ease-out);
  transform-origin: 15.5px 10.5px;
  transform: translateY(-1.5px) rotate(28deg);
}

label.lock:has(input:checked) .padlock .shackle {
  transform: none;
}

label.lock:has(input:focus-visible) {
  outline: 3px solid var(--ink);
  outline-offset: 3px;
}

/* In the swatch column the Lock is a round button with the padlock only. */
label.lock.compact {
  flex: none;
  justify-content: center;
  width: var(--swatch);
  min-height: var(--swatch);
  padding: 0;
}

/* The column clips what reaches past it, so the compact Lock's focus ring sits close in. */
label.lock.compact:has(input:focus-visible) {
  outline-offset: -1px;
}

label.lock.compact .lock-text {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* The tiles fill the panel's width, as many to a row as fit at about 96 px. */
.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(var(--thumbnail), 100%), 1fr));
  gap: 12px;
}

label.tile:not(.swatch),
.tile.coming-soon {
  position: relative;
  display: block;
  min-width: 0;
  border: 2px solid var(--line);
  border-radius: var(--r-tile);
  overflow: hidden;
  line-height: 0;
  cursor: pointer;
  transition:
    border-color 0.18s var(--ease-out),
    transform 0.18s var(--ease-out);
}

/* A coming-soon tile can't be picked, so it gets no pointer and no lift. Its picture stays as clear as the alien's. */
.tile.coming-soon {
  cursor: default;
}

label.tile:not(.swatch):hover {
  border-color: var(--ink);
  transform: translateY(-2px);
}

label.tile:not(.swatch) .thumb,
.tile.coming-soon .thumb {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 1;
}

/*
 * The radio button is hidden on screen and stays in the page, so it keeps
 * focus, the arrow keys and its accessible name.
 */
label.tile input {
  position: absolute;
  top: 0;
  left: 0;
  width: 1px;
  height: 1px;
  margin: 0;
  opacity: 0;
  pointer-events: none;
}

/*
 * The picked tile has an ink frame, a hard shadow and a yellow check, so
 * it doesn't show by colour alone. It pops once when it is picked.
 */
label.tile:not(.swatch):has(input:checked) {
  border-color: var(--ink);
  box-shadow: inset 0 0 0 1px var(--ink);
  animation: pop 0.32s var(--ease-out);
}

label.tile:not(.swatch):has(input:checked)::after {
  content: '✓';
  position: absolute;
  top: 6px;
  right: 6px;
  width: 22px;
  height: 22px;
  border: var(--stroke);
  border-radius: 50%;
  background: var(--accent);
  color: var(--ink);
  font-size: 12px;
  font-weight: 700;
  line-height: 18px;
  text-align: center;
}

label.tile:not(.swatch):has(input:focus-visible) {
  outline: 3px solid var(--ink);
  outline-offset: 3px;
}

@keyframes pop {
  0% {
    transform: scale(0.92);
  }
  60% {
    transform: scale(1.03);
  }
  100% {
    transform: none;
  }
}

/* ---- Phone ----------------------------------------------------------- */

@media (max-width: 560px) {
  /* Ten swatches and the Lock fit beside a preview 314 px tall. */
  :root {
    --swatch: 24px;
    --swatch-gap: 4px;
    --ring: 2px;
  }

  .topbar {
    padding: 14px 16px;
  }

  .wordmark {
    font-size: 1.625rem;
  }

  main {
    padding: 4px 16px 48px;
  }

  .intro {
    margin-bottom: 20px;
  }

  .lede {
    font-size: var(--t-body);
  }

  .stage-row {
    gap: 6px;
  }

  .circle-switch {
    top: 18px;
    right: 18px;
  }

  /* The stars stay inside the page's 16 px margin, so the page never scrolls sideways. */
  .sparkles {
    inset: -10px;
  }

  .stage-row:has(.swatches:not([hidden])) ~ .actions,
  .stage-row:has(.swatches:not([hidden])) ~ .size-picker,
  .stage-row:has(.swatches:not([hidden])) ~ .status {
    margin-left: 0;
  }

  /*
   * Randomize takes the first line. Download and Reset share the second
   * while they fit, and Reset wraps to a line of its own when they don't,
   * on a narrow phone or with the page zoomed in.
   */
  #randomize {
    flex: 1 1 100%;
  }

  #download {
    flex: 1 1 auto;
  }

  .trait {
    padding: 16px;
  }

  .tiles {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 8px;
  }

  /* A character tile has to hold its tag on one line, so the Character tab keeps the wide rule: two to a row at 390 px. */
  .tiles.characters {
    grid-template-columns: repeat(auto-fill, minmax(min(var(--thumbnail), 100%), 1fr));
  }
}

/* With reduced motion on, nothing moves: no settle, no sparkle, no pop. */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }
}
