.edition-compare-builder {
  display: grid;
  gap: .9rem;
  margin: 0 0 1.25rem;
  padding: 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  box-shadow: var(--shadow-sm);
}

.ecb-head {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 1rem;
}

.ecb-kicker {
  margin: 0 0 .2rem;
  color: var(--text-muted);
  font-size: .76rem;
  font-weight: 800;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.ecb-head h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(1.25rem, 3vw, 2rem);
  line-height: 1;
  text-transform: uppercase;
}

.ecb-action,
.ecb-selected button,
.ecb-result {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
}

.ecb-action {
  min-height: 42px;
  padding: .55rem .85rem;
  font-weight: 800;
}

.ecb-action:not(:disabled) {
  border-color: color-mix(in srgb, var(--accent-canonical) 48%, var(--border));
  background: color-mix(in srgb, var(--accent-canonical) 16%, var(--surface));
}

.ecb-action:disabled {
  cursor: not-allowed;
  opacity: .55;
}

/* Sits where the old Compare button did, at the end of the head row. The page
   recomputes on every edit, so the head says so rather than offering a submit
   control that no longer has anything to submit. */
.ecb-live-note {
  max-width: 26ch;
  text-align: right;
}

.ecb-fields {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: .85rem;
}

.ecb-field {
  display: grid;
  gap: .45rem;
  min-width: 0;
}

.ecb-field label {
  color: var(--text-muted);
  font-size: .78rem;
  font-weight: 800;
  text-transform: uppercase;
}

.ecb-input {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: .55rem .7rem;
  background: var(--surface);
  color: var(--text);
}

.ecb-selected {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) auto;
  gap: .6rem;
  align-items: center;
  min-height: 64px;
  padding: .45rem;
  border: 1px solid color-mix(in srgb, var(--border) 72%, transparent);
  border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--surface-2) 56%, transparent);
}

.ecb-selected img,
.ecb-result img {
  width: 44px;
  aspect-ratio: 2 / 3;
  object-fit: cover;
  border-radius: 4px;
  background: var(--surface-2);
}

.ecb-selected strong,
.ecb-result strong {
  display: block;
  overflow-wrap: anywhere;
  line-height: 1.15;
}

.ecb-selected small,
.ecb-result small {
  display: block;
  color: var(--text-muted);
  line-height: 1.25;
}

.ecb-selected button {
  padding: .4rem .55rem;
  font-weight: 700;
}

.ecb-error {
  margin: 0;
  color: var(--danger, #dc3545);
  font-weight: 700;
}

.ecb-suggestions {
  display: grid;
  gap: .75rem;
  max-height: min(56vh, 520px);
  overflow: auto;
  padding: .75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--surface) 98%, transparent);
}

.ecb-group {
  display: grid;
  gap: .4rem;
}

.ecb-group h3 {
  margin: 0;
  color: var(--text-muted);
  font-size: .76rem;
  font-weight: 900;
  text-transform: uppercase;
}

.ecb-result {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr);
  gap: .6rem;
  align-items: center;
  width: 100%;
  padding: .5rem;
  text-align: left;
}

.ecb-result:hover,
.ecb-result:focus-visible {
  border-color: color-mix(in srgb, var(--accent-canonical) 48%, var(--border));
  outline: none;
}

@media (max-width: 767.98px) {
  .ecb-head,
  .ecb-fields {
    grid-template-columns: 1fr;
  }

  .ecb-head {
    display: grid;
  }

  .ecb-action {
    width: 100%;
  }

  .ecb-live-note {
    max-width: none;
    text-align: left;
  }
}

/* --- auto-loaded "Suggested related editions" row --- */
.cb-suggested {
  display: grid;
  gap: .55rem;
  padding: .75rem;
  border: 1px solid color-mix(in srgb, var(--accent-canonical) 30%, var(--border));
  border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--accent-canonical) 7%, var(--surface));
}

.cb-suggested-title {
  margin: 0;
  color: var(--text-muted);
  font-size: .78rem;
  font-weight: 800;
  letter-spacing: .05em;
  text-transform: uppercase;
}

.cb-suggested-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: .55rem;
}

.cb-suggested-card {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr);
  grid-template-rows: auto auto auto;
  column-gap: .6rem;
  align-items: start;
  width: 100%;
  padding: .5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  text-align: left;
  cursor: pointer;
}

.cb-suggested-card:hover:not(:disabled),
.cb-suggested-card:focus-visible {
  border-color: color-mix(in srgb, var(--accent-canonical) 48%, var(--border));
  outline: none;
}

.cb-suggested-card:disabled {
  cursor: not-allowed;
  opacity: .55;
}

.cb-suggested-card img {
  grid-row: 1 / 4;
  width: 44px;
  aspect-ratio: 2 / 3;
  object-fit: cover;
  border-radius: 4px;
  background: var(--surface-2);
}

.cb-suggested-title-text {
  min-width: 0;
  overflow-wrap: anywhere;
  line-height: 1.2;
  font-size: .88rem;
  font-weight: 700;
}

.cb-suggested-type {
  color: var(--text-muted);
  font-size: .78rem;
  line-height: 1.2;
}

.cb-suggested-badge {
  justify-self: start;
  margin-top: .15rem;
  padding: .1rem .4rem;
  border-radius: 999px;
  background: color-mix(in srgb, var(--accent-canonical) 16%, var(--surface-2));
  color: var(--text-muted);
  font-size: .72rem;
  font-weight: 700;
}

/* --- set-vs-set two-side builder --- */
.cb-sides {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: .85rem;
}

.cb-side {
  display: grid;
  align-content: start;
  gap: .6rem;
  min-width: 0;
  padding: .85rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--surface-2) 34%, transparent);
}

.cb-side-title {
  margin: 0;
  color: var(--text-muted);
  font-size: .78rem;
  font-weight: 800;
  letter-spacing: .05em;
  text-transform: uppercase;
}

.cb-chips {
  display: grid;
  gap: .5rem;
}

.cb-chip {
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr) auto;
  /* Row 1 is exactly the pre-existing single-row chip (img/title/remove) --
     "." leaves row 2's outer columns unoccupied so img/remove never span
     into it. That keeps row 1's auto height driven solely by its own three
     items (img is tallest, ~54px), identical to before this task, whether
     or not row 2 ends up with a price in it. Row 2 (price) is a plain
     content-sized track: empty and 0px when Best is absent, so a no-price
     chip renders with the same height, the same align-items: center on the
     same single occupied row, and no extra row-gap (none is set; spacing
     for the price line comes from its own margin-top instead). */
  grid-template-areas:
    "img title  remove"
    ".   price  .";
  column-gap: .55rem;
  align-items: center;
  padding: .4rem;
  border: 1px solid color-mix(in srgb, var(--border) 72%, transparent);
  border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
}

.cb-chip img {
  grid-area: img;
  width: 36px;
  aspect-ratio: 2 / 3;
  object-fit: cover;
  border-radius: 4px;
  background: var(--surface-2);
}

.cb-chip-title {
  grid-area: title;
  min-width: 0;
  overflow-wrap: anywhere;
  line-height: 1.2;
  font-size: .88rem;
}

.cb-chip-price {
  grid-area: price;
  display: block;
  min-width: 0;
  margin: .15rem 0 0;
  color: var(--text-muted);
  font-size: .78rem;
  font-weight: 700;
  line-height: 1.25;
}

.cb-chip-price-state {
  font-style: italic;
}

.cb-chip-condition {
  margin-left: .4rem;
  color: var(--text);
  font-weight: 500;
}

.cb-chip-remove {
  grid-area: remove;
  min-width: 28px;
  min-height: 28px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text-muted);
  font-weight: 800;
  line-height: 1;
  cursor: pointer;
}

.cb-chip-remove:hover,
.cb-chip-remove:focus-visible {
  color: var(--danger, #dc3545);
  border-color: color-mix(in srgb, var(--danger, #dc3545) 48%, var(--border));
  outline: none;
}

.cb-add {
  position: relative;
  display: grid;
  gap: .4rem;
}

.cb-input {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: .5rem .65rem;
  background: var(--surface);
  color: var(--text);
}

.cb-suggestions {
  display: grid;
  gap: .35rem;
  max-height: min(46vh, 420px);
  overflow: auto;
  padding: .5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--surface) 98%, transparent);
  box-shadow: var(--shadow-sm);
}

.cb-suggestion {
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr);
  gap: .55rem;
  align-items: center;
  width: 100%;
  padding: .4rem;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: none;
  color: var(--text);
  text-align: left;
  cursor: pointer;
}

.cb-suggestion img {
  width: 36px;
  aspect-ratio: 2 / 3;
  object-fit: cover;
  border-radius: 4px;
  background: var(--surface-2);
}

.cb-suggestion:hover,
.cb-suggestion:focus-visible {
  border-color: color-mix(in srgb, var(--accent-canonical) 48%, var(--border));
  outline: none;
}

.cb-cap-note {
  margin: 0;
  color: var(--text-muted);
  font-size: .8rem;
}

@media (max-width: 767.98px) {
  .cb-sides {
    grid-template-columns: 1fr;
  }
}
