/* Bead Pattern */
.bd-field-btn {
  align-content: end;
}

.bd-stats {
  margin: 0 0 var(--space);
  font-size: 14px;
  font-weight: 600;
  color: var(--text-muted);
}

.bd-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-sm);
  margin-bottom: var(--space);
}

.bd-toolbar .segmented {
  flex: 0 1 auto;
}

.bd-brush {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 700;
}

.bd-swatch {
  flex: none;
  width: 20px;
  height: 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
}

/* "Empty" (no bead): the usual transparency checkerboard. */
.bd-swatch--empty {
  background-color: #ffffff;
  background-image: conic-gradient(#d1d5db 25%, transparent 0 50%, #d1d5db 0 75%, transparent 0);
  background-size: 10px 10px;
}

.bd-stage {
  max-height: 75vh;
  overflow: auto;
  padding: var(--space-sm);
  background: var(--surface-2);
  border-radius: var(--radius-sm);
}

/* Workbench once an image is loaded (body.is-working): the pattern comes first on narrow
   screens; wide screens put the settings in a left column that scrolls on its own. */
body.is-working .bd-layout {
  display: flex;
  flex-direction: column;
}

body.is-working .bd-result {
  order: -1;
}

body.is-working .bd-stage {
  max-height: calc(100vh - 170px);
}

@media (min-width: 1100px) {
  body.is-working .app {
    max-width: 1680px;
  }

  body.is-working .bd-layout {
    display: grid;
    grid-template-columns: minmax(300px, 360px) minmax(0, 1fr);
    gap: var(--space-lg);
    align-items: start;
  }

  body.is-working .bd-result {
    order: 0;
  }

  body.is-working .bd-layout > .panel {
    margin-bottom: 0;
  }

  body.is-working .bd-settings {
    position: sticky;
    top: var(--space);
    max-height: calc(100vh - 2 * var(--space));
    overflow-y: auto;
    padding: var(--space);
  }
}

.bd-stage canvas {
  display: block;
  margin: 0 auto;
  cursor: crosshair;
  touch-action: none;
}

.bd-heading {
  margin: var(--space-lg) 0 0;
  font-size: 15px;
  font-weight: 700;
}

.bd-legend {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 6px;
  margin-top: var(--space-sm);
}

.bd-color {
  display: flex;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  overflow: hidden;
}

.bd-color.is-active {
  border-color: var(--primary);
  box-shadow: inset 0 0 0 1px var(--primary);
}

.bd-color__pick {
  display: flex;
  flex: 1;
  align-items: center;
  gap: 8px;
  min-width: 0;
  min-height: var(--control-h-sm);
  padding: 0 8px;
  border: none;
  background: none;
  color: var(--text);
  font: inherit;
  font-size: 13px;
  text-align: left;
  cursor: pointer;
}

.bd-color__code {
  font-weight: 700;
}

.bd-color__count {
  margin-left: auto;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.bd-color__swap {
  width: 32px;
  border: none;
  border-left: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-muted);
  font-size: 14px;
  cursor: pointer;
}

.bd-color__swap:hover:not(:disabled) {
  color: var(--primary);
}

.bd-color__swap:disabled {
  opacity: 0.35;
  cursor: default;
}

.bd-palette {
  margin-top: var(--space);
}

.bd-palette summary {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
}

.bd-palette__grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(26px, 1fr));
  gap: 4px;
  margin-top: var(--space-sm);
}

.bd-palette__grid button {
  aspect-ratio: 1;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  cursor: pointer;
}

.bd-palette__grid button.is-active {
  outline: 2px solid var(--primary);
  outline-offset: 1px;
}

.bd-palette__bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-sm);
  margin-top: var(--space-sm);
}

.bd-palette__bar .segmented {
  flex: 0 1 auto;
}

/* Owned colors: a check mark; with "only owned" on, the rest fade. */
.bd-palette__grid button {
  position: relative;
  font-size: 13px;
  font-weight: 800;
  line-height: 1;
}

.bd-palette__grid button.is-owned::after {
  content: "✓";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
}

.bd-palette__grid.is-marking button:not(.is-owned) {
  opacity: 0.55;
}

.bd-palette__grid.is-owned-only button:not(.is-owned) {
  opacity: 0.3;
}

.bd-progress {
  margin: -8px 0 var(--space);
  font-size: 14px;
  font-weight: 700;
  color: var(--primary);
}

.bd-color.is-done .bd-color__pick {
  opacity: 0.45;
  text-decoration: line-through;
}

.bd-color.is-done .bd-color__swap {
  background: var(--primary);
  color: var(--active-text);
}

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