/* ── Multi-level grid: legend inside #pieceTray ──────────────────── */

/* Legend fills the tray when visible. Default hidden. */
#mlgLegend {
  display: none;
  position: absolute;
  inset: 0;
  padding: 16px 20px 28px; /* bottom padding leaves room for the toggle button */
  pointer-events: none;
  z-index: 2;

  /* 4-column layout, one column per level */
  grid-template-columns: repeat(4, 1fr);
  align-content: center;
  gap: 0 8px;

  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 11px;
  color: #5A4638;
}

#mlgLegend.mlg-visible {
  display: grid;
}

/* Each level column */
.mlg-level-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  text-align: center;
}

.mlg-swatch {
  width: 12px;
  height: 12px;
  border-radius: 2px;
  opacity: 0.85;
  flex-shrink: 0;
}

.mlg-name {
  font-size: 10.5px;
  color: #5A4638;
  font-weight: 500;
  line-height: 1.2;
}

.mlg-grid {
  font-size: 9px;
  color: #9B8773;
}

.mlg-bar-wrap {
  width: 80%;
  height: 5px;
  background: rgba(142, 151, 127, 0.15);
  border-radius: 3px;
  overflow: hidden;
}

.mlg-bar {
  height: 100%;
  border-radius: 3px;
  opacity: 0.75;
  transition: width 0.4s ease;
}

.mlg-pct {
  font-size: 10px;
  color: #9B8773;
}

/* ── Toggle button (bottom-right corner of tray) ─────────────────── */
#mlgToggleBtn {
  position: absolute;
  bottom: 6px;
  right: 8px;
  padding: 2px 8px;
  font-size: 10px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: #9B8773;
  background: transparent;
  border: 1px solid rgba(142, 151, 127, 0.4);
  border-radius: 4px;
  cursor: pointer;
  z-index: 3;
  transition: background 0.15s ease, color 0.15s ease;
  pointer-events: auto;
  line-height: 1.6;
}

#mlgToggleBtn:hover {
  background: rgba(142, 151, 127, 0.12);
  color: #5A4638;
}
